openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
4 lines • 1.26 kB
JavaScript
import{p as toErrorObject}from"./error-coercion-DlKnt6w-.mjs";import{n as runtimeProcessEntrypoints}from"./runtime-process-entrypoints-Dnd1WskT.mjs";import{t as gatewaySpawnBrokerState}from"./context-state-CSLm35p3.mjs";import os from"node:os";
//!src/process/spawn-broker/context.ts
async function startGatewaySpawnBroker(e){if(gatewaySpawnBrokerState.startupDisabled)return;const t=process.constrainedMemory();if((t>0?Math.min(os.totalmem(),t):os.totalmem())<=1024**3)return;let n;let r=runtimeProcessEntrypoints.spawnBroker.distWorkerPath;try{const{createSpawnBrokerHost:t}=await import(`./host-Dgq3T-Wk.mjs`);n=t({onReady:e.onReady,onClosed:()=>{if(gatewaySpawnBrokerState.host===n)gatewaySpawnBrokerState.host=void 0}});r=n.entryPath;await n.ready();gatewaySpawnBrokerState.host=n;return n}catch(t){gatewaySpawnBrokerState.startupDisabled=true;let i=toErrorObject(t,`Spawn broker startup failed`).message;try{await n?.close()}catch(e){i+=`; cleanup failed: ${toErrorObject(e,`Spawn broker cleanup failed`).message}`}await e.onStartupFailure(`spawn broker startup failed: ${i}; runtime entry=${r}; in-process spawning is in effect for the lifetime of this process`.replaceAll(`\r`,` `).replaceAll(`
`,` `));return}}export{startGatewaySpawnBroker as t};