Skip to content

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

Merge pull request #303 from 404805854/fix-kimi-coding-plan-sse-parse

nash_su4a8fad825391
diff --cc src/lib/__tests__/llm-providers.test.ts
index 02dc32e8,e079a42b..e38b7f29
--- a/src/lib/__tests__/llm-providers.test.ts
+++ b/src/lib/__tests__/llm-providers.test.ts
@@@ -1,11 -1,53 +1,11 @@@
import { describe, it, expect } from "vitest"
- import { buildAnthropicUrl, parseGoogleLine, getProviderConfig } from "../llm-providers"
+ import { buildAnthropicUrl, parseGoogleLine, parseAnthropicLine, 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 system = systemMessages.map((m) => m.content).join("\n") || 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",
+ model: "MiniMax-M3",
ollamaUrl: "http://localhost:11434",
customEndpoint: "",
maxContextSize: 204800,
diff --cc src/lib/llm-providers.test.ts
index 8aa24f7e,57166f68..463b2511
--- a/src/lib/llm-providers.test.ts
+++ b/src/lib/llm-providers.test.ts
@@@ -387,31 -363,41 +387,64 @@@ describe("reasoning controls", () =>
expect(provider.url).toBe("https://token-plan-cn.xiaomimimo.com/anthropic/v1/messages")
expect(provider.headers.Authorization).toBe("Bearer sk-mimo")
expect(provider.headers["x-api-key"]).toBeUndefined()
+ expect(provider.headers["anthropic-version"]).toBe("2023-06-01")
+ })
+
+ it("uses Bearer auth for Kimi Coding Plan Anthropic wire", () => {
+ const cfg = mkConfig({
+ provider: "custom",
+ apiKey: "sk-kimi-test",
+ model: "kimi-for-coding",
+ customEndpoint: "https://api.kimi.com/coding/",
+ apiMode: "anthropic_messages",
+ })
+ const provider = getProviderConfig(cfg)
+
+ expect(provider.url).toBe("https://api.kimi.com/coding/v1/messages")
+ expect(provider.headers.Authorization).toBe("Bearer sk-kimi-test")
+ expect(provider.headers["x-api-key"]).toBeUndefined()
+ expect(provider.headers["anthropic-version"]).toBe("2023-06-01")
+ })
+
+ it("uses Bearer auth for Moonshot Anthropic wire", () => {
+ const cfg = mkConfig({
+ provider: "custom",
+ apiKey: "sk-moonshot",
+ model: "kimi-k2.6",
+ customEndpoint: "https://api.moonshot.ai/anthropic",
+ apiMode: "anthropic_messages",
+ })
+ const provider = getProviderConfig(cfg)
+
+ expect(provider.url).toBe("https://api.moonshot.ai/anthropic/v1/messages")
+ expect(provider.headers.Authorization).toBe("Bearer sk-moonshot")
+ expect(provider.headers["x-api-key"]).toBeUndefined()
+ expect(provider.headers["anthropic-version"]).toBe("2023-06-01")
})
+ it("uses cacheable system blocks for custom Anthropic-wire providers", () => {
+ const cfg = mkConfig({
+ provider: "custom",
+ apiKey: "sk-custom",
+ model: "custom-claude",
+ customEndpoint: "https://example.com/anthropic",
+ apiMode: "anthropic_messages",
+ })
+ const body = getProviderConfig(cfg).buildBody([
+ { role: "system", content: "Project-wide instruction." },
+ { role: "user", content: "Hi" },
+ ]) as { system?: unknown; messages: unknown[] }
+
+ expect(body.system).toEqual([
+ {
+ type: "text",
+ text: "Project-wide instruction.",
+ cache_control: { type: "ephemeral" },
+ },
+ ])
+ expect(body.messages).toEqual([{ role: "user", content: "Hi" }])
+ })
+
it("disables Qwen3 thinking on OpenAI-compatible local endpoints", () => {
const cfg = mkConfig({
provider: "custom",