/** * Gateway Federation — Hub-and-Spoke cross-gateway agent messaging. * * Hub (thundercat): accepts spoke WebSocket connections at /federation, * maintains a registry of spoke→thread mappings, routes messages. * * Spoke (any device): connects outbound to hub, syncs thread list, * relays inbound messages to local threads. */ import type { IncomingMessage } from 'http'; import type { Duplex } from 'stream'; export interface FederationAuthMessage { type: 'auth'; name: string; apiKey: string; } export interface FederationAuthOk { type: 'auth_ok'; hubName: string; } export interface FederationAuthError { type: 'auth_error'; reason: string; } export interface FederationThreadSync { type: 'thread_sync'; threads: string[]; } export interface FederationRouteMessage { type: 'route'; from: string; to: string; message: string; sender: string; visibility?: string | { hidden: string[]; }; } export interface FederationInjectMessage { type: 'inject'; from: string; to: string; message: string; sender: string; visibility?: string | { hidden: string[]; }; } export type FederationMessage = FederationAuthMessage | FederationAuthOk | FederationAuthError | FederationThreadSync | FederationRouteMessage | FederationInjectMessage; export interface FederationRouterOptions { hubName: string; apiKeys: string[]; allowedSpokes?: string[]; /** Callback to inject a message into a local thread */ injectLocal: (target: string, message: string, sender: string, visibility?: string | { hidden: string[]; }) => Promise<{ status: string; }>; /** Callback to list local threads */ listLocalThreads: () => string[]; } export declare class FederationRouter { private wss; private spokes; private options; constructor(options: FederationRouterOptions); /** Handle HTTP upgrade to WebSocket for /federation path */ handleUpgrade(req: IncomingMessage, socket: Duplex, head: Buffer): void; private handleConnection; /** Route a message from a spoke to its destination */ private handleRoute; /** Route a message originating from a local hub thread to a spoke */ routeToSpoke(targetGateway: string, targetThread: string, message: string, sender: string, visibility?: string | { hidden: string[]; }): Promise<{ status: string; }>; /** Resolve a thread address — returns the gateway name if it's on a spoke, null if local or unknown */ resolveThread(threadName: string): string | null; /** Get all federated agents (for list_agents aggregation) */ getFederatedAgents(): Array<{ name: string; gateway: string; status: 'idle'; }>; /** Get connected spokes status */ getStatus(): Array<{ name: string; threads: string[]; lastSeen: number; connected: boolean; }>; private cleanupSpoke; private send; close(): void; } export interface FederationClientOptions { hubUrl: string; apiKey: string; spokeName: string; /** Callback to inject a message into a local thread */ injectLocal: (target: string, message: string, sender: string, visibility?: string | { hidden: string[]; }) => Promise<{ status: string; }>; /** Callback to list local thread names */ listLocalThreads: () => string[]; } export declare class FederationClient { private ws; private options; private reconnectDelay; private maxReconnectDelay; private reconnectTimer; private authenticated; private closed; private hubName; private lastSyncedThreads; private pingTimer; private lastSeen; constructor(options: FederationClientOptions); /** Connect to the hub */ connect(): void; /** Send a message to a thread on another gateway via the hub */ sendToRemote(targetGateway: string, targetThread: string, message: string, sender: string, visibility?: string | { hidden: string[]; }): boolean; /** Sync current local thread list to hub */ syncThreads(): void; /** Handle a message from the hub destined for a local thread */ private handleInject; private startHeartbeat; private stopHeartbeat; private scheduleReconnect; private send; get isConnected(): boolean; get connectedHubName(): string; close(): void; } /** Parse "gateway:thread" address. Returns { gateway, thread } */ export declare function parseAddress(address: string): { gateway: string | null; thread: string; }; //# sourceMappingURL=federation.d.ts.map