UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 5.84 kB
import{t as formatCliCommand}from"./command-format-D7KhNLP0.mjs";import{m as statIfExists,u as realpathOrResolve}from"./path-existence-BR9MXlgL.mjs";import{t as quoteCliArg}from"./quote-cli-arg-BUHoGELl.mjs";import path from"node:path"; //!src/daemon/node-version-prefix.ts const GATEWAY_NODE_PREFIX_SKEW=`gateway-node-prefix-skew`;const GATEWAY_NODE_VERSION_MISSING=`gateway-node-version-missing`;const GATEWAY_NODE_VERSION_INSPECT_FAILED=`gateway-node-version-inspect-failed`;const NODE_VERSION_CHANGE_CODES=/* @__PURE__ */ new Set([GATEWAY_NODE_PREFIX_SKEW,GATEWAY_NODE_VERSION_MISSING]);function isNodeVersionChangeIssue(e){return NODE_VERSION_CHANGE_CODES.has(e.code)}const VERSION_PREFIXES=[{manager:`nvm`,re:/^(.*\/\.nvm\/versions\/node\/(v[^/]+))(?:\/|$)/i,binary:`bin/node`},{manager:`fnm`,re:/^(.*\/\.?fnm\/node-versions\/(v[^/]+))(?:\/|$)/i,binary:`installation/bin/node`},{manager:`volta`,re:/^(.*\/\.volta\/tools\/image\/node\/([^/]+))(?:\/|$)/i,binary:`bin/node`},{manager:`asdf`,re:/^(.*\/\.asdf\/installs\/nodejs\/([^/]+))(?:\/|$)/i,binary:`bin/node`},{manager:`mise`,re:/^(.*\/mise\/installs\/node\/([^/]+))(?:\/|$)/i,binary:`bin/node`},{manager:`nodenv`,re:/^(.*\/\.nodenv\/versions\/([^/]+))(?:\/|$)/i,binary:`bin/node`},{manager:`nodebrew`,re:/^(.*\/\.nodebrew\/node\/(v[^/]+))(?:\/|$)/i,binary:`bin/node`}];function resolveNodeVersionPrefix(e){if(!e)return;const t=path.posix.normalize(e.replaceAll(`\\`,`/`));for(const e of VERSION_PREFIXES){const n=e.re.exec(t);const r=n?.[1];const i=n?.[2];if(!r||!i)continue;return{manager:e.manager,root:r,version:i}}}function sameNodeVersionPrefix(e,t){return e.manager===t.manager&&e.root.toLowerCase()===t.root.toLowerCase()}function nodeBinaryForPrefix(e){if(process.platform===`win32`&&e.manager===`fnm`)return`${e.root}/installation/node.exe`;const t=VERSION_PREFIXES.find(t=>t.manager===e.manager);return`${e.root}/${t?.binary??`bin/node`}`}function formatGatewayNodePrefixSkew(e,t){return`Gateway Node ${e.version} (${e.root}) does not own this install (${t.version} at ${t.root}). Removing the install's Node version stops the gateway before OpenClaw can start.`}function describeGatewayNodePrefixSkew(e){const t=resolveNodeVersionPrefix(e.nodePath);const n=resolveNodeVersionPrefix(e.packageRoot);if(!t||!n||sameNodeVersionPrefix(t,n))return;return formatGatewayNodePrefixSkew(t,n)}function describeGatewayNodeVersionRepair(e){const t=resolveNodeVersionPrefix(e.entrypointPath);const n=resolveNodeVersionPrefix(e.plannedNodePath);const r=Boolean(e.code===`gateway-node-prefix-skew`&&n&&t&&sameNodeVersionPrefix(n,t));const i=e.pinnedRuntimePath?.trim()||void 0;const a=e.plannedNodePath||e.recordedNodePath;const o=t?nodeBinaryForPrefix(t):void 0;const s=o?formatCliCommand(`openclaw gateway install --runtime-path ${quoteCliArg(o)} --force`):formatCliCommand(`openclaw gateway install --runtime-path <path> --force`);const c=formatCliCommand(`openclaw gateway install --force`);const l=formatCliCommand(`openclaw doctor --fix`);if(e.code===`gateway-node-version-missing`)return{resolvesSplit:false,remains:i?`An explicit runtime pin keeps ${i}.`:`Doctor keeps the service Node at ${a} because that binary still exists.`,action:`The package path is gone. Reinstall OpenClaw under a supported Node, then run \`${c}\` from that install.`};if(r&&e.plannedNodePath)return{resolvesSplit:true,remains:``,action:`Stop the service and rerun \`${l}\` to point it at ${e.plannedNodePath}.`};if(i)return{resolvesSplit:false,remains:`An explicit runtime pin keeps ${i}.`,action:`\`${l}\` reinstalls that pin. Replace it with the Node that owns this install: \`${s}\`.`};if(a)return{resolvesSplit:false,remains:`Doctor keeps this supported Node at ${a}.`,action:`\`${l}\` reinstalls that Node. Select the Node that owns this install with \`${s}\`.`};return{resolvesSplit:false,remains:`Doctor keeps a supported service Node and any explicit runtime pin.`,action:`\`${l}\` reinstalls that Node. Select the Node that owns this install with \`${s}\`.`}}function formatGatewayNodePrefixStartupWarning(e){const t=describeGatewayNodePrefixSkew(e);if(!t)return;const n=describeGatewayNodeVersionRepair({code:GATEWAY_NODE_PREFIX_SKEW,entrypointPath:e.packageRoot,recordedNodePath:e.nodePath});return`${t} ${n.remains} ${n.action}`}function formatInspectionError(e){return e instanceof Error&&e.message?e.message:`unknown filesystem error`}async function auditGatewayNodeVersionChange(e){const t=e.entrypointPath;const n=resolveNodeVersionPrefix(t);if(!t||!n)return;try{return await inspectGatewayNodeVersionChange({entrypoint:t,entryPrefix:n,nodePath:e.nodePath})}catch(e){return{code:GATEWAY_NODE_VERSION_INSPECT_FAILED,message:`Could not inspect whether the gateway Node and install share a version directory: ${formatInspectionError(e)}.`,level:`recommended`,repair:`host`}}}async function inspectGatewayNodeVersionChange(e){const t=e.nodePath;const n=t?await statIfExists(t)!==void 0:false;if(!await statIfExists(e.entrypoint)){if(!n||!t)return;return{code:GATEWAY_NODE_VERSION_MISSING,message:`Gateway install path is missing after a Node version change (${e.entrypoint}). The service Node binary still exists at ${t}.`,detail:e.entryPrefix.root,level:`recommended`}}const[r,i]=await Promise.all([n&&t?realpathOrResolve(t):Promise.resolve(t),realpathOrResolve(e.entrypoint)]);const a=resolveNodeVersionPrefix(r);const o=resolveNodeVersionPrefix(i);if(!a||!o||sameNodeVersionPrefix(a,o))return;return{code:GATEWAY_NODE_PREFIX_SKEW,message:formatGatewayNodePrefixSkew(a,o),detail:`${a.root} -> ${o.root}`,level:`recommended`}}export{describeGatewayNodeVersionRepair as a,auditGatewayNodeVersionChange as i,GATEWAY_NODE_VERSION_INSPECT_FAILED as n,formatGatewayNodePrefixStartupWarning as o,GATEWAY_NODE_VERSION_MISSING as r,isNodeVersionChangeIssue as s,GATEWAY_NODE_PREFIX_SKEW as t};