/** * RpcServer — in-process RPC dispatcher for the new typed surface. * * This is the dispatch core. The wire layer (WebSocket framing, * heartbeats, backpressure) lands when we mount this on the HTTP server's * upgrade path in a follow-up commit. Until then, callers can use the * dispatcher directly (memi-studio's Tauri shell can speak to it via * a thin in-process bridge as a stepping stone). * * The dispatcher operates on: * - a SessionResolver: finds the right HarnessDriver for a sessionId * - an EventJournal: serves replayEvents() * * Both are injected so tests can use mock implementations. */ import { Effect } from "effect"; import type { HarnessId, SessionId, ThreadId } from "../contracts/ids.js"; import type { HarnessDriver } from "../drivers/base.js"; import type { EventJournal } from "../journal/event-journal.js"; import { type RpcResponse } from "./protocol.js"; export interface SessionResolver { /** Look up the live driver for a session, or null if no live driver exists. */ resolveDriver(sessionId: SessionId): HarnessDriver | null; /** * Look up the most recent harnessId attached to a session — used by * dispatchCommand to construct a fresh driver if `start` arrives for * a session that doesn't have a live driver yet. */ resolveHarnessId(sessionId: SessionId): HarnessId | null; /** * Construct + register a fresh HarnessDriver for the given session. * Called by dispatchCommand("start") when no live driver exists. */ createDriver(input: { sessionId: SessionId; harnessId: HarnessId; threadId?: ThreadId; options?: Record; }): HarnessDriver; } export interface RpcServerConfig { readonly resolver: SessionResolver; readonly journal?: EventJournal; } export declare class RpcServer { private readonly config; constructor(config: RpcServerConfig); /** * Dispatch a single RPC request. Returns an async iterable of responses * — single-shot ops yield one response, streaming ops yield many until * the consumer calls `cancel()` on the returned subscription. */ dispatch(rawRequest: unknown): RpcSubscription; private handleDispatchCommand; private runCommand; private handleSubscribeThread; private handleReplayEvents; private handleSubscribeShell; private handleGetTurnDiff; } export declare class RpcSubscription { private buffer; private resolvers; private closed; static singleShot(response: RpcResponse): RpcSubscription; static fromEffect(requestId: string, effect: Effect.Effect): RpcSubscription; push(response: RpcResponse): void; close(): void; cancel(): void; [Symbol.asyncIterator](): AsyncIterator; }