Skip to content

Conversation

@ejc3
Copy link

@ejc3 ejc3 commented Nov 28, 2025

Shows input/output tokens separately and includes cached tokens in the total.

Changes

  • Display format changed from "X tokens" to "X in Y out"
  • Input tokens now include cached tokens (was showing just non-cached portion)
  • Cache percentage shown when there's cache usage (e.g., "100% cached")

Screenshot

Token display

Shows "135,739 in 63 out 100% cached" format.

@seifghazi seifghazi requested a review from Copilot December 16, 2025 16:42
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the token usage display in the request list by showing input/output tokens separately and calculating cache percentage. The changes make token usage information more informative by distinguishing between input and output tokens and showing the proportion of cached tokens as a percentage.

Key Changes:

  • Token display format changed from showing total tokens to showing input and output separately ("X in Y out")
  • Input token calculation now includes cached tokens in addition to regular input tokens
  • Cache display changed from showing raw cached token count to showing cache percentage

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

<span className="font-mono text-gray-600">
<span className="font-medium text-gray-900">{(request.response.body.usage.output_tokens || 0).toLocaleString()}</span> out
</span>
{request.response.body.usage.cache_read_input_tokens && (
Copy link

Copilot AI Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Division by zero potential when both input_tokens and cache_read_input_tokens are 0 or undefined. While the condition on line 714 checks that cache_read_input_tokens exists, it could still be 0, and input_tokens could also be 0, resulting in NaN. Consider adding a guard to ensure the denominator is not zero before performing the calculation.

Suggested change
{request.response.body.usage.cache_read_input_tokens && (
{(request.response.body.usage.cache_read_input_tokens &&
((request.response.body.usage.input_tokens || 0) + (request.response.body.usage.cache_read_input_tokens || 0)) > 0) && (

Copilot uses AI. Check for mistakes.
ejc3 added 5 commits December 20, 2025 11:45
- Replace sequential regex replacements with single-pass tokenizer in
  CodeViewer.tsx highlightCode() function
- The old approach applied patterns sequentially, causing later patterns
  to match numbers inside class attributes (e.g., "400" in "text-purple-400")
- New approach: build combined regex, iterate matches once, escape HTML
  on matched tokens only
- Also fix escapeHtml in formatters.ts to not use document.createElement
  (fails during SSR) and simplify formatLargeText to avoid over-formatting
- Add quote escaping to escapeHtml in CodeViewer.tsx for XSS protection
- Fix string regex patterns to properly handle escaped quotes
- Use template literal for paragraph wrapping in formatLargeText
- Add vitest and tests for escapeHtml, formatLargeText, and string patterns
- Change combined "X tokens" to separate "X in" / "Y out" display
- Makes it clearer how many tokens are uploaded vs generated
- Helps users understand conversation growth per turn
- Show total input tokens (cached + non-cached) instead of just non-cached
- Change cache display from absolute number to percentage
- "68,446 in 100% cached" instead of "1 in 153,525 cached"
Add guard to ensure denominator is non-zero before calculating the
cache percentage. This prevents NaN when both input_tokens and
cache_read_input_tokens are 0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant