Skip to content

feat: add the AI spend total spend card - #32338

Merged
ssncferreira merged 2 commits into
ssncf/ai-spend-overview-shellfrom
ssncf/ai-spend-total-card
Nov 20, 2026
Merged

ssncferreira merged 2 commits into
ssncf/ai-spend-overview-shellfrom
ssncf/ai-spend-total-card

Conversation

@ssncferreira

@ssncferreira ssncferreira commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds the Total spend card to the AI spend Overview tab. The total comes from the fast overview endpoint, and the "N models not set up" warning from GET /api/experimental/organizations/{organization}/ai/model-prices/unpriced, which is slower, so the total renders first and the warning follows with its own loading state.

Changes

  • Add API.experimental.getOrganizationUnpricedAIModels and the organizationUnpricedAIModels query. The page requests it alongside the overview, and viewers who cannot read the organization's model prices get a 403.
  • Add StatCard, the labeled figure the overview cards share, and TotalSpendCard, which shows a skeleton until the total loads and a spinner while the unpriced models load.
  • If the unpriced models request fails, including the 403, hide the warning instead of blocking the total.
  • Format the total with the existing formatCostMicros, e.g. "$2,621.70", like the other spend amounts.
  • If an overview refetch fails, keep the cached cards below the error.
  • Add MockUnpricedAIModels, a test for the unpriced models request, and stories for the card states, including the hidden warning when the request fails.

Related to AIGOV-732

Note

Generated by Coder Agents on behalf of @ssncferreira.

@linear-code

linear-code Bot commented Nov 17, 2026

Copy link
Copy Markdown

AIGOV-732

@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-total-card branch from c2bb9d7 to 9772ff9 Compare November 18, 2026 08:26
@ssncferreira ssncferreira changed the title feat(site/src): add the AI spend total spend card feat: add the AI spend total spend card Nov 18, 2026
@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-total-card branch from 9772ff9 to c8a2e29 Compare November 18, 2026 09:08
@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-total-card branch 3 times, most recently from 5572d9a to e63249b Compare November 18, 2026 15:14
@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-total-card branch from e63249b to 6f99b0f Compare November 18, 2026 15:41
@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-total-card branch from 6f99b0f to 0887658 Compare November 19, 2026 17:03
@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-total-card branch from 0887658 to 8e31c1b Compare November 19, 2026 17:05
@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-total-card branch from 8e31c1b to 141d658 Compare November 19, 2026 17:10
@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-total-card branch from 141d658 to 03d16b8 Compare November 19, 2026 17:20
@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-total-card branch from 03d16b8 to 5d47d37 Compare November 19, 2026 17:46
@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-total-card branch 2 times, most recently from c4af7f9 to 70fb240 Compare November 19, 2026 17:58
@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-total-card branch from 70fb240 to 3a74621 Compare November 19, 2026 18:00
@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-total-card branch from 3a74621 to 12286de Compare November 19, 2026 18:13
@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-total-card branch 6 times, most recently from 1bfa67d to 15b6cf1 Compare November 19, 2026 18:33
@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-total-card branch from 15b6cf1 to add0967 Compare November 19, 2026 18:42
@ssncferreira
ssncferreira marked this pull request as ready for review November 19, 2026 18:58
Comment on lines +46 to +47
{overviewError != null && <ErrorAlert error={overviewError} />}
{(overview !== undefined || overviewError == null) && (

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd prefer strict equality here. Loose != null / == null quietly treats undefined the same as null.

Suggested change
{overviewError != null && <ErrorAlert error={overviewError} />}
{(overview !== undefined || overviewError == null) && (
{overviewError !== null && <ErrorAlert error={overviewError} />}
{(overview !== undefined || overviewError === null) && (

Tightening the prop type would make the strict check correct and discourage the loose one. useQuery already returns Error | null, so overviewError could be typed Error | null here (L21) and in AISpendPageView (the same goes for organizationsError and its != null checks there). The types in api/errors.ts don't fit: ApiError would need a cast from the query's Error, and network errors have no response. One catch: mockApiError isn't assignable to Error, so the stories would need a small adjustment.

Generated by Coder Agents on behalf of @jeremyruppel.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm curious why we don't have a linter rule catching this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yeah 100% we should. agent had this to say in its investigation:

It's also an established pattern in this area of the code:

Other AI settings pages use it the same way, for example InstructionsPageView.tsx:83 (organizationAccessError != null) and OrganizationInstructionsSettings.tsx:68-113.

Across site/src, about 67 places use the loose == null / != null and about 354 use the strict form.

but I agree with you, I'm surprised we don't already have this locked down

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, it seems this pattern is used throughout the codebase, and the lint allows it. I applied the changes on this stack. @jeremyruppel @DanielleMaywood should I go ahead and create a linear issue just to keep track of this?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Jeremy has already got a PR up for this, no need for you to track it

@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-total-card branch 2 times, most recently from 1e4e754 to 1376b61 Compare November 20, 2026 10:49
@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-total-card branch from 1376b61 to cc9b953 Compare November 20, 2026 11:04
@ssncferreira
ssncferreira force-pushed the ssncf/ai-spend-total-card branch from cc9b953 to d3ab1ba Compare November 20, 2026 11:51
@ssncferreira
ssncferreira merged commit 78ee4f3 into main Nov 20, 2026
26 checks passed
@ssncferreira
ssncferreira deleted the ssncf/ai-spend-total-card branch November 20, 2026 17:15

This branch had an error being deployed

1 failed deployment
docs-preview — d3ab1ba3 Deployed Nov 20, 2026 by ssncferreira via cleanup #289
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.

3 participants