openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
63 lines (62 loc) • 4 kB
JavaScript
import { n as isTruthyEnvValue } from "./env-BBJTTIuE.mjs";
import { n as resolvePathViaExistingAncestorSync } from "./boundary-path-CAv_plX7.mjs";
import { r as resolveStateDir } from "./state-dir-BHJORNly.mjs";
import { m as resolveConfigPath } from "./paths-DGIwWbpu.mjs";
import { o as isGatewayExternallySupervised } from "./gateway-supervision-CUdBruRD.mjs";
import { t as isContainerEnvironment } from "./container-environment-e2wGNmXf.mjs";
import { i as UPDATE_PARENT_ALLOWS_GATEWAY_ACTIVATION_ENV } from "./update-phase-BClSJ17n.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(env, serviceEnv) {
const selection = (candidate) => {
const stateDir = resolveStateDir(candidate);
return [stateDir, resolveConfigPath(candidate, stateDir)].map((value) => resolvePathViaExistingAncestorSync(value));
};
const before = selection(env);
if (selection(serviceEnv).some((value, index) => value !== before[index])) 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(env) {
const policy = env[UPDATE_PARENT_ALLOWS_GATEWAY_ACTIVATION_ENV];
return policy === void 0 ? void 0 : isTruthyEnvValue(policy);
}
async function shouldManageGatewayService(env = process.env) {
if (isGatewayExternallySupervised(env) || env.KUBERNETES_SERVICE_HOST?.trim() && env.KUBERNETES_SERVICE_PORT?.trim()) return false;
if (!isContainerEnvironment()) return true;
if (process.platform !== "linux") return false;
try {
const { findInstalledSystemdGatewayScope } = await import("./systemd-B6PAzr4r.mjs");
if ((await findInstalledSystemdGatewayScope(env))?.scope !== "user") return false;
const { resolveGatewayService } = await import("./service-C5exmZL9.mjs");
await resolveGatewayService().isLoaded({
env,
timeoutMs: GATEWAY_SERVICE_MANAGER_TIMEOUT_MS
});
return true;
} catch {
return false;
}
}
/** The existing updater marker selects internal deferral, not external supervision. */
function resolveServiceRepairPolicy(env = process.env) {
if (env["OPENCLAW_SERVICE_REPAIR_POLICY"]?.trim().toLowerCase() === "external") return "external";
return isTruthyEnvValue(env["OPENCLAW_UPDATE_IN_PROGRESS"]) ? "update" : "auto";
}
function isServiceRepairExternallyManaged(policy = resolveServiceRepairPolicy()) {
return policy === "external" || isGatewayExternallySupervised();
}
/** Maintenance inspection remains separate from publishing or activating a service. */
function isServiceRepairDeferred(policy = resolveServiceRepairPolicy()) {
return policy === "update" || isServiceRepairExternallyManaged(policy);
}
function formatServiceRepairDeferredNote(policy = resolveServiceRepairPolicy()) {
return policy === "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(prompter, params, policy = resolveServiceRepairPolicy()) {
return !isServiceRepairDeferred(policy) && await prompter.confirmRuntimeRepair(params);
}
//#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 };