Open History to see the last commit
1import type { UsageProviderKind } from "@t3tools/contracts";
2
3import {
4 AntigravityIcon,
5 ClaudeAI,
6 CursorIcon,
7 GrokIcon,
8 type Icon,
9 OpenAI,
10 OpenCodeIcon,
11} from "../Icons";
12
13type UsageProviderPresentation = {
14 readonly label: string;
15 readonly color: string;
16 readonly mark: Icon;
17};
18
19/**
20 * Exhaustive presentation for providers supported by the usage contract.
21 * Declaration order is reused by every chart and table, so adding a provider
22 * only requires its contract support and one entry here.
23 */
24export const PROVIDER_PRESENTATION = {
25 codex: {
26 label: "Codex",
27 color: "var(--contrast-foreground)",
28 mark: OpenAI,
29 },
30 claude: {
31 label: "Claude Code",
32 color: "#d97757",
33 mark: ClaudeAI,
34 },
35 grok: {
36 label: "Grok Build",
37 // Contrast-aware neutral between the Codex series and muted chart chrome.
38 color: "color-mix(in oklab, var(--contrast-foreground) 72%, var(--background))",
39 mark: GrokIcon,
40 },
41 cursor: { label: "Cursor", color: "#8b8b8b", mark: CursorIcon },
42 opencode: { label: "OpenCode", color: "#5b9bbd", mark: OpenCodeIcon },
43 antigravity: { label: "Antigravity", color: "#8c7bd1", mark: AntigravityIcon },
44} satisfies Record<UsageProviderKind, UsageProviderPresentation>;
45
46/** Stable provider reading order across charts, summaries, tables, and hover rows. */
47export const PROVIDER_ORDER = Object.keys(PROVIDER_PRESENTATION) as UsageProviderKind[];
48
49/** Providers with real activity, independent of the metric currently displayed. */
50export function providersWithUsage(
51 totals: readonly {
52 readonly provider: UsageProviderKind;
53 readonly costUsd: number;
54 readonly totalTokens: number;
55 }[],
56): readonly UsageProviderKind[] {
57 const active = new Set(
58 totals
59 .filter((entry) => entry.totalTokens > 0 || entry.costUsd > 0)
60 .map((entry) => entry.provider),
61 );
62 return PROVIDER_ORDER.filter((provider) => active.has(provider));
63}