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: harden configurable ingest reasoning
nash_su57c5576dc15b
diff --git a/README.md b/README.mdindex c6b0d216..47020c0a 100644--- a/README.md+++ b/README.md@@ -405,7 +405,7 @@ Download from [Releases](https://github.com/nashsu/llm_wiki/releases):### Build from Source```bash-# Prerequisites: Node.js 20+, Rust 1.70+, protoc+# Prerequisites: Node.js 20+, Rust 1.88+, protoc# macOS: brew install protobuf# Linux: sudo apt install protobuf-compiler# Windows: choco install protocdiff --git a/README_CN.md b/README_CN.mdindex 456dd6cb..66730ca0 100644--- a/README_CN.md+++ b/README_CN.md@@ -405,7 +405,7 @@ LLM Wiki 是一个跨平台桌面应用,能将你的文档自动转化为有### 从源码构建```bash-# 前置条件:Node.js 20+, Rust 1.70+, protoc+# 前置条件:Node.js 20+, Rust 1.88+, protoc# macOS: brew install protobuf# Linux: sudo apt install protobuf-compiler# Windows:choco install protocdiff --git a/README_JA.md b/README_JA.mdindex 22030385..3424e940 100644--- a/README_JA.md+++ b/README_JA.md@@ -414,7 +414,7 @@ LLM Wiki は、手元の文書を整理された相互リンク付きの知識### ソースからビルド```bash-# 前提条件: Node.js 20+, Rust 1.70+, protoc+# 前提条件: Node.js 20+, Rust 1.88+, protoc# macOS: brew install protobuf# Linux: sudo apt install protobuf-compiler# Windows: choco install protocdiff --git a/README_KO.md b/README_KO.mdindex 71350b05..03ba8782 100644--- a/README_KO.md+++ b/README_KO.md@@ -414,16 +414,16 @@ LLM Wiki는 문서를 자동으로 정리되고 서로 연결된 지식 베이### 소스에서 빌드```bash-# Prerequisites: Node.js 20+, Rust 1.70+, protoc+# 사전 요구 사항: Node.js 20+, Rust 1.88+, protoc# macOS: brew install protobuf# Linux: sudo apt install protobuf-compiler# Windows: choco install protocgit clone https://github.com/nashsu/llm_wiki.gitcd llm_wikinpm install-npm --prefix mcp-server ci && npm run mcp:build # mcp-server/dist is bundled as a Tauri resource-npm run tauri dev # Development-npm run tauri build # Production build+npm --prefix mcp-server ci && npm run mcp:build # mcp-server/dist는 Tauri 리소스로 번들됩니다+npm run tauri dev # 개발 모드+npm run tauri build # 프로덕션 빌드```### Chrome Extensiondiff --git a/src/components/settings/preset-resolver.test.ts b/src/components/settings/preset-resolver.test.tsindex 73520da1..72789fc0 100644--- a/src/components/settings/preset-resolver.test.ts+++ b/src/components/settings/preset-resolver.test.ts@@ -94,6 +94,27 @@ describe("resolveConfig", () => {expect(resolved.reasoning).toEqual({ mode: "off" })})+ it("keeps ingest reasoning separate from chat reasoning", () => {+ const preset: LlmPreset = {+ id: "openai",+ label: "OpenAI",+ provider: "openai",+ defaultModel: "gpt-5",+ }++ const resolved = resolveConfig(+ preset,+ {+ reasoning: { mode: "high" },+ ingestReasoning: { mode: "low" },+ },+ fallbackConfig(),+ )++ expect(resolved.reasoning).toEqual({ mode: "high" })+ expect(resolved.ingestReasoning).toEqual({ mode: "low" })+ })+it("preserves an explicit non-streaming provider preference", () => {const preset: LlmPreset = {id: "openai",diff --git a/src/components/settings/sections/llm-provider-section.tsx b/src/components/settings/sections/llm-provider-section.tsxindex 36aac719..81ce0f8b 100644--- a/src/components/settings/sections/llm-provider-section.tsx+++ b/src/components/settings/sections/llm-provider-section.tsx@@ -776,13 +776,8 @@ function PresetRow({value={ingestReasoning}config={resolvedConfig}onChange={(ingestReasoning) => onChange({ ingestReasoning })}- title={t("settings.sections.llm.reasoning.ingestTitle", {- defaultValue: "Reasoning during ingest",- })}- hint={t("settings.sections.llm.reasoning.ingestHint", {- defaultValue:- "Off is usually right: ingest asks for structured output and thinking costs time without helping. Raise it only if the model refuses to run with reasoning disabled.",- })}+ title={t("settings.sections.llm.reasoning.ingestTitle")}+ hint={t("settings.sections.llm.reasoning.ingestHint")}/><div className="space-y-2 rounded-md border p-3">@@ -922,9 +917,11 @@ function ReasoningControls({</span></div>)}- <p className="text-xs text-muted-foreground">- {t("settings.sections.llm.reasoning.hint")}- </p>+ {!hint && (+ <p className="text-xs text-muted-foreground">+ {t("settings.sections.llm.reasoning.hint")}+ </p>+ )}</div>)}diff --git a/src/components/settings/settings-types.ts b/src/components/settings/settings-types.tsindex 4712f575..8c0b3ef2 100644--- a/src/components/settings/settings-types.ts+++ b/src/components/settings/settings-types.ts@@ -19,6 +19,7 @@ export interface SettingsDraft {maxContextSize: numberapiMode: CustomApiMode | undefinedreasoning: ReasoningConfig | undefined+ ingestReasoning: ReasoningConfig | undefinedlocalCliIsolation: boolean// Embeddingdiff --git a/src/components/settings/settings-view.tsx b/src/components/settings/settings-view.tsxindex 000b316e..f8ce46d2 100644--- a/src/components/settings/settings-view.tsx+++ b/src/components/settings/settings-view.tsx@@ -129,6 +129,7 @@ function initialDraft(maxContextSize: llm.maxContextSize ?? 204800,apiMode: llm.apiMode,reasoning: llm.reasoning,+ ingestReasoning: llm.ingestReasoning,localCliIsolation: llm.localCliIsolation === true,embeddingEnabled: embed.enabled,embeddingEndpoint: embed.endpoint,@@ -367,6 +368,7 @@ export function SettingsView() {maxContextSize: draft.maxContextSize,apiMode: draft.provider === "custom" ? draft.apiMode : undefined,reasoning: draft.reasoning,+ ingestReasoning: draft.ingestReasoning,localCliIsolation: draft.localCliIsolation,}const newEmbed = {diff --git a/src/i18n/en.json b/src/i18n/en.jsonindex e071f2fe..b62b9e4e 100644--- a/src/i18n/en.json+++ b/src/i18n/en.json@@ -620,7 +620,7 @@"custom": "Custom","budgetTokens": "thinking budget tokens",- "hint": "Structured tasks such as ingest may override this to Off to avoid reasoning-only responses.",+ "hint": "Controls reasoning for chat. Document ingest uses the separate setting below.","ingestTitle": "Reasoning during ingest","ingestHint": "Off is usually right: ingest asks for structured output and thinking costs time without helping. Raise it only if the model refuses to run with reasoning disabled."}diff --git a/src/i18n/it.json b/src/i18n/it.jsonindex 6c6c3eab..201c2551 100644--- a/src/i18n/it.json+++ b/src/i18n/it.json@@ -620,7 +620,7 @@"custom": "Personalizzato","budgetTokens": "token di budget per il ragionamento",- "hint": "Le attività strutturate come l'elaborazione dei documenti possono forzare questo valore su Disattivo per evitare risposte di solo ragionamento.",+ "hint": "Controlla il ragionamento per la chat. L'elaborazione dei documenti usa l'impostazione separata qui sotto.","ingestTitle": "Ragionamento durante l'ingest","ingestHint": "Di norma va tenuto spento: l'ingest chiede output strutturato e il ragionamento costa tempo senza migliorarlo. Alzalo solo se il modello si rifiuta di funzionare con il ragionamento disattivato."}diff --git a/src/i18n/ru.json b/src/i18n/ru.jsonindex 1e5a034b..227d5724 100644--- a/src/i18n/ru.json+++ b/src/i18n/ru.json@@ -620,7 +620,7 @@"custom": "Пользовательское","budgetTokens": "токенов бюджета размышления",- "hint": "Структурированные задачи (например, обработка) могут переопределять этот параметр на «Выкл.», чтобы избежать ответов только с размышлением.",+ "hint": "Управляет рассуждением в чате. Для обработки документов используется отдельная настройка ниже.","ingestTitle": "Рассуждение при импорте","ingestHint": "Обычно лучше выключить: импорт запрашивает структурированный вывод, а рассуждение отнимает время, не улучшая результат. Повышайте только если модель отказывается работать с выключенным рассуждением."}diff --git a/src/i18n/zh.json b/src/i18n/zh.jsonindex b5b99ec8..594f548b 100644--- a/src/i18n/zh.json+++ b/src/i18n/zh.json@@ -620,7 +620,7 @@"custom": "自定义","budgetTokens": "thinking token 预算",- "hint": "结构化任务(如 ingest)可能会自动关闭 reasoning,避免模型只输出思考过程而没有正文。",+ "hint": "控制聊天时的推理强度;文档摄取使用下方的独立设置。","ingestTitle": "导入时的推理","ingestHint": "通常应关闭:导入需要结构化输出,推理只会增加耗时而无助于质量。仅当模型拒绝在关闭推理的情况下运行时才调高。"}diff --git a/src/lib/__tests__/llm-providers.test.ts b/src/lib/__tests__/llm-providers.test.tsindex 1f6c6611..22d24917 100644--- a/src/lib/__tests__/llm-providers.test.ts+++ b/src/lib/__tests__/llm-providers.test.ts@@ -464,6 +464,26 @@ describe("Sampling override translation across wires", () => {expect(body.max_completion_tokens).toBeUndefined()})+ it("maps OpenRouter reasoning settings to its documented request object", () => {+ const cfg = getProviderConfig({+ provider: "custom",+ apiKey: "k",+ model: "vendor/reasoning-model",+ ollamaUrl: "",+ customEndpoint: "https://openrouter.ai/api/v1",+ apiMode: "chat_completions",+ maxContextSize: 128000,+ })++ expect(cfg.buildBody(baseMessages, { reasoning: { mode: "low" } }))+ .toMatchObject({ reasoning: { effort: "low" } })+ expect(cfg.buildBody(baseMessages, { reasoning: { mode: "off" } }))+ .toMatchObject({ reasoning: { effort: "none" } })+ expect(cfg.buildBody(baseMessages, {+ reasoning: { mode: "custom", budgetTokens: 2048 },+ })).toMatchObject({ reasoning: { max_tokens: 2048 } })+ })+it("custom Kimi routes strip unsupported temperature overrides", () => {const cfg = getProviderConfig({provider: "custom",diff --git a/src/lib/dedup-runner.ts b/src/lib/dedup-runner.tsindex 893d1070..e3baf871 100644--- a/src/lib/dedup-runner.ts+++ b/src/lib/dedup-runner.ts@@ -98,13 +98,9 @@ export function buildDedupLlmCall(},},signal,- // Dedup detection + merge want JSON, never chain-of-thought.- // Like every other structured caller (ingest, connection-tests,- // vision-caption, anytxt-search), disable thinking AND cap output- // so a reasoning-capable model (an Ollama thinking model, or an- // unrecognized reasoning model behind a custom endpoint) doesn't- // spend its whole budget on reasoning and run the stream to the- // 30-min backstop — which surfaces as a bare "Request cancelled".+ // Dedup detection + merge want compact JSON. Keep the output capped;+ // reasoning defaults off but remains configurable for models that+ // require it.{ temperature: 0.1, reasoning: resolveIngestReasoning(llmConfig), max_tokens: maxTokens },).catch((err) => {streamError = err instanceof Error ? err : new Error(String(err))diff --git a/src/lib/ingest-reasoning.test.ts b/src/lib/ingest-reasoning.test.tsindex 41a7c620..4596e323 100644--- a/src/lib/ingest-reasoning.test.ts+++ b/src/lib/ingest-reasoning.test.ts@@ -33,10 +33,7 @@ describe("ingest reasoning is settable instead of hardcoded off", () => {expect(config.reasoning).toEqual({ mode: "high" })})- it("is not normalized here, so off cannot decay to auto on auto-only providers", () => {- // Normalizing in both places turned "off" into "auto" for providers whose- // capability list is auto-only, silently re-enabling the thinking that- // ingest disables on purpose. The provider layer normalizes; this does not.+ it("leaves provider normalization to the wire builder", () => {const autoOnly: LlmConfig = {...openAiConfig,provider: "custom",diff --git a/src/lib/ingest.ts b/src/lib/ingest.tsindex 79026fa3..82c27aed 100644--- a/src/lib/ingest.ts+++ b/src/lib/ingest.ts@@ -317,6 +317,9 @@ function resolveCaptionConfig(azureApiVersion: mm.azureApiVersion,azureModelFamily: mm.azureModelFamily,apiMode: mm.apiMode,+ // The dedicated caption provider has no separate reasoning control. Reuse+ // the ingest preference and let its own provider capabilities normalize it.+ ingestReasoning: mainLlm.ingestReasoning,// The caption helper hits `streamChat` directly, which doesn't// care about `maxContextSize` (that field is for the analysis// / generation prompt-truncation logic). Keep it set so thediff --git a/src/lib/llm-providers.ts b/src/lib/llm-providers.tsindex ad780525..2009c7f0 100644--- a/src/lib/llm-providers.ts+++ b/src/lib/llm-providers.ts@@ -8,6 +8,7 @@ import {import {isAdaptiveAnthropicModel,isGeminiThinkingLevelModel,+ isOpenRouterEndpoint,normalizeReasoningForProvider,} from "@/lib/reasoning-capabilities"@@ -463,6 +464,15 @@ function buildOpenAiCompatibleBody(adaptKimiBody(config, body)adaptXiaomiMimoBody(config, body, reasoning)+ if (config.provider === "custom" && isOpenRouterEndpoint(config.customEndpoint)) {+ if (reasoning.mode === "custom" && reasoning.budgetTokens !== undefined) {+ body.reasoning = { max_tokens: reasoning.budgetTokens }+ } else if (reasoning.mode !== "auto") {+ body.reasoning = { effort: reasoning.mode === "off" ? "none" : reasoning.mode }+ }+ return body+ }+if (isDeepSeekEndpoint(config)) {// DeepSeek V4 thinking mode. `thinking.type=disabled` is the most// important path for ingestion/rewrite tasks: it prevents the modeldiff --git a/src/lib/reasoning-capabilities.test.ts b/src/lib/reasoning-capabilities.test.tsindex 52c9a732..e8b40a67 100644--- a/src/lib/reasoning-capabilities.test.ts+++ b/src/lib/reasoning-capabilities.test.ts@@ -20,6 +20,17 @@ describe("reasoning capabilities", () => {expect(normalizeReasoningForProvider(cfg, { mode: "off" })).toEqual({ mode: "auto" })})+ it("offers OpenRouter's documented reasoning controls only on its endpoint", () => {+ const cfg = {+ ...config("custom", "vendor/reasoning-model"),+ customEndpoint: "https://openrouter.ai/api/v1",+ }++ expect(resolveReasoningCapabilities(cfg).modes)+ .toEqual(["auto", "off", "low", "medium", "high", "max", "custom"])+ expect(normalizeReasoningForProvider(cfg, { mode: "low" })).toEqual({ mode: "low" })+ })+it("does not offer off for thinking-required Gemini and Claude models", () => {expect(resolveReasoningCapabilities(config("google", "gemini-2.5-pro")).modes).not.toContain("off")diff --git a/src/lib/reasoning-capabilities.ts b/src/lib/reasoning-capabilities.tsindex 26e6abcc..a10321d7 100644--- a/src/lib/reasoning-capabilities.ts+++ b/src/lib/reasoning-capabilities.ts@@ -54,6 +54,15 @@ function isOpenAiReasoningModel(config: LlmConfig): boolean {return /^(?:gpt-5|o\d+)(?:[.\-_]|$)/.test(model)}+export function isOpenRouterEndpoint(endpoint: string): boolean {+ try {+ const hostname = new URL(endpoint).hostname.toLowerCase()+ return hostname === "openrouter.ai" || hostname.endsWith(".openrouter.ai")+ } catch {+ return false+ }+}+/*** Resolve only capabilities that are part of the selected wire contract.* Generic custom gateways deliberately stay Auto-only: a vendor-looking@@ -84,6 +93,7 @@ export function resolveReasoningCapabilities(config: LlmConfig): ReasoningCapabi}if (config.provider === "custom") {const endpoint = config.customEndpoint.toLowerCase()+ if (isOpenRouterEndpoint(endpoint)) return capabilities(BUDGET_LEVELS)if (/api\.deepseek\.(?:com|cn)(?:[:/]|$)/.test(endpoint)) {return capabilities(DEEPSEEK_LEVELS)}@@ -116,10 +126,9 @@ export function normalizeReasoningForProvider(* what lets those providers be used; "off" stays the default so existing* setups behave exactly as before.*- * Deliberately not normalized here: the provider layer already normalizes when- * it builds the payload, and normalizing twice turns "off" into "auto" for- * providers whose capability list is auto-only, quietly re-enabling the- * thinking ingest disables on purpose.+ * Keep this helper provider-agnostic. The provider layer normalizes the saved+ * value once when it builds the wire payload, including stale settings left by+ * a provider or model change.*/export function resolveIngestReasoning(config: LlmConfig): ReasoningConfig {return config.ingestReasoning ?? { mode: "off" }diff --git a/src/lib/vision-caption.ts b/src/lib/vision-caption.tsindex 465c964a..a5e1786a 100644--- a/src/lib/vision-caption.ts+++ b/src/lib/vision-caption.ts@@ -215,11 +215,8 @@ export async function captionImage({temperature: options?.temperature ?? 0,max_tokens: options?.maxTokens ?? 4096,- // Captioning is a short factual vision task. If the main LLM is- // configured as a reasoning model, inheriting that setting here- // often burns the small caption budget on thinking and produces- // no usable alt text. Disable reasoning for caption calls unless- // this helper grows an explicit caption-reasoning option.+ // Captioning is a short factual vision task, so reasoning defaults off.+ // The ingest preference can enable it for models that require thinking.reasoning: resolveIngestReasoning(llmConfig),},)diff --git a/src/stores/wiki-store.ts b/src/stores/wiki-store.tsindex 863b7732..cbf64f3e 100644--- a/src/stores/wiki-store.ts+++ b/src/stores/wiki-store.ts@@ -35,8 +35,6 @@ interface LlmConfig {maxContextSize: number // max context window in charactersapiMode?: CustomApiModereasoning?: ReasoningConfig- /** Reasoning for ingest's structured calls. See LlmConfig.ingestReasoning. */- ingestReasoning?: ReasoningConfig/*** Reasoning for ingest's structured calls (analysis, page generation,* captioning, dedup), kept separate from `reasoning` because the two want@@ -345,6 +343,8 @@ export interface ProviderOverride {apiMode?: CustomApiModemaxContextSize?: numberreasoning?: ReasoningConfig+ /** Reasoning used by structured ingest calls; defaults to off. */+ ingestReasoning?: ReasoningConfiglocalCliIsolation?: booleancodexCliTimeoutMinutes?: numberrequestTimeoutMinutes?: number