/** * token-logger.ts * * Tracks prompt and response sizes for every AI call made during a session * and reports estimated token usage to stderr. * * Because Playwright Pilot AI is designed to minimize AI token usage, it is important * to have visibility into how many tokens each MCP tool call actually consumes. * This module provides that visibility without requiring access to the actual * tokenizer — it uses the conservative approximation of 4 characters = 1 token. * * Usage pattern: * TokenLogger.log('generate_test', promptText, responseText, rawDomCharCount); * TokenLogger.summary(); // at end of a test run * * The "savedVsRaw" field records how many tokens were saved by compressing the * DOM snapshot before including it in the prompt, compared to sending it raw. * * A singleton TokenLogger instance is exported for use across all MCP tools. * * Role in the overall flow: * generate_test / heal_test → TokenLogger.log() * execute_test / run_yaml → TokenLogger.summary() */ /** * Tracks, aggregates, and reports estimated AI token usage across a session. */ declare class TokenLoggerImpl { private entries; /** * Record one AI call with its prompt and response sizes. * * Logs a single-line summary to stderr immediately, including the estimated * token savings if a raw DOM size is provided. * * @param tool - Name of the MCP tool that triggered the call (e.g. "generate_test"). * @param prompt - The prompt string sent to the AI model. * @param response - The response string received (pass '' if not yet available). * @param rawDomSize - Optional: character count of the full DOM that was NOT sent, * used to calculate how many tokens compression saved. */ log(tool: string, prompt: string, response?: string, rawDomSize?: number): void; /** * Log only the prompt (before the response is available) and return the * entry index so the response can be added later via logResponse(). * * @param tool - MCP tool name. * @param prompt - The prompt string sent. * @param rawDomSize - Optional raw DOM character count for savings calculation. * @returns The zero-based index of the new entry, for use with logResponse(). */ logPrompt(tool: string, prompt: string, rawDomSize?: number): number; /** * Update a previously logged entry with the actual response size. * Call this after the AI model responds, using the index returned by logPrompt(). * * @param entryIndex - The index returned by the preceding logPrompt() call. * @param response - The response string received from the AI model. */ logResponse(entryIndex: number, response: string): void; /** * Print a cumulative token usage summary to stderr. * Includes total AI calls, prompt tokens, response tokens, total tokens, * and tokens saved by DOM compression (if any were saved). */ summary(): void; /** * Clear all recorded entries (e.g. between test runs). */ reset(): void; /** Total estimated tokens consumed across all recorded AI calls this session. */ get totalTokensUsed(): number; } /** Singleton token logger used across all MCP tools. */ export declare const TokenLogger: TokenLoggerImpl; export {}; //# sourceMappingURL=token-logger.d.ts.map