Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.2 KB
Raw Blame
import { useMemo } from 'react'
import type { ExecutionHostId } from '../../../src/shared/execution-host'
import type { MobileRelayHost } from '../../../src/shared/mobile-relay-hosts-contract'
import {
  reachableServerClients,
  relaysToServers
} from '../transport/execution-host-scoped-rpc-client'
import type { RpcClient } from '../transport/rpc-client'
import { useRelayHosts } from './relay-hosts-feed'

// Key clients by the ready-server set so health/label changes cannot trigger repo reloads.
export function useReachableServerClients(
  client: RpcClient | null,
  hostCapabilities: readonly string[],
  active = true
): {
  servers: readonly MobileRelayHost[] | null
  serverClients: ReadonlyMap<ExecutionHostId, RpcClient>
} {
  const relays = client !== null && relaysToServers(client, hostCapabilities)
  const servers = useRelayHosts(active && relays ? client : null)
  const readyKey = (servers ?? [])
    .filter((host) => host.relay === 'ready')
    .map((host) => host.hostId)
    .sort()
    .join('\n')
  const serverClients = useMemo(
    () => reachableServerClients(client, hostCapabilities, servers ?? []),
    [client, hostCapabilities, readyKey]
  )
  return { servers, serverClients }
}