From 87ccbe19ea02934cd125161792b66522e459c511 Mon Sep 17 00:00:00 2001 From: "randomizedcoder dave.seddon.ca@gmail.com" Date: Sun, 25 Jan 2026 16:01:42 -0800 Subject: [PATCH] fix(ollama): pass baseUrl from UI when testing connection --- packages/types/src/vscode-extension-host.ts | 2 ++ src/core/webview/webviewMessageHandler.ts | 6 +++++- webview-ui/src/components/settings/providers/Ollama.tsx | 8 ++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/types/src/vscode-extension-host.ts b/packages/types/src/vscode-extension-host.ts index 510aa2e403..fb3ec1fd21 100644 --- a/packages/types/src/vscode-extension-host.ts +++ b/packages/types/src/vscode-extension-host.ts @@ -582,6 +582,8 @@ export interface WebviewMessage { // eslint-disable-next-line @typescript-eslint/no-explicit-any settings?: any url?: string // For openExternal + ollamaBaseUrl?: string // For testOllamaConnection - allows passing current value from UI + ollamaApiKey?: string // For testOllamaConnection - allows passing current value from UI mpItem?: MarketplaceItem mpInstallOptions?: InstallMarketplaceItemOptions // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/src/core/webview/webviewMessageHandler.ts b/src/core/webview/webviewMessageHandler.ts index 1f2f1d1cab..52dc8304fd 100644 --- a/src/core/webview/webviewMessageHandler.ts +++ b/src/core/webview/webviewMessageHandler.ts @@ -1030,8 +1030,12 @@ export const webviewMessageHandler = async ( case "testOllamaConnection": { const { testOllamaConnection } = await import("../../api/providers/fetchers/ollama") const { apiConfiguration: ollamaApiConfig } = await provider.getState() + // Use the baseUrl and apiKey from the message if provided (current UI values), + // otherwise fall back to saved state + const baseUrl = message.ollamaBaseUrl ?? ollamaApiConfig.ollamaBaseUrl + const apiKey = message.ollamaApiKey ?? ollamaApiConfig.ollamaApiKey try { - const result = await testOllamaConnection(ollamaApiConfig.ollamaBaseUrl, ollamaApiConfig.ollamaApiKey, { + const result = await testOllamaConnection(baseUrl, apiKey, { timeout: ollamaApiConfig.ollamaModelDiscoveryTimeout ?? 10000, enableLogging: ollamaApiConfig.ollamaEnableLogging ?? false, }) diff --git a/webview-ui/src/components/settings/providers/Ollama.tsx b/webview-ui/src/components/settings/providers/Ollama.tsx index 2f5c4feb1c..ca2dfc328a 100644 --- a/webview-ui/src/components/settings/providers/Ollama.tsx +++ b/webview-ui/src/components/settings/providers/Ollama.tsx @@ -117,8 +117,12 @@ export const Ollama = ({ apiConfiguration, setApiConfigurationField }: OllamaPro const handleTestConnection = useCallback(() => { setTestingConnection(true) setTestResult(null) - vscode.postMessage({ type: "testOllamaConnection" }) - }, []) + vscode.postMessage({ + type: "testOllamaConnection", + ollamaBaseUrl: apiConfiguration?.ollamaBaseUrl || "", + ollamaApiKey: apiConfiguration?.ollamaApiKey || "", + }) + }, [apiConfiguration?.ollamaBaseUrl, apiConfiguration?.ollamaApiKey]) const handleRefreshModels = useCallback(() => { setRefreshingModels(true)