diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index e69de418cd3e..9d33982a813a 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -3997,6 +3997,7 @@ export default function ChatView(props: ChatViewProps) { providers: providerStatuses, sources: serverConfig?.usageLimitSources ?? EMPTY_USAGE_LIMIT_SOURCES, contextWindow: activeContextWindow, + onOpenUsageLimits: composerMounted ? openUsageLimits : undefined, }} /> diff --git a/apps/web/src/components/chat/ThreadDetailsUsage.browser.test.tsx b/apps/web/src/components/chat/ThreadDetailsUsage.browser.test.tsx new file mode 100644 index 000000000000..13cacd1233ad --- /dev/null +++ b/apps/web/src/components/chat/ThreadDetailsUsage.browser.test.tsx @@ -0,0 +1,132 @@ +import { + ProviderDriverKind, + ProviderInstanceId, + UsageLimitSourceId, + type ServerProvider, + type UsageLimitSourceSnapshots, +} from "@t3tools/contracts"; +import { expect, it, vi } from "vite-plus/test"; +import { render } from "../../../test/render"; +import { ThreadDetailsUsage } from "./ThreadDetailsUsage"; + +const checkedAt = "2026-11-04T12:00:00.000Z"; +const provider: ServerProvider = { + instanceId: ProviderInstanceId.make("claude-proxy"), + driver: ProviderDriverKind.make("claudeAgent"), + enabled: true, + installed: true, + version: null, + status: "ready", + auth: { status: "authenticated" }, + checkedAt, + models: [], + slashCommands: [], + skills: [], + usageLimits: { checkedAt, windows: [], unavailable: { reason: "unsupported" } }, +}; +const sources: UsageLimitSourceSnapshots = [ + { + id: UsageLimitSourceId.make("hub"), + kind: "cliproxy", + label: "Claude pool", + checkedAt, + accounts: [ + { + id: "claude-account", + driver: provider.driver, + usageLimits: { + checkedAt, + windows: [{ id: "session", kind: "session", label: "Session", usedPercent: 17 }], + }, + }, + ], + }, +]; + +it("opens available hub limits without attributing a hub account's quota to the endpoint", async () => { + const onOpenUsageLimits = vi.fn(); + await using screen = await render( + , + ); + await expect.element(screen.getByRole("button", { name: "View hub limits" })).toBeVisible(); + await expect.element(screen.getByText("Unavailable", { exact: true })).not.toBeInTheDocument(); + await screen.getByRole("button", { name: "View hub limits" }).click(); + expect(onOpenUsageLimits).toHaveBeenCalledOnce(); + + await screen.rerender( + , + ); + await expect.element(screen.getByText("Unavailable", { exact: true })).toBeVisible(); + await expect + .element(screen.getByRole("button", { name: "View hub limits" })) + .not.toBeInTheDocument(); + + for (const unavailableSources of [ + [], + [ + { + ...sources[0]!, + accounts: [{ ...sources[0]!.accounts[0]!, driver: ProviderDriverKind.make("codex") }], + }, + ], + [ + { + ...sources[0]!, + accounts: [ + { + ...sources[0]!.accounts[0]!, + usageLimits: { + checkedAt, + windows: [], + unavailable: { reason: "probeFailed" as const }, + }, + }, + ], + }, + ], + ]) { + await screen.rerender( + , + ); + await expect.element(screen.getByText("Unavailable", { exact: true })).toBeVisible(); + await expect + .element(screen.getByRole("button", { name: "View hub limits" })) + .not.toBeInTheDocument(); + } + + await screen.rerender( + , + ); + await expect.element(screen.getByText("40%", { exact: true })).toBeVisible(); + await expect + .element(screen.getByRole("button", { name: "View hub limits" })) + .not.toBeInTheDocument(); +}); diff --git a/apps/web/src/components/chat/ThreadDetailsUsage.tsx b/apps/web/src/components/chat/ThreadDetailsUsage.tsx index 2997f6faa21b..e476bfc9b792 100644 --- a/apps/web/src/components/chat/ThreadDetailsUsage.tsx +++ b/apps/web/src/components/chat/ThreadDetailsUsage.tsx @@ -20,6 +20,7 @@ import type { ContextWindowSnapshot } from "@t3tools/client-runtime/state/contex import { formatContextWindowTokens } from "../../lib/contextWindow"; import { cn } from "../../lib/utils"; import { formatUpcomingTimestamp } from "../../timestampFormat"; +import { Button } from "../ui/button"; import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; import { formatContextWindowCompactionMessage } from "./compaction.logic"; import { ThreadDetailsSection } from "./ThreadDetailsSection"; @@ -35,6 +36,7 @@ export interface ThreadDetailsUsageInput { readonly providers: readonly ServerProvider[]; readonly sources: UsageLimitSourceSnapshots; readonly contextWindow: ContextWindowSnapshot | null; + readonly onOpenUsageLimits: (() => void) | undefined; } type UsageTone = "error" | "warning" | null; @@ -44,6 +46,7 @@ export function ThreadDetailsUsage({ providerInstanceId, providers, sources, + onOpenUsageLimits, }: Omit) { const gt = useGT(); const m = useMessages(); @@ -55,11 +58,20 @@ export function ThreadDetailsUsage({ : null; // Only this instance's data: the report keeps one instance per login, and any other entry may be // a different login or workspace, so fall back to the instance's own snapshot. + const selected = providers.find((provider) => provider.instanceId === providerInstanceId); const limits = report?.accounts.find((entry) => entry.instanceId === providerInstanceId)?.limits ?? - providers.find((provider) => provider.instanceId === providerInstanceId)?.usageLimits; - if (!limits) return null; - const notice = limitsNotice(limits, m); + selected?.usageLimits; + const hasHubLimits = sources.some((source) => + source.accounts.some( + (account) => + account.driver === selected?.driver && limitsNotice(account.usageLimits, m) === null, + ), + ); + if (!limits && !hasHubLimits) return null; + const notice = limits ? limitsNotice(limits, m) : null; + const showHubLimits = + onOpenUsageLimits !== undefined && hasHubLimits && (!limits || notice !== null); return ( - {notice ? ( + {showHubLimits ? ( + + + {gt("Limits", { $context: "usage limits row label" })} + + + {gt("View hub limits")} + + + ) : notice ? ( {notice}} /> ) : ( - limits.windows.map((window) => ) + limits?.windows.map((window) => ) )} diff --git a/apps/web/src/i18n/translations/de.json b/apps/web/src/i18n/translations/de.json index 648fd58859db..ca1f0cc62940 100644 --- a/apps/web/src/i18n/translations/de.json +++ b/apps/web/src/i18n/translations/de.json @@ -4029,6 +4029,7 @@ "b16fdf56b16d99c9": "Im Tempo", "90f977e97ae8b6c6": "Unter dem Tempo", "b560c47847c88b2e": "Limits", + "9ce17cbde3a324c7": "Hub-Limits anzeigen", "42a02a4b27828027": "Nicht verfügbar", "16fb3b76d0abbb2e": "Kontextfenster", "83bbceecef0f6872": "Kontext", diff --git a/apps/web/src/i18n/translations/en.json b/apps/web/src/i18n/translations/en.json index 599944358b5b..be8f41f077f1 100644 --- a/apps/web/src/i18n/translations/en.json +++ b/apps/web/src/i18n/translations/en.json @@ -4028,6 +4028,7 @@ "b16fdf56b16d99c9": "On pace", "90f977e97ae8b6c6": "Under pace", "b560c47847c88b2e": "Limits", + "9ce17cbde3a324c7": "View hub limits", "42a02a4b27828027": "Unavailable", "16fb3b76d0abbb2e": "Context window", "83bbceecef0f6872": "Context", diff --git a/apps/web/src/i18n/translations/es.json b/apps/web/src/i18n/translations/es.json index 956f4e17a961..74013bd2e48c 100644 --- a/apps/web/src/i18n/translations/es.json +++ b/apps/web/src/i18n/translations/es.json @@ -4026,6 +4026,7 @@ "b16fdf56b16d99c9": "Al ritmo", "90f977e97ae8b6c6": "Por debajo del ritmo", "b560c47847c88b2e": "Límites", + "9ce17cbde3a324c7": "Ver límites del hub", "42a02a4b27828027": "No disponible", "16fb3b76d0abbb2e": "Ventana de contexto", "83bbceecef0f6872": "Contexto", diff --git a/apps/web/src/i18n/translations/fr.json b/apps/web/src/i18n/translations/fr.json index 1c982cc6d6f5..ea0392f1dad9 100644 --- a/apps/web/src/i18n/translations/fr.json +++ b/apps/web/src/i18n/translations/fr.json @@ -4027,6 +4027,7 @@ "b16fdf56b16d99c9": "Dans le rythme", "90f977e97ae8b6c6": "En dessous du rythme", "b560c47847c88b2e": "Limites", + "9ce17cbde3a324c7": "Voir les limites du hub", "42a02a4b27828027": "Indisponible", "16fb3b76d0abbb2e": "Fenêtre de contexte", "83bbceecef0f6872": "Contexte", diff --git a/apps/web/src/i18n/translations/ja.json b/apps/web/src/i18n/translations/ja.json index 879531a396d2..cdab92f35e7b 100644 --- a/apps/web/src/i18n/translations/ja.json +++ b/apps/web/src/i18n/translations/ja.json @@ -4017,6 +4017,7 @@ "b16fdf56b16d99c9": "ペースどおり", "90f977e97ae8b6c6": "ペースより遅い", "b560c47847c88b2e": "上限", + "9ce17cbde3a324c7": "ハブの上限を表示", "42a02a4b27828027": "利用不可", "16fb3b76d0abbb2e": "コンテキストウィンドウ", "83bbceecef0f6872": "コンテキスト", diff --git a/apps/web/src/i18n/translations/ko.json b/apps/web/src/i18n/translations/ko.json index fae8ce2ec6fc..94cca6c7ad75 100644 --- a/apps/web/src/i18n/translations/ko.json +++ b/apps/web/src/i18n/translations/ko.json @@ -4014,6 +4014,7 @@ "b16fdf56b16d99c9": "예상대로", "90f977e97ae8b6c6": "예상보다 느림", "b560c47847c88b2e": "한도", + "9ce17cbde3a324c7": "허브 한도 보기", "42a02a4b27828027": "사용할 수 없음", "16fb3b76d0abbb2e": "컨텍스트 창", "83bbceecef0f6872": "컨텍스트", diff --git a/apps/web/src/i18n/translations/pt-BR.json b/apps/web/src/i18n/translations/pt-BR.json index 7010bef288b1..4d0af775cee1 100644 --- a/apps/web/src/i18n/translations/pt-BR.json +++ b/apps/web/src/i18n/translations/pt-BR.json @@ -4026,6 +4026,7 @@ "b16fdf56b16d99c9": "No ritmo", "90f977e97ae8b6c6": "Abaixo do ritmo", "b560c47847c88b2e": "Limites", + "9ce17cbde3a324c7": "Ver limites do hub", "42a02a4b27828027": "Indisponível", "16fb3b76d0abbb2e": "Janela de contexto", "83bbceecef0f6872": "Contexto", diff --git a/apps/web/src/i18n/translations/ru.json b/apps/web/src/i18n/translations/ru.json index 0766d953dd02..815279cef915 100644 --- a/apps/web/src/i18n/translations/ru.json +++ b/apps/web/src/i18n/translations/ru.json @@ -4026,6 +4026,7 @@ "b16fdf56b16d99c9": "В темпе", "90f977e97ae8b6c6": "Медленнее темпа", "b560c47847c88b2e": "Лимиты", + "9ce17cbde3a324c7": "Посмотреть лимиты хаба", "42a02a4b27828027": "Недоступно", "16fb3b76d0abbb2e": "Контекстное окно", "83bbceecef0f6872": "Контекст", diff --git a/apps/web/src/i18n/translations/sv.json b/apps/web/src/i18n/translations/sv.json index 5e6d1607edf3..3ba7b2b3ebc8 100644 --- a/apps/web/src/i18n/translations/sv.json +++ b/apps/web/src/i18n/translations/sv.json @@ -4027,6 +4027,7 @@ "b16fdf56b16d99c9": "I takt", "90f977e97ae8b6c6": "Under takten", "b560c47847c88b2e": "Gränser", + "9ce17cbde3a324c7": "Visa hubbens gränser", "42a02a4b27828027": "Inte tillgänglig", "16fb3b76d0abbb2e": "Kontextfönster", "83bbceecef0f6872": "Kontext", diff --git a/apps/web/src/i18n/translations/zh.json b/apps/web/src/i18n/translations/zh.json index c86b9e6c55e4..f23ad1308582 100644 --- a/apps/web/src/i18n/translations/zh.json +++ b/apps/web/src/i18n/translations/zh.json @@ -4033,6 +4033,7 @@ "b16fdf56b16d99c9": "用量消耗适中", "90f977e97ae8b6c6": "用量消耗偏慢", "b560c47847c88b2e": "限制", + "9ce17cbde3a324c7": "查看中心限额", "42a02a4b27828027": "不可用", "16fb3b76d0abbb2e": "上下文窗口", "83bbceecef0f6872": "上下文",