UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

113 lines (112 loc) • 4.41 kB
import { i as isStandaloneRuntimeExecutable } from "./cli-invocation-ZSPsKRWa.mjs"; import { r as resolveOpenClawPackageRootSync } from "./openclaw-root-C-ayo09z.mjs"; import { a as resolveBunRuntimeInfo, c as resolvePreferredBunPath, f as resolveSystemNodeInfo, i as renderSystemNodeWarning, l as resolvePreferredNodePath, o as resolveNodeRuntimeInfo, s as resolvePinnedDaemonRuntimePath } from "./runtime-paths-xW9-a89Z.mjs"; import fs from "node:fs"; import path from "node:path"; //#region src/commands/daemon-install-plan.shared.ts function resolveGatewayDevMode() { const e = process.argv[1]?.replaceAll("\\", "/"); return e !== void 0 && e.includes("/src/") && e.endsWith(".ts"); } /** Use the running Bun only when implicit Node discovery found no supported runtime. */ async function resolveRunningBunFallback(e) { if (!process.versions.bun) return; if ((e.nodePath === void 0 ? await resolvePreferredNodePath({ env: e.env, runtime: "node" }) : e.nodePath) || (await resolveBunRuntimeInfo(process.execPath, e.env)).status !== "supported") return; return process.execPath; } async function resolveDaemonInstallRuntimeInputs(e) { const t = e.devMode ?? resolveGatewayDevMode(); if (e.wrapperPath?.trim()) return { devMode: t, runtime: e.runtime, runtimePath: e.runtimePath }; if (e.runtime === "standalone") { const t = e.pinnedRuntimePath ?? e.runtimePath ?? (isStandaloneRuntimeExecutable() ? process.execPath : void 0); if (!t) throw new Error("Standalone services require --runtime-path pointing to a complete standalone artifact."); return { devMode: false, runtime: "standalone", runtimePath: await resolvePinnedDaemonRuntimePath(t, "standalone", e.env) }; } const n = (e.pinnedRuntimePath === void 0 ? void 0 : await resolvePinnedDaemonRuntimePath(e.pinnedRuntimePath, e.runtime, e.env)) ?? e.runtimePath ?? (e.runtime === "bun" ? await resolvePreferredBunPath({ env: e.env, runtime: e.runtime }) : await resolvePreferredNodePath({ env: e.env, runtime: e.runtime })); if (e.runtime === "node" && !e.runtimeExplicit && e.pinnedRuntimePath === void 0 && e.runtimePath === void 0 && n === void 0) { const n = await resolveRunningBunFallback({ env: e.env, nodePath: null }); if (n) { e.warn?.("No supported Node runtime was found; using the running Bun for the service."); return { devMode: t, runtime: "bun", runtimePath: n }; } } return { devMode: t, runtime: e.runtime, runtimePath: n }; } function resolveDaemonRuntimeBinDir(e) { const t = e?.trim(); if (!t || !path.isAbsolute(t)) return; return [path.dirname(t)]; } function safeRealpathSync(e) { try { return fs.realpathSync.native(e); } catch { return; } } function resolveDaemonServicePathDirs(e) { const t = e.platform ?? process.platform; const n = e.argv ?? process.argv; const r = e.env ?? process.env; const i = n[1]?.trim(); const a = new Set(resolveDaemonRuntimeBinDir(e.runtimePath)); const o = path.basename(i ?? ""); if (i && path.isAbsolute(i) && (o === "openclaw" || t === "win32" && [ "openclaw.cmd", "openclaw.ps1", "openclaw.exe" ].includes(o))) a.add(path.dirname(i)); const s = i && path.isAbsolute(i) ? safeRealpathSync(i) : void 0; for (const e of (r.PATH ?? "").split(path.delimiter)) { const n = e.trim(); if (!path.isAbsolute(n)) continue; const r = path.join(n, t === "win32" ? "openclaw.cmd" : "openclaw"); if (!fs.existsSync(r)) continue; const i = safeRealpathSync(r); if (s && i && i !== s) { const e = resolveOpenClawPackageRootSync({ argv1: s }); if (!e || resolveOpenClawPackageRootSync({ argv1: i }) !== e) continue; } a.add(n); } return a.size > 0 ? [...a] : void 0; } //#endregion //#region src/commands/daemon-install-runtime-warning.ts /** Warn when daemon install will use a system Node path that may be unsuitable. */ async function emitNodeRuntimeWarning(e) { if (e.runtime !== "node") return; const t = await resolveSystemNodeInfo({ env: e.env }); const n = renderSystemNodeWarning(t, e.nodeProgram); if (n && (!e.nodeProgram || e.nodeProgram === t?.path || (await resolveNodeRuntimeInfo(e.nodeProgram, e.env)).status !== "supported")) e.warn?.(n, e.title); } //#endregion export { resolveRunningBunFallback as a, resolveDaemonServicePathDirs as i, resolveDaemonInstallRuntimeInputs as n, resolveDaemonRuntimeBinDir as r, emitNodeRuntimeWarning as t };