UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

73 lines (72 loc) • 3.2 kB
import { a as resolveGlobalSingleton } from "./global-singleton-D7yf05nR.mjs"; import { n as normalizeProfileName } from "./profile-utils-d6OWXWRX.mjs"; import { g as normalizeUniqueStringEntries } from "./string-normalization-DLmfYZXI.mjs"; import { r as resolveStateDir } from "./state-dir-DiG0gXzD.mjs"; import "./paths-DAcAg5aV.mjs"; import { h as writeTextAtomic } from "./json-files-Cb1h8pYs.mjs"; import { t as quoteCliArg } from "./quote-cli-arg-J7A9UE6m.mjs"; import { n as quoteCmdScriptArg, o as renderCmdSetAssignment } from "./cmd-argv-CkCgfbnx.mjs"; import { n as resolveCurrentOpenClawCliInvocation } from "./openclaw-cli-invocation-CiQvieV9.mjs"; import { n as resolveStableNodePath } from "./stable-node-path-CgUjRwli.mjs"; import path from "node:path"; import fs from "node:fs/promises"; //#region src/infra/openclaw-cli-shim.ts const AGENT_CLI_BIN_DIR = path.join("tmp", "agent-cli"); const gatewayAgentCliState = resolveGlobalSingleton(Symbol.for("openclaw.gatewayAgentCliShim"), () => ({ binDir: void 0 }), (e) => { e.binDir = void 0; }); /** * Materialize the exact running Gateway CLI as an agent-visible PATH command. * The generated launcher is a runtime tool contract, not persisted product state. */ async function prepareGatewayAgentCliShim() { const e = process.env; const t = process.platform; const n = resolveCurrentOpenClawCliInvocation([]); const r = await resolveStableNodePath(n.command); const i = normalizeProfileName(e.OPENCLAW_PROFILE); const a = path.join(resolveStateDir(e), AGENT_CLI_BIN_DIR); const o = path.join(a, t === "win32" ? "openclaw.cmd" : "openclaw"); const s = [...n.args, ...i ? ["--profile", i] : []]; const c = { delayedExpansion: false }; const l = Object.entries(n.env ?? {}).map(([e, n]) => t === "win32" ? renderCmdSetAssignment(e, n, c) : `export ${e}=${quoteCliArg(n)}`); const u = t === "win32" ? [ "@echo off", "setlocal DisableDelayedExpansion", ...l, `${[r, ...s].map((e) => quoteCmdScriptArg(e, c)).join(" ")} %*`, "" ].join("\r\n") : `#!/bin/sh set -eu ${l.join("\n")} exec ${[r, ...s].map(quoteCliArg).join(" ")} "$@" `; await fs.mkdir(a, { recursive: true, mode: 448 }); await fs.chmod(a, 448).catch(() => void 0); await writeTextAtomic(o, u, { mode: 448, dirMode: 448, durable: false, tempPrefix: "openclaw-agent-cli" }); gatewayAgentCliState.binDir = a; } /** Clear a prepared launcher after startup failure; normal Gateway close resets it globally. */ function clearGatewayAgentCliShim() { gatewayAgentCliState.binDir = void 0; } /** Prepend the prepared Gateway CLI ahead of operator-configured exec PATH entries. */ function mergeGatewayAgentCliPath(e) { const t = normalizeUniqueStringEntries([...gatewayAgentCliState.binDir ? [gatewayAgentCliState.binDir] : [], ...e ?? []]); return t.length > 0 ? t : void 0; } /** Drop the Gateway-local CLI shim, e.g. before judging operator PATH entries for remote hosts. */ function omitGatewayAgentCliPath(e) { const t = gatewayAgentCliState.binDir; return e.filter((e) => e !== t); } //#endregion export { prepareGatewayAgentCliShim as i, mergeGatewayAgentCliPath as n, omitGatewayAgentCliPath as r, clearGatewayAgentCliShim as t };