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::GPT55 | 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::GPT55
243            | ModelId::GPT52
244            | ModelId::GPT54
245            | ModelId::GPT54Pro
246            | ModelId::GPT54Nano
247            | ModelId::GPT54Mini
248            | ModelId::GPT5 => Some(ModelId::GPT5Mini),
249            ModelId::OpenCodeZenGPT54 => Some(ModelId::OpenCodeZenGPT54Mini),
250            ModelId::CopilotGPT52Codex | ModelId::CopilotGPT54 => Some(ModelId::CopilotGPT54Mini),
251            ModelId::DeepSeekV4Pro => Some(ModelId::DeepSeekV4Flash),
252            ModelId::OllamaDeepseekV4ProCloud => Some(ModelId::OllamaDeepseekV4FlashCloud),
253            ModelId::ZaiGlm5 | ModelId::ZaiGlm51 => Some(ModelId::OllamaGlm5Cloud),
254            ModelId::ClaudeOpus47
255            | ModelId::ClaudeOpus46
256            | ModelId::ClaudeSonnet46
257            | ModelId::ClaudeMythosPreview => Some(ModelId::ClaudeSonnet46),
258            ModelId::OpenCodeGoMinimaxM27 => Some(ModelId::OpenCodeGoMinimaxM25),
259            ModelId::MinimaxM27 | ModelId::MinimaxM25 => None,
260            _ => None,
261        };
262
263        direct.and_then(|candidate| {
264            if candidate.supports_reasoning_effort() {
265                None
266            } else {
267                Some(candidate)
268            }
269        })
270    }
271
272    /// Check if this is a "flash" variant (optimized for speed)
273    pub fn is_flash_variant(&self) -> bool {
274        matches!(
275            self,
276            ModelId::Gemini3FlashPreview
277                | ModelId::Gemini31FlashLitePreview
278                | ModelId::OpenRouterStepfunStep35FlashFree
279                | ModelId::OpenRouterNvidiaNemotron3Super120bA12bFree
280                | ModelId::OllamaGemini3FlashPreviewCloud
281                | ModelId::HuggingFaceStep35Flash
282        )
283    }
284
285    /// Check if this is a "pro" variant (optimized for capability)
286    pub fn is_pro_variant(&self) -> bool {
287        matches!(
288            self,
289            ModelId::Gemini31ProPreview
290                | ModelId::Gemini31ProPreviewCustomTools
291                | ModelId::OpenRouterGoogleGemini31ProPreview
292                | ModelId::GPT55
293                | ModelId::GPT5
294                | ModelId::GPT52
295                | ModelId::GPT52Codex
296                | ModelId::GPT54
297                | ModelId::GPT54Pro
298                | ModelId::GPT53Codex
299                | ModelId::GPT51Codex
300                | ModelId::GPT51CodexMax
301                | ModelId::CopilotGPT52Codex
302                | ModelId::CopilotGPT51CodexMax
303                | ModelId::CopilotGPT54
304                | ModelId::CopilotClaudeSonnet46
305                | ModelId::GPT5Codex
306                | ModelId::ClaudeOpus47
307                | ModelId::ClaudeOpus46
308                | ModelId::ClaudeSonnet46
309                | ModelId::ClaudeMythosPreview
310                | ModelId::OpenCodeZenGPT54
311                | ModelId::OpenCodeZenClaudeSonnet46
312                | ModelId::OpenCodeZenGlm51
313                | ModelId::OpenCodeZenKimiK25
314                | ModelId::OpenCodeGoGlm51
315                | ModelId::OpenCodeGoKimiK25
316                | ModelId::OpenCodeGoMinimaxM27
317                | ModelId::DeepSeekV4Pro
318                | ModelId::ZaiGlm5
319                | ModelId::ZaiGlm51
320                | ModelId::OpenRouterStepfunStep35FlashFree
321                | ModelId::OpenRouterNvidiaNemotron3Super120bA12bFree
322                | ModelId::MinimaxM27
323                | ModelId::MinimaxM25
324                | ModelId::OpenCodeGoMinimaxM25
325                | ModelId::OllamaGlm5Cloud
326                | ModelId::OllamaGlm51Cloud
327                | ModelId::OllamaNemotron3SuperCloud
328                | ModelId::OllamaMinimaxM25Cloud
329                | ModelId::HuggingFaceQwen3CoderNextNovita
330                | ModelId::HuggingFaceQwen35397BA17BTogether
331                | ModelId::OpenRouterMoonshotaiKimiK26
332        )
333    }
334
335    /// Check if this is an optimized/efficient variant
336    pub fn is_efficient_variant(&self) -> bool {
337        if let Some(meta) = self.openrouter_metadata() {
338            return meta.efficient;
339        }
340        matches!(
341            self,
342            ModelId::Gemini3FlashPreview
343                | ModelId::Gemini31FlashLitePreview
344                | ModelId::GPT5Mini
345                | ModelId::GPT5Nano
346                | ModelId::CopilotGPT54Mini
347                | ModelId::ClaudeHaiku45
348                | ModelId::OpenCodeZenGPT54Mini
349                | ModelId::OpenCodeGoMinimaxM25
350                | ModelId::DeepSeekV4Flash
351                | ModelId::HuggingFaceStep35Flash
352        )
353    }
354
355    /// Check if this is a top-tier model
356    pub fn is_top_tier(&self) -> bool {
357        if let Some(meta) = self.openrouter_metadata() {
358            return meta.top_tier;
359        }
360        matches!(
361            self,
362            ModelId::Gemini31ProPreview
363                | ModelId::Gemini31ProPreviewCustomTools
364                | ModelId::OpenRouterGoogleGemini31ProPreview
365                | ModelId::Gemini3FlashPreview
366                | ModelId::Gemini31FlashLitePreview
367                | ModelId::GPT55
368                | ModelId::GPT5
369                | ModelId::GPT52
370                | ModelId::GPT52Codex
371                | ModelId::GPT54
372                | ModelId::GPT54Pro
373                | ModelId::GPT53Codex
374                | ModelId::GPT51Codex
375                | ModelId::GPT51CodexMax
376                | ModelId::GPT5Codex
377                | ModelId::ClaudeOpus47
378                | ModelId::ClaudeOpus46
379                | ModelId::ClaudeSonnet46
380                | ModelId::ClaudeMythosPreview
381                | ModelId::OpenCodeZenGPT54
382                | ModelId::OpenCodeZenClaudeSonnet46
383                | ModelId::OpenCodeZenGlm51
384                | ModelId::OpenCodeZenKimiK25
385                | ModelId::OpenCodeGoGlm51
386                | ModelId::OpenCodeGoKimiK25
387                | ModelId::OpenCodeGoMinimaxM27
388                | ModelId::DeepSeekV4Pro
389                | ModelId::ZaiGlm5
390                | ModelId::ZaiGlm51
391                | ModelId::OpenRouterStepfunStep35FlashFree
392                | ModelId::HuggingFaceQwen3CoderNextNovita
393                | ModelId::HuggingFaceQwen35397BA17BTogether
394                | ModelId::OpenRouterMoonshotaiKimiK26
395        )
396    }
397
398    /// Determine whether the model is a reasoning-capable variant
399    pub fn is_reasoning_variant(&self) -> bool {
400        if let Some(meta) = self.openrouter_metadata() {
401            return meta.reasoning;
402        }
403        self.provider().supports_reasoning_effort(self.as_str())
404    }
405
406    /// Determine whether the model supports tool calls/function execution
407    pub fn supports_tool_calls(&self) -> bool {
408        if let Some(meta) = self.generated_capabilities() {
409            return meta.tool_call;
410        }
411        if let Some(meta) = self.openrouter_metadata() {
412            return meta.tool_call;
413        }
414        true
415    }
416
417    /// Ordered list of supported input modalities when VT Code has metadata for this model.
418    pub fn input_modalities(&self) -> &'static [&'static str] {
419        self.generated_capabilities()
420            .map(|meta| meta.input_modalities)
421            .unwrap_or(&[])
422    }
423
424    /// Get the generation/version string for this model
425    pub fn generation(&self) -> &'static str {
426        if let Some(meta) = self.openrouter_metadata() {
427            return meta.generation;
428        }
429        match self {
430            // Gemini generations
431            ModelId::Gemini31ProPreview | ModelId::Gemini31ProPreviewCustomTools => "3.1",
432            ModelId::Gemini31FlashLitePreview => "3.1-lite",
433            ModelId::Gemini3FlashPreview => "3",
434            // OpenAI generations
435            ModelId::GPT55 => "5.5",
436            ModelId::GPT52 | ModelId::GPT52Codex => "5.2",
437            ModelId::GPT54 | ModelId::GPT54Pro | ModelId::GPT54Nano | ModelId::GPT54Mini => "5.4",
438            ModelId::GPT53Codex => "5.3",
439            ModelId::GPT51Codex | ModelId::GPT51CodexMax => "5.1",
440            ModelId::GPT5
441            | ModelId::GPT5Codex
442            | ModelId::GPT5Mini
443            | ModelId::GPT5Nano
444            | ModelId::OpenAIGptOss20b
445            | ModelId::OpenAIGptOss120b => "5",
446            // Anthropic generations
447            ModelId::ClaudeOpus47 => "4.7",
448            ModelId::ClaudeOpus46 => "4.6",
449            ModelId::ClaudeSonnet46 => "4.6",
450            ModelId::ClaudeHaiku45 => "4.5",
451            ModelId::ClaudeMythosPreview => "preview",
452            // DeepSeek generations
453            ModelId::DeepSeekV4Pro | ModelId::DeepSeekV4Flash => "4",
454            // Z.AI generations
455            ModelId::ZaiGlm5 => "5",
456            ModelId::ZaiGlm51 => "5.1",
457            ModelId::OpenCodeZenGPT54 | ModelId::OpenCodeZenGPT54Mini => "5.4",
458            ModelId::OpenCodeZenClaudeSonnet46 => "4.6",
459            ModelId::OpenCodeZenGlm51 | ModelId::OpenCodeGoGlm51 => "5.1",
460            ModelId::OpenCodeZenKimiK25 | ModelId::OpenCodeGoKimiK25 => "k2.5",
461            ModelId::OpenCodeGoMinimaxM25 => "m2.5",
462            ModelId::OpenCodeGoMinimaxM27 => "m2.7",
463            ModelId::OllamaGptOss20b => "oss",
464            ModelId::OllamaGptOss20bCloud => "oss-cloud",
465            ModelId::OllamaGptOss120bCloud => "oss-cloud",
466            ModelId::OllamaQwen317b => "oss",
467            ModelId::OllamaQwen3CoderNext => "qwen3-coder-next:cloud",
468            ModelId::OllamaDeepseekV32Cloud => "deepseek-v3.2",
469            ModelId::OllamaDeepseekV4FlashCloud => "deepseek-v4-flash",
470            ModelId::OllamaDeepseekV4ProCloud => "deepseek-v4-pro",
471            ModelId::OllamaQwen3Next80bCloud => "qwen3-next",
472            ModelId::OllamaMinimaxM2Cloud => "minimax-m2",
473            ModelId::OllamaMinimaxM27Cloud => "minimax-m2.7",
474            ModelId::OllamaGlm5Cloud => "glm-5",
475            ModelId::OllamaGlm51Cloud => "glm-5.1",
476            ModelId::OllamaMinimaxM25Cloud => "minimax-m2.5",
477            ModelId::OllamaKimiK26Cloud => "kimi-k2.6",
478            ModelId::OllamaNemotron3SuperCloud => "nemotron-3",
479            ModelId::OllamaGemini3FlashPreviewCloud => "gemini-3",
480            // MiniMax models
481            ModelId::MinimaxM27 => "M2.7",
482            ModelId::MinimaxM25 => "M2.5",
483            // Moonshot models
484            ModelId::MoonshotKimiK26 => "k2.6",
485            ModelId::MoonshotKimiK25 => "k2.5",
486            // Hugging Face generations
487            ModelId::HuggingFaceDeepseekV32 => "V3.2-Exp",
488            ModelId::HuggingFaceOpenAIGptOss20b => "oss",
489            ModelId::HuggingFaceOpenAIGptOss120b => "oss",
490            ModelId::HuggingFaceMinimaxM25Novita => "m2.5",
491            ModelId::HuggingFaceDeepseekV32Novita => "v3.2",
492            ModelId::HuggingFaceXiaomiMimoV2FlashNovita => "v2-flash",
493            ModelId::HuggingFaceGlm5Novita => "5",
494            ModelId::HuggingFaceGlm51ZaiOrg => "5.1",
495            ModelId::HuggingFaceKimiK26Novita => "k2.6",
496            ModelId::HuggingFaceStep35Flash => "3.5",
497            ModelId::HuggingFaceQwen3CoderNextNovita | ModelId::OpenRouterQwen3CoderNext => {
498                "qwen3-coder-next"
499            }
500            _ => "unknown",
501        }
502    }
503
504    /// Determine if this model supports GPT-5.1+/5.2+/5.3+ shell tool type
505    pub fn supports_shell_tool(&self) -> bool {
506        matches!(
507            self,
508            ModelId::GPT55
509                | ModelId::GPT52
510                | ModelId::GPT52Codex
511                | ModelId::GPT54
512                | ModelId::GPT54Pro
513                | ModelId::GPT53Codex
514                | ModelId::GPT51Codex
515                | ModelId::GPT51CodexMax
516                | ModelId::GPT5Codex
517        )
518    }
519
520    /// Determine if this model supports optimized apply_patch tool
521    pub fn supports_apply_patch_tool(&self) -> bool {
522        false // Placeholder for future optimization
523    }
524}