eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 1.53 kB
JavaScript
import{createActionResultEvent,createActionsRequestedEvent}from"#protocol/message.js";import{createRuntimeToolResultFromValue}from"#harness/action-result-helpers.js";import{collectActionPresentation,createPresentedRuntimeActionRequestFromToolCall}from"#harness/action-presentation.js";import{getWorkflowSandboxInterrupt}from"#shared/workflow-sandbox.js";function createWorkflowLifecycle(e){return{async onAfterExecute(t){if(e.skipReplayed)return;let n=await getWorkflowSandboxInterrupt(t.result,{});n!==void 0&&await emitWorkflowActionsRequested({emit:e.emit,emissionState:e.emissionState,interrupts:[n],tools:e.tools})}}}async function emitWorkflowActionsRequested(e){for(let t of e.interrupts){let n={input:t.input,toolCallId:t.toolCallId,toolName:t.toolName,type:`tool-call`},r=createPresentedRuntimeActionRequestFromToolCall({toolCall:n,tools:e.tools});await e.emit(createActionsRequestedEvent({actions:[r.action],presentation:collectActionPresentation([r]),sequence:e.emissionState.sequence,stepIndex:e.emissionState.stepIndex,turnId:e.emissionState.turnId}))}}async function emitWorkflowActionResults(e){for(let[t,n]of e.results.entries()){let r=e.interrupts[t];if(r===void 0)break;await e.emit(createActionResultEvent({result:createRuntimeToolResultFromValue({callId:r.toolCallId,isError:n.isError,output:n.output,toolName:r.toolName}),sequence:e.emissionState.sequence,stepIndex:e.emissionState.stepIndex,turnId:e.emissionState.turnId}))}}export{createWorkflowLifecycle,emitWorkflowActionResults,emitWorkflowActionsRequested};