Skip to content

feat(overview): add usage breakdown, credit-expiry and credit-history panels - #370

Merged
caigee-cmd merged 2 commits into
caigee-cmd:mainfrom
haocheng23:feat/overview-usage-panels
Oct 23, 2026
Merged

caigee-cmd merged 2 commits into
caigee-cmd:mainfrom
haocheng23:feat/overview-usage-panels

Conversation

@haocheng23

Copy link
Copy Markdown
Contributor

Summary

Adds three read-only insight panels to the Overview page, all driven by the same time window as the traffic chart:

  • Credit-expiry distribution — credits grouped by the calendar day they lapse, one colour per account, plus a soonest-expiry (FEFO) table showing the daily burn rate needed to spend each batch before it expires.
  • Usage breakdown — token split (prompt / completion / total), prefix-cache hit rate, error count and latency; switchable between account / model / realm dimensions and sortable by total tokens, requests, errors or latency.
  • Credit deduction history — sums upstream usage.credit per account and per model, with KPI tiles for credits deducted, matched tokens, average credits per 1M tokens, valid samples and cache-hit rate. Requests without a credit reading are excluded; nothing is back-filled; model rates come from the regional price catalog.

Backend:

  • New GET /api/logs/usage endpoint (internal/console/logs.go).
  • SummarizeRequestUsage aggregation in internal/store/request_logs.go (single grouped query + credit sums), exposed through RequestRecorder.Usage with a 10s TTL cache that mirrors the existing stats cache.
  • New RequestUsage types in internal/accounts/request_logs.go.

Frontend:

  • fetchRequestUsage + RequestUsage types in frontend/src/api/logs.ts.
  • New ExpiryDistribution.tsx and UsagePanels.tsx components; wired into OverviewPage.tsx reusing statsQuery so the panels follow the page time window (including the new Today window).
  • Adds a fixed chart identity palette (--chart-1..8, light/dark) so charts can distinguish 4+ accounts without abusing the semantic status colours (--success / --warning / --danger).

Relationship to #336

This is complementary to #336 (feat(console): add token usage and quota page). #336 adds a standalone usage/quota page; this PR embeds breakdown panels directly in the Overview page and adds the shared /api/logs/usage aggregation. Both touch internal/store/request_logs.go, internal/logs/recorder.go and frontend/src/i18n/messages.ts, so whichever lands second will need a small rebase, but the features are additive and independent.

Test plan

  • go test ./...
  • go vet ./...
  • cd worker && npm test (untouched by this PR)
  • cd frontend && npm run build && npm run lint (build green, lint 0 errors)
  • Added changelog/unreleased/credit-expiry-distribution.md (EN + 中文)
  • No tokens, auth blobs, raw captures, or host details in the diff
  • Manual: open Overview, switch between Today / 1h / 24h / 7d / 30d / custom and confirm all three panels refresh in lockstep with the traffic chart.

haocheng23 and others added 2 commits October 23, 2026 13:06
… panels

- New `/api/logs/usage` endpoint + `SummarizeRequestUsage` store aggregation:
  token split (prompt/completion/total), cache hit/miss, requests, errors,
  latency, and upstream `usage.credit` sums, grouped by account/model/realm.
  10s TTL cache mirrors the existing stats cache.
- Overview: credit-expiry distribution (one colour per account, soonest-expiry
  FEFO table), usage breakdown table (account/model/realm switch, sortable) and
  credit deduction history with KPI tiles. All follow the page time window.
- Add a fixed chart identity palette (--chart-1..8, light/dark) so charts can
  distinguish 4+ accounts without abusing semantic status colours.
- Rebuild embedded console assets (internal/webui/static).
- Overview 30s / visibility refresh also quiet-loads usage panels
- Converge creditExprNullable + creditExprOrZero (keep caigee-cmd#361 semantics)
- Add SummarizeRequestUsage store/API coverage (native/fallback/NULL/realm/1M)
- Drop unused usage.Series scan; mark expired-with-remain packs;口径 footnote
@caigee-cmd
caigee-cmd merged commit 74e83a3 into caigee-cmd:main Oct 23, 2026
6 checks passed
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