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) <noreply@anthropic.com>
This commit is contained in:
Zero Liu 2026-05-04 15:48:45 -07:00 committed by GitHub
parent 95d23b2387
commit 37bea9a65c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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,