/**
 * Gateway WebSocket Server
 *
 * Centralized WebSocket server for multi-client communication.
 * Provides a unified control plane for agents, tools, and sessions.
 */
import { EventEmitter } from 'events';
import type { GatewayConfig, GatewayMessage, GatewayMessageType, ClientState, ErrorPayload } from './types.js';
/**
 * Create a gateway message
 */
export declare function createMessage<T>(type: GatewayMessageType, payload: T, sessionId?: string): GatewayMessage<T>;
/**
 * Create an error message
 */
export declare function createErrorMessage(code: string, message: string, details?: Record<string, unknown>): GatewayMessage<ErrorPayload>;
/**
 * Manages gateway sessions
 */
export declare class SessionManager {
    private sessions;
    /**
     * Create a new session
     */
    createSession(sessionId: string, options?: {
        name?: string;
        metadata?: Record<string, unknown>;
    }): void;
    /**
     * Get a session
     */
    getSession(sessionId: string): {
        id: string;
        name?: string;
        createdAt: number;
        clients: Set<string>;
        metadata?: Record<string, unknown>;
    } | undefined;
    /**
     * Check if session exists
     */
    hasSession(sessionId: string): boolean;
    /**
     * Add client to session
     */
    addClient(sessionId: string, clientId: string): boolean;
    /**
     * Remove client from session
     */
    removeClient(sessionId: string, clientId: string): boolean;
    /**
     * Get clients in session
     */
    getClients(sessionId: string): string[];
    /**
     * Remove empty sessions
     */
    cleanup(): number;
    /**
     * Get all sessions
     */
    getAllSessions(): {
        id: string;
        name?: string;
        createdAt: number;
        clients: Set<string>;
        metadata?: Record<string, unknown>;
    }[];
    /**
     * Clear all sessions
     */
    clear(): void;
}
/**
 * Message handler type
 */
export type MessageHandler = (clientId: string, message: GatewayMessage, send: (msg: GatewayMessage) => void) => Promise<void>;
/**
 * Gateway server (abstract - implement transport-specific subclass)
 */
export declare class GatewayServer extends EventEmitter {
    protected config: GatewayConfig;
    protected clients: Map<string, ClientState>;
    protected sessions: SessionManager;
    protected handlers: Map<GatewayMessageType, MessageHandler>;
    protected running: boolean;
    private pingInterval;
    constructor(config?: Partial<GatewayConfig>);
    /**
     * Setup default message handlers
     */
    private setupDefaultHandlers;
    /**
     * Validate authentication token
     * Override this method for custom authentication
     */
    protected validateToken(_token: string): Promise<boolean>;
    /**
     * Register a message handler
     */
    registerHandler(type: GatewayMessageType, handler: MessageHandler): void;
    /**
     * Unregister a message handler
     */
    unregisterHandler(type: GatewayMessageType): void;
    /**
     * Handle client connection
     */
    protected onConnect(clientId: string): void;
    /**
     * Handle client disconnection
     */
    protected onDisconnect(clientId: string): void;
    /**
     * Handle incoming message
     */
    protected onMessage(clientId: string, message: GatewayMessage, send: (msg: GatewayMessage) => void): Promise<void>;
    /**
     * Broadcast message to session
     */
    broadcastToSession(sessionId: string, message: GatewayMessage, _excludeClientId?: string): void;
    /**
     * Send message to specific client
     * Override in transport-specific subclass
     */
    protected sendToClient(_clientId: string, _message: GatewayMessage): void;
    /**
     * Start ping interval
     */
    protected startPingInterval(): void;
    /**
     * Stop ping interval
     */
    protected stopPingInterval(): void;
    /**
     * Start the server
     * Override in transport-specific subclass
     */
    start(): Promise<void>;
    /**
     * Stop the server
     */
    stop(): Promise<void>;
    /**
     * Check if server is running
     */
    isRunning(): boolean;
    /**
     * Get connected client count
     */
    getClientCount(): number;
    /**
     * Get session count
     */
    getSessionCount(): number;
    /**
     * Get statistics
     */
    getStats(): {
        running: boolean;
        clients: number;
        sessions: number;
        authenticatedClients: number;
    };
}
/**
 * Get the singleton gateway server
 */
export declare function getGatewayServer(config?: Partial<GatewayConfig>): GatewayServer;
/**
 * Reset the singleton gateway server
 */
export declare function resetGatewayServer(): Promise<void>;
