| 1 | //! OMP-style provider descriptors: how to talk to a host. |
| 2 | //! |
| 3 | //! One committed data file owns built-in/legacy defaults and compatible hosts. |
| 4 | //! Model rosters are **not** compiled here. A descriptor names the wire, URL, env |
| 5 | //! var, and whether `GET /v1/models` is the catalog authority |
| 6 | //! for that host. Offerings come from the Codewhale catalog layers and live |
| 7 | //! provider `/models` refreshes. |
| 8 | |
| 9 | use std::sync::OnceLock; |
| 10 | |
| 11 | use serde::Deserialize; |
| 12 | |
| 13 | pub(crate) const DESCRIPTORS_JSON: &str = include_str!("../assets/provider_descriptors.json"); |
| 14 | |
| 15 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 16 | pub enum ModelIdsPolicy { |
| 17 | Strict, |
| 18 | Roster, |
| 19 | Catalog, |
| 20 | Verbatim, |
| 21 | } |
| 22 | |
| 23 | #[derive(Debug, Clone, Copy)] |
| 24 | pub(crate) struct ModelRules { |
| 25 | pub ids: ModelIdsPolicy, |
| 26 | pub accept: &'static [&'static str], |
| 27 | pub strip_prefixes: &'static [&'static str], |
| 28 | pub aliases: &'static [(&'static str, &'static str)], |
| 29 | pub wire_slugs: &'static [(&'static str, &'static str)], |
| 30 | } |
| 31 | |
| 32 | /// Immutable built-in view compiled from the same descriptor data file. |
| 33 | #[derive(Debug, Clone, Copy)] |
| 34 | pub(crate) struct BuiltinProviderDescriptor { |
| 35 | pub kind: crate::ProviderKind, |
| 36 | pub id: &'static str, |
| 37 | pub label: &'static str, |
| 38 | pub base_url: &'static str, |
| 39 | pub default_model: &'static str, |
| 40 | pub env_vars: &'static [&'static str], |
| 41 | pub aliases: &'static [&'static str], |
| 42 | pub config_key: &'static str, |
| 43 | pub secret_store_slot: &'static str, |
| 44 | pub family: &'static str, |
| 45 | pub selectable: bool, |
| 46 | pub retired: bool, |
| 47 | pub wire_policy: crate::provider::WirePolicy, |
| 48 | pub credential_help: crate::provider::CredentialHelp, |
| 49 | pub models: ModelRules, |
| 50 | } |
| 51 | |
| 52 | /// Exact compatibility identity for the TUI-only legacy DeepSeek China table. |
| 53 | #[derive(Debug, Clone, Copy)] |
| 54 | pub struct LegacyProviderDescriptor { |
| 55 | /// Canonical historical identity. |
| 56 | pub id: &'static str, |
| 57 | /// Legacy display label. |
| 58 | pub label: &'static str, |
| 59 | /// Historical route seed. |
| 60 | pub base_url: &'static str, |
| 61 | /// Historical model seed. |
| 62 | pub default_model: &'static str, |
| 63 | /// Config table key; never collapsed into an alias during lookup. |
| 64 | pub config_key: &'static str, |
| 65 | /// Existing shared durable credential slot. |
| 66 | pub secret_store_slot: &'static str, |
| 67 | } |
| 68 | |
| 69 | /// Pure identity/presentation compatibility from the existing descriptor owner. |
| 70 | /// This is a name projection, never credential or route admission authority. |
| 71 | #[derive(Debug, Clone, Copy)] |
| 72 | pub struct ProviderCompatibility { |
| 73 | pub kind: crate::ProviderKind, |
| 74 | pub id: &'static str, |
| 75 | pub tui_wire_tag: &'static str, |
| 76 | pub config_key: &'static str, |
| 77 | pub base_url_config_key: &'static str, |
| 78 | pub catalog_id: &'static str, |
| 79 | pub catalog_source_id: &'static str, |
| 80 | pub subagent_aliases: &'static [&'static str], |
| 81 | pub selector_aliases: &'static [&'static str], |
| 82 | pub label: &'static str, |
| 83 | pub base_url: &'static str, |
| 84 | pub default_model: &'static str, |
| 85 | } |
| 86 | |
| 87 | /// Released presentation rows in the descriptor owner's stable order. |
| 88 | #[must_use] |
| 89 | pub fn provider_compatibility() -> &'static [ProviderCompatibility] { |
| 90 | PROVIDER_COMPATIBILITY |
| 91 | } |
| 92 | |
| 93 | /// Exact canonical configured name; custom table names are not classified here. |
| 94 | #[must_use] |
| 95 | pub fn compatibility_for_id(id: &str) -> Option<&'static ProviderCompatibility> { |
| 96 | PROVIDER_COMPATIBILITY.iter().find(|row| row.id == id) |
| 97 | } |
| 98 | |
| 99 | /// Intrinsic built-in's canonical metadata. No active config is consulted. |
| 100 | #[must_use] |
| 101 | pub fn compatibility_for_kind(kind: crate::ProviderKind) -> &'static ProviderCompatibility { |
| 102 | PROVIDER_COMPATIBILITY |
| 103 | .iter() |
| 104 | .find(|row| row.id == kind.as_str()) |
| 105 | .expect("generated compatibility covers every intrinsic kind") |
| 106 | } |
| 107 | |
| 108 | /// Decode a released presentation tag; callers still admit the resulting name. |
| 109 | #[must_use] |
| 110 | pub fn compatibility_from_wire_tag(tag: &str) -> Option<&'static ProviderCompatibility> { |
| 111 | PROVIDER_COMPATIBILITY |
| 112 | .iter() |
| 113 | .find(|row| row.tui_wire_tag == tag) |
| 114 | } |
| 115 | |
| 116 | /// Explicit legacy aliases are checked before ordinary kind alias grouping. |
| 117 | #[must_use] |
| 118 | pub fn compatibility_for_selector(value: &str) -> Option<&'static ProviderCompatibility> { |
| 119 | let name = value.trim(); |
| 120 | PROVIDER_COMPATIBILITY |
| 121 | .iter() |
| 122 | .find(|row| { |
| 123 | row.selector_aliases |
| 124 | .iter() |
| 125 | .any(|alias| alias.eq_ignore_ascii_case(name)) |
| 126 | }) |
| 127 | .or_else(|| crate::ProviderKind::parse_config_identity(name).map(compatibility_for_kind)) |
| 128 | } |
| 129 | |
| 130 | /// Released TUI wire spelling, paired with an exact non-secret route key. |
| 131 | /// This projection does not admit a route or infer a custom table's kind. |
| 132 | #[must_use] |
| 133 | pub fn tui_wire_tag_for_route(kind: crate::ProviderKind, id: &str) -> Option<&'static str> { |
| 134 | if id.trim().is_empty() || id.trim() != id { |
| 135 | return None; |
| 136 | } |
| 137 | if kind == crate::ProviderKind::Custom { |
| 138 | return Some(compatibility_for_kind(kind).tui_wire_tag); |
| 139 | } |
| 140 | let row = compatibility_for_id(id)?; |
| 141 | (row.kind == kind).then_some(row.tui_wire_tag) |
| 142 | } |
| 143 | |
| 144 | /// Decode a released tag while retaining its exact identity provenance. |
| 145 | #[must_use] |
| 146 | pub fn kind_from_tui_wire_tag(tag: &str, id: &str) -> Option<crate::ProviderKind> { |
| 147 | let row = compatibility_from_wire_tag(tag)?; |
| 148 | (tui_wire_tag_for_route(row.kind, id) == Some(tag)).then_some(row.kind) |
| 149 | } |
| 150 | |
| 151 | /// Compile-time compatibility constants, generated from descriptor data. |
| 152 | pub mod defaults { |
| 153 | include!(concat!(env!("OUT_DIR"), "/provider_defaults.rs")); |
| 154 | } |
| 155 | |
| 156 | include!(concat!(env!("OUT_DIR"), "/provider_descriptors.rs")); |
| 157 | |
| 158 | /// How this host's model list is discovered. |
| 159 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)] |
| 160 | #[serde(rename_all = "snake_case")] |
| 161 | pub enum DescriptorDiscovery { |
| 162 | /// Authenticated `GET {base_url}/models` is authoritative for this credential. |
| 163 | ModelsEndpoint, |
| 164 | PublicModelsEndpoint, |
| 165 | /// No live discovery; only catalog/config rows. |
| 166 | None, |
| 167 | } |
| 168 | |
| 169 | /// Transport used to send turns. Not a brand enum. |
| 170 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize)] |
| 171 | #[serde(rename_all = "kebab-case")] |
| 172 | pub enum DescriptorWire { |
| 173 | OpenaiCompatible, |
| 174 | AnthropicMessages, |
| 175 | } |
| 176 | |
| 177 | #[derive(Debug, Deserialize)] |
| 178 | struct DescriptorFile { |
| 179 | descriptors: Vec<ProviderDescriptor>, |
| 180 | } |
| 181 | |
| 182 | /// Data row describing a hosted OpenAI-compatible (or Anthropic Messages) gateway. |
| 183 | #[derive(Debug, Clone, PartialEq, Eq, Deserialize)] |
| 184 | pub struct ProviderDescriptor { |
| 185 | pub id: String, |
| 186 | pub label: String, |
| 187 | pub wire: DescriptorWire, |
| 188 | pub base_url: String, |
| 189 | pub api_key_env: String, |
| 190 | pub default_model: String, |
| 191 | pub discovery: DescriptorDiscovery, |
| 192 | #[serde(default)] |
| 193 | pub docs_url: Option<String>, |
| 194 | #[serde(default)] |
| 195 | pub credential_url: Option<String>, |
| 196 | #[serde(default)] |
| 197 | pub guidance: Option<String>, |
| 198 | #[serde(default)] |
| 199 | pub aliases: Vec<String>, |
| 200 | } |
| 201 | |
| 202 | impl ProviderDescriptor { |
| 203 | #[must_use] |
| 204 | pub fn matches(&self, needle: &str) -> bool { |
| 205 | let needle = needle.trim().to_ascii_lowercase().replace('_', "-"); |
| 206 | if needle.is_empty() { |
| 207 | return false; |
| 208 | } |
| 209 | self.id == needle |
| 210 | || self |
| 211 | .aliases |
| 212 | .iter() |
| 213 | .any(|alias| alias.eq_ignore_ascii_case(&needle)) |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | static DESCRIPTORS: OnceLock<Vec<ProviderDescriptor>> = OnceLock::new(); |
| 218 | |
| 219 | /// Bundled compatible-host descriptors. Panics only if the committed JSON is invalid. |
| 220 | #[must_use] |
| 221 | pub fn bundled_provider_descriptors() -> &'static [ProviderDescriptor] { |
| 222 | DESCRIPTORS |
| 223 | .get_or_init(|| { |
| 224 | let file: DescriptorFile = serde_json::from_str(DESCRIPTORS_JSON) |
| 225 | .expect("committed provider_descriptors.json must parse"); |
| 226 | file.descriptors |
| 227 | }) |
| 228 | .as_slice() |
| 229 | } |
| 230 | |
| 231 | #[must_use] |
| 232 | pub fn bundled_provider_descriptor(id: &str) -> Option<&'static ProviderDescriptor> { |
| 233 | bundled_provider_descriptors().iter().find(|descriptor| { |
| 234 | descriptor.wire == DescriptorWire::OpenaiCompatible && descriptor.matches(id) |
| 235 | }) |
| 236 | } |
| 237 | |
| 238 | #[must_use] |
| 239 | pub fn bundled_provider_canonical_id(id: &str) -> Option<String> { |
| 240 | let trimmed = id.trim(); |
| 241 | let descriptor = bundled_provider_descriptor(trimmed)?; |
| 242 | if crate::ProviderKind::parse_config_identity(&descriptor.id).is_none() |
| 243 | && compatibility_for_selector(&descriptor.id).is_none() |
| 244 | { |
| 245 | Some(descriptor.id.clone()) |
| 246 | } else { |
| 247 | Some(trimmed.to_ascii_lowercase().replace('_', "-")) |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | #[must_use] |
| 252 | pub fn active_provider_descriptors() -> Vec<ProviderDescriptor> { |
| 253 | let mut out = bundled_provider_descriptors().to_vec(); |
| 254 | if let Some(admitted) = crate::cloud_facts::overlay::pulled_registry() { |
| 255 | for row in &mut out { |
| 256 | if let Some(default_model) = admitted.compiled.descriptor_defaults.get(&row.id) { |
| 257 | row.default_model.clone_from(default_model); |
| 258 | } |
| 259 | } |
| 260 | out.extend( |
| 261 | admitted |
| 262 | .providers |
| 263 | .iter() |
| 264 | .map(crate::cloud_facts::PulledProvider::to_descriptor), |
| 265 | ); |
| 266 | } |
| 267 | out |
| 268 | } |
| 269 | |
| 270 | #[must_use] |
| 271 | pub fn is_registry_admitted_base_url(base_url: &str) -> bool { |
| 272 | fn host(raw: &str) -> Option<String> { |
| 273 | url::Url::parse(raw.trim()).ok().and_then(|url| { |
| 274 | url.host_str() |
| 275 | .map(|host| host.trim_end_matches('.').to_ascii_lowercase()) |
| 276 | }) |
| 277 | } |
| 278 | let Some(target) = host(base_url) else { |
| 279 | return false; |
| 280 | }; |
| 281 | crate::cloud_facts::overlay::pulled_registry().is_some_and(|admitted| { |
| 282 | admitted |
| 283 | .providers |
| 284 | .iter() |
| 285 | .any(|provider| host(&provider.base_url).as_deref() == Some(target.as_str())) |
| 286 | }) |
| 287 | } |
| 288 | |
| 289 | #[must_use] |
| 290 | pub fn provider_descriptor(id: &str) -> Option<ProviderDescriptor> { |
| 291 | active_provider_descriptors() |
| 292 | .into_iter() |
| 293 | .find(|descriptor| descriptor.matches(id)) |
| 294 | } |
| 295 | |
| 296 | #[must_use] |
| 297 | pub(crate) fn normalize_model_lookup_key(model: &str) -> String { |
| 298 | model.trim().to_ascii_lowercase().replace(['_', ' '], "-") |
| 299 | } |
| 300 | |
| 301 | pub(crate) fn model_rules_for(kind: crate::ProviderKind) -> &'static ModelRules { |
| 302 | &builtin_provider_descriptor(kind).models |
| 303 | } |
| 304 | |
| 305 | #[must_use] |
| 306 | pub fn provider_model_alias(kind: crate::ProviderKind, model: &str) -> Option<&'static str> { |
| 307 | let key = normalize_model_lookup_key(model); |
| 308 | model_rules_for(kind) |
| 309 | .aliases |
| 310 | .iter() |
| 311 | .find(|(alias, _)| *alias == key) |
| 312 | .map(|(_, target)| *target) |
| 313 | } |
| 314 | |
| 315 | #[must_use] |
| 316 | pub fn provider_passes_model_through(kind: crate::ProviderKind) -> bool { |
| 317 | model_rules_for(kind).ids == ModelIdsPolicy::Verbatim |
| 318 | } |
| 319 | |
| 320 | #[cfg(test)] |
| 321 | mod tests { |
| 322 | use super::*; |
| 323 | |
| 324 | #[test] |
| 325 | fn descriptors_parse_and_command_code_is_a_row_not_a_kind() { |
| 326 | let rows = bundled_provider_descriptors(); |
| 327 | assert!( |
| 328 | rows.len() >= 6, |
| 329 | "expected compatible hosts plus command-code and dashscope" |
| 330 | ); |
| 331 | for row in rows { |
| 332 | assert!(row.base_url.starts_with("https://"), "{}", row.id); |
| 333 | assert!(!row.api_key_env.is_empty(), "{}", row.id); |
| 334 | assert!(!row.default_model.is_empty(), "{}", row.id); |
| 335 | assert!(matches!( |
| 336 | row.discovery, |
| 337 | DescriptorDiscovery::ModelsEndpoint |
| 338 | | DescriptorDiscovery::PublicModelsEndpoint |
| 339 | | DescriptorDiscovery::None |
| 340 | )); |
| 341 | assert_eq!(row.wire, DescriptorWire::OpenaiCompatible); |
| 342 | } |
| 343 | let cmd = provider_descriptor("command-code").expect("command-code"); |
| 344 | assert_eq!(cmd.base_url, "https://api.commandcode.ai/provider/v1"); |
| 345 | assert_eq!(cmd.api_key_env, "COMMAND_CODE_API_KEY"); |
| 346 | assert_eq!( |
| 347 | provider_descriptor("cmd-code") |
| 348 | .as_ref() |
| 349 | .map(|row| row.id.as_str()), |
| 350 | Some("command-code") |
| 351 | ); |
| 352 | // Alibaba Model Studio is a data-driven row: live /v1/models is the |
| 353 | // Qwen model authority, never a compiled roster. |
| 354 | let dashscope = provider_descriptor("dashscope").expect("dashscope"); |
| 355 | assert_eq!( |
| 356 | dashscope.base_url, |
| 357 | "https://dashscope-intl.aliyuncs.com/compatible-mode/v1" |
| 358 | ); |
| 359 | assert_eq!(dashscope.api_key_env, "DASHSCOPE_API_KEY"); |
| 360 | assert_eq!( |
| 361 | provider_descriptor("qwen") |
| 362 | .as_ref() |
| 363 | .map(|row| row.id.as_str()), |
| 364 | Some("dashscope"), |
| 365 | "the founder's `qwen` name resolves to the DashScope row" |
| 366 | ); |
| 367 | } |
| 368 | |
| 369 | /// #6616: AICraft carries the console, docs and guidance its neighbours |
| 370 | /// do, and every link a descriptor publishes is HTTPS. |
| 371 | #[test] |
| 372 | fn aicraft_carries_console_docs_and_guidance() { |
| 373 | let aicraft = provider_descriptor("ai-craft").expect("aicraft"); |
| 374 | assert_eq!(aicraft.id, "aicraft"); |
| 375 | assert_eq!( |
| 376 | aicraft.docs_url.as_deref(), |
| 377 | Some("https://aicraftapi.com/docs.html#codewhale") |
| 378 | ); |
| 379 | assert_eq!( |
| 380 | aicraft.credential_url.as_deref(), |
| 381 | Some("https://aicraftapi.com/dashboard.html") |
| 382 | ); |
| 383 | let guidance = aicraft.guidance.as_deref().expect("aicraft guidance"); |
| 384 | assert!(guidance.contains("Store AICRAFT_API_KEY"), "{guidance}"); |
| 385 | for row in bundled_provider_descriptors() { |
| 386 | for url in [&row.docs_url, &row.credential_url].into_iter().flatten() { |
| 387 | assert!(url.starts_with("https://"), "{}: {url}", row.id); |
| 388 | } |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | /// #6695: Tsubasa is a data row on the existing compatible transport with |
| 393 | /// its own key env. The row carries no context field, so the guidance is |
| 394 | /// where the 32K window and the second public model id reach the user. |
| 395 | #[test] |
| 396 | fn tsubasa_is_a_compatible_row_with_its_own_key() { |
| 397 | let tsubasa = provider_descriptor("tsubasa").expect("tsubasa"); |
| 398 | assert_eq!(tsubasa.wire, DescriptorWire::OpenaiCompatible); |
| 399 | assert_eq!(tsubasa.base_url, "https://api.tsubasa.sh/v1"); |
| 400 | assert_eq!(tsubasa.api_key_env, "TSUBASA_API_KEY"); |
| 401 | assert_eq!(tsubasa.default_model, "tsubasa-pro"); |
| 402 | let guidance = tsubasa.guidance.as_deref().expect("tsubasa guidance"); |
| 403 | for needle in [ |
| 404 | "tsubasa-fast", |
| 405 | "context_window = 32768", |
| 406 | "Store TSUBASA_API_KEY", |
| 407 | ] { |
| 408 | assert!(guidance.contains(needle), "{needle}: {guidance}"); |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | #[test] |
| 413 | fn cheaper_inference_is_a_descriptor_row() { |
| 414 | let row = provider_descriptor("cheaper-inference").expect("cheaperinference"); |
| 415 | assert_eq!(row.id, "cheaperinference"); |
| 416 | assert_eq!(row.base_url, "https://api.cheaperinference.com/v1"); |
| 417 | assert_eq!(row.api_key_env, "CHEAPER_INFERENCE_API_KEY"); |
| 418 | assert_eq!(row.default_model, "gpt-5.4-mini"); |
| 419 | assert_eq!( |
| 420 | provider_descriptor("cheaper_inference") |
| 421 | .as_ref() |
| 422 | .map(|row| row.id.as_str()), |
| 423 | Some("cheaperinference") |
| 424 | ); |
| 425 | } |
| 426 | |
| 427 | #[test] |
| 428 | fn standard_compute_is_a_descriptor_row() { |
| 429 | let row = provider_descriptor("standard-compute").expect("standardcompute"); |
| 430 | assert_eq!(row.id, "standardcompute"); |
| 431 | assert_eq!(row.wire, DescriptorWire::OpenaiCompatible); |
| 432 | assert_eq!(row.base_url, "https://api.stdcmpt.com/v1"); |
| 433 | assert_eq!(row.api_key_env, "STANDARDCOMPUTE_API_KEY"); |
| 434 | assert_eq!(row.default_model, "standardcompute"); |
| 435 | assert_eq!( |
| 436 | provider_descriptor("standard_compute") |
| 437 | .as_ref() |
| 438 | .map(|row| row.id.as_str()), |
| 439 | Some("standardcompute") |
| 440 | ); |
| 441 | } |
| 442 | |
| 443 | #[test] |
| 444 | fn worldrouter_is_a_descriptor_row() { |
| 445 | let row = provider_descriptor("worldrouter").expect("worldrouter"); |
| 446 | assert_eq!(row.id, "worldrouter"); |
| 447 | assert_eq!(row.wire, DescriptorWire::OpenaiCompatible); |
| 448 | assert_eq!(row.base_url, "https://inference-api.worldrouter.ai/v1"); |
| 449 | assert_eq!(row.api_key_env, "WORLDROUTER_API_KEY"); |
| 450 | assert_eq!(row.default_model, "claude-sonnet-5-5"); |
| 451 | assert_eq!( |
| 452 | provider_descriptor("world_router") |
| 453 | .as_ref() |
| 454 | .map(|row| row.id.as_str()), |
| 455 | Some("worldrouter") |
| 456 | ); |
| 457 | } |
| 458 | |
| 459 | #[test] |
| 460 | fn opper_is_a_descriptor_row() { |
| 461 | let row = provider_descriptor("opper").expect("opper"); |
| 462 | assert_eq!(row.id, "opper"); |
| 463 | assert_eq!(row.wire, DescriptorWire::OpenaiCompatible); |
| 464 | assert_eq!(row.base_url, "https://api.opper.ai/v3/compat"); |
| 465 | assert_eq!(row.api_key_env, "OPPER_API_KEY"); |
| 466 | assert_eq!(row.default_model, "claude-sonnet-4-6"); |
| 467 | assert_eq!( |
| 468 | provider_descriptor("opper_ai") |
| 469 | .as_ref() |
| 470 | .map(|row| row.id.as_str()), |
| 471 | Some("opper") |
| 472 | ); |
| 473 | } |
| 474 | |
| 475 | #[test] |
| 476 | fn trustedrouter_is_a_descriptor_row() { |
| 477 | let row = provider_descriptor("trustedrouter").expect("trustedrouter"); |
| 478 | assert_eq!(row.id, "trustedrouter"); |
| 479 | assert_eq!(row.wire, DescriptorWire::OpenaiCompatible); |
| 480 | assert_eq!(row.base_url, "https://api.trustedrouter.com/v1"); |
| 481 | assert_eq!(row.api_key_env, "TRUSTEDROUTER_API_KEY"); |
| 482 | assert_eq!(row.default_model, "deepseek/deepseek-v4-flash"); |
| 483 | assert_eq!(row.discovery, DescriptorDiscovery::PublicModelsEndpoint); |
| 484 | assert_eq!( |
| 485 | provider_descriptor("trusted_router") |
| 486 | .map(|row| row.id) |
| 487 | .as_deref(), |
| 488 | Some("trustedrouter") |
| 489 | ); |
| 490 | } |
| 491 | |
| 492 | #[test] |
| 493 | fn llmtr_is_a_descriptor_row() { |
| 494 | let row = provider_descriptor("llmtr").expect("llmtr"); |
| 495 | assert_eq!(row.id, "llmtr"); |
| 496 | assert_eq!(row.wire, DescriptorWire::OpenaiCompatible); |
| 497 | assert_eq!(row.base_url, "https://llmtr.com/v1"); |
| 498 | assert_eq!(row.api_key_env, "LLMTR_API_KEY"); |
| 499 | assert_eq!(row.default_model, "minimax/minimax-m3.1-flash"); |
| 500 | } |
| 501 | |
| 502 | #[test] |
| 503 | fn prime_intellect_is_a_descriptor_row() { |
| 504 | let row = provider_descriptor("prime").expect("prime"); |
| 505 | assert_eq!(row.id, "prime"); |
| 506 | assert_eq!(row.label, "Prime Intellect"); |
| 507 | assert_eq!(row.wire, DescriptorWire::OpenaiCompatible); |
| 508 | assert_eq!(row.base_url, "https://api.pinference.ai/api/v1"); |
| 509 | assert_eq!(row.api_key_env, "PRIME_API_KEY"); |
| 510 | assert_eq!(row.default_model, "thinkingmachines/inkling-2-small"); |
| 511 | assert_eq!(row.discovery, DescriptorDiscovery::PublicModelsEndpoint); |
| 512 | for alias in [ |
| 513 | "prime-intellect", |
| 514 | "prime_intellect", |
| 515 | "primeintellect", |
| 516 | "prime-inference", |
| 517 | "pinference", |
| 518 | ] { |
| 519 | assert_eq!( |
| 520 | provider_descriptor(alias).map(|item| item.id).as_deref(), |
| 521 | Some("prime"), |
| 522 | "alias {alias}" |
| 523 | ); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | #[test] |
| 528 | fn descriptors_do_not_embed_model_rosters() { |
| 529 | let raw = DESCRIPTORS_JSON; |
| 530 | assert!( |
| 531 | !raw.contains("moonshotai/Kimi-K2.7-Code"), |
| 532 | "do not compile a Baseten/Kimi roster into descriptors" |
| 533 | ); |
| 534 | assert!( |
| 535 | !raw.contains("openai/gpt-oss-120b"), |
| 536 | "do not compile a Groq roster into descriptors" |
| 537 | ); |
| 538 | } |
| 539 | #[test] |
| 540 | fn metadata_preserves_distinct_registry_and_selector_orders() { |
| 541 | use crate::ProviderKind; |
| 542 | let registry: Vec<_> = crate::provider::all_providers() |
| 543 | .iter() |
| 544 | .map(|row| row.kind()) |
| 545 | .collect(); |
| 546 | let index = |rows: &[ProviderKind], kind| rows.iter().position(|row| *row == kind).unwrap(); |
| 547 | assert_eq!(registry.len(), 52); |
| 548 | assert_eq!(ProviderKind::ALL.len(), 46); |
| 549 | assert!( |
| 550 | index(®istry, ProviderKind::Modelscope) < index(®istry, ProviderKind::Together) |
| 551 | ); |
| 552 | assert!( |
| 553 | index(&ProviderKind::ALL, ProviderKind::ModelstudioTokenPlan) |
| 554 | < index(&ProviderKind::ALL, ProviderKind::Modelscope) |
| 555 | ); |
| 556 | assert_eq!(ProviderKind::ALL.last(), Some(&ProviderKind::Custom)); |
| 557 | assert_eq!(ProviderKind::parse("agy"), None); |
| 558 | assert_eq!( |
| 559 | ProviderKind::parse_config_identity("agy"), |
| 560 | Some(ProviderKind::Antigravity) |
| 561 | ); |
| 562 | assert!( |
| 563 | crate::provider::providers_sorted_for_display() |
| 564 | .iter() |
| 565 | .all(|row| row.kind() != ProviderKind::Antigravity) |
| 566 | ); |
| 567 | } |
| 568 | |
| 569 | #[test] |
| 570 | fn grouped_secret_slots_do_not_collapse_config_or_wire_identity() { |
| 571 | use crate::ProviderKind; |
| 572 | use crate::provider::{CredentialAcquisition, WireFormat, WirePolicy}; |
| 573 | let token = ProviderKind::ModelstudioTokenPlan.provider(); |
| 574 | let coding = ProviderKind::ModelstudioCodingPlanAnthropic.provider(); |
| 575 | assert_ne!(token.provider_config_key(), coding.provider_config_key()); |
| 576 | assert_ne!(token.default_base_url(), coding.default_base_url()); |
| 577 | assert_eq!( |
| 578 | ProviderKind::ModelstudioCodingPlanAnthropic.secret_store_slot(), |
| 579 | "modelstudio-token-plan" |
| 580 | ); |
| 581 | assert_eq!( |
| 582 | ProviderKind::SiliconflowCN.secret_store_slot(), |
| 583 | "siliconflow" |
| 584 | ); |
| 585 | assert_eq!( |
| 586 | ProviderKind::parse_config_identity(coding.id()), |
| 587 | Some(ProviderKind::ModelstudioCodingPlanAnthropic) |
| 588 | ); |
| 589 | assert_eq!( |
| 590 | token.wire_policy(), |
| 591 | WirePolicy::Fixed(WireFormat::ChatCompletions) |
| 592 | ); |
| 593 | assert_eq!( |
| 594 | coding.wire_policy(), |
| 595 | WirePolicy::Fixed(WireFormat::AnthropicMessages) |
| 596 | ); |
| 597 | assert_eq!( |
| 598 | ProviderKind::Codewhale.provider().wire_policy(), |
| 599 | WirePolicy::ModelAware |
| 600 | ); |
| 601 | // Preserve the existing public const metadata accessor as well as |
| 602 | // the ordinary trait facade used by runtime consumers. |
| 603 | const CODEX_HELP: crate::provider::CredentialHelp = |
| 604 | crate::provider::credential_help(ProviderKind::OpenaiCodex); |
| 605 | assert_eq!(CODEX_HELP.acquisition, CredentialAcquisition::OAuth); |
| 606 | assert_eq!( |
| 607 | ProviderKind::Sglang |
| 608 | .provider() |
| 609 | .credential_help() |
| 610 | .acquisition, |
| 611 | CredentialAcquisition::LocalOptional |
| 612 | ); |
| 613 | assert_eq!(LEGACY_DEEPSEEK_CN.secret_store_slot, "deepseek"); |
| 614 | assert_eq!(LEGACY_DEEPSEEK_CN.config_key, "deepseek_cn"); |
| 615 | // A named custom table must never obtain built-in authority just by |
| 616 | // reusing its name; compatible-host lookup remains separately scoped. |
| 617 | assert!(provider_descriptor("openai").is_none()); |
| 618 | assert!(provider_descriptor("deepseek").is_none()); |
| 619 | assert_eq!(bundled_provider_descriptors().len(), 20); |
| 620 | let wafer = provider_descriptor("wafer").expect("wafer"); |
| 621 | assert_eq!(wafer.base_url, "https://pass.wafer.ai/v1"); |
| 622 | assert_eq!(wafer.default_model, "GLM-5.3"); |
| 623 | assert_eq!(wafer.api_key_env, "WAFER_API_KEY"); |
| 624 | assert_eq!(wafer.discovery, DescriptorDiscovery::PublicModelsEndpoint); |
| 625 | } |
| 626 | } |
| 627 |