UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

46 lines (45 loc) 2.07 kB
import { c as normalizeOptionalString } from "./string-coerce-mnp54Vah.js"; import { i as resolveGatewayDiscoveryEndpoint } from "./bonjour-discovery-ayDzfvTN.js"; //#region src/infra/gateway-discovery-targets.ts function pickSshPort(beacon) { return typeof beacon.sshPort === "number" && Number.isFinite(beacon.sshPort) && beacon.sshPort > 0 ? beacon.sshPort : null; } /** Build normalized connection details for a discovered gateway beacon. */ function buildGatewayDiscoveryTarget(beacon, opts) { const endpoint = resolveGatewayDiscoveryEndpoint(beacon); const sshPort = pickSshPort(beacon); const sshUser = normalizeOptionalString(opts?.sshUser) ?? ""; const baseSshTarget = endpoint ? sshUser ? `${sshUser}@${endpoint.host}` : endpoint.host : null; const sshTarget = baseSshTarget && sshPort && sshPort !== 22 ? `${baseSshTarget}:${sshPort}` : baseSshTarget; return { title: normalizeOptionalString(beacon.displayName || beacon.instanceName || "Gateway") ?? "Gateway", domain: normalizeOptionalString(beacon.domain || "local.") ?? "local.", endpoint, wsUrl: endpoint?.wsUrl ?? null, sshPort, sshTarget }; } /** Build the compact label shown in discovery lists. */ function buildGatewayDiscoveryLabel(beacon) { const target = buildGatewayDiscoveryTarget(beacon); const hint = target.endpoint ? `${target.endpoint.host}:${target.endpoint.port}` : "host unknown"; return `${target.title} (${hint})`; } /** Serialize a beacon with resolved websocket information for CLI/UI output. */ function serializeGatewayDiscoveryBeacon(beacon) { const target = buildGatewayDiscoveryTarget(beacon); return { instanceName: beacon.instanceName, displayName: beacon.displayName ?? null, domain: beacon.domain ?? null, host: beacon.host ?? null, lanHost: beacon.lanHost ?? null, tailnetDns: beacon.tailnetDns ?? null, gatewayPort: beacon.gatewayPort ?? null, sshPort: beacon.sshPort ?? null, wsUrl: target.wsUrl }; } //#endregion export { buildGatewayDiscoveryTarget as n, serializeGatewayDiscoveryBeacon as r, buildGatewayDiscoveryLabel as t };