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

usageProviders.ts

60 lines1.7 KB

1import type { UsageProviderKind } from "@t3tools/contracts";
2​
3import { ProviderDriverKind } from "@t3tools/contracts";
4​
5type UsageProviderPresentation = {
6 readonly label: string;
7 readonly color: string;
8 readonly driverKind: ProviderDriverKind;
9};
10​
11export const PROVIDER_PRESENTATION = {
12 codex: {
13 label: "Codex",
14 color: "var(--contrast-foreground)",
15 driverKind: ProviderDriverKind.make("codex"),
16 },
17 claude: {
18 label: "Claude Code",
19 color: "#d97757",
20 driverKind: ProviderDriverKind.make("claudeAgent"),
21 },
22 grok: {
23 label: "Grok Build",
24 color: "color-mix(in oklab, var(--contrast-foreground) 72%, var(--background))",
25 driverKind: ProviderDriverKind.make("grok"),
26 },
27 cursor: { label: "Cursor", color: "#8b8b8b", driverKind: ProviderDriverKind.make("cursor") },
28 opencode: {
29 label: "OpenCode",
30 color: "#5b9bbd",
31 driverKind: ProviderDriverKind.make("opencode"),
32 },
33 antigravity: {
34 label: "Antigravity",
35 color: "#8c7bd1",
36 driverKind: ProviderDriverKind.make("antigravity"),
37 },
38 pi: {
39 label: "Pi",
40 color: "#4d9f8a",
41 driverKind: ProviderDriverKind.make("pi"),
42 },
43} satisfies Record<UsageProviderKind, UsageProviderPresentation>;
44​
45export const PROVIDER_ORDER = Object.keys(PROVIDER_PRESENTATION) as UsageProviderKind[];
46​
47export function providersWithUsage(
48 totals: readonly {
49 readonly provider: UsageProviderKind;
50 readonly costUsd: number;
51 readonly totalTokens: number;
52 }[],
53): readonly UsageProviderKind[] {
54 const active = new Set(
55 totals
56 .filter((entry) => entry.totalTokens > 0 || entry.costUsd > 0)
57 .map((entry) => entry.provider),
58 );
59 return PROVIDER_ORDER.filter((provider) => active.has(provider));