Skip to content

feat(usage): add historical model call statistics page - #2330

Merged
wsp1911 merged 7 commits into
GCWing:usage-statistics-pagefrom
chaos-cl:feat/usage-statistics
Aug 17, 2026
Merged

wsp1911 merged 7 commits into
GCWing:usage-statistics-pagefrom
chaos-cl:feat/usage-statistics

Conversation

@chaos-cl

@chaos-cl chaos-cl commented Aug 16, 2026 •

Copy link
Copy Markdown

Summary

Adds a Usage Statistics page to Settings (设置 → 通用 → 调用统计) that shows historical model call statistics in a dashboard layout: time-range / granularity filters, summary cards, model / provider-group / endpoint distribution donut charts with per-entry tables, a dedicated per-model cache hit rate card, and a token usage trend chart (Input / Output / Cache Creation / Cache Read / Cache Hit Rate).

What changed

Backend

  • bitfun-services-core: pure aggregation module token_usage::statistics (totals, distribution breakdowns with per-entry cache hit rates, hourly/daily trend bucketing) with unit tests.
  • bitfun-core (assembly): UsageAttributionResolver maps each record to a provider group and endpoint label, preferring the model configuration that served the request (model_config_id → provider / base URL / request URL) and falling back to the bundled models.dev catalog inferred from the effective model name, so records survive config deletion. TokenUsageService::get_statistics wires records + resolver together.
  • bitfun-ai-adapters: exposes ModelsDevCatalog::provider_ids() / all_models() for catalog-wide provider inference.
  • bitfun-desktop: new Tauri command get_token_usage_statistics (time range: last 24h / today / this week / this month / all / custom; granularity: hour / day), registered with a RemoteRouted remote-workspace policy.
  • analyze_image tool now persists the vision model call's token usage through a global TokenUsageService reference installed by the desktop runtime — these calls bypass the round executor, so without this they never reached the usage store and multimodal models were missing from the statistics.

Frontend (web-ui)

  • New settings tab usage-statistics wired through settingsConfig / settingsContentRegistry / SettingsScene / tab i18n preload / nav search index.
  • UsageStatisticsConfig page with hand-rolled SVG donut and line charts (no new chart dependency), using appearance tokens only.
  • Distribution tables show name / requests / tokens; a dedicated card lists each model's average cache hit rate with a ratio bar.
  • Cache hit rates are displayed truncated to two decimals (never rounded up); only a true 100% hit (cached == reported input, exact in the backend) shows as 100%.
  • tokenUsageStatisticsApi client registered on bitfunAPI.
  • i18n for en-US / zh-CN / zh-TW (new settings/usage-statistics namespace + settings shell entries).

Notes

  • "分组" maps to the provider (e.g. OpenAI / Anthropic / DeepSeek); "端点" maps to the endpoint host + request path (e.g. api.openbitfun.com/v1/chat/completions).
  • Only calls that are actually persisted (round-executor turns and analyze_image vision calls) appear; other direct AIClient consumers (insights, memory extraction, session titles) are intentionally out of scope for this PR.

Verification

  • cargo test --locked -p bitfun-core -p bitfun-desktop --lib (CI-equivalent): bitfun-core 2010 passed, desktop 312 passed, 0 failures.
  • cargo check --locked --workspace passes.
  • services-core token usage tests (incl. aggregation, exact-100% hit, cache-telemetry cases) and core resolver tests pass.
  • web-ui: UsageStatisticsConfig.test.tsx + settings scene tests pass; type-check, eslint, i18n:audit, i18n:contract:test all pass.
  • Manually verified end-to-end: a real image-analysis call now produces a MiniMax-M3 record in the usage store and shows up on the statistics page.

chaos added 3 commits August 16, 2026 21:18
Add a settings page showing historical model call statistics (requests,
tokens, estimated cost) broken down by model, provider group, and
endpoint, with a token usage trend chart.

- services-core: pure aggregation module with unit tests
- core: attribution resolver (config + models.dev catalog) and
  get_statistics on the token usage service
- desktop: get_token_usage_statistics Tauri command
- web-ui: UsageStatisticsConfig settings tab + i18n (en/zh-CN/zh-TW)
- services-core: remove price estimation; UsageStatisticsEntry now carries
  cacheHitRate (cached / reported input); UsageStatistics gains
  totalCacheReportedInputTokens for the overall hit rate
- core: resolver no longer resolves prices
- web-ui: summary cards show requests/tokens/cached tokens/hit rate; tables
  show model/group/endpoint, requests, tokens, cache hit rate; fix table
  header layout (min column widths + no-wrap) that squeezed Chinese labels;
  drop cost columns and footnote
- i18n: update en/zh-CN/zh-TW copy
@GCWing
GCWing requested a review from wsp1911 August 16, 2026 15:22
chaos added 4 commits August 17, 2026 09:40
…splay

- move cache hit rate out of the distribution tables into a dedicated
  per-model card with a ratio bar
- display hit rates truncated to two decimals (never rounded up); only a
  true 100% hit (cached == reported input, exact in the backend) shows as
  100%
- trend chart now spans the full row; distribution tables revert to
  name / requests / tokens
The image understanding tool calls AIClient directly, bypassing the round
executor, so its consumption never reached the token usage store and
multimodal models were missing from the usage statistics page. Persist the
response usage through a global TokenUsageService reference installed by
the desktop runtime.
Dynamic var() string building (--bf-appearance-token-${name}) is invisible to
the theme color audit, which flagged an unresolved required CSS var and broke
the CI Frontend Build job. Replace every token reference with a literal var()
so the audit resolves them statically.
The appearance contract audit (part of build:web) requires every
data-bf-component to match a registered descriptor id and every data-bf-part
to be a string literal declared on the same node as its component. Align the
usage statistics page: component id 'usage-statistics-config', literal parts
on root/filters/summary/distributions/modelHitRate/trendPanel/empty, and drop
appearance attributes from internal chart components.
@wsp1911

wsp1911 commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

往usage-statistics-page这个分支上提吧

@wsp1911
wsp1911 changed the base branch from main to usage-statistics-page August 17, 2026 04:32
@wsp1911
wsp1911 merged commit 3af8c5d into GCWing:usage-statistics-page Aug 17, 2026
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