Skip to content

Conversation

mikhailsal
Copy link

@mikhailsal mikhailsal commented Sep 12, 2025

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):

  • Token usage statistics per API request shown in a tooltip (input, output, cache reads).
  • Counts are formatted (e.g. "1.2k") and localized labels are used.
  • Tooltip is shown even when there is no price, so token info remains accessible.

Rationale:

  • Makes token usage visible for every request without cluttering the UI.
  • Keeps details available on hover while preserving compactness.

Fixes #7740


Important

Adds a tooltip for token statistics in API requests, updates localization, and introduces token formatting utilities.

  • Behavior:
    • Adds token usage statistics tooltip in ChatRow.tsx for API requests, displaying input, output, and cache reads.
    • Tooltip is visible even without price information.
  • Utilities:
    • Introduces formatTokenCount() and formatTokenStats() in formatTokens.ts for formatting token data.
  • Localization:
    • Updates localization files (chat.json) for multiple languages to include token statistics labels.
  • Styles:
    • Adds CSS rules in index.css to hide API request text on narrow screens.

This description was created by Ellipsis for b9b8dd5. You can customize this summary. It will automatically update as commits are pushed.

- 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
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. UI/UX UI/UX related or focused labels Sep 12, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 12, 2025
Copy link

@roomote roomote bot left a 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,
}
}
Copy link

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
Copy link

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.

@mikhailsal mikhailsal marked this pull request as draft September 12, 2025 06:50
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.
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
@mikhailsal mikhailsal marked this pull request as ready for review September 12, 2025 09:06
@dosubot dosubot bot added the enhancement New feature or request label Sep 12, 2025
@mikhailsal
Copy link
Author

I've done. Latest screenshots:
Screenshot from 2025-09-12 12-01-23
Screenshot from 2025-09-12 12-01-02

@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Sep 12, 2025
@hannesrudolph hannesrudolph removed the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 12, 2025
Copy link
Collaborator

@daniel-lxs daniel-lxs left a 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.

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Sep 15, 2025
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.
@mikhailsal mikhailsal force-pushed the feat/token-stats-tooltip branch from fd3e38f to d6ce827 Compare September 16, 2025 07:12
@mikhailsal
Copy link
Author

@daniel-lxs I made corrections based on your feedback. We are now reusing code, and there is a unit test for the new code.

@github-project-automation github-project-automation bot moved this from PR [Changes Requested] to Done in Roo Code Roadmap Sep 23, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request PR - Changes Requested size:L This PR changes 100-499 lines, ignoring generated files. UI/UX UI/UX related or focused

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Add detailed token stats for every API call

5 participants