eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 2.64 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`),a=new Set(e.reservedToolNames??[]),o=new Set(e.disabledToolNames??[]),s=new Map;for(let c of e.subagents){let e={logicalPath:c.logicalPath,sourceId:c.sourceId};if(s.has(c.nodeId))throw new RuntimeRegistryError(`subagent`,`Found multiple runtime subagents mapped to node id "${c.nodeId}".`,{...e,entryName:c.name});let l,u=c.kind===`subagent`?c.dynamic:void 0;if(u===void 0){let n=createPreparedRuntimeSubagentTool(c,SUBAGENT_TOOL_INPUT_JSON_SCHEMA);l={definition:c,prepared:n},i.register(c.name,l,{location:e,duplicateMessage:`Found multiple subagents named "${c.name}". Subagent names must be unique at runtime.`});let r=c.tool!==!1&&!o.has(c.name);if(r&&a.has(c.name))throw new RuntimeRegistryError(`subagent`,`Subagent "${c.name}" collides with another runtime-visible tool name.`,{...e,entryName:c.name});r&&t.push(n)}else n.add(c.nodeId),r.push({...u,kind:`subagent`,logicalPath:c.logicalPath,name:c.name,nodeId:c.nodeId,sourceId:c.sourceId,sourceKind:`module`,tool:!o.has(c.name)&&void 0}),l={definition:c};s.set(c.nodeId,l)}return{dynamicNodeIds:n,dynamicResolvers:r,preparedTools:t,subagentsByName:i.asMap(),subagentsByNodeId:s}}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,workflowId:subagentToolExecuteWorkflowReference.workflowId}}}export{createPreparedRuntimeSubagentTool,createRuntimeSubagentRegistry};