#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AuthType {
Bearer,
ApiKeyHeader(&'static str),
None,
}
#[derive(Debug, Clone)]
pub struct ProviderDefinition {
pub name: &'static str,
pub display_name: &'static str,
pub base_url: &'static str,
pub auth_env_var: &'static str,
pub auth_type: AuthType,
pub skip_api_key: bool,
pub model_prefix: Option<&'static str>,
}
impl ProviderDefinition {
pub fn to_openai_like_config(
&self,
api_key: Option<&str>,
base_url_override: Option<&str>,
) -> crate::core::providers::openai_like::OpenAILikeConfig {
use crate::core::providers::openai_like::OpenAILikeConfig;
let effective_base = base_url_override.unwrap_or(self.base_url);
let mut config = if let Some(key) = api_key {
OpenAILikeConfig::with_api_key(effective_base, key)
} else {
OpenAILikeConfig::new(effective_base)
};
config.provider_name = self.name.to_string();
config.skip_api_key = self.skip_api_key;
if let Some(prefix) = self.model_prefix {
config.model_prefix = Some(prefix.to_string());
}
match self.auth_type {
AuthType::ApiKeyHeader(header_name) => {
if let Some(key) = api_key {
config
.custom_headers
.insert(header_name.to_string(), key.to_string());
config.base.api_key = None;
}
}
AuthType::None => {
config.skip_api_key = true;
}
AuthType::Bearer => {
}
}
config
}
pub fn resolve_api_key(&self, explicit: Option<&str>) -> Option<String> {
explicit
.map(|s| s.to_string())
.or_else(|| std::env::var(self.auth_env_var).ok())
}
}