fix(chat): 优化消息加载逻辑,移除不必要的延迟参数( Error: 关于v0.5版本数据库引发的问题
Fixes #513)
This commit is contained in:
parent
5fa89ddc85
commit
74cb569569
@ -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}")
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user