Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

refactor(frontend/copilot): split UsageLimits into UsagePopover and UsageLimitReachedCard (#13012)

Ubbeb8fadbc49789
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx
index b298586bb0..ff2b396da1 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx
@@ -15,10 +15,8 @@ import type { TurnStatsMap } from "../../helpers/convertChatSessionToUiMessages"
import { ChatMessagesContainer } from "../ChatMessagesContainer/ChatMessagesContainer";
import { CopilotChatActionsProvider } from "../CopilotChatActionsProvider/CopilotChatActionsProvider";
import { EmptySession } from "../EmptySession/EmptySession";
-import {
- UsageLimitReachedCard,
- useIsUsageLimitReached,
-} from "../UsageLimits/UsageLimitReachedCard";
+import { UsageLimitReachedCard } from "../UsageLimits/UsageLimitReachedCard/UsageLimitReachedCard";
+import { useIsUsageLimitReached } from "../UsageLimits/useIsUsageLimitReached";
import { useAutoOpenArtifacts } from "./useAutoOpenArtifacts";
export interface ChatContainerProps {
@@ -219,8 +217,8 @@ export const ChatContainer = ({
</div>
</TooltipTrigger>
<TooltipContent side="top" className="max-w-sm">
- You&apos;ve reached your usage limit. Reset your daily limit
- or wait for it to refresh before sending more messages.
+ You&apos;ve reached your usage limit. Wait for it to refresh
+ or upgrade your plan to continue sending messages.
</TooltipContent>
</Tooltip>
</motion.div>
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/__tests__/ChatContainer.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/__tests__/ChatContainer.test.tsx
index 166331746a..92d2d3ce93 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/__tests__/ChatContainer.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/__tests__/ChatContainer.test.tsx
@@ -110,11 +110,17 @@ vi.mock("../../EmptySession/EmptySession", () => ({
EmptySession: () => <div data-testid="empty-session" />,
}));
-vi.mock("../../UsageLimits/UsageLimitReachedCard", () => ({
+vi.mock("../../UsageLimits/useIsUsageLimitReached", () => ({
useIsUsageLimitReached: () => mockIsUsageLimitReached(),
- UsageLimitReachedCard: () => <div role="alert">Usage limit reached</div>,
}));
+vi.mock(
+ "../../UsageLimits/UsageLimitReachedCard/UsageLimitReachedCard",
+ () => ({
+ UsageLimitReachedCard: () => <div role="alert">Usage limit reached</div>,
+ }),
+);
+
class MockResizeObserver {
observe() {}
disconnect() {}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/ChatSidebar.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/ChatSidebar.tsx
index a2b0db4ddc..0a6a38587b 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/ChatSidebar.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatSidebar/ChatSidebar.tsx
@@ -40,7 +40,7 @@ import { useCopilotUIStore } from "../../store";
import { useSessionDeletion } from "../../useSessionDeletion";
import { NotificationToggle } from "./components/NotificationToggle/NotificationToggle";
import { DeleteChatDialog } from "../DeleteChatDialog/DeleteChatDialog";
-import { UsageLimits } from "../UsageLimits/UsageLimits";
+import { UsagePopover } from "../UsageLimits/UsagePopover/UsagePopover";
export function ChatSidebar() {
const { state } = useSidebar();
@@ -229,7 +229,7 @@ export function ChatSidebar() {
Your chats
</Text>
<div className="flex items-center">
- <UsageLimits />
+ <UsagePopover />
<NotificationToggle />
<SidebarTrigger />
</div>
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/StorageBar.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/StorageBar.tsx
new file mode 100644
index 0000000000..fe5cf4f965
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/StorageBar.tsx
@@ -0,0 +1,46 @@
+"use client";
+
+import { Text } from "@/components/atoms/Text/Text";
+import { formatBytes } from "../usageHelpers";
+import { useWorkspaceStorage } from "./useWorkspaceStorage";
+
+export function StorageBar() {
+ const { data: storage } = useWorkspaceStorage();
+ if (!storage || storage.limit_bytes <= 0) return null;
+
+ const { used_bytes, limit_bytes, file_count } = storage;
+ const percent = Math.min(100, Math.round((used_bytes / limit_bytes) * 100));
+ const isHigh = percent >= 80;
+ const percentLabel =
+ used_bytes > 0 && percent === 0 ? "<1% used" : `${percent}% used`;
+
+ return (
+ <div className="flex flex-col gap-2">
+ <div className="flex items-baseline justify-between">
+ <Text variant="body-medium" className="text-neutral-700">
+ File storage
+ </Text>
+ <Text variant="body" className="tabular-nums text-neutral-500">
+ {percentLabel}
+ </Text>
+ </div>
+ <div className="h-2 w-full overflow-hidden rounded-full bg-neutral-200">
+ <div
+ role="progressbar"
+ aria-label="File storage usage"
+ aria-valuemin={0}
+ aria-valuemax={100}
+ aria-valuenow={percent}
+ className={`h-full rounded-full transition-[width] duration-300 ease-out ${
+ isHigh ? "bg-orange-500" : "bg-blue-500"
+ }`}
+ style={{ width: `${Math.max(used_bytes > 0 ? 1 : 0, percent)}%` }}
+ />
+ </div>
+ <Text variant="small" className="text-neutral-400">
+ {formatBytes(used_bytes)} of {formatBytes(limit_bytes)} &middot;{" "}
+ {file_count} {file_count === 1 ? "file" : "files"}
+ </Text>
+ </div>
+ );
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageBar.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageBar.tsx
new file mode 100644
index 0000000000..315b9ceb0f
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageBar.tsx
@@ -0,0 +1,44 @@
+import { Text } from "@/components/atoms/Text/Text";
+import { formatResetTime } from "../usageHelpers";
+
+interface Props {
+ label: string;
+ percentUsed: number;
+ resetsAt: Date | string;
+}
+
+export function UsageBar({ label, percentUsed, resetsAt }: Props) {
+ const percent = Math.min(100, Math.max(0, Math.round(percentUsed)));
+ const isHigh = percent >= 80;
+ const percentLabel =
+ percentUsed > 0 && percent === 0 ? "<1% used" : `${percent}% used`;
+
+ return (
+ <div className="flex flex-col gap-2">
+ <div className="flex items-baseline justify-between">
+ <Text variant="body-medium" className="text-neutral-700">
+ {label}
+ </Text>
+ <Text variant="body" className="tabular-nums text-neutral-500">
+ {percentLabel}
+ </Text>
+ </div>
+ <div className="h-2 w-full overflow-hidden rounded-full bg-neutral-200">
+ <div
+ role="progressbar"
+ aria-label={`${label} usage`}
+ aria-valuemin={0}
+ aria-valuemax={100}
+ aria-valuenow={percent}
+ className={`h-full rounded-full transition-[width] duration-300 ease-out ${
+ isHigh ? "bg-orange-500" : "bg-blue-500"
+ }`}
+ style={{ width: `${Math.max(percent > 0 ? 1 : 0, percent)}%` }}
+ />
+ </div>
+ <Text variant="small" className="text-neutral-400">
+ Resets {formatResetTime(resetsAt)}
+ </Text>
+ </div>
+ );
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimitReachedCard.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimitReachedCard.tsx
deleted file mode 100644
index 5670cccff5..0000000000
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimitReachedCard.tsx
+++ /dev/null
@@ -1,78 +0,0 @@
-"use client";
-
-import type { CoPilotUsagePublic } from "@/app/api/__generated__/models/coPilotUsagePublic";
-import { useGetV2GetCopilotUsage } from "@/app/api/__generated__/endpoints/chat/chat";
-import { Badge } from "@/components/atoms/Badge/Badge";
-import { Text } from "@/components/atoms/Text/Text";
-import { Warning } from "@phosphor-icons/react";
-import Link from "next/link";
-import { UsagePanelContent } from "./UsagePanelContent";
-
-const USAGE_QUERY_CONFIG = {
- query: {
- select: (res: { data: unknown }) => res.data as CoPilotUsagePublic,
- refetchInterval: 30000,
- staleTime: 10000,
- },
-} as const;
-
-export function useIsUsageLimitReached() {
- const { data: usage } = useGetV2GetCopilotUsage(USAGE_QUERY_CONFIG);
- const daily = usage?.daily?.percent_used ?? 0;
- const weekly = usage?.weekly?.percent_used ?? 0;
- return daily >= 100 || weekly >= 100;
-}
-
-export function UsageLimitReachedCard() {
- const { data: usage, isSuccess } =
- useGetV2GetCopilotUsage(USAGE_QUERY_CONFIG);
-
- if (!isSuccess || !usage) return null;
- const isDailyExhausted = !!usage.daily && usage.daily.percent_used >= 100;
- const isWeeklyExhausted = !!usage.weekly && usage.weekly.percent_used >= 100;
- if (!isDailyExhausted && !isWeeklyExhausted) return null;
-
- const tierLabel = usage.tier
- ? usage.tier.charAt(0) + usage.tier.slice(1).toLowerCase()
- : null;
-
- return (
- <div
- role="alert"
- className="mx-auto flex w-full max-w-[30rem] flex-col gap-3 rounded-2xl border border-orange-100 bg-white/70 p-4 shadow-[0_8px_32px_rgba(0,0,0,0.04)] backdrop-blur-md"
- >
- <div className="flex items-center justify-between gap-3">
- <div className="flex items-center gap-2">
- <Warning className="size-5 text-orange-500" weight="fill" />
- <Text
- as="span"
- variant="body-medium"
- className="font-semibold text-neutral-900"
- >
- Usage limit reached
- </Text>
- {tierLabel && (
- <Badge
- variant="info"
- size="small"
- className="border border-neutral-200"
- >
- {tierLabel}
- </Badge>
- )}
- </div>
- <Link href="/settings/billing" className="shrink-0 hover:underline">
- <Text as="span" variant="small" className="text-blue-600">
- Learn more about usage limits
- </Text>
- </Link>
- </div>
- <UsagePanelContent
- usage={usage}
- showHeader={false}
- showBillingLink={false}
- size="md"
- />
- </div>
- );
-}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimitReachedCard/UsageLimitReachedCard.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimitReachedCard/UsageLimitReachedCard.tsx
new file mode 100644
index 0000000000..989338e82d
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimitReachedCard/UsageLimitReachedCard.tsx
@@ -0,0 +1,68 @@
+"use client";
+
+import { Badge } from "@/components/atoms/Badge/Badge";
+import { Button } from "@/components/atoms/Button/Button";
+import { Text } from "@/components/atoms/Text/Text";
+import { WarningIcon } from "@phosphor-icons/react";
+import {
+ formatTierLabel,
+ isUsageExhausted,
+ TIER_BADGE_CLASS_NAME,
+} from "../../usageHelpers";
+import { StorageBar } from "../StorageBar";
+import { UsageBar } from "../UsageBar";
+import { useUsageLimitReachedCard } from "./useUsageLimitReachedCard";
+
+export function UsageLimitReachedCard() {
+ const { usage, isSuccess, isBillingEnabled } = useUsageLimitReachedCard();
+
+ if (!isSuccess || !usage) return null;
+ if (!isUsageExhausted(usage)) return null;
+
+ const tierLabel = formatTierLabel(usage.tier);
+
+ return (
+ <div
+ role="alert"
+ className="mx-auto flex w-full max-w-[30rem] flex-col gap-4 rounded-2xl border border-orange-100 bg-white/70 p-4 shadow-[0_8px_32px_rgba(0,0,0,0.04)] backdrop-blur-md"
+ >
+ <div className="flex items-center gap-2">
+ <WarningIcon className="size-5 text-orange-500" weight="fill" />
+ <Text variant="body-medium" className="text-neutral-900">
+ Usage limit reached
+ </Text>
+ {tierLabel && (
+ <Badge variant="info" size="small" className={TIER_BADGE_CLASS_NAME}>
+ {tierLabel} plan
+ </Badge>
+ )}
+ </div>
+ {usage.daily && (
+ <UsageBar
+ label="Today"
+ percentUsed={usage.daily.percent_used}
+ resetsAt={usage.daily.resets_at}
+ />
+ )}
+ {usage.weekly && (
+ <UsageBar
+ label="This week"
+ percentUsed={usage.weekly.percent_used}
+ resetsAt={usage.weekly.resets_at}
+ />
+ )}
+ <StorageBar />
+ {isBillingEnabled && (
+ <Button
+ as="NextLink"
+ href="/settings/billing"
+ variant="primary"
+ size="small"
+ className="mt-1 w-full"
+ >
+ Go to billing
+ </Button>
+ )}
+ </div>
+ );
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimitReachedCard/__tests__/UsageLimitReachedCard.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimitReachedCard/__tests__/UsageLimitReachedCard.test.tsx
new file mode 100644
index 0000000000..0c853d7d39
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimitReachedCard/__tests__/UsageLimitReachedCard.test.tsx
@@ -0,0 +1,114 @@
+import { http, HttpResponse, type JsonBodyType } from "msw";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { server } from "@/mocks/mock-server";
+import { render, screen, waitFor } from "@/tests/integrations/test-utils";
+import { UsageLimitReachedCard } from "../UsageLimitReachedCard";
+
+const mockUseGetFlag = vi.fn();
+vi.mock("@/services/feature-flags/use-get-flag", async () => {
+ const actual = await vi.importActual<
+ typeof import("@/services/feature-flags/use-get-flag")
+ >("@/services/feature-flags/use-get-flag");
+ return {
+ ...actual,
+ useGetFlag: (flag: unknown) => mockUseGetFlag(flag),
+ };
+});
+
+vi.mock("../../StorageBar", () => ({
+ StorageBar: () => null,
+}));
+
+afterEach(() => {
+ mockUseGetFlag.mockReset();
+});
+
+beforeEach(() => {
+ mockUseGetFlag.mockReturnValue(true);
+});
+
+interface UsageOverrides {
+ dailyPercent?: number | null;
+ weeklyPercent?: number | null;
+ tier?: string | null;
+}
+
+function makeUsage({
+ dailyPercent = 100,
+ weeklyPercent = 40,
+ tier = "BASIC",
+}: UsageOverrides = {}) {
+ const future = new Date(Date.now() + 3600 * 1000).toISOString();
+ return {
+ daily:
+ dailyPercent === null
+ ? null
+ : { percent_used: dailyPercent, resets_at: future },
+ weekly:
+ weeklyPercent === null
+ ? null
+ : { percent_used: weeklyPercent, resets_at: future },
+ tier,
+ };
+}
+
+function mockUsageResponse(body: JsonBodyType) {
+ server.use(http.get("*/api/chat/usage", () => HttpResponse.json(body)));
+}
+
+describe("UsageLimitReachedCard", () => {
+ it("renders nothing on the first paint while data is loading", () => {
+ mockUsageResponse(makeUsage());
+ const { container } = render(<UsageLimitReachedCard />);
+ expect(container.innerHTML).toBe("");
+ });
+
+ it("renders nothing when neither daily nor weekly is exhausted", async () => {
+ mockUsageResponse(makeUsage({ dailyPercent: 5, weeklyPercent: 4 }));
+ const { container } = render(<UsageLimitReachedCard />);
+ await waitFor(() => expect(container.innerHTML).toBe(""));
+ });
+
+ it("renders the alert with daily and weekly bars when the daily limit is reached", async () => {
+ mockUsageResponse(makeUsage());
+ render(<UsageLimitReachedCard />);
+
+ expect(await screen.findByRole("alert")).toBeDefined();
+ expect(screen.getByText("Usage limit reached")).toBeDefined();
+ expect(screen.getByText("Today")).toBeDefined();
+ expect(screen.getByText("This week")).toBeDefined();
+ });
+
+ it("always shows the 'Go to billing' button when billing is enabled", async () => {
+ mockUsageResponse(makeUsage());
+ render(<UsageLimitReachedCard />);
+
+ const link = (await screen.findByText("Go to billing")).closest("a");
+ expect(link).not.toBeNull();
+ expect(link?.getAttribute("href")).toBe("/settings/billing");
+ });
+
+ it("hides the 'Go to billing' button when billing is disabled at the platform level", async () => {
+ mockUseGetFlag.mockReturnValue(false);
+ mockUsageResponse(makeUsage());
+ render(<UsageLimitReachedCard />);
+
+ expect(await screen.findByRole("alert")).toBeDefined();
+ expect(screen.queryByText("Go to billing")).toBeNull();
+ });
+
+ it("renders the tier badge when a tier is set", async () => {
+ mockUsageResponse(makeUsage({ tier: "PRO" }));
+ render(<UsageLimitReachedCard />);
+
+ expect(await screen.findByText("Pro plan")).toBeDefined();
+ });
+
+ it("never renders the legacy 'Reset daily limit' control", async () => {
+ mockUsageResponse(makeUsage());
+ render(<UsageLimitReachedCard />);
+
+ expect(await screen.findByRole("alert")).toBeDefined();
+ expect(screen.queryByText(/Reset daily limit/i)).toBeNull();
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimitReachedCard/useUsageLimitReachedCard.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimitReachedCard/useUsageLimitReachedCard.ts
new file mode 100644
index 0000000000..d84222b086
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimitReachedCard/useUsageLimitReachedCard.ts
@@ -0,0 +1,9 @@
+import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";
+import { useCopilotUsage } from "../useCopilotUsage";
+
+export function useUsageLimitReachedCard() {
+ const { data: usage, isSuccess } = useCopilotUsage();
+ const isBillingEnabled = useGetFlag(Flag.ENABLE_PLATFORM_PAYMENT);
+
+ return { usage, isSuccess, isBillingEnabled };
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimits.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimits.tsx
deleted file mode 100644
index 4eb13ac548..0000000000
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsageLimits.tsx
+++ /dev/null
@@ -1,38 +0,0 @@
-import type { CoPilotUsagePublic } from "@/app/api/__generated__/models/coPilotUsagePublic";
-import { useGetV2GetCopilotUsage } from "@/app/api/__generated__/endpoints/chat/chat";
-import {
- Popover,
- PopoverContent,
- PopoverTrigger,
-} from "@/components/molecules/Popover/Popover";
-import { Button } from "@/components/ui/button";
-import { ChartBar } from "@phosphor-icons/react";
-import { UsagePanelContent } from "./UsagePanelContent";
-
-export { UsagePanelContent, formatResetTime } from "./UsagePanelContent";
-
-export function UsageLimits() {
- const { data: usage, isSuccess } = useGetV2GetCopilotUsage({
- query: {
- select: (res) => res.data as CoPilotUsagePublic,
- refetchInterval: 30000,
- staleTime: 10000,
- },
- });
-
- if (!isSuccess || !usage) return null;
- if (!usage.daily && !usage.weekly) return null;
-
- return (
- <Popover>
- <PopoverTrigger asChild>
- <Button variant="ghost" size="icon" aria-label="Usage limits">
- <ChartBar className="!size-5" weight="light" />
- </Button>
- </PopoverTrigger>
- <PopoverContent align="start" className="w-64 p-3">
- <UsagePanelContent usage={usage} />
- </PopoverContent>
- </Popover>
- );
-}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePanelContent.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePanelContent.tsx
deleted file mode 100644
index 86fb536e75..0000000000
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePanelContent.tsx
+++ /dev/null
@@ -1,232 +0,0 @@
-import type { CoPilotUsagePublic } from "@/app/api/__generated__/models/coPilotUsagePublic";
-import { Button } from "@/components/atoms/Button/Button";
-import { Text } from "@/components/atoms/Text/Text";
-import { cn } from "@/lib/utils";
-import Link from "next/link";
-import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";
-import { formatResetTime } from "../usageHelpers";
-import { useWorkspaceStorage } from "./useWorkspaceStorage";
-
-export { formatResetTime };
-
-type Size = "sm" | "md";
-
-const labelVariant = (size: Size) =>
- size === "md" ? "body-medium" : "small-medium";
-const metaVariant = "small" as const;
-
-function UsageBar({
- label,
- percentUsed,
- resetsAt,
- size = "sm",
-}: {
- label: string;
- percentUsed: number;
- resetsAt: Date | string;
- size?: Size;
-}) {
- const percent = Math.min(100, Math.max(0, Math.round(percentUsed)));
- const percentLabel =
- percentUsed > 0 && percent === 0 ? "<1% used" : `${percent}% used`;
-
- return (
- <div className="flex flex-col gap-1">
- <div className="flex items-baseline justify-between">
- <Text
- as="span"
- variant={labelVariant(size)}
- className="text-neutral-700"
- >
- {label}
- </Text>
- <Text
- as="span"
- variant={metaVariant}
- className="tabular-nums text-neutral-500"
- >
- {percentLabel}
- </Text>
- </div>
- <Text as="span" variant={metaVariant} className="text-neutral-400">
- Resets {formatResetTime(resetsAt)}
- </Text>
- <div
- className={cn(
- "w-full overflow-hidden rounded-full bg-neutral-200",
- size === "md" ? "h-2.5" : "h-2",
- )}
- >
- <div
- role="progressbar"
- aria-label={`${label} usage`}
- aria-valuemin={0}
- aria-valuemax={100}
- aria-valuenow={percent}
- className="h-full rounded-full bg-blue-500 transition-[width] duration-300 ease-out"
- style={{ width: `${Math.max(percent > 0 ? 1 : 0, percent)}%` }}
- />
- </div>
- </div>
- );
-}
-
-export function formatBytes(bytes: number): string {
- const KB = 1024;
- const MB = KB * 1024;
- const GB = MB * 1024;
- if (bytes < KB) return `${bytes} B`;
- if (bytes < MB) {
- const kb = Math.round(bytes / KB);
- return kb >= 1024 ? `${(bytes / MB).toFixed(1)} MB` : `${kb} KB`;
- }
- if (bytes < GB) {
- const mb = Math.round(bytes / MB);
- return mb >= 1024 ? `${(bytes / GB).toFixed(1)} GB` : `${mb} MB`;
- }
- return `${(bytes / GB).toFixed(1)} GB`;
-}
-
-function StorageBar({
- usedBytes,
- limitBytes,
- fileCount,
-}: {
- usedBytes: number;
- limitBytes: number;
- fileCount: number;
-}) {
- if (limitBytes <= 0) return null;
-
- const rawPercent = (usedBytes / limitBytes) * 100;
- const percent = Math.min(100, Math.round(rawPercent));
- const isHigh = percent >= 80;
- const percentLabel =
- usedBytes > 0 && percent === 0 ? "<1% used" : `${percent}% used`;
-
- return (
- <div className="flex flex-col gap-1">
- <div className="flex items-baseline justify-between">
- <span className="text-xs font-medium text-neutral-700">
- File storage
- </span>
- <span className="text-[11px] tabular-nums text-neutral-500">
- {percentLabel}
- </span>
- </div>
- <div className="text-[10px] text-neutral-400">
- {formatBytes(usedBytes)} of {formatBytes(limitBytes)} &middot;{" "}
- {fileCount} {fileCount === 1 ? "file" : "files"}
- </div>
- <div className="h-2 w-full overflow-hidden rounded-full bg-neutral-200">
- <div
- className={`h-full rounded-full transition-[width] duration-300 ease-out ${
- isHigh ? "bg-orange-500" : "bg-blue-500"
- }`}
- style={{ width: `${Math.max(usedBytes > 0 ? 1 : 0, percent)}%` }}
- />
- </div>
- </div>
- );
-}
-
-function WorkspaceStorageSection() {
- const { data: storage } = useWorkspaceStorage();
- if (!storage || storage.limit_bytes <= 0) return null;
-
- return (
- <StorageBar
- usedBytes={storage.used_bytes}
- limitBytes={storage.limit_bytes}
- fileCount={storage.file_count}
- />
- );
-}
-
-export function UsagePanelContent({
- usage,
- showHeader = true,
- showBillingLink = true,
- size = "sm",
-}: {
- usage: CoPilotUsagePublic;
- showHeader?: boolean;
- showBillingLink?: boolean;
- size?: Size;
-}) {
- const isBillingEnabled = useGetFlag(Flag.ENABLE_PLATFORM_PAYMENT);
- const daily = usage.daily;
- const weekly = usage.weekly;
- const isDailyExhausted = !!daily && daily.percent_used >= 100;
-
- if (!daily && !weekly) {
- return (
- <div className="flex flex-col gap-3">
- <Text as="span" variant="small" className="text-neutral-500">
- No usage limits configured
- </Text>
- <WorkspaceStorageSection />
- </div>
- );
- }
-
- const tierLabel = usage.tier
- ? usage.tier.charAt(0) + usage.tier.slice(1).toLowerCase()
- : null;
-
- return (
- <div className="flex flex-col gap-3">
- {showHeader && (
- <div className="flex items-baseline justify-between">
- <Text
- as="span"
- variant={size === "md" ? "body-medium" : "small-medium"}
- className="font-semibold text-neutral-800"
- >
- Usage limits
- </Text>
- {tierLabel && (
- <Text as="span" variant="small" className="text-neutral-500">
- {tierLabel} plan
- </Text>
- )}
- </div>
- )}
- {daily && (
- <UsageBar
- label="Today"
- percentUsed={daily.percent_used}
- resetsAt={daily.resets_at}
- size={size}
- />
- )}
- {weekly && (
- <UsageBar
- label="This week"
- percentUsed={weekly.percent_used}
- resetsAt={weekly.resets_at}
- size={size}
- />
- )}
- <WorkspaceStorageSection />
- {isDailyExhausted && isBillingEnabled && showBillingLink && (
- <Button
- as="NextLink"
- href="/settings/billing"
- variant="primary"
- size="small"
- className="mt-1 w-full"
- >
- Go to billing
- </Button>
- )}
- {showBillingLink && !(isDailyExhausted && isBillingEnabled) && (
- <Link href="/settings/billing" className="hover:underline">
- <Text as="span" variant="small" className="text-blue-600">
- Learn more about usage limits
- </Text>
- </Link>
- )}
- </div>
- );
-}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePopover/UsagePopover.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePopover/UsagePopover.tsx
new file mode 100644
index 0000000000..ff9f87cffa
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePopover/UsagePopover.tsx
@@ -0,0 +1,76 @@
+"use client";
+
+import { Badge } from "@/components/atoms/Badge/Badge";
+import { Button } from "@/components/atoms/Button/Button";
+import { Text } from "@/components/atoms/Text/Text";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/molecules/Popover/Popover";
+import { ChartBarIcon } from "@phosphor-icons/react";
+import Link from "next/link";
+import { formatTierLabel, TIER_BADGE_CLASS_NAME } from "../../usageHelpers";
+import { StorageBar } from "../StorageBar";
+import { UsageBar } from "../UsageBar";
+import { useUsagePopover } from "./useUsagePopover";
+
+export function UsagePopover() {
+ const { usage, isSuccess, isBillingEnabled } = useUsagePopover();
+
+ if (!isSuccess || !usage) return null;
+ if (!usage.daily && !usage.weekly) return null;
+
+ const tierLabel = formatTierLabel(usage.tier);
+
+ return (
+ <Popover>
+ <PopoverTrigger asChild>
+ <Button variant="ghost" size="icon" aria-label="Usage limits">
+ <ChartBarIcon className="!size-5" weight="light" />
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent align="start" className="w-72 p-4">
+ <div className="flex flex-col gap-4">
+ <div className="flex items-center gap-2">
+ <Text variant="body-medium" className="text-neutral-800">
+ Usage limits
+ </Text>
+ {tierLabel && (
+ <Badge
+ variant="info"
+ size="small"
+ className={TIER_BADGE_CLASS_NAME}
+ >
+ {tierLabel} plan
+ </Badge>
+ )}
+ </div>
+ {usage.daily && (
+ <UsageBar
+ label="Today"
+ percentUsed={usage.daily.percent_used}
+ resetsAt={usage.daily.resets_at}
+ />
+ )}
+ {usage.weekly && (
+ <UsageBar
+ label="This week"
+ percentUsed={usage.weekly.percent_used}
+ resetsAt={usage.weekly.resets_at}
+ />
+ )}
+ <StorageBar />
+ {isBillingEnabled && (
+ <Link
+ href="/settings/billing"
+ className="text-sm text-blue-600 hover:underline"
+ >
+ Manage billing
+ </Link>
+ )}
+ </div>
+ </PopoverContent>
+ </Popover>
+ );
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePopover/__tests__/UsagePopover.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePopover/__tests__/UsagePopover.test.tsx
new file mode 100644
index 0000000000..6e2e408727
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePopover/__tests__/UsagePopover.test.tsx
@@ -0,0 +1,148 @@
+import { http, HttpResponse, type JsonBodyType } from "msw";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { server } from "@/mocks/mock-server";
+import { render, screen, waitFor } from "@/tests/integrations/test-utils";
+import { UsagePopover } from "../UsagePopover";
+
+const mockUseGetFlag = vi.fn();
+vi.mock("@/services/feature-flags/use-get-flag", async () => {
+ const actual = await vi.importActual<
+ typeof import("@/services/feature-flags/use-get-flag")
+ >("@/services/feature-flags/use-get-flag");
+ return {
+ ...actual,
+ useGetFlag: (flag: unknown) => mockUseGetFlag(flag),
+ };
+});
+
+afterEach(() => {
+ mockUseGetFlag.mockReset();
+});
+
+beforeEach(() => {
+ mockUseGetFlag.mockReturnValue(true);
+});
+
+vi.mock("../../StorageBar", () => ({
+ StorageBar: () => null,
+}));
+
+vi.mock("@/components/molecules/Popover/Popover", () => {
+ function Popover({ children }: { children: React.ReactNode }) {
+ return <div>{children}</div>;
+ }
+ function PopoverTrigger({ children }: { children: React.ReactNode }) {
+ return <div>{children}</div>;
+ }
+ function PopoverContent({ children }: { children: React.ReactNode }) {
+ return <div>{children}</div>;
+ }
+ return { Popover, PopoverTrigger, PopoverContent };
+});
+
+interface UsageOverrides {
+ dailyPercent?: number | null;
+ weeklyPercent?: number | null;
+ tier?: string | null;
+}
+
+function makeUsage({
+ dailyPercent = 5,
+ weeklyPercent = 4,
+ tier = "BASIC",
+}: UsageOverrides = {}) {
+ const future = new Date(Date.now() + 3600 * 1000).toISOString();
+ return {
+ daily:
+ dailyPercent === null
+ ? null
+ : { percent_used: dailyPercent, resets_at: future },
+ weekly:
+ weeklyPercent === null
+ ? null
+ : { percent_used: weeklyPercent, resets_at: future },
+ tier,
+ };
+}
+
+function mockUsageResponse(body: JsonBodyType) {
+ server.use(http.get("*/api/chat/usage", () => HttpResponse.json(body)));
+}
+
+describe("UsagePopover", () => {
+ it("renders nothing on the first paint while data is loading", () => {
+ mockUsageResponse(makeUsage({ dailyPercent: 50 }));
+ const { container } = render(<UsagePopover />);
+ expect(container.innerHTML).toBe("");
+ });
+
+ it("renders nothing when no limits are configured", async () => {
+ mockUsageResponse(makeUsage({ dailyPercent: null, weeklyPercent: null }));
+ const { container } = render(<UsagePopover />);
+ await waitFor(() => expect(container.innerHTML).toBe(""));
+ });
+
+ it("renders the trigger button and panel when limits exist", async () => {
+ mockUsageResponse(makeUsage({ dailyPercent: 50 }));
+ render(<UsagePopover />);
+
+ expect(
+ await screen.findByRole("button", { name: /usage limits/i }),
+ ).toBeDefined();
+ expect(screen.getByText("Usage limits")).toBeDefined();
+ expect(screen.getByText("Today")).toBeDefined();
+ expect(screen.getByText("This week")).toBeDefined();
+ expect(screen.getByText("50% used")).toBeDefined();
+ });
+
+ it("shows only the weekly bar when daily is null", async () => {
+ mockUsageResponse(makeUsage({ dailyPercent: null, weeklyPercent: 50 }));
+ render(<UsagePopover />);
+
+ expect(await screen.findByText("This week")).toBeDefined();
+ expect(screen.queryByText("Today")).toBeNull();
+ });
+
+ it("caps the bar width at 100% when over the limit", async () => {
+ mockUsageResponse(makeUsage({ dailyPercent: 150 }));
+ render(<UsagePopover />);
+
+ const dailyBar = await screen.findByRole("progressbar", {
+ name: /today usage/i,
+ });
+ expect(dailyBar.getAttribute("aria-valuenow")).toBe("100");
+ });
+
+ it("renders the tier label", async () => {
+ mockUsageResponse(makeUsage({ tier: "PRO" }));
+ render(<UsagePopover />);
+
+ expect(await screen.findByText("Pro plan")).toBeDefined();
+ });
+
+ it("never renders the 'Go to billing' button (handled by the card)", async () => {
+ mockUsageResponse(makeUsage({ dailyPercent: 100 }));
+ render(<UsagePopover />);
+
+ expect(await screen.findByText("Today")).toBeDefined();
+ expect(screen.queryByText("Go to billing")).toBeNull();
+ });
+
+ it("renders a 'Manage billing' link when billing is enabled", async () => {
+ mockUsageResponse(makeUsage());
+ render(<UsagePopover />);
+
+ const link = (await screen.findByText("Manage billing")).closest("a");
+ expect(link).not.toBeNull();
+ expect(link?.getAttribute("href")).toBe("/settings/billing");
+ });
+
+ it("hides the 'Manage billing' link when billing is disabled at the platform level", async () => {
+ mockUseGetFlag.mockReturnValue(false);
+ mockUsageResponse(makeUsage());
+ render(<UsagePopover />);
+
+ expect(await screen.findByText("Today")).toBeDefined();
+ expect(screen.queryByText("Manage billing")).toBeNull();
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePopover/useUsagePopover.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePopover/useUsagePopover.ts
new file mode 100644
index 0000000000..d71107c226
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/UsagePopover/useUsagePopover.ts
@@ -0,0 +1,8 @@
+import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";
+import { useCopilotUsage } from "../useCopilotUsage";
+
+export function useUsagePopover() {
+ const { data: usage, isSuccess } = useCopilotUsage();
+ const isBillingEnabled = useGetFlag(Flag.ENABLE_PLATFORM_PAYMENT);
+ return { usage, isSuccess, isBillingEnabled };
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/__tests__/UsageLimits.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/__tests__/UsageLimits.test.tsx
deleted file mode 100644
index eff3fe4801..0000000000
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/__tests__/UsageLimits.test.tsx
+++ /dev/null
@@ -1,146 +0,0 @@
-import { render, screen, cleanup } from "@/tests/integrations/test-utils";
-import { afterEach, describe, expect, it, vi } from "vitest";
-import { UsageLimits } from "../UsageLimits";
-
-// Mock the generated Orval hook, exercising the `select` callback so its
-// line counts as covered alongside the rest of the options.
-const mockUseGetV2GetCopilotUsage = vi.fn();
-vi.mock("@/app/api/__generated__/endpoints/chat/chat", () => ({
- useGetV2GetCopilotUsage: (opts: {
- query?: { select?: (r: { data: unknown }) => unknown };
- }) => {
- const ret = mockUseGetV2GetCopilotUsage(opts) as { data?: unknown };
- if (ret?.data !== undefined && typeof opts?.query?.select === "function") {
- opts.query.select({ data: ret.data });
- }
- return ret;
- },
-}));
-
-// Mock Popover to render children directly (Radix portals don't work in happy-dom)
-vi.mock("@/components/molecules/Popover/Popover", () => ({
- Popover: ({ children }: { children: React.ReactNode }) => (
- <div>{children}</div>
- ),
- PopoverTrigger: ({ children }: { children: React.ReactNode }) => (
- <div>{children}</div>
- ),
- PopoverContent: ({ children }: { children: React.ReactNode }) => (
- <div>{children}</div>
- ),
-}));
-
-afterEach(() => {
- cleanup();
- mockUseGetV2GetCopilotUsage.mockReset();
-});
-
-function makeUsage({
- dailyPercent = 5,
- weeklyPercent = 4,
- tier = "BASIC",
-}: {
- dailyPercent?: number | null;
- weeklyPercent?: number | null;
- tier?: string;
-} = {}) {
- const future = new Date(Date.now() + 3600 * 1000).toISOString();
- return {
- daily:
- dailyPercent === null
- ? null
- : { percent_used: dailyPercent, resets_at: future },
- weekly:
- weeklyPercent === null
- ? null
- : { percent_used: weeklyPercent, resets_at: future },
- tier,
- };
-}
-
-describe("UsageLimits", () => {
- it("renders nothing while loading", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: undefined,
- isSuccess: false,
- });
- const { container } = render(<UsageLimits />);
- expect(container.innerHTML).toBe("");
- });
-
- it("renders nothing when no limits are configured", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: makeUsage({ dailyPercent: null, weeklyPercent: null }),
- isSuccess: true,
- });
- const { container } = render(<UsageLimits />);
- expect(container.innerHTML).toBe("");
- });
-
- it("renders the usage button when limits exist", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: makeUsage(),
- isSuccess: true,
- });
- render(<UsageLimits />);
- expect(screen.getByRole("button", { name: /usage limits/i })).toBeDefined();
- });
-
- it("displays daily and weekly percentage", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: makeUsage({ dailyPercent: 50, weeklyPercent: 4 }),
- isSuccess: true,
- });
- render(<UsageLimits />);
-
- expect(screen.getByText("50% used")).toBeDefined();
- expect(screen.getByText("Today")).toBeDefined();
- expect(screen.getByText("This week")).toBeDefined();
- expect(screen.getByText("Usage limits")).toBeDefined();
- });
-
- it("shows only weekly bar when daily is null", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: makeUsage({ dailyPercent: null, weeklyPercent: 50 }),
- isSuccess: true,
- });
- render(<UsageLimits />);
-
- expect(screen.getByText("This week")).toBeDefined();
- expect(screen.queryByText("Today")).toBeNull();
- });
-
- it("caps bar width at 100% when over limit", () => {
- // 150% exercises the clamp — 100% exactly is merely exhausted, not over.
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: makeUsage({ dailyPercent: 150 }),
- isSuccess: true,
- });
- render(<UsageLimits />);
-
- const dailyBar = screen.getByRole("progressbar", { name: /today usage/i });
- expect(dailyBar.getAttribute("aria-valuenow")).toBe("100");
- });
-
- it("displays the user tier label", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: makeUsage({ tier: "PRO" }),
- isSuccess: true,
- });
- render(<UsageLimits />);
-
- expect(screen.getByText("Pro plan")).toBeDefined();
- });
-
- it("shows learn more link to billing page", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: makeUsage(),
- isSuccess: true,
- });
- render(<UsageLimits />);
-
- const link = screen.getByText("Learn more about usage limits");
- expect(link).toBeDefined();
- expect(link.closest("a")?.getAttribute("href")).toBe("/settings/billing");
- });
-});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/__tests__/UsagePanelContent.test.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/__tests__/UsagePanelContent.test.ts
deleted file mode 100644
index 4473a78959..0000000000
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/__tests__/UsagePanelContent.test.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import { describe, expect, it } from "vitest";
-import { formatResetTime } from "../UsagePanelContent";
-
-describe("formatResetTime", () => {
- const now = new Date("2025-06-15T12:00:00Z");
-
- it("returns 'now' when reset time is in the past", () => {
- expect(formatResetTime("2025-06-15T11:00:00Z", now)).toBe("now");
- });
-
- it("returns minutes only when under 1 hour", () => {
- const result = formatResetTime("2025-06-15T12:30:00Z", now);
- expect(result).toBe("in 30m");
- });
-
- it("returns hours and minutes when under 24 hours", () => {
- const result = formatResetTime("2025-06-15T16:45:00Z", now);
- expect(result).toBe("in 4h 45m");
- });
-
- it("returns formatted date when over 24 hours away", () => {
- const resetsAt = "2025-06-17T00:00:00Z";
- const result = formatResetTime(resetsAt, now);
- const expected = new Date(resetsAt).toLocaleString(undefined, {
- weekday: "short",
- hour: "numeric",
- minute: "2-digit",
- timeZoneName: "short",
- });
-
- expect(result).toBe(expected);
- });
-
- it("accepts a Date object for resetsAt", () => {
- const resetDate = new Date("2025-06-15T14:00:00Z");
- expect(formatResetTime(resetDate, now)).toBe("in 2h 0m");
- });
-});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/__tests__/UsagePanelContentRender.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/__tests__/UsagePanelContentRender.test.tsx
deleted file mode 100644
index a1e13acc9d..0000000000
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/__tests__/UsagePanelContentRender.test.tsx
+++ /dev/null
@@ -1,258 +0,0 @@
-import { render, screen } from "@/tests/integrations/test-utils";
-import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
-import { UsagePanelContent, formatBytes } from "../UsagePanelContent";
-import type { CoPilotUsagePublic } from "@/app/api/__generated__/models/coPilotUsagePublic";
-
-const mockStorageData = vi.fn();
-vi.mock("../useWorkspaceStorage", () => ({
- useWorkspaceStorage: () => mockStorageData(),
-}));
-
-const mockUseGetFlag = vi.fn();
-vi.mock("@/services/feature-flags/use-get-flag", async () => {
- const actual = await vi.importActual<
- typeof import("@/services/feature-flags/use-get-flag")
- >("@/services/feature-flags/use-get-flag");
- return {
- ...actual,
- useGetFlag: (flag: unknown) => mockUseGetFlag(flag),
- };
-});
-
-afterEach(() => {
- mockStorageData.mockReset();
- mockUseGetFlag.mockReset();
-});
-
-beforeEach(() => {
- mockStorageData.mockReturnValue({ data: undefined });
- mockUseGetFlag.mockReturnValue(true);
-});
-
-function makeUsage(
- overrides: Partial<{
- dailyPercent: number | null;
- weeklyPercent: number | null;
- tier: string;
- }> = {},
-): CoPilotUsagePublic {
- const { dailyPercent = 5, weeklyPercent = 4, tier = "BASIC" } = overrides;
- const future = new Date(Date.now() + 3600 * 1000).toISOString();
- return {
- daily:
- dailyPercent === null
- ? null
- : { percent_used: dailyPercent, resets_at: future },
- weekly:
- weeklyPercent === null
- ? null
- : { percent_used: weeklyPercent, resets_at: future },
- tier,
- } as CoPilotUsagePublic;
-}
-
-describe("formatBytes", () => {
- it.each([
- [0, "0 B"],
- [512, "512 B"],
- [1024, "1 KB"],
- [250 * 1024, "250 KB"],
- [1023 * 1024, "1023 KB"],
- [1000 * 1024, "1000 KB"],
- [1024 * 1024, "1 MB"],
- [250 * 1024 * 1024, "250 MB"],
- [1000 * 1024 * 1024, "1000 MB"],
- [1024 * 1024 * 1024, "1.0 GB"],
- [5 * 1024 * 1024 * 1024, "5.0 GB"],
- [15 * 1024 * 1024 * 1024, "15.0 GB"],
- ])("formats %d bytes as %s", (input, expected) => {
- expect(formatBytes(input)).toBe(expected);
- });
-});
-
-describe("UsagePanelContent", () => {
- it("renders 'No usage limits configured' when both windows are null", () => {
- render(
- <UsagePanelContent
- usage={makeUsage({ dailyPercent: null, weeklyPercent: null })}
- />,
- );
- expect(screen.getByText("No usage limits configured")).toBeDefined();
- });
-
- it("still renders file storage when usage windows are null", () => {
- mockStorageData.mockReturnValue({
- data: {
- used_bytes: 100 * 1024 * 1024,
- limit_bytes: 250 * 1024 * 1024,
- used_percent: 40,
- file_count: 5,
- },
- });
-
- render(
- <UsagePanelContent
- usage={makeUsage({ dailyPercent: null, weeklyPercent: null })}
- />,
- );
-
- expect(screen.getByText("No usage limits configured")).toBeDefined();
- expect(screen.getByText("File storage")).toBeDefined();
- });
-
- it("never renders the legacy 'Reset daily limit' button", () => {
- render(<UsagePanelContent usage={makeUsage({ dailyPercent: 100 })} />);
- expect(screen.queryByText(/Reset daily limit/)).toBeNull();
- });
-
- it("renders 'Go to billing' when daily is exhausted and billing is enabled", () => {
- mockUseGetFlag.mockReturnValue(true);
- render(
- <UsagePanelContent
- usage={makeUsage({ dailyPercent: 100, weeklyPercent: 40 })}
- />,
- );
- expect(screen.getByText("Go to billing")).toBeDefined();
- });
-
- it("hides the 'Learn more about usage limits' link when 'Go to billing' button is shown", () => {
- mockUseGetFlag.mockReturnValue(true);
- render(
- <UsagePanelContent
- usage={makeUsage({ dailyPercent: 100, weeklyPercent: 40 })}
- />,
- );
- expect(screen.getByText("Go to billing")).toBeDefined();
- expect(screen.queryByText("Learn more about usage limits")).toBeNull();
- });
-
- it("does not render 'Go to billing' when showBillingLink is false", () => {
- mockUseGetFlag.mockReturnValue(true);
- render(
- <UsagePanelContent
- usage={makeUsage({ dailyPercent: 100, weeklyPercent: 40 })}
- showBillingLink={false}
- />,
- );
- expect(screen.queryByText("Go to billing")).toBeNull();
- });
-
- it("does not render 'Go to billing' when billing flag is disabled", () => {
- mockUseGetFlag.mockReturnValue(false);
- render(
- <UsagePanelContent
- usage={makeUsage({ dailyPercent: 100, weeklyPercent: 40 })}
- />,
- );
- expect(screen.queryByText("Go to billing")).toBeNull();
- });
-
- it("still renders 'Go to billing' when both daily and weekly are exhausted", () => {
- render(
- <UsagePanelContent
- usage={makeUsage({ dailyPercent: 100, weeklyPercent: 100 })}
- />,
- );
- expect(screen.getByText("Go to billing")).toBeDefined();
- });
-
- it("renders percent used in the usage bar", () => {
- render(<UsagePanelContent usage={makeUsage({ dailyPercent: 25 })} />);
- expect(screen.getByText("25% used")).toBeDefined();
- });
-
- it("renders '<1% used' when usage is greater than 0 but rounds to 0", () => {
- render(<UsagePanelContent usage={makeUsage({ dailyPercent: 0.3 })} />);
- expect(screen.getByText("<1% used")).toBeDefined();
- });
-
- it("renders file storage bar when workspace data is available", () => {
- mockStorageData.mockReturnValue({
- data: {
- used_bytes: 100 * 1024 * 1024,
- limit_bytes: 250 * 1024 * 1024,
- used_percent: 40,
- file_count: 5,
- },
- });
-
- render(<UsagePanelContent usage={makeUsage()} />);
- expect(screen.getByText("File storage")).toBeDefined();
- expect(screen.getByText(/100 MB of 250 MB/)).toBeDefined();
- expect(screen.getByText(/5 files/)).toBeDefined();
- });
-
- it("hides file storage bar when no workspace data", () => {
- mockStorageData.mockReturnValue({ data: undefined });
-
- render(<UsagePanelContent usage={makeUsage()} />);
- expect(screen.queryByText("File storage")).toBeNull();
- });
-
- it("hides file storage bar when limit is zero", () => {
- mockStorageData.mockReturnValue({
- data: {
- used_bytes: 0,
- limit_bytes: 0,
- used_percent: 0,
- file_count: 0,
- },
- });
-
- render(<UsagePanelContent usage={makeUsage()} />);
- expect(screen.queryByText("File storage")).toBeNull();
- });
-
- it("shows orange bar when storage usage is at or above 80%", () => {
- mockStorageData.mockReturnValue({
- data: {
- used_bytes: 210 * 1024 * 1024,
- limit_bytes: 250 * 1024 * 1024,
- used_percent: 84,
- file_count: 3,
- },
- });
-
- render(<UsagePanelContent usage={makeUsage()} />);
- expect(screen.getByText("File storage")).toBeDefined();
- expect(screen.getByText("84% used")).toBeDefined();
- });
-
- it("shows singular 'file' for single file", () => {
- mockStorageData.mockReturnValue({
- data: {
- used_bytes: 1024,
- limit_bytes: 250 * 1024 * 1024,
- used_percent: 0,
- file_count: 1,
- },
- });
-
- render(<UsagePanelContent usage={makeUsage()} />);
- expect(screen.getByText(/1 file$/)).toBeDefined();
- });
-
- it("shows storage '<1% used' when usage is tiny", () => {
- mockStorageData.mockReturnValue({
- data: {
- used_bytes: 100,
- limit_bytes: 250 * 1024 * 1024,
- used_percent: 0.001,
- file_count: 1,
- },
- });
-
- render(<UsagePanelContent usage={makeUsage()} />);
- expect(screen.getByText("File storage")).toBeDefined();
- });
-
- it("renders header with tier label", () => {
- render(<UsagePanelContent usage={makeUsage({ tier: "PRO" })} />);
- expect(screen.getByText("Pro plan")).toBeDefined();
- });
-
- it("hides header when showHeader is false", () => {
- render(<UsagePanelContent usage={makeUsage()} showHeader={false} />);
- expect(screen.queryByText("Usage limits")).toBeNull();
- });
-});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/useCopilotUsage.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/useCopilotUsage.ts
new file mode 100644
index 0000000000..6e1f1c2515
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/useCopilotUsage.ts
@@ -0,0 +1,14 @@
+import { useGetV2GetCopilotUsage } from "@/app/api/__generated__/endpoints/chat/chat";
+import type { CoPilotUsagePublic } from "@/app/api/__generated__/models/coPilotUsagePublic";
+
+const USAGE_QUERY_CONFIG = {
+ query: {
+ select: (res: { data: unknown }) => res.data as CoPilotUsagePublic,
+ refetchInterval: 30000,
+ staleTime: 10000,
+ },
+} as const;
+
+export function useCopilotUsage() {
+ return useGetV2GetCopilotUsage(USAGE_QUERY_CONFIG);
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/useIsUsageLimitReached.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/useIsUsageLimitReached.ts
new file mode 100644
index 0000000000..ca75331ea6
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/UsageLimits/useIsUsageLimitReached.ts
@@ -0,0 +1,7 @@
+import { isUsageExhausted } from "../usageHelpers";
+import { useCopilotUsage } from "./useCopilotUsage";
+
+export function useIsUsageLimitReached() {
+ const { data: usage } = useCopilotUsage();
+ return isUsageExhausted(usage);
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/__tests__/usageHelpers.test.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/__tests__/usageHelpers.test.ts
index eecdb70245..9f4b091381 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/__tests__/usageHelpers.test.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/__tests__/usageHelpers.test.ts
@@ -1,8 +1,11 @@
import { describe, expect, it } from "vitest";
import {
+ formatBytes,
formatCents,
formatMicrodollarsAsUsd,
formatResetTime,
+ formatTierLabel,
+ isUsageExhausted,
} from "../usageHelpers";
describe("formatCents", () => {
@@ -74,3 +77,86 @@ describe("formatResetTime", () => {
expect(formatResetTime(future, now)).not.toMatch(/^in \d/);
});
});
+
+describe("formatTierLabel", () => {
+ it("returns null for null", () => {
+ expect(formatTierLabel(null)).toBeNull();
+ });
+
+ it("returns null for undefined", () => {
+ expect(formatTierLabel(undefined)).toBeNull();
+ });
+
+ it("returns null for empty string", () => {
+ expect(formatTierLabel("")).toBeNull();
+ });
+
+ it("returns null for the NO_TIER sentinel", () => {
+ expect(formatTierLabel("NO_TIER")).toBeNull();
+ });
+
+ it("capitalizes a known tier", () => {
+ expect(formatTierLabel("PRO")).toBe("Pro");
+ expect(formatTierLabel("BASIC")).toBe("Basic");
+ });
+
+ it("normalizes first-letter casing for lowercase or mixed-case input", () => {
+ expect(formatTierLabel("pro")).toBe("Pro");
+ expect(formatTierLabel("pRo")).toBe("Pro");
+ });
+});
+
+describe("isUsageExhausted", () => {
+ it("returns false for null/undefined usage", () => {
+ expect(isUsageExhausted(null)).toBe(false);
+ expect(isUsageExhausted(undefined)).toBe(false);
+ });
+
+ it("returns false when neither window is over 100%", () => {
+ expect(
+ isUsageExhausted({
+ daily: { percent_used: 50 },
+ weekly: { percent_used: 60 },
+ }),
+ ).toBe(false);
+ });
+
+ it("returns true when daily is exhausted", () => {
+ expect(
+ isUsageExhausted({
+ daily: { percent_used: 100 },
+ weekly: { percent_used: 10 },
+ }),
+ ).toBe(true);
+ });
+
+ it("returns true when weekly is exhausted", () => {
+ expect(
+ isUsageExhausted({
+ daily: { percent_used: 0 },
+ weekly: { percent_used: 100 },
+ }),
+ ).toBe(true);
+ });
+
+ it("treats missing percent_used as 0", () => {
+ expect(isUsageExhausted({ daily: null, weekly: null })).toBe(false);
+ expect(isUsageExhausted({})).toBe(false);
+ });
+});
+
+describe("formatBytes", () => {
+ it.each([
+ [0, "0 B"],
+ [512, "512 B"],
+ [1024, "1 KB"],
+ [250 * 1024, "250 KB"],
+ [1023 * 1024, "1023 KB"],
+ [1024 * 1024, "1 MB"],
+ [250 * 1024 * 1024, "250 MB"],
+ [1024 * 1024 * 1024, "1.0 GB"],
+ [5 * 1024 * 1024 * 1024, "5.0 GB"],
+ ])("formats %d bytes as %s", (input, expected) => {
+ expect(formatBytes(input)).toBe(expected);
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/usageHelpers.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/usageHelpers.ts
index f25df85e9b..f12c81dfa4 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/usageHelpers.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/usageHelpers.ts
@@ -32,3 +32,44 @@ export function formatResetTime(
timeZoneName: "short",
});
}
+
+export function formatTierLabel(
+ tier: string | null | undefined,
+): string | null {
+ if (!tier || tier === "NO_TIER") return null;
+ return tier.charAt(0).toUpperCase() + tier.slice(1).toLowerCase();
+}
+
+export const TIER_BADGE_CLASS_NAME = "bg-[rgb(224,237,255)]";
+
+interface UsageWindowLike {
+ percent_used?: number | null;
+}
+
+interface UsageLike {
+ daily?: UsageWindowLike | null;
+ weekly?: UsageWindowLike | null;
+}
+
+export function isUsageExhausted(usage: UsageLike | null | undefined): boolean {
+ if (!usage) return false;
+ const daily = usage.daily?.percent_used ?? 0;
+ const weekly = usage.weekly?.percent_used ?? 0;
+ return daily >= 100 || weekly >= 100;
+}
+
+export function formatBytes(bytes: number): string {
+ const KB = 1024;
+ const MB = KB * 1024;
+ const GB = MB * 1024;
+ if (bytes < KB) return `${bytes} B`;
+ if (bytes < MB) {
+ const kb = Math.round(bytes / KB);
+ return kb >= 1024 ? `${(bytes / MB).toFixed(1)} MB` : `${kb} KB`;
+ }
+ if (bytes < GB) {
+ const mb = Math.round(bytes / MB);
+ return mb >= 1024 ? `${(bytes / GB).toFixed(1)} GB` : `${mb} MB`;
+ }
+ return `${(bytes / GB).toFixed(1)} GB`;
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/BriefingTabContent.tsx b/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/BriefingTabContent.tsx
index f7fd7b043a..760a0563a8 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/BriefingTabContent.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/BriefingTabContent.tsx
@@ -3,7 +3,11 @@
import type { CoPilotUsagePublic } from "@/app/api/__generated__/models/coPilotUsagePublic";
import type { LibraryAgent } from "@/app/api/__generated__/models/libraryAgent";
import { useGetV2GetCopilotUsage } from "@/app/api/__generated__/endpoints/chat/chat";
-import { formatResetTime } from "@/app/(platform)/copilot/components/usageHelpers";
+import {
+ formatResetTime,
+ formatTierLabel,
+ TIER_BADGE_CLASS_NAME,
+} from "@/app/(platform)/copilot/components/usageHelpers";
import { Button } from "@/components/atoms/Button/Button";
import { Badge } from "@/components/atoms/Badge/Badge";
import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";
@@ -50,8 +54,7 @@ function UsageSection() {
if (!isSuccess || !usage) return null;
if (!usage.daily && !usage.weekly) return null;
- const isDailyExhausted = !!usage.daily && usage.daily.percent_used >= 100;
- const showGoToBilling = isDailyExhausted && isBillingEnabled;
+ const tierLabel = formatTierLabel(usage.tier);
return (
<div className="py-2">
@@ -59,13 +62,13 @@ function UsageSection() {
<Text variant="h5" className="text-neutral-800">
Usage limits
</Text>
- {usage.tier && (
- <Badge variant="info" size="small" className="bg-[rgb(224,237,255)]">
- {usage.tier.charAt(0) + usage.tier.slice(1).toLowerCase()} plan
+ {tierLabel && (
+ <Badge variant="info" size="small" className={TIER_BADGE_CLASS_NAME}>
+ {tierLabel} plan
</Badge>
)}
<div className="flex-1" />
- {isBillingEnabled && !showGoToBilling && (
+ {isBillingEnabled && (
<Link
href="/settings/billing"
className="text-sm text-blue-600 hover:underline"
@@ -90,18 +93,6 @@ function UsageSection() {
/>
)}
</div>
- {showGoToBilling && (
- <div className="mt-4 flex items-center gap-3">
- <Button
- as="NextLink"
- href="/settings/billing"
- variant="primary"
- size="small"
- >
- Go to billing
- </Button>
- </div>
- )}
</div>
);
}
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/__tests__/BriefingTabContent.test.tsx b/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/__tests__/BriefingTabContent.test.tsx
index 1893630daa..c293395f25 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/__tests__/BriefingTabContent.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/library/components/AgentBriefingPanel/__tests__/BriefingTabContent.test.tsx
@@ -106,46 +106,36 @@ describe("BriefingTabContent — UsageSection", () => {
expect(screen.queryByText(/Reset daily limit/)).toBeNull();
});
- it("shows 'Go to billing' when daily is exhausted and billing flag is on", () => {
+ it("shows 'Manage billing' when billing flag is on, regardless of usage", () => {
mockUseGetV2GetCopilotUsage.mockReturnValue({
data: makeUsage({ dailyPercent: 100, weeklyPercent: 40 }),
isSuccess: true,
});
mockUseGetFlag.mockReturnValue(true);
render(<BriefingTabContent activeTab="all" agents={[]} />);
- expect(screen.getByText("Go to billing")).toBeDefined();
- });
-
- it("hides 'Manage billing' link when 'Go to billing' button is shown", () => {
- mockUseGetV2GetCopilotUsage.mockReturnValue({
- data: makeUsage({ dailyPercent: 100, weeklyPercent: 40 }),
- isSuccess: true,
- });
- mockUseGetFlag.mockReturnValue(true);
- render(<BriefingTabContent activeTab="all" agents={[]} />);
- expect(screen.getByText("Go to billing")).toBeDefined();
- expect(screen.queryByText("Manage billing")).toBeNull();
+ expect(screen.getByText("Manage billing")).toBeDefined();
+ expect(screen.queryByText("Go to billing")).toBeNull();
});
- it("hides 'Go to billing' when billing flag is off", () => {
+ it("hides 'Manage billing' when billing flag is off", () => {
mockUseGetV2GetCopilotUsage.mockReturnValue({
data: makeUsage({ dailyPercent: 100, weeklyPercent: 40 }),
isSuccess: true,
});
mockUseGetFlag.mockReturnValue(false);
render(<BriefingTabContent activeTab="all" agents={[]} />);
- expect(screen.queryByText("Go to billing")).toBeNull();
expect(screen.queryByText("Manage billing")).toBeNull();
+ expect(screen.queryByText("Go to billing")).toBeNull();
});
- it("still shows 'Go to billing' when both daily and weekly are exhausted", () => {
+ it("still shows 'Manage billing' when both daily and weekly are exhausted", () => {
mockUseGetV2GetCopilotUsage.mockReturnValue({
data: makeUsage({ dailyPercent: 100, weeklyPercent: 100 }),
isSuccess: true,
});
mockUseGetFlag.mockReturnValue(true);
render(<BriefingTabContent activeTab="all" agents={[]} />);
- expect(screen.getByText("Go to billing")).toBeDefined();
+ expect(screen.getByText("Manage billing")).toBeDefined();
expect(screen.queryByText(/Reset daily limit/)).toBeNull();
});
diff --git a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/credits/page.tsx b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/credits/page.tsx
index 28e7e49d0f..aeee97d73f 100644
--- a/autogpt_platform/frontend/src/app/(platform)/profile/(user)/credits/page.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/profile/(user)/credits/page.tsx
@@ -12,7 +12,8 @@ import {
import { RefundModal } from "./RefundModal";
import { SubscriptionTierSection } from "./components/SubscriptionTierSection/SubscriptionTierSection";
import { CreditTransaction } from "@/lib/autogpt-server-api";
-import { UsagePanelContent } from "@/app/(platform)/copilot/components/UsageLimits/UsageLimits";
+import { StorageBar } from "@/app/(platform)/copilot/components/UsageLimits/StorageBar";
+import { UsageBar } from "@/app/(platform)/copilot/components/UsageLimits/UsageBar";
import type { CoPilotUsagePublic } from "@/app/api/__generated__/models/coPilotUsagePublic";
import { useGetV2GetCopilotUsage } from "@/app/api/__generated__/endpoints/chat/chat";
@@ -41,8 +42,22 @@ function CoPilotUsageSection() {
return (
<div className="my-6 space-y-4">
<h3 className="text-lg font-medium">AutoPilot Usage & Storage</h3>
- <div className="rounded-lg border border-neutral-200 p-4">
- <UsagePanelContent usage={usage} showBillingLink={false} />
+ <div className="flex flex-col gap-3 rounded-lg border border-neutral-200 p-4">
+ {usage.daily && (
+ <UsageBar
+ label="Today"
+ percentUsed={usage.daily.percent_used}
+ resetsAt={usage.daily.resets_at}
+ />
+ )}
+ {usage.weekly && (
+ <UsageBar
+ label="This week"
+ percentUsed={usage.weekly.percent_used}
+ resetsAt={usage.weekly.resets_at}
+ />
+ )}
+ <StorageBar />
</div>
<Button className="w-full" onClick={() => router.push("/copilot")}>
Open AutoPilot
diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-cards.test.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-cards.test.tsx
index 43ec20b007..7116802a96 100644
--- a/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-cards.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/settings/billing/__tests__/billing-cards.test.tsx
@@ -803,8 +803,8 @@ describe("AutopilotUsageCard", () => {
expect(await screen.findByText("Today")).toBeDefined();
expect(screen.getByText("This Week")).toBeDefined();
- expect(screen.getByText("12%")).toBeDefined();
- expect(screen.getByText("35%")).toBeDefined();
+ expect(screen.getByText("12% used")).toBeDefined();
+ expect(screen.getByText("35% used")).toBeDefined();
});
});
diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/AutopilotUsageCard/AutopilotUsageCard.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/AutopilotUsageCard/AutopilotUsageCard.tsx
index 6f9f7d87a0..9581e1cddf 100644
--- a/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/AutopilotUsageCard/AutopilotUsageCard.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/settings/billing/components/SubscriptionTab/AutopilotUsageCard/AutopilotUsageCard.tsx
@@ -47,35 +47,41 @@ export function AutopilotUsageCard({ index = 0 }: Props) {
function UsageBar({ window }: { window: UsageWindowView }) {
const reduceMotion = useReducedMotion();
const percent = Math.min(Math.max(window.percent, 0), 100);
+ const isHigh = percent >= 80;
+ const percentLabel =
+ window.percent > 0 && percent === 0 ? "<1% used" : `${percent}% used`;
return (
<div className="flex flex-col gap-2">
- <Text variant="body-medium" as="span" className="text-textBlack">
- {window.label}
- </Text>
- <div className="flex items-center gap-3">
- <div className="relative h-6 flex-1 overflow-hidden rounded-[4px] bg-[repeating-linear-gradient(135deg,_#d4d4d8_0,_#d4d4d8_2px,_transparent_2px,_transparent_6px)]">
- <motion.div
- initial={reduceMotion ? { width: `${percent}%` } : { width: 0 }}
- animate={{ width: `${percent}%` }}
- transition={
- reduceMotion
- ? undefined
- : { duration: 0.9, ease: EASE_OUT, delay: 0.25 }
- }
- className="h-full bg-zinc-300"
- />
- </div>
- <Text
- variant="body-medium"
- as="span"
- className="shrink-0 tabular-nums text-textBlack"
- >
- {percent}%
+ <div className="flex items-baseline justify-between">
+ <Text variant="body-medium" className="text-neutral-700">
+ {window.label}
+ </Text>
+ <Text variant="body" className="tabular-nums text-neutral-500">
+ {percentLabel}
</Text>
</div>
- <Text variant="body" as="span" className="text-zinc-500">
- {window.prefix} <span className="text-zinc-800">{window.value}</span>
+ <div className="h-2 w-full overflow-hidden rounded-full bg-neutral-200">
+ <motion.div
+ role="progressbar"
+ aria-label={`${window.label} usage`}
+ aria-valuemin={0}
+ aria-valuemax={100}
+ aria-valuenow={percent}
+ initial={reduceMotion ? { width: `${percent}%` } : { width: 0 }}
+ animate={{ width: `${percent}%` }}
+ transition={
+ reduceMotion
+ ? undefined
+ : { duration: 0.9, ease: EASE_OUT, delay: 0.25 }
+ }
+ className={`h-full rounded-full ${
+ isHigh ? "bg-orange-500" : "bg-blue-500"
+ }`}
+ />
+ </div>
+ <Text variant="small" className="text-neutral-400">
+ {window.prefix} <span className="text-neutral-700">{window.value}</span>
</Text>
</div>
);