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: filter raw sources by name or path
nash_subed0b65c113d
diff --git a/src/components/sources/sources-view.test.ts b/src/components/sources/sources-view.test.tsnew file mode 100644index 00000000..bdd1f62b--- /dev/null+++ b/src/components/sources/sources-view.test.ts@@ -0,0 +1,41 @@+import { describe, expect, it } from "vitest"+import type { FileNode } from "@/types/wiki"+import { filterSourceTreeByQuery } from "./sources-view"++const TREE: FileNode[] = [+ {+ name: "Books",+ path: "/project/raw/sources/Books",+ is_dir: true,+ children: [+ { name: "BookA.md", path: "/project/raw/sources/Books/BookA.md", is_dir: false },+ { name: "三阶段治疗模型.pdf", path: "/project/raw/sources/Books/三阶段治疗模型.pdf", is_dir: false },+ ],+ },+ { name: "notes.txt", path: "/project/raw/sources/notes.txt", is_dir: false },+]++describe("filterSourceTreeByQuery", () => {+ it("keeps parent folders while removing non-matching siblings", () => {+ const result = filterSourceTreeByQuery(TREE, "booka")+ expect(result).toHaveLength(1)+ expect(result[0].name).toBe("Books")+ expect(result[0].children?.map((node) => node.name)).toEqual(["BookA.md"])+ })++ it("matches Unicode names and normalized path segments", () => {+ expect(filterSourceTreeByQuery(TREE, "治疗模型")[0].children?.[0].name)+ .toBe("三阶段治疗模型.pdf")+ expect(filterSourceTreeByQuery(TREE, "BOOKS")).toEqual([TREE[0]])+ })++ it("returns a new top-level array for an empty query without mutating nodes", () => {+ const result = filterSourceTreeByQuery(TREE, " ")+ expect(result).toEqual(TREE)+ expect(result).not.toBe(TREE)+ })++ it("returns an empty tree when no source matches", () => {+ expect(filterSourceTreeByQuery(TREE, "missing source")).toEqual([])+ })+})diff --git a/src/components/sources/sources-view.tsx b/src/components/sources/sources-view.tsxindex 9c013731..135a5134 100644--- a/src/components/sources/sources-view.tsx+++ b/src/components/sources/sources-view.tsx@@ -1,7 +1,8 @@import { useState, useEffect, useCallback, useMemo, useRef } from "react"import { open } from "@tauri-apps/plugin-dialog"-import { Plus, FileText, RefreshCw, BookOpen, Trash2, Folder, ChevronRight, ChevronDown, Link, ExternalLink } from "lucide-react"+import { Plus, FileText, RefreshCw, BookOpen, Trash2, Folder, ChevronRight, ChevronDown, Link, ExternalLink, Search, X } from "lucide-react"import { Button } from "@/components/ui/button"+import { Input } from "@/components/ui/input"import { ScrollArea } from "@/components/ui/scroll-area"import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"import { useWikiStore } from "@/stores/wiki-store"@@ -50,6 +51,7 @@ export function SourcesView() {const [urlResults, setUrlResults] = useState<UrlImportResult[]>([])const [ingestedIdentities, setIngestedIdentities] = useState<string[]>([])const [queueSnapshot, setQueueSnapshot] = useState<IngestTask[]>(() => [...getQueue()])+ const [sourceQuery, setSourceQuery] = useState("")/*** Path of the source-tree node currently in "click again to* confirm delete" state. Lifted up here (rather than living@@ -90,6 +92,10 @@ export function SourcesView() {loadSources()}, [loadSources, dataVersion])+ useEffect(() => {+ setSourceQuery("")+ }, [project?.id])+useEffect(() => {if (!project) {setIngestedIdentities([])@@ -129,6 +135,12 @@ export function SourcesView() {}return statuses}, [ingestedIdentities, project, queueSnapshot])+ const filteredSources = useMemo(+ () => filterSourceTreeByQuery(sources, sourceQuery),+ [sourceQuery, sources],+ )+ const totalSourceCount = useMemo(() => countFiles(sources), [sources])+ const filteredSourceCount = useMemo(() => countFiles(filteredSources), [filteredSources])async function handleRefreshSources() {if (!project || refreshing) return@@ -424,6 +436,33 @@ export function SourcesView() {</DialogContent></Dialog>+ {sources.length > 0 && (+ <div className="border-b px-4 py-2.5">+ <div className="relative">+ <Search className="pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />+ <Input+ value={sourceQuery}+ onChange={(event) => setSourceQuery(event.target.value)}+ placeholder={t("sources.searchPlaceholder")}+ aria-label={t("sources.searchPlaceholder")}+ className="h-8 pl-8 pr-8"+ />+ {sourceQuery && (+ <Button+ type="button"+ variant="ghost"+ size="icon"+ className="absolute right-0.5 top-1/2 h-7 w-7 -translate-y-1/2"+ onClick={() => setSourceQuery("")}+ aria-label={t("sources.clearSearch")}+ >+ <X className="h-3.5 w-3.5" />+ </Button>+ )}+ </div>+ </div>+ )}+<ScrollArea className="min-h-0 flex-1 overflow-hidden">{refreshError && (<div className="mx-4 mt-3 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive">@@ -448,10 +487,14 @@ export function SourcesView() {</Button></div></div>+ ) : filteredSources.length === 0 ? (+ <div className="flex h-32 items-center justify-center px-6 text-center text-sm text-muted-foreground">+ {t("sources.noSearchResults", { query: sourceQuery.trim() })}+ </div>) : (<div className="p-2"><SourceTree- nodes={sources}+ nodes={filteredSources}onOpen={handleOpenSource}onOpenExternal={handleOpenSourceExternally}onIngest={handleIngest}@@ -461,13 +504,21 @@ export function SourcesView() {setPendingDeletePath={setPendingDeletePath}ingestingPath={ingestingPath}sourceStatuses={sourceStatuses}+ forceExpanded={Boolean(sourceQuery.trim())}/></div>)}</ScrollArea><div className="flex items-center justify-between gap-2 border-t px-4 py-2 text-xs text-muted-foreground">- <span>{t("sources.sourceCount", { count: countFiles(sources) })}</span>+ <span>+ {sourceQuery.trim()+ ? t("sources.filteredSourceCount", {+ count: filteredSourceCount,+ total: totalSourceCount,+ })+ : t("sources.sourceCount", { count: totalSourceCount })}+ </span><Tooltip><TooltipTriggerrender={@@ -510,6 +561,28 @@ function countFiles(nodes: FileNode[]): number {return count}+export function filterSourceTreeByQuery(+ nodes: readonly FileNode[],+ query: string,+): FileNode[] {+ const needle = query.trim().normalize("NFKC").toLocaleLowerCase()+ if (!needle) return [...nodes]++ const visit = (node: FileNode): FileNode | null => {+ const haystack = `${node.name}\n${normalizePath(node.path)}`+ .normalize("NFKC")+ .toLocaleLowerCase()+ if (haystack.includes(needle)) return node+ if (!node.is_dir || !node.children) return null+ const children = node.children+ .map(visit)+ .filter((child): child is FileNode => child !== null)+ return children.length > 0 ? { ...node, children } : null+ }++ return nodes.map(visit).filter((node): node is FileNode => node !== null)+}+function sortSourceNodes(nodes: readonly FileNode[]): FileNode[] {return [...nodes].sort((a, b) => {if (a.is_dir && !b.is_dir) return -1@@ -544,6 +617,7 @@ function SourceTree({setPendingDeletePath,ingestingPath,sourceStatuses,+ forceExpanded,}: {nodes: FileNode[]onOpen: (node: FileNode) => void@@ -559,12 +633,16 @@ function SourceTree({setPendingDeletePath: (path: string | null) => voidingestingPath: string | nullsourceStatuses: ReadonlyMap<string, SourceIngestStatus>+ forceExpanded: boolean}) {const { t } = useTranslation()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 rows = useMemo(+ () => flattenVisibleRows(nodes, forceExpanded ? {} : collapsed),+ [collapsed, forceExpanded, nodes],+ )const visibleRows = rows.slice(0, visibleLimit)const hasMore = visibleLimit < rows.length@@ -619,7 +697,7 @@ function SourceTree({const isPendingDelete = pendingDeletePath === node.pathconst ingestStatus = sourceStatuses.get(normalizePath(node.path)) ?? "not-ingested"if (node.is_dir && node.children) {- const isCollapsed = collapsed[node.path] ?? false+ const isCollapsed = !forceExpanded && (collapsed[node.path] ?? false)return (<div key={node.path}><div@@ -627,7 +705,9 @@ function SourceTree({style={{ paddingLeft: `${depth * 16 + 4}px` }}><button- onClick={() => toggle(node.path)}+ onClick={() => {+ if (!forceExpanded) toggle(node.path)+ }}className="flex flex-1 items-center gap-1.5 px-1 py-1 text-left">{isCollapsed ? (diff --git a/src/i18n/en.json b/src/i18n/en.jsonindex 6c28caf3..2d722aa9 100644--- a/src/i18n/en.json+++ b/src/i18n/en.json@@ -207,6 +207,10 @@"confirm": "Confirm","loadingMore": "Loading more sources...","sourceCount": "{{count}} source",+ "searchPlaceholder": "Filter sources by name or path",+ "clearSearch": "Clear source filter",+ "noSearchResults": "No sources match “{{query}}”",+ "filteredSourceCount": "{{count}} of {{total}} sources","sourceCount_plural": "{{count}} sources"},"chat": {diff --git a/src/i18n/it.json b/src/i18n/it.jsonindex ab5e88e8..765ba4dd 100644--- a/src/i18n/it.json+++ b/src/i18n/it.json@@ -207,6 +207,10 @@"confirm": "Conferma","loadingMore": "Caricamento di altre fonti...","sourceCount": "{{count}} fonte",+ "searchPlaceholder": "Filtra le fonti per nome o percorso",+ "clearSearch": "Cancella filtro fonti",+ "noSearchResults": "Nessuna fonte corrisponde a “{{query}}”",+ "filteredSourceCount": "{{count}} di {{total}} fonti","sourceCount_plural": "{{count}} fonti"},"chat": {diff --git a/src/i18n/ru.json b/src/i18n/ru.jsonindex c8d7d1b4..98483e7c 100644--- a/src/i18n/ru.json+++ b/src/i18n/ru.json@@ -207,6 +207,10 @@"confirm": "Подтвердить","loadingMore": "Загрузка дополнительных источников...","sourceCount": "{{count}} источник",+ "searchPlaceholder": "Фильтр источников по имени или пути",+ "clearSearch": "Очистить фильтр источников",+ "noSearchResults": "Нет источников по запросу «{{query}}»",+ "filteredSourceCount": "{{count}} из {{total}} источников","sourceCount_plural": "{{count}} источников"},"chat": {diff --git a/src/i18n/zh.json b/src/i18n/zh.jsonindex 05064457..9a522f9a 100644--- a/src/i18n/zh.json+++ b/src/i18n/zh.json@@ -207,6 +207,10 @@"confirm": "确认","loadingMore": "加载更多资料...","sourceCount": "{{count}} 个资料",+ "searchPlaceholder": "按名称或路径筛选原始资料",+ "clearSearch": "清除资料筛选",+ "noSearchResults": "没有匹配“{{query}}”的原始资料",+ "filteredSourceCount": "显示 {{count}} / {{total}} 个资料","sourceCount_plural": "{{count}} 个资料"},"chat": {