/** * Auto-recording bridge between the MCP tool dispatcher and the AnalyticsManager. * * Every token-optimizer tool returns its result as a JSON string inside an MCP * `content[].text` block. Most optimization tools include a savings triplet * (original tokens, optimized tokens, tokens saved) under one of a handful of * well-known field names. This module extracts that triplet from a tool result * and records it, so the analytics breakdown tools (`get_hook_analytics`, * `get_action_analytics`, `get_mcp_server_analytics`, `export_analytics`, * `get_optimization_report`) have real data instead of always returning zeros. * * It is intentionally best-effort: a tool whose result has no recognizable * savings triplet is silently skipped, and any parsing/storage error is * swallowed so recording can never break a tool call. */ import type { AnalyticsManager } from './analytics-manager.js'; import type { HookPhase } from './analytics-types.js'; /** MCP tool result shape (the parts we read). */ interface McpToolResult { content?: Array<{ type?: string; text?: string; }>; isError?: boolean; _meta?: Record; } /** A normalized savings measurement extracted from a tool result. */ export interface SavingsTriplet { originalTokens: number; optimizedTokens: number; tokensSaved: number; } /** * Extract a savings triplet from a parsed tool-result payload, checking the * top level first, then one level of common nested containers. */ export declare function extractSavings(payload: unknown): SavingsTriplet | null; /** Resolve the current hook phase from the environment (set by hook launchers). */ export declare function currentHookPhase(): HookPhase; /** * Best-effort: record the savings from a single MCP tool result. Never throws. * * @param manager the shared AnalyticsManager * @param toolName the tool that produced the result (e.g. "smart_read") * @param result the MCP result object returned by the tool handler */ export declare function recordToolAnalytics(manager: AnalyticsManager, toolName: string, result: McpToolResult, attribution?: { client?: string | null; clientVersion?: string | null; model?: string | null; modelVersion?: string | null; operationId?: string | null; }, baselineResult?: McpToolResult | null): Promise; export {}; //# sourceMappingURL=record-tool-analytics.d.ts.map