Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
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)
Cihan3181b0a578f6
diff --git a/web/messages/en.json b/web/messages/en.jsonindex 409ebf8b2..e97744716 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -19,6 +19,11 @@"labelWarning": "AI {percent} used this month, close to the limit","labelExhausted": "AI {percent} used this month, the limit is reached"},+ "askAdmin": "To get more AI usage or use your own key, ask an admin of your workspace.",+ "getMore": {+ "plan": "Get more AI usage",+ "ownKey": "Use your own key"+ },"popover": {"title": "AI usage this month · {plan} plan","titleNoPlan": "AI usage this month",@@ -32,10 +37,13 @@"auditPages": "Site Audit pages","promptLocations": "Prompt locations","ofLimit": "{used} of {limit}",- "askAdmin": "To get more AI usage or use your own key, ask an admin of your workspace.",- "getMore": "Get more AI usage",- "useOwnKey": "Use your own key","details": "See details"+ },+ "banner": {+ "warning": "You've used {percent} of this month's AI limit.",+ "seeUsage": "See usage",+ "exhausted": "You've used this month's AI limit. AI features stop until {date}; Agent Chat on your own AI key keeps working.",+ "exhaustedNoDate": "You've used this month's AI limit. AI features stop until it resets; Agent Chat on your own AI key keeps working."}},"common": {diff --git a/web/src/components/ai-usage/ai-usage-banner.test.tsx b/web/src/components/ai-usage/ai-usage-banner.test.tsxnew file mode 100644index 000000000..3ab5eec3e--- /dev/null+++ b/web/src/components/ai-usage/ai-usage-banner.test.tsx@@ -0,0 +1,125 @@+import { act, type ReactNode } from 'react';+import { createRoot, type Root } from 'react-dom/client';+import { NextIntlClientProvider } from 'next-intl';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import messages from '../../../messages/en.json';+import { RoleProvider, type TeamRole } from '@/components/providers/role-provider';+import type { AiUsage } from '@/lib/billing/ai-usage';++/**+ * The banner under a page's header row (AI usage spec §4): amber from 80% of+ * the month's AI allowance, red once it is used up, nothing below.+ */++const state: { usage: AiUsage | null } = { usage: null };+vi.mock('@/components/providers/ai-usage-provider', () => ({+ useAiUsage: () => ({ usage: state.usage, refresh: () => {} }),+}));+vi.mock('@/i18n/navigation', () => ({+ Link: ({+ href,+ className,+ children,+ }: {+ href: string;+ className?: string;+ children: ReactNode;+ }) => (+ <a href={href} className={className}>+ {children}+ </a>+ ),+}));++const { AiUsageBanner } = await import('./ai-usage-banner');++(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT =+ true;++const usage = (over: Partial<AiUsage> = {}): AiUsage => ({+ plan: 'growth',+ planName: 'Growth',+ periodStart: '2026-10-20T09:00:00.000Z',+ periodEnd: '2026-11-20T09:00:00.000Z',+ unlimited: false,+ percentUsed: 84.6,+ features: [],+ ...over,+});++let container: HTMLDivElement;+let root: Root;++async function render(role: TeamRole = 'admin') {+ await act(async () => {+ root.render(+ <NextIntlClientProvider locale="en" messages={messages}>+ <RoleProvider role={role}>+ <AiUsageBanner />+ </RoleProvider>+ </NextIntlClientProvider>,+ );+ });+}+const links = () =>+ [...container.querySelectorAll('a')].map((a) => [a.textContent, a.getAttribute('href')]);++beforeEach(() => {+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+});++afterEach(() => {+ act(() => root.unmount());+ container.remove();+});++describe('AiUsageBanner', () => {+ it('shows nothing below 80%, on a plan without an allowance, or before a read', async () => {+ for (const read of [+ usage({ percentUsed: 79.9 }),+ usage({ unlimited: true, percentUsed: null }),+ null,+ ]) {+ state.usage = read;+ await render();+ expect(container.innerHTML).toBe('');+ }+ });++ it('warns in amber from 80%, with where to see the usage', async () => {+ state.usage = usage();+ await render();+ expect(container.textContent).toContain("You've used 84% of this month's AI limit.");+ expect(container.firstElementChild!.className).toContain('bg-amber-50');+ expect(container.firstElementChild!.className).toContain('dark:bg-amber-950/30');+ expect(links()).toEqual([['See usage', '/dashboard/settings/billing#ai-usage']]);+ });++ it('says in red until when AI stops once used up, with getting more and an own key', async () => {+ state.usage = usage({ percentUsed: 100 });+ await render();+ expect(container.textContent).toContain(+ "You've used this month's AI limit. AI features stop until Nov 20; Agent Chat on your own AI key keeps working.",+ );+ expect(container.firstElementChild!.className).toContain('bg-red-50');+ expect(links()).toEqual([+ ['Get more AI usage', '/dashboard/settings/billing'],+ ['Use your own key', '/dashboard/settings/ai-providers'],+ ]);+ });++ it('leaves Get more out on Enterprise, and tells other members to ask an admin', async () => {+ state.usage = usage({ plan: 'enterprise', planName: 'Enterprise', percentUsed: 100 });+ await render();+ expect(links()).toEqual([['Use your own key', '/dashboard/settings/ai-providers']]);++ state.usage = usage({ percentUsed: 100, periodEnd: null });+ await render('analyst');+ expect(container.textContent).toBe(+ "You've used this month's AI limit. AI features stop until it resets; Agent Chat on your own AI key keeps working. To get more AI usage or use your own key, ask an admin of your workspace.",+ );+ expect(links()).toEqual([]);+ });+});diff --git a/web/src/components/ai-usage/ai-usage-banner.tsx b/web/src/components/ai-usage/ai-usage-banner.tsxnew file mode 100644index 000000000..be0a1da93--- /dev/null+++ b/web/src/components/ai-usage/ai-usage-banner.tsx@@ -0,0 +1,60 @@+'use client';++import { AlertCircle, AlertTriangle } from 'lucide-react';+import { useTranslations } from 'next-intl';+import { Link } from '@/i18n/navigation';+import { useAiUsage } from '@/components/providers/ai-usage-provider';+import { buttonVariants } from '@/components/ui/button-variants';+import { useUserRole } from '@/hooks/use-user-role';+import { aiUsageTone, percentLabel } from '@/lib/billing/ai-usage';+import { formatMonthDay } from '@/lib/format';+import { AiUsageGetMore } from './ai-usage-get-more';++/**+ * The month's AI usage once it needs attention, under a page's header row+ * (AI usage spec §4): amber from 80%, with where to see it; red once used up,+ * saying until when AI features stop, with where to get more (other members+ * are told to ask an admin). Nothing below 80%.+ */+export function AiUsageBanner() {+ const t = useTranslations('aiUsage');+ const { usage } = useAiUsage();+ const { canAdmin } = useUserRole();+ if (!usage || usage.unlimited) return null;++ const tone = aiUsageTone(usage);+ const resets = usage.periodEnd ? formatMonthDay(usage.periodEnd) : null;++ if (tone === 'warning') {+ return (+ <div className="flex flex-wrap items-center gap-x-3 gap-y-2 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm dark:border-amber-900/50 dark:bg-amber-950/30">+ <AlertTriangle className="h-4 w-4 shrink-0 text-amber-600 dark:text-amber-500" />+ <p className="min-w-0 flex-1 text-amber-900 dark:text-amber-200">+ {t('banner.warning', { percent: percentLabel(usage.percentUsed ?? 0) })}+ </p>+ <Link+ href="/dashboard/settings/billing#ai-usage"+ className={buttonVariants({ variant: 'outline', size: 'sm' })}+ >+ {t('banner.seeUsage')}+ </Link>+ </div>+ );+ }++ if (tone !== 'exhausted') return null;+ return (+ <div className="flex flex-wrap items-center gap-x-3 gap-y-2 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm dark:border-red-900/50 dark:bg-red-950/30">+ <AlertCircle className="h-4 w-4 shrink-0 text-red-600 dark:text-red-500" />+ <p className="min-w-0 flex-1 text-red-900 dark:text-red-200">+ {resets ? t('banner.exhausted', { date: resets }) : t('banner.exhaustedNoDate')}+ {!canAdmin && <> {t('askAdmin')}</>}+ </p>+ {canAdmin && (+ <div className="flex flex-wrap gap-1.5">+ <AiUsageGetMore plan={usage.plan} primary />+ </div>+ )}+ </div>+ );+}diff --git a/web/src/components/ai-usage/ai-usage-get-more.tsx b/web/src/components/ai-usage/ai-usage-get-more.tsxnew file mode 100644index 000000000..de0dbbc5a--- /dev/null+++ b/web/src/components/ai-usage/ai-usage-get-more.tsx@@ -0,0 +1,48 @@+'use client';++import { useTranslations } from 'next-intl';+import { Link } from '@/i18n/navigation';+import { buttonVariants } from '@/components/ui/button-variants';+import { useUserRole } from '@/hooks/use-user-role';++/**+ * Where to get more AI usage, in the meter's popover and the used-up banner+ * (AI usage spec §3.1, §4): a bigger plan and the workspace's own key, both+ * an admin's to change, so nothing for other members (they are told to ask+ * one). Enterprise has no bigger plan to move to. `primary` makes the plan+ * link the area's one black button.+ */+export function AiUsageGetMore({+ plan,+ primary,+ onFollow,+}: {+ plan: string;+ primary: boolean;+ /** When a link is followed: the popover closes. */+ onFollow?: () => void;+}) {+ const t = useTranslations('aiUsage.getMore');+ const { canAdmin } = useUserRole();+ if (!canAdmin) return null;+ return (+ <>+ {plan !== 'enterprise' && (+ <Link+ href="/dashboard/settings/billing"+ onClick={onFollow}+ className={buttonVariants({ variant: primary ? 'default' : 'outline', size: 'sm' })}+ >+ {t('plan')}+ </Link>+ )}+ <Link+ href="/dashboard/settings/ai-providers"+ onClick={onFollow}+ className={buttonVariants({ variant: 'outline', size: 'sm' })}+ >+ {t('ownKey')}+ </Link>+ </>+ );+}diff --git a/web/src/components/ai-usage/ai-usage-meter.test.tsx b/web/src/components/ai-usage/ai-usage-meter.test.tsxindex 729af815c..0a4dd258b 100644--- a/web/src/components/ai-usage/ai-usage-meter.test.tsx+++ b/web/src/components/ai-usage/ai-usage-meter.test.tsx@@ -46,6 +46,20 @@ vi.mock('@/stores/use-brand-store', () => ({useBrandStore: (selector: (state: { activeBrandId: string | null }) => unknown) =>selector({ activeBrandId: 'b1' }),}));+// An in-memory localStorage: the test environment has none.+const store = new Map<string, string>();+Object.defineProperty(window, 'localStorage', {+ configurable: true,+ value: {+ getItem: (key: string) => store.get(key) ?? null,+ setItem: (key: string, value: string) => void store.set(key, value),+ removeItem: (key: string) => void store.delete(key),+ clear: () => store.clear(),+ },+});++const toast = vi.hoisted(() => ({ warning: vi.fn(), error: vi.fn() }));+vi.mock('sonner', () => ({ toast }));vi.mock('@/lib/billing/ai-usage-client', () => ({readAiUsage: vi.fn(),readUsageLimits: vi.fn(),@@ -115,6 +129,9 @@ beforeEach(() => {root = createRoot(container);vi.mocked(readAiUsage).mockReset().mockResolvedValue(usage());vi.mocked(readUsageLimits).mockReset().mockResolvedValue(limits);+ toast.warning.mockReset();+ toast.error.mockReset();+ localStorage.clear();});afterEach(() => {@@ -285,9 +302,83 @@ describe('HeaderWithAiUsage', () => {expect(trigger()!.className).toContain('self-end');expect(row.className).toContain('sm:flex-row');});++ it('follows the row with the banner from 80%', async () => {+ vi.mocked(readAiUsage).mockResolvedValue(usage({ percentUsed: 84 }));+ await render(+ 'admin',+ <HeaderWithAiUsage>+ <h1>Mentions</h1>+ </HeaderWithAiUsage>,+ );+ expect(container.children).toHaveLength(2);+ expect(container.lastElementChild!.textContent).toContain(+ "You've used 84% of this month's AI limit.",+ );+ });});describe('AiUsageProvider', () => {+ it('toasts reaching 80% once a period, not again on later reads, in a new tab or once used up', async () => {+ let now = 1_000_000;+ vi.spyOn(Date, 'now').mockImplementation(() => now);+ vi.mocked(readAiUsage).mockImplementation(async () => usage({ percentUsed: 84 }));+ await render();+ expect(toast.warning).toHaveBeenCalledExactlyOnceWith(+ "You've used 84% of this month's AI limit.",+ );+ expect(localStorage.getItem('aeo:ai-usage-toast')).toBe('2026-10-20T09:00:00.000Z:growth');++ const reread = async (over: Partial<AiUsage>) => {+ now += AI_USAGE_STALE_MS;+ vi.mocked(readAiUsage).mockImplementation(async () => usage(over));+ await act(async () => window.dispatchEvent(new Event('focus')));+ await act(async () => {});+ };+ await reread({ percentUsed: 90 });+ await remount();+ // Used up: the red banner says it, no toast.+ await reread({ percentUsed: 100 });+ expect(readAiUsage).toHaveBeenCalledTimes(4);+ expect(toast.warning).toHaveBeenCalledTimes(1);+ expect(toast.error).not.toHaveBeenCalled();++ // A plan changed within the period starts over.+ await reread({ plan: 'enterprise', planName: 'Enterprise', percentUsed: 81 });+ expect(toast.warning).toHaveBeenCalledTimes(2);+ });++ it('toasts nothing below 80%, on a plan without an allowance, or self-hosted', async () => {+ vi.mocked(readAiUsage).mockResolvedValue(usage({ percentUsed: 79.9 }));+ await render();+ vi.mocked(readAiUsage).mockResolvedValue(usage({ unlimited: true, percentUsed: null }));+ await remount();+ env.cloud = false;+ await remount();+ expect(toast.warning).not.toHaveBeenCalled();+ });++ it('toasts once in a tab when the browser’s storage can’t be used', async () => {+ let now = 1_000_000;+ vi.spyOn(Date, 'now').mockImplementation(() => now);+ vi.spyOn(localStorage, 'getItem').mockImplementation(() => {+ throw new Error('blocked');+ });+ vi.spyOn(localStorage, 'setItem').mockImplementation(() => {+ throw new Error('blocked');+ });+ // Each read a new answer, as the server's: the toast is weighed again on each.+ vi.mocked(readAiUsage).mockImplementation(async () => usage({ percentUsed: 84 }));+ await render();+ for (let read = 0; read < 2; read++) {+ now += AI_USAGE_STALE_MS;+ await act(async () => window.dispatchEvent(new Event('focus')));+ await act(async () => {});+ }+ expect(readAiUsage).toHaveBeenCalledTimes(3);+ expect(toast.warning).toHaveBeenCalledTimes(1);+ });+it('reads once for every page, again on a page change once a minute old', async () => {let now = 1_000_000;vi.spyOn(Date, 'now').mockImplementation(() => now);diff --git a/web/src/components/ai-usage/ai-usage-meter.tsx b/web/src/components/ai-usage/ai-usage-meter.tsxindex 90e3abe78..e924745bb 100644--- a/web/src/components/ai-usage/ai-usage-meter.tsx+++ b/web/src/components/ai-usage/ai-usage-meter.tsx@@ -4,6 +4,8 @@ import { useRef, useState, type ReactNode } from 'react';import { useTranslations } from 'next-intl';import { Link } from '@/i18n/navigation';import { useAiUsage } from '@/components/providers/ai-usage-provider';+import { AiUsageBanner } from './ai-usage-banner';+import { AiUsageGetMore } from './ai-usage-get-more';import { buttonVariants } from '@/components/ui/button-variants';import { LoadingDots } from '@/components/ui/loading-dots';import { Popover, PopoverContent, PopoverTitle, PopoverTrigger } from '@/components/ui/popover';@@ -46,14 +48,19 @@ const LABEL_KEY = {* A page's header row with the AI usage meter at its far right, on the* title's line (AI usage spec §3.1): the same place on every page, however* the row's own buttons wrap beside it. On a phone it goes under the row, on- * the right, so the row keeps the whole width for its buttons.+ * the right, so the row keeps the whole width for its buttons. From 80% of+ * the month's allowance the banner follows the row (spec §4), spaced as the+ * page spaces its parts.*/export function HeaderWithAiUsage({ children }: { children: ReactNode }) {return (- <div className="flex flex-col gap-2 sm:flex-row sm:items-start sm:gap-3">- <div className="min-w-0 sm:flex-1">{children}</div>- <AiUsageMeter className="self-end sm:self-auto" />- </div>+ <>+ <div className="flex flex-col gap-2 sm:flex-row sm:items-start sm:gap-3">+ <div className="min-w-0 sm:flex-1">{children}</div>+ <AiUsageMeter className="self-end sm:self-auto" />+ </div>+ <AiUsageBanner />+ </>);}@@ -204,27 +211,9 @@ export function AiUsageMeter({ className }: { className?: string }) {</>)}- {!canAdmin && <p className="mt-3 text-xs text-muted-foreground">{t('popover.askAdmin')}</p>}+ {!canAdmin && <p className="mt-3 text-xs text-muted-foreground">{t('askAdmin')}</p>}<div className="mt-4 flex flex-wrap gap-1.5">- {/* Enterprise has no bigger plan to move to. */}- {canAdmin && usage.plan !== 'enterprise' && (- <Link- href="/dashboard/settings/billing"- onClick={close}- className={buttonVariants({ variant: pressing ? 'default' : 'outline', size: 'sm' })}- >- {t('popover.getMore')}- </Link>- )}- {canAdmin && (- <Link- href="/dashboard/settings/ai-providers"- onClick={close}- className={buttonVariants({ variant: 'outline', size: 'sm' })}- >- {t('popover.useOwnKey')}- </Link>- )}+ <AiUsageGetMore plan={usage.plan} primary={pressing} onFollow={close} /><Linkhref="/dashboard/settings/billing#ai-usage"onClick={close}diff --git a/web/src/components/providers/ai-usage-provider.tsx b/web/src/components/providers/ai-usage-provider.tsxindex 3e2320d39..5a2e01e9c 100644--- a/web/src/components/providers/ai-usage-provider.tsx+++ b/web/src/components/providers/ai-usage-provider.tsx@@ -11,8 +11,16 @@ import {type ReactNode,} from 'react';import { usePathname } from 'next/navigation';+import { useTranslations } from 'next-intl';+import { toast } from 'sonner';import { isCloud } from '@/config/plans';-import type { AiUsage } from '@/lib/billing/ai-usage';+import {+ AI_USAGE_TOAST_KEY,+ aiUsageToastDue,+ aiUsageToastMark,+ percentLabel,+ type AiUsage,+} from '@/lib/billing/ai-usage';import { readAiUsage } from '@/lib/billing/ai-usage-client';/** A read this old is read again when the member opens another page or comes back to the tab. */@@ -35,6 +43,8 @@ const AiUsageContext = createContext<AiUsageState>({ usage: null, refresh: () =>* meter (AI usage spec §3.1), so moving between pages doesn't blink it. It* is read again on a page change or a return to the tab once the last read* is a minute old. Only Ansvisor Cloud meters AI: self-hosted reads nothing.+ * Reaching 80% of the allowance toasts once a period in a browser (spec §4);+ * the banners under the header rows stay.*/export function AiUsageProvider({ children }: { children: ReactNode }) {const metered = isCloud();@@ -42,6 +52,9 @@ export function AiUsageProvider({ children }: { children: ReactNode }) {const [usage, setUsage] = useState<AiUsage | null | undefined>(metered ? undefined : null);const readAt = useRef(0);const reading = useRef(false);+ const t = useTranslations('aiUsage.banner');+ // What this tab toasted, for a browser whose storage can't be used.+ const toasted = useRef<string | null>(null);const read = useCallback(async () => {if (!metered || reading.current) return;@@ -76,6 +89,24 @@ export function AiUsageProvider({ children }: { children: ReactNode }) {};}, [read]);+ useEffect(() => {+ if (!usage) return;+ let shown = toasted.current;+ try {+ shown = localStorage.getItem(AI_USAGE_TOAST_KEY) ?? shown;+ } catch {+ // Storage blocked: this tab's memory decides.+ }+ if (!aiUsageToastDue(usage, shown)) return;+ toasted.current = aiUsageToastMark(usage);+ try {+ localStorage.setItem(AI_USAGE_TOAST_KEY, toasted.current);+ } catch {+ // As above.+ }+ toast.warning(t('warning', { percent: percentLabel(usage.percentUsed ?? 0) }));+ }, [usage, t]);+const refresh = useCallback(() => void read(), [read]);const value = useMemo(() => ({ usage, refresh }), [usage, refresh]);return <AiUsageContext.Provider value={value}>{children}</AiUsageContext.Provider>;diff --git a/web/src/lib/billing/ai-usage.test.ts b/web/src/lib/billing/ai-usage.test.tsnew file mode 100644index 000000000..9ff4595f9--- /dev/null+++ b/web/src/lib/billing/ai-usage.test.ts@@ -0,0 +1,38 @@+import { describe, expect, it } from 'vitest';+import { aiUsageToastDue, aiUsageToastMark, type AiUsage } from './ai-usage';++/** The AI usage toast (AI usage spec §4): once a period in a browser, on reaching 80%. */++const usage = (over: Partial<AiUsage> = {}): AiUsage => ({+ plan: 'growth',+ planName: 'Growth',+ periodStart: '2026-10-20T09:00:00.000Z',+ periodEnd: '2026-11-20T09:00:00.000Z',+ unlimited: false,+ percentUsed: 84,+ features: [],+ ...over,+});+const shown = '2026-10-20T09:00:00.000Z:growth';++describe('aiUsageToastDue', () => {+ it('marks the period and the plan it warned about', () => {+ expect(aiUsageToastMark(usage())).toBe(shown);+ });++ it('is due once a period from 80%', () => {+ expect(aiUsageToastDue(usage({ percentUsed: 80 }), null)).toBe(true);+ expect(aiUsageToastDue(usage({ percentUsed: 91 }), shown)).toBe(false);+ });++ it('starts over in a new period, or on a plan changed within one', () => {+ expect(aiUsageToastDue(usage({ periodStart: '2026-11-20T09:00:00.000Z' }), shown)).toBe(true);+ expect(aiUsageToastDue(usage({ plan: 'enterprise' }), shown)).toBe(true);+ });++ it('is not due below 80%, once used up (the red banner says it), or unmetered', () => {+ expect(aiUsageToastDue(usage({ percentUsed: 79.9 }), null)).toBe(false);+ expect(aiUsageToastDue(usage({ percentUsed: 100 }), null)).toBe(false);+ expect(aiUsageToastDue(usage({ unlimited: true, percentUsed: null }), null)).toBe(false);+ });+});diff --git a/web/src/lib/billing/ai-usage.ts b/web/src/lib/billing/ai-usage.tsindex 6393383c3..6b5d83ff5 100644--- a/web/src/lib/billing/ai-usage.ts+++ b/web/src/lib/billing/ai-usage.ts@@ -56,3 +56,19 @@ export function aiUsageTone(usage: AiUsage): UsageTone {if (usage.percentUsed >= 100) return 'exhausted';return usage.percentUsed >= USAGE_WARNING_RATIO * 100 ? 'warning' : 'normal';}++/** Where a browser keeps the last AI usage toast it showed: "{periodStart}:{plan}". */+export const AI_USAGE_TOAST_KEY = 'aeo:ai-usage-toast';++/** The mark a toast leaves: the period and the plan it warned about. */+export const aiUsageToastMark = (usage: AiUsage) => `${usage.periodStart}:${usage.plan}`;++/**+ * Whether a read calls for the toast (AI usage spec §4), given the mark of the+ * last one this browser showed: once a period on reaching 80%. A new period,+ * or a plan changed within it, starts over; a used-up allowance has its red+ * banner instead.+ */+export function aiUsageToastDue(usage: AiUsage, shown: string | null): boolean {+ return aiUsageTone(usage) === 'warning' && shown !== aiUsageToastMark(usage);+}