From 464b9b43dd67ad96f1463e7e2dc401ccae8607ba Mon Sep 17 00:00:00 2001 From: mrsibe Date: Thu, 24 Sep 2026 18:16:26 +0800 Subject: [PATCH] fix(embedding): treat the built-in local backend as available SourcePanel decided whether the notebook could take documents by checking connections.embedding. Selecting the built-in local backend removes that connection, so the panel claimed embedding was not configured, disabled Add Source and blocked file/URL/paste/note import. Embedding is infrastructure now: EmbeddingService falls back to the built-in local model when no remote connection exists and downloads it on first RAG use. Read the real backend state from embedding:get-status instead and refresh it on connection and download changes. --- .../src/components/notebook/SourcePanel.tsx | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/renderer/src/components/notebook/SourcePanel.tsx b/src/renderer/src/components/notebook/SourcePanel.tsx index 8d3bd8b..8daae92 100644 --- a/src/renderer/src/components/notebook/SourcePanel.tsx +++ b/src/renderer/src/components/notebook/SourcePanel.tsx @@ -253,20 +253,32 @@ export default function SourcePanel(): ReactElement { const { openSettings } = useUIStore() - // 检查是否配置了 embedding connection + // Embedding 是基础设施:没有远程 connection 时由内置本地模型承担(首次 RAG 使用按需下载)。 + // 因此可用性取决于真实后端状态,而不是 connections.embedding 是否存在——内置模式不会写入 connection。 useEffect(() => { - const loadEmbeddingConnection = async () => { - const connections = await window.api.connections.getAll() - setHasEmbeddingModel(Boolean(connections.embedding)) + const loadEmbeddingAvailability = async (): Promise => { + try { + const status = await window.api.embedding.getStatus() + setHasEmbeddingModel(status.activeBackend === 'local' || status.remoteConfigured) + } catch (error) { + console.error('[SourcePanel] Failed to load embedding status:', error) + setHasEmbeddingModel(false) + } } - void loadEmbeddingConnection() + void loadEmbeddingAvailability() - // 监听连接配置变化 - const unsubscribe = window.api.connections.onChanged(() => { - void loadEmbeddingConnection() + // 远程/内置切换、模型安装状态变化都会影响可用性 + const unsubscribeConnections = window.api.connections.onChanged(() => { + void loadEmbeddingAvailability() + }) + const unsubscribeProgress = window.api.embedding.onDownloadProgress(() => { + void loadEmbeddingAvailability() }) - return unsubscribe + return () => { + unsubscribeConnections() + unsubscribeProgress() + } }, []) // 设置监听器