Roo-Code/src/api
Hannes Rudolph 6569710752 fix: add cache reporting support for OpenAI-Native provider (#7602)
* fix: add cache reporting support for OpenAI-Native provider

- Add normalizeUsage method to properly extract cache tokens from Responses API
- Support both detailed token shapes (input_tokens_details) and legacy fields
- Calculate cache read/write tokens with proper fallbacks
- Include reasoning tokens when available in output_tokens_details
- Ensure accurate cost calculation using uncached input tokens

This fixes the issue where caching information was not being reported
when using the OpenAI-Native provider with the Responses API.

* fix: improve cache token normalization and add comprehensive tests

- Add fallback to derive total input tokens from details when totals are missing
- Remove unused convertToOpenAiMessages import
- Add comment explaining cost calculation alignment with Gemini provider
- Add comprehensive test coverage for normalizeUsage method covering:
  - Detailed token shapes with cached/miss tokens
  - Legacy field names and SSE-only events
  - Edge cases including missing totals with details-only
  - Cost calculation with uncached input tokens

* fix: address PR review comments

- Remove incorrect fallback to missFromDetails for cache write tokens
- Fix cost calculation to pass total input tokens (calculateApiCostOpenAI handles subtraction)
- Improve readability by extracting cache detail checks to intermediate variables
- Remove redundant ?? undefined
- Update tests to reflect correct behavior (miss tokens are not cache writes)
- Add clarifying comments about cache miss vs cache write tokens
2025-09-08 17:32:44 -06:00
..
providers fix: add cache reporting support for OpenAI-Native provider (#7602) 2025-09-08 17:32:44 -06:00
transform fix: Tackling Race/State condition issue by Changing the Code Design for Gemini Grounding Sources (#7434) 2025-09-05 15:03:09 -04:00
index.ts feat: Add DeepInfra as a model provider in Roo Code (#7677) 2025-09-04 17:28:45 -04:00