Repository navigation
Add OpenAI Tokens/min tray metric - #925
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
…ns-menubar # Conflicts: # apps/desktop-tauri/scripts/proof-scenarios.json
UI proof (hybrid CDP + CUA, build 3971958)Surface: Settings > Providers > OpenAI API (proof mode Setup: fresh debug build of 3971958 (
Screenshots (cua-driver, real pixels): Not covered:
Focus: FAIL. The run started with the foreground on the terminal ( Note: with a pinned seed, the startup refresh is skipped, so the tray tooltip reads only |
Summary
Ports the optional Tokens/min menu bar token from upstream CodexBar v0.75.0 (steipete#4495, commit 5a40ac4). It builds on the existing OpenAI Live Usage data path (#893, #897) and adds no new fetches.
MetricPreference::TokensPerMinute(tokensPerMinuteon the bridge and insettings.json).Provider::reports_tokens_per_minute()trait hook. The typed fact lives once onProviderId::reports_tokens_per_minute()and the trait default delegates to it, so the shell can check the capability from a provider id without instantiating a provider. Onlyopenaiapiqualifies.ProviderDetail.tokensPerMinuteMetricexposes it, so the Settings > Providers > OpenAI API "Menu and floating bar metric" picker offers Tokens/min without provider branching in shared code.OpenAI API 49M/min, using the latest reported minute (throughput.latestTokensPerMinute). Formatting matches upstreamtokenCountString + "/min", so the output looks like950/min,12K/min,1.5M/minor0/min.usage_metric.rsthe meter (and the floating bar) keeps the Automatic lane. The change there is a single match arm.MetricTokensPerMinuteandTrayTokensPerMinuteUnavailableare in all 10.ftlfiles andkeyGroups/shell.ts.openaiapito the proof catalog plus a browser scenario for the picker.The upstream sparkline token (
tokensSparkline) is not ported. A 34-px graph next to the icon has no Windows tray equivalent.Review fixes (second commit)
MetricPreferenceisrename_all = "lowercase", soTokensPerMinutewould have been written astokensperminutewhile the bridge usestokensPerMinute. It now serializes astokensPerMinutewith the lowercase spelling kept as a read alias, same asExtraUsage. The pre-existingMonthlyPlanhad the same mismatch and is fixed the same way (monthlyPlan, aliasmonthlyplan), so files written by either spelling keep loading. Regression tests cover both spellings for both metrics and confirm a settings file with the camelCase value loads without falling back to defaults (rust/src/settings/tests/metric_preference.rs).tokens_per_minute_status(used by both the tray status row and the tooltip) now also requiresProviderId::reports_tokens_per_minute(), so atokensPerMinutevalue saved against a provider that cannot report a rate falls back to the Automatic label instead of leaking the rate onto that provider's row. Covered bytokens_per_minute_metric_on_a_provider_without_a_rate_falls_back.settings-openaiapi-tokens-per-minute-metricnow actually selects Tokens/min in the picker and asserts the persisted value through the mocked bridge (update_settingswithproviderMetrics.openaiapi = "tokensPerMinute"), then checks the select reads the new value back.MetricPreference::display_name()("Tokens/min") has no callers in the app, the shell or the CLI; the picker labels come from the localizedMetricTokensPerMinutekey, so nothing user-facing goes unlocalized.Commands run
cargo fmt --allcargo test --manifest-path rust/Cargo.toml --lib settings::: 208 passed, 0 failed (includes the 3 new metric serde tests)cargo test --manifest-path rust/Cargo.toml --lib openai: 120 passedcargo test --manifest-path apps/desktop-tauri/src-tauri/Cargo.toml tray_presentation: 59 passed (includes the new fallback test);tray_bridge: 13 passed;provider_detail: 9 passedcargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings: cleancargo clippy --manifest-path apps/desktop-tauri/src-tauri/Cargo.toml --all-targets -- -D warnings: cleanpnpm test: 145 files, 1373 tests passed (one transient failure in an unrelated test on the first run; passed on both reruns)pnpm run build: OKpnpm proof:check(Chromium, mocked IPC): 13/13 passedProof
Tray-affecting: desktop CUA proof to follow. Still to prove on a fresh Windows desktop build:
get_settings_snapshotreportsproviderMetrics.openaiapi = "tokensPerMinute"and thatsettings.jsoncontains the camelCase value.OpenAI API: <n>/minand the tray-menu status row readsOpenAI API <n>/min.Reference: upstream steipete/CodexBar steipete#4495 (read-only).