UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

193 lines (192 loc) • 7.1 kB
//#region node-version.mjs const MINIMUM_BUN_VERSION = { major: 1, minor: 4, patch: 4 }; const NODE_RELEASE_VERSION_RE = /^v?((?:0|[1-9]\d*))\.((?:0|[1-9]\d*))\.((?:0|[1-9]\d*))(?:-((?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u; const NODE_RELEASE_FLOORS = [{ major: 24, minor: 16, patch: 0 }, { major: 26, minor: 1, patch: 0 }]; const NODE_SECURITY_RELEASE_FLOORS = [{ major: 24, minor: 22, patch: 1 }, { major: 26, minor: 12, patch: 1 }]; const HIGHEST_RELEASE_FLOOR = NODE_RELEASE_FLOORS[NODE_RELEASE_FLOORS.length - 1]; const SUPPORTED_NODE_VERSION_RANGE = NODE_RELEASE_FLOORS.map(({ major: e, minor: t, patch: n }, r) => `>=${e}.${t}.${n}${r < NODE_RELEASE_FLOORS.length - 1 ? ` <${e + 1}` : ""}`).join(" || "); const SUPPORTED_NODE_VERSIONS = `${SUPPORTED_NODE_VERSION_RANGE.replaceAll(" || ", ", ").replace(/, ([^,]+)$/, ", or $1")} (Node 26 recommended)`; function formatUnsupportedNodeVersionMessage(e) { return [ `Node ${e ?? "unknown"} is unsupported; OpenClaw requires ${SUPPORTED_NODE_VERSIONS}.`, "npm can finish installing OpenClaw without running its preinstall check; a successful install does not mean Node is supported.", "Re-run the installer: curl -fsSL https://openclaw.ai/install.sh | bash", "On Windows: iwr -useb https://openclaw.ai/install.ps1 | iex", "Or with nvm: nvm install 26 && nvm use 26 && nvm alias default 26", "Then rerun openclaw update. See https://docs.openclaw.ai/install/node" ].join("\n"); } function formatUnsupportedNodeDiagnosticWarning(e) { return `Running on an unsupported Node (${e}); diagnostics may show truncated text`; } function formatNodeSecurityWarning(e) { const t = parseNodeReleaseVersion(e); if (!t) return null; const n = NODE_SECURITY_RELEASE_FLOORS.find((e) => e.major === t.major); if (n ? isNodeVersionAtLeast(t, n) : t.major > HIGHEST_RELEASE_FLOOR.major) return null; return `Node.js ${e} is below the recommended security patch level. Upgrade to Node 24.22.1+ on the 24.x line or Node 26.12.1+ to reject the public keys compromised in the October 2026 eMudhra incident.`; } const ROOT_BOOLEAN_OPTIONS = ["--dev", "--no-color"]; const ROOT_VALUE_OPTIONS = [ "--profile", "--log-level", "--container" ]; function consumeOption(e, t, n, r) { const i = e[t]; if (n.includes(i)) return 1; const a = i.indexOf("="); if (r.includes(a < 0 ? i : i.slice(0, a))) return a >= 0 ? 1 : e[t + 1] === void 0 ? 0 : 2; return 0; } function diagnosticOptions(e, t, n = []) { const r = /* @__PURE__ */ new Set(); for (let i = 0; i < e.length;) { const a = consumeOption(e, i, [...ROOT_BOOLEAN_OPTIONS, ...t], [...ROOT_VALUE_OPTIONS, ...n]); if (!a) return null; r.add(e[i]); i += a; } return r; } /** Shared by the packaged launcher and source guard before either loads command state. */ function classifyUnsupportedNodeCommand(e) { const t = e.slice(2); let n = 0; while (n < t.length) { const e = consumeOption(t, n, ROOT_BOOLEAN_OPTIONS, ROOT_VALUE_OPTIONS); if (!e) break; n += e; } const r = t[n++]; const i = t.slice(n); if ([ "--version", "-V", "-v", "--help", "-h" ].includes(r)) return diagnosticOptions(i, []) ? "diagnostic" : null; if (r === "gateway") { while (n < t.length) { const e = consumeOption(t, n, ROOT_BOOLEAN_OPTIONS, ROOT_VALUE_OPTIONS); if (!e) break; n += e; } return t[n] === "status" ? "diagnostic" : null; } if (r === "doctor") return diagnosticOptions(i, [ "--lint", "--json", "--deep", "--all", "--non-interactive", "--no-workspace-suggestions" ], [ "--only", "--skip", "--severity-min" ]) ? "diagnostic" : null; if (r === "triage") { const e = diagnosticOptions(i, [ "--json", "--non-interactive", "--no-export" ], ["--update-result"]); return e && (e.has("--json") || e.has("--non-interactive")) ? "diagnostic" : null; } if (r === "update") { while (n < t.length) { const e = consumeOption(t, n, ROOT_BOOLEAN_OPTIONS, ROOT_VALUE_OPTIONS); if (!e) break; n += e; } if (t[n] === "status") return diagnosticOptions(t.slice(n + 1), ["--json"], ["--timeout"]) ? "diagnostic" : null; return diagnosticOptions(i, [ "--json", "--yes", "--dry-run", "--no-restart", "--accept-capabilities" ], [ "--channel", "--tag", "--timeout" ]) ? "update" : null; } return null; } /** Diagnostic bundles target Node 22 syntax and require the native SQLite reader. */ function canRunOpenClawNodeDiagnostics(e, t) { return t && isNodeVersionAtLeast(parseNodeReleaseVersion(e), { major: 22, minor: 0, patch: 0 }); } /** Parses release SemVer; future-major prereleases use their numeric core for admission. */ function parseNodeReleaseVersion(e) { if (typeof e !== "string") return null; const t = NODE_RELEASE_VERSION_RE.exec(e.trim()); if (!t) return null; const n = { major: Number(t[1]), minor: Number(t[2]), patch: Number(t[3]) }; return Object.values(n).every(Number.isSafeInteger) && (!t[4] || n.major > HIGHEST_RELEASE_FLOOR.major) ? n : null; } function isNodeVersionAtLeast(e, t) { if (!e) return false; if (e.major !== t.major) return e.major > t.major; if (e.minor !== t.minor) return e.minor > t.minor; return e.patch >= t.patch; } /** Checks compatibility floors; recommended security patches are reported separately. */ function isSupportedOpenClawNodeVersion(e) { const t = parseNodeReleaseVersion(e); if (!t) return false; const n = NODE_RELEASE_FLOORS.find((e) => e.major === t.major); return n ? isNodeVersionAtLeast(t, n) : t.major > HIGHEST_RELEASE_FLOOR.major; } function renderProcessNodeVersionCheck() { return `((value) => { if (typeof value !== "string") return false; const match = new RegExp(${JSON.stringify(NODE_RELEASE_VERSION_RE.source)}, "u").exec(value.trim()); if (!match) return false; const version = { major: Number(match[1]), minor: Number(match[2]), patch: Number(match[3]) }; if (!Object.values(version).every(Number.isSafeInteger)) return false; const floors = ${JSON.stringify(NODE_RELEASE_FLOORS)}; if (match[4] && version.major <= floors[floors.length - 1].major) return false; const minimum = floors.find((floor) => floor.major === version.major); const atLeast = (floor) => version.major > floor.major || (version.major === floor.major && (version.minor > floor.minor || (version.minor === floor.minor && version.patch >= floor.patch))); return minimum ? atLeast(minimum) : version.major > floors[floors.length - 1].major; })(process.versions.node)`; } const PROCESS_NODE_VERSION_CHECK = renderProcessNodeVersionCheck(); //#endregion export { canRunOpenClawNodeDiagnostics as a, formatUnsupportedNodeDiagnosticWarning as c, isSupportedOpenClawNodeVersion as d, parseNodeReleaseVersion as f, SUPPORTED_NODE_VERSION_RANGE as i, formatUnsupportedNodeVersionMessage as l, PROCESS_NODE_VERSION_CHECK as n, classifyUnsupportedNodeCommand as o, SUPPORTED_NODE_VERSIONS as r, formatNodeSecurityWarning as s, MINIMUM_BUN_VERSION as t, isNodeVersionAtLeast as u };