mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 10:58:10 +00:00
Show usage reset dates in account switcher
This commit is contained in:
@@ -21,12 +21,17 @@ function accountRows(provider: 'codex' | 'claude', width = 520) {
|
||||
weekly: {
|
||||
usedPercent: 38,
|
||||
windowMinutes: 10_080,
|
||||
resetsAt: null,
|
||||
resetsAt: Date.now() + (6 * 24 + 4) * 3_600_000 + 5_000,
|
||||
resetDescription: null
|
||||
},
|
||||
fableWeekly:
|
||||
provider === 'claude'
|
||||
? { usedPercent: 42, windowMinutes: 10_080, resetsAt: null, resetDescription: null }
|
||||
? {
|
||||
usedPercent: 42,
|
||||
windowMinutes: 10_080,
|
||||
resetsAt: Date.now() + 43 * 3_600_000 + 5_000,
|
||||
resetDescription: null
|
||||
}
|
||||
: null,
|
||||
updatedAt: 0,
|
||||
error: null,
|
||||
|
||||
@@ -48,7 +48,7 @@ export function AccountSwitchRowItem({
|
||||
<span className="truncate text-2xs text-muted-foreground">{detail}</span>
|
||||
) : null}
|
||||
</span>
|
||||
{children ? <div className="w-[45%] max-w-40 shrink-0 text-xs">{children}</div> : null}
|
||||
{children ? <div className="w-1/2 max-w-48 shrink-0 text-xs">{children}</div> : null}
|
||||
</DropdownMenuItem>
|
||||
{action ? <div className="shrink-0 pr-1.5">{action}</div> : null}
|
||||
</div>
|
||||
|
||||
@@ -10,10 +10,14 @@ import {
|
||||
} from '../../../../shared/usage-percentage-display'
|
||||
import { useResetCountdownClock } from '@/hooks/useResetCountdownClock'
|
||||
import { barColor, clampUsedPercent } from './tooltip'
|
||||
import { formatRateLimitWindowChipLabel } from '../../../../shared/rate-limit-window-label'
|
||||
import { formatWindowLabel } from '../../../../shared/rate-limit-window-label'
|
||||
import { formatResetDuration } from '../../../../shared/rate-limit-reset-format'
|
||||
import { formatUsageLimitResetClock } from '../../../../shared/agent-session/failures/agent-session-usage-limit'
|
||||
import { formatUsagePercentageLabel } from './usage-percentage-label'
|
||||
import { getUsageRosterRowState } from './usage-roster-row-state'
|
||||
import { useTranslate } from '@/i18n/use-translate'
|
||||
import { useIntlLocale, useTranslate } from '@/i18n/use-translate'
|
||||
|
||||
type InlineUsageWindow = { key: string; used: number; label: string; resetsAt: number | null }
|
||||
|
||||
export function InlineUsageBars({
|
||||
limits,
|
||||
@@ -23,32 +27,40 @@ export function InlineUsageBars({
|
||||
isFetching: boolean
|
||||
}): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
const intlLocale = useIntlLocale()
|
||||
const display = normalizeUsagePercentageDisplay(
|
||||
useAppStore((state) => state.usagePercentageDisplay)
|
||||
)
|
||||
// Why: tick the session countdown live via one boundary-scheduled clock, not just the usage poll (#5399).
|
||||
const now = useResetCountdownClock([limits.session?.resetsAt, limits.monthly?.resetsAt])
|
||||
// Why: tick every reset countdown live via one boundary-scheduled clock, not just the usage poll (#5399).
|
||||
const now = useResetCountdownClock([
|
||||
limits.session?.resetsAt,
|
||||
limits.weekly?.resetsAt,
|
||||
limits.fableWeekly?.resetsAt,
|
||||
limits.monthly?.resetsAt
|
||||
])
|
||||
const usageWindows = [
|
||||
limits.session
|
||||
? {
|
||||
key: 'session',
|
||||
used: clampUsedPercent(limits.session.usedPercent),
|
||||
// Why: live reset countdown (matches popover); '5h' window length only when resetsAt is unknown (#5399).
|
||||
label: formatRateLimitWindowChipLabel(limits.session, now)
|
||||
label: formatWindowLabel(limits.session.windowMinutes),
|
||||
resetsAt: limits.session.resetsAt
|
||||
}
|
||||
: null,
|
||||
limits.weekly
|
||||
? {
|
||||
key: 'weekly',
|
||||
used: clampUsedPercent(limits.weekly.usedPercent),
|
||||
label: t('auto.components.status.bar.StatusBar.5c938d39ac', 'wk')
|
||||
label: t('auto.components.status.bar.StatusBar.5c938d39ac', 'wk'),
|
||||
resetsAt: limits.weekly.resetsAt
|
||||
}
|
||||
: null,
|
||||
limits.fableWeekly
|
||||
? {
|
||||
key: 'fableWeekly',
|
||||
used: clampUsedPercent(limits.fableWeekly.usedPercent),
|
||||
label: t('auto.components.status.bar.StatusBar.54e8d6bb2d', 'Fable')
|
||||
label: t('auto.components.status.bar.StatusBar.54e8d6bb2d', 'Fable'),
|
||||
resetsAt: limits.fableWeekly.resetsAt
|
||||
}
|
||||
: null,
|
||||
// Why: matches the status bar chip; monthly is the only limit when there is no 5h/7d window.
|
||||
@@ -56,10 +68,11 @@ export function InlineUsageBars({
|
||||
? {
|
||||
key: 'monthly',
|
||||
used: clampUsedPercent(limits.monthly.usedPercent),
|
||||
label: formatRateLimitWindowChipLabel(limits.monthly, now)
|
||||
label: formatWindowLabel(limits.monthly.windowMinutes),
|
||||
resetsAt: limits.monthly.resetsAt
|
||||
}
|
||||
: null
|
||||
].filter((window): window is { key: string; used: number; label: string } => window !== null)
|
||||
].filter((window): window is InlineUsageWindow => window !== null)
|
||||
// Why: a lapsed token or failed refresh is not a sign-out; ask for a sign-in only when one is confirmed.
|
||||
const emptyState =
|
||||
usageWindows.length === 0 && limits.status === 'error'
|
||||
@@ -70,20 +83,39 @@ export function InlineUsageBars({
|
||||
<div
|
||||
className={`grid w-full items-center gap-1.5 ${isFetching ? 'animate-pulse motion-reduce:animate-none' : ''}`}
|
||||
>
|
||||
{usageWindows.map((window) => (
|
||||
<div key={window.key} className="flex min-w-0 items-center gap-1">
|
||||
<div className="h-1 min-w-0 flex-1 overflow-hidden rounded-full bg-muted">
|
||||
{/* Why: fill follows the selected percentage; color still signals consumption urgency. */}
|
||||
<div
|
||||
className={`h-full rounded-full ${barColor(window.used)}`}
|
||||
style={{ width: `${getDisplayedUsagePercentage(window.used, display)}%` }}
|
||||
/>
|
||||
{usageWindows.map((window) => {
|
||||
const resetsAt =
|
||||
window.resetsAt != null && Number.isFinite(new Date(window.resetsAt).getTime())
|
||||
? window.resetsAt
|
||||
: null
|
||||
return (
|
||||
<div key={window.key} className="grid min-w-0 gap-0.5">
|
||||
<div className="flex min-w-0 items-center gap-1">
|
||||
<div className="h-1 min-w-0 flex-1 overflow-hidden rounded-full bg-muted">
|
||||
{/* Why: fill follows the selected percentage; color still signals consumption urgency. */}
|
||||
<div
|
||||
className={`h-full rounded-full ${barColor(window.used)}`}
|
||||
style={{ width: `${getDisplayedUsagePercentage(window.used, display)}%` }}
|
||||
/>
|
||||
</div>
|
||||
<span className="min-w-[4.5rem] shrink-0 text-right text-3xs tabular-nums text-muted-foreground">
|
||||
{formatUsagePercentageLabel(window.used, display, t)} {window.label}
|
||||
</span>
|
||||
{/* Why: fixed width keeps the reset countdowns in one column across account rows. */}
|
||||
<span className="w-11 shrink-0 text-right text-3xs tabular-nums text-muted-foreground">
|
||||
{resetsAt != null ? formatResetDuration(resetsAt - now) : null}
|
||||
</span>
|
||||
</div>
|
||||
{resetsAt != null ? (
|
||||
<span className="text-right text-3xs tabular-nums text-muted-foreground">
|
||||
{t('auto.components.status.bar.InlineUsageBars.resetsAt', 'Resets {{when}}', {
|
||||
when: formatUsageLimitResetClock(resetsAt, now, intlLocale)
|
||||
})}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
<span className="min-w-[5.5rem] shrink-0 text-right text-3xs tabular-nums text-muted-foreground">
|
||||
{formatUsagePercentageLabel(window.used, display, t)} {window.label}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
)
|
||||
})}
|
||||
{emptyState ? (
|
||||
<span className="text-3xs text-muted-foreground">
|
||||
{emptyState.kind === 'sign-in'
|
||||
|
||||
@@ -5044,6 +5044,9 @@
|
||||
"accounts": "Gespeicherte Antigravity-Konten",
|
||||
"readAgo": "Ausgelesen {{time}}",
|
||||
"notRead": "Nutzung unbekannt: noch nicht ausgelesen"
|
||||
},
|
||||
"InlineUsageBars": {
|
||||
"resetsAt": "Zurücksetzung um {{when}}"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -5308,6 +5308,9 @@
|
||||
"accounts": "Saved Antigravity Accounts",
|
||||
"readAgo": "Read {{time}}",
|
||||
"notRead": "Usage unknown: not read yet"
|
||||
},
|
||||
"InlineUsageBars": {
|
||||
"resetsAt": "Resets {{when}}"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -4610,6 +4610,9 @@
|
||||
"accounts": "Cuentas de Antigravity guardadas",
|
||||
"readAgo": "Consultado {{time}}",
|
||||
"notRead": "Uso desconocido: aún no consultado"
|
||||
},
|
||||
"InlineUsageBars": {
|
||||
"resetsAt": "Se restablece a las {{when}}"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -4835,6 +4835,9 @@
|
||||
"accounts": "Comptes Antigravity enregistrés",
|
||||
"readAgo": "Relevé {{time}}",
|
||||
"notRead": "Utilisation inconnue : pas encore relevée"
|
||||
},
|
||||
"InlineUsageBars": {
|
||||
"resetsAt": "Réinitialisation à {{when}}"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -4474,6 +4474,9 @@
|
||||
"accounts": "保存済み Antigravity アカウント",
|
||||
"readAgo": "{{time}} に取得",
|
||||
"notRead": "使用量は不明:未取得"
|
||||
},
|
||||
"InlineUsageBars": {
|
||||
"resetsAt": "{{when}} にリセット"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -4474,6 +4474,9 @@
|
||||
"accounts": "저장된 Antigravity 계정",
|
||||
"readAgo": "{{time}}에 조회",
|
||||
"notRead": "사용량을 알 수 없음: 아직 조회하지 않음"
|
||||
},
|
||||
"InlineUsageBars": {
|
||||
"resetsAt": "{{when}}에 초기화"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -3629,6 +3629,9 @@
|
||||
"accounts": "Contas Antigravity salvas",
|
||||
"readAgo": "Lido {{time}}",
|
||||
"notRead": "Uso desconhecido: ainda não consultado"
|
||||
},
|
||||
"InlineUsageBars": {
|
||||
"resetsAt": "Redefinição em {{when}}"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -5232,6 +5232,9 @@
|
||||
"accounts": "Сохранённые аккаунты Antigravity",
|
||||
"readAgo": "Считано {{time}}",
|
||||
"notRead": "Использование неизвестно: данные ещё не считаны"
|
||||
},
|
||||
"InlineUsageBars": {
|
||||
"resetsAt": "Сброс: {{when}}"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -5028,6 +5028,9 @@
|
||||
"accounts": "Kayıtlı Antigravity Hesapları",
|
||||
"readAgo": "Okunma zamanı: {{time}}",
|
||||
"notRead": "Kullanım bilinmiyor: henüz okunmadı"
|
||||
},
|
||||
"InlineUsageBars": {
|
||||
"resetsAt": "Sıfırlanma zamanı: {{when}}"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -4929,6 +4929,9 @@
|
||||
"accounts": "已儲存的 Antigravity 帳戶",
|
||||
"readAgo": "讀取於 {{time}}",
|
||||
"notRead": "用量未知:尚未讀取"
|
||||
},
|
||||
"InlineUsageBars": {
|
||||
"resetsAt": "將於 {{when}} 重設"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -4474,6 +4474,9 @@
|
||||
"accounts": "已保存的 Antigravity 账户",
|
||||
"readAgo": "读取于 {{time}}",
|
||||
"notRead": "用量未知:尚未读取"
|
||||
},
|
||||
"InlineUsageBars": {
|
||||
"resetsAt": "将在 {{when}} 重置"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user