import type { ServerWebSocket } from "bun"; import type { Node, NodeMetadata, GatewayMessage } from "./types.js"; /** * Manages connected nodes in the gateway */ export declare class NodeManager { private nodes; private maxNodes; private messageRateLimit; private messageWindow; constructor(maxNodes?: number, messageRateLimit?: number, messageWindow?: number); /** * Register a new node */ registerNode(ws: ServerWebSocket<{ nodeId: string; clientId?: string; clientType?: string; authenticated?: boolean; tailscaleUser?: string; }>, name: string, capabilities?: string[], sessionId?: string, agentName?: string, clientId?: string): Node | null; /** * Unregister a node */ unregisterNode(nodeId: string): boolean; /** * Get a node by ID */ getNode(nodeId: string): Node | undefined; /** * Get all nodes */ getAllNodes(): Node[]; /** * Get all nodes for a stable client ID */ getNodesByClientId(clientId: string): Node[]; /** * Get node metadata (without WebSocket) */ getNodeMetadata(nodeId: string): NodeMetadata | undefined; /** * Update node's last ping time */ updatePing(nodeId: string): void; /** * Check if node is rate limited */ isRateLimited(nodeId: string): boolean; /** * Record a message from a node */ recordMessage(nodeId: string): void; /** * Add a node to a group */ addNodeToGroup(nodeId: string, groupId: string): boolean; /** * Remove a node from a group */ removeNodeFromGroup(nodeId: string, groupId: string): boolean; /** * Send a message to a specific node */ sendToNode(nodeId: string, message: GatewayMessage): boolean; /** * Broadcast a message to multiple nodes */ broadcastToNodes(nodeIds: string[], message: GatewayMessage): number; /** * Broadcast a message to all nodes */ broadcastToAll(message: GatewayMessage): number; /** * Get nodes by group */ getNodesByGroup(groupId: string): Node[]; /** * Check for stale nodes (no ping in timeout period) */ getStaleNodes(timeoutMs: number): Node[]; /** * Remove stale nodes */ removeStaleNodes(timeoutMs: number): number; /** * Generate a unique node ID */ private generateNodeId; /** * Get nodes by session ID */ getNodesBySession(sessionId: string): Node[]; /** * Get all active sessions with their nodes */ getSessionNodes(): Map; /** * Get statistics */ getStats(): { totalNodes: number; maxNodes: number; activeSessions: number; sessionNodes: { sessionId: string; agentName: string | undefined; nodeIds: string[]; }[]; nodes: { id: string; name: string; clientId: string | undefined; groupCount: number; connectedAt: number; lastPing: number | undefined; sessionId: string | undefined; agentName: string | undefined; }[]; }; }