UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

1 lines 2.49 kB
import{serializeInputSchema,serializeOutputSchema}from"#tools/schema.js";import{ROOT_RUNTIME_AGENT_NODE_ID}from"#runtime/graph.js";import{AGENT_TOOL_NAME}from"#tools/framework/agent-contract.js";import{subagentToolExecuteWorkflowReference}from"#runtime/subagents/workflow-reference.js";import{RuntimeRegistry}from"#internal/runtime-registry.js";async function createRuntimeToolRegistry(e,t={}){let n=[],r=new RuntimeRegistry(`tool`,t.reservedToolNames??[]);for(let i of e.tools){let e=await createPreparedRuntimeTool(i,t.nodeId);r.register(i.name,{definition:i,prepared:e},{location:{logicalPath:i.logicalPath,sourceId:i.sourceId},duplicateMessage:`Found multiple authored tools named "${i.name}". Tool names must be unique at runtime.`,reservedMessage:`Tool "${i.name}" collides with another runtime-visible tool name.`}),n.push(e)}return{preparedTools:n,toolsByName:r.asMap()}}function findRegisteredRuntimeTool(e,t){return e.toolsByName.get(t)??null}async function createPreparedRuntimeTool(e,t){let n=e.behavior?.handling?.kind===`dispatch`&&e.behavior.handling.action===`self-agent`,r=n?subagentToolExecuteWorkflowReference.workflowId:e.behavior?.handling?.kind===`workflow-tool`?e.behavior.handling.workflowId:void 0;return{availableInSubagents:e.availableInSubagents,behavior:prepareToolBehavior(e.behavior,t,n?subagentToolExecuteWorkflowReference.workflowId:void 0),description:e.description,execution:e.execution,inputSchema:serializeInputSchema(e.inputSchema),kind:`authored-tool`,logicalPath:e.logicalPath,name:e.name,owner:e.owner,outputSchema:serializeOutputSchema(e.outputSchema),rootOnly:n||void 0,sourceId:e.sourceId,task:r===void 0?void 0:n?{nodeId:ROOT_RUNTIME_AGENT_NODE_ID,workflowId:r}:{workflowId:r}}}function prepareToolBehavior(e,t,n){if(e===void 0)return;let r;if(n!==void 0&&t!==void 0)r={kind:`dispatch`,target:{kind:`self-agent-call`,nodeId:t,subagentName:AGENT_TOOL_NAME}};else if(e.handling?.kind===`dispatch`){if(e.handling.action===`self-agent`&&t===void 0)throw Error(`The self-agent tool requires a concrete runtime node id.`);r={kind:`dispatch`,target:e.handling.action===`self-agent`?{kind:`self-agent-call`,nodeId:t,subagentName:AGENT_TOOL_NAME}:{kind:e.handling.action}}}else r=e.handling?.kind===`workflow-tool`?{kind:`dispatch`,target:{kind:`workflow-tool-call`,workflowId:n??e.handling.workflowId}}:e.handling;return{availability:e.availability,handling:r,presentation:e.presentation}}export{createRuntimeToolRegistry,findRegisteredRuntimeTool};