UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

347 lines (346 loc) • 13.5 kB
import { n as isNodeRuntime } from "./runtime-binary-QwVVJ9cA.mjs"; import { l as formatUnsupportedNodeVersionMessage } from "./node-version-CYJ7qOPD.mjs"; import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs"; import { p as tryResolveSoleAgentId } from "./agent-roster-t1ooUdXp.mjs"; import { n as resolveOpenClawPackageRoot } from "./openclaw-root-C-ayo09z.mjs"; import "./agent-scope-BwB8YH6y.mjs"; import { l as summarizeGatewayServiceLayout } from "./service-layout-C5OySMEw.mjs"; import { r as getSystemdCgroupHygieneSummary } from "./service-runtime-BHR12N-P.mjs"; import { n as readInstallOwner, t as formatInstallOwnerMessage } from "./install-owner-DDPQXcjQ.mjs"; import { o as resolveNodeRuntimeInfo } from "./runtime-paths-xW9-a89Z.mjs"; import { n as resolveGatewayService } from "./service-hQiIzcTo.mjs"; import { t as readGatewayServiceState } from "./service-state-uYnG1mTd.mjs"; import { n as inspectLocalAudioSelection, t as formatLocalAudioSelection } from "./local-audio-DAd8cxxM.mjs"; import { n as buildWorkspaceSkillStatus } from "./status-C6DUmZEt.mjs"; import { l as shouldManageGatewayService } from "./doctor-service-repair-policy-DAuL0W8-.mjs"; import { t as collectUnavailableAgentSkills } from "./doctor-skills-core-3U8Csb15.mjs"; //#region src/flows/doctor-core-checks.runtime.ts const PROVIDER_CATALOG_ORDERS = [ "simple", "profile", "paired", "late" ]; const PROVIDER_CATALOG_ORDER_SET = new Set(PROVIDER_CATALOG_ORDERS); function detectUnavailableSkills(e, t) { const n = buildWorkspaceSkillStatus(t, { config: e, agentId: tryResolveSoleAgentId(e) }); return collectUnavailableAgentSkills(n); } async function collectLocalAudioAccelerationFindings() { const e = await inspectLocalAudioSelection(); const t = e.candidates.filter((e) => e.available); if (t.length === 0) return []; const n = formatLocalAudioSelection(e); if (n) return [{ checkId: "core/doctor/local-audio-acceleration", severity: "info", message: `Local STT auto-selection: ${n}.`, path: "tools.media.models" }]; return [{ checkId: "core/doctor/local-audio-acceleration", severity: "info", message: `Local STT commands were found but none are ready for auto-selection: ${t.map((e) => `${e.command}: ${e.reason}`).join("; ")}.`, path: "tools.media.models", fixHint: "Install the matching local model/runtime, or configure an audio-capable tools.media.models CLI entry." }]; } async function collectGatewayDaemonFindings(e) { if (e.cfg.gateway?.mode === "remote" || !await shouldManageGatewayService()) return []; const t = resolveGatewayService(); const n = await readGatewayServiceState(t, { env: process.env }); const r = await summarizeGatewayServiceLayout(n.command); const i = await readInstallOwner(r?.packageRootReal ?? r?.packageRoot ?? null); const a = i ? formatInstallOwnerMessage(i) : void 0; const o = []; const warn = (e, r, i = n.command?.sourcePath) => { o.push({ checkId: "core/doctor/gateway-daemon", severity: "warning", message: e, path: i, target: t.label, fixHint: r }); }; if (n.loadState.status === "unknown") { warn(`Gateway service status could not be determined: ${n.loadState.detail}`, a ?? t.unsupportedReason ?? "Run `openclaw gateway status --deep`, restore service-manager access, and retry."); return o; } if (!n.installed) { const e = await readInstallOwner(await resolveOpenClawPackageRoot({ moduleUrl: import.meta.url, argv1: process.argv[1] })); if (e) return [{ checkId: "core/doctor/gateway-daemon", severity: "info", message: formatInstallOwnerMessage(e), target: e.displayName }]; warn("Gateway service is not installed.", "Run `openclaw gateway install` to install the service.", "gateway.mode"); return o; } const s = n.command?.programArguments[0]; if (s && isNodeRuntime(s)) { const e = await resolveNodeRuntimeInfo(s, n.env); const t = e.status === "probe-failed" ? e.error.message : e.capabilityError; if (t) o.push({ checkId: "core/doctor/gateway-daemon", severity: e.status === "supported" ? "info" : "warning", message: t, path: n.command?.sourcePath, target: s, ...e.status !== "supported" ? { fixHint: a ?? [...e.status === "unsupported" ? [formatUnsupportedNodeVersionMessage(e.version)] : [], "Repair the Node runtime, then run `openclaw gateway install`."].join("\n") } : {} }); } if (n.loadState.status === "not-loaded") warn("Gateway service is installed but not loaded.", a ?? "Start the installed service with `openclaw gateway start`."); const c = n.runtime; const l = c?.status ?? c?.state ?? c?.subState; if (n.loadState.status === "loaded" && !n.running) warn(l ? `Gateway service runtime is ${l}, not running.` : "Gateway service is loaded but runtime status could not confirm it is running.", "Run `openclaw gateway status --deep` to inspect the service before choosing a recovery action."); if (n.runtime?.missingGuiSession) warn("Gateway service cannot attach to the user GUI session.", n.runtime.detail ?? "Log into a GUI session, then rerun doctor."); if (n.runtime?.missingUnit) warn("Gateway service supervision metadata is missing.", a ?? n.runtime.detail ?? "Reinstall or reload the Gateway service."); const u = getSystemdCgroupHygieneSummary(n.runtime?.systemd); if (u) warn(`Gateway systemd service has risky ${u}.`, "Repair the systemd unit so stale child processes are cleaned up reliably."); return o; } function providerCatalogProjectionFinding(e, t, n) { const r = e.pluginId ? `plugins.entries.${e.pluginId}` : void 0; return { checkId: "core/doctor/provider-catalog-projection", severity: "error", message: t, ...r ? { path: r } : {}, target: e.providerId, requirement: formatErrorMessage(n), fixHint: "Fix the plugin provider catalog hook or disable the plugin, then rerun doctor before relying on model discovery." }; } function isReadableRecord(e) { return e !== null && typeof e === "object"; } function isTrimmedNonEmptyString(e) { return typeof e === "string" && e.trim() === e && e.length > 0; } function groupProviderCatalogsForDoctor(e) { const t = []; const n = { simple: [], profile: [], paired: [], late: [] }; for (const r of e) { let e = "late"; try { const n = r.staticCatalog?.order ?? "late"; if (PROVIDER_CATALOG_ORDER_SET.has(n)) e = n; else t.push(providerCatalogProjectionFinding({ providerId: r.id, pluginId: r.pluginId }, `Provider catalog ${r.id} order is invalid during doctor validation.`, /* @__PURE__ */ new Error("order must be simple, profile, paired, or late"))); } catch (e) { t.push(providerCatalogProjectionFinding({ providerId: r.id, pluginId: r.pluginId }, `Provider catalog ${r.id} order cannot be read during doctor validation.`, e)); } n[e].push(r); } for (const e of PROVIDER_CATALOG_ORDERS) n[e].sort((e, t) => e.label.localeCompare(t.label)); return { findings: t, byOrder: n }; } async function collectProviderCatalogProjectionFindings(e, t) { const { runProviderStaticCatalog: n } = await import("./provider-discovery-CXs0EN_-.mjs"); const { resolvePluginProvidersCore: r } = await import("./providers.runtime.js"); const i = process.env; let a; try { a = r({ config: e, workspaceDir: t, env: i, includeUntrustedWorkspacePlugins: false }); } catch (e) { return [{ checkId: "core/doctor/provider-catalog-projection", severity: "error", message: "Provider catalog hooks could not be loaded for doctor validation.", requirement: formatErrorMessage(e), fixHint: "Fix plugin provider discovery loading, then rerun doctor." }]; } const o = []; const s = groupProviderCatalogsForDoctor(a); o.push(...s.findings); for (const e of PROVIDER_CATALOG_ORDERS) for (const t of s.byOrder[e]) { let e; let r; try { e = t.staticCatalog; r = isReadableRecord(e) ? e.run : void 0; } catch (e) { o.push(providerCatalogProjectionFinding({ providerId: t.id, pluginId: t.pluginId }, `Provider catalog ${t.id} static catalog hook cannot be read during doctor validation.`, e)); continue; } if (e === void 0) continue; if (typeof r !== "function") { o.push(providerCatalogProjectionFinding({ providerId: t.id, pluginId: t.pluginId }, `Provider catalog ${t.id} static catalog hook is invalid during doctor validation.`, /* @__PURE__ */ new Error("static catalog run must be a function"))); continue; } let i; try { i = await n({ provider: t }); } catch (e) { o.push(providerCatalogProjectionFinding({ providerId: t.id, pluginId: t.pluginId }, `Provider catalog ${t.id} failed during doctor validation.`, e)); continue; } const { id: a, pluginId: s } = t; o.push(...(() => { const readValue = (e, t, n = a) => { if (!isReadableRecord(e)) return { ok: true, value: void 0 }; try { return { ok: true, value: e[t] }; } catch (e) { return { ok: false, finding: providerCatalogProjectionFinding({ providerId: n, pluginId: s }, `Provider catalog ${n} entry cannot be read during doctor validation.`, e) }; } }; const collectModels = (e, t = a) => { const n = readValue(e, "models", t); if (!n.ok) return [n.finding]; const r = n.value; const i = []; let o; try { if (!Array.isArray(r)) return [providerCatalogProjectionFinding({ providerId: t, pluginId: s }, `Provider catalog ${t} models value is invalid during doctor validation.`, /* @__PURE__ */ new Error("models must be an array"))]; o = r; } catch (e) { return [providerCatalogProjectionFinding({ providerId: t, pluginId: s }, `Provider catalog ${t} models value cannot be checked during doctor validation.`, e)]; } let c; try { c = [...o]; } catch (e) { return [providerCatalogProjectionFinding({ providerId: t, pluginId: s }, `Provider catalog ${t} model rows cannot be enumerated during doctor validation.`, e)]; } for (const [e, n] of c.entries()) try { if (!isTrimmedNonEmptyString(isReadableRecord(n) ? n.id : void 0)) i.push(providerCatalogProjectionFinding({ providerId: t, pluginId: s }, `Provider catalog ${t} model row ${e} has an invalid model id.`, /* @__PURE__ */ new Error("model id must be a non-empty trimmed string"))); const r = isReadableRecord(n) ? n.name : void 0; if (r !== void 0 && typeof r !== "string") i.push(providerCatalogProjectionFinding({ providerId: t, pluginId: s }, `Provider catalog ${t} model row ${e} has an invalid model name.`, /* @__PURE__ */ new Error("model name must be a string when present"))); } catch (e) { i.push(providerCatalogProjectionFinding({ providerId: t, pluginId: s }, `Provider catalog ${t} entry cannot be read during doctor validation.`, e)); } return i; }; if (i == null) return []; if (!isReadableRecord(i)) return [providerCatalogProjectionFinding({ providerId: a, pluginId: s }, `Provider catalog ${a} result is invalid during doctor validation.`, /* @__PURE__ */ new Error("result must be an object"))]; let e; try { e = "provider" in i; } catch (e) { return [providerCatalogProjectionFinding({ providerId: a, pluginId: s }, `Provider catalog ${a} result keys cannot be checked during doctor validation.`, e)]; } const t = readValue(i, "provider"); if (!t.ok) return [t.finding]; if (e && !isReadableRecord(t.value)) return [providerCatalogProjectionFinding({ providerId: a, pluginId: s }, `Provider catalog ${a} provider value is invalid during doctor validation.`, /* @__PURE__ */ new Error("provider must be an object"))]; if (isReadableRecord(t.value)) return collectModels(t.value); const n = readValue(i, "providers"); if (!n.ok) return [n.finding]; if (!isReadableRecord(n.value)) return [providerCatalogProjectionFinding({ providerId: a, pluginId: s }, `Provider catalog ${a} result is invalid during doctor validation.`, /* @__PURE__ */ new Error("result must include provider or providers object"))]; let r; try { r = Object.keys(n.value); } catch (e) { return [providerCatalogProjectionFinding({ providerId: a, pluginId: s }, `Provider catalog ${a} provider entries cannot be enumerated during doctor validation.`, e)]; } const o = []; for (const e of r) { if (!isTrimmedNonEmptyString(e)) { o.push(providerCatalogProjectionFinding({ providerId: a, pluginId: s }, `Provider catalog ${a} provider key is invalid during doctor validation.`, /* @__PURE__ */ new Error("provider key must be a non-empty trimmed string"))); continue; } const t = readValue(n.value, e, e); if (!t.ok) { o.push(t.finding); continue; } if (!isReadableRecord(t.value)) { o.push(providerCatalogProjectionFinding({ providerId: e, pluginId: s }, `Provider catalog ${e} provider entry is invalid during doctor validation.`, /* @__PURE__ */ new Error("provider entry must be an object"))); continue; } o.push(...collectModels(t.value, e)); } return o; })()); } return o; } //#endregion export { collectGatewayDaemonFindings, collectLocalAudioAccelerationFindings, collectProviderCatalogProjectionFindings, detectUnavailableSkills };