diff --git a/src-tauri/src/commands/process.rs b/src-tauri/src/commands/process.rs index 176b6b7..ab179c8 100644 --- a/src-tauri/src/commands/process.rs +++ b/src-tauri/src/commands/process.rs @@ -114,3 +114,56 @@ pub async fn get_node_version() -> Result, String> { }, } } + +/// Check if Ollama is installed +#[command] +pub async fn check_ollama_installed() -> Result { + info!("[Ollama Check] Checking if Ollama is installed..."); + let installed = shell::command_exists("ollama"); + info!("[Ollama Check] Ollama installation status: {}", if installed { "installed" } else { "not installed" }); + Ok(installed) +} + +/// Get installed Ollama models +#[command] +pub async fn get_ollama_models() -> Result, String> { + info!("[Ollama Check] Getting installed Ollama models..."); + match shell::run_command_output("ollama", &["list"]) { + Ok(output) => { + let mut models = Vec::new(); + // Output format: NAME ID SIZE MODIFIED + // qwen3.5:9b abcd1234ef 5.5GB 3 days ago + for (i, line) in output.lines().enumerate() { + if i == 0 || line.trim().is_empty() { + continue; // Skip header and empty lines + } + if let Some(name) = line.split_whitespace().next() { + models.push(name.to_string()); + } + } + info!("[Ollama Check] Found {} installed models", models.len()); + Ok(models) + }, + Err(e) => { + debug!("[Ollama Check] Failed to get Ollama models: {}", e); + Err(e) + }, + } +} + +/// Install / pull an Ollama model +#[command] +pub async fn install_ollama_model(model_name: String) -> Result { + info!("[Ollama Check] Installing Ollama model: {}", model_name); + // Use `ollama pull` instead of `ollama run` so it doesn't stay interactive. + match shell::run_command_output("ollama", &["pull", &model_name]) { + Ok(_) => { + info!("[Ollama Check] Successfully installed model: {}", model_name); + Ok(format!("Successfully installed {}", model_name)) + }, + Err(e) => { + debug!("[Ollama Check] Failed to install Ollama model {}: {}", model_name, e); + Err(e) + }, + } +} diff --git a/src-tauri/src/models/config.rs b/src-tauri/src/models/config.rs index 323329b..2379540 100644 --- a/src-tauri/src/models/config.rs +++ b/src-tauri/src/models/config.rs @@ -214,6 +214,8 @@ pub struct OfficialProvider { pub suggested_models: Vec, /// Whether API Key is required pub requires_api_key: bool, + /// Default API Key + pub default_api_key: Option, /// Documentation URL pub docs_url: Option, }