Skip to main content

vtcode_config/models/model_id/
capabilities.rs

1use std::cmp::Reverse;
2
3use crate::models::{Provider, ProviderModelSupport};
4
5use super::ModelId;
6
7mod capability_generated {
8    include!(concat!(env!("OUT_DIR"), "/model_capabilities.rs"));
9}
10
11/// Catalog metadata generated from `docs/models.json`.
12#[derive(Clone, Copy, Debug, PartialEq)]
13pub struct ModelPricing {
14    pub input: Option<f64>,
15    pub output: Option<f64>,
16    pub cache_read: Option<f64>,
17    pub cache_write: Option<f64>,
18}
19
20#[derive(Clone, Copy, Debug, PartialEq)]
21pub struct ModelCatalogEntry {
22    pub(crate) provider: &'static str,
23    id: &'static str,
24    pub display_name: &'static str,
25    pub description: &'static str,
26    pub context_window: usize,
27    max_output_tokens: Option<usize>,
28    pub reasoning: bool,
29    pub reasoning_efforts: &'static [&'static str],
30    pub is_pro: bool,
31    pub lightweight_model: Option<&'static str>,
32    pub tool_call: bool,
33    pub vision: bool,
34    pub input_modalities: &'static [&'static str],
35    pub caching: bool,
36    pub structured_output: bool,
37    pub supports_sampling: bool,
38    pub supports_logprobs: bool,
39    pub prompt_cache_ttl: Option<&'static str>,
40    pub prompt_contract: Option<&'static str>,
41    pub pricing: ModelPricing,
42}
43
44fn catalog_provider_key(provider: &str) -> &str {
45    if provider.eq_ignore_ascii_case("google") || provider.eq_ignore_ascii_case("gemini") {
46        "gemini"
47    } else if provider.eq_ignore_ascii_case("openai") {
48        "openai"
49    } else if provider.eq_ignore_ascii_case("anthropic") {
50        "anthropic"
51    } else if provider.eq_ignore_ascii_case("deepseek") {
52        "deepseek"
53    } else if provider.eq_ignore_ascii_case("meta") || provider.eq_ignore_ascii_case("meta-ai") {
54        "meta"
55    } else if provider.eq_ignore_ascii_case("openrouter") {
56        "openrouter"
57    } else if provider.eq_ignore_ascii_case("ollama") {
58        "ollama"
59    } else if provider.eq_ignore_ascii_case("lmstudio") {
60        "lmstudio"
61    } else if provider.eq_ignore_ascii_case("llamacpp") || provider.eq_ignore_ascii_case("llama.cpp") {
62        "llamacpp"
63    } else if provider.eq_ignore_ascii_case("moonshot") {
64        "moonshot"
65    } else if provider.eq_ignore_ascii_case("zai") {
66        "zai"
67    } else if provider.eq_ignore_ascii_case("minimax") {
68        "minimax"
69    } else if provider.eq_ignore_ascii_case("huggingface") {
70        "huggingface"
71    } else if provider.eq_ignore_ascii_case("stepfun") {
72        "stepfun"
73    } else if provider.eq_ignore_ascii_case("evolink") {
74        "evolink"
75    } else if provider.eq_ignore_ascii_case("poolside") {
76        "poolside"
77    } else if provider.eq_ignore_ascii_case("xai") {
78        "xai"
79    } else if provider.eq_ignore_ascii_case("nvidia") {
80        "nvidia"
81    } else if provider.eq_ignore_ascii_case("merge-gateway") {
82        "merge-gateway"
83    } else if provider.eq_ignore_ascii_case("vercel") || provider.eq_ignore_ascii_case("vercel-ai-gateway") {
84        "vercel"
85    } else {
86        provider
87    }
88}
89
90fn catalog_lookup_id<'a>(provider: &str, id: &'a str) -> &'a str {
91    let provider_key = catalog_provider_key(provider);
92    if provider_key == "evolink"
93        && let Some((prefix, model_id)) = id.split_once('/')
94        && prefix.eq_ignore_ascii_case(provider_key)
95    {
96        // Evolink namespaces its ModelId values to avoid collisions with
97        // first-class providers, while its catalog stores the upstream model
98        // id that the gateway receives (for example, `deepseek-v4-pro`).
99        return model_id;
100    }
101    id
102}
103
104fn generated_catalog_entry(provider: &str, id: &str) -> Option<ModelCatalogEntry> {
105    let provider_key = catalog_provider_key(provider);
106    let lookup_id = catalog_lookup_id(provider_key, id);
107    // Exact match wins so gateway providers that store prefixed IDs
108    // (`merge-gateway`/`vercel` keep `openai/gpt-5.6-luna`) keep working.
109    // Fall back to stripping a provider-prefixed request model
110    // (`openai/gpt-5.6-luna` on provider `openai` stores `gpt-5.6-luna`).
111    // The strip is provider-scoped (prefix must equal the provider key) so an
112    // unrelated prefix (`other-org/gpt-5.6-luna`) does not resolve to the bare
113    // model's capabilities. Without this, reasoning-effort and context
114    // lookups miss and the harness omits the effort with an empty
115    // `supported:` diagnostic.
116    let entry = capability_generated::metadata_for(provider_key, lookup_id).or_else(|| {
117        lookup_id
118            .split_once('/')
119            .filter(|(prefix, _)| prefix.eq_ignore_ascii_case(provider_key))
120            .and_then(|(_, rest)| capability_generated::metadata_for(provider_key, rest))
121    });
122    entry.map(|entry| ModelCatalogEntry {
123        provider: entry.provider,
124        id: entry.id,
125        display_name: entry.display_name,
126        description: entry.description,
127        context_window: entry.context_window,
128        max_output_tokens: entry.max_output_tokens,
129        reasoning: entry.reasoning,
130        reasoning_efforts: entry.reasoning_efforts,
131        is_pro: entry.is_pro,
132        lightweight_model: entry.lightweight_model,
133        tool_call: entry.tool_call,
134        vision: entry.vision,
135        input_modalities: entry.input_modalities,
136        caching: entry.caching,
137        structured_output: entry.structured_output,
138        supports_sampling: entry.supports_sampling,
139        supports_logprobs: entry.supports_logprobs,
140        prompt_cache_ttl: entry.prompt_cache_ttl,
141        prompt_contract: entry.prompt_contract,
142        pricing: ModelPricing {
143            input: entry.pricing.input,
144            output: entry.pricing.output,
145            cache_read: entry.pricing.cache_read,
146            cache_write: entry.pricing.cache_write,
147        },
148    })
149}
150
151pub fn model_catalog_entry(provider: &str, id: &str) -> Option<ModelCatalogEntry> {
152    generated_catalog_entry(provider, id)
153}
154
155pub fn supported_models_for_provider(provider: &str) -> Option<&'static [&'static str]> {
156    capability_generated::models_for_provider(catalog_provider_key(provider))
157}
158
159pub fn catalog_provider_keys() -> &'static [&'static str] {
160    capability_generated::PROVIDERS
161}
162
163/// Numeric components of a generation string, e.g. `v2.6` -> `[2, 6]`.
164fn generation_components(generation: &str) -> Vec<u64> {
165    let mut components = Vec::new();
166    let mut digits = String::new();
167    for character in generation.chars() {
168        if character.is_ascii_digit() {
169            digits.push(character);
170        } else if !digits.is_empty() {
171            components.push(digits.parse().unwrap_or_default());
172            digits.clear();
173        }
174    }
175    if !digits.is_empty() {
176        components.push(digits.parse().unwrap_or_default());
177    }
178    components
179}
180
181impl ModelId {
182    fn generated_capabilities(&self) -> Option<ModelCatalogEntry> {
183        // Custom routes keep their declared key: an arbitrary custom provider
184        // must not inherit another provider's catalog entry just because the
185        // model slug happens to match one there.
186        generated_catalog_entry(self.provider_key(), &self.as_str())
187    }
188
189    /// Preferred built-in lightweight sibling or lower-tier fallback for this model.
190    pub fn preferred_lightweight_variant(&self) -> Option<Self> {
191        let target_id = self.generated_capabilities()?.lightweight_model?;
192        Self::all_models().into_iter().find(|candidate| {
193            candidate != self && candidate.provider() == self.provider() && candidate.as_str() == target_id
194        })
195    }
196
197    /// Attempt to find a non-reasoning variant for this model.
198    pub fn non_reasoning_variant(&self) -> Option<Self> {
199        if let Some(meta) = self.openrouter_metadata() {
200            if !meta.reasoning {
201                return None;
202            }
203
204            let vendor = meta.vendor;
205            let mut candidates: Vec<Self> = Self::openrouter_vendor_groups()
206                .into_iter()
207                .find(|(candidate_vendor, _)| *candidate_vendor == vendor)
208                .map(|(_, models)| {
209                    models
210                        .iter()
211                        .filter(|&candidate| candidate != self)
212                        .filter(|&candidate| {
213                            candidate.openrouter_metadata().map(|other| !other.reasoning).unwrap_or(false)
214                        })
215                        .cloned()
216                        .collect()
217                })
218                .unwrap_or_default();
219
220            if candidates.is_empty() {
221                return None;
222            }
223
224            candidates.sort_by_key(|candidate| {
225                candidate
226                    .openrouter_metadata()
227                    .map(|data| (!data.efficient, data.display))
228                    .unwrap_or((true, ""))
229            });
230
231            return candidates.into_iter().next();
232        }
233
234        self.preferred_lightweight_variant()
235            .filter(|candidate| !candidate.is_reasoning_variant())
236    }
237
238    /// Check if this is a "flash" variant (optimized for speed)
239    pub fn is_flash_variant(&self) -> bool {
240        matches!(
241            self,
242            ModelId::Gemini38Flash
243                | ModelId::MergeGatewayGoogleGemini38Flash
244                | ModelId::VercelGoogleGemini38Flash
245                | ModelId::VercelDeepseekFlash
246                | ModelId::VercelOpenAiGpt56Luna
247                | ModelId::VercelAnthropicClaudeHaiku45
248                | ModelId::ClaudeHaiku55
249                | ModelId::MergeGatewayAnthropicClaudeHaiku4520251001
250                | ModelId::MergeGatewayAnthropicClaudeHaiku55
251                | ModelId::StepFun37Flash
252                | ModelId::MergeGatewayDeepseekFlash
253                | ModelId::DeepSeekFlash
254                | ModelId::OllamaDeepSeekV41FlashCloud
255                | ModelId::ZaiGlm53Flash
256                | ModelId::ZaiGlm53Flashx
257                | ModelId::OllamaGlm53FlashCloud
258                | ModelId::OllamaMinimaxM31FlashCloud
259                | ModelId::MergeGatewayZaiGlm53Flash
260                | ModelId::MergeGatewayZaiGlm53Flashx
261                | ModelId::HuggingFaceGlm53FlashTogether
262                | ModelId::MiMoV26Flash
263                | ModelId::MergeGatewayXiaomimimoMimoV26Flash
264                | ModelId::MinimaxM31Flash
265                | ModelId::MergeGatewayMinimaxM31Flash
266                | ModelId::OpenRouterMinimaxM31FlashFree
267        )
268    }
269
270    /// Check if this is a "pro" variant (optimized for capability)
271    pub fn is_pro_variant(&self) -> bool {
272        self.generated_capabilities().is_some_and(|entry| entry.is_pro)
273    }
274
275    /// Check if this is an optimized/efficient variant
276    pub fn is_efficient_variant(&self) -> bool {
277        if let Some(meta) = self.openrouter_metadata() {
278            return meta.efficient;
279        }
280        matches!(
281            self,
282            ModelId::Gemini38Flash
283                | ModelId::MergeGatewayGoogleGemini38Flash
284                | ModelId::Gemini4Neon
285                | ModelId::Gemini4Hydrogen
286                | ModelId::MergeGatewayGoogleGemini4Neon
287                | ModelId::MergeGatewayGoogleGemini4Hydrogen
288                | ModelId::GPT56Luna
289                | ModelId::GPT6Luna
290                | ModelId::MergeGatewayOpenAIGpt56Luna
291                | ModelId::MergeGatewayOpenAIGpt6Luna
292                | ModelId::CopilotGPT54Mini
293                | ModelId::ClaudeHaiku55
294                | ModelId::MergeGatewayAnthropicClaudeHaiku55
295                | ModelId::DeepSeekFlash
296                | ModelId::OllamaDeepSeekV41FlashCloud
297                | ModelId::MergeGatewayDeepseekFlash
298                | ModelId::MetaMuseEmber10
299                | ModelId::MergeGatewayMinimaxH3
300                | ModelId::MiMoV26Flash
301                | ModelId::ZaiGlm53Flash
302                | ModelId::ZaiGlm53Flashx
303                | ModelId::OllamaGlm53FlashCloud
304                | ModelId::OllamaMinimaxM31FlashCloud
305                | ModelId::MergeGatewayZaiGlm53Flash
306                | ModelId::MergeGatewayZaiGlm53Flashx
307                | ModelId::HuggingFaceGlm53FlashTogether
308                | ModelId::VercelDeepseekFlash
309                | ModelId::MergeGatewayXiaomimimoMimoV26Flash
310                | ModelId::MinimaxM31Flash
311                | ModelId::MergeGatewayMinimaxM31Flash
312                | ModelId::OpenRouterMinimaxM31FlashFree
313        )
314    }
315
316    /// Check if this is a top-tier model
317    pub fn is_top_tier(&self) -> bool {
318        if let Some(meta) = self.openrouter_metadata() {
319            return meta.top_tier;
320        }
321        matches!(
322            self,
323            ModelId::Gemini38Flash
324                | ModelId::MergeGatewayGoogleGemini38Flash
325                | ModelId::Gemini4Argon
326                | ModelId::Gemini4Carbon
327                | ModelId::Gemini4Neon
328                | ModelId::Gemini4Hydrogen
329                | ModelId::MergeGatewayGoogleGemini4Argon
330                | ModelId::MergeGatewayGoogleGemini4Carbon
331                | ModelId::MergeGatewayGoogleGemini4Neon
332                | ModelId::MergeGatewayGoogleGemini4Hydrogen
333                | ModelId::GPT62Astra
334                | ModelId::GPT62Sol
335                | ModelId::GPT6Astra
336                | ModelId::GPT6Sol
337                | ModelId::GPT61Sol
338                | ModelId::GPT56Sol
339                | ModelId::MergeGatewayOpenAIGpt56Sol
340                | ModelId::MergeGatewayOpenAIGpt56Terra
341                | ModelId::MergeGatewayOpenAIGpt56Luna
342                | ModelId::MergeGatewayOpenAIGpt62Astra
343                | ModelId::MergeGatewayOpenAIGpt62Sol
344                | ModelId::MergeGatewayOpenAIGpt6Astra
345                | ModelId::MergeGatewayOpenAIGpt6Sol
346                | ModelId::MergeGatewayOpenAIGpt61Sol
347                | ModelId::MergeGatewayOpenAIGpt61Terra
348                | ModelId::MergeGatewayOpenAIGpt6Luna
349                | ModelId::ClaudeSonnet5
350                | ModelId::ClaudeSonnet55
351                | ModelId::ClaudeFable5
352                | ModelId::ClaudeFable51
353                | ModelId::ClaudeFable52
354                | ModelId::ClaudeOpus5
355                | ModelId::ClaudeOpus55
356                | ModelId::MistralLarge4
357                | ModelId::OpenCodeGoGlm53
358                | ModelId::MiMoV26Pro
359                | ModelId::MiMoV26ProUltraspeed
360                | ModelId::OpenCodeGoMinimaxM3
361                | ModelId::MergeGatewayDeepseekFlash
362                | ModelId::VercelDeepseekFlash
363                | ModelId::MetaMuseSpark13
364                | ModelId::MetaMuseSpark13Contributor
365                | ModelId::MetaMuseWonder10
366                | ModelId::MetaMuseWonderFull10
367                | ModelId::ZaiGlm53
368                | ModelId::ZaiGlm53Flash
369                | ModelId::ZaiGlm53Flashx
370                | ModelId::MergeGatewayZaiGlm53Flash
371                | ModelId::MergeGatewayZaiGlm53Flashx
372                | ModelId::HuggingFaceGlm53FlashTogether
373                | ModelId::HuggingFaceGlm53Together
374                | ModelId::HuggingFaceMinimaxM3Novita
375                | ModelId::StepFun5Preview
376                | ModelId::OpenRouterMoonshotaiKimiK3
377                | ModelId::MoonshotKimiK31Pro
378                | ModelId::MoonshotKimiK3
379                | ModelId::MergeGatewayMoonshotKimiK3
380                | ModelId::MergeGatewayMoonshotKimiK31Pro
381                | ModelId::OllamaGlm53Cloud
382                | ModelId::OllamaGlm53FlashCloud
383                | ModelId::OllamaDeepSeekV41FlashCloud
384                | ModelId::OllamaMistralLarge4Cloud
385                | ModelId::OllamaMuseSparkOpenCloud
386                | ModelId::XaiGrok46
387                | ModelId::XaiGrok47
388                | ModelId::MergeGatewayXaiGrok46
389                | ModelId::MergeGatewayXaiGrok47
390                | ModelId::VercelSpacexaiGrok47
391                | ModelId::MergeGatewayXiaomimimoMimoV26Pro
392                | ModelId::MergeGatewayXiaomimimoMimoV26Flash
393                | ModelId::MergeGatewayMistralLarge4
394                | ModelId::MergeGatewayMetaMuseSparkOpen
395                | ModelId::HuggingFaceMuseSparkOpenBaseten
396        )
397    }
398
399    /// Determine whether the model is a reasoning-capable variant
400    pub fn is_reasoning_variant(&self) -> bool {
401        if let Some(meta) = self.openrouter_metadata() {
402            return meta.reasoning;
403        }
404        self.provider().supports_reasoning(&self.as_str())
405    }
406
407    /// Determine whether the model supports tool calls/function execution
408    pub fn supports_tool_calls(&self) -> bool {
409        if let Some(meta) = self.generated_capabilities() {
410            return meta.tool_call;
411        }
412        if let Some(meta) = self.openrouter_metadata() {
413            return meta.tool_call;
414        }
415        true
416    }
417
418    /// Ordered list of supported input modalities when VT Code has metadata for this model.
419    pub fn input_modalities(&self) -> &'static [&'static str] {
420        self.generated_capabilities().map(|meta| meta.input_modalities).unwrap_or(&[])
421    }
422
423    /// Get the generation/version string for this model
424    pub fn generation(&self) -> &'static str {
425        if let Some(meta) = self.openrouter_metadata() {
426            return meta.generation;
427        }
428        match self {
429            // Gemini generations
430            // OpenAI generations
431            ModelId::GPT62Astra | ModelId::GPT62Sol => "6.2",
432            ModelId::GPT6Astra | ModelId::GPT6Sol | ModelId::GPT6Luna => "6",
433            ModelId::GPT61Sol | ModelId::GPT61Terra => "6.1",
434            ModelId::GPT56Sol | ModelId::GPT56Terra | ModelId::GPT56Luna => "5.6",
435            ModelId::OpenAIGptOss20b | ModelId::OpenAIGptOss120b => "5",
436            // Anthropic generations
437            ModelId::ClaudeSonnet5 => "5",
438            ModelId::ClaudeSonnet55 => "5.5",
439            ModelId::ClaudeHaiku55 => "5.5",
440            ModelId::ClaudeFable5 => "5",
441            ModelId::ClaudeFable51 => "5.1",
442            ModelId::ClaudeFable52 => "5.2",
443            ModelId::ClaudeOpus5 => "5",
444            ModelId::ClaudeOpus55 => "5.5",
445            // DeepSeek generations
446            ModelId::DeepSeekFlash => "4",
447            ModelId::OllamaDeepSeekV41FlashCloud => "4.1",
448            // Mistral generations
449            ModelId::MistralLarge3 => "3",
450            ModelId::MistralLarge4 => "4",
451            ModelId::OllamaMistralLarge4Cloud => "4",
452            ModelId::MergeGatewayDeepseekFlash => "4.1",
453            ModelId::MetaMuseSpark13 | ModelId::MetaMuseSpark13Contributor => "Muse-Spark-1.3",
454            ModelId::MergeGatewayMetaMuseSparkOpen | ModelId::HuggingFaceMuseSparkOpenBaseten => "Muse-Spark-Open",
455            ModelId::OllamaMuseSparkOpenCloud => "Muse-Spark-Open",
456            ModelId::MetaMuseWonder10 => "Muse-Wonder-1.0",
457            ModelId::MetaMuseWonderFull10 => "Muse-Wonder-Full-1.0",
458            ModelId::MetaMuseEmber10 => "Muse-Ember-1.0",
459            // Z.AI generations
460            ModelId::ZaiGlm53
461            | ModelId::ZaiGlm53Flash
462            | ModelId::ZaiGlm53Flashx
463            | ModelId::MergeGatewayZaiGlm53Flash
464            | ModelId::MergeGatewayZaiGlm53Flashx => "5.3",
465            ModelId::OllamaGlm53FlashCloud => "5.3",
466            ModelId::Gemini38Flash => "3.8",
467            ModelId::MergeGatewayGoogleGemini38Flash => "3.8",
468            ModelId::Gemini4Argon => "4",
469            ModelId::Gemini4Carbon => "4",
470            ModelId::Gemini4Neon => "4",
471            ModelId::Gemini4Hydrogen => "4",
472            ModelId::MergeGatewayGoogleGemini4Argon => "4",
473            ModelId::MergeGatewayGoogleGemini4Carbon => "4",
474            ModelId::MergeGatewayGoogleGemini4Neon => "4",
475            ModelId::MergeGatewayGoogleGemini4Hydrogen => "4",
476            ModelId::OpenCodeGoGlm53 => "5.3",
477            ModelId::OpenCodeGoGpt56Luna => "5.6-luna",
478            ModelId::OpenCodeGoKimiK3 => "k3",
479            ModelId::MiMoV26Pro | ModelId::MiMoV26Flash | ModelId::MiMoV26ProUltraspeed => "v2.6",
480            ModelId::MergeGatewayXiaomimimoMimoV26Pro | ModelId::MergeGatewayXiaomimimoMimoV26Flash => "v2.6",
481            ModelId::MergeGatewayMistralLarge4 => "4",
482            ModelId::OpenCodeGoMinimaxM3 => "m3",
483            ModelId::OllamaGptOss20b => "oss",
484            ModelId::OllamaGptOss20bCloud => "oss-cloud",
485            ModelId::OllamaGptOss120bCloud => "oss-cloud",
486            ModelId::OllamaMinimaxM3Cloud => "minimax-m3",
487            ModelId::OllamaMinimaxM31FlashCloud => "minimax-m3.1",
488            ModelId::OllamaGlm53Cloud => "glm-5.3",
489            ModelId::OllamaGemma4 => "gemma-4",
490            ModelId::LlamaCppGemma426bA4b => "4",
491            ModelId::LlamaCppGemma4E4b => "4",
492            ModelId::LlamaCppGptOss20b => "oss",
493            // MiniMax models
494            ModelId::MinimaxM3 => "M3",
495            ModelId::MinimaxM31Flash | ModelId::MergeGatewayMinimaxM31Flash => "M3.1",
496            // StepFun models
497            ModelId::StepFun37Flash => "3.7",
498            ModelId::StepFun5Preview => "5",
499            // Moonshot models
500            ModelId::MoonshotKimiK31Pro => "k3.1",
501            ModelId::MoonshotKimiK3 => "k3",
502            ModelId::MergeGatewayMoonshotKimiK3 => "k3",
503            ModelId::MergeGatewayMoonshotKimiK31Pro => "k3.1",
504            // Hugging Face generations
505            ModelId::HuggingFaceOpenAIGptOss20b => "oss",
506            ModelId::HuggingFaceOpenAIGptOss120b => "oss",
507            ModelId::HuggingFaceMinimaxM3Novita => "m3",
508            ModelId::HuggingFaceGlm53FlashTogether => "5.3",
509            ModelId::HuggingFaceGlm53Together => "5.3",
510            // xAI models
511            ModelId::XaiGrok46 => "4.6",
512            ModelId::XaiGrok47 => "4.7",
513            ModelId::MergeGatewayXaiGrok46 => "4.6",
514            ModelId::MergeGatewayXaiGrok47 => "4.7",
515            // Qwen models
516            ModelId::MergeGatewayDefaultRouting => "routing",
517            ModelId::MergeGatewayAnthropicClaudeOpus5 => "5",
518            ModelId::MergeGatewayAnthropicClaudeOpus55 => "5.5",
519            ModelId::MergeGatewayAnthropicClaudeSonnet5 => "5",
520            ModelId::MergeGatewayAnthropicClaudeSonnet55 => "5.5",
521            ModelId::MergeGatewayAnthropicClaudeHaiku55 => "5.5",
522            ModelId::MergeGatewayAnthropicClaudeFable51 => "5.1",
523            ModelId::MergeGatewayAnthropicClaudeFable52 => "5.2",
524            ModelId::MergeGatewayAnthropicClaudeHaiku4520251001 => "4.5",
525            ModelId::MergeGatewayMinimaxH3 => "H3",
526            ModelId::MergeGatewayThinkingMachinesInkling => "Inkling",
527            ModelId::MergeGatewayOpenAIGpt56Luna
528            | ModelId::MergeGatewayOpenAIGpt56Sol
529            | ModelId::MergeGatewayOpenAIGpt56Terra => "5.6",
530            ModelId::MergeGatewayOpenAIGpt62Astra | ModelId::MergeGatewayOpenAIGpt62Sol => "6.2",
531            ModelId::MergeGatewayOpenAIGpt6Astra
532            | ModelId::MergeGatewayOpenAIGpt6Sol
533            | ModelId::MergeGatewayOpenAIGpt6Luna => "6",
534            ModelId::MergeGatewayOpenAIGpt61Sol | ModelId::MergeGatewayOpenAIGpt61Terra => "6.1",
535            // Vercel AI Gateway models
536            ModelId::VercelAnthropicClaudeSonnet5 => "5",
537            ModelId::VercelAnthropicClaudeOpus5 => "5",
538            ModelId::VercelAnthropicClaudeOpus55 => "5.5",
539            ModelId::VercelAnthropicClaudeHaiku45 => "4.5",
540            ModelId::VercelOpenAiGpt56Sol | ModelId::VercelOpenAiGpt56Luna => "5.6",
541            ModelId::VercelOpenAiGpt6Sol | ModelId::VercelOpenAiGpt6Luna => "6",
542            ModelId::VercelOpenAiGpt6Astra => "6",
543            ModelId::VercelGoogleGemini38Flash => "3.8",
544            ModelId::VercelDeepseekFlash => "4.1",
545            ModelId::VercelMoonshotaiKimiK3 => "k3",
546            ModelId::VercelMinimaxM3 => "M3",
547            ModelId::VercelSpacexaiGrok47 => "4.7",
548            _ => "unknown",
549        }
550    }
551
552    /// Sort key that orders models by generation, newest first.
553    ///
554    /// Generation strings are heterogeneous (`6.2`, `v2.6`, `M3.1`,
555    /// `Muse-Spark-1.3`, `oss`), so every run of ASCII digits is read as a
556    /// version component. Models without digits sort last, and equal keys
557    /// keep their input order when used with a stable sort.
558    pub fn generation_sort_key(&self) -> Reverse<Vec<u64>> {
559        Reverse(generation_components(self.generation()))
560    }
561
562    /// Determine if this model supports GPT-5.1+/5.2+/5.3+ shell tool type
563    pub(crate) fn supports_shell_tool(&self) -> bool {
564        matches!(
565            self,
566            ModelId::GPT62Astra
567                | ModelId::GPT62Sol
568                | ModelId::GPT6Astra
569                | ModelId::GPT6Sol
570                | ModelId::GPT61Sol
571                | ModelId::GPT6Luna
572                | ModelId::GPT56Sol
573                | ModelId::GPT56Terra
574                | ModelId::GPT56Luna
575        )
576    }
577
578    /// Determine if this model supports optimized apply_patch tool
579    pub fn supports_apply_patch_tool(&self) -> bool {
580        false
581    }
582}
583
584#[cfg(test)]
585mod tests {
586    use super::*;
587
588    #[test]
589    fn prefixed_request_model_resolves_on_bare_provider() {
590        // Regression for `openai/gpt-5.6-luna` on provider `openai` resolving
591        // to empty `supported:` and omitting reasoning effort: exact bare hit
592        // and prefixed fallback must agree, while gateway prefixed entries
593        // keep their exact match.
594        let bare = model_catalog_entry("openai", "gpt-5.6-luna").expect("bare openai entry exists");
595        let prefixed = model_catalog_entry("openai", "openai/gpt-5.6-luna").expect("prefixed fallback must resolve");
596        assert_eq!(bare.reasoning_efforts, prefixed.reasoning_efforts);
597        assert!(!prefixed.reasoning_efforts.is_empty());
598
599        let gateway =
600            model_catalog_entry("merge-gateway", "openai/gpt-5.6-luna").expect("gateway prefixed entry exists");
601        assert!(!gateway.reasoning_efforts.is_empty());
602
603        // Asymmetric boundary: unknown model stays missing on both shapes,
604        // and an unrelated prefix must not resolve to the bare model.
605        assert!(model_catalog_entry("openai", "no-such-model-xyz").is_none());
606        assert!(model_catalog_entry("openai", "openai/no-such-model-xyz").is_none());
607        assert!(model_catalog_entry("openai", "other-org/gpt-5.6-luna").is_none());
608    }
609
610    #[test]
611    fn generation_components_reads_digit_runs_across_generation_shapes() {
612        assert_eq!(generation_components("6.2"), [6, 2]);
613        assert_eq!(generation_components("v2.6"), [2, 6]);
614        assert_eq!(generation_components("M3.1"), [3, 1]);
615        assert_eq!(generation_components("Muse-Spark-1.3"), [1, 3]);
616        assert_eq!(generation_components("5.6-luna"), [5, 6]);
617        assert_eq!(generation_components("oss"), Vec::<u64>::new());
618        assert_eq!(generation_components(""), Vec::<u64>::new());
619    }
620
621    #[test]
622    fn generation_sort_key_orders_versions_newest_first_and_keeps_ties_stable() {
623        let mut models = vec![
624            ModelId::GPT56Sol, // 5.6
625            ModelId::GPT62Sol, // 6.2
626            ModelId::GPT6Sol,  // 6
627            ModelId::GPT61Sol, // 6.1
628        ];
629        models.sort_by_key(|model| model.generation_sort_key());
630        assert_eq!(
631            models,
632            [
633                ModelId::GPT62Sol,
634                ModelId::GPT61Sol,
635                ModelId::GPT6Sol,
636                ModelId::GPT56Sol
637            ]
638        );
639
640        // Equal generations keep their arrival order (stable sort).
641        let mut ties = vec![ModelId::GPT6Luna, ModelId::GPT6Astra, ModelId::GPT6Sol]; // all "6"
642        ties.sort_by_key(|model| model.generation_sort_key());
643        assert_eq!(ties, [ModelId::GPT6Luna, ModelId::GPT6Astra, ModelId::GPT6Sol]);
644
645        // Generations with no numeric component sort after versioned ones.
646        let mut mixed = vec![ModelId::OllamaGptOss20b, ModelId::GPT6Sol]; // "oss", "6"
647        mixed.sort_by_key(|model| model.generation_sort_key());
648        assert_eq!(mixed, [ModelId::GPT6Sol, ModelId::OllamaGptOss20b]);
649    }
650}