openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
62 lines (61 loc) • 2.54 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { t as formatErrorMessage } from "./errors-BKzCeTYb.mjs";
import { n as getActiveManagedProxyTlsOptions, r as getActiveManagedProxyUrl } from "./active-proxy-state-LRlZWsqe.mjs";
import { s as resolveEnvHttpProxyUrl } from "./proxy-env-CZP0dXDG.mjs";
import { readFileSync } from "node:fs";
import { readFile as readFile$1 } from "node:fs/promises";
//#region src/infra/net/proxy/proxy-tls.ts
/** Returns a CA file only for HTTPS proxy URLs; HTTP proxies do not need TLS trust. */
function resolveManagedProxyCaFileForUrl(e) {
if (!e.proxyUrl || URL.parse(e.proxyUrl)?.protocol !== "https:") return;
return normalizeOptionalString(e.caFileOverride) ?? normalizeOptionalString(e.config?.tls?.caFile);
}
/** Loads managed proxy TLS options asynchronously for startup paths. */
async function loadManagedProxyTlsOptions(e) {
if (!e) return;
try {
return { ca: await readFile$1(e, "utf8") };
} catch (t) {
throw new Error(`proxy CA file could not be read (${e}): ${formatErrorMessage(t)}`, { cause: t });
}
}
/** Loads managed proxy TLS options synchronously for inherited child-process routing. */
function loadManagedProxyTlsOptionsSync(e) {
if (!e) return;
try {
return { ca: readFileSync(e, "utf8") };
} catch (t) {
throw new Error(`proxy CA file could not be read (${e}): ${formatErrorMessage(t)}`, { cause: t });
}
}
//#endregion
//#region src/infra/net/proxy/active-managed-proxy-tls.ts
function normalizeProxyUrl(e) {
return e ? URL.parse(e)?.href : void 0;
}
function resolveManagedProxyUrl(e = process.env) {
const t = getActiveManagedProxyUrl();
if (t) return t.href;
if (e.OPENCLAW_PROXY_ACTIVE !== "1") return;
return normalizeProxyUrl(resolveEnvHttpProxyUrl("https", e));
}
/** Resolves managed proxy TLS trust only when the target proxy is OpenClaw's active proxy. */
function resolveActiveManagedProxyTlsOptions(e) {
const t = e?.env ?? process.env;
const n = resolveManagedProxyUrl(t);
const r = normalizeProxyUrl(e?.proxyUrl ?? resolveEnvHttpProxyUrl("https", t));
if (!n || r !== n) return;
const i = getActiveManagedProxyTlsOptions();
if (i) return i;
const a = resolveManagedProxyCaFileForUrl({
proxyUrl: n,
caFileOverride: t.OPENCLAW_PROXY_CA_FILE
});
try {
return loadManagedProxyTlsOptionsSync(a);
} catch {
return;
}
}
//#endregion
export { resolveManagedProxyCaFileForUrl as i, loadManagedProxyTlsOptions as n, loadManagedProxyTlsOptionsSync as r, resolveActiveManagedProxyTlsOptions as t };