UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.67 kB
import{p as toErrorObject}from"./error-coercion-DlKnt6w-.mjs";import{o as racePromiseWithAbortSignal}from"./src-De06gkOi.mjs";import"./abort-signal-BKkRe6pu.mjs";import"./errors-D37BJTfI.mjs"; //!src/agents/embedded-agent-runner/run/abortable.ts const OPENCLAW_ABORTABLE_WRAPPER=Symbol.for(`openclaw.abortable.wrapper`);function isOpenClawAbortableWrapper(e){return e!==null&&typeof e===`object`&&OPENCLAW_ABORTABLE_WRAPPER in e}function createAbortableError(e){const t=e.reason;const n=new Error(t instanceof Error?t.message:`aborted`,t?{cause:t}:void 0);return Object.assign(n,{name:`AbortError`,[OPENCLAW_ABORTABLE_WRAPPER]:true})}const RUN_LIVENESS_JOIN_TIMEOUT_MS=12e4;function finishRunLivenessJoin(e){e.finish?.()}function joinWithRunLivenessDeadline(e){return new Promise(t=>{const finish=r=>{if(!n.finish)return;n.finish=void 0;clearTimeout(i);e.runAbortSignal?.removeEventListener(`abort`,onAbort);if(r===`timeout`)e.onTimeout();t()};const n={finish:()=>finish(`settled`)};const r=finishRunLivenessJoin.bind(void 0,n);const onAbort=()=>finish(`abort`);const i=setTimeout(()=>finish(`timeout`),e.timeoutMs??12e4);i.unref();if(e.runAbortSignal?.aborted){finish(`abort`);return}e.runAbortSignal?.addEventListener(`abort`,onAbort,{once:true});Promise.resolve().then(()=>e.joinWork()).then(r,r)})}function abortable(e,t){if(e.aborted){t.catch(()=>{});return Promise.reject(createAbortableError(e))}return racePromiseWithAbortSignal(()=>t.catch(e=>{throw toErrorObject(e,`Non-Error rejection`)}),e,createAbortableError)}export{joinWithRunLivenessDeadline as a,isOpenClawAbortableWrapper as i,abortable as n,createAbortableError as r,RUN_LIVENESS_JOIN_TIMEOUT_MS as t};