UNPKG

eve

Version:

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

1 lines 1.43 kB
import{createLogger,logError}from"#internal/logging.js";import{toError}from"#shared/errors.js";import{startWorkflowOnCurrentDeployment,workflowToolRunWorkflowReference}from"#execution/workflow-runtime.js";import{recordWorkflowToolRun}from"#harness/workflow-tool-runs.js";import{createRuntimeToolResultFromValue}from"#harness/action-result-helpers.js";const log=createLogger(`execution.workflow-tool-run`);async function startWorkflowToolRun(e){let t=crypto.randomUUID();return{hookToken:t,runId:(await startWorkflowOnCurrentDeployment(workflowToolRunWorkflowReference,[{...e,hookToken:t}])).runId}}async function startWorkflowTask(e){let{task:t,batchEvent:n,session:r}=e;try{let i=await startWorkflowToolRun({callId:t.callId,executeInput:t.executeInput,input:t.input,owner:e.owner,resultKind:t.resultKind,session:{auth:{current:e.auth,initiator:e.initiatorAuth},id:r.sessionId,parent:e.parentSession,turn:{id:n.turnId,sequence:n.sequence}},stepIndex:n.stepIndex,toolName:t.toolName,workflowId:t.workflowId});return{session:recordWorkflowToolRun(r,{callId:t.callId,hookToken:i.hookToken,resultKind:t.resultKind??`tool`,runId:i.runId,toolName:t.toolName})}}catch(e){return logError(log,`workflow tool run failed to start`,e,{callId:t.callId,toolName:t.toolName}),{result:createRuntimeToolResultFromValue({callId:t.callId,isError:!0,output:toError(e),toolName:t.toolName}),session:r}}}export{startWorkflowTask,startWorkflowToolRun};