UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

4 lines • 5.78 kB
#!/usr/bin/env node import{c as resolveOpenClawCliInvocation,l as resolveOpenClawCliRespawn}from"./cli-invocation-Covx3kvQ.mjs";import{n as resolveOpenClawCompileCacheDirectory,r as resolveOpenClawCompileCacheRespawnEnv,t as enableOpenClawCompileCache}from"./node-compile-cache-BwC4XsKs.mjs";import{r as isForegroundGatewayRunArgv}from"./gateway-run-argv-Cz2rb_aK.mjs";import{t as resolveCliArgvInvocation}from"./argv-invocation-aH4sq40s.mjs";import{t as resolveCliDatabaseProcessRole}from"./database-process-role-BvZWvAnO.mjs";import{i as shouldKeepNativeHookRelayInProcess,t as isForegroundGmailRunArgv}from"./respawn-policy-D0mqiUo0.mjs";import{n as tryRunUpdateAdmissionBeforeStartup}from"./run-main-update-admission-D5qWSNLu.mjs";import"./detached-async-context-DLLuWsxc.mjs";import{i as createGatewayDispatchStartupTrace,n as configureGatewayStartupTraceConsoleFormatting}from"./startup-trace-CnJbL2Y9.mjs";import{t as normalizeWindowsArgv}from"./windows-argv-BJOcchA4.mjs";import{r as installDatabaseProcessRole}from"./admission-scope-Xl89MEui.mjs";import{t as isMainModule}from"./is-main-DX3ahFXh.mjs";import{existsSync}from"node:fs";import process from"node:process";import{fileURLToPath}from"node:url"; //!src/index.ts const isMain=isMainModule({currentFile:fileURLToPath(import.meta.url)});if(isMain)installDatabaseProcessRole(resolveCliDatabaseProcessRole(normalizeWindowsArgv(process.argv)));const handledAdmission=isMain&&await tryRunUpdateAdmissionBeforeStartup(resolveCliArgvInvocation(process.argv));const packageRootUrl=new URL(`../`,import.meta.url);if(!handledAdmission&&!existsSync(new URL(`entry.ts`,import.meta.url))&&(existsSync(new URL(`.openclaw-lifecycle-pending`,packageRootUrl))||existsSync(new URL(`dist/openclaw-install-guard`,packageRootUrl)))){const{completePendingPackageLifecycle:e}=await import(`./infra/package-lifecycle.js`);try{await e({packageRoot:fileURLToPath(packageRootUrl)})}catch(e){throw new Error(`OpenClaw package lifecycle is incomplete. Reinstall with package scripts enabled, then retry. ${e instanceof Error?e.message:String(e)}`,{cause:e})}}let applyTemplate;let createDefaultDeps;let deriveSessionKey;let describePortOwner;let ensureBinary;let ensurePortAvailable;let getReplyFromConfig;let handlePortError;let loadConfig;let monitorWebChannel;let normalizeE164;let PortInUseError;let promptYesNo;let resolveSessionKey;let resolveStorePath;let runCommandWithTimeout;let runExec;let waitForever;async function loadLegacyCliDeps(e){const t=createGatewayDispatchStartupTrace(e,`entry`);await configureGatewayStartupTraceConsoleFormatting(t);const{runCli:n}=await t.measure(`run-main-import`,()=>import(`./cli/run-main.js`));return{runCli:n}}async function runLegacyCliEntry(e=process.argv,t,n){const{runCli:r}=t??await loadLegacyCliDeps(e);await r(e,n)}const handledRootVersion=isMain&&!handledAdmission&&(await import(`./entry.version-fast-path-oUacUqZc.mjs`)).tryHandleRootVersionFastPath(process.argv);if(!isMain)({applyTemplate,createDefaultDeps,deriveSessionKey,describePortOwner,ensureBinary,ensurePortAvailable,getReplyFromConfig,handlePortError,loadConfig,monitorWebChannel,normalizeE164,PortInUseError,promptYesNo,resolveSessionKey,resolveStorePath,runCommandWithTimeout,runExec,waitForever}=await import(`./library-n6PkFg2d.mjs`));const shouldRunCli=isMain&&!handledRootVersion&&!handledAdmission;const compileCacheDirectory=shouldRunCli?resolveOpenClawCompileCacheDirectory({installRoot:fileURLToPath(packageRootUrl),foregroundGateway:isForegroundGatewayRunArgv(process.argv)}):void 0;const compileCacheRespawnEnv=shouldRunCli&&!isForegroundGmailRunArgv(process.argv)&&!shouldKeepNativeHookRelayInProcess(process.argv,process.platform)?resolveOpenClawCompileCacheRespawnEnv({directory:compileCacheDirectory,foregroundGateway:isForegroundGatewayRunArgv(process.argv)}):void 0;if(compileCacheRespawnEnv){const{command:e,args:t}=resolveOpenClawCliInvocation({entryPath:fileURLToPath(import.meta.url)});if(process.platform!==`win32`&&process.execve&&isForegroundGatewayRunArgv(process.argv))process.execve(e,[e,...t],compileCacheRespawnEnv);const{runRespawnedChild:n}=await import(`./node-runtime-recovery-Cp9bcNa8.mjs`);await n(resolveOpenClawCliRespawn({entryPath:fileURLToPath(import.meta.url),env:compileCacheRespawnEnv}))}if(shouldRunCli&&!compileCacheRespawnEnv){enableOpenClawCompileCache({directory:compileCacheDirectory,foregroundGateway:isForegroundGatewayRunArgv(process.argv)});const[{formatCliFailureLines:e,formatCliJsonFailure:t,installCliUncaughtExceptionHandler:n,isExpectedCliError:r},{isJsonOutputModeActive:i},{runCliWithExitFinalization:a},{withCliProcessScope:o},{runFatalErrorHooks:s},{installUnhandledRejectionHandler:c}]=await Promise.all([import(`./failure-output-DGT6T_zF.mjs`),import(`./json-output-mode-D0MKcXgn.mjs`),import(`./one-shot-exit-BH4i-9U_.mjs`),import(`./runtime-cleanup-scope-BT-O2UIL.mjs`),import(`./fatal-error-hooks-CvUABl2N.mjs`),import(`./unhandled-rejections-CubbuaUl.mjs`)]);const{defaultRuntime:l,restoreRuntimeTerminalState:u}=await import(`./runtime-BQCaxGKj.mjs`);c();n();a({run:()=>o(()=>runLegacyCliEntry(process.argv,void 0,{retainConsoleRoutingUntilProcessExit:true})),onError:n=>{if(i(process.argv))l.writeJson(t(n));for(const t of e({title:`The CLI command failed.`,error:n,argv:process.argv}))console.error(t);if(!r(n))for(const e of s({reason:`legacy_cli_failure`,error:n}))console.error(`[openclaw]`,e);u(`legacy cli failure`);process.exitCode=1}})}export{PortInUseError,applyTemplate,createDefaultDeps,deriveSessionKey,describePortOwner,ensureBinary,ensurePortAvailable,getReplyFromConfig,handlePortError,loadConfig,monitorWebChannel,normalizeE164,promptYesNo,resolveSessionKey,resolveStorePath,runCommandWithTimeout,runExec,runLegacyCliEntry,waitForever};