dsh-agent-control-center 0.1.0 → 0.3.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/CHANGELOG.md +116 -0
- package/README.md +217 -83
- package/README.zh.md +159 -58
- package/client.js +7660 -2005
- package/cordis.patch.yml +5 -0
- package/docs/01-CONTRACT.md +3 -2
- package/docs/05-ACCEPTANCE-EVIDENCE.md +81 -0
- package/docs/06-UX-OPTIMIZATION.md +57 -0
- package/docs/07-GUIDE.md +327 -0
- package/docs/08-COMPATIBILITY.md +202 -0
- package/docs/09-ARCHITECTURE.md +333 -0
- package/docs/ROADMAP.md +448 -0
- package/index.js +67 -2
- package/lib/core/cache.js +277 -0
- package/lib/core/compat.js +877 -0
- package/lib/core/errors.js +14 -1
- package/lib/core/http.js +22 -0
- package/lib/core/index.js +53 -2
- package/lib/core/paths.js +6 -0
- package/lib/core/registry.js +21 -5
- package/lib/core/util.js +4 -1
- package/lib/modules/a-agents.js +104 -4
- package/lib/modules/b-tools.js +169 -26
- package/lib/modules/f-diagnostics.js +109 -17
- package/lib/modules/g-templates.js +18 -0
- package/lib/modules/i-recovery.js +84 -23
- package/lib/modules/j-instruction.js +624 -0
- package/lib/modules/k-export.js +540 -0
- package/package.json +1 -1
- package/scripts/release.mjs +81 -0
- package/scripts/verify.mjs +12 -0
- package/src/client/app.js +684 -118
- package/src/client/i18n/agents.js +96 -0
- package/src/client/i18n/common.js +36 -0
- package/src/client/i18n/diagnostics.js +52 -0
- package/src/client/i18n/export.js +174 -0
- package/src/client/i18n/instruction.js +236 -0
- package/src/client/i18n/meta.js +72 -0
- package/src/client/i18n/overview.js +38 -0
- package/src/client/i18n/recovery.js +66 -0
- package/src/client/i18n/sessions.js +64 -0
- package/src/client/i18n/templates.js +88 -0
- package/src/client/i18n/tools.js +96 -0
- package/src/client/i18n/usage.js +42 -0
- package/src/client/kernel.js +327 -40
- package/src/client/pages/agents.js +637 -354
- package/src/client/pages/diagnostics.js +526 -177
- package/src/client/pages/export.js +664 -0
- package/src/client/pages/instruction.js +648 -0
- package/src/client/pages/meta.js +553 -193
- package/src/client/pages/overview.js +255 -34
- package/src/client/pages/recovery.js +332 -131
- package/src/client/pages/sessions.js +470 -307
- package/src/client/pages/templates.js +691 -381
- package/src/client/pages/tools.js +559 -206
- package/src/client/pages/usage.js +235 -57
|
@@ -0,0 +1,664 @@
|
|
|
1
|
+
/* Export page — read-only session export to Markdown or JSON.
|
|
2
|
+
*
|
|
3
|
+
* Data flow: `export.diagnostics` gates the page and supplies the policy note,
|
|
4
|
+
* `export.sessions` feeds the picker, `export.summary` describes the selected
|
|
5
|
+
* session, and `export.session` renders the payload. Any response may report
|
|
6
|
+
* `{ available: false, reason, hint }`; that block is shown as given and never
|
|
7
|
+
* replaced by a made-up result.
|
|
8
|
+
*
|
|
9
|
+
* Layout: the host scrolls the settings content column, so this page only adds
|
|
10
|
+
* padding and vertical gaps. It never takes over height or overflow. Every
|
|
11
|
+
* interactive control is a plain `acc-*` primitive or an ACC component.
|
|
12
|
+
*/
|
|
13
|
+
(function exportPage() {
|
|
14
|
+
const { useState, useEffect, useCallback, useRef } = React
|
|
15
|
+
|
|
16
|
+
const PAGE_STYLE = { display: 'flex', flexDirection: 'column', gap: '12px', padding: '8px 0' }
|
|
17
|
+
const STACK_STYLE = { display: 'flex', flexDirection: 'column', gap: '10px', minWidth: 0 }
|
|
18
|
+
const CLAMP_STYLE = { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', minWidth: 0 }
|
|
19
|
+
const MUTED_SMALL_STYLE = { color: 'var(--dsw-alias-label-tertiary, #81858c)', fontSize: '11px' }
|
|
20
|
+
|
|
21
|
+
const SEARCH_DEBOUNCE_MS = 250
|
|
22
|
+
const SESSIONS_LIMIT = 50
|
|
23
|
+
const DEFAULT_MAX_BYTES = 256 * 1024
|
|
24
|
+
const MAX_BYTES_OPTIONS = [64 * 1024, 256 * 1024, 1024 * 1024]
|
|
25
|
+
const FALLBACK_FORMATS = ['markdown', 'json']
|
|
26
|
+
|
|
27
|
+
/** @param {unknown} value @returns {boolean} */
|
|
28
|
+
function hasText(value) {
|
|
29
|
+
return typeof value === 'string' && value.length > 0
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @param {unknown} value @param {Function} t @returns {string} */
|
|
33
|
+
function bytesText(value, t) {
|
|
34
|
+
return typeof value === 'number' && Number.isFinite(value) ? ACC.fmt.bytes(value) : String(t('common.unknown'))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @param {unknown} value @returns {string} */
|
|
38
|
+
function numberText(value) {
|
|
39
|
+
return typeof value === 'number' && Number.isFinite(value) ? ACC.fmt.num(value) : '—'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** @param {unknown} value @returns {string} */
|
|
43
|
+
function timeText(value) {
|
|
44
|
+
if (typeof value === 'number' && Number.isFinite(value)) return ACC.fmt.relTime(value)
|
|
45
|
+
return hasText(value) ? ACC.fmt.relTime(value) : '—'
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** @param {unknown} value @returns {string} */
|
|
49
|
+
function dateTimeText(value) {
|
|
50
|
+
return hasText(value) ? ACC.fmt.dateTime(value) : '—'
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** @param {number} value @param {Function} t @returns {string} */
|
|
54
|
+
function limitLabel(value, t) {
|
|
55
|
+
if (value === 64 * 1024) return t('export.limit64')
|
|
56
|
+
if (value === 256 * 1024) return t('export.limit256')
|
|
57
|
+
if (value === 1024 * 1024) return t('export.limit1m')
|
|
58
|
+
return ACC.fmt.bytes(value)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @param {unknown} value @returns {string} */
|
|
62
|
+
function formatLabel(value) {
|
|
63
|
+
return value === 'json' ? 'JSON' : 'Markdown'
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @param {unknown} value @returns {string[]} host warning lines, never objects */
|
|
67
|
+
function warningList(value) {
|
|
68
|
+
if (!Array.isArray(value)) return []
|
|
69
|
+
return value.map((entry) => String(entry)).filter((entry) => entry.length > 0)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Show a host `{available:false}` block verbatim: the reason and the next
|
|
74
|
+
* step. A response without either field gets the localized fallback so an
|
|
75
|
+
* unavailable capability is never rendered as an empty success.
|
|
76
|
+
* @param {{ data?: unknown, t: Function }} props
|
|
77
|
+
*/
|
|
78
|
+
function UnavailableNote(props) {
|
|
79
|
+
const t = props.t
|
|
80
|
+
const data = props.data !== null && typeof props.data === 'object' ? props.data : {}
|
|
81
|
+
const reason = hasText(data.reason) ? data.reason : t('export.unknownReason')
|
|
82
|
+
const hint = hasText(data.hint) ? data.hint : t('export.capabilityHint')
|
|
83
|
+
return h(
|
|
84
|
+
C.Notice,
|
|
85
|
+
{ tone: 'warn' },
|
|
86
|
+
h(
|
|
87
|
+
'div',
|
|
88
|
+
{ style: STACK_STYLE },
|
|
89
|
+
h('div', null, `${t('export.reasonLabel')}: ${reason}`),
|
|
90
|
+
h('div', null, `${t('export.nextStepLabel')}: ${hint}`),
|
|
91
|
+
),
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The always-visible policy line: a localized read-only statement plus the
|
|
97
|
+
* host's own `policy.note` when the diagnostics response carries one.
|
|
98
|
+
* @param {{ policy?: unknown, t: Function }} props
|
|
99
|
+
*/
|
|
100
|
+
function PolicyLine(props) {
|
|
101
|
+
const t = props.t
|
|
102
|
+
const policy = props.policy !== null && typeof props.policy === 'object' ? props.policy : null
|
|
103
|
+
const hostNote = policy !== null && hasText(policy.note) ? policy.note : null
|
|
104
|
+
return h(
|
|
105
|
+
C.Notice,
|
|
106
|
+
{ tone: 'info' },
|
|
107
|
+
h(
|
|
108
|
+
'div',
|
|
109
|
+
{ style: STACK_STYLE },
|
|
110
|
+
h(
|
|
111
|
+
'div',
|
|
112
|
+
{ className: 'acc-row', style: { gap: '6px' } },
|
|
113
|
+
h(C.Icon, { name: 'check', size: 14 }),
|
|
114
|
+
h('span', null, t('export.policyNote')),
|
|
115
|
+
),
|
|
116
|
+
hostNote === null ? null : h('span', { style: MUTED_SMALL_STYLE }, `${t('export.policySource')}: ${hostNote}`),
|
|
117
|
+
),
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Blob download helper. The anchor is never appended to the document, and
|
|
123
|
+
* the object URL is revoked after the click so repeated downloads do not
|
|
124
|
+
* leak URLs; pending timers are cleared on unmount.
|
|
125
|
+
*/
|
|
126
|
+
function useDownload() {
|
|
127
|
+
const timers = useRef([])
|
|
128
|
+
useEffect(
|
|
129
|
+
() => () => {
|
|
130
|
+
for (const timer of timers.current) clearTimeout(timer)
|
|
131
|
+
timers.current = []
|
|
132
|
+
},
|
|
133
|
+
[],
|
|
134
|
+
)
|
|
135
|
+
return useCallback((input) => {
|
|
136
|
+
const blob = new Blob([input.text], { type: input.mime })
|
|
137
|
+
const url = URL.createObjectURL(blob)
|
|
138
|
+
const anchor = document.createElement('a')
|
|
139
|
+
anchor.href = url
|
|
140
|
+
anchor.download = input.filename
|
|
141
|
+
anchor.click()
|
|
142
|
+
const timer = setTimeout(() => URL.revokeObjectURL(url), 1000)
|
|
143
|
+
timers.current.push(timer)
|
|
144
|
+
}, [])
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The interactive body. It is mounted only after diagnostics proved the
|
|
149
|
+
* capability available, so every request here has a real host method behind
|
|
150
|
+
* it and no component has to guess why the host said "no".
|
|
151
|
+
* @param {{ t: Function, diagnostics: any }} props
|
|
152
|
+
*/
|
|
153
|
+
function ExportBody(props) {
|
|
154
|
+
const t = props.t
|
|
155
|
+
const diagnostics = props.diagnostics
|
|
156
|
+
const formats = Array.isArray(diagnostics.formats) && diagnostics.formats.length > 0 ? diagnostics.formats : FALLBACK_FORMATS
|
|
157
|
+
const limits = diagnostics.limits !== null && typeof diagnostics.limits === 'object' ? diagnostics.limits : {}
|
|
158
|
+
const initialFormat = formats.includes('markdown') ? 'markdown' : String(formats[0])
|
|
159
|
+
const rawDefaultBytes = typeof limits.defaultBytes === 'number' && Number.isFinite(limits.defaultBytes) ? limits.defaultBytes : DEFAULT_MAX_BYTES
|
|
160
|
+
const initialMaxBytes = MAX_BYTES_OPTIONS.includes(rawDefaultBytes) ? rawDefaultBytes : DEFAULT_MAX_BYTES
|
|
161
|
+
|
|
162
|
+
const [input, setInput] = useState('')
|
|
163
|
+
const [query, setQuery] = useState('')
|
|
164
|
+
const [selectedId, setSelectedId] = useState(null)
|
|
165
|
+
const [format, setFormat] = useState(initialFormat)
|
|
166
|
+
const [includeToolResults, setIncludeToolResults] = useState(diagnostics.includeToolResultsDefault !== false)
|
|
167
|
+
const [maxBytes, setMaxBytes] = useState(initialMaxBytes)
|
|
168
|
+
const [result, setResult] = useState(null)
|
|
169
|
+
const [generating, setGenerating] = useState(false)
|
|
170
|
+
const [generateError, setGenerateError] = useState(null)
|
|
171
|
+
const [copyState, setCopyState] = useState('idle')
|
|
172
|
+
const [downloadState, setDownloadState] = useState('idle')
|
|
173
|
+
const controllerRef = useRef(null)
|
|
174
|
+
const download = useDownload()
|
|
175
|
+
|
|
176
|
+
useEffect(() => {
|
|
177
|
+
const timer = setTimeout(() => setQuery(input.trim()), SEARCH_DEBOUNCE_MS)
|
|
178
|
+
return () => clearTimeout(timer)
|
|
179
|
+
}, [input])
|
|
180
|
+
|
|
181
|
+
const feed = ACC.useAsync((context) => ACC.api('export.sessions', { limit: SESSIONS_LIMIT, query }, context), [query])
|
|
182
|
+
const summary = ACC.useAsync(
|
|
183
|
+
(context) => (selectedId === null ? Promise.resolve(null) : ACC.api('export.summary', { id: selectedId }, context)),
|
|
184
|
+
[selectedId],
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
const settingsKey = `${selectedId === null ? '' : selectedId}\u0000${format}\u0000${String(maxBytes)}\u0000${includeToolResults ? '1' : '0'}`
|
|
188
|
+
useEffect(() => {
|
|
189
|
+
setResult(null)
|
|
190
|
+
setGenerateError(null)
|
|
191
|
+
setCopyState('idle')
|
|
192
|
+
setDownloadState('idle')
|
|
193
|
+
if (controllerRef.current !== null) {
|
|
194
|
+
controllerRef.current.abort()
|
|
195
|
+
controllerRef.current = null
|
|
196
|
+
}
|
|
197
|
+
setGenerating(false)
|
|
198
|
+
}, [settingsKey])
|
|
199
|
+
|
|
200
|
+
useEffect(
|
|
201
|
+
() => () => {
|
|
202
|
+
if (controllerRef.current !== null) controllerRef.current.abort()
|
|
203
|
+
},
|
|
204
|
+
[],
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
useEffect(() => {
|
|
208
|
+
if (copyState === 'idle' && downloadState === 'idle') return undefined
|
|
209
|
+
const timer = setTimeout(() => {
|
|
210
|
+
setCopyState('idle')
|
|
211
|
+
setDownloadState('idle')
|
|
212
|
+
}, 2000)
|
|
213
|
+
return () => clearTimeout(timer)
|
|
214
|
+
}, [copyState, downloadState])
|
|
215
|
+
|
|
216
|
+
const generate = useCallback(async () => {
|
|
217
|
+
if (selectedId === null) return
|
|
218
|
+
if (controllerRef.current !== null) controllerRef.current.abort()
|
|
219
|
+
const controller = new AbortController()
|
|
220
|
+
controllerRef.current = controller
|
|
221
|
+
setGenerating(true)
|
|
222
|
+
setGenerateError(null)
|
|
223
|
+
setResult(null)
|
|
224
|
+
setCopyState('idle')
|
|
225
|
+
setDownloadState('idle')
|
|
226
|
+
try {
|
|
227
|
+
const data = await ACC.api(
|
|
228
|
+
'export.session',
|
|
229
|
+
{ id: selectedId, format, maxBytes, includeToolResults },
|
|
230
|
+
{ signal: controller.signal },
|
|
231
|
+
)
|
|
232
|
+
if (controllerRef.current === controller) setResult(data)
|
|
233
|
+
} catch (error) {
|
|
234
|
+
if (error !== null && error !== undefined && error.name === 'AbortError') return
|
|
235
|
+
if (controllerRef.current === controller) {
|
|
236
|
+
setGenerateError(error === null || error === undefined ? new Error(t('export.generateFailed')) : error)
|
|
237
|
+
}
|
|
238
|
+
} finally {
|
|
239
|
+
if (controllerRef.current === controller) {
|
|
240
|
+
controllerRef.current = null
|
|
241
|
+
setGenerating(false)
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}, [selectedId, format, maxBytes, includeToolResults, t])
|
|
245
|
+
|
|
246
|
+
const copyResult = useCallback(() => {
|
|
247
|
+
const text = result !== null && typeof result.text === 'string' ? result.text : ''
|
|
248
|
+
if (text.length === 0) {
|
|
249
|
+
setCopyState('failed')
|
|
250
|
+
return
|
|
251
|
+
}
|
|
252
|
+
if (typeof navigator !== 'undefined' && navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
|
|
253
|
+
navigator.clipboard.writeText(text).then(() => setCopyState('done'), () => setCopyState('failed'))
|
|
254
|
+
return
|
|
255
|
+
}
|
|
256
|
+
setCopyState('failed')
|
|
257
|
+
}, [result])
|
|
258
|
+
|
|
259
|
+
const downloadResult = useCallback(() => {
|
|
260
|
+
if (result === null || typeof result.text !== 'string' || result.text.length === 0) {
|
|
261
|
+
setDownloadState('failed')
|
|
262
|
+
return
|
|
263
|
+
}
|
|
264
|
+
try {
|
|
265
|
+
const extension = result.format === 'json' ? 'json' : 'md'
|
|
266
|
+
const sourceId = result.sessionId === undefined || result.sessionId === null ? (selectedId === null ? '' : selectedId) : result.sessionId
|
|
267
|
+
download({
|
|
268
|
+
filename: `session-${String(sourceId).slice(0, 8)}.${extension}`,
|
|
269
|
+
mime: result.format === 'json' ? 'application/json;charset=utf-8' : 'text/markdown;charset=utf-8',
|
|
270
|
+
text: result.text,
|
|
271
|
+
})
|
|
272
|
+
setDownloadState('done')
|
|
273
|
+
} catch {
|
|
274
|
+
setDownloadState('failed')
|
|
275
|
+
}
|
|
276
|
+
}, [result, selectedId, download])
|
|
277
|
+
|
|
278
|
+
const feedData = feed.status === 'ready' && feed.data !== null && typeof feed.data === 'object' ? feed.data : null
|
|
279
|
+
const items = feedData !== null && Array.isArray(feedData.items) ? feedData.items : []
|
|
280
|
+
const total = feedData !== null && typeof feedData.total === 'number' ? feedData.total : items.length
|
|
281
|
+
const summaryData = summary.status === 'ready' && summary.data !== null && typeof summary.data === 'object' ? summary.data : null
|
|
282
|
+
const summaryReady = summaryData !== null && summaryData.available === true
|
|
283
|
+
const resultData = result !== null && typeof result === 'object' ? result : null
|
|
284
|
+
|
|
285
|
+
/** One focusable session row; Enter/Space select it through native button semantics. */
|
|
286
|
+
function renderSessionRow(row) {
|
|
287
|
+
const rowData = row !== null && typeof row === 'object' ? row : {}
|
|
288
|
+
const id = rowData.id === undefined || rowData.id === null ? '' : String(rowData.id)
|
|
289
|
+
const active = selectedId === id
|
|
290
|
+
const title = hasText(rowData.title) ? rowData.title : t('export.untitled')
|
|
291
|
+
return h(
|
|
292
|
+
'button',
|
|
293
|
+
{
|
|
294
|
+
key: id.length > 0 ? id : title,
|
|
295
|
+
type: 'button',
|
|
296
|
+
className: `acc-list-item${active ? ' is-selected' : ''}`,
|
|
297
|
+
'aria-pressed': active,
|
|
298
|
+
title: id,
|
|
299
|
+
onClick: () => setSelectedId(id),
|
|
300
|
+
style: { flexDirection: 'column', alignItems: 'stretch', gap: '3px' },
|
|
301
|
+
},
|
|
302
|
+
h(
|
|
303
|
+
'div',
|
|
304
|
+
{ className: 'acc-row', style: { gap: '6px', minWidth: 0 } },
|
|
305
|
+
h('span', { style: { ...CLAMP_STYLE, flex: '1 1 auto', fontWeight: 600 } }, title),
|
|
306
|
+
rowData.archived === true ? h(C.Badge, { tone: 'warn' }, t('export.archived')) : null,
|
|
307
|
+
),
|
|
308
|
+
h(
|
|
309
|
+
'div',
|
|
310
|
+
{ className: 'acc-row', style: { gap: '8px' } },
|
|
311
|
+
h('span', { style: MUTED_SMALL_STYLE }, timeText(rowData.updatedAt)),
|
|
312
|
+
h(
|
|
313
|
+
'span',
|
|
314
|
+
{ style: MUTED_SMALL_STYLE },
|
|
315
|
+
t('export.eventCount', { count: typeof rowData.eventCount === 'number' ? rowData.eventCount : '—' }),
|
|
316
|
+
),
|
|
317
|
+
hasText(rowData.origin) ? h('span', { style: MUTED_SMALL_STYLE }, `${t('export.originLabel')}: ${rowData.origin}`) : null,
|
|
318
|
+
),
|
|
319
|
+
)
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const pickerCard = h(
|
|
323
|
+
C.Card,
|
|
324
|
+
{
|
|
325
|
+
title: t('export.pickTitle'),
|
|
326
|
+
subtitle: feedData !== null && feedData.available === true
|
|
327
|
+
? `${t('export.sessionsCount', { shown: items.length, total })}${query.length > 0 ? ` · ${t('export.searchActive', { query })}` : ''}`
|
|
328
|
+
: undefined,
|
|
329
|
+
},
|
|
330
|
+
h(
|
|
331
|
+
'div',
|
|
332
|
+
{ className: 'acc-row' },
|
|
333
|
+
h('input', {
|
|
334
|
+
className: 'acc-input acc-grow',
|
|
335
|
+
type: 'search',
|
|
336
|
+
value: input,
|
|
337
|
+
placeholder: t('export.searchPlaceholder'),
|
|
338
|
+
'aria-label': t('export.searchAria'),
|
|
339
|
+
onChange: (event) => setInput(event.target.value),
|
|
340
|
+
onKeyDown: (event) => {
|
|
341
|
+
if (event.key === 'Escape') setInput('')
|
|
342
|
+
},
|
|
343
|
+
}),
|
|
344
|
+
input.length > 0 ? h(C.Btn, { tone: 'ghost', onClick: () => setInput('') }, t('export.searchClear')) : null,
|
|
345
|
+
),
|
|
346
|
+
feed.status === 'loading'
|
|
347
|
+
? h(C.Loading, { label: t('export.loadingSessions') })
|
|
348
|
+
: feed.status === 'error'
|
|
349
|
+
? h(C.ErrorBox, { error: feed.error, onRetry: feed.reload, label: t('export.loadFailedSessions') })
|
|
350
|
+
: feedData !== null && feedData.available === false
|
|
351
|
+
? h(
|
|
352
|
+
'div',
|
|
353
|
+
{ style: STACK_STYLE },
|
|
354
|
+
h(UnavailableNote, { data: feedData, t }),
|
|
355
|
+
h('div', { className: 'acc-row' }, h(C.Btn, { onClick: feed.reload, icon: 'retry' }, t('common.retry'))),
|
|
356
|
+
)
|
|
357
|
+
: items.length === 0
|
|
358
|
+
? h(C.Empty, {
|
|
359
|
+
title: query.length > 0 ? t('export.emptySearch') : t('export.emptySessions'),
|
|
360
|
+
hint: query.length > 0 ? t('export.emptySearchHint') : t('export.emptySessionsHint'),
|
|
361
|
+
action: h(
|
|
362
|
+
'div',
|
|
363
|
+
{ className: 'acc-row' },
|
|
364
|
+
query.length > 0 ? h(C.Btn, { tone: 'ghost', onClick: () => setInput('') }, t('export.searchClear')) : null,
|
|
365
|
+
h(C.Btn, { onClick: feed.reload, icon: 'retry' }, t('common.retry')),
|
|
366
|
+
),
|
|
367
|
+
})
|
|
368
|
+
: h('div', { className: 'acc-list', role: 'group', 'aria-label': t('export.sessionsListAria') }, items.map(renderSessionRow)),
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
const settingsCard = h(
|
|
372
|
+
C.Card,
|
|
373
|
+
{ title: t('export.settingsTitle'), subtitle: t('export.settingsHint') },
|
|
374
|
+
h(
|
|
375
|
+
'div',
|
|
376
|
+
{ style: STACK_STYLE },
|
|
377
|
+
h(
|
|
378
|
+
'div',
|
|
379
|
+
{ className: 'acc-field' },
|
|
380
|
+
h('span', { className: 'acc-label' }, t('export.format')),
|
|
381
|
+
h(
|
|
382
|
+
'div',
|
|
383
|
+
{ className: 'acc-tabs', role: 'tablist', 'aria-label': t('export.formatAria') },
|
|
384
|
+
formats.map((entry) => {
|
|
385
|
+
const value = String(entry)
|
|
386
|
+
const active = format === value
|
|
387
|
+
return h(
|
|
388
|
+
'button',
|
|
389
|
+
{
|
|
390
|
+
key: value,
|
|
391
|
+
type: 'button',
|
|
392
|
+
role: 'tab',
|
|
393
|
+
'aria-selected': active,
|
|
394
|
+
className: `acc-tab${active ? ' is-active' : ''}`,
|
|
395
|
+
onClick: () => setFormat(value),
|
|
396
|
+
},
|
|
397
|
+
value === 'json' ? t('export.formatJson') : value === 'markdown' ? t('export.formatMarkdown') : value,
|
|
398
|
+
)
|
|
399
|
+
}),
|
|
400
|
+
),
|
|
401
|
+
),
|
|
402
|
+
h(
|
|
403
|
+
'label',
|
|
404
|
+
{ className: 'acc-row', style: { cursor: 'pointer', alignItems: 'flex-start' } },
|
|
405
|
+
h('input', { type: 'checkbox', checked: includeToolResults, onChange: (event) => setIncludeToolResults(event.target.checked) }),
|
|
406
|
+
h(
|
|
407
|
+
'span',
|
|
408
|
+
{ style: { display: 'flex', flexDirection: 'column', gap: '2px' } },
|
|
409
|
+
h('span', null, t('export.includeToolResults')),
|
|
410
|
+
h('span', { style: MUTED_SMALL_STYLE }, t('export.includeToolResultsHint')),
|
|
411
|
+
),
|
|
412
|
+
),
|
|
413
|
+
h(
|
|
414
|
+
'div',
|
|
415
|
+
{ className: 'acc-field' },
|
|
416
|
+
h('label', { className: 'acc-label', htmlFor: 'acc-export-max-bytes' }, t('export.maxBytes')),
|
|
417
|
+
h(
|
|
418
|
+
'select',
|
|
419
|
+
{
|
|
420
|
+
id: 'acc-export-max-bytes',
|
|
421
|
+
className: 'acc-select',
|
|
422
|
+
value: String(maxBytes),
|
|
423
|
+
'aria-label': t('export.maxBytes'),
|
|
424
|
+
onChange: (event) => setMaxBytes(Number(event.target.value)),
|
|
425
|
+
},
|
|
426
|
+
MAX_BYTES_OPTIONS.map((option) => h('option', { key: String(option), value: String(option) }, limitLabel(option, t))),
|
|
427
|
+
),
|
|
428
|
+
h('span', { style: MUTED_SMALL_STYLE }, t('export.maxBytesHint')),
|
|
429
|
+
),
|
|
430
|
+
),
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
const counts = summaryReady && summaryData.counts !== null && typeof summaryData.counts === 'object' ? summaryData.counts : {}
|
|
434
|
+
const estimated = summaryReady && summaryData.estimatedBytes !== null && typeof summaryData.estimatedBytes === 'object' ? summaryData.estimatedBytes : {}
|
|
435
|
+
const summaryWarnings = summaryReady ? warningList(summaryData.warnings) : []
|
|
436
|
+
const summaryBlock = h(
|
|
437
|
+
'div',
|
|
438
|
+
{ style: STACK_STYLE },
|
|
439
|
+
h(C.KeyValues, {
|
|
440
|
+
items: [
|
|
441
|
+
{ label: t('export.countEvents'), value: numberText(counts.events) },
|
|
442
|
+
{ label: t('export.countUser'), value: numberText(counts.userMessages) },
|
|
443
|
+
{ label: t('export.countAssistant'), value: numberText(counts.assistantMessages) },
|
|
444
|
+
{ label: t('export.countToolCalls'), value: numberText(counts.toolCalls) },
|
|
445
|
+
{ label: t('export.countToolResults'), value: numberText(counts.toolResults) },
|
|
446
|
+
{ label: t('export.countToolErrors'), value: numberText(counts.toolErrors) },
|
|
447
|
+
{ label: t('export.countErrors'), value: numberText(counts.errors) },
|
|
448
|
+
],
|
|
449
|
+
}),
|
|
450
|
+
h(
|
|
451
|
+
'div',
|
|
452
|
+
{ className: 'acc-row' },
|
|
453
|
+
h(C.Badge, { tone: 'neutral' }, `${t('export.estimatedMarkdown')}: ${bytesText(estimated.markdown, t)}`),
|
|
454
|
+
h(C.Badge, { tone: 'neutral' }, `${t('export.estimatedJson')}: ${bytesText(estimated.json, t)}`),
|
|
455
|
+
),
|
|
456
|
+
summaryWarnings.length === 0 ? null : h(C.Notice, { tone: 'info' }, `${t('export.warnings')}: ${summaryWarnings.join(' · ')}`),
|
|
457
|
+
)
|
|
458
|
+
|
|
459
|
+
const resultWarnings = resultData !== null && resultData.available === true ? warningList(resultData.warnings) : []
|
|
460
|
+
const generationBlock = generateError !== null
|
|
461
|
+
? h(C.ErrorBox, { error: generateError, onRetry: generate, label: t('export.generateFailed') })
|
|
462
|
+
: resultData === null
|
|
463
|
+
? h(C.Notice, { tone: 'info' }, t('export.generateHint'))
|
|
464
|
+
: resultData.available === false
|
|
465
|
+
? h(
|
|
466
|
+
'div',
|
|
467
|
+
{ style: STACK_STYLE },
|
|
468
|
+
h(UnavailableNote, { data: resultData, t }),
|
|
469
|
+
h('div', { className: 'acc-row' }, h(C.Btn, { onClick: generate, icon: 'retry' }, t('common.retry'))),
|
|
470
|
+
)
|
|
471
|
+
: h(
|
|
472
|
+
'div',
|
|
473
|
+
{ style: STACK_STYLE },
|
|
474
|
+
h(C.KeyValues, {
|
|
475
|
+
items: [
|
|
476
|
+
{ label: t('export.resultBytes'), value: bytesText(resultData.bytes, t) },
|
|
477
|
+
{ label: t('export.resultTotalBytes'), value: bytesText(resultData.totalBytes, t) },
|
|
478
|
+
{
|
|
479
|
+
label: t('export.truncated'),
|
|
480
|
+
value: h(
|
|
481
|
+
C.Badge,
|
|
482
|
+
{ tone: resultData.truncated === true ? 'warn' : 'success' },
|
|
483
|
+
resultData.truncated === true ? t('export.truncatedYes') : t('export.truncatedNo'),
|
|
484
|
+
),
|
|
485
|
+
},
|
|
486
|
+
{ label: t('export.omittedEvents'), value: numberText(resultData.omittedEvents) },
|
|
487
|
+
{ label: t('export.format'), value: formatLabel(resultData.format) },
|
|
488
|
+
{ label: t('export.generatedAt'), value: dateTimeText(resultData.generatedAt) },
|
|
489
|
+
],
|
|
490
|
+
}),
|
|
491
|
+
resultData.truncated === true
|
|
492
|
+
? h(C.Notice, { tone: 'warn' }, t('export.truncatedNotice', { count: numberText(resultData.omittedEvents) }))
|
|
493
|
+
: null,
|
|
494
|
+
resultWarnings.length === 0 ? null : h(C.Notice, { tone: 'info' }, `${t('export.warnings')}: ${resultWarnings.join(' · ')}`),
|
|
495
|
+
h(
|
|
496
|
+
'div',
|
|
497
|
+
{ className: 'acc-row' },
|
|
498
|
+
h(C.Btn, { tone: 'primary', onClick: copyResult }, copyState === 'done' ? t('export.copied') : t('export.copy')),
|
|
499
|
+
h(C.Btn, { onClick: downloadResult }, downloadState === 'done' ? t('export.downloaded') : t('export.download')),
|
|
500
|
+
h(
|
|
501
|
+
'span',
|
|
502
|
+
{ style: MUTED_SMALL_STYLE, 'aria-live': 'polite' },
|
|
503
|
+
copyState === 'failed' ? t('export.copyFailed') : downloadState === 'failed' ? t('export.downloadFailed') : '',
|
|
504
|
+
),
|
|
505
|
+
),
|
|
506
|
+
h(
|
|
507
|
+
'div',
|
|
508
|
+
{ style: STACK_STYLE },
|
|
509
|
+
h('span', { className: 'acc-label' }, t('export.preview')),
|
|
510
|
+
typeof resultData.text === 'string' && resultData.text.length > 0
|
|
511
|
+
? h(C.Code, { text: resultData.text })
|
|
512
|
+
: h(C.Empty, { title: t('export.previewEmpty') }),
|
|
513
|
+
),
|
|
514
|
+
)
|
|
515
|
+
|
|
516
|
+
const resultBody = selectedId === null
|
|
517
|
+
? h(C.Empty, { title: t('export.selectHint'), hint: t('export.selectHintHint') })
|
|
518
|
+
: h(
|
|
519
|
+
'div',
|
|
520
|
+
{ style: STACK_STYLE },
|
|
521
|
+
summary.status === 'loading'
|
|
522
|
+
? h(C.Loading, { label: t('export.summaryLoading') })
|
|
523
|
+
: summary.status === 'error'
|
|
524
|
+
? h(C.ErrorBox, { error: summary.error, onRetry: summary.reload, label: t('export.summaryFailed') })
|
|
525
|
+
: summaryReady
|
|
526
|
+
? h('div', { style: STACK_STYLE }, summaryBlock, generationBlock)
|
|
527
|
+
: summaryData !== null && summaryData.available === false
|
|
528
|
+
? h(
|
|
529
|
+
'div',
|
|
530
|
+
{ style: STACK_STYLE },
|
|
531
|
+
h(UnavailableNote, { data: summaryData, t }),
|
|
532
|
+
h('div', { className: 'acc-row' }, h(C.Btn, { onClick: summary.reload, icon: 'retry' }, t('common.retry'))),
|
|
533
|
+
)
|
|
534
|
+
: null,
|
|
535
|
+
)
|
|
536
|
+
|
|
537
|
+
const generateButton = h(
|
|
538
|
+
C.Btn,
|
|
539
|
+
{
|
|
540
|
+
tone: 'primary',
|
|
541
|
+
onClick: generate,
|
|
542
|
+
disabled: selectedId === null || !summaryReady || generating,
|
|
543
|
+
title: selectedId === null ? t('export.selectHint') : !summaryReady ? t('export.summaryLoading') : t('export.generateHint'),
|
|
544
|
+
},
|
|
545
|
+
generating ? t('export.generating') : t('export.generate'),
|
|
546
|
+
)
|
|
547
|
+
|
|
548
|
+
return h(
|
|
549
|
+
'div',
|
|
550
|
+
{ style: STACK_STYLE },
|
|
551
|
+
pickerCard,
|
|
552
|
+
settingsCard,
|
|
553
|
+
h(C.Card, { title: t('export.resultTitle'), subtitle: t('export.resultHint'), actions: generateButton }, resultBody),
|
|
554
|
+
)
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* The capability reader. It runs only after the host's module registry
|
|
559
|
+
* proved an `export` module is loaded, so `export.diagnostics` cannot fail
|
|
560
|
+
* merely because an older plugin build never registered the methods.
|
|
561
|
+
* @param {{ t: Function, moduleEntry: any }} props
|
|
562
|
+
*/
|
|
563
|
+
function ExportCapability(props) {
|
|
564
|
+
const t = props.t
|
|
565
|
+
const moduleEntry = props.moduleEntry !== null && typeof props.moduleEntry === 'object' ? props.moduleEntry : {}
|
|
566
|
+
const diagnostics = ACC.useAsync((context) => ACC.api('export.diagnostics', {}, context), [])
|
|
567
|
+
const policy = diagnostics.status === 'ready' && diagnostics.data !== null && typeof diagnostics.data === 'object' ? diagnostics.data.policy : null
|
|
568
|
+
const top = h(PolicyLine, { t, policy })
|
|
569
|
+
|
|
570
|
+
if (diagnostics.status === 'loading') {
|
|
571
|
+
return h('div', { style: PAGE_STYLE }, top, h(C.Loading, { label: t('export.loading') }))
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
if (diagnostics.status === 'error') {
|
|
575
|
+
const failure = diagnostics.error !== null && typeof diagnostics.error === 'object' ? diagnostics.error : {}
|
|
576
|
+
const hostHint = hasText(failure.hint) ? failure.hint : ''
|
|
577
|
+
const errorForBox = {
|
|
578
|
+
code: String(failure.code || failure.name || 'error'),
|
|
579
|
+
message: hasText(failure.message) ? failure.message : t('export.loadFailed'),
|
|
580
|
+
hint: hostHint.length > 0 ? hostHint : t('export.unavailableHint'),
|
|
581
|
+
}
|
|
582
|
+
return h(
|
|
583
|
+
'div',
|
|
584
|
+
{ style: PAGE_STYLE },
|
|
585
|
+
top,
|
|
586
|
+
h(C.Notice, { tone: 'warn' }, t('export.errorHint')),
|
|
587
|
+
h(C.ErrorBox, { error: errorForBox, onRetry: diagnostics.reload, label: t('export.loadFailed') }),
|
|
588
|
+
)
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
const data = diagnostics.data !== null && typeof diagnostics.data === 'object' ? diagnostics.data : {}
|
|
592
|
+
if (data.available !== true) {
|
|
593
|
+
// The module probe knows why a loaded module is degraded; without it the
|
|
594
|
+
// note falls back to the localized capability hint.
|
|
595
|
+
const shown = { available: false, reason: hasText(data.reason) ? data.reason : moduleEntry.detail, hint: data.hint }
|
|
596
|
+
return h(
|
|
597
|
+
'div',
|
|
598
|
+
{ style: PAGE_STYLE },
|
|
599
|
+
top,
|
|
600
|
+
h(
|
|
601
|
+
'div',
|
|
602
|
+
{ style: STACK_STYLE },
|
|
603
|
+
h(UnavailableNote, { data: shown, t }),
|
|
604
|
+
h('div', { className: 'acc-row' }, h(C.Btn, { onClick: diagnostics.reload, icon: 'retry' }, t('common.retry'))),
|
|
605
|
+
),
|
|
606
|
+
)
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
return h('div', { style: PAGE_STYLE }, top, h(ExportBody, { t, diagnostics: data }))
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Page entry: read the host's module registry first and keep the policy line
|
|
614
|
+
* on screen in every state. A host build without the `export` module gets an
|
|
615
|
+
* explicit unavailable error with the next step instead of a request that
|
|
616
|
+
* could only 404; a host that has the module proceeds to the capability
|
|
617
|
+
* reader. Loading and failure stay distinct states too.
|
|
618
|
+
* @param {{ t: Function }} props
|
|
619
|
+
*/
|
|
620
|
+
function ExportPage(props) {
|
|
621
|
+
const t = props.t
|
|
622
|
+
const health = ACC.useAsync((context) => ACC.health(context), [])
|
|
623
|
+
const top = h(PolicyLine, { t, policy: null })
|
|
624
|
+
|
|
625
|
+
if (health.status === 'loading') {
|
|
626
|
+
return h('div', { style: PAGE_STYLE }, top, h(C.Loading, { label: t('export.loading') }))
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
if (health.status === 'error') {
|
|
630
|
+
return h('div', { style: PAGE_STYLE }, top, h(C.ErrorBox, { error: health.error, onRetry: health.reload, label: t('export.loadFailed') }))
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
const healthData = health.data !== null && typeof health.data === 'object' ? health.data : {}
|
|
634
|
+
const modules = Array.isArray(healthData.modules) ? healthData.modules : []
|
|
635
|
+
const moduleEntry = modules.find((entry) => entry !== null && typeof entry === 'object' && entry.id === 'export')
|
|
636
|
+
|
|
637
|
+
if (moduleEntry === undefined) {
|
|
638
|
+
const version = hasText(healthData.version) ? healthData.version : t('common.unknown')
|
|
639
|
+
return h(
|
|
640
|
+
'div',
|
|
641
|
+
{ style: PAGE_STYLE },
|
|
642
|
+
top,
|
|
643
|
+
h(C.Notice, { tone: 'warn' }, t('export.errorHint')),
|
|
644
|
+
h(C.ErrorBox, {
|
|
645
|
+
error: { code: 'not_found', message: t('export.moduleMissing', { version }), hint: t('export.unavailableHint') },
|
|
646
|
+
onRetry: health.reload,
|
|
647
|
+
label: t('export.loadFailed'),
|
|
648
|
+
}),
|
|
649
|
+
)
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
return h(ExportCapability, { t, moduleEntry })
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
ACC.registerPage({
|
|
656
|
+
id: 'export',
|
|
657
|
+
titleKey: 'nav.export',
|
|
658
|
+
descriptionKey: 'nav.desc.export',
|
|
659
|
+
icon: 'download',
|
|
660
|
+
order: 110,
|
|
661
|
+
group: 'insight',
|
|
662
|
+
render: (props) => h(ExportPage, props),
|
|
663
|
+
})
|
|
664
|
+
})()
|