-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba459be
commit 3329c00
Showing
6 changed files
with
117 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
packages/protolib/src/bundles/agents/agents/context/CreateAgent.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
packages/protolib/src/bundles/agents/agents/context/spawnAgent.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
79
packages/protolib/src/bundles/agents/agents/masks/SpawnAgent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
]; |