UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

118 lines (117 loc) • 4.86 kB
import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs"; import { c as prepareChildRuntimeViability } from "./child-runtime-viability-DFyU3D5D.mjs"; import { n as getSessionRowProjection } from "./session-row-projection-access-CjLImwLs.mjs"; import { r as HEALTH_REFRESH_INTERVAL_MS } from "./server-constants-CYohpfLc.mjs"; import { t as getPreparedModelRuntimeStartupStatus } from "./prepared-model-runtime.startup-status-CN_Wlrr3.mjs"; import { n as readGatewayMaintenanceWork } from "./gateway-active-work-2EmwaczJ.mjs"; import { r as getGatewayRecentCrashes } from "./gateway-crash-D22VnCOp.mjs"; import { r as respondUnavailableOnThrow } from "./response-C7fEiIN1.mjs"; import { n as readGatewayProcessVitals, r as readGatewayWorkerPoolFacts } from "./process-vitals-dDZiP3Lo.mjs"; import { t as prepareStatusSummary } from "./summary-DCAuDto8.mjs"; import { r as buildContextEngineHealthSummary, t as buildDeliveryQueueHealthSummary } from "./delivery-queue-CQ5qiz5A.mjs"; import { t as createGatewayServerActiveWorkInspectors } from "./server-active-work-34ARBisE.mjs"; import { t as shouldScheduleBackgroundHealthRefresh } from "./health-refresh-admission-GCeg0zv6.mjs"; //#region src/gateway/server-methods/health.ts const ADMIN_SCOPE = "operator.admin"; function cachedLifecycleDiffersFromRuntime(e, t) { return [ "running", "connected", "lifecycle" ].some((n) => t[n] !== void 0 && e?.[n] !== t[n]); } function cachedHealthDiffersFromRuntime(e, t) { return Object.entries(t.channels).some(([t, n]) => n && cachedLifecycleDiffersFromRuntime(e.channels[t], n)) || Object.entries(t.channelAccounts).some(([t, n]) => { if (!n) return false; const r = e.channels[t]?.accounts; return Object.entries(n).some(([e, t]) => t && cachedLifecycleDiffersFromRuntime(r?.[e], t)); }); } const healthHandlers = { health: async ({ respond: e, context: t, params: n, client: r }) => { const { getHealthCache: i, refreshHealthSnapshot: a, logHealth: o } = t; const s = n?.probe === true; const c = r?.connect.scopes?.includes(ADMIN_SCOPE) ?? false; const l = Date.now(); const u = i(); let d = false; if (!s && u) try { d = cachedHealthDiffersFromRuntime(u, t.getRuntimeSnapshot()); } catch { d = true; } if (!s && u && !d && l - u.ts < 6e4) { const n = t.getEventLoopHealth; const r = t.getConfigReloaderHotReloadStatus?.(); const { contextEngines: i, deliveryQueues: s, eventLoop: d, ...f } = u; const p = await buildDeliveryQueueHealthSummary(); const m = await buildContextEngineHealthSummary(); const h = (await prepareChildRuntimeViability()).publish(); const g = n?.(); e(true, { ...f, coreReady: t.getReadiness?.(h).coreReady, modelRuntime: getPreparedModelRuntimeStartupStatus(), ...g ? { eventLoop: g } : {}, ...m ? { contextEngines: m } : {}, ...p ? { deliveryQueues: p } : {}, ...r ? { configReload: { hotReloadStatus: r } } : {}, childRuntime: h, recentCrashes: getGatewayRecentCrashes() }, void 0, { cached: true }); if (shouldScheduleBackgroundHealthRefresh(a, l)) a({ probe: false, includeSensitive: c }).catch((e) => o.error(`background health refresh failed: ${formatErrorMessage(e)}`)); return; } await respondUnavailableOnThrow(e, async () => { const n = await a({ probe: s, includeSensitive: c }); const r = (await prepareChildRuntimeViability()).publish(); e(true, { ...n, coreReady: t.getReadiness?.(r).coreReady, modelRuntime: getPreparedModelRuntimeStartupStatus(), childRuntime: r, recentCrashes: getGatewayRecentCrashes() }, void 0); }); }, status: async ({ respond: e, client: t, params: n, context: r }) => { const i = t?.connect.scopes ?? []; const a = await r.hostDesktopService?.status(); const o = await prepareStatusSummary({ includeSensitive: i.includes(ADMIN_SCOPE), includeChannelSummary: n.includeChannelSummary !== false, includeCliProjection: n.includeCliProjection === true, sessionRowProjection: getSessionRowProjection(r), ...a ? { hostDesktopStatus: a } : {} }); const s = await readGatewayWorkerPoolFacts(); const c = await prepareChildRuntimeViability(); const l = o.publish().summary; const u = r.hostLifecycle?.getShutdownBudget?.(); const d = u ? readGatewayMaintenanceWork(createGatewayServerActiveWorkInspectors(r)) : void 0; const f = u && d ? { ...u, activeWork: d.counts, writeCustody: d.writeCustody } : void 0; e(true, { ...l, modelRuntime: getPreparedModelRuntimeStartupStatus(), ...readGatewayProcessVitals(r.getEventLoopHealth), workerPools: s, pid: process.pid, shutdownBudget: f, childRuntime: c.publish(), recentCrashes: getGatewayRecentCrashes(), pluginReload: r.getPluginReloadStatus?.() }, void 0); } }; //#endregion export { healthHandlers };