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    /// User-defined OpenAI-compatible endpoint (#1519).
104    ///
105    /// A single dynamic identity for arbitrary `[providers.<name>]
106    /// kind="openai-compatible"` entries. It speaks the OpenAI Chat Completions
107    /// wire protocol and carries no built-in base URL/model — the concrete
108    /// endpoint and model arrive via config (`base_url` / `model`) and the
109    /// route's `base_url_override`, never from this static descriptor.
110    Custom,
111}
112
113impl ProviderKind {
114    pub const ALL: [Self; 30] = [
115        Self::Deepseek,
116        Self::DeepseekAnthropic,
117        Self::NvidiaNim,
118        Self::Openai,
119        Self::Atlascloud,
120        Self::WanjieArk,
121        Self::Volcengine,
122        Self::Openrouter,
123        Self::XiaomiMimo,
124        Self::Novita,
125        Self::Fireworks,
126        Self::Siliconflow,
127        Self::Arcee,
128        Self::SiliconflowCN,
129        Self::Moonshot,
130        Self::Sglang,
131        Self::Vllm,
132        Self::Ollama,
133        Self::Huggingface,
134        Self::Together,
135        Self::Qianfan,
136        Self::OpenaiCodex,
137        Self::Anthropic,
138        Self::Openmodel,
139        Self::Zai,
140        Self::Stepfun,
141        Self::Minimax,
142        Self::Deepinfra,
143        Self::Sakana,
144        Self::Custom,
145    ];
146
147    #[must_use]
148    pub fn all() -> &'static [Self] {
149        &Self::ALL
150    }
151
152    #[must_use]
153    pub fn names_hint() -> String {
154        Self::all()
155            .iter()
156            .map(|provider| provider.as_str())
157            .collect::<Vec<_>>()
158            .join(", ")
159    }
160
161    #[must_use]
162    pub fn as_str(self) -> &'static str {
163        self.provider().id()
164    }
165
166    #[must_use]
167    pub fn parse(value: &str) -> Option<Self> {
168        let trimmed = value.trim();
169        provider::all_providers()
170            .iter()
171            .find(|p| {
172                trimmed.eq_ignore_ascii_case(p.id())
173                    || p.aliases().iter().any(|a| trimmed.eq_ignore_ascii_case(a))
174            })
175            .map(|p| p.kind())
176    }
177
178    #[must_use]
179    pub fn is_siliconflow(self) -> bool {
180        matches!(self, Self::Siliconflow | Self::SiliconflowCN)
181    }
182
183    /// Return the built-in metadata entry for this provider.
184    ///
185    /// This is a metadata foundation only; runtime routing still resolves
186    /// through [`crate::ConfigToml::resolve_runtime_options`].
187    #[must_use]
188    pub fn provider(self) -> &'static dyn provider::Provider {
189        provider::provider_for_kind(self)
190    }
191}