@hongyongli/dsh-session-delete 0.0.0-stage → 1.0.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 +115 -2
- package/client.js +669 -0
- package/cordis.patch.yml +6 -0
- package/icon.svg +8 -0
- package/index.js +456 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +45 -3
- package/test/session-id.test.mjs +133 -0
package/client.js
ADDED
|
@@ -0,0 +1,669 @@
|
|
|
1
|
+
// dsh-chameleon session-delete: CLIENT half.
|
|
2
|
+
//
|
|
3
|
+
// One shared delete dialog for every entry point:
|
|
4
|
+
// - header danger button (conversation.session.header.actions, order 30)
|
|
5
|
+
// - sidebar session-row "..." menu item (DOM injection, title-matched)
|
|
6
|
+
// The dialog is a root-scoped shell.overlay occupant that listens for a
|
|
7
|
+
// window 'chameleon:delete-session' event carrying {sessionId, title,
|
|
8
|
+
// running}; both entry points dispatch it, so the sidebar item NEVER
|
|
9
|
+
// switches the conversation. The dialog shows the session name + id and a
|
|
10
|
+
// running warning; deleting a running session stops it on the host first
|
|
11
|
+
// (agent.cancel + quiescence) — the delete itself is always allowed.
|
|
12
|
+
//
|
|
13
|
+
// Locale: all copy lives in the zh/en dictionaries below and follows the
|
|
14
|
+
// client's active language through the `locale` service (t seat for slot
|
|
15
|
+
// components, `locale/change` refresh for the DOM-injected menu item).
|
|
16
|
+
// Without the service, a browser-language sniff selects the dictionary.
|
|
17
|
+
//
|
|
18
|
+
// Bundle format (client-modules protocol): classic script registering a
|
|
19
|
+
// factory via window.__ModuleLoader__.load({ id, factory }); the factory
|
|
20
|
+
// receives `require` and returns the plugin's exports (apply etc.).
|
|
21
|
+
// No JSX: plain React.createElement. Theme tokens only (--dsw-*).
|
|
22
|
+
window.__ModuleLoader__.load({
|
|
23
|
+
id: '@hongyongli/dsh-session-delete',
|
|
24
|
+
factory: (require) => {
|
|
25
|
+
const React = require('react')
|
|
26
|
+
const { useCallback, useEffect, useState } = React
|
|
27
|
+
// --- self-contained fallbacks -------------------------------------------------
|
|
28
|
+
// `@deepseek-ai/dsh-client-ui-primitives` is a browser module-table entry this
|
|
29
|
+
// plugin does not own: a future client build may drop the module, its Modal or
|
|
30
|
+
// its icon. Fall back to equivalents drawn here so the delete flow keeps working
|
|
31
|
+
// instead of failing at render time.
|
|
32
|
+
function FallbackTrashIcon(props) {
|
|
33
|
+
const size = (props && props.size) || 16
|
|
34
|
+
return React.createElement('svg', {
|
|
35
|
+
width: size,
|
|
36
|
+
height: size,
|
|
37
|
+
viewBox: '0 0 16 16',
|
|
38
|
+
fill: 'none',
|
|
39
|
+
xmlns: 'http://www.w3.org/2000/svg',
|
|
40
|
+
style: { flex: 'none' },
|
|
41
|
+
'aria-hidden': 'true',
|
|
42
|
+
}, React.createElement('path', { d: TRASH_PATH, fill: 'currentColor' }))
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function FallbackModal(props) {
|
|
46
|
+
if (!props || props.open === false) return null
|
|
47
|
+
const children = Array.isArray(props.children) ? props.children : []
|
|
48
|
+
return React.createElement('div', {
|
|
49
|
+
style: {
|
|
50
|
+
position: 'fixed',
|
|
51
|
+
inset: 0,
|
|
52
|
+
zIndex: 2147483000,
|
|
53
|
+
display: 'flex',
|
|
54
|
+
alignItems: 'center',
|
|
55
|
+
justifyContent: 'center',
|
|
56
|
+
background: 'rgba(0,0,0,.35)',
|
|
57
|
+
},
|
|
58
|
+
onClick: (e) => {
|
|
59
|
+
if (e.target === e.currentTarget && typeof props.onClose === 'function') props.onClose()
|
|
60
|
+
},
|
|
61
|
+
}, React.createElement('div', {
|
|
62
|
+
role: 'dialog',
|
|
63
|
+
'aria-modal': 'true',
|
|
64
|
+
'aria-label': props.title,
|
|
65
|
+
style: {
|
|
66
|
+
width: 420,
|
|
67
|
+
maxWidth: 'calc(100vw - 32px)',
|
|
68
|
+
padding: '18px 20px',
|
|
69
|
+
borderRadius: 12,
|
|
70
|
+
border: '1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.2))',
|
|
71
|
+
background: 'var(--dsw-alias-bg-overlay, #fff)',
|
|
72
|
+
color: 'var(--dsw-alias-label-primary, inherit)',
|
|
73
|
+
boxShadow: '0 12px 40px rgba(0,0,0,.28)',
|
|
74
|
+
},
|
|
75
|
+
}, [
|
|
76
|
+
React.createElement('div', {
|
|
77
|
+
key: 'title',
|
|
78
|
+
style: { fontSize: 15, fontWeight: 600, lineHeight: '22px', marginBottom: 8 },
|
|
79
|
+
}, props.title),
|
|
80
|
+
typeof props.description === 'string' && props.description
|
|
81
|
+
? React.createElement('div', {
|
|
82
|
+
key: 'description',
|
|
83
|
+
style: {
|
|
84
|
+
fontSize: 13,
|
|
85
|
+
lineHeight: '20px',
|
|
86
|
+
color: 'var(--dsw-alias-label-secondary, #8a8a8e)',
|
|
87
|
+
marginBottom: 12,
|
|
88
|
+
},
|
|
89
|
+
}, props.description)
|
|
90
|
+
: null,
|
|
91
|
+
...children,
|
|
92
|
+
Array.isArray(props.footer)
|
|
93
|
+
? React.createElement('div', {
|
|
94
|
+
key: 'footer',
|
|
95
|
+
style: { display: 'flex', justifyContent: 'flex-end', marginTop: 16 },
|
|
96
|
+
}, props.footer)
|
|
97
|
+
: null,
|
|
98
|
+
]))
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
let primitives = null
|
|
102
|
+
try {
|
|
103
|
+
primitives = require('@deepseek-ai/dsh-client-ui-primitives') || null
|
|
104
|
+
} catch { /* module absent in this client build */ }
|
|
105
|
+
const IconTrashOutline16 = (primitives && primitives.IconTrashOutline16) || FallbackTrashIcon
|
|
106
|
+
const Modal = (primitives && primitives.Modal) || FallbackModal
|
|
107
|
+
|
|
108
|
+
const SLOT = 'conversation.session.header.actions'
|
|
109
|
+
const ROW_ID = 'session-delete'
|
|
110
|
+
const OVERLAY_SLOT = 'shell.overlay'
|
|
111
|
+
const DIALOG_ID = 'session-delete-dialog'
|
|
112
|
+
const EVENT = 'chameleon:delete-session'
|
|
113
|
+
|
|
114
|
+
// --- locale -----------------------------------------------------------------
|
|
115
|
+
// The copy follows the client's active language (zh/en). Dictionaries are
|
|
116
|
+
// registered under our namespace with the `locale` service when it exists;
|
|
117
|
+
// slot entries declare `locale: NS` so the renderer injects the `t` seat
|
|
118
|
+
// (live re-render on switches). Without the service (minimal compositions)
|
|
119
|
+
// a browser-language sniff keeps the English adaptation working.
|
|
120
|
+
|
|
121
|
+
const NS = 'session-delete'
|
|
122
|
+
|
|
123
|
+
const zhDict = {
|
|
124
|
+
'dialog.title': '删除会话',
|
|
125
|
+
'dialog.cancel': '取消',
|
|
126
|
+
'dialog.confirm': '删除',
|
|
127
|
+
'dialog.confirming': '删除中…',
|
|
128
|
+
'dialog.deleting': '正在删除…',
|
|
129
|
+
'dialog.untitled': '未命名会话',
|
|
130
|
+
'dialog.session': '会话:',
|
|
131
|
+
'dialog.sessionId': '序列号:',
|
|
132
|
+
'dialog.runningWarn': '⚠ 会话正在运行',
|
|
133
|
+
'dialog.ack': '我已了解后果,确认删除',
|
|
134
|
+
'dialog.notFoundDesc': '未能在会话列表中找到该会话(可能已被删除或列表尚未刷新),请刷新后重试。',
|
|
135
|
+
'dialog.runningDesc': '该会话正在运行,删除会立即停止其任务并永久删除,正在进行的操作将中断且无法恢复。',
|
|
136
|
+
'dialog.deleteDesc': '将永久删除该会话及其全部对话记录(会话日志、统计与工作区记账),此操作不可恢复。',
|
|
137
|
+
'button.title': '删除会话',
|
|
138
|
+
'button.titleRunning': '删除会话(运行中,删除将停止任务)',
|
|
139
|
+
'menu.delete': '删除会话',
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const enDict = {
|
|
143
|
+
'dialog.title': 'Delete session',
|
|
144
|
+
'dialog.cancel': 'Cancel',
|
|
145
|
+
'dialog.confirm': 'Delete',
|
|
146
|
+
'dialog.confirming': 'Deleting…',
|
|
147
|
+
'dialog.deleting': 'Deleting…',
|
|
148
|
+
'dialog.untitled': 'Untitled session',
|
|
149
|
+
'dialog.session': 'Session: ',
|
|
150
|
+
'dialog.sessionId': 'Session ID: ',
|
|
151
|
+
'dialog.runningWarn': '⚠ Session is running',
|
|
152
|
+
'dialog.ack': 'I understand the consequences. Confirm deletion',
|
|
153
|
+
'dialog.notFoundDesc': 'Could not find this session in the session list (it may have been deleted or the list has not refreshed yet). Please refresh and try again.',
|
|
154
|
+
'dialog.runningDesc': 'This session is running. Deleting it will stop its task immediately and remove it permanently; any work in progress will be interrupted and cannot be recovered.',
|
|
155
|
+
'dialog.deleteDesc': 'This will permanently delete the session and all of its conversation records (session log, statistics and workspace accounting). This action cannot be undone.',
|
|
156
|
+
'button.title': 'Delete session',
|
|
157
|
+
'button.titleRunning': 'Delete session (running — deleting will stop the task)',
|
|
158
|
+
'menu.delete': 'Delete session',
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const btnStyle = {
|
|
162
|
+
display: 'inline-flex',
|
|
163
|
+
alignItems: 'center',
|
|
164
|
+
justifyContent: 'center',
|
|
165
|
+
width: 28,
|
|
166
|
+
height: 28,
|
|
167
|
+
padding: 0,
|
|
168
|
+
border: 'none',
|
|
169
|
+
borderRadius: 6,
|
|
170
|
+
background: 'transparent',
|
|
171
|
+
color: 'var(--dsw-alias-label-tertiary, #8a8a8e)',
|
|
172
|
+
cursor: 'pointer',
|
|
173
|
+
flex: 'none',
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const metaStyle = {
|
|
177
|
+
color: 'var(--dsw-alias-label-secondary, #8a8a8e)',
|
|
178
|
+
fontSize: 13,
|
|
179
|
+
lineHeight: '20px',
|
|
180
|
+
margin: '0 0 10px',
|
|
181
|
+
overflow: 'hidden',
|
|
182
|
+
textOverflow: 'ellipsis',
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const warnStyle = {
|
|
186
|
+
color: 'var(--dsw-alias-state-warn-primary, #f5a524)',
|
|
187
|
+
fontSize: 13,
|
|
188
|
+
lineHeight: '20px',
|
|
189
|
+
margin: '0 0 10px',
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const errStyle = {
|
|
193
|
+
color: 'var(--dsw-alias-state-error-primary, #e5484d)',
|
|
194
|
+
fontSize: 12,
|
|
195
|
+
lineHeight: '16px',
|
|
196
|
+
marginTop: 8,
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const statusStyle = {
|
|
200
|
+
color: 'var(--dsw-alias-label-secondary, #8a8a8e)',
|
|
201
|
+
fontSize: 12,
|
|
202
|
+
lineHeight: '16px',
|
|
203
|
+
marginTop: 8,
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const optStyle = {
|
|
207
|
+
display: 'flex',
|
|
208
|
+
alignItems: 'center',
|
|
209
|
+
gap: 8,
|
|
210
|
+
fontSize: 13,
|
|
211
|
+
lineHeight: '20px',
|
|
212
|
+
color: 'var(--dsw-alias-label-primary, inherit)',
|
|
213
|
+
marginTop: 10,
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const cancelBtnStyle = {
|
|
217
|
+
padding: '6px 14px',
|
|
218
|
+
borderRadius: 8,
|
|
219
|
+
border: '1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.4))',
|
|
220
|
+
background: 'transparent',
|
|
221
|
+
color: 'var(--dsw-alias-label-primary, inherit)',
|
|
222
|
+
fontSize: 13,
|
|
223
|
+
cursor: 'pointer',
|
|
224
|
+
marginRight: 8,
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const dangerBtnStyle = {
|
|
228
|
+
padding: '6px 14px',
|
|
229
|
+
borderRadius: 8,
|
|
230
|
+
border: '1px solid var(--dsw-alias-state-error-primary, #e5484d)',
|
|
231
|
+
background: 'var(--dsw-alias-state-error-primary, #e5484d)',
|
|
232
|
+
color: '#fff',
|
|
233
|
+
fontSize: 13,
|
|
234
|
+
cursor: 'pointer',
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// --- shared delete dialog (root overlay) -----------------------------------
|
|
238
|
+
|
|
239
|
+
// Module-level handle to the client sessions service: set in apply() and
|
|
240
|
+
// refreshed by a deferred inject, so the dialog always reads the live
|
|
241
|
+
// service even when it was not ready at plugin apply time.
|
|
242
|
+
var __sessionsSvc = null
|
|
243
|
+
|
|
244
|
+
// Module-level handle to the client locale service (LocaleRuntime): set in
|
|
245
|
+
// apply() and refreshed by a deferred inject. `__t` resolves through the
|
|
246
|
+
// service's lookup chain (ns -> ns.zh -> common -> key) when present, and
|
|
247
|
+
// falls back to the built-in dicts selected by browser language otherwise.
|
|
248
|
+
var __locale = null
|
|
249
|
+
|
|
250
|
+
function localeFallbackLang() {
|
|
251
|
+
if (typeof navigator === 'undefined') return 'zh'
|
|
252
|
+
for (const tag of (navigator.languages || []).concat([navigator.language])) {
|
|
253
|
+
const primary = String(tag || '').toLowerCase().split('-')[0]
|
|
254
|
+
if (primary === 'zh' || primary === 'en') return primary
|
|
255
|
+
}
|
|
256
|
+
return 'zh'
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function __t(key) {
|
|
260
|
+
if (__locale && typeof __locale.translate === 'function') {
|
|
261
|
+
const text = __locale.translate(NS, key)
|
|
262
|
+
if (typeof text === 'string' && text !== key) return text
|
|
263
|
+
}
|
|
264
|
+
return (localeFallbackLang() === 'en' ? enDict : zhDict)[key] || key
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Re-render on locale snapshot changes, so copy follows the active
|
|
268
|
+
// language even when an entry was registered without the `locale` seat
|
|
269
|
+
// (e.g. the locale service arrived after slot registration).
|
|
270
|
+
function useLocaleRevision() {
|
|
271
|
+
const [, setRev] = useState(0)
|
|
272
|
+
useEffect(() => {
|
|
273
|
+
if (!__locale || typeof __locale.subscribe !== 'function') return undefined
|
|
274
|
+
return __locale.subscribe(() => setRev((v) => v + 1))
|
|
275
|
+
}, [])
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function normalizeTitle(t) {
|
|
279
|
+
return String(t || '').trim().replace(/\s+/g, ' ')
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// '标题 (1)' -> '标题' (fork-session display suffix)
|
|
283
|
+
function stripForkSuffix(t) {
|
|
284
|
+
return normalizeTitle(t).replace(/\s*\(\d+\)\s*$/, '')
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Resolve the target session from the client's authoritative list store.
|
|
288
|
+
// The sidebar dispatches by title only (its DOM carries no id); the
|
|
289
|
+
// header dispatches by id. Matching levels: exact -> fork-suffix-stripped
|
|
290
|
+
// -> contains. A failed store match falls back to the host list endpoint.
|
|
291
|
+
function resolveTargetFromStore(detail) {
|
|
292
|
+
let sessionId = detail.sessionId || null
|
|
293
|
+
let title = detail.title || null
|
|
294
|
+
let running = detail.running === true
|
|
295
|
+
if (sessionId) return { sessionId, title, running }
|
|
296
|
+
const want = normalizeTitle(title)
|
|
297
|
+
if (!want) return null
|
|
298
|
+
const wantBase = stripForkSuffix(want)
|
|
299
|
+
const svc = __sessionsSvc
|
|
300
|
+
if (svc && svc.list) {
|
|
301
|
+
try {
|
|
302
|
+
const snap = svc.list.getSnapshot()
|
|
303
|
+
const byId = snap && snap.byId ? snap.byId : {}
|
|
304
|
+
const ids = Object.keys(byId)
|
|
305
|
+
for (const id of ids) {
|
|
306
|
+
const s = byId[id]
|
|
307
|
+
if (s && normalizeTitle(s.title) === want) {
|
|
308
|
+
return { sessionId: id, title: s.title, running: s.running === true }
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (wantBase) {
|
|
312
|
+
for (const id of ids) {
|
|
313
|
+
const s = byId[id]
|
|
314
|
+
if (s && stripForkSuffix(s.title) === wantBase) {
|
|
315
|
+
return { sessionId: id, title: s.title, running: s.running === true }
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
let best = null
|
|
320
|
+
for (const id of ids) {
|
|
321
|
+
const s = byId[id]
|
|
322
|
+
if (!s || !s.title) continue
|
|
323
|
+
const t = normalizeTitle(s.title)
|
|
324
|
+
if (t && (t.indexOf(want) >= 0 || want.indexOf(t) >= 0)) {
|
|
325
|
+
best = { sessionId: id, title: s.title, running: s.running === true }
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
if (best) return best
|
|
329
|
+
} catch { /* ignore */ }
|
|
330
|
+
}
|
|
331
|
+
return null
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function DeleteSessionDialog(props) {
|
|
335
|
+
const t = (props && props.t) || __t
|
|
336
|
+
useLocaleRevision()
|
|
337
|
+
const [target, setTarget] = useState(null) // {sessionId, title, running, notFound}
|
|
338
|
+
const [acknowledged, setAcknowledged] = useState(false)
|
|
339
|
+
const [busy, setBusy] = useState(false)
|
|
340
|
+
const [error, setError] = useState(null)
|
|
341
|
+
|
|
342
|
+
useEffect(() => {
|
|
343
|
+
const handler = (e) => {
|
|
344
|
+
const d = e && e.detail ? e.detail : {}
|
|
345
|
+
const resolved = resolveTargetFromStore(d)
|
|
346
|
+
if (resolved) {
|
|
347
|
+
setTarget(resolved)
|
|
348
|
+
setAcknowledged(false)
|
|
349
|
+
setError(null)
|
|
350
|
+
setBusy(false)
|
|
351
|
+
return
|
|
352
|
+
}
|
|
353
|
+
// Store miss: fall back to the host session list (projection
|
|
354
|
+
// cache titles), and surface a not-found dialog if that fails too
|
|
355
|
+
// so a click is never silent.
|
|
356
|
+
const want = normalizeTitle(d.title)
|
|
357
|
+
if (!want) return
|
|
358
|
+
fetch('/__chameleon/session/list')
|
|
359
|
+
.then(function (r) { return r.json() })
|
|
360
|
+
.then(function (data) {
|
|
361
|
+
let m = null
|
|
362
|
+
if (data && data.ok && Array.isArray(data.sessions)) {
|
|
363
|
+
const wantBase = stripForkSuffix(want)
|
|
364
|
+
for (const s of data.sessions) {
|
|
365
|
+
if (!s.title) continue
|
|
366
|
+
const t = normalizeTitle(s.title)
|
|
367
|
+
if (t === want || (wantBase && stripForkSuffix(t) === wantBase) || t.indexOf(want) >= 0 || want.indexOf(t) >= 0) {
|
|
368
|
+
m = s
|
|
369
|
+
break
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
if (m) {
|
|
374
|
+
setTarget({ sessionId: m.sessionId, title: m.title, running: m.running === true })
|
|
375
|
+
} else {
|
|
376
|
+
setTarget({ sessionId: null, title: want, running: false, notFound: true })
|
|
377
|
+
}
|
|
378
|
+
setAcknowledged(false)
|
|
379
|
+
setError(null)
|
|
380
|
+
setBusy(false)
|
|
381
|
+
})
|
|
382
|
+
.catch(function () {
|
|
383
|
+
setTarget({ sessionId: null, title: want, running: false, notFound: true })
|
|
384
|
+
setAcknowledged(false)
|
|
385
|
+
setError(null)
|
|
386
|
+
setBusy(false)
|
|
387
|
+
})
|
|
388
|
+
}
|
|
389
|
+
window.addEventListener(EVENT, handler)
|
|
390
|
+
return () => window.removeEventListener(EVENT, handler)
|
|
391
|
+
}, [])
|
|
392
|
+
|
|
393
|
+
const close = useCallback(() => {
|
|
394
|
+
if (busy) return
|
|
395
|
+
setTarget(null)
|
|
396
|
+
setError(null)
|
|
397
|
+
}, [busy])
|
|
398
|
+
|
|
399
|
+
const confirm = useCallback(() => {
|
|
400
|
+
if (busy || !acknowledged || !target) return
|
|
401
|
+
setBusy(true)
|
|
402
|
+
setError(null)
|
|
403
|
+
fetch('/__chameleon/session/delete', {
|
|
404
|
+
method: 'POST',
|
|
405
|
+
headers: { 'content-type': 'application/json' },
|
|
406
|
+
body: JSON.stringify({ sessionId: target.sessionId }),
|
|
407
|
+
})
|
|
408
|
+
.then(async (res) => {
|
|
409
|
+
let data = {}
|
|
410
|
+
try { data = await res.json() } catch { /* keep {} */ }
|
|
411
|
+
if (!res.ok || !data.ok) {
|
|
412
|
+
throw new Error(data.error || `delete failed (HTTP ${res.status})`)
|
|
413
|
+
}
|
|
414
|
+
// Deleted. Refresh the sidebar list in place — NO page reload —
|
|
415
|
+
// and if the current session was deleted, open the first
|
|
416
|
+
// remaining session so the user can keep working.
|
|
417
|
+
const svc = __sessionsSvc
|
|
418
|
+
const deletedCurrent = svc && svc.list
|
|
419
|
+
? svc.list.getSnapshot().current === target.sessionId
|
|
420
|
+
: false
|
|
421
|
+
setTarget(null)
|
|
422
|
+
const refreshFn =
|
|
423
|
+
svc && typeof svc.refresh === 'function'
|
|
424
|
+
? () => svc.refresh()
|
|
425
|
+
: svc && typeof svc.refreshList === 'function'
|
|
426
|
+
? () => svc.refreshList()
|
|
427
|
+
: null
|
|
428
|
+
if (refreshFn) {
|
|
429
|
+
const done = refreshFn()
|
|
430
|
+
if (deletedCurrent) {
|
|
431
|
+
Promise.resolve(done).then(() => {
|
|
432
|
+
try {
|
|
433
|
+
const snap = svc.list.getSnapshot()
|
|
434
|
+
const next = (snap && snap.ids || []).find((id) => id !== target.sessionId)
|
|
435
|
+
if (next && typeof svc.open === 'function') svc.open(next)
|
|
436
|
+
} catch { /* ignore */ }
|
|
437
|
+
})
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
})
|
|
441
|
+
.catch((reason) => {
|
|
442
|
+
setBusy(false)
|
|
443
|
+
setError(reason && reason.message ? reason.message : String(reason))
|
|
444
|
+
})
|
|
445
|
+
}, [busy, acknowledged, target])
|
|
446
|
+
|
|
447
|
+
if (!target) return null
|
|
448
|
+
|
|
449
|
+
const name = target.notFound ? target.title || t('dialog.untitled') : (target.title || t('dialog.untitled'))
|
|
450
|
+
const description = target.notFound
|
|
451
|
+
? t('dialog.notFoundDesc')
|
|
452
|
+
: target.running
|
|
453
|
+
? t('dialog.runningDesc')
|
|
454
|
+
: t('dialog.deleteDesc')
|
|
455
|
+
|
|
456
|
+
return React.createElement(Modal, {
|
|
457
|
+
open: true,
|
|
458
|
+
onClose: close,
|
|
459
|
+
title: t('dialog.title'),
|
|
460
|
+
closeLabel: t('dialog.cancel'),
|
|
461
|
+
description,
|
|
462
|
+
footer: [
|
|
463
|
+
React.createElement('button', {
|
|
464
|
+
key: 'cancel',
|
|
465
|
+
type: 'button',
|
|
466
|
+
disabled: busy,
|
|
467
|
+
onClick: close,
|
|
468
|
+
style: { ...cancelBtnStyle, ...(busy ? { opacity: 0.5, cursor: 'default' } : {}) },
|
|
469
|
+
}, t('dialog.cancel')),
|
|
470
|
+
React.createElement('button', {
|
|
471
|
+
key: 'confirm',
|
|
472
|
+
type: 'button',
|
|
473
|
+
disabled: busy || !acknowledged || !target.sessionId,
|
|
474
|
+
onClick: confirm,
|
|
475
|
+
style: { ...dangerBtnStyle, ...(busy || !acknowledged || !target.sessionId ? { opacity: 0.5, cursor: 'default' } : {}) },
|
|
476
|
+
}, busy ? t('dialog.confirming') : t('dialog.confirm')),
|
|
477
|
+
],
|
|
478
|
+
}, [
|
|
479
|
+
React.createElement('div', { key: 'meta', style: metaStyle },
|
|
480
|
+
t('dialog.session'), name,
|
|
481
|
+
target.sessionId
|
|
482
|
+
? React.createElement(React.Fragment, null,
|
|
483
|
+
React.createElement('br'),
|
|
484
|
+
t('dialog.sessionId'), target.sessionId)
|
|
485
|
+
: null),
|
|
486
|
+
target.running
|
|
487
|
+
? React.createElement('div', { key: 'warn', style: warnStyle }, t('dialog.runningWarn'))
|
|
488
|
+
: null,
|
|
489
|
+
React.createElement('label', { key: 'ack', style: optStyle },
|
|
490
|
+
React.createElement('input', {
|
|
491
|
+
type: 'checkbox',
|
|
492
|
+
checked: acknowledged,
|
|
493
|
+
disabled: busy,
|
|
494
|
+
onChange: (e) => setAcknowledged(e.target.checked),
|
|
495
|
+
}),
|
|
496
|
+
t('dialog.ack')),
|
|
497
|
+
busy ? React.createElement('div', { key: 'busy', style: statusStyle }, t('dialog.deleting')) : null,
|
|
498
|
+
error ? React.createElement('div', { key: 'err', style: errStyle, role: 'alert' }, error) : null,
|
|
499
|
+
])
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// --- header danger button ---------------------------------------------------
|
|
503
|
+
|
|
504
|
+
function DeleteSessionButton(props) {
|
|
505
|
+
const { sessionId, useSessions } = props
|
|
506
|
+
const t = (props && props.t) || __t
|
|
507
|
+
useLocaleRevision()
|
|
508
|
+
const sessions = useSessions ? useSessions((s) => s) : undefined
|
|
509
|
+
const summary = sessions && sessions.byId ? sessions.byId[sessionId] : undefined
|
|
510
|
+
const running = summary ? summary.running === true : false
|
|
511
|
+
|
|
512
|
+
const openDialog = useCallback(() => {
|
|
513
|
+
window.dispatchEvent(new CustomEvent(EVENT, {
|
|
514
|
+
detail: {
|
|
515
|
+
sessionId,
|
|
516
|
+
title: summary && summary.title ? summary.title : null,
|
|
517
|
+
running,
|
|
518
|
+
},
|
|
519
|
+
}))
|
|
520
|
+
}, [sessionId, summary, running])
|
|
521
|
+
|
|
522
|
+
return React.createElement('button', {
|
|
523
|
+
type: 'button',
|
|
524
|
+
title: running ? t('button.titleRunning') : t('button.title'),
|
|
525
|
+
'aria-label': t('button.title'),
|
|
526
|
+
style: btnStyle,
|
|
527
|
+
onClick: openDialog,
|
|
528
|
+
}, React.createElement(IconTrashOutline16, { size: 16 }))
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// --- sidebar session-row menu injection ------------------------------------
|
|
532
|
+
// rc.6's session-row "..." menu (rename/fork/archive) is hard-coded in
|
|
533
|
+
// ui-workspace with no extension slot, so the delete item is injected at
|
|
534
|
+
// the DOM level. Clicking it matches the row title against the host
|
|
535
|
+
// session list and opens the shared dialog WITHOUT switching sessions.
|
|
536
|
+
// This module is composed into both the desktop client and web.
|
|
537
|
+
|
|
538
|
+
var TRASH_PATH = 'M14.4782 4.84067L14.2138 10.1152C14.1102 12.1872 14.067 13.0115 13.3866 13.9607C13.1044 14.3546 12.7498 14.6912 12.3424 14.9535C11.8239 15.2872 11.2415 15.4316 10.5585 15.4998C9.88727 15.5668 9.04946 15.5656 7.99998 15.5656C6.95051 15.5656 6.1127 15.5668 5.44142 15.4998C4.75851 15.4316 4.17602 15.2872 3.65753 14.9535C3.25012 14.6912 2.89559 14.3546 2.61332 13.9607C1.93296 13.0115 1.88979 12.1872 1.78619 10.1152L1.52179 4.84067L2.89006 4.77277L3.15343 10.0463C3.26221 12.2218 3.32452 12.6015 3.72646 13.1624C3.90825 13.4161 4.13686 13.6334 4.39927 13.8023C4.66204 13.9714 5.00263 14.0792 5.57825 14.1367C6.16562 14.1953 6.92298 14.1963 7.99998 14.1963C9.07699 14.1963 9.83434 14.1953 10.4217 14.1367C10.9973 14.0792 11.3379 13.9714 11.6007 13.8023C11.8631 13.6334 12.0917 13.4161 12.2735 13.1624C12.6755 12.6015 12.7378 12.2218 12.8465 10.0463L13.1099 4.77277L14.4782 4.84067ZM5.43011 6.22849H6.7994V11.3909H5.43011V6.22849ZM9.20056 6.22849H10.5699V11.3909H9.20056V6.22849ZM8.53597 0.434431C9.17976 0.434431 9.6522 0.426926 10.0966 0.571258C10.2357 0.616451 10.3717 0.672554 10.502 0.738948C10.9182 0.951107 11.2464 1.29099 11.7015 1.74612L12.4978 2.54136H15.3742V3.91169H0.625732V2.54136H3.50218L4.29845 1.74612C4.75358 1.29099 5.08174 0.951107 5.49801 0.738948C5.62831 0.672554 5.76425 0.616451 5.90334 0.571258C6.34776 0.426926 6.82021 0.434431 7.46399 0.434431H8.53597ZM7.46399 1.80476C6.73208 1.80476 6.51641 1.81187 6.32617 1.87369C6.25545 1.89667 6.18668 1.92533 6.12041 1.95907C5.96398 2.03878 5.82348 2.16253 5.44142 2.54136H10.5585C10.1765 2.16253 10.036 2.03878 9.87955 1.95907C9.81329 1.92533 9.74452 1.89667 9.6738 1.87369C9.48356 1.81187 9.26789 1.80476 8.53597 1.80476H7.46399Z'
|
|
539
|
+
|
|
540
|
+
// Dispatch the row's title to the shared dialog; the dialog resolves the
|
|
541
|
+
// session id from the client's list store (same data the sidebar shows).
|
|
542
|
+
// Never switches the active conversation and needs no host round-trip.
|
|
543
|
+
function openDeleteFlow(row) {
|
|
544
|
+
if (!row) return
|
|
545
|
+
var titleEl = row.querySelector('[class*=title]')
|
|
546
|
+
var title = titleEl ? String(titleEl.innerText || '').trim() : ''
|
|
547
|
+
if (!title) return
|
|
548
|
+
window.dispatchEvent(new CustomEvent(EVENT, { detail: { title } }))
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function ensureSidebarDeleteItem() {
|
|
552
|
+
var menu = document.querySelector('[role=menu]')
|
|
553
|
+
if (!menu) return
|
|
554
|
+
if (menu.querySelector('[data-chameleon-delete]')) return
|
|
555
|
+
var row = findOpenSessionRow()
|
|
556
|
+
if (!row) return // not a session-row menu
|
|
557
|
+
var item = document.createElement('button')
|
|
558
|
+
item.type = 'button'
|
|
559
|
+
item.setAttribute('role', 'menuitem')
|
|
560
|
+
item.setAttribute('data-chameleon-delete', '1')
|
|
561
|
+
item.style.cssText = [
|
|
562
|
+
'display:flex', 'align-items:center', 'gap:8px', 'width:100%',
|
|
563
|
+
'padding:6px 12px', 'border:none', 'background:transparent',
|
|
564
|
+
'color:var(--dsw-alias-state-error-primary,#e5484d)',
|
|
565
|
+
'font:inherit', 'font-size:13px', 'line-height:20px',
|
|
566
|
+
'text-align:left', 'border-radius:6px', 'cursor:pointer',
|
|
567
|
+
].join(';')
|
|
568
|
+
item.innerHTML = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" style="flex:none"><path d="' + TRASH_PATH + '" fill="currentColor"/></svg><span></span>'
|
|
569
|
+
item.querySelector('span').textContent = __t('menu.delete')
|
|
570
|
+
item.addEventListener('mouseenter', function () {
|
|
571
|
+
item.style.background = 'var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,.14))'
|
|
572
|
+
})
|
|
573
|
+
item.addEventListener('mouseleave', function () {
|
|
574
|
+
item.style.background = 'transparent'
|
|
575
|
+
})
|
|
576
|
+
item.addEventListener('click', function () { openDeleteFlow(row) })
|
|
577
|
+
var sep = document.createElement('div')
|
|
578
|
+
sep.style.cssText = 'height:1px;margin:4px 8px;background:var(--dsw-alias-border-l1,rgba(128,128,128,.2))'
|
|
579
|
+
menu.appendChild(sep)
|
|
580
|
+
menu.appendChild(item)
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
function findOpenSessionRow() {
|
|
584
|
+
var rows = document.querySelectorAll('[class*=sessionRow]')
|
|
585
|
+
for (var i = 0; i < rows.length; i++) {
|
|
586
|
+
if (String(rows[i].className || '').indexOf('menuOpen') >= 0) return rows[i]
|
|
587
|
+
}
|
|
588
|
+
return null
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
// Keep an already-open sidebar menu's label in the active language when
|
|
592
|
+
// the locale switches (fresh menus already read `__t` at creation time).
|
|
593
|
+
function refreshSidebarDeleteLabel() {
|
|
594
|
+
const items = document.querySelectorAll('[data-chameleon-delete]')
|
|
595
|
+
for (let i = 0; i < items.length; i++) {
|
|
596
|
+
const span = items[i].querySelector('span')
|
|
597
|
+
if (span) span.textContent = __t('menu.delete')
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
function installSidebarDelete() {
|
|
602
|
+
if (window.__chameleonSidebarDeleteInstalled) return
|
|
603
|
+
window.__chameleonSidebarDeleteInstalled = true
|
|
604
|
+
try { ensureSidebarDeleteItem() } catch (e) { /* never crash the UI */ }
|
|
605
|
+
var observer = new MutationObserver(function () {
|
|
606
|
+
try { ensureSidebarDeleteItem() } catch (e) { /* never crash the UI */ }
|
|
607
|
+
})
|
|
608
|
+
observer.observe(document.body, { childList: true, subtree: true })
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// --- apply ------------------------------------------------------------------
|
|
612
|
+
|
|
613
|
+
// Adopt the client locale service: register our zh/en dictionaries (the
|
|
614
|
+
// lookup chain falls back to zh, so a missing en entry still renders) and
|
|
615
|
+
// refresh any DOM-injected copy. Disposal of the dictionary registration
|
|
616
|
+
// rides the plugin fiber through ctx.effect.
|
|
617
|
+
function adoptLocale(locale, ctx) {
|
|
618
|
+
if (!locale) return
|
|
619
|
+
__locale = locale
|
|
620
|
+
try {
|
|
621
|
+
if (typeof locale.register === 'function') {
|
|
622
|
+
ctx.effect(() => locale.register(NS, { zh: zhDict, en: enDict }))
|
|
623
|
+
}
|
|
624
|
+
} catch { /* namespace already registered: keep the existing copy */ }
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
function apply(ctx) {
|
|
628
|
+
// The client sessions service (list store, refreshList, open) powers the
|
|
629
|
+
// dialog: title resolution and in-place list refresh after deletion.
|
|
630
|
+
// Grab it now; if it is not ready yet, a deferred inject refreshes the
|
|
631
|
+
// module-level handle and the dialog picks it up.
|
|
632
|
+
__sessionsSvc = ctx.get('sessions')
|
|
633
|
+
if (!__sessionsSvc) {
|
|
634
|
+
ctx.inject(['sessions'], (sub) => {
|
|
635
|
+
__sessionsSvc = sub.sessions
|
|
636
|
+
})
|
|
637
|
+
}
|
|
638
|
+
// The locale service drives the zh/en copy. Absent a deferred inject
|
|
639
|
+
// (minimal compositions), `__t` falls back to the built-in dicts.
|
|
640
|
+
adoptLocale(ctx.get('locale'), ctx)
|
|
641
|
+
if (!__locale) {
|
|
642
|
+
ctx.inject(['locale'], (sub) => {
|
|
643
|
+
adoptLocale(sub.locale, ctx)
|
|
644
|
+
refreshSidebarDeleteLabel()
|
|
645
|
+
})
|
|
646
|
+
}
|
|
647
|
+
ctx.on('locale/change', refreshSidebarDeleteLabel)
|
|
648
|
+
// `locale: NS` gives the registered components the `t` seat (the
|
|
649
|
+
// renderer re-derives it on every locale switch); without the service
|
|
650
|
+
// the components fall back to `__t` + useLocaleRevision().
|
|
651
|
+
ctx.slots.inject(SLOT, () => ctx.slots.register({
|
|
652
|
+
name: SLOT,
|
|
653
|
+
id: ROW_ID,
|
|
654
|
+
order: 30,
|
|
655
|
+
...(__locale ? { locale: NS } : {}),
|
|
656
|
+
}, DeleteSessionButton))
|
|
657
|
+
ctx.slots.inject(OVERLAY_SLOT, () => ctx.slots.register({
|
|
658
|
+
name: OVERLAY_SLOT,
|
|
659
|
+
id: DIALOG_ID,
|
|
660
|
+
order: 100,
|
|
661
|
+
...(__locale ? { locale: NS } : {}),
|
|
662
|
+
}, DeleteSessionDialog))
|
|
663
|
+
installSidebarDelete()
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// The loader gates apply() until the declared services exist.
|
|
667
|
+
return { apply, inject: ['slots'] }
|
|
668
|
+
},
|
|
669
|
+
})
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# dsh-session-delete bundle layer: inserts the session-delete plugin row.
|
|
2
|
+
# Version-unbound fork of @pepsi-ai/dsh-plugin-session-delete: the row id is its
|
|
3
|
+
# own (`session-delete`), so it never collides with the upstream `chameleon-session-delete`.
|
|
4
|
+
- insert:
|
|
5
|
+
- id: session-delete
|
|
6
|
+
name: '@hongyongli/dsh-session-delete'
|
package/icon.svg
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="Delete session">
|
|
2
|
+
<circle cx="32" cy="32" r="25" fill="#C2413B"/>
|
|
3
|
+
<rect x="22" y="21.5" width="20" height="3.4" rx="1.7" fill="#FFFFFF"/>
|
|
4
|
+
<rect x="27.6" y="16.6" width="8.8" height="3.4" rx="1.7" fill="#FFFFFF"/>
|
|
5
|
+
<path d="M24.5 27H39.5L38 44.8Q37.85 46.6 36.05 46.6H27.95Q26.15 46.6 26 44.8Z" fill="#FFFFFF"/>
|
|
6
|
+
<rect x="29.6" y="31" width="2.2" height="11.4" rx="1.1" fill="#C2413B"/>
|
|
7
|
+
<rect x="32.4" y="31" width="2.2" height="11.4" rx="1.1" fill="#C2413B"/>
|
|
8
|
+
</svg>
|