UNPKG

eve

Version:

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

1 lines 1.88 kB
import{z}from"#compiled/zod/index.js";import{defineWorkflowTool}from"#tools/workflow-definition.js";import{DEFAULT_WORKFLOW_PROGRAM_MAX_SUBAGENTS,parseWorkflowProgramOptions}from"#execution/dynamic-workflow/schema.js";import{attachWorkflowProgramOptions}from"#tools/workflow-program-input.js";import{executeWorkflowProgram}from"#execution/dynamic-workflow/tool.js";const workflowProgramAgentContract=`Call ctx.agent(name, { message: string, agentId?: string, outputSchema?: object }). It resolves directly to the child's JSON-serializable output; when outputSchema is provided, the output matches that schema. It does not return an agent metadata wrapper. Use an agentId from the conversation's <agents> block to continue that child. The owning agent resolves the target and applies its existing availability and authorization checks.`,workflowInputSchema=z.strictObject({js:z.string().describe(`JavaScript statements executed inside an async function. Supply only the body, without a surrounding function declaration or arrow function. ${workflowProgramAgentContract} Return one JSON-serializable value.`)});function workflow(e={}){let t=normalizeWorkflowToolOptions(e),n=[`Run an async JavaScript function body that invokes agents and returns one JSON-serializable value.`,workflowProgramAgentContract,`Supply the body directly, for example: return await ctx.agent("researcher", { message: "Describe the task" });`,`The program may invoke at most ${String(t.maxSubagents)} agents.`].join(` `);return attachWorkflowProgramOptions(defineWorkflowTool({description:n,execute:executeWorkflowProgram,inputSchema:workflowInputSchema}),t)}function normalizeWorkflowToolOptions(e){if(typeof e!=`object`||!e)throw TypeError(`workflow options must be an object.`);return parseWorkflowProgramOptions({maxSubagents:e.maxSubagents??DEFAULT_WORKFLOW_PROGRAM_MAX_SUBAGENTS})}export{workflow};