@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 71 lines 1.8 KB
Raw
1 const FAMILY_PREFIXES = ["Claude ", "GPT-", "GPT ", "Gemini ", "Muse ", "Grok "] as const;
2
3 // Words that describe a variant within a family rather than name a model. Off the
4 // family's native provider there is no icon saying which family "4 Pro" belongs to.
5 const VARIANT_WORDS = new Set([
6 "pro",
7 "flash",
8 "mini",
9 "max",
10 "lite",
11 "nano",
12 "ultra",
13 "plus",
14 "fast",
15 "turbo",
16 "preview",
17 "latest",
18 "thinking",
19 "reasoning",
20 "build",
21 "code",
22 "image",
23 "vision",
24 "audio",
25 "live",
26 "custom",
27 "tools",
28 "exp",
29 "experimental",
30 "chat",
31 "tts",
32 "stt",
33 "non",
34 "transcribe",
35 ]);
36
37 const VERSION = /^v?\d+(?:\.\d+)*[a-z]?$/i;
38
39 const VENDOR_PREFIX = /^[A-Z][\w.&\- ]{0,24}: (?=\S)/;
40
41 export function modelShortName(
42 name: string,
43 nativeFamilies: ReadonlyArray<string>,
44 ): string | undefined {
45 const unprefixed = name.replace(VENDOR_PREFIX, "");
46 const short =
47 withoutFamily(unprefixed, nativeFamilies) ?? (namesModel(unprefixed) ? unprefixed : name);
48 return short === name ? undefined : short;
49 }
50
51 function withoutFamily(name: string, nativeFamilies: ReadonlyArray<string>): string | undefined {
52 const prefix = FAMILY_PREFIXES.find((candidate) => name.startsWith(candidate));
53 if (!prefix) return undefined;
54 const rest = name.slice(prefix.length).trim();
55 const keep = nativeFamilies.includes(prefix)
56 ? nonVersionWords(rest).length > 0
57 : namesModel(rest);
58 if (!keep) return undefined;
59 return /\s/.test(rest) ? rest : rest.replaceAll("-", " ");
60 }
61
62 function nonVersionWords(text: string): ReadonlyArray<string> {
63 return text
64 .replace(/\(.*?\)/g, " ")
65 .split(/[\s-]+/)
66 .filter((word) => word.length > 0 && !VERSION.test(word));
67 }
68
69 function namesModel(text: string): boolean {
70 return nonVersionWords(text).some((word) => !VARIANT_WORDS.has(word.toLowerCase()));
71 }