/**
 * OpenClaw-inspired Smart Context Compaction System
 *
 * Intelligently reduces conversation history while preserving essential context:
 * - Provider-specific message validation (Gemini/Anthropic/OpenAI have different rules)
 * - Channel-based history limits (DM vs group contexts)
 * - Token verification after compaction
 * - Multi-stage compaction strategies
 */
import { EventEmitter } from 'events';
export interface Message {
    role: 'system' | 'user' | 'assistant' | 'tool';
    content: string | null;
    name?: string;
    tool_call_id?: string;
    tool_calls?: Array<{
        id: string;
        type: 'function';
        function: {
            name: string;
            arguments: string;
        };
    }>;
}
export type Provider = 'openai' | 'anthropic' | 'gemini' | 'grok' | 'ollama' | 'lmstudio';
export type ChannelType = 'dm' | 'group' | 'api' | 'cli';
export interface CompactionConfig {
    /** Maximum tokens allowed after compaction */
    maxTokens: number;
    /** Target token count (aim for this after compaction) */
    targetTokens?: number;
    /** Provider for validation rules */
    provider: Provider;
    /** Channel type for history limits */
    channelType: ChannelType;
    /** Custom instructions for summarization */
    customInstructions?: string;
    /** Minimum messages to keep */
    minMessages?: number;
    /** Whether to preserve system message */
    preserveSystem?: boolean;
    /** Whether to preserve tool calls */
    preserveToolCalls?: boolean;
}
export interface CompactionResult {
    success: boolean;
    originalTokens: number;
    compactedTokens: number;
    messagesRemoved: number;
    strategy: CompactionStrategy;
    error?: string;
}
export type CompactionStrategy = 'none' | 'truncate' | 'summarize' | 'hybrid' | 'aggressive';
export interface ProviderRules {
    /** Maximum consecutive messages of same role */
    maxConsecutiveSameRole: number;
    /** Whether tool results must follow tool calls */
    toolResultMustFollowCall: boolean;
    /** Whether empty content is allowed */
    allowEmptyContent: boolean;
    /** Maximum message content length */
    maxContentLength: number;
    /** Required message patterns */
    patterns: {
        mustStartWith?: 'system' | 'user';
        mustEndWith?: 'user' | 'assistant';
    };
}
export declare class SmartCompactionEngine extends EventEmitter {
    private config;
    private rules;
    private channelLimits;
    constructor(config: CompactionConfig);
    /**
     * Main compaction entry point
     */
    compact(messages: Message[]): Promise<{
        messages: Message[];
        result: CompactionResult;
    }>;
    /**
     * Sanitize messages according to provider rules
     */
    sanitizeMessages(messages: Message[]): Message[];
    /**
     * Merge consecutive messages from the same role
     */
    private mergeConsecutiveMessages;
    /**
     * Validate tool call/result ordering
     */
    private validateToolCallOrder;
    /**
     * Ensure message patterns match provider requirements
     */
    private ensureMessagePatterns;
    /**
     * Determine the best compaction strategy
     */
    private determineStrategy;
    /**
     * Truncate oldest messages to fit token limit
     */
    private truncateMessages;
    /**
     * Summarize older messages
     */
    private summarizeMessages;
    /**
     * Hybrid compaction: truncate + summarize
     */
    private hybridCompaction;
    /**
     * Aggressive compaction: maximum compression
     */
    private aggressiveCompaction;
    /**
     * Create a summary of messages
     */
    private createSummary;
    /**
     * Estimate tokens for messages
     */
    estimateTokens(messages: Message[]): number;
    /**
     * Estimate tokens for a single message
     */
    private estimateMessageTokens;
    /**
     * Apply channel-specific limits
     */
    limitByChannel(messages: Message[]): Message[];
    /**
     * Update configuration
     */
    updateConfig(config: Partial<CompactionConfig>): void;
    /**
     * Get current configuration
     */
    getConfig(): CompactionConfig;
}
export declare function getSmartCompactionEngine(config?: CompactionConfig): SmartCompactionEngine;
export declare function resetSmartCompactionEngine(): void;
/**
 * Convenience function for quick compaction
 */
export declare function compactMessages(messages: Message[], config: CompactionConfig): Promise<{
    messages: Message[];
    result: CompactionResult;
}>;
/**
 * Convenience function to check if compaction is needed
 */
export declare function needsCompaction(messages: Message[], maxTokens: number): boolean;
