Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

UsagePage.tsx

712 lines29.0 KB

1import { useAtomValue } from "@effect/atom-react";
2import type { UsageProviderKind } from "@t3tools/contracts";
3import { CheckIcon, RefreshCwIcon, XIcon } from "lucide-react";
4import { useMemo, useState } from "react";
5​
6import type { DailyTotals, HourlyTotals } from "@t3tools/shared/usageMerge";
7​
8import { isElectron } from "../../env";
9import { cn } from "../../lib/utils";
10import { environmentPresentations } from "../../state/presentation";
11import { serverEnvironment } from "../../state/server";
12import { useUsage, type EnvironmentUsageStatus } from "../../state/usage";
13import { useAtomCommand } from "../../state/use-atom-command";
14import {
15 enumerateDays,
16 enumerateHourStarts,
17 formatCount,
18 formatDateTimeShort,
19 formatDayShort,
20 formatHourShort,
21 formatPercent,
22 formatTokens,
23 formatUsd,
24 makeWindow,
25} from "@t3tools/shared/usageFormat";
26import { Button } from "../ui/button";
27import { ScrollArea } from "../ui/scroll-area";
28import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
29import { SidebarInset } from "../ui/sidebar";
30import { Skeleton } from "../ui/skeleton";
31import { Toggle, ToggleGroup } from "../ui/toggle-group";
32import {
33 WorkspaceBreadcrumb,
34 WorkspaceBreadcrumbItem,
35 WorkspaceBreadcrumbSeparator,
36} from "../WorkspaceBreadcrumb";
37import { WorkspacePageContainer } from "../WorkspacePageContainer";
38import { WorkspacePageHeader } from "../WorkspacePageHeader";
39import { UsageLimitsSection } from "./UsageLimits";
40import { UsagePriceOverrides } from "./UsagePriceOverrides";
41import { UsageProviderChart, type UsageChartMetric } from "./UsageProviderChart";
42import { PROVIDER_ORDER, PROVIDER_PRESENTATION, providersWithUsage } from "./usageProviders";
43​
44type UsageMetric = UsageChartMetric | "limits";
45const METRIC_OPTIONS = [
46 { value: "cost", label: "Cost" },
47 { value: "tokens", label: "Tokens" },
48 { value: "limits", label: "Limits" },
49] as const satisfies readonly { value: UsageMetric; label: string }[];
50​
51function isUsageMetric(value: string | null | undefined): value is UsageMetric {
52 return METRIC_OPTIONS.some((option) => option.value === value);
54​
55const WINDOW_OPTIONS = [
56 { days: 1, label: "Past 24h" },
57 { days: 7, label: "7 days" },
58 { days: 30, label: "30 days" },
59 { days: 90, label: "90 days" },
60] as const;
61​
62export function UsagePage() {
63 const [windowSelection, setWindowSelection] = useState(() => ({
64 days: 30,
65 window: makeWindow(30),
66 }));
67 const [metric, setMetric] = useState<UsageMetric>("cost");
68 const showingLimits = metric === "limits";
69 const [breakdown, setBreakdown] = useState<"model" | "time">("model");
70 const { days: windowDays, window } = windowSelection;
71 const isPast24Hours = windowDays === 1;
72 const { merged, environments, isPending, isPartial, refresh } = useUsage(window);
73 const presentations = useAtomValue(environmentPresentations.presentationsAtom);
74 const refreshProviders = useAtomCommand(serverEnvironment.refreshProviders, {
75 reportFailure: false,
76 });
77​
78 // Hold the content until every environment is terminal. Rendering merged
79 // totals while devices are still answering makes every number on the page
80 // jump as each one lands.
81 const settling = isPending || isPartial;
82​
83 const days = useMemo(
84 () => enumerateDays(window.sinceDay, window.untilDay),
85 [window.sinceDay, window.untilDay],
86 );
87 const hours = useMemo(
88 () =>
89 window.sinceTime === undefined || window.untilTime === undefined
90 ? []
91 : enumerateHourStarts(window.sinceTime, window.untilTime),
92 [window.sinceTime, window.untilTime],
93 );
94 // Newest first: the window can run 90 periods, so the interesting end
95 // belongs at the top of the table.
96 const breakdownPeriods = useMemo<readonly (DailyTotals | HourlyTotals)[]>(
97 () => (isPast24Hours ? merged.hourly : merged.daily).toReversed(),
98 [isPast24Hours, merged.daily, merged.hourly],
99 );
100 const breakdownModels = useMemo(
101 () =>
102 breakdown === "model" && metric === "tokens"
103 ? merged.models.toSorted(
104 (left, right) => right.totalTokens - left.totalTokens || right.costUsd - left.costUsd,
105 )
106 : merged.models,
107 [breakdown, merged.models, metric],
108 );
109 const activeProviders = useMemo(() => providersWithUsage(merged.providers), [merged.providers]);
110 const timeValueColumnWidth = `${60 / (activeProviders.length + 2)}%`;
111​
112 const selectWindow = (days: number) => {
113 setWindowSelection({
114 days,
115 window: makeWindow(days, undefined, days === 1 ? "hour" : "day"),
116 });
117 };
118 const refreshWindow = () => {
119 if (showingLimits) {
120 for (const [environmentId, presentation] of presentations) {
121 if (presentation.connection.phase === "connected" && presentation.serverConfig !== null) {
122 void refreshProviders({ environmentId, input: {} });
123 }
124 }
125 return;
126 }
127 const nextWindow = makeWindow(windowDays, undefined, isPast24Hours ? "hour" : "day");
128 if (
129 nextWindow.sinceDay === window.sinceDay &&
130 nextWindow.untilDay === window.untilDay &&
131 nextWindow.sinceTime === window.sinceTime &&
132 nextWindow.untilTime === window.untilTime
133 ) {
134 refresh();
135 } else {
136 setWindowSelection({ days: windowDays, window: nextWindow });
137 }
138 };
139 const windowLabel =
140 isPast24Hours && window.sinceTime !== undefined && window.untilTime !== undefined
141 ? `${formatDateTimeShort(window.sinceTime, window.timeZone)} to ${formatDateTimeShort(window.untilTime, window.timeZone)}`
142 : `${formatDayShort(window.sinceDay)} to ${formatDayShort(window.untilDay)}`;
143 const topbarContent = (
144 <div className="flex w-full min-w-0 items-center gap-3">
145 <WorkspaceBreadcrumb ariaLabel="Usage breadcrumb" className="min-w-0">
146 <WorkspaceBreadcrumbItem current>
147 <h1>Usage</h1>
148 </WorkspaceBreadcrumbItem>
149 {showingLimits ? null : (
150 <>
151 <WorkspaceBreadcrumbSeparator className="hidden md:flex" />
152 <WorkspaceBreadcrumbItem className="hidden min-w-0 shrink md:flex">
153 <span className="truncate">{windowLabel}</span>
154 </WorkspaceBreadcrumbItem>
155 </>
156 )}
157 </WorkspaceBreadcrumb>
158 <div className="ms-auto hidden min-w-0 items-center justify-end gap-2 lg:flex">
159 <ToggleGroup
160 aria-label="Usage metric"
161 variant="segmented"
162 value={[metric]}
163 onValueChange={(next) => {
164 const value = next[0];
165 if (isUsageMetric(value)) setMetric(value);
166 }}
167 >
168 {METRIC_OPTIONS.map((option) => (
169 <Toggle key={option.value} value={option.value}>
170 {option.label}
171 </Toggle>
172 ))}
173 </ToggleGroup>
174 {/* The period does not apply to Limits, so it stays in place but
175 disabled; unmounting it shifted the metric toggle ~300px. */}
176 <ToggleGroup
177 aria-label="Usage period"
178 variant="segmented"
179 value={[String(windowDays)]}
180 disabled={showingLimits}
181 onValueChange={(next) => {
182 const value = next[0];
183 if (value) selectWindow(Number(value));
184 }}
185 >
186 {WINDOW_OPTIONS.map((option) => (
187 <Toggle key={option.days} value={String(option.days)}>
188 {option.label}
189 </Toggle>
190 ))}
191 </ToggleGroup>
192 <Button
193 onClick={refreshWindow}
194 aria-label={showingLimits ? "Refresh limits" : "Refresh usage"}
195 size="icon-sm"
196 variant="ghost"
197 >
198 <RefreshCwIcon className="size-3.5" />
199 </Button>
200 </div>
201 <div className="ms-auto flex min-w-0 items-center justify-end gap-1 lg:hidden">
202 <Select
203 value={metric}
204 onValueChange={(value) => {
205 if (isUsageMetric(value)) setMetric(value);
206 }}
207 >
208 <SelectTrigger
209 aria-label="Usage metric"
210 size="compact"
211 variant="ghost"
212 className="w-auto min-w-0"
213 >
214 <SelectValue>
215 {METRIC_OPTIONS.find((option) => option.value === metric)?.label}
216 </SelectValue>
217 </SelectTrigger>
218 <SelectPopup align="end" alignItemWithTrigger={false}>
219 {METRIC_OPTIONS.map((option) => (
220 <SelectItem key={option.value} value={option.value}>
221 {option.label}
222 </SelectItem>
223 ))}
224 </SelectPopup>
225 </Select>
226 <Select
227 value={String(windowDays)}
228 disabled={showingLimits}
229 onValueChange={(value) => selectWindow(Number(value))}
230 >
231 <SelectTrigger
232 aria-label="Usage period"
233 size="compact"
234 variant="ghost"
235 className="w-auto min-w-0"
236 >
237 <SelectValue>
238 {WINDOW_OPTIONS.find((option) => option.days === windowDays)?.label}
239 </SelectValue>
240 </SelectTrigger>
241 <SelectPopup align="end" alignItemWithTrigger={false}>
242 {WINDOW_OPTIONS.map((option) => (
243 <SelectItem key={option.days} value={String(option.days)}>
244 {option.label}
245 </SelectItem>
246 ))}
247 </SelectPopup>
248 </Select>
249 <Button
250 onClick={refreshWindow}
251 aria-label={showingLimits ? "Refresh limits" : "Refresh usage"}
252 size="icon-sm"
253 variant="ghost"
254 >
255 <RefreshCwIcon className="size-3.5" />
256 </Button>
257 </div>
258 </div>
259 );
260​
261 return (
262 <SidebarInset className="h-dvh min-h-0 overflow-hidden overscroll-y-none bg-background text-foreground isolate">
263 <div className="flex min-h-0 min-w-0 flex-1 flex-col bg-background text-foreground">
264 <WorkspacePageHeader electron={isElectron}>{topbarContent}</WorkspacePageHeader>
265​
266 <ScrollArea className="min-h-0 flex-1">
267 <WorkspacePageContainer width="wide">
268 {!showingLimits ? (
269 <div className="flex justify-end">
270 <UsagePriceOverrides usage={environments} />
271 </div>
272 ) : null}
273 {showingLimits ? (
274 <UsageLimitsSection />
275 ) : settling ? (
276 <>
277 {environments.length > 1 ? <UsageDeviceStrip environments={environments} /> : null}
278 <UsageSkeleton />
279 </>
280 ) : (
281 <>
282 <UsageCoverageNotice
283 environments={environments}
284 duplicateSources={merged.duplicateSources}
285 staleEnvironments={merged.staleEnvironments}
286 />
287​
288 <section className="grid gap-6 lg:grid-cols-[minmax(0,18rem)_minmax(0,1fr)]">
289 <div className="flex min-w-0 flex-col gap-5">
290 <div className="flex flex-col gap-1">
291 <span className="text-4xl font-semibold text-foreground tabular-nums">
292 {metric === "cost"
293 ? formatUsd(merged.costUsd)
294 : formatTokens(merged.totalTokens)}
295 </span>
296 <span className="text-xs text-muted-foreground">
297 {metric === "cost"
298 ? `${formatCount(merged.sessions)} sessions · API estimate`
299 : `${formatCount(merged.sessions)} sessions`}
300 </span>
301 </div>
302​
303 {activeProviders.map((provider) => {
304 const totals = merged.providers.find((entry) => entry.provider === provider);
305 const share =
306 metric === "cost" ? (totals?.costShare ?? 0) : (totals?.tokenShare ?? 0);
307 const providerSessions = totals?.sessions ?? 0;
308 const sessionLabel = `${formatCount(providerSessions)} ${
309 providerSessions === 1 ? "session" : "sessions"
310 }`;
311 return (
312 <div key={provider} className="flex flex-col gap-1">
313 <div className="flex items-baseline justify-between gap-4">
314 <span className="flex min-w-0 items-center gap-2 text-sm text-foreground">
315 <span
316 aria-hidden
317 className="size-2 shrink-0 rounded-full"
318 style={{
319 backgroundColor: PROVIDER_PRESENTATION[provider].color,
320 }}
321 />
322 <ProviderMark provider={provider} className="size-4" />
323 <span className="flex min-w-0 items-baseline gap-1.5">
324 <span className="truncate">
325 {PROVIDER_PRESENTATION[provider].label}
326 </span>
327 <span className="shrink-0 whitespace-nowrap text-[11px] text-muted-foreground tabular-nums">
328 {sessionLabel}
329 </span>
330 </span>
331 </span>
332 <span className="shrink-0 text-sm font-medium text-foreground tabular-nums">
333 {metric === "cost"
334 ? formatUsd(totals?.costUsd ?? 0)
335 : formatTokens(totals?.totalTokens ?? 0)}
336 </span>
337 </div>
338 <span className="text-xs text-muted-foreground">
339 {metric === "cost"
340 ? `${formatPercent(share)} of cost · ${formatTokens(totals?.totalTokens ?? 0)} tokens`
341 : `${formatPercent(share)} of tokens · ${formatUsd(totals?.costUsd ?? 0)}`}
342 </span>
343 </div>
344 );
345 })}
346 </div>
347​
348 <div className="flex min-w-0 flex-col gap-3">
349 <h2 className="text-sm font-medium text-foreground">
350 {isPast24Hours ? "Hourly" : "Daily"}{" "}
351 {metric === "tokens" ? "processed tokens" : "cost"}
352 </h2>
353 <UsageProviderChart
354 providers={activeProviders}
355 days={days}
356 daily={merged.daily}
357 hours={hours}
358 hourly={merged.hourly}
359 metric={metric}
360 referenceTime={window.untilTime}
361 resolution={isPast24Hours ? "hour" : "day"}
362 timeZone={window.timeZone}
363 />
364 </div>
365 </section>
366​
367 <section className="flex flex-col gap-2">
368 <h2 className="text-sm font-medium text-foreground">Totals</h2>
369 <div className="grid grid-cols-2 gap-x-6 gap-y-4 py-1 md:grid-cols-5">
370 <Metric label="Processed tokens" value={formatTokens(merged.totalTokens)} />
371 <Metric label="Cached input" value={formatTokens(merged.cachedInputTokens)} />
372 <Metric
373 label="Uncached input"
374 value={formatTokens(merged.uncachedInputTokens)}
375 />
376 <Metric label="Output" value={formatTokens(merged.outputTokens)} />
377 <Metric
378 label="Cache savings"
379 value={formatUsd(merged.costQuality.cacheSavingsUsd)}
380 />
381 </div>
382 </section>
383​
384 <section className="flex flex-col gap-3">
385 <div className="flex items-center justify-between gap-3">
386 <h2 className="text-sm font-medium text-foreground">Breakdown</h2>
387 <ToggleGroup
388 aria-label="Usage breakdown"
389 variant="segmented"
390 value={[breakdown]}
391 onValueChange={(next) => {
392 const value = next[0];
393 if (value === "model" || value === "time") setBreakdown(value);
394 }}
395 >
396 {(
397 [
398 { value: "model", label: "Model" },
399 { value: "time", label: isPast24Hours ? "Hour" : "Day" },
400 ] as const
401 ).map((option) => (
402 <Toggle key={option.value} value={option.value}>
403 {option.label}
404 </Toggle>
405 ))}
406 </ToggleGroup>
407 </div>
408​
409 {breakdown === "model" ? (
410 <table className="w-full table-fixed text-sm">
411 <colgroup>
412 <col className="w-2/5" />
413 <col className="w-1/5" />
414 <col className="w-1/5" />
415 <col className="w-1/5" />
416 </colgroup>
417 <thead>
418 <tr className="border-b border-border text-left text-xs text-muted-foreground">
419 <th className="py-2 font-normal">Model</th>
420 <th className="py-2 text-right font-normal">Cost</th>
421 <th className="py-2 text-right font-normal">Share</th>
422 <th className="py-2 text-right font-normal">Tokens</th>
423 </tr>
424 </thead>
425 <tbody>
426 {breakdownModels.length === 0 ? (
427 <tr>
428 <td colSpan={4} className="py-6 text-center text-muted-foreground">
429 No activity in this window.
430 </td>
431 </tr>
432 ) : (
433 breakdownModels.map((model) => (
434 <tr
435 key={`${model.provider}:${model.model}`}
436 className="border-b border-border/50 transition-colors hover:bg-muted/50"
437 >
438 <td className="py-2 text-foreground">
439 <span className="flex items-center gap-2">
440 <ProviderMark provider={model.provider} className="size-3.5" />
441 {model.model}
442 </span>
443 </td>
444 <td className="py-2 text-right text-foreground tabular-nums">
445 {formatUsd(model.costUsd)}
446 </td>
447 <td className="py-2 text-right text-muted-foreground tabular-nums">
448 {formatPercent(model.costShare)}
449 </td>
450 <td className="py-2 text-right text-muted-foreground tabular-nums">
451 {formatTokens(model.totalTokens)}
452 </td>
453 </tr>
454 ))
455 )}
456 </tbody>
457 </table>
458 ) : (
459 <table className="w-full table-fixed text-sm">
460 <colgroup>
461 <col className="w-2/5" />
462 {activeProviders.map((provider) => (
463 <col key={provider} style={{ width: timeValueColumnWidth }} />
464 ))}
465 <col style={{ width: timeValueColumnWidth }} />
466 <col style={{ width: timeValueColumnWidth }} />
467 </colgroup>
468 <thead>
469 <tr className="border-b border-border text-left text-xs text-muted-foreground">
470 <th className="py-2 font-normal">{isPast24Hours ? "Hour" : "Day"}</th>
471 {activeProviders.map((provider) => (
472 <th key={provider} className="py-2 text-right font-normal">
473 {PROVIDER_PRESENTATION[provider].label}
474 </th>
475 ))}
476 <th className="py-2 text-right font-normal">Total</th>
477 <th className="py-2 text-right font-normal">Tokens</th>
478 </tr>
479 </thead>
480 <tbody>
481 {breakdownPeriods.length === 0 ? (
482 <tr>
483 <td
484 colSpan={activeProviders.length + 3}
485 className="py-6 text-center text-muted-foreground"
486 >
487 No activity in this window.
488 </td>
489 </tr>
490 ) : (
491 breakdownPeriods.map((period) => (
492 <tr
493 key={"hourStart" in period ? period.hourStart : period.day}
494 className="border-b border-border/50 transition-colors hover:bg-muted/50"
495 >
496 <td className="py-2 text-foreground">
497 {"hourStart" in period
498 ? formatHourShort(period.hourStart, window.timeZone)
499 : formatDayShort(period.day)}
500 </td>
501 {activeProviders.map((provider) => (
502 <td
503 key={provider}
504 className="py-2 text-right text-muted-foreground tabular-nums"
505 >
506 {formatUsd(period.byProvider.get(provider)?.costUsd ?? 0)}
507 </td>
508 ))}
509 <td className="py-2 text-right text-foreground tabular-nums">
510 {formatUsd(period.costUsd)}
511 </td>
512 <td className="py-2 text-right text-muted-foreground tabular-nums">
513 {formatTokens(period.totalTokens)}
514 </td>
515 </tr>
516 ))
517 )}
518 </tbody>
519 </table>
520 )}
521 </section>
522 </>
523 )}
524 </WorkspacePageContainer>
525 </ScrollArea>
526 </div>
527 </SidebarInset>
528 );
530​
531/** Brand mark for the harness a row belongs to. */
532function ProviderMark({
533 provider,
534 className,
535}: {
536 readonly provider: UsageProviderKind;
537 readonly className: string;
538}) {
539 const Mark = PROVIDER_PRESENTATION[provider].mark;
540 return <Mark className={cn("shrink-0", className)} aria-hidden />;
542​
543function Metric({ label, value }: { readonly label: string; readonly value: string }) {
544 return (
545 <div className="flex min-w-0 flex-col gap-0.5">
546 <span className="text-xs text-muted-foreground">{label}</span>
547 <span className="text-base font-medium text-foreground tabular-nums">{value}</span>
548 </div>
549 );
551​
552/**
553 * Says plainly when the totals are incomplete: an environment that failed, or
554 * one whose transcripts another environment already reported. Environments
555 * that are still answering never reach this notice; the page shows the
556 * loading skeleton until every one is terminal.
557 */
558function UsageCoverageNotice({
559 environments,
560 duplicateSources,
561 staleEnvironments,
562}: {
563 readonly environments: readonly EnvironmentUsageStatus[];
564 readonly duplicateSources: readonly string[];
565 readonly staleEnvironments: readonly string[];
566}) {
567 const failed = environments.filter((environment) => environment.error !== null);
568 const stale = environments.filter((environment) =>
569 staleEnvironments.includes(environment.environmentId),
570 );
571 if (failed.length === 0 && stale.length === 0 && duplicateSources.length === 0) {
572 return null;
573 }
574​
575 return (
576 <div className="flex flex-col gap-1 border border-border px-3 py-2 text-xs text-muted-foreground">
577 {failed.map((environment) => (
578 <span key={environment.label}>{environment.label} could not report usage.</span>
579 ))}
580 {stale.map((environment) => (
581 <span key={environment.label}>
582 {environment.label} runs an older server version and is excluded from totals.
583 </span>
584 ))}
585 {duplicateSources.length > 0 ? (
586 <span>
587 Counted once across environments sharing a transcript directory:{" "}
588 {duplicateSources.join(", ")}
589 </span>
590 ) : null}
591 </div>
592 );
594​
595/**
596 * Per-device progress while the page waits for every environment to answer.
597 * Only rendered with two or more devices; a lone device has nothing to
598 * enumerate.
599 */
600function UsageDeviceStrip({
601 environments,
602}: {
603 readonly environments: readonly EnvironmentUsageStatus[];
604}) {
605 const scanning = environments.filter(
606 (environment) => environment.summary === null && environment.error === null,
607 );
608 return (
609 <div className="flex flex-wrap items-baseline gap-x-4 gap-y-1 border border-border px-3 py-2 text-xs">
610 {environments.map((environment) => {
611 if (environment.summary !== null) {
612 return (
613 <span
614 key={environment.environmentId}
615 className="flex items-center gap-1 text-foreground"
616 >
617 <CheckIcon className="size-3 text-emerald-600 dark:text-emerald-300/90" aria-hidden />
618 {environment.label}
619 </span>
620 );
621 }
622 if (environment.error !== null) {
623 return (
624 <span
625 key={environment.environmentId}
626 className="flex items-center gap-1 text-destructive"
627 >
628 <XIcon className="size-3" aria-hidden />
629 {environment.label}
630 </span>
631 );
632 }
633 return (
634 <span
635 key={environment.environmentId}
636 className="animate-status-pulse text-muted-foreground"
637 >
638 {environment.label}…
639 </span>
640 );
641 })}
642 <span className="ms-auto text-muted-foreground">
643 {scanning.length === 1
644 ? "1 device still scanning"
645 : `${scanning.length} devices still scanning`}
646 </span>
647 </div>
648 );
650​
651/**
652 * Stand-in with the loaded page's shape, using the shared `Skeleton` bars so it
653 * breathes with the same `animate-skeleton` pulse as every other loading state.
654 * Blocks fill in exactly once when the last device answers.
655 */
656function UsageSkeleton() {
657 return (
658 <>
659 <section className="grid gap-6 lg:grid-cols-[minmax(0,18rem)_minmax(0,1fr)]">
660 <div className="flex flex-col gap-5">
661 <div className="flex flex-col gap-1">
662 <Skeleton className="h-10 w-36" />
663 <Skeleton className="h-4 w-32" />
664 </div>
665 {PROVIDER_ORDER.map((provider) => (
666 <div key={provider} className="flex flex-col gap-1">
667 <div className="flex min-h-5 items-center justify-between gap-4">
668 <span className="flex items-center gap-2">
669 <Skeleton className="size-2 shrink-0 rounded-full" />
670 <Skeleton className="size-4 shrink-0 rounded-full" />
671 <Skeleton className="h-3.5 w-20" />
672 </span>
673 <Skeleton className="h-3.5 w-14" />
674 </div>
675 <Skeleton className="h-4 w-36" />
676 </div>
677 ))}
678 </div>
679​
680 <div className="flex flex-col gap-3">
681 <Skeleton className="h-5 w-24" />
682 <div className="flex flex-col gap-1">
683 <Skeleton className="ml-16 h-56 bg-muted-foreground/10" />
684 <Skeleton className="ml-16 h-4 bg-muted-foreground/10" />
685 </div>
686 </div>
687 </section>
688​
689 <section className="flex flex-col gap-2">
690 <h2 className="text-sm font-medium text-foreground">Totals</h2>
691 <div className="grid grid-cols-2 gap-x-6 gap-y-4 py-1 md:grid-cols-5">
692 {["Processed tokens", "Cached input", "Uncached input", "Output", "Cache savings"].map(
693 (label) => (
694 <div key={label} className="flex flex-col gap-0.5">
695 <span className="text-xs text-muted-foreground">{label}</span>
696 <Skeleton className="h-6 w-16" />
697 </div>
698 ),
699 )}
700 </div>
701 </section>
702​
703 <section className="flex flex-col gap-3">
704 <div className="flex items-center justify-between gap-3">
705 <h2 className="text-sm font-medium text-foreground">Breakdown</h2>
706 <Skeleton className="h-7 w-28 rounded-lg" />
707 </div>
708 <Skeleton className="h-44 bg-muted-foreground/10" />
709 </section>
710 </>
711 );