openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
5 lines • 3.35 kB
JavaScript
import{t as formatCliCommand}from"./command-format-D7KhNLP0.mjs";import{r as hasEnvHttpProxyConfigured}from"./proxy-env-C0Jh7bHZ.mjs";import{n as resolveGatewayService}from"./service-Bz63n2ee.mjs";import{t as note}from"./note-e4DtVgg2.mjs";import{t as probeManagedProxyLoopback}from"./proxy-validation-Cp9RuGTB.mjs";import{l as shouldManageGatewayService}from"./doctor-service-repair-policy-gYXaFNLg.mjs";import tls from"node:tls";
//!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`];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(`
`),`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(`
`),`Web fetch proxy`)}export{noteWebFetchProxyDiagnostic};