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
Release 0.4.10
nash_suea16fda6ea80
diff --git a/src-tauri/src/commands/file_sync.rs b/src-tauri/src/commands/file_sync.rsindex 0bfd75d8..c34750dc 100644--- a/src-tauri/src/commands/file_sync.rs+++ b/src-tauri/src/commands/file_sync.rs@@ -104,6 +104,13 @@ pub struct FileChangeQueue {tasks: Vec<FileChangeTask>,}+#[derive(Debug, Default, Clone, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct FileChangeRescanResult {+ queue: FileChangeQueue,+ changed_tasks: Vec<FileChangeTask>,+}+#[derive(Debug, Clone, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]pub struct SourceWatchConfig {@@ -324,16 +331,19 @@ pub fn rescan_project_files(project_id: String,project_path: String,source_watch_config: Option<SourceWatchConfig>,-) -> Result<FileChangeQueue, String> {+) -> Result<FileChangeRescanResult, String> {run_guarded("rescan_project_files", || {let root = PathBuf::from(project_path);let source_watch_config = normalize_source_watch_config(source_watch_config);ensure_sync_dir(&root)?;enqueue_rescan_changes(&root, &project_id, &source_watch_config)?;- process_queue(&app, &root, &project_id)?;+ let changed_tasks = process_queue(&app, &root, &project_id)?;let queue = with_queue_lock(&root, || read_queue(&root))?;emit_queue(&app, &project_id, &queue);- Ok(queue)+ Ok(FileChangeRescanResult {+ queue,+ changed_tasks,+ })})}@@ -746,7 +756,7 @@ fn upsert_task(});}-fn process_queue(app: &AppHandle, root: &Path, project_id: &str) -> Result<(), String> {+fn process_queue(app: &AppHandle, root: &Path, project_id: &str) -> Result<Vec<FileChangeTask>, String> {process_queue_inner(root,project_id,@@ -760,8 +770,9 @@ fn process_queue_inner(project_id: &str,mut on_queue: impl FnMut(&FileChangeQueue),mut on_changed: impl FnMut(Vec<FileChangeTask>),-) -> Result<(), String> {+) -> Result<Vec<FileChangeTask>, String> {let mut changed_tasks = Vec::<FileChangeTask>::new();+ let mut all_changed_tasks = Vec::<FileChangeTask>::new();let mut processed_since_emit = 0_usize;let mut emitted_processing = false;loop {@@ -796,7 +807,7 @@ fn process_queue_inner(};on_changed(changed_tasks);on_queue(&queue);- return Ok(());+ return Ok(all_changed_tasks);};if !emitted_processing {emitted_processing = true;@@ -835,6 +846,7 @@ fn process_queue_inner(}}current.updated_at = now_ms();+ all_changed_tasks.push(task.clone());changed_tasks.push(task.clone());processed_since_emit += 1;if processed_since_emit >= QUEUE_EMIT_EVERY {diff --git a/src/commands/file-sync.ts b/src/commands/file-sync.tsindex b902150e..05822491 100644--- a/src/commands/file-sync.ts+++ b/src/commands/file-sync.ts@@ -27,6 +27,11 @@ export interface FileChangeQueue {tasks: FileChangeTask[]}+export interface FileChangeRescanResult {+ queue: FileChangeQueue+ changedTasks: FileChangeTask[]+}+export interface FileSyncPayload {projectId: stringtasks: FileChangeTask[]@@ -52,8 +57,8 @@ export function rescanProjectFiles(projectId: string,projectPath: string,sourceWatchConfig?: SourceWatchConfig,-): Promise<FileChangeQueue> {- return invoke<FileChangeQueue>("rescan_project_files", {+): Promise<FileChangeRescanResult> {+ return invoke<FileChangeRescanResult>("rescan_project_files", {projectId,projectPath,sourceWatchConfig: normalizeSourceWatchConfig(sourceWatchConfig),diff --git a/src/components/layout/activity-panel.tsx b/src/components/layout/activity-panel.tsxindex 0a639de3..7f27ac41 100644--- a/src/components/layout/activity-panel.tsx+++ b/src/components/layout/activity-panel.tsx@@ -96,8 +96,8 @@ export function ActivityPanel() {const handleFileSyncRescan = useCallback(() => {if (!project) returnrescanProjectFiles(project.id, normalizePath(project.path), useWikiStore.getState().sourceWatchConfig)- .then((queue) => {- setFileSyncTasks(queue.tasks)+ .then((result) => {+ setFileSyncTasks(result.queue.tasks)useFileSyncStore.getState().setLastError(null)}).catch((err) => useFileSyncStore.getState().setLastError(String(err)))diff --git a/src/components/settings/sections/embedding-section.tsx b/src/components/settings/sections/embedding-section.tsxindex 35f66f8d..2b521cd9 100644--- a/src/components/settings/sections/embedding-section.tsx+++ b/src/components/settings/sections/embedding-section.tsx@@ -23,6 +23,14 @@ type ReindexState =| { kind: "running"; done: number; total: number }| { kind: "done"; count: number }+function parsePositiveInteger(value: string): number | undefined {+ const trimmed = value.trim()+ if (trimmed === "") return undefined+ const n = Number(trimmed)+ if (!Number.isFinite(n) || n <= 0) return undefined+ return Math.floor(n)+}+export function EmbeddingSection({ draft, setDraft }: Props) {const { t } = useTranslation()const project = useWikiStore((s) => s.project)@@ -113,6 +121,9 @@ export function EmbeddingSection({ draft, setDraft }: Props) {onChange={(e) => setDraft("embeddingEndpoint", e.target.value)}placeholder="http://127.0.0.1:1234/v1/embeddings"/>+ <p className="text-xs text-muted-foreground">+ {t("settings.sections.embedding.endpointHint")}+ </p></div><div className="space-y-2">@@ -130,10 +141,27 @@ export function EmbeddingSection({ draft, setDraft }: Props) {<Inputvalue={draft.embeddingModel}onChange={(e) => setDraft("embeddingModel", e.target.value)}- placeholder="e.g. text-embedding-qwen3-embedding-0.6b"+ placeholder="e.g. text-embedding-qwen3-embedding-0.6b or gemini-embedding-001"/></div>+ <div className="space-y-2">+ <Label>{t("settings.sections.embedding.outputDimensionality")}</Label>+ <Input+ type="number"+ min={1}+ step={1}+ value={draft.embeddingOutputDimensionality ?? ""}+ onChange={(e) => {+ setDraft("embeddingOutputDimensionality", parsePositiveInteger(e.target.value))+ }}+ placeholder="768"+ />+ <p className="text-xs text-muted-foreground">+ {t("settings.sections.embedding.outputDimensionalityHint")}+ </p>+ </div>+<div className="space-y-3 rounded-md border p-3"><div className="text-sm font-medium">{t("settings.sections.embedding.chunking")}diff --git a/src/components/settings/sections/llm-provider-section.tsx b/src/components/settings/sections/llm-provider-section.tsxindex 005a163d..516aa657 100644--- a/src/components/settings/sections/llm-provider-section.tsx+++ b/src/components/settings/sections/llm-provider-section.tsx@@ -187,7 +187,7 @@ function PresetRow({: "border-muted-foreground/30 bg-muted-foreground/20 hover:bg-muted-foreground/30"}`}title={isActive ? t("settings.sections.llm.toggleOff") : t("settings.sections.llm.toggleOn")}- aria-label={isActive ? "Deactivate" : "Activate"}+ aria-label={isActive ? t("settings.sections.llm.deactivate") : t("settings.sections.llm.activate")}><spanclassName={`inline-block h-3.5 w-3.5 rounded-full bg-white shadow-sm ring-1 ring-black/10 transition-transform ${@@ -202,7 +202,7 @@ function PresetRow({<div className="space-y-4 border-t bg-background/50 px-4 py-3">{preset.provider === "custom" && (<div className="space-y-2">- <Label>API Mode</Label>+ <Label>{t("settings.sections.llm.apiMode")}</Label><div className="flex flex-wrap gap-2">{([@@ -254,7 +254,7 @@ function PresetRow({{needsApiKey && (<div className="space-y-2">- <Label>API Key</Label>+ <Label>{t("settings.apiKey")}</Label><Inputtype="password"value={apiKey}@@ -269,7 +269,7 @@ function PresetRow({)}<div className="space-y-2">- <Label>Model</Label>+ <Label>{t("settings.model")}</Label><ModelPickervalue={model}suggestions={preset.suggestedModels ?? []}@@ -279,7 +279,7 @@ function PresetRow({</div><div className="space-y-2">- <Label>Context window</Label>+ <Label>{t("settings.sections.llm.contextWindow")}</Label><ContextSizeSelectorvalue={context}onChange={(v) => onChange({ maxContextSize: v })}@@ -303,19 +303,20 @@ function ReasoningControls({value: ReasoningConfigonChange: (value: ReasoningConfig) => void}) {+ const { t } = useTranslation()const modes: { value: ReasoningMode; label: string }[] = [- { value: "auto", label: "Auto" },- { value: "off", label: "Off" },- { value: "low", label: "Low" },- { value: "medium", label: "Medium" },- { value: "high", label: "High" },- { value: "max", label: "Max" },- { value: "custom", label: "Custom" },+ { value: "auto", label: t("settings.sections.llm.reasoning.auto") },+ { value: "off", label: t("settings.sections.llm.reasoning.off") },+ { value: "low", label: t("settings.sections.llm.reasoning.low") },+ { value: "medium", label: t("settings.sections.llm.reasoning.medium") },+ { value: "high", label: t("settings.sections.llm.reasoning.high") },+ { value: "max", label: t("settings.sections.llm.reasoning.max") },+ { value: "custom", label: t("settings.sections.llm.reasoning.custom") },]return (<div className="space-y-2">- <Label>Reasoning / thinking</Label>+ <Label>{t("settings.sections.llm.reasoning.title")}</Label><div className="flex flex-wrap gap-1.5">{modes.map((m) => {const active = value.mode === m.value@@ -352,11 +353,13 @@ function ReasoningControls({}}placeholder="1024"/>- <span className="text-xs text-muted-foreground">thinking budget tokens</span>+ <span className="text-xs text-muted-foreground">+ {t("settings.sections.llm.reasoning.budgetTokens")}+ </span></div>)}<p className="text-xs text-muted-foreground">- Structured tasks such as ingest may override this to Off to avoid reasoning-only responses.+ {t("settings.sections.llm.reasoning.hint")}</p></div>)@@ -389,7 +392,7 @@ function EndpointField({ value, mode, placeholder, onChange }: EndpointFieldPropreturn (<div className="space-y-1.5">- <Label>Endpoint</Label>+ <Label>{t("settings.sections.llm.endpoint")}</Label><Inputvalue={value}onChange={(e) => onChange(e.target.value)}@@ -447,6 +450,7 @@ interface ModelPickerProps {* `suggestedModels` render the input alone.*/function ModelPicker({ value, suggestions, placeholder, onChange }: ModelPickerProps) {+ const { t } = useTranslation()const hasSuggestions = suggestions.length > 0const isCustom = hasSuggestions && value.length > 0 && !suggestions.includes(value)@@ -466,7 +470,7 @@ function ModelPicker({ value, suggestions, placeholder, onChange }: ModelPickerP? "border-primary bg-primary text-primary-foreground": "border-border bg-background hover:bg-accent hover:text-accent-foreground"}`}- title={`Use ${m}`}+ title={t("settings.sections.llm.useModel", { model: m })}>{m}</button>@@ -480,9 +484,11 @@ function ModelPicker({ value, suggestions, placeholder, onChange }: ModelPickerP? "border-primary/60 bg-primary/10 text-primary": "border-dashed border-muted-foreground/40 text-muted-foreground hover:bg-accent hover:text-accent-foreground"}`}- title="Type a custom model id"+ title={t("settings.sections.llm.typeCustomModel")}>- {isCustom ? `Custom: ${value}` : "Custom…"}+ {isCustom+ ? t("settings.sections.llm.customModelBadge", { model: value })+ : t("settings.sections.llm.customModel")}</button></div>)}diff --git a/src/components/settings/sections/web-search-section.tsx b/src/components/settings/sections/web-search-section.tsxindex 5dba3638..efc1c174 100644--- a/src/components/settings/sections/web-search-section.tsx+++ b/src/components/settings/sections/web-search-section.tsx@@ -96,7 +96,7 @@ export function WebSearchSection() {type="button"onClick={() => setExpanded((prev) => ({ ...prev, [provider.id]: !prev[provider.id] }))}className="shrink-0 rounded p-0.5 text-muted-foreground hover:bg-accent"- title={isExpanded ? "Collapse" : "Expand"}+ title={isExpanded ? t("settings.sections.webSearch.collapse") : t("settings.sections.webSearch.expand")}>{isExpanded ? <ChevronDown className="h-4 w-4" /> : <ChevronRight className="h-4 w-4" />}</button>@@ -110,16 +110,18 @@ export function WebSearchSection() {<span className="truncate text-sm font-medium">{provider.label}</span>{hasConfig && !isActive && (<span className="shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground">- Configured+ {t("settings.sections.webSearch.configuredBadge")}</span>)}{isActive && (<span className="shrink-0 rounded-full bg-primary/20 px-1.5 py-0.5 text-[10px] font-medium text-primary">- Active+ {t("settings.sections.webSearch.activeBadge")}</span>)}{savedId === provider.id && (- <span className="shrink-0 text-[10px] text-emerald-600">Saved</span>+ <span className="shrink-0 text-[10px] text-emerald-600">+ {t("settings.sections.webSearch.savedBadge")}+ </span>)}</div><div className="mt-0.5 truncate text-xs text-muted-foreground">@@ -135,7 +137,7 @@ export function WebSearchSection() {? "border-primary bg-primary": "border-muted-foreground/30 bg-muted-foreground/20 hover:bg-muted-foreground/30"}`}- aria-label={isActive ? "Deactivate" : "Activate"}+ aria-label={isActive ? t("settings.sections.webSearch.deactivate") : t("settings.sections.webSearch.activate")}><spanclassName={`inline-block h-3.5 w-3.5 rounded-full bg-white shadow-sm ring-1 ring-black/10 transition-transform ${@@ -149,7 +151,7 @@ export function WebSearchSection() {<div className="space-y-4 border-t bg-background/50 px-4 py-3">{provider.needsApiKey ? (<div className="space-y-2">- <Label>API Key</Label>+ <Label>{t("settings.apiKey")}</Label><Inputtype="password"value={override?.apiKey ?? ""}@@ -159,14 +161,14 @@ export function WebSearchSection() {</div>) : (<div className="space-y-2">- <Label>Instance URL</Label>+ <Label>{t("settings.sections.webSearch.instanceUrl")}</Label><Inputvalue={override?.searXngUrl ?? resolvedConfig.searXngUrl ?? ""}onChange={(e) => updateProvider("searxng", { searXngUrl: e.target.value })}placeholder={provider.urlPlaceholder}/><p className="text-xs text-muted-foreground">- The instance must allow JSON search responses (`format=json`).+ {t("settings.sections.webSearch.searxngJsonHint")}</p></div>)}@@ -201,6 +203,7 @@ function SearXngCategoryPicker({value: string[]onChange: (value: string[]) => void}) {+ const { t } = useTranslation()const selected = value.length > 0 ? value : ["general"]function toggle(category: string) {@@ -212,7 +215,7 @@ function SearXngCategoryPicker({return (<div className="space-y-2">- <Label>Search categories</Label>+ <Label>{t("settings.sections.webSearch.searchCategories")}</Label><div className="flex flex-wrap gap-1.5">{SEARXNG_CATEGORY_OPTIONS.map((category) => (<button@@ -231,7 +234,7 @@ function SearXngCategoryPicker({))}</div><p className="text-xs text-muted-foreground">- Categories are sent as the SearXNG `categories` parameter.+ {t("settings.sections.webSearch.searxngCategoriesHint")}</p></div>)@@ -244,11 +247,12 @@ function SerpApiEnginePicker({value: stringonChange: (value: string) => void}) {+ const { t } = useTranslation()const isCustom = value.length > 0 && !SERPAPI_ENGINE_OPTIONS.some((e) => e.value === value)return (<div className="space-y-2">- <Label>Search engine / category</Label>+ <Label>{t("settings.sections.webSearch.searchEngine")}</Label><div className="flex flex-wrap gap-1.5">{SERPAPI_ENGINE_OPTIONS.map((engine) => (<button@@ -269,11 +273,11 @@ function SerpApiEnginePicker({<Inputvalue={value}onChange={(e) => onChange(e.target.value)}- placeholder="Custom SerpApi engine, e.g. google_finance"+ placeholder={t("settings.sections.webSearch.customSerpApiPlaceholder")}/>{isCustom && (<p className="text-xs text-muted-foreground">- Custom engine will be sent as the SerpApi `engine` parameter.+ {t("settings.sections.webSearch.customSerpApiHint")}</p>)}</div>diff --git a/src/components/settings/settings-types.ts b/src/components/settings/settings-types.tsindex f3e568c2..3f73525c 100644--- a/src/components/settings/settings-types.ts+++ b/src/components/settings/settings-types.ts@@ -23,6 +23,8 @@ export interface SettingsDraft {embeddingEndpoint: stringembeddingApiKey: stringembeddingModel: string+ /** Optional Gemini native output_dimensionality. Empty = provider default. */+ embeddingOutputDimensionality: number | undefined/** Target characters per chunk. Empty = use chunker default (1000). */embeddingMaxChunkChars: number | undefined/** Overlap characters between adjacent chunks. Empty = default (200). */diff --git a/src/components/settings/settings-view.tsx b/src/components/settings/settings-view.tsxindex f5ab4a3f..d1af73ed 100644--- a/src/components/settings/settings-view.tsx+++ b/src/components/settings/settings-view.tsx@@ -110,6 +110,7 @@ function initialDraft(embeddingEndpoint: embed.endpoint,embeddingApiKey: embed.apiKey,embeddingModel: embed.model,+ embeddingOutputDimensionality: embed.outputDimensionality,embeddingMaxChunkChars: embed.maxChunkChars,embeddingOverlapChunkChars: embed.overlapChunkChars,multimodalEnabled: multimodal.enabled,@@ -263,6 +264,7 @@ export function SettingsView() {endpoint: draft.embeddingEndpoint,apiKey: draft.embeddingApiKey,model: draft.embeddingModel,+ outputDimensionality: draft.embeddingOutputDimensionality,maxChunkChars: draft.embeddingMaxChunkChars,overlapChunkChars: draft.embeddingOverlapChunkChars,}diff --git a/src/components/sources/sources-view.tsx b/src/components/sources/sources-view.tsxindex c4730f56..e4605fc3 100644--- a/src/components/sources/sources-view.tsx+++ b/src/components/sources/sources-view.tsx@@ -3,13 +3,14 @@ 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"import { ScrollArea } from "@/components/ui/scroll-area"+import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"import { useWikiStore } from "@/stores/wiki-store"import { listDirectory, readFile } from "@/commands/fs"import type { FileNode } from "@/types/wiki"import { useTranslation } from "react-i18next"import { normalizePath } from "@/lib/path-utils"import { decideDeleteClick } from "@/lib/sources-tree-delete"-import { rescanProjectFiles } from "@/commands/file-sync"+import { rescanProjectFileSync } from "@/lib/project-file-sync"import {deleteSourceFile,deleteSourceFolder,@@ -33,6 +34,7 @@ export function SourcesView() {const [sources, setSources] = useState<FileNode[]>([])const [importing, setImporting] = useState(false)const [ingestingPath, setIngestingPath] = useState<string | null>(null)+ const [refreshing, setRefreshing] = useState(false)const [refreshError, setRefreshError] = useState<string | null>(null)/*** Path of the source-tree node currently in "click again to@@ -77,15 +79,18 @@ export function SourcesView() {}, [loadSources, dataVersion])async function handleRefreshSources() {- if (!project) return- const pp = normalizePath(project.path)+ if (!project || refreshing) return+ setRefreshing(true)try {- await rescanProjectFiles(project.id, pp, useWikiStore.getState().sourceWatchConfig)+ await rescanProjectFileSync(project, useWikiStore.getState().sourceWatchConfig)+ setRefreshError(null)} catch (err) {console.warn("[sources] failed to rescan project files:", err)setRefreshError(String(err))+ } finally {+ await loadSources()+ setRefreshing(false)}- await loadSources()}async function handleImport() {@@ -252,13 +257,29 @@ export function SourcesView() {}return (- <div className="flex h-full flex-col">+ <TooltipProvider delay={300}>+ <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">{t("sources.title")}</h2><div className="flex gap-1">- <Button variant="ghost" size="icon" onClick={handleRefreshSources} title={t("sources.refresh")}>- <RefreshCw className="h-4 w-4" />- </Button>+ <Tooltip>+ <TooltipTrigger+ render={+ <Button+ variant="ghost"+ size="icon"+ onClick={handleRefreshSources}+ disabled={refreshing}+ aria-label={t("sources.refreshFolder")}+ />+ }+ >+ <RefreshCw className={`h-4 w-4 ${refreshing ? "animate-spin" : ""}`} />+ </TooltipTrigger>+ <TooltipContent side="bottom" align="end" className="max-w-80 whitespace-normal leading-relaxed">+ {t("sources.refreshFolderTooltip")}+ </TooltipContent>+ </Tooltip><Button size="sm" onClick={handleImport} disabled={importing}><Plus className="mr-1 h-4 w-4" />{importing ? t("sources.importing") : t("sources.import")}@@ -310,10 +331,30 @@ export function SourcesView() {)}</ScrollArea>- <div className="border-t px-4 py-2 text-xs text-muted-foreground">- {t("sources.sourceCount", { count: countFiles(sources) })}+ <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>+ <Tooltip>+ <TooltipTrigger+ render={+ <Button+ variant="ghost"+ size="sm"+ onClick={handleRefreshSources}+ disabled={!project || refreshing}+ className="h-7 px-2 text-xs"+ />+ }+ >+ <RefreshCw className={`mr-1.5 h-3.5 w-3.5 ${refreshing ? "animate-spin" : ""}`} />+ {refreshing ? t("sources.refreshingFolder") : t("sources.refreshFolder")}+ </TooltipTrigger>+ <TooltipContent side="top" align="end" className="max-w-80 whitespace-normal leading-relaxed">+ {t("sources.refreshFolderTooltip")}+ </TooltipContent>+ </Tooltip>+ </div></div>- </div>+ </TooltipProvider>)}diff --git a/src/i18n/en.json b/src/i18n/en.jsonindex 5795ca4b..80c4f436 100644--- a/src/i18n/en.json+++ b/src/i18n/en.json@@ -80,6 +80,10 @@"importSourceFiles": "Import Source Files","importSourceFolder": "Import Source Folder","refresh": "Refresh",+ "refreshFolder": "Refresh folder",+ "refreshingFolder": "Refreshing...",+ "refreshFolderHint": "Rescan the source folder and process new, changed, or deleted files.",+ "refreshFolderTooltip": "Rescan the project source folder with the same rules as automatic monitoring. New or modified allowed files are queued for ingest; deleted sources trigger the normal wiki and index cleanup; then the file tree is rebuilt.","refreshFailed": "Failed to refresh sources: {{error}}","ingest": "Ingest","delete": "Delete source and related wiki pages",@@ -194,6 +198,11 @@"collapse": "Collapse","toggleOff": "Click to deactivate","toggleOn": "Click to activate (turns off other providers)",+ "deactivate": "Deactivate",+ "activate": "Activate",+ "apiMode": "API Mode",+ "endpoint": "Endpoint",+ "contextWindow": "Context window","wireOpenAi": "OpenAI-compat","wireAnthropic": "Anthropic-compat","apiKeyPlaceholderCustom": "Leave empty if no key (local models)",@@ -201,18 +210,37 @@"savedBadge": "saved","configuredBadge": "configured","activeBadge": "● active",+ "useModel": "Use {{model}}",+ "typeCustomModel": "Type a custom model id",+ "customModel": "Custom…",+ "customModelBadge": "Custom: {{model}}","endpointPreviewWillUse": "Will resolve to",- "endpointPreviewAutoApply": "(applied automatically when you leave the input)"+ "endpointPreviewAutoApply": "(applied automatically when you leave the input)",+ "reasoning": {+ "title": "Reasoning / thinking",+ "auto": "Auto",+ "off": "Off",+ "low": "Low",+ "medium": "Medium",+ "high": "High",+ "max": "Max",+ "custom": "Custom",+ "budgetTokens": "thinking budget tokens",+ "hint": "Structured tasks such as ingest may override this to Off to avoid reasoning-only responses."+ }},"embedding": {"title": "Vector Embeddings",- "description": "Enable semantic search against your wiki. Works with any OpenAI-compatible /v1/embeddings endpoint. Local models (LM Studio, Ollama embedding) don't need an API key.",+ "description": "Enable semantic search against your wiki. Works with OpenAI-compatible /v1/embeddings endpoints and Google Gemini native embedContent endpoints. Local models (LM Studio, Ollama embedding) don't need an API key.","enableLabel": "Enable vector search","enableHint": "When off, search uses token matching only.","endpoint": "Endpoint",+ "endpointHint": "OpenAI-compatible example: http://127.0.0.1:1234/v1/embeddings. Gemini example: https://generativelanguage.googleapis.com/v1beta with model gemini-embedding-001.","apiKey": "API Key (optional)","apiKeyPlaceholder": "Leave empty for local models","model": "Model",+ "outputDimensionality": "Output dimensionality (Gemini only)",+ "outputDimensionalityHint": "Optional. Sent only for Gemini native embedContent endpoints as `output_dimensionality`; OpenAI-compatible endpoints ignore this field. Leave empty for the model default. Rebuild embeddings after changing model or dimension.","chunking": "Chunking","maxChunkChars": "Max chunk size (characters)","maxChunkCharsHint": "Target size of each chunk. Lower this (e.g. 500) when your endpoint's context is small (llama.cpp n_ctx=512, mxbai-embed-large, etc.).",@@ -257,7 +285,21 @@},"webSearch": {"title": "Web Search",- "description": "Used by Deep Research to pull fresh external context."+ "description": "Used by Deep Research to pull fresh external context.",+ "expand": "Expand",+ "collapse": "Collapse",+ "activate": "Activate",+ "deactivate": "Deactivate",+ "configuredBadge": "Configured",+ "activeBadge": "Active",+ "savedBadge": "Saved",+ "instanceUrl": "Instance URL",+ "searxngJsonHint": "The instance must allow JSON search responses (`format=json`).",+ "searchCategories": "Search categories",+ "searxngCategoriesHint": "Categories are sent as the SearXNG `categories` parameter.",+ "searchEngine": "Search engine / category",+ "customSerpApiPlaceholder": "Custom SerpApi engine, e.g. google_finance",+ "customSerpApiHint": "Custom engine will be sent as the SerpApi `engine` parameter."},"network": {"title": "Network",diff --git a/src/i18n/zh.json b/src/i18n/zh.jsonindex 6ea4f97f..fce47791 100644--- a/src/i18n/zh.json+++ b/src/i18n/zh.json@@ -80,6 +80,10 @@"importSourceFiles": "导入源文件","importSourceFolder": "导入源文件夹","refresh": "刷新",+ "refreshFolder": "刷新文件夹",+ "refreshingFolder": "刷新中...",+ "refreshFolderHint": "重新扫描资料文件夹,并处理新增、修改或删除的文件。",+ "refreshFolderTooltip": "按自动监控相同规则重新扫描当前项目的资料文件夹。允许的新增或修改文件会加入提取队列;已删除的资料会走正常的 Wiki 与索引清理流程;随后重建文件树。","refreshFailed": "刷新原始资料失败:{{error}}","ingest": "提取到 Wiki","delete": "删除资料及相关 Wiki 页面",@@ -194,6 +198,11 @@"collapse": "收起","toggleOff": "点击关闭","toggleOn": "点击启用(会关闭其他 provider)",+ "deactivate": "停用",+ "activate": "启用",+ "apiMode": "API 模式",+ "endpoint": "Endpoint",+ "contextWindow": "上下文窗口","wireOpenAi": "OpenAI 兼容","wireAnthropic": "Anthropic 兼容","apiKeyPlaceholderCustom": "无 Key 可留空(本地模型)",@@ -201,18 +210,37 @@"savedBadge": "已保存","configuredBadge": "已配置","activeBadge": "● 活跃",+ "useModel": "使用 {{model}}",+ "typeCustomModel": "输入自定义模型 ID",+ "customModel": "自定义…",+ "customModelBadge": "自定义:{{model}}","endpointPreviewWillUse": "将使用",- "endpointPreviewAutoApply": "(离开输入框时自动套用)"+ "endpointPreviewAutoApply": "(离开输入框时自动套用)",+ "reasoning": {+ "title": "Reasoning / thinking",+ "auto": "自动",+ "off": "关闭",+ "low": "低",+ "medium": "中",+ "high": "高",+ "max": "最大",+ "custom": "自定义",+ "budgetTokens": "thinking token 预算",+ "hint": "结构化任务(如 ingest)可能会自动关闭 reasoning,避免模型只输出思考过程而没有正文。"+ }},"embedding": {"title": "向量嵌入",- "description": "启用语义搜索。对任何 OpenAI 兼容的 /v1/embeddings endpoint 工作。本地模型(如 LM Studio、Ollama embedding)不需要 API Key。",+ "description": "启用语义搜索。支持 OpenAI 兼容的 /v1/embeddings endpoint,也支持 Google Gemini 原生 embedContent endpoint。本地模型(如 LM Studio、Ollama embedding)不需要 API Key。","enableLabel": "启用向量搜索","enableHint": "关掉后搜索只走 token 匹配。","endpoint": "Endpoint",+ "endpointHint": "OpenAI 兼容示例:http://127.0.0.1:1234/v1/embeddings。Gemini 示例:https://generativelanguage.googleapis.com/v1beta,模型填 gemini-embedding-001。","apiKey": "API Key(可选)","apiKeyPlaceholder": "本地模型留空即可","model": "Model",+ "outputDimensionality": "输出维度(仅 Gemini)",+ "outputDimensionalityHint": "可选。仅对 Gemini 原生 embedContent endpoint 作为 `output_dimensionality` 发送;OpenAI 兼容 endpoint 会忽略此项。留空则使用模型默认值。修改模型或维度后需要重建嵌入。","chunking": "切分参数","maxChunkChars": "每块最大字符数","maxChunkCharsHint": "单个 chunk 的目标长度。endpoint 上下文较小时(llama.cpp n_ctx=512、mxbai-embed-large 等)调低(如 500)。",@@ -257,7 +285,21 @@},"webSearch": {"title": "网页搜索",- "description": "Deep Research 会用它拉取最新的外部上下文。"+ "description": "Deep Research 会用它拉取最新的外部上下文。",+ "expand": "展开",+ "collapse": "收起",+ "activate": "启用",+ "deactivate": "停用",+ "configuredBadge": "已配置",+ "activeBadge": "活跃",+ "savedBadge": "已保存",+ "instanceUrl": "实例 URL",+ "searxngJsonHint": "实例必须允许 JSON 搜索响应(`format=json`)。",+ "searchCategories": "搜索分类",+ "searxngCategoriesHint": "分类会作为 SearXNG 的 `categories` 参数发送。",+ "searchEngine": "搜索引擎 / 分类",+ "customSerpApiPlaceholder": "自定义 SerpApi engine,例如 google_finance",+ "customSerpApiHint": "自定义 engine 会作为 SerpApi 的 `engine` 参数发送。"},"network": {"title": "网络",diff --git a/src/lib/changelog.ts b/src/lib/changelog.tsindex 90908cbd..b64a71be 100644--- a/src/lib/changelog.ts+++ b/src/lib/changelog.ts@@ -30,10 +30,12 @@ export const CHANGELOG: ChangelogEntry[] = [date: "2026-05-14",highlights: {en: [- "Source folder monitoring now has configurable file type and exclusion rules. Existing projects should review Settings → Source Watch after upgrading because automatic ingest now defaults to common document formats only.",+ "Added configurable source folder monitoring, manual source-folder refresh, and Gemini native embeddings support.",+ "Fixed source sync, embedding provider compatibility, and settings localization issues.",],zh: [- "资料文件夹监控新增文件类型和排除规则配置。升级后建议到「设置 → 资料文件夹监控」检查配置;自动提取现在默认只纳入常见文档格式。",+ "新增可配置的资料文件夹监控、手动刷新资料文件夹,以及 Gemini 原生向量嵌入支持。",+ "修复资料同步、向量 provider 兼容性和设置页本地化相关问题。",],},},diff --git a/src/lib/embedding.test.ts b/src/lib/embedding.test.tsindex fd085594..be8dda87 100644--- a/src/lib/embedding.test.ts+++ b/src/lib/embedding.test.ts@@ -36,6 +36,7 @@ vi.mock("@/commands/fs", () => ({import {searchByEmbedding,+ fetchEmbedding,embedPage,embedAllPages,getLastEmbeddingError,@@ -227,6 +228,389 @@ describe("searchByEmbedding — aggregation", () => {})})+describe("fetchEmbedding — provider wire formats", () => {+ it("does not route OpenAI text-embedding models through Gemini", async () => {+ mockHttpFetch.mockResolvedValueOnce(okResponse([0.1, 0.2]))++ const out = await fetchEmbedding("hi", {+ enabled: true,+ endpoint: "https://api.openai.com/v1/embeddings",+ apiKey: "sk-test",+ model: "text-embedding-3-small",+ })++ expect(out).toEqual([0.1, 0.2])+ const [url, opts] = mockHttpFetch.mock.calls[0]+ expect(url).toBe("https://api.openai.com/v1/embeddings")+ expect((opts?.headers as Record<string, string>).Authorization).toBe("Bearer sk-test")+ expect((opts?.headers as Record<string, string>)["x-goog-api-key"]).toBeUndefined()+ expect(JSON.parse(String(opts?.body))).toEqual({+ model: "text-embedding-3-small",+ input: "hi",+ })+ })++ it("does not route LM Studio text-embedding models through Gemini", async () => {+ mockHttpFetch.mockResolvedValueOnce(okResponse([0.3, 0.4]))++ const out = await fetchEmbedding("hi", {+ enabled: true,+ endpoint: "http://127.0.0.1:1234/v1/embeddings",+ apiKey: "",+ model: "text-embedding-qwen3-embedding-0.6b",+ })++ expect(out).toEqual([0.3, 0.4])+ const [url, opts] = mockHttpFetch.mock.calls[0]+ expect(url).toBe("http://127.0.0.1:1234/v1/embeddings")+ expect((opts?.headers as Record<string, string>).Authorization).toBeUndefined()+ expect((opts?.headers as Record<string, string>)["x-goog-api-key"]).toBeUndefined()+ expect(JSON.parse(String(opts?.body))).toEqual({+ model: "text-embedding-qwen3-embedding-0.6b",+ input: "hi",+ })+ })++ it("supports Gemini native embedContent endpoint and response shape", async () => {+ mockHttpFetch.mockResolvedValueOnce(+ new Response(JSON.stringify({ embedding: { values: [0.1, 0.2, 0.3] } }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )++ const out = await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://generativelanguage.googleapis.com/v1beta",+ apiKey: "g-key",+ model: "gemini-embedding-001",+ })++ expect(out).toEqual([0.1, 0.2, 0.3])+ expect(mockHttpFetch).toHaveBeenCalledTimes(1)+ const [url, opts] = mockHttpFetch.mock.calls[0]+ expect(url).toBe("https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-001:embedContent")+ expect((opts?.headers as Record<string, string>)["x-goog-api-key"]).toBe("g-key")+ expect((opts?.headers as Record<string, string>).Authorization).toBeUndefined()+ expect(JSON.parse(String(opts?.body))).toEqual({+ model: "models/gemini-embedding-001",+ content: { parts: [{ text: "hello" }] },+ })+ })++ it("accepts a full Gemini model embedContent endpoint", async () => {+ mockHttpFetch.mockResolvedValueOnce(+ new Response(JSON.stringify({ embedding: { values: [1, 2] } }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )++ const out = await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://generativelanguage.googleapis.com/v1beta/models/text-embedding-004:embedContent",+ apiKey: "g-key",+ model: "text-embedding-004",+ })++ expect(out).toEqual([1, 2])+ expect(mockHttpFetch.mock.calls[0][0]).toBe(+ "https://generativelanguage.googleapis.com/v1beta/models/text-embedding-004:embedContent",+ )+ })++ it("preserves non-key query parameters on pasted Gemini endpoints", async () => {+ mockHttpFetch.mockResolvedValueOnce(+ new Response(JSON.stringify({ embedding: { values: [1] } }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )++ await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-2:embedContent?key=url-key&other=foo",+ apiKey: "header-key",+ model: "gemini-embedding-2",+ })++ expect(mockHttpFetch.mock.calls[0][0]).toBe(+ "https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-2:embedContent?other=foo",+ )+ })++ it("routes custom embedContent proxy endpoints through Gemini format", async () => {+ mockHttpFetch.mockResolvedValueOnce(+ new Response(JSON.stringify({ embedding: { values: [0.7] } }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )++ const out = await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://proxy.example.com/google/models/gemini-embedding-2:embedContent",+ apiKey: "g-key",+ model: "gemini-embedding-2",+ })++ expect(out).toEqual([0.7])+ const [url, opts] = mockHttpFetch.mock.calls[0]+ expect(url).toBe("https://proxy.example.com/google/models/gemini-embedding-2:embedContent")+ expect((opts?.headers as Record<string, string>)["x-goog-api-key"]).toBe("g-key")+ expect(JSON.parse(String(opts?.body))).toEqual({+ model: "models/gemini-embedding-2",+ content: { parts: [{ text: "hello" }] },+ })+ })++ it("trims trailing slashes before building Gemini embedContent endpoint", async () => {+ mockHttpFetch.mockResolvedValueOnce(+ new Response(JSON.stringify({ embedding: { values: [0.8] } }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )++ await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://generativelanguage.googleapis.com/v1beta///",+ apiKey: "g-key",+ model: "gemini-embedding-2",+ })++ expect(mockHttpFetch.mock.calls[0][0]).toBe(+ "https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-2:embedContent",+ )+ })++ it("sends Gemini output_dimensionality when configured", async () => {+ mockHttpFetch.mockResolvedValueOnce(+ new Response(JSON.stringify({ embedding: { values: [0.1, 0.2] } }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )++ const out = await fetchEmbedding("What is the meaning of life?", {+ enabled: true,+ endpoint: "https://generativelanguage.googleapis.com/v1beta",+ apiKey: "g-key",+ model: "gemini-embedding-2",+ outputDimensionality: 768,+ })++ expect(out).toEqual([0.1, 0.2])+ const [, opts] = mockHttpFetch.mock.calls[0]+ expect(JSON.parse(String(opts?.body))).toEqual({+ model: "models/gemini-embedding-2",+ content: { parts: [{ text: "What is the meaning of life?" }] },+ output_dimensionality: 768,+ })+ })++ it("omits invalid Gemini output_dimensionality values", async () => {+ const values = [0, -1, Number.NaN]+ for (const value of values) {+ mockHttpFetch.mockReset()+ mockHttpFetch.mockResolvedValueOnce(+ new Response(JSON.stringify({ embedding: { values: [0.1] } }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )++ await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://generativelanguage.googleapis.com/v1beta",+ apiKey: "g-key",+ model: "gemini-embedding-2",+ outputDimensionality: value,+ })++ expect(JSON.parse(String(mockHttpFetch.mock.calls[0][1]?.body))).toEqual({+ model: "models/gemini-embedding-2",+ content: { parts: [{ text: "hello" }] },+ })+ }+ })++ it("floors fractional Gemini output_dimensionality values", async () => {+ mockHttpFetch.mockResolvedValueOnce(+ new Response(JSON.stringify({ embedding: { values: [0.1] } }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )++ await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://generativelanguage.googleapis.com/v1beta",+ apiKey: "g-key",+ model: "gemini-embedding-2",+ outputDimensionality: 1.5,+ })++ expect(JSON.parse(String(mockHttpFetch.mock.calls[0][1]?.body))).toEqual({+ model: "models/gemini-embedding-2",+ content: { parts: [{ text: "hello" }] },+ output_dimensionality: 1,+ })+ })++ it("normalizes a pasted Gemini batch endpoint to single embedContent", async () => {+ mockHttpFetch.mockResolvedValueOnce(+ new Response(JSON.stringify({ embedding: { values: [0.4] } }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )++ const out = await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-2:batchEmbedContents",+ apiKey: "g-key",+ model: "gemini-embedding-2",+ })++ expect(out).toEqual([0.4])+ expect(mockHttpFetch.mock.calls[0][0]).toBe(+ "https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-2:embedContent",+ )+ })++ it("strips pasted Gemini key query parameters from the endpoint", async () => {+ mockHttpFetch.mockResolvedValueOnce(+ new Response(JSON.stringify({ embedding: { values: [0.5] } }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )++ const out = await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-2:embedContent?key=url-key",+ apiKey: "header-key",+ model: "gemini-embedding-2",+ })++ expect(out).toEqual([0.5])+ const [url, opts] = mockHttpFetch.mock.calls[0]+ expect(url).toBe("https://generativelanguage.googleapis.com/v1beta/models/gemini-embedding-2:embedContent")+ expect((opts?.headers as Record<string, string>)["x-goog-api-key"]).toBe("header-key")+ })++ it("rejects empty Gemini embedding vectors", async () => {+ mockHttpFetch.mockResolvedValueOnce(+ new Response(JSON.stringify({ embedding: { values: [] } }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )++ const out = await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://generativelanguage.googleapis.com/v1beta",+ apiKey: "g-key",+ model: "gemini-embedding-2",+ })++ expect(out).toBeNull()+ expect(getLastEmbeddingError()).toContain("missing embedding.values")+ })++ it("rejects Gemini embedding vectors with NaN or Infinity values", async () => {+ const values = [[Number.NaN], [Number.POSITIVE_INFINITY]]+ for (const vector of values) {+ mockHttpFetch.mockReset()+ mockHttpFetch.mockResolvedValueOnce(+ new Response(JSON.stringify({ embedding: { values: vector } }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )++ const out = await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://generativelanguage.googleapis.com/v1beta",+ apiKey: "g-key",+ model: "gemini-embedding-2",+ })++ expect(out).toBeNull()+ expect(getLastEmbeddingError()).toContain("missing embedding.values")+ }+ })++ it("rejects Gemini embedding vectors with mixed value types", async () => {+ mockHttpFetch.mockResolvedValueOnce(+ new Response(JSON.stringify({ embedding: { values: [1, "x"] } }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )++ const out = await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://generativelanguage.googleapis.com/v1beta",+ apiKey: "g-key",+ model: "gemini-embedding-2",+ })++ expect(out).toBeNull()+ expect(getLastEmbeddingError()).toContain("missing embedding.values")+ })++ it("surfaces Gemini auth errors with HTTP status", async () => {+ mockHttpFetch.mockResolvedValueOnce(+ new Response(JSON.stringify({ error: { message: "API key not valid" } }), {+ status: 403,+ statusText: "Forbidden",+ }),+ )++ const out = await fetchEmbedding("hello", {+ enabled: true,+ endpoint: "https://generativelanguage.googleapis.com/v1beta",+ apiKey: "bad-key",+ model: "gemini-embedding-2",+ })++ expect(out).toBeNull()+ expect(getLastEmbeddingError()).toContain("API 403 Forbidden")+ expect(getLastEmbeddingError()).toContain("API key not valid")+ })++ it("auto-halves Gemini requests after an oversize error", async () => {+ mockHttpFetch+ .mockResolvedValueOnce(+ new Response(JSON.stringify({ error: { message: "input length exceeds context" } }), {+ status: 400,+ statusText: "Bad Request",+ }),+ )+ .mockResolvedValueOnce(+ new Response(JSON.stringify({ embedding: { values: [0.1] } }), {+ status: 200,+ headers: { "Content-Type": "application/json" },+ }),+ )++ const out = await fetchEmbedding("a".repeat(200), {+ enabled: true,+ endpoint: "https://generativelanguage.googleapis.com/v1beta",+ apiKey: "g-key",+ model: "gemini-embedding-2",+ })++ expect(out).toEqual([0.1])+ const firstBody = JSON.parse(String(mockHttpFetch.mock.calls[0][1]?.body))+ const secondBody = JSON.parse(String(mockHttpFetch.mock.calls[1][1]?.body))+ expect(firstBody.content.parts[0].text).toHaveLength(200)+ expect(secondBody.content.parts[0].text).toHaveLength(100)+ })+})+// ── fetchEmbedding auto-halve — via embedPage/searchByEmbedding ─────describe("fetchEmbedding (via searchByEmbedding) — auto-halve", () => {diff --git a/src/lib/embedding.ts b/src/lib/embedding.tsindex 8b12746b..b918008b 100644--- a/src/lib/embedding.ts+++ b/src/lib/embedding.ts@@ -84,8 +84,16 @@ export async function fetchEmbedding(): Promise<number[] | null> {if (!cfg.endpoint) return null+ const isGoogleNative = isGoogleEmbeddingConfig(cfg)+ const endpoint = isGoogleNative ? googleEmbeddingEndpoint(cfg) : cfg.endpointconst headers: Record<string, string> = { "Content-Type": "application/json" }- if (cfg.apiKey) headers.Authorization = `Bearer ${cfg.apiKey}`+ if (cfg.apiKey) {+ if (isGoogleNative) {+ headers["x-goog-api-key"] = cfg.apiKey+ } else {+ headers.Authorization = `Bearer ${cfg.apiKey}`+ }+ }let current = textlet attempts = 0@@ -93,20 +101,27 @@ export async function fetchEmbedding(attempts++try {const httpFetch = await getHttpFetch()- const resp = await httpFetch(cfg.endpoint, {+ const resp = await httpFetch(endpoint, {method: "POST",headers,- body: JSON.stringify({ model: cfg.model, input: current }),+ body: JSON.stringify(+ isGoogleNative+ ? googleEmbeddingBody(cfg.model, current, cfg.outputDimensionality)+ : { model: cfg.model, input: current },+ ),})if (resp.ok) {const data = await resp.json()- const embedding = data?.data?.[0]?.embedding ?? null- if (embedding) {+ const embedding = isGoogleNative+ ? data?.embedding?.values ?? null+ : data?.data?.[0]?.embedding ?? null+ if (isNonEmptyNumberArray(embedding)) {lastEmbeddingError = nullreturn embedding}- lastEmbeddingError = `Embedding response missing data[0].embedding (got ${JSON.stringify(data).slice(0, 200)})`+ const expectedShape = isGoogleNative ? "embedding.values" : "data[0].embedding"+ lastEmbeddingError = `Embedding response missing ${expectedShape} (got ${JSON.stringify(data).slice(0, 200)})`console.warn(`[Embedding] ${lastEmbeddingError}`)return null}@@ -139,12 +154,12 @@ export async function fetchEmbedding(}// Non-oversize definitive failure (auth, rate limit, server down, …).- lastEmbeddingError = `API ${resp.status} ${resp.statusText}${bodyText ? ` — ${bodyText.slice(0, 200)}` : ""} at ${cfg.endpoint}`+ lastEmbeddingError = `API ${resp.status} ${resp.statusText}${bodyText ? ` — ${bodyText.slice(0, 200)}` : ""} at ${endpoint}`console.warn(`[Embedding] ${lastEmbeddingError}`)return null} catch (err) {if (isFetchNetworkError(err)) {- lastEmbeddingError = `Network error reaching ${cfg.endpoint}. Check endpoint URL, API key, and connectivity.`+ lastEmbeddingError = `Network error reaching ${endpoint}. Check endpoint URL, API key, and connectivity.`} else {lastEmbeddingError = err instanceof Error ? err.message : String(err)}@@ -160,6 +175,68 @@ export async function fetchEmbedding(return null}+function isNonEmptyNumberArray(value: unknown): value is number[] {+ return Array.isArray(value)+ && value.length > 0+ && value.every((item) => typeof item === "number" && Number.isFinite(item))+}++function isGoogleEmbeddingConfig(cfg: EmbeddingConfig): boolean {+ const endpoint = cfg.endpoint.toLowerCase()+ return endpoint.includes("generativelanguage.googleapis.com")+ || /:embedcontent(\?|$)/i.test(endpoint)+}++function googleEmbeddingEndpoint(cfg: EmbeddingConfig): string {+ const raw = stripGoogleApiKeyQuery(cfg.endpoint.trim()).replace(/\/+$/, "")+ if (/:batchEmbedContents(\?|$)/i.test(raw)) {+ return raw.replace(/:batchEmbedContents/i, ":embedContent")+ }+ if (/:embedContent(\?|$)/i.test(raw)) return raw++ const modelPath = googleModelPath(cfg.model)+ if (/\/models\/[^/?]+$/i.test(raw)) {+ return `${raw}:embedContent`+ }+ return `${raw}/models/${encodeURIComponent(modelPath.replace(/^models\//, ""))}:embedContent`+}++function stripGoogleApiKeyQuery(endpoint: string): string {+ if (!endpoint.includes("?")) return endpoint+ try {+ const url = new URL(endpoint)+ url.searchParams.delete("key")+ return url.toString()+ } catch {+ return endpoint.replace(/([?&])key=[^&]*&?/i, (_, prefix: string) => prefix === "?" ? "?" : "&")+ .replace(/[?&]$/, "")+ .replace("?&", "?")+ }+}++function googleModelPath(model: string): string {+ const trimmed = model.trim()+ if (trimmed.startsWith("models/")) return trimmed+ return `models/${trimmed}`+}++function googleEmbeddingBody(+ model: string,+ text: string,+ outputDimensionality?: number,+): Record<string, unknown> {+ const body: Record<string, unknown> = {+ model: googleModelPath(model),+ content: {+ parts: [{ text }],+ },+ }+ if (typeof outputDimensionality === "number" && Number.isFinite(outputDimensionality) && outputDimensionality > 0) {+ body.output_dimensionality = Math.floor(outputDimensionality)+ }+ return body+}+// ── LanceDB v2 operations (via Rust Tauri commands) ──────────────────────interface ChunkUpsertInput {diff --git a/src/lib/project-file-sync.test.ts b/src/lib/project-file-sync.test.tsindex 6cc514ab..9ef51492 100644--- a/src/lib/project-file-sync.test.ts+++ b/src/lib/project-file-sync.test.ts@@ -12,6 +12,42 @@ const mocks = vi.hoisted(() => {}),emit: (event: string, payload: unknown) => listeners[event]?.({ payload }),stopProjectFileWatcher: vi.fn(async () => undefined),+ rescanProjectFiles: vi.fn(async (projectId: string): Promise<{+ queue: {+ version: number+ tasks: Array<{+ id: string+ projectId: string+ path: string+ kind: "created" | "modified" | "deleted"+ status: "pending" | "processing" | "done" | "failed" | "superseded"+ createdAt: number+ updatedAt: number+ retryCount: number+ needsRerun: boolean+ }>+ }+ changedTasks: Array<{+ id: string+ projectId: string+ path: string+ kind: "created" | "modified" | "deleted"+ status: "pending" | "processing" | "done" | "failed" | "superseded"+ createdAt: number+ updatedAt: number+ retryCount: number+ needsRerun: boolean+ }>+ }> => {+ void projectId+ return {+ queue: {+ version: 1,+ tasks: [],+ },+ changedTasks: [],+ }+ }),startProjectFileWatcher: vi.fn(() => new Promise((resolve) => {resolvers.push(resolve)})),@@ -58,6 +94,7 @@ vi.mock("@tauri-apps/api/event", () => ({}))vi.mock("@/commands/file-sync", () => ({+ rescanProjectFiles: mocks.rescanProjectFiles,startProjectFileWatcher: mocks.startProjectFileWatcher,stopProjectFileWatcher: mocks.stopProjectFileWatcher,}))@@ -92,6 +129,16 @@ describe("project file sync", () => {vi.useRealTimers()vi.clearAllMocks()mocks.clearResolvers()+ mocks.rescanProjectFiles.mockImplementation(async (projectId: string) => {+ void projectId+ return {+ queue: {+ version: 1,+ tasks: [],+ },+ changedTasks: [],+ }+ })mocks.listDirectory.mockImplementation(async (_path?: string) => [])mocks.readFile.mockImplementation(async (_path?: string) => "")mocks.getFileSize.mockImplementation(async (_path?: string) => 1024)@@ -235,6 +282,150 @@ describe("project file sync", () => {expect(mocks.enqueueBatch).not.toHaveBeenCalled()})+ it("manual rescan uses the same source ingest flow when the watcher is stopped", async () => {+ const { rescanProjectFileSync } = await import("@/lib/project-file-sync")+ const { useWikiStore } = await import("@/stores/wiki-store")++ const project = { id: "A", name: "A", path: "/tmp/a" }+ useWikiStore.getState().setProject(project)+ mocks.rescanProjectFiles.mockImplementation(async (projectId: string) => {+ return {+ queue: { version: 1, tasks: [] },+ changedTasks: [+ {+ id: "t1",+ projectId,+ path: "raw/sources/manual.pdf",+ kind: "created",+ status: "done",+ createdAt: 1,+ updatedAt: 1,+ retryCount: 0,+ needsRerun: false,+ },+ ],+ }+ })++ await rescanProjectFileSync(project)++ expect(mocks.rescanProjectFiles).toHaveBeenCalledWith(+ "A",+ "/tmp/a",+ expect.objectContaining({ enabled: true, autoIngest: true }),+ )+ expect(mocks.enqueueBatch).toHaveBeenCalledWith("A", [+ { sourcePath: "raw/sources/manual.pdf", folderContext: "" },+ ])+ })++ it("manual rescan uses returned changed tasks while the watcher is running", async () => {+ const { startProjectFileSync, rescanProjectFileSync } = await import("@/lib/project-file-sync")+ const { useWikiStore } = await import("@/stores/wiki-store")++ const project = { id: "A", name: "A", path: "/tmp/a" }+ useWikiStore.getState().setProject(project)+ void startProjectFileSync(project)+ await vi.waitFor(() => {+ expect(mocks.listen).toHaveBeenCalledTimes(2)+ })++ mocks.rescanProjectFiles.mockImplementation(async (projectId: string) => ({+ queue: { version: 1, tasks: [] },+ changedTasks: [+ {+ id: "t1",+ projectId,+ path: "raw/sources/watcher-running.pdf",+ kind: "created",+ status: "done",+ createdAt: 1,+ updatedAt: 1,+ retryCount: 0,+ needsRerun: false,+ },+ ],+ }))++ await rescanProjectFileSync(project)++ expect(mocks.enqueueBatch).toHaveBeenCalledWith("A", [+ { sourcePath: "raw/sources/watcher-running.pdf", folderContext: "" },+ ])+ })++ it("manual rescan ignores changed tasks after project switch", async () => {+ const { rescanProjectFileSync } = await import("@/lib/project-file-sync")+ const { useWikiStore } = await import("@/stores/wiki-store")++ const projectA = { id: "A", name: "A", path: "/tmp/a" }+ const projectB = { id: "B", name: "B", path: "/tmp/b" }+ useWikiStore.getState().setProject(projectA)+ mocks.rescanProjectFiles.mockImplementation(async (projectId: string) => {+ useWikiStore.getState().setProject(projectB)+ return {+ queue: { version: 1, tasks: [] },+ changedTasks: [+ {+ id: "t1",+ projectId,+ path: "raw/sources/stale.pdf",+ kind: "created",+ status: "done",+ createdAt: 1,+ updatedAt: 1,+ retryCount: 0,+ needsRerun: false,+ },+ ],+ }+ })++ await rescanProjectFileSync(projectA)++ expect(mocks.enqueueBatch).not.toHaveBeenCalled()+ })++ it("manual rescan refreshes the file tree when no files changed", async () => {+ const { rescanProjectFileSync } = await import("@/lib/project-file-sync")+ const { useWikiStore } = await import("@/stores/wiki-store")++ const project = { id: "A", name: "A", path: "/tmp/a" }+ useWikiStore.getState().setProject(project)++ await rescanProjectFileSync(project)++ expect(mocks.listDirectory).toHaveBeenCalledWith("/tmp/a")+ })++ it("manual rescan respects auto ingest disabled", async () => {+ const { rescanProjectFileSync } = await import("@/lib/project-file-sync")+ const { useWikiStore } = await import("@/stores/wiki-store")++ const project = { id: "A", name: "A", path: "/tmp/a" }+ useWikiStore.getState().setProject(project)+ mocks.rescanProjectFiles.mockImplementation(async (projectId: string) => ({+ queue: { version: 1, tasks: [] },+ changedTasks: [+ {+ id: "t1",+ projectId,+ path: "raw/sources/manual.pdf",+ kind: "created",+ status: "done",+ createdAt: 1,+ updatedAt: 1,+ retryCount: 0,+ needsRerun: false,+ },+ ],+ }))++ await rescanProjectFileSync(project, { autoIngest: false } as never)++ expect(mocks.enqueueBatch).not.toHaveBeenCalled()+ })+it("removes an externally deleted raw source from every wiki page sources field", async () => {vi.useFakeTimers()const { startProjectFileSync } = await import("@/lib/project-file-sync")diff --git a/src/lib/project-file-sync.ts b/src/lib/project-file-sync.tsindex dad7445d..a31b2848 100644--- a/src/lib/project-file-sync.ts+++ b/src/lib/project-file-sync.ts@@ -1,6 +1,7 @@import { listen, type UnlistenFn } from "@tauri-apps/api/event"import { readFile, listDirectory } from "@/commands/fs"import {+ rescanProjectFiles,startProjectFileWatcher,stopProjectFileWatcher,type FileSyncPayload,@@ -87,6 +88,26 @@ export async function stopProjectFileSync(): Promise<void> {}}+export async function rescanProjectFileSync(+ project: WikiProject,+ sourceWatchConfig?: SourceWatchConfig,+): Promise<void> {+ const config = normalizeSourceWatchConfig(sourceWatchConfig ?? useWikiStore.getState().sourceWatchConfig)+ activeSourceWatchConfig = config++ const result = await rescanProjectFiles(project.id, normalizePath(project.path), config)+ if (useWikiStore.getState().project?.id !== project.id) return+ useFileSyncStore.getState().setTasks(result.queue.tasks)++ if (useWikiStore.getState().project?.id !== project.id) return+ if (result.changedTasks.length > 0) {+ const paths = [...new Set(result.changedTasks.map((task) => task.path))]+ await processFileChangeBatch(project, paths, result.changedTasks)+ } else {+ await refreshAfterFileChanges(project, [])+ }+}+function scheduleRefreshAfterFileChanges(tasks: FileChangeTask[]): void {for (const task of tasks) {pendingRefreshPaths.add(task.path)@@ -147,7 +168,7 @@ async function refreshAfterFileChanges(project: WikiProject, relativePaths: stri}async function enqueueRawSourceChanges(project: WikiProject, tasks: FileChangeTask[]): Promise<void> {- const config = normalizeSourceWatchConfig(useWikiStore.getState().sourceWatchConfig ?? activeSourceWatchConfig)+ const config = normalizeSourceWatchConfig(activeSourceWatchConfig)if (!config.enabled || !config.autoIngest) returnconst candidates = tasksdiff --git a/src/stores/wiki-store.ts b/src/stores/wiki-store.tsindex b1be2ed0..b19a5894 100644--- a/src/stores/wiki-store.ts+++ b/src/stores/wiki-store.ts@@ -75,6 +75,8 @@ interface EmbeddingConfig {endpoint: string // e.g. "http://127.0.0.1:1234/v1/embeddings"apiKey: stringmodel: string // e.g. "text-embedding-qwen3-embedding-0.6b"+ /** Optional Gemini native `output_dimensionality` value. Ignored by OpenAI-compatible endpoints. */+ outputDimensionality?: number/*** Chunking knobs (Phase 1 RAG). Undefined values fall back to the* chunker's built-in defaults in `src/lib/text-chunker.ts`: