-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: Token statistics tooltip for each API request #7928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
643da52
feat: Add token statistics display to API requests (fixes #7740)
roomote 333e1e4
fix: prevent token stats overflow in narrow windows
roomote e89cd7b
fix: Hide "API Request" text when container width is limited
roomote 7a3faff
Merge remote changes and add API Request text hiding feature
roomote 1666dd5
feat: Move token statistics to tooltip on price hover
roomote 4a48388
feat: Complete i18n localization for token statistics
mikhail-salnikov a2abad1
Fix JSDoc return type for formatTokenStats function
mikhail-salnikov da544a0
Fix rules incorrectly nested in the media container
mikhail-salnikov f5b968c
i18n: resolve locale chat.json conflicts by keeping tokenStats and ad…
mikhail-salnikov 8fa4389
Fix: Add missing Catalan translations for token stats
mikhail-salnikov b9b8dd5
feat: Add tooltip to API request text when cost is hidden
mikhail-salnikov c6fd34e
Refactor: Eliminate duplicate token formatting code
mikhailsal d6ce827
Add comprehensive unit tests for formatTokens.ts
mikhailsal 3fee61f
Merge remote-tracking branch 'upstream/main' into feat/token-stats-to…
mikhailsal aa815f0
Merge remote-tracking branch 'upstream/main' into feat/token-stats-to…
mikhailsal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /** | ||
| * Format token count for display | ||
| * @param count - The token count to format | ||
| * @returns Formatted string (e.g., "1.2k" for 1200) | ||
| */ | ||
| export function formatTokenCount(count: number | undefined): string { | ||
mikhailsal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (count === undefined || count === 0) { | ||
| return "0" | ||
| } | ||
|
|
||
| if (count < 1000) { | ||
| return count.toString() | ||
| } | ||
|
|
||
| // Format as k (thousands) with one decimal place | ||
| const thousands = count / 1000 | ||
| if (thousands < 10) { | ||
| // For values less than 10k, show one decimal place | ||
| return `${thousands.toFixed(1)}k` | ||
| } else { | ||
| // For values 10k and above, show no decimal places | ||
| return `${Math.round(thousands)}k` | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Format token statistics for display | ||
| * @param tokensIn - Input tokens | ||
| * @param tokensOut - Output tokens | ||
| * @param cacheReads - Cache read tokens (optional) | ||
| * @returns Formatted string for display | ||
mikhailsal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| export function formatTokenStats( | ||
| tokensIn?: number, | ||
| tokensOut?: number, | ||
| cacheReads?: number, | ||
| ): { input: string; output: string } { | ||
| let inputDisplay = formatTokenCount(tokensIn) | ||
|
|
||
| // Add cache reads in parentheses if they exist | ||
| if (cacheReads && cacheReads > 0) { | ||
| const cacheDisplay = formatTokenCount(cacheReads) | ||
| inputDisplay = `${inputDisplay} (${cacheDisplay} cache)` | ||
mikhailsal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| const outputDisplay = formatTokenCount(tokensOut) | ||
|
|
||
| return { | ||
| input: inputDisplay, | ||
| output: outputDisplay, | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding unit tests for these formatting functions. They handle several edge cases (undefined, 0, < 1000, < 10k, >= 10k) that would benefit from test coverage to ensure the formatting logic works correctly. You could create a test file at with tests for both functions.
mikhailsal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered the accessibility of this tooltip for keyboard users? The StandardTooltip component might already handle keyboard accessibility, but it's worth verifying that users can access token statistics without a mouse.