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
Improve source list loading and GPT-5 compatibility
nash_sufd21f3f546d0
diff --git a/src/components/sources/sources-view.tsx b/src/components/sources/sources-view.tsxindex b9128499..f9b87a7c 100644--- a/src/components/sources/sources-view.tsx+++ b/src/components/sources/sources-view.tsx@@ -1,4 +1,4 @@-import { useState, useEffect, useCallback } from "react"+import { useState, useEffect, useCallback, useMemo, useRef } from "react"import { open } from "@tauri-apps/plugin-dialog"import { Plus, FileText, RefreshCw, BookOpen, Trash2, Folder, ChevronRight, ChevronDown } from "lucide-react"import { Button } from "@/components/ui/button"@@ -17,6 +17,9 @@ import {importSourceFolder,} from "@/lib/source-lifecycle"+const SOURCE_TREE_INITIAL_ROWS = 160+const SOURCE_TREE_LOAD_BATCH = 160+export function SourcesView() {const { t } = useTranslation()const project = useWikiStore((s) => s.project)@@ -277,7 +280,6 @@ export function SourcesView() {pendingDeletePath={pendingDeletePath}setPendingDeletePath={setPendingDeletePath}ingestingPath={ingestingPath}- depth={0}/></div>)}@@ -290,6 +292,11 @@ export function SourcesView() {)}+interface SourceTreeRow {+ node: FileNode+ depth: number+}+function filterTree(nodes: FileNode[]): FileNode[] {return nodes.filter((n) => !n.name.startsWith("."))@@ -314,6 +321,28 @@ function countFiles(nodes: FileNode[]): number {return count}+function sortSourceNodes(nodes: readonly FileNode[]): FileNode[] {+ return [...nodes].sort((a, b) => {+ if (a.is_dir && !b.is_dir) return -1+ if (!a.is_dir && b.is_dir) return 1+ return a.name.localeCompare(b.name)+ })+}++function flattenVisibleRows(+ nodes: readonly FileNode[],+ collapsed: Record<string, boolean>,+ depth = 0,+): SourceTreeRow[] {+ const rows: SourceTreeRow[] = []+ for (const node of sortSourceNodes(nodes)) {+ rows.push({ node, depth })+ if (node.is_dir && node.children && !(collapsed[node.path] ?? false)) {+ rows.push(...flattenVisibleRows(node.children, collapsed, depth + 1))+ }+ }+ return rows+}function SourceTree({nodes,@@ -324,7 +353,6 @@ function SourceTree({pendingDeletePath,setPendingDeletePath,ingestingPath,- depth,}: {nodes: FileNode[]onOpen: (node: FileNode) => void@@ -338,9 +366,31 @@ function SourceTree({pendingDeletePath: string | nullsetPendingDeletePath: (path: string | null) => voidingestingPath: string | null- depth: number}) {const [collapsed, setCollapsed] = useState<Record<string, boolean>>({})+ const [visibleLimit, setVisibleLimit] = useState(SOURCE_TREE_INITIAL_ROWS)+ const loadMoreRef = useRef<HTMLDivElement | null>(null)+ const rows = useMemo(() => flattenVisibleRows(nodes, collapsed), [nodes, collapsed])+ const visibleRows = rows.slice(0, visibleLimit)+ const hasMore = visibleLimit < rows.length++ useEffect(() => {+ setVisibleLimit(SOURCE_TREE_INITIAL_ROWS)+ }, [nodes])++ useEffect(() => {+ if (!hasMore) return+ const target = loadMoreRef.current+ if (!target) return++ const observer = new IntersectionObserver((entries) => {+ if (!entries.some((entry) => entry.isIntersecting)) return+ setVisibleLimit((current) => Math.min(current + SOURCE_TREE_LOAD_BATCH, rows.length))+ }, { rootMargin: "240px 0px" })++ observer.observe(target)+ return () => observer.disconnect()+ }, [hasMore, rows.length])const toggle = (path: string) => {setCollapsed((prev) => ({ ...prev, [path]: !prev[path] }))@@ -369,16 +419,9 @@ function SourceTree({}}- // Sort: folders first, then files, alphabetical within each group- const sorted = [...nodes].sort((a, b) => {- if (a.is_dir && !b.is_dir) return -1- if (!a.is_dir && b.is_dir) return 1- return a.name.localeCompare(b.name)- })-return (<>- {sorted.map((node) => {+ {visibleRows.map(({ node, depth }) => {const isPendingDelete = pendingDeletePath === node.pathif (node.is_dir && node.children) {const isCollapsed = collapsed[node.path] ?? false@@ -413,19 +456,6 @@ function SourceTree({}/></div>- {!isCollapsed && (- <SourceTree- nodes={node.children}- onOpen={onOpen}- onIngest={onIngest}- onDelete={onDelete}- onDeleteFolder={onDeleteFolder}- pendingDeletePath={pendingDeletePath}- setPendingDeletePath={setPendingDeletePath}- ingestingPath={ingestingPath}- depth={depth + 1}- />- )}</div>)}@@ -465,6 +495,14 @@ function SourceTree({</div>)})}+ {hasMore && (+ <div+ ref={loadMoreRef}+ className="px-3 py-2 text-center text-[11px] text-muted-foreground"+ >+ Loading more sources...+ </div>+ )}</>)}diff --git a/src/lib/__tests__/llm-providers.test.ts b/src/lib/__tests__/llm-providers.test.tsindex 0ea8dbda..f8c28bc1 100644--- a/src/lib/__tests__/llm-providers.test.ts+++ b/src/lib/__tests__/llm-providers.test.ts@@ -300,6 +300,61 @@ describe("Sampling override translation across wires", () => {expect(body.max_tokens).toBe(500)})+ it("OpenAI GPT-5 maps max_tokens and strips unsupported sampling knobs", () => {+ const cfg = getProviderConfig({+ provider: "openai",+ apiKey: "k",+ model: "gpt-5-nano",+ ollamaUrl: "",+ customEndpoint: "",+ maxContextSize: 128000,+ })+ const body = cfg.buildBody(baseMessages, {+ temperature: 0.1,+ top_p: 0.8,+ top_k: 40,+ max_tokens: 4096,+ }) as Record<string, unknown>++ expect(body.max_completion_tokens).toBe(4096)+ expect(body.max_tokens).toBeUndefined()+ expect(body.temperature).toBeUndefined()+ expect(body.top_p).toBeUndefined()+ expect(body.top_k).toBeUndefined()+ })++ it("OpenAI o-series models use max_completion_tokens", () => {+ const cfg = getProviderConfig({+ provider: "openai",+ apiKey: "k",+ model: "o3-mini",+ ollamaUrl: "",+ customEndpoint: "",+ maxContextSize: 128000,+ })+ const body = cfg.buildBody(baseMessages, { max_tokens: 8192 }) as Record<string, unknown>++ expect(body.max_completion_tokens).toBe(8192)+ expect(body.max_tokens).toBeUndefined()+ })++ it("custom OpenAI-compatible GPT-5 routes keep legacy overrides for OpenRouter-style shims", () => {+ const cfg = getProviderConfig({+ provider: "custom",+ apiKey: "k",+ model: "gpt-5.5",+ ollamaUrl: "",+ customEndpoint: "https://openrouter.ai/api/v1",+ apiMode: "chat_completions",+ maxContextSize: 128000,+ })+ const body = cfg.buildBody(baseMessages, { temperature: 0.1, max_tokens: 500 }) as Record<string, unknown>++ expect(body.temperature).toBe(0.1)+ expect(body.max_tokens).toBe(500)+ expect(body.max_completion_tokens).toBeUndefined()+ })+it("Anthropic maps stop → stop_sequences and respects max_tokens override", () => {const cfg = getProviderConfig({provider: "anthropic",diff --git a/src/lib/llm-providers.ts b/src/lib/llm-providers.tsindex 6e5503b1..5603270c 100644--- a/src/lib/llm-providers.ts+++ b/src/lib/llm-providers.ts@@ -239,6 +239,29 @@ function isQwenThinkingModel(model: string): boolean {return /qwen[-_]?3/i.test(model)}+function isOpenAiStrictCompletionModel(config: LlmConfig): boolean {+ if (config.provider !== "openai") return false+ const model = config.model.trim().toLowerCase()+ return /^gpt-5(?:[.\-_]|$)/.test(model) || /^o\d+(?:[.\-_]|$)/.test(model)+}++function adaptOpenAiStrictCompletionBody(config: LlmConfig, body: Record<string, unknown>): void {+ if (!isOpenAiStrictCompletionModel(config)) return++ if (typeof body.max_tokens === "number") {+ body.max_completion_tokens = body.max_tokens+ delete body.max_tokens+ }++ // GPT-5 / o-series Chat Completions deployments reject non-default+ // sampling knobs. Structured ingest passes temperature=0.1, so strip+ // these only on the strict OpenAI path; custom/OpenRouter-compatible+ // routes keep their existing behavior.+ delete body.temperature+ delete body.top_p+ delete body.top_k+}+function buildOpenAiCompatibleBody(config: LlmConfig,messages: ChatMessage[],@@ -246,6 +269,7 @@ function buildOpenAiCompatibleBody(): Record<string, unknown> {const reasoning = effectiveReasoning(config, overrides)const body: Record<string, unknown> = buildOpenAiBody(messages, stripWireAgnosticOverrides(overrides))+ adaptOpenAiStrictCompletionBody(config, body)if (isDeepSeekEndpoint(config)) {// DeepSeek V4 thinking mode. `thinking.type=disabled` is the most