Skip to content

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: add Sources view with file import via native file picker

nash_su8643aa1b4d07
diff --git a/src-tauri/src/commands/fs.rs b/src-tauri/src/commands/fs.rs
index 43a4a8d8..3db8cfe7 100644
--- a/src-tauri/src/commands/fs.rs
+++ b/src-tauri/src/commands/fs.rs
@@ -93,6 +93,18 @@ fn build_tree(dir: &Path, depth: usize, max_depth: usize) -> Result<Vec<FileNode
Ok(nodes)
}
+#[tauri::command]
+pub fn copy_file(source: String, destination: String) -> Result<(), String> {
+ let dest = Path::new(&destination);
+ if let Some(parent) = dest.parent() {
+ fs::create_dir_all(parent)
+ .map_err(|e| format!("Failed to create parent dirs: {}", e))?;
+ }
+ fs::copy(&source, &destination)
+ .map_err(|e| format!("Failed to copy '{}' to '{}': {}", source, destination, e))?;
+ Ok(())
+}
+
#[tauri::command]
pub fn create_directory(path: String) -> Result<(), String> {
fs::create_dir_all(&path)
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 60f0f30a..a07b69c3 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -10,6 +10,7 @@ pub fn run() {
commands::fs::read_file,
commands::fs::write_file,
commands::fs::list_directory,
+ commands::fs::copy_file,
commands::fs::create_directory,
commands::project::create_project,
commands::project::open_project,
diff --git a/src/commands/fs.ts b/src/commands/fs.ts
index 255dddbd..a5131f1d 100644
--- a/src/commands/fs.ts
+++ b/src/commands/fs.ts
@@ -13,6 +13,13 @@ export async function listDirectory(path: string): Promise<FileNode[]> {
return invoke<FileNode[]>("list_directory", { path })
}
+export async function copyFile(
+ source: string,
+ destination: string
+): Promise<void> {
+ return invoke("copy_file", { source, destination })
+}
+
export async function createDirectory(path: string): Promise<void> {
return invoke<void>("create_directory", { path })
}
diff --git a/src/components/layout/content-area.tsx b/src/components/layout/content-area.tsx
index da227ecd..7de9eab6 100644
--- a/src/components/layout/content-area.tsx
+++ b/src/components/layout/content-area.tsx
@@ -1,10 +1,10 @@
import { useEffect, useCallback, useRef } from "react"
-import { Group, Panel, Separator } from "react-resizable-panels"
import { useWikiStore } from "@/stores/wiki-store"
import { readFile, writeFile } from "@/commands/fs"
import { WikiEditor } from "@/components/editor/wiki-editor"
import { ChatBar } from "./chat-bar"
import { SettingsView } from "@/components/settings/settings-view"
+import { SourcesView } from "@/components/sources/sources-view"
export function ContentArea() {
const selectedFile = useWikiStore((s) => s.selectedFile)
@@ -47,6 +47,10 @@ export function ContentArea() {
return <SettingsView />
}
+ if (activeView === "sources") {
+ return <SourcesView />
+ }
+
const isMarkdown = selectedFile?.endsWith(".md")
const editorContent = (
@@ -82,14 +86,12 @@ export function ContentArea() {
}
return (
- <Group orientation="vertical" className="h-full">
- <Panel defaultSize={60} minSize={30}>
- {editorContent}
- </Panel>
- <Separator className="h-1.5 cursor-row-resize bg-border/40 transition-colors hover:bg-primary/30" />
- <Panel defaultSize={40} minSize={20}>
+ <div className="flex h-full min-w-0 flex-col overflow-hidden">
+ <div className="flex-1 overflow-hidden">{editorContent}</div>
+ <div className="h-1.5 shrink-0 cursor-row-resize bg-border/40 transition-colors hover:bg-primary/30" />
+ <div className="h-64 shrink-0 overflow-hidden">
<ChatBar />
- </Panel>
- </Group>
+ </div>
+ </div>
)
}
diff --git a/src/components/sources/sources-view.tsx b/src/components/sources/sources-view.tsx
new file mode 100644
index 00000000..65db3747
--- /dev/null
+++ b/src/components/sources/sources-view.tsx
@@ -0,0 +1,136 @@
+import { useState, useEffect, useCallback } from "react"
+import { open } from "@tauri-apps/plugin-dialog"
+import { Plus, FileText, Trash2, RefreshCw } from "lucide-react"
+import { Button } from "@/components/ui/button"
+import { ScrollArea } from "@/components/ui/scroll-area"
+import { useWikiStore } from "@/stores/wiki-store"
+import { copyFile, listDirectory, readFile } from "@/commands/fs"
+import type { FileNode } from "@/types/wiki"
+
+export function SourcesView() {
+ const project = useWikiStore((s) => s.project)
+ const setSelectedFile = useWikiStore((s) => s.setSelectedFile)
+ const setActiveView = useWikiStore((s) => s.setActiveView)
+ const setFileContent = useWikiStore((s) => s.setFileContent)
+ const [sources, setSources] = useState<FileNode[]>([])
+ const [importing, setImporting] = useState(false)
+
+ const loadSources = useCallback(async () => {
+ if (!project) return
+ try {
+ const tree = await listDirectory(`${project.path}/raw/sources`)
+ const files = flattenFiles(tree)
+ setSources(files)
+ } catch {
+ setSources([])
+ }
+ }, [project])
+
+ useEffect(() => {
+ loadSources()
+ }, [loadSources])
+
+ async function handleImport() {
+ if (!project) return
+
+ const selected = await open({
+ multiple: true,
+ title: "Import Source Files",
+ filters: [
+ {
+ name: "Documents",
+ extensions: ["md", "txt", "pdf", "html", "htm", "json", "csv"],
+ },
+ { name: "All Files", extensions: ["*"] },
+ ],
+ })
+
+ if (!selected || selected.length === 0) return
+
+ setImporting(true)
+ const paths = Array.isArray(selected) ? selected : [selected]
+
+ for (const sourcePath of paths) {
+ const fileName = sourcePath.split("/").pop() || sourcePath.split("\\").pop() || "unknown"
+ const destPath = `${project.path}/raw/sources/${fileName}`
+ try {
+ await copyFile(sourcePath, destPath)
+ } catch (err) {
+ console.error(`Failed to import ${fileName}:`, err)
+ }
+ }
+
+ setImporting(false)
+ await loadSources()
+ }
+
+ async function handleOpenSource(node: FileNode) {
+ setActiveView("wiki")
+ setSelectedFile(node.path)
+ try {
+ const content = await readFile(node.path)
+ setFileContent(content)
+ } catch (err) {
+ console.error("Failed to read source:", err)
+ }
+ }
+
+ return (
+ <div className="flex h-full flex-col">
+ <div className="flex items-center justify-between border-b px-4 py-3">
+ <h2 className="text-sm font-semibold">Raw Sources</h2>
+ <div className="flex gap-1">
+ <Button variant="ghost" size="icon" onClick={loadSources} title="Refresh">
+ <RefreshCw className="h-4 w-4" />
+ </Button>
+ <Button size="sm" onClick={handleImport} disabled={importing}>
+ <Plus className="mr-1 h-4 w-4" />
+ {importing ? "Importing..." : "Import"}
+ </Button>
+ </div>
+ </div>
+
+ <ScrollArea className="flex-1">
+ {sources.length === 0 ? (
+ <div className="flex flex-col items-center justify-center gap-3 p-8 text-center text-sm text-muted-foreground">
+ <p>No sources yet</p>
+ <p>Import documents to start building your wiki</p>
+ <Button variant="outline" size="sm" onClick={handleImport}>
+ <Plus className="mr-1 h-4 w-4" />
+ Import Files
+ </Button>
+ </div>
+ ) : (
+ <div className="p-2">
+ {sources.map((source) => (
+ <button
+ key={source.path}
+ onClick={() => handleOpenSource(source)}
+ className="flex w-full items-center gap-2 rounded-md px-3 py-2 text-left text-sm text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground"
+ >
+ <FileText className="h-4 w-4 shrink-0" />
+ <span className="truncate">{source.name}</span>
+ </button>
+ ))}
+ </div>
+ )}
+ </ScrollArea>
+
+ <div className="border-t px-4 py-2 text-xs text-muted-foreground">
+ {sources.length} source{sources.length !== 1 ? "s" : ""}
+ </div>
+ </div>
+ )
+}
+
+function flattenFiles(nodes: FileNode[]): FileNode[] {
+ const files: FileNode[] = []
+ for (const node of nodes) {
+ if (node.is_dir && node.children) {
+ files.push(...flattenFiles(node.children))
+ } else if (!node.is_dir) {
+ files.push(node)
+ }
+ }
+ return files
+}