openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
60 lines (59 loc) • 2.32 kB
JavaScript
import { a as extractErrorCode } from "./error-coercion-hDrHOSGy.mjs";
import "./errors-BKzCeTYb.mjs";
import { i as withChildProcessOperation } from "./spawn-diagnostics-DBVI9KzR.mjs";
import { i as hasCommandProcessCleanupError, r as createSanitizedCommandError, t as CommandProcessCleanupError } from "./exec-result-DJMhztYN.mjs";
import { t as resolveServiceManagerEnv } from "./service-process-env-03_YbuSP.mjs";
import { n as runCommandWithTimeout } from "./exec-runner-Br73vG-X.mjs";
import "./exec-aRIvS9s4.mjs";
import { a as getGatewayServiceUpdateNativeCommand, i as assertGatewayServiceUpdateCurrent, n as GatewayServiceAuthorityError } from "./service-update-authority-wlK0pAdP.mjs";
//#region src/daemon/exec-file.ts
/** Native service control/inspection only; payload launchers own their full environment. */
async function execFileUtf8(e, t, n = {}) {
const r = getGatewayServiceUpdateNativeCommand();
const i = r ? true : assertGatewayServiceUpdateCurrent();
let a;
const o = n.beforeEffect ? () => {
try {
n.beforeEffect?.();
} catch (e) {
a = { error: e };
throw e;
}
} : void 0;
try {
o?.();
const a = r ?? runCommandWithTimeout;
const { stdout: s, stderr: c, code: l, termination: u, signal: d, cleanup: f } = await withChildProcessOperation("service.manager", () => a([e, ...t], {
baseEnv: resolveServiceManagerEnv(n.env),
cwd: n.cwd ?? (process.platform === "win32" ? void 0 : "/"),
killSignal: n.killSignal,
maxOutputBytes: 1048576,
timeoutMs: n.timeout,
...r && o ? { beforeInput: o } : {}
}));
if (i && f === "uncertain") throw new CommandProcessCleanupError();
if (!r) assertGatewayServiceUpdateCurrent();
return {
stdout: s,
stderr: [c, u === "exit" ? "" : createSanitizedCommandError({
timedOut: u === "timeout" || u === "no-output-timeout",
isTerminated: true,
signal: d
}).message].filter(Boolean).join("\n"),
code: u === "exit" ? l ?? 1 : l || 1,
termination: u
};
} catch (e) {
if (e instanceof GatewayServiceAuthorityError || hasCommandProcessCleanupError(e)) throw e;
if (a) throw a.error;
return {
stdout: "",
stderr: e instanceof Error ? e.message : String(e),
code: 1,
termination: "error",
errorCode: extractErrorCode(e)
};
}
}
//#endregion
export { execFileUtf8 as t };