kandil_code 2.1.1

Intelligent development platform (CLI + TUI + Multi-Agent System) with cross-platform AI model benchmarking, system diagnostics, and advanced development tools
//! AI Provider Factory
//!
//! Creates and manages different AI providers based on configuration

use super::KandilAI;
use crate::utils::config::{Config, SecureKey};
use crate::utils::cost_tracking::CostTracker;
use anyhow::Result;
use std::sync::Arc;

pub struct AIProviderFactory {
    cost_tracker: Arc<CostTracker>,
}

impl AIProviderFactory {
    pub fn new(_config: Config) -> Self {
        Self {
            cost_tracker: Arc::new(CostTracker::new()),
        }
    }

    pub fn create_ai(&self, provider: &str, model: &str) -> Result<KandilAI> {
        // In a more complete implementation, we would retrieve the API key securely
        // from the OS keyring and pass it to the KandilAI constructor if needed
        KandilAI::new(provider.to_string(), model.to_string())
    }

    pub fn create_ai_with_auth(&self, provider: &str, model: &str) -> Result<KandilAI> {
        // This would be used when we need to create an AI instance with authentication
        // For cloud providers, we would load the API key securely here
        if provider != "ollama" {
            // Verify that API key exists in keyring
            let _api_key = SecureKey::load(provider)?;
        }

        KandilAI::new(provider.to_string(), model.to_string())
    }

    pub fn get_cost_tracker(&self) -> Arc<CostTracker> {
        self.cost_tracker.clone()
    }
}