From d1431ac5212e35316cb2d32a3f14ff89de58d5d2 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Mon, 13 Apr 2026 23:10:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20WebSocket=20history=20=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20extra=5Fdata=20=E5=AD=97=E6=AE=B5=EF=BC=8C?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E7=BB=93=E6=9E=9C=E5=8F=AF=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main_v2.py | 1 + templates/index.html | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/main_v2.py b/main_v2.py index eb7c60d..78d3ee2 100644 --- a/main_v2.py +++ b/main_v2.py @@ -743,6 +743,7 @@ async def websocket_endpoint(websocket: WebSocket, user_id: str): "role": m.role, "content": m.content, "thinking_content": m.thinking_content, + "extra_data": m.extra_data, # 包含搜索结果等 "agent_id": m.agent_id, # 每条消息的Agent ID "source": m.source, "created_at": m.created_at.isoformat() diff --git a/templates/index.html b/templates/index.html index 23cadae..aa1bb90 100644 --- a/templates/index.html +++ b/templates/index.html @@ -373,12 +373,18 @@ div.innerHTML = html; // 如果是用户消息且有搜索结果,在设置innerHTML后追加 - if (role === 'user' && extraData && extraData.search_results && extraData.search_results.length > 0) { - const searchHtml = buildSearchResultsHtml(extraData.search_results, extraData.search_query || content); - // 直接追加到 div 的 innerHTML - const bodyDiv = div.querySelector('.message-body'); - if (bodyDiv) { - bodyDiv.insertAdjacentHTML('beforeend', searchHtml); + if (role === 'user' && extraData) { + console.log('Processing extraData for user message:', extraData); + console.log('search_results exists:', extraData.search_results); + if (extraData.search_results && extraData.search_results.length > 0) { + console.log('Building search results HTML for', extraData.search_results.length, 'results'); + const searchHtml = buildSearchResultsHtml(extraData.search_results, extraData.search_query || content); + const bodyDiv = div.querySelector('.message-body'); + console.log('bodyDiv found:', bodyDiv != null); + if (bodyDiv) { + bodyDiv.insertAdjacentHTML('beforeend', searchHtml); + console.log('Search results HTML inserted'); + } } } @@ -634,6 +640,7 @@ const container = document.getElementById('messagesContainer'); container.innerHTML = ''; messages.forEach(m => { + console.log('displayHistory message:', m.role, 'extra_data:', m.extra_data); appendMessage(m.role, m.content, m.thinking_content, null, m.extra_data); }); }