/**
 * Block-Aware Markdown Chunker
 *
 * Intelligently chunks streaming markdown content while preserving
 * code fence integrity. Never splits inside code blocks unless forced.
 */
import { EventEmitter } from 'events';
/**
 * Markdown block state
 */
export interface BlockState {
    /** Whether currently inside a code block */
    inCodeBlock: boolean;
    /** Current fence string (``` or ~~~) */
    fence: string;
    /** Language identifier if any */
    language: string;
    /** Depth of nested blocks (for edge cases) */
    depth: number;
}
/**
 * Chunk result
 */
export interface ChunkResult {
    /** The chunk content */
    content: string;
    /** Whether this chunk was force-split */
    forceSplit: boolean;
    /** Whether fence was closed for force-split */
    fenceClosed: boolean;
    /** Fence to reopen in next chunk */
    reopenFence?: string;
}
/**
 * Chunker configuration
 */
export interface MarkdownChunkerConfig {
    /** Soft maximum chunk size (will try to split at natural breaks) */
    softMaxChars: number;
    /** Hard maximum chunk size (will force split if exceeded) */
    hardMaxChars: number;
    /** Preferred break characters in order of preference */
    preferredBreaks: string[];
    /** Whether to preserve code blocks (avoid splitting inside) */
    preserveCodeBlocks: boolean;
    /** Whether to add continuation markers */
    addContinuationMarkers: boolean;
}
/**
 * Default chunker configuration
 */
export declare const DEFAULT_CHUNKER_CONFIG: MarkdownChunkerConfig;
/**
 * Create initial block state
 */
export declare function createBlockState(): BlockState;
/**
 * Detect fence opening/closing in text
 */
export declare function detectFence(text: string, state: BlockState): {
    newState: BlockState;
    fencePositions: Array<{
        index: number;
        isOpen: boolean;
        fence: string;
        language: string;
    }>;
};
/**
 * Update block state with new content
 */
export declare function updateBlockState(text: string, state: BlockState): BlockState;
/**
 * Block-aware markdown chunker
 */
export declare class MarkdownChunker extends EventEmitter {
    private config;
    private buffer;
    private blockState;
    private chunks;
    constructor(config?: Partial<MarkdownChunkerConfig>);
    /**
     * Add text to the buffer
     */
    write(text: string): ChunkResult[];
    /**
     * Flush remaining buffer
     */
    flush(): ChunkResult[];
    /**
     * Process the buffer and extract chunks
     */
    private processBuffer;
    /**
     * Extract a chunk from the buffer
     */
    private extractChunk;
    /**
     * Find the best split point
     */
    private findSplitPoint;
    /**
     * Force split the buffer (used when hard max is reached)
     */
    private forceSplit;
    /**
     * Get current block state
     */
    getBlockState(): BlockState;
    /**
     * Get all chunks generated so far
     */
    getChunks(): ChunkResult[];
    /**
     * Get current buffer content
     */
    getBuffer(): string;
    /**
     * Reset the chunker
     */
    reset(): void;
}
/**
 * Chunk a complete markdown string
 */
export declare function chunkMarkdown(text: string, config?: Partial<MarkdownChunkerConfig>): ChunkResult[];
/**
 * Check if text contains unclosed code blocks
 */
export declare function hasUnclosedCodeBlock(text: string): boolean;
/**
 * Count code blocks in text
 */
export declare function countCodeBlocks(text: string): {
    open: number;
    closed: number;
};
/**
 * Fix unclosed code blocks in text
 */
export declare function fixUnclosedCodeBlocks(text: string): string;
/**
 * Create a streaming chunker with callback
 */
export declare function createStreamingChunker(onChunk: (chunk: ChunkResult) => void, config?: Partial<MarkdownChunkerConfig>): {
    write: (text: string) => void;
    flush: () => void;
    reset: () => void;
};
