/** * Token Metrics Utility * * Provides token estimation, metrics calculation, and formatted header generation * for displaying token reduction statistics in tool responses. * * Supports the v0.12.0 token metrics feature - shows before/after token counts, * reduction percentage, threats blocked, and elapsed time. */ /** * Token metrics data structure */ export interface TokenMetrics { tokensBefore: number; tokensAfter: number; reductionPct: number; threatsBlocked: number; elapsedMs: number; } /** * Estimates token count from character count using GPT-family approximation. * * Formula: tokens ≈ characters / 4 (rounded up) * * This is a standard approximation for GPT-family models. For production * use cases requiring exact token counts, consider using tiktoken or similar. * * @param text Input text to estimate tokens for * @returns Estimated token count */ export declare function estimateTokens(text: string): number; /** * Calculates token metrics from raw and sanitized content. * * Handles edge cases: * - Empty raw content → tokensBefore = 0 * - Sanitized longer than raw (shouldn't happen) → reductionPct = 0 * - Ensures reduction percentage is never negative * * @param rawContent Original content before sanitization * @param sanitizedContent Content after sanitization * @param threatsBlocked Number of threats detected and blocked * @param elapsedMs Elapsed time in milliseconds * @returns TokenMetrics object */ export declare function calculateMetrics(rawContent: string, sanitizedContent: string, threatsBlocked: number, elapsedMs: number): TokenMetrics; /** * Formats token metrics as a visually-structured header box. * * Output format: * ``` * ╔═ visus-mcp ═══════════════════════════════╗ * ║ 4,200 → 890 tokens · 79% reduction ║ * ║ 3 threats blocked · fetch 1.2s ║ * ╚════════════════════════════════════════════╝ * ``` * * Box width is dynamically sized to fit content. Uses Unicode box-drawing * characters for clean visual appearance. * * @param metrics Token metrics to format * @returns Formatted header string (includes trailing newline for separation) */ export declare function formatMetricsHeader(metrics: TokenMetrics): string; /** * Checks if token metrics should be displayed based on environment configuration. * * Defaults to true. Can be disabled by setting VISUS_SHOW_METRICS=false. * * @returns true if metrics should be displayed, false otherwise */ export declare function shouldShowMetrics(): boolean; //# sourceMappingURL=tokenMetrics.d.ts.map