:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(desktop): show token and compute usage (#79066)
Adam Bowkere4302b2eed77
diff --git a/products/desktop/packages/core/src/billing/usageDisplay.test.ts b/products/desktop/packages/core/src/billing/usageDisplay.test.tsindex 5509f845e84d..e78511da42c3 100644--- a/products/desktop/packages/core/src/billing/usageDisplay.test.ts+++ b/products/desktop/packages/core/src/billing/usageDisplay.test.ts@@ -3,6 +3,7 @@ import type { UsageOutput } from "../usage/schemas";import {codeOrgSpendLimitUsd,codeUsageMeter,+ desktopUsageComponents,formatResetTime,formatUsageBreakdown,formatUsdAmount,@@ -212,6 +213,57 @@ describe("formatUsageBreakdown", () => {});});+describe("desktopUsageComponents", () => {+ it("converts credits and large resource quantities for display", () => {+ const usage: UsageOutput = {+ ...makeUsage(),+ ai_credits: {+ exhausted: false,+ used_usd: 15,+ limit_usd: 20,+ breakdown: {+ token_credits: 1_234,+ compute_credits: 266,+ cpu_millicore_seconds: 9_876_543_210,+ memory_mib_seconds: 7_654_321_098,+ },+ },+ };++ expect(desktopUsageComponents(usage)).toEqual({+ tokenUsd: 12.34,+ computeUsd: 2.66,+ cpuCoreSeconds: 9_876_543.21,+ memoryGibSeconds: 7_474_922.947265625,+ });+ });++ it("distinguishes an absent breakdown, missing values, and explicit zero", () => {+ expect(desktopUsageComponents(makeUsage())).toBeNull();+ expect(+ desktopUsageComponents({+ ...makeUsage(),+ ai_credits: {+ exhausted: false,+ used_usd: 0,+ limit_usd: 20,+ breakdown: {+ token_credits: 0,+ compute_credits: null,+ cpu_millicore_seconds: 0,+ memory_mib_seconds: null,+ },+ },+ }),+ ).toEqual({+ tokenUsd: 0,+ computeUsd: null,+ cpuCoreSeconds: 0,+ memoryGibSeconds: null,+ });+ });+});+describe("formatUsdAmount", () => {it.each([[50, "$50"],diff --git a/products/desktop/packages/core/src/billing/usageDisplay.ts b/products/desktop/packages/core/src/billing/usageDisplay.tsindex 2dd67e05cef3..8a1c0b2f5afd 100644--- a/products/desktop/packages/core/src/billing/usageDisplay.ts+++ b/products/desktop/packages/core/src/billing/usageDisplay.ts@@ -80,6 +80,41 @@ export function formatUsageBreakdown(breakdown: CodeUsageBreakdown): string {return `${formatUsdAmount(breakdown.includedUsd)} included + ${formatUsdAmount(breakdown.spendLimitUsd)} org spend limit`;}+export interface DesktopUsageComponents {+ tokenUsd: number | null;+ computeUsd: number | null;+ cpuCoreSeconds: number | null;+ memoryGibSeconds: number | null;+}++export function desktopUsageComponents(+ usage: UsageOutput | null | undefined,+): DesktopUsageComponents | null {+ const breakdown = usage?.ai_credits?.breakdown;+ if (breakdown == null) return null;++ return {+ tokenUsd:+ breakdown.token_credits == null ? null : breakdown.token_credits / 100,+ computeUsd:+ breakdown.compute_credits == null+ ? null+ : breakdown.compute_credits / 100,+ cpuCoreSeconds:+ breakdown.cpu_millicore_seconds == null+ ? null+ : breakdown.cpu_millicore_seconds / 1_000,+ memoryGibSeconds:+ breakdown.memory_mib_seconds == null+ ? null+ : breakdown.memory_mib_seconds / 1_024,+ };+}++export function formatUsageQuantity(value: number, unit: string): string {+ return `${new Intl.NumberFormat(undefined, { maximumFractionDigits: 3 }).format(value)} ${unit}`;+}+export function isUsageExceeded(usage: UsageOutput): boolean {return (usage.is_rate_limited || usage.sustained.exceeded || usage.burst.exceededdiff --git a/products/desktop/packages/core/src/llm-gateway/llm-gateway.test.ts b/products/desktop/packages/core/src/llm-gateway/llm-gateway.test.tsindex 03dc0acac72d..c16378f6a0b4 100644--- a/products/desktop/packages/core/src/llm-gateway/llm-gateway.test.ts+++ b/products/desktop/packages/core/src/llm-gateway/llm-gateway.test.ts@@ -397,6 +397,31 @@ describe("LlmGatewayService.fetchUsage", () => {expect(usage.ai_credits?.limit_usd).toBeNull();});+ it("parses the optional Desktop component breakdown without rounding integers", async () => {+ const breakdown = {+ token_credits: 1_234,+ compute_credits: 67,+ cpu_millicore_seconds: 9_876_543_210,+ memory_mib_seconds: 7_654_321_098,+ };+ const fetchMock = vi.fn().mockResolvedValue(+ createJsonResponse({+ ...USAGE_BODY,+ ai_credits: {+ exhausted: false,+ used_usd: 13.01,+ limit_usd: 20,+ breakdown,+ },+ }),+ );+ const { service } = createService(fetchMock);++ const usage = await service.fetchUsage();++ expect(usage.ai_credits?.breakdown).toEqual(breakdown);+ });+it("feeds code_usage_subscribed into helper model routing", async () => {const fetchMock = vi.fn()diff --git a/products/desktop/packages/core/src/usage/schemas.ts b/products/desktop/packages/core/src/usage/schemas.tsindex 1ecea3b488b9..7442e53f7b1c 100644--- a/products/desktop/packages/core/src/usage/schemas.ts+++ b/products/desktop/packages/core/src/usage/schemas.ts@@ -16,6 +16,14 @@ export const usageOutput = z.object({exhausted: z.boolean(),used_usd: z.number().nullish(),limit_usd: z.number().nullish(),+ breakdown: z+ .object({+ token_credits: z.number().nullish(),+ compute_credits: z.number().nullish(),+ cpu_millicore_seconds: z.number().nullish(),+ memory_mib_seconds: z.number().nullish(),+ })+ .nullish(),}).optional(),is_rate_limited: z.boolean(),diff --git a/products/desktop/packages/core/src/usage/usage-monitor.ts b/products/desktop/packages/core/src/usage/usage-monitor.tsindex b394ee512b94..af783d96b69b 100644--- a/products/desktop/packages/core/src/usage/usage-monitor.ts+++ b/products/desktop/packages/core/src/usage/usage-monitor.ts@@ -267,6 +267,14 @@ function isSameUsage(a: UsageOutput | null, b: UsageOutput): boolean {a.ai_credits?.exhausted === b.ai_credits?.exhausted &&a.ai_credits?.used_usd === b.ai_credits?.used_usd &&a.ai_credits?.limit_usd === b.ai_credits?.limit_usd &&+ a.ai_credits?.breakdown?.token_credits ===+ b.ai_credits?.breakdown?.token_credits &&+ a.ai_credits?.breakdown?.compute_credits ===+ b.ai_credits?.breakdown?.compute_credits &&+ a.ai_credits?.breakdown?.cpu_millicore_seconds ===+ b.ai_credits?.breakdown?.cpu_millicore_seconds &&+ a.ai_credits?.breakdown?.memory_mib_seconds ===+ b.ai_credits?.breakdown?.memory_mib_seconds &&isSameBucket(a.burst, b.burst) &&isSameBucket(a.sustained, b.sustained));diff --git a/products/desktop/packages/ui/src/features/billing/UsageMeter.stories.tsx b/products/desktop/packages/ui/src/features/billing/UsageMeter.stories.tsxindex 290d0fb41d43..447982e81305 100644--- a/products/desktop/packages/ui/src/features/billing/UsageMeter.stories.tsx+++ b/products/desktop/packages/ui/src/features/billing/UsageMeter.stories.tsx@@ -2,7 +2,7 @@ import { UsageMeter } from "@posthog/ui/features/billing/UsageMeter";import type { Meta, StoryObj } from "@storybook/react-vite";const meta: Meta<typeof UsageMeter> = {- title: "Billing/UsageMeter",+ title: "Billing/Organization usage meter",component: UsageMeter,decorators: [(Story) => (@@ -20,7 +20,7 @@ type Story = StoryObj<typeof UsageMeter>;// segments — the $20 included allowance (green) and the $50 default spend// limit (accent) — with a dot legend naming each amount. Usage still inside// the included allowance only fills the green segment.-export const SubscribedWithBreakdown: Story = {+export const SubscribedWithAllowanceAndLimit: Story = {args: {label: "Usage this period",percent: 18,diff --git a/products/desktop/packages/ui/src/features/settings/sections/PlanUsageSettings.stories.tsx b/products/desktop/packages/ui/src/features/settings/sections/PlanUsageSettings.stories.tsxnew file mode 100644index 000000000000..132890798c85--- /dev/null+++ b/products/desktop/packages/ui/src/features/settings/sections/PlanUsageSettings.stories.tsx@@ -0,0 +1,99 @@+import type { UsageOutput } from "@posthog/core/usage/schemas";+import { PlanUsageContent } from "@posthog/ui/features/settings/sections/PlanUsageSettings";+import type { Meta, StoryObj } from "@storybook/react-vite";++const usage = {+ product: "posthog_code",+ user_id: 1,+ sustained: {+ used_percent: 34,+ reset_at: "2026-09-01T00:00:00.000Z",+ exceeded: false,+ },+ burst: {+ used_percent: 4,+ reset_at: "2026-08-07T00:00:00.000Z",+ exceeded: false,+ },+ ai_credits: {+ exhausted: false,+ used_usd: 23.8,+ limit_usd: 70,+ breakdown: {+ token_credits: 1_840,+ compute_credits: 540,+ cpu_millicore_seconds: 12_450_000,+ memory_mib_seconds: 31_457_280,+ },+ },+ is_rate_limited: false,+ is_pro: true,+ code_usage_subscribed: true,+ billing_period_end: "2026-09-01T00:00:00.000Z",+} satisfies UsageOutput;++const meta: Meta<typeof PlanUsageContent> = {+ title: "Billing/Plan and usage",+ component: PlanUsageContent,+ decorators: [+ (Story) => (+ <div className="mx-auto max-w-3xl p-6">+ <Story />+ </div>+ ),+ ],+ args: {+ billingEnabled: true,+ spendAnalysisEnabled: true,+ billingUrl: "https://app.posthog.com/organization/billing",+ usage,+ usageLoading: false,+ },+};++export default meta;+type Story = StoryObj<typeof PlanUsageContent>;++export const WithComponentBreakdown: Story = {};++export const BreakdownAwaitingData: Story = {+ args: {+ spendAnalysisEnabled: false,+ usage: { ...usage, ai_credits: { ...usage.ai_credits, breakdown: null } },+ },+};++export const ExplicitZeroUsage: Story = {+ args: {+ spendAnalysisEnabled: false,+ usage: {+ ...usage,+ ai_credits: {+ exhausted: false,+ used_usd: 0,+ limit_usd: 70,+ breakdown: {+ token_credits: 0,+ compute_credits: 0,+ cpu_millicore_seconds: 0,+ memory_mib_seconds: 0,+ },+ },+ },+ },+};++export const OrganizationLimitReached: Story = {+ args: {+ spendAnalysisEnabled: false,+ usage: {+ ...usage,+ ai_credits: { ...usage.ai_credits, exhausted: true, used_usd: 70 },+ is_rate_limited: true,+ },+ },+};++export const Loading: Story = {+ args: { usage: null, usageLoading: true, spendAnalysisEnabled: false },+};diff --git a/products/desktop/packages/ui/src/features/settings/sections/PlanUsageSettings.tsx b/products/desktop/packages/ui/src/features/settings/sections/PlanUsageSettings.tsxindex 25cd0211dfed..f9a7c6c2989c 100644--- a/products/desktop/packages/ui/src/features/settings/sections/PlanUsageSettings.tsx+++ b/products/desktop/packages/ui/src/features/settings/sections/PlanUsageSettings.tsx@@ -1,14 +1,19 @@import {ArrowSquareOut,+ CaretDown,+ CaretRight,CreditCard,WarningCircle,} from "@phosphor-icons/react";import {codeUsageMeter,+ desktopUsageComponents,formatResetTime,+ formatUsageQuantity,formatUsdAmount,isCodeUsageFreeTier,} from "@posthog/core/billing/usageDisplay";+import type { UsageOutput } from "@posthog/core/usage/schemas";import {Empty,EmptyDescription,@@ -27,17 +32,8 @@ import { useSpendAnalysisEnabled } from "@posthog/ui/features/usage/useSpendAnalimport { useTrackUsageViewed } from "@posthog/ui/features/usage/useTrackUsageViewed";import { track } from "@posthog/ui/shell/analytics";import { getBillingUrl } from "@posthog/ui/utils/urls";-import {- Badge,- Box,- Button,- Callout,- Flex,- ScrollArea,- Spinner,- Text,-} from "@radix-ui/themes";-import { useEffect } from "react";+import { Button, Callout, Flex, Spinner, Text } from "@radix-ui/themes";+import { type ReactNode, useEffect, useState } from "react";export function PlanUsageSettings() {const billingEnabled = useFeatureFlag(BILLING_FLAG);@@ -64,11 +60,41 @@ export function PlanUsageSettings() {burstUsedPercent: usage?.burst.used_percent ?? null,});- // Tri-state: unknown (absent field) must render as subscribed, never free.+ return (+ <PlanUsageContent+ billingEnabled={billingEnabled}+ spendAnalysisEnabled={spendAnalysisEnabled}+ billingUrl={billingUrl}+ usage={usage}+ usageLoading={usageLoading}+ personalSpendAnalysis={<SpendAnalysisSection />}+ />+ );+}++interface PlanUsageContentProps {+ billingEnabled: boolean;+ spendAnalysisEnabled: boolean;+ billingUrl: string | null | undefined;+ usage: UsageOutput | null | undefined;+ usageLoading: boolean;+ personalSpendAnalysis?: ReactNode;+}++export function PlanUsageContent({+ billingEnabled,+ spendAnalysisEnabled,+ billingUrl,+ usage,+ usageLoading,+ personalSpendAnalysis,+}: PlanUsageContentProps) {const freeTier = isCodeUsageFreeTier(usage);- const subscribed = usage?.code_usage_subscribed === true;const orgLimitReached = usage?.ai_credits?.exhausted === true;const meter = codeUsageMeter(usage);+ const components = desktopUsageComponents(usage);+ const hasUsageMix =+ components?.tokenUsd != null && components.computeUsd != null;const openBilling = () => {if (billingUrl) window.open(billingUrl, "_blank");@@ -91,150 +117,254 @@ export function PlanUsageSettings() {}return (- <ScrollArea className="h-full w-full">- <Box p="6" className="relative z-[1]">- <Flex direction="column" gap="5">- {billingEnabled && (- <>- {orgLimitReached && (- <Callout.Root color="red" size="1">- <Callout.Icon>- <WarningCircle size={16} />- </Callout.Icon>- <Callout.Text>- <Flex direction="column" gap="2">- <Text className="text-sm">- Your organization has reached its usage limit for this- billing period.- </Text>- <Button- size="1"- variant="outline"- color="red"- disabled={!billingUrl}- onClick={openBilling}- className="self-start"- >- Manage billing- <ArrowSquareOut size={12} />- </Button>- </Flex>- </Callout.Text>- </Callout.Root>- )}+ <Flex direction="column" gap="5">+ {billingEnabled && (+ <>+ {orgLimitReached && (+ <Callout.Root color="red" size="1">+ <Callout.Icon>+ <WarningCircle size={16} />+ </Callout.Icon>+ <Callout.Text>+ <Flex direction="column" gap="2">+ <Text className="text-sm">+ Your organization has reached its usage limit for this+ billing period.+ </Text>+ <Button+ size="1"+ variant="outline"+ color="red"+ disabled={!billingUrl}+ onClick={openBilling}+ className="self-start"+ >+ Manage billing+ <ArrowSquareOut size={12} />+ </Button>+ </Flex>+ </Callout.Text>+ </Callout.Root>+ )}+ <Flex+ direction="column"+ gap="4"+ p="4"+ className="rounded-(--radius-3) border border-(--gray-5)"+ >+ <Flex align="start" justify="between" gap="4" wrap="wrap">+ <Flex direction="column" gap="1">+ <Text className="font-bold text-base">Organization usage</Text>+ <Text className="text-(--gray-11) text-sm">+ Combined token and cloud-compute spend counts toward your+ organization's shared allowance and limit.+ </Text>+ </Flex>+ <Button+ size="1"+ variant={freeTier ? "solid" : "outline"}+ disabled={!billingUrl}+ onClick={() => {+ if (freeTier) {+ track(ANALYTICS_EVENTS.UPGRADE_PROMPT_CLICKED, {+ surface: "plan_page_card",+ });+ }+ openBilling();+ }}+ >+ {freeTier ? "Add payment method" : "Manage billing and limits"}+ <ArrowSquareOut size={12} />+ </Button>+ </Flex>+ {usageLoading ? (<Flex- direction="column"- gap="3"+ align="center"+ justify="center"p="4"className="rounded-(--radius-3) border border-(--gray-5)">- <Flex align="center" justify="between">- <Flex direction="column" gap="1">- <Text className="font-bold text-base">- {freeTier ? "Free tier" : "Usage-based billing"}- </Text>- <Text className="text-(--gray-11) text-sm">- {freeTier- ? "Your organization's first $20 of usage each month is included, with access to open models. Add a payment method to unlock premium models — you only pay for what you use."- : "Your organization pays for usage at cost — no seats, no subscriptions. The first $20 each month is included."}- </Text>- </Flex>- {subscribed && (- <Badge variant="soft" color="green" radius="full">- Active- </Badge>- )}- </Flex>- <Button- size="1"- variant={freeTier ? "solid" : "outline"}- disabled={!billingUrl}- onClick={() => {- if (freeTier) {- track(ANALYTICS_EVENTS.UPGRADE_PROMPT_CLICKED, {- surface: "plan_page_card",- });- }- openBilling();- }}- className="self-start"- >- {freeTier- ? "Add payment method"- : "Manage billing and spend limits"}- <ArrowSquareOut size={12} />- </Button>+ <Spinner size="2" /></Flex>-- <Flex direction="column" gap="3">- <Text className="font-medium text-(--gray-9) text-sm">- Organization usage+ ) : meter.kind === "dollars" ? (+ <UsageMeter+ label={freeTier ? "Monthly free usage" : "Usage this period"}+ percent={meter.percent}+ valueLabel={`${formatUsdAmount(meter.usedUsd)} of ${formatUsdAmount(meter.limitUsd)}${freeTier ? " included" : ""}`}+ detail={`${meter.exceeded ? "Limit exceeded. " : ""}${formatResetTime(meter.resetAt, { label: "Billing period ends" })}`}+ breakdown={+ meter.breakdown+ ? { ...meter.breakdown, usedUsd: meter.usedUsd }+ : undefined+ }+ color={meter.exceeded ? "red" : undefined}+ />+ ) : meter.kind === "bucket" ? (+ <UsageMeter+ label="Monthly free usage"+ percent={meter.bucket.used_percent}+ valueLabel={`${meter.bucket.used_percent.toFixed(2)}%`}+ detail={`${meter.bucket.exceeded ? "Limit exceeded. " : ""}${formatResetTime(meter.bucket.reset_at)}`}+ color={meter.bucket.exceeded ? "red" : undefined}+ />+ ) : (+ <Flex+ align="center"+ justify="between"+ p="4"+ className="rounded-(--radius-3) border border-(--gray-5)"+ >+ <Text color="gray" className="text-sm">+ {usage+ ? "Usage is billed to your organization. View detailed usage and spend in PostHog."+ : "Unable to load usage data"}</Text>- {usageLoading ? (- <Flex- align="center"- justify="center"- p="4"- className="rounded-(--radius-3) border border-(--gray-5)"+ {usage && (+ <Button+ size="1"+ variant="outline"+ disabled={!billingUrl}+ onClick={openBilling}>- <Spinner size="2" />- </Flex>- ) : meter.kind === "dollars" ? (- <UsageMeter- label={- freeTier ? "Monthly free usage" : "Usage this period"- }- percent={meter.percent}- valueLabel={`${formatUsdAmount(meter.usedUsd)} of ${formatUsdAmount(meter.limitUsd)}${freeTier ? " included" : ""}`}- detail={`${meter.exceeded ? "Limit exceeded. " : ""}${formatResetTime(meter.resetAt, { label: "Billing period ends" })}`}- breakdown={- meter.breakdown- ? { ...meter.breakdown, usedUsd: meter.usedUsd }- : undefined- }- color={meter.exceeded ? "red" : undefined}- />- ) : meter.kind === "bucket" ? (- <UsageMeter- label="Monthly free usage"- percent={meter.bucket.used_percent}- valueLabel={`${meter.bucket.used_percent.toFixed(2)}%`}- detail={`${meter.bucket.exceeded ? "Limit exceeded. " : ""}${formatResetTime(meter.bucket.reset_at)}`}- color={meter.bucket.exceeded ? "red" : undefined}- />- ) : (- <Flex- align="center"- justify="between"- p="4"- className="rounded-(--radius-3) border border-(--gray-5)"- >- <Text color="gray" className="text-sm">- {usage- ? "Usage is billed to your organization. View detailed usage and spend in PostHog."- : "Unable to load usage data"}- </Text>- {usage && (- <Button- size="1"- variant="outline"- disabled={!billingUrl}- onClick={openBilling}- >- View usage- <ArrowSquareOut size={12} />- </Button>- )}- </Flex>+ View usage+ <ArrowSquareOut size={12} />+ </Button>)}</Flex>- </>- )}+ )}+ {!usageLoading && (+ <Flex direction="column" gap="3">+ {hasUsageMix && <UsageMix components={components} />}+ <Text className="text-(--gray-9) text-[13px]">+ Usage reporting may be delayed by 15–20 minutes.+ </Text>+ </Flex>+ )}+ </Flex>+ </>+ )}- {spendAnalysisEnabled && <SpendAnalysisSection />}+ {spendAnalysisEnabled && (+ <PersonalSpendDisclosure>+ {personalSpendAnalysis}+ </PersonalSpendDisclosure>+ )}+ </Flex>+ );+}++function UsageMix({+ components,+}: {+ components: NonNullable<ReturnType<typeof desktopUsageComponents>>;+}) {+ const tokenUsd = components.tokenUsd ?? 0;+ const computeUsd = components.computeUsd ?? 0;+ const totalUsd = tokenUsd + computeUsd;+ const tokenPercent = totalUsd > 0 ? (tokenUsd / totalUsd) * 100 : 0;+ const roundedTokenPercent = Math.round(tokenPercent);+ const computeDetails = [+ components.cpuCoreSeconds == null+ ? "CPU unavailable"+ : formatUsageQuantity(components.cpuCoreSeconds, "core-seconds"),+ components.memoryGibSeconds == null+ ? "Memory unavailable"+ : formatUsageQuantity(components.memoryGibSeconds, "GiB-seconds"),+ ].join(" · ");++ return (+ <Flex+ direction="column"+ gap="3"+ p="4"+ className="rounded-(--radius-3) bg-(--gray-a2)"+ >+ <Text className="font-medium text-sm">Usage mix</Text>+ <div+ role="img"+ aria-label={`${roundedTokenPercent}% tokens and ${totalUsd > 0 ? 100 - roundedTokenPercent : 0}% cloud compute`}+ className="flex h-3 w-full overflow-hidden rounded-full bg-(--gray-a4)"+ >+ {totalUsd > 0 && (+ <>+ <div+ className="bg-(--purple-9)"+ style={{ width: `${tokenPercent}%` }}+ />+ <div className="flex-1 bg-(--blue-9)" />+ </>+ )}+ </div>+ <Flex align="center" gap="5" wrap="wrap">+ <MixLegend+ color="bg-(--purple-9)"+ label="Tokens"+ percent={roundedTokenPercent}+ value={formatUsdAmount(tokenUsd)}+ />+ <MixLegend+ color="bg-(--blue-9)"+ label="Cloud compute"+ percent={totalUsd > 0 ? 100 - roundedTokenPercent : 0}+ value={formatUsdAmount(computeUsd)}+ />+ </Flex>+ <Text className="text-(--gray-9) text-xs">+ Compute resources: {computeDetails}+ </Text>+ </Flex>+ );+}++function PersonalSpendDisclosure({ children }: { children: ReactNode }) {+ const [expanded, setExpanded] = useState(false);++ return (+ <Flex+ direction="column"+ className="overflow-hidden rounded-(--radius-3) border border-(--gray-5)"+ >+ <button+ type="button"+ aria-expanded={expanded}+ onClick={() => setExpanded((value) => !value)}+ className="flex w-full items-center justify-between gap-4 p-4 text-left hover:bg-(--gray-a2) focus-visible:outline-(--accent-8) focus-visible:outline-2"+ >+ <Flex direction="column" gap="1">+ <Text className="font-medium text-sm">Your spend</Text>+ <Text className="text-(--gray-11) text-xs">+ Near-real-time analysis of your activity, separate from organization+ billing.+ </Text></Flex>- </Box>- </ScrollArea>+ {expanded ? <CaretDown size={16} /> : <CaretRight size={16} />}+ </button>+ {expanded && children && (+ <div className="border-(--gray-5) border-t p-4">{children}</div>+ )}+ </Flex>+ );+}++function MixLegend({+ color,+ label,+ percent,+ value,+}: {+ color: string;+ label: string;+ percent: number;+ value: string;+}) {+ return (+ <Flex align="center" gap="2">+ <span className={`size-2 rounded-full ${color}`} />+ <Text className="text-sm">+ <strong>{percent}%</strong> {label}+ <span className="text-(--gray-9)"> · {value}</span>+ </Text>+ </Flex>);}diff --git a/products/desktop/packages/ui/src/features/usage/components/SpendAnalysisSection.tsx b/products/desktop/packages/ui/src/features/usage/components/SpendAnalysisSection.tsxindex 6f2998c60b7a..a490dfe0d0a4 100644--- a/products/desktop/packages/ui/src/features/usage/components/SpendAnalysisSection.tsx+++ b/products/desktop/packages/ui/src/features/usage/components/SpendAnalysisSection.tsx@@ -36,10 +36,7 @@ export function SpendAnalysisSection() {return (<Flex direction="column" gap="3">- <Flex align="center" justify="between">- <Text className="font-medium text-(--gray-9) text-sm">- Personal spend analysis- </Text>+ <Flex justify="end"><Flex align="center" gap="4"><WindowSelector value={spendWindow} onChange={setSpendWindow} /><Button