Skip to content

Total API-value donut card (SOU-265 pass 3b) - #58

Merged
tsouth89 merged 2 commits into
mainfrom
feat/sou-265-api-value-card
Jul 18, 2026
Merged

Total API-value donut card (SOU-265 pass 3b)#58
tsouth89 merged 2 commits into
mainfrom
feat/sou-265-api-value-card

Conversation

@tsouth89

@tsouth89 tsouth89 commented Jul 18, 2026

Copy link
Copy Markdown
Owner

What

The aggregate "estimated API value" card from SOU-265, consuming the pass-3a backend (#57). Completes the SOU-262 dollar-analytics epic's UI.

Changes

  • lib/apiValueCard.ts - pure, unit-tested model + ring geometry. buildApiValueCard omits providers with no data (never counts zero), computes per-provider shares and pricing coverage; ringSegments turns shares into stroke-dasharray donut segments.
  • components/TotalApiValueCard.tsx - period switcher (Today / Yesterday / 30 days) + metric switcher (API value / Tokens), an SVG donut coloured by provider brand colors, a ranked legend (share + value), and transparency copy: an estimate marker plus "N% of tokens priced (unpriced models in ...)" whenever coverage is below 100%. Empty periods show No data; a failed command shows an unavailable state. role="img" on the ring carries an a11y summary of metric, period, total, and providers.
  • Mounted at the top of ChartsPanel; styling is responsive and theme-aware, reusing existing design tokens.

Terminology (per SOU-265)

Dollars are labelled Estimated API value, never a bill or subscription spend. Providers with no source data are omitted; coverage is surfaced whenever any tokens are unpriced.

Tests

  • 8 pure-logic cases: single / multiple / tiny-share / missing-data / partial-pricing / all-unpriced, plus ring geometry.
  • 3 render cases: aggregate total + ranked legend + coverage note, "No data" on switching to an empty period, unavailable state on command failure.

Frontend 258 / tsc clean.

Note: the donut was verified via the geometry unit tests and the standard stroke-dasharray technique - the in-app browser preview was unavailable for a live screenshot this session, so a visual pass on the rendered ring is worth a glance before release.

Summary by CodeRabbit

  • New Features
    • Added an API value card to the charts panel, always shown at the top.
    • Lets you switch between periods (today, yesterday, past 30 days) and metrics (API value vs tokens).
    • Visualizes provider contributions with a ring breakdown and legend, including token-pricing coverage where available.
    • Shows clear “no data” and “unavailable right now” states.
  • Tests
    • Added UI and calculation test coverage, including pricing coverage, empty-period behavior, and error handling.
  • Style
    • Added responsive styling for the API value card (including small-screen layout).

The aggregate card from SOU-265, consuming the pass-3a backend. Shows
estimated API value across providers with a donut ring + ranked legend.

- lib/apiValueCard.ts: pure, unit-tested model + ring geometry.
  buildApiValueCard omits providers with no data (never zero), computes
  per-provider shares and pricing coverage; ringSegments turns shares into
  stroke-dasharray donut segments.
- components/TotalApiValueCard.tsx: period switcher (Today / Yesterday /
  30 days) + metric switcher (API value / Tokens), an SVG donut coloured by
  provider brand colors, a ranked legend (share + value), and transparency
  copy - an estimate marker plus "N% of tokens priced (unpriced models in
  ...)" whenever coverage is below 100%. Empty periods show "No data"; a
  failed command shows an unavailable state. role=img on the ring carries an
  a11y summary of metric, period, total, and providers.
- Mounted at the top of ChartsPanel; card styling is responsive and
  theme-aware, reusing existing design tokens.

Tests: 8 pure-logic cases (single/multiple/tiny-share/missing-data/partial-
pricing/all-unpriced + ring geometry) and 3 render cases (aggregate + legend
+ coverage, "No data" on period switch, unavailable on failure). Frontend
258 / tsc clean.

Note: the donut was verified via the geometry unit tests and the standard
stroke-dasharray technique; the in-app browser preview was unavailable for a
live screenshot this session.
@cloudflare-workers-and-pages

Copy link
Copy Markdown
Contributor

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ceiling 53359a6 Commit Preview URL

Branch Preview URL
Jul 18 2026, 09:59 PM

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d5e1513d-5cf2-438f-b36c-1585089b7f61

📥 Commits

Reviewing files that changed from the base of the PR and between 53359a6 and 6b974f2.

📒 Files selected for processing (2)
  • apps/desktop-tauri/src/components/TotalApiValueCard.tsx
  • apps/desktop-tauri/src/surfaces/ChartsPanel.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/desktop-tauri/src/surfaces/ChartsPanel.tsx
  • apps/desktop-tauri/src/components/TotalApiValueCard.tsx

📝 Walkthrough

Walkthrough

Adds an API value card that loads local provider totals, supports period and metric selection, renders aggregate and provider-level data, reports pricing coverage, handles empty/error states, and integrates above the existing charts panel.

Changes

API value card

Layer / File(s) Summary
Aggregation model and calculations
apps/desktop-tauri/src/lib/apiValueCard.ts, apps/desktop-tauri/src/lib/apiValueCard.test.ts
Defines card data types and computes ranked metric slices, token pricing coverage, empty states, and SVG ring geometry with unit tests.
Card loading, controls, and rendering
apps/desktop-tauri/src/components/TotalApiValueCard.tsx, apps/desktop-tauri/src/components/TotalApiValueCard.test.tsx
Loads local totals, supports period and metric controls, renders loading/error/empty/data states, and displays provider legends and pricing coverage.
ChartsPanel integration and responsive styling
apps/desktop-tauri/src/surfaces/ChartsPanel.tsx, apps/desktop-tauri/src/styles.css
Places the card above existing chart content and adds its layout, visualization, legend, status, and narrow-screen styles.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ChartsPanel
  participant TotalApiValueCard
  participant getLocalApiValueTotals
  participant buildApiValueCard
  ChartsPanel->>TotalApiValueCard: Render card
  TotalApiValueCard->>getLocalApiValueTotals: Request local API value totals
  getLocalApiValueTotals-->>TotalApiValueCard: Return provider totals
  TotalApiValueCard->>buildApiValueCard: Build selected period and metric model
  buildApiValueCard-->>TotalApiValueCard: Return slices, totals, and coverage
  TotalApiValueCard-->>ChartsPanel: Render card UI
Loading

Possibly related PRs

  • tsouth89/ceiling#57: Adds the Tauri command, bridge function, and DTOs consumed by this API value card.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding the total API-value donut card.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/sou-265-api-value-card

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/desktop-tauri/src/components/TotalApiValueCard.tsx`:
- Around line 114-143: Update the period and metric controls in the
TotalApiValueCard component to use native button-group semantics: remove
role="tablist"/role="tab" and replace aria-selected with aria-pressed on each
button, preserving the existing active-state comparisons and click handlers.
- Around line 94-96: Update the coverage visibility logic near coveragePercent
so showCoverage compares the raw model.coverage ratio against 1, rather than the
rounded percentage. Continue rounding coveragePercent only for display,
preserving null handling and showing partial coverage such as 99.6%.

In `@apps/desktop-tauri/src/surfaces/ChartsPanel.tsx`:
- Line 73: Update the unsupported-chart-provider early-return branch in
ChartsPanel so it still renders TotalApiValueCard alongside the existing
empty-state content. Keep the card mounted even when chart data is unavailable,
including snapshot errors and unsupported providers, while preserving the normal
chart rendering path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cb115959-167e-49b5-8b4b-17fa3a19ac92

📥 Commits

Reviewing files that changed from the base of the PR and between 13e64e2 and 53359a6.

📒 Files selected for processing (6)
  • apps/desktop-tauri/src/components/TotalApiValueCard.test.tsx
  • apps/desktop-tauri/src/components/TotalApiValueCard.tsx
  • apps/desktop-tauri/src/lib/apiValueCard.test.ts
  • apps/desktop-tauri/src/lib/apiValueCard.ts
  • apps/desktop-tauri/src/styles.css
  • apps/desktop-tauri/src/surfaces/ChartsPanel.tsx

Comment thread apps/desktop-tauri/src/components/TotalApiValueCard.tsx Outdated
Comment thread apps/desktop-tauri/src/components/TotalApiValueCard.tsx Outdated
Comment thread apps/desktop-tauri/src/surfaces/ChartsPanel.tsx
…Rabbit)

- Coverage note: compare the raw ratio (model.coverage < 1) instead of the
  rounded percent, so 99.6% (rounds to 100) still shows "N% of tokens priced"
  when tokens are unpriced.
- Switchers: use role="group" + aria-pressed native buttons instead of
  role="tab" without the full tablist keyboard pattern — accurate semantics
  for value toggles.
- ChartsPanel: render TotalApiValueCard in the "no chart providers" empty
  branch too; it loads its own local totals, so API-value analytics should not
  be hidden when no provider reports chart series.

Frontend 258 / tsc clean.
@tsouth89
tsouth89 merged commit d9ff2f4 into main Jul 18, 2026
9 of 10 checks passed
@tsouth89
tsouth89 deleted the feat/sou-265-api-value-card branch July 18, 2026 22:09
@tsouth89 tsouth89 mentioned this pull request Jul 18, 2026
tsouth89 added a commit that referenced this pull request Jul 19, 2026
Version bump to **1.1.0** (build 95) and changelog for the local
spend-analytics work shipped in #52-#58.

## Bumped
- `version.env` (MARKETING_VERSION 1.1.0, BUILD_NUMBER 95)
- `rust/Cargo.toml`, `apps/desktop-tauri/src-tauri/Cargo.toml`
- `apps/desktop-tauri/package.json`,
`apps/desktop-tauri/src-tauri/tauri.conf.json`
- `Cargo.lock` (both workspace crates)

## Changelog highlights (1.1.0)
- Total estimated API-value card (Codex + Claude) with Today / Yesterday
/ 30-day and API value / Tokens views, provider ring, and ranked legend.
- Per-model and per-Codex-effort 30-day breakdowns with pricing-coverage
transparency and "Not priced" rows.
- Codex cost-integrity fixes: suppressed replayed child-session history
(the ~20x inflation), archived-session scanning + rollout dedup,
unknown-model unpricing, and real reasoning-effort tiers.

`cargo check --workspace` compiles both crates at 1.1.0. After merge,
tag `v1.1.0` to trigger the signed release build.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Added a local usage and API-value dashboard with Today, Yesterday, and
30-day views.
  * Added provider breakdowns and ranked usage details.
  * Added 30-day spend breakdowns by model and Codex reasoning effort.
* Added pricing coverage indicators, including clearly labeled “Not
priced” entries.
* **Bug Fixes**
* Improved usage accuracy by preventing duplicate or replayed session
data from being counted.
* Corrected Codex attribution and suppressed misleading dollar estimates
for models without pricing.
* **Release**
  * Updated the application to version 1.1.0.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: tsouth89 <tsouth89@users.noreply.github.com>
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