import { IOptimizationModule, OptimizationResult } from './IOptimizationModule.js'; import { CompressionEngine } from '../core/compression-engine.js'; import { ITokenCounter } from '../interfaces/ITokenCounter.js'; /** * Compression-based optimization module. * * This module wraps the CompressionEngine to provide Brotli compression * as part of the optimization pipeline. It compresses text and stores it * in base64 format, which can be cached externally to reduce token usage * in the LLM context window. * * Key features: * - Brotli compression with configurable quality * - Base64 encoding for easy storage * - Token counting before and after compression * - Detailed compression statistics * * Note: This module is primarily useful for caching scenarios where the * compressed content is stored externally and not sent to the LLM. The * token savings represent the removal of content from the context window. * * @example * ```typescript * const compressionEngine = new CompressionEngine(); * const tokenCounter = new TokenCounter(); * const compressionModule = new CompressionModule( * compressionEngine, * tokenCounter, * { quality: 11 } // Maximum compression * ); * * const result = await compressionModule.apply(largeText); * console.log(`Compressed: ${result.savings} tokens saved`); * console.log(`Compression ratio: ${result.metadata?.compressionRatio}`); * ``` */ export declare class CompressionModule implements IOptimizationModule { private readonly compressionEngine; private readonly tokenCounter; private readonly options?; readonly name = "compression"; /** * Create a compression module. * * @param compressionEngine - The compression engine instance * @param tokenCounter - Token counter for measuring savings * @param options - Optional compression configuration */ constructor(compressionEngine: CompressionEngine, tokenCounter: ITokenCounter, options?: { quality?: number; mode?: "text" | "font" | "generic"; minSize?: number; } | undefined); /** * Apply Brotli compression to the input text. * * This method: * 1. Counts tokens in the original text * 2. Compresses the text using Brotli * 3. Encodes the compressed data as base64 * 4. Returns the base64 string (for external caching) * 5. Calculates token savings based on context window clearance * * Note: The compressed base64 string is meant to be cached externally. * The token savings represent removing the original text from the * LLM context window, not the size of the compressed data. * * @param text - The text to compress * @returns Optimization result with compression metadata */ apply(text: string): Promise; /** * Decompress previously compressed content. * * This is a utility method for retrieving cached compressed content. * Not part of the standard optimization pipeline. * * @param compressed - Base64 encoded compressed text * @returns Original decompressed text */ decompress(compressed: string): string; } //# sourceMappingURL=CompressionModule.d.ts.map