UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

91 lines (90 loc) • 3.84 kB
import { a as readStandaloneRuntimeManifest, s as resolveOpenClawCliInvocation, t as getEmbeddedStandaloneRuntimeRoot } from "./cli-invocation-ZSPsKRWa.mjs"; import { t as isBunRuntime } from "./runtime-binary-QwVVJ9cA.mjs"; import { n as tryProcessCwd } from "./safe-cwd-CZqaxroH.mjs"; import { n as resolveRuntimeWorkerArgv, t as resolveRuntimeArgs } from "./runtime-worker-url-DRDkoS4J.mjs"; import { r as resolveExternalPackageRuntimeEntrypointUrl } from "./runtime-process-url-CoHTemu-.mjs"; import { r as resolveOpenClawPackageRootSync } from "./openclaw-root-C-ayo09z.mjs"; import { createRequire } from "node:module"; import fs from "node:fs"; import { fileURLToPath, pathToFileURL } from "node:url"; import path from "node:path"; //#region src/infra/openclaw-cli-invocation.ts const requireFromHere = createRequire(import.meta.url); const OPENCLAW_CLI_ENTRY_BASENAMES = /* @__PURE__ */ new Set(["openclaw", "openclaw.mjs"]); const OPENCLAW_PACKAGE_ENTRY_PATHS = /* @__PURE__ */ new Set([ path.join("dist", "entry.js"), path.join("dist", "entry.mjs"), path.join("dist", "index.js"), path.join("dist", "index.mjs"), path.join("src", "entry.ts") ]); /** Keep parent runtime flags, pin its known TSX preload, and leave debugger ownership behind. */ function filterOpenClawChildExecArgv(e, t) { const n = []; for (let r = 0; r < e.length; r += 1) { const i = e[r] ?? ""; if (/^--inspect(?:-brk|-wait|-port)?(?:=|$)/.test(i)) { const t = e[r + 1]; if (!i.includes("=") && typeof t === "string" && !t.startsWith("-")) r += 1; continue; } const a = i === "tsx" && e[r - 1] === "--import"; n.push(t && (a || i === "--import=tsx") ? `${a ? "" : "--import="}${pathToFileURL(requireFromHere.resolve("tsx", { paths: [t] })).href}` : i); } return n; } function buildPackageRootCliArgs(e, t) { const n = resolveExternalPackageRuntimeEntrypointUrl("sourceCli", e); const r = fileURLToPath(n); if (fs.existsSync(r)) try { return filterOpenClawChildExecArgv(resolveRuntimeWorkerArgv(n, t), e); } catch {} return [...resolveRuntimeArgs(t), fileURLToPath(resolveExternalPackageRuntimeEntrypointUrl("cliLauncher", e))]; } function resolveOpenClawCliEntryPath(e) { const t = e?.trim(); if (!t) return t; try { return fs.realpathSync(t); } catch { return t; } } function resolveCurrentOpenClawCliInvocation(e, t = {}) { const n = process.execPath; const r = getEmbeddedStandaloneRuntimeRoot(); const i = r ? void 0 : readStandaloneRuntimeManifest(n); const a = r ?? (i ? path.resolve(path.dirname(n), i.runtime.path) : void 0); if (a) return { ...resolveOpenClawCliInvocation({ execPath: n, args: e }), cwd: a }; const o = resolveOpenClawCliEntryPath(process.argv[1]); const s = tryProcessCwd(); const c = o ? resolveOpenClawPackageRootSync({ argv1: o }) : null; const l = c ?? resolveOpenClawPackageRootSync({ argv1: o, cwd: s, moduleUrl: t.moduleUrl ?? import.meta.url }); const u = l ?? s ?? (o ? path.dirname(path.resolve(o)) : path.dirname(n)); const d = l ? path.join(l, "src", "entry.ts") : void 0; const f = o && o !== n && c && (OPENCLAW_CLI_ENTRY_BASENAMES.has(path.basename(o)) || OPENCLAW_PACKAGE_ENTRY_PATHS.has(path.relative(path.resolve(c), path.resolve(o)))) ? o : void 0; const p = f ? [...filterOpenClawChildExecArgv(process.execArgv, f === d ? l ?? void 0 : void 0), f] : l ? buildPackageRootCliArgs(l, n) : o && o !== n ? [o] : []; const m = l && !isBunRuntime(n) && p.at(-1) === d ? { TSX_TSCONFIG_PATH: path.join(l, "tsconfig.json") } : void 0; return { ...resolveOpenClawCliInvocation({ execPath: n, entryPath: p.at(-1), execArgv: p.slice(0, -1), args: e }), cwd: u, ...m ? { env: m } : {} }; } //#endregion export { resolveCurrentOpenClawCliInvocation as n, resolveOpenClawCliEntryPath as r, filterOpenClawChildExecArgv as t };