velocia 0.3.2

velocia – production-ready AI agent framework using ADK-Rust, A2A protocol, and AWS DynamoDB
use std::collections::HashMap;

/// Return `"http"` when `IS_LOCAL=true/1/yes`, otherwise `"https"`.
pub fn get_protocol() -> &'static str {
    let is_local = std::env::var("IS_LOCAL")
        .unwrap_or_default()
        .to_lowercase();
    if matches!(is_local.as_str(), "1" | "true" | "yes") {
        "http"
    } else {
        "https"
    }
}

/// Expand a map of `{ env_key_name: env_var_name }` into concrete
/// `{ key: value }` pairs.  Missing variables are silently dropped.
pub fn expand_env_vars(env: Option<&HashMap<String, String>>) -> HashMap<String, String> {
    let Some(map) = env else { return HashMap::new() };
    map.iter()
        .filter_map(|(k, var_name)| {
            std::env::var(var_name).ok().map(|v| (k.clone(), v))
        })
        .collect()
}

/// Load a YAML config file, returning the parsed `serde_yaml::Value`.
pub fn load_config(path: &str) -> crate::error::Result<serde_yaml::Value> {
    let content = std::fs::read_to_string(path)
        .map_err(|e| crate::error::AgentKitError::ConfigIo {
            path: path.to_string(),
            source: e,
        })?;
    let value = serde_yaml::from_str(&content)?;
    Ok(value)
}