@240xu/dsh-message-ops 0.18.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 +88 -0
- package/package.json +1 -1
- package/src/client.js +725 -251
package/src/client.js
CHANGED
|
@@ -133,14 +133,31 @@ window.__ModuleLoader__.load({
|
|
|
133
133
|
'op.branchDesc': '把此条之前的对话复制到新会话,并把此条原文放回新会话输入框(原会话不变,非破坏操作)。',
|
|
134
134
|
'slot.revert': '回滚到此条',
|
|
135
135
|
'slot.revertUnmatched': '在日志里定位不到这条消息的 seq(通常是模型写的摘要与渲染文本偏差过大)——请改用「消息操作」对话框。',
|
|
136
|
-
'slot.edit': '编辑(复制原文到输入框)',
|
|
137
|
-
'slot.editHint': '复制此条原文到输入框;发出后新增一条消息,不修改原消息',
|
|
138
|
-
'slot.editDone': '原文已复制到输入框',
|
|
139
|
-
'slot.editNoText': '这条消息没有可复制的文本',
|
|
140
136
|
'slot.fork': '从此条分叉',
|
|
141
137
|
'slot.forkHint': '复制此条之前的对话到新会话,并把此条原文放回新会话输入框',
|
|
142
138
|
'slot.forkDone': '已分叉:新会话 {id}',
|
|
143
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': '发送会先回撤此条及其之后的全部可见消息,再把改后的文本作为新消息发出;日志仍保留,可从回撤区重放。',
|
|
144
161
|
'toast.openNew': '打开新会话',
|
|
145
162
|
'fork.official': '分支完成:新会话 {id}',
|
|
146
163
|
'fork.unavailable': '官方分支不可用:通常是因为会话正在运行,请先停止会话后重试。分支功能由 dsh 内置的 session/fork 提供。',
|
|
@@ -167,6 +184,8 @@ window.__ModuleLoader__.load({
|
|
|
167
184
|
'slot.quote': '引用到输入框',
|
|
168
185
|
'quote.done': '已引用到输入框',
|
|
169
186
|
'quote.unavailable': '引用不可用(输入框不可写或无全文)',
|
|
187
|
+
'quote.sourcePrefix': '引用自 seq {seq}',
|
|
188
|
+
'quote.doneWithSource': '已引用(来自 seq {seq})',
|
|
170
189
|
'undo.label': '回滚上一条消息',
|
|
171
190
|
'undo.desc': '移除最后一条用户消息,原文回填输入框',
|
|
172
191
|
'undo.done.undo': '已回滚上一条消息',
|
|
@@ -214,12 +233,6 @@ window.__ModuleLoader__.load({
|
|
|
214
233
|
// 0.17.0(冲突 R2):行为是「复制原文到输入框」,不修改原消息。
|
|
215
234
|
// 旧文案「编辑并重发」暗示会改原消息,实测会误导(发出后是新增一条,
|
|
216
235
|
// 原消息仍在,界面出现两条相似消息)。opencode 也没有消息级编辑。
|
|
217
|
-
'panel.edit': '复制到输入框',
|
|
218
|
-
'panel.editHint': '把此条原文复制到输入框;发出后会新增一条消息,不会修改原消息',
|
|
219
|
-
'panel.editDone': '原文已复制到输入框',
|
|
220
|
-
'panel.editEmpty': '这条消息没有可编辑的文本',
|
|
221
|
-
'panel.editUnavailable': '编辑器不可写(会话可能正在运行或尚未挂载)',
|
|
222
|
-
'panel.editNotReady': '全文尚未就绪(列表只带 160 字摘要)——请重试或改用回滚回填',
|
|
223
236
|
'panel.openNew': '打开新会话',
|
|
224
237
|
'panel.revertDone': '回滚已生效',
|
|
225
238
|
'panel.deleteDone': '删除已生效',
|
|
@@ -268,14 +281,32 @@ window.__ModuleLoader__.load({
|
|
|
268
281
|
'slot.revert': 'Revert to here',
|
|
269
282
|
'slot.revertUnmatched':
|
|
270
283
|
'Cannot locate this message seq in the log (usually the model-written summary drifted too far from the rendered text) — use the Message ops dialog instead.',
|
|
271
|
-
'slot.edit': 'Edit (copy text to composer)',
|
|
272
|
-
'slot.editHint': 'Copies this text into the composer; sending adds a new message without modifying the original',
|
|
273
|
-
'slot.editDone': 'Original text copied to the composer',
|
|
274
|
-
'slot.editNoText': 'This message has no text to copy',
|
|
275
284
|
'slot.fork': 'Branch from here',
|
|
276
285
|
'slot.forkHint': 'Copies the conversation above this message into a new session and puts this message back in the new composer',
|
|
277
286
|
'slot.forkDone': 'Branched: new session {id}',
|
|
278
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.',
|
|
279
310
|
'toast.openNew': 'Open new session',
|
|
280
311
|
'fork.official': 'Branched (official fork): new session {id}',
|
|
281
312
|
'fork.unavailable':
|
|
@@ -303,6 +334,8 @@ window.__ModuleLoader__.load({
|
|
|
303
334
|
'slot.quote': 'Quote to composer',
|
|
304
335
|
'quote.done': 'Quoted into composer',
|
|
305
336
|
'quote.unavailable': 'Quote unavailable (composer locked or no full text)',
|
|
337
|
+
'quote.sourcePrefix': 'Quoted from seq {seq}',
|
|
338
|
+
'quote.doneWithSource': 'Quoted (from seq {seq})',
|
|
306
339
|
'undo.label': 'Undo last message',
|
|
307
340
|
'undo.desc': 'Remove the last user message and put its original text back into the composer',
|
|
308
341
|
'undo.done.undo': 'Undid the last message',
|
|
@@ -348,12 +381,6 @@ window.__ModuleLoader__.load({
|
|
|
348
381
|
'panel.branchHint': 'Copy the conversation above this message into a new session and put this message back in the new composer',
|
|
349
382
|
'panel.branchDone': 'Forked: {id}',
|
|
350
383
|
'panel.branchUserOnly': 'Fork works on user messages only (assistant messages have no text to hand back)',
|
|
351
|
-
'panel.edit': 'Copy to composer',
|
|
352
|
-
'panel.editHint': 'Copies this text into the composer; sending adds a new message and does not modify the original',
|
|
353
|
-
'panel.editDone': 'Original text copied to the composer',
|
|
354
|
-
'panel.editEmpty': 'This message has no editable text',
|
|
355
|
-
'panel.editUnavailable': 'Composer is not writable (session may be running or not mounted)',
|
|
356
|
-
'panel.editNotReady': 'Full text is not ready (the list only carries a 160-char snippet) — retry, or use revert to refill',
|
|
357
384
|
'panel.openNew': 'Open new session',
|
|
358
385
|
'panel.revertDone': 'Revert applied',
|
|
359
386
|
'panel.deleteDone': 'Delete applied',
|
|
@@ -778,19 +805,7 @@ window.__ModuleLoader__.load({
|
|
|
778
805
|
// `?` 分支把成功文案当错误抛出。对话框 mode 只有 revert|delete|branch,
|
|
779
806
|
// branch 在上面已 return,故 done.restore 分支在此不可达,一并删掉。
|
|
780
807
|
const okMsg = mode === 'revert' ? t('done.revert') : t('done.delete')
|
|
781
|
-
// 0.
|
|
782
|
-
// 0.11.3:必须走统一出口,且要落盘 —— 直接 setDraft 会被随后的
|
|
783
|
-
// openSession 用 localStorage 里的旧草稿覆盖(见 refillComposer 注释)。
|
|
784
|
-
if (mode === 'revert' && pickedMsg && pickedMsg.role === 'user' && pickedMsg.fullText) {
|
|
785
|
-
try {
|
|
786
|
-
if (__inputActions && typeof __inputActions.setDraft === 'function') {
|
|
787
|
-
__inputActions.setDraft(pickedMsg.fullText)
|
|
788
|
-
if (typeof __inputActions.persistDraft === 'function') __inputActions.persistDraft()
|
|
789
|
-
}
|
|
790
|
-
} catch (e) {
|
|
791
|
-
console.warn('[message-ops] refill failed:', e)
|
|
792
|
-
}
|
|
793
|
-
}
|
|
808
|
+
// 0.19.0:回填统一由 refillComposer 承担;老 setDraft 路径已删(见 spec §9)。
|
|
794
809
|
setDoneMsg(okMsg)
|
|
795
810
|
setBusyMsg('')
|
|
796
811
|
setState('done')
|
|
@@ -1092,7 +1107,7 @@ window.__ModuleLoader__.load({
|
|
|
1092
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}',
|
|
1093
1108
|
'@keyframes mopsFade{from{opacity:0}to{opacity:1}}',
|
|
1094
1109
|
'@keyframes mopsRise{from{opacity:0;transform:translateY(8px) scale(.985)}to{opacity:1;transform:none}}',
|
|
1095
|
-
'.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)}',
|
|
1096
1111
|
'@media(prefers-reduced-motion:reduce){.mopsPanelScrim,.mopsPanel{animation:none}}',
|
|
1097
1112
|
'.mopsPanel *{box-sizing:border-box}',
|
|
1098
1113
|
'.mopsPanel button{font:inherit;color:inherit;border-radius:0}',
|
|
@@ -1110,7 +1125,7 @@ window.__ModuleLoader__.load({
|
|
|
1110
1125
|
'.mopsSearch:focus{border-color:var(--dsw-alias-brand-primary,#4d6bfe)}',
|
|
1111
1126
|
'.mopsChips{display:flex;gap:6px;padding:0 18px 10px;flex-wrap:wrap;align-items:center}',
|
|
1112
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)}',
|
|
1113
|
-
'.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)}',
|
|
1114
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}',
|
|
1115
1130
|
'.mopsToggle input{accent-color:var(--dsw-alias-brand-primary,#4d6bfe)}',
|
|
1116
1131
|
'.mopsList{flex:1;min-height:0;overflow-y:auto;position:relative;border-top:1px solid var(--dsw-alias-border-l1,#efefef)}',
|
|
@@ -1131,15 +1146,15 @@ window.__ModuleLoader__.load({
|
|
|
1131
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)}',
|
|
1132
1147
|
'.mopsDetailHint{padding:10px 0 14px;color:var(--dsw-alias-label-tertiary,#8a8a8e);font-size:12px}',
|
|
1133
1148
|
'.mopsActions{display:flex;gap:6px;flex-wrap:wrap;margin-top:10px}',
|
|
1134
|
-
'.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)}',
|
|
1135
1150
|
'.mopsImpactTitle{font-size:12px;font-weight:600}',
|
|
1136
1151
|
'.mopsImpact{font-size:11px;line-height:1.5;color:var(--dsw-alias-label-secondary,#6b6b70)}',
|
|
1137
1152
|
'.mopsAction{height:30px;padding:0 10px;border:1px solid var(--dsw-alias-border-l2,#cfcfcf);background:transparent;cursor:pointer;font-size:11px}',
|
|
1138
1153
|
'.mopsAction:hover:not(:disabled){border-color:var(--dsw-alias-label-primary,#0f1115)}',
|
|
1139
|
-
'.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)}',
|
|
1140
1155
|
'.mopsAction.danger{border-color:var(--dsw-alias-state-error-primary,#c63b32);color:var(--dsw-alias-state-error-primary,#c63b32)}',
|
|
1141
1156
|
'.mopsAction:disabled{opacity:.35;cursor:default}',
|
|
1142
|
-
'.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)}',
|
|
1143
1158
|
'.mopsCount{font-size:10px;color:var(--dsw-alias-label-tertiary,#8a8a8e)}',
|
|
1144
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}',
|
|
1145
1160
|
'.mopsDanger:hover{background:rgba(198,59,50,.06)}',
|
|
@@ -1147,7 +1162,7 @@ window.__ModuleLoader__.load({
|
|
|
1147
1162
|
'.mopsBanner.warn{color:var(--dsw-alias-state-warn-primary,#9a6500);background:rgba(154,101,0,.06)}',
|
|
1148
1163
|
'.mopsBanner.err{color:var(--dsw-alias-state-error-primary,#c63b32);background:rgba(198,59,50,.06)}',
|
|
1149
1164
|
'.mopsBanner.ok{color:var(--dsw-alias-state-success-primary,#2f7d4a);background:rgba(47,125,74,.06)}',
|
|
1150
|
-
'.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}',
|
|
1151
1166
|
'.mopsConfirm h3{margin:0;font-size:15px}',
|
|
1152
1167
|
'.mopsConfirm p{margin:0;font-size:12px;color:var(--dsw-alias-label-secondary,#6b6b70)}',
|
|
1153
1168
|
'.mopsConfirm p.mopsImpact{font-size:11px}',
|
|
@@ -1182,7 +1197,6 @@ window.__ModuleLoader__.load({
|
|
|
1182
1197
|
const [detail, setDetail] = useState('')
|
|
1183
1198
|
const [detailState, setDetailState] = useState('idle')
|
|
1184
1199
|
// MED-5:detail 是**全文**还是 snippet 回退?只有全文才允许「编辑并重发」。
|
|
1185
|
-
const [detailFull, setDetailFull] = useState(false)
|
|
1186
1200
|
const [tab, setTab] = useState('messages')
|
|
1187
1201
|
const [hits, setHits] = useState(null)
|
|
1188
1202
|
const [searching, setSearching] = useState(false)
|
|
@@ -1411,63 +1425,6 @@ window.__ModuleLoader__.load({
|
|
|
1411
1425
|
}, 0)
|
|
1412
1426
|
}, [busy, confirmAction])
|
|
1413
1427
|
|
|
1414
|
-
/**
|
|
1415
|
-
* 0.12.0 面板内的「编辑并重发」:把该条用户消息的原文放进编辑器并关掉面板。
|
|
1416
|
-
*
|
|
1417
|
-
* 为什么不自己加一个输入框:编辑器已经有草稿、附件、引用、斜杠命令与提交状态机,
|
|
1418
|
-
* 面板里再复刻一套只会分叉行为。正确做法是**交回官方编辑器**:
|
|
1419
|
-
* 1. `setDraft(text)` 改编辑器内容
|
|
1420
|
-
* 2. `persistDraft()` 落 localStorage —— 否则紧随的 openSession 会用旧草稿覆盖
|
|
1421
|
-
* (0.11.3 已踩过这个坑,见 refillComposer 注释)
|
|
1422
|
-
* 3. 关面板并聚焦编辑器,用户改完直接回车发出
|
|
1423
|
-
* 语义上与 opencode 的「回撤 → 原文回到 composer」一致;区别是我们不预先回撤,
|
|
1424
|
-
* 由用户决定发不发(发了才产生新的分支上下文)。
|
|
1425
|
-
*/
|
|
1426
|
-
const startEdit = useCallback(
|
|
1427
|
-
text => {
|
|
1428
|
-
if (!target || busy) return
|
|
1429
|
-
const body = typeof text === 'string' ? text : ''
|
|
1430
|
-
if (!body) {
|
|
1431
|
-
setError(t('panel.editEmpty'))
|
|
1432
|
-
return
|
|
1433
|
-
}
|
|
1434
|
-
// ── 0.17.0(冲突 C1):与 refillComposer 统一成**同一条**回填路径 ──
|
|
1435
|
-
//
|
|
1436
|
-
// 旧实现走 `__inputActions.setDraft` + `persistDraft`,且
|
|
1437
|
-
// `!__inputActions` 就直接失败返回 —— 但 refillComposer(回滚路径)
|
|
1438
|
-
// 早在 0.14.0 就改成了「先写宿主草稿键、再尽力更新编辑器」,不依赖
|
|
1439
|
-
// 编辑器是否已挂载。同一件事两条实现、两种可靠性,必须合并。
|
|
1440
|
-
//
|
|
1441
|
-
// 现在统一为:① writeSessionDraft 落盘(权威值)② 尽力 setDraft
|
|
1442
|
-
// ③ 回读校验(写不进去就报错且不 close,保留 0.13.1 MED-4 的护栏)
|
|
1443
|
-
const sidForDraft = target.sessionId
|
|
1444
|
-
const persisted = writeSessionDraft(sidForDraft, body)
|
|
1445
|
-
let editorSet = false
|
|
1446
|
-
if (__inputActions && typeof __inputActions.setDraft === 'function') {
|
|
1447
|
-
try {
|
|
1448
|
-
__inputActions.setDraft(body)
|
|
1449
|
-
editorSet = true
|
|
1450
|
-
} catch (reason) {
|
|
1451
|
-
console.warn('[message-ops] setDraft failed:', reason)
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
// 回读校验:落盘失败才是真风险(编辑器可能没挂载,那不是错误)
|
|
1455
|
-
const stored = readSessionDraft(sidForDraft)
|
|
1456
|
-
if (stored !== body) {
|
|
1457
|
-
setError(t('panel.editUnavailable'))
|
|
1458
|
-
return
|
|
1459
|
-
}
|
|
1460
|
-
if (!persisted && !editorSet) {
|
|
1461
|
-
setError(t('panel.editUnavailable'))
|
|
1462
|
-
return
|
|
1463
|
-
}
|
|
1464
|
-
setDone(t('panel.editDone'))
|
|
1465
|
-
notifyDone(t('panel.editDone'))
|
|
1466
|
-
close()
|
|
1467
|
-
},
|
|
1468
|
-
[target, busy, t, close],
|
|
1469
|
-
)
|
|
1470
|
-
|
|
1471
1428
|
useEffect(() => {
|
|
1472
1429
|
if (!open) return undefined
|
|
1473
1430
|
const onKey = e => {
|
|
@@ -1625,7 +1582,6 @@ window.__ModuleLoader__.load({
|
|
|
1625
1582
|
detailReq.current += 1
|
|
1626
1583
|
setPicked(null)
|
|
1627
1584
|
setDetail('')
|
|
1628
|
-
setDetailFull(false)
|
|
1629
1585
|
setDetailState('idle')
|
|
1630
1586
|
setConfirmAction(null)
|
|
1631
1587
|
}
|
|
@@ -1635,7 +1591,6 @@ window.__ModuleLoader__.load({
|
|
|
1635
1591
|
detailReq.current += 1
|
|
1636
1592
|
setPicked(m)
|
|
1637
1593
|
setDetail(m.snippet || '')
|
|
1638
|
-
setDetailFull(false)
|
|
1639
1594
|
setDetailState('ready')
|
|
1640
1595
|
setConfirmAction(null)
|
|
1641
1596
|
setDone('')
|
|
@@ -1712,7 +1667,6 @@ window.__ModuleLoader__.load({
|
|
|
1712
1667
|
setConfirmAction(null)
|
|
1713
1668
|
setPicked(m)
|
|
1714
1669
|
setDetail(m.snippet || '')
|
|
1715
|
-
setDetailFull(false)
|
|
1716
1670
|
setDetailState('loading')
|
|
1717
1671
|
setDone('')
|
|
1718
1672
|
const req = ++detailReq.current
|
|
@@ -1728,13 +1682,11 @@ window.__ModuleLoader__.load({
|
|
|
1728
1682
|
if (!res.ok || !data || data.ok !== true) throw new Error((data && data.error) || 'HTTP ' + res.status)
|
|
1729
1683
|
const full = typeof data.text === 'string' && data.text !== '' ? data.text : null
|
|
1730
1684
|
setDetail(full ?? (m.snippet || ''))
|
|
1731
|
-
setDetailFull(full !== null)
|
|
1732
1685
|
setDetailState('ready')
|
|
1733
1686
|
})
|
|
1734
1687
|
.catch(() => {
|
|
1735
1688
|
if (req !== detailReq.current) return
|
|
1736
|
-
setDetail(m.snippet || '')
|
|
1737
|
-
setDetailFull(false) // 拉全文失败 → 只有截断的 snippet,不许冒充原文
|
|
1689
|
+
setDetail(m.snippet || '') // 拉全文失败 → 只有截断的 snippet,不许冒充原文
|
|
1738
1690
|
setDetailState('ready')
|
|
1739
1691
|
})
|
|
1740
1692
|
},
|
|
@@ -1920,6 +1872,11 @@ window.__ModuleLoader__.load({
|
|
|
1920
1872
|
|
|
1921
1873
|
const pickedLive = picked ? messages.find(m => m.seq === picked.seq) || picked : null
|
|
1922
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'
|
|
1923
1880
|
const visibleCount = messages.filter(m => m.role !== 'system' && m.visible && !m.shadowed).length
|
|
1924
1881
|
const shadowedCount = messages.filter(m => m.role !== 'system' && m.shadowed).length
|
|
1925
1882
|
const totalCount = messages.filter(m => m.role !== 'system').length
|
|
@@ -1932,11 +1889,9 @@ window.__ModuleLoader__.load({
|
|
|
1932
1889
|
// 「这句话说错了,拿回去重说」,AI 消息没有可回填的原文)。
|
|
1933
1890
|
const pickedIsUser = !!pickedLive && pickedLive.role === 'user'
|
|
1934
1891
|
const canFork = !busy && !target.running && pickedIsUser && !pickedLive.shadowed && pickedLive.seq > 0
|
|
1935
|
-
const canEdit = pickedIsUser && !pickedLive.shadowed && state === 'ready' && !busy
|
|
1936
1892
|
// MED-5:只有**真拉到全文**才允许编辑。detail 在 /text 失败时会退化成
|
|
1937
1893
|
// snippet,而 snippet 被服务端硬截断到 160 字(session-file.js:331)——
|
|
1938
1894
|
// 拿它冒充原文会让用户改完发出时静默丢掉后半段。
|
|
1939
|
-
const editTextReady = detailFull === true && typeof detail === 'string' && detail !== ''
|
|
1940
1895
|
const deleteBlockedReason = target.running
|
|
1941
1896
|
? t('panel.running')
|
|
1942
1897
|
: state !== 'ready'
|
|
@@ -2229,7 +2184,7 @@ window.__ModuleLoader__.load({
|
|
|
2229
2184
|
{
|
|
2230
2185
|
type: 'button',
|
|
2231
2186
|
className: 'mopsAction primary',
|
|
2232
|
-
disabled: !
|
|
2187
|
+
disabled: !canRevert || !!confirmAction,
|
|
2233
2188
|
ref: revertBtnRef,
|
|
2234
2189
|
onClick: () => setConfirmAction('revert'),
|
|
2235
2190
|
title: t('panel.revertHint'),
|
|
@@ -2248,23 +2203,6 @@ window.__ModuleLoader__.load({
|
|
|
2248
2203
|
},
|
|
2249
2204
|
t('panel.delete'),
|
|
2250
2205
|
),
|
|
2251
|
-
// 0.12.0:编辑只对用户消息可用 —— 直接把原文交回编辑器。
|
|
2252
|
-
// 无二次确认:它不改日志,只改草稿。
|
|
2253
|
-
React.createElement(
|
|
2254
|
-
'button',
|
|
2255
|
-
{
|
|
2256
|
-
type: 'button',
|
|
2257
|
-
className: 'mopsAction',
|
|
2258
|
-
disabled: !canEdit || !editTextReady,
|
|
2259
|
-
title: !pickedIsUser
|
|
2260
|
-
? t('panel.branchUserOnly')
|
|
2261
|
-
: !editTextReady
|
|
2262
|
-
? t('panel.editNotReady')
|
|
2263
|
-
: t('panel.editHint'),
|
|
2264
|
-
onClick: () => startEdit(detail),
|
|
2265
|
-
},
|
|
2266
|
-
t('panel.edit'),
|
|
2267
|
-
),
|
|
2268
2206
|
// 分叉同样只对用户消息可用(AI 消息没有可回填的原文),
|
|
2269
2207
|
// 语义 = opencode 的 before:新会话不含此条,原文进新会话输入框。
|
|
2270
2208
|
React.createElement(
|
|
@@ -2508,6 +2446,498 @@ window.__ModuleLoader__.load({
|
|
|
2508
2446
|
)
|
|
2509
2447
|
}
|
|
2510
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
|
+
|
|
2511
2941
|
// --- 头部按钮 ---------------------------------------------------------------
|
|
2512
2942
|
|
|
2513
2943
|
// 0.3.0 分支双路径选择:0.2.0+ 官方 sessions.fork({atSeq}) 优先。
|
|
@@ -2719,33 +3149,13 @@ window.__ModuleLoader__.load({
|
|
|
2719
3149
|
)
|
|
2720
3150
|
}
|
|
2721
3151
|
|
|
2722
|
-
// 官方图标适配:0.2.0 primitives 的 IconClock 与原生操作行同款;
|
|
2723
|
-
// require 失败(0.1.x 或裁剪环境)回退内联 SVG,槽在 0.1.x 本就不存在,仅防御。
|
|
2724
|
-
// 0.9.0:移除 IconTrash —— 消息级删除按钮从未渲染(删除只在对话框里),
|
|
2725
|
-
// 专家核查确认 IconTrash/TrashFallback 零渲染点,是死代码。
|
|
2726
|
-
var IconClock = null
|
|
2727
|
-
try {
|
|
2728
|
-
const P = require('@deepseek-ai/dsh-client-ui-primitives')
|
|
2729
|
-
IconClock = P && P.IconClockOutlineRegular
|
|
2730
|
-
} catch {
|
|
2731
|
-
/* fallback below */
|
|
2732
|
-
}
|
|
2733
|
-
if (!IconClock)
|
|
2734
|
-
IconClock = function ClockFallback() {
|
|
2735
|
-
// 官方 IconClockOutlineArtwork 1:1 路径( Regular = 1px stroke)
|
|
2736
|
-
return React.createElement(
|
|
2737
|
-
'svg',
|
|
2738
|
-
{ width: 16, height: 16, viewBox: '0 0 16 16', fill: 'none', 'aria-hidden': true, stroke: 'currentColor', strokeWidth: 1 },
|
|
2739
|
-
React.createElement('path', {
|
|
2740
|
-
d: 'M8 14C11.3137 14 14 11.3137 14 8C14 4.68629 11.3137 2 8 2C4.68629 2 2 4.68629 2 8C2 11.3137 4.68629 14 8 14Z',
|
|
2741
|
-
}),
|
|
2742
|
-
React.createElement('path', { d: 'M8 4.31V8.46L11 10.08' }),
|
|
2743
|
-
)
|
|
2744
|
-
}
|
|
2745
3152
|
var IconQuote = null
|
|
2746
3153
|
try {
|
|
2747
3154
|
const P2 = require('@deepseek-ai/dsh-client-ui-primitives')
|
|
2748
|
-
|
|
3155
|
+
// 0.19.0:不再回退到 IconCopyOutlineRegular —— 宿主在 AI 消息下方本来就
|
|
3156
|
+
// 有一个 Copy 按钮,用复制图标做「引用」会变成两个一模一样的复制按钮。
|
|
3157
|
+
// 优先官方 chat 类图标;拿不到就用下面的引号几何(明确的引用语义)。
|
|
3158
|
+
IconQuote = P2 && P2.IconChatOutlineRegular
|
|
2749
3159
|
} catch {
|
|
2750
3160
|
/* fallback below */
|
|
2751
3161
|
}
|
|
@@ -2875,40 +3285,6 @@ window.__ModuleLoader__.load({
|
|
|
2875
3285
|
return false
|
|
2876
3286
|
}
|
|
2877
3287
|
|
|
2878
|
-
const runRevert = () => {
|
|
2879
|
-
if (busy || seq == null || running) return
|
|
2880
|
-
setBusy('revert')
|
|
2881
|
-
// 0.5.2(P2):Promise.resolve 包裹——fetch/stringify 同步抛出也转为
|
|
2882
|
-
// rejection 落进 finally,busy 永不卡死
|
|
2883
|
-
Promise.resolve()
|
|
2884
|
-
.then(() =>
|
|
2885
|
-
fetch('/api/message-ops/revert', {
|
|
2886
|
-
method: 'POST',
|
|
2887
|
-
headers: { 'content-type': 'application/json' },
|
|
2888
|
-
body: JSON.stringify({ sessionId, seq }),
|
|
2889
|
-
}),
|
|
2890
|
-
)
|
|
2891
|
-
.then(async res => {
|
|
2892
|
-
let data = {}
|
|
2893
|
-
try {
|
|
2894
|
-
data = await res.json()
|
|
2895
|
-
} catch {
|
|
2896
|
-
/* keep {} */
|
|
2897
|
-
}
|
|
2898
|
-
if (!res.ok || !data.ok) throw new Error(data.error || 'HTTP ' + res.status)
|
|
2899
|
-
notifyDone(t('done.revert'))
|
|
2900
|
-
// 0.9.6:回填被删掉的那句用户原文(边界是 AI 消息时取它之前那条用户消息)。
|
|
2901
|
-
// 此前这个入口完全不回填 —— 表现就是「回滚成功但消息框空着」。
|
|
2902
|
-
refillComposer(sessionId, seq)
|
|
2903
|
-
revealSession()
|
|
2904
|
-
emitChanged()
|
|
2905
|
-
})
|
|
2906
|
-
.catch(reason => {
|
|
2907
|
-
notifyDone(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error')
|
|
2908
|
-
})
|
|
2909
|
-
.finally(() => setBusy(null))
|
|
2910
|
-
}
|
|
2911
|
-
|
|
2912
3288
|
// ── 0.18.0:引用改用官方 insertQuote(结构化 QuoteNode)──────────────────
|
|
2913
3289
|
//
|
|
2914
3290
|
// 旧实现(0.5.0)用 `captureInsertion` + `insertText` 手工拼 `> ` markdown:
|
|
@@ -2928,19 +3304,80 @@ window.__ModuleLoader__.load({
|
|
|
2928
3304
|
// `$replaceDetectSpanWithNodes([$createQuoteNode(text, labels), Go(" ")])`
|
|
2929
3305
|
// 即:在当前光标处插入一个**真正的 QuoteNode**(带 remove 标签、独立 undo),
|
|
2930
3306
|
// 并自动补一个空格分隔。这才是"规范"的引用。
|
|
3307
|
+
/**
|
|
3308
|
+
* 0.19.0 引用:只引用「选中的一小段」,不再把整条 AI 消息塞进 composer。
|
|
3309
|
+
*
|
|
3310
|
+
* 用户原话:「这个引用为什么是直接把这个消息直接给我填进输入框,这什么情况?」
|
|
3311
|
+
* 根因:旧实现把 fullText / /text 接口返回的**整条全文**传给 insertQuote,
|
|
3312
|
+
* 于是 composer 里冒出一个几千字的巨大引用块,看起来就像"把消息整个塞进去"。
|
|
3313
|
+
*
|
|
3314
|
+
* 宿主官方 insertQuote 的语义是「引用一段选中文字」(QuoteNode +
|
|
3315
|
+
* QuotePreview 可视化 + 模型可见的 markdown blockquote),本就该用小段。
|
|
3316
|
+
*
|
|
3317
|
+
* 文本来源优先级:
|
|
3318
|
+
* 1. 用户在该消息内选中的文字(window.getSelection,限定消息节点内)
|
|
3319
|
+
* 2. 无选中 → 取整条但截断到 QUOTE_MAX_CHARS,并标注来源(seq / 角色)
|
|
3320
|
+
*/
|
|
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
|
+
}
|
|
3347
|
+
const selectionInMessage = () => {
|
|
3348
|
+
try {
|
|
3349
|
+
const sel = window.getSelection && window.getSelection()
|
|
3350
|
+
if (!sel || sel.isCollapsed || sel.rangeCount === 0) return null
|
|
3351
|
+
const text = String(sel.toString() || '').replace(/\s+$/g, '')
|
|
3352
|
+
if (!text || text.length > QUOTE_MAX_CHARS * 2) return null
|
|
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)
|
|
3358
|
+
} catch {
|
|
3359
|
+
return null
|
|
3360
|
+
}
|
|
3361
|
+
}
|
|
2931
3362
|
const runQuote = () => {
|
|
2932
|
-
|
|
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
|
+
)
|
|
2933
3371
|
try {
|
|
2934
3372
|
if (!inputActions || typeof inputActions.insertQuote !== 'function') {
|
|
2935
3373
|
finish(false)
|
|
2936
3374
|
return
|
|
2937
3375
|
}
|
|
2938
|
-
const put = text => {
|
|
3376
|
+
const put = (text, source) => {
|
|
2939
3377
|
if (typeof text !== 'string' || text.trim() === '') {
|
|
2940
3378
|
finish(false)
|
|
2941
3379
|
return
|
|
2942
3380
|
}
|
|
2943
|
-
// insertQuote 的返回值是 boolean(是否真的插入了)
|
|
2944
3381
|
let ok = false
|
|
2945
3382
|
try {
|
|
2946
3383
|
ok = inputActions.insertQuote(text.replace(/\r\n?/g, '\n')) !== false
|
|
@@ -2948,16 +3385,22 @@ window.__ModuleLoader__.load({
|
|
|
2948
3385
|
console.warn('[message-ops] insertQuote failed:', e)
|
|
2949
3386
|
ok = false
|
|
2950
3387
|
}
|
|
2951
|
-
finish(ok)
|
|
3388
|
+
finish(ok, ok ? source : null)
|
|
3389
|
+
}
|
|
3390
|
+
// ① 选中片段优先:正文就是选中的文字,无需来源标注
|
|
3391
|
+
const selected = selectionInMessage()
|
|
3392
|
+
if (selected != null) {
|
|
3393
|
+
put(selected, null)
|
|
3394
|
+
return
|
|
2952
3395
|
}
|
|
2953
|
-
//
|
|
3396
|
+
// ② 无选中:取整条但截断;来源只通过 toast 告知,不进引用正文
|
|
2954
3397
|
if (fullText != null && fullText !== '') {
|
|
2955
|
-
put(fullText)
|
|
3398
|
+
put(clipQuote(fullText), seq)
|
|
2956
3399
|
return
|
|
2957
3400
|
}
|
|
2958
3401
|
fetch('/api/message-ops/text?sessionId=' + encodeURIComponent(sessionId) + '&seq=' + encodeURIComponent(seq))
|
|
2959
3402
|
.then(r => (r.ok ? r.json() : null))
|
|
2960
|
-
.then(d => put(d && d.ok && typeof d.text === 'string' ? d.text : null))
|
|
3403
|
+
.then(d => put(d && d.ok && typeof d.text === 'string' ? clipQuote(d.text) : null, seq))
|
|
2961
3404
|
.catch(() => put(null))
|
|
2962
3405
|
} catch (e) {
|
|
2963
3406
|
notifyDone(t('errorPrefix') + (e && e.message ? e.message : String(e)), 'error')
|
|
@@ -2991,12 +3434,9 @@ window.__ModuleLoader__.load({
|
|
|
2991
3434
|
},
|
|
2992
3435
|
icon,
|
|
2993
3436
|
)
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
act(React.createElement(IconClock, { size: 16 }), t('slot.revert'), 'revert', runRevert, running),
|
|
2998
|
-
act(React.createElement(IconQuote, { size: 16 }), t('slot.quote'), 'quote', runQuote, false),
|
|
2999
|
-
)
|
|
3437
|
+
// 0.19.0(spec §9):AI 消息动作区只留「引用」。
|
|
3438
|
+
// 原时钟图标 = runRevert(回滚到此条),与用户消息回撤重复,用户要求删除。
|
|
3439
|
+
return act(React.createElement(IconQuote, { size: 16 }), t('slot.quote'), 'quote', runQuote, false)
|
|
3000
3440
|
}
|
|
3001
3441
|
|
|
3002
3442
|
// 0.4.2 引入(恢复的标记自动离开活跃列表 = opencode clear 语义)。
|
|
@@ -3213,10 +3653,11 @@ window.__ModuleLoader__.load({
|
|
|
3213
3653
|
if (step.reload) loadRef.current()
|
|
3214
3654
|
}, [sessionId, activityAt])
|
|
3215
3655
|
|
|
3216
|
-
//
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3656
|
+
// 0.19.0(spec §3.4):去掉「markers 变化就自动折叠」。
|
|
3657
|
+
// 用户反馈:点开 dock 后一操作就被收回去,很烦。折叠状态只由用户
|
|
3658
|
+
// 点击 header / chevron 改变;恢复=重放的语义与文案保持不变。
|
|
3659
|
+
// 注意:不能整个删掉这个 useEffect 的「早退之前」位置约束 —— 这里只是
|
|
3660
|
+
// 不再写 setOpen(false),Hooks 顺序不受影响(下方无其它 Hook 依赖它)。
|
|
3220
3661
|
if (!markers || !markers.length) return null
|
|
3221
3662
|
|
|
3222
3663
|
const restoreRow = row => {
|
|
@@ -3689,7 +4130,7 @@ window.__ModuleLoader__.load({
|
|
|
3689
4130
|
// 配不上(data-mops-unmatched)→ 禁用 + 说明原因,绝不留装饰按钮。
|
|
3690
4131
|
var syncEnabled = (block, btn) => {
|
|
3691
4132
|
if (!btn) return
|
|
3692
|
-
// 0.18.0
|
|
4133
|
+
// 0.18.0/0.20.0:三种按钮各有自己的提示文案(编辑按钮不能写 revert 的 hint)
|
|
3693
4134
|
const hintKey = btn.classList.contains('mopsUserFork')
|
|
3694
4135
|
? 'slot.forkHint'
|
|
3695
4136
|
: btn.classList.contains('mopsUserEdit')
|
|
@@ -3706,7 +4147,7 @@ window.__ModuleLoader__.load({
|
|
|
3706
4147
|
btn.setAttribute('data-mops-unmatched', '1')
|
|
3707
4148
|
}
|
|
3708
4149
|
}
|
|
3709
|
-
/** 块内全部插件按钮一起同步(回滚 / 分叉同一动作行)。 */
|
|
4150
|
+
/** 块内全部插件按钮一起同步(回滚 / 编辑 / 分叉同一动作行)。 */
|
|
3710
4151
|
var syncBlockButtons = block => {
|
|
3711
4152
|
if (!block || !block.querySelectorAll) return
|
|
3712
4153
|
for (const b of block.querySelectorAll('.mopsUserRevert, .mopsUserEdit, .mopsUserFork')) syncEnabled(block, b)
|
|
@@ -3920,14 +4361,46 @@ window.__ModuleLoader__.load({
|
|
|
3920
4361
|
return btn
|
|
3921
4362
|
}
|
|
3922
4363
|
|
|
4364
|
+
/** 0.12.0 分叉按钮:与回滚按钮**同一动作行**(opencode 把 fork 放在 copy/undo 同组)。 */
|
|
4365
|
+
var ensureForkBtn = block => {
|
|
4366
|
+
let host = block.querySelector('[class*="xzv4MW_actions"]')
|
|
4367
|
+
if (!host) {
|
|
4368
|
+
host = document.createElement('div')
|
|
4369
|
+
host.className = 'mopsUserActionsRow'
|
|
4370
|
+
block.appendChild(host)
|
|
4371
|
+
}
|
|
4372
|
+
const existing = host.querySelector('.mopsUserFork')
|
|
4373
|
+
if (existing) return existing
|
|
4374
|
+
const btn = document.createElement('button')
|
|
4375
|
+
btn.type = 'button'
|
|
4376
|
+
btn.className = 'mopsUserFork'
|
|
4377
|
+
btn.title = __t('slot.forkHint')
|
|
4378
|
+
btn.setAttribute('aria-label', __t('slot.fork'))
|
|
4379
|
+
// 官方 IconBranchOutline16 的 1:1 路径(packages/client/ui-primitives/src/icons/index.tsx:149)
|
|
4380
|
+
btn.innerHTML =
|
|
4381
|
+
'<svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="none"><path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M13.0762 1.37207C14.0846 1.37228 14.9021 2.19077 14.9023 3.19922C14.9022 4.20772 14.0847 5.02518 13.0762 5.02539C12.2967 5.02539 11.6325 4.53691 11.3701 3.84961H4.35547C4.79397 4.26458 5.15861 4.7644 5.41699 5.33496L7.10645 9.06738C7.88526 10.7875 9.55104 11.9228 11.4189 12.0371C11.7085 11.4109 12.3411 10.9756 13.0762 10.9756C14.0843 10.9759 14.9023 11.7936 14.9023 12.8018C14.9023 13.81 14.0843 14.6277 13.0762 14.6279C12.2534 14.6279 11.5574 14.0832 11.3291 13.335C8.9868 13.1879 6.89981 11.7612 5.92285 9.60352L4.23242 5.87109C3.67503 4.64033 2.44878 3.84961 1.09766 3.84961V2.54883C1.10665 2.54883 1.11601 2.54975 1.125 2.5498L11.3701 2.54883C11.6326 1.86151 12.2969 1.37207 13.0762 1.37207ZM13.0762 12.2764C12.7858 12.2764 12.5508 12.5114 12.5508 12.8018C12.5508 13.0921 12.7858 13.3281 13.0762 13.3281C13.3664 13.3279 13.6025 13.092 13.6025 12.8018C13.6025 12.5115 13.3664 12.2766 13.0762 12.2764ZM13.0762 2.67285C12.7855 2.67285 12.55 2.90861 12.5498 3.19922C12.5499 3.48987 12.7855 3.72559 13.0762 3.72559C13.3667 3.72538 13.6024 3.48975 13.6025 3.19922C13.6023 2.90874 13.3666 2.67306 13.0762 2.67285Z"/></svg>'
|
|
4382
|
+
btn.addEventListener('click', e => {
|
|
4383
|
+
e.preventDefault()
|
|
4384
|
+
e.stopPropagation()
|
|
4385
|
+
if (btn.disabled) return
|
|
4386
|
+
runUserFork(btn, block)
|
|
4387
|
+
})
|
|
4388
|
+
host.appendChild(btn)
|
|
4389
|
+
syncEnabled(block, btn)
|
|
4390
|
+
return btn
|
|
4391
|
+
}
|
|
4392
|
+
|
|
3923
4393
|
/**
|
|
3924
|
-
* 0.
|
|
4394
|
+
* 0.20.0 铅笔编辑按钮:与回滚**同一动作行**,插在回滚与分叉之间。
|
|
4395
|
+
*
|
|
4396
|
+
* 语义 = 打开「编辑并重发」浮层(`EditResendOverlay`),编辑框里改文字;
|
|
4397
|
+
* **点「发送并回撤」那一刻**才回撤并重发。点按钮本身零写操作。
|
|
3925
4398
|
*
|
|
3926
|
-
*
|
|
3927
|
-
*
|
|
3928
|
-
*
|
|
4399
|
+
* 与 0.19.0 删掉的行内编辑的区别:那版只是把原文**回填 composer**
|
|
4400
|
+
* (`refillComposer`),跟回滚回填是同一件事,所以被判为重复入口而删除。
|
|
4401
|
+
* 这一版是独立编辑框 + 延迟回撤,是用户明确要求的产品行为。
|
|
3929
4402
|
*
|
|
3930
|
-
* 图标取官方 `edit-outline
|
|
4403
|
+
* 图标取官方 `edit-outline` 几何(16 viewBox,填充几何 —— 与分叉图标同族写法)。
|
|
3931
4404
|
*/
|
|
3932
4405
|
var ensureEditBtn = block => {
|
|
3933
4406
|
let host = block.querySelector('[class*="xzv4MW_actions"]')
|
|
@@ -3941,9 +4414,9 @@ window.__ModuleLoader__.load({
|
|
|
3941
4414
|
const btn = document.createElement('button')
|
|
3942
4415
|
btn.type = 'button'
|
|
3943
4416
|
btn.className = 'mopsUserEdit'
|
|
3944
|
-
btn.title = __t('slot.
|
|
4417
|
+
btn.title = __t('slot.editHint')
|
|
3945
4418
|
btn.setAttribute('aria-label', __t('slot.edit'))
|
|
3946
|
-
// 铅笔:官方 edit-outline
|
|
4419
|
+
// 铅笔:官方 edit-outline 的几何(与分支图标同为 fill 几何,不用 stroke)
|
|
3947
4420
|
btn.innerHTML =
|
|
3948
4421
|
'<svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="none">' +
|
|
3949
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"/>' +
|
|
@@ -3960,32 +4433,37 @@ window.__ModuleLoader__.load({
|
|
|
3960
4433
|
}
|
|
3961
4434
|
|
|
3962
4435
|
/**
|
|
3963
|
-
* 0.
|
|
4436
|
+
* 0.20.0 行内编辑入口:解析 seq → 派发 `EDIT_EVENT` 打开编辑浮层。
|
|
3964
4437
|
*
|
|
3965
|
-
*
|
|
3966
|
-
*
|
|
4438
|
+
* 这一步**纯读**:`ensureAssign` / `fetchRows` 只读 `/api/message-ops/messages`,
|
|
4439
|
+
* 不发任何写请求、不改草稿。真正的写操作全在 `sendEditAndRevert` 里,
|
|
4440
|
+
* 由用户在编辑框里点「发送并回撤」才触发。
|
|
3967
4441
|
*/
|
|
3968
4442
|
var runUserEdit = (btn, block) => {
|
|
3969
4443
|
const sid = __currentSessionId
|
|
3970
4444
|
if (!sid) return
|
|
3971
|
-
const seq = Number(block.getAttribute('data-mops-seq'))
|
|
3972
|
-
if (!Number.isFinite(seq)) {
|
|
3973
|
-
notifyDone(__t('errorPrefix') + __t('slot.revertUnmatched'), 'error')
|
|
3974
|
-
return
|
|
3975
|
-
}
|
|
3976
4445
|
btn.disabled = true
|
|
3977
4446
|
Promise.resolve()
|
|
3978
4447
|
.then(() => ensureAssign(sid))
|
|
3979
4448
|
.then(() => fetchRows(sid))
|
|
3980
4449
|
.then(cache => {
|
|
3981
4450
|
const rows = cache && cache.rows
|
|
4451
|
+
const seq = Number(block.getAttribute('data-mops-seq'))
|
|
3982
4452
|
const row = rows && rows.find(r => r.seq === seq)
|
|
3983
4453
|
if (!row) {
|
|
3984
|
-
notifyDone(__t('errorPrefix') + __t('slot.
|
|
4454
|
+
notifyDone(__t('errorPrefix') + __t('slot.editUnmatched'), 'error')
|
|
4455
|
+
return
|
|
4456
|
+
}
|
|
4457
|
+
if (!Number.isSafeInteger(seq) || seq < 0) {
|
|
4458
|
+
notifyDone(__t('slot.editUnmatched'), 'warn')
|
|
3985
4459
|
return
|
|
3986
4460
|
}
|
|
3987
|
-
|
|
3988
|
-
|
|
4461
|
+
// 裸 uuid 给 HTTP,带前缀的给 openSession 与草稿键
|
|
4462
|
+
window.dispatchEvent(
|
|
4463
|
+
new CustomEvent(EDIT_EVENT, {
|
|
4464
|
+
detail: { sessionId: bareSessionId(sid), rawSessionId: sid, seq: seq },
|
|
4465
|
+
}),
|
|
4466
|
+
)
|
|
3989
4467
|
})
|
|
3990
4468
|
.catch(reason => {
|
|
3991
4469
|
notifyDone(__t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)), 'error')
|
|
@@ -3995,39 +4473,11 @@ window.__ModuleLoader__.load({
|
|
|
3995
4473
|
})
|
|
3996
4474
|
}
|
|
3997
4475
|
|
|
3998
|
-
|
|
3999
|
-
var ensureForkBtn = block => {
|
|
4000
|
-
let host = block.querySelector('[class*="xzv4MW_actions"]')
|
|
4001
|
-
if (!host) {
|
|
4002
|
-
host = document.createElement('div')
|
|
4003
|
-
host.className = 'mopsUserActionsRow'
|
|
4004
|
-
block.appendChild(host)
|
|
4005
|
-
}
|
|
4006
|
-
const existing = host.querySelector('.mopsUserFork')
|
|
4007
|
-
if (existing) return existing
|
|
4008
|
-
const btn = document.createElement('button')
|
|
4009
|
-
btn.type = 'button'
|
|
4010
|
-
btn.className = 'mopsUserFork'
|
|
4011
|
-
btn.title = __t('slot.forkHint')
|
|
4012
|
-
btn.setAttribute('aria-label', __t('slot.fork'))
|
|
4013
|
-
// 官方 IconBranchOutline16 的 1:1 路径(packages/client/ui-primitives/src/icons/index.tsx:149)
|
|
4014
|
-
btn.innerHTML =
|
|
4015
|
-
'<svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="none"><path fill="currentColor" fill-rule="evenodd" clip-rule="evenodd" d="M13.0762 1.37207C14.0846 1.37228 14.9021 2.19077 14.9023 3.19922C14.9022 4.20772 14.0847 5.02518 13.0762 5.02539C12.2967 5.02539 11.6325 4.53691 11.3701 3.84961H4.35547C4.79397 4.26458 5.15861 4.7644 5.41699 5.33496L7.10645 9.06738C7.88526 10.7875 9.55104 11.9228 11.4189 12.0371C11.7085 11.4109 12.3411 10.9756 13.0762 10.9756C14.0843 10.9759 14.9023 11.7936 14.9023 12.8018C14.9023 13.81 14.0843 14.6277 13.0762 14.6279C12.2534 14.6279 11.5574 14.0832 11.3291 13.335C8.9868 13.1879 6.89981 11.7612 5.92285 9.60352L4.23242 5.87109C3.67503 4.64033 2.44878 3.84961 1.09766 3.84961V2.54883C1.10665 2.54883 1.11601 2.54975 1.125 2.5498L11.3701 2.54883C11.6326 1.86151 12.2969 1.37207 13.0762 1.37207ZM13.0762 12.2764C12.7858 12.2764 12.5508 12.5114 12.5508 12.8018C12.5508 13.0921 12.7858 13.3281 13.0762 13.3281C13.3664 13.3279 13.6025 13.092 13.6025 12.8018C13.6025 12.5115 13.3664 12.2766 13.0762 12.2764ZM13.0762 2.67285C12.7855 2.67285 12.55 2.90861 12.5498 3.19922C12.5499 3.48987 12.7855 3.72559 13.0762 3.72559C13.3667 3.72538 13.6024 3.48975 13.6025 3.19922C13.6023 2.90874 13.3666 2.67306 13.0762 2.67285Z"/></svg>'
|
|
4016
|
-
btn.addEventListener('click', e => {
|
|
4017
|
-
e.preventDefault()
|
|
4018
|
-
e.stopPropagation()
|
|
4019
|
-
if (btn.disabled) return
|
|
4020
|
-
runUserFork(btn, block)
|
|
4021
|
-
})
|
|
4022
|
-
host.appendChild(btn)
|
|
4023
|
-
syncEnabled(block, btn)
|
|
4024
|
-
return btn
|
|
4025
|
-
}
|
|
4026
|
-
// 两个按钮的顺序由 DOM 顺序决定:回滚在前(破坏性更高),分叉在后(非破坏)。
|
|
4476
|
+
// 三个按钮的顺序由 DOM 顺序决定:回滚在前(破坏性更高),编辑居中,分叉最后(非破坏)。
|
|
4027
4477
|
var ensureUserActions = block => {
|
|
4478
|
+
// 0.20.0:铅笔回归,但语义变了 —— 独立编辑框 + 点「发送并回撤」才写,
|
|
4479
|
+
// 不再是 0.18.0 那种「只回填 composer」的伪编辑。
|
|
4028
4480
|
ensureBtn(block)
|
|
4029
|
-
// 0.18.0:编辑按钮与回滚**同一动作行**(用户要求:和回撤放同一个地方)。
|
|
4030
|
-
// 顺序 = 回滚 → 编辑 → 分叉,破坏性从左到右递减。
|
|
4031
4481
|
ensureEditBtn(block)
|
|
4032
4482
|
ensureForkBtn(block)
|
|
4033
4483
|
}
|
|
@@ -4488,7 +4938,7 @@ window.__ModuleLoader__.load({
|
|
|
4488
4938
|
// **紧接着** `openSession(sid)` 重建整个会话视图。重建会卸载并重挂
|
|
4489
4939
|
// 编辑器,新挂载走 `readConversationDraft(sid)` 从 localStorage 初始化 ——
|
|
4490
4940
|
// 也就是说「回填」实际取决于 persistDraft 是否成功落盘,而再叠上
|
|
4491
|
-
// `bindDraftPersistence` 的时序(见
|
|
4941
|
+
// `bindDraftPersistence` 的时序(见 0.13.1 MED-4),失败时
|
|
4492
4942
|
// 用户看到「已回滚」却拿不到原文。
|
|
4493
4943
|
//
|
|
4494
4944
|
// 唯一无竞态的路径:**直接写宿主的草稿存储键**(writeSessionDraft),
|
|
@@ -4733,6 +5183,18 @@ window.__ModuleLoader__.load({
|
|
|
4733
5183
|
window.__MOPS_LEGACY_DIALOG === true ? OpsDialog : OpsPanel,
|
|
4734
5184
|
),
|
|
4735
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
|
+
)
|
|
4736
5198
|
installSidebarOps()
|
|
4737
5199
|
installUserRevertInjector()
|
|
4738
5200
|
}
|
|
@@ -4740,7 +5202,19 @@ window.__ModuleLoader__.load({
|
|
|
4740
5202
|
return {
|
|
4741
5203
|
apply,
|
|
4742
5204
|
inject: ['slots'],
|
|
4743
|
-
__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
|
+
},
|
|
4744
5218
|
}
|
|
4745
5219
|
},
|
|
4746
5220
|
})
|