UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

49 lines (48 loc) • 2.85 kB
import { b as resolveGatewayPort } from "./paths-DAcAg5aV.mjs"; import { s as isLoopbackHost } from "./net-BgRayX-P.mjs"; import "./gateway-config-runtime-B8ERw-mA.mjs"; import "./ssrf-runtime-B6q6NM4E.mjs"; import { a as resolveFirstExtensionProfileName, i as resolveBrowserConfig, s as resolveProfile } from "./config-ccOD-Wrr.mjs"; import { t as ensureExtensionRelayToken } from "./relay-auth-C1jzy9Sz.mjs"; //#region extensions/browser/src/browser/extension-pairing.ts /** Gateway route for extension pairing that must wake Browser control. */ const GATEWAY_EXTENSION_RELAY_PATH = "/browser/extension"; /** Resolve a safe Gateway relay URL with the v2-bound route path. */ function buildGatewayExtensionRelayUrl(e) { const t = URL.parse(e.trim()); if (!t) throw new Error("--gateway-url must be a valid ws:// or wss:// URL"); const n = t.protocol === "wss:"; const r = t.protocol === "ws:" && isLoopbackHost(t.hostname); if (!n && !r) throw new Error("--gateway-url must use wss:// (ws:// is allowed only for loopback)"); if (t.username || t.password || t.search || t.hash) throw new Error("--gateway-url must not include credentials, a query, or a fragment"); if (t.pathname !== "/") throw new Error("--gateway-url must not include a path prefix; Browser Relay Authentication v2 binds the exact /browser/extension path"); t.pathname = GATEWAY_EXTENSION_RELAY_PATH; return t; } /** * Build the canonical host-owned extension pairing used by both the CLI and * native bootstrap. A direct remote pairing is opt-in because its key belongs * to the remote Gateway rather than the browser host. */ async function buildBrowserExtensionPairing(e) { const t = resolveBrowserConfig(e.cfg.browser, e.cfg); const n = e.profile || resolveFirstExtensionProfileName(t); const r = n ? resolveProfile(t, n) : null; if (e.profile && r?.driver !== "extension") throw new Error("Native bootstrap requires an existing extension profile"); const i = r?.cdpPort ?? t.extensionRelayDefaultPort; const a = await ensureExtensionRelayToken(); const o = e.gatewayUrl?.trim(); const s = !o && e.cfg.gateway?.mode === "remote" ? e.cfg.gateway.remote?.url?.trim() : ""; if (!o && !s && e.cfg.gateway?.tls?.enabled === true) throw new Error("Gateway TLS pairing requires --gateway-url wss://<certificate-host>[:port]"); const c = o || s || `ws://127.0.0.1:${resolveGatewayPort(e.cfg)}`; const l = o || !s && e.localTransport === "gateway" ? buildGatewayExtensionRelayUrl(c) : new URL(`ws://127.0.0.1:${i}/extension`); if (!o && e.profile && l.pathname === GATEWAY_EXTENSION_RELAY_PATH) l.searchParams.set("profile", e.profile); l.searchParams.set("gateway", c); return { pairingString: `${l.toString()}#${a}`, relayPort: i, topology: o ? "direct-remote" : s ? "browser-node" : "local" }; } //#endregion export { buildBrowserExtensionPairing as t };