Skip to content

Commit

Permalink
Add SpawnAgent mask to flows
Browse files Browse the repository at this point in the history
  • Loading branch information
noreplydev committed Oct 29, 2024
1 parent ba459be commit 3329c00
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 9 deletions.
6 changes: 4 additions & 2 deletions packages/app/bundles/masks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import logsMasks from 'protolib/bundles/logs/masks'
import playwrightMasks from 'protolib/bundles/playwright/masks'
import networkMasks from 'protolib/bundles/network/masks'
import stateMachineMasks from 'protolib/bundles/stateMachines/masks'
import agentsMasks from 'protolib/bundles/agents/agents/masks'
import { paths } from './flows';

export const getFlowsCustomComponents = (path: string, queryParams: {}) => {
Expand Down Expand Up @@ -58,8 +59,9 @@ export const getFlowsCustomComponents = (path: string, queryParams: {}) => {
...discordMasks,
...logsMasks,
...playwrightMasks,
...networkMasks,
...stateMachineMasks
...networkMasks,
...stateMachineMasks,
...agentsMasks
]
return []
}
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions packages/protolib/src/bundles/agents/agents/context/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import CreateAgent from "./CreateAgent"
import spawnAgent from "./SpawnAgent"

export default {
CreateAgent
spawnAgent
}
28 changes: 28 additions & 0 deletions packages/protolib/src/bundles/agents/agents/context/spawnAgent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ProtoAgent } from 'agents'

export default function (options: {
agentName: string,
connectionType: string,
subsystems: object[],
host: string,
hostPort: number,
onConnect: () => void
}) {
const {
agentName,
connectionType,
subsystems,
host,
hostPort,
onConnect,
} = options

switch (connectionType) {
case "mqtt":
const agent = ProtoAgent.mqtt(agentName).configure(subsystems)
agent.on("connect", onConnect)
agent.connect(host, hostPort)
default:
return ProtoAgent.mqtt(agentName)
}
}
79 changes: 79 additions & 0 deletions packages/protolib/src/bundles/agents/agents/masks/SpawnAgent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { Node, NodeOutput, FallbackPort, NodeParams, filterConnection, getId, connectNodes, filterObject, restoreObject } from 'protoflow';
import { useColorFromPalette } from 'protoflow/src/diagram/Theme'
import { Split } from '@tamagui/lucide-icons';
import { agentBusTypes } from './index';

const SpawnAgent = ({ node = {}, nodeData = {}, children }: any) => {
const color = useColorFromPalette(10)

return (
<Node icon={Split} node={node} isPreview={!node.id} title='Spawn Agent' color={color} id={node.id} skipCustom={true}>
<p style={{ fontSize: "22px" }}>Client</p>
<NodeParams id={node.id} params={[{ label: 'Agent name', field: 'mask-agentName', type: 'input' }]} />
<NodeParams id={node.id} params={[{ label: 'Exposed Subsystems', field: 'mask-subsystems', type: 'input' }]} />
<div style={{ height: '30px' }} />
<p style={{ fontSize: "22px" }}>Server</p>
<NodeParams id={node.id} params={[{ label: 'Host', field: 'mask-host', type: 'input', }]} />
<NodeParams id={node.id} params={[{ label: 'Host Port', field: 'mask-hostPort', type: 'input', }]} />
<NodeParams id={node.id} params={[{ label: 'Connection type', field: 'mask-connectionType', type: 'select', data: agentBusTypes }]} />
<div style={{ height: '30px' }} />
<p style={{ fontSize: "22px" }}>Handlers</p>
<NodeOutput id={node.id} type={'input'} label={'On Connect'} vars={[]} handleId={'mask-onConnect'} />
</Node>
)
}

export default {
id: 'agents.spawnAgent',
type: 'CallExpression',
category: "Agents",
keywords: ["Agents", "remote", "connection"],
check: (node, nodeData) => {
return node.type == "CallExpression" && nodeData.to?.startsWith('context.agents.spawnAgent')
},
getComponent: (node, nodeData, children) => <SpawnAgent node={node} nodeData={nodeData} children={children} />,
filterChildren: filterObject({
keys: {
agentName: 'input',
connectionType: 'input',
subsystems: 'input',
host: 'input',
hostPort: 'input',
onConnect: 'output',
}
}),
restoreChildren: restoreObject({
keys: {
agentName: 'input',
connectionType: 'input',
subsystems: 'input',
host: 'input',
hostPort: 'input',
onConnect: {
params: { 'mask-onConnect': {}, }
},
}
}),
getInitialData: () => {
return {
await: true,
to: 'context.agents.spawnAgent',
"mask-agentName": {
value: "",
kind: "StringLiteral"
},
"mask-subsystems": {
value: [],
kind: "Identifier"
},
"mask-host": {
value: "127.0.0.1",
kind: "StringLiteral"
},
"mask-hostPort": {
value: 1883,
kind: "Identifier"
},
}
}
}
5 changes: 4 additions & 1 deletion packages/protolib/src/bundles/agents/agents/masks/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
export default [
import SpawnAgent from "./SpawnAgent";

export const agentBusTypes = ["mqtt"]
export default [
SpawnAgent
];

0 comments on commit 3329c00

Please sign in to comment.