feat: 切换对话时恢复对应的Agent显示
This commit is contained in:
@@ -546,14 +546,20 @@ async def websocket_endpoint(websocket: WebSocket, user_id: str):
|
||||
|
||||
if conversation:
|
||||
messages = conv_service.get_messages(conversation.id)
|
||||
|
||||
# 获取对话使用的Agent ID
|
||||
conv_agent_id = conversation.current_agent_id
|
||||
|
||||
await websocket.send_json({
|
||||
"type": "history",
|
||||
"conversation_id": current_conversation_id,
|
||||
"agent_id": conv_agent_id, # 返回对话的Agent ID
|
||||
"messages": [
|
||||
{
|
||||
"role": m.role,
|
||||
"content": m.content,
|
||||
"thinking_content": m.thinking_content,
|
||||
"agent_id": m.agent_id, # 每条消息的Agent ID
|
||||
"source": m.source,
|
||||
"created_at": m.created_at.isoformat()
|
||||
}
|
||||
|
||||
@@ -192,10 +192,7 @@
|
||||
const data = await res.json();
|
||||
agents = data.agents || [];
|
||||
|
||||
const select = document.getElementById('agentSelect');
|
||||
select.innerHTML = agents.filter(a => a.is_active).map(a =>
|
||||
`<option value="${a.id}" ${a.is_default ? 'selected' : ''}>${a.display_name || a.name}</option>`
|
||||
).join('');
|
||||
renderAgentSelect();
|
||||
|
||||
// 设置当前Agent
|
||||
const defaultAgent = agents.find(a => a.is_default) || agents[0];
|
||||
@@ -206,6 +203,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 渲染Agent下拉框
|
||||
function renderAgentSelect(selectedId = null) {
|
||||
const select = document.getElementById('agentSelect');
|
||||
const selected = selectedId || currentAgentId;
|
||||
select.innerHTML = agents.filter(a => a.is_active).map(a =>
|
||||
`<option value="${a.id}" ${a.id === selected ? 'selected' : ''}>${a.display_name || a.name}</option>`
|
||||
).join('');
|
||||
}
|
||||
|
||||
// 更新Agent选择框显示
|
||||
function updateAgentSelect(agentId) {
|
||||
const select = document.getElementById('agentSelect');
|
||||
select.value = agentId;
|
||||
currentAgentId = agentId;
|
||||
}
|
||||
|
||||
// 切换Agent - 自动创建新对话
|
||||
async function switchAgent() {
|
||||
const newAgentId = document.getElementById('agentSelect').value;
|
||||
@@ -336,6 +349,11 @@
|
||||
switch (data.type) {
|
||||
case 'history':
|
||||
displayHistory(data.messages);
|
||||
// 更新Agent选择框为该对话使用的Agent
|
||||
if (data.agent_id) {
|
||||
currentAgentId = data.agent_id;
|
||||
updateAgentSelect(data.agent_id);
|
||||
}
|
||||
break;
|
||||
case 'conversation_created':
|
||||
currentConversationId = data.conversation_id;
|
||||
|
||||
Reference in New Issue
Block a user