Skip to main content

codewhale_config/
provider_kind.rs

1//! The canonical [`ProviderKind`] enum (#3311): the set of built-in provider
2//! kinds, their serde aliases, and identity helpers (`all`, `as_str`, `parse`,
3//! `provider`). Extracted verbatim from `lib.rs` to separate provider identity
4//! from config schema/loading; re-exported at the crate root so
5//! `codewhale_config::ProviderKind` is unchanged. Behavior is identical.
6
7use serde::{Deserialize, Serialize};
8
9use crate::provider;
10
11#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Default)]
12#[serde(rename_all = "kebab-case")]
13pub enum ProviderKind {
14    #[default]
15    #[serde(
16        alias = "deepseek-cn",
17        alias = "deepseek_china",
18        alias = "deepseekcn",
19        alias = "deepseek-china"
20    )]
21    Deepseek,
22    #[serde(
23        alias = "deepseek-anthropic",
24        alias = "deepseek_anthropic",
25        alias = "deepseek-claude",
26        alias = "deepseek_claude"
27    )]
28    DeepseekAnthropic,
29    NvidiaNim,
30    #[serde(alias = "open-ai")]
31    Openai,
32    Atlascloud,
33    #[serde(
34        alias = "wanjie",
35        alias = "wanjie_ark",
36        alias = "ark-wanjie",
37        alias = "ark_wanjie",
38        alias = "wanjie-maas",
39        alias = "wanjie_maas"
40    )]
41    WanjieArk,
42    #[serde(alias = "volcengine-ark", alias = "volcengine_ark", alias = "ark")]
43    Volcengine,
44    Openrouter,
45    #[serde(alias = "mimo", alias = "xiaomi", alias = "xiaomi_mimo")]
46    XiaomiMimo,
47    Novita,
48    Fireworks,
49    #[serde(alias = "silicon-flow", alias = "silicon_flow")]
50    Siliconflow,
51    #[serde(alias = "arcee-ai", alias = "arcee_ai")]
52    Arcee,
53    #[serde(alias = "siliconflow-cn", alias = "siliconflow-CN")]
54    SiliconflowCN,
55    Moonshot,
56    Sglang,
57    Vllm,
58    Ollama,
59    #[serde(alias = "hugging-face", alias = "hugging_face", alias = "hf")]
60    Huggingface,
61    #[serde(alias = "together-ai", alias = "together_ai")]
62    Together,
63    #[serde(alias = "baidu-qianfan", alias = "baidu_qianfan", alias = "baidu")]
64    Qianfan,
65    #[serde(
66        alias = "openai-codex",
67        alias = "openai_codex",
68        alias = "codex",
69        alias = "chatgpt",
70        alias = "chatgpt-codex",
71        alias = "chatgpt_codex"
72    )]
73    OpenaiCodex,
74    #[serde(alias = "claude")]
75    Anthropic,
76    #[serde(alias = "open-model", alias = "open_model")]
77    Openmodel,
78    #[serde(
79        alias = "z-ai",
80        alias = "z_ai",
81        alias = "z.ai",
82        alias = "zhipu",
83        alias = "zhipuai",
84        alias = "bigmodel",
85        alias = "big-model"
86    )]
87    Zai,
88    #[serde(
89        alias = "step-fun",
90        alias = "step_fun",
91        alias = "stepfun",
92        alias = "stepflash",
93        alias = "step-flash",
94        alias = "step_flash"
95    )]
96    Stepfun,
97    #[serde(alias = "mini-max", alias = "mini_max", alias = "minimax")]
98    Minimax,
99    #[serde(alias = "deep-infra", alias = "deep_infra")]
100    Deepinfra,
101    #[serde(alias = "sakana-ai", alias = "sakana_ai", alias = "fugu")]
102    Sakana,
103    #[serde(alias = "long-cat", alias = "meituan-longcat", alias = "meituan")]
104    LongCat,
105    /// User-defined OpenAI-compatible endpoint (#1519).
106    ///
107    /// A single dynamic identity for arbitrary `[providers.<name>]
108    /// kind="openai-compatible"` entries. It speaks the OpenAI Chat Completions
109    /// wire protocol and carries no built-in base URL/model — the concrete
110    /// endpoint and model arrive via config (`base_url` / `model`) and the
111    /// route's `base_url_override`, never from this static descriptor.
112    Custom,
113}
114
115impl ProviderKind {
116    pub const ALL: [Self; 31] = [
117        Self::Deepseek,
118        Self::DeepseekAnthropic,
119        Self::NvidiaNim,
120        Self::Openai,
121        Self::Atlascloud,
122        Self::WanjieArk,
123        Self::Volcengine,
124        Self::Openrouter,
125        Self::XiaomiMimo,
126        Self::Novita,
127        Self::Fireworks,
128        Self::Siliconflow,
129        Self::Arcee,
130        Self::SiliconflowCN,
131        Self::Moonshot,
132        Self::Sglang,
133        Self::Vllm,
134        Self::Ollama,
135        Self::Huggingface,
136        Self::Together,
137        Self::Qianfan,
138        Self::OpenaiCodex,
139        Self::Anthropic,
140        Self::Openmodel,
141        Self::Zai,
142        Self::Stepfun,
143        Self::Minimax,
144        Self::Deepinfra,
145        Self::Sakana,
146        Self::LongCat,
147        Self::Custom,
148    ];
149
150    #[must_use]
151    pub fn all() -> &'static [Self] {
152        &Self::ALL
153    }
154
155    #[must_use]
156    pub fn names_hint() -> String {
157        Self::all()
158            .iter()
159            .map(|provider| provider.as_str())
160            .collect::<Vec<_>>()
161            .join(", ")
162    }
163
164    #[must_use]
165    pub fn as_str(self) -> &'static str {
166        self.provider().id()
167    }
168
169    #[must_use]
170    pub fn parse(value: &str) -> Option<Self> {
171        let trimmed = value.trim();
172        provider::all_providers()
173            .iter()
174            .find(|p| {
175                trimmed.eq_ignore_ascii_case(p.id())
176                    || p.aliases().iter().any(|a| trimmed.eq_ignore_ascii_case(a))
177            })
178            .map(|p| p.kind())
179    }
180
181    #[must_use]
182    pub fn is_siliconflow(self) -> bool {
183        matches!(self, Self::Siliconflow | Self::SiliconflowCN)
184    }
185
186    /// Return the built-in metadata entry for this provider.
187    ///
188    /// This is a metadata foundation only; runtime routing still resolves
189    /// through [`crate::ConfigToml::resolve_runtime_options`].
190    #[must_use]
191    pub fn provider(self) -> &'static dyn provider::Provider {
192        provider::provider_for_kind(self)
193    }
194}