diff --git a/apps/mobile/src/features/usage/UsageLimitsPooled.tsx b/apps/mobile/src/features/usage/UsageLimitsPooled.tsx index 96d8f922340f7..db0f05e23019f 100644 --- a/apps/mobile/src/features/usage/UsageLimitsPooled.tsx +++ b/apps/mobile/src/features/usage/UsageLimitsPooled.tsx @@ -16,6 +16,7 @@ import { collectExternalUsageLinks, collectLimitNotices, cursorUsageWindowDetails, + poolCheckedLabel, } from "@t3tools/shared/usageLimitsCopy"; import { msg, T, useGT, useMessages, Var } from "gt-react-native"; import { Fragment, type ReactNode, useId, useState } from "react"; @@ -501,6 +502,7 @@ export function UsageLimitsSection({ ) : null} {pools.map((pool) => { const windows = displayLimitWindows(pool); + const checked = poolCheckedLabel(pool, now, m); return ( @@ -509,6 +511,11 @@ export function UsageLimitsSection({ {providerClients.get(pool.driver)?.label ?? pool.driver} + {checked ? ( + + {checked} + + ) : null} {windows.map((window) => { const details = diff --git a/apps/mobile/src/i18n/translations/de.json b/apps/mobile/src/i18n/translations/de.json index 2fc89b4d1171d..7da71c2ba5434 100644 --- a/apps/mobile/src/i18n/translations/de.json +++ b/apps/mobile/src/i18n/translations/de.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "Keine Limits gemeldet.", "e27d2cb964df5dd5": "{source}: Keine Konten gemeldet.", "1b503134018285f4": "{days} T. {hours} Std.", + "1b316942cffcbb5f": "gerade geprüft", + "57b04d7ee40cfb03": "vor {duration} geprüft", "164c674cf062933a": "{label} · noch {count} · läuft ab in {expires}", "9c82c39589c23938": "{label} · noch {count}", "ea4eaa756c937d3a": "Einlösen", diff --git a/apps/mobile/src/i18n/translations/en.json b/apps/mobile/src/i18n/translations/en.json index 4e6ca74ec9ac9..6c552a91896c3 100644 --- a/apps/mobile/src/i18n/translations/en.json +++ b/apps/mobile/src/i18n/translations/en.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "No limits reported.", "e27d2cb964df5dd5": "{source}: No accounts reported.", "1b503134018285f4": "{days}d {hours}h", + "1b316942cffcbb5f": "checked just now", + "57b04d7ee40cfb03": "checked {duration} ago", "164c674cf062933a": "{label} · {count} left · expires in {expires}", "9c82c39589c23938": "{label} · {count} left", "ea4eaa756c937d3a": "Use", diff --git a/apps/mobile/src/i18n/translations/es.json b/apps/mobile/src/i18n/translations/es.json index 410b8bd0891a9..e0aadd76a6b73 100644 --- a/apps/mobile/src/i18n/translations/es.json +++ b/apps/mobile/src/i18n/translations/es.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "No se informaron límites.", "e27d2cb964df5dd5": "{source}: no se informaron cuentas.", "1b503134018285f4": "{days} d {hours} h", + "1b316942cffcbb5f": "comprobado ahora mismo", + "57b04d7ee40cfb03": "comprobado hace {duration}", "164c674cf062933a": "{label} · quedan {count} · caduca en {expires}", "9c82c39589c23938": "{label} · quedan {count}", "ea4eaa756c937d3a": "Usar", diff --git a/apps/mobile/src/i18n/translations/fr.json b/apps/mobile/src/i18n/translations/fr.json index 1eb1bfe555fbd..bc24d01f337c9 100644 --- a/apps/mobile/src/i18n/translations/fr.json +++ b/apps/mobile/src/i18n/translations/fr.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "Aucune limite signalée.", "e27d2cb964df5dd5": "{source} : aucun compte signalé.", "1b503134018285f4": "{days} j {hours} h", + "1b316942cffcbb5f": "vérifié à l'instant", + "57b04d7ee40cfb03": "vérifié il y a {duration}", "164c674cf062933a": "{label} · {count} restants · expire dans {expires}", "9c82c39589c23938": "{label} · {count} restants", "ea4eaa756c937d3a": "Utiliser", diff --git a/apps/mobile/src/i18n/translations/ja.json b/apps/mobile/src/i18n/translations/ja.json index bca3f5cd07f1e..d69eddf77045a 100644 --- a/apps/mobile/src/i18n/translations/ja.json +++ b/apps/mobile/src/i18n/translations/ja.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "報告された上限はありません。", "e27d2cb964df5dd5": "{source}: 報告されたアカウントはありません。", "1b503134018285f4": "{days}日{hours}時間", + "1b316942cffcbb5f": "たった今確認", + "57b04d7ee40cfb03": "{duration}前に確認", "164c674cf062933a": "{label} · 残り {count} · {expires}後に期限切れ", "9c82c39589c23938": "{label} · 残り {count}", "ea4eaa756c937d3a": "使用", diff --git a/apps/mobile/src/i18n/translations/ko.json b/apps/mobile/src/i18n/translations/ko.json index 8b1c9c3051e1a..ab802ab736888 100644 --- a/apps/mobile/src/i18n/translations/ko.json +++ b/apps/mobile/src/i18n/translations/ko.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "보고된 한도가 없습니다.", "e27d2cb964df5dd5": "{source}: 보고된 계정이 없습니다.", "1b503134018285f4": "{days}일 {hours}시간", + "1b316942cffcbb5f": "방금 확인함", + "57b04d7ee40cfb03": "{duration} 전에 확인함", "164c674cf062933a": "{label} · {count}개 남음 · {expires} 후 만료", "9c82c39589c23938": "{label} · {count}개 남음", "ea4eaa756c937d3a": "사용", diff --git a/apps/mobile/src/i18n/translations/pt-BR.json b/apps/mobile/src/i18n/translations/pt-BR.json index b027677a9cc33..678b8c48ef60e 100644 --- a/apps/mobile/src/i18n/translations/pt-BR.json +++ b/apps/mobile/src/i18n/translations/pt-BR.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "Nenhum limite informado.", "e27d2cb964df5dd5": "{source}: nenhuma conta informada.", "1b503134018285f4": "{days}d {hours}h", + "1b316942cffcbb5f": "verificado agora mesmo", + "57b04d7ee40cfb03": "verificado há {duration}", "164c674cf062933a": "{label} · {count} restantes · expira em {expires}", "9c82c39589c23938": "{label} · {count} restantes", "ea4eaa756c937d3a": "Usar", diff --git a/apps/mobile/src/i18n/translations/ru.json b/apps/mobile/src/i18n/translations/ru.json index 5566d68d101e4..1fe3c063ed6fc 100644 --- a/apps/mobile/src/i18n/translations/ru.json +++ b/apps/mobile/src/i18n/translations/ru.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "Лимиты не сообщаются.", "e27d2cb964df5dd5": "{source}: аккаунты не найдены.", "1b503134018285f4": "{days} д {hours} ч", + "1b316942cffcbb5f": "проверено только что", + "57b04d7ee40cfb03": "проверено {duration} назад", "164c674cf062933a": "{label} · осталось {count} · истекает через {expires}", "9c82c39589c23938": "{label} · осталось {count}", "ea4eaa756c937d3a": "Использовать", diff --git a/apps/mobile/src/i18n/translations/sv.json b/apps/mobile/src/i18n/translations/sv.json index 352d805285e15..04045130f9269 100644 --- a/apps/mobile/src/i18n/translations/sv.json +++ b/apps/mobile/src/i18n/translations/sv.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "Inga gränser rapporterades.", "e27d2cb964df5dd5": "{source}: inga konton rapporterades.", "1b503134018285f4": "{days} d {hours} h", + "1b316942cffcbb5f": "kontrollerat nyss", + "57b04d7ee40cfb03": "kontrollerat för {duration} sedan", "164c674cf062933a": "{label} · {count} kvar · går ut om {expires}", "9c82c39589c23938": "{label} · {count} kvar", "ea4eaa756c937d3a": "Använd", diff --git a/apps/mobile/src/i18n/translations/zh.json b/apps/mobile/src/i18n/translations/zh.json index df184643184f5..4c7d71389f02a 100644 --- a/apps/mobile/src/i18n/translations/zh.json +++ b/apps/mobile/src/i18n/translations/zh.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "没有报告限额。", "e27d2cb964df5dd5": "{source}:未报告任何账户。", "1b503134018285f4": "{days} 天 {hours} 小时", + "1b316942cffcbb5f": "刚刚检查", + "57b04d7ee40cfb03": "{duration}前检查", "164c674cf062933a": "{label} · 剩余 {count} 个 · {expires} 后过期", "9c82c39589c23938": "{label} · 剩余 {count} 次", "ea4eaa756c937d3a": "使用", diff --git a/apps/server/src/provider/AntigravityProvider.test.ts b/apps/server/src/provider/AntigravityProvider.test.ts index 522be29a8b187..f5c0c11d1b1e3 100644 --- a/apps/server/src/provider/AntigravityProvider.test.ts +++ b/apps/server/src/provider/AntigravityProvider.test.ts @@ -735,6 +735,17 @@ it.layer(layerTest)("Antigravity provider snapshots", (it) => { const published = yield* harness.nextPublish((snapshot) => !!snapshot.usageLimits); yield* harness.initialize; expect((yield* published)?.usageLimits).toEqual(limits); + // A new session renews the CLI sign-in, so its start re-reads quota. + const renewed: ServerProviderUsageLimits = { + checkedAt: "2026-10-09T12:00:30.000Z", + windows: [{ ...limits.windows[0]!, usedPercent: 50 }], + }; + yield* Ref.set(usage, renewed); + const republishedAfterSession = yield* harness.nextPublish( + (snapshot) => snapshot.usageLimits?.checkedAt === renewed.checkedAt, + ); + yield* harness.provider.onSessionStarted(started); + expect((yield* republishedAfterSession)?.usageLimits).toEqual(renewed); // The second health check is the one the failed background read triggers. const checks = yield* Ref.make(0); const failedReadApplied = yield* Deferred.make(); @@ -754,7 +765,7 @@ it.layer(layerTest)("Antigravity provider snapshots", (it) => { }); yield* harness.provider.snapshot.refresh; yield* Deferred.await(failedReadApplied); - expect((yield* harness.provider.snapshot.getSnapshot).usageLimits).toEqual(limits); + expect((yield* harness.provider.snapshot.getSnapshot).usageLimits).toEqual(renewed); yield* harness.provider.onSignedOut; expect((yield* harness.provider.snapshot.getSnapshot).usageLimits).toBeUndefined(); yield* Ref.set(usage, { @@ -796,26 +807,80 @@ it.layer(layerTest)("Antigravity provider snapshots", (it) => { }), ); - it.effect("reports ready and starts sessions while one shared quota read is pending", () => + it.effect("a session start rejected by an auth-required clear does not restore quota", () => + Effect.gen(function* () { + const limits: ServerProviderUsageLimits = { + checkedAt: "2026-10-09T12:00:00.000Z", + windows: [{ id: "gemini-5h", kind: "session", label: "Gemini · 5-hour", usedPercent: 10 }], + }; + const usage = yield* Ref.make(limits); + const harness = yield* makeHarness({ probeUsage: Ref.get(usage) }); + const published = yield* harness.nextPublish((snapshot) => !!snapshot.usageLimits); + yield* harness.initialize; + expect((yield* published)?.usageLimits).toEqual(limits); + // Hold the session start at its capability check, clear the account, then let it finish. + const atGate = yield* Deferred.make(); + const gate = yield* Deferred.make(); + yield* Ref.set( + harness.safety, + Deferred.succeed(atGate, undefined).pipe( + Effect.andThen(Deferred.await(gate)), + Effect.as(true), + ), + ); + const sessionStart = yield* harness.provider.onSessionStarted(started).pipe(Effect.forkChild); + yield* Deferred.await(atGate); + yield* harness.provider.onAuthRequired; + expect((yield* harness.provider.snapshot.getSnapshot).usageLimits).toBeUndefined(); + // The second health check is the one the post-clear background read triggers. + const checks = yield* Ref.make(0); + const readApplied = yield* Deferred.make(); + yield* Ref.set( + harness.probe, + Ref.updateAndGet(checks, (count) => count + 1).pipe( + Effect.tap((count) => + count === 2 ? Deferred.succeed(readApplied, undefined) : Effect.void, + ), + Effect.as(initializeResult), + ), + ); + yield* Deferred.succeed(gate, undefined); + yield* Fiber.join(sessionStart); + yield* harness.provider.snapshot.refresh; + yield* Deferred.await(readApplied); + const snapshot = yield* harness.provider.snapshot.getSnapshot; + expect(snapshot.usageLimits).toBeUndefined(); + expect(snapshot.auth.status).toBe("unauthenticated"); + }), + ); + + it.effect("reports ready while session starts restart a pending quota read", () => Effect.gen(function* () { const reads = yield* Ref.make(0); - const readStarted = yield* Deferred.make(); + const readStarted = [ + yield* Deferred.make(), + yield* Deferred.make(), + yield* Deferred.make(), + ]; const readResult = yield* Deferred.make(); const harness = yield* makeHarness({ - probeUsage: Ref.update(reads, (count) => count + 1).pipe( - Effect.andThen(Deferred.succeed(readStarted, undefined)), + probeUsage: Ref.updateAndGet(reads, (count) => count + 1).pipe( + Effect.tap((count) => Deferred.succeed(readStarted[count - 1]!, undefined)), Effect.andThen(Deferred.await(readResult)), ), }); const published = yield* harness.nextPublish((snapshot) => !!snapshot.usageLimits); yield* harness.initialize; - yield* Deferred.await(readStarted); + yield* Deferred.await(readStarted[0]!); yield* harness.provider.onSessionStarted(started, "/workspace"); + yield* Deferred.await(readStarted[1]!); yield* harness.provider.onSessionStarted(started, "/other"); + yield* Deferred.await(readStarted[2]!); const ready = yield* harness.provider.snapshot.getSnapshot; expect(ready).toMatchObject({ status: "ready", auth: { status: "authenticated" } }); expect(ready.usageLimits).toBeUndefined(); - expect(yield* Ref.get(reads)).toBe(1); + // Each session start replaces the read that predates its renewed sign-in. + expect(yield* Ref.get(reads)).toBe(3); const limits = { checkedAt: "2026-10-09T12:00:00.000Z", windows: [{ id: "gemini-5h", kind: "session", label: "Gemini · 5-hour", usedPercent: 10 }], diff --git a/apps/server/src/provider/AntigravityProvider.ts b/apps/server/src/provider/AntigravityProvider.ts index b3b68d46e8ba8..a9718e463589a 100644 --- a/apps/server/src/provider/AntigravityProvider.ts +++ b/apps/server/src/provider/AntigravityProvider.ts @@ -255,22 +255,30 @@ export const makeAntigravityProvider = Effect.fn("makeAntigravityProvider")(func const usageRead = yield* FiberHandle.make(); const republish = yield* Deferred.make>(); const scope = yield* Effect.scope; - const refreshUsage = Effect.fn("AntigravityProvider.refreshUsage")(function* () { + // A restart interrupts a read that started before the CLI sign-in was renewed. + const refreshUsage = Effect.fn("AntigravityProvider.refreshUsage")(function* (refreshOptions?: { + readonly restart?: boolean; + }) { if (!options.probeUsage || (yield* PublishingUsage)) return; yield* FiberHandle.run( usageRead, options.probeUsage.pipe( Effect.flatMap((probed) => - SubscriptionRef.update(metadata, (state) => ({ - ...state, - draft: { - ...state.draft, - usageLimits: resolveUsageLimitsAfterProbe({ - published: state.draft.usageLimits, - probed, - }), - }, - })), + SubscriptionRef.update(metadata, (state) => + // A cleared account must not get quota back from a read that outlived the clear. + state.draft.auth.status === "unauthenticated" + ? state + : { + ...state, + draft: { + ...state.draft, + usageLimits: resolveUsageLimitsAfterProbe({ + published: state.draft.usageLimits, + probed, + }), + }, + }, + ), ), // Enrichment cannot change published limits; a health check publishes them. Effect.andThen( @@ -283,7 +291,7 @@ export const makeAntigravityProvider = Effect.fn("makeAntigravityProvider")(func ), ), // Store the fiber before it runs, so a sign-out during the read can interrupt it. - { onlyIfMissing: true, startImmediately: false }, + { onlyIfMissing: refreshOptions?.restart !== true, startImmediately: false }, ); }); const resetUsage = Effect.gen(function* () { @@ -442,7 +450,9 @@ export const makeAntigravityProvider = Effect.fn("makeAntigravityProvider")(func }, } satisfies AntigravityProviderState; }); - if (!before.draft.usageLimits || before.draft.usageLimits.unavailable) yield* refreshUsage(); + // Starting a session renews the CLI sign-in, so re-read quota even when a reading exists. + const accepted = yield* SubscriptionRef.get(metadata); + if (accepted.draft.auth.status === "authenticated") yield* refreshUsage({ restart: true }); }); const onConfigOptionsUpdated = Effect.fn("AntigravityProvider.onConfigOptionsUpdated")(function* ( diff --git a/apps/web/src/components/usage/UsageLimitsPooled.tsx b/apps/web/src/components/usage/UsageLimitsPooled.tsx index c3932252691e5..daeebf6e03a07 100644 --- a/apps/web/src/components/usage/UsageLimitsPooled.tsx +++ b/apps/web/src/components/usage/UsageLimitsPooled.tsx @@ -27,6 +27,7 @@ import { } from "react"; import { ensureLocalApi } from "../../localApi"; +import { useNowMinute } from "../../hooks/useNowMinute"; import { usePrimarySettings } from "../../hooks/useSettings"; import { cn } from "../../lib/utils"; import { formatUpcomingTimestamp } from "../../timestampFormat"; @@ -43,6 +44,7 @@ import { collectLimitNotices, cursorUsageWindowDetails, formatResetsIn, + poolCheckedLabel, resetCreditChoices, } from "@t3tools/shared/usageLimitsCopy"; @@ -636,6 +638,18 @@ function PoolWindowCard({ ); } +// The page freezes `now` between refreshes, so the age ticks on its own minute clock. +function PoolCheckedAt({ pool }: { readonly pool: LimitPool }) { + const nowMinute = useNowMinute(); + const m = useMessages(); + const checked = poolCheckedLabel(pool, Date.parse(`${nowMinute}:00Z`), m); + return checked ? ( + + {checked} + + ) : null; +} + function PoolSection({ pool, now }: { readonly pool: LimitPool; readonly now: number }) { const color = barColor(pool.driver); const label = providerClients.get(pool.driver)?.label ?? String(pool.driver); @@ -652,6 +666,7 @@ function PoolSection({ pool, now }: { readonly pool: LimitPool; readonly now: nu iconClassName="size-4 text-foreground/80" /> {label} + {windows.map((window) => { const details = diff --git a/apps/web/src/i18n/translations/de.json b/apps/web/src/i18n/translations/de.json index d137c9575c8ef..4ea05c9bb2b74 100644 --- a/apps/web/src/i18n/translations/de.json +++ b/apps/web/src/i18n/translations/de.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "Keine Limits gemeldet.", "e27d2cb964df5dd5": "{source}: Keine Konten gemeldet.", "1b503134018285f4": "{days} T. {hours} Std.", + "1b316942cffcbb5f": "gerade geprüft", + "57b04d7ee40cfb03": "vor {duration} geprüft", "164c674cf062933a": "{label} · noch {count} · läuft ab in {expires}", "9c82c39589c23938": "{label} · noch {count}", "ea4eaa756c937d3a": "Einlösen", diff --git a/apps/web/src/i18n/translations/en.json b/apps/web/src/i18n/translations/en.json index 20f3f33250f23..3dd9f17dcdf96 100644 --- a/apps/web/src/i18n/translations/en.json +++ b/apps/web/src/i18n/translations/en.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "No limits reported.", "e27d2cb964df5dd5": "{source}: No accounts reported.", "1b503134018285f4": "{days}d {hours}h", + "1b316942cffcbb5f": "checked just now", + "57b04d7ee40cfb03": "checked {duration} ago", "164c674cf062933a": "{label} · {count} left · expires in {expires}", "9c82c39589c23938": "{label} · {count} left", "ea4eaa756c937d3a": "Use", diff --git a/apps/web/src/i18n/translations/es.json b/apps/web/src/i18n/translations/es.json index 466f7e37ffa5d..fafbe7fa5bb3c 100644 --- a/apps/web/src/i18n/translations/es.json +++ b/apps/web/src/i18n/translations/es.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "No se informaron límites.", "e27d2cb964df5dd5": "{source}: no se informaron cuentas.", "1b503134018285f4": "{days} d {hours} h", + "1b316942cffcbb5f": "comprobado ahora mismo", + "57b04d7ee40cfb03": "comprobado hace {duration}", "164c674cf062933a": "{label} · quedan {count} · caduca en {expires}", "9c82c39589c23938": "{label} · quedan {count}", "ea4eaa756c937d3a": "Usar", diff --git a/apps/web/src/i18n/translations/fr.json b/apps/web/src/i18n/translations/fr.json index 579ae257a5c32..1ae56070edfea 100644 --- a/apps/web/src/i18n/translations/fr.json +++ b/apps/web/src/i18n/translations/fr.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "Aucune limite signalée.", "e27d2cb964df5dd5": "{source} : aucun compte signalé.", "1b503134018285f4": "{days} j {hours} h", + "1b316942cffcbb5f": "vérifié à l'instant", + "57b04d7ee40cfb03": "vérifié il y a {duration}", "164c674cf062933a": "{label} · {count} restants · expire dans {expires}", "9c82c39589c23938": "{label} · {count} restants", "ea4eaa756c937d3a": "Utiliser", diff --git a/apps/web/src/i18n/translations/ja.json b/apps/web/src/i18n/translations/ja.json index d418d4753f17d..ed73966ad60b0 100644 --- a/apps/web/src/i18n/translations/ja.json +++ b/apps/web/src/i18n/translations/ja.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "報告された上限はありません。", "e27d2cb964df5dd5": "{source}: 報告されたアカウントはありません。", "1b503134018285f4": "{days}日{hours}時間", + "1b316942cffcbb5f": "たった今確認", + "57b04d7ee40cfb03": "{duration}前に確認", "164c674cf062933a": "{label} · 残り {count} · {expires}後に期限切れ", "9c82c39589c23938": "{label} · 残り {count}", "ea4eaa756c937d3a": "使用", diff --git a/apps/web/src/i18n/translations/ko.json b/apps/web/src/i18n/translations/ko.json index 9f5343afc9173..1d35973218c7c 100644 --- a/apps/web/src/i18n/translations/ko.json +++ b/apps/web/src/i18n/translations/ko.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "보고된 한도가 없습니다.", "e27d2cb964df5dd5": "{source}: 보고된 계정이 없습니다.", "1b503134018285f4": "{days}일 {hours}시간", + "1b316942cffcbb5f": "방금 확인함", + "57b04d7ee40cfb03": "{duration} 전에 확인함", "164c674cf062933a": "{label} · {count}개 남음 · {expires} 후 만료", "9c82c39589c23938": "{label} · {count}개 남음", "ea4eaa756c937d3a": "사용", diff --git a/apps/web/src/i18n/translations/pt-BR.json b/apps/web/src/i18n/translations/pt-BR.json index f9613764f383e..f69a7ff8afe87 100644 --- a/apps/web/src/i18n/translations/pt-BR.json +++ b/apps/web/src/i18n/translations/pt-BR.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "Nenhum limite informado.", "e27d2cb964df5dd5": "{source}: nenhuma conta informada.", "1b503134018285f4": "{days}d {hours}h", + "1b316942cffcbb5f": "verificado agora mesmo", + "57b04d7ee40cfb03": "verificado há {duration}", "164c674cf062933a": "{label} · {count} restantes · expira em {expires}", "9c82c39589c23938": "{label} · {count} restantes", "ea4eaa756c937d3a": "Usar", diff --git a/apps/web/src/i18n/translations/ru.json b/apps/web/src/i18n/translations/ru.json index 356b1a3f25580..73bd522210e47 100644 --- a/apps/web/src/i18n/translations/ru.json +++ b/apps/web/src/i18n/translations/ru.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "Лимиты не сообщаются.", "e27d2cb964df5dd5": "{source}: аккаунты не найдены.", "1b503134018285f4": "{days} д {hours} ч", + "1b316942cffcbb5f": "проверено только что", + "57b04d7ee40cfb03": "проверено {duration} назад", "164c674cf062933a": "{label} · осталось {count} · истекает через {expires}", "9c82c39589c23938": "{label} · осталось {count}", "ea4eaa756c937d3a": "Использовать", diff --git a/apps/web/src/i18n/translations/sv.json b/apps/web/src/i18n/translations/sv.json index 7e8a59ee1407c..14d77c3e102d6 100644 --- a/apps/web/src/i18n/translations/sv.json +++ b/apps/web/src/i18n/translations/sv.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "Inga gränser rapporterades.", "e27d2cb964df5dd5": "{source}: inga konton rapporterades.", "1b503134018285f4": "{days} d {hours} h", + "1b316942cffcbb5f": "kontrollerat nyss", + "57b04d7ee40cfb03": "kontrollerat för {duration} sedan", "164c674cf062933a": "{label} · {count} kvar · går ut om {expires}", "9c82c39589c23938": "{label} · {count} kvar", "ea4eaa756c937d3a": "Använd", diff --git a/apps/web/src/i18n/translations/zh.json b/apps/web/src/i18n/translations/zh.json index 82feffe66e815..1e79b7fe4adbb 100644 --- a/apps/web/src/i18n/translations/zh.json +++ b/apps/web/src/i18n/translations/zh.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "没有报告限额。", "e27d2cb964df5dd5": "{source}:未报告任何账户。", "1b503134018285f4": "{days} 天 {hours} 小时", + "1b316942cffcbb5f": "刚刚检查", + "57b04d7ee40cfb03": "{duration}前检查", "164c674cf062933a": "{label} · 剩余 {count} 个 · {expires} 后过期", "9c82c39589c23938": "{label} · 剩余 {count} 次", "ea4eaa756c937d3a": "使用", diff --git a/packages/shared/src/usageLimits.test.ts b/packages/shared/src/usageLimits.test.ts index 6b553fe5f1555..d14a5f0558772 100644 --- a/packages/shared/src/usageLimits.test.ts +++ b/packages/shared/src/usageLimits.test.ts @@ -26,7 +26,7 @@ import { usesChatGptSharing, resolveNewThreadModelSelection, } from "./usageLimits.ts"; -import { collectLimitNotices } from "./usageLimitsCopy.ts"; +import { collectLimitNotices, poolCheckedLabel } from "./usageLimitsCopy.ts"; const now = Date.parse("2026-09-03T12:00:00.000Z"); @@ -294,6 +294,46 @@ describe("pools", () => { expect(accounts[0]?.limits.windows[0]?.usedPercent).toBe(55); }); + it("labels a pool with the age of its stalest reading", () => { + const account = (email: string, at: string) => + provider({ + driver: claude, + instanceId: ProviderInstanceId.make("claude"), + auth: { status: "authenticated", email }, + usageLimits: { checkedAt: at, windows: [{ ...window, usedPercent: 40 }] }, + }); + const poolsFor = (providers: readonly ServerProvider[]) => + collectLimitPools( + collectLimitAccounts( + new Map([[EnvironmentId.make("env-a"), { ...laptop, serverConfig: { providers } }]]), + ), + now, + ); + const stale = poolsFor([ + account("a@example.com", "2026-09-03T11:30:00.000Z"), + account("b@example.com", checkedAt), + ])[0]!; + expect(poolCheckedLabel(stale, now)).toBe("checked 1h 0m ago"); + const fresh = poolsFor([account("a@example.com", "2026-09-03T11:59:30.000Z")])[0]!; + expect(poolCheckedLabel(fresh, now)).toBe("checked just now"); + const withUnreadable = (pool: typeof stale, at: string) => ({ + ...pool, + accounts: pool.accounts.map((entry, index) => + index === 0 ? { ...entry, limits: { ...entry.limits, checkedAt: at } } : entry, + ), + }); + // One malformed wire timestamp must not hide the readable readings' age. + expect(poolCheckedLabel(withUnreadable(stale, "not-a-date"), now)).toBe("checked 1h 0m ago"); + const unreadable = { + ...fresh, + accounts: fresh.accounts.map((entry) => ({ + ...entry, + limits: { ...entry.limits, checkedAt: "not-a-date" }, + })), + }; + expect(poolCheckedLabel(unreadable, now)).toBeNull(); + }); + it("uses the freshest reported plan even when the newest quota has no plan", () => { const snapshot = (label: string | undefined, checkedAt: string, usedPercent: number) => provider({ diff --git a/packages/shared/src/usageLimitsCopy.ts b/packages/shared/src/usageLimitsCopy.ts index ea9eafaf55ce1..1cae2570c38ea 100644 --- a/packages/shared/src/usageLimitsCopy.ts +++ b/packages/shared/src/usageLimitsCopy.ts @@ -131,6 +131,27 @@ export function formatDuration(ms: number, resolve: MFunctionType = mFallback): return resolve(msg("{minutes}m", { minutes })); } +/** How old a pool's stalest reading is, or null when no reading carries a usable time. @public */ +export function poolCheckedLabel( + pool: LimitPool, + now: number, + resolve: MFunctionType = mFallback, +): string | null { + const readable = pool.accounts + .map((account) => Date.parse(account.limits.checkedAt)) + .filter(Number.isFinite); + if (readable.length === 0) return null; + const oldest = Math.min(...readable); + const age = now - oldest; + if (age < MINUTE) return resolve(msg("checked just now", { $context: "usage limits" })); + return resolve( + msg("checked {duration} ago", { + duration: formatDuration(age, resolve), + $context: "usage limits", + }), + ); +} + /** @public */ export function resetCreditChoices( credits: ServerProviderResetCredits,