openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.9 kB
JavaScript
import{t as formatErrorMessage}from"./errors-D37BJTfI.mjs";import{_ as getGatewayContextResolver}from"./gateway-request-scope-7deHmsb_.mjs";import{yt as getSessionControllerSourceIdentity}from"./session-controller.state-BIDbpLPn.mjs";import{a as getRpcSourceIdentity,r as getRpcSourceForGateway}from"./session-controller.rpc-sources-IDCkO6sT.mjs";import{i as captureSessionControllerStop,r as stopSession}from"./session-controller.stop-DE-wTVTx.mjs";import{n as notifySessionRunStopped}from"./session-run-stopped-DSkA0mof.mjs";import{r as createChatAbortSignalReason,t as abortChatRunById}from"./chat-abort-DTWUmwzL.mjs";import{t as abortControlledSubagents}from"./chat-abort-descendants-CfGWZ0QV.mjs";
//!src/gateway/server-methods/chat-abort-exact-run.ts
function captureSourceAssertion(e,t){const n=getSessionControllerSourceIdentity(e);return()=>{t?.();const r=getSessionControllerSourceIdentity(e);if(r.sessionKey!==n.sessionKey||r.sessionId!==n.sessionId||r.agentId!==n.agentId)throw new Error(`Run changed before cancellation; retry Stop.`)}}async function stopExactClientRun(e){const{ops:t,runId:n,active:r}=e;const i=captureSessionControllerStop({inputs:[r.input]});const{sessionKey:a,sessionId:o,agentId:s}=getRpcSourceIdentity(r);const c={aborted:false};const l=captureSourceAssertion(r.input,e.assertCurrent);const markAborted=()=>{if(!c.aborted){c.aborted=true;e.onAborted?.()}};const assertCurrent=()=>{l();const e=getRpcSourceForGateway(n,getGatewayContextResolver(r.input));if(e&&e!==r)throw new Error(`Run changed before cancellation; retry Stop.`)};try{await stopSession({source:`client-run`,capture:i,assertCurrent,reason:createChatAbortSignalReason(`rpc`,e.userInitiated),hookContext:{...e.hookContext,sessionKey:a,sessionId:o},afterParent:e.afterParent,continueChildStop:()=>c.aborted,onCancelled:e=>{if(e===r.input)markAborted()},cancelInput:(i,o)=>abortChatRunById(t,{runId:n,sessionKey:a,expectedEntry:r,cancel:o,assertCurrent,stopReason:`rpc`,pendingInputEndCause:e.stoppedSession&&r.adapter.kind===`chat-send`&&r.input.phase===`injecting`?`user-stop`:void 0,onAbortPrepared:()=>{if(e.stoppedSession)notifySessionRunStopped({source:`client-run`,sessions:[e.stoppedSession],runIds:[n]});return e.onAbortPrepared?.()},onAbortCommitted:markAborted}).aborted,stopChildren:async t=>{c.descendants=await abortControlledSubagents({cfg:e.cfg,sessionKey:a,agentId:s,requesterTurnRunId:n,sessionId:o,lifecycleRevision:e.lifecycleRevision,assertCurrent,beforeKill:t,parentStopAccepted:()=>c.aborted});return{stopped:c.descendants?.killed??0,failed:c.descendants?.status===`error`?c.descendants.failed:0}}}).completed}catch(e){if(c.aborted&&c.descendants?.status===`error`)c.descendants={...c.descendants,failed:c.descendants.failed+1,error:`${c.descendants.error}; ${formatErrorMessage(e)}`};else c.failure={error:e}}return c}export{stopExactClientRun as n,captureSourceAssertion as t};