use crate::config::LLMProviderConfig;
use crate::providers::ProviderRuntimeConfig;

#[derive(Debug, Clone)]
pub struct AgentRuntimeConfig {
    pub provider: ProviderRuntimeConfig,
    pub context_window_tokens: usize,
    pub context_summary_char_budget: usize,
    pub max_tool_iterations: usize,
    pub tool_result_max_chars: usize,
    pub context_tool_result_trim_chars: usize,
    /// 图片上下文限制配置
    pub max_images_in_context: usize,
    pub max_image_age_rounds: usize,
}

impl From<LLMProviderConfig> for AgentRuntimeConfig {
    fn from(config: LLMProviderConfig) -> Self {
        let context_window_tokens = config.context_window_tokens();
        let context_summary_char_budget = config.context_summary_char_budget();

        Self {
            provider: ProviderRuntimeConfig {
                provider_type: config.provider_type,
                name: config.name,
                base_url: config.base_url,
                api_key: config.api_key,
                extra_headers: config.extra_headers,
                llm_timeout_secs: config.llm_timeout_secs,
                model_id: config.model_id,
                temperature: config.temperature,
                max_tokens: config.max_tokens,
                model_extra: config.model_extra,
            },
            context_window_tokens,
            context_summary_char_budget,
            max_tool_iterations: config.max_tool_iterations,
            tool_result_max_chars: config.tool_result_max_chars,
            context_tool_result_trim_chars: config.context_tool_result_trim_chars,
            max_images_in_context: config.max_images_in_context,
            max_image_age_rounds: config.max_image_age_rounds,
        }
    }
}
