UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

55 lines (54 loc) • 1.82 kB
import { spawn } from "node:child_process"; //#region src/cli/update-cli/update-command-native-gate.worker.ts async function main() { try { const [e, t, ...n] = process.argv.slice(2); const r = Number(e); if (!Number.isSafeInteger(r) || r <= 0 || !t) throw new Error("Native command admission rejected"); const i = []; let a = 0; for await (const e of process.stdin) { a += e.length; if (a > r) throw new Error("Native command admission rejected"); i.push(e); } if (a !== r) throw new Error("Native command admission rejected"); const o = JSON.parse(new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(Buffer.concat(i))); if (!Array.isArray(o) || o.length !== 2 || typeof o[0] !== "string" || !/^[0-9a-f-]{36}$/.test(o[0])) throw new Error("Native command admission rejected"); const [s, c] = o; if (c !== null && (!Array.isArray(c) || c.length !== 2 || typeof c[0] !== "string" || typeof c[1] !== "string" || c[1].includes("\0") || (process.platform === "win32" ? c[0].toUpperCase() : c[0]) !== "NODE_OPTIONS")) throw new Error("Native command admission rejected"); const l = { ...process.env }; if (c !== null) l[c[0]] = c[1]; const u = spawn(t, n, { env: l, stdio: [ "ignore", "inherit", "inherit" ], detached: false, windowsHide: true }); let d = false; u.once("error", (e) => { d = true; const t = "code" in e && typeof e.code === "string" && /^[A-Z0-9_]+$/.test(e.code) ? e.code : "_"; process.stderr.write("native-spawn-error:" + s + ":" + t); process.exitCode = 1; }); u.once("close", (e, t) => { if (d) return; if (t) process.kill(process.pid, t); else process.exitCode = e ?? 1; }); } catch { process.stdin.destroy(); process.exitCode = 1; } } await main(); //#endregion export {};