LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。
TypeScript
release: v0.4.3 — fix Ollama LAN connection (always send Origin: http://localhost)
nash_su1434e080828b
diff --git a/package.json b/package.jsonindex 91cc11be..b87f3b69 100644--- a/package.json+++ b/package.json@@ -1,7 +1,7 @@{"name": "llm-wiki","private": true,- "version": "0.4.2",+ "version": "0.4.3","type": "module","scripts": {"dev": "vite",diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lockindex 459ad9b8..e1a583c7 100644--- a/src-tauri/Cargo.lock+++ b/src-tauri/Cargo.lock@@ -4420,7 +4420,7 @@ checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092"[[package]]name = "llm-wiki"-version = "0.4.2"+version = "0.4.3"dependencies = ["arrow-array","arrow-schema",diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.tomlindex 1a3c9dd4..e101312e 100644--- a/src-tauri/Cargo.toml+++ b/src-tauri/Cargo.toml@@ -1,6 +1,6 @@[package]name = "llm-wiki"-version = "0.4.2"+version = "0.4.3"description = "LLM Wiki - A personal knowledge base for LLM concepts"authors = []edition = "2021"diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.jsonindex 4a5c9f89..6a6c3e51 100644--- a/src-tauri/tauri.conf.json+++ b/src-tauri/tauri.conf.json@@ -1,7 +1,7 @@{"$schema": "https://schema.tauri.app/config/2","productName": "LLM Wiki",- "version": "0.4.2",+ "version": "0.4.3","identifier": "com.llmwiki.app","build": {"beforeDevCommand": "npm run dev",diff --git a/src/lib/__tests__/llm-providers.test.ts b/src/lib/__tests__/llm-providers.test.tsindex 4195c4a2..0ea8dbda 100644--- a/src/lib/__tests__/llm-providers.test.ts+++ b/src/lib/__tests__/llm-providers.test.ts@@ -324,19 +324,34 @@ describe("Sampling override translation across wires", () => {// ── Origin header for local LLM providers (Ollama + custom OpenAI) ──//-// Pinned by a real packet capture from a Windows user (v0.3.11) where-// plugin-http auto-injected `origin: http://tauri.localhost`,-// triggering Ollama 403 because that origin isn't in the default-// `OLLAMA_ORIGINS` allowlist. Setting Origin = same-origin makes-// Ollama always trust the request.+// History pinned by two user reports://-// Plugin-http v2.5.x respects user-set headers (override behavior-// confirmed by reading dist-js/index.js line 71-75), and the-// `unsafe-headers` Cargo feature ensures Rust-side reqwest forwards-// it. So this header surfacing here = bytes on the wire.+// v0.3.11: a Windows user's packet capture showed plugin-http's+// auto-injected origin was `http://tauri.localhost` (NOT+// `tauri://localhost` like macOS/Linux), triggering Ollama 403+// because the default OLLAMA_ORIGINS list has `tauri://*` but+// not `http://tauri.localhost`. We started overriding the header.+//+// v0.4.2: a user with Ollama on a LAN box at 192.168.x reported+// "error sending request" (reqwest network error). Diagnosis:+// our v0.3.11 fix set Origin to the request URL's own host+// (`http://192.168.0.20:11434`), which IS NOT in the default+// OLLAMA_ORIGINS list either. Older Ollama versions reject same-+// origin literally if it's not on the allowlist; some close the+// TCP connection rather than 403, which surfaces as a generic+// reqwest error.+//+// Current strategy: ALWAYS send `Origin: http://localhost`+// regardless of where the actual server is. Ollama's default+// OLLAMA_ORIGINS unconditionally includes `http://localhost` (and+// the related `127.0.0.1` / port-wildcard variants); LM Studio /+// llama.cpp / vLLM don't check Origin at all. The header is purely+// a CORS-allowlist signal — semantically lying about "where this+// request came from" is fine because the server uses API keys (or+// no auth), not origin, for actual permission checks.describe("Origin header — local LLM CORS workaround", () => {- it("Ollama provider sets Origin to the request's own host (localhost)", () => {+ it("Ollama provider sends Origin: http://localhost when server is on localhost", () => {const cfg = getProviderConfig({provider: "ollama",apiKey: "",@@ -345,10 +360,15 @@ describe("Origin header — local LLM CORS workaround", () => {customEndpoint: "",maxContextSize: 8192,})- expect(cfg.headers["Origin"]).toBe("http://localhost:11434")+ expect(cfg.headers["Origin"]).toBe("http://localhost")})- it("Ollama provider Origin reflects remote LAN deployment (not localhost)", () => {+ it("Ollama provider sends Origin: http://localhost EVEN WHEN server is on a remote LAN IP", () => {+ // This is the v0.4.2 user-reported bug: previously the Origin+ // mirrored the request URL's host (`http://192.168.1.50:11434`),+ // which Ollama's default OLLAMA_ORIGINS doesn't include →+ // request rejected. Forcing localhost makes any LAN deployment+ // pass Ollama's CORS check.const cfg = getProviderConfig({provider: "ollama",apiKey: "",@@ -357,16 +377,10 @@ describe("Origin header — local LLM CORS workaround", () => {customEndpoint: "",maxContextSize: 8192,})- expect(cfg.headers["Origin"]).toBe("http://192.168.1.50:11434")+ expect(cfg.headers["Origin"]).toBe("http://localhost")})- it("Ollama provider strips trailing /v1 before deriving Origin", () => {- // User pasted "http://localhost:11434/v1" as their Ollama URL. The- // URL the provider builds will be "http://localhost:11434/v1/chat/completions",- // so Origin must still be "http://localhost:11434" (URL.origin- // never includes a path anyway, but pinning this catches a- // regression where someone derives Origin from the full URL string- // by hand).+ it("Ollama provider Origin doesn't change with /v1 in the URL", () => {const cfg = getProviderConfig({provider: "ollama",apiKey: "",@@ -375,10 +389,14 @@ describe("Origin header — local LLM CORS workaround", () => {customEndpoint: "",maxContextSize: 8192,})- expect(cfg.headers["Origin"]).toBe("http://localhost:11434")+ expect(cfg.headers["Origin"]).toBe("http://localhost")})- it("custom OpenAI-compat endpoint also gets a same-origin Origin (LM Studio / llama.cpp / vLLM)", () => {+ it("custom OpenAI-compat endpoint gets the same Origin override (LM Studio / llama.cpp / vLLM)", () => {+ // For these servers Origin is ignored entirely — but we send+ // the value anyway so behavior is uniform across local-LLM+ // providers and the rare hardened deployment that does check+ // CORS still works.const cfg = getProviderConfig({provider: "custom",apiKey: "",@@ -388,7 +406,7 @@ describe("Origin header — local LLM CORS workaround", () => {maxContextSize: 8192,apiMode: "chat_completions",} as RealLlmConfig)- expect(cfg.headers["Origin"]).toBe("http://127.0.0.1:1234")+ expect(cfg.headers["Origin"]).toBe("http://localhost")})it("commercial provider (OpenAI) does NOT get an explicit Origin override", () => {@@ -406,9 +424,11 @@ describe("Origin header — local LLM CORS workaround", () => {expect(cfg.headers["Origin"]).toBeUndefined()})- it("malformed ollamaUrl falls back gracefully (no Origin header) instead of crashing", () => {- // Settings UI normalizes URLs but a stale config from an older- // version could carry rubbish. Origin parsing must not throw.+ it("Ollama provider always sets Origin even when the configured URL is malformed", () => {+ // The fixed-string Origin doesn't depend on URL parsing, so a+ // mistyped config can't strip the header. (The request itself+ // will fail elsewhere because the URL is bad — that's not this+ // helper's concern.)const cfg = getProviderConfig({provider: "ollama",apiKey: "",@@ -417,9 +437,7 @@ describe("Origin header — local LLM CORS workaround", () => {customEndpoint: "",maxContextSize: 8192,})- expect(cfg.headers["Origin"]).toBeUndefined()- // The URL itself will obviously be broken — but the provider- // builder shouldn't have thrown.+ expect(cfg.headers["Origin"]).toBe("http://localhost")expect(typeof cfg.url).toBe("string")})})diff --git a/src/lib/llm-providers.ts b/src/lib/llm-providers.tsindex d6a06bb7..5bc2c04e 100644--- a/src/lib/llm-providers.ts+++ b/src/lib/llm-providers.ts@@ -64,38 +64,52 @@ const JSON_CONTENT_TYPE = "application/json"* Origin header for local-LLM endpoints (Ollama, LM Studio, llama.cpp* server, LocalAI, vLLM, …).*- * Why we set this explicitly:- * `@tauri-apps/plugin-http` v2.5.x auto-injects the webview's- * own Origin (`tauri://localhost` on macOS/Linux,- * `http://tauri.localhost` on Windows). Ollama's default- * `OLLAMA_ORIGINS` allowlist accepts `tauri://*` since ~0.1.30- * but NOT `http://tauri.localhost` — so Windows users hit 403- * even when everything is configured correctly. A user packet- * capture (v0.3.11) confirmed the request carrying- * `origin: http://tauri.localhost`.+ * Always sets `Origin: http://localhost` regardless of where the+ * actual server is. Two interlocking reasons:*- * Setting Origin to the request's own host = same-origin, which- * Ollama always trusts regardless of `OLLAMA_ORIGINS` value or- * Ollama version.+ * 1. We MUST override the platform default. `@tauri-apps/plugin-+ * http` v2.5.x auto-injects the webview's own origin+ * (`tauri://localhost` on macOS/Linux,+ * `http://tauri.localhost` on Windows). Ollama's default+ * `OLLAMA_ORIGINS` allowlist accepts `tauri://*` since ~0.1.30+ * but NOT `http://tauri.localhost` — without our override,+ * Windows users hit 403. (User packet capture v0.3.11.)*- * Why this works at all:- * plugin-http's JS shim respects user-set headers (see- * `node_modules/@tauri-apps/plugin-http/dist-js/index.js`,- * the loop after `new Request(input, init)` only fills- * browser-default headers when the user did NOT already set- * them). On the Rust side, the `unsafe-headers` feature flag- * in `src-tauri/Cargo.toml` lets reqwest forward Origin- * without stripping it. End-to-end this means our value wins.+ * 2. We can't override with the request's REAL origin because+ * that breaks cross-machine LAN setups. A user pointing at+ * `http://192.168.0.20:11434/v1` would get `Origin:+ * http://192.168.0.20:11434`, which is NOT in Ollama's+ * default OLLAMA_ORIGINS — Ollama then 403s or RST-closes+ * the connection, surfacing as a generic "error sending+ * request" reqwest error. The earlier code claimed Ollama+ * did same-origin bypass; it does not. Reported by user+ * v0.4.2.*- * If `url` can't be parsed (mis-typed config), we return {} —- * better to send no override than to crash building the request.+ * `http://localhost` is unconditionally in Ollama's default+ * OLLAMA_ORIGINS list (`http://localhost`, `http://localhost:*`,+ * `http://127.0.0.1*`, etc.). LM Studio / llama.cpp / vLLM /+ * LocalAI don't check Origin at all, so the value is ignored+ * there. The header is purely a CORS-allowlist signal — semantic+ * "where this request came from" is meaningless here because the+ * server uses API keys (or no auth), not origin, for actual+ * permission checks.+ *+ * Users who actively tightened OLLAMA_ORIGINS to remove localhost+ * (rare) need to re-add `http://localhost` to their server config;+ * no client-side fix can satisfy a hand-locked allowlist that+ * specifically excludes the one origin every other LLM client+ * also relies on.+ *+ * Why this overrides at all: plugin-http's JS shim respects user-+ * set headers (see `node_modules/@tauri-apps/plugin-http/dist-js/+ * index.js` — the loop after `new Request(input, init)` only fills+ * browser-default headers when the user did NOT already set them).+ * Rust-side, the `unsafe-headers` feature flag in+ * `src-tauri/Cargo.toml` lets reqwest forward Origin without+ * stripping it. End-to-end our value wins.*/-function sameOriginHeader(url: string): Record<string, string> {- try {- return { Origin: new URL(url).origin }- } catch {- return {}- }+function localLlmOriginHeader(): Record<string, string> {+ return { Origin: "http://localhost" }}function parseOpenAiLine(line: string): string | null {@@ -474,7 +488,7 @@ export function getProviderConfig(config: LlmConfig): ProviderConfig {url: `${ollamaBase}/v1/chat/completions`,headers: {"Content-Type": JSON_CONTENT_TYPE,- ...sameOriginHeader(ollamaBase),+ ...localLlmOriginHeader(),},buildBody: (messages, overrides) => {const body: Record<string, unknown> = {@@ -556,7 +570,7 @@ export function getProviderConfig(config: LlmConfig): ProviderConfig {// Local OpenAI-compatible servers (LM Studio, llama.cpp,// vLLM, LocalAI) often share Ollama's CORS sensitivity.// Same rationale as the `ollama` branch above.- ...sameOriginHeader(base),+ ...localLlmOriginHeader(),},buildBody: (messages, overrides) => ({...buildOpenAiBody(messages, overrides),