@240xu/dsh-message-ops 0.24.0 → 0.47.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.
@@ -0,0 +1,260 @@
1
+ // ══ 10-i18n · zh / en 字典 ══
2
+
3
+ // 0.9.7(P0-4):zh/en 两本字典 key 集合**必须一致且顺序一致**——宿主 locale
4
+ // 的 translate() 按「活跃语言 → en」回退链查表(zh 回退 en,en 无回退),
5
+ // 所以缺 key 不一定看得见:zh 缺 → 落到 en(0.9.x 这批 en 值是中文,
6
+ // zh 用户"碰巧"正常);en 缺 → 直接把 key 当文案显示。
7
+ // 反过来 en 值写成中文时,英文用户会看到中文。测试锁死了两侧 key 序列相等。
8
+ const zhDict = {
9
+ 'button.title': '消息操作(回滚/删除/分支)',
10
+ 'dialog.title': '消息操作',
11
+ 'dialog.cancel': '关闭',
12
+ 'slot.revert': '回滚到此条',
13
+ 'slot.revertPrivacyHint': '回滚到此条(不是删除:AI 看不到,但原文仍在本地会话文件)',
14
+ 'slot.revertUnmatched': '在日志里定位不到这条消息的 seq(通常是模型写的摘要与渲染文本偏差过大)——请改用「消息操作」对话框。',
15
+ 'slot.forkUnavailable': '分叉不可用:会话正在运行,或宿主未提供 session/fork',
16
+ // 0.24.0(P3 入口收敛):改名消除与外部插件 message-edit 的「同名不同义」。
17
+ // 外部插件在 turnTail 也叫「编辑并重发」,但它 fork 出新分支、源会话不动;
18
+ // 我们(铅笔)是**回撤源会话**再重发。同名让用户无法预判后果,故显式写出「回撤」。
19
+ 'slot.edit': '编辑并回撤重发',
20
+ 'slot.editHint': '打开编辑框;点「撤销并发送」会回撤此条及之后的全部可见消息,再把改后文本当新消息发出',
21
+ 'slot.editUnmatched': '在日志里定位不到这条消息的 seq,暂时无法编辑',
22
+ 'edit.title': '编辑并回撤重发',
23
+ 'edit.placeholder': '编辑这条消息…',
24
+ 'edit.cancel': '取消',
25
+ 'edit.send': '撤销并发送',
26
+ 'edit.sending': '撤销并发送中…',
27
+ 'edit.sendFailed': '回撤已生效,但发送被拒:',
28
+ 'edit.empty': '内容为空,无法发送',
29
+ 'edit.failed': '回撤失败:',
30
+ 'edit.doneSubmitted': '已回撤,改后的消息已提交',
31
+ 'edit.manual': '已回撤,改后的文本已放进输入框——请按回车发送',
32
+ 'edit.running': '会话正在运行:可以先改文字,但要等它停下来才能撤销并发送',
33
+ 'edit.replaceHint':
34
+ '发送会先回撤此条及其之后的全部可见消息,再把改后的文本作为新消息发出。注意:这不是删除——AI 看不到被回撤的内容,但原文仍保留在本地会话文件、可被恢复,直接翻看会话文件仍能读到。',
35
+ 'edit.shortcut': 'Enter 发送 · Shift+Enter 换行 · Esc 取消',
36
+ 'done.restore': '恢复完成:重放 {n} 条,跳过不可重放 {s} 条',
37
+ 'done.revert': '已回滚,原文可从恢复区放回',
38
+ 'done.revertNoRefill': '已回滚,但原文未能放回输入框(会话可能尚未挂载);可重试或从消息操作面板手动复制',
39
+ errorPrefix: '操作失败:',
40
+ 'dock.title': '已回撤 {n} 条消息',
41
+ 'dock.titlePending': '{n} 轮待恢复(共 {m} 条仍被回撤)',
42
+ 'dock.titleTurns': '已回撤 {n} 条记录',
43
+ 'dock.stale': '这条回撤已被后续回撤取代,已从列表移除。',
44
+ 'dock.expand': '展开回撤列表',
45
+ 'dock.collapse': '折叠回撤列表',
46
+ 'dock.restore': '恢复',
47
+ 'dock.restoreHint': '恢复为重放:消息将出现在会话末尾,不会回到原位',
48
+ 'dock.restoring': '恢复中…',
49
+ 'dock.discardLink': '不再恢复,直接丢弃',
50
+ 'dock.discardHint': '丢弃后这段对话永久不再出现在界面,也不会回到输入框;不可撤销',
51
+ 'dock.discardConfirm': '确认永久丢弃这段被回撤的对话(共 {n} 条)?',
52
+ 'dock.discardYes': '确认丢弃',
53
+ 'dock.discardCancel': '取消',
54
+ 'dock.discardDone': '已丢弃:不再恢复这段对话',
55
+ 'dock.discarding': '丢弃中…',
56
+ 'undo.label': '回滚上一条消息',
57
+ 'undo.desc': '移除最后一条用户消息,原文回填输入框',
58
+ 'undo.done.undo': '已回滚上一条消息',
59
+ 'undo.done.redo': '已恢复上一条被回滚的消息',
60
+ 'undo.none': '没有可回滚的消息',
61
+ 'undo.none.redo': '没有可恢复的回滚',
62
+ 'redo.label': '恢复上一条被回滚的消息',
63
+ 'redo.desc': '把回滚掉的消息重新放回对话',
64
+ 'panel.messages': '消息',
65
+ 'panel.trash': '回收站',
66
+ 'panel.search': '搜索当前会话',
67
+ 'panel.searchHint': '搜索全文,不只是摘要',
68
+ 'panel.all': '全部',
69
+ 'panel.user': '用户',
70
+ 'panel.assistant': '助手',
71
+ 'panel.tool': '工具',
72
+ 'panel.includeShadowed': '含已回滚',
73
+ 'panel.loading': '正在读取…',
74
+ 'panel.loadFail': '读取失败:',
75
+ 'panel.searchFail': '搜索失败:',
76
+ 'panel.empty': '没有可显示的消息。',
77
+ 'panel.noMatch': '没有匹配结果。',
78
+ 'panel.selectHint': '选择一条消息,查看全文和操作。',
79
+ 'panel.detailLoading': '正在读取全文…',
80
+ 'panel.shadowed': '已回滚',
81
+ 'panel.running': '会话正在运行:回滚、删除、分支需先停止。',
82
+ 'panel.revert': '回滚到此条',
83
+ 'panel.revertHint': '包含此条及其后的可见消息',
84
+ 'panel.revertConfirmTitle': '回滚到 #{seq}?',
85
+ // 0.23.0:隐私告知并入确认正文(原 body 37 字 + privacy 56 字 = 93 字,合并后 55 字)。
86
+ // 告知内容一条没少:AI 看不到 / 原文仍在本地文件 / 可恢复。只是不再分两层说。
87
+ 'panel.revertConfirmBody':
88
+ '将遮蔽 #{start}–#{end} 共 {n} 条消息(可见 {v} 条)。AI 将看不到它们,但原文仍保留在本地会话文件、可恢复。',
89
+ 'panel.deleteConfirmTitle': '仅遮蔽 #{seq}?',
90
+ 'panel.timeout': '请求超时(结果未知,请刷新确认后再操作)。',
91
+ 'panel.deleteConfirmBody': '将遮蔽这 1 条消息,其他内容不动;日志仍保留,可恢复。',
92
+ 'panel.confirmRevert': '确认回滚',
93
+ 'panel.confirmDeleteOne': '确认遮蔽',
94
+ 'panel.retry': '重试',
95
+ 'panel.searching': '搜索中…',
96
+ 'panel.deleteSessionImpact': '共 {n} 条消息;移入回收站后 7 天内可恢复。',
97
+ 'panel.deleteUnavailable': '会话信息尚未就绪,暂不能删除。',
98
+ 'panel.delete': '遮蔽此条',
99
+ 'panel.deleteHint': '只遮蔽这一条,其他消息不动',
100
+ 'panel.branch': '从此条分叉',
101
+ 'panel.branchHint': '复制此条之前的对话到新会话,并把此条原文放回新会话输入框',
102
+ 'panel.branchDone': '已分叉:新会话 {id}',
103
+ 'panel.textFail': '读取原文失败,无法分叉(不会用摘要代替)。',
104
+ 'panel.snippetOnly': '原文读取失败,这里只是前 160 字摘要,不是完整消息。',
105
+ 'panel.detailTimeout': '读取全文超时,这里只是前 160 字摘要,不是完整消息。',
106
+ 'panel.branchUserOnly': '分叉只对用户消息可用(AI 消息没有可回填的原文)',
107
+ // 0.17.0(冲突 R2):行为是「复制原文到输入框」,不修改原消息。
108
+ // 旧文案「编辑并重发」暗示会改原消息,实测会误导(发出后是新增一条,
109
+ // 原消息仍在,界面出现两条相似消息)。opencode 也没有消息级编辑。
110
+ 'panel.openNew': '打开新会话',
111
+ 'panel.revertDone': '回滚已生效',
112
+ 'panel.deleteDone': '已遮蔽',
113
+ 'panel.count': '共 {n} 条 · 可见 {v} · 已回滚 {s}',
114
+ 'panel.deleteSession': '删除整条会话',
115
+ 'panel.deleteSessionHint': '移入回收站,7 天内可恢复。请输入标题确认:',
116
+ 'panel.cancel': '取消',
117
+ 'panel.confirmDelete': '确认删除',
118
+ 'panel.deleting': '删除中…',
119
+ 'panel.deleted': '会话已移入回收站',
120
+ 'panel.trashEmpty': '回收站是空的。',
121
+ 'panel.untitled': '未命名会话',
122
+ 'panel.restore': '恢复',
123
+ 'panel.purge': '永久删除',
124
+ // 0.42.0(srv-audit D9/D10):回收站条目异常态(moving=删除中断留孤本;corrupt=清单损坏)
125
+ 'panel.trashMoving': '删除中断,仅存副本留作人工恢复',
126
+ 'panel.trashCorrupt': '清单损坏,只能永久删除',
127
+ 'panel.trashManual': '需人工处理',
128
+ 'panel.purgeConfirm': '再点一次永久删除',
129
+ 'panel.restored': '会话已恢复',
130
+ 'panel.purged': '回收站条目已永久删除',
131
+ 'panel.expires': '到期',
132
+ 'panel.busy': '处理中…',
133
+ 'menu.ops': '消息操作',
134
+ }
135
+
136
+ const enDict = {
137
+ 'button.title': 'Message ops (revert / delete / branch)',
138
+ 'dialog.title': 'Message ops',
139
+ 'dialog.cancel': 'Close',
140
+ 'slot.revert': 'Revert to here',
141
+ 'slot.revertPrivacyHint': 'Revert to here (not deletion: hidden from the AI, but the original text stays in the local session file)',
142
+ 'slot.revertUnmatched':
143
+ '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.',
144
+ 'slot.forkUnavailable': 'Branch unavailable: the session is running, or the host provides no session/fork',
145
+ // 0.24.0 (P3): renamed to disambiguate from the third-party message-edit plugin,
146
+ // which also says "Edit and resend" but forks a NEW branch and leaves the source
147
+ // session untouched. This one REVERTS the source session. Same words, opposite
148
+ // consequences — so the revert is now spelled out in the label itself.
149
+ 'slot.edit': 'Edit & revert-resend',
150
+ 'slot.editHint':
151
+ 'Opens the editor. Pressing "Undo and send" reverts this message and every visible message after it, then sends the edited text as a new message.',
152
+ 'slot.editUnmatched': 'Cannot locate this message seq in the log, so it cannot be edited yet',
153
+ 'edit.title': 'Edit & revert-resend',
154
+ 'edit.placeholder': 'Edit this message…',
155
+ 'edit.cancel': 'Cancel',
156
+ 'edit.send': 'Undo and send',
157
+ 'edit.sending': 'Undoing and sending…',
158
+ 'edit.sendFailed': 'The revert went through, but sending was rejected: ',
159
+ 'edit.empty': 'Nothing to send — the text is empty',
160
+ 'edit.failed': 'Revert failed: ',
161
+ 'edit.doneSubmitted': 'Reverted; the edited message has been submitted',
162
+ 'edit.manual': 'Reverted; the edited text is in the composer — press Enter to send',
163
+ 'edit.running': 'The session is running: edit freely, but Undo and send waits until it stops',
164
+ 'edit.replaceHint':
165
+ 'Sending reverts this message and every visible message after it, then sends the edited text as a new message. Note: this is not deletion — the AI will not see the reverted content, but the original text stays in the local session file, can be restored, and is still readable by opening that file directly.',
166
+ 'edit.shortcut': 'Enter to send · Shift+Enter for a new line · Esc to cancel',
167
+ 'done.restore': 'Restored: replayed {n}, skipped non-replayable {s}',
168
+ 'done.revert': 'Reverted — restore the original from the restore area',
169
+ 'done.revertNoRefill':
170
+ 'Reverted, but the original text could not be put back in the composer (the view may not be mounted yet); retry or copy it manually from Message Ops',
171
+ errorPrefix: 'Operation failed: ',
172
+ 'dock.title': '{n} rolled back messages',
173
+ 'dock.titlePending': '{n} pending to restore ({m} still rolled back)',
174
+ 'dock.titleTurns': '{n} revert records',
175
+ 'dock.stale': 'This revert was superseded by a later one; removed from the list.',
176
+ 'dock.expand': 'Expand revert list',
177
+ 'dock.collapse': 'Collapse revert list',
178
+ 'dock.restore': 'Restore',
179
+ 'dock.restoreHint': 'Restores by replay: messages appear at the end of the session, not in their original place',
180
+ 'dock.restoring': 'Restoring…',
181
+ 'dock.discardLink': 'Do not restore, discard instead',
182
+ 'dock.discardHint': 'Discarded messages never return to the transcript or the composer; this cannot be undone',
183
+ 'dock.discardConfirm': 'Permanently discard this rolled-back conversation ({n} messages)?',
184
+ 'dock.discardYes': 'Discard',
185
+ 'dock.discardCancel': 'Cancel',
186
+ 'dock.discardDone': 'Discarded: this conversation will not be restored',
187
+ 'dock.discarding': 'Discarding…',
188
+ 'undo.label': 'Undo last message',
189
+ 'undo.desc': 'Remove the last user message and put its original text back into the composer',
190
+ 'undo.done.undo': 'Undid the last message',
191
+ 'undo.done.redo': 'Restored the last reverted message',
192
+ 'undo.none': 'No message to undo',
193
+ 'undo.none.redo': 'No revert to redo',
194
+ 'redo.label': 'Restore the last reverted message',
195
+ 'redo.desc': 'Put the reverted message back into the conversation',
196
+ 'panel.messages': 'Messages',
197
+ 'panel.trash': 'Trash',
198
+ 'panel.search': 'Search this session',
199
+ 'panel.searchHint': 'Search full text, not just snippets',
200
+ 'panel.all': 'All',
201
+ 'panel.user': 'User',
202
+ 'panel.assistant': 'Assistant',
203
+ 'panel.tool': 'Tool',
204
+ 'panel.includeShadowed': 'Include shadowed',
205
+ 'panel.loading': 'Loading…',
206
+ 'panel.loadFail': 'Failed to load: ',
207
+ 'panel.searchFail': 'Search failed: ',
208
+ 'panel.empty': 'No messages to show.',
209
+ 'panel.noMatch': 'No matches.',
210
+ 'panel.selectHint': 'Pick a message to see its full text and actions.',
211
+ 'panel.detailLoading': 'Loading full text…',
212
+ 'panel.shadowed': 'reverted',
213
+ 'panel.running': 'Session is running: stop it before revert, delete, or branch.',
214
+ 'panel.revert': 'Revert to here',
215
+ 'panel.revertHint': 'Includes this message and all visible messages after it',
216
+ 'panel.revertConfirmTitle': 'Revert to #{seq}?',
217
+ 'panel.revertConfirmBody':
218
+ 'Shadows {n} messages (#{start}–#{end}, {v} visible). The AI will no longer see them, but the original text stays in the local session file and can be restored.',
219
+ 'panel.deleteConfirmTitle': 'Hide only #{seq}?',
220
+ 'panel.timeout': 'Request timed out (result unknown — refresh before retrying).',
221
+ 'panel.deleteConfirmBody': 'This shadows this one message; everything else stays. The log stays append-only and can be restored.',
222
+ 'panel.confirmRevert': 'Confirm revert',
223
+ 'panel.confirmDeleteOne': 'Confirm hide',
224
+ 'panel.retry': 'Retry',
225
+ 'panel.searching': 'Searching…',
226
+ 'panel.deleteSessionImpact': 'Total {n} messages; recoverable from trash for 7 days.',
227
+ 'panel.deleteUnavailable': 'Session details are not ready yet; deletion is disabled.',
228
+ 'panel.delete': 'Hide this',
229
+ 'panel.deleteHint': 'Shadows only this message',
230
+ 'panel.branch': 'Fork from here',
231
+ 'panel.branchHint': 'Copy the conversation above this message into a new session and put this message back in the new composer',
232
+ 'panel.branchDone': 'Forked: {id}',
233
+ 'panel.textFail': 'Could not read the original text; branch cancelled (a snippet is never used).',
234
+ 'panel.snippetOnly': 'The full text could not be loaded; this is only the first 160 characters.',
235
+ 'panel.detailTimeout': 'Timed out loading the full text; this is only the first 160 characters.',
236
+ 'panel.branchUserOnly': 'Fork works on user messages only (assistant messages have no text to hand back)',
237
+ 'panel.openNew': 'Open new session',
238
+ 'panel.revertDone': 'Revert applied',
239
+ 'panel.deleteDone': 'Hidden',
240
+ 'panel.count': 'Total {n} · visible {v} · shadowed {s}',
241
+ 'panel.deleteSession': 'Delete whole session',
242
+ 'panel.deleteSessionHint': 'Moves it to trash for 7 days. Type the title to confirm:',
243
+ 'panel.cancel': 'Cancel',
244
+ 'panel.confirmDelete': 'Delete',
245
+ 'panel.deleting': 'Deleting…',
246
+ 'panel.deleted': 'Session moved to trash',
247
+ 'panel.trashEmpty': 'Trash is empty.',
248
+ 'panel.untitled': 'Untitled session',
249
+ 'panel.restore': 'Restore',
250
+ 'panel.purge': 'Delete forever',
251
+ 'panel.trashMoving': 'Delete was interrupted; the only copy is kept for manual recovery',
252
+ 'panel.trashCorrupt': 'Manifest is corrupt; only deleting forever is possible',
253
+ 'panel.trashManual': 'Needs manual handling',
254
+ 'panel.purgeConfirm': 'Click again to delete forever',
255
+ 'panel.restored': 'Session restored',
256
+ 'panel.purged': 'Trash entry permanently deleted',
257
+ 'panel.expires': 'expires',
258
+ 'panel.busy': 'Working…',
259
+ 'menu.ops': 'Message ops',
260
+ }
@@ -0,0 +1,311 @@
1
+ // ══ 20-host-state · 宿主状态:locale / sessions / inputActions / __t / 面板样式 ══
2
+ var __locale = null
3
+ var __sessionsSvc = null
4
+ /**
5
+ * 0.24.0 P4:InputActions **按会话隔离**。
6
+ *
7
+ * 为什么必须隔离:宿主 `conversation.chat.assistant-actions` 槽声明
8
+ * `scope: "session"`(dsh-client-ui-chat:9238),且 `inputActions` 由
9
+ * `inputHub.shellFor(binding).actions` 提供(dsh-client-ui-conversation:22713)。
10
+ * `shellFor` 按 binding 缓存**独立的 SessionInputShell**(:16145-16147),
11
+ * 每个会话的 `.actions` 是不同对象。
12
+ *
13
+ * 旧实现用模块级单变量 `__inputActions`,写入点是 per-session 组件:
14
+ * · MsgSlotActions —— 每条 AI 消息一个实例
15
+ * · RevertDock —— 每个会话一个实例
16
+ * 多会话同时挂载 / 切会话 / HMR 时会被**最后挂载的会话**覆盖,
17
+ * 于是回填、编辑框提交、dock 内联恢复都可能写进**别的会话的 composer**。
18
+ *
19
+ * 现在:`sessionId -> InputActions`。读写一律按会话取,
20
+ * 取不到就走**明确失败路径**,绝不静默退到别的会话。
21
+ * (0.25.0 清理:无 sessionId 的全局兜底变量 `__inputActions` 已删除——
22
+ * 它 0 个读取方,留着只会让后来者以为还有一条「最后一次已知」的退路。)
23
+ */
24
+ var __inputActionsBySession = new Map()
25
+
26
+ /** 会话键归一:`session-x` 与 `x` 视为同一会话(宿主两种拼写都会传)。 */
27
+ function sessionKeyOf(sessionId) {
28
+ if (typeof sessionId !== 'string' || sessionId === '') return null
29
+ return sessionId.startsWith('session-') ? sessionId.slice('session-'.length) : sessionId
30
+ }
31
+
32
+ /**
33
+ * 按会话取 InputActions。
34
+ * @returns 该会话的 InputActions,或 null(调用方必须显式处理 null,不得回退到别的会话)
35
+ */
36
+ function inputActionsFor(sessionId) {
37
+ const key = sessionKeyOf(sessionId)
38
+ if (key == null) return null
39
+ return __inputActionsBySession.get(key) || null
40
+ }
41
+
42
+ /** 捕获:会话挂载时登记它自己的 InputActions。 */
43
+ function rememberInputActions(sessionId, inputActions) {
44
+ if (!inputActions || typeof inputActions.setDraft !== 'function') return
45
+ const key = sessionKeyOf(sessionId)
46
+ if (key == null) return
47
+ __inputActionsBySession.set(key, inputActions)
48
+ }
49
+
50
+ /** 卸载:只在登记的仍是这一个实例时才删,避免把同会话新挂的实例删掉。 */
51
+ function forgetInputActions(sessionId, inputActions) {
52
+ const key = sessionKeyOf(sessionId)
53
+ if (key == null) return
54
+ if (__inputActionsBySession.get(key) === inputActions) __inputActionsBySession.delete(key)
55
+ }
56
+ var __uiWorkspace = null
57
+ var __currentSessionId = null
58
+ // 0.9.1:视图重建后刷新 transcript 可见性的钩子。
59
+ // 之前 restore 路径里直接调 scan(),但 scan 定义在注入器的闭包里,
60
+ // dock 组件根本取不到 —— `typeof scan === 'function'` 静默跳过了,
61
+ // 结果「恢复后消息回来了但仍被藏 / dock 计数不变」,必须重载页面才对。
62
+ var __refreshSurface = null
63
+ // 0.9.3:注入器闭包内 rowsCache 的只读出口。
64
+ // rowsCache 声明在 installUserRevertInjector() 内(闭包私有),而 /undo 的
65
+ // onPick 在模块级作用域 —— 直接引用会 ReferenceError,表现为点菜单毫无反应。
66
+ var __peekRowsCache = null // 0.6.0:会话视图会话 id(RevertDock/MsgSlotActions 刷新)
67
+ // 0.25.0 清理:messageId→seq / messageId→全文 两份缓存已删。
68
+ // 它们唯一的读者是 MsgSlotActions 的引用解析(0.23.0 起该插槽 return null),
69
+ // 写入方 syncSeqIndex 也随之删除;dataSig 驱动的失效广播一并退场。
70
+ // 现在 seq 的唯一权威来源是 rowsCache(DOM 注入器自己按会话维护)。
71
+
72
+ function localeFallbackLang() {
73
+ if (typeof navigator === 'undefined') return 'zh'
74
+ for (const tag of (navigator.languages || []).concat([navigator.language])) {
75
+ const primary = String(tag || '')
76
+ .toLowerCase()
77
+ .split('-')[0]
78
+ if (primary === 'zh' || primary === 'en') return primary
79
+ }
80
+ return 'zh'
81
+ }
82
+
83
+ function __t(key, vars) {
84
+ let text = key
85
+ if (__locale && typeof __locale.translate === 'function') {
86
+ const translated = __locale.translate(NS, key)
87
+ if (typeof translated === 'string' && translated !== key) text = translated
88
+ }
89
+ if (text === key) text = (localeFallbackLang() === 'en' ? enDict : zhDict)[key] || key
90
+ if (vars) {
91
+ for (const k of Object.keys(vars)) text = text.split('{' + k + '}').join(String(vars[k]))
92
+ }
93
+ return text
94
+ }
95
+
96
+ function useLocaleRevision() {
97
+ const [, setRev] = useState(0)
98
+ useEffect(() => {
99
+ if (!__locale || typeof __locale.subscribe !== 'function') return undefined
100
+ return __locale.subscribe(() => setRev(v => v + 1))
101
+ }, [])
102
+ }
103
+
104
+ // --- styles(仅 --dsw-* 主题令牌) ----------------------------------------
105
+ const btnStyle = {
106
+ display: 'inline-flex',
107
+ alignItems: 'center',
108
+ justifyContent: 'center',
109
+ width: 28,
110
+ height: 28,
111
+ padding: 0,
112
+ border: 'none',
113
+ borderRadius: 4,
114
+ background: 'transparent',
115
+ color: 'var(--dsw-alias-label-tertiary, #8a8a8e)',
116
+ cursor: 'pointer',
117
+ flex: 'none',
118
+ }
119
+
120
+ // 头部按钮图标:三叉分支(git-branch 风格,16x16)。
121
+ // ⚠️ 这条 path 是按**描边**(stroke)设计的:圆点用 arc 画、连接线用
122
+ // `v3.44` / `V6.28` / `v.85` 这类**零宽度线段**。若用 fill 渲染,线段没有
123
+ // 面积 → 整条分支线消失,只剩几个孤立色块(0.11.x 实测症状:
124
+ // 「那个 svg 渲染有问题」)。必须 stroke + round cap/join。
125
+ // 唯一数据源:所有图标入口(React 组件 / innerHTML 字符串)都从这里取,
126
+ // 以免再次出现「一处改名、另一处仍用旧名 → d="undefined"」的回归。
127
+ const BRANCH_PATH =
128
+ 'M5 2.5a2 2 0 1 1-.9 3.78v3.44a2 2 0 1 1-1.2 0V6.28A2 2 0 1 1 5 2.5Zm0 1.2a.8.8 0 1 0 0 1.6.8.8 0 0 0 0-1.6ZM3.5 11.5a.8.8 0 1 0 1.6 0 .8.8 0 0 0-1.6 0ZM12.5 2.5a2 2 0 0 1 .6 3.9v.85c0 1.9-1.54 3.44-3.44 3.44H8.03a2 2 0 1 1 0-1.2h1.63a2.24 2.24 0 0 0 2.24-2.24V6.4a2 2 0 0 1 .6-3.9Zm0 1.2a.8.8 0 1 0 0 1.6.8.8 0 0 0 0-1.6Z'
129
+ const BRANCH_STROKE = 1.4
130
+
131
+ /** 生成分支图标的 SVG 标记(供 innerHTML 场景复用)。 */
132
+ function branchIconMarkup(size) {
133
+ const px = size || 16
134
+ return (
135
+ '<svg width="' +
136
+ px +
137
+ '" height="' +
138
+ px +
139
+ '" viewBox="0 0 16 16" fill="none"' +
140
+ ' xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"' +
141
+ ' style="flex:none"><path d="' +
142
+ BRANCH_PATH +
143
+ '" fill="none"' +
144
+ ' stroke="currentColor" stroke-width="' +
145
+ BRANCH_STROKE +
146
+ '"' +
147
+ ' stroke-linecap="round" stroke-linejoin="round"/></svg>'
148
+ )
149
+ }
150
+
151
+ /**
152
+ * 面板唤起按钮的图标:官方 `list-pen-outline`(列表 + 笔)。
153
+ *
154
+ * 0.18.0 前的 bug:这里用的是**分叉图标**(IconBranch)—— 一个"消息操作"
155
+ * 面板却长着"分叉"的脸,用户会以为点它是 fork。语义错位就是用户说的
156
+ * 「唤起它的 UI 显示明显有问题」。
157
+ *
158
+ * 「列表 + 笔」同时表达了两件事:浏览消息列表、编辑内容 —— 正是这个面板
159
+ * 的用途(用户也确认它可以当作"编辑 + AI 对话上下文面板")。
160
+ *
161
+ * 几何取自宿主 icon sprite 的 `dsw-icon-list-pen-outline-regular`
162
+ * (16 viewBox,描边 1.2,与宿主动作行图标同一套视觉)。
163
+ */
164
+ // 0.25.0 清理:React 版 `BranchIcon` 组件已删(0 处渲染)。
165
+ // 分叉几何现在只有一个入口 —— 侧栏菜单用的 `branchIconMarkup()`(innerHTML 场景),
166
+ // 两者原本共用 `BRANCH_PATH` / `BRANCH_STROKE`,删掉组件后常量仍是唯一数据源。
167
+ function OpsPanelIcon() {
168
+ return React.createElement(
169
+ 'svg',
170
+ {
171
+ width: 16,
172
+ height: 16,
173
+ viewBox: '0 0 16 16',
174
+ fill: 'none',
175
+ xmlns: 'http://www.w3.org/2000/svg',
176
+ 'aria-hidden': 'true',
177
+ focusable: 'false',
178
+ },
179
+ React.createElement('path', { d: 'M4.9375 5.90295H11.0625', stroke: 'currentColor', strokeWidth: 1.2, strokeLinecap: 'round' }),
180
+ React.createElement('path', { d: 'M4.9375 9.02991H8.27841', stroke: 'currentColor', strokeWidth: 1.2, strokeLinecap: 'round' }),
181
+ React.createElement('path', {
182
+ d: 'M12.5 1.32617C13.3039 1.32617 14 1.95171 14 2.77637V7.61328L13 8.68164V2.77637C13 2.55186 12.8007 2.32617 12.5 2.32617H3.5C3.1993 2.32617 3 2.55186 3 2.77637V13.2246C3.00044 13.4489 3.19963 13.6738 3.5 13.6738H8.32812L7.39258 14.6738H3.5C2.69637 14.6738 2.00042 14.0489 2 13.2246V2.77637C2 1.95171 2.69613 1.32617 3.5 1.32617H12.5Z',
183
+ fill: 'currentColor',
184
+ }),
185
+ React.createElement('path', {
186
+ d: 'M8.97212 14.3693C9.17511 14.5723 9.37811 14.7753 9.5811 14.9783C9.67012 14.8953 9.75914 14.8123 9.84815 14.7293C11.4505 13.2352 13.0528 11.7411 14.6551 10.247C14.7441 10.164 14.8331 10.081 14.9221 9.99803C14.5989 9.6748 14.2756 9.35157 13.9524 9.02834C13.8694 9.11736 13.7864 9.20637 13.7034 9.29539C12.2093 10.8977 10.7152 12.5 9.22113 14.1023C9.13813 14.1913 9.05513 14.2803 8.97212 14.3693Z',
187
+ fill: 'currentColor',
188
+ }),
189
+ )
190
+ }
191
+
192
+ // --- A · 功能主义抽屉 -------------------------------------------------------
193
+
194
+ const PANEL_ROW_H = 46
195
+ const PANEL_SEARCH_LIMIT = 100
196
+
197
+ function fmtClock(value) {
198
+ if (typeof value !== 'number') return ''
199
+ try {
200
+ return new Date(value).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
201
+ } catch {
202
+ return ''
203
+ }
204
+ }
205
+
206
+ function roleCode(role) {
207
+ if (role === 'user') return 'U'
208
+ if (role === 'assistant') return 'A'
209
+ if (role === 'tool') return 'T'
210
+ return 'S'
211
+ }
212
+
213
+ function focusablesIn(root) {
214
+ if (!root || typeof root.querySelectorAll !== 'function') return []
215
+ const selector =
216
+ 'button:not([disabled]),[href],input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])'
217
+ return Array.prototype.slice.call(root.querySelectorAll(selector)).filter(el => {
218
+ if (el.getAttribute('aria-hidden') === 'true') return false
219
+ return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0
220
+ })
221
+ }
222
+
223
+ function ensurePanelStyle() {
224
+ try {
225
+ if (document.getElementById('dsh-message-ops-panel-style')) return
226
+ const tag = document.createElement('style')
227
+ tag.id = 'dsh-message-ops-panel-style'
228
+ tag.textContent = [
229
+ '.mopsPanelScrim{position:fixed;inset:0;z-index:1200;background:var(--dsw-alias-bg-mask-1,rgba(15,17,21,.28));display:flex;align-items:center;justify-content:center;padding:24px;animation:mopsFade .12s ease-out}',
230
+ '@keyframes mopsFade{from{opacity:0}to{opacity:1}}',
231
+ '@keyframes mopsRise{from{opacity:0;transform:translateY(8px) scale(.985)}to{opacity:1;transform:none}}',
232
+ '.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)}',
233
+ '@media(prefers-reduced-motion:reduce){.mopsPanelScrim,.mopsPanel{animation:none}}',
234
+ '.mopsPanel *{box-sizing:border-box}',
235
+ '.mopsPanel button{font:inherit;color:inherit;border-radius:0}',
236
+ '.mopsPanelHead{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;padding:16px 18px 12px;border-bottom:1px solid var(--dsw-alias-border-l2,#e6e6e6)}',
237
+ '.mopsPanelKicker{font-size:10px;letter-spacing:.14em;text-transform:uppercase;color:var(--dsw-alias-label-tertiary,#8a8a8e)}',
238
+ '.mopsPanelTitle{font-size:15px;font-weight:500;margin-top:2px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:420px}',
239
+ '.mopsPanelSub{font-size:11px;color:var(--dsw-alias-label-tertiary,#8a8a8e);margin-top:2px}',
240
+ '.mopsPanelClose{width:30px;height:30px;border:1px solid var(--dsw-alias-border-l2,#e6e6e6);background:transparent;cursor:pointer;font-size:16px;line-height:1;flex:none}',
241
+ '.mopsPanelClose:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(15,17,21,.06))}',
242
+ '.mopsTabs{display:flex;border-bottom:1px solid var(--dsw-alias-border-l2,#e6e6e6)}',
243
+ // 0.33.3:tabpanel 包装层与 .mopsPanel 的纵向 flex 布局等价(不改变视觉)。
244
+ '.mopsTabPanel{flex:1;min-height:0;display:flex;flex-direction:column}',
245
+ '.mopsTab{flex:1;padding:9px 12px;border:0;border-bottom:2px solid transparent;background:transparent;cursor:pointer;font-size:12px;color:var(--dsw-alias-label-secondary,#6b6b70)}',
246
+ '.mopsTab.on{border-bottom-color:var(--dsw-alias-brand-primary,#4d6bfe);color:var(--dsw-alias-label-primary,#0f1115);font-weight:500}',
247
+ '.mopsSearchRow{display:flex;gap:8px;padding:12px 18px 8px}',
248
+ '.mopsSearch{flex:1;min-width:0;height:32px;border:1px solid var(--dsw-alias-border-l2,#d8d8d8);background:transparent;color:inherit;padding:0 9px;font:inherit;font-size:12px;outline:none}',
249
+ '.mopsSearch:focus{border-color:var(--dsw-alias-brand-primary,#4d6bfe)}',
250
+ '.mopsChips{display:flex;gap:6px;padding:0 18px 10px;flex-wrap:wrap;align-items:center}',
251
+ '.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)}',
252
+ '.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)}',
253
+ '.mopsToggle{display:inline-flex;align-items:center;gap:5px;font-size:11px;color:var(--dsw-alias-label-secondary,#6b6b70);margin-left:auto;cursor:pointer}',
254
+ '.mopsToggle input{accent-color:var(--dsw-alias-brand-primary,#4d6bfe)}',
255
+ '.mopsList{flex:1;min-height:0;overflow-y:auto;position:relative;border-top:1px solid var(--dsw-alias-border-l1,#efefef)}',
256
+ '.mopsList:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4d6bfe);outline-offset:-2px}',
257
+ '.mopsRow{position:absolute;left:0;right:0;display:grid;grid-template-columns:44px 26px minmax(0,1fr) 48px;align-items:center;gap:8px;width:100%;border:0;border-bottom:1px solid var(--dsw-alias-border-l1,#f0f0f0);background:transparent;text-align:left;cursor:pointer;padding:0 12px 0 18px;color:inherit;font:inherit}',
258
+ '.mopsRow:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(15,17,21,.045))}',
259
+ '.mopsRow.on{background:color-mix(in srgb,var(--dsw-alias-brand-primary,#4d6bfe) 10%,transparent);box-shadow:inset 2px 0 0 var(--dsw-alias-brand-primary,#4d6bfe)}',
260
+ '.mopsRow.shadowed{opacity:.42}',
261
+ '.mopsSeq{font-variant-numeric:tabular-nums;font-size:10px;color:var(--dsw-alias-label-tertiary,#9a9aa0)}',
262
+ '.mopsRole{width:20px;height:20px;display:inline-flex;align-items:center;justify-content:center;border:1px solid var(--dsw-alias-border-l2,#d8d8d8);font-size:9px;font-weight:500;color:var(--dsw-alias-label-secondary,#6b6b70)}',
263
+ '.mopsSnippet{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px}',
264
+ '.mopsClock{font-size:10px;color:var(--dsw-alias-label-tertiary,#9a9aa0);text-align:right;font-variant-numeric:tabular-nums}',
265
+ '.mopsEmpty{padding:28px 18px;color:var(--dsw-alias-label-tertiary,#8a8a8e);font-size:12px}',
266
+ '.mopsErrorState{display:flex;align-items:flex-start;gap:10px;flex-wrap:wrap;color:var(--dsw-alias-state-error-primary,#c63b32)}',
267
+ '.mopsErrorState .mopsAction{flex:none}',
268
+ '.mopsDetail{flex:none;max-height:37%;overflow-y:auto;border-top:1px solid var(--dsw-alias-border-l2,#e6e6e6);padding:12px 18px 10px;background:var(--dsw-alias-bg-layer-2,#f5f5f5)}',
269
+ '.mopsDetailMeta{display:flex;gap:8px;align-items:center;font-size:10px;color:var(--dsw-alias-label-tertiary,#8a8a8e);margin-bottom:6px}',
270
+ '.mopsDetailText{margin:0;white-space:pre-wrap;word-break:break-word;max-height:none;overflow:visible;font-family:inherit;font-size:12px;line-height:1.55;color:var(--dsw-alias-label-primary,#0f1115)}',
271
+ '.mopsDetailHint{padding:10px 0 14px;color:var(--dsw-alias-label-tertiary,#8a8a8e);font-size:12px}',
272
+ '.mopsDetailNote{margin-top:6px;font-size:11px;line-height:1.5;color:var(--dsw-alias-state-warning-primary,#c99a06)}',
273
+ '.mopsActions{display:flex;gap:6px;flex-wrap:wrap;margin-top:10px}',
274
+ '.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)}',
275
+ '.mopsImpactTitle{font-size:12px;font-weight:500}',
276
+ '.mopsImpact{font-size:11px;line-height:1.5;color:var(--dsw-alias-label-secondary,#6b6b70)}',
277
+ // 常显隐私告知条:左竖线 + 灰底,与红色错误条区分;不可关闭,避免"勾了就真删"的误解
278
+ '.mopsAction{height:30px;padding:0 10px;border:1px solid var(--dsw-alias-border-l2,#cfcfcf);background:transparent;cursor:pointer;font-size:11px}',
279
+ '.mopsAction:hover:not(:disabled){border-color:var(--dsw-alias-label-primary,#0f1115)}',
280
+ '.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)}',
281
+ '.mopsAction.danger{border-color:var(--dsw-alias-state-error-primary,#c63b32);color:var(--dsw-alias-state-error-primary,#c63b32)}',
282
+ '.mopsAction:disabled{opacity:.35;cursor:default}',
283
+ '.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)}',
284
+ '.mopsCount{font-size:10px;color:var(--dsw-alias-label-tertiary,#8a8a8e)}',
285
+ '.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}',
286
+ '.mopsDanger:hover{background:rgba(198,59,50,.06)}',
287
+ '.mopsBanner{padding:7px 18px;font-size:11px;border-bottom:1px solid var(--dsw-alias-border-l1,#efefef)}',
288
+ '.mopsBanner.warn{color:var(--dsw-alias-state-warn-primary,#9a6500);background:rgba(154,101,0,.06)}',
289
+ '.mopsBanner.err{color:var(--dsw-alias-state-error-primary,#c63b32);background:rgba(198,59,50,.06)}',
290
+ '.mopsBanner.ok{color:var(--dsw-alias-state-success-primary,#2f7d4a);background:rgba(47,125,74,.06)}',
291
+ '.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}',
292
+ '.mopsConfirm h3{margin:0;font-size:15px}',
293
+ '.mopsConfirm p{margin:0;font-size:12px;color:var(--dsw-alias-label-secondary,#6b6b70)}',
294
+ '.mopsConfirm p.mopsImpact{font-size:11px}',
295
+ '.mopsConfirm .mopsBanner{margin:0 -24px;border-top:1px solid var(--dsw-alias-border-l1,#efefef);border-bottom:1px solid var(--dsw-alias-border-l1,#efefef)}',
296
+ '.mopsConfirm input{height:34px;border:1px solid var(--dsw-alias-border-l2,#d8d8d8);background:transparent;color:inherit;padding:0 9px;font:inherit;font-size:13px}',
297
+ '.mopsConfirm input:disabled{opacity:.5}',
298
+ '.mopsConfirmRow{display:flex;gap:8px;margin-top:4px}',
299
+ '.mopsTrashItem{display:flex;align-items:center;gap:10px;padding:11px 18px;border-bottom:1px solid var(--dsw-alias-border-l1,#f0f0f0)}',
300
+ '.mopsTrashMain{flex:1;min-width:0}',
301
+ '.mopsTrashTitle{font-size:12px;font-weight:500;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
302
+ '.mopsTrashMeta{font-size:10px;color:var(--dsw-alias-label-tertiary,#8a8a8e);margin-top:2px}',
303
+ // 0.42.0:异常态条目(moving / corrupt)不提供 Restore,改显一行说明
304
+ '.mopsTrashNote{flex:none;max-width:150px;font-size:10px;line-height:1.4;text-align:right;color:var(--dsw-alias-label-tertiary,#8a8a8e)}',
305
+ '@media(max-width:760px){.mopsPanelScrim{padding:0}.mopsPanel{width:100%;height:100%;max-width:100%;max-height:100%;border:0}.mopsDetail{max-height:42%}}',
306
+ ].join('')
307
+ document.head.appendChild(tag)
308
+ } catch {
309
+ /* style failure must not break the panel */
310
+ }
311
+ }