From 9f6cab2436ade26ad563aa458e1c39893de1057d Mon Sep 17 00:00:00 2001 From: Shaun Arman Date: Wed, 8 Apr 2026 20:44:51 -0500 Subject: [PATCH] fix: OpenWebUI provider connection and missing command registrations - Add debug logging to OpenAI provider for troubleshooting - Trim trailing periods from model names - Fix HTTP error handling to capture response details - Register missing AI provider commands (save/load/delete) - Fix authenticateWithWebviewCmd to accept optional projectName parameter --- src-tauri/src/ai/openai.rs | 24 +++++++++++++++++++++--- src-tauri/src/lib.rs | 3 +++ src/lib/tauriCommands.ts | 15 +++++++++++++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/ai/openai.rs b/src-tauri/src/ai/openai.rs index 9fd327a0..809e78cb 100644 --- a/src-tauri/src/ai/openai.rs +++ b/src-tauri/src/ai/openai.rs @@ -82,8 +82,17 @@ impl OpenAiProvider { let api_url = config.api_url.trim_end_matches('/'); let url = format!("{api_url}{endpoint_path}"); + tracing::debug!( + url = %url, + model = %config.model, + max_tokens = ?config.max_tokens, + temperature = ?config.temperature, + "OpenAI API request" + ); + + let model = config.model.trim_end_matches('.'); let mut body = serde_json::json!({ - "model": config.model, + "model": model, "messages": messages, }); @@ -128,11 +137,20 @@ impl OpenAiProvider { .header("Content-Type", "application/json") .json(&body) .send() - .await?; + .await; + + let resp = match resp { + Ok(response) => response, + Err(e) => { + tracing::error!(url = %url, error = %e, "OpenAI API request failed"); + anyhow::bail!("OpenAI API request failed: {e}"); + } + }; if !resp.status().is_success() { let status = resp.status(); - let text = resp.text().await?; + let text = resp.text().await.unwrap_or_else(|_| "unable to read response body".to_string()); + tracing::error!(url = %url, status = %status, response = %text, "OpenAI API error response"); anyhow::bail!("OpenAI API error {status}: {text}"); } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 3f99e8cf..9d6471dd 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -82,6 +82,9 @@ pub fn run() { commands::ai::chat_message, commands::ai::test_provider_connection, commands::ai::list_providers, + commands::system::save_ai_provider, + commands::system::load_ai_providers, + commands::system::delete_ai_provider, // Docs commands::docs::generate_rca, commands::docs::generate_postmortem, diff --git a/src/lib/tauriCommands.ts b/src/lib/tauriCommands.ts index 3a16e5dc..3c047b5b 100644 --- a/src/lib/tauriCommands.ts +++ b/src/lib/tauriCommands.ts @@ -443,8 +443,8 @@ export interface IntegrationConfig { space_key?: string; } -export const authenticateWithWebviewCmd = (service: string, baseUrl: string) => - invoke("authenticate_with_webview", { service, baseUrl }); +export const authenticateWithWebviewCmd = (service: string, baseUrl: string, projectName?: string) => + invoke("authenticate_with_webview", { service, baseUrl, projectName }); export const extractCookiesFromWebviewCmd = (service: string, webviewId: string) => invoke("extract_cookies_from_webview", { service, webviewId }); @@ -462,3 +462,14 @@ export const getIntegrationConfigCmd = (service: string) => export const getAllIntegrationConfigsCmd = () => invoke("get_all_integration_configs"); + +// ─── AI Provider Configuration ──────────────────────────────────────────────── + +export const saveAiProviderCmd = (config: ProviderConfig) => + invoke("save_ai_provider", { config }); + +export const loadAiProvidersCmd = () => + invoke("load_ai_providers"); + +export const deleteAiProviderCmd = (name: string) => + invoke("delete_ai_provider", { name });