@240xu/dsh-message-ops 0.19.0 → 0.21.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 +88 -0
- package/package.json +1 -1
- package/src/client.js +742 -40
package/README.md
CHANGED
|
@@ -1228,3 +1228,91 @@ Ctrl/Cmd+Enter 重发。也就是说**本插件从 0.12.0 起造的编辑入口
|
|
|
1228
1228
|
折叠只由用户点击改变;恢复=重放(新 seq、不回原位)的语义与文案不变。
|
|
1229
1229
|
|
|
1230
1230
|
测试 313(309 pass / 4 skip),`prettier --check` 全绿。
|
|
1231
|
+
|
|
1232
|
+
### 0.20.0 · 铅笔编辑框回归 + 真实浏览器验证 + bug 清扫
|
|
1233
|
+
|
|
1234
|
+
本轮启用智能体团队,两条线并行:
|
|
1235
|
+
- 线 A(挖 bug / 官方行为 / 环境):mops-reviewer、dsh-ui-parity、opencode-parity、
|
|
1236
|
+
npm-relay、verify-env
|
|
1237
|
+
- 线 B(铅笔编辑框):oc-visual(设计)、conflict-audit(实现)、audit-entry(测试)
|
|
1238
|
+
|
|
1239
|
+
#### 1 · 铅笔编辑框(用户明确要求「点笔给那个框」)
|
|
1240
|
+
- `ensureEditBtn` 回归用户消息动作行,顺序 `回撤 → 铅笔 → 分叉`
|
|
1241
|
+
- 新增 `EditResendOverlay`(`shell.overlay` 槽,order 102):独立 textarea 编辑框,
|
|
1242
|
+
预填 `/api/message-ops/text` 返回的**全文**(不用 160 字 snippet)
|
|
1243
|
+
- **时序(用户要求,有意区别于 opencode)**:打开/编辑/取消全程零写操作;
|
|
1244
|
+
点「发送并回撤」那一刻才 `POST /revert` → 合并写草稿 → `openSession` → 提交一次
|
|
1245
|
+
- revert 失败保留编辑框与已输入文本;取消零副作用
|
|
1246
|
+
- 与已装 `@linxin666/dsh-client-ui-message-edit`(turnTail 槽,fork 语义)物理隔离,
|
|
1247
|
+
同一用户动作只走自己的 `/revert` 链路,不调 fork / submitEdit
|
|
1248
|
+
|
|
1249
|
+
#### 2 · bug 清扫(来自 design-demos/bug-hunt-019.md)
|
|
1250
|
+
- **H-2**:引用选区必须 anchor/focus 同属一个精确 `data-chat-node-key` 容器,
|
|
1251
|
+
跨消息选区回退到截断路径(防「选中 A 却引用成 B」)
|
|
1252
|
+
- **M-1**:引用截断改按 Unicode code point + 空白边界收尾,不切坏 emoji / markdown 围栏
|
|
1253
|
+
- **M-2**:来源标注移到 toast(`quote.doneWithSource`),不污染 QuoteNode 模型可见正文
|
|
1254
|
+
- **H-1/M-3**:面板回滚按钮限定用户消息(`canRevert`),删除按钮不受限;
|
|
1255
|
+
AI 回滚彻底下线,消除「面板能回滚 AI 却不回填」的旁路
|
|
1256
|
+
- **token**:修掉 `--dsw-alias-bg-primary` → `bg-layer-1`(前者宿主 theme 里不存在,
|
|
1257
|
+
深色模式会露馅),B-2 新编辑框 CSS 已用正确 token
|
|
1258
|
+
|
|
1259
|
+
#### 3 · 真实浏览器验证(重大突破)
|
|
1260
|
+
`verify-env` 翻案:本机 Chromium **能跑** —— `headless_shell.android`(bionic 版)
|
|
1261
|
+
+ `env -u LD_PRELOAD` + `--disable-dev-shm-usage`,CDP 9344 可用。
|
|
1262
|
+
修复了「一直只能靠 bundle 符号指纹推断」的局限。
|
|
1263
|
+
|
|
1264
|
+
实测(3099 预览实例,真实 Chromium DOM):
|
|
1265
|
+
```
|
|
1266
|
+
revert=6 edit=6 fork=6 seqTagged=6 disabled=0
|
|
1267
|
+
点铅笔 → erNodes=12 / textarea=1 / 有「发送并回撤」+「取消」
|
|
1268
|
+
textarea 预填真实全文 89 字(非 snippet)
|
|
1269
|
+
点取消 → erNodes=0 / textarea=0(零副作用)
|
|
1270
|
+
```
|
|
1271
|
+
探针:`~/.dsh/tmp-mops/ui-probe.mjs`,环境文档 `design-demos/preview-env.md`。
|
|
1272
|
+
|
|
1273
|
+
#### 4 · 回撤的数据语义(用户新问,专项核查)
|
|
1274
|
+
`design-demos/revert-data-semantics.md` 实证结论:
|
|
1275
|
+
- **AI 看不到**:宿主 `deriveMessages()` 只读 `surface.nodes`,被 replace 的 seq 不在其中
|
|
1276
|
+
- **翻会话文件拿得到**:实测 161 条被回撤消息原文逐字可读(append-only 日志,
|
|
1277
|
+
marker 只标记遮蔽,事件仍在)
|
|
1278
|
+
- **彻底删除当前做不到**:宿主无 delete/truncate/rewrite API,硬删会破坏 seq 连续性
|
|
1279
|
+
使会话 corrupt。短期方案是「诚实告知」(回撤确认框写明内容仍在本地文件),
|
|
1280
|
+
中期需宿主提供 per-seq payload 重写。此项**未改代码**,仅出报告待决断。
|
|
1281
|
+
|
|
1282
|
+
测试 348(344 pass / 4 skip),`prettier --check` 全绿。
|
|
1283
|
+
|
|
1284
|
+
### 0.21.0 · 回撤隐私预期修正 + 宿主能力需求
|
|
1285
|
+
|
|
1286
|
+
用户问:「回撤的话 AI 还看得到吗?翻会话文件拿得到吗?我希望彻底删除,
|
|
1287
|
+
但因为要恢复,至少在后续几次里能恢复」+「按 opencode 的真删时机来,看看有没有方法」。
|
|
1288
|
+
|
|
1289
|
+
**Spike 结论**(只读查证 + 一次性破坏性试验,未碰真实会话):
|
|
1290
|
+
- AI **看不到**(模型只读 `surface.nodes`);但翻 `session.v4.jsonl.zstd` **拿得到**,
|
|
1291
|
+
实测 161 条被回撤消息原文逐字可读
|
|
1292
|
+
- **物理删中间行会 corrupt**:宿主 `surface.js:425` 的 seq 连续性校验会抛
|
|
1293
|
+
`session event seq 12 is not contiguous; expected 8`(已用宿主 `foldSurface` 实测)
|
|
1294
|
+
- **照抄 opencode 的尾部 DELETE 对不上几何**:opencode 删的是「边界之后的尾部」,
|
|
1295
|
+
而 DSH 真实数据里 49 个回撤 marker **全是中间型**(距末尾几千事件)
|
|
1296
|
+
- **脱敏重写在磁盘冷数据层可行**(保留事件数/seq/类型、把 content 改 `[redacted]`,
|
|
1297
|
+
实测 `foldSurface` 通过),但宿主**没有 reload 入口**、且需持写锁 → 必须宿主来做
|
|
1298
|
+
|
|
1299
|
+
**本次落地(方案 1 + 2)**:
|
|
1300
|
+
|
|
1301
|
+
1. **诚实告知(纯插件,止住隐私预期落差)**
|
|
1302
|
+
- 回撤确认框常显告知条 `panel.revertPrivacyNote`:明确「这不是删除,
|
|
1303
|
+
AI 看不到,但原文仍在本地会话文件、可被恢复、翻文件仍能读到」
|
|
1304
|
+
- 行内回滚按钮 title `slot.revertPrivacyHint`(`syncEnabled` 统一,
|
|
1305
|
+
修掉了它覆盖 ensureBtn 初始值的问题)
|
|
1306
|
+
- 成功 toast `done.revert` 补上「原文仍保留、可恢复」
|
|
1307
|
+
- 真实 Chromium 验证:行内 title 与面板确认框告知条均正确渲染
|
|
1308
|
+
|
|
1309
|
+
2. **给宿主的正式需求文档**
|
|
1310
|
+
`docs/superpowers/specs/2026-11-10-host-per-seq-redaction-request.md`(203 行):
|
|
1311
|
+
- 请求两个能力:**per-seq payload 重写**(改 data 不删行、不破坏 seq 连续性)
|
|
1312
|
+
+ **在 commit 时机自动触发 + 内存 surface 重建**
|
|
1313
|
+
- 对标 opencode 的三个 commit 触发点(prompt / compact / 手动)
|
|
1314
|
+
- 含试验数据、源码行号、接口建议、验收标准
|
|
1315
|
+
- 语义:stage 期间可恢复(现状不变),用户继续对话后宿主脱敏 commit,
|
|
1316
|
+
之后翻文件也拿不到原文 —— 正好对上用户「后续几次能恢复、之后彻底删」的诉求
|
|
1317
|
+
|
|
1318
|
+
测试 353(349 pass / 4 skip),`prettier --check` 全绿。
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -132,11 +132,33 @@ window.__ModuleLoader__.load({
|
|
|
132
132
|
'op.branch': '从此条分叉为新会话',
|
|
133
133
|
'op.branchDesc': '把此条之前的对话复制到新会话,并把此条原文放回新会话输入框(原会话不变,非破坏操作)。',
|
|
134
134
|
'slot.revert': '回滚到此条',
|
|
135
|
+
'slot.revertPrivacyHint': '回滚到此条(不是删除:AI 看不到,但原文仍在本地会话文件)',
|
|
135
136
|
'slot.revertUnmatched': '在日志里定位不到这条消息的 seq(通常是模型写的摘要与渲染文本偏差过大)——请改用「消息操作」对话框。',
|
|
136
137
|
'slot.fork': '从此条分叉',
|
|
137
138
|
'slot.forkHint': '复制此条之前的对话到新会话,并把此条原文放回新会话输入框',
|
|
138
139
|
'slot.forkDone': '已分叉:新会话 {id}',
|
|
139
140
|
'slot.forkUnavailable': '分叉不可用:会话正在运行,或宿主未提供 session/fork',
|
|
141
|
+
// 0.20.0:铅笔编辑框(用户消息动作行)。语义 = 先回撤再发,不是「只回填」。
|
|
142
|
+
'slot.edit': '编辑并重发',
|
|
143
|
+
'slot.editHint': '打开编辑框;点「发送并回撤」时才回撤此条及其后内容,再发出改后的文本',
|
|
144
|
+
'slot.editNoText': '这条消息没有可编辑的文本',
|
|
145
|
+
'slot.editUnmatched': '在日志里定位不到这条消息的 seq,暂时无法编辑',
|
|
146
|
+
'edit.title': '编辑并重发',
|
|
147
|
+
'edit.subtitle': '这条消息 · seq #{seq}',
|
|
148
|
+
'edit.loading': '正在读取原文…',
|
|
149
|
+
'edit.loadFail': '原文读取失败:',
|
|
150
|
+
'edit.retry': '重试',
|
|
151
|
+
'edit.placeholder': '编辑这条消息…',
|
|
152
|
+
'edit.cancel': '取消',
|
|
153
|
+
'edit.send': '发送并回撤',
|
|
154
|
+
'edit.sending': '回撤并发送中…',
|
|
155
|
+
'edit.empty': '内容为空,无法发送',
|
|
156
|
+
'edit.failed': '回撤失败:',
|
|
157
|
+
'edit.done': '已回撤',
|
|
158
|
+
'edit.doneSubmitted': '已回撤,改后的消息已提交',
|
|
159
|
+
'edit.manual': '已回撤,改后的文本已放进输入框——请按回车发送',
|
|
160
|
+
'edit.running': '会话正在运行:需先停止会话再编辑重发',
|
|
161
|
+
'edit.replaceHint': '发送会先回撤此条及其之后的全部可见消息,再把改后的文本作为新消息发出;日志仍保留,可从回撤区重放。',
|
|
140
162
|
'toast.openNew': '打开新会话',
|
|
141
163
|
'fork.official': '分支完成:新会话 {id}',
|
|
142
164
|
'fork.unavailable': '官方分支不可用:通常是因为会话正在运行,请先停止会话后重试。分支功能由 dsh 内置的 session/fork 提供。',
|
|
@@ -149,7 +171,7 @@ window.__ModuleLoader__.load({
|
|
|
149
171
|
'busy.delete': '删除中…',
|
|
150
172
|
'busy.branch': '分支中…',
|
|
151
173
|
'done.restore': '恢复完成:重放 {n} 条,跳过不可重放 {s} 条',
|
|
152
|
-
'done.revert': '
|
|
174
|
+
'done.revert': '已回滚(原文仍保留在本地会话文件,可被恢复);刷新页面后生效',
|
|
153
175
|
'done.delete': '删除完成,刷新页面后生效',
|
|
154
176
|
'action.reload': '刷新页面',
|
|
155
177
|
errorPrefix: '操作失败:',
|
|
@@ -164,6 +186,7 @@ window.__ModuleLoader__.load({
|
|
|
164
186
|
'quote.done': '已引用到输入框',
|
|
165
187
|
'quote.unavailable': '引用不可用(输入框不可写或无全文)',
|
|
166
188
|
'quote.sourcePrefix': '引用自 seq {seq}',
|
|
189
|
+
'quote.doneWithSource': '已引用(来自 seq {seq})',
|
|
167
190
|
'undo.label': '回滚上一条消息',
|
|
168
191
|
'undo.desc': '移除最后一条用户消息,原文回填输入框',
|
|
169
192
|
'undo.done.undo': '已回滚上一条消息',
|
|
@@ -194,6 +217,11 @@ window.__ModuleLoader__.load({
|
|
|
194
217
|
'panel.revertHint': '包含此条及其后的可见消息',
|
|
195
218
|
'panel.revertConfirmTitle': '回滚到 #{seq}?',
|
|
196
219
|
'panel.revertConfirmBody': '将遮蔽 #{start}–#{end} 的 {n} 条消息,其中可见 {v} 条;日志仍保留,可恢复。',
|
|
220
|
+
// 0.21.0:隐私预期落差修正。回撤不是「删除」,别让用户以为内容消失了。
|
|
221
|
+
// 实测(design-demos/revert-data-semantics.md):AI 看不到(模型只读 surface.nodes),
|
|
222
|
+
// 但被回撤消息的原文仍逐字留在本地 session.v4.jsonl.zstd 里,翻文件拿得到。
|
|
223
|
+
'panel.revertPrivacyNote':
|
|
224
|
+
'注意:这不是删除。AI 将看不到这些消息,但原文仍完整保留在本地会话文件中,可被恢复;直接翻看会话文件仍能读到。',
|
|
197
225
|
'panel.deleteConfirmTitle': '仅删除 #{seq}?',
|
|
198
226
|
'panel.deleteConfirmBody': '将遮蔽这 1 条消息,其他内容不动;日志仍保留,可恢复。',
|
|
199
227
|
'panel.confirmRevert': '确认回滚',
|
|
@@ -257,12 +285,35 @@ window.__ModuleLoader__.load({
|
|
|
257
285
|
'op.branchDesc':
|
|
258
286
|
'Copies the conversation above the picked message into a new session and puts this message back in the new composer (original untouched, non-destructive).',
|
|
259
287
|
'slot.revert': 'Revert to here',
|
|
288
|
+
'slot.revertPrivacyHint': 'Revert to here (not deletion: hidden from the AI, but the original text stays in the local session file)',
|
|
260
289
|
'slot.revertUnmatched':
|
|
261
290
|
'Cannot locate this message seq in the log (usually the model-written summary drifted too far from the rendered text) — use the Message ops dialog instead.',
|
|
262
291
|
'slot.fork': 'Branch from here',
|
|
263
292
|
'slot.forkHint': 'Copies the conversation above this message into a new session and puts this message back in the new composer',
|
|
264
293
|
'slot.forkDone': 'Branched: new session {id}',
|
|
265
294
|
'slot.forkUnavailable': 'Branch unavailable: the session is running, or the host provides no session/fork',
|
|
295
|
+
// 0.20.0: pencil edit overlay on the user-message action row (revert-then-send).
|
|
296
|
+
'slot.edit': 'Edit and resend',
|
|
297
|
+
'slot.editHint': 'Opens the editor; nothing is reverted until you press "Send and revert"',
|
|
298
|
+
'slot.editNoText': 'This message has no text to edit',
|
|
299
|
+
'slot.editUnmatched': 'Cannot locate this message seq in the log, so it cannot be edited yet',
|
|
300
|
+
'edit.title': 'Edit and resend',
|
|
301
|
+
'edit.subtitle': 'This message · seq #{seq}',
|
|
302
|
+
'edit.loading': 'Loading the original text…',
|
|
303
|
+
'edit.loadFail': 'Could not load the original text: ',
|
|
304
|
+
'edit.retry': 'Retry',
|
|
305
|
+
'edit.placeholder': 'Edit this message…',
|
|
306
|
+
'edit.cancel': 'Cancel',
|
|
307
|
+
'edit.send': 'Send and revert',
|
|
308
|
+
'edit.sending': 'Reverting and sending…',
|
|
309
|
+
'edit.empty': 'Nothing to send — the text is empty',
|
|
310
|
+
'edit.failed': 'Revert failed: ',
|
|
311
|
+
'edit.done': 'Reverted',
|
|
312
|
+
'edit.doneSubmitted': 'Reverted; the edited message has been submitted',
|
|
313
|
+
'edit.manual': 'Reverted; the edited text is in the composer — press Enter to send',
|
|
314
|
+
'edit.running': 'The session is running: stop it before editing and resending',
|
|
315
|
+
'edit.replaceHint':
|
|
316
|
+
'Sending reverts this message and every visible message after it, then sends the edited text as a new message. The log is kept, so you can replay it from the revert dock.',
|
|
266
317
|
'toast.openNew': 'Open new session',
|
|
267
318
|
'fork.official': 'Branched (official fork): new session {id}',
|
|
268
319
|
'fork.unavailable':
|
|
@@ -276,7 +327,7 @@ window.__ModuleLoader__.load({
|
|
|
276
327
|
'busy.delete': 'Deleting…',
|
|
277
328
|
'busy.branch': 'Branching…',
|
|
278
329
|
'done.restore': 'Restored: replayed {n}, skipped non-replayable {s}',
|
|
279
|
-
'done.revert': 'Reverted; reload to apply',
|
|
330
|
+
'done.revert': 'Reverted (original text stays in the local session file and can be restored); reload to apply',
|
|
280
331
|
'done.delete': 'Deleted; reload to apply',
|
|
281
332
|
'action.reload': 'Reload page',
|
|
282
333
|
errorPrefix: 'Operation failed: ',
|
|
@@ -291,6 +342,7 @@ window.__ModuleLoader__.load({
|
|
|
291
342
|
'quote.done': 'Quoted into composer',
|
|
292
343
|
'quote.unavailable': 'Quote unavailable (composer locked or no full text)',
|
|
293
344
|
'quote.sourcePrefix': 'Quoted from seq {seq}',
|
|
345
|
+
'quote.doneWithSource': 'Quoted (from seq {seq})',
|
|
294
346
|
'undo.label': 'Undo last message',
|
|
295
347
|
'undo.desc': 'Remove the last user message and put its original text back into the composer',
|
|
296
348
|
'undo.done.undo': 'Undid the last message',
|
|
@@ -322,6 +374,8 @@ window.__ModuleLoader__.load({
|
|
|
322
374
|
'panel.revertConfirmTitle': 'Revert to #{seq}?',
|
|
323
375
|
'panel.revertConfirmBody':
|
|
324
376
|
'This shadows {n} messages (#{start}–#{end}), including {v} visible. The log stays append-only and can be restored.',
|
|
377
|
+
'panel.revertPrivacyNote':
|
|
378
|
+
'Note: this is not deletion. The AI will no longer see these messages, but the original text stays in the local session file and can be recovered — reading the session file directly still reveals it.',
|
|
325
379
|
'panel.deleteConfirmTitle': 'Delete only #{seq}?',
|
|
326
380
|
'panel.deleteConfirmBody': 'This shadows this one message; everything else stays. The log stays append-only and can be restored.',
|
|
327
381
|
'panel.confirmRevert': 'Confirm revert',
|
|
@@ -1062,7 +1116,7 @@ window.__ModuleLoader__.load({
|
|
|
1062
1116
|
'.mopsPanelScrim{position:fixed;inset:0;z-index:1200;background:rgba(15,17,21,.28);display:flex;align-items:center;justify-content:center;padding:24px;animation:mopsFade .12s ease-out}',
|
|
1063
1117
|
'@keyframes mopsFade{from{opacity:0}to{opacity:1}}',
|
|
1064
1118
|
'@keyframes mopsRise{from{opacity:0;transform:translateY(8px) scale(.985)}to{opacity:1;transform:none}}',
|
|
1065
|
-
'.mopsPanel{width:560px;max-width:min(560px,100%);height:min(760px,100%);max-height:100%;display:flex;flex-direction:column;background:var(--dsw-alias-bg-
|
|
1119
|
+
'.mopsPanel{width:560px;max-width:min(560px,100%);height:min(760px,100%);max-height:100%;display:flex;flex-direction:column;background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-primary,#0f1115);border:1px solid var(--dsw-alias-border-l2,#e6e6e6);box-shadow:0 24px 64px rgba(15,17,21,.24);font-family:inherit;font-size:13px;line-height:1.45;animation:mopsRise .16s cubic-bezier(.2,.8,.3,1)}',
|
|
1066
1120
|
'@media(prefers-reduced-motion:reduce){.mopsPanelScrim,.mopsPanel{animation:none}}',
|
|
1067
1121
|
'.mopsPanel *{box-sizing:border-box}',
|
|
1068
1122
|
'.mopsPanel button{font:inherit;color:inherit;border-radius:0}',
|
|
@@ -1080,7 +1134,7 @@ window.__ModuleLoader__.load({
|
|
|
1080
1134
|
'.mopsSearch:focus{border-color:var(--dsw-alias-brand-primary,#4d6bfe)}',
|
|
1081
1135
|
'.mopsChips{display:flex;gap:6px;padding:0 18px 10px;flex-wrap:wrap;align-items:center}',
|
|
1082
1136
|
'.mopsChip{height:26px;padding:0 9px;border:1px solid var(--dsw-alias-border-l2,#d8d8d8);background:transparent;cursor:pointer;font-size:11px;color:var(--dsw-alias-label-secondary,#6b6b70)}',
|
|
1083
|
-
'.mopsChip.on{border-color:var(--dsw-alias-label-primary,#0f1115);background:var(--dsw-alias-label-primary,#0f1115);color:var(--dsw-alias-bg-
|
|
1137
|
+
'.mopsChip.on{border-color:var(--dsw-alias-label-primary,#0f1115);background:var(--dsw-alias-label-primary,#0f1115);color:var(--dsw-alias-bg-layer-1,#fff)}',
|
|
1084
1138
|
'.mopsToggle{display:inline-flex;align-items:center;gap:5px;font-size:11px;color:var(--dsw-alias-label-secondary,#6b6b70);margin-left:auto;cursor:pointer}',
|
|
1085
1139
|
'.mopsToggle input{accent-color:var(--dsw-alias-brand-primary,#4d6bfe)}',
|
|
1086
1140
|
'.mopsList{flex:1;min-height:0;overflow-y:auto;position:relative;border-top:1px solid var(--dsw-alias-border-l1,#efefef)}',
|
|
@@ -1101,15 +1155,17 @@ window.__ModuleLoader__.load({
|
|
|
1101
1155
|
'.mopsDetailText{margin:0;white-space:pre-wrap;word-break:break-word;max-height:108px;overflow:auto;font-family:inherit;font-size:12px;line-height:1.55;color:var(--dsw-alias-label-primary,#0f1115)}',
|
|
1102
1156
|
'.mopsDetailHint{padding:10px 0 14px;color:var(--dsw-alias-label-tertiary,#8a8a8e);font-size:12px}',
|
|
1103
1157
|
'.mopsActions{display:flex;gap:6px;flex-wrap:wrap;margin-top:10px}',
|
|
1104
|
-
'.mopsActionConfirm{display:flex;flex-direction:column;gap:7px;margin-top:10px;padding:10px;border:1px solid var(--dsw-alias-border-l2,#e6e6e6);background:var(--dsw-alias-bg-
|
|
1158
|
+
'.mopsActionConfirm{display:flex;flex-direction:column;gap:7px;margin-top:10px;padding:10px;border:1px solid var(--dsw-alias-border-l2,#e6e6e6);background:var(--dsw-alias-bg-layer-1,#fff)}',
|
|
1105
1159
|
'.mopsImpactTitle{font-size:12px;font-weight:600}',
|
|
1106
1160
|
'.mopsImpact{font-size:11px;line-height:1.5;color:var(--dsw-alias-label-secondary,#6b6b70)}',
|
|
1161
|
+
// 常显隐私告知条:左竖线 + 灰底,与红色错误条区分;不可关闭,避免"勾了就真删"的误解
|
|
1162
|
+
'.mopsPrivacyNote{margin-top:2px;padding:6px 9px;border-left:2px solid var(--dsw-alias-label-tertiary,#9a9aa0);background:var(--dsw-alias-bg-layer-2,#efefef);border-radius:0 4px 4px 0;font-size:11px;line-height:1.5;color:var(--dsw-alias-label-secondary,#6b6b70)}',
|
|
1107
1163
|
'.mopsAction{height:30px;padding:0 10px;border:1px solid var(--dsw-alias-border-l2,#cfcfcf);background:transparent;cursor:pointer;font-size:11px}',
|
|
1108
1164
|
'.mopsAction:hover:not(:disabled){border-color:var(--dsw-alias-label-primary,#0f1115)}',
|
|
1109
|
-
'.mopsAction.primary{border-color:var(--dsw-alias-label-primary,#0f1115);background:var(--dsw-alias-label-primary,#0f1115);color:var(--dsw-alias-bg-
|
|
1165
|
+
'.mopsAction.primary{border-color:var(--dsw-alias-label-primary,#0f1115);background:var(--dsw-alias-label-primary,#0f1115);color:var(--dsw-alias-bg-layer-1,#fff)}',
|
|
1110
1166
|
'.mopsAction.danger{border-color:var(--dsw-alias-state-error-primary,#c63b32);color:var(--dsw-alias-state-error-primary,#c63b32)}',
|
|
1111
1167
|
'.mopsAction:disabled{opacity:.35;cursor:default}',
|
|
1112
|
-
'.mopsPanelFoot{flex:none;display:flex;align-items:center;gap:10px;justify-content:space-between;padding:10px 18px;border-top:1px solid var(--dsw-alias-border-l2,#e6e6e6);background:var(--dsw-alias-bg-
|
|
1168
|
+
'.mopsPanelFoot{flex:none;display:flex;align-items:center;gap:10px;justify-content:space-between;padding:10px 18px;border-top:1px solid var(--dsw-alias-border-l2,#e6e6e6);background:var(--dsw-alias-bg-layer-1,#fff)}',
|
|
1113
1169
|
'.mopsCount{font-size:10px;color:var(--dsw-alias-label-tertiary,#8a8a8e)}',
|
|
1114
1170
|
'.mopsDanger{border:1px solid var(--dsw-alias-state-error-primary,#c63b32);background:transparent;color:var(--dsw-alias-state-error-primary,#c63b32);height:28px;padding:0 9px;cursor:pointer;font-size:11px}',
|
|
1115
1171
|
'.mopsDanger:hover{background:rgba(198,59,50,.06)}',
|
|
@@ -1117,7 +1173,7 @@ window.__ModuleLoader__.load({
|
|
|
1117
1173
|
'.mopsBanner.warn{color:var(--dsw-alias-state-warn-primary,#9a6500);background:rgba(154,101,0,.06)}',
|
|
1118
1174
|
'.mopsBanner.err{color:var(--dsw-alias-state-error-primary,#c63b32);background:rgba(198,59,50,.06)}',
|
|
1119
1175
|
'.mopsBanner.ok{color:var(--dsw-alias-state-success-primary,#2f7d4a);background:rgba(47,125,74,.06)}',
|
|
1120
|
-
'.mopsConfirm{position:absolute;inset:0;z-index:2;background:var(--dsw-alias-bg-
|
|
1176
|
+
'.mopsConfirm{position:absolute;inset:0;z-index:2;background:var(--dsw-alias-bg-layer-1,#fff);display:flex;flex-direction:column;justify-content:center;padding:28px 24px;gap:10px}',
|
|
1121
1177
|
'.mopsConfirm h3{margin:0;font-size:15px}',
|
|
1122
1178
|
'.mopsConfirm p{margin:0;font-size:12px;color:var(--dsw-alias-label-secondary,#6b6b70)}',
|
|
1123
1179
|
'.mopsConfirm p.mopsImpact{font-size:11px}',
|
|
@@ -1827,6 +1883,11 @@ window.__ModuleLoader__.load({
|
|
|
1827
1883
|
|
|
1828
1884
|
const pickedLive = picked ? messages.find(m => m.seq === picked.seq) || picked : null
|
|
1829
1885
|
const canAct = !busy && !target.running && pickedLive && !pickedLive.shadowed
|
|
1886
|
+
// 0.20.0(bug-hunt H-1 / M-3):AI 消息回滚已在 0.19.0 从动作区下线
|
|
1887
|
+
// (用户明确要求「回撤是用户消息那边的用处」)。面板不能留一个
|
|
1888
|
+
// 「能回滚 AI 消息却静默不回填」的旁路,故回滚按钮同样限定为用户消息。
|
|
1889
|
+
// 删除按钮仍用 canAct —— 删单条 AI 消息是合理能力,不受此限。
|
|
1890
|
+
const canRevert = canAct && pickedLive && pickedLive.role === 'user'
|
|
1830
1891
|
const visibleCount = messages.filter(m => m.role !== 'system' && m.visible && !m.shadowed).length
|
|
1831
1892
|
const shadowedCount = messages.filter(m => m.role !== 'system' && m.shadowed).length
|
|
1832
1893
|
const totalCount = messages.filter(m => m.role !== 'system').length
|
|
@@ -2134,7 +2195,7 @@ window.__ModuleLoader__.load({
|
|
|
2134
2195
|
{
|
|
2135
2196
|
type: 'button',
|
|
2136
2197
|
className: 'mopsAction primary',
|
|
2137
|
-
disabled: !
|
|
2198
|
+
disabled: !canRevert || !!confirmAction,
|
|
2138
2199
|
ref: revertBtnRef,
|
|
2139
2200
|
onClick: () => setConfirmAction('revert'),
|
|
2140
2201
|
title: t('panel.revertHint'),
|
|
@@ -2196,6 +2257,11 @@ window.__ModuleLoader__.load({
|
|
|
2196
2257
|
})
|
|
2197
2258
|
: t('panel.deleteConfirmBody'),
|
|
2198
2259
|
),
|
|
2260
|
+
// 0.21.0:revert 的常显隐私告知(零副作用、纯文案)。
|
|
2261
|
+
// 只在回滚确认态出现;删除确认不需要(删单条同样遮蔽,但语义不同)。
|
|
2262
|
+
confirmAction === 'revert'
|
|
2263
|
+
? React.createElement('div', { className: 'mopsPrivacyNote', role: 'note' }, t('panel.revertPrivacyNote'))
|
|
2264
|
+
: null,
|
|
2199
2265
|
React.createElement(
|
|
2200
2266
|
'div',
|
|
2201
2267
|
{ className: 'mopsConfirmRow' },
|
|
@@ -2396,6 +2462,498 @@ window.__ModuleLoader__.load({
|
|
|
2396
2462
|
)
|
|
2397
2463
|
}
|
|
2398
2464
|
|
|
2465
|
+
// --- 0.20.0 · 「编辑并重发」的编排层 ----------------------------------------
|
|
2466
|
+
//
|
|
2467
|
+
// 语义(用户明确要求 + lead 决断;**不是** opencode 的立即回填,也**不是** fork):
|
|
2468
|
+
//
|
|
2469
|
+
// 点铅笔 → 只读:GET /text 取全文,在编辑框里改文字。零写操作。
|
|
2470
|
+
// 点「取消」/ Esc / 点遮罩 → 只清本地 state。零 fetch、零写盘、零 openSession。
|
|
2471
|
+
// 点「发送并回撤」这一刻才写,顺序严格如下:
|
|
2472
|
+
// ① POST /api/message-ops/revert { sessionId, seq }
|
|
2473
|
+
// 失败(含 409 运行中)→ 保留编辑框与用户已输入的文本,报错,不再往下走
|
|
2474
|
+
// ② markRowsShadowedFrom(seq) —— 与其它回滚入口共用同一个防 409 护栏
|
|
2475
|
+
// ③ writeSessionDraft(rawSessionId) —— 合并写入,保住 view 偏好;这是权威值
|
|
2476
|
+
// ④ setDraft + persistDraft —— 尽力同步「活着的」编辑器
|
|
2477
|
+
// ⑤ emitChanged + openSessionById —— 视图重建;remount 时从 localStorage 读回同一份草稿
|
|
2478
|
+
// ⑥ 有界等待重挂后 submit() 一次 —— 不可用则明确提示「请按回车发送」,绝不静默
|
|
2479
|
+
//
|
|
2480
|
+
// 为什么 ③ 必须在 ⑤ 之前:openSession 会卸载并重挂编辑器,新挂载走
|
|
2481
|
+
// `readConversationDraft(sid)` 从 localStorage 初始化。先落盘才是无竞态路径
|
|
2482
|
+
// (0.11.3 / 0.14.0 两次事故的同一个教训,见 refillComposer 注释)。
|
|
2483
|
+
//
|
|
2484
|
+
// 为什么不用 fork:「分叉」按钮的语义是源会话一字不动。同一个「编辑」动作若在
|
|
2485
|
+
// 铅笔里改写源会话、在分叉里保留源会话,就是两套相反语义 —— 用户无法预期。
|
|
2486
|
+
const EDIT_EVENT = 'dsh-message-ops:edit'
|
|
2487
|
+
const EDIT_ID = 'message-ops-edit-resend'
|
|
2488
|
+
const EDIT_STYLE_ID = 'dsh-message-ops-edit-style'
|
|
2489
|
+
/** 等待 composer 重挂的最大轮数 / 间隔:有界,不无限自旋。 */
|
|
2490
|
+
const EDIT_SUBMIT_ATTEMPTS = 8
|
|
2491
|
+
const EDIT_SUBMIT_INTERVAL_MS = 120
|
|
2492
|
+
|
|
2493
|
+
/**
|
|
2494
|
+
* 有界等待 composer 重挂后提交**一次**。
|
|
2495
|
+
*
|
|
2496
|
+
* 判据:`__inputActions` 换成新对象 = 宿主重挂了编辑器(openSession 之后必然发生)。
|
|
2497
|
+
* 到上限仍没换(例如视图没重建的内联路径)就用当前这个提交一次 —— 宁可多一条
|
|
2498
|
+
* 兜底提示,也不要无限等。**只提交一次**:重复 submit 会发出两条消息,比失败更糟。
|
|
2499
|
+
*
|
|
2500
|
+
* @param text - 要提交的文本
|
|
2501
|
+
* @param options - { attempts, intervalMs },测试注入更小值
|
|
2502
|
+
* @returns Promise<boolean> 是否成功调用了宿主 submit
|
|
2503
|
+
*/
|
|
2504
|
+
function submitEditedText(text, options) {
|
|
2505
|
+
const opts = options || {}
|
|
2506
|
+
const attempts = Number.isSafeInteger(opts.attempts) && opts.attempts > 0 ? opts.attempts : EDIT_SUBMIT_ATTEMPTS
|
|
2507
|
+
const intervalMs = Number.isSafeInteger(opts.intervalMs) && opts.intervalMs >= 0 ? opts.intervalMs : EDIT_SUBMIT_INTERVAL_MS
|
|
2508
|
+
const before = __inputActions
|
|
2509
|
+
return new Promise(resolve => {
|
|
2510
|
+
let n = 0
|
|
2511
|
+
const tick = () => {
|
|
2512
|
+
n += 1
|
|
2513
|
+
const ia = __inputActions
|
|
2514
|
+
const usable = ia && typeof ia.submit === 'function' && typeof ia.setDraft === 'function'
|
|
2515
|
+
const remounted = !!ia && ia !== before
|
|
2516
|
+
if (usable && (remounted || n >= attempts)) {
|
|
2517
|
+
try {
|
|
2518
|
+
// 先确保编辑器里就是这段文字:重挂后 draft 已从 localStorage 读回,
|
|
2519
|
+
// 但内联路径(视图没重建)里编辑器仍是旧内容,必须显式覆盖。
|
|
2520
|
+
ia.setDraft(text)
|
|
2521
|
+
if (typeof ia.persistDraft === 'function') ia.persistDraft()
|
|
2522
|
+
ia.submit()
|
|
2523
|
+
resolve(true)
|
|
2524
|
+
} catch (e) {
|
|
2525
|
+
console.warn('[message-ops] submit failed:', e)
|
|
2526
|
+
resolve(false)
|
|
2527
|
+
}
|
|
2528
|
+
return
|
|
2529
|
+
}
|
|
2530
|
+
if (n >= attempts) {
|
|
2531
|
+
resolve(false)
|
|
2532
|
+
return
|
|
2533
|
+
}
|
|
2534
|
+
setTimeout(tick, intervalMs)
|
|
2535
|
+
}
|
|
2536
|
+
setTimeout(tick, intervalMs)
|
|
2537
|
+
})
|
|
2538
|
+
}
|
|
2539
|
+
|
|
2540
|
+
/**
|
|
2541
|
+
* 「发送并回撤」的唯一编排实现。
|
|
2542
|
+
*
|
|
2543
|
+
* 抽成具名函数(而不是埋在组件里)有两个理由:
|
|
2544
|
+
* 1. 时序是本功能的核心契约,必须能被测试**真执行**断言
|
|
2545
|
+
* (revert 失败 → 不写草稿、不 openSession、用户文本保留)。
|
|
2546
|
+
* 2. 组件只负责 UI 状态;失败时「保留文本」由调用方按返回值决定。
|
|
2547
|
+
*
|
|
2548
|
+
* @param options - { sessionId, rawSessionId, seq, text, deps }
|
|
2549
|
+
* sessionId 裸 uuid(给 HTTP)
|
|
2550
|
+
* rawSessionId `session-` 前缀(给 openSession 与草稿键);缺省从 sessionId 补
|
|
2551
|
+
* deps 可注入的副作用集合(测试用);缺省取真实实现
|
|
2552
|
+
* @returns Promise<{ok, stage, submitted?, persisted?, reason?, status?}>
|
|
2553
|
+
* stage: 'validate' | 'revert' | 'done'
|
|
2554
|
+
*/
|
|
2555
|
+
async function sendEditAndRevert(options) {
|
|
2556
|
+
const opts = options || {}
|
|
2557
|
+
const sessionId = String(opts.sessionId || '').trim()
|
|
2558
|
+
// 草稿键与 openSession 都必须用带 `session-` 前缀的写法:
|
|
2559
|
+
// 裸 uuid 会让宿主 `sessions.retain` 抛 `unknown session` 并被外层 catch 静默吞掉
|
|
2560
|
+
// (0.9.6 事故,见 afterWrite 注释)。这里显式补齐,不假设调用方传对。
|
|
2561
|
+
const rawSessionId = String(opts.rawSessionId || '').trim() || (sessionId ? 'session-' + sessionId : '')
|
|
2562
|
+
const seq = opts.seq
|
|
2563
|
+
const text = typeof opts.text === 'string' ? opts.text : ''
|
|
2564
|
+
const deps = opts.deps || {}
|
|
2565
|
+
// ⚠️ 这里只先解析 fetch:revert 失败时**不得**触碰任何草稿/视图副作用,
|
|
2566
|
+
// 连「解析实现」都不该发生在失败之前(解析顺序 = 语义顺序)。
|
|
2567
|
+
const doFetch = deps.fetch || fetch
|
|
2568
|
+
|
|
2569
|
+
if (!sessionId || !Number.isSafeInteger(seq) || seq < 0) return { ok: false, stage: 'validate', reason: 'invalid target' }
|
|
2570
|
+
if (text.trim() === '') return { ok: false, stage: 'validate', reason: 'empty' }
|
|
2571
|
+
|
|
2572
|
+
// ① 回撤:失败就**什么都不做**(不写草稿、不重建视图、不动编辑器)
|
|
2573
|
+
let res = null
|
|
2574
|
+
let data = null
|
|
2575
|
+
try {
|
|
2576
|
+
res = await doFetch('/api/message-ops/revert', {
|
|
2577
|
+
method: 'POST',
|
|
2578
|
+
headers: { 'content-type': 'application/json' },
|
|
2579
|
+
body: JSON.stringify({ sessionId, seq }),
|
|
2580
|
+
})
|
|
2581
|
+
data = await res.json().catch(() => null)
|
|
2582
|
+
} catch (e) {
|
|
2583
|
+
return { ok: false, stage: 'revert', reason: e && e.message ? e.message : String(e) }
|
|
2584
|
+
}
|
|
2585
|
+
if (!res || !res.ok || !data || data.ok !== true) {
|
|
2586
|
+
return {
|
|
2587
|
+
ok: false,
|
|
2588
|
+
stage: 'revert',
|
|
2589
|
+
status: res ? res.status : 0,
|
|
2590
|
+
reason: (data && data.error) || 'HTTP ' + (res ? res.status : '?'),
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
|
|
2594
|
+
// ── 回撤已成功 ── 从这里开始才解析并使用其余副作用 ──────────────────────
|
|
2595
|
+
const doWrite = deps.writeSessionDraft || writeSessionDraft
|
|
2596
|
+
const doRead = deps.readSessionDraft || readSessionDraft
|
|
2597
|
+
const markShadowed = deps.markRowsShadowedFrom || markRowsShadowedFrom
|
|
2598
|
+
const doSetDraft = deps.setDraft || (v => (__inputActions && __inputActions.setDraft ? __inputActions.setDraft(v) : false))
|
|
2599
|
+
const doPersistDraft =
|
|
2600
|
+
deps.persistDraft || (() => (__inputActions && __inputActions.persistDraft ? __inputActions.persistDraft() : false))
|
|
2601
|
+
const doEmitChanged = deps.emitChanged || emitChanged
|
|
2602
|
+
const doOpenSession = deps.openSessionById || openSessionById
|
|
2603
|
+
const doSubmit = deps.submitEdited || submitEditedText
|
|
2604
|
+
|
|
2605
|
+
// ② 防 409 护栏:本地缓存里 >= seq 的行立刻标成已遮蔽(与 runUserRevert/runUndo 同一函数)
|
|
2606
|
+
try {
|
|
2607
|
+
markShadowed(seq)
|
|
2608
|
+
} catch (e) {
|
|
2609
|
+
console.warn('[message-ops] markRowsShadowedFrom failed:', e)
|
|
2610
|
+
}
|
|
2611
|
+
|
|
2612
|
+
// ③ 权威落盘(合并写,保住 view 偏好)
|
|
2613
|
+
let persisted = false
|
|
2614
|
+
try {
|
|
2615
|
+
persisted = doWrite(rawSessionId, text) === true
|
|
2616
|
+
} catch (e) {
|
|
2617
|
+
console.warn('[message-ops] writeSessionDraft failed:', e)
|
|
2618
|
+
}
|
|
2619
|
+
// 回读校验:只有读到**不同的非空值**才算落盘失败(读不到时保持原判断,不误判)
|
|
2620
|
+
if (persisted && typeof doRead === 'function') {
|
|
2621
|
+
try {
|
|
2622
|
+
const stored = doRead(rawSessionId)
|
|
2623
|
+
if (stored != null && stored !== text) persisted = false
|
|
2624
|
+
} catch (e) {
|
|
2625
|
+
/* 读回失败不推翻写入结果 */
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
|
|
2629
|
+
// ④ 尽力同步活着的编辑器(重挂路径靠 ③;这里只覆盖「视图没重建」的内联路径)
|
|
2630
|
+
try {
|
|
2631
|
+
doSetDraft(text)
|
|
2632
|
+
} catch (e) {
|
|
2633
|
+
console.warn('[message-ops] setDraft failed:', e)
|
|
2634
|
+
}
|
|
2635
|
+
try {
|
|
2636
|
+
doPersistDraft()
|
|
2637
|
+
} catch (e) {
|
|
2638
|
+
/* persistDraft 缺席不阻断 —— ③ 已经落盘 */
|
|
2639
|
+
}
|
|
2640
|
+
|
|
2641
|
+
// ⑤ 通知 + 重建视图(rawSessionId 带前缀;裸 uuid 会抛 unknown session)
|
|
2642
|
+
try {
|
|
2643
|
+
doEmitChanged()
|
|
2644
|
+
} catch (e) {
|
|
2645
|
+
/* 广播失败不阻断写结果 */
|
|
2646
|
+
}
|
|
2647
|
+
try {
|
|
2648
|
+
doOpenSession(rawSessionId)
|
|
2649
|
+
} catch (e) {
|
|
2650
|
+
console.warn('[message-ops] openSession failed:', e)
|
|
2651
|
+
}
|
|
2652
|
+
|
|
2653
|
+
// ⑥ 有界等待重挂后提交一次;不可用 → 调用方提示手动回车
|
|
2654
|
+
let submitted = false
|
|
2655
|
+
try {
|
|
2656
|
+
submitted = (await doSubmit(text)) === true
|
|
2657
|
+
} catch (e) {
|
|
2658
|
+
console.warn('[message-ops] submitEdited failed:', e)
|
|
2659
|
+
}
|
|
2660
|
+
return { ok: true, stage: 'done', submitted: submitted === true, persisted: persisted }
|
|
2661
|
+
}
|
|
2662
|
+
|
|
2663
|
+
/**
|
|
2664
|
+
* 编辑框样式:颜色全走 `--dsw-alias-*`,圆角全走 `--dsw-radius-*`,无裸 hex。
|
|
2665
|
+
*
|
|
2666
|
+
* ⚠️ 只用**已确认存在**的 token:`--dsw-alias-label-error` 与 `--dsw-alias-bg-layer-1`
|
|
2667
|
+
* 在宿主 theme 包里并不存在(别处有误用),错误色一律用 `--dsw-alias-state-error-primary`,
|
|
2668
|
+
* 背景用 `--dsw-alias-bg-layer-1`。全部带 fallback,深色模式不吃亏。
|
|
2669
|
+
*/
|
|
2670
|
+
function ensureEditStyle() {
|
|
2671
|
+
try {
|
|
2672
|
+
if (typeof document === 'undefined' || !document.head) return
|
|
2673
|
+
if (document.getElementById(EDIT_STYLE_ID)) return
|
|
2674
|
+
const tag = document.createElement('style')
|
|
2675
|
+
tag.id = EDIT_STYLE_ID
|
|
2676
|
+
tag.textContent = [
|
|
2677
|
+
'.mopsErScrim{position:fixed;inset:0;z-index:1200;display:flex;align-items:center;justify-content:center;padding:24px;background:var(--dsw-alias-bg-mask-1,rgba(15,17,21,.42));animation:mopsErFade .12s ease-out}',
|
|
2678
|
+
'@keyframes mopsErFade{from{opacity:0}to{opacity:1}}',
|
|
2679
|
+
'@keyframes mopsErRise{from{opacity:0;transform:translateY(8px) scale(.985)}to{opacity:1;transform:none}}',
|
|
2680
|
+
'@media(prefers-reduced-motion:reduce){.mopsErScrim,.mopsErPanel{animation:none}}',
|
|
2681
|
+
'.mopsErPanel{width:min(560px,100%);max-height:min(720px,100%);display:flex;flex-direction:column;gap:10px;padding:16px;background:var(--dsw-alias-bg-layer-1,#fff);color:var(--dsw-alias-label-primary,#0f1115);border:1px solid var(--dsw-alias-border-l2,#e6e6e6);border-radius:var(--dsw-radius-md,12px);box-shadow:0 24px 64px rgba(15,17,21,.24);font-family:inherit;font-size:13px;line-height:1.45;animation:mopsErRise .16s cubic-bezier(.2,.8,.3,1)}',
|
|
2682
|
+
'.mopsErPanel *{box-sizing:border-box}',
|
|
2683
|
+
'.mopsErHead{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;flex:none}',
|
|
2684
|
+
'.mopsErTitle{font-size:15px;font-weight:600;line-height:22px}',
|
|
2685
|
+
'.mopsErSub{font-size:11px;line-height:16px;color:var(--dsw-alias-label-tertiary,#8a8a8e);margin-top:2px;font-variant-numeric:tabular-nums}',
|
|
2686
|
+
'.mopsErClose{width:28px;height:28px;flex:none;display:inline-flex;align-items:center;justify-content:center;border:1px solid transparent;border-radius:var(--dsw-radius-xs,4px);background:transparent;color:var(--dsw-alias-label-tertiary,#8a8a8e);cursor:pointer;font-size:16px;line-height:1}',
|
|
2687
|
+
'.mopsErClose:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.12));color:var(--dsw-alias-label-primary,#0f1115)}',
|
|
2688
|
+
'.mopsErClose:disabled{opacity:.4;cursor:default}',
|
|
2689
|
+
'.mopsErBody{flex:1;min-height:0;display:flex;flex-direction:column;gap:8px}',
|
|
2690
|
+
'.mopsErText{width:100%;min-height:120px;max-height:40vh;resize:vertical;padding:10px;border:1px solid var(--dsw-alias-border-l2,#e6e6e6);border-radius:var(--dsw-radius-sm,8px);background:var(--dsw-alias-bg-layer-2,#f7f7f8);color:var(--dsw-alias-label-primary,#0f1115);font:inherit;font-size:14px;line-height:1.6;outline:none}',
|
|
2691
|
+
'.mopsErText::placeholder{color:var(--dsw-alias-label-tertiary,#8a8a8e)}',
|
|
2692
|
+
'.mopsErText:focus-visible{box-shadow:0 0 0 2px var(--dsw-alias-bg-layer-1,#fff),0 0 0 4px var(--dsw-alias-brand-primary,#4d6bfe)}',
|
|
2693
|
+
'.mopsErText:disabled{opacity:.6;cursor:progress}',
|
|
2694
|
+
'.mopsErText[aria-invalid="true"]{border-color:var(--dsw-alias-state-error-primary,#c63b32)}',
|
|
2695
|
+
'.mopsErHint{font-size:11px;line-height:17px;color:var(--dsw-alias-label-tertiary,#8a8a8e)}',
|
|
2696
|
+
'.mopsErError{font-size:12px;line-height:18px;color:var(--dsw-alias-state-error-primary,#c63b32);overflow-wrap:anywhere}',
|
|
2697
|
+
'.mopsErOk{font-size:12px;line-height:18px;color:var(--dsw-alias-state-success-primary,#2f7d4a)}',
|
|
2698
|
+
'.mopsErActions{flex:none;display:flex;gap:8px;justify-content:flex-end;flex-wrap:wrap}',
|
|
2699
|
+
'.mopsErBtn{min-height:30px;padding:4px 9px;border-radius:var(--dsw-radius-xs,4px);font:inherit;font-size:12px;line-height:20px;cursor:pointer;border:1px solid transparent}',
|
|
2700
|
+
'.mopsErGhost{color:var(--dsw-alias-label-secondary,#6b6b70);background:transparent}',
|
|
2701
|
+
'.mopsErGhost:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.12));color:var(--dsw-alias-label-primary,#0f1115)}',
|
|
2702
|
+
'.mopsErPrimary{background:var(--dsw-alias-button-primary-fill,#2b2b2e);color:var(--dsw-alias-label-primary-foreground,#fff)}',
|
|
2703
|
+
'.mopsErPrimary:hover:not(:disabled){background:var(--dsw-alias-button-primary-hover,#3a3a3e)}',
|
|
2704
|
+
'.mopsErBtn:disabled{opacity:.5;cursor:not-allowed}',
|
|
2705
|
+
'.mopsErBtn:focus-visible,.mopsErClose:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4d6bfe);outline-offset:1px}',
|
|
2706
|
+
'@media(max-width:760px){.mopsErScrim{padding:0}.mopsErPanel{width:100%;height:100%;max-height:100%;border:0;border-radius:0}}',
|
|
2707
|
+
].join('')
|
|
2708
|
+
document.head.appendChild(tag)
|
|
2709
|
+
} catch (e) {
|
|
2710
|
+
/* 样式注入失败不影响功能 */
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
|
|
2714
|
+
/**
|
|
2715
|
+
* 「编辑并重发」浮层(`shell.overlay` 槽,与本插件 OpsPanel 同族)。
|
|
2716
|
+
*
|
|
2717
|
+
* 常驻挂载、内部 state 控制显隐 —— 与 OpsPanel 完全同款(list 槽的条目没有
|
|
2718
|
+
* 「开关」概念,只能靠组件自身状态)。未打开时返回 null。
|
|
2719
|
+
*/
|
|
2720
|
+
function EditResendOverlay(props) {
|
|
2721
|
+
const { sessionId, useSessions } = props
|
|
2722
|
+
const t = (props && props.t) || __t
|
|
2723
|
+
useLocaleRevision()
|
|
2724
|
+
if (sessionId) __currentSessionId = sessionId
|
|
2725
|
+
const sessions = useSessions ? useSessions(s => s) : undefined
|
|
2726
|
+
const [target, setTarget] = useState(null) // { sessionId, rawSessionId, seq }
|
|
2727
|
+
const [draft, setDraft] = useState('')
|
|
2728
|
+
const [textState, setTextState] = useState('idle') // idle|loading|ready|error
|
|
2729
|
+
const [loadError, setLoadError] = useState(null)
|
|
2730
|
+
const [saving, setSaving] = useState(false)
|
|
2731
|
+
const [error, setError] = useState(null)
|
|
2732
|
+
const [done, setDone] = useState('')
|
|
2733
|
+
const textRef = useRef(null)
|
|
2734
|
+
const reqRef = useRef(0)
|
|
2735
|
+
|
|
2736
|
+
useEffect(() => {
|
|
2737
|
+
ensureEditStyle()
|
|
2738
|
+
const handler = e => {
|
|
2739
|
+
const d = e && e.detail ? e.detail : {}
|
|
2740
|
+
if (!d.sessionId || !Number.isSafeInteger(d.seq)) return
|
|
2741
|
+
reqRef.current += 1
|
|
2742
|
+
setTarget({ sessionId: String(d.sessionId), rawSessionId: d.rawSessionId || d.sessionId, seq: d.seq })
|
|
2743
|
+
setDraft('')
|
|
2744
|
+
setTextState('loading')
|
|
2745
|
+
setLoadError(null)
|
|
2746
|
+
setError(null)
|
|
2747
|
+
setDone('')
|
|
2748
|
+
}
|
|
2749
|
+
window.addEventListener(EDIT_EVENT, handler)
|
|
2750
|
+
return () => window.removeEventListener(EDIT_EVENT, handler)
|
|
2751
|
+
}, [])
|
|
2752
|
+
|
|
2753
|
+
const loadText = useCallback(() => {
|
|
2754
|
+
if (!target) return
|
|
2755
|
+
const req = ++reqRef.current
|
|
2756
|
+
const sid = target.sessionId
|
|
2757
|
+
setTextState('loading')
|
|
2758
|
+
setLoadError(null)
|
|
2759
|
+
fetch('/api/message-ops/text?sessionId=' + encodeURIComponent(sid) + '&seq=' + encodeURIComponent(target.seq))
|
|
2760
|
+
.then(res =>
|
|
2761
|
+
res
|
|
2762
|
+
.json()
|
|
2763
|
+
.catch(() => null)
|
|
2764
|
+
.then(data => ({ res, data })),
|
|
2765
|
+
)
|
|
2766
|
+
.then(({ res, data }) => {
|
|
2767
|
+
if (req !== reqRef.current) return
|
|
2768
|
+
if (!res.ok || !data || data.ok !== true) throw new Error((data && data.error) || 'HTTP ' + res.status)
|
|
2769
|
+
if (typeof data.text !== 'string' || data.text === '') throw new Error(t('slot.editNoText'))
|
|
2770
|
+
// ⚠️ 只认 /text 的全文:绝不拿 160 字 snippet 冒充原文
|
|
2771
|
+
// (service 侧硬截断,见 session-file.js 的 snippet.slice(0,160))
|
|
2772
|
+
setDraft(data.text)
|
|
2773
|
+
setTextState('ready')
|
|
2774
|
+
})
|
|
2775
|
+
.catch(reason => {
|
|
2776
|
+
if (req !== reqRef.current) return
|
|
2777
|
+
setLoadError(t('edit.loadFail') + (reason && reason.message ? reason.message : String(reason)))
|
|
2778
|
+
setTextState('error')
|
|
2779
|
+
})
|
|
2780
|
+
}, [target, t])
|
|
2781
|
+
|
|
2782
|
+
useEffect(() => {
|
|
2783
|
+
if (!target) return undefined
|
|
2784
|
+
loadText()
|
|
2785
|
+
return undefined
|
|
2786
|
+
}, [target, loadText])
|
|
2787
|
+
|
|
2788
|
+
// 光标置末尾:长消息从第一行开始编辑很难受,用户多半是改尾部
|
|
2789
|
+
useEffect(() => {
|
|
2790
|
+
if (textState !== 'ready' || !textRef.current) return
|
|
2791
|
+
const el = textRef.current
|
|
2792
|
+
try {
|
|
2793
|
+
el.focus()
|
|
2794
|
+
const end = el.value.length
|
|
2795
|
+
el.setSelectionRange(end, end)
|
|
2796
|
+
} catch (e) {
|
|
2797
|
+
/* 非浏览器 / 不支持的输入类型:忽略 */
|
|
2798
|
+
}
|
|
2799
|
+
}, [textState])
|
|
2800
|
+
|
|
2801
|
+
const cancel = useCallback(() => {
|
|
2802
|
+
if (saving) return
|
|
2803
|
+
// 零副作用:只清本地 state。不清宿主草稿、不碰会话、不发请求。
|
|
2804
|
+
reqRef.current += 1
|
|
2805
|
+
setTarget(null)
|
|
2806
|
+
setDraft('')
|
|
2807
|
+
setTextState('idle')
|
|
2808
|
+
setLoadError(null)
|
|
2809
|
+
setError(null)
|
|
2810
|
+
setDone('')
|
|
2811
|
+
}, [saving])
|
|
2812
|
+
|
|
2813
|
+
const running = (() => {
|
|
2814
|
+
if (!target || !sessions || !sessions.byId) return false
|
|
2815
|
+
const summary =
|
|
2816
|
+
sessions.byId[target.rawSessionId] || sessions.byId['session-' + target.sessionId] || sessions.byId[target.sessionId]
|
|
2817
|
+
return summary ? summary.running === true : false
|
|
2818
|
+
})()
|
|
2819
|
+
|
|
2820
|
+
const canSubmit = textState === 'ready' && !saving && draft.trim() !== '' && !running
|
|
2821
|
+
|
|
2822
|
+
const send = useCallback(async () => {
|
|
2823
|
+
if (!target || !canSubmit) return
|
|
2824
|
+
setSaving(true)
|
|
2825
|
+
setError(null)
|
|
2826
|
+
setDone('')
|
|
2827
|
+
const result = await sendEditAndRevert({
|
|
2828
|
+
sessionId: target.sessionId,
|
|
2829
|
+
rawSessionId: target.rawSessionId,
|
|
2830
|
+
seq: target.seq,
|
|
2831
|
+
text: draft,
|
|
2832
|
+
})
|
|
2833
|
+
if (!result.ok) {
|
|
2834
|
+
// ⚠️ 失败必须保留编辑框 + 用户已输入的文本(不清 draft、不 close)
|
|
2835
|
+
setSaving(false)
|
|
2836
|
+
setError(
|
|
2837
|
+
result.stage === 'revert'
|
|
2838
|
+
? t('edit.failed') + (result.reason || 'HTTP ' + result.status)
|
|
2839
|
+
: result.reason === 'empty'
|
|
2840
|
+
? t('edit.empty')
|
|
2841
|
+
: String(result.reason || ''),
|
|
2842
|
+
)
|
|
2843
|
+
return
|
|
2844
|
+
}
|
|
2845
|
+
setSaving(false)
|
|
2846
|
+
if (result.submitted) {
|
|
2847
|
+
notifyDone(t('edit.doneSubmitted'))
|
|
2848
|
+
cancel()
|
|
2849
|
+
return
|
|
2850
|
+
}
|
|
2851
|
+
// 提交不可用:明确告诉用户文本已经在输入框里,别让人以为没发生
|
|
2852
|
+
notifyDone(t('edit.manual'), 'warn')
|
|
2853
|
+
setDone(t('edit.manual'))
|
|
2854
|
+
}, [target, canSubmit, draft, t, cancel])
|
|
2855
|
+
|
|
2856
|
+
if (!target) return null
|
|
2857
|
+
|
|
2858
|
+
const onKeyDown = e => {
|
|
2859
|
+
if (e.key === 'Escape') {
|
|
2860
|
+
e.preventDefault()
|
|
2861
|
+
if (!saving) cancel()
|
|
2862
|
+
return
|
|
2863
|
+
}
|
|
2864
|
+
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
|
|
2865
|
+
e.preventDefault()
|
|
2866
|
+
if (canSubmit) send()
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2869
|
+
|
|
2870
|
+
return React.createElement(
|
|
2871
|
+
'div',
|
|
2872
|
+
{
|
|
2873
|
+
className: 'mopsErScrim',
|
|
2874
|
+
role: 'presentation',
|
|
2875
|
+
onMouseDown: e => {
|
|
2876
|
+
if (e.target === e.currentTarget && !saving) cancel()
|
|
2877
|
+
},
|
|
2878
|
+
},
|
|
2879
|
+
React.createElement(
|
|
2880
|
+
'section',
|
|
2881
|
+
{
|
|
2882
|
+
className: 'mopsErPanel',
|
|
2883
|
+
role: 'dialog',
|
|
2884
|
+
'aria-modal': 'true',
|
|
2885
|
+
'aria-labelledby': 'mops-er-title',
|
|
2886
|
+
onKeyDown,
|
|
2887
|
+
},
|
|
2888
|
+
React.createElement(
|
|
2889
|
+
'div',
|
|
2890
|
+
{ className: 'mopsErHead' },
|
|
2891
|
+
React.createElement(
|
|
2892
|
+
'div',
|
|
2893
|
+
null,
|
|
2894
|
+
React.createElement('div', { className: 'mopsErTitle', id: 'mops-er-title' }, t('edit.title')),
|
|
2895
|
+
React.createElement('div', { className: 'mopsErSub' }, t('edit.subtitle', { seq: String(target.seq) })),
|
|
2896
|
+
),
|
|
2897
|
+
React.createElement(
|
|
2898
|
+
'button',
|
|
2899
|
+
{
|
|
2900
|
+
type: 'button',
|
|
2901
|
+
className: 'mopsErClose',
|
|
2902
|
+
onClick: cancel,
|
|
2903
|
+
disabled: saving,
|
|
2904
|
+
title: t('edit.cancel'),
|
|
2905
|
+
'aria-label': t('edit.cancel'),
|
|
2906
|
+
},
|
|
2907
|
+
'×',
|
|
2908
|
+
),
|
|
2909
|
+
),
|
|
2910
|
+
React.createElement(
|
|
2911
|
+
'div',
|
|
2912
|
+
{ className: 'mopsErBody' },
|
|
2913
|
+
React.createElement('textarea', {
|
|
2914
|
+
className: 'mopsErText',
|
|
2915
|
+
ref: textRef,
|
|
2916
|
+
value: draft,
|
|
2917
|
+
rows: 6,
|
|
2918
|
+
readOnly: saving,
|
|
2919
|
+
disabled: textState !== 'ready',
|
|
2920
|
+
'aria-invalid': error || textState === 'error' ? 'true' : undefined,
|
|
2921
|
+
placeholder: textState === 'loading' ? t('edit.loading') : t('edit.placeholder'),
|
|
2922
|
+
onChange: e => setDraft(e.target.value),
|
|
2923
|
+
'aria-label': t('edit.title'),
|
|
2924
|
+
}),
|
|
2925
|
+
textState === 'error'
|
|
2926
|
+
? React.createElement(
|
|
2927
|
+
'div',
|
|
2928
|
+
{ className: 'mopsErError', role: 'alert' },
|
|
2929
|
+
loadError,
|
|
2930
|
+
' ',
|
|
2931
|
+
React.createElement('button', { type: 'button', className: 'mopsErBtn mopsErGhost', onClick: loadText }, t('edit.retry')),
|
|
2932
|
+
)
|
|
2933
|
+
: null,
|
|
2934
|
+
running ? React.createElement('div', { className: 'mopsErError', role: 'alert' }, t('edit.running')) : null,
|
|
2935
|
+
error ? React.createElement('div', { className: 'mopsErError', role: 'alert' }, error) : null,
|
|
2936
|
+
done ? React.createElement('div', { className: 'mopsErOk', role: 'status' }, done) : null,
|
|
2937
|
+
React.createElement('div', { className: 'mopsErHint' }, t('edit.replaceHint')),
|
|
2938
|
+
),
|
|
2939
|
+
React.createElement(
|
|
2940
|
+
'div',
|
|
2941
|
+
{ className: 'mopsErActions' },
|
|
2942
|
+
React.createElement(
|
|
2943
|
+
'button',
|
|
2944
|
+
{ type: 'button', className: 'mopsErBtn mopsErGhost', onClick: cancel, disabled: saving },
|
|
2945
|
+
t('edit.cancel'),
|
|
2946
|
+
),
|
|
2947
|
+
React.createElement(
|
|
2948
|
+
'button',
|
|
2949
|
+
{ type: 'button', className: 'mopsErBtn mopsErPrimary', onClick: send, disabled: !canSubmit },
|
|
2950
|
+
saving ? t('edit.sending') : t('edit.send'),
|
|
2951
|
+
),
|
|
2952
|
+
),
|
|
2953
|
+
),
|
|
2954
|
+
)
|
|
2955
|
+
}
|
|
2956
|
+
|
|
2399
2957
|
// --- 头部按钮 ---------------------------------------------------------------
|
|
2400
2958
|
|
|
2401
2959
|
// 0.3.0 分支双路径选择:0.2.0+ 官方 sessions.fork({atSeq}) 优先。
|
|
@@ -2777,29 +3335,61 @@ window.__ModuleLoader__.load({
|
|
|
2777
3335
|
* 2. 无选中 → 取整条但截断到 QUOTE_MAX_CHARS,并标注来源(seq / 角色)
|
|
2778
3336
|
*/
|
|
2779
3337
|
const QUOTE_MAX_CHARS = 600
|
|
3338
|
+
// 0.20.0(bug-hunt M-1):按 Unicode code point 截断,且尽量在换行/空格处收尾,
|
|
3339
|
+
// 避免把 emoji(代理对)或 markdown 围栏 ``` 从中间切坏。
|
|
3340
|
+
const clipQuote = raw => {
|
|
3341
|
+
const chars = Array.from(String(raw))
|
|
3342
|
+
if (chars.length <= QUOTE_MAX_CHARS) return chars.join('')
|
|
3343
|
+
let end = QUOTE_MAX_CHARS
|
|
3344
|
+
// 往前找最近的空白/换行边界(最多回退 40 个字符),不破坏单词
|
|
3345
|
+
for (let i = end; i > Math.max(0, end - 40); i--) {
|
|
3346
|
+
if (/[\s\n]/.test(chars[i - 1])) {
|
|
3347
|
+
end = i
|
|
3348
|
+
break
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3351
|
+
return chars.slice(0, end).join('') + '…'
|
|
3352
|
+
}
|
|
3353
|
+
// 0.20.0(bug-hunt H-2):把「选区归属」收紧,避免静默串味。
|
|
3354
|
+
// 旧实现算出 root 却从未使用,且用宽松的 [data-chat-flow-kind] 兜底
|
|
3355
|
+
// (会命中 turn-tail / tool / system 等通用块),只看 anchorNode,
|
|
3356
|
+
// 导致「选中 A 消息的一段、去点 B 消息的引用」会把 A 的文字当成 B 引用。
|
|
3357
|
+
// 现在要求 anchor 与 focus 落在**同一个** data-chat-node-key 容器内,
|
|
3358
|
+
// 且该容器必须存在;不满足就返回 null,回退到「截断+标注来源」路径。
|
|
3359
|
+
const ownerOf = node => {
|
|
3360
|
+
const el = node && (node.nodeType === 1 ? node : node.parentElement)
|
|
3361
|
+
return el && el.closest ? el.closest('[data-chat-node-key]') : null
|
|
3362
|
+
}
|
|
2780
3363
|
const selectionInMessage = () => {
|
|
2781
3364
|
try {
|
|
2782
3365
|
const sel = window.getSelection && window.getSelection()
|
|
2783
3366
|
if (!sel || sel.isCollapsed || sel.rangeCount === 0) return null
|
|
2784
3367
|
const text = String(sel.toString() || '').replace(/\s+$/g, '')
|
|
2785
3368
|
if (!text || text.length > QUOTE_MAX_CHARS * 2) return null
|
|
2786
|
-
|
|
2787
|
-
const
|
|
2788
|
-
|
|
2789
|
-
if (!
|
|
2790
|
-
return text
|
|
3369
|
+
const anchorOwner = ownerOf(sel.anchorNode)
|
|
3370
|
+
const focusOwner = ownerOf(sel.focusNode)
|
|
3371
|
+
// 两端必须属于同一个精确的 chat node;跨消息选区不引用(防串味)
|
|
3372
|
+
if (!anchorOwner || !focusOwner || anchorOwner !== focusOwner) return null
|
|
3373
|
+
return clipQuote(text)
|
|
2791
3374
|
} catch {
|
|
2792
3375
|
return null
|
|
2793
3376
|
}
|
|
2794
3377
|
}
|
|
2795
3378
|
const runQuote = () => {
|
|
2796
|
-
|
|
3379
|
+
// 0.20.0(bug-hunt M-2):来源标注放在 toast,不塞进 QuoteNode 正文。
|
|
3380
|
+
// QuoteNode.getTextContent() 是「模型可见文本」,正文里混入
|
|
3381
|
+
// '[引用自 seq N]' 会污染送进模型的引用内容。
|
|
3382
|
+
const finish = (ok, source) =>
|
|
3383
|
+
notifyDone(
|
|
3384
|
+
ok ? (source ? t('quote.doneWithSource', { seq: String(source) }) : t('quote.done')) : t('quote.unavailable'),
|
|
3385
|
+
ok ? 'ok' : 'warn',
|
|
3386
|
+
)
|
|
2797
3387
|
try {
|
|
2798
3388
|
if (!inputActions || typeof inputActions.insertQuote !== 'function') {
|
|
2799
3389
|
finish(false)
|
|
2800
3390
|
return
|
|
2801
3391
|
}
|
|
2802
|
-
const put = text => {
|
|
3392
|
+
const put = (text, source) => {
|
|
2803
3393
|
if (typeof text !== 'string' || text.trim() === '') {
|
|
2804
3394
|
finish(false)
|
|
2805
3395
|
return
|
|
@@ -2811,26 +3401,22 @@ window.__ModuleLoader__.load({
|
|
|
2811
3401
|
console.warn('[message-ops] insertQuote failed:', e)
|
|
2812
3402
|
ok = false
|
|
2813
3403
|
}
|
|
2814
|
-
finish(ok)
|
|
3404
|
+
finish(ok, ok ? source : null)
|
|
2815
3405
|
}
|
|
2816
|
-
// ①
|
|
3406
|
+
// ① 选中片段优先:正文就是选中的文字,无需来源标注
|
|
2817
3407
|
const selected = selectionInMessage()
|
|
2818
3408
|
if (selected != null) {
|
|
2819
|
-
put(selected)
|
|
3409
|
+
put(selected, null)
|
|
2820
3410
|
return
|
|
2821
3411
|
}
|
|
2822
|
-
// ②
|
|
2823
|
-
const withSource = full => {
|
|
2824
|
-
const clipped = full.length > QUOTE_MAX_CHARS ? full.slice(0, QUOTE_MAX_CHARS) + '…' : full
|
|
2825
|
-
return t('quote.sourcePrefix', { seq: String(seq) }) + '\n' + clipped
|
|
2826
|
-
}
|
|
3412
|
+
// ② 无选中:取整条但截断;来源只通过 toast 告知,不进引用正文
|
|
2827
3413
|
if (fullText != null && fullText !== '') {
|
|
2828
|
-
put(
|
|
3414
|
+
put(clipQuote(fullText), seq)
|
|
2829
3415
|
return
|
|
2830
3416
|
}
|
|
2831
3417
|
fetch('/api/message-ops/text?sessionId=' + encodeURIComponent(sessionId) + '&seq=' + encodeURIComponent(seq))
|
|
2832
3418
|
.then(r => (r.ok ? r.json() : null))
|
|
2833
|
-
.then(d => put(d && d.ok && typeof d.text === 'string' ?
|
|
3419
|
+
.then(d => put(d && d.ok && typeof d.text === 'string' ? clipQuote(d.text) : null, seq))
|
|
2834
3420
|
.catch(() => put(null))
|
|
2835
3421
|
} catch (e) {
|
|
2836
3422
|
notifyDone(t('errorPrefix') + (e && e.message ? e.message : String(e)), 'error')
|
|
@@ -3560,8 +4146,14 @@ window.__ModuleLoader__.load({
|
|
|
3560
4146
|
// 配不上(data-mops-unmatched)→ 禁用 + 说明原因,绝不留装饰按钮。
|
|
3561
4147
|
var syncEnabled = (block, btn) => {
|
|
3562
4148
|
if (!btn) return
|
|
3563
|
-
// 0.18.0
|
|
3564
|
-
|
|
4149
|
+
// 0.18.0/0.20.0:三种按钮各有自己的提示文案(编辑按钮不能写 revert 的 hint)
|
|
4150
|
+
// 0.21.0:回滚按钮统一用「带隐私提示」的 title —— syncEnabled 会在
|
|
4151
|
+
// 注入后重设 title,若这里仍用 slot.revert 会覆盖掉 ensureBtn 里的隐私提示。
|
|
4152
|
+
const hintKey = btn.classList.contains('mopsUserFork')
|
|
4153
|
+
? 'slot.forkHint'
|
|
4154
|
+
: btn.classList.contains('mopsUserEdit')
|
|
4155
|
+
? 'slot.editHint'
|
|
4156
|
+
: 'slot.revertPrivacyHint'
|
|
3565
4157
|
const ok = block.getAttribute('data-mops-seq')
|
|
3566
4158
|
if (ok) {
|
|
3567
4159
|
btn.disabled = false
|
|
@@ -3573,10 +4165,10 @@ window.__ModuleLoader__.load({
|
|
|
3573
4165
|
btn.setAttribute('data-mops-unmatched', '1')
|
|
3574
4166
|
}
|
|
3575
4167
|
}
|
|
3576
|
-
/** 块内全部插件按钮一起同步(回滚 / 分叉同一动作行)。 */
|
|
4168
|
+
/** 块内全部插件按钮一起同步(回滚 / 编辑 / 分叉同一动作行)。 */
|
|
3577
4169
|
var syncBlockButtons = block => {
|
|
3578
4170
|
if (!block || !block.querySelectorAll) return
|
|
3579
|
-
for (const b of block.querySelectorAll('.mopsUserRevert, .mopsUserFork')) syncEnabled(block, b)
|
|
4171
|
+
for (const b of block.querySelectorAll('.mopsUserRevert, .mopsUserEdit, .mopsUserFork')) syncEnabled(block, b)
|
|
3580
4172
|
}
|
|
3581
4173
|
var assignSeqs = (sid, cache, anchors) => {
|
|
3582
4174
|
const idx = cache && cache.idx
|
|
@@ -3769,7 +4361,8 @@ window.__ModuleLoader__.load({
|
|
|
3769
4361
|
btn = document.createElement('button')
|
|
3770
4362
|
btn.type = 'button'
|
|
3771
4363
|
btn.className = 'mopsUserRevert'
|
|
3772
|
-
|
|
4364
|
+
// 0.21.0:行内回滚按钮不经过面板确认框,隐私告知必须挂在这里(hover 可见)
|
|
4365
|
+
btn.title = __t('slot.revertPrivacyHint')
|
|
3773
4366
|
btn.setAttribute('aria-label', __t('slot.revert'))
|
|
3774
4367
|
btn.innerHTML =
|
|
3775
4368
|
'<svg width="14" height="14" 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>'
|
|
@@ -3815,11 +4408,96 @@ window.__ModuleLoader__.load({
|
|
|
3815
4408
|
syncEnabled(block, btn)
|
|
3816
4409
|
return btn
|
|
3817
4410
|
}
|
|
3818
|
-
|
|
4411
|
+
|
|
4412
|
+
/**
|
|
4413
|
+
* 0.20.0 铅笔编辑按钮:与回滚**同一动作行**,插在回滚与分叉之间。
|
|
4414
|
+
*
|
|
4415
|
+
* 语义 = 打开「编辑并重发」浮层(`EditResendOverlay`),编辑框里改文字;
|
|
4416
|
+
* **点「发送并回撤」那一刻**才回撤并重发。点按钮本身零写操作。
|
|
4417
|
+
*
|
|
4418
|
+
* 与 0.19.0 删掉的行内编辑的区别:那版只是把原文**回填 composer**
|
|
4419
|
+
* (`refillComposer`),跟回滚回填是同一件事,所以被判为重复入口而删除。
|
|
4420
|
+
* 这一版是独立编辑框 + 延迟回撤,是用户明确要求的产品行为。
|
|
4421
|
+
*
|
|
4422
|
+
* 图标取官方 `edit-outline` 几何(16 viewBox,填充几何 —— 与分叉图标同族写法)。
|
|
4423
|
+
*/
|
|
4424
|
+
var ensureEditBtn = block => {
|
|
4425
|
+
let host = block.querySelector('[class*="xzv4MW_actions"]')
|
|
4426
|
+
if (!host) {
|
|
4427
|
+
host = document.createElement('div')
|
|
4428
|
+
host.className = 'mopsUserActionsRow'
|
|
4429
|
+
block.appendChild(host)
|
|
4430
|
+
}
|
|
4431
|
+
const existing = host.querySelector('.mopsUserEdit')
|
|
4432
|
+
if (existing) return existing
|
|
4433
|
+
const btn = document.createElement('button')
|
|
4434
|
+
btn.type = 'button'
|
|
4435
|
+
btn.className = 'mopsUserEdit'
|
|
4436
|
+
btn.title = __t('slot.editHint')
|
|
4437
|
+
btn.setAttribute('aria-label', __t('slot.edit'))
|
|
4438
|
+
// 铅笔:官方 edit-outline 的几何(与分支图标同为 fill 几何,不用 stroke)
|
|
4439
|
+
btn.innerHTML =
|
|
4440
|
+
'<svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="none">' +
|
|
4441
|
+
'<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"/>' +
|
|
4442
|
+
'</svg>'
|
|
4443
|
+
btn.addEventListener('click', e => {
|
|
4444
|
+
e.preventDefault()
|
|
4445
|
+
e.stopPropagation()
|
|
4446
|
+
if (btn.disabled) return
|
|
4447
|
+
runUserEdit(btn, block)
|
|
4448
|
+
})
|
|
4449
|
+
host.appendChild(btn)
|
|
4450
|
+
syncEnabled(block, btn)
|
|
4451
|
+
return btn
|
|
4452
|
+
}
|
|
4453
|
+
|
|
4454
|
+
/**
|
|
4455
|
+
* 0.20.0 行内编辑入口:解析 seq → 派发 `EDIT_EVENT` 打开编辑浮层。
|
|
4456
|
+
*
|
|
4457
|
+
* 这一步**纯读**:`ensureAssign` / `fetchRows` 只读 `/api/message-ops/messages`,
|
|
4458
|
+
* 不发任何写请求、不改草稿。真正的写操作全在 `sendEditAndRevert` 里,
|
|
4459
|
+
* 由用户在编辑框里点「发送并回撤」才触发。
|
|
4460
|
+
*/
|
|
4461
|
+
var runUserEdit = (btn, block) => {
|
|
4462
|
+
const sid = __currentSessionId
|
|
4463
|
+
if (!sid) return
|
|
4464
|
+
btn.disabled = true
|
|
4465
|
+
Promise.resolve()
|
|
4466
|
+
.then(() => ensureAssign(sid))
|
|
4467
|
+
.then(() => fetchRows(sid))
|
|
4468
|
+
.then(cache => {
|
|
4469
|
+
const rows = cache && cache.rows
|
|
4470
|
+
const seq = Number(block.getAttribute('data-mops-seq'))
|
|
4471
|
+
const row = rows && rows.find(r => r.seq === seq)
|
|
4472
|
+
if (!row) {
|
|
4473
|
+
notifyDone(__t('errorPrefix') + __t('slot.editUnmatched'), 'error')
|
|
4474
|
+
return
|
|
4475
|
+
}
|
|
4476
|
+
if (!Number.isSafeInteger(seq) || seq < 0) {
|
|
4477
|
+
notifyDone(__t('slot.editUnmatched'), 'warn')
|
|
4478
|
+
return
|
|
4479
|
+
}
|
|
4480
|
+
// 裸 uuid 给 HTTP,带前缀的给 openSession 与草稿键
|
|
4481
|
+
window.dispatchEvent(
|
|
4482
|
+
new CustomEvent(EDIT_EVENT, {
|
|
4483
|
+
detail: { sessionId: bareSessionId(sid), rawSessionId: sid, seq: seq },
|
|
4484
|
+
}),
|
|
4485
|
+
)
|
|
4486
|
+
})
|
|
4487
|
+
.catch(reason => {
|
|
4488
|
+
notifyDone(__t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error')
|
|
4489
|
+
})
|
|
4490
|
+
.finally(() => {
|
|
4491
|
+
btn.disabled = false
|
|
4492
|
+
})
|
|
4493
|
+
}
|
|
4494
|
+
|
|
4495
|
+
// 三个按钮的顺序由 DOM 顺序决定:回滚在前(破坏性更高),编辑居中,分叉最后(非破坏)。
|
|
3819
4496
|
var ensureUserActions = block => {
|
|
3820
|
-
// 0.
|
|
3821
|
-
//
|
|
4497
|
+
// 0.20.0:铅笔回归,但语义变了 —— 独立编辑框 + 点「发送并回撤」才写,
|
|
4498
|
+
// 不再是 0.18.0 那种「只回填 composer」的伪编辑。
|
|
3822
4499
|
ensureBtn(block)
|
|
4500
|
+
ensureEditBtn(block)
|
|
3823
4501
|
ensureForkBtn(block)
|
|
3824
4502
|
}
|
|
3825
4503
|
// 0.9.7(P0-2 读合并):把 150/700/1600ms 三档并成**一次**真网络请求,
|
|
@@ -4009,11 +4687,11 @@ window.__ModuleLoader__.load({
|
|
|
4009
4687
|
// (宿主 .xzv4MW_actions 已定 height:28px,改小会撑裂行高)。
|
|
4010
4688
|
// · 无淡入动画(opencode 源码注释明写 "Hover actions show and hide
|
|
4011
4689
|
// at once, without a fade")—— 显隐完全交给宿主 [data-actions-reveal]。
|
|
4012
|
-
'.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}',
|
|
4013
|
-
'.mopsUserRevert svg,.mopsUserFork svg{width:14px;height:14px;display:block}',
|
|
4014
|
-
'.mopsUserRevert:hover,.mopsUserFork:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.12));color:var(--dsw-alias-label-secondary,#6b6b70)}',
|
|
4015
|
-
'.mopsUserRevert:disabled,.mopsUserFork:disabled{opacity:.4;cursor:default;background:transparent}',
|
|
4016
|
-
'.mopsUserRevert:focus-visible,.mopsUserFork:focus-visible{outline:2px solid var(--dsw-alias-border-l2,#b8b8b8);outline-offset:1px}',
|
|
4690
|
+
'.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}',
|
|
4691
|
+
'.mopsUserRevert svg,.mopsUserEdit svg,.mopsUserFork svg{width:14px;height:14px;display:block}',
|
|
4692
|
+
'.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)}',
|
|
4693
|
+
'.mopsUserRevert:disabled,.mopsUserEdit:disabled,.mopsUserFork:disabled{opacity:.4;cursor:default;background:transparent}',
|
|
4694
|
+
'.mopsUserRevert:focus-visible,.mopsUserEdit:focus-visible,.mopsUserFork:focus-visible{outline:2px solid var(--dsw-alias-border-l2,#b8b8b8);outline-offset:1px}',
|
|
4017
4695
|
// 0.18.0:用户反馈「点时间图标也会回撤」——根因不是绑定错误,而是
|
|
4018
4696
|
// 我们的按钮被 appendChild 到宿主 .actions 行末尾,而该行在
|
|
4019
4697
|
// data-clock="start"(用户消息)时第一个子元素就是**时间文本**:
|
|
@@ -4524,6 +5202,18 @@ window.__ModuleLoader__.load({
|
|
|
4524
5202
|
window.__MOPS_LEGACY_DIALOG === true ? OpsDialog : OpsPanel,
|
|
4525
5203
|
),
|
|
4526
5204
|
)
|
|
5205
|
+
// 0.20.0:编辑并重发浮层(同族模态,order 102 排在 OpsPanel 之后 —— 两者互斥打开)
|
|
5206
|
+
ctx.slots.inject(OVERLAY_SLOT, () =>
|
|
5207
|
+
ctx.slots.register(
|
|
5208
|
+
{
|
|
5209
|
+
name: OVERLAY_SLOT,
|
|
5210
|
+
id: EDIT_ID,
|
|
5211
|
+
order: 102,
|
|
5212
|
+
...(__locale ? { locale: NS } : {}),
|
|
5213
|
+
},
|
|
5214
|
+
EditResendOverlay,
|
|
5215
|
+
),
|
|
5216
|
+
)
|
|
4527
5217
|
installSidebarOps()
|
|
4528
5218
|
installUserRevertInjector()
|
|
4529
5219
|
}
|
|
@@ -4531,7 +5221,19 @@ window.__ModuleLoader__.load({
|
|
|
4531
5221
|
return {
|
|
4532
5222
|
apply,
|
|
4533
5223
|
inject: ['slots'],
|
|
4534
|
-
__test: {
|
|
5224
|
+
__test: {
|
|
5225
|
+
activityTransition,
|
|
5226
|
+
forkBoundaryBefore,
|
|
5227
|
+
isHostBranchButton,
|
|
5228
|
+
writeSessionDraft,
|
|
5229
|
+
HOST_BRANCH_ICON_ID,
|
|
5230
|
+
HOST_BRANCH_D_PREFIX,
|
|
5231
|
+
// 0.20.0:编辑并重发的编排层(可注入 deps 真执行断言时序)
|
|
5232
|
+
sendEditAndRevert,
|
|
5233
|
+
submitEditedText,
|
|
5234
|
+
EDIT_EVENT,
|
|
5235
|
+
EDIT_ID,
|
|
5236
|
+
},
|
|
4535
5237
|
}
|
|
4536
5238
|
},
|
|
4537
5239
|
})
|