-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Conversation
- Removed flex-wrap from token stats container to keep items on single line - Added flexShrink: 0 to prevent badge and stats from shrinking - Added whiteSpace: nowrap to maintain single-line display - Grouped cost badge and token stats in separate container for better layout control - Added minWidth: 0 to parent container for proper text truncation This fixes the UI overflow issue where the price would break into two lines and overflow the gray box in narrow window widths.
- Wrapped API Request text in a span with class api-request-text - Added responsive CSS to hide text on narrow screens (< 400px) - Added container query support for more precise control - Maintains visibility of cost badge and token statistics - Prevents text truncation issues in narrow windows
- Wrapped cost badge with StandardTooltip component - Token statistics (input/output/cache) now shown in tooltip - Improved UX by reducing visual clutter while keeping info accessible - Added cursor:default to badge when hovering As suggested by @daniel-lxs in PR RooCodeInc#7741
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.
Thank you for your contribution! I've reviewed the changes and the implementation looks good overall. The token statistics tooltip feature addresses the requirements from issue #7740 nicely. I have some suggestions for improvement below.
input: inputDisplay, | ||
output: outputDisplay, | ||
} | ||
} |
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.
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.
</span> | ||
<div style={{ display: "flex", alignItems: "center", gap: "8px", flexShrink: 0 }}> | ||
{hasTokenData ? ( | ||
<StandardTooltip |
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.
Fix i18n violations by adding complete translations for token statistics tooltip. Changes include: - Add tokenStats section with inputLabel, outputLabel, and cacheLabel to all 18 language files - Replace hardcoded strings in ChatRow.tsx with i18n calls - Update formatTokens.ts to accept localized cache label parameter - Translate shareSuccessPublic message to all supported languages - Ensure proper localization for token usage display in API request tooltips This resolves the automated code review rule violation (irule_C0ez7Rji6ANcGkkX) and provides complete localization support for the token statistics feature.
The @returns comment incorrectly described the function as returning a formatted string for display, but it actually returns an object with 'input' and 'output' strings. Corrected for accuracy.
The media query and container queries were incorrectly nested inside the .transition-colors utility class in webview-ui/src/index.css, which would limit their scope unintentionally. Fixed it by moving them to the root level of the CSS file, right after the .transition-colors rule. This should ensure the responsive hiding of the API request text applies globally as intended.
…ding openInCloud strings across all locales
Add missing translation keys for token statistics in Catalan locale Changes: - Add task.tokenStats.inputLabel: "↑ Entrada:" - Add task.tokenStats.outputLabel: "↓ Sortida:" - Add task.tokenStats.cacheLabel: "caché" This fixes the CI check-translations failure for Catalan language.
Refactor tooltip behavior in ChatRow component to show token stats on hover over api-request-text span when the cost badge is not displayed. Changes include: - Add conditional tooltip rendering on span when cost <= 0 - Extract shared constants to eliminate code duplication - Keep tooltip on badge when cost > 0 - Maintain original cursor behavior
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.
Thank you for your contribution! The token statistics tooltip feature addresses the requirements from issue #7740 nicely. I have a couple of important suggestions below regarding code reuse and test coverage.
Replace custom token formatting logic with existing formatLargeNumber function. Changes: - Use formatLargeNumber from utils/format.ts instead of custom implementation - Maintain same interface and undefined handling - Reduce code duplication across the project - Add import for formatLargeNumber utility
Created formatTokens.spec.ts with 21 tests covering: - formatTokenCount function with all edge cases - formatTokenStats function with cache and parameter combinations - 100% code coverage (statements, branches, functions, lines) Tests verify proper token formatting, cache handling, and error cases.
fd3e38f
to
d6ce827
Compare
@daniel-lxs I made corrections based on your feedback. We are now reusing code, and there is a unit test for the new code. |
This PR replaces the previous attempt, which had to be abandoned due to an AI error (context loss). See the prior PR: #7741
What’s included (difference vs main, in brief):
Rationale:
Fixes #7740
Important
Adds a tooltip for token statistics in API requests, updates localization, and introduces token formatting utilities.
ChatRow.tsx
for API requests, displaying input, output, and cache reads.formatTokenCount()
andformatTokenStats()
informatTokens.ts
for formatting token data.chat.json
) for multiple languages to include token statistics labels.index.css
to hide API request text on narrow screens.This description was created by
for b9b8dd5. You can customize this summary. It will automatically update as commits are pushed.