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
test: cover Anthropic prompt caching paths
nash_su7eb500062ec1
diff --git a/src/lib/__tests__/llm-providers.test.ts b/src/lib/__tests__/llm-providers.test.tsindex 0106b5c0..32ad1db7 100644--- a/src/lib/__tests__/llm-providers.test.ts+++ b/src/lib/__tests__/llm-providers.test.ts@@ -2,52 +2,7 @@ import { describe, it, expect } from "vitest"import { buildAnthropicUrl, parseGoogleLine, getProviderConfig } from "../llm-providers"import type { LlmConfig as RealLlmConfig } from "@/stores/wiki-store"-// Inline minimal types to avoid store/zustand dependencies in unit tests-type Provider = "openai" | "anthropic" | "google" | "azure" | "ollama" | "custom" | "minimax"--interface LlmConfig {- provider: Provider- apiKey: string- model: string- ollamaUrl: string- customEndpoint: string- maxContextSize: number-}--// Re-implement the minimax case logic inline so we can unit-test it-// without a browser environment or Tauri runtime. Keep this in sync with-// the `case "minimax":` branch in src/lib/llm-providers.ts.-function buildMiniMaxProviderConfig(config: LlmConfig) {- const { apiKey, model, customEndpoint } = config- const base = (customEndpoint || "https://api.minimax.io/anthropic").replace(/\/+$/, "")- // MiniMax's /anthropic endpoint requires Authorization: Bearer, NOT- // x-api-key. Its CORS preflight rejects x-api-key entirely. See the- // requiresBearerAuth() helper in src/lib/llm-providers.ts.- return {- url: `${base}/v1/messages`,- headers: {- "Content-Type": "application/json",- Authorization: `Bearer ${apiKey}`,- },- buildBody: (messages: Array<{ role: string; content: string }>) => {- const systemMessages = messages.filter((m) => m.role === "system")- const conversationMessages = messages.filter((m) => m.role !== "system")- const systemText = systemMessages.map((m) => m.content).join("\n")- const system = systemText- ? [{ type: "text", text: systemText, cache_control: { type: "ephemeral" } }]- : undefined- return {- messages: conversationMessages,- ...(system !== undefined ? { system } : {}),- stream: true,- max_tokens: 4096,- model,- }- },- }-}--const makeConfig = (overrides: Partial<LlmConfig> = {}): LlmConfig => ({+const makeConfig = (overrides: Partial<RealLlmConfig> = {}): RealLlmConfig => ({provider: "minimax",apiKey: "test-key",model: "MiniMax-M2.7",@@ -59,48 +14,48 @@ const makeConfig = (overrides: Partial<LlmConfig> = {}): LlmConfig => ({describe("MiniMax Provider", () => {it("uses the Anthropic Messages endpoint under /anthropic", () => {- const cfg = buildMiniMaxProviderConfig(makeConfig())+ const cfg = getProviderConfig(makeConfig())expect(cfg.url).toBe("https://api.minimax.io/anthropic/v1/messages")})it("supports the China regional endpoint via customEndpoint", () => {- const cfg = buildMiniMaxProviderConfig(+ const cfg = getProviderConfig(makeConfig({ customEndpoint: "https://api.minimaxi.com/anthropic" }),)expect(cfg.url).toBe("https://api.minimaxi.com/anthropic/v1/messages")})it("uses Authorization: Bearer (MiniMax rejects x-api-key at CORS layer)", () => {- const cfg = buildMiniMaxProviderConfig(makeConfig({ apiKey: "my-key" }))+ const cfg = getProviderConfig(makeConfig({ apiKey: "my-key" }))expect(cfg.headers.Authorization).toBe("Bearer my-key")expect((cfg.headers as Record<string, string>)["x-api-key"]).toBeUndefined()})it("sets Content-Type to application/json", () => {- const cfg = buildMiniMaxProviderConfig(makeConfig())+ const cfg = getProviderConfig(makeConfig())expect(cfg.headers["Content-Type"]).toBe("application/json")})it("enables streaming", () => {- const cfg = buildMiniMaxProviderConfig(makeConfig())+ const cfg = getProviderConfig(makeConfig())const body = cfg.buildBody([]) as Record<string, unknown>expect(body.stream).toBe(true)})it("includes max_tokens (required by Anthropic wire)", () => {- const cfg = buildMiniMaxProviderConfig(makeConfig())+ const cfg = getProviderConfig(makeConfig())const body = cfg.buildBody([]) as Record<string, unknown>expect(body.max_tokens).toBe(4096)})it("carries the model in the body", () => {- const cfg = buildMiniMaxProviderConfig(makeConfig({ model: "MiniMax-M2.7" }))+ const cfg = getProviderConfig(makeConfig({ model: "MiniMax-M2.7" }))const body = cfg.buildBody([]) as Record<string, unknown>expect(body.model).toBe("MiniMax-M2.7")})it("separates system messages from conversation and marks the system prompt cacheable", () => {- const cfg = buildMiniMaxProviderConfig(makeConfig())+ const cfg = getProviderConfig(makeConfig())const body = cfg.buildBody([{ role: "system", content: "You are helpful" },{ role: "user", content: "Hello" },@@ -118,7 +73,7 @@ describe("MiniMax Provider", () => {describe("MiniMax provider registration", () => {it("minimax is a valid provider value in the type union", () => {- const provider: Provider = "minimax"+ const provider: RealLlmConfig["provider"] = "minimax"expect(provider).toBe("minimax")})})diff --git a/src/lib/llm-providers.test.ts b/src/lib/llm-providers.test.tsindex dffb0626..8aa24f7e 100644--- a/src/lib/llm-providers.test.ts+++ b/src/lib/llm-providers.test.ts@@ -454,6 +454,27 @@ describe("reasoning controls", () => {expect(body.temperature).toBeUndefined()})+ it("keeps cacheable system blocks when Anthropic extended thinking is enabled", () => {+ const cfg = mkConfig({ provider: "anthropic", model: "claude-sonnet-4-5-20250929" })+ const body = getProviderConfig(cfg).buildBody(+ [+ { role: "system", content: "Persistent project context." },+ { role: "user", content: "hi" },+ ],+ { reasoning: { mode: "low" }, temperature: 0.1, max_tokens: 4096 },+ ) as Record<string, unknown>++ expect(body.system).toEqual([+ {+ type: "text",+ text: "Persistent project context.",+ cache_control: { type: "ephemeral" },+ },+ ])+ expect(body.thinking).toEqual({ type: "enabled", budget_tokens: 1024 })+ expect(body.temperature).toBeUndefined()+ })+it("maps Gemini reasoning off to thinkingBudget 0", () => {const cfg = mkConfig({ provider: "google", model: "gemini-2.5-pro" })const body = getProviderConfig(cfg).buildBody(diff --git a/src/lib/llm-providers.ts b/src/lib/llm-providers.tsindex b7fb5827..a147fcef 100644--- a/src/lib/llm-providers.ts+++ b/src/lib/llm-providers.ts@@ -410,6 +410,9 @@ function flattenAnthropicSystem(content: string | ContentBlock[]): string {function buildAnthropicSystem(systemText: string): unknown[] | undefined {if (!systemText) return undefined+ // Anthropic Messages wire only. OpenAI/Gemini-compatible providers+ // use different system-prompt shapes and do not understand this+ // cache_control marker.return [{type: "text",