aimo-cli 0.4.0

AiMo Network client CLI
//! **DEPRECATED**
//!
//! All proxy modules under `aimo-cli` will be replaced by `aimo-proxy`

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 {
    /// Load proxy configuration from a TOML file with environment variable overrides
    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)
    }

    /// Get the node URL, converting from HTTP to WebSocket format if needed
    pub fn node_url(&self) -> String {
        self.router
            .url
            .replace("http://", "ws://")
            .replace("https://", "wss://")
    }

    /// Get the router API key (secret key)
    pub fn secret_key(&self) -> &str {
        &self.router.api_key
    }

    /// Get the endpoint URL
    pub fn endpoint_url(&self) -> &str {
        &self.endpoint.url
    }

    /// Get the endpoint API key
    pub fn endpoint_api_key(&self) -> &str {
        &self.endpoint.api_key
    }
}