UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 4.07 kB
import{i as e}from"./transcript-global-singleton-DIJgobpU.mjs";import{c as t}from"./transcript-plugin-instance-invocation-7y9lfaeO.mjs";import{t as n}from"./transcript-detached-async-context-BKXaSw-L.mjs";import{o as r}from"./transcript-path-guards-u0N7Z9_x.mjs";import{t as i}from"./transcript-subsystem-C0UTtuvS.mjs";import a from"node:path";import{accessSync as o,constants as s,statSync as c}from"node:fs";import"node:fs/promises";import{spawnSync as l}from"node:child_process";const u=e(Symbol.for(`openclaw.childRuntimeViability`),()=>({observations:/* @__PURE__ */ new Map,initialPath:process.execPath,initialIdentity:executableIdentity(process.execPath)})),d=/(?:dyld[^\n]*:\s*Library not loaded:|error while loading shared libraries:)/i,f=/(?:dyld[^\n]*:\s*Symbol not found:|symbol lookup error:|Error loading shared library|version [`'"][^`'"\r\n]+[`'"] not found)/i;function executableIdentity(e){try{return formatExecutableIdentity(c(e))}catch{return}}function formatExecutableIdentity({dev:e,ino:t,size:n,mtimeMs:r,mode:i}){return`${e}:${t}:${n}:${r}:${i}`}function publishRuntimeViability(e,t){return(r(t,`ENOENT`)||r(t,`ENOTDIR`))&&recordUnavailableRuntime(e,t),{execPath:e,available:!(u.execPath===e&&u.failure)}}function readChildRuntimeViability(e){let t=e?.execPath??process.execPath;if(u.execPath===t&&u.failure)return{execPath:t,available:!1};try{o(t,s.X_OK)}catch(e){return publishRuntimeViability(t,e)}return publishRuntimeViability(t)}function recoverUnavailableRuntime(){if(u.execPath!==process.execPath||!u.failure||!u.recover||u.recoveryStarted)return;u.recoveryStarted=!0;let e=u.recover;n(()=>Promise.resolve().then(e).catch(()=>({status:`report-only`,reason:`Automatic runtime recovery is report-only: service or restart preparation failed. Inspect the service runtime and restart through its owner.`})).then(e=>{i(`gateway/runtime`).warn(`${e.status}: ${e.reason}`)}))}function runtimeProbeOptions(e={}){return{encoding:`utf8`,cwd:e.cwd??a.parse(process.execPath).root,env:e.env??{...process.env,NODE_OPTIONS:void 0},timeout:1e3,maxBuffer:8192}}function formatMissingChildRuntimeWarning(e){return e.available?void 0:`The Node.js runtime this Gateway started with (${t(e.execPath)}) can no longer start worker processes, likely because it was upgraded or removed. Restart the Gateway.`}function assertChildRuntimeAvailable(){if(u.execPath===process.execPath&&u.failure)throw u.failure}function recordUnavailableRuntime(e,t,n){if(u.execPath===e&&u.failure)return u.failure;u.execPath=e;let r=formatMissingChildRuntimeWarning({execPath:e,available:!1}),a=n?.trim();return u.failure=Object.assign(Error(a?`${r}\n${a}`:r,{cause:t}),{code:`NODE_RUNTIME_UNAVAILABLE`}),i(`gateway/runtime`).error(u.failure.message),recoverUnavailableRuntime(),u.failure}function needsRuntimeProbe(e){return!!(e.error||e.signal===`SIGABRT`||f.test(e.stderr??``))}function classifyRuntimeProbe(e,t,n,i){if(u.execPath===e&&u.failure)return u.failure;let a=e!==u.initialPath||n!==u.initialIdentity;return d.test(t.stderr)||f.test(t.stderr)||r(t.error,`ENOENT`)||r(t.error,`ENOTDIR`)||a&&(t.signal===`SIGABRT`||r(t.error,`ENOEXEC`)||r(t.error,`EACCES`)||r(t.error,`EPERM`))?recordUnavailableRuntime(e,i,t.stderr):void 0}function classifyChildRuntimeFailure(e){if(e.started)return;let t=e.execPath??process.execPath;if(u.execPath===t&&u.failure)return u.failure;if(d.test(e.stderr??``)||e.error&&!readChildRuntimeViability({execPath:t}).available)return recordUnavailableRuntime(t,e.error,e.stderr);if(needsRuntimeProbe(e))return classifyRuntimeProbe(t,l(t,[`--version`],runtimeProbeOptions()),t===u.initialPath?executableIdentity(t):void 0,e.error)}function observeChildRuntime(e,t=process.execPath){let n=!1,r,i=``;return e.once(`message`,()=>{n=!0,i=``}),e.on(`error`,e=>{r??=e}),e.stderr?.on(`data`,e=>{n||(i=(i+e.toString()).slice(-8192))}),()=>e.exitCode===0&&!r?void 0:classifyChildRuntimeFailure({execPath:t,error:r,stderr:i,signal:e.signalCode,started:n})}export{classifyChildRuntimeFailure as n,observeChildRuntime as r,assertChildRuntimeAvailable as t};