Skip to main content

vtcode_config/models/model_id/
capabilities.rs

1use crate::models::Provider;
2
3use super::ModelId;
4
5#[cfg(not(docsrs))]
6#[allow(dead_code)]
7mod capability_generated {
8    include!(concat!(env!("OUT_DIR"), "/model_capabilities.rs"));
9}
10
11#[cfg(docsrs)]
12#[allow(dead_code)]
13mod capability_generated {
14    #[derive(Clone, Copy)]
15    pub struct Pricing {
16        pub input: Option<f64>,
17        pub output: Option<f64>,
18        pub cache_read: Option<f64>,
19        pub cache_write: Option<f64>,
20    }
21
22    #[derive(Clone, Copy)]
23    pub struct Entry {
24        pub provider: &'static str,
25        pub id: &'static str,
26        pub display_name: &'static str,
27        pub description: &'static str,
28        pub context_window: usize,
29        pub max_output_tokens: Option<usize>,
30        pub reasoning: bool,
31        pub tool_call: bool,
32        pub vision: bool,
33        pub input_modalities: &'static [&'static str],
34        pub caching: bool,
35        pub structured_output: bool,
36        pub pricing: Pricing,
37    }
38
39    pub const ENTRIES: &[Entry] = &[];
40    pub const PROVIDERS: &[&str] = &[];
41
42    pub fn metadata_for(_provider: &str, _id: &str) -> Option<Entry> {
43        None
44    }
45
46    pub fn models_for_provider(_provider: &str) -> Option<&'static [&'static str]> {
47        None
48    }
49}
50
51/// Catalog metadata generated from `docs/models.json`.
52#[derive(Clone, Copy, Debug, PartialEq)]
53pub struct ModelPricing {
54    pub input: Option<f64>,
55    pub output: Option<f64>,
56    pub cache_read: Option<f64>,
57    pub cache_write: Option<f64>,
58}
59
60#[derive(Clone, Copy, Debug, PartialEq)]
61pub struct ModelCatalogEntry {
62    pub provider: &'static str,
63    pub id: &'static str,
64    pub display_name: &'static str,
65    pub description: &'static str,
66    pub context_window: usize,
67    pub max_output_tokens: Option<usize>,
68    pub reasoning: bool,
69    pub tool_call: bool,
70    pub vision: bool,
71    pub input_modalities: &'static [&'static str],
72    pub caching: bool,
73    pub structured_output: bool,
74    pub pricing: ModelPricing,
75}
76
77fn catalog_provider_key(provider: &str) -> &str {
78    if provider.eq_ignore_ascii_case("google") || provider.eq_ignore_ascii_case("gemini") {
79        "gemini"
80    } else if provider.eq_ignore_ascii_case("openai") {
81        "openai"
82    } else if provider.eq_ignore_ascii_case("anthropic") {
83        "anthropic"
84    } else if provider.eq_ignore_ascii_case("deepseek") {
85        "deepseek"
86    } else if provider.eq_ignore_ascii_case("openrouter") {
87        "openrouter"
88    } else if provider.eq_ignore_ascii_case("ollama") {
89        "ollama"
90    } else if provider.eq_ignore_ascii_case("lmstudio") {
91        "lmstudio"
92    } else if provider.eq_ignore_ascii_case("moonshot") {
93        "moonshot"
94    } else if provider.eq_ignore_ascii_case("zai") {
95        "zai"
96    } else if provider.eq_ignore_ascii_case("minimax") {
97        "minimax"
98    } else if provider.eq_ignore_ascii_case("huggingface") {
99        "huggingface"
100    } else {
101        provider
102    }
103}
104
105fn capability_provider_key(provider: Provider) -> &'static str {
106    match provider {
107        Provider::Gemini => "gemini",
108        Provider::OpenAI => "openai",
109        Provider::Anthropic => "anthropic",
110        Provider::Copilot => "copilot",
111        Provider::DeepSeek => "deepseek",
112        Provider::OpenRouter => "openrouter",
113        Provider::Ollama => "ollama",
114        Provider::LmStudio => "lmstudio",
115        Provider::Moonshot => "moonshot",
116        Provider::ZAI => "zai",
117        Provider::Minimax => "minimax",
118        Provider::HuggingFace => "huggingface",
119        Provider::OpenCodeZen => "opencode-zen",
120        Provider::OpenCodeGo => "opencode-go",
121    }
122}
123
124fn generated_catalog_entry(provider: &str, id: &str) -> Option<ModelCatalogEntry> {
125    capability_generated::metadata_for(catalog_provider_key(provider), id).map(|entry| {
126        ModelCatalogEntry {
127            provider: entry.provider,
128            id: entry.id,
129            display_name: entry.display_name,
130            description: entry.description,
131            context_window: entry.context_window,
132            max_output_tokens: entry.max_output_tokens,
133            reasoning: entry.reasoning,
134            tool_call: entry.tool_call,
135            vision: entry.vision,
136            input_modalities: entry.input_modalities,
137            caching: entry.caching,
138            structured_output: entry.structured_output,
139            pricing: ModelPricing {
140                input: entry.pricing.input,
141                output: entry.pricing.output,
142                cache_read: entry.pricing.cache_read,
143                cache_write: entry.pricing.cache_write,
144            },
145        }
146    })
147}
148
149pub fn model_catalog_entry(provider: &str, id: &str) -> Option<ModelCatalogEntry> {
150    generated_catalog_entry(provider, id)
151}
152
153pub fn supported_models_for_provider(provider: &str) -> Option<&'static [&'static str]> {
154    capability_generated::models_for_provider(catalog_provider_key(provider))
155}
156
157pub fn catalog_provider_keys() -> &'static [&'static str] {
158    capability_generated::PROVIDERS
159}
160
161impl ModelId {
162    fn generated_capabilities(&self) -> Option<ModelCatalogEntry> {
163        generated_catalog_entry(capability_provider_key(self.provider()), self.as_str())
164    }
165
166    /// Preferred built-in lightweight sibling or lower-tier fallback for this model.
167    pub fn preferred_lightweight_variant(&self) -> Option<Self> {
168        match self {
169            ModelId::Gemini31ProPreview | ModelId::Gemini31ProPreviewCustomTools => {
170                Some(ModelId::Gemini31FlashLitePreview)
171            }
172            ModelId::GPT54 | ModelId::GPT54Pro => Some(ModelId::GPT54Mini),
173            ModelId::OpenCodeZenGPT54 => Some(ModelId::OpenCodeZenGPT54Mini),
174            ModelId::GPT52
175            | ModelId::GPT52Codex
176            | ModelId::GPT53Codex
177            | ModelId::GPT51Codex
178            | ModelId::GPT51CodexMax
179            | ModelId::GPT5
180            | ModelId::GPT5Codex => Some(ModelId::GPT5Mini),
181            ModelId::ClaudeOpus47
182            | ModelId::ClaudeOpus46
183            | ModelId::ClaudeSonnet46
184            | ModelId::ClaudeMythosPreview => Some(ModelId::ClaudeHaiku45),
185            ModelId::CopilotGPT54 => Some(ModelId::CopilotGPT54Mini),
186            ModelId::CopilotGPT52Codex | ModelId::CopilotGPT51CodexMax => {
187                Some(ModelId::CopilotGPT54Mini)
188            }
189            ModelId::DeepSeekV4Pro => Some(ModelId::DeepSeekV4Flash),
190            ModelId::OllamaDeepseekV4ProCloud => Some(ModelId::OllamaDeepseekV4FlashCloud),
191            ModelId::ZaiGlm51 => Some(ModelId::ZaiGlm5),
192            ModelId::MinimaxM27 => Some(ModelId::MinimaxM25),
193            ModelId::OpenCodeGoMinimaxM27 => Some(ModelId::OpenCodeGoMinimaxM25),
194            _ => None,
195        }
196    }
197
198    /// Attempt to find a non-reasoning variant for this model.
199    pub fn non_reasoning_variant(&self) -> Option<Self> {
200        if let Some(meta) = self.openrouter_metadata() {
201            if !meta.reasoning {
202                return None;
203            }
204
205            let vendor = meta.vendor;
206            let mut candidates: Vec<Self> = Self::openrouter_vendor_groups()
207                .into_iter()
208                .find(|(candidate_vendor, _)| *candidate_vendor == vendor)
209                .map(|(_, models)| {
210                    models
211                        .iter()
212                        .copied()
213                        .filter(|candidate| candidate != self)
214                        .filter(|candidate| {
215                            candidate
216                                .openrouter_metadata()
217                                .map(|other| !other.reasoning)
218                                .unwrap_or(false)
219                        })
220                        .collect()
221                })
222                .unwrap_or_default();
223
224            if candidates.is_empty() {
225                return None;
226            }
227
228            candidates.sort_by_key(|candidate| {
229                candidate
230                    .openrouter_metadata()
231                    .map(|data| (!data.efficient, data.display))
232                    .unwrap_or((true, ""))
233            });
234
235            return candidates.into_iter().next();
236        }
237
238        let direct = match self {
239            ModelId::Gemini31ProPreview
240            | ModelId::Gemini31ProPreviewCustomTools
241            | ModelId::Gemini31FlashLitePreview => Some(ModelId::Gemini3FlashPreview),
242            ModelId::GPT52
243            | ModelId::GPT54
244            | ModelId::GPT54Pro
245            | ModelId::GPT54Nano
246            | ModelId::GPT54Mini
247            | ModelId::GPT5 => Some(ModelId::GPT5Mini),
248            ModelId::OpenCodeZenGPT54 => Some(ModelId::OpenCodeZenGPT54Mini),
249            ModelId::CopilotGPT52Codex | ModelId::CopilotGPT54 => Some(ModelId::CopilotGPT54Mini),
250            ModelId::DeepSeekV4Pro => Some(ModelId::DeepSeekV4Flash),
251            ModelId::OllamaDeepseekV4ProCloud => Some(ModelId::OllamaDeepseekV4FlashCloud),
252            ModelId::ZaiGlm5 | ModelId::ZaiGlm51 => Some(ModelId::OllamaGlm5Cloud),
253            ModelId::ClaudeOpus47
254            | ModelId::ClaudeOpus46
255            | ModelId::ClaudeSonnet46
256            | ModelId::ClaudeMythosPreview => Some(ModelId::ClaudeSonnet46),
257            ModelId::OpenCodeGoMinimaxM27 => Some(ModelId::OpenCodeGoMinimaxM25),
258            ModelId::MinimaxM27 | ModelId::MinimaxM25 => None,
259            _ => None,
260        };
261
262        direct.and_then(|candidate| {
263            if candidate.supports_reasoning_effort() {
264                None
265            } else {
266                Some(candidate)
267            }
268        })
269    }
270
271    /// Check if this is a "flash" variant (optimized for speed)
272    pub fn is_flash_variant(&self) -> bool {
273        matches!(
274            self,
275            ModelId::Gemini3FlashPreview
276                | ModelId::Gemini31FlashLitePreview
277                | ModelId::OpenRouterStepfunStep35FlashFree
278                | ModelId::OpenRouterNvidiaNemotron3Super120bA12bFree
279                | ModelId::OllamaGemini3FlashPreviewCloud
280                | ModelId::HuggingFaceStep35Flash
281        )
282    }
283
284    /// Check if this is a "pro" variant (optimized for capability)
285    pub fn is_pro_variant(&self) -> bool {
286        matches!(
287            self,
288            ModelId::Gemini31ProPreview
289                | ModelId::Gemini31ProPreviewCustomTools
290                | ModelId::OpenRouterGoogleGemini31ProPreview
291                | ModelId::GPT5
292                | ModelId::GPT52
293                | ModelId::GPT52Codex
294                | ModelId::GPT54
295                | ModelId::GPT54Pro
296                | ModelId::GPT53Codex
297                | ModelId::GPT51Codex
298                | ModelId::GPT51CodexMax
299                | ModelId::CopilotGPT52Codex
300                | ModelId::CopilotGPT51CodexMax
301                | ModelId::CopilotGPT54
302                | ModelId::CopilotClaudeSonnet46
303                | ModelId::GPT5Codex
304                | ModelId::ClaudeOpus47
305                | ModelId::ClaudeOpus46
306                | ModelId::ClaudeSonnet46
307                | ModelId::ClaudeMythosPreview
308                | ModelId::OpenCodeZenGPT54
309                | ModelId::OpenCodeZenClaudeSonnet46
310                | ModelId::OpenCodeZenGlm51
311                | ModelId::OpenCodeZenKimiK25
312                | ModelId::OpenCodeGoGlm51
313                | ModelId::OpenCodeGoKimiK25
314                | ModelId::OpenCodeGoMinimaxM27
315                | ModelId::DeepSeekV4Pro
316                | ModelId::ZaiGlm5
317                | ModelId::ZaiGlm51
318                | ModelId::OpenRouterStepfunStep35FlashFree
319                | ModelId::OpenRouterNvidiaNemotron3Super120bA12bFree
320                | ModelId::MinimaxM27
321                | ModelId::MinimaxM25
322                | ModelId::OpenCodeGoMinimaxM25
323                | ModelId::OllamaGlm5Cloud
324                | ModelId::OllamaGlm51Cloud
325                | ModelId::OllamaNemotron3SuperCloud
326                | ModelId::OllamaMinimaxM25Cloud
327                | ModelId::HuggingFaceQwen3CoderNextNovita
328                | ModelId::HuggingFaceQwen35397BA17BTogether
329                | ModelId::OpenRouterMoonshotaiKimiK26
330        )
331    }
332
333    /// Check if this is an optimized/efficient variant
334    pub fn is_efficient_variant(&self) -> bool {
335        if let Some(meta) = self.openrouter_metadata() {
336            return meta.efficient;
337        }
338        matches!(
339            self,
340            ModelId::Gemini3FlashPreview
341                | ModelId::Gemini31FlashLitePreview
342                | ModelId::GPT5Mini
343                | ModelId::GPT5Nano
344                | ModelId::CopilotGPT54Mini
345                | ModelId::ClaudeHaiku45
346                | ModelId::OpenCodeZenGPT54Mini
347                | ModelId::OpenCodeGoMinimaxM25
348                | ModelId::DeepSeekV4Flash
349                | ModelId::HuggingFaceStep35Flash
350        )
351    }
352
353    /// Check if this is a top-tier model
354    pub fn is_top_tier(&self) -> bool {
355        if let Some(meta) = self.openrouter_metadata() {
356            return meta.top_tier;
357        }
358        matches!(
359            self,
360            ModelId::Gemini31ProPreview
361                | ModelId::Gemini31ProPreviewCustomTools
362                | ModelId::OpenRouterGoogleGemini31ProPreview
363                | ModelId::Gemini3FlashPreview
364                | ModelId::Gemini31FlashLitePreview
365                | ModelId::GPT5
366                | ModelId::GPT52
367                | ModelId::GPT52Codex
368                | ModelId::GPT54
369                | ModelId::GPT54Pro
370                | ModelId::GPT53Codex
371                | ModelId::GPT51Codex
372                | ModelId::GPT51CodexMax
373                | ModelId::GPT5Codex
374                | ModelId::ClaudeOpus47
375                | ModelId::ClaudeOpus46
376                | ModelId::ClaudeSonnet46
377                | ModelId::ClaudeMythosPreview
378                | ModelId::OpenCodeZenGPT54
379                | ModelId::OpenCodeZenClaudeSonnet46
380                | ModelId::OpenCodeZenGlm51
381                | ModelId::OpenCodeZenKimiK25
382                | ModelId::OpenCodeGoGlm51
383                | ModelId::OpenCodeGoKimiK25
384                | ModelId::OpenCodeGoMinimaxM27
385                | ModelId::DeepSeekV4Pro
386                | ModelId::ZaiGlm5
387                | ModelId::ZaiGlm51
388                | ModelId::OpenRouterStepfunStep35FlashFree
389                | ModelId::HuggingFaceQwen3CoderNextNovita
390                | ModelId::HuggingFaceQwen35397BA17BTogether
391                | ModelId::OpenRouterMoonshotaiKimiK26
392        )
393    }
394
395    /// Determine whether the model is a reasoning-capable variant
396    pub fn is_reasoning_variant(&self) -> bool {
397        if let Some(meta) = self.openrouter_metadata() {
398            return meta.reasoning;
399        }
400        self.provider().supports_reasoning_effort(self.as_str())
401    }
402
403    /// Determine whether the model supports tool calls/function execution
404    pub fn supports_tool_calls(&self) -> bool {
405        if let Some(meta) = self.generated_capabilities() {
406            return meta.tool_call;
407        }
408        if let Some(meta) = self.openrouter_metadata() {
409            return meta.tool_call;
410        }
411        true
412    }
413
414    /// Ordered list of supported input modalities when VT Code has metadata for this model.
415    pub fn input_modalities(&self) -> &'static [&'static str] {
416        self.generated_capabilities()
417            .map(|meta| meta.input_modalities)
418            .unwrap_or(&[])
419    }
420
421    /// Get the generation/version string for this model
422    pub fn generation(&self) -> &'static str {
423        if let Some(meta) = self.openrouter_metadata() {
424            return meta.generation;
425        }
426        match self {
427            // Gemini generations
428            ModelId::Gemini31ProPreview | ModelId::Gemini31ProPreviewCustomTools => "3.1",
429            ModelId::Gemini31FlashLitePreview => "3.1-lite",
430            ModelId::Gemini3FlashPreview => "3",
431            // OpenAI generations
432            ModelId::GPT52 | ModelId::GPT52Codex => "5.2",
433            ModelId::GPT54 | ModelId::GPT54Pro | ModelId::GPT54Nano | ModelId::GPT54Mini => "5.4",
434            ModelId::GPT53Codex => "5.3",
435            ModelId::GPT51Codex | ModelId::GPT51CodexMax => "5.1",
436            ModelId::GPT5
437            | ModelId::GPT5Codex
438            | ModelId::GPT5Mini
439            | ModelId::GPT5Nano
440            | ModelId::OpenAIGptOss20b
441            | ModelId::OpenAIGptOss120b => "5",
442            // Anthropic generations
443            ModelId::ClaudeOpus47 => "4.7",
444            ModelId::ClaudeOpus46 => "4.6",
445            ModelId::ClaudeSonnet46 => "4.6",
446            ModelId::ClaudeHaiku45 => "4.5",
447            ModelId::ClaudeMythosPreview => "preview",
448            // DeepSeek generations
449            ModelId::DeepSeekV4Pro | ModelId::DeepSeekV4Flash => "4",
450            // Z.AI generations
451            ModelId::ZaiGlm5 => "5",
452            ModelId::ZaiGlm51 => "5.1",
453            ModelId::OpenCodeZenGPT54 | ModelId::OpenCodeZenGPT54Mini => "5.4",
454            ModelId::OpenCodeZenClaudeSonnet46 => "4.6",
455            ModelId::OpenCodeZenGlm51 | ModelId::OpenCodeGoGlm51 => "5.1",
456            ModelId::OpenCodeZenKimiK25 | ModelId::OpenCodeGoKimiK25 => "k2.5",
457            ModelId::OpenCodeGoMinimaxM25 => "m2.5",
458            ModelId::OpenCodeGoMinimaxM27 => "m2.7",
459            ModelId::OllamaGptOss20b => "oss",
460            ModelId::OllamaGptOss20bCloud => "oss-cloud",
461            ModelId::OllamaGptOss120bCloud => "oss-cloud",
462            ModelId::OllamaQwen317b => "oss",
463            ModelId::OllamaQwen3CoderNext => "qwen3-coder-next:cloud",
464            ModelId::OllamaDeepseekV32Cloud => "deepseek-v3.2",
465            ModelId::OllamaDeepseekV4FlashCloud => "deepseek-v4-flash",
466            ModelId::OllamaDeepseekV4ProCloud => "deepseek-v4-pro",
467            ModelId::OllamaQwen3Next80bCloud => "qwen3-next",
468            ModelId::OllamaMinimaxM2Cloud => "minimax-m2",
469            ModelId::OllamaMinimaxM27Cloud => "minimax-m2.7",
470            ModelId::OllamaGlm5Cloud => "glm-5",
471            ModelId::OllamaGlm51Cloud => "glm-5.1",
472            ModelId::OllamaMinimaxM25Cloud => "minimax-m2.5",
473            ModelId::OllamaKimiK26Cloud => "kimi-k2.6",
474            ModelId::OllamaNemotron3SuperCloud => "nemotron-3",
475            ModelId::OllamaGemini3FlashPreviewCloud => "gemini-3",
476            // MiniMax models
477            ModelId::MinimaxM27 => "M2.7",
478            ModelId::MinimaxM25 => "M2.5",
479            // Moonshot models
480            ModelId::MoonshotKimiK26 => "k2.6",
481            ModelId::MoonshotKimiK25 => "k2.5",
482            // Hugging Face generations
483            ModelId::HuggingFaceDeepseekV32 => "V3.2-Exp",
484            ModelId::HuggingFaceOpenAIGptOss20b => "oss",
485            ModelId::HuggingFaceOpenAIGptOss120b => "oss",
486            ModelId::HuggingFaceMinimaxM25Novita => "m2.5",
487            ModelId::HuggingFaceDeepseekV32Novita => "v3.2",
488            ModelId::HuggingFaceXiaomiMimoV2FlashNovita => "v2-flash",
489            ModelId::HuggingFaceGlm5Novita => "5",
490            ModelId::HuggingFaceGlm51ZaiOrg => "5.1",
491            ModelId::HuggingFaceKimiK26Novita => "k2.6",
492            ModelId::HuggingFaceStep35Flash => "3.5",
493            ModelId::HuggingFaceQwen3CoderNextNovita | ModelId::OpenRouterQwen3CoderNext => {
494                "qwen3-coder-next"
495            }
496            _ => "unknown",
497        }
498    }
499
500    /// Determine if this model supports GPT-5.1+/5.2+/5.3+ shell tool type
501    pub fn supports_shell_tool(&self) -> bool {
502        matches!(
503            self,
504            ModelId::GPT52
505                | ModelId::GPT52Codex
506                | ModelId::GPT54
507                | ModelId::GPT54Pro
508                | ModelId::GPT53Codex
509                | ModelId::GPT51Codex
510                | ModelId::GPT51CodexMax
511                | ModelId::GPT5Codex
512        )
513    }
514
515    /// Determine if this model supports optimized apply_patch tool
516    pub fn supports_apply_patch_tool(&self) -> bool {
517        false // Placeholder for future optimization
518    }
519}