Skip to content

feat(usage): add account usage filter and indicators in provider workspace (#1063) - #1083

Closed
agentHits wants to merge 1 commit into
lidge-jun:devfrom
agentHits:feat/separate-account-usage-stats
Closed

feat(usage): add account usage filter and indicators in provider workspace (#1063)#1083
agentHits wants to merge 1 commit into
lidge-jun:devfrom
agentHits:feat/separate-account-usage-stats

Conversation

@agentHits

@agentHits agentHits commented Aug 5, 2026

Copy link
Copy Markdown

Summary

Fixes #1063.

Adds an Account Usage Filter dropdown and indicator badges in the Provider Workspace (Providers -> [Provider] -> Usage) for multi-account providers such as Google Antigravity / Gemini.

UI Screenshots

Usage Account Filter

Key Changes

  1. Provider Usage UI Account Filter (ProviderUsage.tsx & ProviderDetails.tsx):

    • Added an Account Usage Filter selector (All Accounts (Combined) vs individual accounts) on the Usage tab.
    • Display active account badge indicator when a specific account is selected.
    • Plumbed accounts prop from ProviderDetails down into ProviderUsage.
  2. Internationalization (gui/src/i18n/*.ts):

    • Added pws.usageAccountSelector and pws.allAccountsCombined keys across all 6 supported locales (en, ru, zh, de, ja, ko).

Readiness Checklist

  • All CI tests are green on my local testing.
  • I pushed my PR to the latest dev commit.
  • I fixed all correct Codex and CodeRabbit findings.
  • My PR is ready for review.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • All CI tests are green on my local testing.
  • I pushed my PR to the latest dev commit.
  • I fixed all correct Codex and CodeRabbit findings.
  • My PR is ready for review.

Verification

Ran bun run typecheck and bun test tests/provider-workspace-data.test.ts tests/provider-workspace-auth.test.ts:

  • 61 pass, 0 fail
  • tsc --noEmit passed with 0 errors.

Summary by CodeRabbit

  • New Features

    • Added account selection in the provider Usage tab.
    • View usage for an individual account or combined totals across all accounts.
    • The selected account is shown when filtering usage data.
    • Provider credential expiration dates are now displayed.
  • Localization

    • Added translations for account usage filtering, combined totals, JSON import messaging, import results, and expiration dates in English, German, Japanese, Korean, Russian, and Chinese.

@github-actions github-actions Bot added the intake: hygiene-blocked Deterministic PR hygiene checks failed label Aug 5, 2026
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

⚠️ Deterministic hygiene checks failed.

  • missing_regression_test — Behavior changed under src/ or gui/src/ without a test change. Add focused coverage or obtain test-exception-approved.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review readiness checklist

This PR is kept in draft until every requirement below is fulfilled. The tickable checklist has been added to your PR description — tick all four boxes there.

  • ✅ All CI tests are green on my local testing.
  • ✅ I pushed my PR to the latest dev commit.
  • ⬜ I fixed all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

3/4 boxes ticked.

This PR stays in draft until every box above is ticked.

@github-actions github-actions Bot added the enhancement New feature or request label Aug 5, 2026
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The Usage tab now passes OAuth accounts to ProviderUsage. The usage view supports combined-account and per-account selection states, with localized labels added across German, English, Japanese, Korean, Russian, and Chinese catalogs.

Changes

Provider usage account filtering

Layer / File(s) Summary
Usage account selector wiring
gui/src/components/provider-workspace/ProviderUsage.tsx, gui/src/components/provider-workspace/ProviderDetails.tsx
At lines 11-31, ProviderUsage accepts accounts, tracks the selected account ID, and derives the selected account. At lines 55-85, it renders localized account options, account status, and the selected-account badge. ProviderDetails.tsx:272 passes accounts to the component.
Usage localization
gui/src/i18n/en.ts, gui/src/i18n/de.ts, gui/src/i18n/ja.ts, gui/src/i18n/ko.ts, gui/src/i18n/ru.ts, gui/src/i18n/zh.ts
The catalogs add translations for JSON import actions, import results, account usage filtering, combined-account usage, and provider expiration dates.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: lidge-jun, wibias, ingwannu

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes implement combined and per-account usage selection, account indicators, and required data flow for issue #1063.
Out of Scope Changes check ✅ Passed All changes support the account usage feature, including UI data flow and required locale translations.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding account usage filtering and indicators in the provider workspace.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@gui/src/components/provider-workspace/ProviderUsage.tsx`:
- Around line 24-31: Update ProviderUsage so selecting an individual account
does not display provider-wide usage under an account-specific badge: either
wire per-account usage/model data from ProviderDetails and derive the metrics
and sortedModels from the selected account, falling back to usageTotals only for
“all,” or hide those numeric sections and show an explicit
unavailable-per-account message when data is not provided. Ensure the UI clearly
identifies whether statistics represent overall provider usage or the selected
account.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f9a6d906-efdd-46b9-970c-4e339d886891

📥 Commits

Reviewing files that changed from the base of the PR and between 80e4075 and 87428d3.

📒 Files selected for processing (8)
  • gui/src/components/provider-workspace/ProviderDetails.tsx
  • gui/src/components/provider-workspace/ProviderUsage.tsx
  • gui/src/i18n/de.ts
  • gui/src/i18n/en.ts
  • gui/src/i18n/ja.ts
  • gui/src/i18n/ko.ts
  • gui/src/i18n/ru.ts
  • gui/src/i18n/zh.ts

Comment on lines 24 to +31
const quota = accountQuotaFromReport(quotaReport);
const [expandedModel, setExpandedModel] = useState<string | null>(null);
const [selectedAccountId, setSelectedAccountId] = useState<string>("all");

const selectedAccount = useMemo(() => {
if (!accounts?.length || selectedAccountId === "all") return null;
return accounts.find(a => a.id === selectedAccountId) ?? null;
}, [accounts, selectedAccountId]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Account selector changes the badge but not the displayed usage numbers.

selectedAccountId and selectedAccount (lines 26-31) are only read to render the badge (lines 78-85). The cost/requests/tokens metrics (lines 88-101) and the model breakdown table use providerCost and sortedModels, both derived solely from the usageTotals/modelUsage props, which stay fixed at the combined provider totals regardless of selectedAccountId.

Concretely: pick an individual account from the dropdown, and the badge shows that account's email, but "Estimated cost", "requests", "tokens", and the "Model breakdown" table below are unchanged — they still show the provider-wide combined figures. This means the selector currently misleads users into thinking they are looking at per-account numbers.

Issue #1063 (linked in the PR objectives) explicitly requires that selecting an account shows "30-day request count, token usage, and estimated cost" for that account, and that "The interface should clearly indicate whether displayed statistics represent overall provider usage or the selected account's usage." As implemented, the interface never shows account-specific statistics — only account-specific identity.

Since OAuthAccountRow (in types.ts) carries no usage/cost fields, the fix needs either:

  1. A new prop such as accountUsageTotals?: Record<string, ProviderUsageTotals> (or similar) passed down from ProviderDetails, keyed by account id, so the metrics block can pick accountUsageTotals[selectedAccountId] ?? usageTotals and sortedModels can filter/aggregate model usage per account, or
  2. If per-account usage isn't available yet from the management API, disable/hide the numeric metrics when a specific account is selected and show an explicit "not yet available per account" message instead of silently showing combined totals under a misleading badge.
🐛 Minimal fix if per-account data is not yet wired
         {hasUsage ? (
           <>
-            <div className="pws-usage-metrics pws-usage-metrics-3" role="group" aria-label={t("pws.usageLast30d")}>
+            <div className="pws-usage-metrics pws-usage-metrics-3" role="group" aria-label={t("pws.usageLast30d")}>
+              {selectedAccount && (
+                <p className="muted pws-cost-disclaimer">{t("pws.accountUsageUnavailable")}</p>
+              )}
               <div className="pws-usage-metric">

Do you want me to draft the per-account data plumbing through ProviderDetails if the management API already exposes per-account usage?

Also applies to: 55-106

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@gui/src/components/provider-workspace/ProviderUsage.tsx` around lines 24 -
31, Update ProviderUsage so selecting an individual account does not display
provider-wide usage under an account-specific badge: either wire per-account
usage/model data from ProviderDetails and derive the metrics and sortedModels
from the selected account, falling back to usageTotals only for “all,” or hide
those numeric sections and show an explicit unavailable-per-account message when
data is not provided. Ensure the UI clearly identifies whether statistics
represent overall provider usage or the selected account.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 87428d30fd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

id="pws-account-filter"
className="select select-sm"
value={selectedAccountId}
onChange={e => setSelectedAccountId(e.target.value)}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Make the account selector filter the displayed usage

When a multi-account provider user selects an individual account, this handler only changes selectedAccountId, which controls the badge; usageTotals, sortedModels, providerCost, and quota remain derived from the same provider-wide props. Consequently, costs, requests, tokens, model rows, and rate-limit bars stay unchanged and misleadingly appear to belong to the selected account. Pass account-scoped usage and quota data through the management API and derive each display section from the selection, or do not expose individual account options.

AGENTS.md reference: gui/AGENTS.md:L9-L10

Useful? React with 👍 / 👎.

<option value="all">{t("pws.allAccountsCombined")}</option>
{accounts.map(acc => (
<option key={acc.id} value={acc.id}>
{acc.email ?? acc.alias ?? acc.id} {acc.active ? `(${t("prov.accountActive")})` : ""}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep opaque account IDs out of visible labels

When an OAuth account has neither an email nor an alias, this option renders the complete raw acc.id, and the selected-account badge repeats it. The existing dashboard privacy contract uses oauthAccountDisplayLabel or displayAccountId specifically so opaque storage IDs never become user-visible; this regression exposes the identifier in the UI and in screenshots. Build both labels with the existing safe helper instead of falling back to acc.id.

AGENTS.md reference: gui/AGENTS.md:L9-L9

Useful? React with 👍 / 👎.

{accounts && accounts.length > 0 && (
<div style={{ display: "flex", alignItems: "center", gap: 8 }}>
<label htmlFor="pws-account-filter" className="muted faint" style={{ fontSize: 13 }}>
{t("pws.usageAccountSelector")}:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update the dashboard guide for the account filter

This introduces a new user-facing workflow under Providers → Usage, but the commit does not update docs-site/; a repository-wide search shows the existing web-dashboard guide still describes provider account and quota management without the new combined-versus-individual usage selector. Document the selector's behavior and scope in the dashboard guide so the shipped UI and user documentation remain synchronized.

AGENTS.md reference: gui/AGENTS.md:L36-L36

Useful? React with 👍 / 👎.

@github-actions
github-actions Bot marked this pull request as draft August 5, 2026 22:42
@lidge-jun

Copy link
Copy Markdown
Owner

Maintainer triage (code-level, against dev @ 6e1a4e429). Blocking findings:

  1. The filter doesn't filter. selectedAccountId in gui/src/components/provider-workspace/ProviderUsage.tsx only drives the badge; usageTotals, quotaReport, and modelUsage remain the combined provider-level props, so selecting an account changes nothing in the displayed metrics. [Feature Request] Separate Aggregated vs Per-Account Usage Statistics for Multi-Account Providers (Google Antigravity) #1063 asks for per-account usage, which needs a per-account data path on the server side that this diff doesn't add.
  2. Dead i18n keys in all six locales. pws.importJson, pws.importJsonCockpit, pws.importResultSummary, prov.expiresAt are added but referenced by nothing in this diff or on dev — they look like leftovers from the sibling branches (feat(oauth): support importing Google Antigravity accounts from Cockpit Tools JSON (#1076) #1077/feat(providers): display account subscription / plan expiration date in dashboard (#1060) #1081). Please strip them here.
  3. CI hygiene fails with missing_regression_test — a GUI behavior change needs a focused regression test per repo policy.

Minor: prefer the existing pws-* classes over inline style={{...}}. The branch is 17 commits behind dev; please rebase before ticking the readiness boxes.

@lidge-jun

Copy link
Copy Markdown
Owner

Closing this draft — the account filter currently changes the badge only; every metric underneath remains provider-aggregated, so the feature it advertises (#1063, per-account usage) is not delivered by this diff. The missing piece is the data path: per-account usage attribution at write time, then a filtered read. Please reopen once the selector actually filters the aggregation; the UI shell here can come along with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request intake: hygiene-blocked Deterministic PR hygiene checks failed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants