Skip to content

Commit 520dec0

Browse files
committed
DRY ProviderName up
1 parent 05b2700 commit 520dec0

File tree

1 file changed

+61
-69
lines changed

1 file changed

+61
-69
lines changed

packages/types/src/provider-settings.ts

Lines changed: 61 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -33,56 +33,6 @@ import {
3333

3434
export const DEFAULT_CONSECUTIVE_MISTAKE_LIMIT = 3
3535

36-
/**
37-
* ProviderName
38-
*/
39-
40-
export const providerNames = [
41-
"anthropic",
42-
"claude-code",
43-
"glama",
44-
"openrouter",
45-
"bedrock",
46-
"vertex",
47-
"openai",
48-
"ollama",
49-
"vscode-lm",
50-
"lmstudio",
51-
"gemini",
52-
"gemini-cli",
53-
"openai-native",
54-
"mistral",
55-
"moonshot",
56-
"deepseek",
57-
"deepinfra",
58-
"doubao",
59-
"qwen-code",
60-
"unbound",
61-
"requesty",
62-
"human-relay",
63-
"fake-ai",
64-
"xai",
65-
"groq",
66-
"chutes",
67-
"litellm",
68-
"huggingface",
69-
"cerebras",
70-
"sambanova",
71-
"zai",
72-
"fireworks",
73-
"featherless",
74-
"io-intelligence",
75-
"roo",
76-
"vercel-ai-gateway",
77-
] as const
78-
79-
export const providerNamesSchema = z.enum(providerNames)
80-
81-
export type ProviderName = z.infer<typeof providerNamesSchema>
82-
83-
export const isProviderName = (key: unknown): key is ProviderName =>
84-
typeof key === "string" && providerNames.includes(key as ProviderName)
85-
8636
/**
8737
* DynamicProvider
8838
*
@@ -99,7 +49,7 @@ export const dynamicProviders = [
9949
"requesty",
10050
"unbound",
10151
"glama",
102-
] as const satisfies readonly ProviderName[]
52+
] as const
10353

10454
export type DynamicProvider = (typeof dynamicProviders)[number]
10555

@@ -112,50 +62,90 @@ export const isDynamicProvider = (key: string): key is DynamicProvider =>
11262
* Local providers require localhost API calls in order to get the model list.
11363
*/
11464

115-
export const localProviders = ["ollama", "lmstudio"] as const satisfies readonly ProviderName[]
65+
export const localProviders = ["ollama", "lmstudio"] as const
11666

11767
export type LocalProvider = (typeof localProviders)[number]
11868

11969
export const isLocalProvider = (key: string): key is LocalProvider => localProviders.includes(key as LocalProvider)
12070

12171
/**
122-
* FauxProvider
72+
* InternalProvider
12373
*
124-
* Faux providers do not make external inference calls and therefore do not have
125-
* model lists.
74+
* Internal providers require internal VSCode API calls in order to get the
75+
* model list.
12676
*/
12777

128-
export const fauxProviders = ["fake-ai", "human-relay"] as const satisfies readonly ProviderName[]
78+
export const internalProviders = ["vscode-lm"] as const
12979

130-
export type FauxProvider = (typeof fauxProviders)[number]
80+
export type InternalProvider = (typeof internalProviders)[number]
13181

132-
export const isFauxProvider = (key: string): key is FauxProvider => fauxProviders.includes(key as FauxProvider)
82+
export const isInternalProvider = (key: string): key is InternalProvider =>
83+
internalProviders.includes(key as InternalProvider)
13384

13485
/**
13586
* CustomProvider
13687
*
13788
* Custom providers are completely configurable within Roo Code settings.
13889
*/
13990

140-
export const customProviders = ["openai-native"] as const satisfies readonly ProviderName[]
91+
export const customProviders = ["openai"] as const
14192

14293
export type CustomProvider = (typeof customProviders)[number]
14394

14495
export const isCustomProvider = (key: string): key is CustomProvider => customProviders.includes(key as CustomProvider)
14596

14697
/**
147-
* InternalProvider
98+
* FauxProvider
14899
*
149-
* Internal providers require internal VSCode API calls in order to get the
150-
* model list.
100+
* Faux providers do not make external inference calls and therefore do not have
101+
* model lists.
151102
*/
152103

153-
export const internalProviders = ["vscode-lm"] as const satisfies readonly ProviderName[]
104+
export const fauxProviders = ["fake-ai", "human-relay"] as const
154105

155-
export type InternalProvider = (typeof internalProviders)[number]
106+
export type FauxProvider = (typeof fauxProviders)[number]
156107

157-
export const isInternalProvider = (key: string): key is InternalProvider =>
158-
internalProviders.includes(key as InternalProvider)
108+
export const isFauxProvider = (key: string): key is FauxProvider => fauxProviders.includes(key as FauxProvider)
109+
110+
/**
111+
* ProviderName
112+
*/
113+
114+
export const providerNames = [
115+
...dynamicProviders,
116+
...localProviders,
117+
...internalProviders,
118+
...customProviders,
119+
...fauxProviders,
120+
"anthropic",
121+
"bedrock",
122+
"cerebras",
123+
"chutes",
124+
"claude-code",
125+
"doubao",
126+
"deepseek",
127+
"featherless",
128+
"fireworks",
129+
"gemini",
130+
"gemini-cli",
131+
"groq",
132+
"mistral",
133+
"moonshot",
134+
"openai-native",
135+
"qwen-code",
136+
"roo",
137+
"sambanova",
138+
"vertex",
139+
"xai",
140+
"zai",
141+
] as const
142+
143+
export const providerNamesSchema = z.enum(providerNames)
144+
145+
export type ProviderName = z.infer<typeof providerNamesSchema>
146+
147+
export const isProviderName = (key: unknown): key is ProviderName =>
148+
typeof key === "string" && providerNames.includes(key as ProviderName)
159149

160150
/**
161151
* ProviderSettingsEntry
@@ -546,16 +536,18 @@ export const getModelId = (settings: ProviderSettings): string | undefined => {
546536
return modelIdKey ? settings[modelIdKey] : undefined
547537
}
548538

549-
export const modelIdKeysByProvider: Record<Exclude<ProviderName, FauxProvider | CustomProvider>, ModelIdKey> = {
539+
export const modelIdKeysByProvider: Record<
540+
Exclude<ProviderName, InternalProvider | CustomProvider | FauxProvider>,
541+
ModelIdKey
542+
> = {
550543
anthropic: "apiModelId",
551544
"claude-code": "apiModelId",
552545
glama: "glamaModelId",
553546
openrouter: "openRouterModelId",
554547
bedrock: "apiModelId",
555548
vertex: "apiModelId",
556-
openai: "openAiModelId",
549+
"openai-native": "openAiModelId",
557550
ollama: "ollamaModelId",
558-
"vscode-lm": "apiModelId", // This doesn't appear to use `ModelIdKey` at all.
559551
lmstudio: "lmStudioModelId",
560552
gemini: "apiModelId",
561553
"gemini-cli": "apiModelId",

0 commit comments

Comments
 (0)