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
fix: add origin override for local embeddings
nash_sueaf32f20783b
diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.jsonindex 53812fc1..84eaab99 100644--- a/src-tauri/tauri.conf.json+++ b/src-tauri/tauri.conf.json@@ -36,6 +36,7 @@"icons/32x32.png","icons/128x128.png","icons/[email protected]",+ "icons/icon.png","icons/icon.icns","icons/icon.ico"]diff --git a/src/lib/embedding.test.ts b/src/lib/embedding.test.tsindex 3b591b9f..44fc6e46 100644--- a/src/lib/embedding.test.ts+++ b/src/lib/embedding.test.ts@@ -241,9 +241,11 @@ describe("fetchEmbedding — provider wire formats", () => {expect(out).toEqual([0.1, 0.2])const [url, opts] = mockHttpFetch.mock.calls[0]+ const headers = opts?.headers as Record<string, string>expect(url).toBe("https://api.openai.com/v1/embeddings")- expect((opts?.headers as Record<string, string>).Authorization).toBe("Bearer sk-test")- expect((opts?.headers as Record<string, string>)["x-goog-api-key"]).toBeUndefined()+ expect(headers.Authorization).toBe("Bearer sk-test")+ expect(headers.Origin).toBeUndefined()+ expect(headers["x-goog-api-key"]).toBeUndefined()expect(JSON.parse(String(opts?.body))).toEqual({model: "text-embedding-3-small",input: "hi",@@ -262,15 +264,33 @@ describe("fetchEmbedding — provider wire formats", () => {expect(out).toEqual([0.3, 0.4])const [url, opts] = mockHttpFetch.mock.calls[0]+ const headers = opts?.headers as Record<string, string>expect(url).toBe("http://127.0.0.1:1234/v1/embeddings")- expect((opts?.headers as Record<string, string>).Authorization).toBeUndefined()- expect((opts?.headers as Record<string, string>)["x-goog-api-key"]).toBeUndefined()+ expect(headers.Authorization).toBeUndefined()+ expect(headers.Origin).toBe("http://localhost")+ expect(headers["x-goog-api-key"]).toBeUndefined()expect(JSON.parse(String(opts?.body))).toEqual({model: "text-embedding-qwen3-embedding-0.6b",input: "hi",})})+ it("sends Origin override for LAN embedding endpoints", async () => {+ mockHttpFetch.mockResolvedValueOnce(okResponse([0.3, 0.4]))++ const out = await fetchEmbedding("hi", {+ enabled: true,+ endpoint: "http://192.168.1.20:11434/v1/embeddings",+ apiKey: "",+ model: "nomic-embed-text",+ })++ expect(out).toEqual([0.3, 0.4])+ const [, opts] = mockHttpFetch.mock.calls[0]+ const headers = opts?.headers as Record<string, string>+ expect(headers.Origin).toBe("http://localhost")+ })+it("sends safe custom embedding headers on OpenAI-compatible endpoints", async () => {mockHttpFetch.mockResolvedValueOnce(okResponse([0.5, 0.6]))@@ -287,6 +307,7 @@ describe("fetchEmbedding — provider wire formats", () => {"Content-Type": "text/plain",Host: "evil.example.com","Content-Length": "999",+ Origin: "http://tauri.localhost","x-goog-api-key": "wrong-google-key",},})@@ -297,6 +318,7 @@ describe("fetchEmbedding — provider wire formats", () => {expect(headers["X-Model-Provider-Id"]).toBe("siliconflow")expect(headers.Authorization).toBe("Bearer sk-test")expect(headers["Content-Type"]).toBe("application/json")+ expect(headers.Origin).toBeUndefined()expect(headers.Host).toBeUndefined()expect(headers["Content-Length"]).toBeUndefined()expect(headers["x-goog-api-key"]).toBeUndefined()@@ -508,6 +530,7 @@ describe("fetchEmbedding — provider wire formats", () => {const [, opts] = mockHttpFetch.mock.calls[0]const headers = opts?.headers as Record<string, string>expect(headers["x-goog-api-key"]).toBe("real-google-key")+ expect(headers.Origin).toBeUndefined()expect(headers["X-Trace-Id"]).toBe("trace-1")})diff --git a/src/lib/embedding.ts b/src/lib/embedding.tsindex df8a82f8..2ac26ba8 100644--- a/src/lib/embedding.ts+++ b/src/lib/embedding.ts@@ -27,12 +27,14 @@ import type { FileNode } from "@/types/wiki"import { normalizePath } from "@/lib/path-utils"import { getHttpFetch, isFetchNetworkError } from "@/lib/tauri-fetch"import { chunkMarkdown, type Chunk } from "@/lib/text-chunker"+import { isLocalOrPrivateHttpEndpoint, localLlmOriginHeader } from "@/lib/llm-providers"const RESERVED_EMBEDDING_HEADER_NAMES = new Set(["authorization","content-type","host","content-length",+ "origin","x-goog-api-key",])const HTTP_HEADER_NAME_RE = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/@@ -109,7 +111,10 @@ export async function fetchEmbedding(const endpoint = isGoogleNative? googleEmbeddingEndpoint(cfg): volcengineEmbeddingEndpoint(cfg)- const headers: Record<string, string> = { "Content-Type": "application/json" }+ const headers: Record<string, string> = {+ "Content-Type": "application/json",+ ...(isLocalOrPrivateHttpEndpoint(endpoint) ? localLlmOriginHeader() : {}),+ }if (cfg.apiKey) {if (isGoogleNative) {headers["x-goog-api-key"] = cfg.apiKeydiff --git a/src/lib/llm-providers.ts b/src/lib/llm-providers.tsindex d96d907e..9285bcf8 100644--- a/src/lib/llm-providers.ts+++ b/src/lib/llm-providers.ts@@ -114,11 +114,11 @@ const JSON_CONTENT_TYPE = "application/json"* `src-tauri/Cargo.toml` lets reqwest forward Origin without* stripping it. End-to-end our value wins.*/-function localLlmOriginHeader(): Record<string, string> {+export function localLlmOriginHeader(): Record<string, string> {return { Origin: "http://localhost" }}-function isLocalOrPrivateHttpEndpoint(endpoint: string): boolean {+export function isLocalOrPrivateHttpEndpoint(endpoint: string): boolean {try {const url = new URL(endpoint)const host = url.hostname.toLowerCase()