feat(tui): display input/cache tokens with cache percentage in context panel#33933
Open
walker83 wants to merge 2 commits into
Open
feat(tui): display input/cache tokens with cache percentage in context panel#33933walker83 wants to merge 2 commits into
walker83 wants to merge 2 commits into
Conversation
…t panel Show breakdown of non-cached input tokens vs cached tokens in the right-side Context panel. The cache percentage (cache / total input) helps users instantly gauge how much their API calls benefit from cache pricing.
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
- Extract computeContextState function for testability - Cache hit percentage now correctly uses only cache.read tokens - cache.write (cache misses) excluded from hit ratio calculation - Add comprehensive unit tests for cache computation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #
Type of change
What does this PR do?
Enhance the right-side Context panel to display a breakdown of non-cached input tokens vs cached tokens, along with the cache hit percentage. Cache read pricing is 1/5 to 1/10 of regular input pricing (e.g. Anthropic: $0.30/M vs $3.00/M tokens). Users need immediate visibility into their cache hit ratio to optimize costs.
Changes in
packages/tui/src/feature-plugins/sidebar/context.tsx:input(non-cached input tokens) andcache(cache read tokens) from the last assistant message tokenscachePercentascache.read / (input + cache.read) * 100- the true cache hit ratioLocale.number()compact formatNote:
cache.writetokens represent cache misses that write to cache for future use, and are excluded from the cache hit percentage calculation since they are not input tokens served from cache.How did you verify your code works?
Reviewed manually. The change is isolated to a single sidebar plugin file and uses existing
AssistantMessage.tokensdata. Follows patterns used by 15+ other files in the codebase.Screenshots / recordings
Before:
After:
Checklist