@240xu/dsh-message-ops 0.12.0 → 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 +38 -0
- package/package.json +1 -1
- package/src/client.js +2016 -1046
- package/src/index.js +830 -562
- 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
|
}
|
|
@@ -132,7 +152,7 @@ window.__ModuleLoader__.load({
|
|
|
132
152
|
'done.revert': '回滚完成,刷新页面后生效',
|
|
133
153
|
'done.delete': '删除完成,刷新页面后生效',
|
|
134
154
|
'action.reload': '刷新页面',
|
|
135
|
-
|
|
155
|
+
errorPrefix: '操作失败:',
|
|
136
156
|
'dock.title': '已回撤 {n} 条消息',
|
|
137
157
|
'dock.expand': '展开回撤列表',
|
|
138
158
|
'dock.collapse': '折叠回撤列表',
|
|
@@ -230,20 +250,23 @@ window.__ModuleLoader__.load({
|
|
|
230
250
|
'dialog.showMore': 'Show more ({n} older)',
|
|
231
251
|
'dialog.more': '…(showing latest 200 of {n})',
|
|
232
252
|
'op.revert': 'Revert: remove this message and everything after',
|
|
233
|
-
'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.',
|
|
234
255
|
'op.delete': 'Delete only this message',
|
|
235
256
|
'op.deleteDesc': 'Shadows only the picked message; everything else stays.',
|
|
236
257
|
'op.branch': 'Branch into a new session from here',
|
|
237
258
|
'op.branchDesc': 'Copies everything up to and including the picked message into a new session (original untouched, non-destructive).',
|
|
238
259
|
'slot.revert': 'Revert to here',
|
|
239
|
-
'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.',
|
|
240
262
|
'slot.fork': 'Branch from here',
|
|
241
263
|
'slot.forkHint': 'Copies the conversation above this message into a new session and puts this message back in the new composer',
|
|
242
264
|
'slot.forkDone': 'Branched: new session {id}',
|
|
243
265
|
'slot.forkUnavailable': 'Branch unavailable: the session is running, or the host provides no session/fork',
|
|
244
266
|
'toast.openNew': 'Open new session',
|
|
245
267
|
'fork.official': 'Branched (official fork): new session {id}',
|
|
246
|
-
'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.',
|
|
247
270
|
'ack.revert': 'I understand: revert shadows the picked message and everything after it',
|
|
248
271
|
'ack.delete': 'I understand: this message will be shadowed (kept in the log)',
|
|
249
272
|
'confirm.revert': 'Revert',
|
|
@@ -256,7 +279,7 @@ window.__ModuleLoader__.load({
|
|
|
256
279
|
'done.revert': 'Reverted; reload to apply',
|
|
257
280
|
'done.delete': 'Deleted; reload to apply',
|
|
258
281
|
'action.reload': 'Reload page',
|
|
259
|
-
|
|
282
|
+
errorPrefix: 'Operation failed: ',
|
|
260
283
|
'dock.title': '{n} rolled back messages',
|
|
261
284
|
'dock.expand': 'Expand revert list',
|
|
262
285
|
'dock.collapse': 'Collapse revert list',
|
|
@@ -296,7 +319,8 @@ window.__ModuleLoader__.load({
|
|
|
296
319
|
'panel.revert': 'Revert to here',
|
|
297
320
|
'panel.revertHint': 'Includes this message and all visible messages after it',
|
|
298
321
|
'panel.revertConfirmTitle': 'Revert to #{seq}?',
|
|
299
|
-
'panel.revertConfirmBody':
|
|
322
|
+
'panel.revertConfirmBody':
|
|
323
|
+
'This shadows {n} messages (#{start}–#{end}), including {v} visible. The log stays append-only and can be restored.',
|
|
300
324
|
'panel.deleteConfirmTitle': 'Delete only #{seq}?',
|
|
301
325
|
'panel.deleteConfirmBody': 'This shadows this one message; everything else stays. The log stays append-only and can be restored.',
|
|
302
326
|
'panel.confirmRevert': 'Confirm revert',
|
|
@@ -351,7 +375,7 @@ window.__ModuleLoader__.load({
|
|
|
351
375
|
// 0.9.3:注入器闭包内 rowsCache 的只读出口。
|
|
352
376
|
// rowsCache 声明在 installUserRevertInjector() 内(闭包私有),而 /undo 的
|
|
353
377
|
// onPick 在模块级作用域 —— 直接引用会 ReferenceError,表现为点菜单毫无反应。
|
|
354
|
-
var __peekRowsCache = null
|
|
378
|
+
var __peekRowsCache = null // 0.6.0:会话视图会话 id(RevertDock/MsgSlotActions 刷新)
|
|
355
379
|
// messageId→seq 索引缓存(每会话一次拉取;0.3.0 assistant-actions 槽用)
|
|
356
380
|
var __seqIndexCache = new Map()
|
|
357
381
|
// messageId→全文缓存(0.5.0 消息引用用)
|
|
@@ -360,7 +384,9 @@ window.__ModuleLoader__.load({
|
|
|
360
384
|
function localeFallbackLang() {
|
|
361
385
|
if (typeof navigator === 'undefined') return 'zh'
|
|
362
386
|
for (const tag of (navigator.languages || []).concat([navigator.language])) {
|
|
363
|
-
const primary = String(tag || '')
|
|
387
|
+
const primary = String(tag || '')
|
|
388
|
+
.toLowerCase()
|
|
389
|
+
.split('-')[0]
|
|
364
390
|
if (primary === 'zh' || primary === 'en') return primary
|
|
365
391
|
}
|
|
366
392
|
return 'zh'
|
|
@@ -383,65 +409,110 @@ window.__ModuleLoader__.load({
|
|
|
383
409
|
const [, setRev] = useState(0)
|
|
384
410
|
useEffect(() => {
|
|
385
411
|
if (!__locale || typeof __locale.subscribe !== 'function') return undefined
|
|
386
|
-
return __locale.subscribe(() => setRev(
|
|
412
|
+
return __locale.subscribe(() => setRev(v => v + 1))
|
|
387
413
|
}, [])
|
|
388
414
|
}
|
|
389
415
|
|
|
390
416
|
// --- styles(仅 --dsw-* 主题令牌) ----------------------------------------
|
|
391
417
|
const btnStyle = {
|
|
392
|
-
display: 'inline-flex',
|
|
393
|
-
|
|
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,
|
|
394
426
|
background: 'transparent',
|
|
395
|
-
color: 'var(--dsw-alias-label-tertiary, #8a8a8e)',
|
|
427
|
+
color: 'var(--dsw-alias-label-tertiary, #8a8a8e)',
|
|
428
|
+
cursor: 'pointer',
|
|
429
|
+
flex: 'none',
|
|
396
430
|
}
|
|
397
431
|
const metaStyle = {
|
|
398
|
-
color: 'var(--dsw-alias-label-secondary, #8a8a8e)',
|
|
399
|
-
|
|
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',
|
|
400
438
|
}
|
|
401
439
|
const warnStyle = {
|
|
402
|
-
color: 'var(--dsw-alias-state-warn-primary, #f5a524)',
|
|
403
|
-
|
|
440
|
+
color: 'var(--dsw-alias-state-warn-primary, #f5a524)',
|
|
441
|
+
fontSize: 13,
|
|
442
|
+
lineHeight: '20px',
|
|
443
|
+
margin: '0 0 10px',
|
|
404
444
|
}
|
|
405
445
|
const errStyle = {
|
|
406
|
-
color: 'var(--dsw-alias-state-error-primary, #e5484d)',
|
|
407
|
-
|
|
446
|
+
color: 'var(--dsw-alias-state-error-primary, #e5484d)',
|
|
447
|
+
fontSize: 12,
|
|
448
|
+
lineHeight: '16px',
|
|
449
|
+
marginTop: 8,
|
|
408
450
|
}
|
|
409
451
|
const statusStyle = {
|
|
410
|
-
color: 'var(--dsw-alias-label-secondary, #8a8a8e)',
|
|
411
|
-
|
|
452
|
+
color: 'var(--dsw-alias-label-secondary, #8a8a8e)',
|
|
453
|
+
fontSize: 12,
|
|
454
|
+
lineHeight: '16px',
|
|
455
|
+
marginTop: 8,
|
|
412
456
|
}
|
|
413
457
|
const listStyle = {
|
|
414
|
-
maxHeight: 260,
|
|
415
|
-
|
|
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',
|
|
416
464
|
}
|
|
417
465
|
const rowStyle = {
|
|
418
|
-
display: 'flex',
|
|
419
|
-
|
|
466
|
+
display: 'flex',
|
|
467
|
+
alignItems: 'flex-start',
|
|
468
|
+
gap: 8,
|
|
469
|
+
padding: '4px 10px',
|
|
470
|
+
fontSize: 13,
|
|
471
|
+
lineHeight: '18px',
|
|
472
|
+
cursor: 'pointer',
|
|
420
473
|
}
|
|
421
474
|
const descStyle = {
|
|
422
|
-
color: 'var(--dsw-alias-label-secondary, #8a8a8e)',
|
|
423
|
-
|
|
475
|
+
color: 'var(--dsw-alias-label-secondary, #8a8a8e)',
|
|
476
|
+
fontSize: 12,
|
|
477
|
+
lineHeight: '17px',
|
|
478
|
+
margin: '6px 0 0',
|
|
424
479
|
}
|
|
425
480
|
const cancelBtnStyle = {
|
|
426
|
-
padding: '6px 14px',
|
|
481
|
+
padding: '6px 14px',
|
|
482
|
+
borderRadius: 8,
|
|
427
483
|
border: '1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.4))',
|
|
428
|
-
background: 'transparent',
|
|
429
|
-
|
|
484
|
+
background: 'transparent',
|
|
485
|
+
color: 'var(--dsw-alias-label-primary, inherit)',
|
|
486
|
+
fontSize: 13,
|
|
487
|
+
cursor: 'pointer',
|
|
488
|
+
marginRight: 8,
|
|
430
489
|
}
|
|
431
490
|
const primaryBtnStyle = {
|
|
432
|
-
padding: '6px 14px',
|
|
433
|
-
|
|
434
|
-
|
|
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',
|
|
435
498
|
}
|
|
436
499
|
const dangerBtnStyle = {
|
|
437
|
-
padding: '6px 14px',
|
|
500
|
+
padding: '6px 14px',
|
|
501
|
+
borderRadius: 8,
|
|
438
502
|
border: '1px solid var(--dsw-alias-state-error-primary, #e5484d)',
|
|
439
503
|
background: 'var(--dsw-alias-state-error-primary, #e5484d)',
|
|
440
|
-
color: '#fff',
|
|
504
|
+
color: '#fff',
|
|
505
|
+
fontSize: 13,
|
|
506
|
+
cursor: 'pointer',
|
|
441
507
|
}
|
|
442
508
|
const optStyle = {
|
|
443
|
-
display: 'flex',
|
|
444
|
-
|
|
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,
|
|
445
516
|
}
|
|
446
517
|
|
|
447
518
|
// 头部按钮图标:三叉分支(git-branch 风格,16x16)。
|
|
@@ -451,47 +522,68 @@ window.__ModuleLoader__.load({
|
|
|
451
522
|
// 「那个 svg 渲染有问题」)。必须 stroke + round cap/join。
|
|
452
523
|
// 唯一数据源:所有图标入口(React 组件 / innerHTML 字符串)都从这里取,
|
|
453
524
|
// 以免再次出现「一处改名、另一处仍用旧名 → d="undefined"」的回归。
|
|
454
|
-
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'
|
|
455
527
|
const BRANCH_STROKE = 1.4
|
|
456
528
|
|
|
457
529
|
/** 生成分支图标的 SVG 标记(供 innerHTML 场景复用)。 */
|
|
458
530
|
function branchIconMarkup(size) {
|
|
459
531
|
const px = size || 16
|
|
460
|
-
return
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
+
|
|
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
|
+
)
|
|
465
547
|
}
|
|
466
548
|
|
|
467
549
|
function BranchIcon() {
|
|
468
|
-
return React.createElement(
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
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
|
+
)
|
|
478
570
|
}
|
|
479
571
|
|
|
480
572
|
// --- 共享对话框 -------------------------------------------------------------
|
|
481
573
|
// 模块级缓存最近一次 target,事件驱动打开。
|
|
482
574
|
const MAX_RENDER = 200
|
|
483
|
-
const PAGE_SIZE = 50
|
|
575
|
+
const PAGE_SIZE = 50 // 低成本分批渲染:先渲 50 条,按钮渐进展开
|
|
484
576
|
|
|
485
577
|
function OpsDialog(props) {
|
|
486
578
|
const t = (props && props.t) || __t
|
|
487
579
|
useLocaleRevision()
|
|
488
|
-
const [target, setTarget] = useState(null)
|
|
489
|
-
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
|
|
490
582
|
const [messages, setMessages] = useState([])
|
|
491
583
|
const [sessionMeta, setSessionMeta] = useState(null)
|
|
492
|
-
const [picked, setPicked] = useState(null)
|
|
493
|
-
const [mode, setMode] = useState(null)
|
|
494
|
-
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
|
|
495
587
|
const [acknowledged, setAcknowledged] = useState(false)
|
|
496
588
|
const [busyMsg, setBusyMsg] = useState('')
|
|
497
589
|
const [renderLimit, setRenderLimit] = useState(PAGE_SIZE) // 已展开的渲染条数
|
|
@@ -499,15 +591,18 @@ window.__ModuleLoader__.load({
|
|
|
499
591
|
const [error, setError] = useState(null)
|
|
500
592
|
|
|
501
593
|
useEffect(() => {
|
|
502
|
-
const handler =
|
|
594
|
+
const handler = e => {
|
|
503
595
|
const d = e && e.detail ? e.detail : {}
|
|
504
596
|
setTarget({ sessionId: d.sessionId || null, title: d.title || null, running: d.running === true })
|
|
505
597
|
setState('loading')
|
|
506
|
-
setMessages([])
|
|
598
|
+
setMessages([])
|
|
599
|
+
setSessionMeta(null)
|
|
507
600
|
// 槽按钮预置:携带 seq(picked)与 mode 直接进入确认态
|
|
508
601
|
setPicked(typeof d.seq === 'number' ? d.seq : null)
|
|
509
602
|
setMode(typeof d.mode === 'string' ? d.mode : null)
|
|
510
|
-
setAcknowledged(false)
|
|
603
|
+
setAcknowledged(false)
|
|
604
|
+
setError(null)
|
|
605
|
+
setDoneMsg('')
|
|
511
606
|
setRenderLimit(PAGE_SIZE)
|
|
512
607
|
}
|
|
513
608
|
window.addEventListener(EVENT, handler)
|
|
@@ -518,48 +613,62 @@ window.__ModuleLoader__.load({
|
|
|
518
613
|
if (state !== 'loading' || !target || !target.sessionId) return
|
|
519
614
|
let cancelled = false
|
|
520
615
|
fetchMessagesJson('/api/message-ops/messages?sessionId=' + encodeURIComponent(target.sessionId))
|
|
521
|
-
.then(
|
|
616
|
+
.then(data => {
|
|
522
617
|
if (cancelled) return
|
|
523
618
|
if (!data || !data.ok) throw new Error(data && data.error ? data.error : `HTTP ${data && data.status}`)
|
|
524
619
|
setMessages(data.messages || [])
|
|
525
620
|
setSessionMeta(data.session || null)
|
|
526
|
-
if (data.running === true) setTarget(
|
|
621
|
+
if (data.running === true) setTarget(prev => ({ ...(prev || {}), running: true }))
|
|
527
622
|
setState('ready')
|
|
528
623
|
})
|
|
529
|
-
.catch(
|
|
624
|
+
.catch(reason => {
|
|
530
625
|
if (cancelled) return
|
|
531
626
|
setError(t('dialog.loadFail') + (reason && reason.message ? reason.message : String(reason)))
|
|
532
627
|
setState('ready')
|
|
533
628
|
})
|
|
534
|
-
return () => {
|
|
629
|
+
return () => {
|
|
630
|
+
cancelled = true
|
|
631
|
+
}
|
|
535
632
|
}, [state, target, t])
|
|
536
633
|
|
|
537
634
|
const close = useCallback(() => {
|
|
538
635
|
if (state === 'busy') return
|
|
539
|
-
setTarget(null)
|
|
636
|
+
setTarget(null)
|
|
637
|
+
setError(null)
|
|
540
638
|
}, [state])
|
|
541
639
|
|
|
542
|
-
const pick = useCallback(
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
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
|
+
)
|
|
547
650
|
|
|
548
|
-
const chooseMode = useCallback(
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
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
|
+
)
|
|
552
660
|
|
|
553
661
|
const run = useCallback(() => {
|
|
554
662
|
if (state === 'busy' || picked == null || !mode) return
|
|
555
663
|
if (mode !== 'branch' && !acknowledged) return
|
|
556
664
|
setBusyMsg(t('busy.' + (mode === 'revert' || mode === 'delete' ? mode : 'branch')))
|
|
557
|
-
setState('busy')
|
|
665
|
+
setState('busy')
|
|
666
|
+
setError(null)
|
|
558
667
|
if (mode === 'branch') {
|
|
559
668
|
// 0.12.0:与面板/消息行同一实现 —— opencode 的 before 语义
|
|
560
669
|
// (新会话不含此条,原文回新会话输入框)。只对用户消息成立;
|
|
561
670
|
// 分支不再回落写盘(被删的磁盘 applyBranch 语义复盘见 README)。
|
|
562
|
-
const pickedRow = picked != null ? messages.find(
|
|
671
|
+
const pickedRow = picked != null ? messages.find(m => m.seq === picked) : null
|
|
563
672
|
if (!pickedRow || pickedRow.role !== 'user') {
|
|
564
673
|
setError(t('panel.branchUserOnly'))
|
|
565
674
|
setBusyMsg('')
|
|
@@ -567,15 +676,17 @@ window.__ModuleLoader__.load({
|
|
|
567
676
|
return
|
|
568
677
|
}
|
|
569
678
|
Promise.resolve()
|
|
570
|
-
.then(() =>
|
|
571
|
-
|
|
679
|
+
.then(() =>
|
|
680
|
+
forkFromUserMessage(target.sessionId, picked, pickedRow.fullText || pickedRow.snippet || '', pickedRow.turnStartSeq),
|
|
681
|
+
)
|
|
682
|
+
.then(childId => {
|
|
572
683
|
setDoneMsg(t('fork.official', { id: String(childId || '') }))
|
|
573
684
|
setBusyMsg('')
|
|
574
685
|
setChildId(childId || null)
|
|
575
686
|
setState('done')
|
|
576
687
|
notifyDone(t('fork.official', { id: String(childId || '') }))
|
|
577
688
|
})
|
|
578
|
-
.catch(
|
|
689
|
+
.catch(reason => {
|
|
579
690
|
setError(String((reason && reason.message) || reason || t('fork.unavailable')))
|
|
580
691
|
setBusyMsg('')
|
|
581
692
|
setState('error')
|
|
@@ -585,14 +696,20 @@ window.__ModuleLoader__.load({
|
|
|
585
696
|
const path = mode
|
|
586
697
|
const body = { sessionId: target.sessionId, seq: picked }
|
|
587
698
|
Promise.resolve()
|
|
588
|
-
.then(() =>
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
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 => {
|
|
594
707
|
let data = {}
|
|
595
|
-
try {
|
|
708
|
+
try {
|
|
709
|
+
data = await res.json()
|
|
710
|
+
} catch {
|
|
711
|
+
/* keep {} */
|
|
712
|
+
}
|
|
596
713
|
if (!res.ok || !data.ok) throw new Error(data.error || `HTTP ${res.status}`)
|
|
597
714
|
// S6 修复(G-M1):不再 900ms 裸 location.reload。成功走 devkit
|
|
598
715
|
// 标准 toast(无 devkit 时降级为对话框内 doneMsg),并提供手动
|
|
@@ -612,7 +729,9 @@ window.__ModuleLoader__.load({
|
|
|
612
729
|
__inputActions.setDraft(pickedMsg.fullText)
|
|
613
730
|
if (typeof __inputActions.persistDraft === 'function') __inputActions.persistDraft()
|
|
614
731
|
}
|
|
615
|
-
} catch (e) {
|
|
732
|
+
} catch (e) {
|
|
733
|
+
console.warn('[message-ops] refill failed:', e)
|
|
734
|
+
}
|
|
616
735
|
}
|
|
617
736
|
setDoneMsg(okMsg)
|
|
618
737
|
setBusyMsg('')
|
|
@@ -623,9 +742,11 @@ window.__ModuleLoader__.load({
|
|
|
623
742
|
// 重建视图(与 restoreRow 同款 openSession 模式),遮蔽即刻可见。
|
|
624
743
|
try {
|
|
625
744
|
if (__uiWorkspace && typeof __uiWorkspace.openSession === 'function') __uiWorkspace.openSession(target.sessionId)
|
|
626
|
-
} catch {
|
|
745
|
+
} catch {
|
|
746
|
+
/* 视图重建失败不阻断成功反馈 */
|
|
747
|
+
}
|
|
627
748
|
})
|
|
628
|
-
.catch(
|
|
749
|
+
.catch(reason => {
|
|
629
750
|
setBusyMsg('')
|
|
630
751
|
setState('ready')
|
|
631
752
|
setError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
|
|
@@ -636,43 +757,75 @@ window.__ModuleLoader__.load({
|
|
|
636
757
|
|
|
637
758
|
// 0.6.0:system prompt 行不可作为回滚/删除/分支目标(引擎拒之以 node0 守卫,
|
|
638
759
|
// 但不该给用户一个必然500的选项)——列表直接排除 role=system。
|
|
639
|
-
const visible = messages.filter(
|
|
760
|
+
const visible = messages.filter(m => m.visible !== false && m.role !== 'system')
|
|
640
761
|
const shownBase = visible.slice(-MAX_RENDER)
|
|
641
762
|
const hiddenCount = visible.length - shownBase.length
|
|
642
763
|
// 分批渲染(评审 M1):只渲染 renderLimit 条,更早的留给「显示更多」
|
|
643
764
|
// 渐进展开,避免 200 行 radio 列表一次进 DOM。
|
|
644
765
|
const shown = shownBase.slice(-renderLimit)
|
|
645
766
|
const pagedCount = shownBase.length - shown.length
|
|
646
|
-
const pickedMsg = picked != null ? messages.find(
|
|
767
|
+
const pickedMsg = picked != null ? messages.find(m => m.seq === picked) : null
|
|
647
768
|
|
|
648
769
|
// 0.9.0 可发现性:操作区固定在**消息列表之前**。
|
|
649
770
|
// 原先它在列表之后,而列表是 260px 滚动 + 分批渲染 50 条/页 ——
|
|
650
771
|
// 未选中消息时三个 radio 完全不在视野内,用户以为「只有列表、没有操作」。
|
|
651
772
|
// 未选中时给明确指引,而不是空着。
|
|
652
773
|
const opsPanel = pickedMsg
|
|
653
|
-
? React.createElement(
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
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
|
+
),
|
|
665
801
|
mode && mode !== 'branch'
|
|
666
|
-
? React.createElement(
|
|
802
|
+
? React.createElement(
|
|
803
|
+
'label',
|
|
804
|
+
{ key: 'ack', style: optStyle },
|
|
667
805
|
React.createElement('input', {
|
|
668
|
-
type: 'checkbox',
|
|
669
|
-
|
|
806
|
+
type: 'checkbox',
|
|
807
|
+
checked: acknowledged,
|
|
808
|
+
disabled: state === 'busy',
|
|
809
|
+
onChange: e => setAcknowledged(e.target.checked),
|
|
670
810
|
}),
|
|
671
|
-
t(mode === 'revert' ? 'ack.revert' : 'ack.delete')
|
|
811
|
+
t(mode === 'revert' ? 'ack.revert' : 'ack.delete'),
|
|
812
|
+
)
|
|
672
813
|
: null,
|
|
673
814
|
)
|
|
674
|
-
: React.createElement(
|
|
675
|
-
|
|
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
|
+
)
|
|
676
829
|
|
|
677
830
|
let body
|
|
678
831
|
if (state === 'loading') {
|
|
@@ -684,36 +837,67 @@ window.__ModuleLoader__.load({
|
|
|
684
837
|
target.running ? React.createElement('div', { key: 'warn', style: warnStyle }, t('dialog.runningWarn')) : null,
|
|
685
838
|
opsPanel,
|
|
686
839
|
React.createElement('div', { key: 'pick', style: metaStyle }, t('dialog.pick')),
|
|
687
|
-
React.createElement(
|
|
840
|
+
React.createElement(
|
|
841
|
+
'div',
|
|
842
|
+
{ key: 'list', style: listStyle },
|
|
688
843
|
hiddenCount > 0
|
|
689
|
-
? React.createElement(
|
|
690
|
-
|
|
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
|
+
)
|
|
691
849
|
: null,
|
|
692
850
|
pagedCount > 0
|
|
693
|
-
? React.createElement(
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
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
|
+
)
|
|
698
867
|
: null,
|
|
699
|
-
shown.map((m, i) =>
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
}),
|
|
709
|
-
React.createElement('span', {
|
|
710
|
-
style: {
|
|
711
|
-
flex: 1, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap',
|
|
712
|
-
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
|
+
},
|
|
713
877
|
},
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
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
|
+
),
|
|
717
901
|
),
|
|
718
902
|
// 0.9.7:删掉列表**之后**的旧 opsPanel——0.9.0 把操作区挪到列表之前时
|
|
719
903
|
// 没删旧位置,两组同名 radio(name='dsh-message-ops-mode')互抢,
|
|
@@ -721,52 +905,93 @@ window.__ModuleLoader__.load({
|
|
|
721
905
|
])
|
|
722
906
|
}
|
|
723
907
|
|
|
724
|
-
const canRun = state !== 'busy' && state !== 'loading' && picked != null && mode != null
|
|
725
|
-
&& (mode === 'branch' || acknowledged)
|
|
908
|
+
const canRun = state !== 'busy' && state !== 'loading' && picked != null && mode != null && (mode === 'branch' || acknowledged)
|
|
726
909
|
const confirmLabel = busyMsg || (mode ? t('confirm.' + mode) : t('dialog.cancel'))
|
|
727
910
|
|
|
728
|
-
return React.createElement(
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
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,
|
|
762
993
|
],
|
|
763
|
-
|
|
764
|
-
React.createElement('div', { key: 'meta', style: metaStyle },
|
|
765
|
-
t('dialog.session'), target.sessionId || ''),
|
|
766
|
-
body,
|
|
767
|
-
doneMsg ? React.createElement('div', { key: 'done', style: statusStyle }, doneMsg) : null,
|
|
768
|
-
error ? React.createElement('div', { key: 'err', style: errStyle, role: 'alert' }, error) : null,
|
|
769
|
-
])
|
|
994
|
+
)
|
|
770
995
|
}
|
|
771
996
|
|
|
772
997
|
// --- A · 功能主义抽屉 -------------------------------------------------------
|
|
@@ -778,7 +1003,9 @@ window.__ModuleLoader__.load({
|
|
|
778
1003
|
if (typeof value !== 'number') return ''
|
|
779
1004
|
try {
|
|
780
1005
|
return new Date(value).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
|
781
|
-
} catch {
|
|
1006
|
+
} catch {
|
|
1007
|
+
return ''
|
|
1008
|
+
}
|
|
782
1009
|
}
|
|
783
1010
|
|
|
784
1011
|
function roleCode(role) {
|
|
@@ -790,8 +1017,9 @@ window.__ModuleLoader__.load({
|
|
|
790
1017
|
|
|
791
1018
|
function focusablesIn(root) {
|
|
792
1019
|
if (!root || typeof root.querySelectorAll !== 'function') return []
|
|
793
|
-
const selector =
|
|
794
|
-
|
|
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 => {
|
|
795
1023
|
if (el.getAttribute('aria-hidden') === 'true') return false
|
|
796
1024
|
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0
|
|
797
1025
|
})
|
|
@@ -876,7 +1104,9 @@ window.__ModuleLoader__.load({
|
|
|
876
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%}}',
|
|
877
1105
|
].join('')
|
|
878
1106
|
document.head.appendChild(tag)
|
|
879
|
-
} catch {
|
|
1107
|
+
} catch {
|
|
1108
|
+
/* style failure must not break the panel */
|
|
1109
|
+
}
|
|
880
1110
|
}
|
|
881
1111
|
|
|
882
1112
|
function OpsPanel(props) {
|
|
@@ -930,7 +1160,7 @@ window.__ModuleLoader__.load({
|
|
|
930
1160
|
|
|
931
1161
|
useEffect(() => {
|
|
932
1162
|
ensurePanelStyle()
|
|
933
|
-
const handler =
|
|
1163
|
+
const handler = e => {
|
|
934
1164
|
const d = e && e.detail ? e.detail : {}
|
|
935
1165
|
if (!d.sessionId) return
|
|
936
1166
|
const active = document.activeElement
|
|
@@ -970,31 +1200,44 @@ window.__ModuleLoader__.load({
|
|
|
970
1200
|
|
|
971
1201
|
const sid = target && target.sessionId
|
|
972
1202
|
|
|
973
|
-
const loadMessages = useCallback(
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
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
|
+
)
|
|
998
1241
|
|
|
999
1242
|
useEffect(() => {
|
|
1000
1243
|
if (!open || !sid) return
|
|
@@ -1004,29 +1247,47 @@ window.__ModuleLoader__.load({
|
|
|
1004
1247
|
useEffect(() => {
|
|
1005
1248
|
if (!open || tab !== 'messages') return
|
|
1006
1249
|
const q = query.trim()
|
|
1007
|
-
if (!q) {
|
|
1250
|
+
if (!q) {
|
|
1251
|
+
setHits(null)
|
|
1252
|
+
setSearching(false)
|
|
1253
|
+
return
|
|
1254
|
+
}
|
|
1008
1255
|
setSearching(true)
|
|
1009
1256
|
let cancelled = false
|
|
1010
1257
|
const timer = setTimeout(() => {
|
|
1011
1258
|
setError(null)
|
|
1012
|
-
const url =
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
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
|
|
1016
1267
|
fetch(url)
|
|
1017
|
-
.then(
|
|
1268
|
+
.then(res =>
|
|
1269
|
+
res
|
|
1270
|
+
.json()
|
|
1271
|
+
.catch(() => null)
|
|
1272
|
+
.then(data => ({ res, data })),
|
|
1273
|
+
)
|
|
1018
1274
|
.then(({ res, data }) => {
|
|
1019
1275
|
if (cancelled) return
|
|
1020
|
-
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)
|
|
1021
1277
|
setHits(Array.isArray(data.results) ? data.results : [])
|
|
1022
1278
|
setError(null)
|
|
1023
1279
|
})
|
|
1024
|
-
.catch(
|
|
1280
|
+
.catch(reason => {
|
|
1025
1281
|
if (!cancelled) setError(t('panel.searchFail') + (reason && reason.message ? reason.message : String(reason)))
|
|
1026
1282
|
})
|
|
1027
|
-
.finally(() => {
|
|
1283
|
+
.finally(() => {
|
|
1284
|
+
if (!cancelled) setSearching(false)
|
|
1285
|
+
})
|
|
1028
1286
|
}, 200)
|
|
1029
|
-
return () => {
|
|
1287
|
+
return () => {
|
|
1288
|
+
cancelled = true
|
|
1289
|
+
clearTimeout(timer)
|
|
1290
|
+
}
|
|
1030
1291
|
}, [open, tab, sid, query, role, t])
|
|
1031
1292
|
|
|
1032
1293
|
const loadTrash = useCallback(async () => {
|
|
@@ -1037,7 +1298,7 @@ window.__ModuleLoader__.load({
|
|
|
1037
1298
|
const res = await fetch('/api/message-ops/session/trash')
|
|
1038
1299
|
const data = await res.json().catch(() => null)
|
|
1039
1300
|
if (requestId !== trashSeqRef.current) return
|
|
1040
|
-
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)
|
|
1041
1302
|
setTrash(Array.isArray(data.entries) ? data.entries : [])
|
|
1042
1303
|
setTrashError(null)
|
|
1043
1304
|
setTrashState('ready')
|
|
@@ -1102,32 +1363,35 @@ window.__ModuleLoader__.load({
|
|
|
1102
1363
|
* 语义上与 opencode 的「回撤 → 原文回到 composer」一致;区别是我们不预先回撤,
|
|
1103
1364
|
* 由用户决定发不发(发了才产生新的分支上下文)。
|
|
1104
1365
|
*/
|
|
1105
|
-
const startEdit = useCallback(
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
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
|
+
)
|
|
1127
1391
|
|
|
1128
1392
|
useEffect(() => {
|
|
1129
1393
|
if (!open) return undefined
|
|
1130
|
-
const onKey =
|
|
1394
|
+
const onKey = e => {
|
|
1131
1395
|
if (e.key === 'Escape') {
|
|
1132
1396
|
if (busy) return
|
|
1133
1397
|
if (confirmDelete) closeConfirm()
|
|
@@ -1193,13 +1457,15 @@ window.__ModuleLoader__.load({
|
|
|
1193
1457
|
let scrollbarW = 0
|
|
1194
1458
|
try {
|
|
1195
1459
|
scrollbarW = window.innerWidth - document.documentElement.clientWidth
|
|
1196
|
-
} catch {
|
|
1460
|
+
} catch {
|
|
1461
|
+
/* non-browser */
|
|
1462
|
+
}
|
|
1197
1463
|
if (body && body.style) {
|
|
1198
1464
|
body.style.overflow = 'hidden'
|
|
1199
1465
|
// 为被隐藏的经典滚动条补回等宽内边距,避免整页横向跳动。
|
|
1200
1466
|
if (scrollbarW > 0) {
|
|
1201
1467
|
const base = Number.parseFloat(getComputedStyle(body).paddingRight) || 0
|
|
1202
|
-
body.style.paddingRight =
|
|
1468
|
+
body.style.paddingRight = base + scrollbarW + 'px'
|
|
1203
1469
|
}
|
|
1204
1470
|
}
|
|
1205
1471
|
return () => {
|
|
@@ -1217,16 +1483,22 @@ window.__ModuleLoader__.load({
|
|
|
1217
1483
|
const trigger = triggerRef.current
|
|
1218
1484
|
triggerRef.current = null
|
|
1219
1485
|
if (trigger && typeof trigger.focus === 'function') {
|
|
1220
|
-
setTimeout(() => {
|
|
1486
|
+
setTimeout(() => {
|
|
1487
|
+
try {
|
|
1488
|
+
trigger.focus()
|
|
1489
|
+
} catch {
|
|
1490
|
+
/* detached trigger */
|
|
1491
|
+
}
|
|
1492
|
+
}, 0)
|
|
1221
1493
|
}
|
|
1222
1494
|
}
|
|
1223
1495
|
}, [open, sid])
|
|
1224
1496
|
|
|
1225
1497
|
useEffect(() => {
|
|
1226
1498
|
if (!open) return undefined
|
|
1227
|
-
const onKeyDown =
|
|
1499
|
+
const onKeyDown = e => {
|
|
1228
1500
|
if (e.key !== 'Tab') return
|
|
1229
|
-
const scope = confirmDelete ? confirmRef.current :
|
|
1501
|
+
const scope = confirmDelete ? confirmRef.current : confirmAction ? actionConfirmRef.current : panelRef.current
|
|
1230
1502
|
if (!scope) return
|
|
1231
1503
|
const nodes = focusablesIn(scope)
|
|
1232
1504
|
if (!nodes.length) {
|
|
@@ -1264,13 +1536,11 @@ window.__ModuleLoader__.load({
|
|
|
1264
1536
|
}
|
|
1265
1537
|
}, [open, confirmDelete, confirmAction])
|
|
1266
1538
|
|
|
1267
|
-
const baseRows = query.trim() ?
|
|
1539
|
+
const baseRows = query.trim() ? hits || [] : messages
|
|
1268
1540
|
const rows = baseRows
|
|
1269
|
-
.filter(
|
|
1270
|
-
&& (role === 'all' || m.role === role)
|
|
1271
|
-
&& (includeShadowed || !m.shadowed))
|
|
1541
|
+
.filter(m => m && m.role !== 'system' && (role === 'all' || m.role === role) && (includeShadowed || !m.shadowed))
|
|
1272
1542
|
.sort((a, b) => b.seq - a.seq)
|
|
1273
|
-
const activeIndex = picked ? rows.findIndex(
|
|
1543
|
+
const activeIndex = picked ? rows.findIndex(m => m.seq === picked.seq) : -1
|
|
1274
1544
|
|
|
1275
1545
|
const clearPick = () => {
|
|
1276
1546
|
detailReq.current += 1
|
|
@@ -1280,7 +1550,7 @@ window.__ModuleLoader__.load({
|
|
|
1280
1550
|
setConfirmAction(null)
|
|
1281
1551
|
}
|
|
1282
1552
|
|
|
1283
|
-
const previewRow =
|
|
1553
|
+
const previewRow = m => {
|
|
1284
1554
|
if (!m) return
|
|
1285
1555
|
detailReq.current += 1
|
|
1286
1556
|
setPicked(m)
|
|
@@ -1290,7 +1560,7 @@ window.__ModuleLoader__.load({
|
|
|
1290
1560
|
setDone('')
|
|
1291
1561
|
}
|
|
1292
1562
|
|
|
1293
|
-
const scrollRowIntoView =
|
|
1563
|
+
const scrollRowIntoView = index => {
|
|
1294
1564
|
const el = listRef.current
|
|
1295
1565
|
if (!el) return
|
|
1296
1566
|
const top = index * PANEL_ROW_H
|
|
@@ -1304,9 +1574,9 @@ window.__ModuleLoader__.load({
|
|
|
1304
1574
|
}
|
|
1305
1575
|
}
|
|
1306
1576
|
|
|
1307
|
-
const handleListKeyDown =
|
|
1577
|
+
const handleListKeyDown = e => {
|
|
1308
1578
|
if (!rows.length) return
|
|
1309
|
-
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)
|
|
1310
1580
|
let next = activeIndex
|
|
1311
1581
|
if (e.key === 'ArrowDown') next = activeIndex < 0 ? 0 : Math.min(rows.length - 1, activeIndex + 1)
|
|
1312
1582
|
else if (e.key === 'ArrowUp') next = activeIndex < 0 ? rows.length - 1 : Math.max(0, activeIndex - 1)
|
|
@@ -1317,7 +1587,10 @@ window.__ModuleLoader__.load({
|
|
|
1317
1587
|
else if (e.key === 'Enter' || e.key === ' ') {
|
|
1318
1588
|
e.preventDefault()
|
|
1319
1589
|
const row = rows[activeIndex >= 0 ? activeIndex : 0]
|
|
1320
|
-
if (row) {
|
|
1590
|
+
if (row) {
|
|
1591
|
+
pick(row)
|
|
1592
|
+
if (listRef.current) listRef.current.focus()
|
|
1593
|
+
}
|
|
1321
1594
|
return
|
|
1322
1595
|
} else {
|
|
1323
1596
|
return
|
|
@@ -1352,86 +1625,107 @@ window.__ModuleLoader__.load({
|
|
|
1352
1625
|
}
|
|
1353
1626
|
}, [open, tab, rows.length, viewport])
|
|
1354
1627
|
|
|
1355
|
-
const pick = useCallback(
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
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
|
+
)
|
|
1377
1658
|
|
|
1378
|
-
const runAction = useCallback(
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
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)
|
|
1393
1687
|
if (sessionRef.current !== actionSid) return
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
return
|
|
1398
|
-
}
|
|
1399
|
-
const res = await fetch('/api/message-ops/' + mode, {
|
|
1400
|
-
method: 'POST',
|
|
1401
|
-
headers: { 'content-type': 'application/json' },
|
|
1402
|
-
body: JSON.stringify({ sessionId: target.sessionId, seq: picked.seq }),
|
|
1403
|
-
})
|
|
1404
|
-
const data = await res.json().catch(() => null)
|
|
1405
|
-
if (sessionRef.current !== actionSid) return
|
|
1406
|
-
if (!res.ok || !data || data.ok !== true) {
|
|
1407
|
-
if (res.status === 409) setTarget((prev) => prev ? { ...prev, running: true } : prev)
|
|
1408
|
-
throw new Error((data && data.error) || ('HTTP ' + res.status))
|
|
1409
|
-
}
|
|
1410
|
-
if (mode === 'revert') {
|
|
1411
|
-
setMessages((prev) => prev.map((m) => (m.seq >= picked.seq ? { ...m, shadowed: true, visible: false } : m)))
|
|
1412
|
-
if (picked.role === 'user') {
|
|
1413
|
-
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)
|
|
1414
1691
|
}
|
|
1415
|
-
|
|
1416
|
-
|
|
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('')
|
|
1417
1725
|
}
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
setTimeout(() => { if (listRef.current) listRef.current.focus() }, 0)
|
|
1422
|
-
notifyDone(msg)
|
|
1423
|
-
emitChanged()
|
|
1424
|
-
try {
|
|
1425
|
-
if (__uiWorkspace && typeof __uiWorkspace.openSession === 'function') __uiWorkspace.openSession(target.sessionId)
|
|
1426
|
-
} catch { /* view rebuild is best effort */ }
|
|
1427
|
-
setTimeout(() => { loadMessages(true).catch(() => {}) }, 650)
|
|
1428
|
-
} catch (reason) {
|
|
1429
|
-
if (sessionRef.current !== actionSid) return
|
|
1430
|
-
setError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
|
|
1431
|
-
} finally {
|
|
1432
|
-
setBusy('')
|
|
1433
|
-
}
|
|
1434
|
-
}, [target, picked, busy, t, loadMessages])
|
|
1726
|
+
},
|
|
1727
|
+
[target, picked, busy, t, loadMessages],
|
|
1728
|
+
)
|
|
1435
1729
|
|
|
1436
1730
|
const deleteSession = useCallback(async () => {
|
|
1437
1731
|
if (!target || busy || target.running) return
|
|
@@ -1450,14 +1744,20 @@ window.__ModuleLoader__.load({
|
|
|
1450
1744
|
const data = await res.json().catch(() => null)
|
|
1451
1745
|
if (sessionRef.current !== actionSid) return
|
|
1452
1746
|
if (!res.ok || !data || data.ok !== true) {
|
|
1453
|
-
if (res.status === 409) setTarget(
|
|
1454
|
-
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)
|
|
1455
1749
|
}
|
|
1456
1750
|
setConfirmDelete(false)
|
|
1457
1751
|
setDone(t('panel.deleted'))
|
|
1458
1752
|
notifyDone(t('panel.deleted'))
|
|
1459
1753
|
emitChanged()
|
|
1460
|
-
setTimeout(() => {
|
|
1754
|
+
setTimeout(() => {
|
|
1755
|
+
try {
|
|
1756
|
+
window.location.reload()
|
|
1757
|
+
} catch {
|
|
1758
|
+
/* non-browser guard */
|
|
1759
|
+
}
|
|
1760
|
+
}, 700)
|
|
1461
1761
|
} catch (reason) {
|
|
1462
1762
|
if (sessionRef.current !== actionSid) return
|
|
1463
1763
|
setDeleteError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
|
|
@@ -1466,68 +1766,81 @@ window.__ModuleLoader__.load({
|
|
|
1466
1766
|
}
|
|
1467
1767
|
}, [target, busy, confirmTitle, t])
|
|
1468
1768
|
|
|
1469
|
-
const restoreEntry = useCallback(
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
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
|
+
)
|
|
1493
1802
|
|
|
1494
|
-
const purgeEntry = useCallback(
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
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
|
+
)
|
|
1518
1833
|
|
|
1519
1834
|
if (!open) return null
|
|
1520
1835
|
|
|
1521
|
-
const pickedLive = picked ?
|
|
1836
|
+
const pickedLive = picked ? messages.find(m => m.seq === picked.seq) || picked : null
|
|
1522
1837
|
const canAct = !busy && !target.running && pickedLive && !pickedLive.shadowed
|
|
1523
|
-
const visibleCount = messages.filter(
|
|
1524
|
-
const shadowedCount = messages.filter(
|
|
1525
|
-
const totalCount = messages.filter(
|
|
1526
|
-
const revertImpact = pickedLive
|
|
1527
|
-
? messages.filter((m) => m.role !== 'system' && !m.shadowed && m.seq >= pickedLive.seq)
|
|
1528
|
-
: []
|
|
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) : []
|
|
1529
1842
|
const revertCount = revertImpact.length
|
|
1530
|
-
const revertVisibleCount = revertImpact.filter(
|
|
1843
|
+
const revertVisibleCount = revertImpact.filter(m => m.visible).length
|
|
1531
1844
|
const revertEnd = revertImpact.reduce((max, m) => Math.max(max, m.seq), pickedLive ? pickedLive.seq : 0)
|
|
1532
1845
|
const expectedDeleteTitle = target.expectedTitle || ''
|
|
1533
1846
|
// 0.12.0:分叉/编辑只对**用户消息**成立(与 opencode 一致:fork 的语义是
|
|
@@ -1538,250 +1851,568 @@ window.__ModuleLoader__.load({
|
|
|
1538
1851
|
const deleteBlockedReason = target.running
|
|
1539
1852
|
? t('panel.running')
|
|
1540
1853
|
: state !== 'ready'
|
|
1541
|
-
?
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
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
|
|
1545
1862
|
const start = Math.min(Math.max(0, rows.length - 1), Math.max(0, Math.floor(scrollTop / PANEL_ROW_H) - 6))
|
|
1546
1863
|
const end = Math.min(rows.length, start + Math.ceil(viewport / PANEL_ROW_H) + 12)
|
|
1547
1864
|
const windowRows = rows.slice(start, end)
|
|
1548
|
-
const activeRendered = picked && windowRows.some(
|
|
1865
|
+
const activeRendered = picked && windowRows.some(m => m.seq === picked.seq)
|
|
1549
1866
|
const showSearchLoading = searching && query.trim().length > 0
|
|
1550
1867
|
|
|
1551
|
-
return React.createElement(
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
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
|
+
},
|
|
1561
1877
|
},
|
|
1562
|
-
|
|
1563
|
-
|
|
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 } },
|
|
1564
1897
|
React.createElement('div', { className: 'mopsPanelKicker' }, t('dialog.title')),
|
|
1565
|
-
React.createElement(
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
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,
|
|
1583
1951
|
error ? React.createElement('div', { className: 'mopsBanner err', role: 'alert' }, error) : null,
|
|
1584
|
-
done
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
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,
|
|
1589
1977
|
tab === 'messages'
|
|
1590
|
-
? React.createElement(
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
})),
|
|
1597
|
-
React.createElement('div', { className: 'mopsChips' },
|
|
1598
|
-
['all', 'user', 'assistant', 'tool'].map((key) => React.createElement('button', {
|
|
1599
|
-
key, type: 'button', className: 'mopsChip' + (role === key ? ' on' : ''),
|
|
1600
|
-
onClick: () => { setRole(key); clearPick(); setScrollTop(0); if (listRef.current) listRef.current.scrollTop = 0 },
|
|
1601
|
-
}, t('panel.' + key))),
|
|
1602
|
-
React.createElement('label', { className: 'mopsToggle' },
|
|
1978
|
+
? React.createElement(
|
|
1979
|
+
React.Fragment,
|
|
1980
|
+
null,
|
|
1981
|
+
React.createElement(
|
|
1982
|
+
'div',
|
|
1983
|
+
{ className: 'mopsSearchRow' },
|
|
1603
1984
|
React.createElement('input', {
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
:
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
React.createElement('span', { className: 'mopsSeq' }, '#' + m.seq),
|
|
1641
|
-
React.createElement('span', { className: 'mopsRole' }, roleCode(m.role)),
|
|
1642
|
-
React.createElement('span', { className: 'mopsSnippet' }, m.snippet || '—'),
|
|
1643
|
-
React.createElement('span', { className: 'mopsClock' }, fmtClock(m.time)))))),
|
|
1644
|
-
React.createElement('div', { className: 'mopsDetail' },
|
|
1645
|
-
pickedLive
|
|
1646
|
-
? React.createElement(React.Fragment, null,
|
|
1647
|
-
React.createElement('div', { className: 'mopsDetailMeta' },
|
|
1648
|
-
React.createElement('span', null, '#' + pickedLive.seq),
|
|
1649
|
-
React.createElement('span', null, pickedLive.role || ''),
|
|
1650
|
-
pickedLive.shadowed ? React.createElement('span', null, t('panel.shadowed')) : null,
|
|
1651
|
-
pickedLive.time ? React.createElement('span', null, fmtClock(pickedLive.time)) : null),
|
|
1652
|
-
React.createElement('pre', { className: 'mopsDetailText' },
|
|
1653
|
-
detailState === 'loading' ? t('panel.detailLoading') : (detail || pickedLive.snippet || '—')),
|
|
1654
|
-
React.createElement('div', { className: 'mopsActions' },
|
|
1655
|
-
React.createElement('button', {
|
|
1656
|
-
type: 'button', className: 'mopsAction primary', disabled: !canAct || !!confirmAction,
|
|
1657
|
-
ref: revertBtnRef,
|
|
1658
|
-
onClick: () => setConfirmAction('revert'),
|
|
1659
|
-
title: t('panel.revertHint'),
|
|
1660
|
-
}, t('panel.revert') + (revertCount ? ' · ' + revertCount : '')),
|
|
1661
|
-
React.createElement('button', {
|
|
1662
|
-
type: 'button', className: 'mopsAction danger', disabled: !canAct || !!confirmAction,
|
|
1663
|
-
ref: deleteOneBtnRef,
|
|
1664
|
-
onClick: () => setConfirmAction('delete'), title: t('panel.deleteHint'),
|
|
1665
|
-
}, t('panel.delete')),
|
|
1666
|
-
// 0.12.0:编辑只对用户消息可用 —— 直接把原文交回编辑器。
|
|
1667
|
-
// 无二次确认:它不改日志,只改草稿。
|
|
1668
|
-
React.createElement('button', {
|
|
1669
|
-
type: 'button', className: 'mopsAction', disabled: !canEdit,
|
|
1670
|
-
title: pickedIsUser ? t('panel.editHint') : t('panel.branchUserOnly'),
|
|
1671
|
-
onClick: () => startEdit(detail || pickedLive.snippet || ''),
|
|
1672
|
-
}, t('panel.edit')),
|
|
1673
|
-
// 分叉同样只对用户消息可用(AI 消息没有可回填的原文),
|
|
1674
|
-
// 语义 = opencode 的 before:新会话不含此条,原文进新会话输入框。
|
|
1675
|
-
React.createElement('button', {
|
|
1676
|
-
type: 'button', className: 'mopsAction', disabled: !canFork || !!confirmAction,
|
|
1677
|
-
onClick: () => runAction('branch'),
|
|
1678
|
-
title: pickedIsUser ? t('panel.branchHint') : t('panel.branchUserOnly'),
|
|
1679
|
-
}, t('panel.branch'))),
|
|
1680
|
-
confirmAction
|
|
1681
|
-
? React.createElement('div', {
|
|
1682
|
-
className: 'mopsActionConfirm', ref: actionConfirmRef, role: 'group', tabIndex: -1,
|
|
1683
|
-
'aria-labelledby': 'mops-action-confirm-title',
|
|
1684
|
-
},
|
|
1685
|
-
React.createElement('div', { className: 'mopsImpactTitle', id: 'mops-action-confirm-title' },
|
|
1686
|
-
t(confirmAction === 'revert' ? 'panel.revertConfirmTitle' : 'panel.deleteConfirmTitle', { seq: String(pickedLive.seq) })),
|
|
1687
|
-
React.createElement('div', { className: 'mopsImpact' },
|
|
1688
|
-
confirmAction === 'revert'
|
|
1689
|
-
? t('panel.revertConfirmBody', {
|
|
1690
|
-
start: String(pickedLive.seq), end: String(revertEnd),
|
|
1691
|
-
n: String(revertCount), v: String(revertVisibleCount),
|
|
1692
|
-
})
|
|
1693
|
-
: t('panel.deleteConfirmBody')),
|
|
1694
|
-
React.createElement('div', { className: 'mopsConfirmRow' },
|
|
1695
|
-
React.createElement('button', {
|
|
1696
|
-
type: 'button', className: 'mopsAction', onClick: cancelAction, disabled: !!busy,
|
|
1697
|
-
}, t('panel.cancel')),
|
|
1698
|
-
React.createElement('button', {
|
|
1699
|
-
type: 'button', className: 'mopsAction danger',
|
|
1700
|
-
onClick: () => runAction(confirmAction, true),
|
|
1701
|
-
disabled: !!busy || !canAct,
|
|
1702
|
-
}, busy === confirmAction ? t('panel.busy') : t(confirmAction === 'revert' ? 'panel.confirmRevert' : 'panel.confirmDeleteOne'))))
|
|
1703
|
-
: null)
|
|
1704
|
-
: React.createElement('div', { className: 'mopsDetailHint' }, t('panel.selectHint'))),
|
|
1705
|
-
React.createElement('footer', { className: 'mopsPanelFoot' },
|
|
1706
|
-
React.createElement('span', { className: 'mopsCount' },
|
|
1707
|
-
t('panel.count', { n: String(totalCount), v: String(visibleCount), s: String(shadowedCount) })),
|
|
1708
|
-
React.createElement('button', {
|
|
1709
|
-
type: 'button', className: 'mopsDanger', ref: deleteBtnRef,
|
|
1710
|
-
disabled: !!busy || !!deleteBlockedReason,
|
|
1711
|
-
title: deleteBlockedReason || undefined,
|
|
1712
|
-
onClick: () => {
|
|
1713
|
-
setConfirmTitle('')
|
|
1714
|
-
setDeleteError(null)
|
|
1715
|
-
setConfirmAction(null)
|
|
1716
|
-
setConfirmDelete(true)
|
|
1717
|
-
},
|
|
1718
|
-
}, t('panel.deleteSession'))),
|
|
1719
|
-
confirmDelete
|
|
1720
|
-
? React.createElement('div', {
|
|
1721
|
-
className: 'mopsConfirm', ref: confirmRef, role: 'alertdialog', 'aria-modal': 'true',
|
|
1722
|
-
'aria-labelledby': 'mops-delete-title', 'aria-describedby': 'mops-delete-hint mops-delete-impact',
|
|
1723
|
-
tabIndex: -1,
|
|
1724
|
-
},
|
|
1725
|
-
React.createElement('h3', { id: 'mops-delete-title' }, t('panel.deleteSession')),
|
|
1726
|
-
React.createElement('p', { id: 'mops-delete-hint' }, t('panel.deleteSessionHint')),
|
|
1727
|
-
React.createElement('p', { className: 'mopsImpact', id: 'mops-delete-impact' },
|
|
1728
|
-
t('panel.deleteSessionImpact', { n: String(totalCount) })),
|
|
1729
|
-
target.running ? React.createElement('div', { className: 'mopsBanner warn', role: 'status' }, t('panel.running')) : null,
|
|
1730
|
-
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' },
|
|
1731
2021
|
React.createElement('input', {
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
if (e.key === 'Enter') {
|
|
1740
|
-
e.preventDefault()
|
|
1741
|
-
if (canConfirmDelete) deleteSession()
|
|
1742
|
-
} else if (e.key === 'Escape') {
|
|
1743
|
-
e.preventDefault()
|
|
1744
|
-
e.stopPropagation()
|
|
1745
|
-
closeConfirm()
|
|
1746
|
-
}
|
|
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
|
|
1747
2029
|
},
|
|
1748
2030
|
}),
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
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 },
|
|
1761
2348
|
trashState === 'loading' || trashState === 'idle'
|
|
1762
2349
|
? React.createElement('div', { className: 'mopsEmpty', role: 'status', 'aria-live': 'polite' }, t('panel.loading'))
|
|
1763
2350
|
: trashState === 'error'
|
|
1764
|
-
? React.createElement(
|
|
2351
|
+
? React.createElement(
|
|
2352
|
+
'div',
|
|
2353
|
+
{ className: 'mopsEmpty mopsErrorState', role: 'alert' },
|
|
1765
2354
|
React.createElement('span', null, trashError || t('panel.loadFail')),
|
|
1766
|
-
React.createElement(
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
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
|
+
)
|
|
1770
2370
|
: trash.length === 0
|
|
1771
2371
|
? React.createElement('div', { className: 'mopsEmpty' }, t('panel.trashEmpty'))
|
|
1772
|
-
: trash.map(
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
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
|
+
)
|
|
1785
2416
|
}
|
|
1786
2417
|
|
|
1787
2418
|
// --- 头部按钮 ---------------------------------------------------------------
|
|
@@ -1907,27 +2538,38 @@ window.__ModuleLoader__.load({
|
|
|
1907
2538
|
try {
|
|
1908
2539
|
const dk = window.__dshDevkit
|
|
1909
2540
|
if (dk && typeof dk.toast === 'function') dk.toast(msg, { kind: kind || 'ok' })
|
|
1910
|
-
} catch {
|
|
2541
|
+
} catch {
|
|
2542
|
+
/* toast 缺席不阻断成功反馈 */
|
|
2543
|
+
}
|
|
1911
2544
|
}
|
|
1912
2545
|
|
|
1913
2546
|
function OpsButton(props) {
|
|
1914
2547
|
const { sessionId, useSessions } = props
|
|
1915
2548
|
const t = (props && props.t) || __t
|
|
1916
2549
|
useLocaleRevision()
|
|
1917
|
-
const sessions = useSessions ? useSessions(
|
|
2550
|
+
const sessions = useSessions ? useSessions(s => s) : undefined
|
|
1918
2551
|
const summary = sessions && sessions.byId ? sessions.byId[sessionId] : undefined
|
|
1919
2552
|
const running = summary ? summary.running === true : false
|
|
1920
2553
|
|
|
1921
2554
|
const openDialog = useCallback(() => {
|
|
1922
|
-
window.dispatchEvent(
|
|
1923
|
-
|
|
1924
|
-
|
|
2555
|
+
window.dispatchEvent(
|
|
2556
|
+
new CustomEvent(EVENT, {
|
|
2557
|
+
detail: { sessionId, title: summary && summary.title ? summary.title : null, running },
|
|
2558
|
+
}),
|
|
2559
|
+
)
|
|
1925
2560
|
}, [sessionId, summary, running])
|
|
1926
2561
|
|
|
1927
|
-
return React.createElement(
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
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
|
+
)
|
|
1931
2573
|
}
|
|
1932
2574
|
|
|
1933
2575
|
// 官方图标适配:0.2.0 primitives 的 IconClock 与原生操作行同款;
|
|
@@ -1938,22 +2580,38 @@ window.__ModuleLoader__.load({
|
|
|
1938
2580
|
try {
|
|
1939
2581
|
const P = require('@deepseek-ai/dsh-client-ui-primitives')
|
|
1940
2582
|
IconClock = P && P.IconClockOutlineRegular
|
|
1941
|
-
} catch {
|
|
1942
|
-
|
|
1943
|
-
// 官方 IconClockOutlineArtwork 1:1 路径( Regular = 1px stroke)
|
|
1944
|
-
return React.createElement('svg', { width: 16, height: 16, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': true, stroke: 'currentColor', strokeWidth: 1 },
|
|
1945
|
-
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' }),
|
|
1946
|
-
React.createElement('path', { d: 'M8 4.31V8.46L11 10.08' }))
|
|
2583
|
+
} catch {
|
|
2584
|
+
/* fallback below */
|
|
1947
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
|
+
}
|
|
1948
2598
|
var IconQuote = null
|
|
1949
2599
|
try {
|
|
1950
2600
|
const P2 = require('@deepseek-ai/dsh-client-ui-primitives')
|
|
1951
2601
|
IconQuote = P2 && (P2.IconChatOutlineRegular || P2.IconCopyOutlineRegular)
|
|
1952
|
-
} catch {
|
|
1953
|
-
|
|
1954
|
-
return React.createElement('svg', { width: 16, height: 16, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': true, stroke: 'currentColor', strokeWidth: 1 },
|
|
1955
|
-
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 */
|
|
1956
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
|
+
}
|
|
1957
2615
|
|
|
1958
2616
|
// --- 0.3.0 assistant-actions 官方槽:每条 AI 消息旁的原生回撤按钮 ------------
|
|
1959
2617
|
// 契约(dsh-cordis-client-runner):scope session,条目组件收 { messageId } +
|
|
@@ -1967,7 +2625,7 @@ window.__ModuleLoader__.load({
|
|
|
1967
2625
|
const t = (props && props.t) || __t
|
|
1968
2626
|
useLocaleRevision()
|
|
1969
2627
|
if (inputActions && typeof inputActions.setDraft === 'function') __inputActions = inputActions
|
|
1970
|
-
const sessions = useSessions ? useSessions(
|
|
2628
|
+
const sessions = useSessions ? useSessions(s => s) : undefined
|
|
1971
2629
|
const summary = sessions && sessions.byId ? sessions.byId[sessionId] : undefined
|
|
1972
2630
|
const running = summary ? summary.running === true : false
|
|
1973
2631
|
const [seq, setSeq] = React.useState(null)
|
|
@@ -1977,7 +2635,7 @@ window.__ModuleLoader__.load({
|
|
|
1977
2635
|
// 没有回撤/引用按钮」—— 已经挂载的槽位 effect 不会因缓存被换而重跑。
|
|
1978
2636
|
const [idxRev, setIdxRev] = React.useState(0)
|
|
1979
2637
|
React.useEffect(() => {
|
|
1980
|
-
const onIdx = () => setIdxRev(
|
|
2638
|
+
const onIdx = () => setIdxRev(v => v + 1)
|
|
1981
2639
|
window.addEventListener(SEQ_INDEX_EVENT, onIdx)
|
|
1982
2640
|
return () => window.removeEventListener(SEQ_INDEX_EVENT, onIdx)
|
|
1983
2641
|
}, [])
|
|
@@ -1986,31 +2644,35 @@ window.__ModuleLoader__.load({
|
|
|
1986
2644
|
let alive = true
|
|
1987
2645
|
let retried = false
|
|
1988
2646
|
const load = () => {
|
|
1989
|
-
const p = fetchMessagesJson('/api/message-ops/messages?sessionId=' + encodeURIComponent(sessionId))
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
})
|
|
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
|
+
})
|
|
2003
2660
|
__seqIndexCache.set(sessionId, p)
|
|
2004
2661
|
// 0.5.2(P2):失败必须清缓存——否则 rejected promise 被永久缓存,
|
|
2005
2662
|
// 该会话按钮/dock 到刷新页面为止全部失效
|
|
2006
2663
|
// 0.9.7:只在缓存里还是**我们这条** promise 时才删(syncSeqIndex 可能已换掉)
|
|
2007
|
-
p.catch(() => {
|
|
2664
|
+
p.catch(() => {
|
|
2665
|
+
if (__seqIndexCache.get(sessionId) === p) __seqIndexCache.delete(sessionId)
|
|
2666
|
+
})
|
|
2008
2667
|
return p
|
|
2009
2668
|
}
|
|
2010
|
-
const resolve =
|
|
2669
|
+
const resolve = index => {
|
|
2011
2670
|
if (!alive) return
|
|
2012
2671
|
const hit = index && index.get(String(messageId))
|
|
2013
|
-
if (typeof hit === 'number') {
|
|
2672
|
+
if (typeof hit === 'number') {
|
|
2673
|
+
setSeq(hit)
|
|
2674
|
+
return
|
|
2675
|
+
}
|
|
2014
2676
|
// 0.9.7(P4):索引里没有这个 messageId = 会话已增长(或索引过期)。
|
|
2015
2677
|
// 旧实现这里**什么都不做**,`seq` 永远是 null → 组件 return null →
|
|
2016
2678
|
// 按钮再也不渲染。现在失效并重拉一次(retried 保证不自旋);
|
|
@@ -2019,13 +2681,20 @@ window.__ModuleLoader__.load({
|
|
|
2019
2681
|
retried = true
|
|
2020
2682
|
__seqIndexCache.delete(sessionId)
|
|
2021
2683
|
__fullTextCache.delete(sessionId)
|
|
2022
|
-
load()
|
|
2684
|
+
load()
|
|
2685
|
+
.then(resolve)
|
|
2686
|
+
.catch(() => {})
|
|
2023
2687
|
}
|
|
2024
2688
|
const cached = __seqIndexCache.get(sessionId)
|
|
2025
2689
|
if (cached && typeof cached.then === 'function') cached.then(resolve).catch(() => {})
|
|
2026
2690
|
else if (cached) resolve(cached)
|
|
2027
|
-
else
|
|
2028
|
-
|
|
2691
|
+
else
|
|
2692
|
+
load()
|
|
2693
|
+
.then(resolve)
|
|
2694
|
+
.catch(() => {})
|
|
2695
|
+
return () => {
|
|
2696
|
+
alive = false
|
|
2697
|
+
}
|
|
2029
2698
|
}, [messageId, sessionId, idxRev])
|
|
2030
2699
|
|
|
2031
2700
|
// 原文(引用用):seq 解析后按需取全文
|
|
@@ -2033,14 +2702,16 @@ window.__ModuleLoader__.load({
|
|
|
2033
2702
|
if (seq == null || !sessionId) return
|
|
2034
2703
|
let alive = true
|
|
2035
2704
|
const cached = __fullTextCache.get(sessionId)
|
|
2036
|
-
const resolve =
|
|
2705
|
+
const resolve = full => {
|
|
2037
2706
|
if (!alive) return
|
|
2038
2707
|
const hit = full && full.get(String(messageId))
|
|
2039
2708
|
if (typeof hit === 'string') setFullText(hit)
|
|
2040
2709
|
}
|
|
2041
2710
|
if (cached && typeof cached.then === 'function') cached.then(resolve).catch(() => {})
|
|
2042
2711
|
else if (cached) resolve(cached)
|
|
2043
|
-
return () => {
|
|
2712
|
+
return () => {
|
|
2713
|
+
alive = false
|
|
2714
|
+
}
|
|
2044
2715
|
}, [seq, messageId, sessionId])
|
|
2045
2716
|
|
|
2046
2717
|
// 0.5.0 回撤后的视图刷新:openSession(reveal) 重建会话视图 → 遮蔽立即呈现。
|
|
@@ -2051,7 +2722,9 @@ window.__ModuleLoader__.load({
|
|
|
2051
2722
|
__uiWorkspace.openSession(sessionId)
|
|
2052
2723
|
return true
|
|
2053
2724
|
}
|
|
2054
|
-
} catch {
|
|
2725
|
+
} catch {
|
|
2726
|
+
/* fallthrough */
|
|
2727
|
+
}
|
|
2055
2728
|
return false
|
|
2056
2729
|
}
|
|
2057
2730
|
|
|
@@ -2061,14 +2734,21 @@ window.__ModuleLoader__.load({
|
|
|
2061
2734
|
// 0.5.2(P2):Promise.resolve 包裹——fetch/stringify 同步抛出也转为
|
|
2062
2735
|
// rejection 落进 finally,busy 永不卡死
|
|
2063
2736
|
Promise.resolve()
|
|
2064
|
-
.then(() =>
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
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 => {
|
|
2069
2745
|
let data = {}
|
|
2070
|
-
try {
|
|
2071
|
-
|
|
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)
|
|
2072
2752
|
notifyDone(t('done.revert'))
|
|
2073
2753
|
// 0.9.6:回填被删掉的那句用户原文(边界是 AI 消息时取它之前那条用户消息)。
|
|
2074
2754
|
// 此前这个入口完全不回填 —— 表现就是「回滚成功但消息框空着」。
|
|
@@ -2076,7 +2756,7 @@ window.__ModuleLoader__.load({
|
|
|
2076
2756
|
revealSession()
|
|
2077
2757
|
emitChanged()
|
|
2078
2758
|
})
|
|
2079
|
-
.catch(
|
|
2759
|
+
.catch(reason => {
|
|
2080
2760
|
notifyDone(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error')
|
|
2081
2761
|
})
|
|
2082
2762
|
.finally(() => setBusy(null))
|
|
@@ -2090,17 +2770,27 @@ window.__ModuleLoader__.load({
|
|
|
2090
2770
|
return
|
|
2091
2771
|
}
|
|
2092
2772
|
const span = inputActions.captureInsertion()
|
|
2093
|
-
const insertQuote =
|
|
2094
|
-
if (text == null || text === '') {
|
|
2095
|
-
|
|
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'
|
|
2096
2783
|
const ok = inputActions.insertText(quoted, span)
|
|
2097
2784
|
notifyDone(ok ? t('quote.done') : t('quote.unavailable'), ok ? 'ok' : 'warn')
|
|
2098
2785
|
}
|
|
2099
2786
|
// assistant 消息 fullText 恒 null(列表不携带)→ 按 seq 向服务端取单条全文
|
|
2100
|
-
if (fullText != null && fullText !== '') {
|
|
2787
|
+
if (fullText != null && fullText !== '') {
|
|
2788
|
+
insertQuote(fullText)
|
|
2789
|
+
return
|
|
2790
|
+
}
|
|
2101
2791
|
fetch('/api/message-ops/text?sessionId=' + encodeURIComponent(sessionId) + '&seq=' + encodeURIComponent(seq))
|
|
2102
|
-
.then(
|
|
2103
|
-
.then(
|
|
2792
|
+
.then(r => (r.ok ? r.json() : null))
|
|
2793
|
+
.then(d => insertQuote(d && d.ok && typeof d.text === 'string' ? d.text : null))
|
|
2104
2794
|
.catch(() => insertQuote(null))
|
|
2105
2795
|
} catch (e) {
|
|
2106
2796
|
notifyDone(t('errorPrefix') + (e && e.message ? e.message : String(e)), 'error')
|
|
@@ -2108,16 +2798,35 @@ window.__ModuleLoader__.load({
|
|
|
2108
2798
|
}
|
|
2109
2799
|
|
|
2110
2800
|
if (seq == null) return null
|
|
2111
|
-
const act = (icon, label, mode, onClick, disabled) =>
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
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 } },
|
|
2121
2830
|
act(React.createElement(IconClock, { size: 16 }), t('slot.revert'), 'revert', runRevert, running),
|
|
2122
2831
|
act(React.createElement(IconQuote, { size: 16 }), t('slot.quote'), 'quote', runQuote, false),
|
|
2123
2832
|
)
|
|
@@ -2135,9 +2844,9 @@ window.__ModuleLoader__.load({
|
|
|
2135
2844
|
// SessionRevert.commit() → revert:null → affordance 消失)。
|
|
2136
2845
|
// 我们是 append-only,marker 不会真消失,所以由服务端按
|
|
2137
2846
|
// 「marker 之后有无 source.kind==='user' 的真实输入」算出 committed。
|
|
2138
|
-
return (msgs || []).filter(
|
|
2139
|
-
m.marker && m.sourceKind !== 'compact-checkpoint'
|
|
2140
|
-
|
|
2847
|
+
return (msgs || []).filter(
|
|
2848
|
+
m => m.marker && m.sourceKind !== 'compact-checkpoint' && m.restoreComplete !== true && m.committed !== true,
|
|
2849
|
+
)
|
|
2141
2850
|
}
|
|
2142
2851
|
|
|
2143
2852
|
/**
|
|
@@ -2169,7 +2878,7 @@ window.__ModuleLoader__.load({
|
|
|
2169
2878
|
const t = (props && props.t) || __t
|
|
2170
2879
|
useLocaleRevision()
|
|
2171
2880
|
if (inputActions && typeof inputActions.setDraft === 'function') __inputActions = inputActions
|
|
2172
|
-
const sessions = useSessions ? useSessions(
|
|
2881
|
+
const sessions = useSessions ? useSessions(s => s) : undefined
|
|
2173
2882
|
const summary = sessions && sessions.byId ? sessions.byId[sessionId] : undefined
|
|
2174
2883
|
const running = summary ? summary.running === true : false
|
|
2175
2884
|
// F1 主路径:宿主 activity 信号(见下方 effect);null = 无 useSessions 或尚无活动
|
|
@@ -2192,7 +2901,10 @@ window.__ModuleLoader__.load({
|
|
|
2192
2901
|
// opencode SessionRevertDock 视觉(v2 布局,DSH 令牌等价映射)
|
|
2193
2902
|
useEffect(() => {
|
|
2194
2903
|
if (styleInjected || typeof document === 'undefined') return
|
|
2195
|
-
if (document.getElementById('dsh-message-ops-dock-style')) {
|
|
2904
|
+
if (document.getElementById('dsh-message-ops-dock-style')) {
|
|
2905
|
+
setStyleInjected(true)
|
|
2906
|
+
return
|
|
2907
|
+
}
|
|
2196
2908
|
const tag = document.createElement('style')
|
|
2197
2909
|
tag.id = 'dsh-message-ops-dock-style'
|
|
2198
2910
|
tag.textContent = [
|
|
@@ -2232,31 +2944,31 @@ window.__ModuleLoader__.load({
|
|
|
2232
2944
|
// emitChanged() 自己就是先 invalidate 再发事件,这里同款红线。
|
|
2233
2945
|
invalidateMessagesMemo()
|
|
2234
2946
|
return fetchMessagesJson('/api/message-ops/messages?sessionId=' + encodeURIComponent(sessionId))
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
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
|
+
}
|
|
2255
2968
|
}
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
.catch(() => {})
|
|
2969
|
+
setShadowCount(seen.size)
|
|
2970
|
+
})
|
|
2971
|
+
.catch(() => {})
|
|
2260
2972
|
}
|
|
2261
2973
|
|
|
2262
2974
|
// F1(复审后重做):宿主在 user/message(source.kind==='user') 时会
|
|
@@ -2322,45 +3034,67 @@ window.__ModuleLoader__.load({
|
|
|
2322
3034
|
if (step.reload) loadRef.current()
|
|
2323
3035
|
}, [sessionId, activityAt])
|
|
2324
3036
|
|
|
2325
|
-
|
|
2326
3037
|
// items 变化自动折叠(opencode createEffect 同款;必须在早退之前——Hooks 规则)
|
|
2327
|
-
useEffect(() => {
|
|
3038
|
+
useEffect(() => {
|
|
3039
|
+
setOpen(false)
|
|
3040
|
+
}, [markers && markers.length, markers && markers[0] && markers[0].seq])
|
|
2328
3041
|
if (!markers || !markers.length) return null
|
|
2329
3042
|
|
|
2330
|
-
const restoreRow =
|
|
3043
|
+
const restoreRow = row => {
|
|
2331
3044
|
if (restoring != null || running) return
|
|
2332
3045
|
setRestoring(rowKey(row))
|
|
2333
3046
|
Promise.resolve()
|
|
2334
|
-
.then(() =>
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
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 => {
|
|
2340
3056
|
let data = {}
|
|
2341
|
-
try {
|
|
2342
|
-
|
|
2343
|
-
|
|
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
|
+
)
|
|
2344
3069
|
setRestoring(null)
|
|
2345
3070
|
// 0.5.0:恢复后重建会话视图(重放消息立即可见)
|
|
2346
3071
|
try {
|
|
2347
3072
|
if (__uiWorkspace && typeof __uiWorkspace.openSession === 'function') __uiWorkspace.openSession(sessionId)
|
|
2348
|
-
} catch {
|
|
3073
|
+
} catch {
|
|
3074
|
+
/* fallthrough */
|
|
3075
|
+
}
|
|
2349
3076
|
// 0.9.1:重放的消息带**新 seq**,被恢复的行必须解除 hidden;dock 的
|
|
2350
3077
|
// marker 列表要按权威数据重算(restoreComplete 会变 true)后重拉。
|
|
2351
3078
|
emitChanged()
|
|
2352
|
-
for (const delay of [150, 700, 1600])
|
|
3079
|
+
for (const delay of [150, 700, 1600])
|
|
3080
|
+
setTimeout(() => {
|
|
3081
|
+
if (__refreshSurface) __refreshSurface(sessionId)
|
|
3082
|
+
}, delay)
|
|
2353
3083
|
const fresh = await fetchMessagesJson('/api/message-ops/messages?sessionId=' + encodeURIComponent(sessionId)).catch(() => null)
|
|
2354
3084
|
if (fresh && fresh.ok) setMarkers(activeMarkers(fresh.messages || []))
|
|
2355
3085
|
})
|
|
2356
|
-
.catch(
|
|
3086
|
+
.catch(reason => {
|
|
2357
3087
|
notifyDone(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error')
|
|
2358
3088
|
})
|
|
2359
3089
|
.finally(() => setRestoring(null))
|
|
2360
3090
|
}
|
|
2361
3091
|
|
|
2362
|
-
|
|
2363
|
-
|
|
3092
|
+
const headerKbd = e => {
|
|
3093
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
3094
|
+
e.preventDefault()
|
|
3095
|
+
setOpen(v => !v)
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
2364
3098
|
// 0.5.2(P2):标题报「被遮蔽消息数」而非标记数——一个 revert 可遮蔽数百条,
|
|
2365
3099
|
// 用标记数会严重低报(0.4.2 文案引入的错口径);无 range 数据时回退标记数
|
|
2366
3100
|
const label = t('dock.title', { n: String(shadowCount || markers.length) })
|
|
@@ -2368,19 +3102,28 @@ window.__ModuleLoader__.load({
|
|
|
2368
3102
|
|
|
2369
3103
|
// 0.8.0:行 = 待恢复"轮"(对齐 opencode 按轮步进);无可重放轮的标记
|
|
2370
3104
|
// 保留旧式整段行(空区间 → 停用 notice 路径)。restoring 键区分同标记多轮。
|
|
2371
|
-
const rowKey =
|
|
2372
|
-
const rowEl =
|
|
2373
|
-
React.createElement(
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
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
|
+
)
|
|
2384
3127
|
const dockRows = []
|
|
2385
3128
|
for (const mk of markers || []) {
|
|
2386
3129
|
if (Array.isArray(mk.pendingTurns) && mk.pendingTurns.length > 0) {
|
|
@@ -2392,26 +3135,74 @@ window.__ModuleLoader__.load({
|
|
|
2392
3135
|
}
|
|
2393
3136
|
}
|
|
2394
3137
|
|
|
2395
|
-
const chevron = React.createElement(
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
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
|
+
},
|
|
2407
3149
|
},
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
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
|
+
),
|
|
2412
3202
|
React.createElement('span', { className: 'mopsRdLabel' + (open ? '' : ' mopsRdLabelCollapsed') }, label),
|
|
2413
3203
|
open ? null : React.createElement('span', { className: 'mopsRdPreview' }, preview),
|
|
2414
|
-
React.createElement('span', { style: { marginLeft: 'auto', flex: 'none' } }, chevron)
|
|
3204
|
+
React.createElement('span', { style: { marginLeft: 'auto', flex: 'none' } }, chevron),
|
|
3205
|
+
),
|
|
2415
3206
|
open ? React.createElement('div', { className: 'mopsRdList' }, dockRows.map(rowEl)) : null,
|
|
2416
3207
|
)
|
|
2417
3208
|
}
|
|
@@ -2435,7 +3226,7 @@ window.__ModuleLoader__.load({
|
|
|
2435
3226
|
window.__MOPS_USER_REVERT_INSTALLED = true
|
|
2436
3227
|
var rowsCache = { sid: null, rows: null, at: 0 }
|
|
2437
3228
|
__peekRowsCache = () => rowsCache
|
|
2438
|
-
var norm =
|
|
3229
|
+
var norm = x => String(x || '').replace(/\s+/g, '')
|
|
2439
3230
|
|
|
2440
3231
|
// 0.9.7(P4):messageId→seq / 全文索引挂在**同一个 dataSig** 上。
|
|
2441
3232
|
// 旧实现每会话只写一次、仅失败时 delete —— 会话增长后新 assistant 消息的
|
|
@@ -2449,7 +3240,7 @@ window.__ModuleLoader__.load({
|
|
|
2449
3240
|
__seqDataSig = sig
|
|
2450
3241
|
const index = new Map()
|
|
2451
3242
|
const full = new Map()
|
|
2452
|
-
for (const m of
|
|
3243
|
+
for (const m of messages || []) {
|
|
2453
3244
|
if (!m || m.id == null) continue
|
|
2454
3245
|
const k = String(m.id)
|
|
2455
3246
|
// 同 id 取**最早** seq —— 与槽位自己的 buildSeqIndex 口径一致
|
|
@@ -2461,17 +3252,21 @@ window.__ModuleLoader__.load({
|
|
|
2461
3252
|
__seqIndexCache.set(key, index)
|
|
2462
3253
|
__fullTextCache.set(key, full)
|
|
2463
3254
|
}
|
|
2464
|
-
try {
|
|
3255
|
+
try {
|
|
3256
|
+
window.dispatchEvent(new CustomEvent(SEQ_INDEX_EVENT))
|
|
3257
|
+
} catch {
|
|
3258
|
+
/* non-browser */
|
|
3259
|
+
}
|
|
2465
3260
|
}
|
|
2466
3261
|
|
|
2467
|
-
var fetchRows =
|
|
3262
|
+
var fetchRows = sidIn => {
|
|
2468
3263
|
// 0.9.7:统一按**裸 uuid** 作缓存键。调用方有的传 `session-xxx`(scan /
|
|
2469
3264
|
// /undo 的 rawSid)有的传裸 uuid(/redo 的 bareSessionId)—— 混用会让
|
|
2470
3265
|
// rowsCache.sid 在两个键之间来回横跳,每次都是缓存未命中(白白多发 GET)。
|
|
2471
3266
|
const sid = bareSessionId(sidIn)
|
|
2472
3267
|
if (rowsCache.sid === sid && rowsCache.rows && Date.now() - rowsCache.at < 8000) return Promise.resolve(rowsCache)
|
|
2473
3268
|
return fetchMessagesJson('/api/message-ops/messages?sessionId=' + encodeURIComponent(sid))
|
|
2474
|
-
.then(
|
|
3269
|
+
.then(d => {
|
|
2475
3270
|
// 宿主会把 <system-reminder> / runtime context 等也记为 role=user 的行,
|
|
2476
3271
|
// DOM 里并不渲染成"我的消息"块 —— 必须滤掉,否则按序配对会错位(0.7.0 根因)。
|
|
2477
3272
|
// 注意:对话框的「可回滚目标」列表仍应过滤 visible(那是另一套语义)。
|
|
@@ -2482,11 +3277,21 @@ window.__ModuleLoader__.load({
|
|
|
2482
3277
|
// 否则 `Background job 是我自己的问题` 这种真人输入会被误杀
|
|
2483
3278
|
// (曾用 ^background job\b,测试当场抓到这个误杀)。
|
|
2484
3279
|
// 样本里没出现过的模式(已停止 / User feedback:)一律**不加** —— 没证据就不猜。
|
|
2485
|
-
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
|
+
)
|
|
2486
3284
|
const rows = ((d && d.messages) || [])
|
|
2487
|
-
.filter(
|
|
2488
|
-
.map(
|
|
2489
|
-
|
|
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))
|
|
2490
3295
|
// 0.9.1:同时产出 node-key 查表索引(隐藏 transcript 用)
|
|
2491
3296
|
const idx = buildIndex(d)
|
|
2492
3297
|
rowsCache = { sid: sid, rows: rows, idx: idx, at: Date.now() }
|
|
@@ -2500,37 +3305,37 @@ window.__ModuleLoader__.load({
|
|
|
2500
3305
|
// dsh transcript 刻意不折叠(surface.d.ts:51-63 "replacement copies stay
|
|
2501
3306
|
// model-only"),回滚只能在渲染层按 `data-chat-node-key` 精确查表(零启发式)。
|
|
2502
3307
|
// 背景长文与「40 字符前缀匹配」事故见 README「0.9.1 / 0.9.2 · 回滚「真的生效了」」。
|
|
2503
|
-
var parseNodeKey =
|
|
2504
|
-
var m = /^(\d+):/.exec(k || '')
|
|
2505
|
-
if (!m) return null
|
|
2506
|
-
var digits = m[1].length
|
|
2507
|
-
var kindLen = Number(m[1])
|
|
2508
|
-
var start = digits + 1
|
|
2509
|
-
if (!Number.isSafeInteger(kindLen) || kindLen <= 0 || k.length < start + kindLen) return null
|
|
2510
|
-
return { kind: k.slice(start, start + kindLen), id: k.slice(start + kindLen) }
|
|
2511
|
-
}
|
|
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
|
+
}
|
|
2512
3317
|
|
|
2513
3318
|
/**
|
|
2514
3319
|
* 从 /api/message-ops/messages 的响应构建全部查表。
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
var buildIndex =
|
|
3320
|
+
* 两条铁律:① 索引只认唯一 id;② 缺数据一律返回 undefined(调用方保持可见)。
|
|
3321
|
+
*/
|
|
3322
|
+
var buildIndex = payload => {
|
|
2518
3323
|
var list = (payload && payload.messages) || []
|
|
2519
3324
|
// 0.9.1:回合页脚/过程条不是消息,用 turn/end 的 seq 定位(边界常落在 turn 内部,
|
|
2520
3325
|
// 用 turn/start 会漏判该回合的页脚)
|
|
2521
|
-
var turnEnd = (payload && payload.turnEndSeq) || null
|
|
2522
|
-
var byMessageId = new Map()
|
|
2523
|
-
var byTurnStep = new Map()
|
|
2524
|
-
var byCallId = new Map()
|
|
2525
|
-
var byTurn = new Map()
|
|
2526
|
-
var shadowed = new Set()
|
|
2527
|
-
var visibleTurns = new Set()
|
|
2528
|
-
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()
|
|
2529
3334
|
for (var i = 0; i < list.length; i++) {
|
|
2530
|
-
var m = list[i]
|
|
2531
|
-
if (!m || typeof m.seq !== 'number') continue
|
|
3335
|
+
var m = list[i]
|
|
3336
|
+
if (!m || typeof m.seq !== 'number') continue
|
|
2532
3337
|
if (m.id != null) {
|
|
2533
|
-
var k = String(m.id)
|
|
3338
|
+
var k = String(m.id)
|
|
2534
3339
|
// restore 是「重放」语义 → 原件与副本可能同 id 并存。
|
|
2535
3340
|
// 0.9.1:不再「保留最早」,而是收集**全部** seq,隐藏判据取「任一 seq 越过
|
|
2536
3341
|
// fence」。回放副本才是当前 surface 上的那条,用最早的 seq 判会让
|
|
@@ -2539,32 +3344,34 @@ window.__ModuleLoader__.load({
|
|
|
2539
3344
|
const arr = dupByMessageId.get(k) || [byMessageId.get(k)]
|
|
2540
3345
|
arr.push(m.seq)
|
|
2541
3346
|
dupByMessageId.set(k, arr)
|
|
2542
|
-
byMessageId.set(k, m.seq)
|
|
2543
|
-
} else {
|
|
3347
|
+
byMessageId.set(k, m.seq) // 指向最新的
|
|
3348
|
+
} else {
|
|
3349
|
+
byMessageId.set(k, m.seq)
|
|
3350
|
+
}
|
|
2544
3351
|
}
|
|
2545
3352
|
if (m.type === 'assistant/message' && m.turn != null && m.step != null) {
|
|
2546
|
-
byTurnStep.set(m.turn + ':' + m.step, m.seq)
|
|
3353
|
+
byTurnStep.set(m.turn + ':' + m.step, m.seq)
|
|
2547
3354
|
}
|
|
2548
|
-
if (m.type === 'tool/call' && m.id != null) byCallId.set(String(m.id), m.seq)
|
|
2549
|
-
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)
|
|
2550
3357
|
// 0.9.6:藏行判据用 shadowed(replace 区间),**不用** m.visible(模型 surface)。
|
|
2551
3358
|
// visible 在 live 路径下对 tool/call 恒 false → 拿它当判据会把整页工具行全藏,
|
|
2552
3359
|
// 故这里连集合都不建(判据样本见 test/surface-visibility.test.js)。
|
|
2553
|
-
if (m.shadowed === true) shadowed.add(m.seq)
|
|
2554
|
-
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))
|
|
2555
3362
|
}
|
|
2556
3363
|
// turnEnd 优先:它对「该 turn 内一条消息都没有」的情况仍然有效
|
|
2557
3364
|
if (turnEnd) for (const k in turnEnd) if (Object.prototype.hasOwnProperty.call(turnEnd, k)) byTurn.set(k, turnEnd[k])
|
|
2558
|
-
return { byMessageId, dupByMessageId, byTurnStep, byCallId, byTurn, shadowed, visibleTurns, total: list.length }
|
|
2559
|
-
}
|
|
3365
|
+
return { byMessageId, dupByMessageId, byTurnStep, byCallId, byTurn, shadowed, visibleTurns, total: list.length }
|
|
3366
|
+
}
|
|
2560
3367
|
|
|
2561
3368
|
/** node-key → { seq, all }(all = 同 id 的全部 seq,处理 restore 重放副本)。 */
|
|
2562
3369
|
var seqOfNodeKey = (key, idx) => {
|
|
2563
|
-
var parsed = parseNodeKey(key)
|
|
2564
|
-
if (!parsed || !idx) return null
|
|
2565
|
-
var id = parsed.id
|
|
3370
|
+
var parsed = parseNodeKey(key)
|
|
3371
|
+
if (!parsed || !idx) return null
|
|
3372
|
+
var id = parsed.id
|
|
2566
3373
|
switch (parsed.kind) {
|
|
2567
|
-
case 'input-message':
|
|
3374
|
+
case 'input-message': // user / steering / turn-trigger
|
|
2568
3375
|
case 'developer-message':
|
|
2569
3376
|
case 'trajectory-note': {
|
|
2570
3377
|
const hit = idx.byMessageId.get(id)
|
|
@@ -2590,9 +3397,9 @@ window.__ModuleLoader__.load({
|
|
|
2590
3397
|
return hit === undefined ? null : { kind: parsed.kind, seq: hit, all: [hit], turn: id }
|
|
2591
3398
|
}
|
|
2592
3399
|
default:
|
|
2593
|
-
return null
|
|
3400
|
+
return null // compaction / command / workflow-run 等不参与
|
|
2594
3401
|
}
|
|
2595
|
-
}
|
|
3402
|
+
}
|
|
2596
3403
|
|
|
2597
3404
|
/**
|
|
2598
3405
|
* 把 transcript 行按模型 surface 可见性打上 hidden。
|
|
@@ -2604,46 +3411,49 @@ window.__ModuleLoader__.load({
|
|
|
2604
3411
|
* 是唯一会误藏用户内容的路径。
|
|
2605
3412
|
*/
|
|
2606
3413
|
var applySurfaceVisibility = (root, idx) => {
|
|
2607
|
-
if (!idx) return { hidden: 0, unresolved: 0, shown: 0 }
|
|
3414
|
+
if (!idx) return { hidden: 0, unresolved: 0, shown: 0 }
|
|
2608
3415
|
// 0.9.7(P2-1):root 既可传 document/元素(调用方自查),也可直接传
|
|
2609
3416
|
// 已经查好的行集合 —— ensureAssign 每次都要算 rows.length 当签名,
|
|
2610
3417
|
// 传集合避免同一次扫描里 querySelectorAll 跑两遍。
|
|
2611
|
-
var rows =
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
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
|
|
2615
3425
|
for (var i = 0; i < rows.length; i++) {
|
|
2616
|
-
var row = rows[i]
|
|
3426
|
+
var row = rows[i]
|
|
2617
3427
|
// 0.9.6 藏行判据 = **replace 区间(shadowed)**;revertFences→visible→shadowed
|
|
2618
3428
|
// 演进史(含 4792/4793 全藏事故)见 README「历史事故记录」#4。
|
|
2619
|
-
var hit = seqOfNodeKey(row.getAttribute('data-chat-node-key'), idx)
|
|
3429
|
+
var hit = seqOfNodeKey(row.getAttribute('data-chat-node-key'), idx)
|
|
2620
3430
|
// 0.9.7(P2-1)幂等跳写:判据与执行时机**一字未改**,只在
|
|
2621
3431
|
// 「目标状态 ≠ 当前状态」时才碰属性 —— 省掉全表几百次无效写。
|
|
2622
3432
|
if (hit === null) {
|
|
2623
|
-
unresolved
|
|
2624
|
-
if (row.hasAttribute('hidden')) row.removeAttribute('hidden')
|
|
2625
|
-
continue
|
|
3433
|
+
unresolved++
|
|
3434
|
+
if (row.hasAttribute('hidden')) row.removeAttribute('hidden')
|
|
3435
|
+
continue
|
|
2626
3436
|
}
|
|
2627
|
-
var shouldHide
|
|
3437
|
+
var shouldHide
|
|
2628
3438
|
if (hit.turn !== undefined) {
|
|
2629
3439
|
// 回合 chrome:本 turn 还有未被遮蔽的消息就露出
|
|
2630
|
-
shouldHide = !idx.visibleTurns.has(String(hit.turn))
|
|
3440
|
+
shouldHide = !idx.visibleTurns.has(String(hit.turn))
|
|
2631
3441
|
} else {
|
|
2632
3442
|
// 消息/工具类:**是否落在 replace 区间内**(= 被回滚掉了)。
|
|
2633
3443
|
// ⚠️ 不能用 visible(模型 surface)——live 路径下 tool/call 恒不在 surface,
|
|
2634
3444
|
// 会把整页工具行全藏(实测 157 行藏 152 行)。
|
|
2635
|
-
shouldHide = idx.shadowed.has(hit.seq)
|
|
3445
|
+
shouldHide = idx.shadowed.has(hit.seq)
|
|
2636
3446
|
}
|
|
2637
3447
|
if (shouldHide) {
|
|
2638
|
-
hidden
|
|
2639
|
-
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')
|
|
2640
3450
|
} else {
|
|
2641
|
-
shown
|
|
2642
|
-
if (row.hasAttribute('hidden')) row.removeAttribute('hidden')
|
|
3451
|
+
shown++
|
|
3452
|
+
if (row.hasAttribute('hidden')) row.removeAttribute('hidden')
|
|
2643
3453
|
}
|
|
2644
3454
|
}
|
|
2645
|
-
return { hidden, unresolved, shown }
|
|
2646
|
-
}
|
|
3455
|
+
return { hidden, unresolved, shown }
|
|
3456
|
+
}
|
|
2647
3457
|
|
|
2648
3458
|
// 用户消息锚点:优先官方 Sixlwa_userRow(含 .xzv4MW_actions),回退 flow-kind 属性
|
|
2649
3459
|
// 锚点 = 每条用户消息自己的容器(一个块只算一次):
|
|
@@ -2651,12 +3461,18 @@ window.__ModuleLoader__.load({
|
|
|
2651
3461
|
var userAnchors = () => {
|
|
2652
3462
|
const out = []
|
|
2653
3463
|
const seen = new Set()
|
|
2654
|
-
const add =
|
|
3464
|
+
const add = el => {
|
|
3465
|
+
if (el && !seen.has(el)) {
|
|
3466
|
+
seen.add(el)
|
|
3467
|
+
out.push(el)
|
|
3468
|
+
}
|
|
3469
|
+
}
|
|
2655
3470
|
const rows = Array.from(document.querySelectorAll('[class*="xzv4MW_actions"]'))
|
|
2656
3471
|
for (const r of rows) {
|
|
2657
|
-
const block =
|
|
2658
|
-
|
|
2659
|
-
|
|
3472
|
+
const block =
|
|
3473
|
+
r.closest('[data-chat-flow-kind="user"]') ||
|
|
3474
|
+
r.closest('[class*="_userRow"], [class*="_userStack"], [class*="_bubble"]') ||
|
|
3475
|
+
r.parentElement
|
|
2660
3476
|
// 0.9.0:只按**稳定属性** + hash-immune 类名后缀判定,不再匹配 CSS-module
|
|
2661
3477
|
// 生成的前缀(`Sixlwa_*`)。dsh 0.2.0-rc.2 的哈希已变为 `EvIC1a_flowItem`,
|
|
2662
3478
|
// 旧前缀正则把所有块都滤掉 → anchors 为空 → 按钮拿不到 seq → 点击必失败。
|
|
@@ -2690,7 +3506,7 @@ window.__ModuleLoader__.load({
|
|
|
2690
3506
|
}
|
|
2691
3507
|
}
|
|
2692
3508
|
/** 块内全部插件按钮一起同步(回滚 / 分叉同一动作行)。 */
|
|
2693
|
-
var syncBlockButtons =
|
|
3509
|
+
var syncBlockButtons = block => {
|
|
2694
3510
|
if (!block || !block.querySelectorAll) return
|
|
2695
3511
|
for (const b of block.querySelectorAll('.mopsUserRevert, .mopsUserFork')) syncEnabled(block, b)
|
|
2696
3512
|
}
|
|
@@ -2698,7 +3514,7 @@ window.__ModuleLoader__.load({
|
|
|
2698
3514
|
const idx = cache && cache.idx
|
|
2699
3515
|
if (!idx) return
|
|
2700
3516
|
// 0.9.1:node-key 查表,替代旧的 40 字符前缀包含匹配(实测 4 条错 2 条)
|
|
2701
|
-
for (const b of
|
|
3517
|
+
for (const b of anchors || userAnchors()) {
|
|
2702
3518
|
b.removeAttribute('data-mops-seq')
|
|
2703
3519
|
b.removeAttribute('data-mops-unmatched')
|
|
2704
3520
|
const hit = seqOfNodeKey(b.getAttribute('data-chat-node-key'), idx)
|
|
@@ -2726,32 +3542,35 @@ window.__ModuleLoader__.load({
|
|
|
2726
3542
|
// 摘牌后 node-key 相同但打标为空,靠这里发现)
|
|
2727
3543
|
// 🔴 applySurfaceVisibility 仍然**无条件**执行,藏行判据与时机一字未改。
|
|
2728
3544
|
var assignSig = null
|
|
2729
|
-
var anchorSigOf =
|
|
3545
|
+
var anchorSigOf = anchors => {
|
|
2730
3546
|
let s = ''
|
|
2731
3547
|
for (let i = 0; i < anchors.length; i++) {
|
|
2732
3548
|
const b = anchors[i]
|
|
2733
|
-
s +=
|
|
2734
|
-
(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
|
+
','
|
|
2735
3554
|
}
|
|
2736
3555
|
return s
|
|
2737
3556
|
}
|
|
2738
|
-
var sigOf = (sid, dataSig, rowsLen, anchors) =>
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
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
|
+
})
|
|
2755
3574
|
// 0.7.0:点击时先**同步完成**配对(打标是异步 fetch 的结果,
|
|
2756
3575
|
// 早先点在未打标的按钮上会静默失败 = 用户反馈的"点了没用")。
|
|
2757
3576
|
var runUserRevert = (btn, block) => {
|
|
@@ -2761,43 +3580,57 @@ window.__ModuleLoader__.load({
|
|
|
2761
3580
|
Promise.resolve()
|
|
2762
3581
|
.then(() => ensureAssign(sid))
|
|
2763
3582
|
.then(() => fetchRows(sid))
|
|
2764
|
-
.then(
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
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
|
+
})
|
|
2801
3634
|
})
|
|
2802
3635
|
}
|
|
2803
3636
|
/**
|
|
@@ -2816,10 +3649,10 @@ window.__ModuleLoader__.load({
|
|
|
2816
3649
|
Promise.resolve()
|
|
2817
3650
|
.then(() => ensureAssign(sid))
|
|
2818
3651
|
.then(() => fetchRows(sid))
|
|
2819
|
-
.then(async
|
|
3652
|
+
.then(async cache => {
|
|
2820
3653
|
const rows = cache && cache.rows
|
|
2821
3654
|
const seq = Number(block.getAttribute('data-mops-seq'))
|
|
2822
|
-
const row = rows && rows.find(
|
|
3655
|
+
const row = rows && rows.find(r => r.seq === seq)
|
|
2823
3656
|
if (!row) {
|
|
2824
3657
|
notifyDone(__t('errorPrefix') + (__t('revert.unresolved') || 'fork target verification failed'), 'error')
|
|
2825
3658
|
return
|
|
@@ -2831,22 +3664,28 @@ window.__ModuleLoader__.load({
|
|
|
2831
3664
|
let text = typeof row.fullText === 'string' ? row.fullText : ''
|
|
2832
3665
|
if (!text) {
|
|
2833
3666
|
try {
|
|
2834
|
-
const res = await fetch(
|
|
3667
|
+
const res = await fetch(
|
|
3668
|
+
'/api/message-ops/text?sessionId=' + encodeURIComponent(bareSessionId(sid)) + '&seq=' + encodeURIComponent(seq),
|
|
3669
|
+
)
|
|
2835
3670
|
const data = res.ok ? await res.json().catch(() => null) : null
|
|
2836
3671
|
if (data && data.ok && typeof data.text === 'string') text = data.text
|
|
2837
|
-
} catch {
|
|
3672
|
+
} catch {
|
|
3673
|
+
/* 取全文失败:分叉照做,只是输入框留空 */
|
|
3674
|
+
}
|
|
2838
3675
|
}
|
|
2839
3676
|
const childId = await forkFromUserMessage(sid, seq, text, row.turnStartSeq)
|
|
2840
3677
|
notifyDone(__t('slot.forkDone', { id: String(childId || '') }))
|
|
2841
3678
|
if (childId) openSessionById(childId)
|
|
2842
3679
|
})
|
|
2843
|
-
.catch(
|
|
3680
|
+
.catch(reason => {
|
|
2844
3681
|
notifyDone(__t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error')
|
|
2845
3682
|
})
|
|
2846
|
-
.finally(() => {
|
|
3683
|
+
.finally(() => {
|
|
3684
|
+
btn.disabled = false
|
|
3685
|
+
})
|
|
2847
3686
|
}
|
|
2848
3687
|
|
|
2849
|
-
var ensureBtn =
|
|
3688
|
+
var ensureBtn = block => {
|
|
2850
3689
|
// 官方动作行(含 Copy):把按钮放到这一行里,与 Copy 同级
|
|
2851
3690
|
let host = block.querySelector('[class*="xzv4MW_actions"]')
|
|
2852
3691
|
if (!host) {
|
|
@@ -2861,9 +3700,11 @@ window.__ModuleLoader__.load({
|
|
|
2861
3700
|
btn.className = 'mopsUserRevert'
|
|
2862
3701
|
btn.title = __t('slot.revert')
|
|
2863
3702
|
btn.setAttribute('aria-label', __t('slot.revert'))
|
|
2864
|
-
btn.innerHTML =
|
|
2865
|
-
|
|
2866
|
-
|
|
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()
|
|
2867
3708
|
if (btn.disabled) return
|
|
2868
3709
|
runUserRevert(btn, block)
|
|
2869
3710
|
})
|
|
@@ -2876,7 +3717,7 @@ window.__ModuleLoader__.load({
|
|
|
2876
3717
|
}
|
|
2877
3718
|
|
|
2878
3719
|
/** 0.12.0 分叉按钮:与回滚按钮**同一动作行**(opencode 把 fork 放在 copy/undo 同组)。 */
|
|
2879
|
-
var ensureForkBtn =
|
|
3720
|
+
var ensureForkBtn = block => {
|
|
2880
3721
|
let host = block.querySelector('[class*="xzv4MW_actions"]')
|
|
2881
3722
|
if (!host) {
|
|
2882
3723
|
host = document.createElement('div')
|
|
@@ -2891,9 +3732,11 @@ window.__ModuleLoader__.load({
|
|
|
2891
3732
|
btn.title = __t('slot.forkHint')
|
|
2892
3733
|
btn.setAttribute('aria-label', __t('slot.fork'))
|
|
2893
3734
|
// 官方 IconBranchOutline16 的 1:1 路径(packages/client/ui-primitives/src/icons/index.tsx:149)
|
|
2894
|
-
btn.innerHTML =
|
|
2895
|
-
|
|
2896
|
-
|
|
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()
|
|
2897
3740
|
if (btn.disabled) return
|
|
2898
3741
|
runUserFork(btn, block)
|
|
2899
3742
|
})
|
|
@@ -2902,7 +3745,7 @@ window.__ModuleLoader__.load({
|
|
|
2902
3745
|
return btn
|
|
2903
3746
|
}
|
|
2904
3747
|
// 两个按钮的顺序由 DOM 顺序决定:回滚在前(破坏性更高),分叉在后(非破坏)。
|
|
2905
|
-
var ensureUserActions =
|
|
3748
|
+
var ensureUserActions = block => {
|
|
2906
3749
|
ensureBtn(block)
|
|
2907
3750
|
ensureForkBtn(block)
|
|
2908
3751
|
}
|
|
@@ -2913,25 +3756,32 @@ window.__ModuleLoader__.load({
|
|
|
2913
3756
|
// 共享窗口里的新鲜载荷先把隐藏刷对,不必等兜底那一发。
|
|
2914
3757
|
var refreshTimer = null
|
|
2915
3758
|
var refreshDeadline = 0
|
|
2916
|
-
__refreshSurface =
|
|
3759
|
+
__refreshSurface = sid => {
|
|
2917
3760
|
const id = sid || __currentSessionId
|
|
2918
3761
|
if (!id) return
|
|
2919
|
-
if (rowsCache) rowsCache.at = 0
|
|
3762
|
+
if (rowsCache) rowsCache.at = 0 // 强制重取权威数据
|
|
2920
3763
|
const now = Date.now()
|
|
2921
3764
|
if (!refreshTimer) refreshDeadline = now + 1500
|
|
2922
3765
|
clearTimeout(refreshTimer)
|
|
2923
|
-
refreshTimer = setTimeout(
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
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
|
+
)
|
|
2935
3785
|
}
|
|
2936
3786
|
var scan = () => {
|
|
2937
3787
|
try {
|
|
@@ -2944,7 +3794,9 @@ window.__ModuleLoader__.load({
|
|
|
2944
3794
|
// 打标后 transcript 再变化(openSession 重建 / 分页 / restore 重放)
|
|
2945
3795
|
// 就再也不会重算隐藏,导致「界面停在旧状态,必须重载页面才对」。
|
|
2946
3796
|
ensureAssign(sid)
|
|
2947
|
-
} catch {
|
|
3797
|
+
} catch {
|
|
3798
|
+
/* 注入失败不影响会话 */
|
|
3799
|
+
}
|
|
2948
3800
|
}
|
|
2949
3801
|
/**
|
|
2950
3802
|
* 0.12.0 隐藏官方 assistant turn-tail 上的 branch 按钮。
|
|
@@ -2974,16 +3826,22 @@ window.__ModuleLoader__.load({
|
|
|
2974
3826
|
}
|
|
2975
3827
|
|
|
2976
3828
|
// 触发:hover / 滚动 / DOM 变化 / 变更事件
|
|
2977
|
-
document.addEventListener(
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
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
|
+
)
|
|
2987
3845
|
window.addEventListener('scroll', scan, { passive: true })
|
|
2988
3846
|
try {
|
|
2989
3847
|
// 0.9.7(P1-2)回调过滤 + maxWait。
|
|
@@ -3011,36 +3869,56 @@ window.__ModuleLoader__.load({
|
|
|
3011
3869
|
return
|
|
3012
3870
|
}
|
|
3013
3871
|
clearTimeout(scan._t)
|
|
3014
|
-
scan._t = setTimeout(() => {
|
|
3872
|
+
scan._t = setTimeout(() => {
|
|
3873
|
+
scan._t = null
|
|
3874
|
+
scanPendingSince = 0
|
|
3875
|
+
scan()
|
|
3876
|
+
}, 200)
|
|
3015
3877
|
}
|
|
3016
|
-
var mo = new MutationObserver(
|
|
3878
|
+
var mo = new MutationObserver(records => {
|
|
3017
3879
|
try {
|
|
3018
3880
|
for (var i = 0; i < records.length; i++) {
|
|
3019
3881
|
var rec = records[i]
|
|
3020
3882
|
if (rec.type === 'attributes') {
|
|
3021
3883
|
var tgt = rec.target
|
|
3022
|
-
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
|
+
}
|
|
3023
3888
|
continue
|
|
3024
3889
|
}
|
|
3025
3890
|
var added = rec.addedNodes
|
|
3026
3891
|
for (var j = 0; j < added.length; j++) {
|
|
3027
3892
|
var n = added[j]
|
|
3028
3893
|
if (!n || n.nodeType !== 1) continue
|
|
3029
|
-
if (
|
|
3030
|
-
|
|
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
|
+
}
|
|
3031
3901
|
}
|
|
3032
3902
|
}
|
|
3033
|
-
} catch {
|
|
3903
|
+
} catch {
|
|
3904
|
+
scheduleScan()
|
|
3905
|
+
}
|
|
3034
3906
|
})
|
|
3035
3907
|
mo.observe(document.body, {
|
|
3036
|
-
childList: true,
|
|
3037
|
-
|
|
3908
|
+
childList: true,
|
|
3909
|
+
subtree: true,
|
|
3910
|
+
attributes: true,
|
|
3911
|
+
attributeFilter: ['data-chat-node-key'],
|
|
3038
3912
|
})
|
|
3039
|
-
} catch {
|
|
3913
|
+
} catch {
|
|
3914
|
+
/* noop */
|
|
3915
|
+
}
|
|
3040
3916
|
window.addEventListener(CHANGED_EVENT, () => {
|
|
3041
3917
|
try {
|
|
3042
|
-
document.querySelectorAll('[data-mops-seq]').forEach(
|
|
3043
|
-
} catch {
|
|
3918
|
+
document.querySelectorAll('[data-mops-seq]').forEach(b => b.removeAttribute('data-mops-seq'))
|
|
3919
|
+
} catch {
|
|
3920
|
+
/* noop */
|
|
3921
|
+
}
|
|
3044
3922
|
})
|
|
3045
3923
|
// 样式:与官方 action 按钮同款(28px、ghost),可见性继承宿主动作行
|
|
3046
3924
|
try {
|
|
@@ -3058,7 +3936,9 @@ window.__ModuleLoader__.load({
|
|
|
3058
3936
|
].join('')
|
|
3059
3937
|
document.head.appendChild(tag)
|
|
3060
3938
|
}
|
|
3061
|
-
} catch {
|
|
3939
|
+
} catch {
|
|
3940
|
+
/* style 注入失败不影响功能 */
|
|
3941
|
+
}
|
|
3062
3942
|
}
|
|
3063
3943
|
|
|
3064
3944
|
function ensureSidebarOpsItem() {
|
|
@@ -3072,18 +3952,29 @@ window.__ModuleLoader__.load({
|
|
|
3072
3952
|
item.setAttribute('role', 'menuitem')
|
|
3073
3953
|
item.setAttribute('data-dsh-message-ops', '1')
|
|
3074
3954
|
item.style.cssText = [
|
|
3075
|
-
'display:flex',
|
|
3076
|
-
'
|
|
3955
|
+
'display:flex',
|
|
3956
|
+
'align-items:center',
|
|
3957
|
+
'gap:8px',
|
|
3958
|
+
'width:100%',
|
|
3959
|
+
'padding:6px 12px',
|
|
3960
|
+
'border:none',
|
|
3961
|
+
'background:transparent',
|
|
3077
3962
|
'color:var(--dsw-alias-label-primary,inherit)',
|
|
3078
|
-
'font:inherit',
|
|
3079
|
-
'
|
|
3963
|
+
'font:inherit',
|
|
3964
|
+
'font-size:13px',
|
|
3965
|
+
'line-height:20px',
|
|
3966
|
+
'text-align:left',
|
|
3967
|
+
'border-radius:6px',
|
|
3968
|
+
'cursor:pointer',
|
|
3080
3969
|
].join(';')
|
|
3081
3970
|
item.innerHTML = branchIconMarkup(16) + '<span></span>'
|
|
3082
3971
|
item.querySelector('span').textContent = __t('menu.ops')
|
|
3083
3972
|
item.addEventListener('mouseenter', function () {
|
|
3084
3973
|
item.style.background = 'var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.14))'
|
|
3085
3974
|
})
|
|
3086
|
-
item.addEventListener('mouseleave', function () {
|
|
3975
|
+
item.addEventListener('mouseleave', function () {
|
|
3976
|
+
item.style.background = 'transparent'
|
|
3977
|
+
})
|
|
3087
3978
|
item.addEventListener('click', function () {
|
|
3088
3979
|
var titleEl = row.querySelector('[class*=title]')
|
|
3089
3980
|
var title = titleEl ? String(titleEl.innerText || '').trim() : ''
|
|
@@ -3111,7 +4002,11 @@ window.__ModuleLoader__.load({
|
|
|
3111
4002
|
function installSidebarOps() {
|
|
3112
4003
|
if (window.__dshMessageOpsSidebarInstalled) return
|
|
3113
4004
|
window.__dshMessageOpsSidebarInstalled = true
|
|
3114
|
-
try {
|
|
4005
|
+
try {
|
|
4006
|
+
ensureSidebarOpsItem()
|
|
4007
|
+
} catch (e) {
|
|
4008
|
+
/* never crash the UI */
|
|
4009
|
+
}
|
|
3115
4010
|
// 观察范围收窄(评审 M2):仍需 observe document.body(会话行菜单由宿主
|
|
3116
4011
|
// React 动态渲染在侧栏任意挂载点,安装期无法锚定稳定容器),但回调改为
|
|
3117
4012
|
// 精确过滤——只有新增节点本身就是(或包含)[role=menu] 时才调度探测,
|
|
@@ -3123,7 +4018,11 @@ window.__ModuleLoader__.load({
|
|
|
3123
4018
|
pending = true
|
|
3124
4019
|
setTimeout(function () {
|
|
3125
4020
|
pending = false
|
|
3126
|
-
try {
|
|
4021
|
+
try {
|
|
4022
|
+
ensureSidebarOpsItem()
|
|
4023
|
+
} catch (e) {
|
|
4024
|
+
/* never crash the UI */
|
|
4025
|
+
}
|
|
3127
4026
|
}, 0)
|
|
3128
4027
|
}
|
|
3129
4028
|
var observer = new MutationObserver(function (mutations) {
|
|
@@ -3134,10 +4033,16 @@ window.__ModuleLoader__.load({
|
|
|
3134
4033
|
if (n.nodeType !== 1) continue
|
|
3135
4034
|
var isMenu = false
|
|
3136
4035
|
try {
|
|
3137
|
-
isMenu =
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
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
|
+
}
|
|
3141
4046
|
}
|
|
3142
4047
|
}
|
|
3143
4048
|
})
|
|
@@ -3153,10 +4058,11 @@ window.__ModuleLoader__.load({
|
|
|
3153
4058
|
if (typeof locale.register === 'function') {
|
|
3154
4059
|
ctx.effect(() => locale.register(NS, { zh: zhDict, en: enDict }))
|
|
3155
4060
|
}
|
|
3156
|
-
} catch {
|
|
4061
|
+
} catch {
|
|
4062
|
+
/* namespace already registered: keep existing copy */
|
|
4063
|
+
}
|
|
3157
4064
|
}
|
|
3158
4065
|
|
|
3159
|
-
|
|
3160
4066
|
// ═══ 0.9.3 /undo —— opencode 招牌交互 ═════════════════════════════════════
|
|
3161
4067
|
//
|
|
3162
4068
|
// 「我说的那句话不对」→ 一个命令 → 消息从 transcript 消失 + 原文回输入框。
|
|
@@ -3197,7 +4103,7 @@ window.__ModuleLoader__.load({
|
|
|
3197
4103
|
|
|
3198
4104
|
/** 执行 undo/redo。返回 true 表示确实动过盘。 */
|
|
3199
4105
|
/** __currentSessionId 来自 DOM dataset,可能带 `session-` 前缀;API 只要裸 uuid。 */
|
|
3200
|
-
var bareSessionId =
|
|
4106
|
+
var bareSessionId = id => String(id || '').replace(/^session-/, '')
|
|
3201
4107
|
/** 写盘成功后的统一收尾:通知、刷新、重放隐藏。 */
|
|
3202
4108
|
/**
|
|
3203
4109
|
* 写盘成功后的统一收尾。
|
|
@@ -3220,7 +4126,10 @@ window.__ModuleLoader__.load({
|
|
|
3220
4126
|
if (window.__MOPS_DEBUG) console.warn('[message-ops] openSession failed:', e)
|
|
3221
4127
|
}
|
|
3222
4128
|
const bare = bareSessionId(rawSid)
|
|
3223
|
-
for (const delay of [150, 700, 1600])
|
|
4129
|
+
for (const delay of [150, 700, 1600])
|
|
4130
|
+
setTimeout(() => {
|
|
4131
|
+
if (__refreshSurface) __refreshSurface(bare)
|
|
4132
|
+
}, delay)
|
|
3224
4133
|
}
|
|
3225
4134
|
|
|
3226
4135
|
/**
|
|
@@ -3248,13 +4157,17 @@ window.__ModuleLoader__.load({
|
|
|
3248
4157
|
if (!cache || !Array.isArray(cache.rows)) return false
|
|
3249
4158
|
const want = bareSessionId(rawSid)
|
|
3250
4159
|
if (bareSessionId(cache.sid) !== want) return false
|
|
3251
|
-
const rows = cache.rows.filter(
|
|
4160
|
+
const rows = cache.rows.filter(r => r && typeof r.seq === 'number' && r.seq <= boundarySeq && r.fullText)
|
|
3252
4161
|
if (!rows.length) return false
|
|
3253
4162
|
if (!__inputActions || typeof __inputActions.setDraft !== 'function') return false
|
|
3254
4163
|
__inputActions.setDraft(rows[rows.length - 1].fullText)
|
|
3255
4164
|
// 关键:不落盘的话,紧随其后的 openSession 会从 localStorage 读回旧草稿。
|
|
3256
4165
|
if (typeof __inputActions.persistDraft === 'function') {
|
|
3257
|
-
try {
|
|
4166
|
+
try {
|
|
4167
|
+
__inputActions.persistDraft()
|
|
4168
|
+
} catch (e) {
|
|
4169
|
+
console.warn('[message-ops] persistDraft failed:', e)
|
|
4170
|
+
}
|
|
3258
4171
|
}
|
|
3259
4172
|
return true
|
|
3260
4173
|
} catch (e) {
|
|
@@ -3272,16 +4185,23 @@ window.__ModuleLoader__.load({
|
|
|
3272
4185
|
var runUndo = () => {
|
|
3273
4186
|
const rawSid = __currentSessionId
|
|
3274
4187
|
const sid = bareSessionId(rawSid)
|
|
3275
|
-
if (!sid) {
|
|
4188
|
+
if (!sid) {
|
|
4189
|
+
notifyDone(__t('undo.none') || '没有可回滚的消息', 'error')
|
|
4190
|
+
return false
|
|
4191
|
+
}
|
|
3276
4192
|
const target = lastRevertable()
|
|
3277
|
-
if (!target) {
|
|
4193
|
+
if (!target) {
|
|
4194
|
+
notifyDone(__t('undo.none') || '没有可回滚的消息', 'error')
|
|
4195
|
+
return false
|
|
4196
|
+
}
|
|
3278
4197
|
fetch('/api/message-ops/revert', {
|
|
3279
|
-
method: 'POST',
|
|
4198
|
+
method: 'POST',
|
|
4199
|
+
headers: { 'content-type': 'application/json' },
|
|
3280
4200
|
body: JSON.stringify({ sessionId: sid, seq: target.seq }),
|
|
3281
4201
|
})
|
|
3282
|
-
.then(async
|
|
4202
|
+
.then(async res => {
|
|
3283
4203
|
const data = await res.json().catch(() => ({}))
|
|
3284
|
-
if (!res.ok || !data.ok) throw new Error(data.error ||
|
|
4204
|
+
if (!res.ok || !data.ok) throw new Error(data.error || 'HTTP ' + res.status)
|
|
3285
4205
|
// 0.11.3:立刻把本行标成已遮蔽,否则 afterWrite 的异步刷新窗里
|
|
3286
4206
|
// 再点一次 /undo 仍会选中同一个 seq → 409。
|
|
3287
4207
|
const rowsCache = __peekRowsCache ? __peekRowsCache() : null
|
|
@@ -3291,10 +4211,10 @@ window.__ModuleLoader__.load({
|
|
|
3291
4211
|
}
|
|
3292
4212
|
rowsCache.at = 0
|
|
3293
4213
|
}
|
|
3294
|
-
refillComposer(rawSid, target.seq)
|
|
4214
|
+
refillComposer(rawSid, target.seq) // 先回填,再重建视图(与对话框一致)
|
|
3295
4215
|
afterWrite(rawSid, __t('undo.done.undo'))
|
|
3296
4216
|
})
|
|
3297
|
-
.catch(
|
|
4217
|
+
.catch(reason => notifyDone(__t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error'))
|
|
3298
4218
|
return true
|
|
3299
4219
|
}
|
|
3300
4220
|
|
|
@@ -3310,27 +4230,31 @@ window.__ModuleLoader__.load({
|
|
|
3310
4230
|
const sid = bareSessionId(rawSid)
|
|
3311
4231
|
if (!sid) return false
|
|
3312
4232
|
fetchMessagesJson('/api/message-ops/messages?sessionId=' + encodeURIComponent(sid))
|
|
3313
|
-
.then(
|
|
4233
|
+
.then(d => {
|
|
3314
4234
|
if (!d || !d.ok) throw new Error((d && d.error) || 'messages unavailable')
|
|
3315
4235
|
const markers = activeMarkers(d.messages || [])
|
|
3316
|
-
if (!markers.length) {
|
|
3317
|
-
|
|
4236
|
+
if (!markers.length) {
|
|
4237
|
+
notifyDone(__t('undo.none.redo') || '没有可恢复的回滚', 'error')
|
|
4238
|
+
return null
|
|
4239
|
+
}
|
|
4240
|
+
const mk = markers[markers.length - 1] // 最新一条未恢复标记
|
|
3318
4241
|
return fetch('/api/message-ops/restore', {
|
|
3319
|
-
method: 'POST',
|
|
4242
|
+
method: 'POST',
|
|
4243
|
+
headers: { 'content-type': 'application/json' },
|
|
3320
4244
|
body: JSON.stringify({ sessionId: sid, seq: mk.seq }),
|
|
3321
|
-
}).then(async
|
|
4245
|
+
}).then(async res => {
|
|
3322
4246
|
const data = await res.json().catch(() => ({}))
|
|
3323
|
-
if (!res.ok || !data.ok) throw new Error(data.error ||
|
|
4247
|
+
if (!res.ok || !data.ok) throw new Error(data.error || 'HTTP ' + res.status)
|
|
3324
4248
|
// afterWrite 契约:rawSid 必须带 session- 前缀(传裸 uuid 会抛
|
|
3325
4249
|
// `sessions.retain: unknown session` 并被外层 catch 静默吞掉)
|
|
3326
4250
|
afterWrite(rawSid, __t('undo.done.redo'))
|
|
3327
4251
|
})
|
|
3328
4252
|
})
|
|
3329
|
-
.catch(
|
|
4253
|
+
.catch(reason => notifyDone(__t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error'))
|
|
3330
4254
|
return true
|
|
3331
4255
|
}
|
|
3332
4256
|
|
|
3333
|
-
var runUndoRedo =
|
|
4257
|
+
var runUndoRedo = kind => (kind === 'redo' ? runRedo() : runUndo())
|
|
3334
4258
|
|
|
3335
4259
|
/** 注册 /undo /redo 到官方斜杠管线。服务缺失时安静 no-op。 */
|
|
3336
4260
|
var __undoRegistered = false
|
|
@@ -3338,107 +4262,153 @@ window.__ModuleLoader__.load({
|
|
|
3338
4262
|
if (__undoRegistered || !it || typeof it.registerSource !== 'function') return
|
|
3339
4263
|
__undoRegistered = true
|
|
3340
4264
|
try {
|
|
3341
|
-
ctx.effect(() =>
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
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 => ({
|
|
3354
4279
|
name: c.name,
|
|
3355
4280
|
icon: c.icon,
|
|
3356
|
-
label: c.name === 'undo'
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
: (__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') || '把回滚掉的消息重新放回对话',
|
|
3362
4286
|
value: c.value,
|
|
3363
4287
|
}))
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
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
|
+
)
|
|
3379
4306
|
} catch (e) {
|
|
3380
4307
|
__undoRegistered = false
|
|
3381
4308
|
if (window.__MOPS_DEBUG) console.warn('[message-ops] /undo 注册失败:', e)
|
|
3382
4309
|
}
|
|
3383
4310
|
}
|
|
3384
4311
|
|
|
3385
|
-
var registerUndoSlash =
|
|
4312
|
+
var registerUndoSlash = ctx => {
|
|
3386
4313
|
// ⚠️ cordis 的 inject 回调**第一个参数是服务本身**,不是 ctx。
|
|
3387
4314
|
// 早先写成 `registerUndoSlash(sub.ctx || sub)` → 在服务对象上找 .get
|
|
3388
4315
|
// 必然是 undefined → 静默不注册(表现为 /undo 根本不出现)。
|
|
3389
4316
|
const it = typeof ctx.get === 'function' ? ctx.get('inputTriggers') : null
|
|
3390
|
-
if (it) {
|
|
4317
|
+
if (it) {
|
|
4318
|
+
doRegisterUndoSlash(ctx, it)
|
|
4319
|
+
return
|
|
4320
|
+
}
|
|
3391
4321
|
try {
|
|
3392
4322
|
// ⚠️ cordis inject 回调收到的是**注入命名空间**,服务在其同名字段下
|
|
3393
4323
|
// (与本文件 `ctx.inject(['uiWorkspace'], sub => sub.uiWorkspace || sub)` 同模式)。
|
|
3394
4324
|
// 直接把 sub 当服务用会抛 `cannot get property "registerSource" without inject`。
|
|
3395
|
-
ctx.inject(['inputTriggers'],
|
|
4325
|
+
ctx.inject(['inputTriggers'], sub => {
|
|
3396
4326
|
doRegisterUndoSlash(ctx, sub && (sub.inputTriggers || sub))
|
|
3397
4327
|
})
|
|
3398
|
-
} catch (e) {
|
|
3399
|
-
}
|
|
4328
|
+
} catch (e) {}
|
|
3400
4329
|
}
|
|
3401
4330
|
|
|
3402
4331
|
function apply(ctx) {
|
|
3403
4332
|
__sessionsSvc = ctx.get('sessions')
|
|
3404
4333
|
__uiWorkspace = typeof ctx.get === 'function' ? ctx.get('uiWorkspace') : null
|
|
3405
4334
|
if (!__uiWorkspace) {
|
|
3406
|
-
try {
|
|
4335
|
+
try {
|
|
4336
|
+
ctx.inject(['uiWorkspace'], sub => {
|
|
4337
|
+
__uiWorkspace = sub.uiWorkspace || sub
|
|
4338
|
+
})
|
|
4339
|
+
} catch {
|
|
4340
|
+
/* 0.1.x 无此服务 */
|
|
4341
|
+
}
|
|
3407
4342
|
}
|
|
3408
4343
|
if (!__sessionsSvc) {
|
|
3409
|
-
ctx.inject(['sessions'],
|
|
4344
|
+
ctx.inject(['sessions'], sub => {
|
|
4345
|
+
__sessionsSvc = sub.sessions
|
|
4346
|
+
})
|
|
3410
4347
|
}
|
|
3411
4348
|
registerUndoSlash(ctx)
|
|
3412
4349
|
adoptLocale(ctx.get('locale'), ctx)
|
|
3413
4350
|
if (!__locale) {
|
|
3414
|
-
ctx.inject(['locale'],
|
|
4351
|
+
ctx.inject(['locale'], sub => {
|
|
3415
4352
|
adoptLocale(sub.locale, ctx)
|
|
3416
4353
|
refreshSidebarOpsLabel()
|
|
3417
4354
|
})
|
|
3418
4355
|
}
|
|
3419
4356
|
ctx.on('locale/change', refreshSidebarOpsLabel)
|
|
3420
|
-
if (window.__MOPS_DISABLE_HEADER !== true)
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
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
|
+
)
|
|
3424
4369
|
// 0.3.0:每条 AI 消息旁的原生回撤按钮(0.1.x 无此槽,inject 自动 no-op)
|
|
3425
|
-
ctx.slots.inject(CHAT_ACTIONS_SLOT, () =>
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
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
|
+
)
|
|
3429
4381
|
// 0.4.0:composer 上方回撤 dock(0.1.x 无此槽自动 no-op)
|
|
3430
|
-
ctx.slots.inject(INPUT_DOCK_SLOT, () =>
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
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
|
+
)
|
|
3438
4404
|
installSidebarOps()
|
|
3439
4405
|
installUserRevertInjector()
|
|
3440
4406
|
}
|
|
3441
4407
|
|
|
3442
|
-
return {
|
|
4408
|
+
return {
|
|
4409
|
+
apply,
|
|
4410
|
+
inject: ['slots'],
|
|
4411
|
+
__test: { activityTransition, forkBoundaryBefore, isHostBranchButton, writeSessionDraft, HOST_BRANCH_D_PREFIX },
|
|
4412
|
+
}
|
|
3443
4413
|
},
|
|
3444
4414
|
})
|