-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualization.html
More file actions
298 lines (272 loc) · 11.2 KB
/
Copy pathvisualization.html
File metadata and controls
298 lines (272 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Agent进化系统 - 事件可视化</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Segoe UI', Arial, sans-serif;
background: #0a0e27;
color: #e0e0e0;
padding: 20px;
}
.header {
text-align: center;
padding: 30px 0;
border-bottom: 2px solid #1e2a4a;
}
h1 { color: #64b5f6; font-size: 2em; }
.controls {
display: flex;
gap: 15px;
justify-content: center;
margin: 20px 0;
flex-wrap: wrap;
}
button {
background: #1e3a5f;
color: #64b5f6;
border: 1px solid #2c5282;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s;
}
button:hover { background: #2c5282; }
button.active { background: #64b5f6; color: #0a0e27; }
.stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin: 20px 0;
}
.stat-card {
background: #1a1f3a;
padding: 20px;
border-radius: 8px;
border: 1px solid #2c3e5f;
}
.stat-value { font-size: 2em; color: #64b5f6; font-weight: bold; }
.stat-label { color: #9e9e9e; margin-top: 5px; }
.timeline {
margin-top: 30px;
position: relative;
}
.event {
background: #1a1f3a;
border-left: 4px solid #64b5f6;
padding: 15px;
margin: 10px 0;
border-radius: 5px;
transition: all 0.3s;
}
.event:hover { transform: translateX(5px); box-shadow: 0 4px 12px rgba(100, 181, 246, 0.2); }
.event.task { border-left-color: #4caf50; }
.event.attack { border-left-color: #f44336; }
.event.evolution { border-left-color: #ff9800; }
.event.elimination { border-left-color: #9c27b0; }
.event-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.event-type {
display: inline-block;
padding: 4px 12px;
border-radius: 12px;
font-size: 0.85em;
font-weight: bold;
}
.event-type.task { background: #4caf50; color: white; }
.event-type.attack { background: #f44336; color: white; }
.event-type.evolution { background: #ff9800; color: white; }
.event-type.elimination { background: #9c27b0; color: white; }
.event-time { color: #757575; font-size: 0.9em; }
.event-content { line-height: 1.6; }
.event-detail {
background: #0f1429;
padding: 10px;
margin-top: 10px;
border-radius: 4px;
font-family: 'Courier New', monospace;
font-size: 0.9em;
max-height: 300px;
overflow-y: auto;
}
.llm-thinking {
background: #1e2a4a;
padding: 10px;
margin: 5px 0;
border-radius: 4px;
border-left: 3px solid #64b5f6;
}
.no-data {
text-align: center;
padding: 50px;
color: #757575;
}
.file-input {
display: none;
}
.load-file-btn {
background: #2e7d32;
color: white;
}
.load-file-btn:hover { background: #388e3c; }
</style>
</head>
<body>
<div class="header">
<h1>🧬 Agent进化系统 - 事件可视化</h1>
</div>
<div class="controls">
<input type="file" id="fileInput" class="file-input" accept=".jsonl">
<button class="load-file-btn" onclick="document.getElementById('fileInput').click()">
📂 加载 events.jsonl
</button>
<button class="active" data-filter="all">全部</button>
<button data-filter="task">任务执行</button>
<button data-filter="attack">攻击</button>
<button data-filter="evolution">进化</button>
<button data-filter="elimination">淘汰</button>
</div>
<div class="stats" id="stats"></div>
<div class="timeline" id="timeline"></div>
<script>
let allEvents = [];
let currentFilter = 'all';
// 文件加载
document.getElementById('fileInput').addEventListener('change', function(e) {
const file = e.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(event) {
const lines = event.target.result.split('\n').filter(l => l.trim());
allEvents = lines.map(line => JSON.parse(line));
renderStats();
renderTimeline();
};
reader.readAsText(file);
});
// 过滤按钮
document.querySelectorAll('.controls button[data-filter]').forEach(btn => {
btn.addEventListener('click', function() {
document.querySelectorAll('.controls button[data-filter]').forEach(b => b.classList.remove('active'));
this.classList.add('active');
currentFilter = this.dataset.filter;
renderTimeline();
});
});
function renderStats() {
const stats = {
total: allEvents.length,
task: allEvents.filter(e => e.event_type === 'task_execution').length,
attack: allEvents.filter(e => e.event_type === 'attack').length,
evolution: allEvents.filter(e => e.event_type === 'evolution').length,
elimination: allEvents.filter(e => e.event_type === 'elimination').length
};
document.getElementById('stats').innerHTML = `
<div class="stat-card">
<div class="stat-value">${stats.total}</div>
<div class="stat-label">总事件数</div>
</div>
<div class="stat-card">
<div class="stat-value">${stats.task}</div>
<div class="stat-label">任务执行</div>
</div>
<div class="stat-card">
<div class="stat-value">${stats.attack}</div>
<div class="stat-label">攻击事件</div>
</div>
<div class="stat-card">
<div class="stat-value">${stats.evolution}</div>
<div class="stat-label">进化事件</div>
</div>
<div class="stat-card">
<div class="stat-value">${stats.elimination}</div>
<div class="stat-label">淘汰事件</div>
</div>
`;
}
function renderTimeline() {
const filtered = currentFilter === 'all'
? allEvents
: allEvents.filter(e => e.event_type === currentFilter ||
(currentFilter === 'task' && e.event_type === 'task_execution'));
if (filtered.length === 0) {
document.getElementById('timeline').innerHTML = '<div class="no-data">暂无数据,请加载 events.jsonl 文件</div>';
return;
}
const html = filtered.map(event => renderEvent(event)).join('');
document.getElementById('timeline').innerHTML = html;
}
function renderEvent(event) {
const time = new Date(event.timestamp * 1000).toLocaleString('zh-CN');
const type = event.event_type === 'task_execution' ? 'task' : event.event_type;
let content = '';
if (type === 'task') {
const success = event.result?.success ? '✅ 成功' : '❌ 失败';
content = `
<div><strong>Agent:</strong> ${event.agent_id}</div>
<div><strong>任务:</strong> ${event.task_id} (难度 ${event.task_difficulty})</div>
<div><strong>结果:</strong> ${success}</div>
${event.llm_details ? `
<div class="event-detail">
<div class="llm-thinking">
<strong>💭 LLM思考:</strong><br>
<strong>输入:</strong> ${event.llm_details.prompt?.substring(0, 200)}...<br>
<strong>输出:</strong> ${event.llm_details.response?.substring(0, 200)}...<br>
<strong>Tokens:</strong> ${event.llm_details.tokens}
</div>
</div>
` : ''}
`;
} else if (type === 'attack') {
const success = event.success ? '✅ 成功' : '❌ 失败';
content = `
<div><strong>攻击者:</strong> ${event.attacker_id}</div>
<div><strong>目标:</strong> ${event.target_id}</div>
<div><strong>类型:</strong> ${event.attack_type}</div>
<div><strong>结果:</strong> ${success}</div>
${event.damage ? `<div><strong>伤害:</strong> ${event.damage}</div>` : ''}
`;
} else if (type === 'evolution') {
content = `
<div><strong>父代:</strong> ${event.parent_ids?.join(', ') || '无'}</div>
<div><strong>子代:</strong> ${event.child_id}</div>
<div><strong>变异信息:</strong> ${JSON.stringify(event.mutation_info)}</div>
`;
} else if (type === 'elimination') {
content = `
<div><strong>淘汰Agent:</strong> ${event.agent_id}</div>
<div><strong>原因:</strong> ${event.reason}</div>
<div><strong>最终统计:</strong> ${JSON.stringify(event.final_stats)}</div>
`;
}
return `
<div class="event ${type}">
<div class="event-header">
<span class="event-type ${type}">${getTypeLabel(type)}</span>
<span class="event-time">${time}</span>
</div>
<div class="event-content">${content}</div>
</div>
`;
}
function getTypeLabel(type) {
const labels = {
'task': '任务执行',
'attack': '攻击',
'evolution': '进化',
'elimination': '淘汰'
};
return labels[type] || type;
}
// 初始渲染
renderTimeline();
</script>
</body>
</html>