UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

288 lines (287 loc) • 9.99 kB
import "./logger-kwZIqwuw.js"; import "./paths-ViKUYWUK.js"; import "./tmp-openclaw-dir-idKIOMmb.js"; import "./theme-CdOoMzRk.js"; import "./globals-DBUMOBZ8.js"; import "./subsystem-DISldKSB.js"; import "./ansi-BEJF8NKS.js"; import "./boolean-C3GkJetE.js"; import "./env-Dnra1IpT.js"; import "./utils-CS0Ikux6.js"; import "./agent-scope-bjWqU22i.js"; import "./boundary-path-Dm0QJ7-y.js"; import "./boundary-file-read-DcZxlWD8.js"; import "./logger-BmpSCz93.js"; import "./exec-B5_AYfQG.js"; import "./workspace-D4K6QX9X.js"; import "./model-selection-BnFtDmP7.js"; import { Mt as ensureControlUiAllowedOriginsForNonLoopbackBind } from "./io-y3Az_Onx.js"; import "./shell-env-BOu7XeT_.js"; import "./safe-text-yavot2qw.js"; import "./version-CD3oP1-d.js"; import { d as resolveSecretInputRef, l as normalizeSecretInputString } from "./types.secrets-DgX397vI.js"; import "./env-substitution-O6uabUmO.js"; import "./includes-Bj3eLUWH.js"; import "./zod-schema.providers-core-COy5nBQ0.js"; import "./legacy-web-search-BB-ZHEhz.js"; import "./registry-C5UkPpaO.js"; import "./config-state-Br0ucqMb.js"; import "./min-host-version-RMBWtIAR.js"; import "./manifest-registry-B5JNQdOM.js"; import "./runtime-guard-PhQ6PwQa.js"; import "./avatar-policy-B5nOfso_.js"; import "./ip-Ce8EDTBZ.js"; import "./zod-schema.agent-runtime-Dtg4Jy6G.js"; import "./zod-schema.core-BuVz8Rk7.js"; import "./config-D4zN4BRl.js"; import "./audit-fs-DTQIjp2r.js"; import "./resolve-B7S4PlnO.js"; import { a as findTailscaleBinary } from "./tailscale-CxY-91GZ.js"; import "./tailnet-DHiKSG7V.js"; import "./net-JAg9zL0G.js"; import "./credentials-D8pfRimu.js"; import "./message-channel-BliByQBl.js"; import "./store-C5UK26Ce.js"; import "./runtime-Iz8uZ7EU.js"; import "./plugins-B09-vgme.js"; import "./sessions-D9ZgHCHb.js"; import "./paths-rhN9LKM_.js"; import "./session-write-lock-va3qZE6f.js"; import "./method-scopes-BiEi0X2g.js"; import "./call-CQbSO4Fr.js"; import "./control-ui-shared-BBhZvISc.js"; import { m as randomToken, u as normalizeGatewayTokenInput, y as validateGatewayPasswordInput } from "./onboard-helpers-D5cfC-Ra.js"; import "./prompt-style-C4CV4Y_p.js"; import "./provider-env-vars-CpUJqT5v.js"; import { t as resolveSecretInputModeForEnvSelection } from "./provider-auth-mode-DkhMmaR7.js"; import { n as promptSecretRefForSetup } from "./provider-auth-ref-CQEp9sp3.js"; import { t as resolveSetupSecretInputString } from "./setup.secret-input-DtZB3jrW.js"; import { t as DEFAULT_DANGEROUS_NODE_COMMANDS } from "./node-command-policy-Ceicw2bH.js"; import { a as maybeAddTailnetOriginToControlUiAllowedOrigins, i as TAILSCALE_MISSING_BIN_NOTE_LINES, n as TAILSCALE_DOCS_LINES, r as TAILSCALE_EXPOSURE_OPTIONS, t as validateIPv4AddressInput } from "./ipv4-C2Z4Fnda.js"; //#region src/wizard/setup.gateway-config.ts async function configureGatewayForSetup(opts) { const { flow, localPort, quickstartGateway, prompter } = opts; let { nextConfig } = opts; const port = flow === "quickstart" ? quickstartGateway.port : Number.parseInt(String(await prompter.text({ message: "Gateway port", initialValue: String(localPort), validate: (value) => Number.isFinite(Number(value)) ? void 0 : "Invalid port" })), 10); let bind = flow === "quickstart" ? quickstartGateway.bind : await prompter.select({ message: "Gateway bind", options: [ { value: "loopback", label: "Loopback (127.0.0.1)" }, { value: "lan", label: "LAN (0.0.0.0)" }, { value: "tailnet", label: "Tailnet (Tailscale IP)" }, { value: "auto", label: "Auto (Loopback → LAN)" }, { value: "custom", label: "Custom IP" } ] }); let customBindHost = quickstartGateway.customBindHost; if (bind === "custom") { if (flow !== "quickstart" || !customBindHost) { const input = await prompter.text({ message: "Custom IP address", placeholder: "192.168.1.100", initialValue: customBindHost ?? "", validate: validateIPv4AddressInput }); customBindHost = typeof input === "string" ? input.trim() : void 0; } } let authMode = flow === "quickstart" ? quickstartGateway.authMode : await prompter.select({ message: "Gateway auth", options: [{ value: "token", label: "Token", hint: "Recommended default (local + remote)" }, { value: "password", label: "Password" }], initialValue: "token" }); const tailscaleMode = flow === "quickstart" ? quickstartGateway.tailscaleMode : await prompter.select({ message: "Tailscale exposure", options: [...TAILSCALE_EXPOSURE_OPTIONS] }); let tailscaleBin = null; if (tailscaleMode !== "off") { tailscaleBin = await findTailscaleBinary(); if (!tailscaleBin) await prompter.note(TAILSCALE_MISSING_BIN_NOTE_LINES.join("\n"), "Tailscale Warning"); } let tailscaleResetOnExit = flow === "quickstart" ? quickstartGateway.tailscaleResetOnExit : false; if (tailscaleMode !== "off" && flow !== "quickstart") { await prompter.note(TAILSCALE_DOCS_LINES.join("\n"), "Tailscale"); tailscaleResetOnExit = Boolean(await prompter.confirm({ message: "Reset Tailscale serve/funnel on exit?", initialValue: false })); } if (tailscaleMode !== "off" && bind !== "loopback") { await prompter.note("Tailscale requires bind=loopback. Adjusting bind to loopback.", "Note"); bind = "loopback"; customBindHost = void 0; } if (tailscaleMode === "funnel" && authMode !== "password") { await prompter.note("Tailscale funnel requires password auth.", "Note"); authMode = "password"; } let gatewayToken; let gatewayTokenInput; if (authMode === "token") { const quickstartTokenString = normalizeSecretInputString(quickstartGateway.token); const quickstartTokenRef = resolveSecretInputRef({ value: quickstartGateway.token, defaults: nextConfig.secrets?.defaults }).ref; if ((flow === "quickstart" && opts.secretInputMode !== "ref" ? quickstartTokenRef ? "ref" : "plaintext" : await resolveSecretInputModeForEnvSelection({ prompter, explicitMode: opts.secretInputMode, copy: { modeMessage: "How do you want to provide the gateway token?", plaintextLabel: "Generate/store plaintext token", plaintextHint: "Default", refLabel: "Use SecretRef", refHint: "Store a reference instead of plaintext" } })) === "ref") if (flow === "quickstart" && quickstartTokenRef) { gatewayTokenInput = quickstartTokenRef; gatewayToken = await resolveSetupSecretInputString({ config: nextConfig, value: quickstartTokenRef, path: "gateway.auth.token", env: process.env }); } else { const resolved = await promptSecretRefForSetup({ provider: "gateway-auth-token", config: nextConfig, prompter, preferredEnvVar: "OPENCLAW_GATEWAY_TOKEN", copy: { sourceMessage: "Where is this gateway token stored?", envVarPlaceholder: "OPENCLAW_GATEWAY_TOKEN" } }); gatewayTokenInput = resolved.ref; gatewayToken = resolved.resolvedValue; } else if (flow === "quickstart") { gatewayToken = (quickstartTokenString ?? normalizeGatewayTokenInput(process.env.OPENCLAW_GATEWAY_TOKEN)) || randomToken(); gatewayTokenInput = gatewayToken; } else { gatewayToken = normalizeGatewayTokenInput(await prompter.text({ message: "Gateway token (blank to generate)", placeholder: "Needed for multi-machine or non-loopback access", initialValue: quickstartTokenString ?? normalizeGatewayTokenInput(process.env.OPENCLAW_GATEWAY_TOKEN) ?? "" })) || randomToken(); gatewayTokenInput = gatewayToken; } } if (authMode === "password") { let password = flow === "quickstart" && quickstartGateway.password ? quickstartGateway.password : void 0; if (!password) if (await resolveSecretInputModeForEnvSelection({ prompter, explicitMode: opts.secretInputMode, copy: { modeMessage: "How do you want to provide the gateway password?", plaintextLabel: "Enter password now", plaintextHint: "Stores the password directly in OpenClaw config" } }) === "ref") password = (await promptSecretRefForSetup({ provider: "gateway-auth-password", config: nextConfig, prompter, preferredEnvVar: "OPENCLAW_GATEWAY_PASSWORD", copy: { sourceMessage: "Where is this gateway password stored?", envVarPlaceholder: "OPENCLAW_GATEWAY_PASSWORD" } })).ref; else password = String(await prompter.text({ message: "Gateway password", validate: validateGatewayPasswordInput }) ?? "").trim(); nextConfig = { ...nextConfig, gateway: { ...nextConfig.gateway, auth: { ...nextConfig.gateway?.auth, mode: "password", password } } }; } else if (authMode === "token") nextConfig = { ...nextConfig, gateway: { ...nextConfig.gateway, auth: { ...nextConfig.gateway?.auth, mode: "token", token: gatewayTokenInput } } }; nextConfig = { ...nextConfig, gateway: { ...nextConfig.gateway, port, bind, ...bind === "custom" && customBindHost ? { customBindHost } : {}, tailscale: { ...nextConfig.gateway?.tailscale, mode: tailscaleMode, resetOnExit: tailscaleResetOnExit } } }; nextConfig = ensureControlUiAllowedOriginsForNonLoopbackBind(nextConfig, { requireControlUiEnabled: true }).config; nextConfig = await maybeAddTailnetOriginToControlUiAllowedOrigins({ config: nextConfig, tailscaleMode, tailscaleBin }); if (!quickstartGateway.hasExisting && nextConfig.gateway?.nodes?.denyCommands === void 0 && nextConfig.gateway?.nodes?.allowCommands === void 0 && nextConfig.gateway?.nodes?.browser === void 0) nextConfig = { ...nextConfig, gateway: { ...nextConfig.gateway, nodes: { ...nextConfig.gateway?.nodes, denyCommands: [...DEFAULT_DANGEROUS_NODE_COMMANDS] } } }; return { nextConfig, settings: { port, bind, customBindHost: bind === "custom" ? customBindHost : void 0, authMode, gatewayToken, tailscaleMode, tailscaleResetOnExit } }; } //#endregion export { configureGatewayForSetup };