TypeScript
feat(mobile): Usage uses the width on iPad and unfolded phones (#26061)
Julius Marminge9ff05979ee7a
diff --git a/apps/mobile/src/features/usage/UsageLimitsPooled.tsx b/apps/mobile/src/features/usage/UsageLimitsPooled.tsxindex 1eec514d330..19e7e7e03c6 100644--- a/apps/mobile/src/features/usage/UsageLimitsPooled.tsx+++ b/apps/mobile/src/features/usage/UsageLimitsPooled.tsx@@ -31,6 +31,7 @@ import { usageProviderKind, useProviderColors } from "./usageProviders";const DRIVER_LABEL: Partial<Record<string, string>> = {codex: "Codex",claudeAgent: "Claude",+ grok: "Grok",antigravity: "Antigravity",};const PACE_LABEL = { ahead: "Ahead of pace", on: "On pace", under: "Under pace" } as const;@@ -38,8 +39,35 @@ const PACE_LABEL = { ahead: "Ahead of pace", on: "On pace", under: "Under pace"function accountName(account: LimitAccount) {if (account.displayName) return account.displayName;if (!account.email) return DRIVER_LABEL[account.driver] ?? String(account.driver);- const [local = "", domain = ""] = account.email.split("@");- return `${local[0] ?? ""}${domain[0] ?? ""}`.toUpperCase() || "Account";+ return emailInitials(account.email) || "Account";+}++function emailInitials(email: string) {+ const [local = "", domain = ""] = email.split("@");+ return `${local[0] ?? ""}${domain[0] ?? ""}`.toUpperCase();+}++function accountHue(email: string) {+ let hash = 0;+ for (let index = 0; index < email.length; index += 1) {+ hash = (hash * 31 + email.charCodeAt(index)) | 0;+ }+ return Math.abs(hash) % 360;+}++// Same hashed hue as the web account chip, so an account keeps its color across clients.+function AccountChip({ email }: { readonly email: string }) {+ const hue = accountHue(email);+ return (+ <View+ className="size-5 items-center justify-center rounded-full"+ style={{ backgroundColor: `hsl(${hue}, 45%, 82%)` }}+ >+ <Text className="text-[9px] font-t3-bold" style={{ color: `hsl(${hue}, 45%, 28%)` }}>+ {emailInitials(email)}+ </Text>+ </View>+ );}// Same gap-and-tick as the Limits rows: two clipped copies of the segment leave a see-through gap.@@ -141,6 +169,7 @@ function PoolWindowCard({environmentIds,label,description,+ wide,}: {readonly pool: LimitPoolWindow;readonly color: string;@@ -148,8 +177,15 @@ function PoolWindowCard({readonly environmentIds: readonly string[] | null;readonly label?: string;readonly description?: string;+ readonly wide: boolean;}) {const navigation = useNavigation();+ const [barWidth, setBarWidth] = useState(0);+ // Each segment needs room for its account, percent and reset to label itself.+ const segmentWidth = barWidth / Math.max(pool.columns.length, 1);+ const inlineLabels = wide && segmentWidth >= 96;+ const inlineReset = wide && segmentWidth >= 150;+ const inlineName = wide && segmentWidth >= 220;const nextRefill = pool.resets.find((reset) => reset.restoresPercent > 0);const openAccount = (account: LimitAccount) =>navigation.navigate("SettingsUsageAccount", {@@ -159,9 +195,9 @@ function PoolWindowCard({environmentIds,now,});- return (- <View className="gap-3 rounded-[24px] border-continuous bg-grouped-card p-4">- <View className="flex-row items-start justify-between gap-3">+ const summary = (+ <>+ <View className={wide ? "gap-1" : "flex-row items-start justify-between gap-3"}><View className="gap-1"><Text className="text-sm font-t3-medium text-foreground">{label ?? pool.label}</Text><View className="flex-row items-baseline gap-1.5">@@ -184,31 +220,89 @@ function PoolWindowCard({.replace("resets now", "now")}</Text>) : null}- <View className="flex-row gap-1">- {pool.columns.map((member, index) => {- if (!member.window)- return <View key={member.account.key} className="h-7 min-w-0 flex-1" />;- const { account, window } = member;- const timeLeft = paceRemainingPercent(window, now);+ </>+ );+ const bar = (+ <View+ className="flex-row gap-1"+ onLayout={(event) => setBarWidth(event.nativeEvent.layout.width)}+ >+ {pool.columns.map((member, index) => {+ if (!member.window)return (- <Pressable- key={account.key}- accessibilityRole="button"- accessibilityLabel={`Segment ${index + 1}, ${accountName(account)}, ${remainingPercent(window)}% left${timeLeft === null ? "" : `, ${timeLeft}% of the window left`}`}- accessibilityHint="Show account details"- onPress={() => openAccount(account)}- className="h-7 min-w-0 flex-1 rounded-md"- >- <PaceGap timeLeft={timeLeft}>- <View className="absolute inset-0 rounded-md bg-subtle" />- <View className="absolute inset-0 overflow-hidden rounded-md">- <AccountSegment- remaining={remainingPercent(window)}- color={color}- refillPercent={window.resetsAt ? member.refillPercent : 0}- />+ <View+ key={member.account.key}+ className={wide ? "h-9 min-w-0 flex-1" : "h-7 min-w-0 flex-1"}+ />+ );+ const { account, window } = member;+ const timeLeft = paceRemainingPercent(window, now);+ const credits = account.limits.resetCredits?.availableCount ?? 0;+ const resetsIn = formatResetsIn(window, now)?.replace("resets in ", "");+ return (+ <Pressable+ key={account.key}+ accessibilityRole="button"+ accessibilityLabel={`Segment ${index + 1}, ${accountName(account)}, ${remainingPercent(window)}% left${timeLeft === null ? "" : `, ${timeLeft}% of the window left`}`}+ accessibilityHint="Show account details"+ onPress={() => openAccount(account)}+ className={wide ? "h-9 min-w-0 flex-1 rounded-md" : "h-7 min-w-0 flex-1 rounded-md"}+ >+ <PaceGap timeLeft={timeLeft}>+ <View className="absolute inset-0 rounded-md bg-subtle" />+ <View className="absolute inset-0 overflow-hidden rounded-md">+ <AccountSegment+ remaining={remainingPercent(window)}+ color={color}+ refillPercent={window.resetsAt ? member.refillPercent : 0}+ />+ </View>+ </PaceGap>+ {inlineLabels ? (+ <View+ pointerEvents="none"+ className="absolute inset-0 flex-row items-center justify-between gap-2 overflow-hidden rounded-md px-2"+ >+ <View className="min-w-0 shrink flex-row items-center gap-1.5">+ {account.email ? <AccountChip email={account.email} /> : null}+ {account.email && !(account.displayName && inlineName) ? null : (+ <Text+ numberOfLines={1}+ className="min-w-0 shrink text-xs font-t3-medium text-foreground"+ >+ {accountName(account)}+ </Text>+ )}+ <Text className="text-sm font-t3-bold tabular-nums text-foreground">+ {remainingPercent(window)}%+ </Text></View>- </PaceGap>+ {inlineReset && (resetsIn || credits) ? (+ <View className="shrink-0 flex-row items-center gap-1 rounded bg-grouped-card/85 px-1.5 py-0.5">+ {resetsIn ? (+ <>+ <SymbolView+ name="arrow.clockwise"+ size={11}+ tintColorClassName="accent-foreground-muted"+ />+ <Text className="text-xs tabular-nums text-foreground-muted">+ {resetsIn}+ </Text>+ </>+ ) : null}+ {credits ? (+ <>+ <SymbolView name="ticket" size={12} tintColorClassName="accent-icon" />+ <Text className="text-xs font-t3-medium tabular-nums text-foreground">+ {credits}+ </Text>+ </>+ ) : null}+ </View>+ ) : null}+ </View>+ ) : (<ViewpointerEvents="none"className="absolute inset-0 items-center justify-center overflow-hidden rounded-md"@@ -220,65 +314,85 @@ function PoolWindowCard({{index + 1}</Text></View>- </Pressable>- );- })}- </View>- <View>- {pool.columns.map(({ account, window }, index) => {- if (!window) return null;- const credits = account.limits.resetCredits?.availableCount ?? 0;- const resetsIn = formatResetsIn(window, now);- return (- <Pressable- key={account.key}- accessibilityRole="button"- accessibilityLabel={`Segment ${index + 1}, ${accountName(account)}, ${remainingPercent(window)}% left${resetsIn ? `, ${resetsIn}` : ""}${credits ? `, ${credits} reset credits banked` : ""}`}- accessibilityHint="Show account details"- onPress={() => openAccount(account)}- className="min-h-[44px] flex-row items-center gap-2 active:opacity-60"- >- <View className="size-5 items-center justify-center overflow-hidden rounded-md bg-subtle-strong">- <Text className="text-xs font-t3-medium tabular-nums text-foreground">- {index + 1}- </Text>- </View>- <Text- numberOfLines={1}- className="min-w-0 flex-1 text-sm font-t3-medium text-foreground"- >- {accountName(account)}- </Text>- <Text className="text-sm font-t3-medium tabular-nums text-foreground">- {remainingPercent(window)}%+ )}+ </Pressable>+ );+ })}+ </View>+ );+ const legend = (+ <View>+ {pool.columns.map(({ account, window }, index) => {+ if (!window) return null;+ const credits = account.limits.resetCredits?.availableCount ?? 0;+ const resetsIn = formatResetsIn(window, now);+ return (+ <Pressable+ key={account.key}+ accessibilityRole="button"+ accessibilityLabel={`Segment ${index + 1}, ${accountName(account)}, ${remainingPercent(window)}% left${resetsIn ? `, ${resetsIn}` : ""}${credits ? `, ${credits} reset credits banked` : ""}`}+ accessibilityHint="Show account details"+ onPress={() => openAccount(account)}+ className="min-h-[44px] flex-row items-center gap-2 active:opacity-60"+ >+ <View className="size-5 items-center justify-center overflow-hidden rounded-md bg-subtle-strong">+ <Text className="text-xs font-t3-medium tabular-nums text-foreground">+ {index + 1}</Text>- <View className="flex-row items-center gap-1">- {resetsIn ? (- <>- <SymbolView- name="arrow.clockwise"- size={12}- tintColorClassName="accent-foreground-muted"- />- <Text className="text-xs tabular-nums text-foreground-muted">- {resetsIn.replace("resets in ", "")}- </Text>- </>- ) : null}- {credits ? (- <>- {resetsIn ? <Text className="text-xs text-foreground-tertiary">·</Text> : null}- <SymbolView name="ticket" size={13} tintColorClassName="accent-icon" />- <Text className="text-xs font-t3-medium tabular-nums text-foreground">- {credits}- </Text>- </>- ) : null}- </View>- </Pressable>- );- })}+ </View>+ <Text+ numberOfLines={1}+ className="min-w-0 flex-1 text-sm font-t3-medium text-foreground"+ >+ {accountName(account)}+ </Text>+ <Text className="text-sm font-t3-medium tabular-nums text-foreground">+ {remainingPercent(window)}%+ </Text>+ <View className="flex-row items-center gap-1">+ {resetsIn ? (+ <>+ <SymbolView+ name="arrow.clockwise"+ size={12}+ tintColorClassName="accent-foreground-muted"+ />+ <Text className="text-xs tabular-nums text-foreground-muted">+ {resetsIn.replace("resets in ", "")}+ </Text>+ </>+ ) : null}+ {credits ? (+ <>+ {resetsIn ? <Text className="text-xs text-foreground-tertiary">·</Text> : null}+ <SymbolView name="ticket" size={13} tintColorClassName="accent-icon" />+ <Text className="text-xs font-t3-medium tabular-nums text-foreground">+ {credits}+ </Text>+ </>+ ) : null}+ </View>+ </Pressable>+ );+ })}+ </View>+ );+ if (wide) {+ return (+ <View className="flex-row items-center gap-6 rounded-[24px] border-continuous bg-grouped-card p-4">+ <View className="w-44 gap-1">{summary}</View>+ <View className="min-w-0 flex-1 gap-1">+ {bar}+ {inlineLabels ? null : legend}+ </View></View>+ );+ }+ return (+ <View className="gap-3 rounded-[24px] border-continuous bg-grouped-card p-4">+ {summary}+ {bar}+ {legend}</View>);}@@ -288,11 +402,13 @@ export function UsageLimitsSection({failedLabels,selectedEnvironmentIds,cursorPrompt,+ wide = false,}: {readonly now: number;readonly failedLabels: readonly string[];readonly selectedEnvironmentIds: ReadonlySet<EnvironmentId> | null;readonly cursorPrompt?: ReactNode;+ readonly wide?: boolean;}) {const presentations = useAtomValue(environmentPresentations.presentationsWithProvidersAtom);const selected =@@ -347,6 +463,7 @@ export function UsageLimitsSection({}label={details?.label}description={details?.description}+ wide={wide}/>);})}diff --git a/apps/mobile/src/features/usage/UsageRouteScreen.tsx b/apps/mobile/src/features/usage/UsageRouteScreen.tsxindex 5e165cac5ff..1cba6c00547 100644--- a/apps/mobile/src/features/usage/UsageRouteScreen.tsx+++ b/apps/mobile/src/features/usage/UsageRouteScreen.tsx@@ -54,11 +54,12 @@ import { withNativeGlassHeaderItem } from "../layout/native-glass-header-items";import type { UsageChartMetric } from "./usageChartData";import { PROVIDER_LABEL, useProviderColors, useUsageMixColors } from "./usageProviders";-type UsageTab = "usage" | "limits";-const TAB_OPTIONS = [- { value: "usage", label: "Usage" },+type UsageView = UsageChartMetric | "limits";+const VIEW_OPTIONS = [+ { value: "cost", label: "Cost" },+ { value: "tokens", label: "Tokens" },{ value: "limits", label: "Limits" },-] as const satisfies readonly { value: UsageTab; label: string }[];+] as const satisfies readonly { value: UsageView; label: string }[];const WINDOW_OPTIONS = [{ value: 1, label: "24h", accessibilityLabel: "Past 24 hours" },@@ -67,12 +68,11 @@ const WINDOW_OPTIONS = [{ value: 90, label: "90d", accessibilityLabel: "Past 90 days" },] as const;-const METRIC_OPTIONS = [- { value: "cost", label: "Cost" },- { value: "tokens", label: "Tokens" },-] as const satisfies readonly { value: UsageChartMetric; label: string }[];-const CHART_HEIGHT = 180;+const WIDE_CHART_HEIGHT = 260;+// Below this the page keeps the phone's single column.+const WIDE_WIDTH = 600;+const MAX_CONTENT_WIDTH = 1080;const providerLabel = (provider: UsageProviderKind) => PROVIDER_LABEL[provider];const CURSOR_KEYCHAIN_COPY = "Requires access to your Cursor login in macOS Keychain.";@@ -88,21 +88,22 @@ function UsageScreen(props: {const insets = useSafeAreaInsets();const [selection, setSelection] = useState(() => ({params: props.tabParam,- tab: (props.tabParam === "usage" ? "usage" : "limits") as UsageTab,+ view: (props.tabParam === "usage" ? "cost" : "limits") as UsageView,}));if (selection.params !== props.tabParam) {setSelection({params: props.tabParam,- tab: props.tabParam === "usage" ? "usage" : "limits",+ view: props.tabParam === "usage" ? "cost" : "limits",});}- const { tab } = selection;- const setTab = (tab: UsageTab) => setSelection({ params: props.tabParam, tab });+ const { view } = selection;+ const setView = (view: UsageView) => setSelection({ params: props.tabParam, view });+ const [width, setWidth] = useState(0);+ const wide = width >= WIDE_WIDTH;const [windowSelection, setWindowSelection] = useState(() => ({days: 30,window: makeWindow(30),}));- const [metric, setMetric] = useState<UsageChartMetric>("cost");const { days: windowDays, window } = windowSelection;const isPast24Hours = windowDays === 1;const [selectedEnvironmentIds, setSelectedEnvironmentIds] =@@ -112,7 +113,7 @@ function UsageScreen(props: {selectedEnvironmentIds,);const isFocused = useIsFocused();- const limits = useRefreshLimits(selectedEnvironmentIds, isFocused && tab === "limits");+ const limits = useRefreshLimits(selectedEnvironmentIds, isFocused && view === "limits");const cursorAccessEnvironments = cursorKeychainAccessEnvironments(selectedEnvironments);const refreshAfterCursorEnable = () => {void refresh();@@ -154,7 +155,8 @@ function UsageScreen(props: {const [refreshingUsage, setRefreshingUsage] = useState(false);const refreshingRef = useRef(false);- const showingLimits = tab === "limits";+ const showingLimits = view === "limits";+ const metric: UsageChartMetric = view === "tokens" ? "tokens" : "cost";const progress = usageProgress(selectedEnvironments, {refreshing: refreshingUsage,providerLabel,@@ -184,6 +186,27 @@ function UsageScreen(props: {});};+ const chart = {+ merged,+ days: chartDays,+ daily: chartTotals,+ metric,+ sinceDay: window.sinceDay,+ untilDay: window.untilDay,+ isPast24Hours,+ timeZone: window.timeZone,+ };+ const providers = (+ <ProviderSection+ merged={merged}+ metric={metric}+ cursorAccessEnvironments={cursorAccessEnvironments}+ showCursorEnvironment={selectedEnvironments.length > 1}+ onCursorEnabled={refreshAfterCursorEnable}+ compact={wide}+ />+ );+const showEnvironmentFilter = environments.length > 0 || selectedEnvironmentIds !== null;const filterIcon =selectedEnvironmentIds === null@@ -271,8 +294,9 @@ function UsageScreen(props: {contentInsetAdjustmentBehavior="automatic"showsVerticalScrollIndicator={false}className="flex-1"- contentContainerClassName="gap-6 px-5 pt-4"+ contentContainerClassName="px-5 pt-4"contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }}+ onLayout={(event) => setWidth(event.nativeEvent.layout.width)}refreshControl={showingLimits || canReadDiagnostics ? (<RefreshControl@@ -282,107 +306,141 @@ function UsageScreen(props: {) : undefined}>- <SegmentedControl options={TAB_OPTIONS} selected={tab} onSelect={setTab} role="tab" />- <Animated.View- key={tab}- entering={FadeIn.duration(160).reduceMotion(ReduceMotion.System)}- className="gap-6"- >- {showingLimits ? (- <UsageLimitsSection- now={limits.now}- failedLabels={limits.failedLabels}- selectedEnvironmentIds={selectedEnvironmentIds}- cursorPrompt={- cursorAccessEnvironments.length > 0 ? (- <CursorEnableLimits- environments={cursorAccessEnvironments}- onEnabled={refreshAfterCursorEnable}- />- ) : null- }- />- ) : (- <>- <View className="gap-3 ios:flex-row ios:items-center">+ <View className="w-full gap-6 self-center" style={{ maxWidth: MAX_CONTENT_WIDTH }}>+ {wide ? (+ <View className="flex-row items-center gap-3">+ {showingLimits ? (+ <View className="flex-1" />+ ) : (<SegmentedControloptions={WINDOW_OPTIONS}selected={windowDays}onSelect={selectWindow}size="compact"- className="w-full ios:flex-1"- />- <SegmentedControl- options={METRIC_OPTIONS}- selected={metric}- onSelect={setMetric}- size="compact"- className="w-full ios:w-36"+ className="flex-1"/>- </View>- <ChatGptUsageSummary selectedEnvironmentIds={selectedEnvironmentIds} />- {merged.duplicateSources.length > 0 ? (- <Text className="text-sm text-foreground-muted">- Counted once across environments sharing a transcript directory:{" "}- {merged.duplicateSources.join(", ")}- </Text>- ) : null}- {isPending ? (- <Text className="py-16 text-center text-base text-foreground-muted">- Scanning provider transcripts…- </Text>- ) : selectedEnvironments.length === 0 ? (- <Text className="py-16 text-center text-base text-foreground-muted">- {environments.length === 0- ? "Connect an environment to see usage."- : "Select an environment to see usage."}- </Text>- ) : !canReadDiagnostics ? (- <View className="gap-2 py-16">- {selectedEnvironments.map((environment) => (- <Text- key={environment.environmentId}- className="text-center text-base text-foreground-muted"- >- {selectedEnvironments.length > 1 ? `${environment.label}: ` : null}- {environment.error}- </Text>- ))}- </View>- ) : (- <>- {sourceMessages.map((message) => (- <Text key={message} className="text-sm text-foreground-muted">- {message}- </Text>- ))}- <UsageUpdating dimmed={progress.dimmed} label={progress.label}>- <ChartCard- merged={merged}- days={chartDays}- daily={chartTotals}- metric={metric}- sinceDay={window.sinceDay}- untilDay={window.untilDay}- isPast24Hours={isPast24Hours}- timeZone={window.timeZone}- />- <ProviderSection- merged={merged}- metric={metric}- cursorAccessEnvironments={cursorAccessEnvironments}- showCursorEnvironment={selectedEnvironments.length > 1}- onCursorEnabled={refreshAfterCursorEnable}- />- <TotalsSection merged={merged} isPast24Hours={isPast24Hours} />- <CostSection merged={merged} />- <ModelsSection merged={merged} metric={metric} />- </UsageUpdating>- </>)}- </>+ <SegmentedControl+ options={VIEW_OPTIONS}+ selected={view}+ onSelect={setView}+ size="compact"+ role="tab"+ className="w-60"+ />+ </View>+ ) : (+ <SegmentedControl+ options={VIEW_OPTIONS}+ selected={view}+ onSelect={setView}+ role="tab"+ />)}- </Animated.View>+ <Animated.View+ key={showingLimits ? "limits" : "usage"}+ entering={FadeIn.duration(160).reduceMotion(ReduceMotion.System)}+ className="gap-6"+ >+ {showingLimits ? (+ <UsageLimitsSection+ now={limits.now}+ failedLabels={limits.failedLabels}+ selectedEnvironmentIds={selectedEnvironmentIds}+ wide={wide}+ cursorPrompt={+ cursorAccessEnvironments.length > 0 ? (+ <CursorEnableLimits+ environments={cursorAccessEnvironments}+ onEnabled={refreshAfterCursorEnable}+ />+ ) : null+ }+ />+ ) : (+ <>+ {wide ? null : (+ <SegmentedControl+ options={WINDOW_OPTIONS}+ selected={windowDays}+ onSelect={selectWindow}+ size="compact"+ />+ )}+ <ChatGptUsageSummary selectedEnvironmentIds={selectedEnvironmentIds} />+ {merged.duplicateSources.length > 0 ? (+ <Text className="text-sm text-foreground-muted">+ Counted once across environments sharing a transcript directory:{" "}+ {merged.duplicateSources.join(", ")}+ </Text>+ ) : null}+ {isPending ? (+ <Text className="py-16 text-center text-base text-foreground-muted">+ Scanning provider transcripts…+ </Text>+ ) : selectedEnvironments.length === 0 ? (+ <Text className="py-16 text-center text-base text-foreground-muted">+ {environments.length === 0+ ? "Connect an environment to see usage."+ : "Select an environment to see usage."}+ </Text>+ ) : !canReadDiagnostics ? (+ <View className="gap-2 py-16">+ {selectedEnvironments.map((environment) => (+ <Text+ key={environment.environmentId}+ className="text-center text-base text-foreground-muted"+ >+ {selectedEnvironments.length > 1 ? `${environment.label}: ` : null}+ {environment.error}+ </Text>+ ))}+ </View>+ ) : (+ <>+ {sourceMessages.map((message) => (+ <Text key={message} className="text-sm text-foreground-muted">+ {message}+ </Text>+ ))}+ <UsageUpdating dimmed={progress.dimmed} label={progress.label}>+ {wide ? (+ <View className="flex-row gap-6">+ <View className="w-72 gap-6">+ <View className="rounded-[24px] border-continuous bg-grouped-card p-4">+ <UsageSummary merged={merged} metric={metric} />+ </View>+ {providers}+ </View>+ <View className="min-w-0 flex-1">+ <ChartCard+ {...chart}+ height={WIDE_CHART_HEIGHT}+ fill+ title={`${isPast24Hours ? "Hourly" : "Daily"} ${metric === "cost" ? "cost" : "processed tokens"}`}+ />+ </View>+ </View>+ ) : (+ <>+ <ChartCard {...chart} height={CHART_HEIGHT} />+ {providers}+ </>+ )}+ <TotalsSection+ merged={merged}+ isPast24Hours={isPast24Hours}+ columns={width >= 900 ? 6 : wide ? 3 : 2}+ />+ <CostSection merged={merged} wide={wide} />+ <ModelsSection merged={merged} metric={metric} columns={wide ? 2 : 1} />+ </UsageUpdating>+ </>+ )}+ </>+ )}+ </Animated.View>+ </View></ScrollView></SettingsScreen>);@@ -536,38 +594,46 @@ function ChartCard(props: {readonly untilDay: string;readonly isPast24Hours: boolean;readonly timeZone: string;+ readonly height: number;+ /** Replaces the summary when it sits beside the chart. */+ readonly title?: string;+ /** Grows the chart past `height` to match a taller neighbouring column. */+ readonly fill?: boolean;}) {const { merged, metric } = props;const colors = useProviderColors();const hasActivity = props.daily.some((period) => period.totalTokens > 0);+ const [fillHeight, setFillHeight] = useState(0);+ const height = props.fill ? Math.max(fillHeight, props.height) : props.height;+ const chart = hasActivity ? (+ <UsageDailyChart days={props.days} daily={props.daily} metric={metric} height={height} />+ ) : (+ <View style={{ height }} className="items-center justify-center">+ <Text className="text-base text-foreground-muted">No activity in this window.</Text>+ </View>+ );return (- <View className="gap-4 rounded-[24px] border-continuous bg-grouped-card p-4">- <View className="gap-0.5">- <Text className="text-sm text-foreground-muted">- {metric === "cost" ? "Raw token cost" : "Processed tokens"}- </Text>- <Text className="text-4xl font-t3-bold tabular-nums text-foreground">- {metric === "cost" ? `${formatUsd(merged.costUsd)}*` : formatTokens(merged.totalTokens)}- </Text>- <Text className="text-sm text-foreground-muted">- {metric === "cost"- ? "* if billed at full API rate"- : `Across ${formatCount(merged.sessions)} sessions`}- </Text>- </View>-- {hasActivity ? (- <UsageDailyChart- days={props.days}- daily={props.daily}- metric={metric}- height={CHART_HEIGHT}- />+ <View+ className={`gap-4 rounded-[24px] border-continuous bg-grouped-card p-4${props.fill ? " flex-1" : ""}`}+ >+ {props.title ? (+ <Text className="text-sm font-t3-medium text-foreground">{props.title}</Text>) : (- <View style={{ height: CHART_HEIGHT }} className="items-center justify-center">- <Text className="text-base text-foreground-muted">No activity in this window.</Text>+ <UsageSummary merged={merged} metric={metric} />+ )}++ {props.fill ? (+ // Absolute so the measured slot can shrink again when the neighbour gets shorter.+ <View+ className="flex-1"+ style={{ minHeight: props.height }}+ onLayout={(event) => setFillHeight(event.nativeEvent.layout.height)}+ >+ <View className="absolute inset-0">{chart}</View></View>+ ) : (+ chart)}<View className="gap-2">@@ -601,12 +667,33 @@ function ChartCard(props: {);}+function UsageSummary(props: { readonly merged: MergedUsage; readonly metric: UsageChartMetric }) {+ const { merged, metric } = props;+ return (+ <View className="gap-0.5">+ <Text className="text-sm text-foreground-muted">+ {metric === "cost" ? "Raw token cost" : "Processed tokens"}+ </Text>+ <Text className="text-4xl font-t3-bold tabular-nums text-foreground">+ {metric === "cost" ? `${formatUsd(merged.costUsd)}*` : formatTokens(merged.totalTokens)}+ </Text>+ <Text className="text-sm text-foreground-muted">+ {metric === "cost"+ ? "* if billed at full API rate"+ : `Across ${formatCount(merged.sessions)} sessions`}+ </Text>+ </View>+ );+}+function ProviderSection(props: {readonly merged: MergedUsage;readonly metric: UsageChartMetric;readonly cursorAccessEnvironments: readonly EnvironmentUsageStatus[];readonly showCursorEnvironment: boolean;readonly onCursorEnabled: () => void;+ /** Drops the share bar so the list fits beside the chart. */+ readonly compact: boolean;}) {const { merged, metric } = props;const colors = useProviderColors();@@ -654,7 +741,10 @@ function ProviderSection(props: {return (<Viewkey={provider.provider}- className={index === 0 ? "gap-2 p-4" : "gap-2 border-t border-border-subtle p-4"}+ className={cn(+ props.compact ? "gap-0.5 px-4 py-3" : "gap-2 p-4",+ index > 0 && "border-t border-border-subtle",+ )}><View className="flex-row items-baseline justify-between gap-3"><View className="flex-row items-center gap-2">@@ -662,21 +752,35 @@ function ProviderSection(props: {className="size-2.5 rounded-full"style={{ backgroundColor: colors[provider.provider] }}/>- <Text className="text-lg text-foreground">{PROVIDER_LABEL[provider.provider]}</Text>+ <Text+ className={+ props.compact ? "text-base text-foreground" : "text-lg text-foreground"+ }+ >+ {PROVIDER_LABEL[provider.provider]}+ </Text></View>- <Text className="text-lg tabular-nums text-foreground">+ <Text+ className={+ props.compact+ ? "text-base tabular-nums text-foreground"+ : "text-lg tabular-nums text-foreground"+ }+ >{metric === "cost"? formatUsd(provider.costUsd): formatTokens(provider.totalTokens)}</Text></View>- <View className="h-1 flex-row overflow-hidden rounded-full bg-subtle">- <View- className="h-full rounded-full"- style={{ flex: share, backgroundColor: colors[provider.provider] }}- />- <View style={{ flex: 1 - share }} />- </View>+ {props.compact ? null : (+ <View className="h-1 flex-row overflow-hidden rounded-full bg-subtle">+ <View+ className="h-full rounded-full"+ style={{ flex: share, backgroundColor: colors[provider.provider] }}+ />+ <View style={{ flex: 1 - share }} />+ </View>+ )}<Text className="text-sm text-foreground-muted">{metric === "cost"? `${formatPercent(share)} of cost · ${formatTokens(provider.totalTokens)} tokens`@@ -689,7 +793,11 @@ function ProviderSection(props: {);}-function TotalsSection(props: { readonly merged: MergedUsage; readonly isPast24Hours: boolean }) {+function TotalsSection(props: {+ readonly merged: MergedUsage;+ readonly isPast24Hours: boolean;+ readonly columns: number;+}) {const { merged } = props;const activePeriods = (props.isPast24Hours ? merged.hourly : merged.daily).filter((period) => period.totalTokens > 0,@@ -702,11 +810,13 @@ function TotalsSection(props: { readonly merged: MergedUsage; readonly isPast24H<SettingsSection title="Totals"><View className="flex-row flex-wrap"><MetricCell+ columns={props.columns}label="Processed tokens"value={formatTokens(merged.totalTokens)}detail={`${formatTokens(periodAverage)} per active ${props.isPast24Hours ? "hour" : "day"}`}/><MetricCell+ columns={props.columns}label="Cache savings"value={formatUsd(merged.costQuality.cacheSavingsUsd)}detail={@@ -716,21 +826,25 @@ function TotalsSection(props: { readonly merged: MergedUsage; readonly isPast24H}/><MetricCell+ columns={props.columns}label="Cached input"value={formatTokens(merged.cachedInputTokens)}detail={`${formatPercent(cachedShare)} of observed input`}/><MetricCell+ columns={props.columns}label="Uncached input"value={formatTokens(merged.uncachedInputTokens)}detail={`${formatTokens(merged.cacheCreationTokens)} cache writes`}/><MetricCell+ columns={props.columns}label="Output"value={formatTokens(merged.outputTokens)}detail={`incl. ${formatTokens(merged.reasoningTokens)} reasoning`}/><MetricCell+ columns={props.columns}label="Unpriced"value={formatPercent(merged.costQuality.unpricedShare)}detail="of records, excluded from cost"@@ -740,7 +854,7 @@ function TotalsSection(props: { readonly merged: MergedUsage; readonly isPast24H);}-function CostSection(props: { readonly merged: MergedUsage }) {+function CostSection(props: { readonly merged: MergedUsage; readonly wide: boolean }) {const { categoryCost, speedCost } = props.merged;const colors = useUsageMixColors();const byType = [@@ -765,16 +879,26 @@ function CostSection(props: { readonly merged: MergedUsage }) {return (<SettingsSection title="Cost">- <ShareBar label="By type" segments={byType} />- {speedCost.fast + speedCost.ultrafast > 0 ? (- <View className="border-t border-border-subtle">- <ShareBar- label="By speed"- segments={bySpeed}- aside={`${formatUsd(speedCost.premium)} premium`}- />+ <View className={props.wide ? "flex-row" : undefined}>+ <View className={props.wide ? "min-w-0 flex-1" : undefined}>+ <ShareBar label="By type" segments={byType} /></View>- ) : null}+ {speedCost.fast + speedCost.ultrafast > 0 ? (+ <View+ className={+ props.wide+ ? "min-w-0 flex-1 border-l border-border-subtle"+ : "border-t border-border-subtle"+ }+ >+ <ShareBar+ label="By speed"+ segments={bySpeed}+ aside={`${formatUsd(speedCost.premium)} premium`}+ />+ </View>+ ) : null}+ </View></SettingsSection>);}@@ -821,9 +945,10 @@ function MetricCell(props: {readonly label: string;readonly value: string;readonly detail: string;+ readonly columns: number;}) {return (- <View className="w-1/2 gap-0.5 p-4">+ <View className="gap-0.5 p-4" style={{ width: `${100 / props.columns}%` }}><Text className="text-sm text-foreground-muted">{props.label}</Text><Text className="text-xl font-t3-medium tabular-nums text-foreground">{props.value}</Text><Text className="text-xs text-foreground-tertiary">{props.detail}</Text>@@ -831,7 +956,11 @@ function MetricCell(props: {);}-function ModelsSection(props: { readonly merged: MergedUsage; readonly metric: UsageChartMetric }) {+function ModelsSection(props: {+ readonly merged: MergedUsage;+ readonly metric: UsageChartMetric;+ readonly columns: 1 | 2;+}) {const { merged, metric } = props;const colors = useProviderColors();if (merged.models.length === 0) return null;@@ -845,42 +974,45 @@ function ModelsSection(props: { readonly merged: MergedUsage; readonly metric: Ureturn (<SettingsSection title="By model">- {ordered.map((model, index) => (- <View- key={`${model.provider}:${model.model}`}- className={- index === 0- ? "flex-row items-center gap-3 p-4"- : "flex-row items-center gap-3 border-t border-border-subtle p-4"- }- >+ <View className="flex-row flex-wrap">+ {ordered.map((model, index) => (<View- className="size-2.5 shrink-0 rounded-full"- style={{ backgroundColor: colors[model.provider] }}- />- <View className="min-w-0 flex-1 gap-0.5">- <Text className="text-base text-foreground" numberOfLines={1}>- {model.model}- </Text>- <Text className="text-sm text-foreground-muted">+ key={`${model.provider}:${model.model}`}+ className={cn(+ "flex-row items-center gap-3 p-4",+ index >= props.columns && "border-t border-border-subtle",+ index % props.columns === 1 && "border-l border-border-subtle",+ )}+ style={{ width: `${100 / props.columns}%` }}+ >+ <View+ className="size-2.5 shrink-0 rounded-full"+ style={{ backgroundColor: colors[model.provider] }}+ />+ <View className="min-w-0 flex-1 gap-0.5">+ <Text className="text-base text-foreground" numberOfLines={1}>+ {model.model}+ </Text>+ <Text className="text-sm text-foreground-muted">+ {metric === "tokens"+ ? `${formatPercent(model.tokenShare)} of tokens · ${+ isModelCostUnknown(model) ? "no known rates" : formatUsd(model.costUsd)+ }`+ : isModelCostUnknown(model)+ ? `no known rates · ${formatTokens(model.totalTokens)} tokens`+ : `${formatPercent(model.costShare)} of cost · ${formatTokens(model.totalTokens)} tokens`}+ </Text>+ </View>+ <Text className="text-base tabular-nums text-foreground">{metric === "tokens"- ? `${formatPercent(model.tokenShare)} of tokens · ${- isModelCostUnknown(model) ? "no known rates" : formatUsd(model.costUsd)- }`+ ? formatTokens(model.totalTokens): isModelCostUnknown(model)- ? `no known rates · ${formatTokens(model.totalTokens)} tokens`- : `${formatPercent(model.costShare)} of cost · ${formatTokens(model.totalTokens)} tokens`}+ ? "Unpriced"+ : formatUsd(model.costUsd)}</Text></View>- <Text className="text-base tabular-nums text-foreground">- {metric === "tokens"- ? formatTokens(model.totalTokens)- : isModelCostUnknown(model)- ? "Unpriced"- : formatUsd(model.costUsd)}- </Text>- </View>- ))}+ ))}+ </View></SettingsSection>);}