import { EventEmitter } from 'events';
import { Readable, Transform } from 'stream';
import { StreamEvent, StreamStats, StreamChunk } from './types.js';
import { OptimizedChunkProcessorOptions, StreamingMetrics } from './chunk-processor.js';
import { CodeBuddyToolCall } from '../codebuddy/client.js';
import { ToolResult } from '../types/index.js';
/**
 * Extended stream stats with detailed metrics
 */
export interface ExtendedStreamStats extends StreamStats {
    /** Detailed metrics from chunk processor */
    metrics?: StreamingMetrics;
    /** Number of chunk timeouts */
    chunkTimeouts?: number;
    /** Whether stream completed due to timeout */
    timedOut?: boolean;
}
/**
 * Options for stream handler
 */
export interface StreamHandlerOptions {
    /** Options to pass to the chunk processor */
    processorOptions?: OptimizedChunkProcessorOptions;
    /** Per-chunk timeout in ms (default: 5000) */
    chunkTimeoutMs?: number;
    /** Global stream timeout in ms (default: 0 = no timeout) */
    globalTimeoutMs?: number;
    /** Enable metrics collection (default: true) */
    collectMetrics?: boolean;
}
export declare class StreamHandler extends EventEmitter {
    private processor;
    private stats;
    private options;
    private globalTimeoutTimer;
    constructor(options?: StreamHandlerOptions);
    private createInitialStats;
    /**
     * Start global timeout timer
     */
    private startGlobalTimeout;
    /**
     * Clear global timeout timer
     */
    private clearGlobalTimeout;
    /**
     * Handle an async stream of chunks
     */
    handleStream(stream: AsyncIterable<StreamChunk>, abortSignal?: AbortSignal): AsyncGenerator<StreamEvent, void, unknown>;
    /**
     * Create a Node.js Transform stream for piping
     * This allows integration with native Node.js streams
     */
    createTransformStream(): Transform;
    /**
     * Process a Readable stream and return an async generator
     * Useful for integrating with Node.js streams
     */
    processReadableStream(readable: Readable, abortSignal?: AbortSignal): AsyncGenerator<StreamEvent, void, unknown>;
    /**
     * Helper to create a tool result event
     */
    createToolResultEvent(toolCall: CodeBuddyToolCall, result: ToolResult): StreamEvent;
    /**
     * Get current streaming statistics
     */
    getStats(): StreamStats;
    /**
     * Get accumulated data
     */
    getAccumulated(): {
        content: string;
        toolCalls: CodeBuddyToolCall[];
    };
}
