@niracler/encore 0.2.0 → 0.3.0
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/README.md +104 -75
- package/README.zh-CN.md +105 -69
- package/bin/encore.mjs +53 -22
- package/package.json +4 -2
- package/player/encore-player.css +83 -1
- package/player/encore-player.js +422 -90
- package/schema/session.schema.json +63 -1
- package/skills/encore/SKILL.md +39 -35
- package/src/attachment-previews.mjs +169 -0
- package/src/attachment-reader.mjs +169 -0
- package/src/claude-ai.mjs +3 -1
- package/src/claude-code.mjs +11 -7
- package/src/codex.mjs +10 -3
- package/src/common.mjs +25 -5
- package/src/external-files.mjs +176 -0
- package/src/i18n.mjs +107 -25
- package/src/index.d.ts +18 -2
- package/src/index.mjs +59 -41
- package/src/markdown.mjs +14 -11
- package/src/player-assets.mjs +4 -1
- package/src/player-runtime.mjs +53 -11
- package/src/render.mjs +48 -13
- package/src/server.mjs +2 -0
- package/src/timeline.mjs +32 -30
- package/src/workbuddy.mjs +6 -5
package/player/encore-player.js
CHANGED
|
@@ -3,6 +3,33 @@
|
|
|
3
3
|
// --- i18n.mjs ---
|
|
4
4
|
const DICTS = {
|
|
5
5
|
zh: {
|
|
6
|
+
workspaceWrite: '工作区可写',
|
|
7
|
+
contextLabel: '上下文',
|
|
8
|
+
itemCount: '{n} 条',
|
|
9
|
+
agentSent: '已派出',
|
|
10
|
+
agentStopped: '已叫停',
|
|
11
|
+
agentRateLimited: '额度中断',
|
|
12
|
+
agentFailed: '失败',
|
|
13
|
+
agentDone: '已交回',
|
|
14
|
+
turnTag: '第 {n} 轮',
|
|
15
|
+
replyTag: '第 {n} 次回复',
|
|
16
|
+
stepTag: '第 {n} 步',
|
|
17
|
+
thinking: '思考',
|
|
18
|
+
reasoning: '推理过程',
|
|
19
|
+
preview: '预览',
|
|
20
|
+
draft: '草稿',
|
|
21
|
+
rule: '规则',
|
|
22
|
+
promptTitle: '提问 #{n}',
|
|
23
|
+
sessionStart: '会话开始',
|
|
24
|
+
userMessage: '用户消息',
|
|
25
|
+
assistantReply: '助手回复',
|
|
26
|
+
appendedPrompt: '已将用户消息加入上下文',
|
|
27
|
+
waitingForTools: '等待助手推理与调用工具',
|
|
28
|
+
synthesizing: '汇总结果({tools})',
|
|
29
|
+
directResponse: '直接回复',
|
|
30
|
+
completedResponse: '回复完成',
|
|
31
|
+
toolCalls: '工具调用 × {n}',
|
|
32
|
+
archivedTools: '已归档 {n} 条工具输出(-{tokens}k tokens)',
|
|
6
33
|
langCode: 'zh-CN',
|
|
7
34
|
toggleLangLabel: 'EN',
|
|
8
35
|
toggleLangTitle: 'Switch to English',
|
|
@@ -19,12 +46,12 @@ const DICTS = {
|
|
|
19
46
|
sendThisPrompt: '发送本轮提问',
|
|
20
47
|
waitNextStep: '等待下一步',
|
|
21
48
|
composerPlaceholder: '向 Agent 发送消息…',
|
|
22
|
-
composerFinished: '会话已结束 ·
|
|
49
|
+
composerFinished: '会话已结束 · 点击上方任意消息可查看当时的上下文快照',
|
|
23
50
|
emptyHintStart: '点击左下角 <b>▶ 播放</b>',
|
|
24
51
|
emptyHintOrSend: ' 或输入框蓝色发送键 <b>↑</b>',
|
|
25
52
|
emptyHintEnd: ',体验完整对话与上下文生长',
|
|
26
|
-
activeContext: '
|
|
27
|
-
snapInitial: '
|
|
53
|
+
activeContext: '上下文快照',
|
|
54
|
+
snapInitial: '初始上下文',
|
|
28
55
|
snapInspect: '回看:第 {step} / {total} 步',
|
|
29
56
|
snapCurrent: '第 {step} / {total} 步',
|
|
30
57
|
usedSuffix: '已用',
|
|
@@ -35,20 +62,20 @@ const DICTS = {
|
|
|
35
62
|
legendSys: '系统提示词',
|
|
36
63
|
legendSchema: '工具定义',
|
|
37
64
|
legendUser: '用户消息',
|
|
38
|
-
legendMem: '
|
|
65
|
+
legendMem: '记忆规则',
|
|
39
66
|
legendSkill: '技能注入',
|
|
40
67
|
legendMsg: '助手回复',
|
|
41
68
|
legendTool: '工具输出',
|
|
42
69
|
catSys: '系统提示词(System Prompt)',
|
|
43
70
|
catSchema: '工具定义(Tool Schemas & MCP)',
|
|
44
71
|
catUser: '用户消息(User Messages)',
|
|
45
|
-
catMem: '
|
|
72
|
+
catMem: '记忆规则(Memory & Rules)',
|
|
46
73
|
catSkill: '技能注入(Skills)',
|
|
47
|
-
catMsg: '助手回复(Assistant
|
|
74
|
+
catMsg: '助手回复(Assistant Replies)',
|
|
48
75
|
catTool: '工具输出(Tool Outputs)',
|
|
49
76
|
contextInspector: '上下文明细',
|
|
50
77
|
contextInspectorHint: '点击色块或消息定格展开',
|
|
51
|
-
emptyCategory: '
|
|
78
|
+
emptyCategory: '当前步骤暂无记录',
|
|
52
79
|
viewFullPayload: '查看完整内容 ↗',
|
|
53
80
|
omittedImages: '({prefix}{count} 张附图未收录)',
|
|
54
81
|
omittedImagesAlso: '另有 ',
|
|
@@ -62,15 +89,29 @@ const DICTS = {
|
|
|
62
89
|
compactModalTitle: '上下文压缩摘要',
|
|
63
90
|
asksYou: '{tool} 问你',
|
|
64
91
|
deliverablesTitle: '交回的成果',
|
|
65
|
-
|
|
92
|
+
inputFiles: '随消息附上的文件',
|
|
93
|
+
fileVerified: '已核对为会话当时的版本',
|
|
94
|
+
fileExportCopy: '已收录导出时的版本,无法确认是否与会话当时一致',
|
|
95
|
+
fileHashMismatch: '已收录导出时的版本,与会话记录的校验值不符',
|
|
96
|
+
fileMissing: '未找到原文件,无法回看',
|
|
97
|
+
fileOutsideRoot: '文件位于资产根目录之外,未收录',
|
|
98
|
+
fileUnreadable: '未能读取原文件,无法回看',
|
|
99
|
+
viewChanges: '查看改动', beforeRevision: '原稿', afterRevision: '校订稿', openSourcePage: '打开这一页',
|
|
100
|
+
readPdf: '阅读报告', readWorkbook: '查看完整表格', downloadFile: '下载 {type}',
|
|
101
|
+
pdfPages: '{n} 页', sheetCount: '{n} 张工作表', sheetName: '工作表', emptySheet: '空白工作表',
|
|
102
|
+
pageNumber: '页码', pdfPage: '第 {n} 页', prevPage: '上一页', nextPage: '下一页',
|
|
103
|
+
zoom: '缩放', fitWidth: '适合宽度', loadingSheet: '正在读取表格…', sheetLoadError: '读取失败,可重新打开预览或下载原文件。',
|
|
104
|
+
landscape: '横版',
|
|
105
|
+
portrait: '竖版',
|
|
106
|
+
subagentReportTitle: '子 Agent 报告 · {label}',
|
|
66
107
|
viewReport: '查看报告',
|
|
67
108
|
refFrameEyebrow: '📎 参考画面',
|
|
68
|
-
aiFrameEyebrow: '🖼
|
|
109
|
+
aiFrameEyebrow: '🖼 过程画面',
|
|
69
110
|
frameSub: '{time} 产出 · 点击放大查看',
|
|
70
111
|
docEyebrow: '📄 中间文稿产出 · {file}',
|
|
71
112
|
docSub: '{time} 写入 · 约 {kb}k 字 · 点击阅读草稿',
|
|
72
113
|
audioEyebrow: '🔊 过程配音试听({count} 段)',
|
|
73
|
-
lightboxDefaultTitle: '
|
|
114
|
+
lightboxDefaultTitle: '画面预览',
|
|
74
115
|
docModalDefaultTitle: '中间文稿预览',
|
|
75
116
|
closePreview: '关闭预览',
|
|
76
117
|
tlAria: '回放时间轴与控制',
|
|
@@ -79,10 +120,10 @@ const DICTS = {
|
|
|
79
120
|
tlStepMeta: '第 {step} 步 · {time}',
|
|
80
121
|
tlCompressPin: '压缩 #{seq}',
|
|
81
122
|
tlCompressTitle: '🗜 上下文压缩 #{seq}(-{dropped}k)',
|
|
82
|
-
tlPromptTitle: '💬
|
|
123
|
+
tlPromptTitle: '💬 第 {turn} 轮:{summary}',
|
|
83
124
|
tlStepFallback: '步骤详情',
|
|
84
125
|
defaultRefFrame: '参考画面 #{n}',
|
|
85
|
-
defaultAiFrame: '
|
|
126
|
+
defaultAiFrame: '过程画面 #{n}',
|
|
86
127
|
defaultAudioClip: '试听片段',
|
|
87
128
|
statSearch: '搜索 {n} 次',
|
|
88
129
|
statOpen: '打开 {n} 个网页',
|
|
@@ -93,13 +134,40 @@ const DICTS = {
|
|
|
93
134
|
statCode: '运行 {n} 段代码',
|
|
94
135
|
statEdit: '写 {n} 个文件',
|
|
95
136
|
statSkill: '加载 {n} 个技能',
|
|
96
|
-
statAgent: '派出 {n}
|
|
97
|
-
statReply: '收到 {n}
|
|
137
|
+
statAgent: '派出 {n} 个子 Agent',
|
|
138
|
+
statReply: '收到 {n} 份子 Agent 报告',
|
|
98
139
|
statOther: '其他操作 {n} 次',
|
|
99
140
|
statSep: ',',
|
|
100
141
|
execToolsFallback: '执行工具',
|
|
101
142
|
},
|
|
102
143
|
en: {
|
|
144
|
+
workspaceWrite: 'Workspace Write',
|
|
145
|
+
contextLabel: 'Context',
|
|
146
|
+
itemCount: '{n} records',
|
|
147
|
+
agentSent: 'Dispatched',
|
|
148
|
+
agentStopped: 'Stopped',
|
|
149
|
+
agentRateLimited: 'Rate limited',
|
|
150
|
+
agentFailed: 'Failed',
|
|
151
|
+
agentDone: 'Returned',
|
|
152
|
+
turnTag: 'Turn #{n}',
|
|
153
|
+
replyTag: 'Reply #{n}',
|
|
154
|
+
stepTag: 'Step {n}',
|
|
155
|
+
thinking: 'Thinking',
|
|
156
|
+
reasoning: 'Reasoning',
|
|
157
|
+
preview: 'Preview',
|
|
158
|
+
draft: 'Draft',
|
|
159
|
+
rule: 'Rule',
|
|
160
|
+
promptTitle: 'Prompt #{n}',
|
|
161
|
+
sessionStart: 'Session start',
|
|
162
|
+
userMessage: 'User message',
|
|
163
|
+
assistantReply: 'Assistant reply',
|
|
164
|
+
appendedPrompt: 'User message appended to context',
|
|
165
|
+
waitingForTools: 'Waiting for agent reasoning and tool calls',
|
|
166
|
+
synthesizing: 'Synthesizing ({tools})',
|
|
167
|
+
directResponse: 'Direct response',
|
|
168
|
+
completedResponse: 'Completed response',
|
|
169
|
+
toolCalls: 'Tool calls × {n}',
|
|
170
|
+
archivedTools: 'Archived {n} tool outputs (-{tokens}k tokens)',
|
|
103
171
|
langCode: 'en',
|
|
104
172
|
toggleLangLabel: '中文',
|
|
105
173
|
toggleLangTitle: '切换到中文',
|
|
@@ -120,8 +188,8 @@ const DICTS = {
|
|
|
120
188
|
emptyHintStart: 'Click <b>▶ Play</b> at the bottom-left',
|
|
121
189
|
emptyHintOrSend: ' or the blue <b>↑</b> send button',
|
|
122
190
|
emptyHintEnd: ' to replay the conversation and live context growth',
|
|
123
|
-
activeContext: '
|
|
124
|
-
snapInitial: '
|
|
191
|
+
activeContext: 'Context Snapshot',
|
|
192
|
+
snapInitial: 'Initial Context',
|
|
125
193
|
snapInspect: 'Inspecting: Step {step} / {total}',
|
|
126
194
|
snapCurrent: 'Step {step} / {total}',
|
|
127
195
|
usedSuffix: 'used',
|
|
@@ -131,7 +199,7 @@ const DICTS = {
|
|
|
131
199
|
outputReserveTitle: 'Max Output Reserve (8%)',
|
|
132
200
|
legendSys: 'System Prompt',
|
|
133
201
|
legendSchema: 'Tool Schemas',
|
|
134
|
-
legendUser: 'User
|
|
202
|
+
legendUser: 'User Messages',
|
|
135
203
|
legendMem: 'Memory & Rules',
|
|
136
204
|
legendSkill: 'Skills',
|
|
137
205
|
legendMsg: 'Assistant',
|
|
@@ -139,13 +207,13 @@ const DICTS = {
|
|
|
139
207
|
catSys: 'System Prompt',
|
|
140
208
|
catSchema: 'Tool Schemas & MCP',
|
|
141
209
|
catUser: 'User Messages',
|
|
142
|
-
catMem: 'Memory &
|
|
210
|
+
catMem: 'Memory & Rules',
|
|
143
211
|
catSkill: 'Skills',
|
|
144
|
-
catMsg: 'Assistant
|
|
212
|
+
catMsg: 'Assistant Replies',
|
|
145
213
|
catTool: 'Tool Outputs',
|
|
146
214
|
contextInspector: 'Context Inspector',
|
|
147
215
|
contextInspectorHint: 'Click a bar segment or message to inspect',
|
|
148
|
-
emptyCategory: 'No
|
|
216
|
+
emptyCategory: 'No records at this step',
|
|
149
217
|
viewFullPayload: 'View full payload ↗',
|
|
150
218
|
omittedImages: '({prefix}{count} attached image(s) omitted)',
|
|
151
219
|
omittedImagesAlso: 'plus ',
|
|
@@ -159,10 +227,24 @@ const DICTS = {
|
|
|
159
227
|
compactModalTitle: 'Compaction Summary',
|
|
160
228
|
asksYou: '{tool} asks',
|
|
161
229
|
deliverablesTitle: 'Deliverables',
|
|
230
|
+
inputFiles: 'Attachments',
|
|
231
|
+
fileVerified: 'Verified against the version in the session',
|
|
232
|
+
fileExportCopy: 'Captured at export. Its version at the time of the session could not be confirmed.',
|
|
233
|
+
fileHashMismatch: 'Captured at export. Its checksum differs from the one recorded in the session.',
|
|
234
|
+
fileMissing: 'Original file not found. No copy is available.',
|
|
235
|
+
fileOutsideRoot: 'Outside the asset roots. No copy was included.',
|
|
236
|
+
fileUnreadable: 'The original file could not be read. No copy is available.',
|
|
237
|
+
viewChanges: 'View changes', beforeRevision: 'Original', afterRevision: 'Revised', openSourcePage: 'Open this page',
|
|
238
|
+
readPdf: 'Read PDF', readWorkbook: 'View workbook', downloadFile: 'Download {type}',
|
|
239
|
+
pdfPages: '{n} pages', sheetCount: '{n} sheets', sheetName: 'Sheet', emptySheet: 'Empty worksheet',
|
|
240
|
+
pageNumber: 'Page', pdfPage: 'Page {n}', prevPage: 'Previous page', nextPage: 'Next page',
|
|
241
|
+
zoom: 'Zoom', fitWidth: 'Fit width', loadingSheet: 'Loading workbook…', sheetLoadError: 'Could not read workbook. Reopen the preview to retry or download the file.',
|
|
242
|
+
landscape: 'Landscape',
|
|
243
|
+
portrait: 'Portrait',
|
|
162
244
|
subagentReportTitle: 'Sub-agent Report · {label}',
|
|
163
245
|
viewReport: 'View Report',
|
|
164
|
-
refFrameEyebrow: '📎 Reference
|
|
165
|
-
aiFrameEyebrow: '🖼
|
|
246
|
+
refFrameEyebrow: '📎 Reference Frame',
|
|
247
|
+
aiFrameEyebrow: '🖼 Agent Frame',
|
|
166
248
|
frameSub: 'Produced at {time} · Click to enlarge',
|
|
167
249
|
docEyebrow: '📄 Draft Document · {file}',
|
|
168
250
|
docSub: 'Written at {time} · ~{kb}k chars · Click to read',
|
|
@@ -176,10 +258,10 @@ const DICTS = {
|
|
|
176
258
|
tlStepMeta: 'Step {step} · {time}',
|
|
177
259
|
tlCompressPin: 'Compact #{seq}',
|
|
178
260
|
tlCompressTitle: '🗜 Compaction #{seq} (-{dropped}k)',
|
|
179
|
-
tlPromptTitle: '💬
|
|
261
|
+
tlPromptTitle: '💬 Turn #{turn}: {summary}',
|
|
180
262
|
tlStepFallback: 'Step details',
|
|
181
|
-
defaultRefFrame: 'Reference #{n}',
|
|
182
|
-
defaultAiFrame: '
|
|
263
|
+
defaultRefFrame: 'Reference Frame #{n}',
|
|
264
|
+
defaultAiFrame: 'Agent Frame #{n}',
|
|
183
265
|
defaultAudioClip: 'Audio clip',
|
|
184
266
|
statSearch: 'searched {n}x',
|
|
185
267
|
statOpen: 'opened {n} page(s)',
|
|
@@ -286,6 +368,9 @@ function isTableSeparator(line) {
|
|
|
286
368
|
return cells.length > 0 && cells.every(c => /^:?-{2,}:?$/.test(c))
|
|
287
369
|
}
|
|
288
370
|
|
|
371
|
+
const openingFence = /^ {0,3}(`{3,})([^`]*)$/
|
|
372
|
+
const closingFence = /^ {0,3}(`{3,})[ \t]*$/
|
|
373
|
+
|
|
289
374
|
function renderMarkdown(source) {
|
|
290
375
|
const raw = String(source ?? '').replace(/\r\n/g, '\n').trim()
|
|
291
376
|
if (!raw) return ''
|
|
@@ -302,16 +387,17 @@ function renderMarkdown(source) {
|
|
|
302
387
|
continue
|
|
303
388
|
}
|
|
304
389
|
|
|
305
|
-
const fence = line.match(
|
|
390
|
+
const fence = line.match(openingFence)
|
|
306
391
|
if (fence) {
|
|
307
|
-
const lang = fence[1]
|
|
392
|
+
const lang = fence[2].trim().split(/\s+/, 1)[0]
|
|
308
393
|
const codeLines = []
|
|
309
394
|
i++
|
|
310
|
-
while (i < lines.length
|
|
311
|
-
|
|
312
|
-
|
|
395
|
+
while (i < lines.length) {
|
|
396
|
+
const codeLine = lines[i++]
|
|
397
|
+
const close = codeLine.match(closingFence)
|
|
398
|
+
if (close && close[1].length >= fence[1].length) break
|
|
399
|
+
codeLines.push(codeLine)
|
|
313
400
|
}
|
|
314
|
-
if (i < lines.length) i++
|
|
315
401
|
const cls = lang ? ` class="language-${escapeHtml(lang)}"` : ''
|
|
316
402
|
out.push(`<pre><code${cls}>${escapeHtml(codeLines.join('\n'))}</code></pre>`)
|
|
317
403
|
continue
|
|
@@ -377,11 +463,12 @@ function renderMarkdown(source) {
|
|
|
377
463
|
continue
|
|
378
464
|
}
|
|
379
465
|
|
|
380
|
-
const paraLines = []
|
|
466
|
+
const paraLines = [renderInline(line)]
|
|
467
|
+
i++
|
|
381
468
|
while (
|
|
382
469
|
i < lines.length &&
|
|
383
470
|
lines[i].trim() !== '' &&
|
|
384
|
-
|
|
471
|
+
!openingFence.test(lines[i]) &&
|
|
385
472
|
!/^(#{1,6})\s+/.test(lines[i]) &&
|
|
386
473
|
!/^(?:-{3,}|\*{3,}|_{3,})\s*$/.test(lines[i].trim()) &&
|
|
387
474
|
!/^\s*>\s?/.test(lines[i]) &&
|
|
@@ -392,9 +479,7 @@ function renderMarkdown(source) {
|
|
|
392
479
|
paraLines.push(renderInline(lines[i]))
|
|
393
480
|
i++
|
|
394
481
|
}
|
|
395
|
-
|
|
396
|
-
out.push(`<p>${paraLines.join('<br>')}</p>`)
|
|
397
|
-
}
|
|
482
|
+
out.push(`<p>${paraLines.join('<br>')}</p>`)
|
|
398
483
|
}
|
|
399
484
|
|
|
400
485
|
return out.join('\n')
|
|
@@ -563,7 +648,7 @@ function extractStepDocs(toolItems, stepIndex) {
|
|
|
563
648
|
return [...byPath.values()]
|
|
564
649
|
}
|
|
565
650
|
|
|
566
|
-
function extractStepSubagents(toolItems, stepIndex) {
|
|
651
|
+
function extractStepSubagents(toolItems, stepIndex, t) {
|
|
567
652
|
const list = []
|
|
568
653
|
toolItems.forEach((item, idx) => {
|
|
569
654
|
const rawSum = String(item.summary || '')
|
|
@@ -589,17 +674,17 @@ function extractStepSubagents(toolItems, stepIndex) {
|
|
|
589
674
|
const combined = `${rawSum}\n${item.output || ''}`
|
|
590
675
|
const isAsyncSpawn = /^(?:spawn_agent|collaboration__spawn_agent|followup_task|collaboration__followup_task)$/.test(item.name || '')
|
|
591
676
|
let state = 'sent'
|
|
592
|
-
let badge = '
|
|
677
|
+
let badge = t('agentSent')
|
|
593
678
|
let report = ''
|
|
594
679
|
if (/was stopped|中途打断|已取消/i.test(combined)) {
|
|
595
680
|
state = 'stopped'
|
|
596
|
-
badge = '
|
|
681
|
+
badge = t('agentStopped')
|
|
597
682
|
} else if (/failed:|terminated early|rate_limit|hit your session limit|^Error:\s*Failed/im.test(combined)) {
|
|
598
683
|
state = 'failed'
|
|
599
|
-
badge = /limit|429/i.test(combined) ? '
|
|
684
|
+
badge = /limit|429/i.test(combined) ? t('agentRateLimited') : t('agentFailed')
|
|
600
685
|
} else if (item.kind === 'reply' || item.stats?.reply || (!isAsyncSpawn && item.output && item.output.length > 80 && !item.output.trim().startsWith('{'))) {
|
|
601
686
|
state = 'done'
|
|
602
|
-
badge = '
|
|
687
|
+
badge = t('agentDone')
|
|
603
688
|
if (item.output && item.output.length > 40 && !item.output.trim().startsWith('{')) {
|
|
604
689
|
report = String(item.output).trim()
|
|
605
690
|
}
|
|
@@ -863,7 +948,9 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
863
948
|
}
|
|
864
949
|
for (const item of items) {
|
|
865
950
|
if (item.type === 'tool' || item.type === 'reasoning') {
|
|
951
|
+
if (item.deliverables?.length) flushWork()
|
|
866
952
|
work.push(item)
|
|
953
|
+
if (item.deliverables?.length) flushWork()
|
|
867
954
|
continue
|
|
868
955
|
}
|
|
869
956
|
flushWork()
|
|
@@ -973,7 +1060,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
973
1060
|
name,
|
|
974
1061
|
color,
|
|
975
1062
|
itemCount: records.length,
|
|
976
|
-
count:
|
|
1063
|
+
count: t('itemCount', { n: records.length }),
|
|
977
1064
|
tok: `≈${(curTok / 1000).toFixed(1)}k`,
|
|
978
1065
|
pct: `${kindPct(curTok)}%`,
|
|
979
1066
|
delta: stepIdx >= 0 ? fmtCountDelta(records.length, prevCount) : '',
|
|
@@ -1083,8 +1170,8 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
1083
1170
|
id: `user-${userSeq}`,
|
|
1084
1171
|
stepIndex: index,
|
|
1085
1172
|
tokEst: userTok,
|
|
1086
|
-
tag:
|
|
1087
|
-
title: cleanPromptText.slice(0, 56) || '
|
|
1173
|
+
tag: t('turnTag', { n: turnCount }),
|
|
1174
|
+
title: cleanPromptText.slice(0, 56) || t('userMessage'),
|
|
1088
1175
|
meta: `≈${(userTok / 1000).toFixed(1)}k · ${stepTime}s`,
|
|
1089
1176
|
payload: String(first.text || ''),
|
|
1090
1177
|
...(first.images?.length ? { images: first.images } : {}),
|
|
@@ -1101,7 +1188,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
1101
1188
|
tokEst: skTok,
|
|
1102
1189
|
tag: 'SKILL.md',
|
|
1103
1190
|
title: `${skill}/SKILL.md`,
|
|
1104
|
-
meta: `≈${(skTok / 1000).toFixed(1)}k ·
|
|
1191
|
+
meta: `≈${(skTok / 1000).toFixed(1)}k · ${t('turnTag', { n: turnCount })}`,
|
|
1105
1192
|
payload: `# ${skill} (SKILL.md)\nLoaded into active context.`,
|
|
1106
1193
|
}))
|
|
1107
1194
|
}
|
|
@@ -1110,10 +1197,10 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
1110
1197
|
primaryCat = 'user'
|
|
1111
1198
|
speedLabel = '1.0×'
|
|
1112
1199
|
dwellMs = 1500
|
|
1113
|
-
detailTitle =
|
|
1200
|
+
detailTitle = t('promptTitle', { n: turnCount })
|
|
1114
1201
|
detailSnippet = (first.text || '').slice(0, 260)
|
|
1115
|
-
inBrief = '
|
|
1116
|
-
responseBrief = '
|
|
1202
|
+
inBrief = t('appendedPrompt')
|
|
1203
|
+
responseBrief = t('waitingForTools')
|
|
1117
1204
|
} else if (group.groupType === 'compact') {
|
|
1118
1205
|
compactSeq++
|
|
1119
1206
|
const cItem = first
|
|
@@ -1166,10 +1253,10 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
1166
1253
|
speedLabel = '0.8×'
|
|
1167
1254
|
dwellMs = 2100
|
|
1168
1255
|
spotlight = 'context-compact'
|
|
1169
|
-
detailTitle =
|
|
1256
|
+
detailTitle = t('compactTitle', { seq: compactInfo.seq })
|
|
1170
1257
|
detailSnippet = summaryText.slice(0, 260)
|
|
1171
1258
|
inBrief = `${(preTokens / 1000).toFixed(1)}k → ${(postTokens / 1000).toFixed(1)}k`
|
|
1172
|
-
responseBrief =
|
|
1259
|
+
responseBrief = t('archivedTools', { n: archivedTools, tokens: (droppedTokens / 1000).toFixed(1) })
|
|
1173
1260
|
} else if (group.groupType === 'assistant') {
|
|
1174
1261
|
msgSeq++
|
|
1175
1262
|
const cleanReply = (first.text || '').replace(/\s+/g, ' ').trim()
|
|
@@ -1180,8 +1267,8 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
1180
1267
|
id: `msg-${msgSeq}`,
|
|
1181
1268
|
stepIndex: index,
|
|
1182
1269
|
tokEst: msgTok,
|
|
1183
|
-
tag:
|
|
1184
|
-
title: cleanReply.slice(0, 56) || '
|
|
1270
|
+
tag: t('replyTag', { n: msgSeq }),
|
|
1271
|
+
title: cleanReply.slice(0, 56) || t('assistantReply'),
|
|
1185
1272
|
meta: `≈${(msgTok / 1000).toFixed(1)}k · ${stepTime}s`,
|
|
1186
1273
|
payload: String(first.text || ''),
|
|
1187
1274
|
}))
|
|
@@ -1195,17 +1282,17 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
1195
1282
|
primaryCat = 'msg'
|
|
1196
1283
|
speedLabel = '1.0×'
|
|
1197
1284
|
dwellMs = 1750
|
|
1198
|
-
detailTitle = '
|
|
1285
|
+
detailTitle = t('assistantReply')
|
|
1199
1286
|
detailSnippet = (first.text || '').slice(0, 260)
|
|
1200
|
-
inBrief = allTools.length ?
|
|
1201
|
-
responseBrief = cleanReply.slice(0, 96) || '
|
|
1287
|
+
inBrief = allTools.length ? t('synthesizing', { tools: allTools.slice(-2).join(', ') }) : t('directResponse')
|
|
1288
|
+
responseBrief = cleanReply.slice(0, 96) || t('completedResponse')
|
|
1202
1289
|
} else {
|
|
1203
1290
|
const toolItems = group.items.filter(item => item.type === 'tool')
|
|
1204
1291
|
const reasoningItems = group.items.filter(item => item.type === 'reasoning')
|
|
1205
1292
|
const stats = sumStats(toolItems)
|
|
1206
1293
|
const extracted = extractFileChips(toolItems)
|
|
1207
1294
|
stepDocs = extractStepDocs(toolItems, index)
|
|
1208
|
-
stepSubagents = extractStepSubagents(toolItems, index)
|
|
1295
|
+
stepSubagents = extractStepSubagents(toolItems, index, t)
|
|
1209
1296
|
stepAudios = extractStepAudios(toolItems, t)
|
|
1210
1297
|
allTools.push(...extracted.tools)
|
|
1211
1298
|
allChanges.push(...extracted.changes)
|
|
@@ -1220,9 +1307,9 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
1220
1307
|
id: `mem-dyn-${memRecords.length + 1}`,
|
|
1221
1308
|
stepIndex: index,
|
|
1222
1309
|
tokEst: memTok,
|
|
1223
|
-
tag: '
|
|
1310
|
+
tag: t('rule'),
|
|
1224
1311
|
title: `${memName}`,
|
|
1225
|
-
meta: `≈${(memTok / 1000).toFixed(1)}k ·
|
|
1312
|
+
meta: `≈${(memTok / 1000).toFixed(1)}k · ${t('stepTag', { n: index + 1 })}`,
|
|
1226
1313
|
payload: `# ${memName}\nLoaded into context during step ${index + 1}.`,
|
|
1227
1314
|
}))
|
|
1228
1315
|
}
|
|
@@ -1238,9 +1325,9 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
1238
1325
|
id: `think-${msgSeq}`,
|
|
1239
1326
|
stepIndex: index,
|
|
1240
1327
|
tokEst: rTok,
|
|
1241
|
-
tag: '
|
|
1328
|
+
tag: t('thinking'),
|
|
1242
1329
|
title: rItem.text.replace(/\s+/g, ' ').trim().slice(0, 54),
|
|
1243
|
-
meta: `≈${(rTok / 1000).toFixed(1)}k ·
|
|
1330
|
+
meta: `≈${(rTok / 1000).toFixed(1)}k · ${t('reasoning')}`,
|
|
1244
1331
|
payload: String(rItem.text),
|
|
1245
1332
|
}))
|
|
1246
1333
|
}
|
|
@@ -1266,7 +1353,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
1266
1353
|
tokEst: skTok,
|
|
1267
1354
|
tag: 'SKILL.md',
|
|
1268
1355
|
title: `${skill}/SKILL.md`,
|
|
1269
|
-
meta: `≈${(skTok / 1000).toFixed(1)}k ·
|
|
1356
|
+
meta: `≈${(skTok / 1000).toFixed(1)}k · ${t('stepTag', { n: index + 1 })}`,
|
|
1270
1357
|
payload: String(item.output || item.input || `# ${skill} (SKILL.md)`),
|
|
1271
1358
|
}))
|
|
1272
1359
|
}
|
|
@@ -1306,7 +1393,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
1306
1393
|
toolRecords.push(registerRecord({
|
|
1307
1394
|
id: `frame-${++toolSeq}`,
|
|
1308
1395
|
stepIndex: index,
|
|
1309
|
-
tag: '
|
|
1396
|
+
tag: t('preview'),
|
|
1310
1397
|
title: `${fr.label}`,
|
|
1311
1398
|
meta: '≈1.2k tok',
|
|
1312
1399
|
payload: `Preview frame: ${fr.label}`,
|
|
@@ -1314,7 +1401,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
1314
1401
|
}))
|
|
1315
1402
|
}
|
|
1316
1403
|
rawMontage.push({
|
|
1317
|
-
tag: '
|
|
1404
|
+
tag: t('preview'),
|
|
1318
1405
|
title: `${fr.label}`,
|
|
1319
1406
|
isSpot: true,
|
|
1320
1407
|
speed: '🖼',
|
|
@@ -1322,7 +1409,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
1322
1409
|
}
|
|
1323
1410
|
for (const doc of stepDocs) {
|
|
1324
1411
|
rawMontage.push({
|
|
1325
|
-
tag: '
|
|
1412
|
+
tag: t('draft'),
|
|
1326
1413
|
title: `${doc.title}`,
|
|
1327
1414
|
isSpot: true,
|
|
1328
1415
|
speed: '📄',
|
|
@@ -1369,7 +1456,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
1369
1456
|
dwellMs = 1100
|
|
1370
1457
|
}
|
|
1371
1458
|
if (toolItems.length) {
|
|
1372
|
-
detailTitle =
|
|
1459
|
+
detailTitle = t('toolCalls', { n: toolItems.length })
|
|
1373
1460
|
detailSnippet = toolItems.slice(0, 3).map(item => item.summary).join('\n')
|
|
1374
1461
|
const primaryTool = toolItems[0]?.name || 'tool'
|
|
1375
1462
|
inBrief = `${primaryTool} · ${toolItems.slice(0, 2).map(i => i.summary).join(';')}`
|
|
@@ -1460,7 +1547,7 @@ function buildSteps(items, end, sessionTool = 'codex', sessionModel = '', frames
|
|
|
1460
1547
|
snippet: detailSnippet,
|
|
1461
1548
|
},
|
|
1462
1549
|
brief: {
|
|
1463
|
-
user: latestUserPrompt || '
|
|
1550
|
+
user: latestUserPrompt || t('sessionStart'),
|
|
1464
1551
|
in: inBrief,
|
|
1465
1552
|
response: responseBrief,
|
|
1466
1553
|
},
|
|
@@ -1567,11 +1654,181 @@ function describeStats(stats, keys = statKeyMap.map(([key]) => key), lang = 'zh'
|
|
|
1567
1654
|
.join(t('statSep'))
|
|
1568
1655
|
}
|
|
1569
1656
|
|
|
1657
|
+
// --- attachment-reader.mjs ---
|
|
1658
|
+
function attachmentTable(rows, { compact = false } = {}) {
|
|
1659
|
+
if (!rows.length) return ''
|
|
1660
|
+
const head = rows[0].map(cell => `<th scope="col">${escapeHtml(cell)}</th>`).join('')
|
|
1661
|
+
const body = rows.slice(1).map(row => {
|
|
1662
|
+
const cells = row.map(value => {
|
|
1663
|
+
const text = String(value ?? '')
|
|
1664
|
+
const content = !compact && text.length > 70
|
|
1665
|
+
? `<details><summary>${escapeHtml(text.slice(0, 52))}…</summary>${escapeHtml(text)}</details>`
|
|
1666
|
+
: escapeHtml(text)
|
|
1667
|
+
return `<td>${content}</td>`
|
|
1668
|
+
})
|
|
1669
|
+
return `<tr>${cells.join('')}</tr>`
|
|
1670
|
+
})
|
|
1671
|
+
return `<table><thead><tr>${head}</tr></thead><tbody>${body.join('')}</tbody></table>`
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
function renderRevision(file, t, url) {
|
|
1675
|
+
const change = file.preview.change
|
|
1676
|
+
if (!change || !file.revision) return ''
|
|
1677
|
+
const revision = file.revision
|
|
1678
|
+
const pdf = file.preview.type === 'pdf'
|
|
1679
|
+
const location = pdf ? t('pdfPage', { n: revision.page }) : `${revision.sheet} · ${revision.cell}`
|
|
1680
|
+
const before = Array.from(change.before), after = Array.from(change.after)
|
|
1681
|
+
const shorter = Math.min(before.length, after.length)
|
|
1682
|
+
let start = 0, end = 0
|
|
1683
|
+
while (start < shorter && before[start] === after[start]) start++
|
|
1684
|
+
while (end < shorter - start && before.at(-1 - end) === after.at(-1 - end)) end++
|
|
1685
|
+
function side(chars, original) {
|
|
1686
|
+
const stop = chars.length - end
|
|
1687
|
+
const tag = original ? 'del' : 'ins'
|
|
1688
|
+
const text = escapeHtml(chars.slice(0, start).join(''))
|
|
1689
|
+
+ `<${tag}>${escapeHtml(chars.slice(start, stop).join(''))}</${tag}>`
|
|
1690
|
+
+ escapeHtml(chars.slice(stop).join(''))
|
|
1691
|
+
const src = url(original ? revision.href : file.href)
|
|
1692
|
+
const link = pdf
|
|
1693
|
+
? `<a href="${escapeHtml(src)}#page=${Number(revision.page)}" target="_blank" rel="noopener noreferrer">${t('openSourcePage')}</a>`
|
|
1694
|
+
: `<a href="${escapeHtml(src)}" download>${t('downloadFile', { type: 'Excel' })}</a>`
|
|
1695
|
+
return `<section><strong>${t(original ? 'beforeRevision' : 'afterRevision')}</strong><p>${text}</p>${link}</section>`
|
|
1696
|
+
}
|
|
1697
|
+
return `<details class="session-revision"><summary>${t('viewChanges')}</summary>
|
|
1698
|
+
<div class="session-revision-context"><b>${escapeHtml(revision.label)}</b><span>${escapeHtml(location)}</span></div>
|
|
1699
|
+
<div class="session-revision-pair">${side(before, true)}${side(after, false)}</div></details>`
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
function renderAttachment(file, t, url) {
|
|
1703
|
+
const preview = file.preview
|
|
1704
|
+
const pdf = preview.type === 'pdf'
|
|
1705
|
+
const type = pdf ? 'PDF' : 'Excel'
|
|
1706
|
+
const action = t(pdf ? 'readPdf' : 'readWorkbook')
|
|
1707
|
+
const count = pdf ? t('pdfPages', { n: preview.pages.length }) : t('sheetCount', { n: preview.count })
|
|
1708
|
+
const download = `<a href="${escapeHtml(url(file.href))}" download${file.availability ? `="${escapeHtml(file.title)}"` : ''}>${t('downloadFile', { type })}</a>`
|
|
1709
|
+
const title = escapeHtml(file.title)
|
|
1710
|
+
const toolbar = pdf
|
|
1711
|
+
? `<button type="button" data-page-prev aria-label="${t('prevPage')}">‹</button>
|
|
1712
|
+
<label>${t('pageNumber')} <input data-page-number type="number" min="1" max="${preview.pages.length}" value="1"> / ${preview.pages.length}</label>
|
|
1713
|
+
<button type="button" data-page-next aria-label="${t('nextPage')}">›</button>
|
|
1714
|
+
<select data-page-zoom aria-label="${t('zoom')}"><option value="100">${t('fitWidth')}</option><option value="125">125%</option><option value="150">150%</option></select>`
|
|
1715
|
+
: `<label>${t('sheetName')} <select data-sheet-picker></select></label>`
|
|
1716
|
+
const content = pdf
|
|
1717
|
+
? `<template>${preview.pages.map((page, i) => `<img loading="lazy" src="${escapeHtml(url(page.src))}" width="${Number(page.width)}" height="${Number(page.height)}" alt="${escapeHtml(t('pdfPage', { n: i + 1 }))}">`).join('')}</template>`
|
|
1718
|
+
: ''
|
|
1719
|
+
const source = pdf ? '' : ` data-workbook-src="${escapeHtml(url(preview.src))}" data-first-sheet="${escapeHtml(preview.sheet)}"`
|
|
1720
|
+
const summary = pdf
|
|
1721
|
+
? `<img class="session-pdf-cover" src="${escapeHtml(url(file.cover || preview.pages[0].src))}" alt="" loading="lazy">`
|
|
1722
|
+
: ''
|
|
1723
|
+
return `<section class="session-attachment" data-attachment="${preview.type}"${source}>
|
|
1724
|
+
<div class="session-attachment-head">${summary}<div><strong>${title}</strong>
|
|
1725
|
+
<small>${type} · ${count}${file.meta ? ' · ' + escapeHtml(file.meta) : ''}</small></div></div>
|
|
1726
|
+
${pdf ? '' : `<div class="session-sheet-sample">${attachmentTable(preview.rows, { compact: true })}</div>`}
|
|
1727
|
+
<div class="session-attachment-actions"><button type="button" data-open-attachment>${action}</button>${download}</div>
|
|
1728
|
+
${renderRevision(file, t, url)}
|
|
1729
|
+
<dialog class="session-attachment-dialog" aria-label="${title}">
|
|
1730
|
+
<header><strong>${title}</strong>${download}<button type="button" data-close-attachment aria-label="${t('closePreview')}">✕</button></header>
|
|
1731
|
+
<div class="session-attachment-toolbar">${toolbar}</div>
|
|
1732
|
+
<div class="session-attachment-viewport" role="region" aria-label="${title}" tabindex="0"></div>
|
|
1733
|
+
</dialog>${content}
|
|
1734
|
+
</section>`
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
function attachPdfReader(card, viewport) {
|
|
1738
|
+
viewport.append(card.querySelector('template').content.cloneNode(true))
|
|
1739
|
+
const pages = [...viewport.querySelectorAll('img')]
|
|
1740
|
+
const number = card.querySelector('[data-page-number]')
|
|
1741
|
+
const previous = card.querySelector('[data-page-prev]')
|
|
1742
|
+
const next = card.querySelector('[data-page-next]')
|
|
1743
|
+
function setPage(n) {
|
|
1744
|
+
number.value = n
|
|
1745
|
+
previous.disabled = n === 1
|
|
1746
|
+
next.disabled = n === pages.length
|
|
1747
|
+
}
|
|
1748
|
+
function jump(n) {
|
|
1749
|
+
n = Math.max(1, Math.min(pages.length, Math.round(n) || 1))
|
|
1750
|
+
pages[n - 1].scrollIntoView({ block: 'start', inline: 'nearest' })
|
|
1751
|
+
setPage(n)
|
|
1752
|
+
}
|
|
1753
|
+
number.addEventListener('change', () => jump(number.valueAsNumber))
|
|
1754
|
+
number.addEventListener('keydown', event => {
|
|
1755
|
+
if (event.key === 'Enter') jump(number.valueAsNumber)
|
|
1756
|
+
})
|
|
1757
|
+
previous.addEventListener('click', () => jump(number.valueAsNumber - 1))
|
|
1758
|
+
next.addEventListener('click', () => jump(number.valueAsNumber + 1))
|
|
1759
|
+
card.querySelector('[data-page-zoom]').addEventListener('change', event => {
|
|
1760
|
+
viewport.style.setProperty('--attachment-page-width', event.target.value + '%')
|
|
1761
|
+
jump(number.valueAsNumber)
|
|
1762
|
+
})
|
|
1763
|
+
viewport.addEventListener('scroll', () => {
|
|
1764
|
+
if (document.activeElement === number) return
|
|
1765
|
+
const top = viewport.getBoundingClientRect().top + 32
|
|
1766
|
+
const i = pages.findIndex(page => page.getBoundingClientRect().bottom > top)
|
|
1767
|
+
setPage(i < 0 ? pages.length : i + 1)
|
|
1768
|
+
}, { passive: true })
|
|
1769
|
+
setPage(1)
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
async function attachWorkbookReader(card, viewport, t) {
|
|
1773
|
+
const response = await fetch(card.dataset.workbookSrc)
|
|
1774
|
+
if (!response.ok) throw new Error('HTTP ' + response.status)
|
|
1775
|
+
const sheets = await response.json()
|
|
1776
|
+
const picker = card.querySelector('[data-sheet-picker]')
|
|
1777
|
+
for (const sheet of sheets) picker.add(new Option(sheet.sheet, sheet.sheet))
|
|
1778
|
+
picker.value = card.dataset.firstSheet
|
|
1779
|
+
function selectSheet() {
|
|
1780
|
+
viewport.innerHTML = attachmentTable(sheets[picker.selectedIndex].data) || escapeHtml(t('emptySheet'))
|
|
1781
|
+
viewport.scrollTo(0, 0)
|
|
1782
|
+
}
|
|
1783
|
+
picker.addEventListener('change', selectSheet)
|
|
1784
|
+
selectSheet()
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
function attachAttachmentReaders(container, t, pauseReplay) {
|
|
1788
|
+
for (const card of container.querySelectorAll('[data-attachment]')) {
|
|
1789
|
+
const revision = card.querySelector('.session-revision')
|
|
1790
|
+
revision?.addEventListener('toggle', () => {
|
|
1791
|
+
if (revision.open) {
|
|
1792
|
+
pauseReplay()
|
|
1793
|
+
revision.scrollIntoView({ block: 'nearest' })
|
|
1794
|
+
}
|
|
1795
|
+
})
|
|
1796
|
+
const dialog = card.querySelector('dialog')
|
|
1797
|
+
const viewport = card.querySelector('.session-attachment-viewport')
|
|
1798
|
+
let initialized = false
|
|
1799
|
+
card.querySelector('[data-open-attachment]').addEventListener('click', async () => {
|
|
1800
|
+
pauseReplay()
|
|
1801
|
+
dialog.showModal()
|
|
1802
|
+
if (initialized) return
|
|
1803
|
+
initialized = true
|
|
1804
|
+
if (card.dataset.attachment === 'pdf') {
|
|
1805
|
+
attachPdfReader(card, viewport)
|
|
1806
|
+
} else {
|
|
1807
|
+
viewport.textContent = t('loadingSheet')
|
|
1808
|
+
try {
|
|
1809
|
+
await attachWorkbookReader(card, viewport, t)
|
|
1810
|
+
} catch {
|
|
1811
|
+
viewport.textContent = t('sheetLoadError')
|
|
1812
|
+
initialized = false
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
})
|
|
1816
|
+
card.querySelector('[data-close-attachment]').addEventListener('click', () => dialog.close())
|
|
1817
|
+
dialog.addEventListener('click', event => {
|
|
1818
|
+
if (event.target === dialog) {
|
|
1819
|
+
const box = dialog.getBoundingClientRect()
|
|
1820
|
+
if (event.clientX < box.left || event.clientX > box.right || event.clientY < box.top || event.clientY > box.bottom) dialog.close()
|
|
1821
|
+
}
|
|
1822
|
+
})
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1570
1826
|
// --- render.mjs ---
|
|
1571
1827
|
const escape = escapeHtml
|
|
1572
1828
|
|
|
1573
1829
|
|
|
1574
1830
|
|
|
1831
|
+
|
|
1575
1832
|
const toolLabels = {
|
|
1576
1833
|
codex: 'Codex',
|
|
1577
1834
|
workbuddy: 'WorkBuddy',
|
|
@@ -1896,12 +2153,51 @@ function contextSidebar(line, t) {
|
|
|
1896
2153
|
</aside>`
|
|
1897
2154
|
}
|
|
1898
2155
|
|
|
2156
|
+
function renderDeliverable(file, t, baseUrl) {
|
|
2157
|
+
if (!file.availability) return renderFileContents(file, t, baseUrl)
|
|
2158
|
+
if (file.availability === 'missing') {
|
|
2159
|
+
const notice = { 'outside-root': 'fileOutsideRoot', unreadable: 'fileUnreadable' }[file.unavailableReason] || 'fileMissing'
|
|
2160
|
+
return `<section class="session-file-missing" data-availability="missing"><strong>${escape(file.title)}</strong><small>${escape(t(notice))}</small></section>`
|
|
2161
|
+
}
|
|
2162
|
+
const notice = t(file.availability === 'verified' ? 'fileVerified' : file.sessionSha256 ? 'fileHashMismatch' : 'fileExportCopy')
|
|
2163
|
+
return `<div class="session-file-copy" data-availability="${escape(file.availability)}"><small>${escape(notice)}</small>${renderFileContents(file, t, baseUrl)}</div>`
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
function renderFileContents(file, t, baseUrl) {
|
|
2167
|
+
if (file.preview?.type === 'xlsx' || file.preview?.pages?.length && file.preview.type === 'pdf') {
|
|
2168
|
+
return renderAttachment(file, t, src => resolveAsset(src, baseUrl))
|
|
2169
|
+
}
|
|
2170
|
+
const href = escape(resolveAsset(file.href, baseUrl))
|
|
2171
|
+
const cover = escape(resolveAsset(file.cover, baseUrl))
|
|
2172
|
+
const title = escape(file.title)
|
|
2173
|
+
const caption = `<b>${title}</b>${file.meta ? `<small>${escape(file.meta)}</small>` : ''}`
|
|
2174
|
+
if (!validVideo.test(file.href)) {
|
|
2175
|
+
if (file.availability) return `<a class="session-file-download" href="${href}" download="${title}">${caption}</a>`
|
|
2176
|
+
return `<a class="session-file" href="${href}" target="_blank" rel="noopener noreferrer">${cover ? `<img src="${cover}" alt="" width="56" height="79" loading="lazy">` : ''}<span>${caption}</span></a>`
|
|
2177
|
+
}
|
|
2178
|
+
const formats = file.portrait?.href ? `<div class="session-video-formats">
|
|
2179
|
+
<button type="button" data-video-format="landscape" data-src="${href}" data-cover="${cover}" aria-pressed="true">${t('landscape')}</button>
|
|
2180
|
+
<button type="button" data-video-format="portrait" data-src="${escape(resolveAsset(file.portrait.href, baseUrl))}" data-cover="${escape(resolveAsset(file.portrait.cover, baseUrl))}" aria-pressed="false">${t('portrait')}</button>
|
|
2181
|
+
</div>` : ''
|
|
2182
|
+
return `<figure class="session-video">
|
|
2183
|
+
<figcaption><span>${caption}</span>${formats}</figcaption>
|
|
2184
|
+
<video controls playsinline loading="lazy" preload="none" width="960" height="540" aria-label="${title}" src="${href}"${cover ? ` poster="${cover}"` : ''}></video>
|
|
2185
|
+
</figure>`
|
|
2186
|
+
}
|
|
2187
|
+
|
|
1899
2188
|
function renderLog(session, line, { t, baseUrl = '' }) {
|
|
1900
2189
|
const tool = toolLabels[session.tool] || session.tool || 'Agent'
|
|
1901
2190
|
const render = text => renderMarkdown(localLinks(text))
|
|
1902
2191
|
const entries = []
|
|
1903
2192
|
let shown = -Infinity
|
|
1904
2193
|
let stepIndex = 0
|
|
2194
|
+
let delivery = 0
|
|
2195
|
+
|
|
2196
|
+
function addFiles(files, step, time, atEnd = false, label = 'deliverablesTitle') {
|
|
2197
|
+
if (!files?.length) return
|
|
2198
|
+
const html = files.map(file => renderDeliverable(file, t, baseUrl)).join('')
|
|
2199
|
+
entries.push(`<li class="session-entry session-ai session-files" data-delivery="${++delivery}"${atEnd ? ' data-final-files' : ''} data-for-step="${step}" data-t="${time}"><div class="session-bubble"><span class="session-who">${escape(t(label))}</span>${html}</div></li>`)
|
|
2200
|
+
}
|
|
1905
2201
|
|
|
1906
2202
|
const stamp = (seconds, forStep) => {
|
|
1907
2203
|
if (seconds - shown < 300) return ''
|
|
@@ -1957,7 +2253,12 @@ function renderLog(session, line, { t, baseUrl = '' }) {
|
|
|
1957
2253
|
|
|
1958
2254
|
for (const item of line.items) {
|
|
1959
2255
|
if (item.type === 'tool' || item.type === 'reasoning') {
|
|
2256
|
+
if (item.deliverables?.length) flush()
|
|
1960
2257
|
work.push(item)
|
|
2258
|
+
if (item.deliverables?.length) {
|
|
2259
|
+
flush()
|
|
2260
|
+
addFiles(item.deliverables, stepIndex - 1, item.t)
|
|
2261
|
+
}
|
|
1961
2262
|
continue
|
|
1962
2263
|
}
|
|
1963
2264
|
flush()
|
|
@@ -1985,20 +2286,10 @@ function renderLog(session, line, { t, baseUrl = '' }) {
|
|
|
1985
2286
|
} else {
|
|
1986
2287
|
entries.push(`${stamp(item.t, stepIndex - 1)}<li class="session-entry session-ai" data-step="${stepIndex - 1}" data-echo-cat="msg" data-kind="reply" data-t="${item.t}"><div class="session-bubble">${item.question ? `<span class="session-who">${escape(t('asksYou', { tool }))}</span>` : ''}<div class="session-ai-body">${render(item.text)}</div>${renderStepArtifacts(stepMeta, { renderMd: render, t, baseUrl })}</div></li>`)
|
|
1987
2288
|
}
|
|
2289
|
+
addFiles(item.deliverables, stepIndex - 1, item.t, false, item.type === 'user' ? 'inputFiles' : 'deliverablesTitle')
|
|
1988
2290
|
}
|
|
1989
2291
|
flush()
|
|
1990
|
-
|
|
1991
|
-
const deliverables = session.deliverables || session.files || []
|
|
1992
|
-
const filesHtml = deliverables.map(file => {
|
|
1993
|
-
const href = escape(resolveAsset(file.href, baseUrl))
|
|
1994
|
-
const cover = file.cover ? escape(resolveAsset(file.cover, baseUrl)) : ''
|
|
1995
|
-
return validVideo.test(file.href)
|
|
1996
|
-
? `<figure class="session-video"><video controls preload="none" playsinline width="960" height="540"${cover ? ` poster="${cover}"` : ''}><source src="${href}" type="video/mp4"></video><figcaption><b>${escape(file.title)}</b>${file.meta ? `<small>${escape(file.meta)}</small>` : ''}</figcaption></figure>`
|
|
1997
|
-
: `<a class="session-file" href="${href}" target="_blank" rel="noopener noreferrer">${cover ? `<img src="${cover}" alt="" width="56" height="79" loading="lazy">` : ''}<span><b>${escape(file.title)}</b>${file.meta ? `<small>${escape(file.meta)}</small>` : ''}</span></a>`
|
|
1998
|
-
}).join('')
|
|
1999
|
-
if (filesHtml) {
|
|
2000
|
-
entries.push(`<li class="session-entry session-ai session-files" data-for-step="${Math.max(0, line.steps.length - 1)}" data-t="${line.end}"><div class="session-bubble"><span class="session-who">${escape(t('deliverablesTitle'))}</span>${filesHtml}</div></li>`)
|
|
2001
|
-
}
|
|
2292
|
+
addFiles(session.deliverables || session.files, Math.max(0, line.steps.length - 1), line.end, true)
|
|
2002
2293
|
return `<ol class="session-log">${entries.join('')}</ol>`
|
|
2003
2294
|
}
|
|
2004
2295
|
|
|
@@ -2131,7 +2422,7 @@ function renderPlayerWidget(session, computedTimeline, {
|
|
|
2131
2422
|
<div class="session-composer-bar">
|
|
2132
2423
|
<span class="session-composer-left">
|
|
2133
2424
|
<span class="session-composer-plus" aria-hidden="true">+</span>
|
|
2134
|
-
<span class="session-composer-perm" data-session-stage-badge
|
|
2425
|
+
<span class="session-composer-perm" data-session-stage-badge>${escape(t('workspaceWrite'))}</span>
|
|
2135
2426
|
</span>
|
|
2136
2427
|
<span class="session-composer-right">
|
|
2137
2428
|
<span class="session-composer-model">${escape(session.model || tool)}</span>
|
|
@@ -2514,7 +2805,36 @@ function attachPlayerController(containerEl, playerData, { lang = 'zh', initialS
|
|
|
2514
2805
|
}
|
|
2515
2806
|
|
|
2516
2807
|
if (play) play.hidden = false
|
|
2808
|
+
attachAttachmentReaders(containerEl, t, () => { if (playing) setPlaying(false) })
|
|
2517
2809
|
if (log) log.classList.add('is-staged')
|
|
2810
|
+
for (const formats of containerEl.querySelectorAll('.session-video-formats')) {
|
|
2811
|
+
const figure = formats.closest('figure')
|
|
2812
|
+
const video = figure.querySelector('video')
|
|
2813
|
+
formats.addEventListener('click', async event => {
|
|
2814
|
+
const button = event.target.closest('[data-video-format]')
|
|
2815
|
+
if (!button || button.getAttribute('aria-pressed') === 'true') return
|
|
2816
|
+
const time = video.currentTime
|
|
2817
|
+
const resume = !video.paused && !video.ended
|
|
2818
|
+
formats.querySelector('[aria-pressed="true"]').setAttribute('aria-pressed', 'false')
|
|
2819
|
+
button.setAttribute('aria-pressed', 'true')
|
|
2820
|
+
video.dataset.format = button.dataset.videoFormat
|
|
2821
|
+
if (button.dataset.cover) video.poster = button.dataset.cover
|
|
2822
|
+
else video.removeAttribute('poster')
|
|
2823
|
+
video.preload = time > 0 ? 'metadata' : 'none'
|
|
2824
|
+
video.src = button.dataset.src
|
|
2825
|
+
video.load()
|
|
2826
|
+
if (time > 0) video.currentTime = time
|
|
2827
|
+
figure.scrollIntoView({ block: 'nearest' })
|
|
2828
|
+
if (resume) {
|
|
2829
|
+
try {
|
|
2830
|
+
await video.play()
|
|
2831
|
+
} catch (error) {
|
|
2832
|
+
// Switching again or pausing can interrupt the pending play request.
|
|
2833
|
+
if (error.name !== 'AbortError') throw error
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
})
|
|
2837
|
+
}
|
|
2518
2838
|
if (scrubber) {
|
|
2519
2839
|
scrubber.classList.add('is-ready')
|
|
2520
2840
|
scrubber.removeAttribute('aria-hidden')
|
|
@@ -2741,7 +3061,7 @@ function attachPlayerController(containerEl, playerData, { lang = 'zh', initialS
|
|
|
2741
3061
|
: shorten(s.summary || t('tlStepFallback'), 24)
|
|
2742
3062
|
const tokStr = `${((s.contextSnapshot?.totalTokens || 0) / 1000).toFixed(1)}k`
|
|
2743
3063
|
tlPop.style.left = `${pct.toFixed(1)}%`
|
|
2744
|
-
tlPop.innerHTML = `${thumbHtml}<span class="session-tl-pop-meta"><small>${escapeHtml(t('tlStepMeta', { step: idx + 1, time: elapsedClock(s.t) }))}</small><b>${escapeHtml(headTitle)}</b><span
|
|
3064
|
+
tlPop.innerHTML = `${thumbHtml}<span class="session-tl-pop-meta"><small>${escapeHtml(t('tlStepMeta', { step: idx + 1, time: elapsedClock(s.t) }))}</small><b>${escapeHtml(headTitle)}</b><span>${escapeHtml(t('contextLabel'))} ≈${escapeHtml(tokStr)}</span></span>`
|
|
2745
3065
|
tlPop.hidden = false
|
|
2746
3066
|
}
|
|
2747
3067
|
|
|
@@ -3194,6 +3514,9 @@ function attachPlayerController(containerEl, playerData, { lang = 'zh', initialS
|
|
|
3194
3514
|
if (!future) latestVisibleEntry = item.entry
|
|
3195
3515
|
}
|
|
3196
3516
|
for (const aux of auxEntries) {
|
|
3517
|
+
if (aux.forStep > playHead && aux.entry.matches('.session-files:not(.is-future)')) {
|
|
3518
|
+
aux.entry.querySelectorAll('video').forEach(video => video.pause())
|
|
3519
|
+
}
|
|
3197
3520
|
aux.entry.classList.toggle('is-future', aux.forStep > playHead)
|
|
3198
3521
|
}
|
|
3199
3522
|
|
|
@@ -3321,8 +3644,8 @@ function attachPlayerController(containerEl, playerData, { lang = 'zh', initialS
|
|
|
3321
3644
|
})
|
|
3322
3645
|
|
|
3323
3646
|
const onKeyDown = event => {
|
|
3324
|
-
if (event.defaultPrevented || event.metaKey || event.ctrlKey || event.altKey) return
|
|
3325
|
-
if (event.target.closest('input, textarea, select, a, audio, video, summary, [contenteditable]')) return
|
|
3647
|
+
if (lightbox?.open || event.target.closest('dialog[open]') || event.defaultPrevented || event.metaKey || event.ctrlKey || event.altKey) return
|
|
3648
|
+
if (event.target.closest('input, textarea, select, a, audio, video, .session-video-formats, summary, [contenteditable]')) return
|
|
3326
3649
|
if (event.key === ' ' && event.target.closest('button')) return
|
|
3327
3650
|
if (event.key === 'ArrowLeft') {
|
|
3328
3651
|
setPlaying(false)
|
|
@@ -3337,9 +3660,8 @@ function attachPlayerController(containerEl, playerData, { lang = 'zh', initialS
|
|
|
3337
3660
|
}
|
|
3338
3661
|
event.preventDefault()
|
|
3339
3662
|
}
|
|
3340
|
-
if (
|
|
3341
|
-
|
|
3342
|
-
}
|
|
3663
|
+
if (!appEl.hasAttribute('tabindex')) appEl.tabIndex = -1
|
|
3664
|
+
appEl.addEventListener('keydown', onKeyDown)
|
|
3343
3665
|
|
|
3344
3666
|
if (scrubber) {
|
|
3345
3667
|
const fromPointer = event => {
|
|
@@ -3369,9 +3691,7 @@ function attachPlayerController(containerEl, playerData, { lang = 'zh', initialS
|
|
|
3369
3691
|
destroy() {
|
|
3370
3692
|
clearStepAnimations()
|
|
3371
3693
|
camera.stop()
|
|
3372
|
-
|
|
3373
|
-
document.removeEventListener('keydown', onKeyDown)
|
|
3374
|
-
}
|
|
3694
|
+
appEl.removeEventListener('keydown', onKeyDown)
|
|
3375
3695
|
},
|
|
3376
3696
|
goToStage,
|
|
3377
3697
|
setPlaying,
|
|
@@ -3440,7 +3760,7 @@ async function createEncorePlayer(targetEl, sourceOrSession, options = {}) {
|
|
|
3440
3760
|
if (activeController) activeController.destroy()
|
|
3441
3761
|
activeLang = resolveLang(lang)
|
|
3442
3762
|
const line = timeline(session, { lang: activeLang })
|
|
3443
|
-
el.innerHTML = renderPlayerWidget(session, line, { lang: activeLang, baseUrl })
|
|
3763
|
+
el.innerHTML = renderPlayerWidget(session, line, { lang: activeLang, baseUrl, showLangToggle: options.showLangToggle })
|
|
3444
3764
|
if (session.title && document.querySelectorAll('[data-encore-player]').length <= 1) {
|
|
3445
3765
|
document.title = `${session.title} · Encore`
|
|
3446
3766
|
}
|
|
@@ -3467,7 +3787,19 @@ async function autoMountEncorePlayers() {
|
|
|
3467
3787
|
if (node.dataset.encoreMounted) continue
|
|
3468
3788
|
node.dataset.encoreMounted = '1'
|
|
3469
3789
|
try {
|
|
3470
|
-
await createEncorePlayer(node)
|
|
3790
|
+
const player = await createEncorePlayer(node)
|
|
3791
|
+
const showLinkedDelivery = () => {
|
|
3792
|
+
const match = /^#delivery-(\d+)$/.exec(location.hash)
|
|
3793
|
+
const files = match ? node.querySelector(`[data-delivery="${match[1]}"]`)
|
|
3794
|
+
: location.hash === '#deliverables' && [...node.querySelectorAll('[data-delivery]')].at(-1)
|
|
3795
|
+
if (!files) return
|
|
3796
|
+
const controller = player.getController()
|
|
3797
|
+
controller.setPlaying(false)
|
|
3798
|
+
controller.goToStage(Number(files.dataset.forStep), false)
|
|
3799
|
+
files.scrollIntoView({ block: 'start' })
|
|
3800
|
+
}
|
|
3801
|
+
showLinkedDelivery()
|
|
3802
|
+
window.addEventListener('hashchange', showLinkedDelivery)
|
|
3471
3803
|
} catch (err) {
|
|
3472
3804
|
node.innerHTML = `<div class="encore-load-error">Failed to load session replay: ${escapeHtml(err.message || String(err))}</div>`
|
|
3473
3805
|
}
|