Skip to main content

vtcode_config/models/model_id/
provider.rs

1use crate::models::{Provider, ProviderModelSupport};
2
3use super::ModelId;
4
5/// Canonical catalog key for a built-in provider. Kept here so capability
6/// lookups can derive a `'static` key from a temporary `Provider` without an
7/// allocation, and so a new provider variant forces this table to be updated.
8fn canonical_provider_key(provider: Provider) -> &'static str {
9    match provider {
10        Provider::Gemini => "gemini",
11        Provider::OpenAI => "openai",
12        Provider::Anthropic => "anthropic",
13        Provider::Copilot => "copilot",
14        Provider::DeepSeek => "deepseek",
15        Provider::Meta => "meta",
16        Provider::OpenRouter => "openrouter",
17        Provider::Ollama => "ollama",
18        Provider::OllamaCloud => "ollama-cloud",
19        Provider::LmStudio => "lmstudio",
20        Provider::LlamaCpp => "llamacpp",
21        Provider::Moonshot => "moonshot",
22        Provider::ZAI => "zai",
23        Provider::Minimax => "minimax",
24        Provider::MiMo => "mimo",
25        Provider::Mistral => "mistral",
26        Provider::HuggingFace => "huggingface",
27        Provider::OpenCodeZen => "opencode-zen",
28        Provider::OpenCodeGo => "opencode-go",
29        Provider::Qwen => "qwen",
30        Provider::StepFun => "stepfun",
31        Provider::Evolink => "evolink",
32        Provider::Poolside => "poolside",
33        Provider::XAI => "xai",
34        Provider::NVIDIA => "nvidia",
35        Provider::MergeGateway => "merge-gateway",
36        Provider::Vercel => "vercel",
37    }
38}
39
40impl ModelId {
41    /// Raw provider key for this model.
42    ///
43    /// Custom variants preserve the user-declared key even when it is not a
44    /// built-in [`Provider`]; every other variant uses its canonical provider
45    /// key. Capability lookups must use this rather than [`Self::provider`],
46    /// whose fallback would attribute a custom route to OpenAI's catalog.
47    pub(super) fn provider_key(&self) -> &str {
48        match self {
49            ModelId::Custom(provider_key, _) => provider_key,
50            _ => canonical_provider_key(self.provider()),
51        }
52    }
53
54    /// Whether the declared provider key names a built-in provider. Custom
55    /// routes without one have no reliable catalog or provider capabilities.
56    fn has_builtin_provider_key(&self) -> bool {
57        match self {
58            ModelId::Custom(provider_key, _) => {
59                use std::str::FromStr;
60                Provider::from_str(provider_key).is_ok()
61            }
62            _ => true,
63        }
64    }
65
66    /// Get the provider for this model
67    pub fn provider(&self) -> Provider {
68        if self.openrouter_metadata().is_some() {
69            return Provider::OpenRouter;
70        }
71        if let Some(provider) = self.table_provider() {
72            return provider;
73        }
74        match self {
75            ModelId::Custom(provider_key, _) => {
76                use std::str::FromStr;
77                Provider::from_str(provider_key).unwrap_or(Provider::OpenAI)
78            }
79            // Every remaining variant is a hand-written OpenRouter model without
80            // generated metadata; the table covers all other providers.
81            _ => Provider::OpenRouter,
82        }
83    }
84
85    /// Whether this model supports configurable reasoning effort levels
86    pub fn supports_reasoning_effort(&self) -> bool {
87        self.has_builtin_provider_key() && self.provider().supports_reasoning_effort(&self.as_str())
88    }
89
90    /// Whether this model exposes structured reasoning output.
91    pub fn supports_reasoning(&self) -> bool {
92        self.has_builtin_provider_key() && self.provider().supports_reasoning(&self.as_str())
93    }
94}