UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.9 kB
import{r as resolveStateDir}from"./state-dir-BwIClCab.mjs";import"./paths-D_FOvGon.mjs";import process from"node:process";import path from"node:path";import{randomUUID}from"node:crypto";import{createAmbientNodeProxyAgent}from"@openclaw/proxyline"; //!src/proxy-capture/env.ts function resolveDebugProxyRootDir(e=process.env){return path.join(resolveStateDir(e),`debug-proxy`)}function resolveDebugProxyCertDir(e=process.env){return path.join(resolveDebugProxyRootDir(e),`certs`)}const OPENCLAW_DEBUG_PROXY_ENABLED=`OPENCLAW_DEBUG_PROXY_ENABLED`;const OPENCLAW_DEBUG_PROXY_URL=`OPENCLAW_DEBUG_PROXY_URL`;const OPENCLAW_DEBUG_PROXY_CERT_DIR=`OPENCLAW_DEBUG_PROXY_CERT_DIR`;const OPENCLAW_DEBUG_PROXY_SESSION_ID=`OPENCLAW_DEBUG_PROXY_SESSION_ID`;const OPENCLAW_DEBUG_PROXY_REQUIRE=`OPENCLAW_DEBUG_PROXY_REQUIRE`;const DEBUG_PROXY_CHILD_CAPTURE_USERNAME=`openclaw-capture`;function readDebugProxyChildEndpoint(e=process.env){const t=URL.parse(e[OPENCLAW_DEBUG_PROXY_URL]?.trim()??``);return t?.username===`openclaw-capture`?t:void 0}let cachedImplicitSessionId;function isTruthy(e){return e===`1`||e===`true`||e===`yes`||e===`on`}function resolveDebugProxySettings(e=process.env){const t=isTruthy(e[OPENCLAW_DEBUG_PROXY_ENABLED]);const n=e[OPENCLAW_DEBUG_PROXY_SESSION_ID]?.trim()||void 0;const r=readDebugProxyChildEndpoint(e);const i=n??(cachedImplicitSessionId??=randomUUID());return{enabled:t,required:isTruthy(e[OPENCLAW_DEBUG_PROXY_REQUIRE]),proxyUrl:r?.origin??(e[OPENCLAW_DEBUG_PROXY_URL]?.trim()||void 0),dbPath:path.join(resolveDebugProxyRootDir(e),`capture.sqlite`),blobDir:path.join(resolveDebugProxyRootDir(e),`blobs`),certDir:e[OPENCLAW_DEBUG_PROXY_CERT_DIR]?.trim()||resolveDebugProxyCertDir(e),sessionId:i,sourceProcess:`openclaw`}}function resolveEnabledDebugProxySettings(e){if(!(e?.enabled??isTruthy(process.env[OPENCLAW_DEBUG_PROXY_ENABLED])))return;return e??resolveDebugProxySettings()}function applyDebugProxyEnv(e,t){return{...e,[OPENCLAW_DEBUG_PROXY_ENABLED]:`1`,[OPENCLAW_DEBUG_PROXY_REQUIRE]:`1`,[OPENCLAW_DEBUG_PROXY_URL]:t.proxyUrl,[OPENCLAW_DEBUG_PROXY_CERT_DIR]:t.certDir??resolveDebugProxyCertDir(e),[OPENCLAW_DEBUG_PROXY_SESSION_ID]:t.sessionId,HTTP_PROXY:t.proxyUrl,HTTPS_PROXY:t.proxyUrl,ALL_PROXY:t.proxyUrl}}function createDebugProxyWebSocketAgent(e){if(!e.enabled||!e.proxyUrl)return;return createAmbientNodeProxyAgent({protocol:`https`,env:{HTTP_PROXY:e.proxyUrl,HTTPS_PROXY:e.proxyUrl,ALL_PROXY:void 0,NO_PROXY:void 0,http_proxy:void 0,https_proxy:void 0,all_proxy:void 0,no_proxy:void 0}})}function resolveEffectiveDebugProxyUrl(e){const t=e?.trim();if(t)return t;return resolveEnabledDebugProxySettings()?.proxyUrl}export{resolveDebugProxySettings as a,readDebugProxyChildEndpoint as i,applyDebugProxyEnv as n,resolveEffectiveDebugProxyUrl as o,createDebugProxyWebSocketAgent as r,resolveEnabledDebugProxySettings as s,DEBUG_PROXY_CHILD_CAPTURE_USERNAME as t};