UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

71 lines (70 loc) 2.91 kB
import { t as formatErrorMessage } from "./errors-Db3Ymjlb.js"; import { n as gatewayInstallErrorHint, t as buildGatewayInstallPlan } from "./daemon-install-helpers-w30vR2Jt.js"; import { r as isGatewayDaemonRuntime } from "./daemon-runtime-CdTwKGNX.js"; import { t as resolveGatewayInstallToken } from "./gateway-install-token-09efDYo7.js"; import { m as isSystemdUserServiceAvailable } from "./systemd-exec-C9fneC4I.js"; import { o as resolveGatewayService } from "./service-Cc6NX6Jm.js"; import "./systemd-C1W5NZTY.js"; import { n as ensureSystemdUserLingerNonInteractive } from "./systemd-linger-5WlVACdb.js"; //#region src/commands/onboard-non-interactive/local/daemon-install.ts /** Installs the managed gateway daemon when non-interactive setup requested it. */ async function installGatewayDaemonNonInteractive(params) { const { opts, runtime, port } = params; if (!opts.installDaemon) return { installed: false }; const daemonRuntimeRaw = opts.daemonRuntime ?? "node"; const systemdAvailable = process.platform === "linux" ? await isSystemdUserServiceAvailable() : true; if (process.platform === "linux" && !systemdAvailable) { runtime.log("Systemd user services are unavailable; skipping service install. Use a direct shell run (`openclaw gateway run`) or rerun without --install-daemon on this session."); return { installed: false, skippedReason: "systemd-user-unavailable" }; } if (!isGatewayDaemonRuntime(daemonRuntimeRaw)) { runtime.error("Invalid --daemon-runtime. Use \"node\" or \"bun\"."); runtime.exit(1); return { installed: false }; } const service = resolveGatewayService(); const tokenResolution = await resolveGatewayInstallToken({ config: params.nextConfig, env: process.env }); for (const warning of tokenResolution.warnings) runtime.log(warning); if (tokenResolution.unavailableReason) { runtime.error([ "Gateway install blocked:", tokenResolution.unavailableReason, "Fix gateway auth config/token input and rerun setup." ].join(" ")); runtime.exit(1); return { installed: false }; } const existingCommand = await service.readCommand(process.env).catch(() => null); const { programArguments, workingDirectory, environment, environmentValueSources } = await buildGatewayInstallPlan({ env: process.env, port, runtime: daemonRuntimeRaw, existingCommand, warn: (message) => runtime.log(message), config: params.nextConfig }); try { await service.install({ env: process.env, stdout: process.stdout, programArguments, workingDirectory, environment, environmentValueSources }); } catch (err) { runtime.error(`Gateway service install failed: ${formatErrorMessage(err)}`); runtime.log(gatewayInstallErrorHint()); return { installed: false }; } await ensureSystemdUserLingerNonInteractive({ runtime }); return { installed: true }; } //#endregion export { installGatewayDaemonNonInteractive };