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
fix(billing): read the AI usage share as it is, to a tenth (#1513)
Cihan3b034aebee8f
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsxindex 90c395a60..a2cf1bb1b 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/editor/[draftId]/page.test.tsx@@ -409,7 +409,7 @@ describe('the content editor', () => {await act(async () => {});expect(readDraftAiUsage).toHaveBeenCalledWith('d1');expect(document.querySelector('[data-slot="popover-content"]')!.textContent).toContain(- 'This page this month3%',+ 'This page this month3.7%',);});diff --git a/web/src/components/ai-usage/ai-usage-banner.test.tsx b/web/src/components/ai-usage/ai-usage-banner.test.tsxindex 344ae4371..4df56b257 100644--- a/web/src/components/ai-usage/ai-usage-banner.test.tsx+++ b/web/src/components/ai-usage/ai-usage-banner.test.tsx@@ -91,7 +91,7 @@ describe('AiUsageBanner', () => {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.textContent).toContain("You've used 84.6% 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']]);@@ -114,7 +114,7 @@ describe('AiUsageBanner', () => {state.usage = usage({ trial: true });await render();expect(container.textContent).toContain(- "You've used 84% of the free trial's AI usage. Starting the plan gives its full monthly allowance.",+ "You've used 84.6% of the free trial's AI usage. Starting the plan gives its full monthly allowance.",);state.usage = usage({ trial: true, percentUsed: 100 });diff --git a/web/src/components/ai-usage/ai-usage-meter.test.tsx b/web/src/components/ai-usage/ai-usage-meter.test.tsxindex a14266c93..8c889b53d 100644--- a/web/src/components/ai-usage/ai-usage-meter.test.tsx+++ b/web/src/components/ai-usage/ai-usage-meter.test.tsx@@ -145,8 +145,8 @@ describe('AiUsageMeter', () => {it('shows the month’s share with a bar, named with what it shows', async () => {await render();const button = trigger()!;- expect(button.textContent).toBe('AI21%');- expect(button.getAttribute('aria-label')).toBe('AI 21% used this month');+ expect(button.textContent).toBe('AI21.4%');+ expect(button.getAttribute('aria-label')).toBe('AI 21.4% used this month');expect(button.className).toContain('text-foreground');expect(button.querySelector<HTMLElement>('[style]')!.style.width).toBe('21.4%');});@@ -208,8 +208,8 @@ describe('AiUsageMeter', () => {const rows = [...popup()!.querySelectorAll('li')].map((li) => li.textContent);expect(rows).toEqual(['Improve suggestions4%',- 'Content Editor (briefs, Content Agent)17%',- 'Action Center task writing<1%',+ 'Content Editor (briefs, Content Agent)17.2%',+ 'Action Center task writing0.2%','Agent Chat, on your own AI keyNot counted','Site Audit pages42 of 500','Prompt locations1,148 of 2,000',@@ -311,7 +311,7 @@ describe('AiUsageMeter in the Content Editor', () => {const [label, bar] = trigger()!.querySelectorAll('span');expect(label.className).toContain('hidden xl:inline');expect(bar.className).toContain('hidden xl:block');- expect(trigger()!.title).toBe('AI 21% used this month');+ expect(trigger()!.title).toBe('AI 21.4% used this month');});it('adds the page’s share of the month, read on each opening', async () => {@@ -322,13 +322,14 @@ describe('AiUsageMeter in the Content Editor', () => {expect(readDraftAiUsage).toHaveBeenCalledWith('d1');expect(page()!.textContent).toBe('This page this monthLoading...');await act(async () => answer(3.7));- expect(page()!.textContent).toBe('This page this month3%');+ // Under 10%, to a tenth: a few runs show.+ expect(page()!.textContent).toBe('This page this month3.7%');- // A sliver reads as under 1%; one it can't read is left out.+ // A sliver under a tenth still reads as used; one it can't read is left out.await act(async () => trigger()!.click());- vi.mocked(readDraftAiUsage).mockResolvedValue(0.1);+ vi.mocked(readDraftAiUsage).mockResolvedValue(0.04);await open();- expect(page()!.textContent).toBe('This page this month<1%');+ expect(page()!.textContent).toBe('This page this month<0.1%');await act(async () => trigger()!.click());vi.mocked(readDraftAiUsage).mockResolvedValue(null);await open();@@ -497,7 +498,7 @@ describe('AiUsageProvider', () => {await act(async () => window.dispatchEvent(new Event('focus')));await act(async () => {});expect(readAiUsage).toHaveBeenCalledTimes(2);- expect(trigger()!.textContent).toBe('AI21%');+ expect(trigger()!.textContent).toBe('AI21.4%');});it('reads again when the tab becomes visible, not while it is hidden', async () => {diff --git a/web/src/components/ai-usage/ai-usage-meter.tsx b/web/src/components/ai-usage/ai-usage-meter.tsxindex 294d33a66..cd6261ddb 100644--- a/web/src/components/ai-usage/ai-usage-meter.tsx+++ b/web/src/components/ai-usage/ai-usage-meter.tsx@@ -118,7 +118,7 @@ export function AiUsageMeter({aria-hiddenclassName={cn('hidden shrink-0 sm:inline-block',- compact ? 'h-7 w-12 xl:w-[7.5rem]' : 'h-8 w-[7.75rem]',+ compact ? 'h-7 w-[3.625rem] xl:w-[8.25rem]' : 'h-8 w-[8.5rem]',className,)}/>@@ -181,7 +181,8 @@ export function AiUsageMeter({><span className={cn('block h-full rounded-full', FILL_CLASS[tone])} style={{ width }} /></span>- <span aria-hidden className="tabular-nums">+ {/* As wide as "99.9%": the button keeps its width as the tenths move. */}+ <span aria-hidden className="inline-block min-w-9 text-right tabular-nums">{used}</span></PopoverTrigger>diff --git a/web/src/components/settings/ai-usage-card.test.tsx b/web/src/components/settings/ai-usage-card.test.tsxindex 0f6ca2ca6..d005e58e3 100644--- a/web/src/components/settings/ai-usage-card.test.tsx+++ b/web/src/components/settings/ai-usage-card.test.tsx@@ -62,17 +62,17 @@ describe('AiUsageCard', () => {await render();const text = container.textContent;expect(text).toContain("This period's AI usage");- expect(text).toContain('42% used');+ expect(text).toContain('42.5% used');expect(text).toContain('Resets on November 20, 2026');expect([...container.querySelectorAll('li')].map((li) => li.textContent)).toEqual([- 'Improve suggestions12%',+ 'Improve suggestions12.5%','Content Editor (briefs, Content Agent)30%',- 'Action Center task writing<1%',+ 'Action Center task writing0.4%',]);expect(text).toContain("Agent Chat runs on your own AI key, so it doesn't use this allowance.");const bar = container.querySelector('[role="progressbar"]')!;expect(bar.getAttribute('aria-valuenow')).toBe('42');- expect(bar.getAttribute('aria-valuetext')).toBe('42% used');+ expect(bar.getAttribute('aria-valuetext')).toBe('42.5% used');expect((bar.firstElementChild as HTMLElement).style.width).toBe('42.5%');expect(text).not.toContain('used up');});@@ -148,12 +148,20 @@ describe('AiUsageCard', () => {});describe('the meter’s reading', () => {- it('reads a sliver as under 1%, else whole percents, rounded down', () => {+ it('reads the share as it is now, to a tenth, rounded down', () => {expect(percentLabel(0)).toBe('0%');- expect(percentLabel(0.4)).toBe('<1%');- expect(percentLabel(12.5)).toBe('12%');+ // A sliver still reads as used.+ expect(percentLabel(0.04)).toBe('<0.1%');+ expect(percentLabel(0.4)).toBe('0.4%');+ // Each run shows: 1.1, 1.2, … rather than 1% until it's 2%.+ expect(percentLabel(1.1)).toBe('1.1%');+ expect(percentLabel(2.3)).toBe('2.3%');+ expect(percentLabel(4.9)).toBe('4.9%');+ expect(percentLabel(28)).toBe('28%');+ expect(percentLabel(28.3)).toBe('28.3%');// Never all of it before it is.- expect(percentLabel(99.9)).toBe('99%');+ expect(percentLabel(99.9)).toBe('99.9%');+ expect(percentLabel(99.96)).toBe('99.9%');expect(percentLabel(100)).toBe('100%');});diff --git a/web/src/lib/billing/ai-usage.ts b/web/src/lib/billing/ai-usage.tsindex d73228e4b..6133bcddb 100644--- a/web/src/lib/billing/ai-usage.ts+++ b/web/src/lib/billing/ai-usage.ts@@ -50,13 +50,15 @@ export interface UsageLimits {}/**- * A share as it reads: a sliver as "<1%", else whole percents, rounded down- * so nothing reads as all of it before it is (the server sends 100 only- * once the allowance is spent).+ * A share as it is now, to the tenth the server sends ("1.1%", "28.3%",+ * "99.9%"; "28%" when whole), so each run shows; a sliver under a tenth+ * as "<0.1%". Rounded down, so nothing reads as all of it before it is+ * (the server sends 100 only once the allowance is spent).*/export function percentLabel(percent: number): string {- if (percent > 0 && percent < 1) return '<1%';- return `${Math.floor(percent)}%`;+ if (percent > 0 && percent < 0.1) return '<0.1%';+ // The tiny nudge keeps a tenth the server sent (2.3 × 10) from flooring below it.+ return `${Math.floor(percent * 10 + 1e-9) / 10}%`;}/** Warning from 80% of the allowance, used up at 100%. */