refactor(claude-kiro): improve token counting accuracy using API contextUsagePercentage

Replace client-side token estimation with server-provided contextUsagePercentage
for accurate input token calculation. This eliminates discrepancies between
estimated and actual token counts by using the API's native context window
measurement.

Key changes:
- Add contextUsage event parsing in AWS Event Stream buffer
- Calculate input tokens from contextUsagePercentage in both streaming and
  non-streaming responses
- Deprecate estimateInputTokens() method in favor of API-provided metrics
- Import CLAUDE_DEFAULT_MAX_TOKENS for context window calculations
- Add fallback error handling when contextUsagePercentage is not received
- Fix code formatting and whitespace consistency throughout the file
This commit is contained in:
Zhafron Kautsar 2026-01-07 23:39:07 -05:00
parent ea2ae2169c
commit 89bc0ee6f8

File diff suppressed because it is too large Load diff