fix: 修复Agent执行历史为空的问题
- 在Agent初始化时添加示例执行历史 - 添加触发示例动作和清空历史的功能 - 完善Agent执行历史的显示界面 - 添加执行历史的操作按钮(触发示例、刷新、清空) - 优化执行历史的显示格式,包括优先级、置信度、执行时间等 - 修复前端Agent数据加载逻辑
This commit is contained in:
@@ -615,7 +615,7 @@ class TSPDashboard {
|
||||
this.updateToolsList(data.tools || []);
|
||||
|
||||
// 更新执行历史
|
||||
this.updateExecutionHistory(data.execution_history || []);
|
||||
this.updateAgentExecutionHistory(data.execution_history || []);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载Agent数据失败:', error);
|
||||
@@ -2009,6 +2009,136 @@ class TSPDashboard {
|
||||
window.print();
|
||||
}
|
||||
|
||||
// Agent执行历史相关功能
|
||||
async refreshAgentHistory() {
|
||||
try {
|
||||
const response = await fetch('/api/agent/action-history?limit=20');
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
this.updateAgentExecutionHistory(data.history);
|
||||
this.showNotification(`已加载 ${data.count} 条执行历史`, 'success');
|
||||
} else {
|
||||
throw new Error(data.error || '获取执行历史失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('刷新Agent历史失败:', error);
|
||||
this.showNotification('刷新Agent历史失败: ' + error.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async triggerSampleAction() {
|
||||
try {
|
||||
const response = await fetch('/api/agent/trigger-sample', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
this.showNotification(data.message, 'success');
|
||||
// 刷新执行历史
|
||||
await this.refreshAgentHistory();
|
||||
} else {
|
||||
throw new Error(data.error || '触发示例动作失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('触发示例动作失败:', error);
|
||||
this.showNotification('触发示例动作失败: ' + error.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async clearAgentHistory() {
|
||||
if (!confirm('确定要清空Agent执行历史吗?此操作不可恢复。')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/agent/clear-history', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
this.showNotification(data.message, 'success');
|
||||
// 清空显示
|
||||
this.updateAgentExecutionHistory([]);
|
||||
} else {
|
||||
throw new Error(data.error || '清空历史失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('清空Agent历史失败:', error);
|
||||
this.showNotification('清空Agent历史失败: ' + error.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
updateAgentExecutionHistory(history) {
|
||||
const container = document.getElementById('agent-execution-history');
|
||||
|
||||
if (!history || history.length === 0) {
|
||||
container.innerHTML = `
|
||||
<div class="empty-state">
|
||||
<i class="fas fa-history"></i>
|
||||
<p>暂无执行历史</p>
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
const historyHtml = history.map(record => {
|
||||
const startTime = new Date(record.start_time * 1000).toLocaleString();
|
||||
const endTime = new Date(record.end_time * 1000).toLocaleString();
|
||||
const duration = Math.round((record.end_time - record.start_time) * 100) / 100;
|
||||
|
||||
const priorityColor = {
|
||||
5: 'danger',
|
||||
4: 'warning',
|
||||
3: 'info',
|
||||
2: 'secondary',
|
||||
1: 'light'
|
||||
}[record.priority] || 'secondary';
|
||||
|
||||
const confidenceColor = record.confidence >= 0.8 ? 'success' :
|
||||
record.confidence >= 0.5 ? 'warning' : 'danger';
|
||||
|
||||
return `
|
||||
<div class="card mb-2">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between align-items-start">
|
||||
<div class="flex-grow-1">
|
||||
<h6 class="mb-1">${record.description}</h6>
|
||||
<div class="d-flex gap-3 mb-2">
|
||||
<span class="badge bg-${priorityColor}">优先级 ${record.priority}</span>
|
||||
<span class="badge bg-${confidenceColor}">置信度 ${(record.confidence * 100).toFixed(0)}%</span>
|
||||
<span class="badge bg-${record.success ? 'success' : 'danger'}">${record.success ? '成功' : '失败'}</span>
|
||||
</div>
|
||||
<small class="text-muted">
|
||||
<i class="fas fa-clock me-1"></i>开始: ${startTime} |
|
||||
<i class="fas fa-stopwatch me-1"></i>耗时: ${duration}秒
|
||||
</small>
|
||||
</div>
|
||||
<div class="ms-3">
|
||||
<span class="badge bg-primary">${record.action_type}</span>
|
||||
</div>
|
||||
</div>
|
||||
${record.result && record.result.message ? `
|
||||
<div class="mt-2">
|
||||
<small class="text-muted">结果: ${record.result.message}</small>
|
||||
</div>
|
||||
` : ''}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
|
||||
container.innerHTML = historyHtml;
|
||||
}
|
||||
|
||||
// 更新分析报告
|
||||
updateAnalyticsReport(data) {
|
||||
const reportContainer = document.getElementById('analytics-report');
|
||||
|
||||
Reference in New Issue
Block a user