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

providerIconUtils.ts

125 lines4.0 KB

1import { ProviderDriverKind } from "@t3tools/contracts";
2import {
3 AntigravityIcon,
4 ClaudeAI,
5 CognitionIcon,
6 CursorIcon,
7 DeepSeekIcon,
8 DevinIcon,
9 Gemini,
10 GLMIcon,
11 GrokIcon,
12 Icon,
13 KimiIcon,
14 NvidiaIcon,
15 OpenAI,
16 OpenCodeIcon,
17} from "../Icons";
18import { PROVIDER_OPTIONS } from "../../session-logic";
19​
20export const PROVIDER_ICON_BY_PROVIDER: Partial<Record<ProviderDriverKind, Icon>> = {
21 [ProviderDriverKind.make("codex")]: OpenAI,
22 [ProviderDriverKind.make("claudeAgent")]: ClaudeAI,
23 [ProviderDriverKind.make("opencode")]: OpenCodeIcon,
24 [ProviderDriverKind.make("cursor")]: CursorIcon,
25 [ProviderDriverKind.make("devin")]: DevinIcon,
26 [ProviderDriverKind.make("grok")]: GrokIcon,
27 [ProviderDriverKind.make("antigravity")]: AntigravityIcon,
28};
29​
30export type ModelEsque = {
31 slug: string;
32 name: string;
33 shortName?: string | undefined;
34 subProvider?: string | undefined;
35 aliases?: ReadonlyArray<string> | undefined;
36 isDefault?: boolean | undefined;
37 badge?: "new" | undefined;
38 isLegacy?: boolean | undefined;
39 isUnavailable?: boolean | undefined;
40};
41​
42export type ModelProviderBrand = {
43 readonly label: string;
44 readonly icon: Icon;
45};
46​
47function modelIdentity(model: ModelEsque): string {
48 return `${model.slug} ${model.name} ${model.subProvider ?? ""}`.toLowerCase();
50​
51/** Resolve the company behind a model exposed through Devin. */
52export function getDevinModelProviderBrand(model: ModelEsque): ModelProviderBrand {
53 const identity = modelIdentity(model);
54 if (identity.includes("claude") || identity.includes("anthropic")) {
55 return { label: "Anthropic", icon: ClaudeAI };
56 }
57 if (identity.includes("gpt") || identity.includes("openai") || identity.includes("codex")) {
58 return { label: "OpenAI", icon: OpenAI };
59 }
60 if (identity.includes("gemini") || identity.includes("google")) {
61 return { label: "Google", icon: Gemini };
62 }
63 if (identity.includes("glm") || identity.includes("zhipu") || identity.includes("z.ai")) {
64 return { label: "Z.ai", icon: GLMIcon };
65 }
66 if (identity.includes("kimi") || identity.includes("moonshot")) {
67 return { label: "Moonshot AI", icon: KimiIcon };
68 }
69 if (identity.includes("deepseek")) {
70 return { label: "DeepSeek", icon: DeepSeekIcon };
71 }
72 if (identity.includes("grok") || identity.includes("xai")) {
73 return { label: "xAI", icon: GrokIcon };
74 }
75 if (identity.includes("nemotron") || identity.includes("nvidia")) {
76 return { label: "NVIDIA", icon: NvidiaIcon };
77 }
78 if (identity.includes("swe-") || identity.includes("adaptive") || identity.includes("inkling")) {
79 return { label: "Cognition", icon: CognitionIcon };
80 }
81 return { label: "Devin", icon: DevinIcon };
83​
84export function getModelProviderBrand(
85 driverKind: ProviderDriverKind,
86 model: ModelEsque,
87): ModelProviderBrand {
88 if (driverKind === ProviderDriverKind.make("devin")) {
89 return getDevinModelProviderBrand(model);
90 }
91 return {
92 label: PROVIDER_OPTIONS.find((option) => option.value === driverKind)?.label ?? driverKind,
93 icon: PROVIDER_ICON_BY_PROVIDER[driverKind] ?? DevinIcon,
94 };
96​
97function escapeRegExp(value: string): string {
98 return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
100​
101function stripLeadingQualifier(value: string, qualifier: string | null | undefined): string {
102 const trimmedQualifier = qualifier?.trim();
103 if (!trimmedQualifier) {
104 return value;
105 }
106​
107 const pattern = new RegExp(`^${escapeRegExp(trimmedQualifier)}(?:\\s*[.:/-]\\s*|\\s+)`, "iu");
108 return value.replace(pattern, "").trim() || value;
110​
111export function getDisplayModelName(
112 model: ModelEsque,
113 options?: { preferShortName?: boolean },
114): string {
115 const name = options?.preferShortName && model.shortName ? model.shortName : model.name;
116 return stripLeadingQualifier(name, model.subProvider);
118​
119export function getTriggerDisplayModelName(model: ModelEsque): string {
120 return getDisplayModelName(model, { preferShortName: true });
122​
123export function getTriggerDisplayModelLabel(model: ModelEsque): string {
124 return getTriggerDisplayModelName(model);