Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion internal/quotahistory/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ var antigravityTierPlans = map[string]string{
}

// antigravityPlan names the Google subscription tier. The paid tier wins over
// the current tier, as in the panel's account view.
// the current tier, as in the panel's account view. A trial ("Google AI Pro ·
// Trial") gets a "-trial" suffix: Google gives it fewer models than the paid
// plan (no Claude or GPT), so its account shows no Claude and GPT windows.
func (r *Recorder) antigravityPlan(ctx context.Context, auth *coreauth.Auth) string {
headers := bearerHeaders()
headers["User-Agent"] = misc.AntigravityUserAgent()
Expand All @@ -235,6 +237,9 @@ func parseAntigravityPlan(body []byte) string {
continue
}
if plan := antigravityTierPlans[id]; plan != "" {
if strings.Contains(strings.ToLower(firstString(tier.Get("name"))), "trial") {
return plan + "-trial"
}
return plan
}
if name := firstString(tier.Get("name")); name != "" {
Expand Down
11 changes: 6 additions & 5 deletions internal/quotahistory/providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,12 @@ func TestRecorderRetriesAnUnknownPlanOnTheNextPoll(t *testing.T) {

func TestParseAntigravityPlan(t *testing.T) {
for body, want := range map[string]string{
`{"currentTier":{"id":"free-tier"}}`: "free",
`{"paid_tier":{"id":"g1-ultra-tier"},"current_tier":{"id":"free-tier"}}`: "ultra",
`{"currentTier":{"id":"new-tier","name":"Google AI Next"}}`: "Google AI Next",
`{"currentTier":{"id":"new-tier"}}`: "new-tier",
`{}`: "",
`{"currentTier":{"id":"free-tier"}}`: "free",
`{"paid_tier":{"id":"g1-ultra-tier"},"current_tier":{"id":"free-tier"}}`: "ultra",
`{"currentTier":{"id":"new-tier","name":"Google AI Next"}}`: "Google AI Next",
`{"currentTier":{"id":"new-tier"}}`: "new-tier",
`{"paidTier":{"id":"g1-pro-tier","name":"Google AI Pro · Trial"},"currentTier":{"id":"standard-tier"}}`: "pro-trial",
`{}`: "",
} {
if got := parseAntigravityPlan([]byte(body)); got != want {
t.Fatalf("parseAntigravityPlan(%s) = %q, want %q", body, got, want)
Expand Down
6 changes: 3 additions & 3 deletions web/src/features/quota/QuotaPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import {
} from './poolModel';
import { formatPlanName, formatWeight } from './poolPrefs';
import { liveReadFor, type LiveRead } from './liveWindows';
import { windowColumns, windowLabel } from './poolWindowLabels';
import { resetColumns, windowColumns } from './poolWindowLabels';
import { formatMoney } from './poolFormat';
import { useQuotaHistory } from './hooks/useQuotaHistory';
import { usePlanWeights } from './hooks/usePlanWeights';
Expand Down Expand Up @@ -1058,8 +1058,8 @@ export function QuotaPage() {
providerLabel={providerLabel}
rows={rows}
windowColumns={columns}
primaryLabel={
orderingKey ? windowLabel(t, orderingKey, windowLabels) : undefined
resetColumns={
columns ? resetColumns(t, windows, windowLabels, orderingKey) : undefined
}
now={now}
locale={locale}
Expand Down
70 changes: 48 additions & 22 deletions web/src/features/quota/components/PoolAccountsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ export interface PoolAccountsTableProps {
rows: readonly PoolAccountRow[];
/** Window columns for providers other than Claude and Codex, shortest first. */
windowColumns?: readonly PoolWindowColumn[];
/** Label of the window the reset column follows (other providers). */
primaryLabel?: string;
/**
* Windows that get a reset column (other providers): the primary window, or
* each group's longest window when the windows split into groups.
*/
resetColumns?: readonly { key: string; label: string }[];
now: number;
locale: string;
/** Codex only: banked reset credits per auth index. */
Expand Down Expand Up @@ -133,7 +136,7 @@ export function PoolAccountsTable({
providerLabel,
rows,
windowColumns,
primaryLabel,
resetColumns,
now,
locale,
credits,
Expand Down Expand Up @@ -162,16 +165,27 @@ export function PoolAccountsTable({
const capacityOf = (row: PoolAccountRow) => (heaviest > 0 ? (100 * row.weight) / heaviest : 100);
// "Next" only means something when there is another account to pick instead.
const showNext = rows.filter((row) => !row.disabled).length > 1;
const resetLabel =
generic && primaryLabel
? t('quota_accounts.col_window_reset', { window: primaryLabel })
: t('quota_accounts.col_next_reset');
// Claude and Codex (and a provider with no reset windows): one "Next reset" column on `weekly`.
const resets =
generic && resetColumns?.length
? resetColumns.map((column) => ({
key: column.key,
label: t('quota_accounts.col_window_reset', { window: column.label }),
of: (row: PoolAccountRow) => row.windows[column.key]?.resetsAt ?? null,
}))
: [
{
key: 'next',
label: t('quota_accounts.col_next_reset'),
of: (row: PoolAccountRow) => row.weekly?.resetsAt ?? null,
},
];

const columnCount =
3 +
(generic ? windowColumns.length : 2) +
(!generic && showScoped ? 1 : 0) +
1 +
resets.length +
(showCredits ? 1 : 0);

const renderCredits = (row: PoolAccountRow) => {
Expand Down Expand Up @@ -250,15 +264,18 @@ export function PoolAccountsTable({
{!generic && showScoped && (
<TableHead className={styles.colWindow}>{labels.scoped}</TableHead>
)}
<TableHead className={styles.colReset}>{resetLabel}</TableHead>
{resets.map((column) => (
<TableHead key={column.key} className={styles.colReset}>
{column.label}
</TableHead>
))}
{showCredits && (
<TableHead className={styles.colCredits}>{t('quota_accounts.col_banked')}</TableHead>
)}
</TableRow>
</TableHeader>
<TableBody>
{rows.map((row) => {
const reset = row.weekly?.resetsAt ?? null;
const expanded = open.has(row.authIndex);
const detailId = `pool-account-${provider}-${row.authIndex}`;
return (
Expand Down Expand Up @@ -352,18 +369,27 @@ export function PoolAccountsTable({
<Meter reading={row.scopedWeekly} label={labels.scoped} locale={locale} />
</TableCell>
)}
<TableCell className={styles.reset}>
{reset === null ? (
<span className={styles.muted}>—</span>
) : (
<>
<span>
{t('quota_pool.in_duration', { duration: formatDuration(reset - now) })}
</span>
<span className={styles.muted}>{formatResetInstant(reset, now, locale)}</span>
</>
)}
</TableCell>
{resets.map((column) => {
const reset = column.of(row);
return (
<TableCell key={column.key} className={styles.reset}>
{reset === null ? (
<span className={styles.muted}>—</span>
) : (
<>
<span>
{t('quota_pool.in_duration', {
duration: formatDuration(reset - now),
})}
</span>
<span className={styles.muted}>
{formatResetInstant(reset, now, locale)}
</span>
</>
)}
</TableCell>
);
})}
{showCredits && <TableCell>{renderCredits(row)}</TableCell>}
</TableRow>
{expanded && renderDetail && (
Expand Down
4 changes: 4 additions & 0 deletions web/src/features/quota/liveWindows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ export function liveReadFor(provider: string, quota: unknown): LiveRead | null {
const groups = quota as AntigravityQuotaState;
windows = groupWindows(groups);
plan = groups.subscription?.plan ? stableKey(groups.subscription.plan) : null;
// A trial ("Google AI Pro · Trial") has fewer models than the paid plan; the recorder says "pro-trial".
if (plan && plan !== 'unknown' && /trial/i.test(groups.subscription?.tierName ?? '')) {
plan += '_trial';
}
break;
}
case 'xai': {
Expand Down
24 changes: 24 additions & 0 deletions web/src/features/quota/poolWindowLabels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,27 @@ export function windowColumns(
}))
);
}

/**
* Reset columns for a provider's windows (given longest first): the primary
* window alone (the window accounts are ordered by, else the longest), or,
* when the windows split into groups, each group's longest window ("Claude
* and GPT models weekly", "Gemini Models weekly"), since each group resets on
* its own clock.
*/
export function resetColumns(
t: Translate,
windows: readonly { key: string; periodHours?: number | null }[],
reported?: Record<string, string>,
primary?: string | null
): { key: string; label: string }[] {
const columns = windowColumns(t, windows, reported);
if (!columns.some((column) => column.group)) {
const key = windows.find((window) => window.key === primary)?.key ?? windows[0]?.key;
return key ? [{ key, label: windowLabel(t, key, reported) }] : [];
}
// Columns run shortest first within a group, so the last one seen is the group's longest.
const longest = new Map<string, WindowColumn>();
columns.forEach((column) => longest.set(column.group ?? '', column));
return [...longest.values()].map(({ key, label }) => ({ key, label }));
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ const getAntigravityPlanLabel = (
t: TFunction
): string | null => {
if (!subscription) return null;
// "Google AI Pro · Trial": the trial has fewer models than the paid plan, so keep Google's name.
if (subscription.tierName && /trial/i.test(subscription.tierName)) return subscription.tierName;
if (subscription.plan === 'free') return t('antigravity_subscription.plan_free');
if (subscription.plan === 'pro') return t('antigravity_subscription.plan_pro');
if (subscription.plan === 'ultra') return t('antigravity_subscription.plan_ultra');
Expand Down
52 changes: 52 additions & 0 deletions web/tests/quotaAccountDetail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,58 @@ describe('accounts table rows', () => {
expect(markup).not.toContain('>detail<');
});

test('grouped windows get a reset column per group', () => {
const geminiReset = NOW + 3 * 86_400_000;
const claudeReset = NOW + 17 * 60_000;
const history = normalizeQuotaHistory({
accounts: [{ auth_index: 'a1', provider: 'antigravity', label: 'ag', plan: 'pro' }],
samples: [
{
t: NOW - 60_000,
auth_index: 'a1',
windows: {
group_claude_and_gpt_models_3p_weekly: {
used_percent: 100,
resets_at: claudeReset,
period_hours: 168,
},
group_gemini_models_gemini_weekly: {
used_percent: 62,
resets_at: geminiReset,
period_hours: 168,
},
},
},
],
});
const keys = ['group_claude_and_gpt_models_3p_weekly', 'group_gemini_models_gemini_weekly'];
const agRows = buildPoolAccountRows(
history,
'antigravity',
[{ authIndex: 'a1', label: 'ag', plan: 'pro', disabled: false }],
NOW,
{ windowKeys: keys, primary: keys[0] }
);
const markup = renderToStaticMarkup(
createElement(PoolAccountsTable, {
provider: 'antigravity',
providerLabel: 'Antigravity',
rows: agRows,
windowColumns: keys.map((key) => ({ key, label: key })),
resetColumns: [
{ key: keys[0], label: 'Claude and GPT models weekly' },
{ key: keys[1], label: 'Gemini Models weekly' },
],
now: NOW,
locale: 'en',
})
);
expect(markup).toContain('Claude and GPT models weekly reset');
expect(markup).toContain('Gemini Models weekly reset');
expect(markup).toContain('in 17m');
expect(markup).toContain('in 3d');
});

test('a history-only account lists its recorded windows', () => {
const markup = renderToStaticMarkup(
createElement(HistoryAccountDetail, {
Expand Down
45 changes: 44 additions & 1 deletion web/tests/quotaLivePools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ import {
providerWindowLabels,
providerWindows,
} from '../src/features/quota/poolModel';
import { groupWindowChoices, windowColumns } from '../src/features/quota/poolWindowLabels';
import {
groupWindowChoices,
resetColumns,
windowColumns,
} from '../src/features/quota/poolWindowLabels';
import { POOL_UNITS } from '../src/features/quota/poolFormat';
import { formatPlanName } from '../src/features/quota/poolPrefs';

const NOW = Date.UTC(2026, 10, 15, 12, 0, 0);
const H = 3_600_000;
Expand Down Expand Up @@ -129,6 +134,17 @@ describe('live reads as history windows', () => {
expect(read?.windows[1].usedPercent).toBeCloseTo(27);
});

test('an Antigravity trial reads as its own plan, matching the recorder', () => {
const read = liveReadFor('antigravity', {
status: 'success',
subscription: { plan: 'pro', tierName: 'Google AI Pro · Trial', tierId: 'g1-pro-tier' },
groups: [],
});
expect(read?.plan).toBe('pro_trial');
expect(formatPlanName(read?.plan ?? null)).toBe('Pro Trial');
expect(formatPlanName('pro-trial')).toBe('Pro Trial');
});

test('xAI weekly credit usage maps to `weekly`; a monthly limit adds `monthly`', () => {
const read = liveReadFor('xai', {
status: 'success',
Expand Down Expand Up @@ -295,6 +311,33 @@ describe('owner pool fixture', () => {
['Claude and GPT models', '5-hour'],
['Claude and GPT models', 'Weekly'],
]);
// Each group resets on its own clock, so each gets a reset column.
expect(resetColumns(t, providerWindows(history, 'antigravity'), labels)).toEqual([
{ key: 'group_gemini_models_gemini_weekly', label: 'Gemini Models weekly' },
{ key: 'group_claude_and_gpt_models_3p_weekly', label: 'Claude and GPT models weekly' },
]);
});

test('ungrouped windows keep one reset column on the primary window', () => {
expect(
resetColumns(t, [
{ key: 'monthly', periodHours: 720 },
{ key: 'five_hour', periodHours: 5 },
])
).toEqual([{ key: 'monthly', label: 'Monthly' }]);
// The window accounts are ordered by wins over the longest one.
expect(
resetColumns(
t,
[
{ key: 'monthly', periodHours: 720 },
{ key: 'five_hour', periodHours: 5 },
],
undefined,
'five_hour'
)
).toEqual([{ key: 'five_hour', label: '5-hour' }]);
expect(resetColumns(t, [])).toEqual([]);
});

test('xAI with one unlabelled weekly window offers no switcher', () => {
Expand Down