/** * Lightweight RPC client for pi's --mode rpc. * * Works with any ChildProcess that speaks JSONL on stdin/stdout. * No dependency on pi — just the wire protocol. */ import type { ChildProcess } from "node:child_process"; /** Any JSON event from pi's stdout. */ export interface RpcEvent { type: string; [key: string]: unknown; } /** RPC command response (type: "response"). */ export interface RpcResponse extends RpcEvent { type: "response"; id?: string; command: string; success: boolean; error?: string; data?: unknown; } /** Extension UI request that needs a reply. */ export interface ExtensionUIRequest extends RpcEvent { type: "extension_ui_request"; id: string; method: string; } /** Handler for extension UI dialogs. Return the response payload. */ export type UIHandler = (req: ExtensionUIRequest) => Record | undefined; export interface RpcClient { /** All events received so far. */ readonly events: RpcEvent[]; /** Send a raw RPC command and wait for its response. */ send(cmd: Record, timeoutMs?: number): Promise; /** Wait for an event matching a predicate. Scans existing events from scanFrom first. */ waitFor(pred: (e: RpcEvent) => boolean, timeoutMs?: number, scanFrom?: number): Promise; /** Subscribe to every event. Returns unsubscribe function. */ on(listener: (e: RpcEvent) => void): () => void; /** Set handler for extension UI requests. */ setUIHandler(handler: UIHandler): void; /** Write raw JSON to stdin (fire-and-forget). */ write(obj: Record): void; } export declare function createRpcClient(proc: ChildProcess): RpcClient; //# sourceMappingURL=rpc.d.ts.map