From 13291fba772b91601ecd3822e89ac5d6fd260f1f Mon Sep 17 00:00:00 2001 From: Metona Date: Sun, 5 Apr 2026 00:53:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B5=81=E7=BB=93=E6=9D=9F=E5=90=8E?= =?UTF-8?q?=E6=89=8B=E5=8A=A8=E6=8F=92=E5=85=A5RAG=E6=9D=A5=E6=BA=90?= =?UTF-8?q?=E5=88=B0DOM=EF=BC=8C=E8=A7=A3=E5=86=B3=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E4=B8=AD=E4=B8=8D=E6=98=BE=E7=A4=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ragSources 在流结束后才添加到消息对象,但 assistant 消息 DOM 已由流式更新创建, renderMessages 只追加新消息不会重新渲染已有元素。 直接在流结束后将 RAG 来源 HTML 插入到 msg-body 中。 --- js/components/input-area.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/js/components/input-area.js b/js/components/input-area.js index be530e3..96dd74d 100644 --- a/js/components/input-area.js +++ b/js/components/input-area.js @@ -508,6 +508,21 @@ ${ragContext} updateLastAssistantMessage(assistantContent, thinkContent || null, finalStats, modelName || null); } + // 流结束后插入 RAG 来源到现有 DOM(renderMessages 不会重新渲染已有消息) + if (ragSources && ragSources.length > 0) { + const lastAssistant = document.querySelector('#messagesContainer .message.assistant:last-of-type'); + if (lastAssistant) { + const sourcesHtml = ragSources.map((s, i) => { + const scorePercent = s.score ? `${(s.score * 100).toFixed(0)}%` : ''; + return `
📄 来源 ${i + 1}: ${escapeHtml(s.filename)}${scorePercent ? `${scorePercent}` : ''}
`; + }).join(''); + const ragDiv = document.createElement('div'); + ragDiv.className = 'rag-sources'; + ragDiv.innerHTML = `
🧠 基于知识库回答
${sourcesHtml}`; + lastAssistant.querySelector('.msg-body').appendChild(ragDiv); + } + } + await saveCurrentSession(); } catch (err) {