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: ingest standalone image sources
nash_sub08406220ecf
diff --git a/src/lib/extract-source-images.test.ts b/src/lib/extract-source-images.test.tsindex 6bff1152..3576c9ad 100644--- a/src/lib/extract-source-images.test.ts+++ b/src/lib/extract-source-images.test.ts@@ -1,5 +1,28 @@-import { describe, expect, it } from "vitest"-import { findLocalMarkdownImageRefs } from "./extract-source-images"+import { beforeEach, describe, expect, it, vi } from "vitest"++const mocks = vi.hoisted(() => ({+ copyFile: vi.fn(),+ createDirectory: vi.fn(),+ readFileAsBase64: vi.fn(),+ invoke: vi.fn(),+}))++vi.mock("@tauri-apps/api/core", () => ({ invoke: mocks.invoke }))+vi.mock("@/commands/fs", () => ({+ copyFile: mocks.copyFile,+ createDirectory: mocks.createDirectory,+ fileExists: vi.fn(),+ readFileAsBase64: mocks.readFileAsBase64,+}))++import { extractAndSaveSourceImages, findLocalMarkdownImageRefs } from "./extract-source-images"++beforeEach(() => {+ vi.clearAllMocks()+ mocks.copyFile.mockResolvedValue(undefined)+ mocks.createDirectory.mockResolvedValue(undefined)+ mocks.readFileAsBase64.mockResolvedValue({ base64: "aW1hZ2U=", mimeType: "image/png" })+})describe("findLocalMarkdownImageRefs", () => {it("extracts Obsidian and markdown local image references", () => {@@ -21,3 +44,29 @@ describe("findLocalMarkdownImageRefs", () => {expect(refs).toEqual([])})})++describe("extractAndSaveSourceImages", () => {+ it("imports a standalone image as the source's only saved image", async () => {+ const images = await extractAndSaveSourceImages(+ "/project",+ "/project/raw/sources/process flow.JPG",+ "process-flow",+ )++ expect(mocks.createDirectory).toHaveBeenCalledWith("/project/wiki/media/process-flow")+ expect(mocks.copyFile).toHaveBeenCalledWith(+ "/project/raw/sources/process flow.JPG",+ "/project/wiki/media/process-flow/001-process flow.JPG",+ )+ expect(mocks.invoke).not.toHaveBeenCalled()+ expect(images).toHaveLength(1)+ expect(images[0]).toMatchObject({+ index: 1,+ mimeType: "image/jpeg",+ page: null,+ relPath: "media/process-flow/001-process flow.JPG",+ absPath: "/project/wiki/media/process-flow/001-process flow.JPG",+ })+ expect(images[0].sha256).toMatch(/^[a-f0-9]{64}$/)+ })+})diff --git a/src/lib/extract-source-images.ts b/src/lib/extract-source-images.tsindex c715ce6a..6545f0e5 100644--- a/src/lib/extract-source-images.ts+++ b/src/lib/extract-source-images.ts@@ -38,6 +38,7 @@ export interface SavedImage {* a one-line change here. */const SUPPORTED_PDF_EXTS = ["pdf"] as constconst SUPPORTED_OFFICE_EXTS = ["pptx", "docx"] as const+const SUPPORTED_SOURCE_IMAGE_EXTS = new Set(["png", "jpg", "jpeg"])// Legacy binary .doc/.ppt text extraction is handled separately; image// extraction here is ZIP-based and only supports OOXML files.const MARKDOWN_IMAGE_EXTS = new Set([@@ -160,13 +161,30 @@ export async function extractAndSaveSourceImages(const isPdf = (SUPPORTED_PDF_EXTS as readonly string[]).includes(ext)const isOffice = (SUPPORTED_OFFICE_EXTS as readonly string[]).includes(ext)- if (!isPdf && !isOffice) return []+ const isStandaloneImage = SUPPORTED_SOURCE_IMAGE_EXTS.has(ext)+ if (!isPdf && !isOffice && !isStandaloneImage) return []const slug = slugOverride ?? fileName.replace(/\.[^.]+$/, "")const destDir = `${pp}/wiki/media/${slug}`const relTo = `${pp}/wiki`try {+ if (isStandaloneImage) {+ await createDirectory(destDir)+ const destName = uniqueDestName(1, sp)+ const dest = `${destDir}/${destName}`+ await copyFile(sp, dest)+ return [{+ index: 1,+ mimeType: imageMimeType(dest),+ page: null,+ width: 0,+ height: 0,+ relPath: `media/${slug}/${destName}`,+ absPath: dest,+ sha256: await sha256OfFile(dest),+ }]+ }const images = await invoke<unknown[]>(isPdf ? "extract_and_save_pdf_images_cmd" : "extract_and_save_office_images_cmd",{ sourcePath: sp, destDir, relTo },diff --git a/src/lib/source-lifecycle.test.ts b/src/lib/source-lifecycle.test.tsindex b1cd8635..bf345bb4 100644--- a/src/lib/source-lifecycle.test.ts+++ b/src/lib/source-lifecycle.test.ts@@ -60,6 +60,12 @@ describe("source-lifecycle path helpers", () => {expect(isIngestableSourcePath("C:\\project\\raw\\sources\\book.MOBI")).toBe(true)})+ it("accepts standalone PNG and JPEG image sources", () => {+ expect(isIngestableSourcePath("raw/sources/diagram.png")).toBe(true)+ expect(isIngestableSourcePath("C:\\project\\raw\\sources\\photo.JPG")).toBe(true)+ expect(isIngestableSourcePath("raw/sources/photo.jpeg")).toBe(true)+ })+it("accepts AnyDoc Office and RTF source variants", () => {for (const path of ["report.docm",@@ -440,7 +446,7 @@ describe("source import skip reporting", () => {expect(mocks.copyFile).not.toHaveBeenCalled()})- it("reports file types the picker offers but ingest cannot read", async () => {+ it("imports supported images and reports file types ingest cannot read", async () => {const result = await importSourceFiles(project,["/external/script.py", "/external/photo.png", "/external/notes.md"],@@ -448,10 +454,12 @@ describe("source import skip reporting", () => {watchConfig(),)- expect(result.imported).toEqual(["/project/raw/sources/notes.md"])+ expect(result.imported).toEqual([+ "/project/raw/sources/photo.png",+ "/project/raw/sources/notes.md",+ ])expect(result.skipped).toEqual([{ name: "script.py", reason: "unsupported-type" },- { name: "photo.png", reason: "unsupported-type" },])})diff --git a/src/lib/source-lifecycle.ts b/src/lib/source-lifecycle.tsindex a51b1ab8..347cf666 100644--- a/src/lib/source-lifecycle.ts+++ b/src/lib/source-lifecycle.ts@@ -75,6 +75,9 @@ export const INGESTABLE_SOURCE_EXTENSIONS = new Set(["epub","mobi","org",+ "png",+ "jpg",+ "jpeg",])function flattenFiles(nodes: FileNode[]): FileNode[] {diff --git a/src/lib/source-watch-config.test.ts b/src/lib/source-watch-config.test.tsindex b8e16f65..2bf3ba5a 100644--- a/src/lib/source-watch-config.test.ts+++ b/src/lib/source-watch-config.test.ts@@ -12,6 +12,21 @@ describe("source watch config", () => {expect(DEFAULT_SOURCE_WATCH_CONFIG.includeExtensions).toContain(extension)}})+ it("includes standalone image sources in the default watch set", () => {+ for (const extension of ["png", "jpg", "jpeg"]) {+ expect(DEFAULT_SOURCE_WATCH_CONFIG.includeExtensions).toContain(extension)+ }+ })++ it("upgrades the previous default extension set without changing custom lists", () => {+ const previousDefaults = DEFAULT_SOURCE_WATCH_CONFIG.includeExtensions.filter(+ (extension) => !["png", "jpg", "jpeg"].includes(extension),+ )+ expect(normalizeSourceWatchConfig({ includeExtensions: previousDefaults }).includeExtensions)+ .toEqual([...previousDefaults, "png", "jpg", "jpeg"])+ expect(normalizeSourceWatchConfig({ includeExtensions: ["md", "pdf"] }).includeExtensions)+ .toEqual(["md", "pdf"])+ })it("uses the shared default fixture", () => {expect(DEFAULT_SOURCE_WATCH_CONFIG).toEqual(sourceWatchDefaults)expect(normalizeSourceWatchConfig({}).persistExtractedMarkdown).toBe(false)diff --git a/src/lib/source-watch-config.ts b/src/lib/source-watch-config.tsindex 149be74e..a58747d3 100644--- a/src/lib/source-watch-config.ts+++ b/src/lib/source-watch-config.ts@@ -26,8 +26,17 @@ export const SOURCE_WATCH_FILE_TYPE_GROUPS = [id: "data",extensions: ["json", "yaml", "yml", "xml"],},+ {+ id: "images",+ extensions: ["png", "jpg", "jpeg"],+ },]+const SOURCE_IMAGE_EXTENSIONS = ["png", "jpg", "jpeg"] as const+const LEGACY_DEFAULT_INCLUDE_EXTENSIONS = sourceWatchDefaults.includeExtensions.filter(+ (extension) => !SOURCE_IMAGE_EXTENSIONS.includes(extension as typeof SOURCE_IMAGE_EXTENSIONS[number]),+)+function normalizeExtensions(values: readonly string[] | undefined): string[] {return [...new Set((values ?? []).flatMap((value) => value.split(/[,,\n]/))@@ -53,6 +62,11 @@ export function normalizeSourceWatchConfig(config?: Partial<SourceWatchConfig> |const ingestConcurrency = Number.isFinite(rawIngestConcurrency)? clampUserConcurrency(rawIngestConcurrency): DEFAULT_SOURCE_WATCH_CONFIG.ingestConcurrency+ const includeExtensions = normalizeExtensions(+ config?.includeExtensions ?? DEFAULT_SOURCE_WATCH_CONFIG.includeExtensions,+ )+ const usesLegacyDefaults = includeExtensions.length === LEGACY_DEFAULT_INCLUDE_EXTENSIONS.length+ && LEGACY_DEFAULT_INCLUDE_EXTENSIONS.every((extension) => includeExtensions.includes(extension))return {enabled: config?.enabled ?? DEFAULT_SOURCE_WATCH_CONFIG.enabled,autoIngest: config?.autoIngest ?? DEFAULT_SOURCE_WATCH_CONFIG.autoIngest,@@ -60,7 +74,9 @@ export function normalizeSourceWatchConfig(config?: Partial<SourceWatchConfig> |config?.persistExtractedMarkdown ?? DEFAULT_SOURCE_WATCH_CONFIG.persistExtractedMarkdown,parsingConcurrency,ingestConcurrency,- includeExtensions: normalizeExtensions(config?.includeExtensions ?? DEFAULT_SOURCE_WATCH_CONFIG.includeExtensions),+ includeExtensions: usesLegacyDefaults+ ? [...includeExtensions, ...SOURCE_IMAGE_EXTENSIONS]+ : includeExtensions,excludeExtensions: normalizeExtensions(config?.excludeExtensions ?? DEFAULT_SOURCE_WATCH_CONFIG.excludeExtensions),excludeDirs: normalizeList(config?.excludeDirs ?? DEFAULT_SOURCE_WATCH_CONFIG.excludeDirs),excludeGlobs: normalizeList(config?.excludeGlobs ?? DEFAULT_SOURCE_WATCH_CONFIG.excludeGlobs),diff --git a/src/lib/source-watch-defaults.json b/src/lib/source-watch-defaults.jsonindex 4916f90a..d779e7db 100644--- a/src/lib/source-watch-defaults.json+++ b/src/lib/source-watch-defaults.json@@ -30,7 +30,10 @@"rtf","html","htm",- "csv"+ "csv",+ "png",+ "jpg",+ "jpeg"],"excludeExtensions": ["tmp",