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

fix(multimodal): UI freeze on import + images missing from generated wiki page

nash_suec5f00e332b4
diff --git a/src-tauri/src/commands/extract_images.rs b/src-tauri/src/commands/extract_images.rs
index fcae1e11..b6f413f3 100644
--- a/src-tauri/src/commands/extract_images.rs
+++ b/src-tauri/src/commands/extract_images.rs
@@ -640,21 +640,21 @@ pub fn extract_and_save_office_images(
// ── Tauri command bindings ─────────────────────────────────────────────
#[tauri::command]
-pub fn extract_pdf_images_cmd(path: String) -> Result<Vec<ExtractedImage>, String> {
+pub async fn extract_pdf_images_cmd(path: String) -> Result<Vec<ExtractedImage>, String> {
crate::panic_guard::run_guarded("extract_pdf_images", || {
extract_pdf_images(&path, &ExtractOptions::default())
})
}
#[tauri::command]
-pub fn extract_office_images_cmd(path: String) -> Result<Vec<ExtractedImage>, String> {
+pub async fn extract_office_images_cmd(path: String) -> Result<Vec<ExtractedImage>, String> {
crate::panic_guard::run_guarded("extract_office_images", || {
extract_office_images(&path, &ExtractOptions::default())
})
}
#[tauri::command]
-pub fn extract_and_save_pdf_images_cmd(
+pub async fn extract_and_save_pdf_images_cmd(
source_path: String,
dest_dir: String,
rel_to: String,
@@ -670,7 +670,7 @@ pub fn extract_and_save_pdf_images_cmd(
}
#[tauri::command]
-pub fn extract_and_save_office_images_cmd(
+pub async fn extract_and_save_office_images_cmd(
source_path: String,
dest_dir: String,
rel_to: String,
diff --git a/src-tauri/src/commands/fs.rs b/src-tauri/src/commands/fs.rs
index 76a45037..29e7eced 100644
--- a/src-tauri/src/commands/fs.rs
+++ b/src-tauri/src/commands/fs.rs
@@ -19,7 +19,7 @@ const MEDIA_EXTS: &[&str] = &[
const LEGACY_DOC_EXTS: &[&str] = &["doc", "xls", "ppt", "pages", "numbers", "key", "epub"];
#[tauri::command]
-pub fn read_file(path: String) -> Result<String, String> {
+pub async fn read_file(path: String) -> Result<String, String> {
run_guarded("read_file", || {
let p = Path::new(&path);
let ext = p
@@ -81,7 +81,7 @@ pub fn read_file(path: String) -> Result<String, String> {
/// Pre-process a file and cache the extracted text.
#[tauri::command]
-pub fn preprocess_file(path: String) -> Result<String, String> {
+pub async fn preprocess_file(path: String) -> Result<String, String> {
run_guarded("preprocess_file", || {
let p = Path::new(&path);
let ext = p
@@ -819,7 +819,7 @@ fn extract_odf_text(archive: &mut zip::ZipArchive<fs::File>) -> Result<String, S
}
#[tauri::command]
-pub fn write_file(path: String, contents: String) -> Result<(), String> {
+pub async fn write_file(path: String, contents: String) -> Result<(), String> {
run_guarded("write_file", || {
let p = Path::new(&path);
if let Some(parent) = p.parent() {
@@ -832,7 +832,7 @@ pub fn write_file(path: String, contents: String) -> Result<(), String> {
}
#[tauri::command]
-pub fn list_directory(path: String) -> Result<Vec<FileNode>, String> {
+pub async fn list_directory(path: String) -> Result<Vec<FileNode>, String> {
run_guarded("list_directory", || {
let p = Path::new(&path);
if !p.exists() {
@@ -914,7 +914,7 @@ fn build_tree(dir: &Path, depth: usize, max_depth: usize) -> Result<Vec<FileNode
}
#[tauri::command]
-pub fn copy_file(source: String, destination: String) -> Result<(), String> {
+pub async fn copy_file(source: String, destination: String) -> Result<(), String> {
run_guarded("copy_file", || {
let dest = Path::new(&destination);
if let Some(parent) = dest.parent() {
@@ -930,7 +930,7 @@ pub fn copy_file(source: String, destination: String) -> Result<(), String> {
/// Recursively copy a directory, preserving structure.
/// Returns list of copied file paths (destination paths).
#[tauri::command]
-pub fn copy_directory(source: String, destination: String) -> Result<Vec<String>, String> {
+pub async fn copy_directory(source: String, destination: String) -> Result<Vec<String>, String> {
run_guarded("copy_directory", || {
let src = Path::new(&source);
let dest = Path::new(&destination);
@@ -983,7 +983,7 @@ pub fn copy_directory(source: String, destination: String) -> Result<Vec<String>
}
#[tauri::command]
-pub fn delete_file(path: String) -> Result<(), String> {
+pub async fn delete_file(path: String) -> Result<(), String> {
run_guarded("delete_file", || {
let p = Path::new(&path);
if p.is_dir() {
@@ -999,7 +999,7 @@ pub fn delete_file(path: String) -> Result<(), String> {
/// Find wiki pages that reference a given source file name.
/// Scans all .md files under wiki/ for the source filename in frontmatter or content.
#[tauri::command]
-pub fn find_related_wiki_pages(project_path: String, source_name: String) -> Result<Vec<String>, String> {
+pub async fn find_related_wiki_pages(project_path: String, source_name: String) -> Result<Vec<String>, String> {
run_guarded("find_related_wiki_pages", || {
let wiki_dir = Path::new(&project_path).join("wiki");
if !wiki_dir.is_dir() {
@@ -1128,7 +1128,7 @@ fn collect_related_pages(dir: &Path, source_name: &str, results: &mut Vec<String
}
#[tauri::command]
-pub fn create_directory(path: String) -> Result<(), String> {
+pub async fn create_directory(path: String) -> Result<(), String> {
run_guarded("create_directory", || {
fs::create_dir_all(&path)
.map_err(|e| format!("Failed to create directory '{}': {}", path, e))
@@ -1138,7 +1138,7 @@ pub fn create_directory(path: String) -> Result<(), String> {
/// Cheap existence check without reading or classifying the file.
/// Returns true iff `path` refers to something on disk right now.
#[tauri::command]
-pub fn file_exists(path: String) -> Result<bool, String> {
+pub async fn file_exists(path: String) -> Result<bool, String> {
run_guarded("file_exists", || Ok(Path::new(&path).exists()))
}
diff --git a/src/lib/ingest.ts b/src/lib/ingest.ts
index 9be45184..e0b02ecb 100644
--- a/src/lib/ingest.ts
+++ b/src/lib/ingest.ts
@@ -279,25 +279,32 @@ async function autoIngestImpl(
// ── Step 0.5: Extract embedded images ─────────────────────────
// Pulls every embedded image out of PDF / PPTX / DOCX into
- // `wiki/media/<source-slug>/`, returns metadata. Markdown image
- // references get appended to the source content the LLM sees, so
- // generated wiki pages can reference figures by page number even
- // though we don't have captions yet (Phase 3a). Failure here is
- // never fatal — extractAndSaveSourceImages logs + returns [] on
- // any error.
+ // `wiki/media/<source-slug>/`. We DON'T inject the markdown
+ // references into sourceContent here — without VLM captions
+ // (Phase 3a) the alt text is empty, which gives the LLM no
+ // semantic signal to preserve them. The LLM tends to silently
+ // strip empty-alt images when summarizing.
+ //
+ // Instead, the markdown section is appended to the source-summary
+ // page on disk AFTER writeFileBlocks (see Step 5b below). That
+ // guarantees images appear in `wiki/sources/<slug>.md` regardless
+ // of LLM behavior. Once Phase 3a lands, we'll re-introduce the
+ // sourceContent injection because the captioned alt-text gives
+ // the LLM something meaningful to work with.
+ //
+ // Failure here is never fatal — extractAndSaveSourceImages logs
+ // and returns [] on any error.
activity.updateItem(activityId, { detail: "Extracting embedded images..." })
const savedImages = await extractAndSaveSourceImages(pp, sp)
- const imageSection = buildImageMarkdownSection(savedImages)
- const enrichedSourceContent = sourceContent + imageSection
if (savedImages.length > 0) {
console.log(
`[ingest:images] saved ${savedImages.length} image(s) for "${fileName}" → wiki/media/${fileName.replace(/\.[^.]+$/, "")}/`,
)
}
- const truncatedContent = enrichedSourceContent.length > 50000
- ? enrichedSourceContent.slice(0, 50000) + "\n\n[...truncated...]"
- : enrichedSourceContent
+ const truncatedContent = sourceContent.length > 50000
+ ? sourceContent.slice(0, 50000) + "\n\n[...truncated...]"
+ : sourceContent
// ── Step 1: Analysis ──────────────────────────────────────────
// LLM reads the source and produces a structured analysis:
@@ -435,6 +442,44 @@ async function autoIngestImpl(
}
}
+ // ── Step 3.5: Append extracted images to the source-summary page ─
+ // Reliable image surfacing: regardless of whether the LLM kept any
+ // image references in its generated content, we directly append a
+ // "## Embedded Images" section to wiki/sources/<slug>.md with the
+ // saved image paths. The custom <img> resolver in the markdown
+ // preview takes care of rendering them.
+ //
+ // Idempotent: if a previous ingest already appended this section,
+ // we replace it rather than duplicating. The marker comment
+ // <!-- llm-wiki:embedded-images --> identifies our injection.
+ if (savedImages.length > 0 && !signal?.aborted) {
+ try {
+ const existing = await tryReadFile(sourceSummaryFullPath)
+ if (existing) {
+ const newSection = buildImageMarkdownSection(savedImages)
+ const marker = "<!-- llm-wiki:embedded-images -->"
+ // Wrap the section in marker comments for idempotent
+ // replacement on re-ingest.
+ const wrapped = `\n\n${marker}\n${newSection.trim()}\n${marker}\n`
+ // Strip any prior injection (paired markers) so re-ingest
+ // doesn't accumulate stale references when images change.
+ const stripped = existing.replace(
+ new RegExp(`\\n*${marker}[\\s\\S]*?${marker}\\n*`, "g"),
+ "",
+ )
+ await writeFile(sourceSummaryFullPath, stripped.trimEnd() + wrapped)
+ console.log(
+ `[ingest:images] injected ${savedImages.length} image reference(s) into ${sourceSummaryPath}`,
+ )
+ }
+ } catch (err) {
+ console.warn(
+ `[ingest:images] failed to append images to ${sourceSummaryPath}:`,
+ err instanceof Error ? err.message : err,
+ )
+ }
+ }
+
if (writtenPaths.length > 0) {
try {
const tree = await listDirectory(pp)