eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 2.48 kB
JavaScript
import{serializeInputSchema,serializeOutputSchema}from"#tools/schema.js";import{SUBAGENT_TASK_RECEIPT_OUTPUT_SCHEMA}from"#tools/framework/task-contract.js";import{SUBAGENT_TOOL_INPUT_SCHEMA}from"#tools/framework/agent-contract.js";import{subagentToolExecuteWorkflowReference}from"#runtime/subagents/workflow-reference.js";import{RuntimeRegistry,RuntimeRegistryError}from"#internal/runtime-registry.js";const SUBAGENT_TOOL_INPUT_JSON_SCHEMA=serializeInputSchema(SUBAGENT_TOOL_INPUT_SCHEMA),SUBAGENT_TOOL_OUTPUT_JSON_SCHEMA=serializeOutputSchema(SUBAGENT_TASK_RECEIPT_OUTPUT_SCHEMA);function createRuntimeSubagentRegistry(e){let t=[],n=new Set,r=[],i=new RuntimeRegistry(`subagent`,e.reservedToolNames??[]),a=new Map;for(let o of e.subagents){let e={logicalPath:o.logicalPath,sourceId:o.sourceId};if(a.has(o.nodeId))throw new RuntimeRegistryError(`subagent`,`Found multiple runtime subagents mapped to node id "${o.nodeId}".`,{...e,entryName:o.name});let s,c=o.kind===`subagent`?o.dynamic:void 0;if(c===void 0){let n=createPreparedRuntimeSubagentTool(o,SUBAGENT_TOOL_INPUT_JSON_SCHEMA);s={definition:o,prepared:n},i.register(o.name,s,{location:e,duplicateMessage:`Found multiple subagents named "${o.name}". Subagent names must be unique at runtime.`,reservedMessage:`Subagent "${o.name}" collides with another runtime-visible tool name.`}),t.push(n)}else n.add(o.nodeId),r.push({...c,kind:`subagent`,logicalPath:o.logicalPath,name:o.name,nodeId:o.nodeId,sourceId:o.sourceId,sourceKind:`module`}),s={definition:o};a.set(o.nodeId,s)}return{dynamicNodeIds:n,dynamicResolvers:r,preparedTools:t,subagentsByName:i.asMap(),subagentsByNodeId:a}}function createPreparedRuntimeSubagentTool(e,t=SUBAGENT_TOOL_INPUT_JSON_SCHEMA){if(e.description===void 0)throw Error(`Static subagent "${e.name}" is missing a description.`);return{behavior:{availability:[],handling:{kind:`dispatch`,target:e.kind===`remote`?{kind:`remote-agent-call`,nodeId:e.nodeId,remoteAgentName:e.name}:{kind:`subagent-call`,nodeId:e.nodeId,subagentName:e.name}}},description:`${e.description}\n\nThis call starts a background task and returns a task receipt immediately.`,execution:`background`,inputSchema:t,kind:e.kind,logicalPath:e.logicalPath,name:e.name,nodeId:e.nodeId,outputSchema:SUBAGENT_TOOL_OUTPUT_JSON_SCHEMA,sourceId:e.sourceId,task:{nodeId:e.nodeId,resultKind:`subagent`,workflowId:subagentToolExecuteWorkflowReference.workflowId}}}export{createPreparedRuntimeSubagentTool,createRuntimeSubagentRegistry};