import { a as ChatEvent } from './types-ajANVzf7.js';

/**
 * @witqq/agent-sdk/chat/backends/transport
 *
 * IChatTransport abstracts how ChatEvents are delivered to clients.
 * SSEChatTransport implements Server-Sent Events over HTTP.
 */

/**
 * Abstraction for delivering chat events to a client.
 * Implementations handle protocol details (SSE, WebSocket, etc.).
 */
interface IChatTransport {
    /** Send a single chat event to the client */
    send(event: ChatEvent): void;
    /** Signal stream completion and close the connection */
    close(): void;
    /** Signal an error to the client */
    error(err: Error): void;
    /** Whether the transport is still open */
    readonly isOpen: boolean;
}
/** Writable HTTP response interface — minimal type satisfied by Express, Fastify (raw), and Node http.ServerResponse without casts. */
interface WritableResponse {
    writeHead(statusCode: number, headers?: Record<string, string | string[]>): unknown;
    setHeader(name: string, value: string): unknown;
    write(chunk: string): boolean;
    end(body?: string): unknown;
    readonly writableEnded: boolean;
}
/** Minimal interface for detecting client disconnection */
interface CloseDetectable {
    on(event: "close", listener: () => void): void;
}
/** Configuration options for SSEChatTransport */
interface SSETransportOptions {
    /** Heartbeat interval in milliseconds. 0 or undefined disables heartbeat. */
    heartbeatMs?: number;
    /** Request object for detecting client disconnection (listens for 'close' event) */
    request?: CloseDetectable;
}
/**
 * Server-Sent Events transport for ChatEvent streaming.
 * Sends events as `data: JSON\n\n` lines with SSE headers.
 */
declare class SSEChatTransport implements IChatTransport {
    private readonly res;
    private _open;
    private _heartbeatTimer;
    constructor(res: WritableResponse, options?: SSETransportOptions);
    get isOpen(): boolean;
    send(event: ChatEvent): void;
    close(): void;
    error(err: Error): void;
    private _cleanup;
    private _clearHeartbeat;
}
/**
 * Pipes an async iterable of ChatEvents into a transport.
 * Handles errors and ensures transport is closed on completion.
 *
 * @param events - Async iterable of ChatEvent (from adapter.streamMessage)
 * @param transport - Transport to send events through
 */
declare function streamToTransport(events: AsyncIterable<ChatEvent>, transport: IChatTransport): Promise<void>;

export { type CloseDetectable as C, type IChatTransport as I, SSEChatTransport as S, type WritableResponse as W, type SSETransportOptions as a, streamToTransport as s };
