Skip to main content

steer_core/config/
provider.rs

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