@240xu/dsh-message-ops 0.11.8 → 0.13.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 +97 -4
- package/package.json +2 -2
- package/src/client.js +2280 -1017
- package/src/index.js +847 -543
- package/src/ops-core.js +460 -378
- package/src/session-file.js +218 -189
- package/src/session-trash.js +302 -216
package/src/client.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
window.__ModuleLoader__.load({
|
|
8
8
|
id: '@240xu/dsh-message-ops',
|
|
9
|
-
factory:
|
|
9
|
+
factory: require => {
|
|
10
10
|
const React = require('react')
|
|
11
11
|
const { useCallback, useEffect, useRef, useState } = React
|
|
12
12
|
const { Modal } = require('@deepseek-ai/dsh-client-ui-primitives')
|
|
@@ -29,31 +29,43 @@ window.__ModuleLoader__.load({
|
|
|
29
29
|
// 否则「视图重建后重算隐藏」的 1600ms 兜底会被上一次响应吞掉。
|
|
30
30
|
const MSG_COALESCE_MS = 1000
|
|
31
31
|
var __messagesMemo = { url: null, at: 0, p: null, settled: false }
|
|
32
|
-
var invalidateMessagesMemo = () => {
|
|
32
|
+
var invalidateMessagesMemo = () => {
|
|
33
|
+
__messagesMemo = { url: null, at: 0, p: null, settled: false }
|
|
34
|
+
}
|
|
33
35
|
const SYNTHETIC_TURN_STYLE_ID = 'dsh-message-ops-synthetic-turn-hide'
|
|
34
|
-
const syncSyntheticTurnStyle =
|
|
36
|
+
const syncSyntheticTurnStyle = messages => {
|
|
35
37
|
if (typeof document === 'undefined' || !document.head) return
|
|
36
38
|
const turns = new Set()
|
|
37
39
|
for (const m of messages || []) {
|
|
38
40
|
if (m && m.syntheticTurn === true && Number.isSafeInteger(m.turn)) turns.add(m.turn)
|
|
39
41
|
}
|
|
40
42
|
let tag = document.getElementById(SYNTHETIC_TURN_STYLE_ID)
|
|
41
|
-
if (turns.size === 0) {
|
|
43
|
+
if (turns.size === 0) {
|
|
44
|
+
if (tag) tag.remove()
|
|
45
|
+
return
|
|
46
|
+
}
|
|
42
47
|
if (!tag) {
|
|
43
48
|
tag = document.createElement('style')
|
|
44
49
|
tag.id = SYNTHETIC_TURN_STYLE_ID
|
|
45
50
|
document.head.appendChild(tag)
|
|
46
51
|
}
|
|
47
|
-
tag.textContent = Array.from(turns)
|
|
48
|
-
'[data-chat-flow-kind="turn-process"][data-chat-turn="' + turn + '"]{display:none!important}'
|
|
49
|
-
|
|
52
|
+
tag.textContent = Array.from(turns)
|
|
53
|
+
.map(turn => '[data-chat-flow-kind="turn-process"][data-chat-turn="' + turn + '"]{display:none!important}')
|
|
54
|
+
.join('\n')
|
|
50
55
|
}
|
|
51
56
|
const emitChanged = () => {
|
|
52
57
|
// 数据变了:连同本地缓存一起作废(否则 8s TTL 会让 openSession 后的
|
|
53
58
|
// scan 拿旧 payload 重算隐藏 = 「回滚了但界面没变」)。
|
|
54
59
|
invalidateMessagesMemo()
|
|
55
|
-
if (__peekRowsCache) {
|
|
56
|
-
|
|
60
|
+
if (__peekRowsCache) {
|
|
61
|
+
const c = __peekRowsCache()
|
|
62
|
+
if (c) c.at = 0
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
window.dispatchEvent(new CustomEvent(CHANGED_EVENT))
|
|
66
|
+
} catch {
|
|
67
|
+
/* noop */
|
|
68
|
+
}
|
|
57
69
|
}
|
|
58
70
|
const NS = 'dsh-message-ops'
|
|
59
71
|
|
|
@@ -64,7 +76,7 @@ window.__ModuleLoader__.load({
|
|
|
64
76
|
* - 只在 `ok:true` 时才留窗口:失败/非 2xx 立刻作废,免得把后续重试也吃掉;
|
|
65
77
|
* - 1600ms 那档兜底刷新由调用方先 `invalidateMessagesMemo()` 再拉,保证是真网络。
|
|
66
78
|
*/
|
|
67
|
-
var fetchMessagesJson =
|
|
79
|
+
var fetchMessagesJson = rawUrl => {
|
|
68
80
|
// 归一 sessionId 写法:本文件有的调用方传 `session-xxx`(dock / 对话框),
|
|
69
81
|
// 有的传裸 uuid(fetchRows / /redo)。不归一就是两个缓存槽,合并直接失效。
|
|
70
82
|
// 服务端两种写法都认(index.js "uuid or session-<uuid> form")。
|
|
@@ -73,14 +85,22 @@ window.__ModuleLoader__.load({
|
|
|
73
85
|
if (m.url === url && m.p && (!m.settled || Date.now() - m.at < MSG_COALESCE_MS)) return m.p
|
|
74
86
|
const entry = { url, at: Date.now(), p: null, settled: false }
|
|
75
87
|
entry.p = fetch(url)
|
|
76
|
-
.then(
|
|
88
|
+
.then(r =>
|
|
89
|
+
r
|
|
90
|
+
.json()
|
|
91
|
+
.catch(() => null)
|
|
92
|
+
.then(d => ({ r, d })),
|
|
93
|
+
)
|
|
77
94
|
.then(({ r, d }) => {
|
|
78
|
-
if (!r.ok || !d || d.ok !== true) throw new Error((d && d.error) ||
|
|
95
|
+
if (!r.ok || !d || d.ok !== true) throw new Error((d && d.error) || 'HTTP ' + r.status)
|
|
79
96
|
entry.settled = true
|
|
80
97
|
entry.at = Date.now()
|
|
81
98
|
return d
|
|
82
99
|
})
|
|
83
|
-
.catch(
|
|
100
|
+
.catch(e => {
|
|
101
|
+
if (__messagesMemo === entry) invalidateMessagesMemo()
|
|
102
|
+
throw e
|
|
103
|
+
})
|
|
84
104
|
__messagesMemo = entry
|
|
85
105
|
return entry.p
|
|
86
106
|
}
|
|
@@ -113,6 +133,10 @@ window.__ModuleLoader__.load({
|
|
|
113
133
|
'op.branchDesc': '复制所选消息(含)之前的全部事件为新会话(原会话不变,非破坏操作)。',
|
|
114
134
|
'slot.revert': '回滚到此条',
|
|
115
135
|
'slot.revertUnmatched': '在日志里定位不到这条消息的 seq(通常是模型写的摘要与渲染文本偏差过大)——请改用「消息操作」对话框。',
|
|
136
|
+
'slot.fork': '从此条分叉',
|
|
137
|
+
'slot.forkHint': '复制此条之前的对话到新会话,并把此条原文放回新会话输入框',
|
|
138
|
+
'slot.forkDone': '已分叉:新会话 {id}',
|
|
139
|
+
'slot.forkUnavailable': '分叉不可用:会话正在运行,或宿主未提供 session/fork',
|
|
116
140
|
'toast.openNew': '打开新会话',
|
|
117
141
|
'fork.official': '分支完成:新会话 {id}',
|
|
118
142
|
'fork.unavailable': '官方分支不可用:通常是因为会话正在运行,请先停止会话后重试。分支功能由 dsh 内置的 session/fork 提供。',
|
|
@@ -128,7 +152,7 @@ window.__ModuleLoader__.load({
|
|
|
128
152
|
'done.revert': '回滚完成,刷新页面后生效',
|
|
129
153
|
'done.delete': '删除完成,刷新页面后生效',
|
|
130
154
|
'action.reload': '刷新页面',
|
|
131
|
-
|
|
155
|
+
errorPrefix: '操作失败:',
|
|
132
156
|
'dock.title': '已回撤 {n} 条消息',
|
|
133
157
|
'dock.expand': '展开回撤列表',
|
|
134
158
|
'dock.collapse': '折叠回撤列表',
|
|
@@ -179,9 +203,15 @@ window.__ModuleLoader__.load({
|
|
|
179
203
|
'panel.deleteUnavailable': '会话信息尚未就绪,暂不能删除。',
|
|
180
204
|
'panel.delete': '仅删除此条',
|
|
181
205
|
'panel.deleteHint': '只遮蔽这一条,其他消息不动',
|
|
182
|
-
'panel.branch': '
|
|
183
|
-
'panel.branchHint': '
|
|
184
|
-
'panel.branchDone': '
|
|
206
|
+
'panel.branch': '从此条分叉',
|
|
207
|
+
'panel.branchHint': '复制此条之前的对话到新会话,并把此条原文放回新会话输入框',
|
|
208
|
+
'panel.branchDone': '已分叉:新会话 {id}',
|
|
209
|
+
'panel.branchUserOnly': '分叉只对用户消息可用(AI 消息没有可回填的原文)',
|
|
210
|
+
'panel.edit': '编辑并重发',
|
|
211
|
+
'panel.editHint': '把此条原文放回输入框,改完直接发送',
|
|
212
|
+
'panel.editDone': '原文已放回输入框',
|
|
213
|
+
'panel.editEmpty': '这条消息没有可编辑的文本',
|
|
214
|
+
'panel.editUnavailable': '编辑器不可写(会话可能正在运行或尚未挂载)',
|
|
185
215
|
'panel.openNew': '打开新会话',
|
|
186
216
|
'panel.revertDone': '回滚已生效',
|
|
187
217
|
'panel.deleteDone': '删除已生效',
|
|
@@ -220,16 +250,23 @@ window.__ModuleLoader__.load({
|
|
|
220
250
|
'dialog.showMore': 'Show more ({n} older)',
|
|
221
251
|
'dialog.more': '…(showing latest 200 of {n})',
|
|
222
252
|
'op.revert': 'Revert: remove this message and everything after',
|
|
223
|
-
'op.revertDesc':
|
|
253
|
+
'op.revertDesc':
|
|
254
|
+
'Shadows the picked message and all later visible content; the log stays append-only so context can be restored by re-sending.',
|
|
224
255
|
'op.delete': 'Delete only this message',
|
|
225
256
|
'op.deleteDesc': 'Shadows only the picked message; everything else stays.',
|
|
226
257
|
'op.branch': 'Branch into a new session from here',
|
|
227
258
|
'op.branchDesc': 'Copies everything up to and including the picked message into a new session (original untouched, non-destructive).',
|
|
228
259
|
'slot.revert': 'Revert to here',
|
|
229
|
-
'slot.revertUnmatched':
|
|
260
|
+
'slot.revertUnmatched':
|
|
261
|
+
'Cannot locate this message seq in the log (usually the model-written summary drifted too far from the rendered text) — use the Message ops dialog instead.',
|
|
262
|
+
'slot.fork': 'Branch from here',
|
|
263
|
+
'slot.forkHint': 'Copies the conversation above this message into a new session and puts this message back in the new composer',
|
|
264
|
+
'slot.forkDone': 'Branched: new session {id}',
|
|
265
|
+
'slot.forkUnavailable': 'Branch unavailable: the session is running, or the host provides no session/fork',
|
|
230
266
|
'toast.openNew': 'Open new session',
|
|
231
267
|
'fork.official': 'Branched (official fork): new session {id}',
|
|
232
|
-
'fork.unavailable':
|
|
268
|
+
'fork.unavailable':
|
|
269
|
+
'Built-in branch unavailable — usually because the session is running. Stop it and retry. Branching is provided by the dsh built-in session/fork.',
|
|
233
270
|
'ack.revert': 'I understand: revert shadows the picked message and everything after it',
|
|
234
271
|
'ack.delete': 'I understand: this message will be shadowed (kept in the log)',
|
|
235
272
|
'confirm.revert': 'Revert',
|
|
@@ -242,7 +279,7 @@ window.__ModuleLoader__.load({
|
|
|
242
279
|
'done.revert': 'Reverted; reload to apply',
|
|
243
280
|
'done.delete': 'Deleted; reload to apply',
|
|
244
281
|
'action.reload': 'Reload page',
|
|
245
|
-
|
|
282
|
+
errorPrefix: 'Operation failed: ',
|
|
246
283
|
'dock.title': '{n} rolled back messages',
|
|
247
284
|
'dock.expand': 'Expand revert list',
|
|
248
285
|
'dock.collapse': 'Collapse revert list',
|
|
@@ -282,7 +319,8 @@ window.__ModuleLoader__.load({
|
|
|
282
319
|
'panel.revert': 'Revert to here',
|
|
283
320
|
'panel.revertHint': 'Includes this message and all visible messages after it',
|
|
284
321
|
'panel.revertConfirmTitle': 'Revert to #{seq}?',
|
|
285
|
-
'panel.revertConfirmBody':
|
|
322
|
+
'panel.revertConfirmBody':
|
|
323
|
+
'This shadows {n} messages (#{start}–#{end}), including {v} visible. The log stays append-only and can be restored.',
|
|
286
324
|
'panel.deleteConfirmTitle': 'Delete only #{seq}?',
|
|
287
325
|
'panel.deleteConfirmBody': 'This shadows this one message; everything else stays. The log stays append-only and can be restored.',
|
|
288
326
|
'panel.confirmRevert': 'Confirm revert',
|
|
@@ -293,9 +331,15 @@ window.__ModuleLoader__.load({
|
|
|
293
331
|
'panel.deleteUnavailable': 'Session details are not ready yet; deletion is disabled.',
|
|
294
332
|
'panel.delete': 'Delete only this',
|
|
295
333
|
'panel.deleteHint': 'Shadows only this message',
|
|
296
|
-
'panel.branch': '
|
|
297
|
-
'panel.branchHint': 'Copy
|
|
298
|
-
'panel.branchDone': '
|
|
334
|
+
'panel.branch': 'Fork from here',
|
|
335
|
+
'panel.branchHint': 'Copy the conversation above this message into a new session and put this message back in the new composer',
|
|
336
|
+
'panel.branchDone': 'Forked: {id}',
|
|
337
|
+
'panel.branchUserOnly': 'Fork works on user messages only (assistant messages have no text to hand back)',
|
|
338
|
+
'panel.edit': 'Edit and resend',
|
|
339
|
+
'panel.editHint': 'Put this message back in the composer to change and send',
|
|
340
|
+
'panel.editDone': 'Original text is back in the composer',
|
|
341
|
+
'panel.editEmpty': 'This message has no editable text',
|
|
342
|
+
'panel.editUnavailable': 'Composer is not writable (session may be running or not mounted)',
|
|
299
343
|
'panel.openNew': 'Open new session',
|
|
300
344
|
'panel.revertDone': 'Revert applied',
|
|
301
345
|
'panel.deleteDone': 'Delete applied',
|
|
@@ -331,7 +375,7 @@ window.__ModuleLoader__.load({
|
|
|
331
375
|
// 0.9.3:注入器闭包内 rowsCache 的只读出口。
|
|
332
376
|
// rowsCache 声明在 installUserRevertInjector() 内(闭包私有),而 /undo 的
|
|
333
377
|
// onPick 在模块级作用域 —— 直接引用会 ReferenceError,表现为点菜单毫无反应。
|
|
334
|
-
var __peekRowsCache = null
|
|
378
|
+
var __peekRowsCache = null // 0.6.0:会话视图会话 id(RevertDock/MsgSlotActions 刷新)
|
|
335
379
|
// messageId→seq 索引缓存(每会话一次拉取;0.3.0 assistant-actions 槽用)
|
|
336
380
|
var __seqIndexCache = new Map()
|
|
337
381
|
// messageId→全文缓存(0.5.0 消息引用用)
|
|
@@ -340,7 +384,9 @@ window.__ModuleLoader__.load({
|
|
|
340
384
|
function localeFallbackLang() {
|
|
341
385
|
if (typeof navigator === 'undefined') return 'zh'
|
|
342
386
|
for (const tag of (navigator.languages || []).concat([navigator.language])) {
|
|
343
|
-
const primary = String(tag || '')
|
|
387
|
+
const primary = String(tag || '')
|
|
388
|
+
.toLowerCase()
|
|
389
|
+
.split('-')[0]
|
|
344
390
|
if (primary === 'zh' || primary === 'en') return primary
|
|
345
391
|
}
|
|
346
392
|
return 'zh'
|
|
@@ -363,65 +409,110 @@ window.__ModuleLoader__.load({
|
|
|
363
409
|
const [, setRev] = useState(0)
|
|
364
410
|
useEffect(() => {
|
|
365
411
|
if (!__locale || typeof __locale.subscribe !== 'function') return undefined
|
|
366
|
-
return __locale.subscribe(() => setRev(
|
|
412
|
+
return __locale.subscribe(() => setRev(v => v + 1))
|
|
367
413
|
}, [])
|
|
368
414
|
}
|
|
369
415
|
|
|
370
416
|
// --- styles(仅 --dsw-* 主题令牌) ----------------------------------------
|
|
371
417
|
const btnStyle = {
|
|
372
|
-
display: 'inline-flex',
|
|
373
|
-
|
|
418
|
+
display: 'inline-flex',
|
|
419
|
+
alignItems: 'center',
|
|
420
|
+
justifyContent: 'center',
|
|
421
|
+
width: 28,
|
|
422
|
+
height: 28,
|
|
423
|
+
padding: 0,
|
|
424
|
+
border: 'none',
|
|
425
|
+
borderRadius: 6,
|
|
374
426
|
background: 'transparent',
|
|
375
|
-
color: 'var(--dsw-alias-label-tertiary, #8a8a8e)',
|
|
427
|
+
color: 'var(--dsw-alias-label-tertiary, #8a8a8e)',
|
|
428
|
+
cursor: 'pointer',
|
|
429
|
+
flex: 'none',
|
|
376
430
|
}
|
|
377
431
|
const metaStyle = {
|
|
378
|
-
color: 'var(--dsw-alias-label-secondary, #8a8a8e)',
|
|
379
|
-
|
|
432
|
+
color: 'var(--dsw-alias-label-secondary, #8a8a8e)',
|
|
433
|
+
fontSize: 13,
|
|
434
|
+
lineHeight: '20px',
|
|
435
|
+
margin: '0 0 8px',
|
|
436
|
+
overflow: 'hidden',
|
|
437
|
+
textOverflow: 'ellipsis',
|
|
380
438
|
}
|
|
381
439
|
const warnStyle = {
|
|
382
|
-
color: 'var(--dsw-alias-state-warn-primary, #f5a524)',
|
|
383
|
-
|
|
440
|
+
color: 'var(--dsw-alias-state-warn-primary, #f5a524)',
|
|
441
|
+
fontSize: 13,
|
|
442
|
+
lineHeight: '20px',
|
|
443
|
+
margin: '0 0 10px',
|
|
384
444
|
}
|
|
385
445
|
const errStyle = {
|
|
386
|
-
color: 'var(--dsw-alias-state-error-primary, #e5484d)',
|
|
387
|
-
|
|
446
|
+
color: 'var(--dsw-alias-state-error-primary, #e5484d)',
|
|
447
|
+
fontSize: 12,
|
|
448
|
+
lineHeight: '16px',
|
|
449
|
+
marginTop: 8,
|
|
388
450
|
}
|
|
389
451
|
const statusStyle = {
|
|
390
|
-
color: 'var(--dsw-alias-label-secondary, #8a8a8e)',
|
|
391
|
-
|
|
452
|
+
color: 'var(--dsw-alias-label-secondary, #8a8a8e)',
|
|
453
|
+
fontSize: 12,
|
|
454
|
+
lineHeight: '16px',
|
|
455
|
+
marginTop: 8,
|
|
392
456
|
}
|
|
393
457
|
const listStyle = {
|
|
394
|
-
maxHeight: 260,
|
|
395
|
-
|
|
458
|
+
maxHeight: 260,
|
|
459
|
+
overflowY: 'auto',
|
|
460
|
+
border: '1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.35))',
|
|
461
|
+
borderRadius: 8,
|
|
462
|
+
margin: '8px 0 4px',
|
|
463
|
+
padding: '4px 0',
|
|
396
464
|
}
|
|
397
465
|
const rowStyle = {
|
|
398
|
-
display: 'flex',
|
|
399
|
-
|
|
466
|
+
display: 'flex',
|
|
467
|
+
alignItems: 'flex-start',
|
|
468
|
+
gap: 8,
|
|
469
|
+
padding: '4px 10px',
|
|
470
|
+
fontSize: 13,
|
|
471
|
+
lineHeight: '18px',
|
|
472
|
+
cursor: 'pointer',
|
|
400
473
|
}
|
|
401
474
|
const descStyle = {
|
|
402
|
-
color: 'var(--dsw-alias-label-secondary, #8a8a8e)',
|
|
403
|
-
|
|
475
|
+
color: 'var(--dsw-alias-label-secondary, #8a8a8e)',
|
|
476
|
+
fontSize: 12,
|
|
477
|
+
lineHeight: '17px',
|
|
478
|
+
margin: '6px 0 0',
|
|
404
479
|
}
|
|
405
480
|
const cancelBtnStyle = {
|
|
406
|
-
padding: '6px 14px',
|
|
481
|
+
padding: '6px 14px',
|
|
482
|
+
borderRadius: 8,
|
|
407
483
|
border: '1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.4))',
|
|
408
|
-
background: 'transparent',
|
|
409
|
-
|
|
484
|
+
background: 'transparent',
|
|
485
|
+
color: 'var(--dsw-alias-label-primary, inherit)',
|
|
486
|
+
fontSize: 13,
|
|
487
|
+
cursor: 'pointer',
|
|
488
|
+
marginRight: 8,
|
|
410
489
|
}
|
|
411
490
|
const primaryBtnStyle = {
|
|
412
|
-
padding: '6px 14px',
|
|
413
|
-
|
|
414
|
-
|
|
491
|
+
padding: '6px 14px',
|
|
492
|
+
borderRadius: 8,
|
|
493
|
+
border: 'none',
|
|
494
|
+
background: 'var(--dsw-alias-brand-primary, #4d6bfe)',
|
|
495
|
+
color: '#fff',
|
|
496
|
+
fontSize: 13,
|
|
497
|
+
cursor: 'pointer',
|
|
415
498
|
}
|
|
416
499
|
const dangerBtnStyle = {
|
|
417
|
-
padding: '6px 14px',
|
|
500
|
+
padding: '6px 14px',
|
|
501
|
+
borderRadius: 8,
|
|
418
502
|
border: '1px solid var(--dsw-alias-state-error-primary, #e5484d)',
|
|
419
503
|
background: 'var(--dsw-alias-state-error-primary, #e5484d)',
|
|
420
|
-
color: '#fff',
|
|
504
|
+
color: '#fff',
|
|
505
|
+
fontSize: 13,
|
|
506
|
+
cursor: 'pointer',
|
|
421
507
|
}
|
|
422
508
|
const optStyle = {
|
|
423
|
-
display: 'flex',
|
|
424
|
-
|
|
509
|
+
display: 'flex',
|
|
510
|
+
alignItems: 'center',
|
|
511
|
+
gap: 8,
|
|
512
|
+
fontSize: 13,
|
|
513
|
+
lineHeight: '20px',
|
|
514
|
+
color: 'var(--dsw-alias-label-primary, inherit)',
|
|
515
|
+
marginTop: 10,
|
|
425
516
|
}
|
|
426
517
|
|
|
427
518
|
// 头部按钮图标:三叉分支(git-branch 风格,16x16)。
|
|
@@ -431,47 +522,68 @@ window.__ModuleLoader__.load({
|
|
|
431
522
|
// 「那个 svg 渲染有问题」)。必须 stroke + round cap/join。
|
|
432
523
|
// 唯一数据源:所有图标入口(React 组件 / innerHTML 字符串)都从这里取,
|
|
433
524
|
// 以免再次出现「一处改名、另一处仍用旧名 → d="undefined"」的回归。
|
|
434
|
-
const BRANCH_PATH =
|
|
525
|
+
const BRANCH_PATH =
|
|
526
|
+
'M5 2.5a2 2 0 1 1-.9 3.78v3.44a2 2 0 1 1-1.2 0V6.28A2 2 0 1 1 5 2.5Zm0 1.2a.8.8 0 1 0 0 1.6.8.8 0 0 0 0-1.6ZM3.5 11.5a.8.8 0 1 0 1.6 0 .8.8 0 0 0-1.6 0ZM12.5 2.5a2 2 0 0 1 .6 3.9v.85c0 1.9-1.54 3.44-3.44 3.44H8.03a2 2 0 1 1 0-1.2h1.63a2.24 2.24 0 0 0 2.24-2.24V6.4a2 2 0 0 1 .6-3.9Zm0 1.2a.8.8 0 1 0 0 1.6.8.8 0 0 0 0-1.6Z'
|
|
435
527
|
const BRANCH_STROKE = 1.4
|
|
436
528
|
|
|
437
529
|
/** 生成分支图标的 SVG 标记(供 innerHTML 场景复用)。 */
|
|
438
530
|
function branchIconMarkup(size) {
|
|
439
531
|
const px = size || 16
|
|
440
|
-
return
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
+
|
|
532
|
+
return (
|
|
533
|
+
'<svg width="' +
|
|
534
|
+
px +
|
|
535
|
+
'" height="' +
|
|
536
|
+
px +
|
|
537
|
+
'" viewBox="0 0 16 16" fill="none"' +
|
|
538
|
+
' xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"' +
|
|
539
|
+
' style="flex:none"><path d="' +
|
|
540
|
+
BRANCH_PATH +
|
|
541
|
+
'" fill="none"' +
|
|
542
|
+
' stroke="currentColor" stroke-width="' +
|
|
543
|
+
BRANCH_STROKE +
|
|
544
|
+
'"' +
|
|
545
|
+
' stroke-linecap="round" stroke-linejoin="round"/></svg>'
|
|
546
|
+
)
|
|
445
547
|
}
|
|
446
548
|
|
|
447
549
|
function BranchIcon() {
|
|
448
|
-
return React.createElement(
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
550
|
+
return React.createElement(
|
|
551
|
+
'svg',
|
|
552
|
+
{
|
|
553
|
+
width: 16,
|
|
554
|
+
height: 16,
|
|
555
|
+
viewBox: '0 0 16 16',
|
|
556
|
+
fill: 'none',
|
|
557
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
558
|
+
'aria-hidden': 'true',
|
|
559
|
+
focusable: 'false',
|
|
560
|
+
},
|
|
561
|
+
React.createElement('path', {
|
|
562
|
+
d: BRANCH_PATH,
|
|
563
|
+
stroke: 'currentColor',
|
|
564
|
+
strokeWidth: BRANCH_STROKE,
|
|
565
|
+
strokeLinecap: 'round',
|
|
566
|
+
strokeLinejoin: 'round',
|
|
567
|
+
fill: 'none',
|
|
568
|
+
}),
|
|
569
|
+
)
|
|
458
570
|
}
|
|
459
571
|
|
|
460
572
|
// --- 共享对话框 -------------------------------------------------------------
|
|
461
573
|
// 模块级缓存最近一次 target,事件驱动打开。
|
|
462
574
|
const MAX_RENDER = 200
|
|
463
|
-
const PAGE_SIZE = 50
|
|
575
|
+
const PAGE_SIZE = 50 // 低成本分批渲染:先渲 50 条,按钮渐进展开
|
|
464
576
|
|
|
465
577
|
function OpsDialog(props) {
|
|
466
578
|
const t = (props && props.t) || __t
|
|
467
579
|
useLocaleRevision()
|
|
468
|
-
const [target, setTarget] = useState(null)
|
|
469
|
-
const [state, setState] = useState('idle')
|
|
580
|
+
const [target, setTarget] = useState(null) // {sessionId, title, running}
|
|
581
|
+
const [state, setState] = useState('idle') // idle|loading|ready|busy|done
|
|
470
582
|
const [messages, setMessages] = useState([])
|
|
471
583
|
const [sessionMeta, setSessionMeta] = useState(null)
|
|
472
|
-
const [picked, setPicked] = useState(null)
|
|
473
|
-
const [mode, setMode] = useState(null)
|
|
474
|
-
const [childId, setChildId] = useState(null)
|
|
584
|
+
const [picked, setPicked] = useState(null) // seq
|
|
585
|
+
const [mode, setMode] = useState(null) // revert|delete|branch|restore
|
|
586
|
+
const [childId, setChildId] = useState(null) // 官方 fork 成功后的子会话 id
|
|
475
587
|
const [acknowledged, setAcknowledged] = useState(false)
|
|
476
588
|
const [busyMsg, setBusyMsg] = useState('')
|
|
477
589
|
const [renderLimit, setRenderLimit] = useState(PAGE_SIZE) // 已展开的渲染条数
|
|
@@ -479,15 +591,18 @@ window.__ModuleLoader__.load({
|
|
|
479
591
|
const [error, setError] = useState(null)
|
|
480
592
|
|
|
481
593
|
useEffect(() => {
|
|
482
|
-
const handler =
|
|
594
|
+
const handler = e => {
|
|
483
595
|
const d = e && e.detail ? e.detail : {}
|
|
484
596
|
setTarget({ sessionId: d.sessionId || null, title: d.title || null, running: d.running === true })
|
|
485
597
|
setState('loading')
|
|
486
|
-
setMessages([])
|
|
598
|
+
setMessages([])
|
|
599
|
+
setSessionMeta(null)
|
|
487
600
|
// 槽按钮预置:携带 seq(picked)与 mode 直接进入确认态
|
|
488
601
|
setPicked(typeof d.seq === 'number' ? d.seq : null)
|
|
489
602
|
setMode(typeof d.mode === 'string' ? d.mode : null)
|
|
490
|
-
setAcknowledged(false)
|
|
603
|
+
setAcknowledged(false)
|
|
604
|
+
setError(null)
|
|
605
|
+
setDoneMsg('')
|
|
491
606
|
setRenderLimit(PAGE_SIZE)
|
|
492
607
|
}
|
|
493
608
|
window.addEventListener(EVENT, handler)
|
|
@@ -498,62 +613,80 @@ window.__ModuleLoader__.load({
|
|
|
498
613
|
if (state !== 'loading' || !target || !target.sessionId) return
|
|
499
614
|
let cancelled = false
|
|
500
615
|
fetchMessagesJson('/api/message-ops/messages?sessionId=' + encodeURIComponent(target.sessionId))
|
|
501
|
-
.then(
|
|
616
|
+
.then(data => {
|
|
502
617
|
if (cancelled) return
|
|
503
618
|
if (!data || !data.ok) throw new Error(data && data.error ? data.error : `HTTP ${data && data.status}`)
|
|
504
619
|
setMessages(data.messages || [])
|
|
505
620
|
setSessionMeta(data.session || null)
|
|
506
|
-
if (data.running === true) setTarget(
|
|
621
|
+
if (data.running === true) setTarget(prev => ({ ...(prev || {}), running: true }))
|
|
507
622
|
setState('ready')
|
|
508
623
|
})
|
|
509
|
-
.catch(
|
|
624
|
+
.catch(reason => {
|
|
510
625
|
if (cancelled) return
|
|
511
626
|
setError(t('dialog.loadFail') + (reason && reason.message ? reason.message : String(reason)))
|
|
512
627
|
setState('ready')
|
|
513
628
|
})
|
|
514
|
-
return () => {
|
|
629
|
+
return () => {
|
|
630
|
+
cancelled = true
|
|
631
|
+
}
|
|
515
632
|
}, [state, target, t])
|
|
516
633
|
|
|
517
634
|
const close = useCallback(() => {
|
|
518
635
|
if (state === 'busy') return
|
|
519
|
-
setTarget(null)
|
|
636
|
+
setTarget(null)
|
|
637
|
+
setError(null)
|
|
520
638
|
}, [state])
|
|
521
639
|
|
|
522
|
-
const pick = useCallback(
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
640
|
+
const pick = useCallback(
|
|
641
|
+
m => {
|
|
642
|
+
if (state === 'busy') return
|
|
643
|
+
setPicked(m.seq)
|
|
644
|
+
setMode(null)
|
|
645
|
+
setAcknowledged(false)
|
|
646
|
+
setError(null)
|
|
647
|
+
},
|
|
648
|
+
[state],
|
|
649
|
+
)
|
|
527
650
|
|
|
528
|
-
const chooseMode = useCallback(
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
651
|
+
const chooseMode = useCallback(
|
|
652
|
+
m => {
|
|
653
|
+
if (picked == null || state === 'busy') return
|
|
654
|
+
setMode(m)
|
|
655
|
+
setAcknowledged(false)
|
|
656
|
+
setError(null)
|
|
657
|
+
},
|
|
658
|
+
[picked, state],
|
|
659
|
+
)
|
|
532
660
|
|
|
533
661
|
const run = useCallback(() => {
|
|
534
662
|
if (state === 'busy' || picked == null || !mode) return
|
|
535
663
|
if (mode !== 'branch' && !acknowledged) return
|
|
536
664
|
setBusyMsg(t('busy.' + (mode === 'revert' || mode === 'delete' ? mode : 'branch')))
|
|
537
|
-
setState('busy')
|
|
665
|
+
setState('busy')
|
|
666
|
+
setError(null)
|
|
538
667
|
if (mode === 'branch') {
|
|
539
|
-
// 0.
|
|
540
|
-
//
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
668
|
+
// 0.12.0:与面板/消息行同一实现 —— opencode 的 before 语义
|
|
669
|
+
// (新会话不含此条,原文回新会话输入框)。只对用户消息成立;
|
|
670
|
+
// 分支不再回落写盘(被删的磁盘 applyBranch 语义复盘见 README)。
|
|
671
|
+
const pickedRow = picked != null ? messages.find(m => m.seq === picked) : null
|
|
672
|
+
if (!pickedRow || pickedRow.role !== 'user') {
|
|
673
|
+
setError(t('panel.branchUserOnly'))
|
|
544
674
|
setBusyMsg('')
|
|
545
675
|
setState('error')
|
|
546
676
|
return
|
|
547
677
|
}
|
|
548
|
-
|
|
549
|
-
.then((
|
|
678
|
+
Promise.resolve()
|
|
679
|
+
.then(() =>
|
|
680
|
+
forkFromUserMessage(target.sessionId, picked, pickedRow.fullText || pickedRow.snippet || '', pickedRow.turnStartSeq),
|
|
681
|
+
)
|
|
682
|
+
.then(childId => {
|
|
550
683
|
setDoneMsg(t('fork.official', { id: String(childId || '') }))
|
|
551
684
|
setBusyMsg('')
|
|
552
685
|
setChildId(childId || null)
|
|
553
686
|
setState('done')
|
|
554
687
|
notifyDone(t('fork.official', { id: String(childId || '') }))
|
|
555
688
|
})
|
|
556
|
-
.catch(
|
|
689
|
+
.catch(reason => {
|
|
557
690
|
setError(String((reason && reason.message) || reason || t('fork.unavailable')))
|
|
558
691
|
setBusyMsg('')
|
|
559
692
|
setState('error')
|
|
@@ -563,14 +696,20 @@ window.__ModuleLoader__.load({
|
|
|
563
696
|
const path = mode
|
|
564
697
|
const body = { sessionId: target.sessionId, seq: picked }
|
|
565
698
|
Promise.resolve()
|
|
566
|
-
.then(() =>
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
699
|
+
.then(() =>
|
|
700
|
+
fetch('/api/message-ops/' + path, {
|
|
701
|
+
method: 'POST',
|
|
702
|
+
headers: { 'content-type': 'application/json' },
|
|
703
|
+
body: JSON.stringify(body),
|
|
704
|
+
}),
|
|
705
|
+
)
|
|
706
|
+
.then(async res => {
|
|
572
707
|
let data = {}
|
|
573
|
-
try {
|
|
708
|
+
try {
|
|
709
|
+
data = await res.json()
|
|
710
|
+
} catch {
|
|
711
|
+
/* keep {} */
|
|
712
|
+
}
|
|
574
713
|
if (!res.ok || !data.ok) throw new Error(data.error || `HTTP ${res.status}`)
|
|
575
714
|
// S6 修复(G-M1):不再 900ms 裸 location.reload。成功走 devkit
|
|
576
715
|
// 标准 toast(无 devkit 时降级为对话框内 doneMsg),并提供手动
|
|
@@ -590,7 +729,9 @@ window.__ModuleLoader__.load({
|
|
|
590
729
|
__inputActions.setDraft(pickedMsg.fullText)
|
|
591
730
|
if (typeof __inputActions.persistDraft === 'function') __inputActions.persistDraft()
|
|
592
731
|
}
|
|
593
|
-
} catch (e) {
|
|
732
|
+
} catch (e) {
|
|
733
|
+
console.warn('[message-ops] refill failed:', e)
|
|
734
|
+
}
|
|
594
735
|
}
|
|
595
736
|
setDoneMsg(okMsg)
|
|
596
737
|
setBusyMsg('')
|
|
@@ -601,9 +742,11 @@ window.__ModuleLoader__.load({
|
|
|
601
742
|
// 重建视图(与 restoreRow 同款 openSession 模式),遮蔽即刻可见。
|
|
602
743
|
try {
|
|
603
744
|
if (__uiWorkspace && typeof __uiWorkspace.openSession === 'function') __uiWorkspace.openSession(target.sessionId)
|
|
604
|
-
} catch {
|
|
745
|
+
} catch {
|
|
746
|
+
/* 视图重建失败不阻断成功反馈 */
|
|
747
|
+
}
|
|
605
748
|
})
|
|
606
|
-
.catch(
|
|
749
|
+
.catch(reason => {
|
|
607
750
|
setBusyMsg('')
|
|
608
751
|
setState('ready')
|
|
609
752
|
setError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
|
|
@@ -614,43 +757,75 @@ window.__ModuleLoader__.load({
|
|
|
614
757
|
|
|
615
758
|
// 0.6.0:system prompt 行不可作为回滚/删除/分支目标(引擎拒之以 node0 守卫,
|
|
616
759
|
// 但不该给用户一个必然500的选项)——列表直接排除 role=system。
|
|
617
|
-
const visible = messages.filter(
|
|
760
|
+
const visible = messages.filter(m => m.visible !== false && m.role !== 'system')
|
|
618
761
|
const shownBase = visible.slice(-MAX_RENDER)
|
|
619
762
|
const hiddenCount = visible.length - shownBase.length
|
|
620
763
|
// 分批渲染(评审 M1):只渲染 renderLimit 条,更早的留给「显示更多」
|
|
621
764
|
// 渐进展开,避免 200 行 radio 列表一次进 DOM。
|
|
622
765
|
const shown = shownBase.slice(-renderLimit)
|
|
623
766
|
const pagedCount = shownBase.length - shown.length
|
|
624
|
-
const pickedMsg = picked != null ? messages.find(
|
|
767
|
+
const pickedMsg = picked != null ? messages.find(m => m.seq === picked) : null
|
|
625
768
|
|
|
626
769
|
// 0.9.0 可发现性:操作区固定在**消息列表之前**。
|
|
627
770
|
// 原先它在列表之后,而列表是 260px 滚动 + 分批渲染 50 条/页 ——
|
|
628
771
|
// 未选中消息时三个 radio 完全不在视野内,用户以为「只有列表、没有操作」。
|
|
629
772
|
// 未选中时给明确指引,而不是空着。
|
|
630
773
|
const opsPanel = pickedMsg
|
|
631
|
-
? React.createElement(
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
774
|
+
? React.createElement(
|
|
775
|
+
'div',
|
|
776
|
+
{ key: 'ops', style: { margin: '8px 0 0' } },
|
|
777
|
+
React.createElement(
|
|
778
|
+
'div',
|
|
779
|
+
{ style: { ...metaStyle, margin: '0 0 4px' } },
|
|
780
|
+
t('dialog.pickedAs', { seq: String(pickedMsg.seq), text: (pickedMsg.snippet || '').slice(0, 60) }),
|
|
781
|
+
),
|
|
782
|
+
['revert', 'delete', 'branch'].map((m, i) =>
|
|
783
|
+
React.createElement(
|
|
784
|
+
'div',
|
|
785
|
+
{ key: m, style: { marginTop: i === 0 ? 6 : 4 } },
|
|
786
|
+
React.createElement(
|
|
787
|
+
'label',
|
|
788
|
+
{ style: optStyle },
|
|
789
|
+
React.createElement('input', {
|
|
790
|
+
type: 'radio',
|
|
791
|
+
name: 'dsh-message-ops-mode',
|
|
792
|
+
checked: mode === m,
|
|
793
|
+
onChange: () => chooseMode(m),
|
|
794
|
+
disabled: state === 'busy',
|
|
795
|
+
}),
|
|
796
|
+
t('op.' + m),
|
|
797
|
+
),
|
|
798
|
+
mode === m ? React.createElement('div', { style: descStyle }, t('op.' + m + 'Desc')) : null,
|
|
799
|
+
),
|
|
800
|
+
),
|
|
643
801
|
mode && mode !== 'branch'
|
|
644
|
-
? React.createElement(
|
|
802
|
+
? React.createElement(
|
|
803
|
+
'label',
|
|
804
|
+
{ key: 'ack', style: optStyle },
|
|
645
805
|
React.createElement('input', {
|
|
646
|
-
type: 'checkbox',
|
|
647
|
-
|
|
806
|
+
type: 'checkbox',
|
|
807
|
+
checked: acknowledged,
|
|
808
|
+
disabled: state === 'busy',
|
|
809
|
+
onChange: e => setAcknowledged(e.target.checked),
|
|
648
810
|
}),
|
|
649
|
-
t(mode === 'revert' ? 'ack.revert' : 'ack.delete')
|
|
811
|
+
t(mode === 'revert' ? 'ack.revert' : 'ack.delete'),
|
|
812
|
+
)
|
|
650
813
|
: null,
|
|
651
814
|
)
|
|
652
|
-
: React.createElement(
|
|
653
|
-
|
|
815
|
+
: React.createElement(
|
|
816
|
+
'div',
|
|
817
|
+
{
|
|
818
|
+
key: 'opshint',
|
|
819
|
+
style: {
|
|
820
|
+
...metaStyle,
|
|
821
|
+
margin: '8px 0 0',
|
|
822
|
+
padding: '6px 8px',
|
|
823
|
+
borderRadius: 6,
|
|
824
|
+
background: 'var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.1))',
|
|
825
|
+
},
|
|
826
|
+
},
|
|
827
|
+
t('dialog.pickFirst'),
|
|
828
|
+
)
|
|
654
829
|
|
|
655
830
|
let body
|
|
656
831
|
if (state === 'loading') {
|
|
@@ -662,36 +837,67 @@ window.__ModuleLoader__.load({
|
|
|
662
837
|
target.running ? React.createElement('div', { key: 'warn', style: warnStyle }, t('dialog.runningWarn')) : null,
|
|
663
838
|
opsPanel,
|
|
664
839
|
React.createElement('div', { key: 'pick', style: metaStyle }, t('dialog.pick')),
|
|
665
|
-
React.createElement(
|
|
840
|
+
React.createElement(
|
|
841
|
+
'div',
|
|
842
|
+
{ key: 'list', style: listStyle },
|
|
666
843
|
hiddenCount > 0
|
|
667
|
-
? React.createElement(
|
|
668
|
-
|
|
844
|
+
? React.createElement(
|
|
845
|
+
'div',
|
|
846
|
+
{ key: 'more', style: { ...rowStyle, cursor: 'default', color: 'var(--dsw-alias-label-secondary,#8a8a8e)' } },
|
|
847
|
+
t('dialog.more', { n: String(visible.length) }),
|
|
848
|
+
)
|
|
669
849
|
: null,
|
|
670
850
|
pagedCount > 0
|
|
671
|
-
? React.createElement(
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
851
|
+
? React.createElement(
|
|
852
|
+
'button',
|
|
853
|
+
{
|
|
854
|
+
key: 'show-more',
|
|
855
|
+
type: 'button',
|
|
856
|
+
style: {
|
|
857
|
+
...rowStyle,
|
|
858
|
+
border: 'none',
|
|
859
|
+
width: '100%',
|
|
860
|
+
color: 'var(--dsw-alias-label-secondary,#8a8a8e)',
|
|
861
|
+
cursor: 'pointer',
|
|
862
|
+
},
|
|
863
|
+
onClick: () => setRenderLimit(l => Math.min(l + PAGE_SIZE, MAX_RENDER)),
|
|
864
|
+
},
|
|
865
|
+
t('dialog.showMore', { n: String(pagedCount) }),
|
|
866
|
+
)
|
|
676
867
|
: null,
|
|
677
|
-
shown.map((m, i) =>
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
}),
|
|
687
|
-
React.createElement('span', {
|
|
688
|
-
style: {
|
|
689
|
-
flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
|
|
690
|
-
color: m.visible === false ? 'var(--dsw-alias-label-tertiary,#b0b0b4)' : 'inherit',
|
|
868
|
+
shown.map((m, i) =>
|
|
869
|
+
React.createElement(
|
|
870
|
+
'label',
|
|
871
|
+
{
|
|
872
|
+
key: m.seq + '-' + i,
|
|
873
|
+
style: {
|
|
874
|
+
...rowStyle,
|
|
875
|
+
background: picked === m.seq ? 'var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.14))' : 'transparent',
|
|
876
|
+
},
|
|
691
877
|
},
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
878
|
+
React.createElement('input', {
|
|
879
|
+
type: 'radio',
|
|
880
|
+
name: 'dsh-message-ops-pick',
|
|
881
|
+
checked: picked === m.seq,
|
|
882
|
+
onChange: () => pick(m),
|
|
883
|
+
disabled: state === 'busy',
|
|
884
|
+
}),
|
|
885
|
+
React.createElement(
|
|
886
|
+
'span',
|
|
887
|
+
{
|
|
888
|
+
style: {
|
|
889
|
+
flex: 1,
|
|
890
|
+
minWidth: 0,
|
|
891
|
+
overflow: 'hidden',
|
|
892
|
+
textOverflow: 'ellipsis',
|
|
893
|
+
whiteSpace: 'nowrap',
|
|
894
|
+
color: m.visible === false ? 'var(--dsw-alias-label-tertiary,#b0b0b4)' : 'inherit',
|
|
895
|
+
},
|
|
896
|
+
},
|
|
897
|
+
'#' + m.seq + ' ' + (m.role || '') + ' · ' + (m.snippet || '') + (m.visible === false ? t('dialog.invisible') : ''),
|
|
898
|
+
),
|
|
899
|
+
),
|
|
900
|
+
),
|
|
695
901
|
),
|
|
696
902
|
// 0.9.7:删掉列表**之后**的旧 opsPanel——0.9.0 把操作区挪到列表之前时
|
|
697
903
|
// 没删旧位置,两组同名 radio(name='dsh-message-ops-mode')互抢,
|
|
@@ -699,52 +905,93 @@ window.__ModuleLoader__.load({
|
|
|
699
905
|
])
|
|
700
906
|
}
|
|
701
907
|
|
|
702
|
-
const canRun = state !== 'busy' && state !== 'loading' && picked != null && mode != null
|
|
703
|
-
&& (mode === 'branch' || acknowledged)
|
|
908
|
+
const canRun = state !== 'busy' && state !== 'loading' && picked != null && mode != null && (mode === 'branch' || acknowledged)
|
|
704
909
|
const confirmLabel = busyMsg || (mode ? t('confirm.' + mode) : t('dialog.cancel'))
|
|
705
910
|
|
|
706
|
-
return React.createElement(
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
911
|
+
return React.createElement(
|
|
912
|
+
Modal,
|
|
913
|
+
{
|
|
914
|
+
open: true,
|
|
915
|
+
onClose: close,
|
|
916
|
+
title: t('dialog.title'),
|
|
917
|
+
closeLabel: t('dialog.cancel'),
|
|
918
|
+
description: t('dialog.session') + (target.title || target.sessionId || ''),
|
|
919
|
+
footer: [
|
|
920
|
+
React.createElement(
|
|
921
|
+
'button',
|
|
922
|
+
{
|
|
923
|
+
key: 'cancel',
|
|
924
|
+
type: 'button',
|
|
925
|
+
disabled: state === 'busy',
|
|
926
|
+
onClick: close,
|
|
927
|
+
style: { ...cancelBtnStyle, ...(state === 'busy' ? { opacity: 0.5, cursor: 'default' } : {}) },
|
|
928
|
+
},
|
|
929
|
+
t('dialog.cancel'),
|
|
930
|
+
),
|
|
931
|
+
React.createElement(
|
|
932
|
+
'button',
|
|
933
|
+
{
|
|
934
|
+
key: 'confirm',
|
|
935
|
+
type: 'button',
|
|
936
|
+
disabled: !canRun,
|
|
937
|
+
onClick: run,
|
|
938
|
+
style: {
|
|
939
|
+
...(mode === 'delete' || mode === 'revert' ? dangerBtnStyle : primaryBtnStyle),
|
|
940
|
+
...(!canRun ? { opacity: 0.5, cursor: 'default' } : {}),
|
|
941
|
+
},
|
|
942
|
+
},
|
|
943
|
+
confirmLabel,
|
|
944
|
+
),
|
|
945
|
+
...(state === 'done' && (mode === 'revert' || mode === 'delete')
|
|
946
|
+
? [
|
|
947
|
+
React.createElement(
|
|
948
|
+
'button',
|
|
949
|
+
{
|
|
950
|
+
key: 'reload',
|
|
951
|
+
type: 'button',
|
|
952
|
+
onClick: () => {
|
|
953
|
+
try {
|
|
954
|
+
window.location.reload()
|
|
955
|
+
} catch {
|
|
956
|
+
/* non-browser guard */
|
|
957
|
+
}
|
|
958
|
+
},
|
|
959
|
+
style: primaryBtnStyle,
|
|
960
|
+
},
|
|
961
|
+
t('action.reload'),
|
|
962
|
+
),
|
|
963
|
+
]
|
|
964
|
+
: []),
|
|
965
|
+
...(state === 'done' && mode === 'branch' && childId
|
|
966
|
+
? [
|
|
967
|
+
React.createElement(
|
|
968
|
+
'button',
|
|
969
|
+
{
|
|
970
|
+
key: 'open-new',
|
|
971
|
+
type: 'button',
|
|
972
|
+
onClick: () => {
|
|
973
|
+
try {
|
|
974
|
+
// 0.2.0+:uiWorkspace.openSession 是宿主唯一打开通道
|
|
975
|
+
if (__uiWorkspace && typeof __uiWorkspace.openSession === 'function') __uiWorkspace.openSession(childId)
|
|
976
|
+
} catch {
|
|
977
|
+
/* 打开失败不阻断 */
|
|
978
|
+
}
|
|
979
|
+
},
|
|
980
|
+
style: primaryBtnStyle,
|
|
981
|
+
},
|
|
982
|
+
t('toast.openNew'),
|
|
983
|
+
),
|
|
984
|
+
]
|
|
985
|
+
: []),
|
|
986
|
+
],
|
|
987
|
+
},
|
|
988
|
+
[
|
|
989
|
+
React.createElement('div', { key: 'meta', style: metaStyle }, t('dialog.session'), target.sessionId || ''),
|
|
990
|
+
body,
|
|
991
|
+
doneMsg ? React.createElement('div', { key: 'done', style: statusStyle }, doneMsg) : null,
|
|
992
|
+
error ? React.createElement('div', { key: 'err', style: errStyle, role: 'alert' }, error) : null,
|
|
740
993
|
],
|
|
741
|
-
|
|
742
|
-
React.createElement('div', { key: 'meta', style: metaStyle },
|
|
743
|
-
t('dialog.session'), target.sessionId || ''),
|
|
744
|
-
body,
|
|
745
|
-
doneMsg ? React.createElement('div', { key: 'done', style: statusStyle }, doneMsg) : null,
|
|
746
|
-
error ? React.createElement('div', { key: 'err', style: errStyle, role: 'alert' }, error) : null,
|
|
747
|
-
])
|
|
994
|
+
)
|
|
748
995
|
}
|
|
749
996
|
|
|
750
997
|
// --- A · 功能主义抽屉 -------------------------------------------------------
|
|
@@ -756,7 +1003,9 @@ window.__ModuleLoader__.load({
|
|
|
756
1003
|
if (typeof value !== 'number') return ''
|
|
757
1004
|
try {
|
|
758
1005
|
return new Date(value).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
|
759
|
-
} catch {
|
|
1006
|
+
} catch {
|
|
1007
|
+
return ''
|
|
1008
|
+
}
|
|
760
1009
|
}
|
|
761
1010
|
|
|
762
1011
|
function roleCode(role) {
|
|
@@ -768,8 +1017,9 @@ window.__ModuleLoader__.load({
|
|
|
768
1017
|
|
|
769
1018
|
function focusablesIn(root) {
|
|
770
1019
|
if (!root || typeof root.querySelectorAll !== 'function') return []
|
|
771
|
-
const selector =
|
|
772
|
-
|
|
1020
|
+
const selector =
|
|
1021
|
+
'button:not([disabled]),[href],input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])'
|
|
1022
|
+
return Array.prototype.slice.call(root.querySelectorAll(selector)).filter(el => {
|
|
773
1023
|
if (el.getAttribute('aria-hidden') === 'true') return false
|
|
774
1024
|
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0
|
|
775
1025
|
})
|
|
@@ -854,7 +1104,9 @@ window.__ModuleLoader__.load({
|
|
|
854
1104
|
'@media(max-width:760px){.mopsPanelScrim{padding:0}.mopsPanel{width:100%;height:100%;max-width:100%;max-height:100%;border:0}.mopsDetail{max-height:42%}}',
|
|
855
1105
|
].join('')
|
|
856
1106
|
document.head.appendChild(tag)
|
|
857
|
-
} catch {
|
|
1107
|
+
} catch {
|
|
1108
|
+
/* style failure must not break the panel */
|
|
1109
|
+
}
|
|
858
1110
|
}
|
|
859
1111
|
|
|
860
1112
|
function OpsPanel(props) {
|
|
@@ -908,7 +1160,7 @@ window.__ModuleLoader__.load({
|
|
|
908
1160
|
|
|
909
1161
|
useEffect(() => {
|
|
910
1162
|
ensurePanelStyle()
|
|
911
|
-
const handler =
|
|
1163
|
+
const handler = e => {
|
|
912
1164
|
const d = e && e.detail ? e.detail : {}
|
|
913
1165
|
if (!d.sessionId) return
|
|
914
1166
|
const active = document.activeElement
|
|
@@ -948,31 +1200,44 @@ window.__ModuleLoader__.load({
|
|
|
948
1200
|
|
|
949
1201
|
const sid = target && target.sessionId
|
|
950
1202
|
|
|
951
|
-
const loadMessages = useCallback(
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
1203
|
+
const loadMessages = useCallback(
|
|
1204
|
+
async quiet => {
|
|
1205
|
+
if (!sid) return
|
|
1206
|
+
const requestId = ++loadSeqRef.current
|
|
1207
|
+
const requestSid = sid
|
|
1208
|
+
if (!quiet) {
|
|
1209
|
+
setState('loading')
|
|
1210
|
+
setLoadError(null)
|
|
1211
|
+
}
|
|
1212
|
+
try {
|
|
1213
|
+
const data = await fetchMessagesJson('/api/message-ops/messages?sessionId=' + encodeURIComponent(requestSid) + '&view=compact')
|
|
1214
|
+
if (requestId !== loadSeqRef.current) return
|
|
1215
|
+
setMessages(Array.isArray(data.messages) ? data.messages : [])
|
|
1216
|
+
setTarget(prev =>
|
|
1217
|
+
prev && prev.sessionId === requestSid
|
|
1218
|
+
? {
|
|
1219
|
+
...prev,
|
|
1220
|
+
running: data.running === true,
|
|
1221
|
+
title: prev.title || (data.session && data.session.title) || null,
|
|
1222
|
+
expectedTitle: (data.session && data.session.confirmTitle) || prev.expectedTitle || prev.title || prev.sessionId,
|
|
1223
|
+
}
|
|
1224
|
+
: prev,
|
|
1225
|
+
)
|
|
1226
|
+
setLoadError(null)
|
|
1227
|
+
setError(null)
|
|
1228
|
+
setState('ready')
|
|
1229
|
+
} catch (reason) {
|
|
1230
|
+
if (requestId !== loadSeqRef.current) return
|
|
1231
|
+
const message = t('panel.loadFail') + (reason && reason.message ? reason.message : String(reason))
|
|
1232
|
+
if (quiet) setError(message)
|
|
1233
|
+
else {
|
|
1234
|
+
setLoadError(message)
|
|
1235
|
+
setState('error')
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
},
|
|
1239
|
+
[sid, t],
|
|
1240
|
+
)
|
|
976
1241
|
|
|
977
1242
|
useEffect(() => {
|
|
978
1243
|
if (!open || !sid) return
|
|
@@ -982,29 +1247,47 @@ window.__ModuleLoader__.load({
|
|
|
982
1247
|
useEffect(() => {
|
|
983
1248
|
if (!open || tab !== 'messages') return
|
|
984
1249
|
const q = query.trim()
|
|
985
|
-
if (!q) {
|
|
1250
|
+
if (!q) {
|
|
1251
|
+
setHits(null)
|
|
1252
|
+
setSearching(false)
|
|
1253
|
+
return
|
|
1254
|
+
}
|
|
986
1255
|
setSearching(true)
|
|
987
1256
|
let cancelled = false
|
|
988
1257
|
const timer = setTimeout(() => {
|
|
989
1258
|
setError(null)
|
|
990
|
-
const url =
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1259
|
+
const url =
|
|
1260
|
+
'/api/message-ops/search?sessionId=' +
|
|
1261
|
+
encodeURIComponent(sid) +
|
|
1262
|
+
'&q=' +
|
|
1263
|
+
encodeURIComponent(q) +
|
|
1264
|
+
(role !== 'all' ? '&role=' + encodeURIComponent(role) : '') +
|
|
1265
|
+
'&limit=' +
|
|
1266
|
+
PANEL_SEARCH_LIMIT
|
|
994
1267
|
fetch(url)
|
|
995
|
-
.then(
|
|
1268
|
+
.then(res =>
|
|
1269
|
+
res
|
|
1270
|
+
.json()
|
|
1271
|
+
.catch(() => null)
|
|
1272
|
+
.then(data => ({ res, data })),
|
|
1273
|
+
)
|
|
996
1274
|
.then(({ res, data }) => {
|
|
997
1275
|
if (cancelled) return
|
|
998
|
-
if (!res.ok || !data || data.ok !== true) throw new Error((data && data.error) ||
|
|
1276
|
+
if (!res.ok || !data || data.ok !== true) throw new Error((data && data.error) || 'HTTP ' + res.status)
|
|
999
1277
|
setHits(Array.isArray(data.results) ? data.results : [])
|
|
1000
1278
|
setError(null)
|
|
1001
1279
|
})
|
|
1002
|
-
.catch(
|
|
1280
|
+
.catch(reason => {
|
|
1003
1281
|
if (!cancelled) setError(t('panel.searchFail') + (reason && reason.message ? reason.message : String(reason)))
|
|
1004
1282
|
})
|
|
1005
|
-
.finally(() => {
|
|
1283
|
+
.finally(() => {
|
|
1284
|
+
if (!cancelled) setSearching(false)
|
|
1285
|
+
})
|
|
1006
1286
|
}, 200)
|
|
1007
|
-
return () => {
|
|
1287
|
+
return () => {
|
|
1288
|
+
cancelled = true
|
|
1289
|
+
clearTimeout(timer)
|
|
1290
|
+
}
|
|
1008
1291
|
}, [open, tab, sid, query, role, t])
|
|
1009
1292
|
|
|
1010
1293
|
const loadTrash = useCallback(async () => {
|
|
@@ -1015,7 +1298,7 @@ window.__ModuleLoader__.load({
|
|
|
1015
1298
|
const res = await fetch('/api/message-ops/session/trash')
|
|
1016
1299
|
const data = await res.json().catch(() => null)
|
|
1017
1300
|
if (requestId !== trashSeqRef.current) return
|
|
1018
|
-
if (!res.ok || !data || data.ok !== true) throw new Error((data && data.error) ||
|
|
1301
|
+
if (!res.ok || !data || data.ok !== true) throw new Error((data && data.error) || 'HTTP ' + res.status)
|
|
1019
1302
|
setTrash(Array.isArray(data.entries) ? data.entries : [])
|
|
1020
1303
|
setTrashError(null)
|
|
1021
1304
|
setTrashState('ready')
|
|
@@ -1068,9 +1351,47 @@ window.__ModuleLoader__.load({
|
|
|
1068
1351
|
}, 0)
|
|
1069
1352
|
}, [busy, confirmAction])
|
|
1070
1353
|
|
|
1354
|
+
/**
|
|
1355
|
+
* 0.12.0 面板内的「编辑并重发」:把该条用户消息的原文放进编辑器并关掉面板。
|
|
1356
|
+
*
|
|
1357
|
+
* 为什么不自己加一个输入框:编辑器已经有草稿、附件、引用、斜杠命令与提交状态机,
|
|
1358
|
+
* 面板里再复刻一套只会分叉行为。正确做法是**交回官方编辑器**:
|
|
1359
|
+
* 1. `setDraft(text)` 改编辑器内容
|
|
1360
|
+
* 2. `persistDraft()` 落 localStorage —— 否则紧随的 openSession 会用旧草稿覆盖
|
|
1361
|
+
* (0.11.3 已踩过这个坑,见 refillComposer 注释)
|
|
1362
|
+
* 3. 关面板并聚焦编辑器,用户改完直接回车发出
|
|
1363
|
+
* 语义上与 opencode 的「回撤 → 原文回到 composer」一致;区别是我们不预先回撤,
|
|
1364
|
+
* 由用户决定发不发(发了才产生新的分支上下文)。
|
|
1365
|
+
*/
|
|
1366
|
+
const startEdit = useCallback(
|
|
1367
|
+
text => {
|
|
1368
|
+
if (!target || busy) return
|
|
1369
|
+
const body = typeof text === 'string' ? text : ''
|
|
1370
|
+
if (!body) {
|
|
1371
|
+
setError(t('panel.editEmpty'))
|
|
1372
|
+
return
|
|
1373
|
+
}
|
|
1374
|
+
if (!__inputActions || typeof __inputActions.setDraft !== 'function') {
|
|
1375
|
+
setError(t('panel.editUnavailable'))
|
|
1376
|
+
return
|
|
1377
|
+
}
|
|
1378
|
+
try {
|
|
1379
|
+
__inputActions.setDraft(body)
|
|
1380
|
+
if (typeof __inputActions.persistDraft === 'function') __inputActions.persistDraft()
|
|
1381
|
+
} catch (reason) {
|
|
1382
|
+
setError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
|
|
1383
|
+
return
|
|
1384
|
+
}
|
|
1385
|
+
setDone(t('panel.editDone'))
|
|
1386
|
+
notifyDone(t('panel.editDone'))
|
|
1387
|
+
close()
|
|
1388
|
+
},
|
|
1389
|
+
[target, busy, t, close],
|
|
1390
|
+
)
|
|
1391
|
+
|
|
1071
1392
|
useEffect(() => {
|
|
1072
1393
|
if (!open) return undefined
|
|
1073
|
-
const onKey =
|
|
1394
|
+
const onKey = e => {
|
|
1074
1395
|
if (e.key === 'Escape') {
|
|
1075
1396
|
if (busy) return
|
|
1076
1397
|
if (confirmDelete) closeConfirm()
|
|
@@ -1136,13 +1457,15 @@ window.__ModuleLoader__.load({
|
|
|
1136
1457
|
let scrollbarW = 0
|
|
1137
1458
|
try {
|
|
1138
1459
|
scrollbarW = window.innerWidth - document.documentElement.clientWidth
|
|
1139
|
-
} catch {
|
|
1460
|
+
} catch {
|
|
1461
|
+
/* non-browser */
|
|
1462
|
+
}
|
|
1140
1463
|
if (body && body.style) {
|
|
1141
1464
|
body.style.overflow = 'hidden'
|
|
1142
1465
|
// 为被隐藏的经典滚动条补回等宽内边距,避免整页横向跳动。
|
|
1143
1466
|
if (scrollbarW > 0) {
|
|
1144
1467
|
const base = Number.parseFloat(getComputedStyle(body).paddingRight) || 0
|
|
1145
|
-
body.style.paddingRight =
|
|
1468
|
+
body.style.paddingRight = base + scrollbarW + 'px'
|
|
1146
1469
|
}
|
|
1147
1470
|
}
|
|
1148
1471
|
return () => {
|
|
@@ -1160,16 +1483,22 @@ window.__ModuleLoader__.load({
|
|
|
1160
1483
|
const trigger = triggerRef.current
|
|
1161
1484
|
triggerRef.current = null
|
|
1162
1485
|
if (trigger && typeof trigger.focus === 'function') {
|
|
1163
|
-
setTimeout(() => {
|
|
1486
|
+
setTimeout(() => {
|
|
1487
|
+
try {
|
|
1488
|
+
trigger.focus()
|
|
1489
|
+
} catch {
|
|
1490
|
+
/* detached trigger */
|
|
1491
|
+
}
|
|
1492
|
+
}, 0)
|
|
1164
1493
|
}
|
|
1165
1494
|
}
|
|
1166
1495
|
}, [open, sid])
|
|
1167
1496
|
|
|
1168
1497
|
useEffect(() => {
|
|
1169
1498
|
if (!open) return undefined
|
|
1170
|
-
const onKeyDown =
|
|
1499
|
+
const onKeyDown = e => {
|
|
1171
1500
|
if (e.key !== 'Tab') return
|
|
1172
|
-
const scope = confirmDelete ? confirmRef.current :
|
|
1501
|
+
const scope = confirmDelete ? confirmRef.current : confirmAction ? actionConfirmRef.current : panelRef.current
|
|
1173
1502
|
if (!scope) return
|
|
1174
1503
|
const nodes = focusablesIn(scope)
|
|
1175
1504
|
if (!nodes.length) {
|
|
@@ -1207,13 +1536,11 @@ window.__ModuleLoader__.load({
|
|
|
1207
1536
|
}
|
|
1208
1537
|
}, [open, confirmDelete, confirmAction])
|
|
1209
1538
|
|
|
1210
|
-
const baseRows = query.trim() ?
|
|
1539
|
+
const baseRows = query.trim() ? hits || [] : messages
|
|
1211
1540
|
const rows = baseRows
|
|
1212
|
-
.filter(
|
|
1213
|
-
&& (role === 'all' || m.role === role)
|
|
1214
|
-
&& (includeShadowed || !m.shadowed))
|
|
1541
|
+
.filter(m => m && m.role !== 'system' && (role === 'all' || m.role === role) && (includeShadowed || !m.shadowed))
|
|
1215
1542
|
.sort((a, b) => b.seq - a.seq)
|
|
1216
|
-
const activeIndex = picked ? rows.findIndex(
|
|
1543
|
+
const activeIndex = picked ? rows.findIndex(m => m.seq === picked.seq) : -1
|
|
1217
1544
|
|
|
1218
1545
|
const clearPick = () => {
|
|
1219
1546
|
detailReq.current += 1
|
|
@@ -1223,7 +1550,7 @@ window.__ModuleLoader__.load({
|
|
|
1223
1550
|
setConfirmAction(null)
|
|
1224
1551
|
}
|
|
1225
1552
|
|
|
1226
|
-
const previewRow =
|
|
1553
|
+
const previewRow = m => {
|
|
1227
1554
|
if (!m) return
|
|
1228
1555
|
detailReq.current += 1
|
|
1229
1556
|
setPicked(m)
|
|
@@ -1233,7 +1560,7 @@ window.__ModuleLoader__.load({
|
|
|
1233
1560
|
setDone('')
|
|
1234
1561
|
}
|
|
1235
1562
|
|
|
1236
|
-
const scrollRowIntoView =
|
|
1563
|
+
const scrollRowIntoView = index => {
|
|
1237
1564
|
const el = listRef.current
|
|
1238
1565
|
if (!el) return
|
|
1239
1566
|
const top = index * PANEL_ROW_H
|
|
@@ -1247,9 +1574,9 @@ window.__ModuleLoader__.load({
|
|
|
1247
1574
|
}
|
|
1248
1575
|
}
|
|
1249
1576
|
|
|
1250
|
-
const handleListKeyDown =
|
|
1577
|
+
const handleListKeyDown = e => {
|
|
1251
1578
|
if (!rows.length) return
|
|
1252
|
-
const page = Math.max(1, Math.floor((listRef.current && listRef.current.clientHeight || viewport) / PANEL_ROW_H) - 1)
|
|
1579
|
+
const page = Math.max(1, Math.floor(((listRef.current && listRef.current.clientHeight) || viewport) / PANEL_ROW_H) - 1)
|
|
1253
1580
|
let next = activeIndex
|
|
1254
1581
|
if (e.key === 'ArrowDown') next = activeIndex < 0 ? 0 : Math.min(rows.length - 1, activeIndex + 1)
|
|
1255
1582
|
else if (e.key === 'ArrowUp') next = activeIndex < 0 ? rows.length - 1 : Math.max(0, activeIndex - 1)
|
|
@@ -1260,7 +1587,10 @@ window.__ModuleLoader__.load({
|
|
|
1260
1587
|
else if (e.key === 'Enter' || e.key === ' ') {
|
|
1261
1588
|
e.preventDefault()
|
|
1262
1589
|
const row = rows[activeIndex >= 0 ? activeIndex : 0]
|
|
1263
|
-
if (row) {
|
|
1590
|
+
if (row) {
|
|
1591
|
+
pick(row)
|
|
1592
|
+
if (listRef.current) listRef.current.focus()
|
|
1593
|
+
}
|
|
1264
1594
|
return
|
|
1265
1595
|
} else {
|
|
1266
1596
|
return
|
|
@@ -1295,84 +1625,107 @@ window.__ModuleLoader__.load({
|
|
|
1295
1625
|
}
|
|
1296
1626
|
}, [open, tab, rows.length, viewport])
|
|
1297
1627
|
|
|
1298
|
-
const pick = useCallback(
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1628
|
+
const pick = useCallback(
|
|
1629
|
+
m => {
|
|
1630
|
+
if (!m || busy) return
|
|
1631
|
+
setConfirmAction(null)
|
|
1632
|
+
setPicked(m)
|
|
1633
|
+
setDetail(m.snippet || '')
|
|
1634
|
+
setDetailState('loading')
|
|
1635
|
+
setDone('')
|
|
1636
|
+
const req = ++detailReq.current
|
|
1637
|
+
fetch('/api/message-ops/text?sessionId=' + encodeURIComponent(sid) + '&seq=' + encodeURIComponent(m.seq))
|
|
1638
|
+
.then(res =>
|
|
1639
|
+
res
|
|
1640
|
+
.json()
|
|
1641
|
+
.catch(() => null)
|
|
1642
|
+
.then(data => ({ res, data })),
|
|
1643
|
+
)
|
|
1644
|
+
.then(({ res, data }) => {
|
|
1645
|
+
if (req !== detailReq.current) return
|
|
1646
|
+
if (!res.ok || !data || data.ok !== true) throw new Error((data && data.error) || 'HTTP ' + res.status)
|
|
1647
|
+
setDetail(typeof data.text === 'string' && data.text ? data.text : m.snippet || '')
|
|
1648
|
+
setDetailState('ready')
|
|
1649
|
+
})
|
|
1650
|
+
.catch(() => {
|
|
1651
|
+
if (req !== detailReq.current) return
|
|
1652
|
+
setDetail(m.snippet || '')
|
|
1653
|
+
setDetailState('ready')
|
|
1654
|
+
})
|
|
1655
|
+
},
|
|
1656
|
+
[busy, sid],
|
|
1657
|
+
)
|
|
1320
1658
|
|
|
1321
|
-
const runAction = useCallback(
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1659
|
+
const runAction = useCallback(
|
|
1660
|
+
async (mode, confirmed) => {
|
|
1661
|
+
if (!target || !picked || busy) return
|
|
1662
|
+
if (target.running && mode !== 'branch') return
|
|
1663
|
+
if ((mode === 'revert' || mode === 'delete') && confirmed !== true) return
|
|
1664
|
+
const actionSid = target.sessionId
|
|
1665
|
+
setBusy(mode)
|
|
1666
|
+
setError(null)
|
|
1667
|
+
setDone('')
|
|
1668
|
+
try {
|
|
1669
|
+
if (mode === 'branch') {
|
|
1670
|
+
// 0.12.0:分叉 = opencode 的 before 语义(新会话不含此条,原文回输入框)。
|
|
1671
|
+
// 非破坏操作,故不受 running 限制(官方 fork 会自己拒绝运行中源会话)。
|
|
1672
|
+
// 取文本用 `detail`(该条全文,pick 时已按 seq 拉好);非用户消息不带文本。
|
|
1673
|
+
const pickedRole = picked && picked.role
|
|
1674
|
+
const created = await forkFromUserMessage(actionSid, picked.seq, pickedRole === 'user' ? detail : '', picked.turnStartSeq)
|
|
1675
|
+
if (sessionRef.current !== actionSid) return
|
|
1676
|
+
setChildId(created || null)
|
|
1677
|
+
setDone(t('panel.branchDone', { id: String(created || '') }))
|
|
1678
|
+
notifyDone(t('panel.branchDone', { id: String(created || '') }))
|
|
1679
|
+
return
|
|
1680
|
+
}
|
|
1681
|
+
const res = await fetch('/api/message-ops/' + mode, {
|
|
1682
|
+
method: 'POST',
|
|
1683
|
+
headers: { 'content-type': 'application/json' },
|
|
1684
|
+
body: JSON.stringify({ sessionId: target.sessionId, seq: picked.seq }),
|
|
1685
|
+
})
|
|
1686
|
+
const data = await res.json().catch(() => null)
|
|
1334
1687
|
if (sessionRef.current !== actionSid) return
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
return
|
|
1339
|
-
}
|
|
1340
|
-
const res = await fetch('/api/message-ops/' + mode, {
|
|
1341
|
-
method: 'POST',
|
|
1342
|
-
headers: { 'content-type': 'application/json' },
|
|
1343
|
-
body: JSON.stringify({ sessionId: target.sessionId, seq: picked.seq }),
|
|
1344
|
-
})
|
|
1345
|
-
const data = await res.json().catch(() => null)
|
|
1346
|
-
if (sessionRef.current !== actionSid) return
|
|
1347
|
-
if (!res.ok || !data || data.ok !== true) {
|
|
1348
|
-
if (res.status === 409) setTarget((prev) => prev ? { ...prev, running: true } : prev)
|
|
1349
|
-
throw new Error((data && data.error) || ('HTTP ' + res.status))
|
|
1350
|
-
}
|
|
1351
|
-
if (mode === 'revert') {
|
|
1352
|
-
setMessages((prev) => prev.map((m) => (m.seq >= picked.seq ? { ...m, shadowed: true, visible: false } : m)))
|
|
1353
|
-
if (picked.role === 'user') {
|
|
1354
|
-
try { refillComposer(target.sessionId, picked.seq) } catch { /* non-blocking */ }
|
|
1688
|
+
if (!res.ok || !data || data.ok !== true) {
|
|
1689
|
+
if (res.status === 409) setTarget(prev => (prev ? { ...prev, running: true } : prev))
|
|
1690
|
+
throw new Error((data && data.error) || 'HTTP ' + res.status)
|
|
1355
1691
|
}
|
|
1356
|
-
|
|
1357
|
-
|
|
1692
|
+
if (mode === 'revert') {
|
|
1693
|
+
setMessages(prev => prev.map(m => (m.seq >= picked.seq ? { ...m, shadowed: true, visible: false } : m)))
|
|
1694
|
+
if (picked.role === 'user') {
|
|
1695
|
+
try {
|
|
1696
|
+
refillComposer(target.sessionId, picked.seq)
|
|
1697
|
+
} catch {
|
|
1698
|
+
/* non-blocking */
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
} else {
|
|
1702
|
+
setMessages(prev => prev.map(m => (m.seq === picked.seq ? { ...m, shadowed: true, visible: false } : m)))
|
|
1703
|
+
}
|
|
1704
|
+
const msg = t(mode === 'revert' ? 'panel.revertDone' : 'panel.deleteDone')
|
|
1705
|
+
setDone(msg)
|
|
1706
|
+
setConfirmAction(null)
|
|
1707
|
+
setTimeout(() => {
|
|
1708
|
+
if (listRef.current) listRef.current.focus()
|
|
1709
|
+
}, 0)
|
|
1710
|
+
notifyDone(msg)
|
|
1711
|
+
emitChanged()
|
|
1712
|
+
try {
|
|
1713
|
+
if (__uiWorkspace && typeof __uiWorkspace.openSession === 'function') __uiWorkspace.openSession(target.sessionId)
|
|
1714
|
+
} catch {
|
|
1715
|
+
/* view rebuild is best effort */
|
|
1716
|
+
}
|
|
1717
|
+
setTimeout(() => {
|
|
1718
|
+
loadMessages(true).catch(() => {})
|
|
1719
|
+
}, 650)
|
|
1720
|
+
} catch (reason) {
|
|
1721
|
+
if (sessionRef.current !== actionSid) return
|
|
1722
|
+
setError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
|
|
1723
|
+
} finally {
|
|
1724
|
+
setBusy('')
|
|
1358
1725
|
}
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
setTimeout(() => { if (listRef.current) listRef.current.focus() }, 0)
|
|
1363
|
-
notifyDone(msg)
|
|
1364
|
-
emitChanged()
|
|
1365
|
-
try {
|
|
1366
|
-
if (__uiWorkspace && typeof __uiWorkspace.openSession === 'function') __uiWorkspace.openSession(target.sessionId)
|
|
1367
|
-
} catch { /* view rebuild is best effort */ }
|
|
1368
|
-
setTimeout(() => { loadMessages(true).catch(() => {}) }, 650)
|
|
1369
|
-
} catch (reason) {
|
|
1370
|
-
if (sessionRef.current !== actionSid) return
|
|
1371
|
-
setError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
|
|
1372
|
-
} finally {
|
|
1373
|
-
setBusy('')
|
|
1374
|
-
}
|
|
1375
|
-
}, [target, picked, busy, t, loadMessages])
|
|
1726
|
+
},
|
|
1727
|
+
[target, picked, busy, t, loadMessages],
|
|
1728
|
+
)
|
|
1376
1729
|
|
|
1377
1730
|
const deleteSession = useCallback(async () => {
|
|
1378
1731
|
if (!target || busy || target.running) return
|
|
@@ -1391,14 +1744,20 @@ window.__ModuleLoader__.load({
|
|
|
1391
1744
|
const data = await res.json().catch(() => null)
|
|
1392
1745
|
if (sessionRef.current !== actionSid) return
|
|
1393
1746
|
if (!res.ok || !data || data.ok !== true) {
|
|
1394
|
-
if (res.status === 409) setTarget(
|
|
1395
|
-
throw new Error((data && data.error) ||
|
|
1747
|
+
if (res.status === 409) setTarget(prev => (prev ? { ...prev, running: true } : prev))
|
|
1748
|
+
throw new Error((data && data.error) || 'HTTP ' + res.status)
|
|
1396
1749
|
}
|
|
1397
1750
|
setConfirmDelete(false)
|
|
1398
1751
|
setDone(t('panel.deleted'))
|
|
1399
1752
|
notifyDone(t('panel.deleted'))
|
|
1400
1753
|
emitChanged()
|
|
1401
|
-
setTimeout(() => {
|
|
1754
|
+
setTimeout(() => {
|
|
1755
|
+
try {
|
|
1756
|
+
window.location.reload()
|
|
1757
|
+
} catch {
|
|
1758
|
+
/* non-browser guard */
|
|
1759
|
+
}
|
|
1760
|
+
}, 700)
|
|
1402
1761
|
} catch (reason) {
|
|
1403
1762
|
if (sessionRef.current !== actionSid) return
|
|
1404
1763
|
setDeleteError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
|
|
@@ -1407,307 +1766,653 @@ window.__ModuleLoader__.load({
|
|
|
1407
1766
|
}
|
|
1408
1767
|
}, [target, busy, confirmTitle, t])
|
|
1409
1768
|
|
|
1410
|
-
const restoreEntry = useCallback(
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1769
|
+
const restoreEntry = useCallback(
|
|
1770
|
+
async trashId => {
|
|
1771
|
+
if (busy) return
|
|
1772
|
+
setBusy('restore:' + trashId)
|
|
1773
|
+
setError(null)
|
|
1774
|
+
setDone('')
|
|
1775
|
+
try {
|
|
1776
|
+
const res = await fetch('/api/message-ops/session/restore', {
|
|
1777
|
+
method: 'POST',
|
|
1778
|
+
headers: { 'content-type': 'application/json' },
|
|
1779
|
+
body: JSON.stringify({ trashId }),
|
|
1780
|
+
})
|
|
1781
|
+
const data = await res.json().catch(() => null)
|
|
1782
|
+
if (!res.ok || !data || data.ok !== true) throw new Error((data && data.error) || 'HTTP ' + res.status)
|
|
1783
|
+
setTrash(prev => prev.filter(x => x.trashId !== trashId))
|
|
1784
|
+
setDone(t('panel.restored'))
|
|
1785
|
+
notifyDone(t('panel.restored'))
|
|
1786
|
+
emitChanged()
|
|
1787
|
+
setTimeout(() => {
|
|
1788
|
+
try {
|
|
1789
|
+
window.location.reload()
|
|
1790
|
+
} catch {
|
|
1791
|
+
/* non-browser guard */
|
|
1792
|
+
}
|
|
1793
|
+
}, 700)
|
|
1794
|
+
} catch (reason) {
|
|
1795
|
+
setError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
|
|
1796
|
+
} finally {
|
|
1797
|
+
setBusy('')
|
|
1798
|
+
}
|
|
1799
|
+
},
|
|
1800
|
+
[busy, t],
|
|
1801
|
+
)
|
|
1434
1802
|
|
|
1435
|
-
const purgeEntry = useCallback(
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1803
|
+
const purgeEntry = useCallback(
|
|
1804
|
+
async trashId => {
|
|
1805
|
+
if (busy) return
|
|
1806
|
+
if (purgeId !== trashId) {
|
|
1807
|
+
setPurgeId(trashId)
|
|
1808
|
+
return
|
|
1809
|
+
}
|
|
1810
|
+
setBusy('purge:' + trashId)
|
|
1811
|
+
setError(null)
|
|
1812
|
+
setDone('')
|
|
1813
|
+
try {
|
|
1814
|
+
const res = await fetch('/api/message-ops/session/purge', {
|
|
1815
|
+
method: 'POST',
|
|
1816
|
+
headers: { 'content-type': 'application/json' },
|
|
1817
|
+
body: JSON.stringify({ trashId }),
|
|
1818
|
+
})
|
|
1819
|
+
const data = await res.json().catch(() => null)
|
|
1820
|
+
if (!res.ok || !data || data.ok !== true) throw new Error((data && data.error) || 'HTTP ' + res.status)
|
|
1821
|
+
setTrash(prev => prev.filter(x => x.trashId !== trashId))
|
|
1822
|
+
setPurgeId(null)
|
|
1823
|
+
setDone(t('panel.purged'))
|
|
1824
|
+
notifyDone(t('panel.purged'))
|
|
1825
|
+
} catch (reason) {
|
|
1826
|
+
setError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
|
|
1827
|
+
} finally {
|
|
1828
|
+
setBusy('')
|
|
1829
|
+
}
|
|
1830
|
+
},
|
|
1831
|
+
[busy, purgeId, t],
|
|
1832
|
+
)
|
|
1459
1833
|
|
|
1460
1834
|
if (!open) return null
|
|
1461
1835
|
|
|
1462
|
-
const pickedLive = picked ?
|
|
1836
|
+
const pickedLive = picked ? messages.find(m => m.seq === picked.seq) || picked : null
|
|
1463
1837
|
const canAct = !busy && !target.running && pickedLive && !pickedLive.shadowed
|
|
1464
|
-
const visibleCount = messages.filter(
|
|
1465
|
-
const shadowedCount = messages.filter(
|
|
1466
|
-
const totalCount = messages.filter(
|
|
1467
|
-
const revertImpact = pickedLive
|
|
1468
|
-
? messages.filter((m) => m.role !== 'system' && !m.shadowed && m.seq >= pickedLive.seq)
|
|
1469
|
-
: []
|
|
1838
|
+
const visibleCount = messages.filter(m => m.role !== 'system' && m.visible && !m.shadowed).length
|
|
1839
|
+
const shadowedCount = messages.filter(m => m.role !== 'system' && m.shadowed).length
|
|
1840
|
+
const totalCount = messages.filter(m => m.role !== 'system').length
|
|
1841
|
+
const revertImpact = pickedLive ? messages.filter(m => m.role !== 'system' && !m.shadowed && m.seq >= pickedLive.seq) : []
|
|
1470
1842
|
const revertCount = revertImpact.length
|
|
1471
|
-
const revertVisibleCount = revertImpact.filter(
|
|
1843
|
+
const revertVisibleCount = revertImpact.filter(m => m.visible).length
|
|
1472
1844
|
const revertEnd = revertImpact.reduce((max, m) => Math.max(max, m.seq), pickedLive ? pickedLive.seq : 0)
|
|
1473
1845
|
const expectedDeleteTitle = target.expectedTitle || ''
|
|
1846
|
+
// 0.12.0:分叉/编辑只对**用户消息**成立(与 opencode 一致:fork 的语义是
|
|
1847
|
+
// 「这句话说错了,拿回去重说」,AI 消息没有可回填的原文)。
|
|
1848
|
+
const pickedIsUser = !!pickedLive && pickedLive.role === 'user'
|
|
1849
|
+
const canFork = !busy && !target.running && pickedIsUser && !pickedLive.shadowed && pickedLive.seq > 0
|
|
1850
|
+
const canEdit = pickedIsUser && !pickedLive.shadowed && state === 'ready' && !busy
|
|
1474
1851
|
const deleteBlockedReason = target.running
|
|
1475
1852
|
? t('panel.running')
|
|
1476
1853
|
: state !== 'ready'
|
|
1477
|
-
?
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1854
|
+
? state === 'error'
|
|
1855
|
+
? t('panel.loadFail')
|
|
1856
|
+
: t('panel.loading')
|
|
1857
|
+
: !expectedDeleteTitle
|
|
1858
|
+
? t('panel.deleteUnavailable')
|
|
1859
|
+
: ''
|
|
1860
|
+
const canConfirmDelete =
|
|
1861
|
+
!busy && state === 'ready' && !target.running && !!expectedDeleteTitle && confirmTitle.trim() === expectedDeleteTitle
|
|
1481
1862
|
const start = Math.min(Math.max(0, rows.length - 1), Math.max(0, Math.floor(scrollTop / PANEL_ROW_H) - 6))
|
|
1482
1863
|
const end = Math.min(rows.length, start + Math.ceil(viewport / PANEL_ROW_H) + 12)
|
|
1483
1864
|
const windowRows = rows.slice(start, end)
|
|
1484
|
-
const activeRendered = picked && windowRows.some(
|
|
1865
|
+
const activeRendered = picked && windowRows.some(m => m.seq === picked.seq)
|
|
1485
1866
|
const showSearchLoading = searching && query.trim().length > 0
|
|
1486
1867
|
|
|
1487
|
-
return React.createElement(
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
style: { position: 'relative' },
|
|
1868
|
+
return React.createElement(
|
|
1869
|
+
'div',
|
|
1870
|
+
{
|
|
1871
|
+
className: 'mopsPanelScrim',
|
|
1872
|
+
role: 'presentation',
|
|
1873
|
+
ref: scrimRef,
|
|
1874
|
+
onMouseDown: e => {
|
|
1875
|
+
if (e.target === e.currentTarget) close()
|
|
1876
|
+
},
|
|
1497
1877
|
},
|
|
1498
|
-
|
|
1499
|
-
|
|
1878
|
+
React.createElement(
|
|
1879
|
+
'section',
|
|
1880
|
+
{
|
|
1881
|
+
className: 'mopsPanel',
|
|
1882
|
+
role: 'dialog',
|
|
1883
|
+
'aria-modal': 'true',
|
|
1884
|
+
'aria-labelledby': 'mops-panel-title',
|
|
1885
|
+
'aria-describedby': 'mops-panel-session',
|
|
1886
|
+
'aria-busy': busy || state === 'loading' ? 'true' : undefined,
|
|
1887
|
+
tabIndex: -1,
|
|
1888
|
+
ref: panelRef,
|
|
1889
|
+
style: { position: 'relative' },
|
|
1890
|
+
},
|
|
1891
|
+
React.createElement(
|
|
1892
|
+
'header',
|
|
1893
|
+
{ className: 'mopsPanelHead' },
|
|
1894
|
+
React.createElement(
|
|
1895
|
+
'div',
|
|
1896
|
+
{ style: { minWidth: 0 } },
|
|
1500
1897
|
React.createElement('div', { className: 'mopsPanelKicker' }, t('dialog.title')),
|
|
1501
|
-
React.createElement(
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1898
|
+
React.createElement(
|
|
1899
|
+
'div',
|
|
1900
|
+
{ className: 'mopsPanelTitle', id: 'mops-panel-title' },
|
|
1901
|
+
target.title || target.expectedTitle || target.sessionId,
|
|
1902
|
+
),
|
|
1903
|
+
React.createElement('div', { className: 'mopsPanelSub', id: 'mops-panel-session' }, target.sessionId),
|
|
1904
|
+
),
|
|
1905
|
+
React.createElement(
|
|
1906
|
+
'button',
|
|
1907
|
+
{
|
|
1908
|
+
type: 'button',
|
|
1909
|
+
className: 'mopsPanelClose',
|
|
1910
|
+
title: t('dialog.cancel'),
|
|
1911
|
+
'aria-label': t('dialog.cancel'),
|
|
1912
|
+
onClick: close,
|
|
1913
|
+
disabled: !!busy,
|
|
1914
|
+
},
|
|
1915
|
+
'×',
|
|
1916
|
+
),
|
|
1917
|
+
),
|
|
1918
|
+
React.createElement(
|
|
1919
|
+
'div',
|
|
1920
|
+
{ className: 'mopsTabs' },
|
|
1921
|
+
React.createElement(
|
|
1922
|
+
'button',
|
|
1923
|
+
{
|
|
1924
|
+
type: 'button',
|
|
1925
|
+
className: 'mopsTab' + (tab === 'messages' ? ' on' : ''),
|
|
1926
|
+
onClick: () => {
|
|
1927
|
+
setTab('messages')
|
|
1928
|
+
setConfirmDelete(false)
|
|
1929
|
+
setConfirmAction(null)
|
|
1930
|
+
setDeleteError(null)
|
|
1931
|
+
},
|
|
1932
|
+
},
|
|
1933
|
+
t('panel.messages') + ' ' + totalCount,
|
|
1934
|
+
),
|
|
1935
|
+
React.createElement(
|
|
1936
|
+
'button',
|
|
1937
|
+
{
|
|
1938
|
+
type: 'button',
|
|
1939
|
+
className: 'mopsTab' + (tab === 'trash' ? ' on' : ''),
|
|
1940
|
+
onClick: () => {
|
|
1941
|
+
setTab('trash')
|
|
1942
|
+
setConfirmDelete(false)
|
|
1943
|
+
setConfirmAction(null)
|
|
1944
|
+
setDeleteError(null)
|
|
1945
|
+
},
|
|
1946
|
+
},
|
|
1947
|
+
t('panel.trash') + (trash.length ? ' ' + trash.length : ''),
|
|
1948
|
+
),
|
|
1949
|
+
),
|
|
1950
|
+
target.running && tab === 'messages' ? React.createElement('div', { className: 'mopsBanner warn' }, t('panel.running')) : null,
|
|
1519
1951
|
error ? React.createElement('div', { className: 'mopsBanner err', role: 'alert' }, error) : null,
|
|
1520
|
-
done
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1952
|
+
done
|
|
1953
|
+
? React.createElement(
|
|
1954
|
+
'div',
|
|
1955
|
+
{ className: 'mopsBanner ok' },
|
|
1956
|
+
done,
|
|
1957
|
+
childId
|
|
1958
|
+
? React.createElement(
|
|
1959
|
+
'button',
|
|
1960
|
+
{
|
|
1961
|
+
type: 'button',
|
|
1962
|
+
className: 'mopsAction primary',
|
|
1963
|
+
style: { marginLeft: 10 },
|
|
1964
|
+
onClick: () => {
|
|
1965
|
+
try {
|
|
1966
|
+
if (__uiWorkspace && typeof __uiWorkspace.openSession === 'function') __uiWorkspace.openSession(childId)
|
|
1967
|
+
} catch {
|
|
1968
|
+
/* best effort */
|
|
1969
|
+
}
|
|
1970
|
+
},
|
|
1971
|
+
},
|
|
1972
|
+
t('panel.openNew'),
|
|
1973
|
+
)
|
|
1974
|
+
: null,
|
|
1975
|
+
)
|
|
1976
|
+
: null,
|
|
1525
1977
|
tab === 'messages'
|
|
1526
|
-
? React.createElement(
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
})),
|
|
1533
|
-
React.createElement('div', { className: 'mopsChips' },
|
|
1534
|
-
['all', 'user', 'assistant', 'tool'].map((key) => React.createElement('button', {
|
|
1535
|
-
key, type: 'button', className: 'mopsChip' + (role === key ? ' on' : ''),
|
|
1536
|
-
onClick: () => { setRole(key); clearPick(); setScrollTop(0); if (listRef.current) listRef.current.scrollTop = 0 },
|
|
1537
|
-
}, t('panel.' + key))),
|
|
1538
|
-
React.createElement('label', { className: 'mopsToggle' },
|
|
1978
|
+
? React.createElement(
|
|
1979
|
+
React.Fragment,
|
|
1980
|
+
null,
|
|
1981
|
+
React.createElement(
|
|
1982
|
+
'div',
|
|
1983
|
+
{ className: 'mopsSearchRow' },
|
|
1539
1984
|
React.createElement('input', {
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
:
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
React.createElement('span', { className: 'mopsSeq' }, '#' + m.seq),
|
|
1577
|
-
React.createElement('span', { className: 'mopsRole' }, roleCode(m.role)),
|
|
1578
|
-
React.createElement('span', { className: 'mopsSnippet' }, m.snippet || '—'),
|
|
1579
|
-
React.createElement('span', { className: 'mopsClock' }, fmtClock(m.time)))))),
|
|
1580
|
-
React.createElement('div', { className: 'mopsDetail' },
|
|
1581
|
-
pickedLive
|
|
1582
|
-
? React.createElement(React.Fragment, null,
|
|
1583
|
-
React.createElement('div', { className: 'mopsDetailMeta' },
|
|
1584
|
-
React.createElement('span', null, '#' + pickedLive.seq),
|
|
1585
|
-
React.createElement('span', null, pickedLive.role || ''),
|
|
1586
|
-
pickedLive.shadowed ? React.createElement('span', null, t('panel.shadowed')) : null,
|
|
1587
|
-
pickedLive.time ? React.createElement('span', null, fmtClock(pickedLive.time)) : null),
|
|
1588
|
-
React.createElement('pre', { className: 'mopsDetailText' },
|
|
1589
|
-
detailState === 'loading' ? t('panel.detailLoading') : (detail || pickedLive.snippet || '—')),
|
|
1590
|
-
React.createElement('div', { className: 'mopsActions' },
|
|
1591
|
-
React.createElement('button', {
|
|
1592
|
-
type: 'button', className: 'mopsAction primary', disabled: !canAct || !!confirmAction,
|
|
1593
|
-
ref: revertBtnRef,
|
|
1594
|
-
onClick: () => setConfirmAction('revert'),
|
|
1595
|
-
title: t('panel.revertHint'),
|
|
1596
|
-
}, t('panel.revert') + (revertCount ? ' · ' + revertCount : '')),
|
|
1597
|
-
React.createElement('button', {
|
|
1598
|
-
type: 'button', className: 'mopsAction danger', disabled: !canAct || !!confirmAction,
|
|
1599
|
-
ref: deleteOneBtnRef,
|
|
1600
|
-
onClick: () => setConfirmAction('delete'), title: t('panel.deleteHint'),
|
|
1601
|
-
}, t('panel.delete')),
|
|
1602
|
-
React.createElement('button', {
|
|
1603
|
-
type: 'button', className: 'mopsAction', disabled: !canAct || !!confirmAction,
|
|
1604
|
-
onClick: () => runAction('branch'), title: t('panel.branchHint'),
|
|
1605
|
-
}, t('panel.branch'))),
|
|
1606
|
-
confirmAction
|
|
1607
|
-
? React.createElement('div', {
|
|
1608
|
-
className: 'mopsActionConfirm', ref: actionConfirmRef, role: 'group', tabIndex: -1,
|
|
1609
|
-
'aria-labelledby': 'mops-action-confirm-title',
|
|
1610
|
-
},
|
|
1611
|
-
React.createElement('div', { className: 'mopsImpactTitle', id: 'mops-action-confirm-title' },
|
|
1612
|
-
t(confirmAction === 'revert' ? 'panel.revertConfirmTitle' : 'panel.deleteConfirmTitle', { seq: String(pickedLive.seq) })),
|
|
1613
|
-
React.createElement('div', { className: 'mopsImpact' },
|
|
1614
|
-
confirmAction === 'revert'
|
|
1615
|
-
? t('panel.revertConfirmBody', {
|
|
1616
|
-
start: String(pickedLive.seq), end: String(revertEnd),
|
|
1617
|
-
n: String(revertCount), v: String(revertVisibleCount),
|
|
1618
|
-
})
|
|
1619
|
-
: t('panel.deleteConfirmBody')),
|
|
1620
|
-
React.createElement('div', { className: 'mopsConfirmRow' },
|
|
1621
|
-
React.createElement('button', {
|
|
1622
|
-
type: 'button', className: 'mopsAction', onClick: cancelAction, disabled: !!busy,
|
|
1623
|
-
}, t('panel.cancel')),
|
|
1624
|
-
React.createElement('button', {
|
|
1625
|
-
type: 'button', className: 'mopsAction danger',
|
|
1626
|
-
onClick: () => runAction(confirmAction, true),
|
|
1627
|
-
disabled: !!busy || !canAct,
|
|
1628
|
-
}, busy === confirmAction ? t('panel.busy') : t(confirmAction === 'revert' ? 'panel.confirmRevert' : 'panel.confirmDeleteOne'))))
|
|
1629
|
-
: null)
|
|
1630
|
-
: React.createElement('div', { className: 'mopsDetailHint' }, t('panel.selectHint'))),
|
|
1631
|
-
React.createElement('footer', { className: 'mopsPanelFoot' },
|
|
1632
|
-
React.createElement('span', { className: 'mopsCount' },
|
|
1633
|
-
t('panel.count', { n: String(totalCount), v: String(visibleCount), s: String(shadowedCount) })),
|
|
1634
|
-
React.createElement('button', {
|
|
1635
|
-
type: 'button', className: 'mopsDanger', ref: deleteBtnRef,
|
|
1636
|
-
disabled: !!busy || !!deleteBlockedReason,
|
|
1637
|
-
title: deleteBlockedReason || undefined,
|
|
1638
|
-
onClick: () => {
|
|
1639
|
-
setConfirmTitle('')
|
|
1640
|
-
setDeleteError(null)
|
|
1641
|
-
setConfirmAction(null)
|
|
1642
|
-
setConfirmDelete(true)
|
|
1643
|
-
},
|
|
1644
|
-
}, t('panel.deleteSession'))),
|
|
1645
|
-
confirmDelete
|
|
1646
|
-
? React.createElement('div', {
|
|
1647
|
-
className: 'mopsConfirm', ref: confirmRef, role: 'alertdialog', 'aria-modal': 'true',
|
|
1648
|
-
'aria-labelledby': 'mops-delete-title', 'aria-describedby': 'mops-delete-hint mops-delete-impact',
|
|
1649
|
-
tabIndex: -1,
|
|
1650
|
-
},
|
|
1651
|
-
React.createElement('h3', { id: 'mops-delete-title' }, t('panel.deleteSession')),
|
|
1652
|
-
React.createElement('p', { id: 'mops-delete-hint' }, t('panel.deleteSessionHint')),
|
|
1653
|
-
React.createElement('p', { className: 'mopsImpact', id: 'mops-delete-impact' },
|
|
1654
|
-
t('panel.deleteSessionImpact', { n: String(totalCount) })),
|
|
1655
|
-
target.running ? React.createElement('div', { className: 'mopsBanner warn', role: 'status' }, t('panel.running')) : null,
|
|
1656
|
-
deleteError ? React.createElement('div', { className: 'mopsBanner err', role: 'alert' }, deleteError) : null,
|
|
1985
|
+
ref: searchRef,
|
|
1986
|
+
className: 'mopsSearch',
|
|
1987
|
+
value: query,
|
|
1988
|
+
placeholder: t('panel.searchHint'),
|
|
1989
|
+
'aria-label': t('panel.search'),
|
|
1990
|
+
onChange: e => {
|
|
1991
|
+
setQuery(e.target.value)
|
|
1992
|
+
clearPick()
|
|
1993
|
+
setScrollTop(0)
|
|
1994
|
+
if (listRef.current) listRef.current.scrollTop = 0
|
|
1995
|
+
},
|
|
1996
|
+
}),
|
|
1997
|
+
),
|
|
1998
|
+
React.createElement(
|
|
1999
|
+
'div',
|
|
2000
|
+
{ className: 'mopsChips' },
|
|
2001
|
+
['all', 'user', 'assistant', 'tool'].map(key =>
|
|
2002
|
+
React.createElement(
|
|
2003
|
+
'button',
|
|
2004
|
+
{
|
|
2005
|
+
key,
|
|
2006
|
+
type: 'button',
|
|
2007
|
+
className: 'mopsChip' + (role === key ? ' on' : ''),
|
|
2008
|
+
onClick: () => {
|
|
2009
|
+
setRole(key)
|
|
2010
|
+
clearPick()
|
|
2011
|
+
setScrollTop(0)
|
|
2012
|
+
if (listRef.current) listRef.current.scrollTop = 0
|
|
2013
|
+
},
|
|
2014
|
+
},
|
|
2015
|
+
t('panel.' + key),
|
|
2016
|
+
),
|
|
2017
|
+
),
|
|
2018
|
+
React.createElement(
|
|
2019
|
+
'label',
|
|
2020
|
+
{ className: 'mopsToggle' },
|
|
1657
2021
|
React.createElement('input', {
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
if (e.key === 'Enter') {
|
|
1666
|
-
e.preventDefault()
|
|
1667
|
-
if (canConfirmDelete) deleteSession()
|
|
1668
|
-
} else if (e.key === 'Escape') {
|
|
1669
|
-
e.preventDefault()
|
|
1670
|
-
e.stopPropagation()
|
|
1671
|
-
closeConfirm()
|
|
1672
|
-
}
|
|
2022
|
+
type: 'checkbox',
|
|
2023
|
+
checked: includeShadowed,
|
|
2024
|
+
onChange: e => {
|
|
2025
|
+
setIncludeShadowed(e.target.checked)
|
|
2026
|
+
clearPick()
|
|
2027
|
+
setScrollTop(0)
|
|
2028
|
+
if (listRef.current) listRef.current.scrollTop = 0
|
|
1673
2029
|
},
|
|
1674
2030
|
}),
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
2031
|
+
t('panel.includeShadowed'),
|
|
2032
|
+
),
|
|
2033
|
+
),
|
|
2034
|
+
React.createElement(
|
|
2035
|
+
'div',
|
|
2036
|
+
{
|
|
2037
|
+
className: 'mopsList',
|
|
2038
|
+
ref: listRef,
|
|
2039
|
+
role: state === 'ready' && rows.length ? 'listbox' : 'region',
|
|
2040
|
+
tabIndex: state === 'ready' && rows.length ? 0 : -1,
|
|
2041
|
+
'aria-label': t('panel.messages'),
|
|
2042
|
+
'aria-busy': state === 'loading' || showSearchLoading ? 'true' : undefined,
|
|
2043
|
+
'aria-activedescendant': state === 'ready' && activeRendered ? 'mops-opt-' + picked.seq : undefined,
|
|
2044
|
+
onKeyDown: handleListKeyDown,
|
|
2045
|
+
onScroll: e => setScrollTop(e.currentTarget.scrollTop),
|
|
2046
|
+
},
|
|
2047
|
+
state === 'loading' || state === 'idle'
|
|
2048
|
+
? React.createElement('div', { className: 'mopsEmpty', role: 'status', 'aria-live': 'polite' }, t('panel.loading'))
|
|
2049
|
+
: state === 'error'
|
|
2050
|
+
? React.createElement(
|
|
2051
|
+
'div',
|
|
2052
|
+
{ className: 'mopsEmpty mopsErrorState', role: 'alert' },
|
|
2053
|
+
React.createElement('span', null, loadError || t('panel.loadFail')),
|
|
2054
|
+
React.createElement(
|
|
2055
|
+
'button',
|
|
2056
|
+
{
|
|
2057
|
+
type: 'button',
|
|
2058
|
+
className: 'mopsAction',
|
|
2059
|
+
onClick: () => {
|
|
2060
|
+
loadMessages(false)
|
|
2061
|
+
setTimeout(() => {
|
|
2062
|
+
if (searchRef.current) searchRef.current.focus()
|
|
2063
|
+
}, 0)
|
|
2064
|
+
},
|
|
2065
|
+
},
|
|
2066
|
+
t('panel.retry'),
|
|
2067
|
+
),
|
|
2068
|
+
)
|
|
2069
|
+
: rows.length === 0
|
|
2070
|
+
? React.createElement(
|
|
2071
|
+
'div',
|
|
2072
|
+
{ className: 'mopsEmpty', role: 'status', 'aria-live': 'polite' },
|
|
2073
|
+
showSearchLoading ? t('panel.searching') : query.trim() ? t('panel.noMatch') : t('panel.empty'),
|
|
2074
|
+
)
|
|
2075
|
+
: React.createElement(
|
|
2076
|
+
'div',
|
|
2077
|
+
{ style: { height: rows.length * PANEL_ROW_H, position: 'relative' } },
|
|
2078
|
+
windowRows.map((m, i) =>
|
|
2079
|
+
React.createElement(
|
|
2080
|
+
'div',
|
|
2081
|
+
{
|
|
2082
|
+
key: m.seq,
|
|
2083
|
+
id: 'mops-opt-' + m.seq,
|
|
2084
|
+
role: 'option',
|
|
2085
|
+
'aria-selected': pickedLive && pickedLive.seq === m.seq,
|
|
2086
|
+
'aria-setsize': rows.length,
|
|
2087
|
+
'aria-posinset': start + i + 1,
|
|
2088
|
+
tabIndex: -1,
|
|
2089
|
+
className:
|
|
2090
|
+
'mopsRow' + (pickedLive && pickedLive.seq === m.seq ? ' on' : '') + (m.shadowed ? ' shadowed' : ''),
|
|
2091
|
+
style: { top: (start + i) * PANEL_ROW_H, height: PANEL_ROW_H },
|
|
2092
|
+
onClick: () => {
|
|
2093
|
+
pick(m)
|
|
2094
|
+
if (listRef.current) listRef.current.focus()
|
|
2095
|
+
},
|
|
2096
|
+
title: '#' + m.seq + ' ' + (m.role || '') + ' · ' + (m.snippet || ''),
|
|
2097
|
+
'aria-label':
|
|
2098
|
+
'#' +
|
|
2099
|
+
m.seq +
|
|
2100
|
+
' ' +
|
|
2101
|
+
(m.role || '') +
|
|
2102
|
+
(m.shadowed ? ' ' + t('panel.shadowed') : '') +
|
|
2103
|
+
' · ' +
|
|
2104
|
+
(m.snippet || '') +
|
|
2105
|
+
(m.time ? ' · ' + fmtClock(m.time) : ''),
|
|
2106
|
+
},
|
|
2107
|
+
React.createElement('span', { className: 'mopsSeq' }, '#' + m.seq),
|
|
2108
|
+
React.createElement('span', { className: 'mopsRole' }, roleCode(m.role)),
|
|
2109
|
+
React.createElement('span', { className: 'mopsSnippet' }, m.snippet || '—'),
|
|
2110
|
+
React.createElement('span', { className: 'mopsClock' }, fmtClock(m.time)),
|
|
2111
|
+
),
|
|
2112
|
+
),
|
|
2113
|
+
),
|
|
2114
|
+
),
|
|
2115
|
+
React.createElement(
|
|
2116
|
+
'div',
|
|
2117
|
+
{ className: 'mopsDetail' },
|
|
2118
|
+
pickedLive
|
|
2119
|
+
? React.createElement(
|
|
2120
|
+
React.Fragment,
|
|
2121
|
+
null,
|
|
2122
|
+
React.createElement(
|
|
2123
|
+
'div',
|
|
2124
|
+
{ className: 'mopsDetailMeta' },
|
|
2125
|
+
React.createElement('span', null, '#' + pickedLive.seq),
|
|
2126
|
+
React.createElement('span', null, pickedLive.role || ''),
|
|
2127
|
+
pickedLive.shadowed ? React.createElement('span', null, t('panel.shadowed')) : null,
|
|
2128
|
+
pickedLive.time ? React.createElement('span', null, fmtClock(pickedLive.time)) : null,
|
|
2129
|
+
),
|
|
2130
|
+
React.createElement(
|
|
2131
|
+
'pre',
|
|
2132
|
+
{ className: 'mopsDetailText' },
|
|
2133
|
+
detailState === 'loading' ? t('panel.detailLoading') : detail || pickedLive.snippet || '—',
|
|
2134
|
+
),
|
|
2135
|
+
React.createElement(
|
|
2136
|
+
'div',
|
|
2137
|
+
{ className: 'mopsActions' },
|
|
2138
|
+
React.createElement(
|
|
2139
|
+
'button',
|
|
2140
|
+
{
|
|
2141
|
+
type: 'button',
|
|
2142
|
+
className: 'mopsAction primary',
|
|
2143
|
+
disabled: !canAct || !!confirmAction,
|
|
2144
|
+
ref: revertBtnRef,
|
|
2145
|
+
onClick: () => setConfirmAction('revert'),
|
|
2146
|
+
title: t('panel.revertHint'),
|
|
2147
|
+
},
|
|
2148
|
+
t('panel.revert') + (revertCount ? ' · ' + revertCount : ''),
|
|
2149
|
+
),
|
|
2150
|
+
React.createElement(
|
|
2151
|
+
'button',
|
|
2152
|
+
{
|
|
2153
|
+
type: 'button',
|
|
2154
|
+
className: 'mopsAction danger',
|
|
2155
|
+
disabled: !canAct || !!confirmAction,
|
|
2156
|
+
ref: deleteOneBtnRef,
|
|
2157
|
+
onClick: () => setConfirmAction('delete'),
|
|
2158
|
+
title: t('panel.deleteHint'),
|
|
2159
|
+
},
|
|
2160
|
+
t('panel.delete'),
|
|
2161
|
+
),
|
|
2162
|
+
// 0.12.0:编辑只对用户消息可用 —— 直接把原文交回编辑器。
|
|
2163
|
+
// 无二次确认:它不改日志,只改草稿。
|
|
2164
|
+
React.createElement(
|
|
2165
|
+
'button',
|
|
2166
|
+
{
|
|
2167
|
+
type: 'button',
|
|
2168
|
+
className: 'mopsAction',
|
|
2169
|
+
disabled: !canEdit,
|
|
2170
|
+
title: pickedIsUser ? t('panel.editHint') : t('panel.branchUserOnly'),
|
|
2171
|
+
onClick: () => startEdit(detail || pickedLive.snippet || ''),
|
|
2172
|
+
},
|
|
2173
|
+
t('panel.edit'),
|
|
2174
|
+
),
|
|
2175
|
+
// 分叉同样只对用户消息可用(AI 消息没有可回填的原文),
|
|
2176
|
+
// 语义 = opencode 的 before:新会话不含此条,原文进新会话输入框。
|
|
2177
|
+
React.createElement(
|
|
2178
|
+
'button',
|
|
2179
|
+
{
|
|
2180
|
+
type: 'button',
|
|
2181
|
+
className: 'mopsAction',
|
|
2182
|
+
disabled: !canFork || !!confirmAction,
|
|
2183
|
+
onClick: () => runAction('branch'),
|
|
2184
|
+
title: pickedIsUser ? t('panel.branchHint') : t('panel.branchUserOnly'),
|
|
2185
|
+
},
|
|
2186
|
+
t('panel.branch'),
|
|
2187
|
+
),
|
|
2188
|
+
),
|
|
2189
|
+
confirmAction
|
|
2190
|
+
? React.createElement(
|
|
2191
|
+
'div',
|
|
2192
|
+
{
|
|
2193
|
+
className: 'mopsActionConfirm',
|
|
2194
|
+
ref: actionConfirmRef,
|
|
2195
|
+
role: 'group',
|
|
2196
|
+
tabIndex: -1,
|
|
2197
|
+
'aria-labelledby': 'mops-action-confirm-title',
|
|
2198
|
+
},
|
|
2199
|
+
React.createElement(
|
|
2200
|
+
'div',
|
|
2201
|
+
{ className: 'mopsImpactTitle', id: 'mops-action-confirm-title' },
|
|
2202
|
+
t(confirmAction === 'revert' ? 'panel.revertConfirmTitle' : 'panel.deleteConfirmTitle', {
|
|
2203
|
+
seq: String(pickedLive.seq),
|
|
2204
|
+
}),
|
|
2205
|
+
),
|
|
2206
|
+
React.createElement(
|
|
2207
|
+
'div',
|
|
2208
|
+
{ className: 'mopsImpact' },
|
|
2209
|
+
confirmAction === 'revert'
|
|
2210
|
+
? t('panel.revertConfirmBody', {
|
|
2211
|
+
start: String(pickedLive.seq),
|
|
2212
|
+
end: String(revertEnd),
|
|
2213
|
+
n: String(revertCount),
|
|
2214
|
+
v: String(revertVisibleCount),
|
|
2215
|
+
})
|
|
2216
|
+
: t('panel.deleteConfirmBody'),
|
|
2217
|
+
),
|
|
2218
|
+
React.createElement(
|
|
2219
|
+
'div',
|
|
2220
|
+
{ className: 'mopsConfirmRow' },
|
|
2221
|
+
React.createElement(
|
|
2222
|
+
'button',
|
|
2223
|
+
{
|
|
2224
|
+
type: 'button',
|
|
2225
|
+
className: 'mopsAction',
|
|
2226
|
+
onClick: cancelAction,
|
|
2227
|
+
disabled: !!busy,
|
|
2228
|
+
},
|
|
2229
|
+
t('panel.cancel'),
|
|
2230
|
+
),
|
|
2231
|
+
React.createElement(
|
|
2232
|
+
'button',
|
|
2233
|
+
{
|
|
2234
|
+
type: 'button',
|
|
2235
|
+
className: 'mopsAction danger',
|
|
2236
|
+
onClick: () => runAction(confirmAction, true),
|
|
2237
|
+
disabled: !!busy || !canAct,
|
|
2238
|
+
},
|
|
2239
|
+
busy === confirmAction
|
|
2240
|
+
? t('panel.busy')
|
|
2241
|
+
: t(confirmAction === 'revert' ? 'panel.confirmRevert' : 'panel.confirmDeleteOne'),
|
|
2242
|
+
),
|
|
2243
|
+
),
|
|
2244
|
+
)
|
|
2245
|
+
: null,
|
|
2246
|
+
)
|
|
2247
|
+
: React.createElement('div', { className: 'mopsDetailHint' }, t('panel.selectHint')),
|
|
2248
|
+
),
|
|
2249
|
+
React.createElement(
|
|
2250
|
+
'footer',
|
|
2251
|
+
{ className: 'mopsPanelFoot' },
|
|
2252
|
+
React.createElement(
|
|
2253
|
+
'span',
|
|
2254
|
+
{ className: 'mopsCount' },
|
|
2255
|
+
t('panel.count', { n: String(totalCount), v: String(visibleCount), s: String(shadowedCount) }),
|
|
2256
|
+
),
|
|
2257
|
+
React.createElement(
|
|
2258
|
+
'button',
|
|
2259
|
+
{
|
|
2260
|
+
type: 'button',
|
|
2261
|
+
className: 'mopsDanger',
|
|
2262
|
+
ref: deleteBtnRef,
|
|
2263
|
+
disabled: !!busy || !!deleteBlockedReason,
|
|
2264
|
+
title: deleteBlockedReason || undefined,
|
|
2265
|
+
onClick: () => {
|
|
2266
|
+
setConfirmTitle('')
|
|
2267
|
+
setDeleteError(null)
|
|
2268
|
+
setConfirmAction(null)
|
|
2269
|
+
setConfirmDelete(true)
|
|
2270
|
+
},
|
|
2271
|
+
},
|
|
2272
|
+
t('panel.deleteSession'),
|
|
2273
|
+
),
|
|
2274
|
+
),
|
|
2275
|
+
confirmDelete
|
|
2276
|
+
? React.createElement(
|
|
2277
|
+
'div',
|
|
2278
|
+
{
|
|
2279
|
+
className: 'mopsConfirm',
|
|
2280
|
+
ref: confirmRef,
|
|
2281
|
+
role: 'alertdialog',
|
|
2282
|
+
'aria-modal': 'true',
|
|
2283
|
+
'aria-labelledby': 'mops-delete-title',
|
|
2284
|
+
'aria-describedby': 'mops-delete-hint mops-delete-impact',
|
|
2285
|
+
tabIndex: -1,
|
|
2286
|
+
},
|
|
2287
|
+
React.createElement('h3', { id: 'mops-delete-title' }, t('panel.deleteSession')),
|
|
2288
|
+
React.createElement('p', { id: 'mops-delete-hint' }, t('panel.deleteSessionHint')),
|
|
2289
|
+
React.createElement(
|
|
2290
|
+
'p',
|
|
2291
|
+
{ className: 'mopsImpact', id: 'mops-delete-impact' },
|
|
2292
|
+
t('panel.deleteSessionImpact', { n: String(totalCount) }),
|
|
2293
|
+
),
|
|
2294
|
+
target.running
|
|
2295
|
+
? React.createElement('div', { className: 'mopsBanner warn', role: 'status' }, t('panel.running'))
|
|
2296
|
+
: null,
|
|
2297
|
+
deleteError ? React.createElement('div', { className: 'mopsBanner err', role: 'alert' }, deleteError) : null,
|
|
2298
|
+
React.createElement('input', {
|
|
2299
|
+
id: 'mops-delete-title-input',
|
|
2300
|
+
value: confirmTitle,
|
|
2301
|
+
autoFocus: true,
|
|
2302
|
+
'aria-label': t('panel.deleteSessionHint'),
|
|
2303
|
+
'aria-describedby': 'mops-delete-hint',
|
|
2304
|
+
placeholder: expectedDeleteTitle || target.title || target.sessionId,
|
|
2305
|
+
disabled: !!busy || target.running || !expectedDeleteTitle,
|
|
2306
|
+
onChange: e => setConfirmTitle(e.target.value),
|
|
2307
|
+
onKeyDown: e => {
|
|
2308
|
+
if (e.key === 'Enter') {
|
|
2309
|
+
e.preventDefault()
|
|
2310
|
+
if (canConfirmDelete) deleteSession()
|
|
2311
|
+
} else if (e.key === 'Escape') {
|
|
2312
|
+
e.preventDefault()
|
|
2313
|
+
e.stopPropagation()
|
|
2314
|
+
closeConfirm()
|
|
2315
|
+
}
|
|
2316
|
+
},
|
|
2317
|
+
}),
|
|
2318
|
+
React.createElement(
|
|
2319
|
+
'div',
|
|
2320
|
+
{ className: 'mopsConfirmRow' },
|
|
2321
|
+
React.createElement(
|
|
2322
|
+
'button',
|
|
2323
|
+
{
|
|
2324
|
+
type: 'button',
|
|
2325
|
+
className: 'mopsAction',
|
|
2326
|
+
onClick: closeConfirm,
|
|
2327
|
+
disabled: busy === 'session-delete',
|
|
2328
|
+
},
|
|
2329
|
+
t('panel.cancel'),
|
|
2330
|
+
),
|
|
2331
|
+
React.createElement(
|
|
2332
|
+
'button',
|
|
2333
|
+
{
|
|
2334
|
+
type: 'button',
|
|
2335
|
+
className: 'mopsAction danger',
|
|
2336
|
+
disabled: !canConfirmDelete,
|
|
2337
|
+
onClick: deleteSession,
|
|
2338
|
+
},
|
|
2339
|
+
busy === 'session-delete' ? t('panel.deleting') : t('panel.confirmDelete'),
|
|
2340
|
+
),
|
|
2341
|
+
),
|
|
2342
|
+
)
|
|
2343
|
+
: null,
|
|
2344
|
+
)
|
|
2345
|
+
: React.createElement(
|
|
2346
|
+
'div',
|
|
2347
|
+
{ className: 'mopsList', style: { borderTop: 0 }, 'aria-busy': trashState === 'loading' ? 'true' : undefined },
|
|
1687
2348
|
trashState === 'loading' || trashState === 'idle'
|
|
1688
2349
|
? React.createElement('div', { className: 'mopsEmpty', role: 'status', 'aria-live': 'polite' }, t('panel.loading'))
|
|
1689
2350
|
: trashState === 'error'
|
|
1690
|
-
? React.createElement(
|
|
2351
|
+
? React.createElement(
|
|
2352
|
+
'div',
|
|
2353
|
+
{ className: 'mopsEmpty mopsErrorState', role: 'alert' },
|
|
1691
2354
|
React.createElement('span', null, trashError || t('panel.loadFail')),
|
|
1692
|
-
React.createElement(
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
2355
|
+
React.createElement(
|
|
2356
|
+
'button',
|
|
2357
|
+
{
|
|
2358
|
+
type: 'button',
|
|
2359
|
+
className: 'mopsAction',
|
|
2360
|
+
onClick: () => {
|
|
2361
|
+
loadTrash()
|
|
2362
|
+
setTimeout(() => {
|
|
2363
|
+
if (panelRef.current) panelRef.current.focus()
|
|
2364
|
+
}, 0)
|
|
2365
|
+
},
|
|
2366
|
+
},
|
|
2367
|
+
t('panel.retry'),
|
|
2368
|
+
),
|
|
2369
|
+
)
|
|
1696
2370
|
: trash.length === 0
|
|
1697
2371
|
? React.createElement('div', { className: 'mopsEmpty' }, t('panel.trashEmpty'))
|
|
1698
|
-
: trash.map(
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
2372
|
+
: trash.map(item =>
|
|
2373
|
+
React.createElement(
|
|
2374
|
+
'div',
|
|
2375
|
+
{ className: 'mopsTrashItem', key: item.trashId },
|
|
2376
|
+
React.createElement(
|
|
2377
|
+
'div',
|
|
2378
|
+
{ className: 'mopsTrashMain' },
|
|
2379
|
+
React.createElement('div', { className: 'mopsTrashTitle' }, item.title || t('panel.untitled')),
|
|
2380
|
+
React.createElement(
|
|
2381
|
+
'div',
|
|
2382
|
+
{ className: 'mopsTrashMeta' },
|
|
2383
|
+
item.sessionId +
|
|
2384
|
+
(item.expiresAt ? ' · ' + t('panel.expires') + ' ' + new Date(item.expiresAt).toLocaleDateString() : ''),
|
|
2385
|
+
),
|
|
2386
|
+
),
|
|
2387
|
+
React.createElement(
|
|
2388
|
+
'button',
|
|
2389
|
+
{
|
|
2390
|
+
type: 'button',
|
|
2391
|
+
className: 'mopsAction',
|
|
2392
|
+
disabled: !!busy,
|
|
2393
|
+
onClick: () => restoreEntry(item.trashId),
|
|
2394
|
+
},
|
|
2395
|
+
busy === 'restore:' + item.trashId ? t('panel.busy') : t('panel.restore'),
|
|
2396
|
+
),
|
|
2397
|
+
React.createElement(
|
|
2398
|
+
'button',
|
|
2399
|
+
{
|
|
2400
|
+
type: 'button',
|
|
2401
|
+
className: 'mopsAction danger',
|
|
2402
|
+
disabled: !!busy,
|
|
2403
|
+
onClick: () => purgeEntry(item.trashId),
|
|
2404
|
+
},
|
|
2405
|
+
busy === 'purge:' + item.trashId
|
|
2406
|
+
? t('panel.busy')
|
|
2407
|
+
: purgeId === item.trashId
|
|
2408
|
+
? t('panel.purgeConfirm')
|
|
2409
|
+
: t('panel.purge'),
|
|
2410
|
+
),
|
|
2411
|
+
),
|
|
2412
|
+
),
|
|
2413
|
+
),
|
|
2414
|
+
),
|
|
2415
|
+
)
|
|
1711
2416
|
}
|
|
1712
2417
|
|
|
1713
2418
|
// --- 头部按钮 ---------------------------------------------------------------
|
|
@@ -1720,32 +2425,151 @@ window.__ModuleLoader__.load({
|
|
|
1720
2425
|
return { kind: 'disk' }
|
|
1721
2426
|
}
|
|
1722
2427
|
|
|
2428
|
+
// --- 0.12.0 消息级分叉(opencode 语义:分叉点**排他**,原文回到新会话输入框)-----
|
|
2429
|
+
//
|
|
2430
|
+
// 官方 `sessions.fork(source, boundary)` 的 boundary 是**闭区间**(含该事件)。
|
|
2431
|
+
// opencode 的 fork 是 before 语义(不含该条用户消息)+ 把该条放回新会话 composer。
|
|
2432
|
+
// 两者要一致,就必须把边界退到「该用户消息所在 turn 之前」。
|
|
2433
|
+
//
|
|
2434
|
+
// ⚠️ 不能退到 `seq - 1`。实测 40 份语料:真人输入的前一个事件**恒是同一 turn
|
|
2435
|
+
// 内的 system/message**(turn/start → agent/inbox/spliced → step/start →
|
|
2436
|
+
// system/message → user/message)。按 seq-1 切会得到一个「turn/step 已开、
|
|
2437
|
+
// 却没有任何 user 消息」的悬空前缀,引擎必须补合成 closers,语义也不是
|
|
2438
|
+
// 用户要的「这条之前」。
|
|
2439
|
+
// 正确边界 = 该 turn 的 turn/start seq 的**前一个**事件(`turnStartSeq - 1`)。
|
|
2440
|
+
// 服务端在 `GET /messages?view=compact` 里直接给出 `turnStartSeq`(见
|
|
2441
|
+
// src/index.js buildDerived),客户端不猜。
|
|
2442
|
+
const FORK_SESSION_STORAGE_PREFIX = 'dsh.conversation.'
|
|
2443
|
+
|
|
2444
|
+
/**
|
|
2445
|
+
* 官方 fork 边界(inclusive):目标用户消息所在 turn 的 turn/start 前一个事件。
|
|
2446
|
+
*
|
|
2447
|
+
* @param seq - 目标用户消息的日志 seq(仅用于无 turn 信息时的保守回退)
|
|
2448
|
+
* @param turnStartSeq - 该消息所在 turn 的 turn/start seq;服务端 compact 视图提供
|
|
2449
|
+
* @returns 可直接作为 `sessions.fork({ atSeq })` 的闭区间边界;不可分叉时 -1
|
|
2450
|
+
*/
|
|
2451
|
+
function forkBoundaryBefore(seq, turnStartSeq) {
|
|
2452
|
+
// 首选:按轮切(服务端已给出 turnStartSeq)
|
|
2453
|
+
if (Number.isSafeInteger(turnStartSeq) && turnStartSeq > 0) return turnStartSeq - 1
|
|
2454
|
+
// 回退:没有 turn 信息(老服务端 / 合成行)时退一格。
|
|
2455
|
+
// 这时切点可能落在 turn 内部,官方会补合成 closers —— 结果仍可加载,
|
|
2456
|
+
// 只是前缀边界不如按轮切干净。宁可这样也不静默不分叉。
|
|
2457
|
+
return Number.isSafeInteger(seq) && seq > 0 ? seq - 1 : -1
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2460
|
+
/**
|
|
2461
|
+
* 官方 assistant turn-tail 的 branch 按钮识别(0.12.0)。
|
|
2462
|
+
*
|
|
2463
|
+
* 为什么不能靠 aria-label:官方文案有 8 种语言(zh/en/ja/es/fr/de/ru/pt),
|
|
2464
|
+
* 逐个匹配等于把 i18n 表抄进来。也不能靠 class:CSS Modules 会哈希前缀
|
|
2465
|
+
* (实测 0.2.0-rc.2 是 `xzv4MW_`,0.2.1 起变过)。
|
|
2466
|
+
* 唯一稳定的是**图标几何**:官方 `IconBranchOutline16` 的 path d 是常量
|
|
2467
|
+
* (packages/client/ui-primitives/src/icons/index.tsx:149)。
|
|
2468
|
+
* 我们自己的分叉按钮复用同一 path,所以必须显式排除。
|
|
2469
|
+
*
|
|
2470
|
+
* @param btn - 候选按钮(任意元素;非 button 的宿主节点返回 false)
|
|
2471
|
+
* @returns 是否官方 branch 按钮
|
|
2472
|
+
*/
|
|
2473
|
+
const HOST_BRANCH_D_PREFIX = 'M13.0762 1.37207'
|
|
2474
|
+
const HOST_BRANCH_CLASS = 'mopsUserFork'
|
|
2475
|
+
function isHostBranchButton(btn) {
|
|
2476
|
+
if (!btn || typeof btn.querySelector !== 'function') return false
|
|
2477
|
+
const cls = String((btn.classList && btn.classList.value) || btn.className || '')
|
|
2478
|
+
if (cls.split(/\s+/).includes(HOST_BRANCH_CLASS)) return false
|
|
2479
|
+
const path = btn.querySelector('svg path')
|
|
2480
|
+
const d = path ? path.getAttribute('d') || '' : ''
|
|
2481
|
+
return d.startsWith(HOST_BRANCH_D_PREFIX)
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2484
|
+
/**
|
|
2485
|
+
* 把文本预置成某个会话的草稿(新会话刚 fork 出来时输入框是空的)。
|
|
2486
|
+
*
|
|
2487
|
+
* 为什么直接写 localStorage 而不是 `inputActions.setDraft`:fork 出来的是一个**还没
|
|
2488
|
+
* 挂载**的会话,此刻 `inputActions` 仍绑定在源会话上;宿主挂载新会话时会用
|
|
2489
|
+
* `readConversationDraft(sessionId)` 从 localStorage 初始化编辑器。所以**先落盘再
|
|
2490
|
+
* openSession** 才是无竞态的路径(`{ draft: '<text>' }` 是宿主 `parseStoredDraft`
|
|
2491
|
+
* 支持的字符串形态,见 dsh-client-ui-conversation:4455-4456)。
|
|
2492
|
+
*/
|
|
2493
|
+
function writeSessionDraft(childSessionId, text) {
|
|
2494
|
+
try {
|
|
2495
|
+
if (!childSessionId || typeof localStorage === 'undefined') return false
|
|
2496
|
+
localStorage.setItem(FORK_SESSION_STORAGE_PREFIX + childSessionId, JSON.stringify({ draft: String(text || '') }))
|
|
2497
|
+
return true
|
|
2498
|
+
} catch (e) {
|
|
2499
|
+
console.warn('[message-ops] writeSessionDraft failed:', e)
|
|
2500
|
+
return false
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
|
|
2504
|
+
/** 打开会话(宿主唯一通道)。childId 需要 `session-` 前缀才不会抛 unknown session。 */
|
|
2505
|
+
function openSessionById(sessionId) {
|
|
2506
|
+
try {
|
|
2507
|
+
if (__uiWorkspace && typeof __uiWorkspace.openSession === 'function') {
|
|
2508
|
+
__uiWorkspace.openSession(sessionId)
|
|
2509
|
+
return true
|
|
2510
|
+
}
|
|
2511
|
+
} catch (e) {
|
|
2512
|
+
console.warn('[message-ops] openSession failed:', e)
|
|
2513
|
+
}
|
|
2514
|
+
return false
|
|
2515
|
+
}
|
|
2516
|
+
|
|
2517
|
+
/**
|
|
2518
|
+
* 从一条**用户消息**分叉:复制到该条之前,并把该条原文放回新会话输入框。
|
|
2519
|
+
*
|
|
2520
|
+
* @param sessionId - 源会话 id(前缀写法都接受,官方 store 自己归一)。
|
|
2521
|
+
* @param seq - 目标用户消息的日志 seq。
|
|
2522
|
+
* @param text - 该条用户消息原文;缺省时新会话输入框留空。
|
|
2523
|
+
* @returns 新会话 id。
|
|
2524
|
+
* @throws 无官方 fork、seq 无前驱、或宿主拒绝(会话运行中)时抛出可展示的错误。
|
|
2525
|
+
*/
|
|
2526
|
+
async function forkFromUserMessage(sessionId, seq, text, turnStartSeq) {
|
|
2527
|
+
const forkPath = pickForkPath(__sessionsSvc)
|
|
2528
|
+
if (forkPath.kind !== 'official') throw new Error(__t('slot.forkUnavailable'))
|
|
2529
|
+
const boundary = forkBoundaryBefore(seq, turnStartSeq)
|
|
2530
|
+
if (boundary < 0) throw new Error(__t('slot.forkUnavailable'))
|
|
2531
|
+
const childId = await forkPath.fork({ sessionId, atSeq: boundary, increaseTitle: true })
|
|
2532
|
+
if (childId && text) writeSessionDraft(childId, text)
|
|
2533
|
+
return childId
|
|
2534
|
+
}
|
|
2535
|
+
|
|
1723
2536
|
// 成功反馈统一出口:devkit 标准 toast 优先,无 devkit 时对话框内文案兜底。
|
|
1724
2537
|
function notifyDone(msg, kind) {
|
|
1725
2538
|
try {
|
|
1726
2539
|
const dk = window.__dshDevkit
|
|
1727
2540
|
if (dk && typeof dk.toast === 'function') dk.toast(msg, { kind: kind || 'ok' })
|
|
1728
|
-
} catch {
|
|
2541
|
+
} catch {
|
|
2542
|
+
/* toast 缺席不阻断成功反馈 */
|
|
2543
|
+
}
|
|
1729
2544
|
}
|
|
1730
2545
|
|
|
1731
2546
|
function OpsButton(props) {
|
|
1732
2547
|
const { sessionId, useSessions } = props
|
|
1733
2548
|
const t = (props && props.t) || __t
|
|
1734
2549
|
useLocaleRevision()
|
|
1735
|
-
const sessions = useSessions ? useSessions(
|
|
2550
|
+
const sessions = useSessions ? useSessions(s => s) : undefined
|
|
1736
2551
|
const summary = sessions && sessions.byId ? sessions.byId[sessionId] : undefined
|
|
1737
2552
|
const running = summary ? summary.running === true : false
|
|
1738
2553
|
|
|
1739
2554
|
const openDialog = useCallback(() => {
|
|
1740
|
-
window.dispatchEvent(
|
|
1741
|
-
|
|
1742
|
-
|
|
2555
|
+
window.dispatchEvent(
|
|
2556
|
+
new CustomEvent(EVENT, {
|
|
2557
|
+
detail: { sessionId, title: summary && summary.title ? summary.title : null, running },
|
|
2558
|
+
}),
|
|
2559
|
+
)
|
|
1743
2560
|
}, [sessionId, summary, running])
|
|
1744
2561
|
|
|
1745
|
-
return React.createElement(
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
2562
|
+
return React.createElement(
|
|
2563
|
+
'button',
|
|
2564
|
+
{
|
|
2565
|
+
type: 'button',
|
|
2566
|
+
title: t('button.title'),
|
|
2567
|
+
'aria-label': t('button.title'),
|
|
2568
|
+
style: btnStyle,
|
|
2569
|
+
onClick: openDialog,
|
|
2570
|
+
},
|
|
2571
|
+
React.createElement(BranchIcon),
|
|
2572
|
+
)
|
|
1749
2573
|
}
|
|
1750
2574
|
|
|
1751
2575
|
// 官方图标适配:0.2.0 primitives 的 IconClock 与原生操作行同款;
|
|
@@ -1756,22 +2580,38 @@ window.__ModuleLoader__.load({
|
|
|
1756
2580
|
try {
|
|
1757
2581
|
const P = require('@deepseek-ai/dsh-client-ui-primitives')
|
|
1758
2582
|
IconClock = P && P.IconClockOutlineRegular
|
|
1759
|
-
} catch {
|
|
1760
|
-
|
|
1761
|
-
// 官方 IconClockOutlineArtwork 1:1 路径( Regular = 1px stroke)
|
|
1762
|
-
return React.createElement('svg', { width: 16, height: 16, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': true, stroke: 'currentColor', strokeWidth: 1 },
|
|
1763
|
-
React.createElement('path', { d: 'M8 14C11.3137 14 14 11.3137 14 8C14 4.68629 11.3137 2 8 2C4.68629 2 2 4.68629 2 8C2 11.3137 4.68629 14 8 14Z' }),
|
|
1764
|
-
React.createElement('path', { d: 'M8 4.31V8.46L11 10.08' }))
|
|
2583
|
+
} catch {
|
|
2584
|
+
/* fallback below */
|
|
1765
2585
|
}
|
|
2586
|
+
if (!IconClock)
|
|
2587
|
+
IconClock = function ClockFallback() {
|
|
2588
|
+
// 官方 IconClockOutlineArtwork 1:1 路径( Regular = 1px stroke)
|
|
2589
|
+
return React.createElement(
|
|
2590
|
+
'svg',
|
|
2591
|
+
{ width: 16, height: 16, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': true, stroke: 'currentColor', strokeWidth: 1 },
|
|
2592
|
+
React.createElement('path', {
|
|
2593
|
+
d: 'M8 14C11.3137 14 14 11.3137 14 8C14 4.68629 11.3137 2 8 2C4.68629 2 2 4.68629 2 8C2 11.3137 4.68629 14 8 14Z',
|
|
2594
|
+
}),
|
|
2595
|
+
React.createElement('path', { d: 'M8 4.31V8.46L11 10.08' }),
|
|
2596
|
+
)
|
|
2597
|
+
}
|
|
1766
2598
|
var IconQuote = null
|
|
1767
2599
|
try {
|
|
1768
2600
|
const P2 = require('@deepseek-ai/dsh-client-ui-primitives')
|
|
1769
2601
|
IconQuote = P2 && (P2.IconChatOutlineRegular || P2.IconCopyOutlineRegular)
|
|
1770
|
-
} catch {
|
|
1771
|
-
|
|
1772
|
-
return React.createElement('svg', { width: 16, height: 16, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': true, stroke: 'currentColor', strokeWidth: 1 },
|
|
1773
|
-
React.createElement('path', { d: 'M3 6.5A3.5 3.5 0 0 1 6.5 3H7v1.5h-.5A2 2 0 0 0 4.5 6.5V7H7v3.5H3V6.5ZM9 6.5A3.5 3.5 0 0 1 12.5 3H13v1.5h-.5A2 2 0 0 0 10.5 6.5V7H13v3.5H9V6.5Z' }))
|
|
2602
|
+
} catch {
|
|
2603
|
+
/* fallback below */
|
|
1774
2604
|
}
|
|
2605
|
+
if (!IconQuote)
|
|
2606
|
+
IconQuote = function QuoteFallback() {
|
|
2607
|
+
return React.createElement(
|
|
2608
|
+
'svg',
|
|
2609
|
+
{ width: 16, height: 16, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': true, stroke: 'currentColor', strokeWidth: 1 },
|
|
2610
|
+
React.createElement('path', {
|
|
2611
|
+
d: 'M3 6.5A3.5 3.5 0 0 1 6.5 3H7v1.5h-.5A2 2 0 0 0 4.5 6.5V7H7v3.5H3V6.5ZM9 6.5A3.5 3.5 0 0 1 12.5 3H13v1.5h-.5A2 2 0 0 0 10.5 6.5V7H13v3.5H9V6.5Z',
|
|
2612
|
+
}),
|
|
2613
|
+
)
|
|
2614
|
+
}
|
|
1775
2615
|
|
|
1776
2616
|
// --- 0.3.0 assistant-actions 官方槽:每条 AI 消息旁的原生回撤按钮 ------------
|
|
1777
2617
|
// 契约(dsh-cordis-client-runner):scope session,条目组件收 { messageId } +
|
|
@@ -1785,7 +2625,7 @@ window.__ModuleLoader__.load({
|
|
|
1785
2625
|
const t = (props && props.t) || __t
|
|
1786
2626
|
useLocaleRevision()
|
|
1787
2627
|
if (inputActions && typeof inputActions.setDraft === 'function') __inputActions = inputActions
|
|
1788
|
-
const sessions = useSessions ? useSessions(
|
|
2628
|
+
const sessions = useSessions ? useSessions(s => s) : undefined
|
|
1789
2629
|
const summary = sessions && sessions.byId ? sessions.byId[sessionId] : undefined
|
|
1790
2630
|
const running = summary ? summary.running === true : false
|
|
1791
2631
|
const [seq, setSeq] = React.useState(null)
|
|
@@ -1795,7 +2635,7 @@ window.__ModuleLoader__.load({
|
|
|
1795
2635
|
// 没有回撤/引用按钮」—— 已经挂载的槽位 effect 不会因缓存被换而重跑。
|
|
1796
2636
|
const [idxRev, setIdxRev] = React.useState(0)
|
|
1797
2637
|
React.useEffect(() => {
|
|
1798
|
-
const onIdx = () => setIdxRev(
|
|
2638
|
+
const onIdx = () => setIdxRev(v => v + 1)
|
|
1799
2639
|
window.addEventListener(SEQ_INDEX_EVENT, onIdx)
|
|
1800
2640
|
return () => window.removeEventListener(SEQ_INDEX_EVENT, onIdx)
|
|
1801
2641
|
}, [])
|
|
@@ -1804,31 +2644,35 @@ window.__ModuleLoader__.load({
|
|
|
1804
2644
|
let alive = true
|
|
1805
2645
|
let retried = false
|
|
1806
2646
|
const load = () => {
|
|
1807
|
-
const p = fetchMessagesJson('/api/message-ops/messages?sessionId=' + encodeURIComponent(sessionId))
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
})
|
|
2647
|
+
const p = fetchMessagesJson('/api/message-ops/messages?sessionId=' + encodeURIComponent(sessionId)).then(data => {
|
|
2648
|
+
const index = new Map()
|
|
2649
|
+
const full = new Map()
|
|
2650
|
+
for (const m of (data && data.messages) || []) {
|
|
2651
|
+
// 0.5.2(P2):同 id 取**最早** seq——与服务端 buildSeqIndex 口径一致
|
|
2652
|
+
// (重试链取最早可见节点;此前内联 set 覆盖=取最大,双实现分裂)
|
|
2653
|
+
if (m && m.id != null && !index.has(String(m.id))) index.set(String(m.id), m.seq)
|
|
2654
|
+
if (m && m.id != null && m.fullText) full.set(String(m.id), m.fullText)
|
|
2655
|
+
}
|
|
2656
|
+
__seqIndexCache.set(sessionId, index)
|
|
2657
|
+
__fullTextCache.set(sessionId, full)
|
|
2658
|
+
return index
|
|
2659
|
+
})
|
|
1821
2660
|
__seqIndexCache.set(sessionId, p)
|
|
1822
2661
|
// 0.5.2(P2):失败必须清缓存——否则 rejected promise 被永久缓存,
|
|
1823
2662
|
// 该会话按钮/dock 到刷新页面为止全部失效
|
|
1824
2663
|
// 0.9.7:只在缓存里还是**我们这条** promise 时才删(syncSeqIndex 可能已换掉)
|
|
1825
|
-
p.catch(() => {
|
|
2664
|
+
p.catch(() => {
|
|
2665
|
+
if (__seqIndexCache.get(sessionId) === p) __seqIndexCache.delete(sessionId)
|
|
2666
|
+
})
|
|
1826
2667
|
return p
|
|
1827
2668
|
}
|
|
1828
|
-
const resolve =
|
|
2669
|
+
const resolve = index => {
|
|
1829
2670
|
if (!alive) return
|
|
1830
2671
|
const hit = index && index.get(String(messageId))
|
|
1831
|
-
if (typeof hit === 'number') {
|
|
2672
|
+
if (typeof hit === 'number') {
|
|
2673
|
+
setSeq(hit)
|
|
2674
|
+
return
|
|
2675
|
+
}
|
|
1832
2676
|
// 0.9.7(P4):索引里没有这个 messageId = 会话已增长(或索引过期)。
|
|
1833
2677
|
// 旧实现这里**什么都不做**,`seq` 永远是 null → 组件 return null →
|
|
1834
2678
|
// 按钮再也不渲染。现在失效并重拉一次(retried 保证不自旋);
|
|
@@ -1837,13 +2681,20 @@ window.__ModuleLoader__.load({
|
|
|
1837
2681
|
retried = true
|
|
1838
2682
|
__seqIndexCache.delete(sessionId)
|
|
1839
2683
|
__fullTextCache.delete(sessionId)
|
|
1840
|
-
load()
|
|
2684
|
+
load()
|
|
2685
|
+
.then(resolve)
|
|
2686
|
+
.catch(() => {})
|
|
1841
2687
|
}
|
|
1842
2688
|
const cached = __seqIndexCache.get(sessionId)
|
|
1843
2689
|
if (cached && typeof cached.then === 'function') cached.then(resolve).catch(() => {})
|
|
1844
2690
|
else if (cached) resolve(cached)
|
|
1845
|
-
else
|
|
1846
|
-
|
|
2691
|
+
else
|
|
2692
|
+
load()
|
|
2693
|
+
.then(resolve)
|
|
2694
|
+
.catch(() => {})
|
|
2695
|
+
return () => {
|
|
2696
|
+
alive = false
|
|
2697
|
+
}
|
|
1847
2698
|
}, [messageId, sessionId, idxRev])
|
|
1848
2699
|
|
|
1849
2700
|
// 原文(引用用):seq 解析后按需取全文
|
|
@@ -1851,14 +2702,16 @@ window.__ModuleLoader__.load({
|
|
|
1851
2702
|
if (seq == null || !sessionId) return
|
|
1852
2703
|
let alive = true
|
|
1853
2704
|
const cached = __fullTextCache.get(sessionId)
|
|
1854
|
-
const resolve =
|
|
2705
|
+
const resolve = full => {
|
|
1855
2706
|
if (!alive) return
|
|
1856
2707
|
const hit = full && full.get(String(messageId))
|
|
1857
2708
|
if (typeof hit === 'string') setFullText(hit)
|
|
1858
2709
|
}
|
|
1859
2710
|
if (cached && typeof cached.then === 'function') cached.then(resolve).catch(() => {})
|
|
1860
2711
|
else if (cached) resolve(cached)
|
|
1861
|
-
return () => {
|
|
2712
|
+
return () => {
|
|
2713
|
+
alive = false
|
|
2714
|
+
}
|
|
1862
2715
|
}, [seq, messageId, sessionId])
|
|
1863
2716
|
|
|
1864
2717
|
// 0.5.0 回撤后的视图刷新:openSession(reveal) 重建会话视图 → 遮蔽立即呈现。
|
|
@@ -1869,7 +2722,9 @@ window.__ModuleLoader__.load({
|
|
|
1869
2722
|
__uiWorkspace.openSession(sessionId)
|
|
1870
2723
|
return true
|
|
1871
2724
|
}
|
|
1872
|
-
} catch {
|
|
2725
|
+
} catch {
|
|
2726
|
+
/* fallthrough */
|
|
2727
|
+
}
|
|
1873
2728
|
return false
|
|
1874
2729
|
}
|
|
1875
2730
|
|
|
@@ -1879,14 +2734,21 @@ window.__ModuleLoader__.load({
|
|
|
1879
2734
|
// 0.5.2(P2):Promise.resolve 包裹——fetch/stringify 同步抛出也转为
|
|
1880
2735
|
// rejection 落进 finally,busy 永不卡死
|
|
1881
2736
|
Promise.resolve()
|
|
1882
|
-
.then(() =>
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
2737
|
+
.then(() =>
|
|
2738
|
+
fetch('/api/message-ops/revert', {
|
|
2739
|
+
method: 'POST',
|
|
2740
|
+
headers: { 'content-type': 'application/json' },
|
|
2741
|
+
body: JSON.stringify({ sessionId, seq }),
|
|
2742
|
+
}),
|
|
2743
|
+
)
|
|
2744
|
+
.then(async res => {
|
|
1887
2745
|
let data = {}
|
|
1888
|
-
try {
|
|
1889
|
-
|
|
2746
|
+
try {
|
|
2747
|
+
data = await res.json()
|
|
2748
|
+
} catch {
|
|
2749
|
+
/* keep {} */
|
|
2750
|
+
}
|
|
2751
|
+
if (!res.ok || !data.ok) throw new Error(data.error || 'HTTP ' + res.status)
|
|
1890
2752
|
notifyDone(t('done.revert'))
|
|
1891
2753
|
// 0.9.6:回填被删掉的那句用户原文(边界是 AI 消息时取它之前那条用户消息)。
|
|
1892
2754
|
// 此前这个入口完全不回填 —— 表现就是「回滚成功但消息框空着」。
|
|
@@ -1894,7 +2756,7 @@ window.__ModuleLoader__.load({
|
|
|
1894
2756
|
revealSession()
|
|
1895
2757
|
emitChanged()
|
|
1896
2758
|
})
|
|
1897
|
-
.catch(
|
|
2759
|
+
.catch(reason => {
|
|
1898
2760
|
notifyDone(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error')
|
|
1899
2761
|
})
|
|
1900
2762
|
.finally(() => setBusy(null))
|
|
@@ -1908,17 +2770,27 @@ window.__ModuleLoader__.load({
|
|
|
1908
2770
|
return
|
|
1909
2771
|
}
|
|
1910
2772
|
const span = inputActions.captureInsertion()
|
|
1911
|
-
const insertQuote =
|
|
1912
|
-
if (text == null || text === '') {
|
|
1913
|
-
|
|
2773
|
+
const insertQuote = text => {
|
|
2774
|
+
if (text == null || text === '') {
|
|
2775
|
+
notifyDone(t('quote.unavailable'), 'warn')
|
|
2776
|
+
return
|
|
2777
|
+
}
|
|
2778
|
+
const quoted =
|
|
2779
|
+
text
|
|
2780
|
+
.split('\n')
|
|
2781
|
+
.map(l => '> ' + l)
|
|
2782
|
+
.join('\n') + '\n\n'
|
|
1914
2783
|
const ok = inputActions.insertText(quoted, span)
|
|
1915
2784
|
notifyDone(ok ? t('quote.done') : t('quote.unavailable'), ok ? 'ok' : 'warn')
|
|
1916
2785
|
}
|
|
1917
2786
|
// assistant 消息 fullText 恒 null(列表不携带)→ 按 seq 向服务端取单条全文
|
|
1918
|
-
if (fullText != null && fullText !== '') {
|
|
2787
|
+
if (fullText != null && fullText !== '') {
|
|
2788
|
+
insertQuote(fullText)
|
|
2789
|
+
return
|
|
2790
|
+
}
|
|
1919
2791
|
fetch('/api/message-ops/text?sessionId=' + encodeURIComponent(sessionId) + '&seq=' + encodeURIComponent(seq))
|
|
1920
|
-
.then(
|
|
1921
|
-
.then(
|
|
2792
|
+
.then(r => (r.ok ? r.json() : null))
|
|
2793
|
+
.then(d => insertQuote(d && d.ok && typeof d.text === 'string' ? d.text : null))
|
|
1922
2794
|
.catch(() => insertQuote(null))
|
|
1923
2795
|
} catch (e) {
|
|
1924
2796
|
notifyDone(t('errorPrefix') + (e && e.message ? e.message : String(e)), 'error')
|
|
@@ -1926,16 +2798,35 @@ window.__ModuleLoader__.load({
|
|
|
1926
2798
|
}
|
|
1927
2799
|
|
|
1928
2800
|
if (seq == null) return null
|
|
1929
|
-
const act = (icon, label, mode, onClick, disabled) =>
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
2801
|
+
const act = (icon, label, mode, onClick, disabled) =>
|
|
2802
|
+
React.createElement(
|
|
2803
|
+
'button',
|
|
2804
|
+
{
|
|
2805
|
+
type: 'button',
|
|
2806
|
+
title: running && mode === 'revert' ? t('dialog.runningWarn') : label,
|
|
2807
|
+
'aria-label': label,
|
|
2808
|
+
disabled: !!disabled,
|
|
2809
|
+
style: {
|
|
2810
|
+
display: 'inline-flex',
|
|
2811
|
+
alignItems: 'center',
|
|
2812
|
+
justifyContent: 'center',
|
|
2813
|
+
minWidth: 44,
|
|
2814
|
+
minHeight: 44,
|
|
2815
|
+
padding: 0,
|
|
2816
|
+
border: 'none',
|
|
2817
|
+
background: 'transparent',
|
|
2818
|
+
color: 'inherit',
|
|
2819
|
+
opacity: busy && busy !== mode ? 0.4 : running && mode === 'revert' ? 0.35 : 0.72,
|
|
2820
|
+
cursor: disabled ? 'default' : 'pointer',
|
|
2821
|
+
borderRadius: 6,
|
|
2822
|
+
},
|
|
2823
|
+
onClick,
|
|
2824
|
+
},
|
|
2825
|
+
icon,
|
|
2826
|
+
)
|
|
2827
|
+
return React.createElement(
|
|
2828
|
+
'span',
|
|
2829
|
+
{ style: { display: 'inline-flex', gap: 0 } },
|
|
1939
2830
|
act(React.createElement(IconClock, { size: 16 }), t('slot.revert'), 'revert', runRevert, running),
|
|
1940
2831
|
act(React.createElement(IconQuote, { size: 16 }), t('slot.quote'), 'quote', runQuote, false),
|
|
1941
2832
|
)
|
|
@@ -1953,9 +2844,9 @@ window.__ModuleLoader__.load({
|
|
|
1953
2844
|
// SessionRevert.commit() → revert:null → affordance 消失)。
|
|
1954
2845
|
// 我们是 append-only,marker 不会真消失,所以由服务端按
|
|
1955
2846
|
// 「marker 之后有无 source.kind==='user' 的真实输入」算出 committed。
|
|
1956
|
-
return (msgs || []).filter(
|
|
1957
|
-
m.marker && m.sourceKind !== 'compact-checkpoint'
|
|
1958
|
-
|
|
2847
|
+
return (msgs || []).filter(
|
|
2848
|
+
m => m.marker && m.sourceKind !== 'compact-checkpoint' && m.restoreComplete !== true && m.committed !== true,
|
|
2849
|
+
)
|
|
1959
2850
|
}
|
|
1960
2851
|
|
|
1961
2852
|
/**
|
|
@@ -1987,7 +2878,7 @@ window.__ModuleLoader__.load({
|
|
|
1987
2878
|
const t = (props && props.t) || __t
|
|
1988
2879
|
useLocaleRevision()
|
|
1989
2880
|
if (inputActions && typeof inputActions.setDraft === 'function') __inputActions = inputActions
|
|
1990
|
-
const sessions = useSessions ? useSessions(
|
|
2881
|
+
const sessions = useSessions ? useSessions(s => s) : undefined
|
|
1991
2882
|
const summary = sessions && sessions.byId ? sessions.byId[sessionId] : undefined
|
|
1992
2883
|
const running = summary ? summary.running === true : false
|
|
1993
2884
|
// F1 主路径:宿主 activity 信号(见下方 effect);null = 无 useSessions 或尚无活动
|
|
@@ -2010,7 +2901,10 @@ window.__ModuleLoader__.load({
|
|
|
2010
2901
|
// opencode SessionRevertDock 视觉(v2 布局,DSH 令牌等价映射)
|
|
2011
2902
|
useEffect(() => {
|
|
2012
2903
|
if (styleInjected || typeof document === 'undefined') return
|
|
2013
|
-
if (document.getElementById('dsh-message-ops-dock-style')) {
|
|
2904
|
+
if (document.getElementById('dsh-message-ops-dock-style')) {
|
|
2905
|
+
setStyleInjected(true)
|
|
2906
|
+
return
|
|
2907
|
+
}
|
|
2014
2908
|
const tag = document.createElement('style')
|
|
2015
2909
|
tag.id = 'dsh-message-ops-dock-style'
|
|
2016
2910
|
tag.textContent = [
|
|
@@ -2050,31 +2944,31 @@ window.__ModuleLoader__.load({
|
|
|
2050
2944
|
// emitChanged() 自己就是先 invalidate 再发事件,这里同款红线。
|
|
2051
2945
|
invalidateMessagesMemo()
|
|
2052
2946
|
return fetchMessagesJson('/api/message-ops/messages?sessionId=' + encodeURIComponent(sessionId))
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2947
|
+
.then(data => {
|
|
2948
|
+
if (!alive || !data || !data.ok) return
|
|
2949
|
+
// R2:只有**最新发起且仍未被更新的请求**的结果才允许落地。
|
|
2950
|
+
// 注意不能只看 reqSeq 是否等于当前发起序号 —— 后发请求若失败(fetchMessagesJson
|
|
2951
|
+
// 对非 2xx / ok!==true 会 throw,被下面 catch 吞掉),它的序号已被占用,
|
|
2952
|
+
// 先发那次**成功的**好响应就会被这里丢弃 → markers 停在旧值且无重试。
|
|
2953
|
+
// 故另记一个「已落地序号」,失败不回滚它。
|
|
2954
|
+
if (reqSeq !== reqSeqRef.current || reqSeq <= landedSeqRef.current) return
|
|
2955
|
+
landedSeqRef.current = reqSeq
|
|
2956
|
+
const msgs = data.messages || []
|
|
2957
|
+
syncSyntheticTurnStyle(msgs)
|
|
2958
|
+
const act = activeMarkers(msgs)
|
|
2959
|
+
setMarkers(act)
|
|
2960
|
+
// 0.5.2(P2):标题口径 = 标记 range 内 visible=false 的去重 seq 数
|
|
2961
|
+
const seen = new Set()
|
|
2962
|
+
for (const mk of act) {
|
|
2963
|
+
const start = mk.range && typeof mk.range.start === 'number' ? mk.range.start : mk.seq
|
|
2964
|
+
const end = mk.range && typeof mk.range.end === 'number' ? mk.range.end : start
|
|
2965
|
+
for (const m of msgs) {
|
|
2966
|
+
if (m && m.visible === false && typeof m.seq === 'number' && m.seq >= start && m.seq <= end) seen.add(m.seq)
|
|
2967
|
+
}
|
|
2073
2968
|
}
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
.catch(() => {})
|
|
2969
|
+
setShadowCount(seen.size)
|
|
2970
|
+
})
|
|
2971
|
+
.catch(() => {})
|
|
2078
2972
|
}
|
|
2079
2973
|
|
|
2080
2974
|
// F1(复审后重做):宿主在 user/message(source.kind==='user') 时会
|
|
@@ -2140,45 +3034,67 @@ window.__ModuleLoader__.load({
|
|
|
2140
3034
|
if (step.reload) loadRef.current()
|
|
2141
3035
|
}, [sessionId, activityAt])
|
|
2142
3036
|
|
|
2143
|
-
|
|
2144
3037
|
// items 变化自动折叠(opencode createEffect 同款;必须在早退之前——Hooks 规则)
|
|
2145
|
-
useEffect(() => {
|
|
3038
|
+
useEffect(() => {
|
|
3039
|
+
setOpen(false)
|
|
3040
|
+
}, [markers && markers.length, markers && markers[0] && markers[0].seq])
|
|
2146
3041
|
if (!markers || !markers.length) return null
|
|
2147
3042
|
|
|
2148
|
-
const restoreRow =
|
|
3043
|
+
const restoreRow = row => {
|
|
2149
3044
|
if (restoring != null || running) return
|
|
2150
3045
|
setRestoring(rowKey(row))
|
|
2151
3046
|
Promise.resolve()
|
|
2152
|
-
.then(() =>
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
3047
|
+
.then(() =>
|
|
3048
|
+
fetch('/api/message-ops/restore', {
|
|
3049
|
+
method: 'POST',
|
|
3050
|
+
headers: { 'content-type': 'application/json' },
|
|
3051
|
+
// 0.8.0:upToSeq 存在 → 按轮步进恢复(只重放到该 seq)
|
|
3052
|
+
body: JSON.stringify(row.upTo != null ? { sessionId, seq: row.seq, upToSeq: row.upTo } : { sessionId, seq: row.seq }),
|
|
3053
|
+
}),
|
|
3054
|
+
)
|
|
3055
|
+
.then(async res => {
|
|
2158
3056
|
let data = {}
|
|
2159
|
-
try {
|
|
2160
|
-
|
|
2161
|
-
|
|
3057
|
+
try {
|
|
3058
|
+
data = await res.json()
|
|
3059
|
+
} catch {
|
|
3060
|
+
/* keep {} */
|
|
3061
|
+
}
|
|
3062
|
+
if (!res.ok || !data.ok) throw new Error(data.error || 'HTTP ' + res.status)
|
|
3063
|
+
notifyDone(
|
|
3064
|
+
t('done.restore', {
|
|
3065
|
+
n: String(data.restoredCount != null ? data.restoredCount : '?'),
|
|
3066
|
+
s: String(data.skipped != null ? data.skipped : 0),
|
|
3067
|
+
}),
|
|
3068
|
+
)
|
|
2162
3069
|
setRestoring(null)
|
|
2163
3070
|
// 0.5.0:恢复后重建会话视图(重放消息立即可见)
|
|
2164
3071
|
try {
|
|
2165
3072
|
if (__uiWorkspace && typeof __uiWorkspace.openSession === 'function') __uiWorkspace.openSession(sessionId)
|
|
2166
|
-
} catch {
|
|
3073
|
+
} catch {
|
|
3074
|
+
/* fallthrough */
|
|
3075
|
+
}
|
|
2167
3076
|
// 0.9.1:重放的消息带**新 seq**,被恢复的行必须解除 hidden;dock 的
|
|
2168
3077
|
// marker 列表要按权威数据重算(restoreComplete 会变 true)后重拉。
|
|
2169
3078
|
emitChanged()
|
|
2170
|
-
for (const delay of [150, 700, 1600])
|
|
3079
|
+
for (const delay of [150, 700, 1600])
|
|
3080
|
+
setTimeout(() => {
|
|
3081
|
+
if (__refreshSurface) __refreshSurface(sessionId)
|
|
3082
|
+
}, delay)
|
|
2171
3083
|
const fresh = await fetchMessagesJson('/api/message-ops/messages?sessionId=' + encodeURIComponent(sessionId)).catch(() => null)
|
|
2172
3084
|
if (fresh && fresh.ok) setMarkers(activeMarkers(fresh.messages || []))
|
|
2173
3085
|
})
|
|
2174
|
-
.catch(
|
|
3086
|
+
.catch(reason => {
|
|
2175
3087
|
notifyDone(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error')
|
|
2176
3088
|
})
|
|
2177
3089
|
.finally(() => setRestoring(null))
|
|
2178
3090
|
}
|
|
2179
3091
|
|
|
2180
|
-
|
|
2181
|
-
|
|
3092
|
+
const headerKbd = e => {
|
|
3093
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
3094
|
+
e.preventDefault()
|
|
3095
|
+
setOpen(v => !v)
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
2182
3098
|
// 0.5.2(P2):标题报「被遮蔽消息数」而非标记数——一个 revert 可遮蔽数百条,
|
|
2183
3099
|
// 用标记数会严重低报(0.4.2 文案引入的错口径);无 range 数据时回退标记数
|
|
2184
3100
|
const label = t('dock.title', { n: String(shadowCount || markers.length) })
|
|
@@ -2186,19 +3102,28 @@ window.__ModuleLoader__.load({
|
|
|
2186
3102
|
|
|
2187
3103
|
// 0.8.0:行 = 待恢复"轮"(对齐 opencode 按轮步进);无可重放轮的标记
|
|
2188
3104
|
// 保留旧式整段行(空区间 → 停用 notice 路径)。restoring 键区分同标记多轮。
|
|
2189
|
-
const rowKey =
|
|
2190
|
-
const rowEl =
|
|
2191
|
-
React.createElement(
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
3105
|
+
const rowKey = row => (row.upTo != null ? row.seq + ':' + row.upTo : String(row.seq))
|
|
3106
|
+
const rowEl = row =>
|
|
3107
|
+
React.createElement(
|
|
3108
|
+
'div',
|
|
3109
|
+
{ key: rowKey(row), className: 'mopsRdRow' },
|
|
3110
|
+
React.createElement('span', { className: 'mopsRdRowText' }, '#' + row.seq + ' · ' + (row.snippet || '')),
|
|
3111
|
+
React.createElement(
|
|
3112
|
+
'button',
|
|
3113
|
+
{
|
|
3114
|
+
type: 'button',
|
|
3115
|
+
className: 'mopsRdRestore',
|
|
3116
|
+
disabled: restoring != null || running,
|
|
3117
|
+
// 0.10.2 专家组评估结论:唯一「严重度=高」的真实缺口是 restore 为**重放**语义 ——
|
|
3118
|
+
// 消息带新 seq 落到会话末尾,**不会回到原位**(引擎 SurfaceOp 只有 append/replace,
|
|
3119
|
+
// 不存在解除遮蔽的原语)。用户点下去看到消息"搬家到底部"会以为出 bug,
|
|
3120
|
+
// 所以把语义写在按钮上,别让人靠猜。
|
|
3121
|
+
title: t('dock.restoreHint'),
|
|
3122
|
+
onClick: () => restoreRow(row),
|
|
3123
|
+
},
|
|
3124
|
+
restoring === rowKey(row) ? t('dock.restoring') : t('dock.restore'),
|
|
3125
|
+
),
|
|
3126
|
+
)
|
|
2202
3127
|
const dockRows = []
|
|
2203
3128
|
for (const mk of markers || []) {
|
|
2204
3129
|
if (Array.isArray(mk.pendingTurns) && mk.pendingTurns.length > 0) {
|
|
@@ -2210,26 +3135,74 @@ window.__ModuleLoader__.load({
|
|
|
2210
3135
|
}
|
|
2211
3136
|
}
|
|
2212
3137
|
|
|
2213
|
-
const chevron = React.createElement(
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
onClick: () => setOpen((v) => !v), onKeyDown: headerKbd,
|
|
3138
|
+
const chevron = React.createElement(
|
|
3139
|
+
'button',
|
|
3140
|
+
{
|
|
3141
|
+
type: 'button',
|
|
3142
|
+
'aria-label': open ? t('dock.collapse') : t('dock.expand'),
|
|
3143
|
+
'aria-expanded': open,
|
|
3144
|
+
className: 'mopsRdChevron',
|
|
3145
|
+
onClick: e => {
|
|
3146
|
+
e.stopPropagation()
|
|
3147
|
+
setOpen(v => !v)
|
|
3148
|
+
},
|
|
2225
3149
|
},
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
3150
|
+
React.createElement(
|
|
3151
|
+
'svg',
|
|
3152
|
+
{
|
|
3153
|
+
width: 14,
|
|
3154
|
+
height: 14,
|
|
3155
|
+
viewBox: '0 0 16 16',
|
|
3156
|
+
fill: 'none',
|
|
3157
|
+
style: { transform: open ? 'rotate(0deg)' : 'rotate(180deg)', transition: 'transform .15s ease' },
|
|
3158
|
+
},
|
|
3159
|
+
React.createElement('path', {
|
|
3160
|
+
d: 'M4 6l4 4 4-4',
|
|
3161
|
+
stroke: 'currentColor',
|
|
3162
|
+
strokeWidth: 1.3,
|
|
3163
|
+
strokeLinecap: 'round',
|
|
3164
|
+
strokeLinejoin: 'round',
|
|
3165
|
+
}),
|
|
3166
|
+
),
|
|
3167
|
+
)
|
|
3168
|
+
|
|
3169
|
+
return React.createElement(
|
|
3170
|
+
'div',
|
|
3171
|
+
{ className: 'mopsRd', role: 'region', 'aria-label': label },
|
|
3172
|
+
React.createElement(
|
|
3173
|
+
'div',
|
|
3174
|
+
{
|
|
3175
|
+
className: 'mopsRdHead',
|
|
3176
|
+
role: 'button',
|
|
3177
|
+
tabIndex: 0,
|
|
3178
|
+
onClick: () => setOpen(v => !v),
|
|
3179
|
+
onKeyDown: headerKbd,
|
|
3180
|
+
},
|
|
3181
|
+
React.createElement(
|
|
3182
|
+
'span',
|
|
3183
|
+
{ className: 'mopsRdIcon' },
|
|
3184
|
+
React.createElement(
|
|
3185
|
+
'svg',
|
|
3186
|
+
{ width: 15, height: 15, viewBox: '0 0 16 16', fill: 'none' },
|
|
3187
|
+
React.createElement('path', {
|
|
3188
|
+
d: 'M2.5 8a5.5 5.5 0 1 0 1.6-3.9',
|
|
3189
|
+
stroke: 'currentColor',
|
|
3190
|
+
strokeWidth: 1.2,
|
|
3191
|
+
strokeLinecap: 'round',
|
|
3192
|
+
}),
|
|
3193
|
+
React.createElement('path', {
|
|
3194
|
+
d: 'M2.2 2.8v3h3',
|
|
3195
|
+
stroke: 'currentColor',
|
|
3196
|
+
strokeWidth: 1.2,
|
|
3197
|
+
strokeLinecap: 'round',
|
|
3198
|
+
strokeLinejoin: 'round',
|
|
3199
|
+
}),
|
|
3200
|
+
),
|
|
3201
|
+
),
|
|
2230
3202
|
React.createElement('span', { className: 'mopsRdLabel' + (open ? '' : ' mopsRdLabelCollapsed') }, label),
|
|
2231
3203
|
open ? null : React.createElement('span', { className: 'mopsRdPreview' }, preview),
|
|
2232
|
-
React.createElement('span', { style: { marginLeft: 'auto', flex: 'none' } }, chevron)
|
|
3204
|
+
React.createElement('span', { style: { marginLeft: 'auto', flex: 'none' } }, chevron),
|
|
3205
|
+
),
|
|
2233
3206
|
open ? React.createElement('div', { className: 'mopsRdList' }, dockRows.map(rowEl)) : null,
|
|
2234
3207
|
)
|
|
2235
3208
|
}
|
|
@@ -2253,7 +3226,7 @@ window.__ModuleLoader__.load({
|
|
|
2253
3226
|
window.__MOPS_USER_REVERT_INSTALLED = true
|
|
2254
3227
|
var rowsCache = { sid: null, rows: null, at: 0 }
|
|
2255
3228
|
__peekRowsCache = () => rowsCache
|
|
2256
|
-
var norm =
|
|
3229
|
+
var norm = x => String(x || '').replace(/\s+/g, '')
|
|
2257
3230
|
|
|
2258
3231
|
// 0.9.7(P4):messageId→seq / 全文索引挂在**同一个 dataSig** 上。
|
|
2259
3232
|
// 旧实现每会话只写一次、仅失败时 delete —— 会话增长后新 assistant 消息的
|
|
@@ -2267,7 +3240,7 @@ window.__ModuleLoader__.load({
|
|
|
2267
3240
|
__seqDataSig = sig
|
|
2268
3241
|
const index = new Map()
|
|
2269
3242
|
const full = new Map()
|
|
2270
|
-
for (const m of
|
|
3243
|
+
for (const m of messages || []) {
|
|
2271
3244
|
if (!m || m.id == null) continue
|
|
2272
3245
|
const k = String(m.id)
|
|
2273
3246
|
// 同 id 取**最早** seq —— 与槽位自己的 buildSeqIndex 口径一致
|
|
@@ -2279,17 +3252,21 @@ window.__ModuleLoader__.load({
|
|
|
2279
3252
|
__seqIndexCache.set(key, index)
|
|
2280
3253
|
__fullTextCache.set(key, full)
|
|
2281
3254
|
}
|
|
2282
|
-
try {
|
|
3255
|
+
try {
|
|
3256
|
+
window.dispatchEvent(new CustomEvent(SEQ_INDEX_EVENT))
|
|
3257
|
+
} catch {
|
|
3258
|
+
/* non-browser */
|
|
3259
|
+
}
|
|
2283
3260
|
}
|
|
2284
3261
|
|
|
2285
|
-
var fetchRows =
|
|
3262
|
+
var fetchRows = sidIn => {
|
|
2286
3263
|
// 0.9.7:统一按**裸 uuid** 作缓存键。调用方有的传 `session-xxx`(scan /
|
|
2287
3264
|
// /undo 的 rawSid)有的传裸 uuid(/redo 的 bareSessionId)—— 混用会让
|
|
2288
3265
|
// rowsCache.sid 在两个键之间来回横跳,每次都是缓存未命中(白白多发 GET)。
|
|
2289
3266
|
const sid = bareSessionId(sidIn)
|
|
2290
3267
|
if (rowsCache.sid === sid && rowsCache.rows && Date.now() - rowsCache.at < 8000) return Promise.resolve(rowsCache)
|
|
2291
3268
|
return fetchMessagesJson('/api/message-ops/messages?sessionId=' + encodeURIComponent(sid))
|
|
2292
|
-
.then(
|
|
3269
|
+
.then(d => {
|
|
2293
3270
|
// 宿主会把 <system-reminder> / runtime context 等也记为 role=user 的行,
|
|
2294
3271
|
// DOM 里并不渲染成"我的消息"块 —— 必须滤掉,否则按序配对会错位(0.7.0 根因)。
|
|
2295
3272
|
// 注意:对话框的「可回滚目标」列表仍应过滤 visible(那是另一套语义)。
|
|
@@ -2300,11 +3277,21 @@ window.__ModuleLoader__.load({
|
|
|
2300
3277
|
// 否则 `Background job 是我自己的问题` 这种真人输入会被误杀
|
|
2301
3278
|
// (曾用 ^background job\b,测试当场抓到这个误杀)。
|
|
2302
3279
|
// 样本里没出现过的模式(已停止 / User feedback:)一律**不加** —— 没证据就不猜。
|
|
2303
|
-
const injected =
|
|
3280
|
+
const injected = raw =>
|
|
3281
|
+
/^<system-reminder|current\s+runtime\s+context|^<system-Reminder|^background job\s+[\w-]+|^Background subagent\s+[0-9a-f]{8}-|^Agent\s+[0-9a-f]{8}-|^\[model changed:/i.test(
|
|
3282
|
+
String(raw || ''),
|
|
3283
|
+
)
|
|
2304
3284
|
const rows = ((d && d.messages) || [])
|
|
2305
|
-
.filter(
|
|
2306
|
-
.map(
|
|
2307
|
-
|
|
3285
|
+
.filter(m => m && m.role === 'user')
|
|
3286
|
+
.map(m => ({
|
|
3287
|
+
seq: m.seq,
|
|
3288
|
+
sn: norm(m.snippet),
|
|
3289
|
+
raw: String(m.snippet == null ? '' : m.snippet),
|
|
3290
|
+
fullText: m.fullText ?? null,
|
|
3291
|
+
visible: m.visible !== false,
|
|
3292
|
+
turnStartSeq: m.turnStartSeq ?? null,
|
|
3293
|
+
}))
|
|
3294
|
+
.filter(r => r.sn && !injected(r.raw))
|
|
2308
3295
|
// 0.9.1:同时产出 node-key 查表索引(隐藏 transcript 用)
|
|
2309
3296
|
const idx = buildIndex(d)
|
|
2310
3297
|
rowsCache = { sid: sid, rows: rows, idx: idx, at: Date.now() }
|
|
@@ -2318,37 +3305,37 @@ window.__ModuleLoader__.load({
|
|
|
2318
3305
|
// dsh transcript 刻意不折叠(surface.d.ts:51-63 "replacement copies stay
|
|
2319
3306
|
// model-only"),回滚只能在渲染层按 `data-chat-node-key` 精确查表(零启发式)。
|
|
2320
3307
|
// 背景长文与「40 字符前缀匹配」事故见 README「0.9.1 / 0.9.2 · 回滚「真的生效了」」。
|
|
2321
|
-
var parseNodeKey =
|
|
2322
|
-
var m = /^(\d+):/.exec(k || '')
|
|
2323
|
-
if (!m) return null
|
|
2324
|
-
var digits = m[1].length
|
|
2325
|
-
var kindLen = Number(m[1])
|
|
2326
|
-
var start = digits + 1
|
|
2327
|
-
if (!Number.isSafeInteger(kindLen) || kindLen <= 0 || k.length < start + kindLen) return null
|
|
2328
|
-
return { kind: k.slice(start, start + kindLen), id: k.slice(start + kindLen) }
|
|
2329
|
-
}
|
|
3308
|
+
var parseNodeKey = k => {
|
|
3309
|
+
var m = /^(\d+):/.exec(k || '')
|
|
3310
|
+
if (!m) return null
|
|
3311
|
+
var digits = m[1].length
|
|
3312
|
+
var kindLen = Number(m[1])
|
|
3313
|
+
var start = digits + 1
|
|
3314
|
+
if (!Number.isSafeInteger(kindLen) || kindLen <= 0 || k.length < start + kindLen) return null
|
|
3315
|
+
return { kind: k.slice(start, start + kindLen), id: k.slice(start + kindLen) }
|
|
3316
|
+
}
|
|
2330
3317
|
|
|
2331
3318
|
/**
|
|
2332
3319
|
* 从 /api/message-ops/messages 的响应构建全部查表。
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
var buildIndex =
|
|
3320
|
+
* 两条铁律:① 索引只认唯一 id;② 缺数据一律返回 undefined(调用方保持可见)。
|
|
3321
|
+
*/
|
|
3322
|
+
var buildIndex = payload => {
|
|
2336
3323
|
var list = (payload && payload.messages) || []
|
|
2337
3324
|
// 0.9.1:回合页脚/过程条不是消息,用 turn/end 的 seq 定位(边界常落在 turn 内部,
|
|
2338
3325
|
// 用 turn/start 会漏判该回合的页脚)
|
|
2339
|
-
var turnEnd = (payload && payload.turnEndSeq) || null
|
|
2340
|
-
var byMessageId = new Map()
|
|
2341
|
-
var byTurnStep = new Map()
|
|
2342
|
-
var byCallId = new Map()
|
|
2343
|
-
var byTurn = new Map()
|
|
2344
|
-
var shadowed = new Set()
|
|
2345
|
-
var visibleTurns = new Set()
|
|
2346
|
-
var dupByMessageId = new Map()
|
|
3326
|
+
var turnEnd = (payload && payload.turnEndSeq) || null
|
|
3327
|
+
var byMessageId = new Map()
|
|
3328
|
+
var byTurnStep = new Map()
|
|
3329
|
+
var byCallId = new Map()
|
|
3330
|
+
var byTurn = new Map()
|
|
3331
|
+
var shadowed = new Set() // 落在 replace 区间内 = 已被回滚(transcript 藏行判据)
|
|
3332
|
+
var visibleTurns = new Set() // 含至少一条**未被遮蔽**消息的 turn 号(回合 chrome)
|
|
3333
|
+
var dupByMessageId = new Map()
|
|
2347
3334
|
for (var i = 0; i < list.length; i++) {
|
|
2348
|
-
var m = list[i]
|
|
2349
|
-
if (!m || typeof m.seq !== 'number') continue
|
|
3335
|
+
var m = list[i]
|
|
3336
|
+
if (!m || typeof m.seq !== 'number') continue
|
|
2350
3337
|
if (m.id != null) {
|
|
2351
|
-
var k = String(m.id)
|
|
3338
|
+
var k = String(m.id)
|
|
2352
3339
|
// restore 是「重放」语义 → 原件与副本可能同 id 并存。
|
|
2353
3340
|
// 0.9.1:不再「保留最早」,而是收集**全部** seq,隐藏判据取「任一 seq 越过
|
|
2354
3341
|
// fence」。回放副本才是当前 surface 上的那条,用最早的 seq 判会让
|
|
@@ -2357,32 +3344,34 @@ window.__ModuleLoader__.load({
|
|
|
2357
3344
|
const arr = dupByMessageId.get(k) || [byMessageId.get(k)]
|
|
2358
3345
|
arr.push(m.seq)
|
|
2359
3346
|
dupByMessageId.set(k, arr)
|
|
2360
|
-
byMessageId.set(k, m.seq)
|
|
2361
|
-
} else {
|
|
3347
|
+
byMessageId.set(k, m.seq) // 指向最新的
|
|
3348
|
+
} else {
|
|
3349
|
+
byMessageId.set(k, m.seq)
|
|
3350
|
+
}
|
|
2362
3351
|
}
|
|
2363
3352
|
if (m.type === 'assistant/message' && m.turn != null && m.step != null) {
|
|
2364
|
-
byTurnStep.set(m.turn + ':' + m.step, m.seq)
|
|
3353
|
+
byTurnStep.set(m.turn + ':' + m.step, m.seq)
|
|
2365
3354
|
}
|
|
2366
|
-
if (m.type === 'tool/call' && m.id != null) byCallId.set(String(m.id), m.seq)
|
|
2367
|
-
if (m.turn != null && !byTurn.has(String(m.turn))) byTurn.set(String(m.turn), m.seq)
|
|
3355
|
+
if (m.type === 'tool/call' && m.id != null) byCallId.set(String(m.id), m.seq)
|
|
3356
|
+
if (m.turn != null && !byTurn.has(String(m.turn))) byTurn.set(String(m.turn), m.seq)
|
|
2368
3357
|
// 0.9.6:藏行判据用 shadowed(replace 区间),**不用** m.visible(模型 surface)。
|
|
2369
3358
|
// visible 在 live 路径下对 tool/call 恒 false → 拿它当判据会把整页工具行全藏,
|
|
2370
3359
|
// 故这里连集合都不建(判据样本见 test/surface-visibility.test.js)。
|
|
2371
|
-
if (m.shadowed === true) shadowed.add(m.seq)
|
|
2372
|
-
else if (m.turn != null) visibleTurns.add(String(m.turn))
|
|
3360
|
+
if (m.shadowed === true) shadowed.add(m.seq)
|
|
3361
|
+
else if (m.turn != null) visibleTurns.add(String(m.turn))
|
|
2373
3362
|
}
|
|
2374
3363
|
// turnEnd 优先:它对「该 turn 内一条消息都没有」的情况仍然有效
|
|
2375
3364
|
if (turnEnd) for (const k in turnEnd) if (Object.prototype.hasOwnProperty.call(turnEnd, k)) byTurn.set(k, turnEnd[k])
|
|
2376
|
-
return { byMessageId, dupByMessageId, byTurnStep, byCallId, byTurn, shadowed, visibleTurns, total: list.length }
|
|
2377
|
-
}
|
|
3365
|
+
return { byMessageId, dupByMessageId, byTurnStep, byCallId, byTurn, shadowed, visibleTurns, total: list.length }
|
|
3366
|
+
}
|
|
2378
3367
|
|
|
2379
3368
|
/** node-key → { seq, all }(all = 同 id 的全部 seq,处理 restore 重放副本)。 */
|
|
2380
3369
|
var seqOfNodeKey = (key, idx) => {
|
|
2381
|
-
var parsed = parseNodeKey(key)
|
|
2382
|
-
if (!parsed || !idx) return null
|
|
2383
|
-
var id = parsed.id
|
|
3370
|
+
var parsed = parseNodeKey(key)
|
|
3371
|
+
if (!parsed || !idx) return null
|
|
3372
|
+
var id = parsed.id
|
|
2384
3373
|
switch (parsed.kind) {
|
|
2385
|
-
case 'input-message':
|
|
3374
|
+
case 'input-message': // user / steering / turn-trigger
|
|
2386
3375
|
case 'developer-message':
|
|
2387
3376
|
case 'trajectory-note': {
|
|
2388
3377
|
const hit = idx.byMessageId.get(id)
|
|
@@ -2408,9 +3397,9 @@ window.__ModuleLoader__.load({
|
|
|
2408
3397
|
return hit === undefined ? null : { kind: parsed.kind, seq: hit, all: [hit], turn: id }
|
|
2409
3398
|
}
|
|
2410
3399
|
default:
|
|
2411
|
-
return null
|
|
3400
|
+
return null // compaction / command / workflow-run 等不参与
|
|
2412
3401
|
}
|
|
2413
|
-
}
|
|
3402
|
+
}
|
|
2414
3403
|
|
|
2415
3404
|
/**
|
|
2416
3405
|
* 把 transcript 行按模型 surface 可见性打上 hidden。
|
|
@@ -2422,46 +3411,49 @@ window.__ModuleLoader__.load({
|
|
|
2422
3411
|
* 是唯一会误藏用户内容的路径。
|
|
2423
3412
|
*/
|
|
2424
3413
|
var applySurfaceVisibility = (root, idx) => {
|
|
2425
|
-
if (!idx) return { hidden: 0, unresolved: 0, shown: 0 }
|
|
3414
|
+
if (!idx) return { hidden: 0, unresolved: 0, shown: 0 }
|
|
2426
3415
|
// 0.9.7(P2-1):root 既可传 document/元素(调用方自查),也可直接传
|
|
2427
3416
|
// 已经查好的行集合 —— ensureAssign 每次都要算 rows.length 当签名,
|
|
2428
3417
|
// 传集合避免同一次扫描里 querySelectorAll 跑两遍。
|
|
2429
|
-
var rows =
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
3418
|
+
var rows =
|
|
3419
|
+
root && typeof root.querySelectorAll === 'function'
|
|
3420
|
+
? root.querySelectorAll('[data-chat-node-key]')
|
|
3421
|
+
: root || document.querySelectorAll('[data-chat-node-key]')
|
|
3422
|
+
var hidden = 0,
|
|
3423
|
+
unresolved = 0,
|
|
3424
|
+
shown = 0
|
|
2433
3425
|
for (var i = 0; i < rows.length; i++) {
|
|
2434
|
-
var row = rows[i]
|
|
3426
|
+
var row = rows[i]
|
|
2435
3427
|
// 0.9.6 藏行判据 = **replace 区间(shadowed)**;revertFences→visible→shadowed
|
|
2436
3428
|
// 演进史(含 4792/4793 全藏事故)见 README「历史事故记录」#4。
|
|
2437
|
-
var hit = seqOfNodeKey(row.getAttribute('data-chat-node-key'), idx)
|
|
3429
|
+
var hit = seqOfNodeKey(row.getAttribute('data-chat-node-key'), idx)
|
|
2438
3430
|
// 0.9.7(P2-1)幂等跳写:判据与执行时机**一字未改**,只在
|
|
2439
3431
|
// 「目标状态 ≠ 当前状态」时才碰属性 —— 省掉全表几百次无效写。
|
|
2440
3432
|
if (hit === null) {
|
|
2441
|
-
unresolved
|
|
2442
|
-
if (row.hasAttribute('hidden')) row.removeAttribute('hidden')
|
|
2443
|
-
continue
|
|
3433
|
+
unresolved++
|
|
3434
|
+
if (row.hasAttribute('hidden')) row.removeAttribute('hidden')
|
|
3435
|
+
continue
|
|
2444
3436
|
}
|
|
2445
|
-
var shouldHide
|
|
3437
|
+
var shouldHide
|
|
2446
3438
|
if (hit.turn !== undefined) {
|
|
2447
3439
|
// 回合 chrome:本 turn 还有未被遮蔽的消息就露出
|
|
2448
|
-
shouldHide = !idx.visibleTurns.has(String(hit.turn))
|
|
3440
|
+
shouldHide = !idx.visibleTurns.has(String(hit.turn))
|
|
2449
3441
|
} else {
|
|
2450
3442
|
// 消息/工具类:**是否落在 replace 区间内**(= 被回滚掉了)。
|
|
2451
3443
|
// ⚠️ 不能用 visible(模型 surface)——live 路径下 tool/call 恒不在 surface,
|
|
2452
3444
|
// 会把整页工具行全藏(实测 157 行藏 152 行)。
|
|
2453
|
-
shouldHide = idx.shadowed.has(hit.seq)
|
|
3445
|
+
shouldHide = idx.shadowed.has(hit.seq)
|
|
2454
3446
|
}
|
|
2455
3447
|
if (shouldHide) {
|
|
2456
|
-
hidden
|
|
2457
|
-
if (row.getAttribute('hidden') !== 'until-found') row.setAttribute('hidden', 'until-found')
|
|
3448
|
+
hidden++
|
|
3449
|
+
if (row.getAttribute('hidden') !== 'until-found') row.setAttribute('hidden', 'until-found')
|
|
2458
3450
|
} else {
|
|
2459
|
-
shown
|
|
2460
|
-
if (row.hasAttribute('hidden')) row.removeAttribute('hidden')
|
|
3451
|
+
shown++
|
|
3452
|
+
if (row.hasAttribute('hidden')) row.removeAttribute('hidden')
|
|
2461
3453
|
}
|
|
2462
3454
|
}
|
|
2463
|
-
return { hidden, unresolved, shown }
|
|
2464
|
-
}
|
|
3455
|
+
return { hidden, unresolved, shown }
|
|
3456
|
+
}
|
|
2465
3457
|
|
|
2466
3458
|
// 用户消息锚点:优先官方 Sixlwa_userRow(含 .xzv4MW_actions),回退 flow-kind 属性
|
|
2467
3459
|
// 锚点 = 每条用户消息自己的容器(一个块只算一次):
|
|
@@ -2469,12 +3461,18 @@ window.__ModuleLoader__.load({
|
|
|
2469
3461
|
var userAnchors = () => {
|
|
2470
3462
|
const out = []
|
|
2471
3463
|
const seen = new Set()
|
|
2472
|
-
const add =
|
|
3464
|
+
const add = el => {
|
|
3465
|
+
if (el && !seen.has(el)) {
|
|
3466
|
+
seen.add(el)
|
|
3467
|
+
out.push(el)
|
|
3468
|
+
}
|
|
3469
|
+
}
|
|
2473
3470
|
const rows = Array.from(document.querySelectorAll('[class*="xzv4MW_actions"]'))
|
|
2474
3471
|
for (const r of rows) {
|
|
2475
|
-
const block =
|
|
2476
|
-
|
|
2477
|
-
|
|
3472
|
+
const block =
|
|
3473
|
+
r.closest('[data-chat-flow-kind="user"]') ||
|
|
3474
|
+
r.closest('[class*="_userRow"], [class*="_userStack"], [class*="_bubble"]') ||
|
|
3475
|
+
r.parentElement
|
|
2478
3476
|
// 0.9.0:只按**稳定属性** + hash-immune 类名后缀判定,不再匹配 CSS-module
|
|
2479
3477
|
// 生成的前缀(`Sixlwa_*`)。dsh 0.2.0-rc.2 的哈希已变为 `EvIC1a_flowItem`,
|
|
2480
3478
|
// 旧前缀正则把所有块都滤掉 → anchors 为空 → 按钮拿不到 seq → 点击必失败。
|
|
@@ -2499,7 +3497,7 @@ window.__ModuleLoader__.load({
|
|
|
2499
3497
|
const ok = block.getAttribute('data-mops-seq')
|
|
2500
3498
|
if (ok) {
|
|
2501
3499
|
btn.disabled = false
|
|
2502
|
-
btn.title = __t('slot.revert')
|
|
3500
|
+
btn.title = __t(btn.classList.contains('mopsUserFork') ? 'slot.forkHint' : 'slot.revert')
|
|
2503
3501
|
btn.removeAttribute('data-mops-unmatched')
|
|
2504
3502
|
} else {
|
|
2505
3503
|
btn.disabled = true
|
|
@@ -2507,22 +3505,27 @@ window.__ModuleLoader__.load({
|
|
|
2507
3505
|
btn.setAttribute('data-mops-unmatched', '1')
|
|
2508
3506
|
}
|
|
2509
3507
|
}
|
|
3508
|
+
/** 块内全部插件按钮一起同步(回滚 / 分叉同一动作行)。 */
|
|
3509
|
+
var syncBlockButtons = block => {
|
|
3510
|
+
if (!block || !block.querySelectorAll) return
|
|
3511
|
+
for (const b of block.querySelectorAll('.mopsUserRevert, .mopsUserFork')) syncEnabled(block, b)
|
|
3512
|
+
}
|
|
2510
3513
|
var assignSeqs = (sid, cache, anchors) => {
|
|
2511
3514
|
const idx = cache && cache.idx
|
|
2512
3515
|
if (!idx) return
|
|
2513
3516
|
// 0.9.1:node-key 查表,替代旧的 40 字符前缀包含匹配(实测 4 条错 2 条)
|
|
2514
|
-
for (const b of
|
|
3517
|
+
for (const b of anchors || userAnchors()) {
|
|
2515
3518
|
b.removeAttribute('data-mops-seq')
|
|
2516
3519
|
b.removeAttribute('data-mops-unmatched')
|
|
2517
3520
|
const hit = seqOfNodeKey(b.getAttribute('data-chat-node-key'), idx)
|
|
2518
3521
|
const seq = hit === null ? null : hit.seq
|
|
2519
3522
|
if (seq === null || seq === undefined) {
|
|
2520
3523
|
b.setAttribute('data-mops-unmatched', '1')
|
|
2521
|
-
|
|
3524
|
+
syncBlockButtons(b)
|
|
2522
3525
|
continue
|
|
2523
3526
|
}
|
|
2524
3527
|
b.setAttribute('data-mops-seq', String(seq))
|
|
2525
|
-
|
|
3528
|
+
syncBlockButtons(b)
|
|
2526
3529
|
}
|
|
2527
3530
|
}
|
|
2528
3531
|
// 按钮可用性在 assignSeqs 内部**同步**更新(与打标同一次循环)——
|
|
@@ -2539,32 +3542,35 @@ window.__ModuleLoader__.load({
|
|
|
2539
3542
|
// 摘牌后 node-key 相同但打标为空,靠这里发现)
|
|
2540
3543
|
// 🔴 applySurfaceVisibility 仍然**无条件**执行,藏行判据与时机一字未改。
|
|
2541
3544
|
var assignSig = null
|
|
2542
|
-
var anchorSigOf =
|
|
3545
|
+
var anchorSigOf = anchors => {
|
|
2543
3546
|
let s = ''
|
|
2544
3547
|
for (let i = 0; i < anchors.length; i++) {
|
|
2545
3548
|
const b = anchors[i]
|
|
2546
|
-
s +=
|
|
2547
|
-
(b.getAttribute('data-
|
|
3549
|
+
s +=
|
|
3550
|
+
(b.getAttribute('data-chat-node-key') || '') +
|
|
3551
|
+
'=' +
|
|
3552
|
+
(b.getAttribute('data-mops-seq') || (b.hasAttribute('data-mops-unmatched') ? '?' : '-')) +
|
|
3553
|
+
','
|
|
2548
3554
|
}
|
|
2549
3555
|
return s
|
|
2550
3556
|
}
|
|
2551
|
-
var sigOf = (sid, dataSig, rowsLen, anchors) =>
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
3557
|
+
var sigOf = (sid, dataSig, rowsLen, anchors) => bareSessionId(sid) + '|' + dataSig + '|' + rowsLen + '|' + anchorSigOf(anchors)
|
|
3558
|
+
var ensureAssign = sid =>
|
|
3559
|
+
fetchRows(sid).then(cache => {
|
|
3560
|
+
if (!cache || !cache.idx) return cache
|
|
3561
|
+
const idx = cache.idx
|
|
3562
|
+
const rows = document.querySelectorAll('[data-chat-node-key]')
|
|
3563
|
+
const dataSig = idx.total + '/' + idx.shadowed.size + '/' + idx.visibleTurns.size
|
|
3564
|
+
const anchors = userAnchors()
|
|
3565
|
+
const before = sigOf(sid, dataSig, rows.length, anchors)
|
|
3566
|
+
if (before !== assignSig) {
|
|
3567
|
+
assignSeqs(sid, cache, anchors)
|
|
3568
|
+
// 存**改写之后**的真实签名:下一次直接相等就跳过,不用跑两轮才收敛
|
|
3569
|
+
assignSig = sigOf(sid, dataSig, rows.length, anchors)
|
|
3570
|
+
}
|
|
3571
|
+
applySurfaceVisibility(rows, idx)
|
|
3572
|
+
return cache
|
|
3573
|
+
})
|
|
2568
3574
|
// 0.7.0:点击时先**同步完成**配对(打标是异步 fetch 的结果,
|
|
2569
3575
|
// 早先点在未打标的按钮上会静默失败 = 用户反馈的"点了没用")。
|
|
2570
3576
|
var runUserRevert = (btn, block) => {
|
|
@@ -2574,46 +3580,112 @@ window.__ModuleLoader__.load({
|
|
|
2574
3580
|
Promise.resolve()
|
|
2575
3581
|
.then(() => ensureAssign(sid))
|
|
2576
3582
|
.then(() => fetchRows(sid))
|
|
2577
|
-
.then(
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
3583
|
+
.then(cache => {
|
|
3584
|
+
const rows = cache && cache.rows
|
|
3585
|
+
// 0.9.1:seq 来自 node-key 精确查表,**不再**做文本前缀匹配验证
|
|
3586
|
+
// (旧的前缀包含匹配实测 4 条错 2 条 —— "继续" 命中 "继续,…")。
|
|
3587
|
+
const seq = Number(block.getAttribute('data-mops-seq'))
|
|
3588
|
+
const row = rows && rows.find(r => r.seq === seq)
|
|
3589
|
+
if (!row) {
|
|
3590
|
+
ensureAssign(sid)
|
|
3591
|
+
notifyDone(__t('errorPrefix') + (__t('revert.unresolved') || 'revert target verification failed'), 'error')
|
|
3592
|
+
return
|
|
3593
|
+
}
|
|
3594
|
+
btn.disabled = true
|
|
3595
|
+
Promise.resolve()
|
|
3596
|
+
.then(() =>
|
|
3597
|
+
fetch('/api/message-ops/revert', {
|
|
3598
|
+
method: 'POST',
|
|
3599
|
+
headers: { 'content-type': 'application/json' },
|
|
3600
|
+
body: JSON.stringify({ sessionId: sid, seq: row.seq }),
|
|
3601
|
+
}),
|
|
3602
|
+
)
|
|
3603
|
+
.then(async res => {
|
|
3604
|
+
let data = {}
|
|
3605
|
+
try {
|
|
3606
|
+
data = await res.json()
|
|
3607
|
+
} catch {
|
|
3608
|
+
/* keep {} */
|
|
3609
|
+
}
|
|
3610
|
+
if (!res.ok || !data.ok) throw new Error(data.error || 'HTTP ' + res.status)
|
|
3611
|
+
notifyDone(__t('done.revert'))
|
|
3612
|
+
// 0.9.6:统一回填出口 —— 这个入口原先也不回填
|
|
3613
|
+
refillComposer(sid, row.seq)
|
|
3614
|
+
emitChanged()
|
|
3615
|
+
try {
|
|
3616
|
+
if (__uiWorkspace && typeof __uiWorkspace.openSession === 'function') __uiWorkspace.openSession(sid)
|
|
3617
|
+
} catch {
|
|
3618
|
+
/* 视图重建失败不阻断 */
|
|
3619
|
+
}
|
|
3620
|
+
// 0.9.1:视图重建后重新拉权威可见性并隐藏被遮蔽的行。
|
|
3621
|
+
// openSession 会重挂 DOM,旧节点上的 hidden 属性随之失效,必须重刷。
|
|
3622
|
+
if (rowsCache) rowsCache.at = 0
|
|
3623
|
+
for (const delay of [150, 700, 1600])
|
|
3624
|
+
setTimeout(() => {
|
|
3625
|
+
if (__refreshSurface) __refreshSurface(sid)
|
|
3626
|
+
}, delay)
|
|
3627
|
+
})
|
|
3628
|
+
.catch(reason => {
|
|
3629
|
+
notifyDone(__t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error')
|
|
3630
|
+
})
|
|
3631
|
+
.finally(() => {
|
|
3632
|
+
btn.disabled = false
|
|
3633
|
+
})
|
|
3634
|
+
})
|
|
3635
|
+
}
|
|
3636
|
+
/**
|
|
3637
|
+
* 0.12.0 用户消息「从此条分叉」:非破坏操作,源会话一字不动。
|
|
3638
|
+
*
|
|
3639
|
+
* opencode 语义 = 复制此条**之前**的对话到一个新会话,并把此条原文放回
|
|
3640
|
+
* 新会话的输入框,让用户改完再发。因此这里要三步:
|
|
3641
|
+
* 1. 解析 seq(点击当下可能还没打标 → 先 ensureAssign 再 fetchRows)
|
|
3642
|
+
* 2. 取该条用户消息的**原文**(列表只携带 snippet,长度会被截断)
|
|
3643
|
+
* 3. fork(boundary = seq - 1) → 把原文写进子会话草稿 → 打开子会话
|
|
3644
|
+
*/
|
|
3645
|
+
var runUserFork = (btn, block) => {
|
|
3646
|
+
const sid = __currentSessionId
|
|
3647
|
+
if (!sid) return
|
|
3648
|
+
btn.disabled = true
|
|
3649
|
+
Promise.resolve()
|
|
3650
|
+
.then(() => ensureAssign(sid))
|
|
3651
|
+
.then(() => fetchRows(sid))
|
|
3652
|
+
.then(async cache => {
|
|
3653
|
+
const rows = cache && cache.rows
|
|
3654
|
+
const seq = Number(block.getAttribute('data-mops-seq'))
|
|
3655
|
+
const row = rows && rows.find(r => r.seq === seq)
|
|
3656
|
+
if (!row) {
|
|
3657
|
+
notifyDone(__t('errorPrefix') + (__t('revert.unresolved') || 'fork target verification failed'), 'error')
|
|
3658
|
+
return
|
|
3659
|
+
}
|
|
3660
|
+
if (!(seq > 0)) {
|
|
3661
|
+
notifyDone(__t('slot.forkUnavailable'), 'warn')
|
|
3662
|
+
return
|
|
3663
|
+
}
|
|
3664
|
+
let text = typeof row.fullText === 'string' ? row.fullText : ''
|
|
3665
|
+
if (!text) {
|
|
2602
3666
|
try {
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
3667
|
+
const res = await fetch(
|
|
3668
|
+
'/api/message-ops/text?sessionId=' + encodeURIComponent(bareSessionId(sid)) + '&seq=' + encodeURIComponent(seq),
|
|
3669
|
+
)
|
|
3670
|
+
const data = res.ok ? await res.json().catch(() => null) : null
|
|
3671
|
+
if (data && data.ok && typeof data.text === 'string') text = data.text
|
|
3672
|
+
} catch {
|
|
3673
|
+
/* 取全文失败:分叉照做,只是输入框留空 */
|
|
3674
|
+
}
|
|
3675
|
+
}
|
|
3676
|
+
const childId = await forkFromUserMessage(sid, seq, text, row.turnStartSeq)
|
|
3677
|
+
notifyDone(__t('slot.forkDone', { id: String(childId || '') }))
|
|
3678
|
+
if (childId) openSessionById(childId)
|
|
3679
|
+
})
|
|
3680
|
+
.catch(reason => {
|
|
3681
|
+
notifyDone(__t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error')
|
|
3682
|
+
})
|
|
3683
|
+
.finally(() => {
|
|
3684
|
+
btn.disabled = false
|
|
2614
3685
|
})
|
|
2615
3686
|
}
|
|
2616
|
-
|
|
3687
|
+
|
|
3688
|
+
var ensureBtn = block => {
|
|
2617
3689
|
// 官方动作行(含 Copy):把按钮放到这一行里,与 Copy 同级
|
|
2618
3690
|
let host = block.querySelector('[class*="xzv4MW_actions"]')
|
|
2619
3691
|
if (!host) {
|
|
@@ -2628,9 +3700,11 @@ window.__ModuleLoader__.load({
|
|
|
2628
3700
|
btn.className = 'mopsUserRevert'
|
|
2629
3701
|
btn.title = __t('slot.revert')
|
|
2630
3702
|
btn.setAttribute('aria-label', __t('slot.revert'))
|
|
2631
|
-
btn.innerHTML =
|
|
2632
|
-
|
|
2633
|
-
|
|
3703
|
+
btn.innerHTML =
|
|
3704
|
+
'<svg width="15" height="15" viewBox="0 0 16 16" fill="none"><path d="M2.5 8a5.5 5.5 0 1 0 1.6-3.9" stroke="currentColor" stroke-width="1.2"/><path d="M2.2 2.8v3h3" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/></svg>'
|
|
3705
|
+
btn.addEventListener('click', e => {
|
|
3706
|
+
e.preventDefault()
|
|
3707
|
+
e.stopPropagation()
|
|
2634
3708
|
if (btn.disabled) return
|
|
2635
3709
|
runUserRevert(btn, block)
|
|
2636
3710
|
})
|
|
@@ -2641,6 +3715,40 @@ window.__ModuleLoader__.load({
|
|
|
2641
3715
|
syncEnabled(block, btn)
|
|
2642
3716
|
return btn
|
|
2643
3717
|
}
|
|
3718
|
+
|
|
3719
|
+
/** 0.12.0 分叉按钮:与回滚按钮**同一动作行**(opencode 把 fork 放在 copy/undo 同组)。 */
|
|
3720
|
+
var ensureForkBtn = block => {
|
|
3721
|
+
let host = block.querySelector('[class*="xzv4MW_actions"]')
|
|
3722
|
+
if (!host) {
|
|
3723
|
+
host = document.createElement('div')
|
|
3724
|
+
host.className = 'mopsUserActionsRow'
|
|
3725
|
+
block.appendChild(host)
|
|
3726
|
+
}
|
|
3727
|
+
const existing = host.querySelector('.mopsUserFork')
|
|
3728
|
+
if (existing) return existing
|
|
3729
|
+
const btn = document.createElement('button')
|
|
3730
|
+
btn.type = 'button'
|
|
3731
|
+
btn.className = 'mopsUserFork'
|
|
3732
|
+
btn.title = __t('slot.forkHint')
|
|
3733
|
+
btn.setAttribute('aria-label', __t('slot.fork'))
|
|
3734
|
+
// 官方 IconBranchOutline16 的 1:1 路径(packages/client/ui-primitives/src/icons/index.tsx:149)
|
|
3735
|
+
btn.innerHTML =
|
|
3736
|
+
'<svg width="15" height="15" viewBox="0 0 16 16" fill="none" stroke="none"><path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M13.0762 1.37207C14.0846 1.37228 14.9021 2.19077 14.9023 3.19922C14.9022 4.20772 14.0847 5.02518 13.0762 5.02539C12.2967 5.02539 11.6325 4.53691 11.3701 3.84961H4.35547C4.79397 4.26458 5.15861 4.7644 5.41699 5.33496L7.10645 9.06738C7.88526 10.7875 9.55104 11.9228 11.4189 12.0371C11.7085 11.4109 12.3411 10.9756 13.0762 10.9756C14.0843 10.9759 14.9023 11.7936 14.9023 12.8018C14.9023 13.81 14.0843 14.6277 13.0762 14.6279C12.2534 14.6279 11.5574 14.0832 11.3291 13.335C8.9868 13.1879 6.89981 11.7612 5.92285 9.60352L4.23242 5.87109C3.67503 4.64033 2.44878 3.84961 1.09766 3.84961V2.54883C1.10665 2.54883 1.11601 2.54975 1.125 2.5498L11.3701 2.54883C11.6326 1.86151 12.2969 1.37207 13.0762 1.37207ZM13.0762 12.2764C12.7858 12.2764 12.5508 12.5114 12.5508 12.8018C12.5508 13.0921 12.7858 13.3281 13.0762 13.3281C13.3664 13.3279 13.6025 13.092 13.6025 12.8018C13.6025 12.5115 13.3664 12.2766 13.0762 12.2764ZM13.0762 2.67285C12.7855 2.67285 12.55 2.90861 12.5498 3.19922C12.5499 3.48987 12.7855 3.72559 13.0762 3.72559C13.3667 3.72538 13.6024 3.48975 13.6025 3.19922C13.6023 2.90874 13.3666 2.67306 13.0762 2.67285Z"/></svg>'
|
|
3737
|
+
btn.addEventListener('click', e => {
|
|
3738
|
+
e.preventDefault()
|
|
3739
|
+
e.stopPropagation()
|
|
3740
|
+
if (btn.disabled) return
|
|
3741
|
+
runUserFork(btn, block)
|
|
3742
|
+
})
|
|
3743
|
+
host.appendChild(btn)
|
|
3744
|
+
syncEnabled(block, btn)
|
|
3745
|
+
return btn
|
|
3746
|
+
}
|
|
3747
|
+
// 两个按钮的顺序由 DOM 顺序决定:回滚在前(破坏性更高),分叉在后(非破坏)。
|
|
3748
|
+
var ensureUserActions = block => {
|
|
3749
|
+
ensureBtn(block)
|
|
3750
|
+
ensureForkBtn(block)
|
|
3751
|
+
}
|
|
2644
3752
|
// 0.9.7(P0-2 读合并):把 150/700/1600ms 三档并成**一次**真网络请求,
|
|
2645
3753
|
// 落点 = 本 burst 第一档 + 1500ms ≈ 原来的 1600ms 那一档。
|
|
2646
3754
|
// 🔴 红线:这一档是「视图重建后重算隐藏」的兜底,绝不能砍成 0。
|
|
@@ -2648,49 +3756,92 @@ window.__ModuleLoader__.load({
|
|
|
2648
3756
|
// 共享窗口里的新鲜载荷先把隐藏刷对,不必等兜底那一发。
|
|
2649
3757
|
var refreshTimer = null
|
|
2650
3758
|
var refreshDeadline = 0
|
|
2651
|
-
__refreshSurface =
|
|
3759
|
+
__refreshSurface = sid => {
|
|
2652
3760
|
const id = sid || __currentSessionId
|
|
2653
3761
|
if (!id) return
|
|
2654
|
-
if (rowsCache) rowsCache.at = 0
|
|
3762
|
+
if (rowsCache) rowsCache.at = 0 // 强制重取权威数据
|
|
2655
3763
|
const now = Date.now()
|
|
2656
3764
|
if (!refreshTimer) refreshDeadline = now + 1500
|
|
2657
3765
|
clearTimeout(refreshTimer)
|
|
2658
|
-
refreshTimer = setTimeout(
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
3766
|
+
refreshTimer = setTimeout(
|
|
3767
|
+
() => {
|
|
3768
|
+
refreshTimer = null
|
|
3769
|
+
try {
|
|
3770
|
+
// 会话已切走就别把旧会话的 idx 刷到新会话的 DOM 上
|
|
3771
|
+
if (bareSessionId(__currentSessionId) !== bareSessionId(id)) return
|
|
3772
|
+
invalidateMessagesMemo() // 兜底档必须是真网络,不许吃缓存
|
|
3773
|
+
if (rowsCache) rowsCache.at = 0
|
|
3774
|
+
fetchRows(id)
|
|
3775
|
+
.then(cache => {
|
|
3776
|
+
if (cache && cache.idx) applySurfaceVisibility(document, cache.idx)
|
|
3777
|
+
})
|
|
3778
|
+
.catch(() => {})
|
|
3779
|
+
} catch {
|
|
3780
|
+
/* noop */
|
|
3781
|
+
}
|
|
3782
|
+
},
|
|
3783
|
+
Math.max(0, refreshDeadline - now),
|
|
3784
|
+
)
|
|
2670
3785
|
}
|
|
2671
3786
|
var scan = () => {
|
|
2672
3787
|
try {
|
|
2673
3788
|
const sid = __currentSessionId
|
|
2674
3789
|
if (!sid) return
|
|
2675
3790
|
const blocks = userAnchors()
|
|
2676
|
-
for (const b of blocks)
|
|
3791
|
+
for (const b of blocks) ensureUserActions(b)
|
|
3792
|
+
suppressHostBranch()
|
|
2677
3793
|
// 0.9.1:**始终**刷新(原先只在按钮未打标时刷)——
|
|
2678
3794
|
// 打标后 transcript 再变化(openSession 重建 / 分页 / restore 重放)
|
|
2679
3795
|
// 就再也不会重算隐藏,导致「界面停在旧状态,必须重载页面才对」。
|
|
2680
3796
|
ensureAssign(sid)
|
|
2681
|
-
} catch {
|
|
3797
|
+
} catch {
|
|
3798
|
+
/* 注入失败不影响会话 */
|
|
3799
|
+
}
|
|
3800
|
+
}
|
|
3801
|
+
/**
|
|
3802
|
+
* 0.12.0 隐藏官方 assistant turn-tail 上的 branch 按钮。
|
|
3803
|
+
*
|
|
3804
|
+
* 产品决定:分叉只属于**用户消息**(opencode 语义 —— fork 的目的是「这句话说错了,
|
|
3805
|
+
* 拿回输入框重说」,AI 消息没有可回填的原文,分叉出去只会得到一个半截对话)。
|
|
3806
|
+
* 官方把 branch 画在 MessageIconActions 里,与 copy 同一行;官方没有开关
|
|
3807
|
+
* (ui-chat 的 Config 只有折叠/性能/链接几项),所以只能在渲染层隐藏。
|
|
3808
|
+
*
|
|
3809
|
+
* 识别方式不用 aria-label(8 种语言各不同),也不用哈希 class,而用
|
|
3810
|
+
* **图标路径前缀**:官方 IconBranchOutline16 的 d 是固定字符串
|
|
3811
|
+
* (packages/client/ui-primitives/src/icons/index.tsx:149)。作用域限定在
|
|
3812
|
+
* `[data-turn-tail]`(官方 TurnTailNodeView 渲染的稳定属性),
|
|
3813
|
+
* 并排除我们自己注入的 .mopsUserFork(它复用同一 path)。
|
|
3814
|
+
*/
|
|
3815
|
+
var suppressHostBranch = () => {
|
|
3816
|
+
let hidden = 0
|
|
3817
|
+
for (const btn of document.querySelectorAll('[data-turn-tail] button')) {
|
|
3818
|
+
if (!isHostBranchButton(btn)) continue
|
|
3819
|
+
hidden++
|
|
3820
|
+
if (btn.getAttribute('data-mops-host-branch') !== 'hidden') {
|
|
3821
|
+
btn.setAttribute('data-mops-host-branch', 'hidden')
|
|
3822
|
+
btn.style.display = 'none'
|
|
3823
|
+
}
|
|
3824
|
+
}
|
|
3825
|
+
return hidden
|
|
2682
3826
|
}
|
|
3827
|
+
|
|
2683
3828
|
// 触发:hover / 滚动 / DOM 变化 / 变更事件
|
|
2684
|
-
document.addEventListener(
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
3829
|
+
document.addEventListener(
|
|
3830
|
+
'mouseover',
|
|
3831
|
+
e => {
|
|
3832
|
+
try {
|
|
3833
|
+
if (!e || !e.target || !e.target.closest) return
|
|
3834
|
+
if (!__currentSessionId) return
|
|
3835
|
+
const block = e.target.closest('[class*="Sixlwa_userRow"], [data-chat-flow-kind="user"]')
|
|
3836
|
+
if (!block) return
|
|
3837
|
+
ensureUserActions(block)
|
|
3838
|
+
if (!block.hasAttribute('data-mops-seq')) ensureAssign(__currentSessionId)
|
|
3839
|
+
} catch {
|
|
3840
|
+
/* noop */
|
|
3841
|
+
}
|
|
3842
|
+
},
|
|
3843
|
+
{ passive: true },
|
|
3844
|
+
)
|
|
2694
3845
|
window.addEventListener('scroll', scan, { passive: true })
|
|
2695
3846
|
try {
|
|
2696
3847
|
// 0.9.7(P1-2)回调过滤 + maxWait。
|
|
@@ -2704,7 +3855,7 @@ window.__ModuleLoader__.load({
|
|
|
2704
3855
|
// 这是正确性问题,不只是性能。
|
|
2705
3856
|
// ③ attributeFilter 只盯 data-chat-node-key:本插件不写该属性(写的是
|
|
2706
3857
|
// data-mops-seq / hidden),所以不会被自己触发成环。
|
|
2707
|
-
var MO_SEL = '[data-chat-node-key],[data-chat-flow-kind="user"],[class*="xzv4MW_actions"],[class*="_userRow"]'
|
|
3858
|
+
var MO_SEL = '[data-chat-node-key],[data-chat-flow-kind="user"],[class*="xzv4MW_actions"],[class*="_userRow"],[data-turn-tail]'
|
|
2708
3859
|
var scanPendingSince = 0
|
|
2709
3860
|
var scheduleScan = () => {
|
|
2710
3861
|
var now = Date.now()
|
|
@@ -2718,36 +3869,56 @@ window.__ModuleLoader__.load({
|
|
|
2718
3869
|
return
|
|
2719
3870
|
}
|
|
2720
3871
|
clearTimeout(scan._t)
|
|
2721
|
-
scan._t = setTimeout(() => {
|
|
3872
|
+
scan._t = setTimeout(() => {
|
|
3873
|
+
scan._t = null
|
|
3874
|
+
scanPendingSince = 0
|
|
3875
|
+
scan()
|
|
3876
|
+
}, 200)
|
|
2722
3877
|
}
|
|
2723
|
-
var mo = new MutationObserver(
|
|
3878
|
+
var mo = new MutationObserver(records => {
|
|
2724
3879
|
try {
|
|
2725
3880
|
for (var i = 0; i < records.length; i++) {
|
|
2726
3881
|
var rec = records[i]
|
|
2727
3882
|
if (rec.type === 'attributes') {
|
|
2728
3883
|
var tgt = rec.target
|
|
2729
|
-
if (tgt && tgt.nodeType === 1 && typeof tgt.matches === 'function' && tgt.matches(MO_SEL)) {
|
|
3884
|
+
if (tgt && tgt.nodeType === 1 && typeof tgt.matches === 'function' && tgt.matches(MO_SEL)) {
|
|
3885
|
+
scheduleScan()
|
|
3886
|
+
return
|
|
3887
|
+
}
|
|
2730
3888
|
continue
|
|
2731
3889
|
}
|
|
2732
3890
|
var added = rec.addedNodes
|
|
2733
3891
|
for (var j = 0; j < added.length; j++) {
|
|
2734
3892
|
var n = added[j]
|
|
2735
3893
|
if (!n || n.nodeType !== 1) continue
|
|
2736
|
-
if (
|
|
2737
|
-
|
|
3894
|
+
if (
|
|
3895
|
+
(typeof n.matches === 'function' && n.matches(MO_SEL)) ||
|
|
3896
|
+
(typeof n.querySelector === 'function' && n.querySelector(MO_SEL))
|
|
3897
|
+
) {
|
|
3898
|
+
scheduleScan()
|
|
3899
|
+
return
|
|
3900
|
+
}
|
|
2738
3901
|
}
|
|
2739
3902
|
}
|
|
2740
|
-
} catch {
|
|
3903
|
+
} catch {
|
|
3904
|
+
scheduleScan()
|
|
3905
|
+
}
|
|
2741
3906
|
})
|
|
2742
3907
|
mo.observe(document.body, {
|
|
2743
|
-
childList: true,
|
|
2744
|
-
|
|
3908
|
+
childList: true,
|
|
3909
|
+
subtree: true,
|
|
3910
|
+
attributes: true,
|
|
3911
|
+
attributeFilter: ['data-chat-node-key'],
|
|
2745
3912
|
})
|
|
2746
|
-
} catch {
|
|
3913
|
+
} catch {
|
|
3914
|
+
/* noop */
|
|
3915
|
+
}
|
|
2747
3916
|
window.addEventListener(CHANGED_EVENT, () => {
|
|
2748
3917
|
try {
|
|
2749
|
-
document.querySelectorAll('[data-mops-seq]').forEach(
|
|
2750
|
-
} catch {
|
|
3918
|
+
document.querySelectorAll('[data-mops-seq]').forEach(b => b.removeAttribute('data-mops-seq'))
|
|
3919
|
+
} catch {
|
|
3920
|
+
/* noop */
|
|
3921
|
+
}
|
|
2751
3922
|
})
|
|
2752
3923
|
// 样式:与官方 action 按钮同款(28px、ghost),可见性继承宿主动作行
|
|
2753
3924
|
try {
|
|
@@ -2757,15 +3928,17 @@ window.__ModuleLoader__.load({
|
|
|
2757
3928
|
tag.textContent = [
|
|
2758
3929
|
// 不再用 absolute + :hover:按钮作为宿主动作行的子元素,
|
|
2759
3930
|
// 由宿主 [data-actions-reveal] 统一控制显隐(触屏也跟着宿主走)。
|
|
2760
|
-
'.mopsUserRevert{display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border:none;border-radius:6px;background:transparent;color:var(--dsw-alias-label-tertiary,#9a9aa0);cursor:pointer;padding:0;flex:none}',
|
|
2761
|
-
'.mopsUserRevert:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.12))}',
|
|
2762
|
-
'.mopsUserRevert:disabled{opacity:.4;cursor:default}',
|
|
3931
|
+
'.mopsUserRevert,.mopsUserFork{display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border:none;border-radius:6px;background:transparent;color:var(--dsw-alias-label-tertiary,#9a9aa0);cursor:pointer;padding:0;flex:none}',
|
|
3932
|
+
'.mopsUserRevert:hover,.mopsUserFork:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.12))}',
|
|
3933
|
+
'.mopsUserRevert:disabled,.mopsUserFork:disabled{opacity:.4;cursor:default}',
|
|
2763
3934
|
'.mopsUserActionsRow{height:28px;display:flex;align-items:center;gap:8px;margin-left:-6px}',
|
|
2764
3935
|
'@media (hover:none){.mopsUserActionsRow{opacity:1}}',
|
|
2765
3936
|
].join('')
|
|
2766
3937
|
document.head.appendChild(tag)
|
|
2767
3938
|
}
|
|
2768
|
-
} catch {
|
|
3939
|
+
} catch {
|
|
3940
|
+
/* style 注入失败不影响功能 */
|
|
3941
|
+
}
|
|
2769
3942
|
}
|
|
2770
3943
|
|
|
2771
3944
|
function ensureSidebarOpsItem() {
|
|
@@ -2779,18 +3952,29 @@ window.__ModuleLoader__.load({
|
|
|
2779
3952
|
item.setAttribute('role', 'menuitem')
|
|
2780
3953
|
item.setAttribute('data-dsh-message-ops', '1')
|
|
2781
3954
|
item.style.cssText = [
|
|
2782
|
-
'display:flex',
|
|
2783
|
-
'
|
|
3955
|
+
'display:flex',
|
|
3956
|
+
'align-items:center',
|
|
3957
|
+
'gap:8px',
|
|
3958
|
+
'width:100%',
|
|
3959
|
+
'padding:6px 12px',
|
|
3960
|
+
'border:none',
|
|
3961
|
+
'background:transparent',
|
|
2784
3962
|
'color:var(--dsw-alias-label-primary,inherit)',
|
|
2785
|
-
'font:inherit',
|
|
2786
|
-
'
|
|
3963
|
+
'font:inherit',
|
|
3964
|
+
'font-size:13px',
|
|
3965
|
+
'line-height:20px',
|
|
3966
|
+
'text-align:left',
|
|
3967
|
+
'border-radius:6px',
|
|
3968
|
+
'cursor:pointer',
|
|
2787
3969
|
].join(';')
|
|
2788
3970
|
item.innerHTML = branchIconMarkup(16) + '<span></span>'
|
|
2789
3971
|
item.querySelector('span').textContent = __t('menu.ops')
|
|
2790
3972
|
item.addEventListener('mouseenter', function () {
|
|
2791
3973
|
item.style.background = 'var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.14))'
|
|
2792
3974
|
})
|
|
2793
|
-
item.addEventListener('mouseleave', function () {
|
|
3975
|
+
item.addEventListener('mouseleave', function () {
|
|
3976
|
+
item.style.background = 'transparent'
|
|
3977
|
+
})
|
|
2794
3978
|
item.addEventListener('click', function () {
|
|
2795
3979
|
var titleEl = row.querySelector('[class*=title]')
|
|
2796
3980
|
var title = titleEl ? String(titleEl.innerText || '').trim() : ''
|
|
@@ -2818,7 +4002,11 @@ window.__ModuleLoader__.load({
|
|
|
2818
4002
|
function installSidebarOps() {
|
|
2819
4003
|
if (window.__dshMessageOpsSidebarInstalled) return
|
|
2820
4004
|
window.__dshMessageOpsSidebarInstalled = true
|
|
2821
|
-
try {
|
|
4005
|
+
try {
|
|
4006
|
+
ensureSidebarOpsItem()
|
|
4007
|
+
} catch (e) {
|
|
4008
|
+
/* never crash the UI */
|
|
4009
|
+
}
|
|
2822
4010
|
// 观察范围收窄(评审 M2):仍需 observe document.body(会话行菜单由宿主
|
|
2823
4011
|
// React 动态渲染在侧栏任意挂载点,安装期无法锚定稳定容器),但回调改为
|
|
2824
4012
|
// 精确过滤——只有新增节点本身就是(或包含)[role=menu] 时才调度探测,
|
|
@@ -2830,7 +4018,11 @@ window.__ModuleLoader__.load({
|
|
|
2830
4018
|
pending = true
|
|
2831
4019
|
setTimeout(function () {
|
|
2832
4020
|
pending = false
|
|
2833
|
-
try {
|
|
4021
|
+
try {
|
|
4022
|
+
ensureSidebarOpsItem()
|
|
4023
|
+
} catch (e) {
|
|
4024
|
+
/* never crash the UI */
|
|
4025
|
+
}
|
|
2834
4026
|
}, 0)
|
|
2835
4027
|
}
|
|
2836
4028
|
var observer = new MutationObserver(function (mutations) {
|
|
@@ -2841,10 +4033,16 @@ window.__ModuleLoader__.load({
|
|
|
2841
4033
|
if (n.nodeType !== 1) continue
|
|
2842
4034
|
var isMenu = false
|
|
2843
4035
|
try {
|
|
2844
|
-
isMenu =
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
4036
|
+
isMenu =
|
|
4037
|
+
(typeof n.matches === 'function' && n.matches('[role=menu]')) ||
|
|
4038
|
+
(typeof n.querySelector === 'function' && n.querySelector('[role=menu]') !== null)
|
|
4039
|
+
} catch (e) {
|
|
4040
|
+
isMenu = false
|
|
4041
|
+
}
|
|
4042
|
+
if (isMenu) {
|
|
4043
|
+
scheduleEnsure()
|
|
4044
|
+
return
|
|
4045
|
+
}
|
|
2848
4046
|
}
|
|
2849
4047
|
}
|
|
2850
4048
|
})
|
|
@@ -2860,10 +4058,11 @@ window.__ModuleLoader__.load({
|
|
|
2860
4058
|
if (typeof locale.register === 'function') {
|
|
2861
4059
|
ctx.effect(() => locale.register(NS, { zh: zhDict, en: enDict }))
|
|
2862
4060
|
}
|
|
2863
|
-
} catch {
|
|
4061
|
+
} catch {
|
|
4062
|
+
/* namespace already registered: keep existing copy */
|
|
4063
|
+
}
|
|
2864
4064
|
}
|
|
2865
4065
|
|
|
2866
|
-
|
|
2867
4066
|
// ═══ 0.9.3 /undo —— opencode 招牌交互 ═════════════════════════════════════
|
|
2868
4067
|
//
|
|
2869
4068
|
// 「我说的那句话不对」→ 一个命令 → 消息从 transcript 消失 + 原文回输入框。
|
|
@@ -2904,7 +4103,7 @@ window.__ModuleLoader__.load({
|
|
|
2904
4103
|
|
|
2905
4104
|
/** 执行 undo/redo。返回 true 表示确实动过盘。 */
|
|
2906
4105
|
/** __currentSessionId 来自 DOM dataset,可能带 `session-` 前缀;API 只要裸 uuid。 */
|
|
2907
|
-
var bareSessionId =
|
|
4106
|
+
var bareSessionId = id => String(id || '').replace(/^session-/, '')
|
|
2908
4107
|
/** 写盘成功后的统一收尾:通知、刷新、重放隐藏。 */
|
|
2909
4108
|
/**
|
|
2910
4109
|
* 写盘成功后的统一收尾。
|
|
@@ -2927,7 +4126,10 @@ window.__ModuleLoader__.load({
|
|
|
2927
4126
|
if (window.__MOPS_DEBUG) console.warn('[message-ops] openSession failed:', e)
|
|
2928
4127
|
}
|
|
2929
4128
|
const bare = bareSessionId(rawSid)
|
|
2930
|
-
for (const delay of [150, 700, 1600])
|
|
4129
|
+
for (const delay of [150, 700, 1600])
|
|
4130
|
+
setTimeout(() => {
|
|
4131
|
+
if (__refreshSurface) __refreshSurface(bare)
|
|
4132
|
+
}, delay)
|
|
2931
4133
|
}
|
|
2932
4134
|
|
|
2933
4135
|
/**
|
|
@@ -2955,13 +4157,17 @@ window.__ModuleLoader__.load({
|
|
|
2955
4157
|
if (!cache || !Array.isArray(cache.rows)) return false
|
|
2956
4158
|
const want = bareSessionId(rawSid)
|
|
2957
4159
|
if (bareSessionId(cache.sid) !== want) return false
|
|
2958
|
-
const rows = cache.rows.filter(
|
|
4160
|
+
const rows = cache.rows.filter(r => r && typeof r.seq === 'number' && r.seq <= boundarySeq && r.fullText)
|
|
2959
4161
|
if (!rows.length) return false
|
|
2960
4162
|
if (!__inputActions || typeof __inputActions.setDraft !== 'function') return false
|
|
2961
4163
|
__inputActions.setDraft(rows[rows.length - 1].fullText)
|
|
2962
4164
|
// 关键:不落盘的话,紧随其后的 openSession 会从 localStorage 读回旧草稿。
|
|
2963
4165
|
if (typeof __inputActions.persistDraft === 'function') {
|
|
2964
|
-
try {
|
|
4166
|
+
try {
|
|
4167
|
+
__inputActions.persistDraft()
|
|
4168
|
+
} catch (e) {
|
|
4169
|
+
console.warn('[message-ops] persistDraft failed:', e)
|
|
4170
|
+
}
|
|
2965
4171
|
}
|
|
2966
4172
|
return true
|
|
2967
4173
|
} catch (e) {
|
|
@@ -2979,16 +4185,23 @@ window.__ModuleLoader__.load({
|
|
|
2979
4185
|
var runUndo = () => {
|
|
2980
4186
|
const rawSid = __currentSessionId
|
|
2981
4187
|
const sid = bareSessionId(rawSid)
|
|
2982
|
-
if (!sid) {
|
|
4188
|
+
if (!sid) {
|
|
4189
|
+
notifyDone(__t('undo.none') || '没有可回滚的消息', 'error')
|
|
4190
|
+
return false
|
|
4191
|
+
}
|
|
2983
4192
|
const target = lastRevertable()
|
|
2984
|
-
if (!target) {
|
|
4193
|
+
if (!target) {
|
|
4194
|
+
notifyDone(__t('undo.none') || '没有可回滚的消息', 'error')
|
|
4195
|
+
return false
|
|
4196
|
+
}
|
|
2985
4197
|
fetch('/api/message-ops/revert', {
|
|
2986
|
-
method: 'POST',
|
|
4198
|
+
method: 'POST',
|
|
4199
|
+
headers: { 'content-type': 'application/json' },
|
|
2987
4200
|
body: JSON.stringify({ sessionId: sid, seq: target.seq }),
|
|
2988
4201
|
})
|
|
2989
|
-
.then(async
|
|
4202
|
+
.then(async res => {
|
|
2990
4203
|
const data = await res.json().catch(() => ({}))
|
|
2991
|
-
if (!res.ok || !data.ok) throw new Error(data.error ||
|
|
4204
|
+
if (!res.ok || !data.ok) throw new Error(data.error || 'HTTP ' + res.status)
|
|
2992
4205
|
// 0.11.3:立刻把本行标成已遮蔽,否则 afterWrite 的异步刷新窗里
|
|
2993
4206
|
// 再点一次 /undo 仍会选中同一个 seq → 409。
|
|
2994
4207
|
const rowsCache = __peekRowsCache ? __peekRowsCache() : null
|
|
@@ -2998,10 +4211,10 @@ window.__ModuleLoader__.load({
|
|
|
2998
4211
|
}
|
|
2999
4212
|
rowsCache.at = 0
|
|
3000
4213
|
}
|
|
3001
|
-
refillComposer(rawSid, target.seq)
|
|
4214
|
+
refillComposer(rawSid, target.seq) // 先回填,再重建视图(与对话框一致)
|
|
3002
4215
|
afterWrite(rawSid, __t('undo.done.undo'))
|
|
3003
4216
|
})
|
|
3004
|
-
.catch(
|
|
4217
|
+
.catch(reason => notifyDone(__t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error'))
|
|
3005
4218
|
return true
|
|
3006
4219
|
}
|
|
3007
4220
|
|
|
@@ -3017,27 +4230,31 @@ window.__ModuleLoader__.load({
|
|
|
3017
4230
|
const sid = bareSessionId(rawSid)
|
|
3018
4231
|
if (!sid) return false
|
|
3019
4232
|
fetchMessagesJson('/api/message-ops/messages?sessionId=' + encodeURIComponent(sid))
|
|
3020
|
-
.then(
|
|
4233
|
+
.then(d => {
|
|
3021
4234
|
if (!d || !d.ok) throw new Error((d && d.error) || 'messages unavailable')
|
|
3022
4235
|
const markers = activeMarkers(d.messages || [])
|
|
3023
|
-
if (!markers.length) {
|
|
3024
|
-
|
|
4236
|
+
if (!markers.length) {
|
|
4237
|
+
notifyDone(__t('undo.none.redo') || '没有可恢复的回滚', 'error')
|
|
4238
|
+
return null
|
|
4239
|
+
}
|
|
4240
|
+
const mk = markers[markers.length - 1] // 最新一条未恢复标记
|
|
3025
4241
|
return fetch('/api/message-ops/restore', {
|
|
3026
|
-
method: 'POST',
|
|
4242
|
+
method: 'POST',
|
|
4243
|
+
headers: { 'content-type': 'application/json' },
|
|
3027
4244
|
body: JSON.stringify({ sessionId: sid, seq: mk.seq }),
|
|
3028
|
-
}).then(async
|
|
4245
|
+
}).then(async res => {
|
|
3029
4246
|
const data = await res.json().catch(() => ({}))
|
|
3030
|
-
if (!res.ok || !data.ok) throw new Error(data.error ||
|
|
4247
|
+
if (!res.ok || !data.ok) throw new Error(data.error || 'HTTP ' + res.status)
|
|
3031
4248
|
// afterWrite 契约:rawSid 必须带 session- 前缀(传裸 uuid 会抛
|
|
3032
4249
|
// `sessions.retain: unknown session` 并被外层 catch 静默吞掉)
|
|
3033
4250
|
afterWrite(rawSid, __t('undo.done.redo'))
|
|
3034
4251
|
})
|
|
3035
4252
|
})
|
|
3036
|
-
.catch(
|
|
4253
|
+
.catch(reason => notifyDone(__t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error'))
|
|
3037
4254
|
return true
|
|
3038
4255
|
}
|
|
3039
4256
|
|
|
3040
|
-
var runUndoRedo =
|
|
4257
|
+
var runUndoRedo = kind => (kind === 'redo' ? runRedo() : runUndo())
|
|
3041
4258
|
|
|
3042
4259
|
/** 注册 /undo /redo 到官方斜杠管线。服务缺失时安静 no-op。 */
|
|
3043
4260
|
var __undoRegistered = false
|
|
@@ -3045,107 +4262,153 @@ window.__ModuleLoader__.load({
|
|
|
3045
4262
|
if (__undoRegistered || !it || typeof it.registerSource !== 'function') return
|
|
3046
4263
|
__undoRegistered = true
|
|
3047
4264
|
try {
|
|
3048
|
-
ctx.effect(() =>
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
4265
|
+
ctx.effect(() =>
|
|
4266
|
+
it.registerSource({
|
|
4267
|
+
trigger: '/',
|
|
4268
|
+
name: __undoSourceName,
|
|
4269
|
+
order: 20,
|
|
4270
|
+
showGroupTitle: true,
|
|
4271
|
+
// ⚠️ 必须返回 **Promise**:宿主在 InputTriggerController.fetchCandidates 里
|
|
4272
|
+
// 直接 `source.candidates(...).then(...)`,同步返回数组会抛
|
|
4273
|
+
// `source.candidates(...).then is not a function`,整个菜单静默失效。
|
|
4274
|
+
candidates: async (session, req) => {
|
|
4275
|
+
const q = String((req && req.query) || '')
|
|
4276
|
+
.trim()
|
|
4277
|
+
.toLowerCase()
|
|
4278
|
+
return UNDO_CANDIDATES.filter(c => !q || c.name.includes(q)).map(c => ({
|
|
3061
4279
|
name: c.name,
|
|
3062
4280
|
icon: c.icon,
|
|
3063
|
-
label: c.name === 'undo'
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
: (__t('redo.desc') || '把回滚掉的消息重新放回对话'),
|
|
4281
|
+
label: c.name === 'undo' ? __t('undo.label') || '回滚上一条消息' : __t('redo.label') || '恢复上一条被回滚的消息',
|
|
4282
|
+
description:
|
|
4283
|
+
c.name === 'undo'
|
|
4284
|
+
? __t('undo.desc') || '移除最后一条用户消息,原文回填输入框'
|
|
4285
|
+
: __t('redo.desc') || '把回滚掉的消息重新放回对话',
|
|
3069
4286
|
value: c.value,
|
|
3070
4287
|
}))
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
4288
|
+
},
|
|
4289
|
+
onPick: pick => {
|
|
4290
|
+
const v = pick && pick.candidate && pick.candidate.value
|
|
4291
|
+
if (v !== 'undo' && v !== 'redo') return undefined
|
|
4292
|
+
runUndoRedo(v)
|
|
4293
|
+
return 'handled'
|
|
4294
|
+
},
|
|
4295
|
+
// Enter 直接执行:`/undo` 不必先在菜单里选中
|
|
4296
|
+
matchEnter: (session, line) => {
|
|
4297
|
+
const t = String(line || '')
|
|
4298
|
+
.trim()
|
|
4299
|
+
.toLowerCase()
|
|
4300
|
+
if (t !== '/undo' && t !== '/redo') return undefined
|
|
4301
|
+
runUndoRedo(t === '/redo' ? 'redo' : 'undo')
|
|
4302
|
+
return 'handled'
|
|
4303
|
+
},
|
|
4304
|
+
}),
|
|
4305
|
+
)
|
|
3086
4306
|
} catch (e) {
|
|
3087
4307
|
__undoRegistered = false
|
|
3088
4308
|
if (window.__MOPS_DEBUG) console.warn('[message-ops] /undo 注册失败:', e)
|
|
3089
4309
|
}
|
|
3090
4310
|
}
|
|
3091
4311
|
|
|
3092
|
-
var registerUndoSlash =
|
|
4312
|
+
var registerUndoSlash = ctx => {
|
|
3093
4313
|
// ⚠️ cordis 的 inject 回调**第一个参数是服务本身**,不是 ctx。
|
|
3094
4314
|
// 早先写成 `registerUndoSlash(sub.ctx || sub)` → 在服务对象上找 .get
|
|
3095
4315
|
// 必然是 undefined → 静默不注册(表现为 /undo 根本不出现)。
|
|
3096
4316
|
const it = typeof ctx.get === 'function' ? ctx.get('inputTriggers') : null
|
|
3097
|
-
if (it) {
|
|
4317
|
+
if (it) {
|
|
4318
|
+
doRegisterUndoSlash(ctx, it)
|
|
4319
|
+
return
|
|
4320
|
+
}
|
|
3098
4321
|
try {
|
|
3099
4322
|
// ⚠️ cordis inject 回调收到的是**注入命名空间**,服务在其同名字段下
|
|
3100
4323
|
// (与本文件 `ctx.inject(['uiWorkspace'], sub => sub.uiWorkspace || sub)` 同模式)。
|
|
3101
4324
|
// 直接把 sub 当服务用会抛 `cannot get property "registerSource" without inject`。
|
|
3102
|
-
ctx.inject(['inputTriggers'],
|
|
4325
|
+
ctx.inject(['inputTriggers'], sub => {
|
|
3103
4326
|
doRegisterUndoSlash(ctx, sub && (sub.inputTriggers || sub))
|
|
3104
4327
|
})
|
|
3105
|
-
} catch (e) {
|
|
3106
|
-
}
|
|
4328
|
+
} catch (e) {}
|
|
3107
4329
|
}
|
|
3108
4330
|
|
|
3109
4331
|
function apply(ctx) {
|
|
3110
4332
|
__sessionsSvc = ctx.get('sessions')
|
|
3111
4333
|
__uiWorkspace = typeof ctx.get === 'function' ? ctx.get('uiWorkspace') : null
|
|
3112
4334
|
if (!__uiWorkspace) {
|
|
3113
|
-
try {
|
|
4335
|
+
try {
|
|
4336
|
+
ctx.inject(['uiWorkspace'], sub => {
|
|
4337
|
+
__uiWorkspace = sub.uiWorkspace || sub
|
|
4338
|
+
})
|
|
4339
|
+
} catch {
|
|
4340
|
+
/* 0.1.x 无此服务 */
|
|
4341
|
+
}
|
|
3114
4342
|
}
|
|
3115
4343
|
if (!__sessionsSvc) {
|
|
3116
|
-
ctx.inject(['sessions'],
|
|
4344
|
+
ctx.inject(['sessions'], sub => {
|
|
4345
|
+
__sessionsSvc = sub.sessions
|
|
4346
|
+
})
|
|
3117
4347
|
}
|
|
3118
4348
|
registerUndoSlash(ctx)
|
|
3119
4349
|
adoptLocale(ctx.get('locale'), ctx)
|
|
3120
4350
|
if (!__locale) {
|
|
3121
|
-
ctx.inject(['locale'],
|
|
4351
|
+
ctx.inject(['locale'], sub => {
|
|
3122
4352
|
adoptLocale(sub.locale, ctx)
|
|
3123
4353
|
refreshSidebarOpsLabel()
|
|
3124
4354
|
})
|
|
3125
4355
|
}
|
|
3126
4356
|
ctx.on('locale/change', refreshSidebarOpsLabel)
|
|
3127
|
-
if (window.__MOPS_DISABLE_HEADER !== true)
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
4357
|
+
if (window.__MOPS_DISABLE_HEADER !== true)
|
|
4358
|
+
ctx.slots.inject(SLOT, () =>
|
|
4359
|
+
ctx.slots.register(
|
|
4360
|
+
{
|
|
4361
|
+
name: SLOT,
|
|
4362
|
+
id: ROW_ID,
|
|
4363
|
+
order: 31,
|
|
4364
|
+
...(__locale ? { locale: NS } : {}),
|
|
4365
|
+
},
|
|
4366
|
+
OpsButton,
|
|
4367
|
+
),
|
|
4368
|
+
)
|
|
3131
4369
|
// 0.3.0:每条 AI 消息旁的原生回撤按钮(0.1.x 无此槽,inject 自动 no-op)
|
|
3132
|
-
ctx.slots.inject(CHAT_ACTIONS_SLOT, () =>
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
4370
|
+
ctx.slots.inject(CHAT_ACTIONS_SLOT, () =>
|
|
4371
|
+
ctx.slots.register(
|
|
4372
|
+
{
|
|
4373
|
+
name: CHAT_ACTIONS_SLOT,
|
|
4374
|
+
id: CHAT_ACTIONS_ID,
|
|
4375
|
+
order: 20,
|
|
4376
|
+
...(__locale ? { locale: NS } : {}),
|
|
4377
|
+
},
|
|
4378
|
+
MsgSlotActions,
|
|
4379
|
+
),
|
|
4380
|
+
)
|
|
3136
4381
|
// 0.4.0:composer 上方回撤 dock(0.1.x 无此槽自动 no-op)
|
|
3137
|
-
ctx.slots.inject(INPUT_DOCK_SLOT, () =>
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
4382
|
+
ctx.slots.inject(INPUT_DOCK_SLOT, () =>
|
|
4383
|
+
ctx.slots.register(
|
|
4384
|
+
{
|
|
4385
|
+
name: INPUT_DOCK_SLOT,
|
|
4386
|
+
id: INPUT_DOCK_ID,
|
|
4387
|
+
order: 10,
|
|
4388
|
+
...(__locale ? { locale: NS } : {}),
|
|
4389
|
+
},
|
|
4390
|
+
RevertDock,
|
|
4391
|
+
),
|
|
4392
|
+
)
|
|
4393
|
+
ctx.slots.inject(OVERLAY_SLOT, () =>
|
|
4394
|
+
ctx.slots.register(
|
|
4395
|
+
{
|
|
4396
|
+
name: OVERLAY_SLOT,
|
|
4397
|
+
id: DIALOG_ID,
|
|
4398
|
+
order: 101,
|
|
4399
|
+
...(__locale ? { locale: NS } : {}),
|
|
4400
|
+
},
|
|
4401
|
+
window.__MOPS_LEGACY_DIALOG === true ? OpsDialog : OpsPanel,
|
|
4402
|
+
),
|
|
4403
|
+
)
|
|
3145
4404
|
installSidebarOps()
|
|
3146
4405
|
installUserRevertInjector()
|
|
3147
4406
|
}
|
|
3148
4407
|
|
|
3149
|
-
return {
|
|
4408
|
+
return {
|
|
4409
|
+
apply,
|
|
4410
|
+
inject: ['slots'],
|
|
4411
|
+
__test: { activityTransition, forkBoundaryBefore, isHostBranchButton, writeSessionDraft, HOST_BRANCH_D_PREFIX },
|
|
4412
|
+
}
|
|
3150
4413
|
},
|
|
3151
4414
|
})
|