openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.12 kB
JavaScript
import{R as resolveTimerTimeoutMs}from"../number-coercion-B3CfI447.mjs";import{d as sleepWithAbort}from"../src-De06gkOi.mjs";import{n as monotonicNow}from"../monotonic-time-DjtFTu2s.mjs";import"../backoff-DRW5tqzp.mjs";import{r as theme}from"../theme-DS2CtI9X.mjs";
//!src/plugin-sdk/transport-ready-runtime.ts
async function waitForTransportReady(e){const t=monotonicNow();const n=resolveTimerTimeoutMs(e.timeoutMs,0,0);const r=t+n;const i=resolveTimerTimeoutMs(e.logAfterMs,n,0);const a=resolveTimerTimeoutMs(e.logIntervalMs,3e4,1e3);const o=resolveTimerTimeoutMs(e.pollIntervalMs,150,50);let s=t+i;let c=null;const logNotReady=t=>e.runtime.error?.(theme.error(`${e.label} not ready after ${t}ms (${c??`unknown error`})`));while(true){if(e.abortSignal?.aborted)return;const n=await e.check();if(n.ok||e.abortSignal?.aborted)return;c=n.error??null;const i=monotonicNow();if(i>=r)break;if(i>=s){logNotReady(i-t);s=i+a}try{await sleepWithAbort(o,e.abortSignal)}catch(t){if(e.abortSignal?.aborted)return;throw t}}logNotReady(n);throw new Error(`${e.label} not ready (${c??`unknown error`})`)}export{waitForTransportReady};