use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::path::Path;
use aimo_core::provider::ProviderMetadata;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProxyConfig {
pub router: RouterConfig,
pub endpoint: EndpointConfig,
pub metadata: ProviderMetadata,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RouterConfig {
pub url: String,
#[serde(rename = "api-key")]
pub api_key: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EndpointConfig {
pub url: String,
#[serde(rename = "api-key")]
pub api_key: String,
}
impl ProxyConfig {
pub fn from_file(path: &Path) -> Result<Self> {
let content = std::fs::read_to_string(path)?;
let config: ProxyConfig = toml::from_str(&content)?;
Ok(config)
}
pub fn node_url(&self) -> String {
self.router
.url
.replace("http://", "ws://")
.replace("https://", "wss://")
}
pub fn secret_key(&self) -> &str {
&self.router.api_key
}
pub fn endpoint_url(&self) -> &str {
&self.endpoint.url
}
pub fn endpoint_api_key(&self) -> &str {
&self.endpoint.api_key
}
}