The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { UsageProviderKind } from "@t3tools/contracts"; |
| 2 | |
| 3 | import { ProviderDriverKind } from "@t3tools/contracts"; |
| 4 | |
| 5 | import type { UsageMetric } from "./usageShortcuts"; |
| 6 | |
| 7 | type UsageProviderPresentation = { |
| 8 | readonly label: string; |
| 9 | readonly color: string; |
| 10 | readonly driverKind: ProviderDriverKind; |
| 11 | }; |
| 12 | |
| 13 | export const PROVIDER_PRESENTATION = { |
| 14 | codex: { |
| 15 | label: "Codex", |
| 16 | color: "var(--contrast-foreground)", |
| 17 | driverKind: ProviderDriverKind.make("codex"), |
| 18 | }, |
| 19 | claude: { |
| 20 | label: "Claude Code", |
| 21 | color: "#d97757", |
| 22 | driverKind: ProviderDriverKind.make("claudeAgent"), |
| 23 | }, |
| 24 | grok: { |
| 25 | label: "Grok Build", |
| 26 | color: "color-mix(in oklab, var(--contrast-foreground) 72%, var(--background))", |
| 27 | driverKind: ProviderDriverKind.make("grok"), |
| 28 | }, |
| 29 | cursor: { label: "Cursor", color: "#8b8b8b", driverKind: ProviderDriverKind.make("cursor") }, |
| 30 | opencode: { |
| 31 | label: "OpenCode", |
| 32 | color: "#5b9bbd", |
| 33 | driverKind: ProviderDriverKind.make("opencode"), |
| 34 | }, |
| 35 | antigravity: { |
| 36 | label: "Antigravity", |
| 37 | color: "#8c7bd1", |
| 38 | driverKind: ProviderDriverKind.make("antigravity"), |
| 39 | }, |
| 40 | pi: { |
| 41 | label: "Pi", |
| 42 | color: "#4d9f8a", |
| 43 | driverKind: ProviderDriverKind.make("pi"), |
| 44 | }, |
| 45 | muse: { |
| 46 | label: "Muse Code", |
| 47 | color: "#0866ff", |
| 48 | driverKind: ProviderDriverKind.make("muse"), |
| 49 | }, |
| 50 | } satisfies Record<UsageProviderKind, UsageProviderPresentation>; |
| 51 | |
| 52 | export const PROVIDER_ORDER = Object.keys(PROVIDER_PRESENTATION) as UsageProviderKind[]; |
| 53 | |
| 54 | export function providersWithUsage( |
| 55 | totals: readonly { |
| 56 | readonly provider: UsageProviderKind; |
| 57 | readonly costUsd: number; |
| 58 | readonly totalTokens: number; |
| 59 | }[], |
| 60 | ): readonly UsageProviderKind[] { |
| 61 | const active = new Set( |
| 62 | totals |
| 63 | .filter((entry) => entry.totalTokens > 0 || entry.costUsd > 0) |
| 64 | .map((entry) => entry.provider), |
| 65 | ); |
| 66 | return PROVIDER_ORDER.filter((provider) => active.has(provider)); |
| 67 | } |
| 68 | |
| 69 | export function rankProvidersByMetric( |
| 70 | providers: readonly UsageProviderKind[], |
| 71 | totals: readonly { |
| 72 | readonly provider: UsageProviderKind; |
| 73 | readonly costUsd: number; |
| 74 | readonly totalTokens: number; |
| 75 | }[], |
| 76 | metric: UsageMetric, |
| 77 | ): readonly UsageProviderKind[] { |
| 78 | const field = metric === "cost" ? "costUsd" : "totalTokens"; |
| 79 | const value = (provider: UsageProviderKind) => |
| 80 | totals.find((entry) => entry.provider === provider)?.[field] ?? 0; |
| 81 | return providers.toSorted((left, right) => value(right) - value(left)); |
| 82 | } |