@240xu/dsh-message-ops 0.19.0 → 0.20.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 +52 -0
- package/package.json +1 -1
- package/src/client.js +720 -37
package/README.md
CHANGED
|
@@ -1228,3 +1228,55 @@ 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` 全绿。
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -137,6 +137,27 @@ window.__ModuleLoader__.load({
|
|
|
137
137
|
'slot.forkHint': '复制此条之前的对话到新会话,并把此条原文放回新会话输入框',
|
|
138
138
|
'slot.forkDone': '已分叉:新会话 {id}',
|
|
139
139
|
'slot.forkUnavailable': '分叉不可用:会话正在运行,或宿主未提供 session/fork',
|
|
140
|
+
// 0.20.0:铅笔编辑框(用户消息动作行)。语义 = 先回撤再发,不是「只回填」。
|
|
141
|
+
'slot.edit': '编辑并重发',
|
|
142
|
+
'slot.editHint': '打开编辑框;点「发送并回撤」时才回撤此条及其后内容,再发出改后的文本',
|
|
143
|
+
'slot.editNoText': '这条消息没有可编辑的文本',
|
|
144
|
+
'slot.editUnmatched': '在日志里定位不到这条消息的 seq,暂时无法编辑',
|
|
145
|
+
'edit.title': '编辑并重发',
|
|
146
|
+
'edit.subtitle': '这条消息 · seq #{seq}',
|
|
147
|
+
'edit.loading': '正在读取原文…',
|
|
148
|
+
'edit.loadFail': '原文读取失败:',
|
|
149
|
+
'edit.retry': '重试',
|
|
150
|
+
'edit.placeholder': '编辑这条消息…',
|
|
151
|
+
'edit.cancel': '取消',
|
|
152
|
+
'edit.send': '发送并回撤',
|
|
153
|
+
'edit.sending': '回撤并发送中…',
|
|
154
|
+
'edit.empty': '内容为空,无法发送',
|
|
155
|
+
'edit.failed': '回撤失败:',
|
|
156
|
+
'edit.done': '已回撤',
|
|
157
|
+
'edit.doneSubmitted': '已回撤,改后的消息已提交',
|
|
158
|
+
'edit.manual': '已回撤,改后的文本已放进输入框——请按回车发送',
|
|
159
|
+
'edit.running': '会话正在运行:需先停止会话再编辑重发',
|
|
160
|
+
'edit.replaceHint': '发送会先回撤此条及其之后的全部可见消息,再把改后的文本作为新消息发出;日志仍保留,可从回撤区重放。',
|
|
140
161
|
'toast.openNew': '打开新会话',
|
|
141
162
|
'fork.official': '分支完成:新会话 {id}',
|
|
142
163
|
'fork.unavailable': '官方分支不可用:通常是因为会话正在运行,请先停止会话后重试。分支功能由 dsh 内置的 session/fork 提供。',
|
|
@@ -164,6 +185,7 @@ window.__ModuleLoader__.load({
|
|
|
164
185
|
'quote.done': '已引用到输入框',
|
|
165
186
|
'quote.unavailable': '引用不可用(输入框不可写或无全文)',
|
|
166
187
|
'quote.sourcePrefix': '引用自 seq {seq}',
|
|
188
|
+
'quote.doneWithSource': '已引用(来自 seq {seq})',
|
|
167
189
|
'undo.label': '回滚上一条消息',
|
|
168
190
|
'undo.desc': '移除最后一条用户消息,原文回填输入框',
|
|
169
191
|
'undo.done.undo': '已回滚上一条消息',
|
|
@@ -263,6 +285,28 @@ window.__ModuleLoader__.load({
|
|
|
263
285
|
'slot.forkHint': 'Copies the conversation above this message into a new session and puts this message back in the new composer',
|
|
264
286
|
'slot.forkDone': 'Branched: new session {id}',
|
|
265
287
|
'slot.forkUnavailable': 'Branch unavailable: the session is running, or the host provides no session/fork',
|
|
288
|
+
// 0.20.0: pencil edit overlay on the user-message action row (revert-then-send).
|
|
289
|
+
'slot.edit': 'Edit and resend',
|
|
290
|
+
'slot.editHint': 'Opens the editor; nothing is reverted until you press "Send and revert"',
|
|
291
|
+
'slot.editNoText': 'This message has no text to edit',
|
|
292
|
+
'slot.editUnmatched': 'Cannot locate this message seq in the log, so it cannot be edited yet',
|
|
293
|
+
'edit.title': 'Edit and resend',
|
|
294
|
+
'edit.subtitle': 'This message · seq #{seq}',
|
|
295
|
+
'edit.loading': 'Loading the original text…',
|
|
296
|
+
'edit.loadFail': 'Could not load the original text: ',
|
|
297
|
+
'edit.retry': 'Retry',
|
|
298
|
+
'edit.placeholder': 'Edit this message…',
|
|
299
|
+
'edit.cancel': 'Cancel',
|
|
300
|
+
'edit.send': 'Send and revert',
|
|
301
|
+
'edit.sending': 'Reverting and sending…',
|
|
302
|
+
'edit.empty': 'Nothing to send — the text is empty',
|
|
303
|
+
'edit.failed': 'Revert failed: ',
|
|
304
|
+
'edit.done': 'Reverted',
|
|
305
|
+
'edit.doneSubmitted': 'Reverted; the edited message has been submitted',
|
|
306
|
+
'edit.manual': 'Reverted; the edited text is in the composer — press Enter to send',
|
|
307
|
+
'edit.running': 'The session is running: stop it before editing and resending',
|
|
308
|
+
'edit.replaceHint':
|
|
309
|
+
'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
310
|
'toast.openNew': 'Open new session',
|
|
267
311
|
'fork.official': 'Branched (official fork): new session {id}',
|
|
268
312
|
'fork.unavailable':
|
|
@@ -291,6 +335,7 @@ window.__ModuleLoader__.load({
|
|
|
291
335
|
'quote.done': 'Quoted into composer',
|
|
292
336
|
'quote.unavailable': 'Quote unavailable (composer locked or no full text)',
|
|
293
337
|
'quote.sourcePrefix': 'Quoted from seq {seq}',
|
|
338
|
+
'quote.doneWithSource': 'Quoted (from seq {seq})',
|
|
294
339
|
'undo.label': 'Undo last message',
|
|
295
340
|
'undo.desc': 'Remove the last user message and put its original text back into the composer',
|
|
296
341
|
'undo.done.undo': 'Undid the last message',
|
|
@@ -1062,7 +1107,7 @@ window.__ModuleLoader__.load({
|
|
|
1062
1107
|
'.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
1108
|
'@keyframes mopsFade{from{opacity:0}to{opacity:1}}',
|
|
1064
1109
|
'@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-
|
|
1110
|
+
'.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
1111
|
'@media(prefers-reduced-motion:reduce){.mopsPanelScrim,.mopsPanel{animation:none}}',
|
|
1067
1112
|
'.mopsPanel *{box-sizing:border-box}',
|
|
1068
1113
|
'.mopsPanel button{font:inherit;color:inherit;border-radius:0}',
|
|
@@ -1080,7 +1125,7 @@ window.__ModuleLoader__.load({
|
|
|
1080
1125
|
'.mopsSearch:focus{border-color:var(--dsw-alias-brand-primary,#4d6bfe)}',
|
|
1081
1126
|
'.mopsChips{display:flex;gap:6px;padding:0 18px 10px;flex-wrap:wrap;align-items:center}',
|
|
1082
1127
|
'.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-
|
|
1128
|
+
'.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
1129
|
'.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
1130
|
'.mopsToggle input{accent-color:var(--dsw-alias-brand-primary,#4d6bfe)}',
|
|
1086
1131
|
'.mopsList{flex:1;min-height:0;overflow-y:auto;position:relative;border-top:1px solid var(--dsw-alias-border-l1,#efefef)}',
|
|
@@ -1101,15 +1146,15 @@ window.__ModuleLoader__.load({
|
|
|
1101
1146
|
'.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
1147
|
'.mopsDetailHint{padding:10px 0 14px;color:var(--dsw-alias-label-tertiary,#8a8a8e);font-size:12px}',
|
|
1103
1148
|
'.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-
|
|
1149
|
+
'.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
1150
|
'.mopsImpactTitle{font-size:12px;font-weight:600}',
|
|
1106
1151
|
'.mopsImpact{font-size:11px;line-height:1.5;color:var(--dsw-alias-label-secondary,#6b6b70)}',
|
|
1107
1152
|
'.mopsAction{height:30px;padding:0 10px;border:1px solid var(--dsw-alias-border-l2,#cfcfcf);background:transparent;cursor:pointer;font-size:11px}',
|
|
1108
1153
|
'.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-
|
|
1154
|
+
'.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
1155
|
'.mopsAction.danger{border-color:var(--dsw-alias-state-error-primary,#c63b32);color:var(--dsw-alias-state-error-primary,#c63b32)}',
|
|
1111
1156
|
'.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-
|
|
1157
|
+
'.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
1158
|
'.mopsCount{font-size:10px;color:var(--dsw-alias-label-tertiary,#8a8a8e)}',
|
|
1114
1159
|
'.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
1160
|
'.mopsDanger:hover{background:rgba(198,59,50,.06)}',
|
|
@@ -1117,7 +1162,7 @@ window.__ModuleLoader__.load({
|
|
|
1117
1162
|
'.mopsBanner.warn{color:var(--dsw-alias-state-warn-primary,#9a6500);background:rgba(154,101,0,.06)}',
|
|
1118
1163
|
'.mopsBanner.err{color:var(--dsw-alias-state-error-primary,#c63b32);background:rgba(198,59,50,.06)}',
|
|
1119
1164
|
'.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-
|
|
1165
|
+
'.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
1166
|
'.mopsConfirm h3{margin:0;font-size:15px}',
|
|
1122
1167
|
'.mopsConfirm p{margin:0;font-size:12px;color:var(--dsw-alias-label-secondary,#6b6b70)}',
|
|
1123
1168
|
'.mopsConfirm p.mopsImpact{font-size:11px}',
|
|
@@ -1827,6 +1872,11 @@ window.__ModuleLoader__.load({
|
|
|
1827
1872
|
|
|
1828
1873
|
const pickedLive = picked ? messages.find(m => m.seq === picked.seq) || picked : null
|
|
1829
1874
|
const canAct = !busy && !target.running && pickedLive && !pickedLive.shadowed
|
|
1875
|
+
// 0.20.0(bug-hunt H-1 / M-3):AI 消息回滚已在 0.19.0 从动作区下线
|
|
1876
|
+
// (用户明确要求「回撤是用户消息那边的用处」)。面板不能留一个
|
|
1877
|
+
// 「能回滚 AI 消息却静默不回填」的旁路,故回滚按钮同样限定为用户消息。
|
|
1878
|
+
// 删除按钮仍用 canAct —— 删单条 AI 消息是合理能力,不受此限。
|
|
1879
|
+
const canRevert = canAct && pickedLive && pickedLive.role === 'user'
|
|
1830
1880
|
const visibleCount = messages.filter(m => m.role !== 'system' && m.visible && !m.shadowed).length
|
|
1831
1881
|
const shadowedCount = messages.filter(m => m.role !== 'system' && m.shadowed).length
|
|
1832
1882
|
const totalCount = messages.filter(m => m.role !== 'system').length
|
|
@@ -2134,7 +2184,7 @@ window.__ModuleLoader__.load({
|
|
|
2134
2184
|
{
|
|
2135
2185
|
type: 'button',
|
|
2136
2186
|
className: 'mopsAction primary',
|
|
2137
|
-
disabled: !
|
|
2187
|
+
disabled: !canRevert || !!confirmAction,
|
|
2138
2188
|
ref: revertBtnRef,
|
|
2139
2189
|
onClick: () => setConfirmAction('revert'),
|
|
2140
2190
|
title: t('panel.revertHint'),
|
|
@@ -2396,6 +2446,498 @@ window.__ModuleLoader__.load({
|
|
|
2396
2446
|
)
|
|
2397
2447
|
}
|
|
2398
2448
|
|
|
2449
|
+
// --- 0.20.0 · 「编辑并重发」的编排层 ----------------------------------------
|
|
2450
|
+
//
|
|
2451
|
+
// 语义(用户明确要求 + lead 决断;**不是** opencode 的立即回填,也**不是** fork):
|
|
2452
|
+
//
|
|
2453
|
+
// 点铅笔 → 只读:GET /text 取全文,在编辑框里改文字。零写操作。
|
|
2454
|
+
// 点「取消」/ Esc / 点遮罩 → 只清本地 state。零 fetch、零写盘、零 openSession。
|
|
2455
|
+
// 点「发送并回撤」这一刻才写,顺序严格如下:
|
|
2456
|
+
// ① POST /api/message-ops/revert { sessionId, seq }
|
|
2457
|
+
// 失败(含 409 运行中)→ 保留编辑框与用户已输入的文本,报错,不再往下走
|
|
2458
|
+
// ② markRowsShadowedFrom(seq) —— 与其它回滚入口共用同一个防 409 护栏
|
|
2459
|
+
// ③ writeSessionDraft(rawSessionId) —— 合并写入,保住 view 偏好;这是权威值
|
|
2460
|
+
// ④ setDraft + persistDraft —— 尽力同步「活着的」编辑器
|
|
2461
|
+
// ⑤ emitChanged + openSessionById —— 视图重建;remount 时从 localStorage 读回同一份草稿
|
|
2462
|
+
// ⑥ 有界等待重挂后 submit() 一次 —— 不可用则明确提示「请按回车发送」,绝不静默
|
|
2463
|
+
//
|
|
2464
|
+
// 为什么 ③ 必须在 ⑤ 之前:openSession 会卸载并重挂编辑器,新挂载走
|
|
2465
|
+
// `readConversationDraft(sid)` 从 localStorage 初始化。先落盘才是无竞态路径
|
|
2466
|
+
// (0.11.3 / 0.14.0 两次事故的同一个教训,见 refillComposer 注释)。
|
|
2467
|
+
//
|
|
2468
|
+
// 为什么不用 fork:「分叉」按钮的语义是源会话一字不动。同一个「编辑」动作若在
|
|
2469
|
+
// 铅笔里改写源会话、在分叉里保留源会话,就是两套相反语义 —— 用户无法预期。
|
|
2470
|
+
const EDIT_EVENT = 'dsh-message-ops:edit'
|
|
2471
|
+
const EDIT_ID = 'message-ops-edit-resend'
|
|
2472
|
+
const EDIT_STYLE_ID = 'dsh-message-ops-edit-style'
|
|
2473
|
+
/** 等待 composer 重挂的最大轮数 / 间隔:有界,不无限自旋。 */
|
|
2474
|
+
const EDIT_SUBMIT_ATTEMPTS = 8
|
|
2475
|
+
const EDIT_SUBMIT_INTERVAL_MS = 120
|
|
2476
|
+
|
|
2477
|
+
/**
|
|
2478
|
+
* 有界等待 composer 重挂后提交**一次**。
|
|
2479
|
+
*
|
|
2480
|
+
* 判据:`__inputActions` 换成新对象 = 宿主重挂了编辑器(openSession 之后必然发生)。
|
|
2481
|
+
* 到上限仍没换(例如视图没重建的内联路径)就用当前这个提交一次 —— 宁可多一条
|
|
2482
|
+
* 兜底提示,也不要无限等。**只提交一次**:重复 submit 会发出两条消息,比失败更糟。
|
|
2483
|
+
*
|
|
2484
|
+
* @param text - 要提交的文本
|
|
2485
|
+
* @param options - { attempts, intervalMs },测试注入更小值
|
|
2486
|
+
* @returns Promise<boolean> 是否成功调用了宿主 submit
|
|
2487
|
+
*/
|
|
2488
|
+
function submitEditedText(text, options) {
|
|
2489
|
+
const opts = options || {}
|
|
2490
|
+
const attempts = Number.isSafeInteger(opts.attempts) && opts.attempts > 0 ? opts.attempts : EDIT_SUBMIT_ATTEMPTS
|
|
2491
|
+
const intervalMs = Number.isSafeInteger(opts.intervalMs) && opts.intervalMs >= 0 ? opts.intervalMs : EDIT_SUBMIT_INTERVAL_MS
|
|
2492
|
+
const before = __inputActions
|
|
2493
|
+
return new Promise(resolve => {
|
|
2494
|
+
let n = 0
|
|
2495
|
+
const tick = () => {
|
|
2496
|
+
n += 1
|
|
2497
|
+
const ia = __inputActions
|
|
2498
|
+
const usable = ia && typeof ia.submit === 'function' && typeof ia.setDraft === 'function'
|
|
2499
|
+
const remounted = !!ia && ia !== before
|
|
2500
|
+
if (usable && (remounted || n >= attempts)) {
|
|
2501
|
+
try {
|
|
2502
|
+
// 先确保编辑器里就是这段文字:重挂后 draft 已从 localStorage 读回,
|
|
2503
|
+
// 但内联路径(视图没重建)里编辑器仍是旧内容,必须显式覆盖。
|
|
2504
|
+
ia.setDraft(text)
|
|
2505
|
+
if (typeof ia.persistDraft === 'function') ia.persistDraft()
|
|
2506
|
+
ia.submit()
|
|
2507
|
+
resolve(true)
|
|
2508
|
+
} catch (e) {
|
|
2509
|
+
console.warn('[message-ops] submit failed:', e)
|
|
2510
|
+
resolve(false)
|
|
2511
|
+
}
|
|
2512
|
+
return
|
|
2513
|
+
}
|
|
2514
|
+
if (n >= attempts) {
|
|
2515
|
+
resolve(false)
|
|
2516
|
+
return
|
|
2517
|
+
}
|
|
2518
|
+
setTimeout(tick, intervalMs)
|
|
2519
|
+
}
|
|
2520
|
+
setTimeout(tick, intervalMs)
|
|
2521
|
+
})
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
/**
|
|
2525
|
+
* 「发送并回撤」的唯一编排实现。
|
|
2526
|
+
*
|
|
2527
|
+
* 抽成具名函数(而不是埋在组件里)有两个理由:
|
|
2528
|
+
* 1. 时序是本功能的核心契约,必须能被测试**真执行**断言
|
|
2529
|
+
* (revert 失败 → 不写草稿、不 openSession、用户文本保留)。
|
|
2530
|
+
* 2. 组件只负责 UI 状态;失败时「保留文本」由调用方按返回值决定。
|
|
2531
|
+
*
|
|
2532
|
+
* @param options - { sessionId, rawSessionId, seq, text, deps }
|
|
2533
|
+
* sessionId 裸 uuid(给 HTTP)
|
|
2534
|
+
* rawSessionId `session-` 前缀(给 openSession 与草稿键);缺省从 sessionId 补
|
|
2535
|
+
* deps 可注入的副作用集合(测试用);缺省取真实实现
|
|
2536
|
+
* @returns Promise<{ok, stage, submitted?, persisted?, reason?, status?}>
|
|
2537
|
+
* stage: 'validate' | 'revert' | 'done'
|
|
2538
|
+
*/
|
|
2539
|
+
async function sendEditAndRevert(options) {
|
|
2540
|
+
const opts = options || {}
|
|
2541
|
+
const sessionId = String(opts.sessionId || '').trim()
|
|
2542
|
+
// 草稿键与 openSession 都必须用带 `session-` 前缀的写法:
|
|
2543
|
+
// 裸 uuid 会让宿主 `sessions.retain` 抛 `unknown session` 并被外层 catch 静默吞掉
|
|
2544
|
+
// (0.9.6 事故,见 afterWrite 注释)。这里显式补齐,不假设调用方传对。
|
|
2545
|
+
const rawSessionId = String(opts.rawSessionId || '').trim() || (sessionId ? 'session-' + sessionId : '')
|
|
2546
|
+
const seq = opts.seq
|
|
2547
|
+
const text = typeof opts.text === 'string' ? opts.text : ''
|
|
2548
|
+
const deps = opts.deps || {}
|
|
2549
|
+
// ⚠️ 这里只先解析 fetch:revert 失败时**不得**触碰任何草稿/视图副作用,
|
|
2550
|
+
// 连「解析实现」都不该发生在失败之前(解析顺序 = 语义顺序)。
|
|
2551
|
+
const doFetch = deps.fetch || fetch
|
|
2552
|
+
|
|
2553
|
+
if (!sessionId || !Number.isSafeInteger(seq) || seq < 0) return { ok: false, stage: 'validate', reason: 'invalid target' }
|
|
2554
|
+
if (text.trim() === '') return { ok: false, stage: 'validate', reason: 'empty' }
|
|
2555
|
+
|
|
2556
|
+
// ① 回撤:失败就**什么都不做**(不写草稿、不重建视图、不动编辑器)
|
|
2557
|
+
let res = null
|
|
2558
|
+
let data = null
|
|
2559
|
+
try {
|
|
2560
|
+
res = await doFetch('/api/message-ops/revert', {
|
|
2561
|
+
method: 'POST',
|
|
2562
|
+
headers: { 'content-type': 'application/json' },
|
|
2563
|
+
body: JSON.stringify({ sessionId, seq }),
|
|
2564
|
+
})
|
|
2565
|
+
data = await res.json().catch(() => null)
|
|
2566
|
+
} catch (e) {
|
|
2567
|
+
return { ok: false, stage: 'revert', reason: e && e.message ? e.message : String(e) }
|
|
2568
|
+
}
|
|
2569
|
+
if (!res || !res.ok || !data || data.ok !== true) {
|
|
2570
|
+
return {
|
|
2571
|
+
ok: false,
|
|
2572
|
+
stage: 'revert',
|
|
2573
|
+
status: res ? res.status : 0,
|
|
2574
|
+
reason: (data && data.error) || 'HTTP ' + (res ? res.status : '?'),
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
|
|
2578
|
+
// ── 回撤已成功 ── 从这里开始才解析并使用其余副作用 ──────────────────────
|
|
2579
|
+
const doWrite = deps.writeSessionDraft || writeSessionDraft
|
|
2580
|
+
const doRead = deps.readSessionDraft || readSessionDraft
|
|
2581
|
+
const markShadowed = deps.markRowsShadowedFrom || markRowsShadowedFrom
|
|
2582
|
+
const doSetDraft = deps.setDraft || (v => (__inputActions && __inputActions.setDraft ? __inputActions.setDraft(v) : false))
|
|
2583
|
+
const doPersistDraft =
|
|
2584
|
+
deps.persistDraft || (() => (__inputActions && __inputActions.persistDraft ? __inputActions.persistDraft() : false))
|
|
2585
|
+
const doEmitChanged = deps.emitChanged || emitChanged
|
|
2586
|
+
const doOpenSession = deps.openSessionById || openSessionById
|
|
2587
|
+
const doSubmit = deps.submitEdited || submitEditedText
|
|
2588
|
+
|
|
2589
|
+
// ② 防 409 护栏:本地缓存里 >= seq 的行立刻标成已遮蔽(与 runUserRevert/runUndo 同一函数)
|
|
2590
|
+
try {
|
|
2591
|
+
markShadowed(seq)
|
|
2592
|
+
} catch (e) {
|
|
2593
|
+
console.warn('[message-ops] markRowsShadowedFrom failed:', e)
|
|
2594
|
+
}
|
|
2595
|
+
|
|
2596
|
+
// ③ 权威落盘(合并写,保住 view 偏好)
|
|
2597
|
+
let persisted = false
|
|
2598
|
+
try {
|
|
2599
|
+
persisted = doWrite(rawSessionId, text) === true
|
|
2600
|
+
} catch (e) {
|
|
2601
|
+
console.warn('[message-ops] writeSessionDraft failed:', e)
|
|
2602
|
+
}
|
|
2603
|
+
// 回读校验:只有读到**不同的非空值**才算落盘失败(读不到时保持原判断,不误判)
|
|
2604
|
+
if (persisted && typeof doRead === 'function') {
|
|
2605
|
+
try {
|
|
2606
|
+
const stored = doRead(rawSessionId)
|
|
2607
|
+
if (stored != null && stored !== text) persisted = false
|
|
2608
|
+
} catch (e) {
|
|
2609
|
+
/* 读回失败不推翻写入结果 */
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2613
|
+
// ④ 尽力同步活着的编辑器(重挂路径靠 ③;这里只覆盖「视图没重建」的内联路径)
|
|
2614
|
+
try {
|
|
2615
|
+
doSetDraft(text)
|
|
2616
|
+
} catch (e) {
|
|
2617
|
+
console.warn('[message-ops] setDraft failed:', e)
|
|
2618
|
+
}
|
|
2619
|
+
try {
|
|
2620
|
+
doPersistDraft()
|
|
2621
|
+
} catch (e) {
|
|
2622
|
+
/* persistDraft 缺席不阻断 —— ③ 已经落盘 */
|
|
2623
|
+
}
|
|
2624
|
+
|
|
2625
|
+
// ⑤ 通知 + 重建视图(rawSessionId 带前缀;裸 uuid 会抛 unknown session)
|
|
2626
|
+
try {
|
|
2627
|
+
doEmitChanged()
|
|
2628
|
+
} catch (e) {
|
|
2629
|
+
/* 广播失败不阻断写结果 */
|
|
2630
|
+
}
|
|
2631
|
+
try {
|
|
2632
|
+
doOpenSession(rawSessionId)
|
|
2633
|
+
} catch (e) {
|
|
2634
|
+
console.warn('[message-ops] openSession failed:', e)
|
|
2635
|
+
}
|
|
2636
|
+
|
|
2637
|
+
// ⑥ 有界等待重挂后提交一次;不可用 → 调用方提示手动回车
|
|
2638
|
+
let submitted = false
|
|
2639
|
+
try {
|
|
2640
|
+
submitted = (await doSubmit(text)) === true
|
|
2641
|
+
} catch (e) {
|
|
2642
|
+
console.warn('[message-ops] submitEdited failed:', e)
|
|
2643
|
+
}
|
|
2644
|
+
return { ok: true, stage: 'done', submitted: submitted === true, persisted: persisted }
|
|
2645
|
+
}
|
|
2646
|
+
|
|
2647
|
+
/**
|
|
2648
|
+
* 编辑框样式:颜色全走 `--dsw-alias-*`,圆角全走 `--dsw-radius-*`,无裸 hex。
|
|
2649
|
+
*
|
|
2650
|
+
* ⚠️ 只用**已确认存在**的 token:`--dsw-alias-label-error` 与 `--dsw-alias-bg-layer-1`
|
|
2651
|
+
* 在宿主 theme 包里并不存在(别处有误用),错误色一律用 `--dsw-alias-state-error-primary`,
|
|
2652
|
+
* 背景用 `--dsw-alias-bg-layer-1`。全部带 fallback,深色模式不吃亏。
|
|
2653
|
+
*/
|
|
2654
|
+
function ensureEditStyle() {
|
|
2655
|
+
try {
|
|
2656
|
+
if (typeof document === 'undefined' || !document.head) return
|
|
2657
|
+
if (document.getElementById(EDIT_STYLE_ID)) return
|
|
2658
|
+
const tag = document.createElement('style')
|
|
2659
|
+
tag.id = EDIT_STYLE_ID
|
|
2660
|
+
tag.textContent = [
|
|
2661
|
+
'.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}',
|
|
2662
|
+
'@keyframes mopsErFade{from{opacity:0}to{opacity:1}}',
|
|
2663
|
+
'@keyframes mopsErRise{from{opacity:0;transform:translateY(8px) scale(.985)}to{opacity:1;transform:none}}',
|
|
2664
|
+
'@media(prefers-reduced-motion:reduce){.mopsErScrim,.mopsErPanel{animation:none}}',
|
|
2665
|
+
'.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)}',
|
|
2666
|
+
'.mopsErPanel *{box-sizing:border-box}',
|
|
2667
|
+
'.mopsErHead{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;flex:none}',
|
|
2668
|
+
'.mopsErTitle{font-size:15px;font-weight:600;line-height:22px}',
|
|
2669
|
+
'.mopsErSub{font-size:11px;line-height:16px;color:var(--dsw-alias-label-tertiary,#8a8a8e);margin-top:2px;font-variant-numeric:tabular-nums}',
|
|
2670
|
+
'.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}',
|
|
2671
|
+
'.mopsErClose:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.12));color:var(--dsw-alias-label-primary,#0f1115)}',
|
|
2672
|
+
'.mopsErClose:disabled{opacity:.4;cursor:default}',
|
|
2673
|
+
'.mopsErBody{flex:1;min-height:0;display:flex;flex-direction:column;gap:8px}',
|
|
2674
|
+
'.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}',
|
|
2675
|
+
'.mopsErText::placeholder{color:var(--dsw-alias-label-tertiary,#8a8a8e)}',
|
|
2676
|
+
'.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)}',
|
|
2677
|
+
'.mopsErText:disabled{opacity:.6;cursor:progress}',
|
|
2678
|
+
'.mopsErText[aria-invalid="true"]{border-color:var(--dsw-alias-state-error-primary,#c63b32)}',
|
|
2679
|
+
'.mopsErHint{font-size:11px;line-height:17px;color:var(--dsw-alias-label-tertiary,#8a8a8e)}',
|
|
2680
|
+
'.mopsErError{font-size:12px;line-height:18px;color:var(--dsw-alias-state-error-primary,#c63b32);overflow-wrap:anywhere}',
|
|
2681
|
+
'.mopsErOk{font-size:12px;line-height:18px;color:var(--dsw-alias-state-success-primary,#2f7d4a)}',
|
|
2682
|
+
'.mopsErActions{flex:none;display:flex;gap:8px;justify-content:flex-end;flex-wrap:wrap}',
|
|
2683
|
+
'.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}',
|
|
2684
|
+
'.mopsErGhost{color:var(--dsw-alias-label-secondary,#6b6b70);background:transparent}',
|
|
2685
|
+
'.mopsErGhost:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.12));color:var(--dsw-alias-label-primary,#0f1115)}',
|
|
2686
|
+
'.mopsErPrimary{background:var(--dsw-alias-button-primary-fill,#2b2b2e);color:var(--dsw-alias-label-primary-foreground,#fff)}',
|
|
2687
|
+
'.mopsErPrimary:hover:not(:disabled){background:var(--dsw-alias-button-primary-hover,#3a3a3e)}',
|
|
2688
|
+
'.mopsErBtn:disabled{opacity:.5;cursor:not-allowed}',
|
|
2689
|
+
'.mopsErBtn:focus-visible,.mopsErClose:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4d6bfe);outline-offset:1px}',
|
|
2690
|
+
'@media(max-width:760px){.mopsErScrim{padding:0}.mopsErPanel{width:100%;height:100%;max-height:100%;border:0;border-radius:0}}',
|
|
2691
|
+
].join('')
|
|
2692
|
+
document.head.appendChild(tag)
|
|
2693
|
+
} catch (e) {
|
|
2694
|
+
/* 样式注入失败不影响功能 */
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2697
|
+
|
|
2698
|
+
/**
|
|
2699
|
+
* 「编辑并重发」浮层(`shell.overlay` 槽,与本插件 OpsPanel 同族)。
|
|
2700
|
+
*
|
|
2701
|
+
* 常驻挂载、内部 state 控制显隐 —— 与 OpsPanel 完全同款(list 槽的条目没有
|
|
2702
|
+
* 「开关」概念,只能靠组件自身状态)。未打开时返回 null。
|
|
2703
|
+
*/
|
|
2704
|
+
function EditResendOverlay(props) {
|
|
2705
|
+
const { sessionId, useSessions } = props
|
|
2706
|
+
const t = (props && props.t) || __t
|
|
2707
|
+
useLocaleRevision()
|
|
2708
|
+
if (sessionId) __currentSessionId = sessionId
|
|
2709
|
+
const sessions = useSessions ? useSessions(s => s) : undefined
|
|
2710
|
+
const [target, setTarget] = useState(null) // { sessionId, rawSessionId, seq }
|
|
2711
|
+
const [draft, setDraft] = useState('')
|
|
2712
|
+
const [textState, setTextState] = useState('idle') // idle|loading|ready|error
|
|
2713
|
+
const [loadError, setLoadError] = useState(null)
|
|
2714
|
+
const [saving, setSaving] = useState(false)
|
|
2715
|
+
const [error, setError] = useState(null)
|
|
2716
|
+
const [done, setDone] = useState('')
|
|
2717
|
+
const textRef = useRef(null)
|
|
2718
|
+
const reqRef = useRef(0)
|
|
2719
|
+
|
|
2720
|
+
useEffect(() => {
|
|
2721
|
+
ensureEditStyle()
|
|
2722
|
+
const handler = e => {
|
|
2723
|
+
const d = e && e.detail ? e.detail : {}
|
|
2724
|
+
if (!d.sessionId || !Number.isSafeInteger(d.seq)) return
|
|
2725
|
+
reqRef.current += 1
|
|
2726
|
+
setTarget({ sessionId: String(d.sessionId), rawSessionId: d.rawSessionId || d.sessionId, seq: d.seq })
|
|
2727
|
+
setDraft('')
|
|
2728
|
+
setTextState('loading')
|
|
2729
|
+
setLoadError(null)
|
|
2730
|
+
setError(null)
|
|
2731
|
+
setDone('')
|
|
2732
|
+
}
|
|
2733
|
+
window.addEventListener(EDIT_EVENT, handler)
|
|
2734
|
+
return () => window.removeEventListener(EDIT_EVENT, handler)
|
|
2735
|
+
}, [])
|
|
2736
|
+
|
|
2737
|
+
const loadText = useCallback(() => {
|
|
2738
|
+
if (!target) return
|
|
2739
|
+
const req = ++reqRef.current
|
|
2740
|
+
const sid = target.sessionId
|
|
2741
|
+
setTextState('loading')
|
|
2742
|
+
setLoadError(null)
|
|
2743
|
+
fetch('/api/message-ops/text?sessionId=' + encodeURIComponent(sid) + '&seq=' + encodeURIComponent(target.seq))
|
|
2744
|
+
.then(res =>
|
|
2745
|
+
res
|
|
2746
|
+
.json()
|
|
2747
|
+
.catch(() => null)
|
|
2748
|
+
.then(data => ({ res, data })),
|
|
2749
|
+
)
|
|
2750
|
+
.then(({ res, data }) => {
|
|
2751
|
+
if (req !== reqRef.current) return
|
|
2752
|
+
if (!res.ok || !data || data.ok !== true) throw new Error((data && data.error) || 'HTTP ' + res.status)
|
|
2753
|
+
if (typeof data.text !== 'string' || data.text === '') throw new Error(t('slot.editNoText'))
|
|
2754
|
+
// ⚠️ 只认 /text 的全文:绝不拿 160 字 snippet 冒充原文
|
|
2755
|
+
// (service 侧硬截断,见 session-file.js 的 snippet.slice(0,160))
|
|
2756
|
+
setDraft(data.text)
|
|
2757
|
+
setTextState('ready')
|
|
2758
|
+
})
|
|
2759
|
+
.catch(reason => {
|
|
2760
|
+
if (req !== reqRef.current) return
|
|
2761
|
+
setLoadError(t('edit.loadFail') + (reason && reason.message ? reason.message : String(reason)))
|
|
2762
|
+
setTextState('error')
|
|
2763
|
+
})
|
|
2764
|
+
}, [target, t])
|
|
2765
|
+
|
|
2766
|
+
useEffect(() => {
|
|
2767
|
+
if (!target) return undefined
|
|
2768
|
+
loadText()
|
|
2769
|
+
return undefined
|
|
2770
|
+
}, [target, loadText])
|
|
2771
|
+
|
|
2772
|
+
// 光标置末尾:长消息从第一行开始编辑很难受,用户多半是改尾部
|
|
2773
|
+
useEffect(() => {
|
|
2774
|
+
if (textState !== 'ready' || !textRef.current) return
|
|
2775
|
+
const el = textRef.current
|
|
2776
|
+
try {
|
|
2777
|
+
el.focus()
|
|
2778
|
+
const end = el.value.length
|
|
2779
|
+
el.setSelectionRange(end, end)
|
|
2780
|
+
} catch (e) {
|
|
2781
|
+
/* 非浏览器 / 不支持的输入类型:忽略 */
|
|
2782
|
+
}
|
|
2783
|
+
}, [textState])
|
|
2784
|
+
|
|
2785
|
+
const cancel = useCallback(() => {
|
|
2786
|
+
if (saving) return
|
|
2787
|
+
// 零副作用:只清本地 state。不清宿主草稿、不碰会话、不发请求。
|
|
2788
|
+
reqRef.current += 1
|
|
2789
|
+
setTarget(null)
|
|
2790
|
+
setDraft('')
|
|
2791
|
+
setTextState('idle')
|
|
2792
|
+
setLoadError(null)
|
|
2793
|
+
setError(null)
|
|
2794
|
+
setDone('')
|
|
2795
|
+
}, [saving])
|
|
2796
|
+
|
|
2797
|
+
const running = (() => {
|
|
2798
|
+
if (!target || !sessions || !sessions.byId) return false
|
|
2799
|
+
const summary =
|
|
2800
|
+
sessions.byId[target.rawSessionId] || sessions.byId['session-' + target.sessionId] || sessions.byId[target.sessionId]
|
|
2801
|
+
return summary ? summary.running === true : false
|
|
2802
|
+
})()
|
|
2803
|
+
|
|
2804
|
+
const canSubmit = textState === 'ready' && !saving && draft.trim() !== '' && !running
|
|
2805
|
+
|
|
2806
|
+
const send = useCallback(async () => {
|
|
2807
|
+
if (!target || !canSubmit) return
|
|
2808
|
+
setSaving(true)
|
|
2809
|
+
setError(null)
|
|
2810
|
+
setDone('')
|
|
2811
|
+
const result = await sendEditAndRevert({
|
|
2812
|
+
sessionId: target.sessionId,
|
|
2813
|
+
rawSessionId: target.rawSessionId,
|
|
2814
|
+
seq: target.seq,
|
|
2815
|
+
text: draft,
|
|
2816
|
+
})
|
|
2817
|
+
if (!result.ok) {
|
|
2818
|
+
// ⚠️ 失败必须保留编辑框 + 用户已输入的文本(不清 draft、不 close)
|
|
2819
|
+
setSaving(false)
|
|
2820
|
+
setError(
|
|
2821
|
+
result.stage === 'revert'
|
|
2822
|
+
? t('edit.failed') + (result.reason || 'HTTP ' + result.status)
|
|
2823
|
+
: result.reason === 'empty'
|
|
2824
|
+
? t('edit.empty')
|
|
2825
|
+
: String(result.reason || ''),
|
|
2826
|
+
)
|
|
2827
|
+
return
|
|
2828
|
+
}
|
|
2829
|
+
setSaving(false)
|
|
2830
|
+
if (result.submitted) {
|
|
2831
|
+
notifyDone(t('edit.doneSubmitted'))
|
|
2832
|
+
cancel()
|
|
2833
|
+
return
|
|
2834
|
+
}
|
|
2835
|
+
// 提交不可用:明确告诉用户文本已经在输入框里,别让人以为没发生
|
|
2836
|
+
notifyDone(t('edit.manual'), 'warn')
|
|
2837
|
+
setDone(t('edit.manual'))
|
|
2838
|
+
}, [target, canSubmit, draft, t, cancel])
|
|
2839
|
+
|
|
2840
|
+
if (!target) return null
|
|
2841
|
+
|
|
2842
|
+
const onKeyDown = e => {
|
|
2843
|
+
if (e.key === 'Escape') {
|
|
2844
|
+
e.preventDefault()
|
|
2845
|
+
if (!saving) cancel()
|
|
2846
|
+
return
|
|
2847
|
+
}
|
|
2848
|
+
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
|
|
2849
|
+
e.preventDefault()
|
|
2850
|
+
if (canSubmit) send()
|
|
2851
|
+
}
|
|
2852
|
+
}
|
|
2853
|
+
|
|
2854
|
+
return React.createElement(
|
|
2855
|
+
'div',
|
|
2856
|
+
{
|
|
2857
|
+
className: 'mopsErScrim',
|
|
2858
|
+
role: 'presentation',
|
|
2859
|
+
onMouseDown: e => {
|
|
2860
|
+
if (e.target === e.currentTarget && !saving) cancel()
|
|
2861
|
+
},
|
|
2862
|
+
},
|
|
2863
|
+
React.createElement(
|
|
2864
|
+
'section',
|
|
2865
|
+
{
|
|
2866
|
+
className: 'mopsErPanel',
|
|
2867
|
+
role: 'dialog',
|
|
2868
|
+
'aria-modal': 'true',
|
|
2869
|
+
'aria-labelledby': 'mops-er-title',
|
|
2870
|
+
onKeyDown,
|
|
2871
|
+
},
|
|
2872
|
+
React.createElement(
|
|
2873
|
+
'div',
|
|
2874
|
+
{ className: 'mopsErHead' },
|
|
2875
|
+
React.createElement(
|
|
2876
|
+
'div',
|
|
2877
|
+
null,
|
|
2878
|
+
React.createElement('div', { className: 'mopsErTitle', id: 'mops-er-title' }, t('edit.title')),
|
|
2879
|
+
React.createElement('div', { className: 'mopsErSub' }, t('edit.subtitle', { seq: String(target.seq) })),
|
|
2880
|
+
),
|
|
2881
|
+
React.createElement(
|
|
2882
|
+
'button',
|
|
2883
|
+
{
|
|
2884
|
+
type: 'button',
|
|
2885
|
+
className: 'mopsErClose',
|
|
2886
|
+
onClick: cancel,
|
|
2887
|
+
disabled: saving,
|
|
2888
|
+
title: t('edit.cancel'),
|
|
2889
|
+
'aria-label': t('edit.cancel'),
|
|
2890
|
+
},
|
|
2891
|
+
'×',
|
|
2892
|
+
),
|
|
2893
|
+
),
|
|
2894
|
+
React.createElement(
|
|
2895
|
+
'div',
|
|
2896
|
+
{ className: 'mopsErBody' },
|
|
2897
|
+
React.createElement('textarea', {
|
|
2898
|
+
className: 'mopsErText',
|
|
2899
|
+
ref: textRef,
|
|
2900
|
+
value: draft,
|
|
2901
|
+
rows: 6,
|
|
2902
|
+
readOnly: saving,
|
|
2903
|
+
disabled: textState !== 'ready',
|
|
2904
|
+
'aria-invalid': error || textState === 'error' ? 'true' : undefined,
|
|
2905
|
+
placeholder: textState === 'loading' ? t('edit.loading') : t('edit.placeholder'),
|
|
2906
|
+
onChange: e => setDraft(e.target.value),
|
|
2907
|
+
'aria-label': t('edit.title'),
|
|
2908
|
+
}),
|
|
2909
|
+
textState === 'error'
|
|
2910
|
+
? React.createElement(
|
|
2911
|
+
'div',
|
|
2912
|
+
{ className: 'mopsErError', role: 'alert' },
|
|
2913
|
+
loadError,
|
|
2914
|
+
' ',
|
|
2915
|
+
React.createElement('button', { type: 'button', className: 'mopsErBtn mopsErGhost', onClick: loadText }, t('edit.retry')),
|
|
2916
|
+
)
|
|
2917
|
+
: null,
|
|
2918
|
+
running ? React.createElement('div', { className: 'mopsErError', role: 'alert' }, t('edit.running')) : null,
|
|
2919
|
+
error ? React.createElement('div', { className: 'mopsErError', role: 'alert' }, error) : null,
|
|
2920
|
+
done ? React.createElement('div', { className: 'mopsErOk', role: 'status' }, done) : null,
|
|
2921
|
+
React.createElement('div', { className: 'mopsErHint' }, t('edit.replaceHint')),
|
|
2922
|
+
),
|
|
2923
|
+
React.createElement(
|
|
2924
|
+
'div',
|
|
2925
|
+
{ className: 'mopsErActions' },
|
|
2926
|
+
React.createElement(
|
|
2927
|
+
'button',
|
|
2928
|
+
{ type: 'button', className: 'mopsErBtn mopsErGhost', onClick: cancel, disabled: saving },
|
|
2929
|
+
t('edit.cancel'),
|
|
2930
|
+
),
|
|
2931
|
+
React.createElement(
|
|
2932
|
+
'button',
|
|
2933
|
+
{ type: 'button', className: 'mopsErBtn mopsErPrimary', onClick: send, disabled: !canSubmit },
|
|
2934
|
+
saving ? t('edit.sending') : t('edit.send'),
|
|
2935
|
+
),
|
|
2936
|
+
),
|
|
2937
|
+
),
|
|
2938
|
+
)
|
|
2939
|
+
}
|
|
2940
|
+
|
|
2399
2941
|
// --- 头部按钮 ---------------------------------------------------------------
|
|
2400
2942
|
|
|
2401
2943
|
// 0.3.0 分支双路径选择:0.2.0+ 官方 sessions.fork({atSeq}) 优先。
|
|
@@ -2777,29 +3319,61 @@ window.__ModuleLoader__.load({
|
|
|
2777
3319
|
* 2. 无选中 → 取整条但截断到 QUOTE_MAX_CHARS,并标注来源(seq / 角色)
|
|
2778
3320
|
*/
|
|
2779
3321
|
const QUOTE_MAX_CHARS = 600
|
|
3322
|
+
// 0.20.0(bug-hunt M-1):按 Unicode code point 截断,且尽量在换行/空格处收尾,
|
|
3323
|
+
// 避免把 emoji(代理对)或 markdown 围栏 ``` 从中间切坏。
|
|
3324
|
+
const clipQuote = raw => {
|
|
3325
|
+
const chars = Array.from(String(raw))
|
|
3326
|
+
if (chars.length <= QUOTE_MAX_CHARS) return chars.join('')
|
|
3327
|
+
let end = QUOTE_MAX_CHARS
|
|
3328
|
+
// 往前找最近的空白/换行边界(最多回退 40 个字符),不破坏单词
|
|
3329
|
+
for (let i = end; i > Math.max(0, end - 40); i--) {
|
|
3330
|
+
if (/[\s\n]/.test(chars[i - 1])) {
|
|
3331
|
+
end = i
|
|
3332
|
+
break
|
|
3333
|
+
}
|
|
3334
|
+
}
|
|
3335
|
+
return chars.slice(0, end).join('') + '…'
|
|
3336
|
+
}
|
|
3337
|
+
// 0.20.0(bug-hunt H-2):把「选区归属」收紧,避免静默串味。
|
|
3338
|
+
// 旧实现算出 root 却从未使用,且用宽松的 [data-chat-flow-kind] 兜底
|
|
3339
|
+
// (会命中 turn-tail / tool / system 等通用块),只看 anchorNode,
|
|
3340
|
+
// 导致「选中 A 消息的一段、去点 B 消息的引用」会把 A 的文字当成 B 引用。
|
|
3341
|
+
// 现在要求 anchor 与 focus 落在**同一个** data-chat-node-key 容器内,
|
|
3342
|
+
// 且该容器必须存在;不满足就返回 null,回退到「截断+标注来源」路径。
|
|
3343
|
+
const ownerOf = node => {
|
|
3344
|
+
const el = node && (node.nodeType === 1 ? node : node.parentElement)
|
|
3345
|
+
return el && el.closest ? el.closest('[data-chat-node-key]') : null
|
|
3346
|
+
}
|
|
2780
3347
|
const selectionInMessage = () => {
|
|
2781
3348
|
try {
|
|
2782
3349
|
const sel = window.getSelection && window.getSelection()
|
|
2783
3350
|
if (!sel || sel.isCollapsed || sel.rangeCount === 0) return null
|
|
2784
3351
|
const text = String(sel.toString() || '').replace(/\s+$/g, '')
|
|
2785
3352
|
if (!text || text.length > QUOTE_MAX_CHARS * 2) return null
|
|
2786
|
-
|
|
2787
|
-
const
|
|
2788
|
-
|
|
2789
|
-
if (!
|
|
2790
|
-
return text
|
|
3353
|
+
const anchorOwner = ownerOf(sel.anchorNode)
|
|
3354
|
+
const focusOwner = ownerOf(sel.focusNode)
|
|
3355
|
+
// 两端必须属于同一个精确的 chat node;跨消息选区不引用(防串味)
|
|
3356
|
+
if (!anchorOwner || !focusOwner || anchorOwner !== focusOwner) return null
|
|
3357
|
+
return clipQuote(text)
|
|
2791
3358
|
} catch {
|
|
2792
3359
|
return null
|
|
2793
3360
|
}
|
|
2794
3361
|
}
|
|
2795
3362
|
const runQuote = () => {
|
|
2796
|
-
|
|
3363
|
+
// 0.20.0(bug-hunt M-2):来源标注放在 toast,不塞进 QuoteNode 正文。
|
|
3364
|
+
// QuoteNode.getTextContent() 是「模型可见文本」,正文里混入
|
|
3365
|
+
// '[引用自 seq N]' 会污染送进模型的引用内容。
|
|
3366
|
+
const finish = (ok, source) =>
|
|
3367
|
+
notifyDone(
|
|
3368
|
+
ok ? (source ? t('quote.doneWithSource', { seq: String(source) }) : t('quote.done')) : t('quote.unavailable'),
|
|
3369
|
+
ok ? 'ok' : 'warn',
|
|
3370
|
+
)
|
|
2797
3371
|
try {
|
|
2798
3372
|
if (!inputActions || typeof inputActions.insertQuote !== 'function') {
|
|
2799
3373
|
finish(false)
|
|
2800
3374
|
return
|
|
2801
3375
|
}
|
|
2802
|
-
const put = text => {
|
|
3376
|
+
const put = (text, source) => {
|
|
2803
3377
|
if (typeof text !== 'string' || text.trim() === '') {
|
|
2804
3378
|
finish(false)
|
|
2805
3379
|
return
|
|
@@ -2811,26 +3385,22 @@ window.__ModuleLoader__.load({
|
|
|
2811
3385
|
console.warn('[message-ops] insertQuote failed:', e)
|
|
2812
3386
|
ok = false
|
|
2813
3387
|
}
|
|
2814
|
-
finish(ok)
|
|
3388
|
+
finish(ok, ok ? source : null)
|
|
2815
3389
|
}
|
|
2816
|
-
// ①
|
|
3390
|
+
// ① 选中片段优先:正文就是选中的文字,无需来源标注
|
|
2817
3391
|
const selected = selectionInMessage()
|
|
2818
3392
|
if (selected != null) {
|
|
2819
|
-
put(selected)
|
|
3393
|
+
put(selected, null)
|
|
2820
3394
|
return
|
|
2821
3395
|
}
|
|
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
|
-
}
|
|
3396
|
+
// ② 无选中:取整条但截断;来源只通过 toast 告知,不进引用正文
|
|
2827
3397
|
if (fullText != null && fullText !== '') {
|
|
2828
|
-
put(
|
|
3398
|
+
put(clipQuote(fullText), seq)
|
|
2829
3399
|
return
|
|
2830
3400
|
}
|
|
2831
3401
|
fetch('/api/message-ops/text?sessionId=' + encodeURIComponent(sessionId) + '&seq=' + encodeURIComponent(seq))
|
|
2832
3402
|
.then(r => (r.ok ? r.json() : null))
|
|
2833
|
-
.then(d => put(d && d.ok && typeof d.text === 'string' ?
|
|
3403
|
+
.then(d => put(d && d.ok && typeof d.text === 'string' ? clipQuote(d.text) : null, seq))
|
|
2834
3404
|
.catch(() => put(null))
|
|
2835
3405
|
} catch (e) {
|
|
2836
3406
|
notifyDone(t('errorPrefix') + (e && e.message ? e.message : String(e)), 'error')
|
|
@@ -3560,8 +4130,12 @@ window.__ModuleLoader__.load({
|
|
|
3560
4130
|
// 配不上(data-mops-unmatched)→ 禁用 + 说明原因,绝不留装饰按钮。
|
|
3561
4131
|
var syncEnabled = (block, btn) => {
|
|
3562
4132
|
if (!btn) return
|
|
3563
|
-
// 0.18.0
|
|
3564
|
-
const hintKey = btn.classList.contains('mopsUserFork')
|
|
4133
|
+
// 0.18.0/0.20.0:三种按钮各有自己的提示文案(编辑按钮不能写 revert 的 hint)
|
|
4134
|
+
const hintKey = btn.classList.contains('mopsUserFork')
|
|
4135
|
+
? 'slot.forkHint'
|
|
4136
|
+
: btn.classList.contains('mopsUserEdit')
|
|
4137
|
+
? 'slot.editHint'
|
|
4138
|
+
: 'slot.revert'
|
|
3565
4139
|
const ok = block.getAttribute('data-mops-seq')
|
|
3566
4140
|
if (ok) {
|
|
3567
4141
|
btn.disabled = false
|
|
@@ -3573,10 +4147,10 @@ window.__ModuleLoader__.load({
|
|
|
3573
4147
|
btn.setAttribute('data-mops-unmatched', '1')
|
|
3574
4148
|
}
|
|
3575
4149
|
}
|
|
3576
|
-
/** 块内全部插件按钮一起同步(回滚 / 分叉同一动作行)。 */
|
|
4150
|
+
/** 块内全部插件按钮一起同步(回滚 / 编辑 / 分叉同一动作行)。 */
|
|
3577
4151
|
var syncBlockButtons = block => {
|
|
3578
4152
|
if (!block || !block.querySelectorAll) return
|
|
3579
|
-
for (const b of block.querySelectorAll('.mopsUserRevert, .mopsUserFork')) syncEnabled(block, b)
|
|
4153
|
+
for (const b of block.querySelectorAll('.mopsUserRevert, .mopsUserEdit, .mopsUserFork')) syncEnabled(block, b)
|
|
3580
4154
|
}
|
|
3581
4155
|
var assignSeqs = (sid, cache, anchors) => {
|
|
3582
4156
|
const idx = cache && cache.idx
|
|
@@ -3815,11 +4389,96 @@ window.__ModuleLoader__.load({
|
|
|
3815
4389
|
syncEnabled(block, btn)
|
|
3816
4390
|
return btn
|
|
3817
4391
|
}
|
|
3818
|
-
|
|
4392
|
+
|
|
4393
|
+
/**
|
|
4394
|
+
* 0.20.0 铅笔编辑按钮:与回滚**同一动作行**,插在回滚与分叉之间。
|
|
4395
|
+
*
|
|
4396
|
+
* 语义 = 打开「编辑并重发」浮层(`EditResendOverlay`),编辑框里改文字;
|
|
4397
|
+
* **点「发送并回撤」那一刻**才回撤并重发。点按钮本身零写操作。
|
|
4398
|
+
*
|
|
4399
|
+
* 与 0.19.0 删掉的行内编辑的区别:那版只是把原文**回填 composer**
|
|
4400
|
+
* (`refillComposer`),跟回滚回填是同一件事,所以被判为重复入口而删除。
|
|
4401
|
+
* 这一版是独立编辑框 + 延迟回撤,是用户明确要求的产品行为。
|
|
4402
|
+
*
|
|
4403
|
+
* 图标取官方 `edit-outline` 几何(16 viewBox,填充几何 —— 与分叉图标同族写法)。
|
|
4404
|
+
*/
|
|
4405
|
+
var ensureEditBtn = block => {
|
|
4406
|
+
let host = block.querySelector('[class*="xzv4MW_actions"]')
|
|
4407
|
+
if (!host) {
|
|
4408
|
+
host = document.createElement('div')
|
|
4409
|
+
host.className = 'mopsUserActionsRow'
|
|
4410
|
+
block.appendChild(host)
|
|
4411
|
+
}
|
|
4412
|
+
const existing = host.querySelector('.mopsUserEdit')
|
|
4413
|
+
if (existing) return existing
|
|
4414
|
+
const btn = document.createElement('button')
|
|
4415
|
+
btn.type = 'button'
|
|
4416
|
+
btn.className = 'mopsUserEdit'
|
|
4417
|
+
btn.title = __t('slot.editHint')
|
|
4418
|
+
btn.setAttribute('aria-label', __t('slot.edit'))
|
|
4419
|
+
// 铅笔:官方 edit-outline 的几何(与分支图标同为 fill 几何,不用 stroke)
|
|
4420
|
+
btn.innerHTML =
|
|
4421
|
+
'<svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="none">' +
|
|
4422
|
+
'<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"/>' +
|
|
4423
|
+
'</svg>'
|
|
4424
|
+
btn.addEventListener('click', e => {
|
|
4425
|
+
e.preventDefault()
|
|
4426
|
+
e.stopPropagation()
|
|
4427
|
+
if (btn.disabled) return
|
|
4428
|
+
runUserEdit(btn, block)
|
|
4429
|
+
})
|
|
4430
|
+
host.appendChild(btn)
|
|
4431
|
+
syncEnabled(block, btn)
|
|
4432
|
+
return btn
|
|
4433
|
+
}
|
|
4434
|
+
|
|
4435
|
+
/**
|
|
4436
|
+
* 0.20.0 行内编辑入口:解析 seq → 派发 `EDIT_EVENT` 打开编辑浮层。
|
|
4437
|
+
*
|
|
4438
|
+
* 这一步**纯读**:`ensureAssign` / `fetchRows` 只读 `/api/message-ops/messages`,
|
|
4439
|
+
* 不发任何写请求、不改草稿。真正的写操作全在 `sendEditAndRevert` 里,
|
|
4440
|
+
* 由用户在编辑框里点「发送并回撤」才触发。
|
|
4441
|
+
*/
|
|
4442
|
+
var runUserEdit = (btn, block) => {
|
|
4443
|
+
const sid = __currentSessionId
|
|
4444
|
+
if (!sid) return
|
|
4445
|
+
btn.disabled = true
|
|
4446
|
+
Promise.resolve()
|
|
4447
|
+
.then(() => ensureAssign(sid))
|
|
4448
|
+
.then(() => fetchRows(sid))
|
|
4449
|
+
.then(cache => {
|
|
4450
|
+
const rows = cache && cache.rows
|
|
4451
|
+
const seq = Number(block.getAttribute('data-mops-seq'))
|
|
4452
|
+
const row = rows && rows.find(r => r.seq === seq)
|
|
4453
|
+
if (!row) {
|
|
4454
|
+
notifyDone(__t('errorPrefix') + __t('slot.editUnmatched'), 'error')
|
|
4455
|
+
return
|
|
4456
|
+
}
|
|
4457
|
+
if (!Number.isSafeInteger(seq) || seq < 0) {
|
|
4458
|
+
notifyDone(__t('slot.editUnmatched'), 'warn')
|
|
4459
|
+
return
|
|
4460
|
+
}
|
|
4461
|
+
// 裸 uuid 给 HTTP,带前缀的给 openSession 与草稿键
|
|
4462
|
+
window.dispatchEvent(
|
|
4463
|
+
new CustomEvent(EDIT_EVENT, {
|
|
4464
|
+
detail: { sessionId: bareSessionId(sid), rawSessionId: sid, seq: seq },
|
|
4465
|
+
}),
|
|
4466
|
+
)
|
|
4467
|
+
})
|
|
4468
|
+
.catch(reason => {
|
|
4469
|
+
notifyDone(__t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error')
|
|
4470
|
+
})
|
|
4471
|
+
.finally(() => {
|
|
4472
|
+
btn.disabled = false
|
|
4473
|
+
})
|
|
4474
|
+
}
|
|
4475
|
+
|
|
4476
|
+
// 三个按钮的顺序由 DOM 顺序决定:回滚在前(破坏性更高),编辑居中,分叉最后(非破坏)。
|
|
3819
4477
|
var ensureUserActions = block => {
|
|
3820
|
-
// 0.
|
|
3821
|
-
//
|
|
4478
|
+
// 0.20.0:铅笔回归,但语义变了 —— 独立编辑框 + 点「发送并回撤」才写,
|
|
4479
|
+
// 不再是 0.18.0 那种「只回填 composer」的伪编辑。
|
|
3822
4480
|
ensureBtn(block)
|
|
4481
|
+
ensureEditBtn(block)
|
|
3823
4482
|
ensureForkBtn(block)
|
|
3824
4483
|
}
|
|
3825
4484
|
// 0.9.7(P0-2 读合并):把 150/700/1600ms 三档并成**一次**真网络请求,
|
|
@@ -4009,11 +4668,11 @@ window.__ModuleLoader__.load({
|
|
|
4009
4668
|
// (宿主 .xzv4MW_actions 已定 height:28px,改小会撑裂行高)。
|
|
4010
4669
|
// · 无淡入动画(opencode 源码注释明写 "Hover actions show and hide
|
|
4011
4670
|
// 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}',
|
|
4671
|
+
'.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}',
|
|
4672
|
+
'.mopsUserRevert svg,.mopsUserEdit svg,.mopsUserFork svg{width:14px;height:14px;display:block}',
|
|
4673
|
+
'.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)}',
|
|
4674
|
+
'.mopsUserRevert:disabled,.mopsUserEdit:disabled,.mopsUserFork:disabled{opacity:.4;cursor:default;background:transparent}',
|
|
4675
|
+
'.mopsUserRevert:focus-visible,.mopsUserEdit:focus-visible,.mopsUserFork:focus-visible{outline:2px solid var(--dsw-alias-border-l2,#b8b8b8);outline-offset:1px}',
|
|
4017
4676
|
// 0.18.0:用户反馈「点时间图标也会回撤」——根因不是绑定错误,而是
|
|
4018
4677
|
// 我们的按钮被 appendChild 到宿主 .actions 行末尾,而该行在
|
|
4019
4678
|
// data-clock="start"(用户消息)时第一个子元素就是**时间文本**:
|
|
@@ -4524,6 +5183,18 @@ window.__ModuleLoader__.load({
|
|
|
4524
5183
|
window.__MOPS_LEGACY_DIALOG === true ? OpsDialog : OpsPanel,
|
|
4525
5184
|
),
|
|
4526
5185
|
)
|
|
5186
|
+
// 0.20.0:编辑并重发浮层(同族模态,order 102 排在 OpsPanel 之后 —— 两者互斥打开)
|
|
5187
|
+
ctx.slots.inject(OVERLAY_SLOT, () =>
|
|
5188
|
+
ctx.slots.register(
|
|
5189
|
+
{
|
|
5190
|
+
name: OVERLAY_SLOT,
|
|
5191
|
+
id: EDIT_ID,
|
|
5192
|
+
order: 102,
|
|
5193
|
+
...(__locale ? { locale: NS } : {}),
|
|
5194
|
+
},
|
|
5195
|
+
EditResendOverlay,
|
|
5196
|
+
),
|
|
5197
|
+
)
|
|
4527
5198
|
installSidebarOps()
|
|
4528
5199
|
installUserRevertInjector()
|
|
4529
5200
|
}
|
|
@@ -4531,7 +5202,19 @@ window.__ModuleLoader__.load({
|
|
|
4531
5202
|
return {
|
|
4532
5203
|
apply,
|
|
4533
5204
|
inject: ['slots'],
|
|
4534
|
-
__test: {
|
|
5205
|
+
__test: {
|
|
5206
|
+
activityTransition,
|
|
5207
|
+
forkBoundaryBefore,
|
|
5208
|
+
isHostBranchButton,
|
|
5209
|
+
writeSessionDraft,
|
|
5210
|
+
HOST_BRANCH_ICON_ID,
|
|
5211
|
+
HOST_BRANCH_D_PREFIX,
|
|
5212
|
+
// 0.20.0:编辑并重发的编排层(可注入 deps 真执行断言时序)
|
|
5213
|
+
sendEditAndRevert,
|
|
5214
|
+
submitEditedText,
|
|
5215
|
+
EDIT_EVENT,
|
|
5216
|
+
EDIT_ID,
|
|
5217
|
+
},
|
|
4535
5218
|
}
|
|
4536
5219
|
},
|
|
4537
5220
|
})
|