UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

116 lines (115 loc) • 6.39 kB
#!/usr/bin/env node import { c as resolveOpenClawCliRespawn, s as resolveOpenClawCliInvocation } from "./cli-invocation-ZSPsKRWa.mjs"; import { n as resolveOpenClawCompileCacheDirectory, r as resolveOpenClawCompileCacheRespawnEnv, t as enableOpenClawCompileCache } from "./node-compile-cache-BodUgF6I.mjs"; import { r as isForegroundGatewayRunArgv } from "./gateway-run-argv-DfcBAs2-.mjs"; import { t as resolveCliArgvInvocation } from "./argv-invocation-C9SmXUsh.mjs"; import { t as resolveCliDatabaseProcessRole } from "./database-process-role-MptgTPr9.mjs"; import { i as shouldKeepNativeHookRelayInProcess, t as isForegroundGmailRunArgv } from "./respawn-policy-LFXoiOm5.mjs"; import { n as tryRunUpdateAdmissionBeforeStartup } from "./run-main-update-admission-2cBv_sw3.mjs"; import "./detached-async-context-D_mi-wUl.mjs"; import { i as createGatewayDispatchStartupTrace, n as configureGatewayStartupTraceConsoleFormatting } from "./startup-trace-DWZsuODq.mjs"; import { t as normalizeWindowsArgv } from "./windows-argv-Co4garuq.mjs"; import { r as installDatabaseProcessRole } from "./admission-scope-DmxaPNhm.mjs"; import { t as isMainModule } from "./is-main-DHs8alyJ.mjs"; import { existsSync } from "node:fs"; import process from "node:process"; import { fileURLToPath } from "node:url"; //#region 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-BNyLVi_Q.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-8oqmEJuo.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-DkL1Uw9l.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, handleCliUncaughtException: n, isExpectedCliError: r }, { isJsonOutputModeActive: i }, { runCliWithExitFinalization: a }, { withCliProcessScope: o }, { runFatalErrorHooks: s }, { installUnhandledRejectionHandler: c }] = await Promise.all([ import("./failure-output-DKniP608.mjs"), import("./json-output-mode-hTr0tmcB.mjs"), import("./one-shot-exit-DGkIdz5q.mjs"), import("./runtime-cleanup-scope-CYOx21nX.mjs"), import("./fatal-error-hooks-CCvI6sHb.mjs"), import("./unhandled-rejections-C3_E5_Ob.mjs") ]); const { defaultRuntime: l, restoreRuntimeTerminalState: u } = await import("./runtime-PcIG_sHE.mjs"); c(); process.on("uncaughtException", (e) => { n(e); }); 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; } }); } //#endregion export { PortInUseError, applyTemplate, createDefaultDeps, deriveSessionKey, describePortOwner, ensureBinary, ensurePortAvailable, getReplyFromConfig, handlePortError, loadConfig, monitorWebChannel, normalizeE164, promptYesNo, resolveSessionKey, resolveStorePath, runCommandWithTimeout, runExec, runLegacyCliEntry, waitForever };