/**
 * SageMaker Streaming Response Parsers
 *
 * This module provides protocol-specific parsers for different streaming
 * formats used by SageMaker endpoints (HuggingFace, LLaMA, custom models).
 */
import type { SageMakerStreamChunk, SageMakerUsage, SageMakerStructuredOutput } from "../../types/providers.js";
import { type StructuredOutputParser } from "./structured-parser.js";
/**
 * Shared bracket counting state and utilities
 * Used by both validateJSONCompleteness and StructuredOutputParser
 */
export type BracketCountingState = {
    braceCount: number;
    bracketCount: number;
    inString: boolean;
    escapeNext: boolean;
};
/**
 * Process a single character for bracket counting logic
 * Shared utility to avoid code duplication between parsers
 */
export declare function processBracketCharacter(char: string, state: BracketCountingState): {
    isValid: boolean;
    reason?: string;
};
/**
 * Utility function to validate JSON completeness using efficient bracket counting
 * Extracted from parseArgumentsForToolCall for reusability
 */
export declare function validateJSONCompleteness(jsonString: string): {
    isComplete: boolean;
    reason?: string;
};
/**
 * Utility function to parse tool call arguments with robust validation
 * Extracted from parseArgumentsForToolCall for reusability
 */
export declare function parseToolCallArguments(args: string): {
    arguments?: string;
    complete?: boolean;
    argumentsDelta?: string;
};
/**
 * Base interface for streaming response parsers
 */
export type StreamingParser = {
    /** Parse a chunk of streaming data */
    parse(chunk: Uint8Array): SageMakerStreamChunk[];
    /** Check if a chunk indicates completion */
    isComplete(chunk: SageMakerStreamChunk): boolean;
    /** Extract final usage information */
    extractUsage(finalChunk: SageMakerStreamChunk): SageMakerUsage | undefined;
    /** Get parser name for debugging */
    getName(): string;
    /** Reset parser state for new stream */
    reset(): void;
};
/**
 * Abstract base parser with common functionality
 */
declare abstract class BaseStreamingParser implements StreamingParser {
    protected buffer: string;
    protected isCompleted: boolean;
    protected totalUsage?: SageMakerUsage;
    protected structuredParser?: StructuredOutputParser;
    protected responseSchema?: Record<string, unknown>;
    abstract parse(chunk: Uint8Array): SageMakerStreamChunk[];
    abstract getName(): string;
    isComplete(chunk: SageMakerStreamChunk): boolean;
    extractUsage(finalChunk: SageMakerStreamChunk): SageMakerUsage | undefined;
    reset(): void;
    /**
     * Enable structured output parsing with optional schema
     */
    enableStructuredOutput(schema?: Record<string, unknown>): void;
    /**
     * Parse structured content if enabled
     */
    protected parseStructuredContent(content: string): SageMakerStructuredOutput | undefined;
    protected decodeChunk(chunk: Uint8Array): string;
    protected parseJSON(text: string): unknown;
}
/**
 * HuggingFace Transformers streaming parser (Server-Sent Events)
 */
export declare class HuggingFaceStreamParser extends BaseStreamingParser {
    getName(): string;
    parse(chunk: Uint8Array): SageMakerStreamChunk[];
    private parseHuggingFaceChunk;
    private parseHuggingFaceUsage;
    private mapFinishReason;
}
/**
 * LLaMA/OpenAI-compatible streaming parser (JSON Lines)
 */
export declare class LlamaStreamParser extends BaseStreamingParser {
    getName(): string;
    parse(chunk: Uint8Array): SageMakerStreamChunk[];
    private parseLlamaChunk;
    /**
     * Parse tool call arguments with robust validation and error handling
     */
    private parseToolCallArguments;
    /**
     * Parse streaming tool call from OpenAI-compatible format (Phase 2.3)
     */
    private parseStreamingToolCall;
    private parseLlamaUsage;
    private mapFinishReason;
}
/**
 * Custom/Generic streaming parser (Chunked Transfer)
 */
export declare class CustomStreamParser extends BaseStreamingParser {
    private expectedFormat;
    constructor(format?: "json" | "text");
    getName(): string;
    parse(chunk: Uint8Array): SageMakerStreamChunk[];
    private parseJSONFormat;
    private parseTextFormat;
    private parseCustomChunk;
    private parseCustomUsage;
}
/**
 * Parser factory to create appropriate parser for detected protocol
 */
export declare class StreamingParserFactory {
    static createParser(protocol: string, options?: Record<string, unknown>): StreamingParser;
    static getSupportedProtocols(): string[];
}
/**
 * Utility function to estimate token usage when not provided
 */
export declare function estimateTokenUsage(prompt: string, completion: string): SageMakerUsage;
export {};
