UNPKG

eve

Version:

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

1 lines 1.23 kB
import{sleep}from"#compiled/@workflow/core/index.js";import{createWorkflowBodyRef,executeWorkflowBody}from"#execution/tools/workflow/body.js";import{resumeHookStep}from"#execution/tools/workflow/resume-hook-step.js";import{normalizeSerializableError}from"#execution/workflow-errors.js";import{openWorkflowToolRunControlInbox}from"#execution/tools/workflow/run-control.js";async function workflowToolRunWorkflow(e){"use workflow";let t=openWorkflowToolRunControlInbox(e.hookToken),n={...e,execution:e.execution??`blocking`},r=createWorkflowBodyRef(n),i=executeWorkflowBody(n,t.signal).then(({outcome:e})=>{if(e.status===`completed`)return e.output;throw e.status===`failed`?e.error:t.signal.reason??Error(e.reason??`Workflow tool run cancelled.`)}),a=i.catch(()=>{}),o;try{o={output:await Promise.race([i,t.cancelled]),status:`completed`}}catch(e){t.signal.aborted?(await Promise.race([a,sleep(`30s`)]),o={reason:t.reason(),status:`cancelled`}):o={error:normalizeSerializableError(e),status:`failed`}}let s={from:r,result:o};await resumeHookStep(e.owner.inbox,{kind:`outcome`,...s},{ifPresent:o.status===`cancelled`})}workflowToolRunWorkflow.workflowId=`workflow//eve//workflowToolRunWorkflow`;export{workflowToolRunWorkflow};