/** * IPCSessionHost — owner-side, multi-session IPC endpoint. * * The generalization of the CLI's single-session SyncClient: a process that * OWNS PTY sessions (a CLI wrapper, a runtime daemon, an agent host) connects * to a hub's UDSServer, announces any number of IPTYSessions, relays their * output, and routes inbound input/resize/kill back to them. * * With a `spawnHandler`, the host also accepts hub-initiated `spawn:request` * messages: the handler creates a session (however the host pleases — local * node-pty, a wrapped runtime, anything implementing IPTYSession), the host * announces it, then acknowledges with `spawn:response` carrying the session * id. The announce is sent before the response so the hub's proxy session * exists by the time the requester's promise resolves. * * Handshake, heartbeat, and payload shapes match UDSServer and * IPCPTYTransport (`hello` → `welcome`, 30s `heartbeat`, base64 output). * On reconnect every live session is re-announced; the hub side creates * fresh proxy sessions because the old transport died with the connection. */ import { EventEmitter } from 'events'; import type { IPTYSession } from '#types'; import type { SpawnRequestPayload } from './ipc-transport.js'; /** Spawn configuration as received from the hub (requestId stripped). */ export type SpawnConfig = Omit; /** * Creates and returns a session for a hub spawn request. The returned session * is registered with the host automatically; throwing rejects the request. */ export type SpawnHandler = (config: SpawnConfig) => Promise | IPTYSession; export interface IPCSessionHostOptions { socketPath: string; /** Reported in the hello handshake and announcements. */ version?: string; /** Present to accept hub-initiated spawns; absent hosts reject them. */ spawnHandler?: SpawnHandler; /** Announce metadata: project/workspace path shown by hub UIs. */ projectPath?: string; autoRetry?: boolean; retryIntervalMs?: number; } export interface IPCSessionHostEvents { connect: []; disconnect: [reason: string]; error: [err: Error]; /** A hub spawn request was accepted and the session announced. */ spawned: [session: IPTYSession]; } export interface IPCSessionHost extends EventEmitter { on(event: K, listener: (...args: IPCSessionHostEvents[K]) => void): this; off(event: K, listener: (...args: IPCSessionHostEvents[K]) => void): this; emit(event: K, ...args: IPCSessionHostEvents[K]): boolean; } export declare class IPCSessionHost extends EventEmitter { private readonly options; private readonly client; private readonly hosted; private handshakeComplete; private heartbeatTimer; private disposed; constructor(options: IPCSessionHostOptions); isConnected(): boolean; /** Resolves true when the socket is up (handshake completes asynchronously). */ connect(): Promise; /** * Register a session with the host. Announced immediately when connected, * or on the next (re)connect. The host relays output and routes inbound * input/resize/kill; it does NOT own the session's lifecycle. */ addSession(session: IPTYSession): void; /** Stop hosting a session without touching the session itself. */ removeSession(sessionId: string): void; getSessions(): IPTYSession[]; dispose(): void; private send; private sendHello; private announce; private handleMessage; private sessionFor; private handleSpawnRequest; private startHeartbeat; private stopHeartbeat; } export declare function createIPCSessionHost(options: IPCSessionHostOptions): IPCSessionHost; //# sourceMappingURL=session-host.d.ts.map