import type { AgentSession } from "../../core/runtime/agent-session.js"; import type { AgentSessionEvent } from "../../core/runtime/session-events.js"; import type { RpcCommand, RpcExtensionUIRequest, RpcExtensionUIResponse, RpcResponse, RpcSessionState, RpcLoopPolicyOptions, RpcSlashCommand } from "./rpc-types.js"; import type { AgentLoopPolicyOptions } from "@catui/agent-core"; type RpcSlashCommandCatalogSession = Pick; type RpcStateSession = Pick; /** Every message a Catui RPC server pushes to a connected client (one JSON object per transport frame). */ export type RpcServerMessage = RpcResponse | RpcExtensionUIRequest | AgentSessionEvent | { type: "extension_error"; extensionPath: string; event: string; error: string; }; export declare function buildRpcSlashCommands(session: RpcSlashCommandCatalogSession): RpcSlashCommand[]; export declare function buildRpcSessionState(session: RpcStateSession): RpcSessionState; export declare function buildRpcLoopPolicyOptions(policy: RpcLoopPolicyOptions): Partial; export interface RpcCommandHandlerOptions { session: AgentSession; /** * Default sink for session events, extension UI requests, and extension errors. * stdio transport: stdout. Remote transport: fan-out to all connected clients. */ send: (message: RpcServerMessage) => void; } /** * Transport-agnostic RPC protocol core. * Owns command dispatch, session event forwarding, and extension UI bridging. * Transports (stdio JSON-lines, WebSocket) provide the send sinks and lifecycle. */ export declare class RpcCommandHandler { private readonly session; private readonly output; private readonly pendingExtensionRequests; private _shutdownRequested; private _bound; constructor(options: RpcCommandHandlerOptions); get shutdownRequested(): boolean; private readonly success; private readonly error; /** * Bind extensions with the protocol-backed UI context and subscribe to session events. * Idempotent. Must be called before handleCommand. */ bind(): Promise; /** Helper for dialog methods with signal/timeout support */ private createDialogPromise; /** * Create an extension UI context that uses the RPC protocol. */ private createExtensionUIContext; /** * Resolve a pending extension UI request. First response wins. * Returns false for unknown or already-resolved request ids. */ handleExtensionUIResponse(response: RpcExtensionUIResponse): boolean; /** * Handle a single command. * @param send Optional per-call sink for async errors (e.g. prompt failures) so replies * route back to the requesting client instead of the broadcast sink. */ handleCommand(command: RpcCommand, send?: (message: RpcServerMessage) => void): Promise; /** * Emit session_shutdown extension hooks. Call once at transport teardown * when an extension invoked the shutdown handler. */ runShutdownHooks(): Promise; } export {};