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)