fix: 搜索结果持久化保存,刷新页面后历史对话也显示搜索结果
- 用户消息 extra_data 存储搜索结果 - API 返回消息时包含 extra_data - 前端 displayHistory 处理历史搜索结果显示
This commit is contained in:
@@ -648,6 +648,7 @@ async def get_messages(conversation_id: str, db: Session = Depends(get_db)):
|
||||
"role": m.role,
|
||||
"content": m.content,
|
||||
"thinking_content": m.thinking_content, # v2新增
|
||||
"extra_data": m.extra_data, # 包含搜索结果等
|
||||
"source": m.source,
|
||||
"agent_id": m.agent_id, # v2新增
|
||||
"model_used": m.model_used, # v2新增
|
||||
@@ -807,6 +808,7 @@ async def websocket_endpoint(websocket: WebSocket, user_id: str):
|
||||
|
||||
# 4. 执行搜索并发送搜索结果
|
||||
search_context = None
|
||||
search_results_for_client = None # 用于发送给前端和保存
|
||||
logger.info(f"检查搜索条件: agent_tools={agent_tools}, disabled_tools={disabled_tools}")
|
||||
|
||||
if 'search' in agent_tools and 'search' not in disabled_tools:
|
||||
@@ -888,12 +890,13 @@ async def websocket_endpoint(websocket: WebSocket, user_id: str):
|
||||
'duration_ms': duration_ms
|
||||
})
|
||||
|
||||
# 5. 保存用户消息到数据库
|
||||
# 5. 保存用户消息到数据库(包含搜索结果)
|
||||
user_msg = conv_service.add_message(
|
||||
conversation_id=conversation.id,
|
||||
role='user',
|
||||
content=message,
|
||||
source='web'
|
||||
source='web',
|
||||
extra_data={'search_results': search_results_for_client, 'search_query': message} if search_results_for_client else None
|
||||
)
|
||||
|
||||
# 6. 获取对话历史(包含刚保存的用户消息)
|
||||
|
||||
Reference in New Issue
Block a user