Repository navigation
feat(usage): add historical model call statistics page - #2330
Merged
wsp1911 merged 7 commits intoAug 17, 2026
Merged
Conversation
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
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.
Collaborator
|
往usage-statistics-page这个分支上提吧 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 moduletoken_usage::statistics(totals, distribution breakdowns with per-entry cache hit rates, hourly/daily trend bucketing) with unit tests.bitfun-core(assembly):UsageAttributionResolvermaps 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_statisticswires records + resolver together.bitfun-ai-adapters: exposesModelsDevCatalog::provider_ids()/all_models()for catalog-wide provider inference.bitfun-desktop: new Tauri commandget_token_usage_statistics(time range: last 24h / today / this week / this month / all / custom; granularity: hour / day), registered with aRemoteRoutedremote-workspace policy.analyze_imagetool now persists the vision model call's token usage through a globalTokenUsageServicereference 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)
usage-statisticswired throughsettingsConfig/settingsContentRegistry/SettingsScene/ tab i18n preload / nav search index.UsageStatisticsConfigpage with hand-rolled SVG donut and line charts (no new chart dependency), using appearance tokens only.tokenUsageStatisticsApiclient registered onbitfunAPI.settings/usage-statisticsnamespace + settings shell entries).Notes
api.openbitfun.com/v1/chat/completions).analyze_imagevision calls) appear; other directAIClientconsumers (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 --workspacepasses.UsageStatisticsConfig.test.tsx+ settings scene tests pass;type-check,eslint,i18n:audit,i18n:contract:testall pass.MiniMax-M3record in the usage store and shows up on the statistics page.