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

usageProviders.ts

52 lines1.6 KB

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