import type { SSEEvent } from '../types/api'; export type SSEEventHandler = (event: SSEEvent) => void; export type SSEConnectionState = { status: 'idle'; } | { status: 'connecting'; attempt: number; } | { status: 'connected'; } | { status: 'retrying'; attempt: number; delay: number; httpStatus?: number; }; export interface SSEConnectOptions { /** * Called when the server answers with a non-OK HTTP status. Return false * to stop reconnecting (e.g. 404 from an older daemon that lacks the * endpoint); return true (default) to keep retrying. */ onHttpError?: (status: number) => boolean; /** Supplies credentials immediately before every connection attempt. */ getHeaders?: () => HeadersInit; /** Renews credentials after a 401. Concurrent renewal should be deduplicated. */ onUnauthorized?: () => Promise; } export type SSETransport = (url: string, init: RequestInit) => Promise; /** Installs a host-provided SSE transport, such as the native desktop broker. */ export declare function setSSETransport(transport: SSETransport | undefined): void; export declare class SSEClient { private abortController; private handlers; private stateHandlers; private running; private state; private lastEventId; connect(url: string, headers?: HeadersInit, opts?: SSEConnectOptions): Promise; private streamOnce; disconnect(): void; /** Returns the current connection state for external-store consumers. */ getConnectionState(): SSEConnectionState; getLastEventId(): string | undefined; setLastEventId(lastEventId: string | undefined): void; /** Subscribes to connection/retry state changes. */ onConnectionState(handler: (state: SSEConnectionState) => void): () => void; private setState; on(eventType: string, handler: SSEEventHandler): () => void; off(eventType: string, handler: SSEEventHandler): void; private emit; } /** * Acquire a shared SSE connection for a stream URL. * * Multiple subscribers (message thread, floating viewers, looper panes) for * the same session reuse ONE underlying connection instead of opening their * own. This matters in webviews (Tauri/WKWebView) where HTTP/1.1 allows only * ~6 connections per host across all windows: unbounded SSE connections * starve regular fetches and the UI appears stuck loading. * * Returns the client plus a release function. The connection closes when the * last subscriber releases it. */ export declare function acquireSharedSSEStream(url: string, headers?: HeadersInit, opts?: SSEConnectOptions): { client: SSEClient; release: () => void; }; //# sourceMappingURL=sse-client.d.ts.map