@240xu/dsh-message-ops 0.16.0 → 0.18.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 +127 -0
- package/package.json +1 -1
- package/src/client.js +251 -56
package/README.md
CHANGED
|
@@ -891,6 +891,133 @@ min fence=10 → seq>=10 全藏 → 4792/4793 全被隐藏 → 正文几乎空
|
|
|
891
891
|
| `src/index.js:336-340` `revertFences` 塌缩复盘 | 「0.9.4 · 修「正文几乎空白」」 |
|
|
892
892
|
| `src/ops-core.js:551-557` 0.5.7 磁盘路径复盘 | 「0.5.7 · 第四层根因:store-miss 会话的磁盘追加路径」 |
|
|
893
893
|
|
|
894
|
+
### 0.18.0 · 行内操作三项修复 + 面板唤起 UI
|
|
895
|
+
|
|
896
|
+
用户反馈(原话):
|
|
897
|
+
|
|
898
|
+
> 「编辑重发的按钮可以和回撤放在同一个地方,就是用一个笔的那个图标」
|
|
899
|
+
> 「引用AI的话…我怎么还得点一下这个类似于复制的按钮,然后这个会话直接跳进输入框,
|
|
900
|
+
> 这UI做的怎么这么诡异?而且这样真的行吗?查点权威资料和官方代码」
|
|
901
|
+
> 「还有就是那个时间的图标,怎么点那个也是回撤啊?」
|
|
902
|
+
> 「消息操作的那个面板的,唤起它的UI显示明显有问题」
|
|
903
|
+
|
|
904
|
+
#### 1 · 行内编辑按钮(铅笔图标)
|
|
905
|
+
|
|
906
|
+
新增 `ensureEditBtn`,与回滚**同一动作行**,顺序 `回滚 → 编辑 → 分叉`
|
|
907
|
+
(破坏性从左到右递减)。图标用官方 `edit-outline` 几何。
|
|
908
|
+
|
|
909
|
+
回填**复用 `refillComposer`** —— 0.17.0 刚清理掉「同语义两套实现」,
|
|
910
|
+
这里绝不能另起一条。
|
|
911
|
+
|
|
912
|
+
#### 2 · 引用改用官方 `insertQuote`
|
|
913
|
+
|
|
914
|
+
**旧实现是错的**(用户直觉对:「这样真的行吗」)。查宿主源码:
|
|
915
|
+
|
|
916
|
+
```js
|
|
917
|
+
// dsh-client-ui-conversation:15369
|
|
918
|
+
insertQuote: (text) => this.insertQuote(text)
|
|
919
|
+
// → draftEditor.insertQuote(text, labels)
|
|
920
|
+
// → $replaceDetectSpanWithNodes({start, end}, [$createQuoteNode(text, labels), Go(" ")])
|
|
921
|
+
```
|
|
922
|
+
|
|
923
|
+
官方插入的是**结构化 QuoteNode**(带删除标签、独立 undo 编辑、自动补空格分隔)。
|
|
924
|
+
|
|
925
|
+
而 0.5.0 的旧实现是:
|
|
926
|
+
|
|
927
|
+
```js
|
|
928
|
+
text.split('\n').map(l => '> ' + l).join('\n') + '\n\n' // ← 手工拼 markdown
|
|
929
|
+
inputActions.insertText(quoted, span) // ← 裸插文本
|
|
930
|
+
```
|
|
931
|
+
|
|
932
|
+
三个问题:
|
|
933
|
+
1. **不是引用** —— 宿主不会渲染成引用块,也没有删除按钮
|
|
934
|
+
2. `captureInsertion()` 返回的是**插入位置快照**,用户在菜单里点完到文本到达之间
|
|
935
|
+
若改过草稿,位置就失效 → 文本插到奇怪的地方
|
|
936
|
+
3. 手工拼的 `> ` 会和已有内容粘连
|
|
937
|
+
|
|
938
|
+
已改为直接调 `inputActions.insertQuote(text)`。
|
|
939
|
+
|
|
940
|
+
#### 3 · 时间文本与回滚按钮的误触
|
|
941
|
+
|
|
942
|
+
用户说「点那个时间图标也是回撤」。核实后**不是绑定错误**
|
|
943
|
+
(插件代码里没有任何 `data-clock` / `timeStart` 的事件绑定),
|
|
944
|
+
而是**视觉与命中区相邻**:
|
|
945
|
+
|
|
946
|
+
```
|
|
947
|
+
宿主 DOM: div.actions[data-clock="start"] > span.timeStart + button(copy) + extraActions
|
|
948
|
+
↑ 时间文本 padding-right:12px ↑ 8px gap
|
|
949
|
+
我们: appendChild → [回滚][编辑][分叉] 紧跟在复制按钮后面
|
|
950
|
+
```
|
|
951
|
+
|
|
952
|
+
触屏上 28px 按钮的命中区紧贴时间文本,点时间很容易滑到回滚上。
|
|
953
|
+
|
|
954
|
+
修法:给插件按钮组加**视觉分隔**(首按钮左侧 10px 间距 + 1px 竖线),
|
|
955
|
+
把「消息元信息(时间/复制)」与「破坏性操作」在视觉和命中上分成两组。
|
|
956
|
+
|
|
957
|
+
#### 4 · 面板唤起 UI
|
|
958
|
+
|
|
959
|
+
**唤起按钮用的是分叉图标** —— 一个「消息操作」面板长着「分叉」的脸,
|
|
960
|
+
用户会以为点它是 fork。这就是「唤起它的 UI 显示明显有问题」。
|
|
961
|
+
|
|
962
|
+
改为官方 `list-pen-outline`(列表 + 笔)—— 同时表达「浏览消息列表」与「编辑」,
|
|
963
|
+
正是这个面板的用途(用户确认它可以当作「编辑 + AI 对话上下文面板」)。
|
|
964
|
+
|
|
965
|
+
圆角从写死的 `6` 改为 `4`,与行内按钮统一。
|
|
966
|
+
|
|
967
|
+
#### 主题自适应审计
|
|
968
|
+
|
|
969
|
+
逐行检查面板 CSS:**没有裸 hex**,所有颜色都是
|
|
970
|
+
`var(--dsw-alias-*, <浅色 fallback>)` 形式 → 深色模式自动跟随宿主 token。
|
|
971
|
+
新增测试锁定这条(防止以后有人图省事写死颜色)。
|
|
972
|
+
|
|
973
|
+
新增 `test/row-actions-v2.test.js`(11 条)。测试 309(305 pass / 4 skip)。
|
|
974
|
+
|
|
975
|
+
### 0.17.0 · 动作入口冲突清理
|
|
976
|
+
|
|
977
|
+
用户问:「那个编辑并重发是你的吗?你看看有多少是功能冲突的」
|
|
978
|
+
|
|
979
|
+
**是插件自造的**(`git log -S "panel.editDone"` 只有 `d699ddb` 一次提交),
|
|
980
|
+
opencode 没有消息级编辑。查下来三个真冲突,全部已修:
|
|
981
|
+
|
|
982
|
+
#### C1 · 回填有两条实现,可靠性不同
|
|
983
|
+
|
|
984
|
+
| 路径 | 旧实现 | 问题 |
|
|
985
|
+
|---|---|---|
|
|
986
|
+
| `refillComposer`(回滚) | `writeSessionDraft`(0.14.0 起) | 不依赖编辑器,可靠 |
|
|
987
|
+
| `startEdit`(面板编辑) | `__inputActions.setDraft` + `persistDraft`,且 `!__inputActions` **直接失败** | 依赖 `bindDraftPersistence` 绑定的 writer,视图未挂载时空转 |
|
|
988
|
+
|
|
989
|
+
同一语义两条实现、两种可靠性 → **合并**为同一条路径:
|
|
990
|
+
先 `writeSessionDraft` 落盘(权威值)→ 尽力 `setDraft`(立刻可见)→ 回读校验。
|
|
991
|
+
|
|
992
|
+
#### R2 · 「编辑并重发」文案误导
|
|
993
|
+
|
|
994
|
+
`startEdit` **完全不调服务端**(函数体内无 fetch)。它只把原文放回输入框,
|
|
995
|
+
**不遮蔽原消息**。用户改完发出后:
|
|
996
|
+
|
|
997
|
+
- 日志 **append 一条新 user/message**
|
|
998
|
+
- 原消息 **仍然 visible**,不被遮蔽
|
|
999
|
+
- 界面上出现**两条相似消息**,用户以为「改了」,实际「加了一条」
|
|
1000
|
+
|
|
1001
|
+
而旧文案 `编辑并重发` / `Edit and resend` 暗示的是「修改原消息」。
|
|
1002
|
+
改为 **`复制到输入框`** / `Copy to composer`,提示补上
|
|
1003
|
+
「发出后会新增一条消息,不会修改原消息」。
|
|
1004
|
+
|
|
1005
|
+
#### C2 · 防 409 护栏只有一条路径有
|
|
1006
|
+
|
|
1007
|
+
`/undo`(`runUndo`)在回滚成功后立刻把 `rowsCache` 里 `>= seq` 的行标成
|
|
1008
|
+
`shadowed = true`,注释写明是为了防止刷新窗口内重复点击拿到已遮蔽的 seq。
|
|
1009
|
+
**按钮路径 `runUserRevert` 漏了这段** —— 同一语义两套实现,其中一套少了护栏。
|
|
1010
|
+
|
|
1011
|
+
抽成共享函数 `markRowsShadowedFrom(boundarySeq)`,两条路径都调。
|
|
1012
|
+
|
|
1013
|
+
#### 没动的重复入口(故意的)
|
|
1014
|
+
|
|
1015
|
+
`/undo` vs 按钮、`/redo` vs dock 恢复、`message_ops` tool vs UI——
|
|
1016
|
+
这些是不同上下文/不同调用方,共用 `ops-core.js` 同一个核,不算冲突。
|
|
1017
|
+
详见 `design-demos/conflict-audit-lead.md`。
|
|
1018
|
+
|
|
1019
|
+
新增 `test/action-conflict.test.js`(6 条)。测试 298(294 pass / 4 skip)。
|
|
1020
|
+
|
|
894
1021
|
### 0.16.0 · 视觉对齐 opencode(有依据、有取舍)
|
|
895
1022
|
|
|
896
1023
|
**方法**:不是照着印象改,而是拉了 `sst/opencode` 源码
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -133,6 +133,10 @@ window.__ModuleLoader__.load({
|
|
|
133
133
|
'op.branchDesc': '把此条之前的对话复制到新会话,并把此条原文放回新会话输入框(原会话不变,非破坏操作)。',
|
|
134
134
|
'slot.revert': '回滚到此条',
|
|
135
135
|
'slot.revertUnmatched': '在日志里定位不到这条消息的 seq(通常是模型写的摘要与渲染文本偏差过大)——请改用「消息操作」对话框。',
|
|
136
|
+
'slot.edit': '编辑(复制原文到输入框)',
|
|
137
|
+
'slot.editHint': '复制此条原文到输入框;发出后新增一条消息,不修改原消息',
|
|
138
|
+
'slot.editDone': '原文已复制到输入框',
|
|
139
|
+
'slot.editNoText': '这条消息没有可复制的文本',
|
|
136
140
|
'slot.fork': '从此条分叉',
|
|
137
141
|
'slot.forkHint': '复制此条之前的对话到新会话,并把此条原文放回新会话输入框',
|
|
138
142
|
'slot.forkDone': '已分叉:新会话 {id}',
|
|
@@ -207,9 +211,12 @@ window.__ModuleLoader__.load({
|
|
|
207
211
|
'panel.branchHint': '复制此条之前的对话到新会话,并把此条原文放回新会话输入框',
|
|
208
212
|
'panel.branchDone': '已分叉:新会话 {id}',
|
|
209
213
|
'panel.branchUserOnly': '分叉只对用户消息可用(AI 消息没有可回填的原文)',
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
214
|
+
// 0.17.0(冲突 R2):行为是「复制原文到输入框」,不修改原消息。
|
|
215
|
+
// 旧文案「编辑并重发」暗示会改原消息,实测会误导(发出后是新增一条,
|
|
216
|
+
// 原消息仍在,界面出现两条相似消息)。opencode 也没有消息级编辑。
|
|
217
|
+
'panel.edit': '复制到输入框',
|
|
218
|
+
'panel.editHint': '把此条原文复制到输入框;发出后会新增一条消息,不会修改原消息',
|
|
219
|
+
'panel.editDone': '原文已复制到输入框',
|
|
213
220
|
'panel.editEmpty': '这条消息没有可编辑的文本',
|
|
214
221
|
'panel.editUnavailable': '编辑器不可写(会话可能正在运行或尚未挂载)',
|
|
215
222
|
'panel.editNotReady': '全文尚未就绪(列表只带 160 字摘要)——请重试或改用回滚回填',
|
|
@@ -261,6 +268,10 @@ window.__ModuleLoader__.load({
|
|
|
261
268
|
'slot.revert': 'Revert to here',
|
|
262
269
|
'slot.revertUnmatched':
|
|
263
270
|
'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.',
|
|
271
|
+
'slot.edit': 'Edit (copy text to composer)',
|
|
272
|
+
'slot.editHint': 'Copies this text into the composer; sending adds a new message without modifying the original',
|
|
273
|
+
'slot.editDone': 'Original text copied to the composer',
|
|
274
|
+
'slot.editNoText': 'This message has no text to copy',
|
|
264
275
|
'slot.fork': 'Branch from here',
|
|
265
276
|
'slot.forkHint': 'Copies the conversation above this message into a new session and puts this message back in the new composer',
|
|
266
277
|
'slot.forkDone': 'Branched: new session {id}',
|
|
@@ -337,9 +348,9 @@ window.__ModuleLoader__.load({
|
|
|
337
348
|
'panel.branchHint': 'Copy the conversation above this message into a new session and put this message back in the new composer',
|
|
338
349
|
'panel.branchDone': 'Forked: {id}',
|
|
339
350
|
'panel.branchUserOnly': 'Fork works on user messages only (assistant messages have no text to hand back)',
|
|
340
|
-
'panel.edit': '
|
|
341
|
-
'panel.editHint': '
|
|
342
|
-
'panel.editDone': 'Original text
|
|
351
|
+
'panel.edit': 'Copy to composer',
|
|
352
|
+
'panel.editHint': 'Copies this text into the composer; sending adds a new message and does not modify the original',
|
|
353
|
+
'panel.editDone': 'Original text copied to the composer',
|
|
343
354
|
'panel.editEmpty': 'This message has no editable text',
|
|
344
355
|
'panel.editUnavailable': 'Composer is not writable (session may be running or not mounted)',
|
|
345
356
|
'panel.editNotReady': 'Full text is not ready (the list only carries a 160-char snippet) — retry, or use revert to refill',
|
|
@@ -425,7 +436,7 @@ window.__ModuleLoader__.load({
|
|
|
425
436
|
height: 28,
|
|
426
437
|
padding: 0,
|
|
427
438
|
border: 'none',
|
|
428
|
-
borderRadius:
|
|
439
|
+
borderRadius: 4,
|
|
429
440
|
background: 'transparent',
|
|
430
441
|
color: 'var(--dsw-alias-label-tertiary, #8a8a8e)',
|
|
431
442
|
cursor: 'pointer',
|
|
@@ -549,6 +560,25 @@ window.__ModuleLoader__.load({
|
|
|
549
560
|
)
|
|
550
561
|
}
|
|
551
562
|
|
|
563
|
+
/**
|
|
564
|
+
* 面板唤起按钮的图标:官方 `list-pen-outline`(列表 + 笔)。
|
|
565
|
+
*
|
|
566
|
+
* 0.18.0 前的 bug:这里用的是**分叉图标**(IconBranch)—— 一个"消息操作"
|
|
567
|
+
* 面板却长着"分叉"的脸,用户会以为点它是 fork。语义错位就是用户说的
|
|
568
|
+
* 「唤起它的 UI 显示明显有问题」。
|
|
569
|
+
*
|
|
570
|
+
* 「列表 + 笔」同时表达了两件事:浏览消息列表、编辑内容 —— 正是这个面板
|
|
571
|
+
* 的用途(用户也确认它可以当作"编辑 + AI 对话上下文面板")。
|
|
572
|
+
*
|
|
573
|
+
* 几何取自宿主 icon sprite 的 `dsw-icon-list-pen-outline-regular`
|
|
574
|
+
* (16 viewBox,描边 1.2,与宿主动作行图标同一套视觉)。
|
|
575
|
+
*/
|
|
576
|
+
/**
|
|
577
|
+
* 分叉图标组件。0.18.0 起**不再用于面板唤起按钮**(那曾造成语义错位:
|
|
578
|
+
* "消息操作"面板长着"分叉"的脸),但保留它是因为 `branchIconMarkup`
|
|
579
|
+
* 与它共用 `BRANCH_PATH` 常量 —— `test/icon-render.test.js` 锁定了这条同源约束,
|
|
580
|
+
* 防止两处各画一套分叉几何而慢慢漂移。
|
|
581
|
+
*/
|
|
552
582
|
function BranchIcon() {
|
|
553
583
|
return React.createElement(
|
|
554
584
|
'svg',
|
|
@@ -572,6 +602,31 @@ window.__ModuleLoader__.load({
|
|
|
572
602
|
)
|
|
573
603
|
}
|
|
574
604
|
|
|
605
|
+
function OpsPanelIcon() {
|
|
606
|
+
return React.createElement(
|
|
607
|
+
'svg',
|
|
608
|
+
{
|
|
609
|
+
width: 16,
|
|
610
|
+
height: 16,
|
|
611
|
+
viewBox: '0 0 16 16',
|
|
612
|
+
fill: 'none',
|
|
613
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
614
|
+
'aria-hidden': 'true',
|
|
615
|
+
focusable: 'false',
|
|
616
|
+
},
|
|
617
|
+
React.createElement('path', { d: 'M4.9375 5.90295H11.0625', stroke: 'currentColor', strokeWidth: 1.2, strokeLinecap: 'round' }),
|
|
618
|
+
React.createElement('path', { d: 'M4.9375 9.02991H8.27841', stroke: 'currentColor', strokeWidth: 1.2, strokeLinecap: 'round' }),
|
|
619
|
+
React.createElement('path', {
|
|
620
|
+
d: 'M12.5 1.32617C13.3039 1.32617 14 1.95171 14 2.77637V7.61328L13 8.68164V2.77637C13 2.55186 12.8007 2.32617 12.5 2.32617H3.5C3.1993 2.32617 3 2.55186 3 2.77637V13.2246C3.00044 13.4489 3.19963 13.6738 3.5 13.6738H8.32812L7.39258 14.6738H3.5C2.69637 14.6738 2.00042 14.0489 2 13.2246V2.77637C2 1.95171 2.69613 1.32617 3.5 1.32617H12.5Z',
|
|
621
|
+
fill: 'currentColor',
|
|
622
|
+
}),
|
|
623
|
+
React.createElement('path', {
|
|
624
|
+
d: 'M8.97212 14.3693C9.17511 14.5723 9.37811 14.7753 9.5811 14.9783C9.67012 14.8953 9.75914 14.8123 9.84815 14.7293C11.4505 13.2352 13.0528 11.7411 14.6551 10.247C14.7441 10.164 14.8331 10.081 14.9221 9.99803C14.5989 9.6748 14.2756 9.35157 13.9524 9.02834C13.8694 9.11736 13.7864 9.20637 13.7034 9.29539C12.2093 10.8977 10.7152 12.5 9.22113 14.1023C9.13813 14.1913 9.05513 14.2803 8.97212 14.3693Z',
|
|
625
|
+
fill: 'currentColor',
|
|
626
|
+
}),
|
|
627
|
+
)
|
|
628
|
+
}
|
|
629
|
+
|
|
575
630
|
// --- 共享对话框 -------------------------------------------------------------
|
|
576
631
|
// 模块级缓存最近一次 target,事件驱动打开。
|
|
577
632
|
const MAX_RENDER = 200
|
|
@@ -1376,25 +1431,33 @@ window.__ModuleLoader__.load({
|
|
|
1376
1431
|
setError(t('panel.editEmpty'))
|
|
1377
1432
|
return
|
|
1378
1433
|
}
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1434
|
+
// ── 0.17.0(冲突 C1):与 refillComposer 统一成**同一条**回填路径 ──
|
|
1435
|
+
//
|
|
1436
|
+
// 旧实现走 `__inputActions.setDraft` + `persistDraft`,且
|
|
1437
|
+
// `!__inputActions` 就直接失败返回 —— 但 refillComposer(回滚路径)
|
|
1438
|
+
// 早在 0.14.0 就改成了「先写宿主草稿键、再尽力更新编辑器」,不依赖
|
|
1439
|
+
// 编辑器是否已挂载。同一件事两条实现、两种可靠性,必须合并。
|
|
1440
|
+
//
|
|
1441
|
+
// 现在统一为:① writeSessionDraft 落盘(权威值)② 尽力 setDraft
|
|
1442
|
+
// ③ 回读校验(写不进去就报错且不 close,保留 0.13.1 MED-4 的护栏)
|
|
1443
|
+
const sidForDraft = target.sessionId
|
|
1444
|
+
const persisted = writeSessionDraft(sidForDraft, body)
|
|
1445
|
+
let editorSet = false
|
|
1446
|
+
if (__inputActions && typeof __inputActions.setDraft === 'function') {
|
|
1447
|
+
try {
|
|
1448
|
+
__inputActions.setDraft(body)
|
|
1449
|
+
editorSet = true
|
|
1450
|
+
} catch (reason) {
|
|
1451
|
+
console.warn('[message-ops] setDraft failed:', reason)
|
|
1452
|
+
}
|
|
1382
1453
|
}
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
setError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
|
|
1454
|
+
// 回读校验:落盘失败才是真风险(编辑器可能没挂载,那不是错误)
|
|
1455
|
+
const stored = readSessionDraft(sidForDraft)
|
|
1456
|
+
if (stored !== body) {
|
|
1457
|
+
setError(t('panel.editUnavailable'))
|
|
1388
1458
|
return
|
|
1389
1459
|
}
|
|
1390
|
-
|
|
1391
|
-
// `bindDraftPersistence` 在视图挂载时绑定;blank/hero 态或视图未挂载时
|
|
1392
|
-
// 该函数在但空转。于是「setDraft 改的是内存编辑器、随后 close() 关面板、
|
|
1393
|
-
// 宿主重挂会话时从 localStorage 读回旧草稿」→ 用户看到成功却什么都没了。
|
|
1394
|
-
// 判据不能靠函数存在,只能**回读**:写不进存储就当失败,不 close。
|
|
1395
|
-
const sidForDraft = target.sessionId
|
|
1396
|
-
const stored = readSessionDraft(sidForDraft)
|
|
1397
|
-
if (stored != null && stored !== body) {
|
|
1460
|
+
if (!persisted && !editorSet) {
|
|
1398
1461
|
setError(t('panel.editUnavailable'))
|
|
1399
1462
|
return
|
|
1400
1463
|
}
|
|
@@ -2652,7 +2715,7 @@ window.__ModuleLoader__.load({
|
|
|
2652
2715
|
style: btnStyle,
|
|
2653
2716
|
onClick: openDialog,
|
|
2654
2717
|
},
|
|
2655
|
-
React.createElement(
|
|
2718
|
+
React.createElement(OpsPanelIcon),
|
|
2656
2719
|
)
|
|
2657
2720
|
}
|
|
2658
2721
|
|
|
@@ -2846,36 +2909,56 @@ window.__ModuleLoader__.load({
|
|
|
2846
2909
|
.finally(() => setBusy(null))
|
|
2847
2910
|
}
|
|
2848
2911
|
|
|
2849
|
-
// 0.
|
|
2912
|
+
// ── 0.18.0:引用改用官方 insertQuote(结构化 QuoteNode)──────────────────
|
|
2913
|
+
//
|
|
2914
|
+
// 旧实现(0.5.0)用 `captureInsertion` + `insertText` 手工拼 `> ` markdown:
|
|
2915
|
+
//
|
|
2916
|
+
// text.split('\n').map(l => '> ' + l).join('\n') + '\n\n'
|
|
2917
|
+
//
|
|
2918
|
+
// 问题(用户实测反馈「这 UI 做的怎么这么诡异」):
|
|
2919
|
+
// 1. **不是引用**,是一段普通 markdown 文本 —— 宿主不会渲染成引用块,
|
|
2920
|
+
// 也不会给删除按钮、不进结构化编辑语义;
|
|
2921
|
+
// 2. `captureInsertion` 返回的是**插入位置快照**,用户在菜单里点完到
|
|
2922
|
+
// 文本到达之间若改过草稿,位置就失效,文本会插到奇怪的地方;
|
|
2923
|
+
// 3. 手工拼的 `> ` 会和用户已有内容粘连(无空行分隔时)。
|
|
2924
|
+
//
|
|
2925
|
+
// 宿主其实提供了官方能力(dsh-client-ui-conversation:15369):
|
|
2926
|
+
// insertQuote: (text) => this.insertQuote(text)
|
|
2927
|
+
// 它内部走 `draftEditor.insertQuote(text, labels)` →
|
|
2928
|
+
// `$replaceDetectSpanWithNodes([$createQuoteNode(text, labels), Go(" ")])`
|
|
2929
|
+
// 即:在当前光标处插入一个**真正的 QuoteNode**(带 remove 标签、独立 undo),
|
|
2930
|
+
// 并自动补一个空格分隔。这才是"规范"的引用。
|
|
2850
2931
|
const runQuote = () => {
|
|
2932
|
+
const finish = ok => notifyDone(ok ? t('quote.done') : t('quote.unavailable'), ok ? 'ok' : 'warn')
|
|
2851
2933
|
try {
|
|
2852
|
-
if (!inputActions || typeof inputActions.
|
|
2853
|
-
|
|
2934
|
+
if (!inputActions || typeof inputActions.insertQuote !== 'function') {
|
|
2935
|
+
finish(false)
|
|
2854
2936
|
return
|
|
2855
2937
|
}
|
|
2856
|
-
const
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
notifyDone(t('quote.unavailable'), 'warn')
|
|
2938
|
+
const put = text => {
|
|
2939
|
+
if (typeof text !== 'string' || text.trim() === '') {
|
|
2940
|
+
finish(false)
|
|
2860
2941
|
return
|
|
2861
2942
|
}
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2943
|
+
// insertQuote 的返回值是 boolean(是否真的插入了)
|
|
2944
|
+
let ok = false
|
|
2945
|
+
try {
|
|
2946
|
+
ok = inputActions.insertQuote(text.replace(/\r\n?/g, '\n')) !== false
|
|
2947
|
+
} catch (e) {
|
|
2948
|
+
console.warn('[message-ops] insertQuote failed:', e)
|
|
2949
|
+
ok = false
|
|
2950
|
+
}
|
|
2951
|
+
finish(ok)
|
|
2869
2952
|
}
|
|
2870
|
-
// assistant 消息 fullText 恒 null(列表不携带)→ 按 seq
|
|
2953
|
+
// assistant 消息 fullText 恒 null(列表不携带)→ 按 seq 取单条全文
|
|
2871
2954
|
if (fullText != null && fullText !== '') {
|
|
2872
|
-
|
|
2955
|
+
put(fullText)
|
|
2873
2956
|
return
|
|
2874
2957
|
}
|
|
2875
2958
|
fetch('/api/message-ops/text?sessionId=' + encodeURIComponent(sessionId) + '&seq=' + encodeURIComponent(seq))
|
|
2876
2959
|
.then(r => (r.ok ? r.json() : null))
|
|
2877
|
-
.then(d =>
|
|
2878
|
-
.catch(() =>
|
|
2960
|
+
.then(d => put(d && d.ok && typeof d.text === 'string' ? d.text : null))
|
|
2961
|
+
.catch(() => put(null))
|
|
2879
2962
|
} catch (e) {
|
|
2880
2963
|
notifyDone(t('errorPrefix') + (e && e.message ? e.message : String(e)), 'error')
|
|
2881
2964
|
}
|
|
@@ -3606,10 +3689,16 @@ window.__ModuleLoader__.load({
|
|
|
3606
3689
|
// 配不上(data-mops-unmatched)→ 禁用 + 说明原因,绝不留装饰按钮。
|
|
3607
3690
|
var syncEnabled = (block, btn) => {
|
|
3608
3691
|
if (!btn) return
|
|
3692
|
+
// 0.18.0:三种按钮各有自己的提示文案(新增编辑按钮后不能都写 revert)
|
|
3693
|
+
const hintKey = btn.classList.contains('mopsUserFork')
|
|
3694
|
+
? 'slot.forkHint'
|
|
3695
|
+
: btn.classList.contains('mopsUserEdit')
|
|
3696
|
+
? 'slot.editHint'
|
|
3697
|
+
: 'slot.revert'
|
|
3609
3698
|
const ok = block.getAttribute('data-mops-seq')
|
|
3610
3699
|
if (ok) {
|
|
3611
3700
|
btn.disabled = false
|
|
3612
|
-
btn.title = __t(
|
|
3701
|
+
btn.title = __t(hintKey)
|
|
3613
3702
|
btn.removeAttribute('data-mops-unmatched')
|
|
3614
3703
|
} else {
|
|
3615
3704
|
btn.disabled = true
|
|
@@ -3620,7 +3709,7 @@ window.__ModuleLoader__.load({
|
|
|
3620
3709
|
/** 块内全部插件按钮一起同步(回滚 / 分叉同一动作行)。 */
|
|
3621
3710
|
var syncBlockButtons = block => {
|
|
3622
3711
|
if (!block || !block.querySelectorAll) return
|
|
3623
|
-
for (const b of block.querySelectorAll('.mopsUserRevert, .mopsUserFork')) syncEnabled(block, b)
|
|
3712
|
+
for (const b of block.querySelectorAll('.mopsUserRevert, .mopsUserEdit, .mopsUserFork')) syncEnabled(block, b)
|
|
3624
3713
|
}
|
|
3625
3714
|
var assignSeqs = (sid, cache, anchors) => {
|
|
3626
3715
|
const idx = cache && cache.idx
|
|
@@ -3721,6 +3810,9 @@ window.__ModuleLoader__.load({
|
|
|
3721
3810
|
}
|
|
3722
3811
|
if (!res.ok || !data.ok) throw new Error(data.error || 'HTTP ' + res.status)
|
|
3723
3812
|
notifyDone(__t('done.revert'))
|
|
3813
|
+
// 0.17.0(冲突 C2):按钮路径原先漏了「立刻标遮蔽」,
|
|
3814
|
+
// 导致刷新窗口内重复点击会拿已遮蔽的 seq 去 POST → 409。
|
|
3815
|
+
markRowsShadowedFrom(row.seq)
|
|
3724
3816
|
// 0.9.6:统一回填出口 —— 这个入口原先也不回填
|
|
3725
3817
|
refillComposer(sid, row.seq)
|
|
3726
3818
|
emitChanged()
|
|
@@ -3828,6 +3920,81 @@ window.__ModuleLoader__.load({
|
|
|
3828
3920
|
return btn
|
|
3829
3921
|
}
|
|
3830
3922
|
|
|
3923
|
+
/**
|
|
3924
|
+
* 0.18.0 编辑按钮:与回滚**同一动作行**,铅笔图标。
|
|
3925
|
+
*
|
|
3926
|
+
* 语义 = 把该条原文放回输入框(不遮蔽后续、不修改原消息)。发出后会新增
|
|
3927
|
+
* 一条消息 —— 与面板里的「复制到输入框」是同一件事,两条入口共用
|
|
3928
|
+
* `refillToComposer` 实现,避免又出现"同语义两套实现"。
|
|
3929
|
+
*
|
|
3930
|
+
* 图标取官方 `edit-outline`(宿主 icon sprite 里的 dsw-icon-edit-outline-regular)。
|
|
3931
|
+
*/
|
|
3932
|
+
var ensureEditBtn = block => {
|
|
3933
|
+
let host = block.querySelector('[class*="xzv4MW_actions"]')
|
|
3934
|
+
if (!host) {
|
|
3935
|
+
host = document.createElement('div')
|
|
3936
|
+
host.className = 'mopsUserActionsRow'
|
|
3937
|
+
block.appendChild(host)
|
|
3938
|
+
}
|
|
3939
|
+
const existing = host.querySelector('.mopsUserEdit')
|
|
3940
|
+
if (existing) return existing
|
|
3941
|
+
const btn = document.createElement('button')
|
|
3942
|
+
btn.type = 'button'
|
|
3943
|
+
btn.className = 'mopsUserEdit'
|
|
3944
|
+
btn.title = __t('slot.edit')
|
|
3945
|
+
btn.setAttribute('aria-label', __t('slot.edit'))
|
|
3946
|
+
// 铅笔:官方 edit-outline 的几何(16 viewBox)
|
|
3947
|
+
btn.innerHTML =
|
|
3948
|
+
'<svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="none">' +
|
|
3949
|
+
'<path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M11.9 1.4a1.6 1.6 0 0 1 2.3 0l.4.4a1.6 1.6 0 0 1 0 2.3l-1 1-2.7-2.7 1-1ZM9.8 3.5l2.7 2.7-6.9 6.9a1 1 0 0 1-.4.2l-2.6.7a.5.5 0 0 1-.6-.6l.7-2.6a1 1 0 0 1 .2-.4l6.9-6.9Z"/>' +
|
|
3950
|
+
'</svg>'
|
|
3951
|
+
btn.addEventListener('click', e => {
|
|
3952
|
+
e.preventDefault()
|
|
3953
|
+
e.stopPropagation()
|
|
3954
|
+
if (btn.disabled) return
|
|
3955
|
+
runUserEdit(btn, block)
|
|
3956
|
+
})
|
|
3957
|
+
host.appendChild(btn)
|
|
3958
|
+
syncEnabled(block, btn)
|
|
3959
|
+
return btn
|
|
3960
|
+
}
|
|
3961
|
+
|
|
3962
|
+
/**
|
|
3963
|
+
* 0.18.0 行内编辑:把该条原文放回输入框。
|
|
3964
|
+
*
|
|
3965
|
+
* 直接复用 `refillComposer`(回滚路径用的同一实现)——
|
|
3966
|
+
* 0.17.0 刚把"同语义两套实现"问题清理掉,绝不能在这里再引入一条。
|
|
3967
|
+
*/
|
|
3968
|
+
var runUserEdit = (btn, block) => {
|
|
3969
|
+
const sid = __currentSessionId
|
|
3970
|
+
if (!sid) return
|
|
3971
|
+
const seq = Number(block.getAttribute('data-mops-seq'))
|
|
3972
|
+
if (!Number.isFinite(seq)) {
|
|
3973
|
+
notifyDone(__t('errorPrefix') + __t('slot.revertUnmatched'), 'error')
|
|
3974
|
+
return
|
|
3975
|
+
}
|
|
3976
|
+
btn.disabled = true
|
|
3977
|
+
Promise.resolve()
|
|
3978
|
+
.then(() => ensureAssign(sid))
|
|
3979
|
+
.then(() => fetchRows(sid))
|
|
3980
|
+
.then(cache => {
|
|
3981
|
+
const rows = cache && cache.rows
|
|
3982
|
+
const row = rows && rows.find(r => r.seq === seq)
|
|
3983
|
+
if (!row) {
|
|
3984
|
+
notifyDone(__t('errorPrefix') + __t('slot.revertUnmatched'), 'error')
|
|
3985
|
+
return
|
|
3986
|
+
}
|
|
3987
|
+
const ok = refillComposer(sid, seq)
|
|
3988
|
+
notifyDone(ok ? __t('slot.editDone') : __t('slot.editNoText'), ok ? 'ok' : 'warn')
|
|
3989
|
+
})
|
|
3990
|
+
.catch(reason => {
|
|
3991
|
+
notifyDone(__t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error')
|
|
3992
|
+
})
|
|
3993
|
+
.finally(() => {
|
|
3994
|
+
btn.disabled = false
|
|
3995
|
+
})
|
|
3996
|
+
}
|
|
3997
|
+
|
|
3831
3998
|
/** 0.12.0 分叉按钮:与回滚按钮**同一动作行**(opencode 把 fork 放在 copy/undo 同组)。 */
|
|
3832
3999
|
var ensureForkBtn = block => {
|
|
3833
4000
|
let host = block.querySelector('[class*="xzv4MW_actions"]')
|
|
@@ -3859,6 +4026,9 @@ window.__ModuleLoader__.load({
|
|
|
3859
4026
|
// 两个按钮的顺序由 DOM 顺序决定:回滚在前(破坏性更高),分叉在后(非破坏)。
|
|
3860
4027
|
var ensureUserActions = block => {
|
|
3861
4028
|
ensureBtn(block)
|
|
4029
|
+
// 0.18.0:编辑按钮与回滚**同一动作行**(用户要求:和回撤放同一个地方)。
|
|
4030
|
+
// 顺序 = 回滚 → 编辑 → 分叉,破坏性从左到右递减。
|
|
4031
|
+
ensureEditBtn(block)
|
|
3862
4032
|
ensureForkBtn(block)
|
|
3863
4033
|
}
|
|
3864
4034
|
// 0.9.7(P0-2 读合并):把 150/700/1600ms 三档并成**一次**真网络请求,
|
|
@@ -4048,11 +4218,20 @@ window.__ModuleLoader__.load({
|
|
|
4048
4218
|
// (宿主 .xzv4MW_actions 已定 height:28px,改小会撑裂行高)。
|
|
4049
4219
|
// · 无淡入动画(opencode 源码注释明写 "Hover actions show and hide
|
|
4050
4220
|
// at once, without a fade")—— 显隐完全交给宿主 [data-actions-reveal]。
|
|
4051
|
-
'.mopsUserRevert,.mopsUserFork{display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border:none;border-radius:4px;background:transparent;color:var(--dsw-alias-label-tertiary,#808080);cursor:pointer;padding:0;flex:none}',
|
|
4052
|
-
'.mopsUserRevert svg,.mopsUserFork svg{width:14px;height:14px;display:block}',
|
|
4053
|
-
'.mopsUserRevert:hover,.mopsUserFork:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.12));color:var(--dsw-alias-label-secondary,#6b6b70)}',
|
|
4054
|
-
'.mopsUserRevert:disabled,.mopsUserFork:disabled{opacity:.4;cursor:default;background:transparent}',
|
|
4055
|
-
'.mopsUserRevert:focus-visible,.mopsUserFork:focus-visible{outline:2px solid var(--dsw-alias-border-l2,#b8b8b8);outline-offset:1px}',
|
|
4221
|
+
'.mopsUserRevert,.mopsUserEdit,.mopsUserFork{display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border:none;border-radius:4px;background:transparent;color:var(--dsw-alias-label-tertiary,#808080);cursor:pointer;padding:0;flex:none}',
|
|
4222
|
+
'.mopsUserRevert svg,.mopsUserEdit svg,.mopsUserFork svg{width:14px;height:14px;display:block}',
|
|
4223
|
+
'.mopsUserRevert:hover,.mopsUserEdit:hover,.mopsUserFork:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.12));color:var(--dsw-alias-label-secondary,#6b6b70)}',
|
|
4224
|
+
'.mopsUserRevert:disabled,.mopsUserEdit:disabled,.mopsUserFork:disabled{opacity:.4;cursor:default;background:transparent}',
|
|
4225
|
+
'.mopsUserRevert:focus-visible,.mopsUserEdit:focus-visible,.mopsUserFork:focus-visible{outline:2px solid var(--dsw-alias-border-l2,#b8b8b8);outline-offset:1px}',
|
|
4226
|
+
// 0.18.0:用户反馈「点时间图标也会回撤」——根因不是绑定错误,而是
|
|
4227
|
+
// 我们的按钮被 appendChild 到宿主 .actions 行末尾,而该行在
|
|
4228
|
+
// data-clock="start"(用户消息)时第一个子元素就是**时间文本**:
|
|
4229
|
+
// [时间文本 padding-right:12px] 8px [复制] 8px [回滚][编辑][分叉]
|
|
4230
|
+
// 触屏上 28px 按钮的命中区紧贴时间文本,点时间很容易滑到回滚上。
|
|
4231
|
+
// 修:给插件按钮组加一道**视觉与命中分隔**(左侧细线 + 额外间距),
|
|
4232
|
+
// 让"消息元信息(时间/复制)"和"破坏性操作"在视觉上分成两组。
|
|
4233
|
+
'.mopsUserRevert:first-of-type{margin-left:10px;position:relative}',
|
|
4234
|
+
'.mopsUserRevert:first-of-type::before{content:"";position:absolute;left:-9px;top:50%;transform:translateY(-50%);width:1px;height:14px;background:var(--dsw-alias-border-l1,rgba(128,128,128,.28));pointer-events:none}',
|
|
4056
4235
|
'.mopsUserActionsRow{height:28px;display:flex;align-items:center;gap:8px;margin-left:-6px}',
|
|
4057
4236
|
'@media (hover:none){.mopsUserActionsRow{opacity:1}}',
|
|
4058
4237
|
].join('')
|
|
@@ -4273,6 +4452,28 @@ window.__ModuleLoader__.load({
|
|
|
4273
4452
|
* - AI 时钟按钮 → boundary 是 AI 消息 seq → 取到它之前那条用户消息 ✓
|
|
4274
4453
|
* 会话不匹配时直接放弃(不跨会话写,避免串台)。
|
|
4275
4454
|
*/
|
|
4455
|
+
/**
|
|
4456
|
+
* 回滚成功后立刻把本地行缓存标成已遮蔽(0.17.0 · 冲突 C2)。
|
|
4457
|
+
*
|
|
4458
|
+
* 为什么必须做:回滚成功后到视图刷新完成之间有一个窗口期,
|
|
4459
|
+
* `rowsCache.rows[*].shadowed` 还是旧值。此时用户再点同一行按钮
|
|
4460
|
+
* (或另一行更靠后的),`runUserRevert` 会拿**已被遮蔽的 seq** 去
|
|
4461
|
+
* POST /revert → 服务端 409 `start seq N not found in surface`。
|
|
4462
|
+
*
|
|
4463
|
+
* 原先只有 `/undo` 路径(`runUndo`)做了这件事,按钮路径漏了 ——
|
|
4464
|
+
* 同一语义两套实现、其中一套少了护栏。这里抽成共享函数,两条路径都调。
|
|
4465
|
+
*
|
|
4466
|
+
* @param boundarySeq - 本次回滚的目标 seq;>= 它的都已不可再回滚
|
|
4467
|
+
*/
|
|
4468
|
+
var markRowsShadowedFrom = boundarySeq => {
|
|
4469
|
+
const cache = __peekRowsCache ? __peekRowsCache() : null
|
|
4470
|
+
if (!cache || !Array.isArray(cache.rows)) return
|
|
4471
|
+
for (const r of cache.rows) {
|
|
4472
|
+
if (r && typeof r.seq === 'number' && r.seq >= boundarySeq) r.shadowed = true
|
|
4473
|
+
}
|
|
4474
|
+
cache.at = 0
|
|
4475
|
+
}
|
|
4476
|
+
|
|
4276
4477
|
var refillComposer = (rawSid, boundarySeq) => {
|
|
4277
4478
|
try {
|
|
4278
4479
|
const cache = __peekRowsCache ? __peekRowsCache() : null
|
|
@@ -4341,13 +4542,7 @@ window.__ModuleLoader__.load({
|
|
|
4341
4542
|
if (!res.ok || !data.ok) throw new Error(data.error || 'HTTP ' + res.status)
|
|
4342
4543
|
// 0.11.3:立刻把本行标成已遮蔽,否则 afterWrite 的异步刷新窗里
|
|
4343
4544
|
// 再点一次 /undo 仍会选中同一个 seq → 409。
|
|
4344
|
-
|
|
4345
|
-
if (rowsCache && Array.isArray(rowsCache.rows)) {
|
|
4346
|
-
for (const r of rowsCache.rows) {
|
|
4347
|
-
if (r && typeof r.seq === 'number' && r.seq >= target.seq) r.shadowed = true
|
|
4348
|
-
}
|
|
4349
|
-
rowsCache.at = 0
|
|
4350
|
-
}
|
|
4545
|
+
markRowsShadowedFrom(target.seq)
|
|
4351
4546
|
refillComposer(rawSid, target.seq) // 先回填,再重建视图(与对话框一致)
|
|
4352
4547
|
afterWrite(rawSid, __t('undo.done.undo'))
|
|
4353
4548
|
})
|