Skip to content

Port upstream 0.66.0: OpenAI daily usage chart UI (stacked on #699) - #701

Draft
Finesssee wants to merge 2 commits into
port/micro-0.66.0-openai-daily-usage-corefrom
port/micro-0.66.0-openai-daily-usage-chart
Draft

Finesssee wants to merge 2 commits into
port/micro-0.66.0-openai-daily-usage-corefrom
port/micro-0.66.0-openai-daily-usage-chart

Conversation

@Finesssee

Copy link
Copy Markdown
Collaborator

Summary

Part (b) of the deferred upstream CodexBar 0.66.0 "OpenAI per-day usage chart": the UI. Part (a) (Rust model, provider fetch, bridge DTO, types/bridge.ts) is #699; this PR is stacked on it and targets port/micro-0.66.0-openai-daily-usage-core.

  • New OpenAIApiUsageChart: Cost | Tokens toggle, one bar per UTC day, a day detail panel (cost, requests, input / cached input / output tokens, line items, models) and a footer with the window label and total.
  • Tray / pop-out MenuCard: collapsed "Daily API usage" section for openaiapi only, hidden on error, in compact overview, and when daily is empty.
  • Settings > Providers: ChartsSection draws the same chart for openaiapi from the new ProviderDetail.openAiApiUsage field.
  • BarChart gains an optional controlled selection prop (listbox/option semantics, roving tabindex, arrow/Home/End keys). Without it, behavior is unchanged.
  • 13 new locale keys (OpenAIChart*) in all 8 locales, LocaleKey, and i18n/keys.ts.

Approved design (summarized)

From design-openai-per-day-chart.md, implemented as written:

  • Reuse the existing dependency-free SVG BarChart; no new charting or other dependency.
  • Cost | Tokens toggle as a tablist with roving tabindex; bars are a roving-tabindex listbox; hover or focus selects a day.
  • Detail panel under the chart is an aria-live=polite region; line items and models are capped at 5 rows plus "+N more".
  • Footer shows the window label ("Today" / "Last N days") and the total for the selected metric.
  • USD only, matching the Admin API; provider id is openaiapi (the id openai aliases Codex).
  • No new Settings tab; openaiapi stays out of PROVIDER_CHART_DATA_IDS (the local-log tabs do not apply).
  • Provider data stays siloed: nothing renders for any other provider even if it carries the same payload.

Upstream reference

Pinned to steipete/CodexBar tag v0.66.0 (read only): openai.js, OpenAIAPIUsageSnapshot.swift, CostHistoryChartMenuView, docs/openai.md.

Deferred / not done

  • CODEXBAR_SEED_USAGE_JSON OpenAI-API seed variant for proof harness runs.
  • Currency conversion (USD only).
  • OPENAI_HISTORY_DAYS setting.
  • Tray chart animations are disabled (animations={false}); Settings honors enableAnimations.

Interpretation notes

  • The shared 280px chart geometry cannot fit 366 bars, so the chart draws the latest 60 days; when trimmed, the footer label uses the drawn day count.
  • A single-day window renders; an empty daily renders nothing in the card/Settings (the standalone component shows DetailChartEmpty).
  • Added open_ai_api_usage to the Tauri ProviderDetail DTO (and TS ProviderDetail) so Settings has a data path; it is only filled when the snapshot has no error.
  • The project id is not shown.
  • Fluent placeholders use the existing { "{}" } convention.
  • Selection is stored by bucket start so it survives a refresh.

Validation

Commands ran through the E-core wrappers with cargo +1.98.0.

Command Result
cargo fmt --all clean
cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings pass
cargo clippy --manifest-path apps/desktop-tauri/src-tauri/Cargo.toml --all-targets -- -D warnings pass
cargo test -p codexbar (includes locale completeness test) 2194 passed, 0 failed, 1 ignored
cargo test -p codexbar-desktop-tauri 466 passed, 1 failed (see below)
pnpm test (vitest, full) 69 files, 429 tests passed
vitest run new/touched: OpenAIApiUsageChart, BarChart, MenuCardOpenAIUsage, ChartsSection 33 passed
pnpm run lint 0 errors; only pre-existing warnings
pnpm run build (check-locale, tsc --noEmit, vite build) pass; 892 locale keys match between Rust and TS

Known failure, not caused by this PR: commands::tests::bootstrap_payload_exposes_every_provider_variant fails (catalog 79 vs 78 active providers). It fails identically on the unmodified base branch (804ff96a), and it reads the machine's real settings via dirs::config_dir(), so it is environment dependent.

New tests: OpenAIApiUsageChart.test.tsx (13), MenuCardOpenAIUsage.test.tsx (6, including provider siloing, error, compact overview, empty window, describeCard presence), BarChart selection mode (5), ChartsSection openaiapi (3), and a Rust test for ProviderDetail.open_ai_api_usage (default None, omitted from JSON, serialized as openAiApiUsage).

Affected areas

Tray/pop-out MenuCard, Settings > Providers detail pane, shared BarChart, locale files (8), Tauri get_provider_detail DTO, styles.css.

UI proof

Pending: coordinator will capture CUA proof on a fresh build. No desktop app was run for this PR.

…tings)

Adds the per-day OpenAI Admin API chart to the tray/pop-out MenuCard and the Settings providers pane, on top of the core model and bridge DTO. Extends BarChart with an optional controlled selection API, adds ProviderDetail.openAiApiUsage, 13 locale keys in 8 locales, and tests.
@coderabbitai

coderabbitai Bot commented Sep 29, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Thermo-nuclear review

Reviewed by Codex gpt-6-luna (xhigh); verified and validated by Claude

The PR was checked for completeness against the approved design note (chart, toggle, day detail, footer, tray/pop-out card, Settings, 13 locale keys in all 8 locales, tests). Nothing was missing. Findings:

  • P1 MenuCard.tsx, IdentitySection.tsx: the OpenAI Admin project id showed in the card plan badge and in Settings identity rows even with "Hide personal info" on. Fix: mask it on both surfaces (lib/openAiApiIdentity.ts), with tests.
  • P2 OpenAIApiUsageChart.tsx: the chart silently dropped history beyond 60 days, so bars and the footer total omitted data. Fix: draw the full window in a horizontally scrollable chart (BarChart scrollable prop, width-aware chartGeometry).
  • P2 useChartAnimation.ts: entrance delay grew with every bar, about 8 s for a 366-day chart. Fix: only the first 30 bars stagger; test added.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Thermo-nuclear fixes landed at 813458d ("Address thermo review").

Fixed: all 3 findings above (project id masking, full-window scrollable chart, capped animation stagger).
Left: none. Note: Codex also reflowed a few unrelated lines in OpenAIApiUsageChart.tsx (formatting only).

Commands run (E-core wrappers, pnpm): vitest run full (72 files, 437 tests passed), pnpm run lint (0 errors, pre-existing warnings only), pnpm run build (pass). No Rust changed, so cargo fmt/clippy/test were not re-run. UI proof (CUA) still pending on a fresh build; the scrollable chart and masked project id are user-visible.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

CUA proof

Build commit: 813458d0f9a99b359051794fd3fbf0ad6eb7275b (PR head) plus throwaway proof-only patches, never committed (reverted with git restore; diff kept outside the repo):

  • Cargo.toml: [patch.crates-io] dirs = <local shim> so all config/data dirs live under an isolated CODEXBAR_PROOF_HOME (no real profile data).
  • rust/src/providers/openaiapi/mod.rs: Endpoints::production() honors CODEXBAR_PROOF_OPENAI_BASE (plain-http localhost mock; no TLS or URL validation weakened) and the keyring target is renamed so the real Credential Manager entry is never read.

Data path: the real Admin fetch path (fetch_admin_usage -> history::daily_usage -> bridge -> React) against a local mock serving synthetic per-day costs and completions buckets for 30 UTC days (3 models, 2 line items, a few idle days). Dummy key only. Only openaiapi enabled, theme auto.

Commands: pnpm --dir apps/desktop-tauri install --frozen-lockfile, pnpm --dir apps/desktop-tauri run tauri:build:debug (CARGO_TARGET_DIR proof-1); launched with CODEXBAR_PROOF_MODE=trayPanel and settings:providers; driven with cua-driver call (background UIA invoke/select/set_value only; window on the second monitor, no foreground input).

# Assertion Result
0 No real email/account from the machine visible PASS
1 Tray: only the OpenAI API card; collapsible "Daily API usage" section present PASS
2 Tray section expands to Cost/Tokens tabs, 30 daily bars (2026-09-01 .. 2026-09-30), latest day selected: cost $2.92, 372 requests, input 558,000 / cached 186,000 / output 93,000 PASS
3 Tokens tab switches the axis and total: 1.6M first day, 24.2M total (matches 24,150,000 tokens on the card); Cost total $108.77 = $92.38 + $16.39 PASS
4 Settings > Providers > OpenAI API: chart section shows the same data plus "Cost by line item" (Text tokens $2.48, Cached input $0.44) and Models (gpt-5.2 420K / 240 requests, gpt-5-mini 147K / 84, o4-mini 84K / 48) PASS
5 Mock log: GET /v1/organization/costs and /v1/organization/usage/completions, both bearer-present, 30-day window PASS
6 Theme auto stays dark in tray and settings PASS
7 Selecting another day by hover/focus NOT EXERCISED (background click does not trigger hover/focus; foreground input is off limits). Covered by the PR's unit tests.

Not verified visually: the tray card's line item / model lists below the fold (background scroll is unavailable on this surface); they are shown in the Settings screenshots.

Screenshots (local, not committed), C:\Users\FSOS\AppData\Local\Win-CodexBar\port-audit\proof\701\shots\:
01-tray.png, 03-tray-daily-usage.png, 04-tray-tokens-tab.png, 09-settings-tall.png, 10-settings-tokens.png.

@Finesssee

Copy link
Copy Markdown
Collaborator Author

Validated 2026-10-02 at 813458d (PR head; base #699 at the new head f328c66 pending merge-in — see stack note):

  • Reviewed against the deferred-feature scope (DONE.md item 2, OpenAI per-day chart; 0.66.0.md row 28a item 5 + the Windows design note in the PR body): the chart UI (OpenAIApiUsageChart, MenuCardOpenAIUsage, ChartsSection/IdentitySection wiring), the Cost/Tokens tabs with per-day bars, the latest-day selection, and locale keys across all 8 .ftl files match the design note; the thermo fixes at this head are included.
  • cargo fmt --all --check — clean.
  • cargo test -p codexbar — 2194 passed / 0 failed / 1 ignored (with the pinned 1.98.0 toolchain).
  • cargo test -p codexbar-desktop-tauri — 466 passed / 1 failed = the documented Isolate bootstrap payload test from real settings #684 bootstrap env baseline (dev machine only; passes on CI hosts).
  • cargo clippy both crates (shared + tauri) --all-targets -- -D warnings — 0 errors at 1.98.0.
  • Frontend: vitest 437/437 pass (incl. the new MenuCardOpenAIUsage, OpenAIApiUsageChart, BarChart, chartGeometry, useChartAnimation, IdentitySection tests); pnpm run check-locale OK — 892 keys; pnpm run lint 0 errors; pnpm run build pass.
  • UI proof: the prior CUA proof at this exact head (813458d) exists — comment issuecomment-5912754275 (tray chart section, Cost/Tokens tabs, 30 daily bars, seeded data, no personal data). Since the head is unchanged, that proof remains at-head; a fresh browser-use pass was additionally run for the OpenAI chart surface during this validation round (see the proof comment below at the same head).
  • No push needed (head 813458d already on origin); no code changes required.

Stack note: this branch still contains the OLD #699 head (5d99354) below its merge base — after #699's f328c66 lands, merge the new base in so the flake fix is behind this head too.

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