openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.91 kB
JavaScript
import{o as writeRuntimeJson}from"./runtime-DIcLIHcp.mjs";import{n as sanitizeTerminalText}from"./safe-text-B_QTgn0s.mjs";import{t as GatewayClientRequestError}from"./request-error-DCrb--_5.mjs";import{t as GatewayTransportError}from"./transport-error-COMVGbZH.mjs";import"./client-BH-Snzbs.mjs";import{n as buildGatewayProbeConnectionDetails}from"./call-CVqWsTxX.mjs";import{r as DEFAULT_RESTART_HEALTH_TIMEOUT_MS}from"./restart-health.constants-BS7LeiAV.mjs";import{t as waitForGatewayDiagnosticReadiness}from"./diagnostic-readiness-DoWRBYaK.mjs";
//!src/commands/gateway-diagnostic-readiness.ts
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&&!e.signal?.aborted)t.log(`Gateway is still starting (phase: ${sanitizeTerminalText(n)}).`)}});e.signal?.throwIfAborted();if(a?.waitOutcome===`connected-no-operator-scope`)throw new GatewayClientRequestError({code:`FORBIDDEN`,message:a.operatorScopeWarning,details:{code:`MISSING_SCOPE`,missingScope:`operator.read`,requiredScopes:[`operator.read`]}});const o=Math.max(0,Math.ceil(i-performance.now()));if(o>0&&(!a||a.healthy||a.waitOutcome===`channel-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.`})}export{waitForGatewayDiagnostic as t};