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): say in the free trial that starting the plan gives more AI usage, on the meter and banners (AI usage display, part 6) (#1436)
Cihand632ae4d09b6
diff --git a/web/messages/en.json b/web/messages/en.jsonindex 8e426f2bc..f8a529e7d 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -22,16 +22,19 @@"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"+ "ownKey": "Use your own key",+ "startPlan": "Start your plan"},"popover": {"title": "AI usage this month · {plan} plan",+ "titleTrial": "AI usage this month · {plan} free trial","titleNoPlan": "AI usage this month","page": "This page this month","shared": "Shared by every seat · resets {date}","sharedNoDate": "Shared by every seat","exhausted": "Used up. AI features stop until {date}; Agent Chat on your own AI key keeps working.","exhaustedNoDate": "Used up. AI features stop until it resets; Agent Chat on your own AI key keeps working.",+ "exhaustedTrial": "The free trial's AI usage is used up. Starting the plan gives its full monthly allowance; Agent Chat on your own AI key keeps working.","ownKey": "Agent Chat, on your own AI key","notCounted": "Not counted","otherLimits": "Other limits this month",@@ -42,9 +45,11 @@},"banner": {"warning": "You've used {percent} of this month's AI limit.",+ "warningTrial": "You've used {percent} of the free trial's AI usage. Starting the plan gives its full monthly allowance.","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."+ "exhaustedNoDate": "You've used this month's AI limit. AI features stop until it resets; Agent Chat on your own AI key keeps working.",+ "exhaustedTrial": "You've used the free trial's AI usage. Starting the plan gives its full monthly allowance; 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.tsxindex 3ab5eec3e..344ae4371 100644--- a/web/src/components/ai-usage/ai-usage-banner.test.tsx+++ b/web/src/components/ai-usage/ai-usage-banner.test.tsx@@ -110,6 +110,30 @@ describe('AiUsageBanner', () => {]);});+ it('says in the free trial that starting the plan gives more, also when used up', async () => {+ 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.",+ );++ state.usage = usage({ trial: true, percentUsed: 100 });+ await render();+ expect(container.textContent).toContain(+ "You've used the free trial's AI usage. Starting the plan gives its full monthly allowance;",+ );+ expect(links()).toEqual([+ ['Start your plan', '/dashboard/settings/billing'],+ ['Use your own key', '/dashboard/settings/ai-providers'],+ ]);+ expect(container.textContent).not.toContain('Get more AI usage');++ // A member who isn't an admin can't start it: asked to ask one, no links.+ await render('analyst');+ expect(container.textContent).toContain('ask an admin of your workspace');+ expect(links()).toEqual([]);+ });+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();diff --git a/web/src/components/ai-usage/ai-usage-banner.tsx b/web/src/components/ai-usage/ai-usage-banner.tsxindex cfb7a289e..f0db38c1d 100644--- a/web/src/components/ai-usage/ai-usage-banner.tsx+++ b/web/src/components/ai-usage/ai-usage-banner.tsx@@ -36,7 +36,9 @@ export function AiUsageBanner({ className }: { className?: string }) {><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) })}+ {t(usage.trial ? 'banner.warningTrial' : 'banner.warning', {+ percent: percentLabel(usage.percentUsed ?? 0),+ })}</p><Linkhref="/dashboard/settings/billing#ai-usage"@@ -58,12 +60,16 @@ export function AiUsageBanner({ className }: { className?: string }) {><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')}+ {usage.trial+ ? t('banner.exhaustedTrial')+ : 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 />+ <AiUsageGetMore plan={usage.plan} trial={usage.trial} 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.tsxindex de0dbbc5a..88ab52b0a 100644--- a/web/src/components/ai-usage/ai-usage-get-more.tsx+++ b/web/src/components/ai-usage/ai-usage-get-more.tsx@@ -9,15 +9,18 @@ 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.+ * one). Enterprise has no bigger plan to move to. In the free trial, more+ * comes with starting the plan, so the link says so. `primary` makes the+ * plan link the area's one black button.*/export function AiUsageGetMore({plan,+ trial = false,primary,onFollow,}: {plan: string;+ trial?: boolean;primary: boolean;/** When a link is followed: the popover closes. */onFollow?: () => void;@@ -27,13 +30,13 @@ export function AiUsageGetMore({if (!canAdmin) return null;return (<>- {plan !== 'enterprise' && (+ {(trial || plan !== 'enterprise') && (<Linkhref="/dashboard/settings/billing"onClick={onFollow}className={buttonVariants({ variant: primary ? 'default' : 'outline', size: 'sm' })}>- {t('plan')}+ {trial ? t('startPlan') : t('plan')}</Link>)}<Linkdiff --git a/web/src/components/ai-usage/ai-usage-meter.test.tsx b/web/src/components/ai-usage/ai-usage-meter.test.tsxindex 8be147861..08eaf8c6a 100644--- a/web/src/components/ai-usage/ai-usage-meter.test.tsx+++ b/web/src/components/ai-usage/ai-usage-meter.test.tsx@@ -250,6 +250,18 @@ describe('AiUsageMeter', () => {expect(popup()!.textContent).not.toContain('Get more AI usage');});+ it('names the free trial, and says starting the plan gives more once it’s used up', async () => {+ vi.mocked(readAiUsage).mockResolvedValue(usage({ trial: true, percentUsed: 100 }));+ await render();+ await open();+ expect(popup()!.textContent).toContain('AI usage this month · Growth free trial');+ expect(popup()!.textContent).toContain(+ "The free trial's AI usage is used up. Starting the plan gives its full monthly allowance;",+ );+ expect(links()[0]).toEqual(['Start your plan', '/dashboard/settings/billing']);+ expect(popup()!.textContent).not.toContain('Get more AI usage');+ });+it('tells a member who isn’t an admin to ask one, instead of the admin’s links', async () => {await render('manager');await open();@@ -391,6 +403,17 @@ describe('AiUsageProvider', () => {expect(toast.warning).toHaveBeenCalledTimes(2);});+ it('toasts the free trial’s warning in its own words', async () => {+ vi.mocked(readAiUsage).mockResolvedValue(usage({ trial: true, percentUsed: 84 }));+ await render();+ expect(toast.warning).toHaveBeenCalledExactlyOnceWith(+ "You've used 84% of the free trial's AI usage. Starting the plan gives its full monthly allowance.",+ );+ expect(localStorage.getItem('aeo:ai-usage-toast')).toBe(+ '2026-10-20T09:00:00.000Z:growth:trial',+ );+ });+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();diff --git a/web/src/components/ai-usage/ai-usage-meter.tsx b/web/src/components/ai-usage/ai-usage-meter.tsxindex c44485c90..098dd25f7 100644--- a/web/src/components/ai-usage/ai-usage-meter.tsx+++ b/web/src/components/ai-usage/ai-usage-meter.tsx@@ -177,7 +177,9 @@ export function AiUsageMeter({</PopoverTrigger><PopoverContent align="end" className="w-80 max-w-[calc(100vw-2rem)] text-sm"><PopoverTitle className="text-xs font-normal text-muted-foreground">- {usage.planName ? t('popover.title', { plan: usage.planName }) : t('popover.titleNoPlan')}+ {usage.planName+ ? t(usage.trial ? 'popover.titleTrial' : 'popover.title', { plan: usage.planName })+ : t('popover.titleNoPlan')}</PopoverTitle><p className="mt-0.5 text-2xl font-semibold tabular-nums">{used}</p><div@@ -210,7 +212,11 @@ export function AiUsageMeter({)}{tone === 'exhausted' && (<p className="mt-2 text-xs text-red-700 dark:text-red-400">- {resets ? t('popover.exhausted', { date: resets }) : t('popover.exhaustedNoDate')}+ {usage.trial+ ? t('popover.exhaustedTrial')+ : resets+ ? t('popover.exhausted', { date: resets })+ : t('popover.exhaustedNoDate')}</p>)}@@ -264,7 +270,12 @@ export function AiUsageMeter({{!canAdmin && <p className="mt-3 text-xs text-muted-foreground">{t('askAdmin')}</p>}<div className="mt-4 flex flex-wrap gap-1.5">- <AiUsageGetMore plan={usage.plan} primary={pressing} onFollow={close} />+ <AiUsageGetMore+ plan={usage.plan}+ trial={usage.trial}+ 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 5a2e01e9c..4e20def8e 100644--- a/web/src/components/providers/ai-usage-provider.tsx+++ b/web/src/components/providers/ai-usage-provider.tsx@@ -104,7 +104,11 @@ export function AiUsageProvider({ children }: { children: ReactNode }) {} catch {// As above.}- toast.warning(t('warning', { percent: percentLabel(usage.percentUsed ?? 0) }));+ toast.warning(+ t(usage.trial ? 'warningTrial' : 'warning', {+ percent: percentLabel(usage.percentUsed ?? 0),+ }),+ );}, [usage, t]);const refresh = useCallback(() => void read(), [read]);diff --git a/web/src/lib/billing/ai-usage.test.ts b/web/src/lib/billing/ai-usage.test.tsindex 9ff4595f9..a3cee4c16 100644--- a/web/src/lib/billing/ai-usage.test.ts+++ b/web/src/lib/billing/ai-usage.test.ts@@ -25,6 +25,11 @@ describe('aiUsageToastDue', () => {expect(aiUsageToastDue(usage({ percentUsed: 91 }), shown)).toBe(false);});+ it('marks the free trial apart, so a plan started within its period warns again', () => {+ expect(aiUsageToastMark(usage({ trial: true }))).toBe(`${shown}:trial`);+ expect(aiUsageToastDue(usage(), `${shown}:trial`)).toBe(true);+ });+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);diff --git a/web/src/lib/billing/ai-usage.ts b/web/src/lib/billing/ai-usage.tsindex 6b5d83ff5..74940efdf 100644--- a/web/src/lib/billing/ai-usage.ts+++ b/web/src/lib/billing/ai-usage.ts@@ -15,6 +15,8 @@ export type AiUsageFeature = (typeof AI_USAGE_FEATURES)[number];export interface AiUsage {plan: string;planName: string | null;+ /** The free trial's smaller allowance: more comes with starting the plan. */+ trial?: boolean;periodStart: string | null;periodEnd: string | null;/** No allowance to meter (self-hosted, or a plan without one). */@@ -57,11 +59,15 @@ export function aiUsageTone(usage: AiUsage): UsageTone {return usage.percentUsed >= USAGE_WARNING_RATIO * 100 ? 'warning' : 'normal';}-/** Where a browser keeps the last AI usage toast it showed: "{periodStart}:{plan}". */+/** Where a browser keeps the last AI usage toast it showed: "{periodStart}:{plan}", ":trial" in the free trial. */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}`;+/**+ * The mark a toast leaves: the period and the plan it warned about, and the+ * free trial's apart, so a plan started within the trial's period warns again.+ */+export const aiUsageToastMark = (usage: AiUsage) =>+ `${usage.periodStart}:${usage.plan}${usage.trial ? ':trial' : ''}`;/*** Whether a read calls for the toast (AI usage spec §4), given the mark of the