import type { Readable, Writable } from "node:stream"; import { type DaemonCommandResultMap, type DaemonCommandParamsMap, type DaemonControlRequestFrame, type DaemonQueryMethod, type DaemonWireSessionMessage, type JsonObject, type JsonValue, type OpenSessionParams, type RenameSessionResult } from "./protocol.js"; import type { SdkAuthPayload } from "../types/auth.js"; import { DaemonSessionTransport, type DaemonSessionTransportOptions } from "./daemon-session-transport.js"; export declare const SESSION_STORE_FILE_CHECKPOINTING_CAPABILITY = "session_store_file_checkpointing_v1"; export declare const SESSION_STORE_FORK_BARRIER_CAPABILITY = "session_store_fork_barrier_v1"; export interface DaemonConnectionOptions { input: Writable; output: Readable; requestHandler?: DaemonRequestHandler; maxFrameBytes?: number; } export interface DaemonInitializeOptions { /** Advertised in addition to the capability this SDK cannot work without. */ capabilities?: readonly string[]; timeoutMs?: number; /** * Daemon-level credentials, sent in-band on the initialize frame. This is * what unlocks the account-level query plane; Session management works * without it. Carries a plaintext credential — never log it. */ auth?: SdkAuthPayload; } export type DaemonRequestHandler = (request: DaemonControlRequestFrame) => Promise; export declare class DaemonRpcError extends Error { readonly code: string; readonly retryable: boolean; readonly details: JsonObject | undefined; constructor(options: { code: string; message: string; retryable: boolean; details?: JsonObject; }); } export declare class DaemonRequestError extends Error { readonly code: string; readonly retryable: boolean; readonly details: JsonObject | undefined; constructor(options: { code: string; message: string; retryable: boolean; details?: JsonObject; }); } export declare class DaemonConnection { private readonly input; private readonly requestHandler; private readonly pendingRequests; private readonly timedOutRequestIds; private readonly activeInboundRequestIds; private readonly sessions; private readonly closedSessionIds; private readonly pendingSessionMessages; private readonly pendingSessionMessageBytes; private pendingSessionMessageFrameCount; private pendingSessionMessageByteCount; private readonly maxFrameBytes; private readonly readTask; private writeChain; private nextRequestId; private initializing; private initialized; private readonly capabilities; private stopping; private failure; private readonly failureListeners; constructor(options: DaemonConnectionOptions); initialize(sdkVersion: string, options?: DaemonInitializeOptions): Promise; createSessionTransport(options: DaemonSessionTransportOptions): DaemonSessionTransport; supportsCapability(capability: string): boolean; onFailure(listener: (error: Error) => void): () => void; openSession(params: OpenSessionParams, transport: DaemonSessionTransport): Promise; listSessions(): Promise; renameSession(sessionId: string, title: string): Promise; sendSessionMessage(message: DaemonWireSessionMessage): Promise; closeSession(sessionId: string): Promise; deleteSession(localSessionId: string): Promise; /** * Sends one account-level query (`daemon_queries_v1`). * * Rejected with `DaemonProtocolError` when the daemon never reported the * capability, and with `DaemonRpcError` carrying the daemon's error code when * the query itself fails. The timeout is request-scoped: a slow upstream call * fails that one query, not the connection. */ query(method: Method, params: DaemonCommandParamsMap[Method]): Promise; shutdown(timeoutMs?: number): Promise; fail(error: unknown, notifyListeners?: boolean): void; private request; private readOutput; private acceptFrame; private rememberTimedOutRequestId; private routeSessionMessage; private acceptControlResponse; private hasPendingSessionRequest; private failIfSessionMessagesAreOrphaned; private bufferPendingSessionMessage; private takePendingSessionMessages; private deletePendingSessionMessages; private clearPendingSessionMessages; private rejectLegacyInitialize; private acceptRequest; private writeInboundError; private acceptSessionUpdatedStatusEvent; private writeFrame; }