UNPKG

eve

Version:

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

2 lines 2.2 kB
import{z}from"#compiled/zod/index.js";import{DEFAULT_WORKFLOW_MAX_SUBAGENTS}from"#harness/workflow-subagent-limit.js";import{WORKFLOW_TASK_INTERRUPT_KIND}from"#harness/workflow-task-state.js";import{WORKFLOW_TOOL_NAME,createWorkflowSandboxTool,readWorkflowSandboxResolution,requestWorkflowSandboxInterrupt}from"#shared/workflow-sandbox.js";import{workflowToolDescription}from"#harness/workflow-tool-description.js";const workflowInputSchema=z.strictObject({js:z.string().describe(`Complete JavaScript orchestration program. Call only the agents listed in the Workflow description and return one JSON-serializable result.`)});async function applyWorkflowTool(e){let t=createWorkflowHostTools(e.harnessTools,Object.keys(e.tools));if(Object.keys(t).length===0)return{hostTools:t,modelTools:e.tools};let n=await createWorkflowSandboxTool({bridgeRequestLimit:resolveWorkflowSandboxBridgeRequestLimit(e.maxSubagents),continuationSecurity:e.continuationSecurity,hostTools:t}),r=typeof n.description==`string`?n.description:``,i=workflowToolDescription(Object.keys(t),{maxSubagents:e.maxSubagents}),a=workflowApiReference(r),o={...e.tools};return o[WORKFLOW_TOOL_NAME]={...n,description:a.length>0?`${i}\n\n${a}`:i,inputSchema:workflowInputSchema},{hostTools:t,modelTools:o}}function resolveWorkflowSandboxBridgeRequestLimit(e){return Math.max(256,(e??DEFAULT_WORKFLOW_MAX_SUBAGENTS)+1)}function workflowApiReference(e){let t=e.indexOf(`Tools: `);return t<0?e:`Available agent API:\n${e.slice(t+7)}`}function buildWorkflowHostTools(e){return createWorkflowHostTools(e.tools,e.tools.keys())}function createWorkflowHostTools(e,t){let n={};for(let r of t){let t=e.get(r);t?.workflowId!==void 0&&(n[r]=createWorkflowTaskHostTool(t))}return n}function createWorkflowTaskHostTool(e){return{description:e.description,inputSchema:e.inputSchema,execute:async(t,n)=>{let r=readWorkflowSandboxResolution(n);return r===void 0?requestWorkflowSandboxInterrupt({kind:WORKFLOW_TASK_INTERRUPT_KIND,task:{executeInput:e.executeInput?.(t),nodeId:e.nodeId,resultKind:e.resultKind,workflowId:e.workflowId},toolInput:t,toolName:e.name}):r}}}export{applyWorkflowTool,buildWorkflowHostTools,resolveWorkflowSandboxBridgeRequestLimit};