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