/**
 * 统一的SSE事件流写入器
 * 处理backpressure、超时、心跳、错误处理等通用流管理逻辑
 */
import { PassThrough } from 'stream';
import type { BaseSseEvent } from '../types/core-interfaces.js';
import type { ChatSseEvent, ResponsesSseEvent, AnthropicSseEvent, GeminiSseEvent } from '../types/index.js';
export interface StreamWriterConfig {
    timeoutMs?: number;
    enableHeartbeat?: boolean;
    heartbeatIntervalMs?: number;
    maxBufferSize?: number;
    enableBackpressure?: boolean;
    onEvent?: (event: BaseSseEvent) => void;
    onError?: (error: Error) => void;
    onComplete?: () => void;
}
export interface StreamWriterStats {
    totalEvents: number;
    bytesWritten: number;
    startTime: number;
    lastWriteTime: number;
    errors: number;
}
/**
 * 统一的SSE流写入器
 */
export declare class StreamWriter {
    private stream;
    private config;
    private stats;
    private heartbeatInterval?;
    private isActive;
    private writeQueue;
    private isWriting;
    constructor(stream: PassThrough, config?: StreamWriterConfig);
    /**
     * 设置心跳
     */
    private setupHeartbeat;
    /**
     * 设置错误处理
     */
    private setupErrorHandling;
    /**
     * 发送心跳事件
     */
    private sendHeartbeat;
    /**
     * 写入单个事件
     */
    private writeEvent;
    /**
     * 处理背压
     */
    private handleBackpressure;
    /**
     * 序列化Responses事件（临时实现，需要 ResponsesSerializer）
     * TODO: 等Responses协议修复后，实现完整的ResponsesSerializer
     * 当前为临时实现，仅用于避免编译错误
     */
    private serializeResponsesEvent;
    /**
     * 异步写入事件流
     */
    writeEventStream(events: AsyncIterable<BaseSseEvent>): Promise<void>;
    /**
     * 同步写入事件数组
     */
    writeEvents(events: BaseSseEvent[]): Promise<void>;
    /**
     * 写入Chat事件流
     */
    writeChatEvents(events: AsyncIterable<ChatSseEvent> | ChatSseEvent[]): Promise<void>;
    /**
     * 写入Responses事件流
     */
    writeResponsesEvents(events: AsyncIterable<ResponsesSseEvent> | ResponsesSseEvent[]): Promise<void>;
    /**
     * 写入Anthropic事件流
     */
    writeAnthropicEvents(events: AsyncIterable<AnthropicSseEvent> | AnthropicSseEvent[]): Promise<void>;
    /**
     * 写入Gemini事件流
     */
    writeGeminiEvents(events: AsyncIterable<GeminiSseEvent> | GeminiSseEvent[]): Promise<void>;
    /**
     * 完成流写入
     */
    complete(): void;
    /**
     * 中止流写入
     */
    abort(error?: Error): void;
    /**
     * 获取写入统计
     */
    getStats(): StreamWriterStats;
    /**
     * 检查流是否活跃
     */
    isStreamActive(): boolean;
    /**
     * 清理资源
     */
    private cleanup;
    /**
     * 获取底层流
     */
    getUnderlyingStream(): PassThrough;
}
/**
 * 创建Chat流写入器工厂函数
 */
export declare function createChatStreamWriter(stream: PassThrough, config?: StreamWriterConfig): StreamWriter;
/**
 * 创建Responses流写入器工厂函数
 */
export declare function createResponsesStreamWriter(stream: PassThrough, config?: StreamWriterConfig): StreamWriter;
/**
 * 创建Anthropic流写入器工厂函数
 */
export declare function createAnthropicStreamWriter(stream: PassThrough, config?: StreamWriterConfig): StreamWriter;
/**
 * 创建Gemini流写入器工厂函数
 */
export declare function createGeminiStreamWriter(stream: PassThrough, config?: StreamWriterConfig): StreamWriter;
