From 323d65db9509bb0a96aaa2e9e15dda1ed85c5a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Flor=C3=AAncio?= Date: Thu, 16 Jul 2026 23:08:51 +0100 Subject: [PATCH] fix(web): prioritize subscription usage (#1741) --- apps/web/app/settings/agents/page.tsx | 8 +- .../task/chat/token-usage-display.test.tsx | 37 +++++- .../task/chat/token-usage-display.tsx | 106 +++++++++++------- 3 files changed, 104 insertions(+), 47 deletions(-) diff --git a/apps/web/app/settings/agents/page.tsx b/apps/web/app/settings/agents/page.tsx index 73d4e2ae5b..7e5462e596 100644 --- a/apps/web/app/settings/agents/page.tsx +++ b/apps/web/app/settings/agents/page.tsx @@ -218,14 +218,14 @@ function InstalledAgentsSection({ return (
-
+

Installed Agents

Agents detected on this machine are ready to configure.

-
+
+ + - - ({ })); vi.mock("@kandev/ui/tooltip", () => ({ - Tooltip: ({ children }: { children: React.ReactNode }) => <>{children}, + Tooltip: ({ children, open }: { children: React.ReactNode; open?: boolean }) => ( +
+ {children} +
+ ), TooltipTrigger: ({ children }: { children: React.ReactNode }) => <>{children}, TooltipContent: ({ children }: { children: React.ReactNode }) => <>{children}, })); @@ -73,6 +77,21 @@ describe("TokenUsageDisplay", () => { expect(container.querySelector("svg")).not.toBeNull(); }); + it("opens the tooltip when the context ring is tapped", () => { + vi.mocked(useSessionContextWindow).mockReturnValue({ + size: 200_000, + used: 56_047, + remaining: 143_953, + efficiency: 28, + }); + + const { getByRole, getByTestId } = render(); + + fireEvent.click(getByRole("button", { name: "Context window: 28% used" })); + + expect(getByTestId("tooltip-root").getAttribute("data-open")).toBe("true"); + }); + it("shows subscription usage rows in the tooltip when the agent has them", () => { vi.mocked(useSessionContextWindow).mockReturnValue({ size: 200_000, @@ -102,10 +121,20 @@ describe("TokenUsageDisplay", () => { }, }); - const { container, getByText } = render(); + const { container, getByRole, getByTestId, getByText } = render( + , + ); expect(container.querySelector('[data-testid="doughnut-subscription-usage"]')).not.toBeNull(); - expect(getByText(/Subscription usage · max/i)).toBeDefined(); + expect(getByRole("button", { name: "Context window: 28% used" })).toBeDefined(); + expect(getByText("Context window")).toBeDefined(); + expect(getByText("56.0K of 200.0K tokens")).toBeDefined(); + expect(getByText(/Subscription · max/i)).toBeDefined(); + expect( + getByTestId("context-window-usage").compareDocumentPosition( + getByTestId("doughnut-subscription-usage"), + ) & Node.DOCUMENT_POSITION_FOLLOWING, + ).toBeTruthy(); // Worst window is 86% → provider status "High". expect(getByText("High")).toBeDefined(); expect(getByText("5h")).toBeDefined(); diff --git a/apps/web/components/task/chat/token-usage-display.tsx b/apps/web/components/task/chat/token-usage-display.tsx index 0b373de30d..a8365d0184 100644 --- a/apps/web/components/task/chat/token-usage-display.tsx +++ b/apps/web/components/task/chat/token-usage-display.tsx @@ -1,6 +1,6 @@ "use client"; -import { memo } from "react"; +import { memo, useState } from "react"; import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip"; import { cn } from "@/lib/utils"; import { UsageWindowRows, usageStatus } from "@/components/usage/usage-window-rows"; @@ -54,16 +54,16 @@ function SessionUsageRows({ sessionId }: { sessionId: string | null }) { return (
- - Subscription usage{usage.plan ? ` · ${usage.plan}` : ""} + + Subscription{usage.plan ? ` · ${usage.plan}` : ""} - {status.label} + {status.label}
- +
); } @@ -72,6 +72,7 @@ export const TokenUsageDisplay = memo(function TokenUsageDisplay({ sessionId, className, }: TokenUsageDisplayProps) { + const [tooltipOpen, setTooltipOpen] = useState(false); const contextWindow = useSessionContextWindow(sessionId); if (!contextWindow) return null; @@ -92,42 +93,69 @@ export const TokenUsageDisplay = memo(function TokenUsageDisplay({ const strokeDashoffset = circumference * (1 - progress); return ( - + -
-
- -
-
+
-
-
- {usagePercent.toFixed(0)}% ({formatNumber(used)} / {formatNumber(size)}) +
+
+
+ + Context window + + + {usagePercent.toFixed(0)}% + +
+
+
+
+
+ {formatNumber(used)} of {formatNumber(size)} tokens +