UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

63 lines (62 loc) • 3.77 kB
import { n as isTruthyEnvValue } from "./env-HehwidXj.mjs"; import { r as resolvePathViaExistingAncestorSync } from "./boundary-path-C2gXEiXe.mjs"; import { r as resolveStateDir } from "./state-dir-DiG0gXzD.mjs"; import { m as resolveConfigPath } from "./paths-DAcAg5aV.mjs"; import { o as isGatewayExternallySupervised, s as resolveGatewayPlatformSupervisor } from "./gateway-supervision-C1X-e8qk.mjs"; import { t as isContainerEnvironment } from "./container-environment-BQP66a3c.mjs"; import { i as UPDATE_PARENT_ALLOWS_GATEWAY_ACTIVATION_ENV, r as UPDATE_IN_PROGRESS_ENV } from "./update-phase-YdZvaQsy.mjs"; //#region src/commands/doctor-service-repair-policy.ts const GATEWAY_SERVICE_MANAGER_TIMEOUT_MS = 5e3; const SERVICE_REPAIR_POLICY_ENV = "OPENCLAW_SERVICE_REPAIR_POLICY"; const EXTERNAL_SERVICE_REPAIR_NOTE = "Gateway service is managed externally; skipped service install/start repair. Start or repair the gateway through your supervisor."; function assertDoctorServiceSelection(e, t) { const selection = (e) => { const t = resolveStateDir(e); return [t, resolveConfigPath(e, t)].map((e) => resolvePathViaExistingAncestorSync(e)); }; const n = selection(e); if (selection(t).some((e, t) => e !== n[t])) throw new Error("Doctor and the managed Gateway select different config or state directories. Run doctor with the Gateway's installation and profile; the service was left unchanged."); } /** Missing activation policy belongs to legacy parents, not an explicit denial. */ function resolveUpdateParentGatewayActivation(e) { const t = e[UPDATE_PARENT_ALLOWS_GATEWAY_ACTIVATION_ENV]; return t === void 0 ? void 0 : isTruthyEnvValue(t); } async function shouldManageGatewayService(e = process.env) { if (resolveGatewayPlatformSupervisor(e)) return false; if (!isContainerEnvironment()) return true; if (process.platform !== "linux") return false; try { const { findInstalledSystemdGatewayScope: t } = await import("./systemd-C3ApdIee.mjs"); if ((await t(e))?.scope !== "user") return false; const { resolveGatewayService: n } = await import("./service-D5ZNJZsc.mjs"); await n().isLoaded({ env: e, timeoutMs: GATEWAY_SERVICE_MANAGER_TIMEOUT_MS }); return true; } catch { return false; } } /** The existing updater marker selects internal deferral, not external supervision. */ function resolveServiceRepairPolicy(e = process.env) { if (e["OPENCLAW_SERVICE_REPAIR_POLICY"]?.trim().toLowerCase() === "external") return "external"; return isTruthyEnvValue(e["OPENCLAW_UPDATE_IN_PROGRESS"]) ? "update" : "auto"; } function isServiceRepairExternallyManaged(e, t = process.env) { return (e ?? resolveServiceRepairPolicy(t)) === "external" || isGatewayExternallySupervised(t); } /** Maintenance inspection remains separate from publishing or activating a service. */ function isServiceRepairDeferred(e = resolveServiceRepairPolicy()) { return e === "update" || isServiceRepairExternallyManaged(e); } function formatServiceRepairDeferredNote(e = resolveServiceRepairPolicy()) { return e === "update" ? "Gateway service repair deferred to update finalization; Doctor left its definition and activation unchanged." : EXTERNAL_SERVICE_REPAIR_NOTE; } /** Confirms a service repair only when Doctor owns publication and activation. */ async function confirmDoctorServiceRepair(e, t, n = resolveServiceRepairPolicy()) { return !isServiceRepairDeferred(n) && await e.confirmRuntimeRepair(t); } //#endregion export { isServiceRepairDeferred as a, resolveUpdateParentGatewayActivation as c, formatServiceRepairDeferredNote as i, shouldManageGatewayService as l, assertDoctorServiceSelection as n, isServiceRepairExternallyManaged as o, confirmDoctorServiceRepair as r, resolveServiceRepairPolicy as s, SERVICE_REPAIR_POLICY_ENV as t };