Skip to content

feat: usage page, traffic chart metric switch, stats dim/limit, provider log filter - #361

Merged
caigee-cmd merged 1 commit into
mainfrom
feat/usage-metrics
Oct 22, 2026
Merged

caigee-cmd merged 1 commit into
mainfrom
feat/usage-metrics

Conversation

@caigee-cmd

Copy link
Copy Markdown
Owner

Backend

  • DB engine is SQLite (modernc). SQLite has no percentile aggregate, so p50/p95 use the existing approach: read latencies sorted by key, then pick the nearest-rank value in Go.
  • requestSeries: each bucket adds prompt_tokens, completion_tokens, cache_read_tokens, latency_p50_ms and latency_p95_ms.
  • Grouped stats (models / accounts / providers): each row adds latency_p95_ms, prompt_tokens, completion_tokens, cache_read_tokens, cache_write_tokens and credits.
  • Totals: credits is added to totals, and cache_write to tokens.
  • Credits come from credits, falling back to request_usage_details.credit, the same source the request list uses.
  • /api/logs/stats?dim=model,account,provider&limit=N:
    • dim limits which grouped lists are computed. Unknown names are ignored, and an empty dim means all three.
    • limit defaults to 6 and is capped at 500.
    • The recorder's stats cache key now includes dim and limit.
    • Calls without these parameters work exactly as before. SummarizeRequestLogs is kept as a wrapper around the new SummarizeRequestLogsWith.
  • /api/logs/requests?provider=: matches the same effective provider the ranking groups by (the logged provider, else the account's provider).
  • SPA fallback: /usage is added to the route list in internal/server/router.go.

Frontend

  • TrafficChart has a HeroUI segmented switch (the existing FilterToggle) for:
    • requests: ok / failed
    • tokens: input / output / cache read
    • latency: p95 / p50
  • The tooltip, axis formatting and legend follow the selected metric. Drag-to-logs still works.
  • Usage page (/usage, sidebar → Workspace → Usage, Phosphor ChartBar icon). It is a separate page rather than an Overview tab because:
    • the sidebar already has one page per task (Overview, Accounts, Logs…);
    • the tables are full-width and need their own sort state, row-count and dimension tabs;
    • the Overview is already dense.
  • On the Usage page:
    • Tabs switch between Models, Accounts and Providers. The tables use HeroUI Table with allowsSorting and SortableColumnHeader.
    • Columns: requests, success rate, p95, tokens (input/output), cache write, credits.
    • Each tab fetches dim=<tab>&limit=500, so the hard-coded limit of 6 no longer applies there.
    • Rows link to filtered logs.
  • The window controls are pulled into StatsWindowControls and lib/statsWindow.ts and shared with the Overview (1h / 24h / 7d / 30d / custom from-to).
  • Provider ranking rows on the Overview now drill down to /logs?provider=. LogsPage has a provider select and syncs provider with the URL.
  • logsHref moved to lib/logsLink.ts.

Tests

  • store:
    • per-bucket tokens and p50/p95
    • grouped p95, tokens, cache_write and credits (including the usage-detail fallback)
    • dim + limit
    • default limit of 6
    • provider filter
  • api: dim/limit over HTTP, the default contract, provider on requests, and the /usage SPA fallback.
  • console: ParseStatsDims.
  • The frontend has no test runner (no vitest/jest; CI's npm test is for the worker), so there are no frontend unit tests. I didn't add a test framework.

…filter

- store: series buckets carry prompt/completion/cache_read tokens and p50/p95
  latency; grouped stats add p95, tokens, cache_write, credits; dim + limit
  options (SummarizeRequestLogs keeps the 6-row, all-dims contract)
- logs API: ?provider= filter (logged provider, else account provider)
- stats API: ?dim=model,account,provider&limit=N (max 500)
- console: TrafficChart requests/tokens/latency switch; /usage page with
  sortable tables and shared window controls; provider drill-down; LogsPage
  provider filter synced with the URL
- tests: store usage/series/dim/limit/provider filter, API dim/limit/provider,
  ParseStatsDims, SPA /usage fallback
@caigee-cmd
caigee-cmd merged commit e29f060 into main Oct 22, 2026
6 checks passed
caigee-cmd added a commit to haocheng23/cli2api that referenced this pull request Oct 23, 2026
- 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
fengye102 pushed a commit to fengye102/cli2api that referenced this pull request Oct 24, 2026
Extract the token/quota cost UI from caigee-cmd#336 as a Cost tab on the existing
Usage page (caigee-cmd#361 Stats kept). Adds pricing catalog (incl. deepseek-flash),
/api/usage/{pricing,cost}, SummarizeModelCosts with creditExpr fallback,
and CostChart. Does not change log retention or WorkBuddy TTFB.
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