UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

85 lines (84 loc) • 3.83 kB
import { t as formatCliCommand } from "./command-format-CqdwUgPk.mjs"; import { r as hasEnvHttpProxyConfigured } from "./proxy-env-CZP0dXDG.mjs"; import { n as resolveGatewayService } from "./service-hQiIzcTo.mjs"; import { t as note } from "./note-CnLgHvug.mjs"; import { t as probeManagedProxyLoopback } from "./proxy-validation-BE9qXMDB.mjs"; import { l as shouldManageGatewayService } from "./doctor-service-repair-policy-DAuL0W8-.mjs"; import tls from "node:tls"; //#region src/commands/doctor-web-fetch-proxy.ts const DIRECT_PROBE_HOST = "docs.openclaw.ai"; const DIRECT_PROBE_PORT = 443; const DIRECT_PROBE_TIMEOUT_MS = 3e3; const HTTP_PROXY_ENV_KEYS = [ "HTTP_PROXY", "HTTPS_PROXY", "http_proxy", "https_proxy" ]; /** Emits a managed-loopback failure or the web_fetch proxy diagnostic when relevant. */ async function noteWebFetchProxyDiagnostic(e) { if (e.cfg.gateway?.mode === "remote") return; const t = e.env ?? process.env; if (await probeManagedProxyLoopback({ config: e.cfg.proxy, env: t }).catch(() => false) === false) { const n = e.cfg.proxy?.loopbackMode ?? t.OPENCLAW_PROXY_LOOPBACK_MODE; const r = n === "proxy" || n === "block" ? [`- proxy.loopbackMode=${n} prevents direct local routing. Restore it with:`, ` ${formatCliCommand("openclaw config set proxy.loopbackMode gateway-only")}`] : [ "- Temporarily disable managed routing to recover local connections:", ` ${formatCliCommand("openclaw config set proxy.enabled false")}`, "- If external traffic requires a proxy, keep HTTP_PROXY/HTTPS_PROXY and set NO_PROXY=127.0.0.1,localhost,::1 in the Gateway service environment." ]; note([ "- Managed proxy routing (proxy.enabled) is active, but a request to this process's loopback listener failed. This can cause WebChat/Codex handshake errors or 502 responses.", `- Inspect the proxy configuration: ${formatCliCommand("openclaw config get proxy")}`, ...r, `- Apply the change: ${formatCliCommand("openclaw gateway restart")}` ].join("\n"), "Managed proxy loopback"); return; } if (e.cfg.tools?.web?.fetch?.enabled === false || e.cfg.tools?.web?.fetch?.useTrustedEnvProxy === true) return; const n = resolveGatewayService(); const r = []; if (hasEnvHttpProxyConfigured("https", t)) r.push({ env: t, label: "doctor process" }); if (await shouldManageGatewayService(t)) { const e = (await n.readCommand(t).catch(() => null))?.environment; if (e && hasEnvHttpProxyConfigured("https", e)) r.push({ env: e, label: "installed Gateway service" }); } if (r.length === 0) return; const i = await new Promise((e) => { const t = tls.connect({ host: DIRECT_PROBE_HOST, port: DIRECT_PROBE_PORT, servername: DIRECT_PROBE_HOST, timeout: DIRECT_PROBE_TIMEOUT_MS }); const finish = (n) => { t.destroy(); e(n); }; t.once("secureConnect", () => finish("reachable")); t.once("timeout", () => finish("unreachable")); t.once("error", () => finish("unreachable")); }); const a = r.map((e) => { const t = HTTP_PROXY_ENV_KEYS.filter((t) => Boolean(e.env[t]?.trim())); return `- HTTP(S) proxy environment detected in the ${e.label}: ${t.join(", ")}.`; }); note([ ...a, "- web_fetch still uses direct connections because tools.web.fetch.useTrustedEnvProxy is not enabled.", `- Direct TLS connectivity to ${DIRECT_PROBE_HOST}:${DIRECT_PROBE_PORT} ${i === "reachable" ? "succeeded" : "failed"}.`, "- If direct web_fetch requests time out and the proxy is operator-controlled, enable the explicit opt-in:", ` ${formatCliCommand("openclaw config set tools.web.fetch.useTrustedEnvProxy true")}`, "- Keep the opt-in disabled for untrusted proxies; enabling it lets the proxy resolve DNS after OpenClaw's hostname checks." ].join("\n"), "Web fetch proxy"); } //#endregion export { noteWebFetchProxyDiagnostic };