/**
 * Chunk Handler
 *
 * Handles different types of stream chunks with type-safe processing
 * and content accumulation.
 */
import { EventEmitter } from 'events';
export type ChunkType = 'content' | 'tool_call' | 'tool_result' | 'token_count' | 'error' | 'done';
export interface Chunk {
    type: ChunkType;
    content?: string;
    toolCall?: {
        id: string;
        name: string;
        arguments: string;
    };
    toolResult?: {
        id: string;
        success: boolean;
        output?: string;
        error?: string;
    };
    tokenCount?: number;
    error?: string;
}
export interface ChunkHandlerOptions {
    /** Maximum content length to accumulate */
    maxContentLength?: number;
    /** Whether to validate chunk structure */
    validateChunks?: boolean;
    /** Custom chunk type handlers */
    typeHandlers?: Partial<Record<ChunkType, (chunk: Chunk) => void>>;
}
export interface AccumulatedContent {
    content: string;
    chunks: Chunk[];
    toolCalls: Chunk['toolCall'][];
    toolResults: Chunk['toolResult'][];
    tokenCount: number;
    errors: string[];
}
export declare class ChunkHandler extends EventEmitter {
    private options;
    private accumulated;
    private chunkCount;
    constructor(options?: ChunkHandlerOptions);
    private createEmptyAccumulator;
    /**
     * Handle a single chunk
     */
    handle(chunk: Chunk): void;
    /**
     * Handle multiple chunks
     */
    handleMany(chunks: Chunk[]): void;
    /**
     * Process an async iterable of chunks
     */
    process(source: AsyncIterable<Chunk>): AsyncGenerator<Chunk, void, unknown>;
    private handleContentChunk;
    private handleToolCallChunk;
    private handleToolResultChunk;
    private handleTokenCountChunk;
    private handleErrorChunk;
    private handleDoneChunk;
    /**
     * Validate a chunk structure
     */
    validateChunk(chunk: Chunk): {
        valid: boolean;
        errors: string[];
    };
    private isValidChunkType;
    /**
     * Get accumulated content
     */
    getAccumulated(): AccumulatedContent;
    /**
     * Get content string
     */
    getContent(): string;
    /**
     * Get chunk count
     */
    getChunkCount(): number;
    /**
     * Check if stream has errors
     */
    hasErrors(): boolean;
    /**
     * Check if stream has tool calls
     */
    hasToolCalls(): boolean;
    /**
     * Reset handler state
     */
    reset(): void;
    /**
     * Create a content chunk
     */
    static createContentChunk(content: string): Chunk;
    /**
     * Create a tool call chunk
     */
    static createToolCallChunk(id: string, name: string, args: string): Chunk;
    /**
     * Create a tool result chunk
     */
    static createToolResultChunk(id: string, success: boolean, output?: string, error?: string): Chunk;
    /**
     * Create a token count chunk
     */
    static createTokenCountChunk(count: number): Chunk;
    /**
     * Create an error chunk
     */
    static createErrorChunk(error: string): Chunk;
    /**
     * Create a done chunk
     */
    static createDoneChunk(): Chunk;
}
