Skip to content

Commit

Permalink
Move protofy agents network to another module
Browse files Browse the repository at this point in the history
  • Loading branch information
noreplydev committed Nov 8, 2024
1 parent 081389d commit c21d518
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
12 changes: 3 additions & 9 deletions packages/protolib/src/bundles/agents/agents/agentsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getDB } from '@my/config/dist/storageProviders';
import { generateEvent } from "../../events/eventsLibrary";
import { getLogger } from 'protobase';
import { BifrostProtocol } from "../bifrost/bifrost";
import { network } from "../network/networkApi";

export const AgentsAutoAPI = AutoAPI({
modelName: 'agents',
Expand All @@ -20,12 +21,8 @@ export const AgentsAPI = (app, context) => {
const agentsPath = '../../data/agents/'
const { topicSub, topicPub, mqtt } = context;
AgentsAutoAPI(app, context)
// agents topics: agents/[agentName]/[endpoint], en caso de no tener endpoint: agents/[agentName]
/* examples
agents/patata/switch/relay/actions/status
agents/patata/button/relay/actions/status
...
*/
network(app, context)

app.get('/api/core/v1/agents/:agent/subsystems/:subsystem/actions/:action/:value', handler(async (req, res, session) => {
if (!session || !session.user.admin) {
res.status(401).send({ error: "Unauthorized" })
Expand Down Expand Up @@ -131,7 +128,4 @@ export const AgentsAPI = (app, context) => {
// await db.put(agent.getId(), JSON.stringify(agent.serialize(true)))
res.send({ status: agentInfo.data.status })
}))

// agents protocol
BifrostProtocol({ ...context, logger })
}
24 changes: 24 additions & 0 deletions packages/protolib/src/bundles/agents/network/networkApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { API } from "protobase";
import { AutoAPI, handler, getServiceToken } from 'protonode'
import { getLogger } from 'protobase';
import { BifrostProtocol } from "../bifrost/bifrost";

const logger = getLogger()


export const network = (app, context) => {
const agentsPath = '../../data/agents/'
const { topicSub, topicPub, mqtt } = context;

app.get('/api/core/v1/network', handler(async (req, res, session) => {
if (!session || !session.user.admin) {
res.status(401).send({ error: "Unauthorized" })
return
}

res.send("protofy network")
}))

// agents protocol
BifrostProtocol({ ...context, logger })
}

0 comments on commit c21d518

Please sign in to comment.