openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 4.6 kB
JavaScript
import{a as isStandaloneRuntimeExecutable}from"./cli-invocation-Covx3kvQ.mjs";import{r as resolveOpenClawPackageRootSync}from"./openclaw-root-DP80HYD2.mjs";import{a as resolveBunRuntimeInfo,c as resolvePreferredBunPath,f as resolveSystemNodeInfo,i as renderSystemNodeWarning,l as resolvePreferredNodePath,o as resolveNodeRuntimeInfo,s as resolvePinnedDaemonRuntimePath}from"./runtime-paths-BOio2Rt6.mjs";import{a as isDisposableInstallPath,o as resolveDurableServiceBinDir,s as resolveDurableServiceCli}from"./durable-service-entrypoint-CYy_WbI9.mjs";import fs from"node:fs";import path from"node:path";
//!src/commands/daemon-install-plan.shared.ts
function resolveGatewayDevMode(){const e=process.argv[1]?.replaceAll(`\\`,`/`);return e!==void 0&&e.includes(`/src/`)&&e.endsWith(`.ts`)}async function resolveRunningBunFallback(e){if(!process.versions.bun)return;if((e.nodePath===void 0?await resolvePreferredNodePath({env:e.env,runtime:`node`}):e.nodePath)||(await resolveBunRuntimeInfo(process.execPath,e.env)).status!==`supported`)return;return process.execPath}async function resolveDaemonInstallRuntimeInputs(e){const t=e.devMode??resolveGatewayDevMode();if(e.wrapperPath?.trim())return{devMode:t,runtime:e.runtime,runtimePath:e.runtimePath};if(e.runtime===`standalone`){const t=e.pinnedRuntimePath??e.runtimePath??(isStandaloneRuntimeExecutable()?process.execPath:void 0);if(!t)throw new Error(`Standalone services require --runtime-path pointing to a complete standalone artifact.`);return{devMode:false,runtime:`standalone`,runtimePath:await resolvePinnedDaemonRuntimePath(t,`standalone`,e.env)}}const n=(e.pinnedRuntimePath===void 0?void 0:await resolvePinnedDaemonRuntimePath(e.pinnedRuntimePath,e.runtime,e.env))??e.runtimePath??(e.runtime===`bun`?await resolvePreferredBunPath({env:e.env,runtime:e.runtime}):await resolvePreferredNodePath({env:e.env,runtime:e.runtime}));if(e.runtime===`node`&&!e.runtimeExplicit&&e.pinnedRuntimePath===void 0&&e.runtimePath===void 0&&n===void 0){const n=await resolveRunningBunFallback({env:e.env,nodePath:null});if(n){e.warn?.(`No supported Node runtime was found; using the running Bun for the service.`);return{devMode:t,runtime:`bun`,runtimePath:n}}}return{devMode:t,runtime:e.runtime,runtimePath:n}}function runsCliEntrypoint(e){return!e.wrapperPath?.trim()&&e.runtime!==`standalone`}async function resolveDaemonInstallPlanInputs(e){const t=await resolveDaemonInstallRuntimeInputs({...e,devMode:e.serviceCli?false:e.devMode});const n=e.serviceCli?.entrypoint;const r=n||t.devMode||!runsCliEntrypoint({...t,wrapperPath:e.wrapperPath})?void 0:await resolveDurableServiceCli(e.env,{install:e.installDurableCli===true,service:e.service});return{...t,cliEntrypoint:n??r?.entrypoint,...r?.replacement?{durableCliReplacement:r.replacement}:{}}}function resolveDaemonRuntimeBinDir(e){const t=e?.trim();if(!t||!path.isAbsolute(t))return;return[path.dirname(t)]}function safeRealpathSync(e){try{return fs.realpathSync.native(e)}catch{return}}function resolveDaemonServicePathDirs(e){const t=e.platform??process.platform;const n=e.argv??process.argv;const r=e.env??process.env;const i=n[1]?.trim();const a=new Set(resolveDaemonRuntimeBinDir(e.runtimePath));const addDurable=e=>{if(!isDisposableInstallPath(safeRealpathSync(e)??path.resolve(e)))a.add(e)};const o=path.basename(i??``);const s=i&&isDisposableInstallPath(safeRealpathSync(i)??path.resolve(i))?resolveDurableServiceBinDir(r,t,{planned:e.durableCliPlanned}):void 0;if(s)a.add(s);if(i&&path.isAbsolute(i)&&(o===`openclaw`||t===`win32`&&[`openclaw.cmd`,`openclaw.ps1`,`openclaw.exe`].includes(o)))addDurable(path.dirname(i));const c=i&&path.isAbsolute(i)?safeRealpathSync(i):void 0;for(const e of(r.PATH??``).split(path.delimiter)){const n=e.trim();if(!path.isAbsolute(n))continue;const r=path.join(n,t===`win32`?`openclaw.cmd`:`openclaw`);if(!fs.existsSync(r))continue;const i=safeRealpathSync(r);if(c&&i&&i!==c){const e=resolveOpenClawPackageRootSync({argv1:c});if(!e||resolveOpenClawPackageRootSync({argv1:i})!==e)continue}addDurable(n)}return a.size>0?[...a]:void 0}
//!src/commands/daemon-install-runtime-warning.ts
async function emitNodeRuntimeWarning(e){if(e.runtime!==`node`)return;const t=await resolveSystemNodeInfo({env:e.env});const n=renderSystemNodeWarning(t,e.nodeProgram);if(n&&(!e.nodeProgram||e.nodeProgram===t?.path||(await resolveNodeRuntimeInfo(e.nodeProgram,e.env)).status!==`supported`))e.warn?.(n,e.title)}export{resolveRunningBunFallback as a,resolveDaemonServicePathDirs as i,resolveDaemonInstallPlanInputs as n,resolveDaemonRuntimeBinDir as r,emitNodeRuntimeWarning as t};