openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
41 lines (40 loc) • 1.35 kB
JavaScript
import { n as sanitizeTerminalText } from "./safe-text-C6FhHCw7.mjs";
import { accessSync, constants } from "node:fs";
//#region src/infra/child-runtime-viability.ts
function errnoCode(error) {
if (!(error instanceof Error) || !("code" in error)) return;
const code = error.code;
return typeof code === "string" ? code : void 0;
}
function accessExecutable(execPath) {
accessSync(execPath, constants.X_OK);
}
/** Reports whether this process can still spawn children with its own Node binary. */
function readChildRuntimeViability(params) {
const execPath = params?.execPath ?? process.execPath;
const access = params?.access ?? accessExecutable;
try {
access(execPath);
return {
execPath,
available: true
};
} catch (error) {
const code = errnoCode(error);
if (code === "ENOENT" || code === "ENOTDIR") return {
execPath,
available: false
};
return {
execPath,
available: true
};
}
}
/** Operator text for a Gateway whose retained Node binary is gone. */
function formatMissingChildRuntimeWarning(viability) {
if (viability.available) return;
return `Gateway runtime is stale after Node upgrade: child workers are using ${sanitizeTerminalText(viability.execPath)}, which no longer exists. Restart the Gateway.`;
}
//#endregion
export { readChildRuntimeViability as n, formatMissingChildRuntimeWarning as t };