import { ConversationSummary } from "../tools/distill-conversation-tool.js";
import { ModelSettings } from "@inkeep/agents-core";

//#region src/domains/run/services/BaseCompressor.d.ts
interface CompressionConfig {
  hardLimit: number;
  safetyBuffer: number;
  enabled?: boolean;
}
interface CompressionResult {
  artifactIds: string[];
  summary: any;
}
interface CompressionEventData {
  reason: 'manual' | 'automatic';
  messageCount: number;
  artifactCount: number;
  contextSizeBefore: number;
  contextSizeAfter: number;
  compressionType: 'mid_generation' | 'conversation_level';
}
/**
 * Base compressor class containing shared functionality for all compression types
 */
declare abstract class BaseCompressor {
  protected sessionId: string;
  protected conversationId: string;
  protected tenantId: string;
  protected projectId: string;
  protected config: CompressionConfig;
  protected summarizerModel?: ModelSettings | undefined;
  protected baseModel?: ModelSettings | undefined;
  protected processedToolCalls: Set<string>;
  protected cumulativeSummary: ConversationSummary | null;
  constructor(sessionId: string, conversationId: string, tenantId: string, projectId: string, config: CompressionConfig, summarizerModel?: ModelSettings | undefined, baseModel?: ModelSettings | undefined);
  /**
   * Get the hard limit for compression decisions
   */
  getHardLimit(): number;
  /**
   * Estimate tokens (4 chars = 1 token)
   */
  protected estimateTokens(content: any): number;
  /**
   * Calculate total context size for messages
   */
  protected calculateContextSize(messages: any[]): number;
  /**
   * Save tool results as artifacts
   */
  saveToolResultsAsArtifacts(messages: any[], startIndex?: number): Promise<Record<string, string>>;
  /**
   * Extract all tool call IDs from messages for batch lookup
   */
  private extractToolCallIds;
  /**
   * Batch lookup existing artifacts for multiple tool call IDs (solves N+1 query problem)
   */
  private batchFindExistingArtifacts;
  /**
   * Query database for existing artifacts using enhanced getLedgerArtifacts with batch support
   */
  private queryExistingArtifactsBatch;
  /**
   * Convert database format tool-result messages to Vercel AI SDK format
   */
  private convertDatabaseFormatMessage;
  /**
   * Process all tool results in a message
   */
  private processMessageToolResults;
  /**
   * Process a single tool result block
   */
  private processToolResult;
  /**
   * Check if a tool should be skipped
   */
  private shouldSkipToolCall;
  /**
   * Create a new artifact for a tool call
   */
  private createNewArtifact;
  /**
   * Find tool input for a given tool call ID
   */
  private findToolInput;
  /**
   * Build artifact data structure
   */
  private buildArtifactData;
  /**
   * Validate artifact data has meaningful content
   */
  private validateArtifactData;
  /**
   * Create conversation summary using distillConversation
   */
  protected createConversationSummary(messages: any[], toolCallToArtifactMap: Record<string, string>): Promise<any>;
  /**
   * Record compression event in session
   */
  /**
   * Generate a preview of the tool result for the artifact summary
   */
  protected generateResultPreview(toolResult: any): string;
  protected recordCompressionEvent(eventData: CompressionEventData): void;
  /**
   * Check if tool result data is effectively empty
   */
  protected isEmpty(toolResultData: any): boolean;
  /**
   * Recursively remove _structureHints from an object
   */
  protected removeStructureHints(obj: any): any;
  /**
   * Get current compression summary
   */
  getCompressionSummary(): ConversationSummary | null;
  /**
   * Clean up memory by clearing processed tool calls and optionally resetting summary
   * Call this at the end of agent generation or after compression cycles
   */
  cleanup(options?: {
    resetSummary?: boolean;
    keepRecentToolCalls?: number;
  }): void;
  /**
   * Partial cleanup that preserves recent state for ongoing conversations
   */
  partialCleanup(): void;
  /**
   * Full cleanup that resets all state - use when conversation/session ends
   */
  fullCleanup(): void;
  /**
   * Get current state for debugging
   */
  getState(): {
    config: CompressionConfig;
    processedToolCalls: string[];
    cumulativeSummary: {
      type: "conversation_summary_v1";
      high_level: string;
      user_intent: string;
      decisions: string[];
      open_questions: string[];
      next_steps: {
        for_agent: string[];
        for_user: string[];
      };
      session_id?: string | null | undefined;
      related_artifacts?: {
        id: string;
        name: string;
        tool_name: string;
        tool_call_id: string;
        content_type: string;
        key_findings: string[];
      }[] | undefined;
    } | null;
  };
  /**
   * Safe compression wrapper with fallback handling
   */
  safeCompress(messages: any[], fullContextSize?: number): Promise<CompressionResult>;
  /**
   * Simple compression fallback using the same logic as Agent.simpleCompression
   * Returns the compressed messages, not just a summary
   */
  protected simpleCompressionFallback(messages: any[]): Promise<CompressionResult>;
  abstract isCompressionNeeded(messages: any[]): boolean;
  abstract compress(messages: any[]): Promise<CompressionResult>;
  abstract getCompressionType(): string;
}
/**
 * Get model-aware compression config for any model
 * @param modelSettings - Model settings to get context window for
 * @param targetPercentage - Target percentage of context window (e.g., 0.5 for conversation, undefined for aggressive)
 */
declare function getModelAwareCompressionConfig(modelSettings?: ModelSettings, targetPercentage?: number): CompressionConfig;
//#endregion
export { BaseCompressor, CompressionConfig, CompressionEventData, CompressionResult, getModelAwareCompressionConfig };