/** * Kernel Proxy * * Handles proxying kernel operations to peer servers in a cluster. * When a kernel is started on a remote server, this module manages * the communication between the client and the remote kernel. */ import { WebSocket } from 'ws'; import { PeerServer } from './server-registry'; interface ProxiedSession { serverId: string; remoteSessionId: string; remoteWs?: WebSocket; localWs?: WebSocket; } /** * Create a composite session ID that encodes the server */ export declare function createProxiedSessionId(serverId: string, remoteSessionId: string): string; /** * Parse a composite session ID */ export declare function parseSessionId(sessionId: string): { isProxied: boolean; serverId?: string; remoteSessionId?: string; }; /** * Check if a session ID is for a proxied (remote) kernel */ export declare function isProxiedSession(sessionId: string): boolean; /** * Get the server for a session */ export declare function getSessionServer(sessionId: string): PeerServer | null; /** * Start a kernel on a remote server */ export declare function startRemoteKernel(serverId: string, kernelName: string, filePath?: string): Promise<{ sessionId: string; created?: boolean; createdAt?: number; }>; export interface RemoteExecuteResult { status: string; executionCount: number | null; error?: string; queuePosition?: number; queueLength?: number; } /** * Execute code on a remote kernel and stream its outputs — the headless * counterpart of the UI's WebSocket proxy, speaking the same protocol: * subscribe (`sync_outputs`), `execute`, collect `output` messages until the * `result` arrives. Outputs are filtered to the executing cell so concurrent * runs on the session don't cross streams. */ export declare function executeRemoteCode(proxySessionId: string, code: string, outputCallback: (output: Record) => void | Promise, cellId?: string | null): Promise; /** * Interrupt a kernel on a remote server */ export declare function interruptRemoteKernel(sessionId: string): Promise; /** * Restart a kernel on a remote server */ export declare function restartRemoteKernel(sessionId: string): Promise; /** * Get status of a kernel on a remote server */ export declare function getRemoteKernelStatus(sessionId: string): Promise<{ status: string; execution_count?: number; memory_mb?: number; }>; /** * Shutdown a kernel on a remote server */ export declare function shutdownRemoteKernel(sessionId: string): Promise; /** * Get available kernels from a remote server */ export declare function getRemoteKernels(serverId: string): Promise<{ kernels: any[]; }>; /** * Get active kernel sessions from a remote server */ export declare function getRemoteKernelSessions(serverId: string): Promise<{ sessions: any[]; }>; /** * Get dead kernel sessions from a remote server */ export declare function getRemoteDeadKernelSessions(serverId: string): Promise<{ sessions: any[]; }>; /** * Cleanup dead kernel sessions on a remote server */ export declare function cleanupRemoteDeadKernelSessions(serverId: string, sessionIds?: string[]): Promise<{ deleted: number; }>; /** * Create a WebSocket proxy to a remote kernel */ export declare function createWebSocketProxy(sessionId: string, clientWs: WebSocket): WebSocket | null; /** * Get all proxied sessions */ export declare function getProxiedSessions(): Map; /** * Cleanup all proxied sessions */ export declare function cleanupProxiedSessions(): void; export {};