feat: 切换对话时恢复对应的Agent显示
This commit is contained in:
@@ -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