eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 2 kB
JavaScript
import{createLogger,logError}from"#internal/logging.js";import{isObject}from"#shared/guards.js";import{walkCauseChain}from"#shared/errors.js";import{cancelRun,getWorld}from"#internal/workflow/runtime.js";import{EntityConflictError,RunExpiredError,WorkflowRunNotFoundError}from"#compiled/@workflow/errors/index.js";import{terminateChildSessionsStep}from"#execution/terminate-child-sessions-step.js";import{settleCancelledTurnStep}from"#execution/settle-cancelled-turn-step.js";async function interruptLegacySessionStep(e){"use step";let t={...e.sessionState,snapshot:{session:{...e.originalSession,history:e.sessionState.snapshot.session.history}}};try{await terminateChildSessionsStep({sessionState:t,serializedContext:e.serializedContext})}catch(e){logError(createLogger(`execution.legacy-session`),`could not cooperatively stop legacy children`,e)}let n=await getWorld(),r=e.originalSession.state,i=new Set,a=r?.[`eve.runtime.workflowToolRuns`];if(Array.isArray(a))for(let e of a)isObject(e)&&typeof e.runId==`string`&&i.add(e.runId);let o=r?.[`eve.agent.handles`];if(isObject(o)&&Array.isArray(o.handles))for(let e of o.handles)isObject(e)&&isObject(e.address)&&(e.address.kind===`agent/local`||e.address.kind===`agent/self`)&&typeof e.address.sessionId==`string`&&i.add(e.address.sessionId);let s=r?.[`eve.tasks`];if(isObject(s)&&Array.isArray(s.tasks))for(let e of s.tasks)isObject(e)&&typeof e.taskRunId==`string`&&i.add(e.taskRunId);for(let t of i)if(t&&t!==e.sessionState.sessionId)try{await cancelRun(n,t,{cancelReason:`Session upgraded`})}catch(e){if(![...walkCauseChain(e)].some(e=>EntityConflictError.is(e)||RunExpiredError.is(e)||WorkflowRunNotFoundError.is(e)))throw e}return e.input.inputCommitted||e.sessionState.emissionState.turnId===``?{sessionState:e.sessionState,serializedContext:e.serializedContext}:await settleCancelledTurnStep({sessionWritable:e.input.sessionWritable,serializedContext:e.serializedContext,sessionState:e.sessionState})}export{interruptLegacySessionStep};