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: unify "is LLM usable" check so claude-code provider works everywhere
nash_su62c9a5548587
diff --git a/src/components/chat/chat-message.tsx b/src/components/chat/chat-message.tsxindex d84e1786..f6ac821f 100644--- a/src/components/chat/chat-message.tsx+++ b/src/components/chat/chat-message.tsx@@ -18,6 +18,7 @@ import type { FileNode } from "@/types/wiki"import { convertLatexToUnicode } from "@/lib/latex-to-unicode"import { normalizePath, getFileName } from "@/lib/path-utils"import { makeQueryFileName } from "@/lib/wiki-filename"+import { hasUsableLlm } from "@/lib/has-usable-llm"import { resolveMarkdownImageSrc } from "@/lib/markdown-image-resolver"import { findRawSourceForImage, imageUrlToAbsolute } from "@/lib/raw-source-resolver"@@ -231,7 +232,7 @@ function SaveToWikiButton({ content, visible }: { content: string; visible: bool// Full auto-ingest: extract entities, concepts, cross-references from saved contentconst llmConfig = useWikiStore.getState().llmConfig- if (llmConfig.apiKey || llmConfig.provider === "ollama") {+ if (hasUsableLlm(llmConfig)) {const { autoIngest } = await import("@/lib/ingest")autoIngest(pp, filePath, llmConfig).catch((err) =>console.error("Failed to auto-ingest saved query:", err)diff --git a/src/components/lint/lint-view.tsx b/src/components/lint/lint-view.tsxindex ebcb0360..faa5be98 100644--- a/src/components/lint/lint-view.tsx+++ b/src/components/lint/lint-view.tsx@@ -15,6 +15,7 @@ import { Button } from "@/components/ui/button"import { useWikiStore } from "@/stores/wiki-store"import { useReviewStore } from "@/stores/review-store"import { runStructuralLint, runSemanticLint, type LintResult } from "@/lib/lint"+import { hasUsableLlm } from "@/lib/has-usable-llm"import { readFile, writeFile, listDirectory } from "@/commands/fs"import { normalizePath } from "@/lib/path-utils"@@ -49,7 +50,7 @@ export function LintView() {const structural = await runStructuralLint(pp)let all = structural- if (runSemantic && (llmConfig.apiKey || llmConfig.provider === "ollama")) {+ if (runSemantic && hasUsableLlm(llmConfig)) {const semantic = await runSemanticLint(pp, llmConfig)all = [...structural, ...semantic]}diff --git a/src/components/sources/sources-view.tsx b/src/components/sources/sources-view.tsxindex 349f9c1c..11bc429c 100644--- a/src/components/sources/sources-view.tsx+++ b/src/components/sources/sources-view.tsx@@ -8,6 +8,7 @@ import { useWikiStore } from "@/stores/wiki-store"import { copyFile, listDirectory, readFile, writeFile, deleteFile, findRelatedWikiPages, preprocessFile } from "@/commands/fs"import type { FileNode } from "@/types/wiki"import { enqueueIngest, enqueueBatch } from "@/lib/ingest-queue"+import { hasUsableLlm } from "@/lib/has-usable-llm"import { useTranslation } from "react-i18next"import { normalizePath, getFileName } from "@/lib/path-utils"import {@@ -139,7 +140,7 @@ export function SourcesView() {await loadSources()// Enqueue for serial ingest (runs in background via ingest queue)- if (llmConfig.apiKey || llmConfig.provider === "ollama" || llmConfig.provider === "custom") {+ if (hasUsableLlm(llmConfig)) {for (const destPath of importedPaths) {enqueueIngest(project.id, destPath).catch((err) =>console.error(`Failed to enqueue ingest:`, err)@@ -181,7 +182,7 @@ export function SourcesView() {await loadSources()// Build ingest tasks with folder context- if (llmConfig.apiKey || llmConfig.provider === "ollama" || llmConfig.provider === "custom") {+ if (hasUsableLlm(llmConfig)) {const tasks = copiedFiles.filter((fp) => {const ext = fp.split(".").pop()?.toLowerCase() ?? ""diff --git a/src/lib/clip-watcher.ts b/src/lib/clip-watcher.tsindex bada1b00..3e5923e1 100644--- a/src/lib/clip-watcher.ts+++ b/src/lib/clip-watcher.ts@@ -1,6 +1,7 @@import { useWikiStore } from "@/stores/wiki-store"import { enqueueIngest } from "./ingest-queue"import { listDirectory } from "@/commands/fs"+import { hasUsableLlm } from "@/lib/has-usable-llm"const POLL_INTERVAL = 3000 // Check every 3 secondslet intervalId: ReturnType<typeof setInterval> | null = null@@ -40,12 +41,7 @@ export function startClipWatcher() {// a UI refresh. Same path used by file imports from sources-view.// Pass the project's stable UUID — the queue looks up the// current filesystem path from the registry at run time.- const llmConfig = store.llmConfig- const hasLlm =- !!llmConfig.apiKey ||- llmConfig.provider === "ollama" ||- llmConfig.provider === "custom"- if (hasLlm) {+ if (hasUsableLlm(store.llmConfig)) {enqueueIngest(project.id, clipFilePath).catch((err) => {console.error("Failed to enqueue web clip:", err)})diff --git a/src/lib/has-usable-llm.test.ts b/src/lib/has-usable-llm.test.tsnew file mode 100644index 00000000..35ce7534--- /dev/null+++ b/src/lib/has-usable-llm.test.ts@@ -0,0 +1,109 @@+import { describe, it, expect } from "vitest"+import {+ hasUsableLlm,+ PROVIDERS_WITHOUT_KEY,+ type LlmProvider,+} from "./has-usable-llm"++// Compile-time exhaustiveness check: if a new provider is added to+// the LlmProvider union, this assignment will fail until the+// developer either adds the provider to PROVIDERS_WITHOUT_KEY *or*+// adds a case to KNOWN_PROVIDERS_WITH_KEY below. The runtime test+// then fails for any provider missing from both, so silently+// dropping a new provider into the wrong bucket is impossible.+const KNOWN_PROVIDERS_WITH_KEY: ReadonlySet<LlmProvider> = new Set([+ "openai",+ "anthropic",+ "google",+ "minimax",+])++describe("hasUsableLlm", () => {+ it("returns true for ollama with no API key", () => {+ expect(+ hasUsableLlm({ provider: "ollama", apiKey: "" }),+ ).toBe(true)+ })++ it("returns true for custom with no API key", () => {+ expect(+ hasUsableLlm({ provider: "custom", apiKey: "" }),+ ).toBe(true)+ })++ it("returns true for claude-code with no API key", () => {+ expect(+ hasUsableLlm({ provider: "claude-code", apiKey: "" }),+ ).toBe(true)+ })++ it("returns false for openai with no API key", () => {+ expect(+ hasUsableLlm({ provider: "openai", apiKey: "" }),+ ).toBe(false)+ })++ it("returns true for openai with an API key", () => {+ expect(+ hasUsableLlm({ provider: "openai", apiKey: "sk-test" }),+ ).toBe(true)+ })++ it("returns false for anthropic with empty key", () => {+ expect(+ hasUsableLlm({ provider: "anthropic", apiKey: "" }),+ ).toBe(false)+ })++ it("returns true for anthropic with a key", () => {+ expect(+ hasUsableLlm({ provider: "anthropic", apiKey: "sk-ant-..." }),+ ).toBe(true)+ })++ it("treats whitespace-only key as missing for key-required providers", () => {+ // Whitespace-only is almost always a paste accident; we want to+ // surface "set API key in Settings" rather than fail later with+ // a 401.+ expect(+ hasUsableLlm({ provider: "google", apiKey: " " }),+ ).toBe(false)+ })++ it("PROVIDERS_WITHOUT_KEY covers the locally-running / CLI-auth providers", () => {+ expect(PROVIDERS_WITHOUT_KEY.has("ollama")).toBe(true)+ expect(PROVIDERS_WITHOUT_KEY.has("custom")).toBe(true)+ expect(PROVIDERS_WITHOUT_KEY.has("claude-code")).toBe(true)+ })++ it("PROVIDERS_WITHOUT_KEY does not include hosted-API providers", () => {+ expect(PROVIDERS_WITHOUT_KEY.has("openai")).toBe(false)+ expect(PROVIDERS_WITHOUT_KEY.has("anthropic")).toBe(false)+ expect(PROVIDERS_WITHOUT_KEY.has("google")).toBe(false)+ expect(PROVIDERS_WITHOUT_KEY.has("minimax")).toBe(false)+ })++ // Exhaustiveness guard. Every member of the LlmProvider union+ // must be classified into exactly one bucket; adding a new+ // provider that's missing from both sets fails this test, which+ // is the whole reason this helper exists.+ it("classifies every LlmProvider into exactly one bucket", () => {+ const allProviders: LlmProvider[] = [+ "openai",+ "anthropic",+ "google",+ "ollama",+ "custom",+ "minimax",+ "claude-code",+ ]+ for (const p of allProviders) {+ const inNoKey = PROVIDERS_WITHOUT_KEY.has(p)+ const inKey = KNOWN_PROVIDERS_WITH_KEY.has(p)+ expect(+ inNoKey !== inKey,+ `provider "${p}" is in ${inNoKey && inKey ? "BOTH" : "NEITHER"} bucket — pick one`,+ ).toBe(true)+ }+ })+})diff --git a/src/lib/has-usable-llm.ts b/src/lib/has-usable-llm.tsnew file mode 100644index 00000000..36f69be7--- /dev/null+++ b/src/lib/has-usable-llm.ts@@ -0,0 +1,44 @@+import type { LlmConfig } from "@/stores/wiki-store"++export type LlmProvider = LlmConfig["provider"]++/**+ * Providers that don't need an API key to operate:+ * - `ollama` runs on a local HTTP endpoint with no auth+ * - `custom` is an OpenAI-compatible local-or-LAN endpoint that+ * may or may not require auth (LM Studio, llama.cpp, vLLM+ * defaults are all unauthenticated; users who deploy behind a+ * proxy can still set apiKey to add Bearer auth)+ * - `claude-code` spawns the Claude Code CLI subprocess, which+ * authenticates via the user's existing ~/.claude OAuth — no+ * API key is needed (or accepted) at this layer.+ *+ * Hosted providers (openai, anthropic, google, minimax) require a+ * key from the user.+ */+export const PROVIDERS_WITHOUT_KEY: ReadonlySet<LlmProvider> = new Set<LlmProvider>([+ "ollama",+ "custom",+ "claude-code",+])++/**+ * Single source of truth for "is the user's LLM configuration good+ * enough to make calls?" Replaces ad-hoc `apiKey || provider ===+ * "ollama" || …` checks scattered across ingest, sweep, lint,+ * chat, and clip-watcher — every one of which had to be edited+ * by hand whenever a new no-key provider was added, and at least+ * three of which were silently out of date when the+ * Claude Code CLI provider shipped.+ *+ * Use this everywhere a guard like "do we have an LLM?" is+ * needed; the type-level union plus the exhaustiveness test in+ * `has-usable-llm.test.ts` ensures future provider additions+ * land in exactly one bucket and don't slip through.+ */+export function hasUsableLlm(+ cfg: Pick<LlmConfig, "provider" | "apiKey">,+): boolean {+ if (PROVIDERS_WITHOUT_KEY.has(cfg.provider)) return true+ return cfg.apiKey.trim().length > 0+}diff --git a/src/lib/ingest-queue.ts b/src/lib/ingest-queue.tsindex 0d83c9c0..7b2b42dd 100644--- a/src/lib/ingest-queue.ts+++ b/src/lib/ingest-queue.ts@@ -3,6 +3,7 @@ import { autoIngest } from "./ingest"import { useWikiStore } from "@/stores/wiki-store"import { normalizePath, isAbsolutePath } from "@/lib/path-utils"import { getProjectPathById } from "@/lib/project-identity"+import { hasUsableLlm } from "@/lib/has-usable-llm"// ── Types ─────────────────────────────────────────────────────────────────@@ -473,7 +474,7 @@ async function processNext(projectId: string): Promise<void> {const llmConfig = useWikiStore.getState().llmConfig// Check if LLM is configured- if (!llmConfig.apiKey && llmConfig.provider !== "ollama" && llmConfig.provider !== "custom") {+ if (!hasUsableLlm(llmConfig)) {next.status = "failed"next.error = "LLM not configured — set API key in Settings"processing = falsediff --git a/src/lib/sweep-reviews.ts b/src/lib/sweep-reviews.tsindex 27a1407d..2a0506df 100644--- a/src/lib/sweep-reviews.ts+++ b/src/lib/sweep-reviews.ts@@ -18,6 +18,7 @@ import { streamChat } from "@/lib/llm-client"import type { FileNode } from "@/types/wiki"import { normalizePath } from "@/lib/path-utils"import { normalizeReviewTitle } from "@/lib/review-utils"+import { hasUsableLlm } from "@/lib/has-usable-llm"// ── Types ─────────────────────────────────────────────────────────────────@@ -195,9 +196,7 @@ async function judgeBatch(if (batch.length === 0 || signal?.aborted) return new Set()const llmConfig = useWikiStore.getState().llmConfig- const hasConfig =- !!llmConfig.apiKey || llmConfig.provider === "ollama" || llmConfig.provider === "custom"- if (!hasConfig) return new Set()+ if (!hasUsableLlm(llmConfig)) return new Set()const pages = index.pages.slice(0, MAX_PAGES_IN_PROMPT)