@fantasticit/sumi 0.15.0 → 0.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/host-messages.d.ts +6 -0
- package/dist/host-messages.js +8 -0
- package/dist/host-messages.js.map +1 -0
- package/dist/host-transcripts.d.ts +5 -0
- package/dist/host-transcripts.js +86 -0
- package/dist/host-transcripts.js.map +1 -0
- package/dist/hub/board.d.ts +43 -1
- package/dist/hub/board.js +87 -13
- package/dist/hub/board.js.map +1 -1
- package/dist/hub/page-icons.d.ts +1 -0
- package/dist/hub/page-icons.js +5 -0
- package/dist/hub/page-icons.js.map +1 -0
- package/dist/hub/page-model.d.ts +102 -0
- package/dist/hub/page-model.js +302 -0
- package/dist/hub/page-model.js.map +1 -0
- package/dist/hub/page-overlays.d.ts +1 -0
- package/dist/hub/page-overlays.js +115 -0
- package/dist/hub/page-overlays.js.map +1 -0
- package/dist/hub/page-sessions.d.ts +1 -0
- package/dist/hub/page-sessions.js +588 -0
- package/dist/hub/page-sessions.js.map +1 -0
- package/dist/hub/page-style.d.ts +1 -0
- package/dist/hub/page-style.js +346 -0
- package/dist/hub/page-style.js.map +1 -0
- package/dist/hub/page-tips.d.ts +2 -0
- package/dist/hub/page-tips.js +93 -0
- package/dist/hub/page-tips.js.map +1 -0
- package/dist/hub/page-usage.d.ts +2 -0
- package/dist/hub/page-usage.js +360 -0
- package/dist/hub/page-usage.js.map +1 -0
- package/dist/hub/page-workbench.d.ts +1 -0
- package/dist/hub/page-workbench.js +901 -0
- package/dist/hub/page-workbench.js.map +1 -0
- package/dist/hub/pages.d.ts +1 -0
- package/dist/hub/pages.js +68 -182
- package/dist/hub/pages.js.map +1 -1
- package/dist/hub/server.js +2 -4
- package/dist/hub/server.js.map +1 -1
- package/dist/hub/snapshot.d.ts +9 -0
- package/dist/hub/snapshot.js +97 -20
- package/dist/hub/snapshot.js.map +1 -1
- package/dist/hub/usage-summary.d.ts +36 -0
- package/dist/hub/usage-summary.js +76 -0
- package/dist/hub/usage-summary.js.map +1 -0
- package/dist/hub/usage.d.ts +50 -0
- package/dist/hub/usage.js +285 -0
- package/dist/hub/usage.js.map +1 -0
- package/dist/visualize-sessions.d.ts +6 -0
- package/dist/visualize-sessions.js +9 -2
- package/dist/visualize-sessions.js.map +1 -1
- package/dist/visualize.d.ts +6 -0
- package/dist/visualize.js +1 -1
- package/dist/visualize.js.map +1 -1
- package/node_modules/@sumi/create/package.json +2 -2
- package/node_modules/@sumi/kernel/package.json +2 -2
- package/node_modules/@sumi/plugin-sdk/dist/hub.d.ts +21 -2
- package/node_modules/@sumi/plugin-sdk/dist/hub.js +42 -0
- package/node_modules/@sumi/plugin-sdk/dist/hub.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/dist/snapshot.d.ts +5 -1
- package/node_modules/@sumi/plugin-sdk/dist/snapshot.js +28 -12
- package/node_modules/@sumi/plugin-sdk/dist/snapshot.js.map +1 -1
- package/node_modules/@sumi/plugin-sdk/package.json +1 -1
- package/node_modules/@sumi/plugins-core/package.json +3 -3
- package/node_modules/@sumi/plugins-governance/dist/hub-snapshot.d.ts +1 -1
- package/node_modules/@sumi/plugins-governance/dist/hub-snapshot.js +52 -10
- package/node_modules/@sumi/plugins-governance/dist/hub-snapshot.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/dist/index.d.ts +1 -1
- package/node_modules/@sumi/plugins-governance/dist/index.js +1 -1
- package/node_modules/@sumi/plugins-governance/dist/index.js.map +1 -1
- package/node_modules/@sumi/plugins-governance/instructions/push.md +1 -1
- package/node_modules/@sumi/plugins-governance/package.json +4 -4
- package/node_modules/@sumi/plugins-openspec/package.json +6 -6
- package/node_modules/@sumi/plugins-precedent/package.json +3 -3
- package/node_modules/@sumi/plugins-review/dist/fix-list.js +2 -1
- package/node_modules/@sumi/plugins-review/dist/fix-list.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/instructions.js +1 -1
- package/node_modules/@sumi/plugins-review/dist/instructions.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/review.d.ts +13 -1
- package/node_modules/@sumi/plugins-review/dist/review.js +90 -3
- package/node_modules/@sumi/plugins-review/dist/review.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/rubric-check.js +5 -20
- package/node_modules/@sumi/plugins-review/dist/rubric-check.js.map +1 -1
- package/node_modules/@sumi/plugins-review/dist/submission.js +11 -5
- package/node_modules/@sumi/plugins-review/dist/submission.js.map +1 -1
- package/node_modules/@sumi/plugins-review/package.json +6 -6
- package/package.json +10 -10
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
// 复用既有事件读取与确认语义,按偏移追加,不重建已展开事件。
|
|
2
|
+
export const SESSIONS_SCRIPT = String.raw `
|
|
3
|
+
const CHANNELS = {
|
|
4
|
+
prompt: '提示词',
|
|
5
|
+
startup: '会话开始',
|
|
6
|
+
'session-start': '会话开始',
|
|
7
|
+
clear: '清空后',
|
|
8
|
+
compact: '压缩后',
|
|
9
|
+
'subagent-start': '子代理启动',
|
|
10
|
+
'before-edit': '编辑前',
|
|
11
|
+
'after-edit': '编辑后',
|
|
12
|
+
'rules-fallback': '规则兜底',
|
|
13
|
+
'read-gate': '读取门槛',
|
|
14
|
+
'task-select': '任务选择',
|
|
15
|
+
'context-read': '路径查询',
|
|
16
|
+
};
|
|
17
|
+
const METHODS = {
|
|
18
|
+
'additional-context': ['上下文注入', ''],
|
|
19
|
+
denial: ['拒绝工具调用', 'bad'],
|
|
20
|
+
'tool-output': ['AI 主动读取', ''],
|
|
21
|
+
};
|
|
22
|
+
const CONFIRM = { confirmed: ['已进入会话记录', 'ok'], missing: ['未找到', 'bad'], unknown: ['无法核对', ''] };
|
|
23
|
+
const KINDS = {
|
|
24
|
+
prompt: ['提示词', 'prompt'],
|
|
25
|
+
injection: ['Sumi 送达', ''],
|
|
26
|
+
'agent-read': ['AI 读取', 'read'],
|
|
27
|
+
document: ['Sumi 读取', 'plain'],
|
|
28
|
+
command: ['Sumi 命令', 'plain'],
|
|
29
|
+
};
|
|
30
|
+
const FILTERS = [
|
|
31
|
+
['deliveries', '送达与读取'],
|
|
32
|
+
['all', '全部事件'],
|
|
33
|
+
];
|
|
34
|
+
let sessions = [];
|
|
35
|
+
let selected = decodeURIComponent(location.hash.slice(1));
|
|
36
|
+
let events = [];
|
|
37
|
+
let next = 0;
|
|
38
|
+
let confirmations = {};
|
|
39
|
+
let confirmationsReady = false;
|
|
40
|
+
let host = '';
|
|
41
|
+
let project = '';
|
|
42
|
+
let view = 'deliveries';
|
|
43
|
+
let allSessions = false;
|
|
44
|
+
let sessionQuery = '';
|
|
45
|
+
let sessionSort = 'recent';
|
|
46
|
+
const eventNodes = new Map();
|
|
47
|
+
const keyOf = (item) => item.projectId + ':' + item.id;
|
|
48
|
+
const chars = (value) => (value >= 10000 ? (value / 10000).toFixed(1) + ' 万' : String(value));
|
|
49
|
+
const current = () => sessions.find((item) => keyOf(item) === selected);
|
|
50
|
+
function filtered() {
|
|
51
|
+
return sessions.filter(
|
|
52
|
+
(item) =>
|
|
53
|
+
(!host || item.host === host) &&
|
|
54
|
+
(!project || item.projectId === project) &&
|
|
55
|
+
matchesSearch(item.title, sessionQuery),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
function renderList() {
|
|
59
|
+
const list = byId('list');
|
|
60
|
+
const top = list.scrollTop;
|
|
61
|
+
const folded = list.querySelector('details')?.open;
|
|
62
|
+
const items = filtered().sort((a, b) => sessionSort === 'token' ? (usageReady(b.usage) ? tokenTotal(b.usage) : -1) - (usageReady(a.usage) ? tokenTotal(a.usage) : -1) : Date.parse(b.updatedAt) - Date.parse(a.updatedAt));
|
|
63
|
+
list.replaceChildren();
|
|
64
|
+
const untitled = make('details', 'untitled');
|
|
65
|
+
untitled.open = !!folded;
|
|
66
|
+
untitled.append(make('summary', '', '自动会话 · ' + items.filter((item) => !item.title).length));
|
|
67
|
+
for (const item of items) {
|
|
68
|
+
const button = make('button', 'si' + (keyOf(item) === selected ? ' sel' : ''));
|
|
69
|
+
button.type = 'button';
|
|
70
|
+
button.setAttribute('aria-current', String(keyOf(item) === selected));
|
|
71
|
+
button.title = item.title || '';
|
|
72
|
+
button.append(make('div', 't', item.title || '(无提示词)'));
|
|
73
|
+
const meta = make('div', 'm');
|
|
74
|
+
meta.append(
|
|
75
|
+
projectTag(item.project),
|
|
76
|
+
agentTag(item.host),
|
|
77
|
+
make('time', '', item.updatedAt ? ago(item.updatedAt) : '时间未提供'),
|
|
78
|
+
make('span', 'deliveries', '送达 ' + item.deliveries + ' 次'),
|
|
79
|
+
);
|
|
80
|
+
button.append(meta);
|
|
81
|
+
const amount = make('div', 'm um');
|
|
82
|
+
amount.append(
|
|
83
|
+
tokenLabel(item.usage),
|
|
84
|
+
make('span', 'tk', usageReady(item.usage) ? usageDuration(item.usage.activeMs) : ''),
|
|
85
|
+
);
|
|
86
|
+
const card = lastBoard?.cards.find((card) => card.projectId === item.projectId && (card.linkedSession?.id === item.id || item.checkouts?.includes(card.checkout)));
|
|
87
|
+
if (card) {
|
|
88
|
+
const state = workState(card, lastBoard.generatedAt);
|
|
89
|
+
const badge = make('span', 'sx ' + state.tone, state.label);
|
|
90
|
+
badge.dataset.tip = state.reason;
|
|
91
|
+
amount.append(badge);
|
|
92
|
+
}
|
|
93
|
+
button.append(amount);
|
|
94
|
+
button.addEventListener('click', () => select(keyOf(item)));
|
|
95
|
+
(item.title || allSessions ? list : untitled).append(button);
|
|
96
|
+
}
|
|
97
|
+
if (untitled.children.length > 1) list.append(untitled);
|
|
98
|
+
if (!items.length) list.append(make('div', 'empty', '暂无会话'));
|
|
99
|
+
list.setAttribute('aria-busy', 'false');
|
|
100
|
+
list.scrollTop = top;
|
|
101
|
+
prepareTooltips(list);
|
|
102
|
+
}
|
|
103
|
+
function renderFilters(board) {
|
|
104
|
+
const hosts = [...new Set(sessions.map((item) => item.host).filter(Boolean))];
|
|
105
|
+
const projectBox = byId('project');
|
|
106
|
+
if (projectBox.options.length !== board.projects.length + 1) {
|
|
107
|
+
projectBox.replaceChildren(
|
|
108
|
+
new Option('全部项目', ''),
|
|
109
|
+
...board.projects.map((entry) => new Option(entry.name, entry.id)),
|
|
110
|
+
);
|
|
111
|
+
projectBox.value = project;
|
|
112
|
+
}
|
|
113
|
+
const hostBox = byId('host');
|
|
114
|
+
if (hostBox.options.length !== hosts.length + 1) {
|
|
115
|
+
hostBox.replaceChildren(new Option('全部', ''), ...hosts.map((name) => new Option(name, name)));
|
|
116
|
+
hostBox.value = host;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function renderHeader() {
|
|
120
|
+
const item = current();
|
|
121
|
+
byId('title').textContent = item ? item.title || '(无提示词)' : '选择会话查看详情';
|
|
122
|
+
byId('title').title = item && item.title ? item.title : '';
|
|
123
|
+
const meta = byId('meta');
|
|
124
|
+
meta.replaceChildren();
|
|
125
|
+
if (item) meta.append(projectTag(item.project), agentTag(item.host), make('span', 'mono', item.session));
|
|
126
|
+
const stats = byId('stats');
|
|
127
|
+
const evidence = byId('evidence-stats');
|
|
128
|
+
stats.replaceChildren();
|
|
129
|
+
evidence.replaceChildren();
|
|
130
|
+
if (!item) return;
|
|
131
|
+
const count = (state) => Object.values(confirmations).filter((value) => value === state).length;
|
|
132
|
+
const files = new Set(
|
|
133
|
+
events
|
|
134
|
+
.filter((event) => event.kind === 'agent-read' && event.source)
|
|
135
|
+
.map((event) => (event.checkout || '') + ':' + event.source),
|
|
136
|
+
).size;
|
|
137
|
+
const usage = item.usage;
|
|
138
|
+
const ready = usageReady(usage);
|
|
139
|
+
const cards = [
|
|
140
|
+
[
|
|
141
|
+
usageLabel(usage),
|
|
142
|
+
'Token',
|
|
143
|
+
ready ? '缓存命中率 ' + percent(usage.hitRate) : 'unavailable' in (usage || {}) ? usage.unavailable : '统计中',
|
|
144
|
+
],
|
|
145
|
+
[
|
|
146
|
+
ready ? usageDuration(usage.activeMs) : '—',
|
|
147
|
+
'AI 工作时长',
|
|
148
|
+
ready ? '会话跨度 ' + usageDuration(usage.spanMs) : '暂无数据',
|
|
149
|
+
],
|
|
150
|
+
[
|
|
151
|
+
ready ? usage.turns + ' 轮 · ' + usage.tools + ' 次' : '—',
|
|
152
|
+
'对话与工具调用',
|
|
153
|
+
ready && usage.subagents ? '含 ' + usage.subagents + ' 个子代理记录' : '按会话记录统计,不推断跨会话父子关系',
|
|
154
|
+
],
|
|
155
|
+
[
|
|
156
|
+
item.deliveries + ' 次',
|
|
157
|
+
'Sumi 送达',
|
|
158
|
+
chars(item.chars) +
|
|
159
|
+
' 字;' +
|
|
160
|
+
(confirmationsReady ? count('confirmed') : '—') +
|
|
161
|
+
'/' +
|
|
162
|
+
item.deliveries +
|
|
163
|
+
' 进入会话记录',
|
|
164
|
+
],
|
|
165
|
+
];
|
|
166
|
+
for (const [value, label, note] of cards) {
|
|
167
|
+
const box = make('div', 'panel metric');
|
|
168
|
+
const description = make('div', 'd', note);
|
|
169
|
+
description.title = note;
|
|
170
|
+
box.append(make('div', 'l', label), make('div', 'v', value));
|
|
171
|
+
if (label === 'Token') box.append(usageStack(usage));
|
|
172
|
+
box.append(description);
|
|
173
|
+
stats.append(box);
|
|
174
|
+
}
|
|
175
|
+
const facts = make('dl', 'kv');
|
|
176
|
+
for (const [label, value] of [
|
|
177
|
+
['未命中输入', ready ? tokenNumber(usage.input) : '—'],
|
|
178
|
+
['缓存读取', ready ? tokenNumber(usage.cacheRead) : '—'],
|
|
179
|
+
['写入缓存', ready ? tokenNumber(usage.cacheWrite) : '—'],
|
|
180
|
+
['输出', ready ? tokenNumber(usage.output) : '—'],
|
|
181
|
+
['模型', ready ? Object.keys(usage.models).join('、') : '—'],
|
|
182
|
+
['子代理', ready ? usage.subagents : '—'],
|
|
183
|
+
['用量状态', ready ? '已统计' : usage && 'unavailable' in usage ? usage.unavailable : '统计中'],
|
|
184
|
+
])
|
|
185
|
+
facts.append(make('dt', '', label), make('dd', '', value));
|
|
186
|
+
byId('usage-facts').replaceChildren(facts);
|
|
187
|
+
byId('usage-summary').replaceChildren(
|
|
188
|
+
make('span', '', 'Token 明细'),
|
|
189
|
+
copyTip(
|
|
190
|
+
[
|
|
191
|
+
usageScope(lastBoard),
|
|
192
|
+
'每轮按用户提示词划分,子会话用量计入总量,不分摊到每轮。',
|
|
193
|
+
'全局按会话记录去重,工作目录汇总可能重叠。',
|
|
194
|
+
'AI 工作时长不含 5 分钟以上空闲。',
|
|
195
|
+
].join('\n'),
|
|
196
|
+
),
|
|
197
|
+
);
|
|
198
|
+
for (const [label, value] of [
|
|
199
|
+
['AI 读取文件数', files],
|
|
200
|
+
['送达字符', item.chars],
|
|
201
|
+
['送达次数', item.deliveries],
|
|
202
|
+
['提示词', item.prompts],
|
|
203
|
+
['已进入会话记录', count('confirmed')],
|
|
204
|
+
['未找到', count('missing')],
|
|
205
|
+
['无法核对', count('unknown')],
|
|
206
|
+
['AI 主动读取上下文', item.reads],
|
|
207
|
+
['拒绝式送达', item.denials],
|
|
208
|
+
['AI 工具', item.host || '未提供'],
|
|
209
|
+
['会话', item.session],
|
|
210
|
+
['工作目录', item.checkouts.map((path) => homePath(path, lastBoard?.home)).join('、') || '未提供'],
|
|
211
|
+
['子代理', item.agents.join('、') || '未提供'],
|
|
212
|
+
])
|
|
213
|
+
evidence.append(make('dt', '', label), make('dd', '', value));
|
|
214
|
+
renderTurnAxis();
|
|
215
|
+
prepareTooltips(byId('session-main'));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function groups(items) {
|
|
219
|
+
const map = new Map();
|
|
220
|
+
for (const entry of items) {
|
|
221
|
+
if (entry.key === 'catalog:complete') continue;
|
|
222
|
+
const prefix = entry.key.split(':')[0];
|
|
223
|
+
map.set(prefix, [...(map.get(prefix) || []), entry]);
|
|
224
|
+
}
|
|
225
|
+
return map;
|
|
226
|
+
}
|
|
227
|
+
function title(event) {
|
|
228
|
+
if (event.kind === 'injection')
|
|
229
|
+
return (CHANNELS[event.channel] || event.channel || '上下文') + (event.agent ? ' · 子代理' : '');
|
|
230
|
+
if (event.kind === 'command')
|
|
231
|
+
return (
|
|
232
|
+
'sumi ' +
|
|
233
|
+
(event.command || '') +
|
|
234
|
+
(Array.isArray(event.args) && event.args.length ? ' ' + event.args.join(' ').slice(0, 80) : '')
|
|
235
|
+
);
|
|
236
|
+
if (event.kind === 'prompt') return (event.content || '').split('\n')[0].slice(0, 160);
|
|
237
|
+
return event.source || '';
|
|
238
|
+
}
|
|
239
|
+
function renderEvent(event) {
|
|
240
|
+
if (event.kind === 'prompt') {
|
|
241
|
+
const prompt = make('div', 'prompt');
|
|
242
|
+
const text = event.content || '';
|
|
243
|
+
prompt.append(make('div', 'prompt-preview', text.slice(0, 360)));
|
|
244
|
+
if (text.length > 360) {
|
|
245
|
+
const details = make('details');
|
|
246
|
+
details.append(make('summary', '', '展开完整提示词'), make('pre', '', text));
|
|
247
|
+
prompt.append(details);
|
|
248
|
+
}
|
|
249
|
+
return prompt;
|
|
250
|
+
}
|
|
251
|
+
const row = make(
|
|
252
|
+
'div',
|
|
253
|
+
event.kind === 'injection' || event.kind === 'prompt' || event.kind === 'agent-read'
|
|
254
|
+
? 'ev-record'
|
|
255
|
+
: 'ev-record hidden-by-view',
|
|
256
|
+
);
|
|
257
|
+
row.dataset.at = event.at || '';
|
|
258
|
+
row.dataset.kind = event.kind;
|
|
259
|
+
row.dataset.event = String(event.id);
|
|
260
|
+
|
|
261
|
+
const head = make('div', 'ev');
|
|
262
|
+
const time = make('time', '', clock(event.at));
|
|
263
|
+
if (event.at) time.dateTime = event.at;
|
|
264
|
+
const kind = KINDS[event.kind] || [event.kind, 'plain'];
|
|
265
|
+
const what = make('span', 'event-title');
|
|
266
|
+
what.append(make('b', '', title(event)));
|
|
267
|
+
const notes = [];
|
|
268
|
+
if (event.kind === 'injection') {
|
|
269
|
+
const method = METHODS[event.method] || [event.method || '方式未知', ''];
|
|
270
|
+
notes.push(method[0]);
|
|
271
|
+
if (event.checkout) notes.push('工作目录 ' + event.checkout);
|
|
272
|
+
}
|
|
273
|
+
if (event.paths && event.paths.length)
|
|
274
|
+
notes.push(
|
|
275
|
+
'触发路径 ' +
|
|
276
|
+
event.paths.slice(0, 4).join('、') +
|
|
277
|
+
(event.paths.length > 4 ? ' 等 ' + event.paths.length + ' 个' : ''),
|
|
278
|
+
);
|
|
279
|
+
if (event.selected && event.selected.length) notes.push('选中 ' + event.selected.join('、'));
|
|
280
|
+
if (notes.length) what.append(make('small', '', notes.join(' · ')));
|
|
281
|
+
head.append(time, make('span', 'pill ' + kind[1], kind[0]), what);
|
|
282
|
+
const trailing = make('span', 'event-trailing');
|
|
283
|
+
if (event.kind === 'injection') {
|
|
284
|
+
const state = make('span', 'tag', '核对中');
|
|
285
|
+
state.dataset.confirm = event.id;
|
|
286
|
+
trailing.append(state);
|
|
287
|
+
}
|
|
288
|
+
const text = event.kind === 'command' ? event.output || '' : event.content || '';
|
|
289
|
+
if (text) trailing.append(make('span', 'mono', text.length + ' 字'));
|
|
290
|
+
head.append(trailing);
|
|
291
|
+
row.append(head);
|
|
292
|
+
const lines = [];
|
|
293
|
+
for (const [prefix, group] of groups(event.items || []))
|
|
294
|
+
lines.push(
|
|
295
|
+
'送达 ' +
|
|
296
|
+
group.length +
|
|
297
|
+
' 条:' +
|
|
298
|
+
group
|
|
299
|
+
.slice(0, 6)
|
|
300
|
+
.map((entry) => entry.key)
|
|
301
|
+
.join('、') +
|
|
302
|
+
(group.length > 6 ? ' 等' : ''),
|
|
303
|
+
);
|
|
304
|
+
const skipped = event.skipped || [];
|
|
305
|
+
if (skipped.length)
|
|
306
|
+
lines.push(
|
|
307
|
+
'跳过 ' +
|
|
308
|
+
skipped.length +
|
|
309
|
+
' 条:' +
|
|
310
|
+
skipped
|
|
311
|
+
.slice(0, 4)
|
|
312
|
+
.map((entry) => entry.key + '(' + entry.reason + ')')
|
|
313
|
+
.join('、'),
|
|
314
|
+
);
|
|
315
|
+
if (lines.length) {
|
|
316
|
+
const box = make('div', 'note');
|
|
317
|
+
box.className = 'event-detail muted';
|
|
318
|
+
box.textContent = lines.join(';');
|
|
319
|
+
row.append(box);
|
|
320
|
+
}
|
|
321
|
+
if (text) {
|
|
322
|
+
const details = make('details', 'event-detail');
|
|
323
|
+
details.append(make('summary', '', '查看全文'), make('pre', '', text));
|
|
324
|
+
row.append(details);
|
|
325
|
+
}
|
|
326
|
+
return row;
|
|
327
|
+
}
|
|
328
|
+
function renderTurnAxis() {
|
|
329
|
+
const target = byId('turn-axis');
|
|
330
|
+
target.replaceChildren();
|
|
331
|
+
target.append(make('h3', '', '每轮时间轴'));
|
|
332
|
+
const usage = current()?.usage;
|
|
333
|
+
if (!usageReady(usage) || !usage.perTurn?.length) {
|
|
334
|
+
target.append(make('p', 'muted', '暂无每轮用量数据'));
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
const prompts = events.filter((event) => isUserTurnPrompt(event, current()?.host));
|
|
338
|
+
const paired = pairTurnUsage(prompts, usage.perTurn);
|
|
339
|
+
const max = Math.max(1, ...usage.perTurn.map((turn) => turn.activeMs));
|
|
340
|
+
for (const [index, turn] of usage.perTurn.entries()) {
|
|
341
|
+
const prompt = prompts.find((event) => paired[String(event.id)] === turn);
|
|
342
|
+
const row = make('button', 'wfr');
|
|
343
|
+
row.type = 'button';
|
|
344
|
+
row.dataset.tip = '第 ' + (index + 1) + ' 轮 · ' + stamp(turn.at) + ' · AI 工作时长 ' + usageDuration(turn.activeMs) + ' · ' + turn.tokens + ' Token · 工具 ' + turn.tools + ' 次' + (prompt ? '' : ';暂无匹配提示词');
|
|
345
|
+
const label = make('span', 'why', (index + 1) + ' · ' + (prompt?.content || clock(turn.at)));
|
|
346
|
+
const track = make('span', 'wftrack');
|
|
347
|
+
const bar = make('i');
|
|
348
|
+
bar.style.width = turn.activeMs / max * 100 + '%';
|
|
349
|
+
track.append(bar);
|
|
350
|
+
row.append(label, track, make('span', 'tk', tokenNumber(turn.tokens)), make('span', 'tk', turn.tools + ' 次'));
|
|
351
|
+
row.addEventListener('click', () => {
|
|
352
|
+
const section = prompt ? byId('turn-' + prompt.id) : byId('timeline');
|
|
353
|
+
section?.scrollIntoView({ block: 'start', behavior: 'smooth' });
|
|
354
|
+
});
|
|
355
|
+
target.append(row);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
function renderTurns() {
|
|
359
|
+
const target = byId('timeline');
|
|
360
|
+
const scroll = byId('session-main').scrollTop;
|
|
361
|
+
const fragments = document.createDocumentFragment();
|
|
362
|
+
let body;
|
|
363
|
+
let round = 0;
|
|
364
|
+
const paired = pairTurnUsage(
|
|
365
|
+
events.filter((event) => isUserTurnPrompt(event, current()?.host)),
|
|
366
|
+
usageReady(current()?.usage) ? current().usage.perTurn : [],
|
|
367
|
+
);
|
|
368
|
+
for (const event of [...events].sort((a, b) => (a.at || '').localeCompare(b.at || '') || a.id - b.id)) {
|
|
369
|
+
const startsTurn = isUserTurnPrompt(event, current()?.host);
|
|
370
|
+
if (!body || startsTurn) {
|
|
371
|
+
const turn = make('section', 'turn');
|
|
372
|
+
if (startsTurn) turn.id = 'turn-' + event.id;
|
|
373
|
+
const heading = make('div', 'uh');
|
|
374
|
+
heading.append(
|
|
375
|
+
make('b', '', startsTurn ? '第 ' + ++round + ' 轮' : '会话开始'),
|
|
376
|
+
make('time', '', clock(event.at)),
|
|
377
|
+
);
|
|
378
|
+
const amount = paired[String(event.id)];
|
|
379
|
+
if (startsTurn && amount)
|
|
380
|
+
heading.append(
|
|
381
|
+
make(
|
|
382
|
+
'span',
|
|
383
|
+
'tu',
|
|
384
|
+
'AI 工作时长 ' +
|
|
385
|
+
usageDuration(amount.activeMs) +
|
|
386
|
+
' · ' +
|
|
387
|
+
tokenNumber(amount.tokens) +
|
|
388
|
+
' Token · 工具 ' +
|
|
389
|
+
amount.tools +
|
|
390
|
+
' 次',
|
|
391
|
+
),
|
|
392
|
+
);
|
|
393
|
+
body = make('div', 'evs');
|
|
394
|
+
turn.append(heading);
|
|
395
|
+
if (startsTurn) {
|
|
396
|
+
if (!eventNodes.has(event.id)) eventNodes.set(event.id, renderEvent(event));
|
|
397
|
+
turn.append(eventNodes.get(event.id));
|
|
398
|
+
}
|
|
399
|
+
turn.append(body);
|
|
400
|
+
fragments.append(turn);
|
|
401
|
+
}
|
|
402
|
+
if (startsTurn) continue;
|
|
403
|
+
if (!eventNodes.has(event.id)) eventNodes.set(event.id, renderEvent(event));
|
|
404
|
+
body.append(eventNodes.get(event.id));
|
|
405
|
+
}
|
|
406
|
+
target.replaceChildren(fragments);
|
|
407
|
+
byId('session-main').scrollTop = scroll;
|
|
408
|
+
prepareTooltips(target);
|
|
409
|
+
}
|
|
410
|
+
function applyConfirmations() {
|
|
411
|
+
for (const [id, state] of Object.entries(confirmations)) {
|
|
412
|
+
const node = [...document.querySelectorAll('[data-confirm]')].find((entry) => entry.dataset.confirm === id);
|
|
413
|
+
if (!node) continue;
|
|
414
|
+
const def = CONFIRM[state];
|
|
415
|
+
node.textContent = def[0];
|
|
416
|
+
node.className = 'tag ' + def[1];
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
async function loadEvents(key) {
|
|
420
|
+
const item = current();
|
|
421
|
+
if (!item) return;
|
|
422
|
+
for (let more = true; more && key === selected;) {
|
|
423
|
+
let page;
|
|
424
|
+
try {
|
|
425
|
+
page = await getJson('/api/projects/' + item.projectId + '/sessions/' + item.id + '/events?after=' + next);
|
|
426
|
+
} catch {
|
|
427
|
+
byId('count').textContent = '读取失败,将自动重试';
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (key !== selected) return;
|
|
431
|
+
for (const event of page.events) {
|
|
432
|
+
if (!eventNodes.has(event.id) && !events.some((entry) => entry.id === event.id)) events.push(event);
|
|
433
|
+
}
|
|
434
|
+
more = page.more && page.next > next;
|
|
435
|
+
next = page.next;
|
|
436
|
+
}
|
|
437
|
+
renderTurns();
|
|
438
|
+
applyConfirmations();
|
|
439
|
+
renderHeader();
|
|
440
|
+
byId('count').textContent = '共 ' + events.length + ' 条事件';
|
|
441
|
+
}
|
|
442
|
+
async function loadConfirmations(key) {
|
|
443
|
+
const item = current();
|
|
444
|
+
if (!item) return;
|
|
445
|
+
let value;
|
|
446
|
+
try {
|
|
447
|
+
value = await getJson('/api/projects/' + item.projectId + '/sessions/' + item.id + '/confirmations');
|
|
448
|
+
} catch { return; }
|
|
449
|
+
if (key !== selected) return;
|
|
450
|
+
confirmations = value;
|
|
451
|
+
confirmationsReady = true;
|
|
452
|
+
applyConfirmations();
|
|
453
|
+
renderHeader();
|
|
454
|
+
}
|
|
455
|
+
async function select(key) {
|
|
456
|
+
if (selected === key) return;
|
|
457
|
+
selected = key;
|
|
458
|
+
history.replaceState(null, '', '#' + encodeURIComponent(key));
|
|
459
|
+
events = [];
|
|
460
|
+
eventNodes.clear();
|
|
461
|
+
next = 0;
|
|
462
|
+
confirmations = {};
|
|
463
|
+
confirmationsReady = false;
|
|
464
|
+
byId('timeline').replaceChildren();
|
|
465
|
+
byId('count').textContent = '读取中';
|
|
466
|
+
renderList();
|
|
467
|
+
renderHeader();
|
|
468
|
+
updateCapture();
|
|
469
|
+
try {
|
|
470
|
+
await loadEvents(key);
|
|
471
|
+
await loadConfirmations(key);
|
|
472
|
+
} catch (error) {
|
|
473
|
+
console.error('页面渲染出错', error);
|
|
474
|
+
showAlerts([['bad', '页面渲染出错', error instanceof Error ? error.message : String(error)]]);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
function updateCapture() {
|
|
478
|
+
const item = current();
|
|
479
|
+
const capture = lastBoard?.projects.find((entry) => entry.id === item?.projectId)?.capture;
|
|
480
|
+
byId('capture').textContent = capture
|
|
481
|
+
? '会话记录版本 ' +
|
|
482
|
+
capture.observer +
|
|
483
|
+
' · 项目 ' +
|
|
484
|
+
(capture.project || '未提供') +
|
|
485
|
+
' · ' +
|
|
486
|
+
(capture.sameRuntime ? '与正式入口同一构建' : '与正式入口构建不一致或无法核实') +
|
|
487
|
+
' · AI 工具:' +
|
|
488
|
+
(capture.agents.join('、') || '未提供')
|
|
489
|
+
: '暂无会话记录版本与 AI 工具信息';
|
|
490
|
+
}
|
|
491
|
+
async function refresh() {
|
|
492
|
+
let board;
|
|
493
|
+
try {
|
|
494
|
+
board = await getJson('/api/board');
|
|
495
|
+
} catch {
|
|
496
|
+
byId('list').setAttribute('aria-busy', 'false');
|
|
497
|
+
showAlerts([['bad', '', '读取失败,将自动重试']]);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
try {
|
|
501
|
+
sessions = board.sessions;
|
|
502
|
+
updateShell(board);
|
|
503
|
+
updateCapture();
|
|
504
|
+
showAlerts(projectAlerts(board), true);
|
|
505
|
+
renderFilters(board);
|
|
506
|
+
if (!current() && sessions.length && !selected) {
|
|
507
|
+
await select(keyOf(sessions.find((item) => item.title) || sessions[0]));
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
renderList();
|
|
511
|
+
renderHeader();
|
|
512
|
+
if (selected && !current()) byId('count').textContent = '该会话不在最近 7 天的展示范围内';
|
|
513
|
+
if (current()) {
|
|
514
|
+
history.replaceState(null, '', '#' + encodeURIComponent(selected));
|
|
515
|
+
await loadEvents(selected);
|
|
516
|
+
}
|
|
517
|
+
} catch (error) {
|
|
518
|
+
byId('list').setAttribute('aria-busy', 'false');
|
|
519
|
+
console.error('页面渲染出错', error);
|
|
520
|
+
showAlerts([['bad', '页面渲染出错', error instanceof Error ? error.message : String(error)]]);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
byId('project').addEventListener('change', (event) => {
|
|
524
|
+
project = event.target.value;
|
|
525
|
+
renderList();
|
|
526
|
+
});
|
|
527
|
+
byId('host').addEventListener('change', (event) => {
|
|
528
|
+
host = event.target.value;
|
|
529
|
+
renderList();
|
|
530
|
+
});
|
|
531
|
+
byId('pills').replaceChildren(
|
|
532
|
+
...FILTERS.map(([id, label]) => {
|
|
533
|
+
const button = make('button', id === view ? 'on' : '', label);
|
|
534
|
+
button.type = 'button';
|
|
535
|
+
button.setAttribute('aria-pressed', String(id === view));
|
|
536
|
+
button.addEventListener('click', () => {
|
|
537
|
+
view = id;
|
|
538
|
+
byId('timeline').dataset.view = id;
|
|
539
|
+
for (const option of byId('pills').children) {
|
|
540
|
+
option.setAttribute('aria-pressed', String(option === button));
|
|
541
|
+
option.classList.toggle('on', option === button);
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
return button;
|
|
545
|
+
}),
|
|
546
|
+
);
|
|
547
|
+
addEventListener('hashchange', () => {
|
|
548
|
+
const key = decodeURIComponent(location.hash.slice(1));
|
|
549
|
+
selected = '';
|
|
550
|
+
select(key);
|
|
551
|
+
});
|
|
552
|
+
for (const [id, value] of [
|
|
553
|
+
['with-prompts', false],
|
|
554
|
+
['all-sessions', true],
|
|
555
|
+
])
|
|
556
|
+
byId(id).addEventListener('click', () => {
|
|
557
|
+
allSessions = value;
|
|
558
|
+
for (const option of ['with-prompts', 'all-sessions']) {
|
|
559
|
+
const active = option === id;
|
|
560
|
+
byId(option).classList.toggle('on', active);
|
|
561
|
+
byId(option).setAttribute('aria-pressed', String(active));
|
|
562
|
+
}
|
|
563
|
+
renderList();
|
|
564
|
+
});
|
|
565
|
+
byId('session-query').addEventListener('input', (event) => {
|
|
566
|
+
sessionQuery = event.target.value;
|
|
567
|
+
renderList();
|
|
568
|
+
});
|
|
569
|
+
for (const [id, value] of [
|
|
570
|
+
['sort-recent', 'recent'],
|
|
571
|
+
['sort-token', 'token'],
|
|
572
|
+
])
|
|
573
|
+
byId(id).addEventListener('click', () => {
|
|
574
|
+
sessionSort = value;
|
|
575
|
+
for (const name of ['sort-recent', 'sort-token']) {
|
|
576
|
+
byId(name).classList.toggle('on', name === id);
|
|
577
|
+
byId(name).setAttribute('aria-pressed', String(name === id));
|
|
578
|
+
}
|
|
579
|
+
renderList();
|
|
580
|
+
});
|
|
581
|
+
byId('session-help').append(helpButton('sessions'));
|
|
582
|
+
refresh();
|
|
583
|
+
setInterval(refresh, 3000);
|
|
584
|
+
setInterval(() => {
|
|
585
|
+
if (selected) loadConfirmations(selected);
|
|
586
|
+
}, 8000);
|
|
587
|
+
`;
|
|
588
|
+
//# sourceMappingURL=page-sessions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-sessions.js","sourceRoot":"","sources":["../../src/hub/page-sessions.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAykBxC,CAAC"}
|