@@ -27,53 +27,126 @@ import {
2727 internationalZAiModels ,
2828} from "./providers/index.js"
2929
30+ /**
31+ * constants
32+ */
33+
34+ export const DEFAULT_CONSECUTIVE_MISTAKE_LIMIT = 3
35+
36+ /**
37+ * DynamicProvider
38+ *
39+ * Dynamic provider requires external API calls in order to get the model list.
40+ */
41+
42+ export const dynamicProviders = [
43+ "openrouter" ,
44+ "vercel-ai-gateway" ,
45+ "huggingface" ,
46+ "litellm" ,
47+ "deepinfra" ,
48+ "io-intelligence" ,
49+ "requesty" ,
50+ "unbound" ,
51+ "glama" ,
52+ ] as const
53+
54+ export type DynamicProvider = ( typeof dynamicProviders ) [ number ]
55+
56+ export const isDynamicProvider = ( key : string ) : key is DynamicProvider =>
57+ dynamicProviders . includes ( key as DynamicProvider )
58+
59+ /**
60+ * LocalProvider
61+ *
62+ * Local providers require localhost API calls in order to get the model list.
63+ */
64+
65+ export const localProviders = [ "ollama" , "lmstudio" ] as const
66+
67+ export type LocalProvider = ( typeof localProviders ) [ number ]
68+
69+ export const isLocalProvider = ( key : string ) : key is LocalProvider => localProviders . includes ( key as LocalProvider )
70+
71+ /**
72+ * InternalProvider
73+ *
74+ * Internal providers require internal VSCode API calls in order to get the
75+ * model list.
76+ */
77+
78+ export const internalProviders = [ "vscode-lm" ] as const
79+
80+ export type InternalProvider = ( typeof internalProviders ) [ number ]
81+
82+ export const isInternalProvider = ( key : string ) : key is InternalProvider =>
83+ internalProviders . includes ( key as InternalProvider )
84+
85+ /**
86+ * CustomProvider
87+ *
88+ * Custom providers are completely configurable within Roo Code settings.
89+ */
90+
91+ export const customProviders = [ "openai" ] as const
92+
93+ export type CustomProvider = ( typeof customProviders ) [ number ]
94+
95+ export const isCustomProvider = ( key : string ) : key is CustomProvider => customProviders . includes ( key as CustomProvider )
96+
97+ /**
98+ * FauxProvider
99+ *
100+ * Faux providers do not make external inference calls and therefore do not have
101+ * model lists.
102+ */
103+
104+ export const fauxProviders = [ "fake-ai" , "human-relay" ] as const
105+
106+ export type FauxProvider = ( typeof fauxProviders ) [ number ]
107+
108+ export const isFauxProvider = ( key : string ) : key is FauxProvider => fauxProviders . includes ( key as FauxProvider )
109+
30110/**
31111 * ProviderName
32112 */
33113
34114export const providerNames = [
115+ ...dynamicProviders ,
116+ ...localProviders ,
117+ ...internalProviders ,
118+ ...customProviders ,
119+ ...fauxProviders ,
35120 "anthropic" ,
36- "claude-code" ,
37- "glama" ,
38- "openrouter" ,
39121 "bedrock" ,
40- "vertex" ,
41- "openai" ,
42- "ollama" ,
43- "vscode-lm" ,
44- "lmstudio" ,
122+ "cerebras" ,
123+ "chutes" ,
124+ "claude-code" ,
125+ "doubao" ,
126+ "deepseek" ,
127+ "featherless" ,
128+ "fireworks" ,
45129 "gemini" ,
46130 "gemini-cli" ,
47- "openai-native " ,
131+ "groq " ,
48132 "mistral" ,
49133 "moonshot" ,
50- "deepseek" ,
51- "deepinfra" ,
52- "doubao" ,
134+ "openai-native" ,
53135 "qwen-code" ,
54- "unbound" ,
55- "requesty" ,
56- "human-relay" ,
57- "fake-ai" ,
58- "xai" ,
59- "groq" ,
60- "chutes" ,
61- "litellm" ,
62- "huggingface" ,
63- "cerebras" ,
136+ "roo" ,
64137 "sambanova" ,
138+ "vertex" ,
139+ "xai" ,
65140 "zai" ,
66- "fireworks" ,
67- "featherless" ,
68- "io-intelligence" ,
69- "roo" ,
70- "vercel-ai-gateway" ,
71141] as const
72142
73143export const providerNamesSchema = z . enum ( providerNames )
74144
75145export type ProviderName = z . infer < typeof providerNamesSchema >
76146
147+ export const isProviderName = ( key : unknown ) : key is ProviderName =>
148+ typeof key === "string" && providerNames . includes ( key as ProviderName )
149+
77150/**
78151 * ProviderSettingsEntry
79152 */
@@ -91,11 +164,6 @@ export type ProviderSettingsEntry = z.infer<typeof providerSettingsEntrySchema>
91164 * ProviderSettings
92165 */
93166
94- /**
95- * Default value for consecutive mistake limit
96- */
97- export const DEFAULT_CONSECUTIVE_MISTAKE_LIMIT = 3
98-
99167const baseProviderSettingsSchema = z . object ( {
100168 includeMaxTokens : z . boolean ( ) . optional ( ) ,
101169 diffEnabled : z . boolean ( ) . optional ( ) ,
@@ -124,7 +192,7 @@ const anthropicSchema = apiModelIdProviderModelSchema.extend({
124192 apiKey : z . string ( ) . optional ( ) ,
125193 anthropicBaseUrl : z . string ( ) . optional ( ) ,
126194 anthropicUseAuthToken : z . boolean ( ) . optional ( ) ,
127- anthropicBeta1MContext : z . boolean ( ) . optional ( ) , // Enable 'context-1m-2025-08-07' beta for 1M context window
195+ anthropicBeta1MContext : z . boolean ( ) . optional ( ) , // Enable 'context-1m-2025-08-07' beta for 1M context window.
128196} )
129197
130198const claudeCodeSchema = apiModelIdProviderModelSchema . extend ( {
@@ -160,7 +228,7 @@ const bedrockSchema = apiModelIdProviderModelSchema.extend({
160228 awsModelContextWindow : z . number ( ) . optional ( ) ,
161229 awsBedrockEndpointEnabled : z . boolean ( ) . optional ( ) ,
162230 awsBedrockEndpoint : z . string ( ) . optional ( ) ,
163- awsBedrock1MContext : z . boolean ( ) . optional ( ) , // Enable 'context-1m-2025-08-07' beta for 1M context window
231+ awsBedrock1MContext : z . boolean ( ) . optional ( ) , // Enable 'context-1m-2025-08-07' beta for 1M context window.
164232} )
165233
166234const vertexSchema = apiModelIdProviderModelSchema . extend ( {
@@ -335,7 +403,7 @@ const qwenCodeSchema = apiModelIdProviderModelSchema.extend({
335403} )
336404
337405const rooSchema = apiModelIdProviderModelSchema . extend ( {
338- // No additional fields needed - uses cloud authentication
406+ // No additional fields needed - uses cloud authentication.
339407} )
340408
341409const vercelAiGatewaySchema = baseProviderSettingsSchema . extend ( {
@@ -440,7 +508,11 @@ export type ProviderSettingsWithId = z.infer<typeof providerSettingsWithIdSchema
440508
441509export const PROVIDER_SETTINGS_KEYS = providerSettingsSchema . keyof ( ) . options
442510
443- export const MODEL_ID_KEYS : Partial < keyof ProviderSettings > [ ] = [
511+ /**
512+ * ModelIdKey
513+ */
514+
515+ export const modelIdKeys = [
444516 "apiModelId" ,
445517 "glamaModelId" ,
446518 "openRouterModelId" ,
@@ -455,13 +527,63 @@ export const MODEL_ID_KEYS: Partial<keyof ProviderSettings>[] = [
455527 "ioIntelligenceModelId" ,
456528 "vercelAiGatewayModelId" ,
457529 "deepInfraModelId" ,
458- ]
530+ ] as const satisfies readonly ( keyof ProviderSettings ) [ ]
531+
532+ export type ModelIdKey = ( typeof modelIdKeys ) [ number ]
459533
460534export const getModelId = ( settings : ProviderSettings ) : string | undefined => {
461- const modelIdKey = MODEL_ID_KEYS . find ( ( key ) => settings [ key ] )
462- return modelIdKey ? ( settings [ modelIdKey ] as string ) : undefined
535+ const modelIdKey = modelIdKeys . find ( ( key ) => settings [ key ] )
536+ return modelIdKey ? settings [ modelIdKey ] : undefined
537+ }
538+
539+ /**
540+ * TypicalProvider
541+ */
542+
543+ export type TypicalProvider = Exclude < ProviderName , InternalProvider | CustomProvider | FauxProvider >
544+
545+ export const isTypicalProvider = ( key : unknown ) : key is TypicalProvider =>
546+ isProviderName ( key ) && ! isInternalProvider ( key ) && ! isCustomProvider ( key ) && ! isFauxProvider ( key )
547+
548+ export const modelIdKeysByProvider : Record < TypicalProvider , ModelIdKey > = {
549+ anthropic : "apiModelId" ,
550+ "claude-code" : "apiModelId" ,
551+ glama : "glamaModelId" ,
552+ openrouter : "openRouterModelId" ,
553+ bedrock : "apiModelId" ,
554+ vertex : "apiModelId" ,
555+ "openai-native" : "openAiModelId" ,
556+ ollama : "ollamaModelId" ,
557+ lmstudio : "lmStudioModelId" ,
558+ gemini : "apiModelId" ,
559+ "gemini-cli" : "apiModelId" ,
560+ mistral : "apiModelId" ,
561+ moonshot : "apiModelId" ,
562+ deepseek : "apiModelId" ,
563+ deepinfra : "deepInfraModelId" ,
564+ doubao : "apiModelId" ,
565+ "qwen-code" : "apiModelId" ,
566+ unbound : "unboundModelId" ,
567+ requesty : "requestyModelId" ,
568+ xai : "apiModelId" ,
569+ groq : "apiModelId" ,
570+ chutes : "apiModelId" ,
571+ litellm : "litellmModelId" ,
572+ huggingface : "huggingFaceModelId" ,
573+ cerebras : "apiModelId" ,
574+ sambanova : "apiModelId" ,
575+ zai : "apiModelId" ,
576+ fireworks : "apiModelId" ,
577+ featherless : "apiModelId" ,
578+ "io-intelligence" : "ioIntelligenceModelId" ,
579+ roo : "apiModelId" ,
580+ "vercel-ai-gateway" : "vercelAiGatewayModelId" ,
463581}
464582
583+ /**
584+ * ANTHROPIC_STYLE_PROVIDERS
585+ */
586+
465587// Providers that use Anthropic-style API protocol.
466588export const ANTHROPIC_STYLE_PROVIDERS : ProviderName [ ] = [ "anthropic" , "claude-code" , "bedrock" ]
467589
@@ -482,6 +604,10 @@ export const getApiProtocol = (provider: ProviderName | undefined, modelId?: str
482604 return "openai"
483605}
484606
607+ /**
608+ * MODELS_BY_PROVIDER
609+ */
610+
485611export const MODELS_BY_PROVIDER : Record <
486612 Exclude < ProviderName , "fake-ai" | "human-relay" | "gemini-cli" | "lmstudio" | "openai" | "ollama" > ,
487613 { id : ProviderName ; label : string ; models : string [ ] }
@@ -579,19 +705,3 @@ export const MODELS_BY_PROVIDER: Record<
579705 deepinfra : { id : "deepinfra" , label : "DeepInfra" , models : [ ] } ,
580706 "vercel-ai-gateway" : { id : "vercel-ai-gateway" , label : "Vercel AI Gateway" , models : [ ] } ,
581707}
582-
583- export const dynamicProviders = [
584- "glama" ,
585- "huggingface" ,
586- "litellm" ,
587- "openrouter" ,
588- "requesty" ,
589- "unbound" ,
590- "deepinfra" ,
591- "vercel-ai-gateway" ,
592- ] as const satisfies readonly ProviderName [ ]
593-
594- export type DynamicProvider = ( typeof dynamicProviders ) [ number ]
595-
596- export const isDynamicProvider = ( key : string ) : key is DynamicProvider =>
597- dynamicProviders . includes ( key as DynamicProvider )
0 commit comments