openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
66 lines (65 loc) • 2.96 kB
JavaScript
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs";
import { n as parseTcpPort } from "./tcp-port-CuNPxuH-.mjs";
import { o as requireTlsFingerprint } from "./client-address-utils-Clpzy8Fr.mjs";
import { a as nodeHostCloudflareAccessConfigFromEnv, s as nodeHostGatewaysShareOrigin } from "./node-worker-prepared-workspace-publication-BHZAZGva.mjs";
import { n as decodePairingSetupCode } from "./setup-code-BZtNhry3.mjs";
//#region src/cli/node-cli/gateway-options.ts
function gatewayConfigFromUrl(e, t) {
const n = new URL(e);
const r = n.protocol === "wss:";
return {
host: n.hostname,
port: n.port ? Number.parseInt(n.port, 10) : r ? 443 : 80,
...n.pathname !== "/" ? { contextPath: n.pathname } : {},
tls: r,
...t ? { tlsFingerprint: t } : {}
};
}
function resolveNodePairGatewayOptions(e, t = {}) {
return resolveNodePairGatewayPayload(decodePairingSetupCode(e, t));
}
/** Project a validated pairing payload into the canonical node-host candidate list. */
function resolveNodePairGatewayPayload(e) {
const t = (e.urls ?? [e.url]).map((t) => gatewayConfigFromUrl(t, t === e.url ? e.tlsFingerprint : void 0));
const n = t[0];
return {
host: n.host,
port: n.port,
...n.contextPath ? { contextPath: n.contextPath } : {},
tls: n.tls,
...n.tlsFingerprint ? { tlsFingerprint: n.tlsFingerprint } : {},
bootstrapToken: e.bootstrapToken,
...e.expiresAtMs !== void 0 ? { expiresAtMs: e.expiresAtMs } : {},
candidates: t
};
}
function resolveNodeGatewayOptions(e, t, n, r = process.env) {
const i = n?.host ?? t?.gateway?.host ?? "127.0.0.1";
const a = n?.port ?? t?.gateway?.port ?? 18789;
const o = normalizeOptionalString(e.host) || i;
const s = e.port === void 0 ? a : parseTcpPort(e.port);
const c = o !== i || s !== null && s !== a;
const l = n?.tlsFingerprint ?? t?.gateway?.tlsFingerprint;
const u = e.tls === false ? void 0 : normalizeOptionalString(e.tlsFingerprint) ?? (c ? void 0 : l);
const d = n?.tls ?? t?.gateway?.tls;
const f = u ? requireTlsFingerprint(u) : void 0;
const p = typeof e.tls === "boolean" ? e.tls : Boolean(f) || (c ? void 0 : d);
const m = normalizeOptionalString(e.contextPath) ?? (e.contextPath !== void 0 || c ? void 0 : n?.contextPath ?? t?.gateway?.contextPath);
const h = e.host !== void 0 || e.port !== void 0 || e.contextPath !== void 0 || e.tls !== void 0 || e.tlsFingerprint !== void 0;
const g = !n || t?.gateway !== void 0 && nodeHostGatewaysShareOrigin(t.gateway, n.candidates[0]);
const _ = (!c && g ? t?.gateway?.cloudflareAccess : void 0) ?? nodeHostCloudflareAccessConfigFromEnv(r);
return {
host: o,
port: s,
contextPath: m,
tls: p,
tlsFingerprint: f,
cloudflareAccess: _,
gatewayCandidates: n && !h ? n.candidates.map((e, t) => t === 0 && _ ? {
...e,
cloudflareAccess: _
} : e) : void 0
};
}
//#endregion
export { resolveNodePairGatewayOptions as n, resolveNodePairGatewayPayload as r, resolveNodeGatewayOptions as t };