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
feat: route chat and ingest models separately
nash_su8bcd184248cc
diff --git a/src/App.tsx b/src/App.tsxindex 6be4e1bc..8cd58ea4 100644--- a/src/App.tsx+++ b/src/App.tsx@@ -9,7 +9,7 @@ import { useLintStore } from "@/stores/lint-store"import { useChatStore } from "@/stores/chat-store"import { BASE_FONT_SIZE_PX, useZoomStore } from "@/stores/zoom-store"import { openProject } from "@/commands/fs"-import { getLastProject, getRecentProjects, saveLastProject, loadLlmConfig, loadLanguage, loadSearchApiConfig, loadEmbeddingConfig, loadMineruConfig, loadMultimodalConfig, loadOutputLanguage, loadProviderConfigs, loadActivePresetId, loadProxyConfig, loadScheduledImportConfig, saveScheduledImportConfig, loadSourceWatchConfig, loadApiConfig, loadGeneralConfig, loadZoomLevel } from "@/lib/project-store"+import { getLastProject, getRecentProjects, saveLastProject, loadLlmConfig, loadLanguage, loadSearchApiConfig, loadEmbeddingConfig, loadMineruConfig, loadMultimodalConfig, loadOutputLanguage, loadProviderConfigs, loadActivePresetId, loadTaskModelRouting, loadProxyConfig, loadScheduledImportConfig, saveScheduledImportConfig, loadSourceWatchConfig, loadApiConfig, loadGeneralConfig, loadZoomLevel } from "@/lib/project-store"import { loadReviewItems, loadLintItems, loadChatHistory, loadChatPreferences } from "@/lib/persist"import { setupAutoSave } from "@/lib/auto-save"import { startClipWatcher } from "@/lib/clip-watcher"@@ -313,6 +313,10 @@ function App() {await saveLlmConfig(resolved)}}+ const savedTaskModelRouting = await loadTaskModelRouting()+ if (savedTaskModelRouting) {+ useWikiStore.getState().setTaskModelRouting(savedTaskModelRouting)+ }const savedSearchConfig = await loadSearchApiConfig()if (savedSearchConfig) {useWikiStore.getState().setSearchApiConfig(savedSearchConfig)diff --git a/src/components/chat/chat-message.tsx b/src/components/chat/chat-message.tsxindex 8be26e46..7fc7913f 100644--- a/src/components/chat/chat-message.tsx+++ b/src/components/chat/chat-message.tsx@@ -22,6 +22,7 @@ import { convertLatexToUnicode } from "@/lib/latex-to-unicode"import { normalizePath, getFileName, isAbsolutePath } from "@/lib/path-utils"import { makeQueryFileName } from "@/lib/wiki-filename"import { hasUsableLlm } from "@/lib/has-usable-llm"+import { getTaskLlmConfig } from "@/lib/llm-task-routing"import { messageImageToDataUrl } from "@/lib/chat-image-utils"import { resolveMarkdownImageSrc } from "@/lib/markdown-image-resolver"import { transformImageEmbeds } from "@/lib/wikilink-transform"@@ -612,7 +613,7 @@ function SaveToWikiButton({ content, visible }: { content: string; visible: boolsetTimeout(() => setSaved(false), 2000)// Full auto-ingest: extract entities, concepts, cross-references from saved content- const llmConfig = useWikiStore.getState().llmConfig+ const llmConfig = getTaskLlmConfig("ingest")if (hasUsableLlm(llmConfig)) {const { autoIngest } = await import("@/lib/ingest")autoIngest(pp, filePath, llmConfig).catch((err) =>diff --git a/src/components/chat/chat-panel.tsx b/src/components/chat/chat-panel.tsxindex d57e8c38..3a6e940d 100644--- a/src/components/chat/chat-panel.tsx+++ b/src/components/chat/chat-panel.tsx@@ -8,6 +8,7 @@ import { ChatMessage, StreamingMessage, useSourceFiles, type ChatReferencePrevieimport { ChatInput, type ChatSendOptions } from "./chat-input"import { useChatStore, chatMessagesToLLM, type MessageImage, type MessageReference } from "@/stores/chat-store"import { useWikiStore } from "@/stores/wiki-store"+import { resolveTaskLlmConfig } from "@/lib/llm-task-routing"import { isReasoningOnlyResponseError, streamChat } from "@/lib/llm-client"import { supportsImageInput } from "@/lib/llm-providers"import { executeIngestWrites } from "@/lib/ingest"@@ -462,7 +463,13 @@ export function ChatPanel() {const project = useWikiStore((s) => s.project)const projectPathIndex = useWikiStore((s) => s.projectPathIndex)- const llmConfig = useWikiStore((s) => s.llmConfig)+ const baseLlmConfig = useWikiStore((s) => s.llmConfig)+ const providerConfigs = useWikiStore((s) => s.providerConfigs)+ const taskModelRouting = useWikiStore((s) => s.taskModelRouting)+ const llmConfig = useMemo(+ () => resolveTaskLlmConfig("chat", baseLlmConfig, providerConfigs, taskModelRouting),+ [baseLlmConfig, providerConfigs, taskModelRouting],+ )const searchApiConfig = useWikiStore((s) => s.searchApiConfig)const anyTxtAvailable = hasConfiguredAnyTxt(searchApiConfig.anyTxt)const imageInputAvailable = supportsImageInput(llmConfig)diff --git a/src/components/settings/sections/llm-provider-section.tsx b/src/components/settings/sections/llm-provider-section.tsxindex 390dbfd8..7991b58c 100644--- a/src/components/settings/sections/llm-provider-section.tsx+++ b/src/components/settings/sections/llm-provider-section.tsx@@ -20,6 +20,8 @@ export function LlmProviderSection() {const setActivePresetId = useWikiStore((s) => s.setActivePresetId)const setLlmConfig = useWikiStore((s) => s.setLlmConfig)const llmConfig = useWikiStore((s) => s.llmConfig)+ const taskModelRouting = useWikiStore((s) => s.taskModelRouting)+ const setTaskModelRouting = useWikiStore((s) => s.setTaskModelRouting)const [expanded, setExpanded] = useState<Record<string, boolean>>({})const [savedId, setSavedId] = useState<string | null>(null)@@ -74,6 +76,16 @@ export function LlmProviderSection() {persist(providerConfigs, next).catch(() => {})}+ async function updateTaskRouting(task: "chat" | "ingest", value: string) {+ const next = {+ ...taskModelRouting,+ [task === "chat" ? "chatPresetId" : "ingestPresetId"]: value || null,+ }+ setTaskModelRouting(next)+ const { saveTaskModelRouting } = await import("@/lib/project-store")+ await saveTaskModelRouting(next)+ }+return (<div className="space-y-4"><div>@@ -83,6 +95,30 @@ export function LlmProviderSection() {</p></div>+ <div className="grid gap-3 rounded-md border bg-muted/20 p-3 sm:grid-cols-2">+ <TaskModelSelect+ id="chat-task-model"+ label={t("settings.sections.llm.taskRouting.chat")}+ value={taskModelRouting.chatPresetId ?? ""}+ onChange={(value) => void updateTaskRouting("chat", value).catch((error) => {+ console.error("Failed to save chat model routing:", error)+ })}+ fallbackLabel={t("settings.sections.llm.taskRouting.activeDefault")}+ />+ <TaskModelSelect+ id="ingest-task-model"+ label={t("settings.sections.llm.taskRouting.ingest")}+ value={taskModelRouting.ingestPresetId ?? ""}+ onChange={(value) => void updateTaskRouting("ingest", value).catch((error) => {+ console.error("Failed to save ingest model routing:", error)+ })}+ fallbackLabel={t("settings.sections.llm.taskRouting.activeDefault")}+ />+ <p className="text-xs text-muted-foreground sm:col-span-2">+ {t("settings.sections.llm.taskRouting.hint")}+ </p>+ </div>+<div className="space-y-2">{LLM_PRESETS.map((preset) => (<PresetRow@@ -102,6 +138,37 @@ export function LlmProviderSection() {)}+function TaskModelSelect({+ id,+ label,+ value,+ onChange,+ fallbackLabel,+}: {+ id: string+ label: string+ value: string+ onChange: (value: string) => void+ fallbackLabel: string+}) {+ return (+ <div className="space-y-1.5">+ <Label htmlFor={id}>{label}</Label>+ <select+ id={id}+ value={value}+ onChange={(event) => onChange(event.target.value)}+ className="h-9 w-full rounded-md border border-input bg-background px-3 text-sm"+ >+ <option value="">{fallbackLabel}</option>+ {LLM_PRESETS.map((preset) => (+ <option key={preset.id} value={preset.id}>{preset.label}</option>+ ))}+ </select>+ </div>+ )+}+interface PresetRowProps {preset: LlmPresetoverride: ProviderOverride | undefineddiff --git a/src/i18n/en.json b/src/i18n/en.jsonindex 88af5749..312daf55 100644--- a/src/i18n/en.json+++ b/src/i18n/en.json@@ -456,6 +456,12 @@"llm": {"title": "LLM Models","description": "One row per vendor. Toggling one on automatically turns off the others. Changes save instantly; each vendor's API key is stored independently so switching doesn't lose data.",+ "taskRouting": {+ "chat": "Chat model",+ "ingest": "Ingest model",+ "activeDefault": "Use active model",+ "hint": "Choose separate models for interactive chat and document ingest. The active model remains the fallback."+ },"expand": "Expand config","collapse": "Collapse","toggleOff": "Click to deactivate",diff --git a/src/i18n/zh.json b/src/i18n/zh.jsonindex 0ea3a662..5aaf9336 100644--- a/src/i18n/zh.json+++ b/src/i18n/zh.json@@ -456,6 +456,12 @@"llm": {"title": "LLM 模型","description": "每个厂商一条独立配置。打开开关即切换为当前活跃 provider;其他的会自动关闭。配置改动即时保存,每个厂商的 API Key 独立存储,切换之间不丢失。",+ "taskRouting": {+ "chat": "Chat 模型",+ "ingest": "Ingest 模型",+ "activeDefault": "使用当前活跃模型",+ "hint": "可为交互聊天和文档摄取分别选择模型;未指定时继续使用当前活跃模型。"+ },"expand": "展开配置","collapse": "收起","toggleOff": "点击关闭",diff --git a/src/lib/dedup-queue.ts b/src/lib/dedup-queue.tsindex ad2fddf3..badf6f49 100644--- a/src/lib/dedup-queue.ts+++ b/src/lib/dedup-queue.ts@@ -20,6 +20,7 @@ import { useWikiStore } from "@/stores/wiki-store"import { normalizePath } from "@/lib/path-utils"import { getProjectPathById } from "@/lib/project-identity"import { hasUsableLlm } from "@/lib/has-usable-llm"+import { getTaskLlmConfig } from "@/lib/llm-task-routing"import { executeMerge } from "@/lib/dedup-runner"import type { DuplicateGroup } from "@/lib/dedup"@@ -348,7 +349,7 @@ async function processNext(projectId: string): Promise<void> {await saveQueue(pp)if (currentProjectId !== projectId) return- const llmConfig = useWikiStore.getState().llmConfig+ const llmConfig = getTaskLlmConfig("ingest")if (!hasUsableLlm(llmConfig)) {next.status = "failed"diff --git a/src/lib/ingest-queue.ts b/src/lib/ingest-queue.tsindex 5276c453..4a34a05f 100644--- a/src/lib/ingest-queue.ts+++ b/src/lib/ingest-queue.ts@@ -1,9 +1,9 @@import { readFile, writeFile } from "@/commands/fs"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"+import { getTaskLlmConfig } from "@/lib/llm-task-routing"// ── Types ─────────────────────────────────────────────────────────────────@@ -715,7 +715,7 @@ async function processNext(projectId: string): Promise<void> {await saveQueue(pp)if (currentProjectId !== projectId) return- const llmConfig = useWikiStore.getState().llmConfig+ const llmConfig = getTaskLlmConfig("ingest")// Check if LLM is configuredif (!hasUsableLlm(llmConfig)) {diff --git a/src/lib/llm-task-routing.test.ts b/src/lib/llm-task-routing.test.tsnew file mode 100644index 00000000..20d6b570--- /dev/null+++ b/src/lib/llm-task-routing.test.ts@@ -0,0 +1,47 @@+import { describe, expect, it } from "vitest"+import { resolveTaskLlmConfig } from "./llm-task-routing"+import type { LlmConfig } from "@/stores/wiki-store"++const fallback: LlmConfig = {+ provider: "openai",+ apiKey: "global-key",+ model: "global-model",+ ollamaUrl: "http://localhost:11434",+ customEndpoint: "",+ maxContextSize: 128000,+}++describe("resolveTaskLlmConfig", () => {+ it("uses the active global config when no task override is selected", () => {+ expect(resolveTaskLlmConfig("chat", fallback, {}, {+ chatPresetId: null,+ ingestPresetId: null,+ })).toBe(fallback)+ })++ it("resolves chat and ingest from independent provider presets", () => {+ const configs = {+ openai: { apiKey: "chat-key", model: "gpt-4o-mini" },+ anthropic: { apiKey: "ingest-key", model: "claude-sonnet-4-6" },+ }+ const routing = { chatPresetId: "openai", ingestPresetId: "anthropic" }++ expect(resolveTaskLlmConfig("chat", fallback, configs, routing)).toMatchObject({+ provider: "openai",+ apiKey: "chat-key",+ model: "gpt-4o-mini",+ })+ expect(resolveTaskLlmConfig("ingest", fallback, configs, routing)).toMatchObject({+ provider: "anthropic",+ apiKey: "ingest-key",+ model: "claude-sonnet-4-6",+ })+ })++ it("falls back when a persisted preset id no longer exists", () => {+ expect(resolveTaskLlmConfig("ingest", fallback, {}, {+ chatPresetId: null,+ ingestPresetId: "removed-provider",+ })).toBe(fallback)+ })+})diff --git a/src/lib/llm-task-routing.ts b/src/lib/llm-task-routing.tsnew file mode 100644index 00000000..53fe8077--- /dev/null+++ b/src/lib/llm-task-routing.ts@@ -0,0 +1,40 @@+import { LLM_PRESETS } from "@/components/settings/llm-presets"+import { resolveConfig } from "@/components/settings/preset-resolver"+import type {+ LlmConfig,+ ProviderConfigs,+ TaskModelRoutingConfig,+} from "@/stores/wiki-store"+import { useWikiStore } from "@/stores/wiki-store"++export type LlmTaskKind = "chat" | "ingest"++/**+ * Resolve a task-specific provider from the current preset overrides.+ * Routing stores preset ids rather than credential snapshots so API-key,+ * endpoint, and model edits take effect immediately. Missing/deleted preset+ * ids fail safely to the active global configuration.+ */+export function resolveTaskLlmConfig(+ task: LlmTaskKind,+ fallback: LlmConfig,+ providerConfigs: ProviderConfigs,+ routing: TaskModelRoutingConfig,+): LlmConfig {+ const presetId = task === "chat" ? routing.chatPresetId : routing.ingestPresetId+ if (!presetId) return fallback+ const preset = LLM_PRESETS.find((candidate) => candidate.id === presetId)+ if (!preset) return fallback+ return resolveConfig(preset, providerConfigs[presetId], fallback)+}++/** Resolve against one atomic Zustand snapshot for imperative/background code. */+export function getTaskLlmConfig(task: LlmTaskKind, fallback?: LlmConfig): LlmConfig {+ const state = useWikiStore.getState()+ return resolveTaskLlmConfig(+ task,+ fallback ?? state.llmConfig,+ state.providerConfigs,+ state.taskModelRouting,+ )+}diff --git a/src/lib/project-store.ts b/src/lib/project-store.tsindex 08377bfe..0297fc2d 100644--- a/src/lib/project-store.ts+++ b/src/lib/project-store.ts@@ -1,6 +1,6 @@import { load } from "@tauri-apps/plugin-store"import type { WikiProject } from "@/types/wiki"-import type { ApiConfig, GeneralConfig, LlmConfig, SearchApiConfig, EmbeddingConfig, MineruConfig, MultimodalConfig, OutputLanguage, ProviderConfigs, ProxyConfig, ScheduledImportConfig, SourceWatchConfig } from "@/stores/wiki-store"+import type { ApiConfig, GeneralConfig, LlmConfig, SearchApiConfig, EmbeddingConfig, MineruConfig, MultimodalConfig, OutputLanguage, ProviderConfigs, ProxyConfig, ScheduledImportConfig, SourceWatchConfig, TaskModelRoutingConfig } from "@/stores/wiki-store"import { normalizeSourceWatchConfig } from "@/lib/source-watch-config"import { normalizePath } from "@/lib/path-utils"import { DEFAULT_ZOOM_LEVEL, clampZoomLevel } from "@/stores/zoom-store"@@ -44,6 +44,7 @@ export async function addToRecentProjects(const LLM_CONFIG_KEY = "llmConfig"const PROVIDER_CONFIGS_KEY = "providerConfigs"const ACTIVE_PRESET_KEY = "activePresetId"+const TASK_MODEL_ROUTING_KEY = "taskModelRouting"export async function saveLlmConfig(config: LlmConfig): Promise<void> {const store = await getStore()@@ -75,6 +76,21 @@ export async function loadActivePresetId(): Promise<string | null> {return (await store.get<string | null>(ACTIVE_PRESET_KEY)) ?? null}+export async function saveTaskModelRouting(config: TaskModelRoutingConfig): Promise<void> {+ const store = await getStore()+ await store.set(TASK_MODEL_ROUTING_KEY, config)+}++export async function loadTaskModelRouting(): Promise<TaskModelRoutingConfig | null> {+ const store = await getStore()+ const saved = await store.get<Partial<TaskModelRoutingConfig>>(TASK_MODEL_ROUTING_KEY)+ if (!saved) return null+ return {+ chatPresetId: typeof saved.chatPresetId === "string" ? saved.chatPresetId : null,+ ingestPresetId: typeof saved.ingestPresetId === "string" ? saved.ingestPresetId : null,+ }+}+const SEARCH_API_KEY = "searchApiConfig"export async function saveSearchApiConfig(config: SearchApiConfig): Promise<void> {diff --git a/src/lib/source-lifecycle.ts b/src/lib/source-lifecycle.tsindex 2d0f8d65..d901ef28 100644--- a/src/lib/source-lifecycle.ts+++ b/src/lib/source-lifecycle.ts@@ -13,6 +13,7 @@ import type { WikiProject, FileNode } from "@/types/wiki"import type { LlmConfig } from "@/stores/wiki-store"import { enqueueBatch } from "@/lib/ingest-queue"import { hasUsableLlm } from "@/lib/has-usable-llm"+import { getTaskLlmConfig } from "@/lib/llm-task-routing"import { getFileName, getFileStem, getRelativePath, normalizePath } from "@/lib/path-utils"import {sourceIdentityForPath,@@ -240,7 +241,7 @@ export async function enqueueSourceIngest(llmConfig: LlmConfig,options: { sourceRoot?: string; rootContext?: string } = {},): Promise<string[]> {- if (!hasUsableLlm(llmConfig)) return []+ if (!hasUsableLlm(getTaskLlmConfig("ingest", llmConfig))) return []const files = sourcePaths.filter((sourcePath) =>isIngestableSourcePath(sourcePath) &&@@ -353,7 +354,7 @@ export async function importSourceFolder(naturalCompare(getRelativePath(a, destDir), getRelativePath(b, destDir)),)- if (hasUsableLlm(llmConfig)) {+ if (hasUsableLlm(getTaskLlmConfig("ingest", llmConfig))) {await enqueueSourceIngest(project, naturallyOrderedFiles, llmConfig, {sourceRoot: destDir,rootContext: folderName,diff --git a/src/lib/sweep-reviews.ts b/src/lib/sweep-reviews.tsindex 2f92238c..4279504e 100644--- a/src/lib/sweep-reviews.ts+++ b/src/lib/sweep-reviews.ts@@ -19,6 +19,7 @@ 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"+import { getTaskLlmConfig } from "@/lib/llm-task-routing"import { parseFrontmatter } from "@/lib/frontmatter"// ── Types ─────────────────────────────────────────────────────────────────@@ -196,7 +197,7 @@ async function judgeBatch(): Promise<Set<string>> {if (batch.length === 0 || signal?.aborted) return new Set()- const llmConfig = useWikiStore.getState().llmConfig+ const llmConfig = getTaskLlmConfig("ingest")if (!hasUsableLlm(llmConfig)) return new Set()const pages = index.pages.slice(0, MAX_PAGES_IN_PROMPT)diff --git a/src/stores/wiki-store.ts b/src/stores/wiki-store.tsindex 2846842d..5c30e702 100644--- a/src/stores/wiki-store.ts+++ b/src/stores/wiki-store.ts@@ -323,6 +323,13 @@ export interface ProviderOverride {export type ProviderConfigs = Record<string, ProviderOverride>+export interface TaskModelRoutingConfig {+ /** Null keeps chat on the globally active provider preset. */+ chatPresetId: string | null+ /** Null keeps ingest on the globally active provider preset. */+ ingestPresetId: string | null+}+export interface ExternalPreview {title: stringpath: string@@ -372,6 +379,7 @@ interface WikiState {providerConfigs: ProviderConfigs/** Which preset is currently active. `null` = no LLM configured. */activePresetId: string | null+ taskModelRouting: TaskModelRoutingConfigsearchApiConfig: SearchApiConfigembeddingConfig: EmbeddingConfigmultimodalConfig: MultimodalConfig@@ -399,6 +407,7 @@ interface WikiState {setLlmConfig: (config: LlmConfig) => voidsetProviderConfigs: (configs: ProviderConfigs) => voidsetActivePresetId: (id: string | null) => void+ setTaskModelRouting: (config: TaskModelRoutingConfig) => voidsetSearchApiConfig: (config: SearchApiConfig) => voidsetEmbeddingConfig: (config: EmbeddingConfig) => voidsetMultimodalConfig: (config: MultimodalConfig) => void@@ -438,6 +447,10 @@ export const useWikiStore = create<WikiState>((set) => ({},providerConfigs: {},activePresetId: null,+ taskModelRouting: {+ chatPresetId: null,+ ingestPresetId: null,+ },dataVersion: 0,@@ -582,6 +595,7 @@ export const useWikiStore = create<WikiState>((set) => ({setLlmConfig: (llmConfig) => set({ llmConfig }),setProviderConfigs: (providerConfigs) => set({ providerConfigs }),setActivePresetId: (activePresetId) => set({ activePresetId }),+ setTaskModelRouting: (taskModelRouting) => set({ taskModelRouting }),setSearchApiConfig: (searchApiConfig) => set({ searchApiConfig }),setEmbeddingConfig: (embeddingConfig) => set({ embeddingConfig }),setMultimodalConfig: (multimodalConfig) => set({ multimodalConfig }),