From 74cb56956977c99a207ac95f365ddcb2250f6903 Mon Sep 17 00:00:00 2001 From: Wenjie Zhang Date: Wed, 25 Feb 2026 12:17:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(chat):=20=E4=BC=98=E5=8C=96=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=8A=A0=E8=BD=BD=E9=80=BB=E8=BE=91=EF=BC=8C=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E4=B8=8D=E5=BF=85=E8=A6=81=E7=9A=84=E5=BB=B6=E8=BF=9F?= =?UTF-8?q?=E5=8F=82=E6=95=B0=EF=BC=88=20Error:=20=E5=85=B3=E4=BA=8Ev0.5?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E6=95=B0=E6=8D=AE=E5=BA=93=E5=BC=95=E5=8F=91?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20Fixes=20#513=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/chat_stream_service.py | 9 ++++++--- web/src/components/AgentChatComponent.vue | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/services/chat_stream_service.py b/src/services/chat_stream_service.py index 49e4be61..a1bd5b1a 100644 --- a/src/services/chat_stream_service.py +++ b/src/services/chat_stream_service.py @@ -433,8 +433,7 @@ async def stream_agent_chat( if agent_state: yield make_chunk(status="agent_state", agent_state=agent_state, meta=meta) - yield make_chunk(status="finished", meta=meta) - + # 先存储数据库,再返回 finished,避免前端查询时数据未落库 await save_messages_from_langgraph_state( agent_instance=agent, thread_id=thread_id, @@ -442,6 +441,8 @@ async def stream_agent_chat( config_dict=langgraph_config, ) + yield make_chunk(status="finished", meta=meta) + except (asyncio.CancelledError, ConnectionError) as e: logger.warning(f"Client disconnected, cancelling stream: {e}") @@ -589,8 +590,8 @@ async def stream_agent_resume( yield chunk meta["time_cost"] = asyncio.get_event_loop().time() - start_time - yield make_resume_chunk(status="finished", meta=meta) + # 先存储数据库,再返回 finished,避免前端查询时数据未落库 conv_repo = ConversationRepository(db) await save_messages_from_langgraph_state( agent_instance=agent, @@ -599,6 +600,8 @@ async def stream_agent_resume( config_dict=langgraph_config, ) + yield make_resume_chunk(status="finished", meta=meta) + except (asyncio.CancelledError, ConnectionError) as e: logger.warning(f"Client disconnected during resume: {e}") diff --git a/web/src/components/AgentChatComponent.vue b/web/src/components/AgentChatComponent.vue index bfe2e111..04875ba6 100644 --- a/web/src/components/AgentChatComponent.vue +++ b/web/src/components/AgentChatComponent.vue @@ -962,7 +962,7 @@ const handleSendMessage = async ({ image } = {}) => { } finally { threadState.streamAbortController = null // 异步加载历史记录,保持当前消息显示直到历史记录加载完成 - fetchThreadMessages({ agentId: currentAgentId.value, threadId: threadId, delay: 500 }).finally( + fetchThreadMessages({ agentId: currentAgentId.value, threadId: threadId }).finally( () => { // 历史记录加载完成后,安全地清空当前进行中的对话 resetOnGoingConv(threadId) @@ -982,7 +982,7 @@ const handleSendOrStop = async (payload) => { // 中断后刷新消息历史,确保显示最新的状态 try { - await fetchThreadMessages({ agentId: currentAgentId.value, threadId: threadId, delay: 500 }) + await fetchThreadMessages({ agentId: currentAgentId.value, threadId: threadId }) message.info('已中断对话生成') } catch (error) { console.error('刷新消息历史失败:', error) @@ -1043,7 +1043,7 @@ const handleApprovalWithStream = async (approved) => { } // 异步加载历史记录,保持当前消息显示直到历史记录加载完成 - fetchThreadMessages({ agentId: currentAgentId.value, threadId: threadId, delay: 500 }).finally( + fetchThreadMessages({ agentId: currentAgentId.value, threadId: threadId }).finally( () => { // 历史记录加载完成后,安全地清空当前进行中的对话 resetOnGoingConv(threadId)