import type { RelayConfig, RouteEntry } from './config.js'; import type { RelayMessage, ClusterMetadata } from './messages.js'; export type RelayState = 'disconnected' | 'connecting' | 'authenticating' | 'connected' | 'disconnecting'; export interface Logger { info(msg: string): void; info(obj: Record, msg: string): void; warn(msg: string): void; warn(obj: Record, msg: string): void; error(msg: string): void; error(obj: Record, msg: string): void; } /** Options accepted by ClusterRelayClient (orchestrator-facing API). */ export interface ClusterRelayClientOptions { /** API key for cloud authentication (GENERACY_API_KEY) */ apiKey: string; /** Cloud relay WebSocket URL (set via GENERACY_RELAY_URL env var) */ cloudUrl?: string; /** Base reconnect delay in ms (default: 5000) */ baseReconnectDelayMs?: number; /** URL of the local orchestrator API (default: http://localhost:3000) */ orchestratorUrl?: string; /** API key for authenticating relay-proxied requests to the orchestrator */ orchestratorApiKey?: string; /** Path-prefix routes for dispatching API requests to unix sockets or HTTP targets */ routes?: RouteEntry[]; } type EventMap = { message: (msg: RelayMessage) => void; connected: () => void; disconnected: (reason: string) => void; error: (error: Error) => void; }; export declare class ClusterRelay { private _state; private ws; private readonly config; private readonly logger; private readonly messageHandlers; private readonly eventHandlers; private running; private abortController; private reconnectAttempt; private heartbeatTimer; private pongReceived; private metadataOverride; /** * Accept either a full RelayConfig or a ClusterRelayClientOptions (orchestrator API). * ClusterRelayClientOptions uses `cloudUrl` instead of `relayUrl`. */ constructor(config: RelayConfig | ClusterRelayClientOptions, logger?: Logger); /** Whether the relay is currently connected (orchestrator-facing API). */ get isConnected(): boolean; /** Register an event handler (orchestrator-facing EventEmitter API). */ on(event: K, handler: EventMap[K]): void; /** Remove an event handler (orchestrator-facing EventEmitter API). */ off(event: string, handler: (...args: unknown[]) => void): void; private emit; get state(): RelayState; /** * Establish WebSocket connection with automatic reconnection. */ connect(): Promise; /** * Gracefully disconnect. */ disconnect(): Promise; /** * Send a message over the WebSocket. */ send(message: RelayMessage): void; /** * Register a handler for incoming messages. */ onMessage(handler: (message: RelayMessage) => void): void; /** * Push an event to the cloud (library mode). */ pushEvent(event: string, data: unknown): void; /** * Override metadata for library mode. */ setMetadata(metadata: Partial): void; /** * Establish a single WebSocket connection, authenticate, and process messages. * Resolves when the connection closes normally, throws on error. */ private connectOnce; /** * Send handshake with cluster metadata. */ private sendHandshake; /** * Start the heartbeat interval. */ private startHeartbeat; /** * Stop the heartbeat interval. */ private stopHeartbeat; /** * Calculate exponential backoff delay. */ private get reconnectDelayMs(); /** * Cancellable sleep. */ private sleep; } export {}; //# sourceMappingURL=relay.d.ts.map