openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.63 kB
JavaScript
import{Jn as string,Un as record,qn as strictObject}from"./schemas-DuCQi-Qb.mjs";import{t as NativeRuntimeConfigSchema}from"./native-runtime-config-BEzEhVtx.mjs";import{closeSync,readSync,realpathSync}from"node:fs";
//!src/worker/native-inference-startup.ts
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))});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`)}export{takeNativeInferenceStartup as i,WORKER_NATIVE_INFERENCE_STARTUP_MAX_BYTES as n,assertNativeInferenceAssignment as r,WORKER_NATIVE_INFERENCE_STARTUP_ARG as t};