openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
38 lines (37 loc) • 1.84 kB
JavaScript
import { o as writeRuntimeJson } from "./runtime-B-SLYP-m.mjs";
import { n as sanitizeTerminalText } from "./safe-text-C80HAQ2e.mjs";
import { t as GatewayTransportError } from "./transport-error-BL_kuysc.mjs";
import { n as buildGatewayProbeConnectionDetails } from "./call-DVCK1deJ.mjs";
import { r as DEFAULT_RESTART_HEALTH_TIMEOUT_MS } from "./restart-health.constants-BJKsCEH8.mjs";
import { t as waitForGatewayDiagnosticReadiness } from "./diagnostic-readiness-DbThzGUe.mjs";
//#region src/commands/gateway-diagnostic-readiness.ts
/** Keep startup progress separate from terminal diagnostic failure. */
async function waitForGatewayDiagnostic(e, t) {
const n = e.timeoutMs ?? DEFAULT_RESTART_HEALTH_TIMEOUT_MS;
const r = performance.now();
const i = Math.min(e.deadlineMs ?? Infinity, r + n);
const a = await waitForGatewayDiagnosticReadiness({
...e,
deadlineMs: i,
onProgress: (n) => {
if (!e.json) t.log(`Gateway is still starting (phase: ${sanitizeTerminalText(n)}).`);
}
});
const o = Math.max(0, Math.ceil(i - performance.now()));
if (o > 0 && (!a || a.healthy || a.waitOutcome === "channel-errors" || a.waitOutcome === "plugin-errors")) return o;
if (a?.waitOutcome === "still-starting") {
if (e.json) writeRuntimeJson(t, {
status: "starting",
startupPhase: a.startupPhase
});
return;
}
throw new GatewayTransportError({
kind: "timeout",
timeoutMs: n,
connectionDetails: await buildGatewayProbeConnectionDetails(e),
message: `${!a || a.healthy ? "Gateway diagnostic budget exhausted" : "Gateway not reachable"} after waiting ${Math.round((performance.now() - r) / 1e3)} s.\n${sanitizeTerminalText(a?.probeError ?? a?.startupPhase ?? "Readiness could not be confirmed.")}\nRun openclaw gateway status --deep to diagnose.`
});
}
//#endregion
export { waitForGatewayDiagnostic as t };