#!/usr/bin/env node
/**
 * DeltaAccumulator - Maintain state across streaming deltas
 *
 * Tracks:
 * - Message metadata (id, model, role)
 * - Content blocks (thinking, text)
 * - Current block index
 * - Accumulated content
 *
 * Usage:
 *   const acc = new DeltaAccumulator(thinkingConfig);
 *   const events = transformer.transformDelta(openaiEvent, acc);
 */
interface ThinkingConfig {
    [key: string]: unknown;
}
interface DeltaAccumulatorOptions {
    maxBlocks?: number;
    maxBufferSize?: number;
    loopDetectionThreshold?: number;
}
interface ContentBlock {
    index: number;
    type: string;
    content: string;
    started: boolean;
    stopped: boolean;
}
interface ToolCall {
    index: number;
    id: string;
    type: string;
    function: {
        name: string;
        arguments: string;
    };
    blockIndex: number;
}
interface ToolCallDelta {
    index: number;
    id?: string;
    type?: string;
    function?: {
        name?: string;
        arguments?: string;
    };
}
interface UsageStats {
    prompt_tokens?: number;
    input_tokens?: number;
    completion_tokens?: number;
    output_tokens?: number;
}
interface AccumulatorSummary {
    messageId: string;
    model: string | null;
    role: string;
    blockCount: number;
    currentIndex: number;
    toolCallCount: number;
    messageStarted: boolean;
    finalized: boolean;
    loopDetected: boolean;
    usage: {
        input_tokens: number;
        output_tokens: number;
    };
}
export declare class DeltaAccumulator {
    private messageId;
    private model;
    private role;
    private contentBlocks;
    private currentBlockIndex;
    private toolCalls;
    private toolCallsIndex;
    private thinkingBuffer;
    private textBuffer;
    private maxBlocks;
    private maxBufferSize;
    private loopDetectionThreshold;
    private loopDetected;
    private messageStarted;
    private finalized;
    private inputTokens;
    private outputTokens;
    constructor(_thinkingConfig?: ThinkingConfig, options?: DeltaAccumulatorOptions);
    /**
     * Get current content block
     * @returns Current block or null
     */
    getCurrentBlock(): ContentBlock | null;
    /**
     * Start new content block
     * @param type - Block type ('thinking', 'text', or 'tool_use')
     * @returns New block
     */
    startBlock(type: string): ContentBlock;
    /**
     * Add delta to current block
     * @param delta - Content delta
     */
    addDelta(delta: string): void;
    /**
     * Mark current block as stopped
     */
    stopCurrentBlock(): void;
    /**
     * Update usage statistics
     * @param usage - Usage object from OpenAI
     */
    updateUsage(usage: UsageStats): void;
    /**
     * Add or update tool call delta
     * @param toolCallDelta - Tool call delta from OpenAI
     */
    addToolCallDelta(toolCallDelta: ToolCallDelta): void;
    setToolCallBlockIndex(toolCallIndex: number, blockIndex: number): void;
    getToolCallBlockIndex(toolCallIndex: number): number;
    getUnstoppedBlocks(): ContentBlock[];
    /**
     * Get all tool calls
     * @returns Tool calls array
     */
    getToolCalls(): ToolCall[];
    /**
     * Check for planning loop pattern
     * Loop = N consecutive thinking blocks with no tool calls
     * @returns True if loop detected
     */
    checkForLoop(): boolean;
    /**
     * Reset loop detection state (for testing)
     */
    resetLoopDetection(): void;
    /**
     * Get summary of accumulated state
     * @returns Summary
     */
    getSummary(): AccumulatorSummary;
    /**
     * Check if message has been finalized
     */
    isFinalized(): boolean;
    /**
     * Check if message has started
     */
    isMessageStarted(): boolean;
    /**
     * Get message ID
     */
    getMessageId(): string;
    /**
     * Get model name
     */
    getModel(): string | null;
    /**
     * Get role
     */
    getRole(): string;
    /**
     * Get input tokens
     */
    getInputTokens(): number;
    /**
     * Get output tokens
     */
    getOutputTokens(): number;
    /**
     * Set model name
     */
    setModel(model: string): void;
    /**
     * Set message started flag
     */
    setMessageStarted(started: boolean): void;
    /**
     * Set role
     */
    setRole(role: string): void;
    /**
     * Set finalized flag
     */
    setFinalized(finalized: boolean): void;
    private finishReason;
    private usageReceived;
    /**
     * Set finish reason
     */
    setFinishReason(reason: string): void;
    /**
     * Get finish reason
     */
    getFinishReason(): string | null;
    /**
     * Check if usage stats have been received
     */
    hasUsageReceived(): boolean;
    /**
     * Mark usage as received
     */
    setUsageReceived(received: boolean): void;
    /**
     * Check if there are any tool calls, or check if a specific index exists
     */
    hasToolCall(index?: number): boolean;
    /**
     * Get tool call by index
     */
    getToolCall(index: number): ToolCall | undefined;
}
export {};
//# sourceMappingURL=delta-accumulator.d.ts.map