openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
45 lines (44 loc) • 2.03 kB
JavaScript
import { Jn as string, Un as record, qn as strictObject } from "./schemas-Cy6abvsu.mjs";
import { t as NativeRuntimeConfigSchema } from "./native-runtime-config-BhaaooA4.mjs";
import { closeSync, readSync, realpathSync } from "node:fs";
//#region src/worker/native-inference-startup.ts
/** Private node-to-worker startup carrier, never part of a Gateway turn envelope. */
const WORKER_NATIVE_INFERENCE_STARTUP_ARG = "--internal-worker-native-inference";
const WORKER_NATIVE_INFERENCE_STARTUP_FD = 3;
const WORKER_NATIVE_INFERENCE_STARTUP_MAX_BYTES = 2097152;
const NativeInferenceStartupSchema = strictObject({
config: NativeRuntimeConfigSchema,
credentials: record(string(), string().min(1))
});
/** Drain the private pipe before the start gate, then close it before any tools can run. */
function takeNativeInferenceStartup(e = process.argv) {
const t = e.indexOf(WORKER_NATIVE_INFERENCE_STARTUP_ARG);
if (t < 0) return;
e.splice(t, 1);
try {
const e = Buffer.alloc(2097153);
try {
let t = 0;
for (;;) {
const n = readSync(3, e, t, e.length - t, null);
t += n;
if (t > 2097152) throw new Error("Startup payload exceeds limit");
if (n === 0) return NativeInferenceStartupSchema.parse(JSON.parse(e.toString("utf8", 0, t)));
}
} finally {
e.fill(0);
closeSync(3);
}
} catch {
throw new Error("Invalid node-local inference startup configuration");
}
}
function assertNativeInferenceAssignment(e, t) {
const n = t.assignment;
const r = `${n.modelRef.provider}/${n.modelRef.model}`;
const i = realpathSync(e.config.workspace);
const a = realpathSync(n.workspaceDir);
if (n.inference !== "runtime-local" || !e.config.models.some((t) => `${t.provider}/${t.id}` === r && e.credentials[r]) || i !== a) throw new Error("Node-local inference startup does not match the admitted workspace or model");
}
//#endregion
export { takeNativeInferenceStartup as i, WORKER_NATIVE_INFERENCE_STARTUP_MAX_BYTES as n, assertNativeInferenceAssignment as r, WORKER_NATIVE_INFERENCE_STARTUP_ARG as t };