From 37bea9a65c9fea9002fef839365e13bd331ce270 Mon Sep 17 00:00:00 2001 From: Zero Liu Date: Mon, 4 May 2026 15:48:45 -0700 Subject: [PATCH] fix(ollama): route through safeFetch when enableCors is set (#2382) Other OpenAI-compatible providers (LM Studio, OpenAI-format, SiliconFlow, etc.) already pass a fetch override so requests can go through Obsidian's requestUrl API. The Ollama branch was missing this wiring, so toggling "Enable CORS" on an Ollama model had no effect and mobile (WKWebView) requests to http:// Ollama hosts failed with "Load failed" due to CORS / mixed-content blocking. Co-authored-by: Claude Opus 4.7 (1M context) --- src/LLMProviders/chatModelManager.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/LLMProviders/chatModelManager.ts b/src/LLMProviders/chatModelManager.ts index 677af5a2..c5c9dee3 100644 --- a/src/LLMProviders/chatModelManager.ts +++ b/src/LLMProviders/chatModelManager.ts @@ -344,6 +344,9 @@ export default class ChatModelManager { headers: { Authorization: `Bearer ${await getDecryptedKey(customModel.apiKey || "default-key")}`, }, + // Route through Obsidian's requestUrl (safeFetch) to bypass CORS / mixed-content + // restrictions — required on mobile (WKWebView) when calling http:// Ollama hosts. + fetch: customModel.enableCors ? safeFetch : undefined, // Enable thinking for models with REASONING capability (e.g., qwen3, deepseek-r1) // Thinking content goes to additional_kwargs.reasoning_content think: customModel.capabilities?.includes(ModelCapability.REASONING) ?? false,