UNPKG

eve

Version:

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

1 lines 1.62 kB
import{createLogger,logError}from"#internal/logging.js";import{BundleKey}from"#runtime/sessions/runtime-context-keys.js";import{deserializeContext}from"#context/serialize.js";import{readDurableSession}from"#execution/durable-session-store.js";import{resolveEffectiveAgentRuntime}from"#execution/effective-agent-config.js";import{hydrateDurableSession}from"#execution/session.js";import{cancelOwnedTask}from"#execution/tasks/parent/dispatch.js";import{cancelBackgroundAgentTask}from"#execution/tools/subagent/task-cancel.js";import{getSessionTaskIndex}from"#tasks/session-index.js";const log=createLogger(`execution.cancel-indexed-session-tasks`);async function cancelAllIndexedSessionTasksStep(e){"use step";let t;try{t=await readDurableSession(e.sessionState)}catch(t){logError(log,`failed to read the session for indexed task cancellation`,t,{parentSessionId:e.sessionState.sessionId});return}let n;try{n=getSessionTaskIndex(t.state)}catch(e){logError(log,`failed to read the task index`,e,{parentSessionId:t.sessionId});return}if(n.length===0)return;if(e.serializedContext===void 0)throw Error(`Indexed task cancellation requires serialized runtime context.`);let r=await deserializeContext(e.serializedContext),i=r.require(BundleKey),a=resolveEffectiveAgentRuntime(i,r),o=hydrateDurableSession({durable:t,turnAgent:a.turnAgent});for(let r of n)try{await cancelOwnedTask({cancelOwnedWork:cancelBackgroundAgentTask,entry:r,serializedContext:e.serializedContext,session:o})}catch(e){logError(log,`failed to cancel indexed task`,e,{parentSessionId:t.sessionId,taskId:r.taskId})}}export{cancelAllIndexedSessionTasksStep};