Skip to content

The agent that grows with you

765 B
Raw Blame
import { resolveGatewayWsUrl } from '@hermes/shared'

import type { HermesConnection } from '@/global'

export function resolveDesktopGatewayWsUrl(
  desktop: Window['hermesDesktop'],
  connection: HermesConnection
): Promise<string> {
  // Only a registry-scoped descriptor may use the *For bridge (see
  // HermesConnection.registryScoped); an absent bridge fails closed rather
  // than minting the peer's URL against the local pool.
  const { connectionId, profile, registryScoped } = connection

  if (!registryScoped || !connectionId) {
    return resolveGatewayWsUrl(desktop, connection)
  }

  const mint = desktop.getGatewayWsUrlFor

  return resolveGatewayWsUrl({ getGatewayWsUrl: mint ? () => mint({ connectionId, profile }) : undefined }, connection)
}