Skip to content

Enhance OpenRouter usage details rendering and percent calculation - #20

Open
toniher wants to merge 3 commits into
InledGroup:mainfrom
toniher:fix/openrouter
Open

Enhance OpenRouter usage details rendering and percent calculation#20
toniher wants to merge 3 commits into
InledGroup:mainfrom
toniher:fix/openrouter

Conversation

@toniher

@toniher toniher commented Aug 24, 2026

Copy link
Copy Markdown

This pull request adds support for displaying provider-supplied detail sections (such as credits, spend history, and rate limits) in the CodexBar GNOME Shell extension. It introduces a new setting to control the visibility of these sections, improves the handling of balance-based providers like OpenRouter, and includes robust normalization and rendering logic for these details. Additionally, the documentation is updated to clarify API key setup for OpenRouter, and comprehensive tests are added for the new features.

imatge

Provider-supplied details display and normalization:

  • Added a new function normalizeDetailSections in usageApi.js to sanitize and flatten provider-supplied usage.details arrays for safe rendering, dropping charts and handling edge cases. (Fcd7b7e9L30R30)
  • Implemented deriveCreditsPercent in usageApi.js to compute a meaningful usage percentage from "Credits" sections for providers that only report a balance (e.g., OpenRouter), improving the accuracy of the usage bar display. (Fcd7b7e9L30R30)
  • Updated extension.js to render these normalized detail sections in the UI, with new styling in stylesheet.css, and to use derived credits percent for degenerate tiers. [1] [2] [3] [4]

Settings and preferences:

  • Introduced a new boolean GSettings key show-provider-details, defaulting to true, and exposed it in the preferences UI to allow users to toggle provider detail sections. [1] [2]
  • Wired up the new setting in the extension, so changes take effect immediately in the UI.

Documentation:

  • Expanded the README with clear instructions for setting up API keys via systemd user environment for providers like OpenRouter, addressing common pitfalls with environment variables in GNOME Shell.

Testing:

  • Added extensive tests in test_all_providers.js to verify normalization, rendering, edge cases, and percent derivation for provider details, especially for OpenRouter's API output. [1] [2] [3]

LLM Usage: Claude Code Opus 5, Sonnet 5

toniher and others added 3 commits August 24, 2026 18:43
Adds a generic renderer for the codexbar CLI's usage.details array so
OpenRouter's Credits/API key/Spend history breakdown shows up in the
popup, gated behind a new show-provider-details setting. Any other
provider that starts emitting details gets it for free; providers
without it (Claude, Codex) are unaffected.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
When a provider reports a placeholder tier with usedPercent:0 and no
windowSeconds (e.g. OpenRouter's balance tier), derive a meaningful usage
percent from the Credits detail section instead. Add deriveCreditsPercent
function to parse Used/Total or Remaining/Total from Credits rows, skip
the tier entirely if no Credits section is available, and update the UI
logic to use the derived percent or fall back to normalized usedPercent.
Add documentation explaining how to configure API keys (e.g. OPENROUTER_API_KEY) for the CodexBar CLI extension. Unlike shell dotfiles, environment variables must be set in systemd's user environment since GNOME Shell is started by the display manager rather than an interactive shell. Includes instructions for creating the environment.d configuration file, applying changes without full logout, and verifying the variable is accessible to GNOME Shell.
@jaimegh-es

Copy link
Copy Markdown
Member

Hello!
Thanks for your contribution!
Rn im have a lot of work, but i will review it.
Thanks for your time!

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.

2 participants