steer_core/config/
provider.rs

1use serde::{Deserialize, Serialize};
2use std::fmt;
3use url::Url;
4
5// Re-export enums from toml_types
6pub use crate::config::toml_types::{ApiFormat, AuthScheme};
7
8/// Identifier for a provider (built-in or custom).
9#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
10#[serde(transparent)]
11pub struct ProviderId(pub String);
12
13impl ProviderId {
14    pub fn as_str(&self) -> &str {
15        &self.0
16    }
17}
18
19impl fmt::Display for ProviderId {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        write!(f, "{}", self.0)
22    }
23}
24
25impl From<&'static str> for ProviderId {
26    fn from(s: &'static str) -> Self {
27        ProviderId(s.to_string())
28    }
29}
30
31// Generated provider constants
32include!(concat!(env!("OUT_DIR"), "/generated_provider_ids.rs"));
33
34impl From<crate::config::toml_types::ProviderData> for ProviderConfig {
35    fn from(data: crate::config::toml_types::ProviderData) -> Self {
36        ProviderConfig {
37            id: ProviderId(data.id),
38            name: data.name,
39            api_format: data.api_format,
40            auth_schemes: data.auth_schemes,
41            base_url: data.base_url.and_then(|s| s.parse().ok()),
42        }
43    }
44}
45
46impl ProviderId {
47    /// Returns the storage key used for credential persistence.
48    /// This provides a single source of truth for storage keys.
49    pub fn storage_key(&self) -> String {
50        self.0.clone()
51    }
52
53    /// Returns the default display name for this provider ID.
54    /// For UI, prefer using ProviderRegistry config.name; this falls back to the raw ID.
55    pub fn default_display_name(&self) -> String {
56        self.0.clone()
57    }
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
61pub struct ProviderConfig {
62    pub id: ProviderId,
63    pub name: String,
64    pub api_format: ApiFormat,
65    pub auth_schemes: Vec<AuthScheme>,
66    /// Optional override for the HTTP base URL.
67    #[serde(default, skip_serializing_if = "Option::is_none")]
68    pub base_url: Option<Url>,
69}
70
71#[derive(Debug, Clone)]
72pub struct ProviderModel {
73    pub provider: ProviderId,
74    pub model_id: String,
75    pub name: String,
76}