pub mod catalog;
pub mod manifest;
pub use catalog::{refresh_models_sync, resolve_models_sync};
pub use manifest::{ManifestAuth, ProviderManifest};
use serde::Serialize;
use std::collections::HashMap;
pub struct ProviderRegistry;
impl ProviderRegistry {
pub fn providers() -> &'static Vec<ProviderManifest> {
manifest::load_manifests()
}
pub fn find(id: &str) -> Option<ProviderManifest> {
let id_lower = id.to_lowercase();
Self::providers()
.iter()
.find(|p| p.id.to_lowercase() == id_lower)
.cloned()
}
}
#[derive(Debug, Serialize)]
pub struct PiAuthJson(HashMap<String, ProviderAuth>);
#[derive(Debug, Serialize)]
struct ProviderAuth {
#[serde(rename = "type")]
auth_type: String,
key: String,
}
impl PiAuthJson {
pub fn new(provider_keys: &[(String, String)]) -> Self {
let map = provider_keys
.iter()
.map(|(provider, key)| {
(
provider.clone(),
ProviderAuth {
auth_type: "api_key".to_string(),
key: key.clone(),
},
)
})
.collect();
PiAuthJson(map)
}
pub fn to_json_string(&self) -> Result<String, serde_json::Error> {
serde_json::to_string_pretty(&self)
}
}