@chatcode/cco-better-sidebar 0.18.0-rc.7 → 0.18.1-rc.13.022-rc1
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 +20 -10
- package/README_EN.md +20 -10
- package/lib/client-editor.js +300 -299
- package/lib/client-mermaid.js +295 -296
- package/lib/client-registry.js +2124 -2086
- package/lib/client-terminal.js +298 -297
- package/lib/client.js +2124 -2086
- package/lib/index.js +28 -7
- package/lib/types/client/AccountMenu.d.ts +4 -1
- package/lib/types/client/ContextMenu.d.ts +15 -0
- package/lib/types/client/api.d.ts +4 -0
- package/lib/types/client/locales-ja.d.ts +25 -0
- package/lib/types/client/service.d.ts +1 -1
- package/lib/types/client/ui-tweaks/archive.d.ts +9 -28
- package/lib/types/client/ui-tweaks/branding.d.ts +1 -1
- package/lib/types/client/ui-tweaks/dom-text.d.ts +2 -0
- package/lib/types/client/ui-tweaks/index.d.ts +10 -0
- package/lib/types/client/ui-tweaks/notifier.d.ts +4 -2
- package/lib/types/client/useChatcodeAccount.d.ts +1 -0
- package/lib/types/ui-tweaks/config.d.ts +1 -1
- package/lib/types/ui-tweaks/turn-outcome.d.ts +1 -1
- package/package.json +84 -86
- package/src/client/AccountMenu.tsx +13 -17
- package/src/client/ContextMenu.tsx +22 -0
- package/src/client/FileTree.tsx +6 -13
- package/src/client/FreeWindow.tsx +4 -3
- package/src/client/GitView.tsx +8 -5
- package/src/client/SideCardSection.tsx +0 -15
- package/src/client/Sidebar.tsx +0 -3
- package/src/client/TabBar.tsx +5 -4
- package/src/client/api.ts +3 -0
- package/src/client/index.tsx +18 -40
- package/src/client/locales-ja.ts +26 -0
- package/src/client/service.ts +1 -1
- package/src/client/shell-presets.ts +1 -1
- package/src/client/sidebar.module.css +23 -13
- package/src/client/ui-tweaks/archive.tsx +118 -140
- package/src/client/ui-tweaks/branding.tsx +94 -35
- package/src/client/ui-tweaks/cachehit.tsx +24 -14
- package/src/client/ui-tweaks/dom-text.ts +12 -0
- package/src/client/ui-tweaks/index.tsx +84 -26
- package/src/client/ui-tweaks/notifier.ts +13 -12
- package/src/client/ui-tweaks/whale.tsx +1 -1
- package/src/client/useChatcodeAccount.ts +12 -2
- package/src/index.ts +10 -3
- package/src/ui-tweaks/config.ts +1 -1
- package/src/ui-tweaks/git.ts +1 -1
- package/src/ui-tweaks/turn-outcome.ts +3 -3
- package/src/ui-tweaks/web.ts +1 -0
|
@@ -1,84 +1,21 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* when the `archiveManagerEnabled` toggle in 界面调整 is on — otherwise it
|
|
6
|
-
* shows an invite card with a one-click enable). The section lists every
|
|
7
|
-
* archived session — enriched from the framework `useSessions` /
|
|
8
|
-
* `useWorkspaces` feeds — with per-row actions and batch actions that go
|
|
9
|
-
* through the same-origin archive route (`/_dsh/ui-tweaks/archive`):
|
|
10
|
-
*
|
|
11
|
-
* - **恢复** (Restore): remove the session from the archive set — its log and
|
|
12
|
-
* workspace slot are kept, so the conversation reappears in the normal
|
|
13
|
-
* sidebar list.
|
|
14
|
-
* - **删除** (Delete): PERMANENTLY delete the session — the server removes its
|
|
15
|
-
* durable log, workspace accounting, archive-set entry and caches; the list
|
|
16
|
-
* then refreshes so the row (and the session itself) disappear.
|
|
17
|
-
* - **全部恢复 / 全部删除**: the same actions for every archived session.
|
|
18
|
-
*
|
|
19
|
-
* Live (open/running) sessions are refused by the server; the client maps the
|
|
20
|
-
* `session-live` error code to localized copy.
|
|
21
|
-
* @module dsh-ui-tweaks/client/archive
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import { useEffect, useMemo, useState, useSyncExternalStore } from 'react'
|
|
25
|
-
import type { ISessions, SessionListState, SessionSummary } from '@deepseek-ai/dsh-api-session-controller/client'
|
|
1
|
+
/** Archived sessions use the shared Host operations for restore and confirmed deletion. */
|
|
2
|
+
import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'
|
|
3
|
+
import { Button, Modal } from '@deepseek-ai/dsh-client-ui-primitives'
|
|
4
|
+
import type { SessionListState, SessionSummary } from '@deepseek-ai/dsh-api-session-controller/client'
|
|
26
5
|
import type { WorkspaceSnapshot } from '@deepseek-ai/dsh-api-workspace-controller/client'
|
|
27
6
|
import type { SnapshotSelectorHook } from '@deepseek-ai/dsh-client-ui-slots'
|
|
28
7
|
import type { SettingsClient } from './index.tsx'
|
|
29
8
|
|
|
30
|
-
/**
|
|
31
|
-
const ARCHIVE_ROUTE = '/_dsh/ui-tweaks/archive'
|
|
32
|
-
|
|
33
|
-
/** Locale keys the Archive manager reads off the `ui-tweaks` dictionary. */
|
|
9
|
+
/** Locale keys read by archive management. */
|
|
34
10
|
type ArchiveLabelKey =
|
|
35
|
-
| '
|
|
36
|
-
| 'archiveDelete' | 'archiveDeleteAll' | 'archiveRestoreAll'
|
|
37
|
-
| '
|
|
38
|
-
| '
|
|
39
|
-
|
|
11
|
+
| 'archiveTitle' | 'archiveEmpty' | 'archiveRestore' | 'archiveRestoring'
|
|
12
|
+
| 'archiveDelete' | 'archiveDeleteAll' | 'archiveRestoreAll' | 'archiveCount'
|
|
13
|
+
| 'archiveDisabledHint' | 'archiveEnable' | 'unavailable'
|
|
14
|
+
| 'archiveConfirmTitle' | 'archiveConfirmDescription' | 'archiveCancel'
|
|
15
|
+
| 'archiveSelectAll' | 'archiveSelectedCount' | 'archiveClearSelection'
|
|
16
|
+
| 'archiveDeleteSelected' | 'archiveDeleteFailed'
|
|
40
17
|
type Translate = (key: ArchiveLabelKey) => string
|
|
41
18
|
|
|
42
|
-
interface ApiSuccess<T> { ok: true; value: T }
|
|
43
|
-
interface ApiFailure { ok: false; error: { code: string; message: string } }
|
|
44
|
-
|
|
45
|
-
interface ArchiveSnapshot {
|
|
46
|
-
archivedSessionIds: string[]
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Fetch one archive route call, attaching the server error code when present. */
|
|
50
|
-
async function archiveRequest<T>(init?: RequestInit): Promise<T> {
|
|
51
|
-
const response = await fetch(ARCHIVE_ROUTE, { credentials: 'same-origin', ...init })
|
|
52
|
-
let body: ApiSuccess<T> | ApiFailure | undefined
|
|
53
|
-
try {
|
|
54
|
-
body = await response.json() as ApiSuccess<T> | ApiFailure
|
|
55
|
-
} catch {
|
|
56
|
-
// Non-JSON response (e.g. the route is not mounted yet) — fall through to
|
|
57
|
-
// a clean error instead of a JSON-parse exception.
|
|
58
|
-
body = undefined
|
|
59
|
-
}
|
|
60
|
-
if (!response.ok || body === undefined || !body.ok) {
|
|
61
|
-
const failure = body as ApiFailure | undefined
|
|
62
|
-
const error = new Error(failure?.error?.message ?? `UI Tweaks archive request failed with HTTP ${response.status}`) as Error & { code: string | undefined }
|
|
63
|
-
error.code = failure?.error?.code
|
|
64
|
-
throw error
|
|
65
|
-
}
|
|
66
|
-
return body.value
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** Map a thrown archive error to user-facing copy. */
|
|
70
|
-
function errorMessage(error: unknown, t: Translate): string {
|
|
71
|
-
const code = (error as { code?: string } | null)?.code
|
|
72
|
-
if (code === 'session-live') return t('archiveLiveError')
|
|
73
|
-
return error instanceof Error ? error.message : String(error)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** Re-pull the host session list after a permanent delete (the outward
|
|
77
|
-
* ISessions face omits refresh; the concrete runtime provides it). */
|
|
78
|
-
function refreshSessions(sessionsService: ISessions): void {
|
|
79
|
-
void (sessionsService as unknown as { refresh(): Promise<void> }).refresh()
|
|
80
|
-
}
|
|
81
|
-
|
|
82
19
|
/** Workspace display title: the path's last non-empty segment. */
|
|
83
20
|
function basenameOf(path: string | undefined): string {
|
|
84
21
|
if (path === undefined || path === '') return ''
|
|
@@ -99,8 +36,8 @@ function relativeTime(ms: number, now: number, formatter: Intl.RelativeTimeForma
|
|
|
99
36
|
}
|
|
100
37
|
|
|
101
38
|
export const ARCHIVE_CSS = `
|
|
102
|
-
.dut-arc{display:grid;gap:12px;max-width:680px;padding:6px 2px 36px}
|
|
103
|
-
.dut-arc-head{display:flex;align-items:center;gap:10px;padding:14px 16px 0}
|
|
39
|
+
.dut-arc{display:grid;grid-template-columns:minmax(0,1fr);gap:12px;max-width:680px;padding:6px 2px 36px}
|
|
40
|
+
.dut-arc-head{display:flex;align-items:center;flex-wrap:wrap;gap:10px;padding:14px 16px 0}
|
|
104
41
|
.dut-arc-head h2{margin:0;font-size:15px;font-weight:600;letter-spacing:-.01em;color:var(--dsw-alias-label-primary)}
|
|
105
42
|
.dut-arc-count{font-size:11.5px;color:var(--dsw-alias-label-secondary);padding:2px 8px;border-radius:999px;background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1)}
|
|
106
43
|
.dut-arc-spacer{flex:1}
|
|
@@ -109,14 +46,19 @@ export const ARCHIVE_CSS = `
|
|
|
109
46
|
.dut-arc-btn:disabled{opacity:.5;cursor:default}
|
|
110
47
|
.dut-arc-btn.dut-arc-del:hover{border-color:color-mix(in srgb,var(--dsw-alias-state-error-primary) 55%,transparent);color:var(--dsw-alias-state-error-primary);background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 10%,transparent)}
|
|
111
48
|
.dut-arc-btn.dut-arc-confirm{border-color:color-mix(in srgb,var(--dsw-alias-state-error-primary) 55%,transparent);color:var(--dsw-alias-state-error-primary);font-weight:600}
|
|
112
|
-
.dut-arc-body{display:grid;gap:2px;margin-top:4px}
|
|
49
|
+
.dut-arc-body{display:grid;grid-template-columns:minmax(0,1fr);gap:2px;margin-top:4px}
|
|
50
|
+
.dut-arc-toolbar{display:flex;align-items:center;flex-wrap:wrap;gap:10px;padding:12px 16px 0;font-size:12px;color:var(--dsw-alias-label-secondary)}
|
|
51
|
+
.dut-arc-select{display:flex;align-items:center;gap:10px;cursor:pointer}
|
|
52
|
+
.dut-arc-select input{flex-shrink:0;width:14px;height:14px;margin:0;accent-color:var(--dsw-alias-label-primary);cursor:inherit}
|
|
53
|
+
.dut-arc-session{flex:1;min-width:0}
|
|
113
54
|
.dut-arc-row{display:flex;align-items:center;gap:8px;padding:10px 16px;border-radius:12px}
|
|
114
55
|
.dut-arc-row:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
115
|
-
.dut-arc-main{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px;text-align:left;background:transparent;border:none;padding:0;
|
|
56
|
+
.dut-arc-main{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px;text-align:left;background:transparent;border:none;padding:0;color:var(--dsw-alias-label-primary);font:inherit}
|
|
116
57
|
.dut-arc-title{font-size:13.5px;font-weight:600;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}
|
|
117
58
|
.dut-arc-sub{font-size:11.5px;color:var(--dsw-alias-label-secondary);white-space:nowrap;text-overflow:ellipsis;overflow:hidden}
|
|
118
59
|
.dut-arc-empty{padding:32px 16px;text-align:center;font-size:12.5px;color:var(--dsw-alias-label-secondary)}
|
|
119
|
-
.dut-arc-alert{margin:8px 16px 0;padding:8px 12px;border-radius:10px;font-size:12px;line-height:1.5;background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 10%,transparent);color:var(--dsw-alias-state-error-primary)}
|
|
60
|
+
.dut-arc-alert{margin:8px 16px 0;padding:8px 12px;border-radius:10px;font-size:12px;line-height:1.5;white-space:pre-line;background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 10%,transparent);color:var(--dsw-alias-state-error-primary)}
|
|
61
|
+
.dut-arc-targets{max-height:240px;overflow:auto;padding-inline-start:20px;overflow-wrap:anywhere}
|
|
120
62
|
.dut-arc-off{padding:20px 16px;display:grid;gap:12px}
|
|
121
63
|
.dut-arc-off p{margin:0;font-size:12.5px;line-height:1.6;color:var(--dsw-alias-label-secondary)}
|
|
122
64
|
`
|
|
@@ -143,35 +85,28 @@ interface ArchiveRow {
|
|
|
143
85
|
export interface ArchiveSectionProps {
|
|
144
86
|
controller: SettingsClient
|
|
145
87
|
t: Translate
|
|
146
|
-
|
|
88
|
+
restoreSession: (id: string) => Promise<void>
|
|
89
|
+
previewDeletion: (id: string) => Promise<readonly string[]>
|
|
90
|
+
deleteSession: (id: string, scope: readonly string[]) => Promise<void>
|
|
147
91
|
/** Framework standard feeds: session list + workspace archive set. */
|
|
148
92
|
useSessions: SnapshotSelectorHook<SessionListState>
|
|
149
93
|
useWorkspaces: SnapshotSelectorHook<WorkspaceSnapshot>
|
|
150
94
|
}
|
|
151
95
|
|
|
152
|
-
|
|
96
|
+
/** Select archived sessions for confirmed deletion, retaining failed targets for retry. */
|
|
97
|
+
export function ArchiveSection({ controller, t, restoreSession, previewDeletion, deleteSession, useSessions, useWorkspaces }: ArchiveSectionProps) {
|
|
153
98
|
const settingsState = useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot)
|
|
154
99
|
const enabled = settingsState.value?.archiveManagerEnabled === true
|
|
155
100
|
const sessions = useSessions(state => state)
|
|
156
101
|
const workspaces = useWorkspaces(state => state)
|
|
157
|
-
const [confirmId, setConfirmId] = useState<string | null>(null)
|
|
158
|
-
const [confirmAll, setConfirmAll] = useState(false)
|
|
159
102
|
const [busy, setBusy] = useState<string | null>(null)
|
|
103
|
+
const busyRef = useRef(false)
|
|
104
|
+
const [selected, setSelected] = useState<readonly string[]>([])
|
|
105
|
+
const [deletion, setDeletion] = useState<readonly { id: string; title: string; scope: readonly string[] }[] | null>(null)
|
|
160
106
|
const [error, setError] = useState<string | null>(null)
|
|
161
107
|
const timeFormatter = useMemo(() => new Intl.RelativeTimeFormat(navigator.language, { numeric: 'auto' }), [])
|
|
162
108
|
const now = Date.now()
|
|
163
109
|
|
|
164
|
-
useEffect(() => {
|
|
165
|
-
if (confirmId === null) return
|
|
166
|
-
const timer = window.setTimeout(() => { setConfirmId(current => (current === confirmId ? null : current)) }, 3000)
|
|
167
|
-
return () => { window.clearTimeout(timer) }
|
|
168
|
-
}, [confirmId])
|
|
169
|
-
useEffect(() => {
|
|
170
|
-
if (!confirmAll) return
|
|
171
|
-
const timer = window.setTimeout(() => { setConfirmAll(false) }, 3000)
|
|
172
|
-
return () => { window.clearTimeout(timer) }
|
|
173
|
-
}, [confirmAll])
|
|
174
|
-
|
|
175
110
|
const rows: ArchiveRow[] = useMemo(() => {
|
|
176
111
|
const byId = sessions.byId
|
|
177
112
|
return workspaces.archivedSessionIds.map(id => ({ id, summary: byId[id] })).sort((a, b) => {
|
|
@@ -180,44 +115,62 @@ export function ArchiveSection({ controller, t, sessionsService, useSessions, us
|
|
|
180
115
|
return tb - ta
|
|
181
116
|
})
|
|
182
117
|
}, [workspaces.archivedSessionIds, sessions.byId])
|
|
118
|
+
const selectedSet = useMemo(() => new Set(selected), [selected])
|
|
119
|
+
const selectedIds = rows.filter(row => selectedSet.has(row.id)).map(row => row.id)
|
|
120
|
+
const allSelected = rows.length > 0 && selectedIds.length === rows.length
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
const available = new Set(rows.map(row => row.id))
|
|
123
|
+
setSelected(previous => previous.every(id => available.has(id)) ? previous : previous.filter(id => available.has(id)))
|
|
124
|
+
}, [rows])
|
|
183
125
|
|
|
184
|
-
const run = (key: string,
|
|
126
|
+
const run = async (key: string, operation: () => Promise<void>): Promise<void> => {
|
|
127
|
+
if (busyRef.current) return
|
|
128
|
+
busyRef.current = true
|
|
185
129
|
setBusy(key)
|
|
186
130
|
setError(null)
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
body: JSON.stringify(body),
|
|
191
|
-
}).then(() => { after?.() }).catch((reason: unknown) => {
|
|
192
|
-
setError(errorMessage(reason, t))
|
|
193
|
-
}).finally(() => { setBusy(current => (current === key ? null : current)) })
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const restore = (id: string): void => {
|
|
197
|
-
run(`restore:${id}`, { action: 'restore', sessionId: id })
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const remove = (id: string): void => {
|
|
201
|
-
if (confirmId !== id) {
|
|
202
|
-
setConfirmId(id)
|
|
203
|
-
return
|
|
204
|
-
}
|
|
205
|
-
setConfirmId(null)
|
|
206
|
-
run(`delete:${id}`, { action: 'delete', sessionId: id }, () => { refreshSessions(sessionsService) })
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const restoreAll = (): void => {
|
|
210
|
-
run('restore-all', { action: 'restore-all' })
|
|
131
|
+
try { await operation() }
|
|
132
|
+
catch (reason) { setError(reason instanceof Error ? reason.message : String(reason)) }
|
|
133
|
+
finally { busyRef.current = false; setBusy(null) }
|
|
211
134
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
135
|
+
const restore = (id: string): void => { void run(`restore:${id}`, async () => {
|
|
136
|
+
await restoreSession(id)
|
|
137
|
+
setSelected(previous => previous.filter(value => value !== id))
|
|
138
|
+
}) }
|
|
139
|
+
const restoreAll = (): void => { void run('restore-all', async () => {
|
|
140
|
+
for (const row of rows) {
|
|
141
|
+
await restoreSession(row.id)
|
|
142
|
+
setSelected(previous => previous.filter(id => id !== row.id))
|
|
217
143
|
}
|
|
218
|
-
|
|
219
|
-
|
|
144
|
+
}) }
|
|
145
|
+
const requestDelete = (ids: readonly string[]): void => { void run('preview-delete', async () => {
|
|
146
|
+
const targets = []
|
|
147
|
+
const titles = new Map(rows.map(row => [row.id, row.summary?.displayTitle ?? row.id]))
|
|
148
|
+
for (const id of ids) targets.push({ id, title: titles.get(id) ?? id, scope: await previewDeletion(id) })
|
|
149
|
+
if (targets.length > 0) setDeletion(targets)
|
|
150
|
+
}) }
|
|
151
|
+
const confirmDelete = (): void => {
|
|
152
|
+
if (deletion === null) return
|
|
153
|
+
void run('delete', async () => {
|
|
154
|
+
const failed = []
|
|
155
|
+
const failures: string[] = []
|
|
156
|
+
for (const target of deletion) {
|
|
157
|
+
try { await deleteSession(target.id, target.scope) }
|
|
158
|
+
catch (reason) {
|
|
159
|
+
failed.push(target)
|
|
160
|
+
const message = reason instanceof Error ? reason.message : String(reason)
|
|
161
|
+
failures.push(deletion.length > 1
|
|
162
|
+
? t('archiveDeleteFailed').replace('{title}', () => target.title).replace('{error}', () => message)
|
|
163
|
+
: message)
|
|
164
|
+
continue
|
|
165
|
+
}
|
|
166
|
+
const removed = new Set([target.id, ...target.scope])
|
|
167
|
+
setSelected(previous => previous.filter(id => !removed.has(id)))
|
|
168
|
+
}
|
|
169
|
+
setDeletion(failed.length > 0 ? failed : null)
|
|
170
|
+
if (failures.length > 0) setError(failures.join('\n'))
|
|
171
|
+
})
|
|
220
172
|
}
|
|
173
|
+
const dismissDeletion = (): void => { if (!busyRef.current) { setDeletion(null); setError(null) } }
|
|
221
174
|
|
|
222
175
|
if (!enabled) {
|
|
223
176
|
return (
|
|
@@ -244,11 +197,25 @@ export function ArchiveSection({ controller, t, sessionsService, useSessions, us
|
|
|
244
197
|
{rows.length > 1 ? (
|
|
245
198
|
<>
|
|
246
199
|
<button type="button" className="dut-arc-btn" disabled={busy !== null} onClick={restoreAll}>{busy === 'restore-all' ? t('archiveRestoring') : t('archiveRestoreAll')}</button>
|
|
247
|
-
<button type="button" className=
|
|
200
|
+
<button type="button" className="dut-arc-btn dut-arc-del" disabled={busy !== null} onClick={() => requestDelete(rows.map(row => row.id))}>{t('archiveDeleteAll')}</button>
|
|
248
201
|
</>
|
|
249
202
|
) : null}
|
|
250
203
|
</div>
|
|
251
|
-
{
|
|
204
|
+
{rows.length > 0 && <div className="dut-arc-toolbar">
|
|
205
|
+
<label className="dut-arc-select">
|
|
206
|
+
<input type="checkbox" checked={allSelected} disabled={busy !== null}
|
|
207
|
+
ref={input => { if (input !== null) input.indeterminate = selectedIds.length > 0 && !allSelected }}
|
|
208
|
+
onChange={event => { setSelected(event.target.checked ? rows.map(row => row.id) : []) }} />
|
|
209
|
+
<span>{t('archiveSelectAll')}</span>
|
|
210
|
+
</label>
|
|
211
|
+
<span role="status">{t('archiveSelectedCount').replace('{count}', String(selectedIds.length))}</span>
|
|
212
|
+
<span className="dut-arc-spacer" />
|
|
213
|
+
<button type="button" className="dut-arc-btn" disabled={busy !== null || selectedIds.length === 0}
|
|
214
|
+
onClick={() => { setSelected([]) }}>{t('archiveClearSelection')}</button>
|
|
215
|
+
<button type="button" className="dut-arc-btn dut-arc-del" disabled={busy !== null || selectedIds.length === 0}
|
|
216
|
+
onClick={() => requestDelete(selectedIds)}>{t('archiveDeleteSelected').replace('{count}', String(selectedIds.length))}</button>
|
|
217
|
+
</div>}
|
|
218
|
+
{error !== null && deletion === null ? <div role="alert" className="dut-arc-alert">{error}</div> : null}
|
|
252
219
|
<div className="dut-arc-body">
|
|
253
220
|
{rows.length === 0 ? (
|
|
254
221
|
<div className="dut-arc-empty">{t('archiveEmpty')}</div>
|
|
@@ -258,24 +225,35 @@ export function ArchiveSection({ controller, t, sessionsService, useSessions, us
|
|
|
258
225
|
const sub = [basenameOf(summary?.cwd), summary !== undefined ? relativeTime(summary.updatedAt, now, timeFormatter) : ''].filter(Boolean).join(' · ')
|
|
259
226
|
return (
|
|
260
227
|
<div className="dut-arc-row" key={row.id}>
|
|
261
|
-
<
|
|
262
|
-
<
|
|
263
|
-
|
|
264
|
-
|
|
228
|
+
<label className="dut-arc-select dut-arc-session" title={title}>
|
|
229
|
+
<input type="checkbox" aria-label={title} checked={selectedSet.has(row.id)} disabled={busy !== null}
|
|
230
|
+
onChange={event => {
|
|
231
|
+
const checked = event.target.checked
|
|
232
|
+
setSelected(previous => checked ? [...previous, row.id] : previous.filter(id => id !== row.id))
|
|
233
|
+
}} />
|
|
234
|
+
<span className="dut-arc-main">
|
|
235
|
+
<span className="dut-arc-title">{title}</span>
|
|
236
|
+
{sub !== '' ? <span className="dut-arc-sub">{sub}</span> : null}
|
|
237
|
+
</span>
|
|
238
|
+
</label>
|
|
265
239
|
<button type="button" className="dut-arc-btn" disabled={busy !== null} onClick={() => { restore(row.id) }}>{busy === `restore:${row.id}` ? t('archiveRestoring') : t('archiveRestore')}</button>
|
|
266
|
-
<button
|
|
267
|
-
type="button"
|
|
268
|
-
className={'dut-arc-btn dut-arc-del' + (confirmId === row.id ? ' dut-arc-confirm' : '')}
|
|
269
|
-
disabled={busy !== null}
|
|
270
|
-
onClick={() => { remove(row.id) }}
|
|
271
|
-
>
|
|
272
|
-
{busy === `delete:${row.id}` ? t('archiveDelete') + '…' : confirmId === row.id ? t('archiveDelete') + '?' : t('archiveDelete')}
|
|
273
|
-
</button>
|
|
240
|
+
<button type="button" className="dut-arc-btn dut-arc-del" disabled={busy !== null} onClick={() => requestDelete([row.id])}>{t('archiveDelete')}</button>
|
|
274
241
|
</div>
|
|
275
242
|
)
|
|
276
243
|
})}
|
|
277
244
|
</div>
|
|
278
245
|
</div>
|
|
246
|
+
<Modal open={deletion !== null} title={t('archiveConfirmTitle')} closeLabel={t('archiveCancel')} onClose={dismissDeletion}
|
|
247
|
+
description={t('archiveConfirmDescription').replace('{count}', String(new Set(deletion?.flatMap(target => [...target.scope]) ?? []).size))}
|
|
248
|
+
footer={<>
|
|
249
|
+
<Button data-modal-autofocus autoFocus disabled={busy === 'delete'} onClick={dismissDeletion}>{t('archiveCancel')}</Button>
|
|
250
|
+
<Button disabled={busy !== null} onClick={confirmDelete}>{t('archiveDelete')}</Button>
|
|
251
|
+
</>}>
|
|
252
|
+
{deletion !== null && deletion.length > 1 && <ul className="dut-arc-targets">
|
|
253
|
+
{deletion.map(target => <li key={target.id}>{target.title}</li>)}
|
|
254
|
+
</ul>}
|
|
255
|
+
{error !== null && <p role="alert" style={{ whiteSpace: 'pre-line' }}>{error}</p>}
|
|
256
|
+
</Modal>
|
|
279
257
|
</div>
|
|
280
258
|
)
|
|
281
259
|
}
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { ReactNode } from 'react'
|
|
11
|
+
import { api } from '../api.ts'
|
|
12
|
+
import { updateTextContent } from './dom-text.ts'
|
|
11
13
|
import { clearSidebarHeader, SIDEBAR_HEADER_CSS, syncSidebarHeader } from './sidebar-header.ts'
|
|
12
14
|
|
|
13
15
|
declare module '@deepseek-ai/dsh-client-ui-slots' {
|
|
@@ -37,7 +39,12 @@ const HOST_BUILD_VERSION_TEXT = /^v?\d+\.\d+\.\d+(?:[-+][0-9a-z.-]+)*$/iu
|
|
|
37
39
|
const HERO_HEADLINE = /探索未至之境/u
|
|
38
40
|
const HERO_PREVIEW_TEXT = /^(?:预览版|Preview)$/iu
|
|
39
41
|
const FAVICON_MARKER = 'data-dut-project-favicon'
|
|
42
|
+
const SIDEBAR_VERSION_MARKER = 'data-dut-sidebar-version'
|
|
40
43
|
const VERSION_NOTICE_MARKER = 'data-dut-version-notice'
|
|
44
|
+
/** The General Settings "current version" row the plugin moves to the sidebar. */
|
|
45
|
+
const VERSION_ROW_TEXT = /^(?:当前版本|Current version)\s*[::]\s*v?\d/iu
|
|
46
|
+
/** The globally installed CLI version, fetched once from the sidebar host. */
|
|
47
|
+
let sidebarVersion: string | null = null
|
|
41
48
|
const VERSION_NOTICE = {
|
|
42
49
|
en: {
|
|
43
50
|
legacyTitle: 'Internal Testing Notice',
|
|
@@ -80,20 +87,30 @@ export function SidebarProjectName(): ReactNode {
|
|
|
80
87
|
}
|
|
81
88
|
|
|
82
89
|
export const BRANDING_CSS = `
|
|
83
|
-
/*
|
|
84
|
-
other
|
|
85
|
-
menus, the composer, text and shadows) remains owned by the host theme. */
|
|
90
|
+
/* Solid branding is limited to primary actions. Question choices only get a
|
|
91
|
+
faint token-derived tint; other surfaces remain owned by the host theme. */
|
|
86
92
|
body:not([data-ds-dark-theme]) .dut-unicom-primary-action{background:linear-gradient(135deg,#9B0B09,#b71916) !important;border-color:#9B0B09 !important;color:#fff !important;box-shadow:0 7px 18px rgba(155,11,9,.24) !important}
|
|
87
93
|
body:not([data-ds-dark-theme]) .dut-unicom-primary-action:hover{background:linear-gradient(135deg,#b71916,#cf302c) !important;border-color:#b71916 !important;color:#fff !important;box-shadow:0 10px 24px rgba(155,11,9,.30) !important}
|
|
88
94
|
body:not([data-ds-dark-theme]) .dut-unicom-primary-action:active{transform:translateY(1px);box-shadow:0 4px 11px rgba(155,11,9,.22) !important}
|
|
89
95
|
/* In dark mode, alter only the resting background of primary buttons. Once
|
|
90
96
|
hovered, the host owns the complete interaction treatment again. */
|
|
91
97
|
body[data-ds-dark-theme] .dut-unicom-primary-action:not(:hover){background:#9B0B09 !important}
|
|
98
|
+
/* Only the host's question composer, never global radio/checkbox controls.
|
|
99
|
+
Keep normal text, focus rings and disabled behavior; no gradient or shadow. */
|
|
100
|
+
[data-question-key] button:is([role="radio"],[role="checkbox"]):hover:not(:disabled){background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 5%,transparent)}
|
|
101
|
+
[data-question-key] button:is([role="radio"],[role="checkbox"])[aria-checked="true"]{background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 8%,transparent);border-color:color-mix(in srgb,var(--dsw-alias-state-error-primary) 18%,transparent)}
|
|
102
|
+
[data-question-key] button:is([role="radio"],[role="checkbox"])[aria-checked="true"]:hover:not(:disabled){background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 10%,transparent)}
|
|
92
103
|
.dut-project-logo{display:block;object-fit:contain}
|
|
93
104
|
.dut-left-logo{width:24px !important;height:24px !important}
|
|
105
|
+
/* Legacy host marks remain in React's tree; only their painted appearance changes. */
|
|
106
|
+
svg.dut-project-logo{background:url("${PROJECT_LOGO_URL}") center/contain no-repeat}
|
|
107
|
+
svg.dut-project-logo>*{visibility:hidden}
|
|
94
108
|
.dut-brand-title{font:var(--dsw-font-s-strong-14) !important}
|
|
95
109
|
.dut-sidebar-logo{width:24px !important;height:24px !important}
|
|
96
110
|
.dut-sidebar-brand-name{font:var(--dsw-font-s-strong-14) !important;letter-spacing:-.01em !important;white-space:nowrap}
|
|
111
|
+
/* The version the plugin injects beside the sidebar wordmark. */
|
|
112
|
+
.dut-sidebar-version{margin-left:8px;font-size:12px !important;font-weight:500 !important;line-height:22px !important;color:var(--dsw-alias-label-secondary) !important;letter-spacing:0 !important;white-space:nowrap}
|
|
113
|
+
.dut-version-row-hidden{display:none !important}
|
|
97
114
|
${SIDEBAR_HEADER_CSS}
|
|
98
115
|
.dut-brand-version{display:none !important}
|
|
99
116
|
.dut-hero-preview{display:none !important}
|
|
@@ -107,24 +124,23 @@ function hasPrimaryLabel(button: HTMLButtonElement): boolean {
|
|
|
107
124
|
// Plugin cards own their appearance. Inventory disclosure buttons include
|
|
108
125
|
// descriptions, where words like "install" do not identify a primary action.
|
|
109
126
|
if (button.closest('[data-chatcode-plugin-market], [data-plugin-module]')) return false
|
|
110
|
-
|
|
127
|
+
// User/model text can itself be "Send" or contain "发送". These are choices
|
|
128
|
+
// and transcript disclosures, not submit/install actions, regardless of copy.
|
|
129
|
+
if (button.closest('[data-question-key], [data-tool], [data-variant="think"], [data-disclosure-row]')) return false
|
|
130
|
+
const role = button.getAttribute('role')
|
|
131
|
+
if ((role !== null && role !== 'button') || button.hasAttribute('aria-expanded')) return false
|
|
111
132
|
if (button.classList.contains('dut-sidebar-brand') || button.classList.contains('dut-sidebar-new-session')) return false
|
|
112
|
-
|
|
133
|
+
// Prefer the accessible action name. Never match words inside descriptions,
|
|
134
|
+
// nor concatenate title/text/aria-label into an unbounded substring search.
|
|
135
|
+
const label = (button.getAttribute('aria-label')?.trim() || button.title.trim() || button.textContent || '')
|
|
136
|
+
.replace(/\s+/gu, ' ').trim().toLowerCase()
|
|
137
|
+
return /^(?:发送(?:消息)?|排队发送|插话发送|send(?: message)?|queue message|steer (?:queued )?message|安装|install)$/u.test(label)
|
|
113
138
|
}
|
|
114
139
|
|
|
115
|
-
/**
|
|
116
|
-
function
|
|
140
|
+
/** Restyle a legacy host SVG without replacing the DOM node held by React. */
|
|
141
|
+
function styleHostLogo(svg: SVGElement): void {
|
|
117
142
|
if (svg.classList.contains('dut-project-logo')) return
|
|
118
|
-
|
|
119
|
-
image.className = `${svg.getAttribute('class') ?? ''} dut-project-logo dut-left-logo`.trim()
|
|
120
|
-
image.src = PROJECT_LOGO_URL
|
|
121
|
-
image.alt = ''
|
|
122
|
-
image.setAttribute('aria-hidden', 'true')
|
|
123
|
-
const width = svg.getAttribute('width')
|
|
124
|
-
const height = svg.getAttribute('height')
|
|
125
|
-
if (width !== null) image.setAttribute('width', width)
|
|
126
|
-
if (height !== null) image.setAttribute('height', height)
|
|
127
|
-
svg.replaceWith(image)
|
|
143
|
+
svg.classList.add('dut-project-logo', 'dut-left-logo')
|
|
128
144
|
}
|
|
129
145
|
|
|
130
146
|
/** Locate the mark adjacent to an otherwise unstructured sidebar brand label. */
|
|
@@ -135,12 +151,12 @@ function replaceLogoBesideBrandLabel(label: HTMLElement): void {
|
|
|
135
151
|
]
|
|
136
152
|
for (const candidate of nearby) {
|
|
137
153
|
if (candidate instanceof SVGElement) {
|
|
138
|
-
|
|
154
|
+
styleHostLogo(candidate)
|
|
139
155
|
return
|
|
140
156
|
}
|
|
141
157
|
const svg = candidate?.querySelector('svg')
|
|
142
158
|
if (svg instanceof SVGElement) {
|
|
143
|
-
|
|
159
|
+
styleHostLogo(svg)
|
|
144
160
|
return
|
|
145
161
|
}
|
|
146
162
|
}
|
|
@@ -152,12 +168,40 @@ function hideVersionBesideBrandLabel(label: HTMLElement): void {
|
|
|
152
168
|
if (container === null) return
|
|
153
169
|
for (const sibling of container.children) {
|
|
154
170
|
if (sibling === label || !(sibling instanceof HTMLElement)) continue
|
|
171
|
+
if (sibling.hasAttribute(SIDEBAR_VERSION_MARKER)) continue
|
|
155
172
|
if (!HOST_BUILD_VERSION_TEXT.test(sibling.textContent?.trim() ?? '')) continue
|
|
156
173
|
sibling.classList.add('dut-brand-version')
|
|
157
174
|
sibling.setAttribute('aria-hidden', 'true')
|
|
158
175
|
}
|
|
159
176
|
}
|
|
160
177
|
|
|
178
|
+
/** Insert or update the version span immediately after the sidebar wordmark. */
|
|
179
|
+
function injectSidebarVersion(name: HTMLElement, version: string): void {
|
|
180
|
+
const container = name.parentElement
|
|
181
|
+
if (container === null) return
|
|
182
|
+
for (const sibling of container.children) {
|
|
183
|
+
if (sibling === name || !(sibling instanceof HTMLElement)) continue
|
|
184
|
+
if (!sibling.hasAttribute(SIDEBAR_VERSION_MARKER)) continue
|
|
185
|
+
if (sibling.textContent !== version) sibling.textContent = version
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
const span = document.createElement('span')
|
|
189
|
+
span.className = 'dut-sidebar-version'
|
|
190
|
+
span.setAttribute(SIDEBAR_VERSION_MARKER, '')
|
|
191
|
+
span.textContent = version
|
|
192
|
+
name.after(span)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Hide the General Settings "当前版本" row, now that the sidebar owns it. */
|
|
196
|
+
function hideSettingsVersionRow(): void {
|
|
197
|
+
document.querySelectorAll<HTMLElement>('body *').forEach((row) => {
|
|
198
|
+
if (row.childElementCount !== 0) return
|
|
199
|
+
if (!VERSION_ROW_TEXT.test(row.textContent?.trim() ?? '')) return
|
|
200
|
+
row.classList.add('dut-version-row-hidden')
|
|
201
|
+
row.setAttribute('aria-hidden', 'true')
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
|
|
161
205
|
/** Replace the registry build's older upstream notice with ChatCode product copy. */
|
|
162
206
|
function syncVersionNotice(): void {
|
|
163
207
|
document.querySelectorAll<HTMLElement>(
|
|
@@ -173,17 +217,18 @@ function syncVersionNotice(): void {
|
|
|
173
217
|
dialog.setAttribute('aria-label', notice.title)
|
|
174
218
|
dialog.setAttribute(VERSION_NOTICE_MARKER, '')
|
|
175
219
|
dialog.dataset.dutVersionNoticeLanguage = language
|
|
176
|
-
if (heading !== null) heading
|
|
220
|
+
if (heading !== null) updateTextContent(heading, notice.title)
|
|
177
221
|
const paragraphs = dialog.querySelectorAll<HTMLParagraphElement>('p')
|
|
178
222
|
notice.paragraphs.forEach((text, index) => {
|
|
179
223
|
const paragraph = paragraphs.item(index)
|
|
180
|
-
if (paragraph !== null) paragraph
|
|
224
|
+
if (paragraph !== null) updateTextContent(paragraph, text)
|
|
181
225
|
})
|
|
182
226
|
})
|
|
183
227
|
}
|
|
184
228
|
|
|
185
229
|
function syncBranding(): void {
|
|
186
|
-
|
|
230
|
+
const title = document.title.replace(LEGACY_HOST_BRAND_TEXT, PROJECT_NAME)
|
|
231
|
+
if (title !== document.title) document.title = title
|
|
187
232
|
|
|
188
233
|
// The host deliberately renders the blank-session preview badge as a
|
|
189
234
|
// third headline column. ChatCode is the production identity here, so
|
|
@@ -201,24 +246,26 @@ function syncBranding(): void {
|
|
|
201
246
|
surface.querySelectorAll<HTMLElement>('*').forEach((element) => {
|
|
202
247
|
if (element.closest(USER_CONTENT) !== null) return
|
|
203
248
|
if (element.childElementCount !== 0 || !LEGACY_HOST_BRAND_LABEL_TEXT.test(element.textContent?.trim() ?? '')) return
|
|
204
|
-
|
|
249
|
+
updateTextContent(element, PROJECT_NAME)
|
|
205
250
|
element.classList.add('dut-brand-title')
|
|
206
251
|
replaceLogoBesideBrandLabel(element)
|
|
207
252
|
hideVersionBesideBrandLabel(element)
|
|
253
|
+
// The sidebar wordmark carries its dedicated slot class; inject the version
|
|
254
|
+
// only there, never onto the hero headline that shares the label text.
|
|
255
|
+
if (element.classList.contains('dut-sidebar-brand-name') && sidebarVersion !== null) {
|
|
256
|
+
injectSidebarVersion(element, sidebarVersion)
|
|
257
|
+
}
|
|
208
258
|
})
|
|
209
259
|
})
|
|
210
260
|
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
node.data = node.data.replace(LEGACY_HOST_BRAND_TEXT, PROJECT_NAME)
|
|
219
|
-
LEGACY_HOST_BRAND_TEXT.lastIndex = 0
|
|
261
|
+
for (const surface of document.querySelectorAll(BRAND_SURFACE)) {
|
|
262
|
+
const walker = document.createTreeWalker(surface, NodeFilter.SHOW_TEXT)
|
|
263
|
+
let node: Text | null
|
|
264
|
+
while ((node = walker.nextNode() as Text | null) !== null) {
|
|
265
|
+
if (node.parentElement?.closest(USER_CONTENT) !== null) continue
|
|
266
|
+
const next = node.data.replace(LEGACY_HOST_BRAND_TEXT, PROJECT_NAME).replace(HERO_HEADLINE, PROJECT_NAME)
|
|
267
|
+
if (next !== node.data) node.data = next
|
|
220
268
|
}
|
|
221
|
-
if (HERO_HEADLINE.test(node.data)) node.data = node.data.replace(HERO_HEADLINE, PROJECT_NAME)
|
|
222
269
|
}
|
|
223
270
|
|
|
224
271
|
// Keep the product name in the sidebar, but use a more expressive headline
|
|
@@ -228,16 +275,19 @@ function syncBranding(): void {
|
|
|
228
275
|
const title = Array.from(headline?.querySelectorAll<HTMLElement>('*') ?? [])
|
|
229
276
|
.find(element => element.childElementCount === 0 && element.textContent?.trim() === PROJECT_NAME)
|
|
230
277
|
if (title === undefined) return
|
|
231
|
-
title
|
|
278
|
+
updateTextContent(title, HERO_TITLE)
|
|
232
279
|
title.classList.add('dut-hero-title')
|
|
233
280
|
})
|
|
234
281
|
|
|
235
282
|
syncVersionNotice()
|
|
236
283
|
|
|
284
|
+
// The General Settings version row moved to the sidebar; keep it hidden.
|
|
285
|
+
hideSettingsVersionRow()
|
|
286
|
+
|
|
237
287
|
// Older host builds expose a brand-mark wrapper but no text-bearing sibling.
|
|
238
288
|
document.querySelectorAll<HTMLElement>('[class*="brandMark"]').forEach((host) => {
|
|
239
289
|
const svg = host.matches('svg') ? host : host.querySelector('svg')
|
|
240
|
-
if (svg instanceof SVGElement)
|
|
290
|
+
if (svg instanceof SVGElement) styleHostLogo(svg)
|
|
241
291
|
})
|
|
242
292
|
|
|
243
293
|
syncSidebarHeader()
|
|
@@ -280,6 +330,15 @@ export function installBranding(): () => void {
|
|
|
280
330
|
})
|
|
281
331
|
}
|
|
282
332
|
syncBranding()
|
|
333
|
+
// Fetch the installed version asynchronously; once it lands, re-run the
|
|
334
|
+
// pass so the sidebar wordmark gets its version span.
|
|
335
|
+
void api.chatcodeInstalledVersion()
|
|
336
|
+
.then(({ version }) => {
|
|
337
|
+
if (version === null || version === '') return
|
|
338
|
+
sidebarVersion = version
|
|
339
|
+
schedule()
|
|
340
|
+
})
|
|
341
|
+
.catch(() => {})
|
|
283
342
|
const observer = new MutationObserver(schedule)
|
|
284
343
|
observer.observe(document.body, { childList: true, characterData: true, subtree: true })
|
|
285
344
|
return () => {
|