From bc299ae17e7c03e8033b78fcf2c63834f3d6ffbb Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 14 Feb 2026 21:59:42 +0000 Subject: [PATCH] refactor(wizard): dedupe gateway health check --- src/commands/configure.wizard.ts | 102 ++++++++++++------------------- 1 file changed, 40 insertions(+), 62 deletions(-) diff --git a/src/commands/configure.wizard.ts b/src/commands/configure.wizard.ts index 390626ced1..06b2dcd1a3 100644 --- a/src/commands/configure.wizard.ts +++ b/src/commands/configure.wizard.ts @@ -45,6 +45,44 @@ import { setupSkills } from "./onboard-skills.js"; type ConfigureSectionChoice = WizardSection | "__continue"; +async function runGatewayHealthCheck(params: { + cfg: OpenClawConfig; + runtime: RuntimeEnv; + port: number; +}): Promise { + const localLinks = resolveControlUiLinks({ + bind: params.cfg.gateway?.bind ?? "loopback", + port: params.port, + customBindHost: params.cfg.gateway?.customBindHost, + basePath: undefined, + }); + const remoteUrl = params.cfg.gateway?.remote?.url?.trim(); + const wsUrl = params.cfg.gateway?.mode === "remote" && remoteUrl ? remoteUrl : localLinks.wsUrl; + const token = params.cfg.gateway?.auth?.token ?? process.env.OPENCLAW_GATEWAY_TOKEN; + const password = params.cfg.gateway?.auth?.password ?? process.env.OPENCLAW_GATEWAY_PASSWORD; + + await waitForGatewayReachable({ + url: wsUrl, + token, + password, + deadlineMs: 15_000, + }); + + try { + await healthCommand({ json: false, timeoutMs: 10_000 }, params.runtime); + } catch (err) { + params.runtime.error(formatHealthCheckFailure(err)); + note( + [ + "Docs:", + "https://docs.openclaw.ai/gateway/health", + "https://docs.openclaw.ai/gateway/troubleshooting", + ].join("\n"), + "Health check help", + ); + } +} + async function promptConfigureSection( runtime: RuntimeEnv, hasSelection: boolean, @@ -368,37 +406,7 @@ export async function runConfigureWizard( } if (selected.includes("health")) { - const localLinks = resolveControlUiLinks({ - bind: nextConfig.gateway?.bind ?? "loopback", - port: gatewayPort, - customBindHost: nextConfig.gateway?.customBindHost, - basePath: undefined, - }); - const remoteUrl = nextConfig.gateway?.remote?.url?.trim(); - const wsUrl = - nextConfig.gateway?.mode === "remote" && remoteUrl ? remoteUrl : localLinks.wsUrl; - const token = nextConfig.gateway?.auth?.token ?? process.env.OPENCLAW_GATEWAY_TOKEN; - const password = - nextConfig.gateway?.auth?.password ?? process.env.OPENCLAW_GATEWAY_PASSWORD; - await waitForGatewayReachable({ - url: wsUrl, - token, - password, - deadlineMs: 15_000, - }); - try { - await healthCommand({ json: false, timeoutMs: 10_000 }, runtime); - } catch (err) { - runtime.error(formatHealthCheckFailure(err)); - note( - [ - "Docs:", - "https://docs.openclaw.ai/gateway/health", - "https://docs.openclaw.ai/gateway/troubleshooting", - ].join("\n"), - "Health check help", - ); - } + await runGatewayHealthCheck({ cfg: nextConfig, runtime, port: gatewayPort }); } } else { let ranSection = false; @@ -495,37 +503,7 @@ export async function runConfigureWizard( } if (choice === "health") { - const localLinks = resolveControlUiLinks({ - bind: nextConfig.gateway?.bind ?? "loopback", - port: gatewayPort, - customBindHost: nextConfig.gateway?.customBindHost, - basePath: undefined, - }); - const remoteUrl = nextConfig.gateway?.remote?.url?.trim(); - const wsUrl = - nextConfig.gateway?.mode === "remote" && remoteUrl ? remoteUrl : localLinks.wsUrl; - const token = nextConfig.gateway?.auth?.token ?? process.env.OPENCLAW_GATEWAY_TOKEN; - const password = - nextConfig.gateway?.auth?.password ?? process.env.OPENCLAW_GATEWAY_PASSWORD; - await waitForGatewayReachable({ - url: wsUrl, - token, - password, - deadlineMs: 15_000, - }); - try { - await healthCommand({ json: false, timeoutMs: 10_000 }, runtime); - } catch (err) { - runtime.error(formatHealthCheckFailure(err)); - note( - [ - "Docs:", - "https://docs.openclaw.ai/gateway/health", - "https://docs.openclaw.ai/gateway/troubleshooting", - ].join("\n"), - "Health check help", - ); - } + await runGatewayHealthCheck({ cfg: nextConfig, runtime, port: gatewayPort }); } }