UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

110 lines (109 loc) • 4.78 kB
import { r as resolveStateDir } from "./state-dir-DiG0gXzD.mjs"; import { r as parseTcpPortFromArgs } from "./tcp-port-CuNPxuH-.mjs"; import { b as resolveGatewayPort, m as resolveConfigPath, o as isDefaultInstallIdentity } from "./paths-DAcAg5aV.mjs"; import { r as readGatewayOwnerLease } from "./gateway-owner-lease-I0ETcEQK.mjs"; import { f as withCommandProcessScope } from "./exec-spawn-DMKoejF-.mjs"; import { o as readActiveGatewayLockIdentity } from "./gateway-lock-IYOwJQai.mjs"; import { t as mergeGatewayServiceEnv } from "./service-env-merge-994N__ny.mjs"; import { f as isImplicitLocalGatewayTarget } from "./call-DVCK1deJ.mjs"; import { n as resolveGatewayService } from "./service-hQiIzcTo.mjs"; import { t as LOOPBACK_PORT_PROBE_HOSTS } from "./ports-probe-DVN9Sc3E.mjs"; import { n as createGatewayRestartDeadline } from "./restart-health-deadline-C9ASZjXK.mjs"; import { r as DEFAULT_RESTART_HEALTH_TIMEOUT_MS } from "./restart-health.constants-BJKsCEH8.mjs"; import { r as resolveGatewayProbeAuthSafeWithSecretInputs } from "./probe-auth-CWenh0cl.mjs"; import { a as resolveGatewayRestartProbeContext } from "./restart-health-probe-CQiYaScK.mjs"; import { n as waitForGatewayHealthyRestart } from "./restart-health-C1P8c-k3.mjs"; //#region src/cli/daemon-cli/diagnostic-readiness.ts /** Returns undefined when the original diagnostic path should probe without a startup wait. */ async function waitForGatewayDiagnosticReadiness(e) { if (!await isImplicitLocalGatewayTarget(e)) return; const t = e.config ? { config: e.config, auth: (await resolveGatewayProbeAuthSafeWithSecretInputs({ cfg: e.config, mode: "local", explicitAuth: { token: e.token, password: e.password } })).auth } : await resolveGatewayRestartProbeContext(process.env, { token: e.token, password: e.password }); if (!t.auth?.token && !t.auth?.password && t.config.gateway?.auth?.mode !== "none") return; const n = e.localPortOverride ?? resolveGatewayPort(t.config); const r = resolveGatewayService(); const i = e.serviceMode !== "external" && isDefaultInstallIdentity(process.env); let a; let o = false; const s = createGatewayRestartDeadline({ timeoutMs: Math.max(0, Math.min(e.timeoutMs ?? DEFAULT_RESTART_HEALTH_TIMEOUT_MS, e.deadlineMs === void 0 ? Infinity : e.deadlineMs - performance.now())) }); try { const c = await withCommandProcessScope(() => waitForGatewayHealthyRestart({ port: n, timeoutMs: e.timeoutMs ?? DEFAULT_RESTART_HEALTH_TIMEOUT_MS, deadline: s, deadlineOutcome: "snapshot", probeContext: t, probeHosts: LOOPBACK_PORT_PROBE_HOSTS, requirePluginHealth: false, allowUnattributedDiagnosticProbe: true, waitForMissingService: false, onProgress: e.onProgress, service: { readCommand: async () => null, readRuntime: async (c, l) => { const u = await s.read("diagnostic:owner", async () => readGatewayOwnerLease({ env: c, port: n })); if (u?.state === "live" && (e.serviceMode === "external" || u.mode === "foreground" || u.supervisor?.kind === "external")) return { status: "running", pid: u.pid }; const remainingReadOptions = () => ({ ...l, timeoutMs: Math.max(1, Math.min(l?.timeoutMs ?? Infinity, s.remainingMs())) }); const d = !i ? null : await (a ??= (async () => { o = await s.read("diagnostic:service-absence", async () => r.isAbsent?.({ env: c, timeoutMs: remainingReadOptions().timeoutMs })) === true; s.signal.throwIfAborted(); return o ? null : s.read("diagnostic:service-command", () => r.readCommand(c, { ...remainingReadOptions(), requireEffective: true })); })()); s.signal.throwIfAborted(); const readNativeRuntime = () => s.read("diagnostic:native-runtime", () => r.readRuntime(c, remainingReadOptions())); const f = mergeGatewayServiceEnv(c, d); const p = parseTcpPortFromArgs(d?.programArguments) ?? resolveGatewayPort(t.config, f); if (!d || p !== n || resolveStateDir(f) !== resolveStateDir(c) || resolveConfigPath(f) !== resolveConfigPath(c)) { const e = await s.read("diagnostic:legacy-owner", () => readActiveGatewayLockIdentity({ env: c, requireInspection: true, timeoutMs: s.remainingMs(), signal: s.signal })); if (e?.port === n) return { status: "running", pid: e.pid }; return !i || o || d !== null ? { status: "unknown", missingUnit: true } : readNativeRuntime(); } return readNativeRuntime(); } } }), s.signal); return c.waitOutcome === "stopped-free" && c.runtime.missingUnit ? void 0 : c; } finally { s.dispose(); } } //#endregion export { waitForGatewayDiagnosticReadiness as t };