Skip to content

feat(billing): warn under each page's header from 80% of the month's AI usage, and once it's used up (AI usage display, part 2) - #1431

Merged
gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:feature/ai-usage-banners
Oct 24, 2026
Merged

gkhngyk merged 3 commits into
ansvisor:mainfrom
cihan-gyk:feature/ai-usage-banners

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

AI usage display, part 2: the warnings at 80% and 100% of the month's AI allowance (Drive › AI Usage › AI-USAGE-spec.md §4).

Stacked on #1430 (the header meter). Web only, no migration.

Banner under each page's header row. HeaderWithAiUsage (#1430) now puts it right after the row, so it shows on every page that has the meter, in the same place.

  • 80–99%, amber: "You've used 84% of this month's AI limit." with See usage, which goes to Billing's AI usage card.
  • 100%, red: "You've used this month's AI limit. AI features stop until Nov 1; Agent Chat on your own AI key keeps working."
    • Admins see Get more AI usage (left out on Enterprise) and Use your own key. These come from AiUsageGetMore, which the meter's popover now uses too.
    • Other members read the popover's "To get more AI usage or use your own key, ask an admin of your workspace."
  • Below 80%, on a plan without an allowance, and before the first read, nothing shows.
  • Colours follow the app's existing amber and red notice boxes, with dark: variants.

Toast, once a period in a browser, on reaching 80%, with the banner's words (spec §4). A used-up allowance has its red banner and no toast.

  • aiUsageToastDue (lib/billing/ai-usage.ts) decides from the last toast the browser showed. It keeps "{periodStart}:{plan}" in localStorage under aeo:ai-usage-toast.
  • A new period, or a plan changed within one, starts over.
  • If storage can't be used, the tab remembers in memory, so a re-read doesn't toast again.

From the spec, changed here:

Next (same spec, §4 and §3.1): the Content Editor's meter with "This page so far", its banner, and the agent buttons saying why they can't run (stacked on #1429), then the detail pages. Chat gets its banner with the Chat work.

Pre-push review: no high findings. Fixed:

  • the storage-blocked test now gives a new answer on each read, as the server does; it fails without the in-memory fallback;
  • the 100% toast was dropped to follow the spec;
  • the admin links are shared with the popover, and the "ask an admin" sentence is one text;
  • a plan changed within the period warns again;
  • tests now check that nothing toasts below 80%, unmetered or self-hosted.

Related issue

Drive spec AI Usage (approved 2026-10-23). No GitHub issue.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation

How to test

  1. As in feat(billing): show the month's AI usage at the top right of the main pages (AI usage display, part 1) #1430, run Cloud mode with a workspace on a cloud plan.
  2. Put the workspace at 84% of its allowance (rows in prompt_improve_usage) and open any page:
    • an amber banner follows the header row;
    • a toast says the same, once; reloading or opening another page doesn't toast again.
  3. Put it at 100%:
    • the banner turns red, with the reset date and the two links;
    • no new toast;
    • as a member who isn't an admin, the banner asks you to ask an admin instead.
  4. Below 80%, there is no banner and no toast.
  5. Check light and dark, and 1024 px.

Checked locally on the demo workspace, temporarily on Growth with test usage rows (restored and removed afterwards):

  • 84% and 100% on Insights, Mentions, Content Library and Action Center at 1280 and 1024 px:
    • the banner sits 24 px under the header row, at full width;
    • there is no horizontal overflow.
  • The toast showed once (watched with a MutationObserver).
  • Contrast:
    • text 8.7 light / 15.1 dark (amber), 9.2 / 11.2 (red);
    • links 12–19.

Checklist

  • web/: yarn format:check, yarn lint (0 errors; 6 existing warnings elsewhere), yarn typecheck, yarn test (366 files, 3,312 tests) and yarn build pass
  • Tests:
    • ai-usage-banner.test.tsx:
      • nothing below 80%, unmetered or before a read;
      • amber with See usage;
      • red with the date and the admin's links;
      • no Get more on Enterprise;
      • "ask an admin" for other members.
    • lib/billing/ai-usage.test.ts: the toast is due once a period from 80%, again in a new period or on a changed plan, and not below 80%, once used up, or unmetered.
    • ai-usage-meter.test.tsx:
      • the banner follows the header row from 80%;
      • the provider toasts the warning once, across re-reads, a new tab and reaching 100%, and again on a changed plan;
      • no toast below 80%, unmetered or self-hosted;
      • once in a tab when storage throws, with a new answer on each read.
  • UI text in messages/en.json

🤖 Generated with Claude Code

cihan-gyk and others added 2 commits October 24, 2026 01:06
… pages (AI usage display, part 1)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…AI usage, and once it's used up (AI usage display, part 2)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good.

@gkhngyk
gkhngyk merged commit 3181b0a into ansvisor:main Oct 24, 2026
4 of 5 checks passed
cihan-gyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 24, 2026
ansvisor#1430 and ansvisor#1431 are on main (squash-merged), with ansvisor#1433 and ansvisor#1436; this
branch's own change (part 4) is applied on top of them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants