openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
44 lines (43 loc) • 1.51 kB
JavaScript
import { R as resolveTimerTimeoutMs } from "../number-coercion-D6u-4YD8.mjs";
import { d as sleepWithAbort } from "../src-BPmQBLJp.mjs";
import "../backoff-B-fIQi7C.mjs";
import { n as monotonicNow } from "../monotonic-time-Cc4T2fkU.mjs";
import { r as theme } from "../theme-BOI0xyRZ.mjs";
//#region src/plugin-sdk/transport-ready-runtime.ts
/** Polls until ready, timed out, or aborted, with bounded logging through the runtime sink. */
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"})`);
}
/**
* Lazy runtime SDK subpath for waiting until an outbound transport is ready.
*/
//#endregion
export { waitForTransportReady };