import { RetryConfig } from '../utils/resilience.js';

/**
 * Core types for Morph Compact SDK
 */

/**
 * A line range that was removed during compaction (1-indexed, inclusive)
 */
interface CompactedRange {
    start: number;
    end: number;
}
/**
 * A compacted message with metadata about which lines were removed
 */
interface CompactMessage {
    role: string;
    content: string;
    name?: string | null;
    compacted_line_ranges: CompactedRange[];
    /** Line ranges force-preserved via <keepContext> tags */
    kept_line_ranges: CompactedRange[];
}
/**
 * Input for /v1/compact
 */
interface CompactInput {
    /** String input, array of messages, or omitted (use messages field instead) */
    input?: string | Array<{
        role: string;
        content: string;
        name?: string;
    }>;
    /** Array of messages to compact (takes priority over input) */
    messages?: Array<{
        role: string;
        content: string;
        name?: string;
    }>;
    /** Query to condition compaction on. Auto-detected from last user message if omitted. */
    query?: string;
    /** Fraction of content to keep (0.05-1.0). Default 0.5 */
    compressionRatio?: number;
    /** Keep last N messages uncompressed. Default 2 */
    preserveRecent?: number;
    /** Include compacted_line_ranges in response (default true) */
    includeLineRanges?: boolean;
    /** Include '(filtered N lines)' text markers (default true). When false, gaps become empty lines. */
    includeMarkers?: boolean;
    /** Model identifier */
    model?: string;
}
/**
 * Result from /v1/compact
 */
interface CompactResult {
    /** Response ID */
    id: string;
    /** All compacted messages joined by newline */
    output: string;
    /** Compacted messages with line ranges */
    messages: CompactMessage[];
    /** Token usage and compression statistics */
    usage: {
        input_tokens: number;
        output_tokens: number;
        compression_ratio: number;
        processing_time_ms: number;
    };
    /** Model used */
    model: string;
}
/**
 * Configuration for CompactClient
 */
interface CompactConfig {
    /** Morph API key (defaults to MORPH_API_KEY env var) */
    morphApiKey?: string;
    /** Morph API base URL */
    morphApiUrl?: string;
    /** Timeout for API calls in ms (default: 120000) */
    timeout?: number;
    /** Retry configuration for API calls */
    retryConfig?: RetryConfig;
    /** Enable debug logging (default: false) */
    debug?: boolean;
}

export type { CompactConfig, CompactInput, CompactMessage, CompactResult, CompactedRange };
