From eac510bb5e9a6efde7bcfa5afaeb071abee69c31 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Mon, 15 Dec 2025 09:43:17 +0000 Subject: [PATCH] fix(ai): allow enabling AI when any provider is configured The enable validation was using the legacy single-provider model which checked settings.Provider and settings.APIKey. Users configuring Ollama via the new multi-provider UI (setting ollama_base_url) couldn't enable AI because settings.Provider defaulted to "anthropic" which required an API key. Now checks GetConfiguredProviders() first - if any provider is configured (Anthropic, OpenAI, DeepSeek, or Ollama), AI can be enabled. Related to #847 --- internal/api/ai_handlers.go | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/internal/api/ai_handlers.go b/internal/api/ai_handlers.go index aa8d85d..f9c3663 100644 --- a/internal/api/ai_handlers.go +++ b/internal/api/ai_handlers.go @@ -360,20 +360,28 @@ func (h *AISettingsHandler) HandleUpdateAISettings(w http.ResponseWriter, r *htt } if req.Enabled != nil { - // Only allow enabling if properly configured + // Only allow enabling if at least one provider is configured if *req.Enabled { - switch settings.Provider { - case config.AIProviderAnthropic, config.AIProviderOpenAI, config.AIProviderDeepSeek: - if settings.APIKey == "" { - http.Error(w, "Cannot enable AI: API key is required for "+settings.Provider, http.StatusBadRequest) + configuredProviders := settings.GetConfiguredProviders() + if len(configuredProviders) == 0 { + // Fall back to legacy validation for backwards compatibility + switch settings.Provider { + case config.AIProviderAnthropic, config.AIProviderOpenAI, config.AIProviderDeepSeek: + if settings.APIKey == "" { + http.Error(w, "Cannot enable AI: configure at least one AI provider first", http.StatusBadRequest) + return + } + case config.AIProviderOllama: + // Ollama doesn't need API key, but needs base URL (or will use default) + if settings.BaseURL == "" { + settings.BaseURL = config.DefaultOllamaBaseURL + } + default: + http.Error(w, "Cannot enable AI: configure at least one AI provider first", http.StatusBadRequest) return } - case config.AIProviderOllama: - // Ollama doesn't need API key, but needs base URL (or will use default) - if settings.BaseURL == "" { - settings.BaseURL = config.DefaultOllamaBaseURL - } } + // If we have configured providers, we're good to enable } settings.Enabled = *req.Enabled }