openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
136 lines (135 loc) • 5.72 kB
JavaScript
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs";
//#region src/daemon/constants.ts
const GATEWAY_LAUNCH_AGENT_LABEL = "ai.openclaw.gateway";
const GATEWAY_SYSTEMD_SERVICE_NAME = "openclaw-gateway";
const GATEWAY_WINDOWS_TASK_NAME = "OpenClaw Gateway";
const GATEWAY_SERVICE_MARKER = "openclaw";
const GATEWAY_SERVICE_KIND = "gateway";
const GATEWAY_SERVICE_RUNTIME_PID_ENV = "OPENCLAW_GATEWAY_SERVICE_PID";
const GATEWAY_SERVICE_SELECTOR_ENV_KEYS = [
"OPENCLAW_STATE_DIR",
"OPENCLAW_CONFIG_PATH",
"OPENCLAW_PROFILE",
"OPENCLAW_GATEWAY_PORT",
"OPENCLAW_LAUNCHD_LABEL",
"OPENCLAW_SYSTEMD_UNIT",
"OPENCLAW_WINDOWS_TASK_NAME"
];
function isGatewayServiceEnv(e) {
if (e.OPENCLAW_SERVICE_MARKER?.trim() !== "openclaw") return false;
const t = e.OPENCLAW_SERVICE_KIND?.trim();
return !t || t === "gateway";
}
const NODE_LAUNCH_AGENT_LABEL = "ai.openclaw.node";
const NODE_SYSTEMD_SERVICE_NAME = "openclaw-node";
const NODE_WINDOWS_TASK_NAME = "OpenClaw Node";
const NODE_SERVICE_MARKER = "openclaw";
const NODE_SERVICE_KIND = "node";
const NODE_WINDOWS_TASK_SCRIPT_NAME = "node.cmd";
const LEGACY_GATEWAY_SYSTEMD_SERVICE_NAMES = ["clawdbot-gateway"];
function normalizeGatewayProfile(e) {
const t = e?.trim();
return t && normalizeLowercaseStringOrEmpty(t) !== "default" ? t : null;
}
function resolveGatewayProfileSuffix(e) {
const t = normalizeGatewayProfile(e);
return t ? `-${t}` : "";
}
function resolveGatewayLaunchAgentLabel(e) {
const t = normalizeGatewayProfile(e);
return t ? `ai.openclaw.${t}` : GATEWAY_LAUNCH_AGENT_LABEL;
}
function resolveGatewaySystemdServiceName(e) {
return `${GATEWAY_SYSTEMD_SERVICE_NAME}${resolveGatewayProfileSuffix(e)}`;
}
/**
* Service-name candidates for a profile, preferred order.
*
* Current installs use `openclaw-gateway[-profile]`. Older multi-agent hosts
* used `openclaw-<profile>` (no "gateway" segment). Doctor/runtime resolution
* must try both for the same profile before scanning unrelated units.
*/
function resolveGatewaySystemdServiceNameCandidates(e) {
const t = resolveGatewaySystemdServiceName(e);
const n = resolveGatewayProfileSuffix(e);
if (!n) return [t, "openclaw"];
const r = `openclaw${n}`;
return r === NODE_SYSTEMD_SERVICE_NAME || r === GATEWAY_SYSTEMD_SERVICE_NAME || r.startsWith(`${GATEWAY_SYSTEMD_SERVICE_NAME}-`) ? [t] : [t, r];
}
function resolveGatewayWindowsTaskName(e) {
const t = normalizeGatewayProfile(e);
return t ? `${GATEWAY_WINDOWS_TASK_NAME} (${t})` : GATEWAY_WINDOWS_TASK_NAME;
}
function normalizeWindowsTaskIdentity(e) {
return e.replace(/^\\+/, "").toLowerCase();
}
function resolveGatewayNativeServiceIdentityConflict(e, t = process.platform) {
const n = normalizeGatewayProfile(e.OPENCLAW_PROFILE);
if (!n) return null;
if (t === "darwin") {
const t = "OPENCLAW_LAUNCHD_LABEL";
const r = e[t]?.trim();
const i = resolveGatewayLaunchAgentLabel(n);
return r && r !== i ? {
envKey: t,
expected: i
} : null;
}
if (t === "linux") {
const t = "OPENCLAW_SYSTEMD_UNIT";
const r = e[t]?.trim();
const i = r?.endsWith(".service") ? r : r && `${r}.service`;
const a = `${resolveGatewaySystemdServiceName(n)}.service`;
return i && i !== a ? {
envKey: t,
expected: a
} : null;
}
if (t === "win32") {
const t = "OPENCLAW_WINDOWS_TASK_NAME";
const r = e[t]?.trim();
const i = resolveGatewayWindowsTaskName(n);
return r && normalizeWindowsTaskIdentity(r) !== normalizeWindowsTaskIdentity(i) ? {
envKey: t,
expected: i
} : null;
}
return null;
}
function formatGatewayServiceDescription(e) {
const t = normalizeGatewayProfile(e);
return t ? `OpenClaw Gateway (profile: ${t})` : "OpenClaw Gateway";
}
function resolveGatewayServiceDescription(e) {
return e.description ?? formatGatewayServiceDescription(e.env.OPENCLAW_PROFILE);
}
function resolveNodeLaunchAgentLabel(e) {
const t = normalizeGatewayProfile(e);
return t ? `${NODE_LAUNCH_AGENT_LABEL}.${t}` : NODE_LAUNCH_AGENT_LABEL;
}
function isNodeLaunchAgentLabel(e) {
return e === NODE_LAUNCH_AGENT_LABEL || e.startsWith(`${NODE_LAUNCH_AGENT_LABEL}.`);
}
function resolveNodeSystemdServiceName(e) {
return `${NODE_SYSTEMD_SERVICE_NAME}${resolveGatewayProfileSuffix(e)}`;
}
function resolveNodeWindowsTaskName(e) {
const t = normalizeGatewayProfile(e);
return t ? `${NODE_WINDOWS_TASK_NAME} (${t})` : NODE_WINDOWS_TASK_NAME;
}
function resolveNodeServiceIdentityEnvironment(e = {}) {
const t = e.OPENCLAW_PROFILE;
return {
OPENCLAW_PROFILE: t,
OPENCLAW_LAUNCHD_LABEL: resolveNodeLaunchAgentLabel(t),
OPENCLAW_SYSTEMD_UNIT: resolveNodeSystemdServiceName(t),
OPENCLAW_WINDOWS_TASK_NAME: resolveNodeWindowsTaskName(t),
OPENCLAW_WINDOWS_TASK_HIDDEN_LAUNCHER: "1",
OPENCLAW_TASK_SCRIPT_NAME: NODE_WINDOWS_TASK_SCRIPT_NAME,
OPENCLAW_LOG_PREFIX: `node${resolveGatewayProfileSuffix(t)}`,
OPENCLAW_SERVICE_MARKER: NODE_SERVICE_MARKER,
OPENCLAW_SERVICE_KIND: NODE_SERVICE_KIND
};
}
//#endregion
export { resolveGatewayWindowsTaskName as _, GATEWAY_SERVICE_SELECTOR_ENV_KEYS as a, resolveNodeSystemdServiceName as b, isGatewayServiceEnv as c, resolveGatewayLaunchAgentLabel as d, resolveGatewayNativeServiceIdentityConflict as f, resolveGatewaySystemdServiceNameCandidates as g, resolveGatewaySystemdServiceName as h, GATEWAY_SERVICE_RUNTIME_PID_ENV as i, isNodeLaunchAgentLabel as l, resolveGatewayServiceDescription as m, GATEWAY_SERVICE_KIND as n, LEGACY_GATEWAY_SYSTEMD_SERVICE_NAMES as o, resolveGatewayProfileSuffix as p, GATEWAY_SERVICE_MARKER as r, NODE_SERVICE_KIND as s, GATEWAY_LAUNCH_AGENT_LABEL as t, normalizeWindowsTaskIdentity as u, resolveNodeLaunchAgentLabel as v, resolveNodeWindowsTaskName as x, resolveNodeServiceIdentityEnvironment as y };