/**
 * Session Management for Remote UI
 *
 * Manages session lifecycle including:
 * - Creating new sessions
 * - Suspending sessions on disconnect (pending reconnection)
 * - Resuming sessions on reconnect
 * - Expiring sessions after TTL
 * - Handling concurrent connections
 */
import type { Session, SessionConfig } from "./types.js";
/**
 * Internal representation of a pending (disconnected) session
 */
interface PendingSession {
    session: Session;
    savedState: unknown;
    expiryTimer: ReturnType<typeof setTimeout>;
}
/**
 * Callback invoked when a session expires
 */
export type SessionExpireCallback = (session: Session) => void | Promise<void>;
/**
 * Manages session lifecycle for remote UI connections
 */
export declare class SessionManager {
    /** Active sessions (currently connected) */
    private activeSessions;
    /** Pending sessions (disconnected, waiting for reconnect within TTL) */
    private pendingSessions;
    /** Maps session ID to connected WebSocket(s) for concurrent handling */
    private sessionConnections;
    /** Resolved configuration with defaults */
    private config;
    constructor(config?: SessionConfig);
    /**
     * Get the configured TTL in seconds
     */
    getTtl(): number;
    /**
     * Get the concurrent connection policy
     */
    getConcurrentPolicy(): "kick-old" | "reject-new" | "allow-multiple";
    /**
     * Create a new session
     */
    createSession(props?: Record<string, any>): Session;
    /**
     * Get an active (connected) session by ID
     */
    getActiveSession(id: string): Session | null;
    /**
     * Get a pending (disconnected) session by ID
     */
    getPendingSession(id: string): PendingSession | null;
    /**
     * Check if a session exists (either active or pending)
     */
    hasSession(id: string): boolean;
    /**
     * Suspend a session when client disconnects
     * Moves from active to pending with a TTL timer
     *
     * @param sessionId - The session to suspend
     * @param savedState - State snapshot to restore on reconnect
     * @param onExpire - Callback when TTL expires
     */
    suspendSession(sessionId: string, savedState: unknown, onExpire: SessionExpireCallback): void;
    /**
     * Resume a pending session when client reconnects
     *
     * @param sessionId - The session to resume
     * @returns Session and saved state, or null if not found/expired
     */
    resumeSession(sessionId: string): {
        session: Session;
        savedState: unknown;
    } | null;
    /**
     * Destroy a session completely (both active and pending)
     */
    destroySession(sessionId: string): void;
    /**
     * Track a WebSocket connection for a session
     * Used for concurrent connection handling
     */
    trackConnection(sessionId: string, ws: unknown): void;
    /**
     * Untrack a WebSocket connection
     */
    untrackConnection(sessionId: string, ws: unknown): void;
    /**
     * Get all connections for a session
     */
    getConnections(sessionId: string): Set<unknown> | undefined;
    /**
     * Get connection count for a session
     */
    getConnectionCount(sessionId: string): number;
    /**
     * Get stats about current sessions
     */
    getStats(): {
        activeSessions: number;
        pendingSessions: number;
        totalConnections: number;
    };
    /**
     * Clean up all sessions and timers
     * Call this when shutting down the server
     */
    destroy(): void;
}
export {};
