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.
Files changed (56) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/README.md +217 -83
  3. package/README.zh.md +159 -58
  4. package/client.js +7660 -2005
  5. package/cordis.patch.yml +5 -0
  6. package/docs/01-CONTRACT.md +3 -2
  7. package/docs/05-ACCEPTANCE-EVIDENCE.md +81 -0
  8. package/docs/06-UX-OPTIMIZATION.md +57 -0
  9. package/docs/07-GUIDE.md +327 -0
  10. package/docs/08-COMPATIBILITY.md +202 -0
  11. package/docs/09-ARCHITECTURE.md +333 -0
  12. package/docs/ROADMAP.md +448 -0
  13. package/index.js +67 -2
  14. package/lib/core/cache.js +277 -0
  15. package/lib/core/compat.js +877 -0
  16. package/lib/core/errors.js +14 -1
  17. package/lib/core/http.js +22 -0
  18. package/lib/core/index.js +53 -2
  19. package/lib/core/paths.js +6 -0
  20. package/lib/core/registry.js +21 -5
  21. package/lib/core/util.js +4 -1
  22. package/lib/modules/a-agents.js +104 -4
  23. package/lib/modules/b-tools.js +169 -26
  24. package/lib/modules/f-diagnostics.js +109 -17
  25. package/lib/modules/g-templates.js +18 -0
  26. package/lib/modules/i-recovery.js +84 -23
  27. package/lib/modules/j-instruction.js +624 -0
  28. package/lib/modules/k-export.js +540 -0
  29. package/package.json +1 -1
  30. package/scripts/release.mjs +81 -0
  31. package/scripts/verify.mjs +12 -0
  32. package/src/client/app.js +684 -118
  33. package/src/client/i18n/agents.js +96 -0
  34. package/src/client/i18n/common.js +36 -0
  35. package/src/client/i18n/diagnostics.js +52 -0
  36. package/src/client/i18n/export.js +174 -0
  37. package/src/client/i18n/instruction.js +236 -0
  38. package/src/client/i18n/meta.js +72 -0
  39. package/src/client/i18n/overview.js +38 -0
  40. package/src/client/i18n/recovery.js +66 -0
  41. package/src/client/i18n/sessions.js +64 -0
  42. package/src/client/i18n/templates.js +88 -0
  43. package/src/client/i18n/tools.js +96 -0
  44. package/src/client/i18n/usage.js +42 -0
  45. package/src/client/kernel.js +327 -40
  46. package/src/client/pages/agents.js +637 -354
  47. package/src/client/pages/diagnostics.js +526 -177
  48. package/src/client/pages/export.js +664 -0
  49. package/src/client/pages/instruction.js +648 -0
  50. package/src/client/pages/meta.js +553 -193
  51. package/src/client/pages/overview.js +255 -34
  52. package/src/client/pages/recovery.js +332 -131
  53. package/src/client/pages/sessions.js +470 -307
  54. package/src/client/pages/templates.js +691 -381
  55. package/src/client/pages/tools.js +559 -206
  56. package/src/client/pages/usage.js +235 -57
@@ -1,8 +1,15 @@
1
1
  /* Usage page — real token accounting (module D).
2
- * Six headline cells for the selected local day, a pure-CSS provider/model bar
3
- * chart for the trend window, the accounting definition, and three explicit
4
- * states: loading, empty, error (a missing host method is labelled differently
5
- * from a real failure). Auto-refresh only runs while collection is enabled. */
2
+ *
3
+ * Page order: controls (date stepper + collection switch) → six headline cells
4
+ * for the selected local day → 30-day provider chart (name, tokens, calls and a
5
+ * share bar per row, plus a per-day strip with a text equivalent for empty
6
+ * days) → per-model breakdown → collapsible accounting definition.
7
+ *
8
+ * Rules that stay visible in the UI:
9
+ * - A day without records says "该日没有用量记录" instead of rendering zeroes
10
+ * as data; the statistics start point is shown when replay is unavailable.
11
+ * - Auto-refresh runs only while collection is enabled and the tab is visible.
12
+ * - Colours are host alias tokens only; there is no dark-mode branch here. */
6
13
  (function usagePage() {
7
14
  const POLL_INTERVAL_MS = 60_000
8
15
  const TREND_DAYS = 30
@@ -47,11 +54,17 @@
47
54
  return ACC.fmt.num(typeof value === 'number' ? value : 0)
48
55
  }
49
56
 
50
- /** @param {{ label: unknown, value: unknown, hint?: unknown, tone?: string }} props */
57
+ /** @param {number} value @returns {string} `42.3%` for a 0..1 share */
58
+ function percent(value) {
59
+ const share = typeof value === 'number' && Number.isFinite(value) ? Math.max(0, Math.min(1, value)) : 0
60
+ return `${(share * 100).toFixed(share >= 0.995 || share <= 0.005 ? 0 : 1)}%`
61
+ }
62
+
63
+ /** @param {{ label: unknown, value: unknown, hint?: unknown, tone?: string, title?: string }} props */
51
64
  function StatCell(props) {
52
65
  return h(
53
66
  'div',
54
- { className: 'acc-card', style: { padding: '12px', display: 'flex', flexDirection: 'column', gap: '2px' } },
67
+ { className: 'acc-card', style: { padding: '12px', display: 'flex', flexDirection: 'column', gap: '2px' }, title: props.title },
55
68
  h('span', { className: 'acc-stat-label' }, props.label),
56
69
  h(
57
70
  'span',
@@ -84,6 +97,37 @@
84
97
  )
85
98
  }
86
99
 
100
+ /** Collapsible block with a real button header. */
101
+ function Disclosure(props) {
102
+ return h(
103
+ 'div',
104
+ { style: { display: 'flex', flexDirection: 'column', gap: '6px' } },
105
+ h(
106
+ 'button',
107
+ {
108
+ type: 'button',
109
+ onClick: props.onToggle,
110
+ 'aria-expanded': props.open,
111
+ style: {
112
+ display: 'flex',
113
+ alignItems: 'center',
114
+ gap: '6px',
115
+ padding: 0,
116
+ border: 0,
117
+ background: 'transparent',
118
+ color: 'inherit',
119
+ font: 'inherit',
120
+ cursor: 'pointer',
121
+ textAlign: 'left',
122
+ },
123
+ },
124
+ h('span', { 'aria-hidden': 'true' }, props.open ? '▾' : '▸'),
125
+ h('strong', null, props.label),
126
+ ),
127
+ props.open ? props.children : null,
128
+ )
129
+ }
130
+
87
131
  /**
88
132
  * One provider bar with model segments. The row is keyboard focusable and
89
133
  * carries a full text equivalent (aria-label + title); the model breakdown is
@@ -95,8 +139,8 @@
95
139
  const row = props.row
96
140
  const providerName = row.unknown ? props.t('usage.unknownProvider') : String(row.provider)
97
141
  const modelText = row.models
98
- .map((model) => `${model.unknown ? props.t('usage.unknownProvider') : model.model} ${num(model.totals.totalTokens)} tokens · ${num(model.totals.calls)} ${props.t('usage.calls')}`)
99
- .join(';')
142
+ .map((model) => `${model.unknown ? props.t('usage.unknownProvider') : model.model} ${num(model.totals.totalTokens)} tokens · ${num(model.totals.calls)} ${props.t('usage.calls')} · ${percent(model.share)}`)
143
+ .join(ACC.l10n.lang() === 'en' ? '; ' : ';')
100
144
  const text = props.t('usage.chartAria', {
101
145
  provider: providerName,
102
146
  tokens: num(row.totals.totalTokens),
@@ -111,7 +155,7 @@
111
155
  className: 'acc-usage-row',
112
156
  'aria-label': text,
113
157
  title: text,
114
- style: { display: 'flex', flexDirection: 'column', gap: '4px', padding: '4px 0' },
158
+ style: { display: 'flex', flexDirection: 'column', gap: '4px', padding: '4px 0', borderRadius: TOKENS.radius },
115
159
  },
116
160
  h(
117
161
  'div',
@@ -151,25 +195,82 @@
151
195
  { style: { flex: '0 0 auto', display: 'flex', gap: '6px', alignItems: 'baseline', color: TOKENS.weak } },
152
196
  h('strong', { style: { color: TOKENS.text } }, num(row.totals.totalTokens)),
153
197
  h('span', null, `tokens · ${num(row.totals.calls)} ${props.t('usage.calls')}`),
198
+ h('span', { style: { color: TOKENS.faint, fontVariantNumeric: 'tabular-nums' } }, percent(row.share)),
154
199
  ),
155
200
  ),
156
201
  h('div', { className: 'acc-muted', style: { fontSize: '11px', paddingLeft: '140px', color: TOKENS.faint } }, modelText),
157
202
  )
158
203
  }
159
204
 
160
- /** @param {{ trend: any, t: Function }} props */
205
+ /**
206
+ * One slim bar per day of the window. Empty days are still rendered (with a
207
+ * tooltip that says the day has no records) so gaps are visible instead of
208
+ * silently collapsed.
209
+ * @param {{ series: any[], t: Function }} props
210
+ */
211
+ function DailyStrip(props) {
212
+ const series = Array.isArray(props.series) ? props.series : []
213
+ if (series.length === 0) return null
214
+ const max = series.reduce((value, entry) => Math.max(value, Number(entry.totals && entry.totals.totalTokens) || 0), 0)
215
+ return h(
216
+ 'div',
217
+ { role: 'img', 'aria-label': props.t('usage.dailyAria', { days: series.length }), style: { display: 'flex', flexDirection: 'column', gap: '4px' } },
218
+ h('div', { style: { display: 'flex', alignItems: 'flex-end', gap: '2px', height: '36px' } },
219
+ series.map((entry) =>
220
+ h(
221
+ 'div',
222
+ {
223
+ key: String(entry.day || entry.date),
224
+ title: entry.totals && entry.totals.totalTokens > 0
225
+ ? props.t('usage.dailyPoint', { date: String(entry.day || entry.date), tokens: num(entry.totals.totalTokens), calls: num(entry.totals.calls) })
226
+ : props.t('usage.dailyEmpty', { date: String(entry.day || entry.date) }),
227
+ style: {
228
+ flex: '1 1 0',
229
+ minWidth: '3px',
230
+ height: max > 0 && entry.totals && entry.totals.totalTokens > 0 ? `${Math.max(6, Math.round((entry.totals.totalTokens / max) * 100))}%` : '2px',
231
+ background: entry.totals && entry.totals.totalTokens > 0 ? TOKENS.bar : TOKENS.border,
232
+ borderRadius: '2px 2px 0 0',
233
+ },
234
+ },
235
+ ),
236
+ ),
237
+ ),
238
+ h('div', { style: { display: 'flex', justifyContent: 'space-between', fontSize: '11px', color: TOKENS.faint } },
239
+ h('span', null, monthDay(series[0].day || series[0].date)),
240
+ h('span', null, monthDay(series[series.length - 1].day || series[series.length - 1].date)),
241
+ ),
242
+ )
243
+ }
244
+
245
+ /** @param {{ trend: any, t: Function, tz: string }} props */
161
246
  function TrendChart(props) {
162
247
  const trend = props.trend || {}
163
248
  const rows = Array.isArray(trend.providers) ? trend.providers : []
249
+ const series = Array.isArray(trend.series) ? trend.series : []
250
+ const days = String(trend.days ?? TREND_DAYS)
164
251
  const summary = props.t('usage.chartSummary', {
165
- days: String(trend.days ?? TREND_DAYS),
252
+ days,
166
253
  tokens: num(trend.totals && trend.totals.totalTokens),
167
254
  calls: num(trend.totals && trend.totals.calls),
168
255
  providers: String(trend.totalProviders ?? rows.length),
169
256
  })
170
257
  return h(
171
258
  C.Card,
172
- { title: props.t('usage.trendTitle', { days: String(trend.days ?? TREND_DAYS) }), subtitle: props.t('usage.trendHint') },
259
+ {
260
+ title: props.t('usage.trendTitle', { days }),
261
+ subtitle: props.t('usage.trendHint'),
262
+ },
263
+ h(
264
+ 'div',
265
+ { className: 'acc-row', style: { justifyContent: 'space-between' } },
266
+ h('span', { className: 'acc-muted', style: { fontSize: '12px' } }, props.t('usage.windowTotals', {
267
+ tokens: num(trend.totals && trend.totals.totalTokens),
268
+ calls: num(trend.totals && trend.totals.calls),
269
+ days: String(trend.daysWithData ?? 0),
270
+ })),
271
+ h('span', { className: 'acc-muted', style: { fontSize: '11px' } }, props.t('usage.tzNote', { tz: props.tz })),
272
+ ),
273
+ h(DailyStrip, { series, t: props.t }),
173
274
  h(
174
275
  'div',
175
276
  { role: 'img', 'aria-label': summary, style: { display: 'flex', flexDirection: 'column', gap: '2px' } },
@@ -202,6 +303,7 @@
202
303
  model: model.unknown ? props.t('usage.unknownProvider') : model.model,
203
304
  tokens: model.totals.totalTokens,
204
305
  calls: model.totals.calls,
306
+ share: model.share,
205
307
  })
206
308
  }
207
309
  }
@@ -214,6 +316,22 @@
214
316
  { key: 'model', label: props.t('usage.model') },
215
317
  { key: 'tokens', label: props.t('usage.tokens'), align: 'right', render: (row) => num(row.tokens) },
216
318
  { key: 'calls', label: props.t('usage.calls'), align: 'right', render: (row) => num(row.calls) },
319
+ {
320
+ key: 'share',
321
+ label: props.t('usage.share'),
322
+ align: 'right',
323
+ render: (row) =>
324
+ h(
325
+ 'span',
326
+ { style: { display: 'inline-flex', alignItems: 'center', gap: '6px', minWidth: '90px' } },
327
+ h(
328
+ 'span',
329
+ { 'aria-hidden': 'true', style: { flex: '1 1 auto', height: '6px', background: TOKENS.hover, borderRadius: '999px', overflow: 'hidden', minWidth: '48px' } },
330
+ h('span', { style: { display: 'block', width: width(row.share), height: '100%', background: TOKENS.bar } }),
331
+ ),
332
+ h('span', { style: { color: TOKENS.weak, fontVariantNumeric: 'tabular-nums' } }, percent(row.share)),
333
+ ),
334
+ },
217
335
  ],
218
336
  rows,
219
337
  rowKey: 'key',
@@ -222,26 +340,73 @@
222
340
  )
223
341
  }
224
342
 
225
- /** @param {{ data: any, t: Function }} props */
343
+ /** @param {{ data: any, open: boolean, onToggle: Function, t: Function }} props */
226
344
  function Caliber(props) {
227
345
  const data = props.data
228
346
  const calibration = data.calibration || {}
229
347
  const days = String(data.retentionDays ?? calibration.retentionDays ?? '')
230
- const timezone = String(calibration.timezone ?? 'local')
348
+ const timezone = String(calibration.timezone ?? props.tz)
231
349
  return h(
232
350
  C.Card,
233
- { title: props.t('usage.caliberTitle') },
234
- h('ul', { style: { margin: 0, paddingLeft: '18px', display: 'flex', flexDirection: 'column', gap: '4px' } }, [
235
- h('li', { key: 'total' }, props.t('usage.caliberTotal')),
236
- h('li', { key: 'input' }, props.t('usage.caliberBilledInput')),
237
- h('li', { key: 'calls' }, props.t('usage.caliberCalls')),
238
- h('li', { key: 'day' }, props.t('usage.caliberDay', { timezone })),
239
- h('li', { key: 'unknown' }, props.t('usage.caliberUnknown')),
240
- h('li', { key: 'reasoning' }, props.t('usage.caliberReasoning')),
241
- h('li', { key: 'deleted' }, props.t('usage.caliberDeleted')),
242
- h('li', { key: 'cost' }, props.t('usage.caliberCost')),
243
- h('li', { key: 'retention' }, props.t('usage.caliberRetention', { days })),
244
- ]),
351
+ { title: props.t('usage.caliberTitle'), subtitle: props.t('usage.caliberSummary') },
352
+ h(
353
+ Disclosure,
354
+ { open: props.open, onToggle: props.onToggle, label: props.t('usage.caliberToggle') },
355
+ h('ul', { style: { margin: 0, paddingLeft: '18px', display: 'flex', flexDirection: 'column', gap: '4px' } }, [
356
+ h('li', { key: 'total' }, props.t('usage.caliberTotal')),
357
+ h('li', { key: 'input' }, props.t('usage.caliberBilledInput')),
358
+ h('li', { key: 'calls' }, props.t('usage.caliberCalls')),
359
+ h('li', { key: 'day' }, props.t('usage.caliberDay', { timezone })),
360
+ h('li', { key: 'unknown' }, props.t('usage.caliberUnknown')),
361
+ h('li', { key: 'reasoning' }, props.t('usage.caliberReasoning')),
362
+ h('li', { key: 'deleted' }, props.t('usage.caliberDeleted')),
363
+ h('li', { key: 'cost' }, props.t('usage.caliberCost')),
364
+ h('li', { key: 'retention' }, props.t('usage.caliberRetention', { days })),
365
+ ]),
366
+ ),
367
+ )
368
+ }
369
+
370
+ /**
371
+ * Compact day picker: previous/next buttons around a select grouped by month,
372
+ * plus a "today" shortcut. The list can hold one entry per recorded day
373
+ * (months), so grouping keeps the dropdown usable instead of a 180-row list.
374
+ * @param {{ dates: string[], today: string, selected: string, onPick: Function, t: Function }} props
375
+ */
376
+ function DatePicker(props) {
377
+ const dates = props.dates
378
+ const selectedIndex = dates.indexOf(props.selected)
379
+ const previous = selectedIndex > 0 ? dates[selectedIndex - 1] : null
380
+ const next = selectedIndex >= 0 && selectedIndex < dates.length - 1 ? dates[selectedIndex + 1] : null
381
+ const byMonth = new Map()
382
+ for (const key of dates) {
383
+ const month = key.slice(0, 7)
384
+ if (!byMonth.has(month)) byMonth.set(month, [])
385
+ byMonth.get(month).push(key)
386
+ }
387
+ return h(
388
+ 'div',
389
+ { className: 'acc-row', style: { gap: '6px' } },
390
+ h(C.Btn, { tone: 'ghost', disabled: previous === null, onClick: () => props.onPick(previous), title: previous ? monthDay(previous) : props.t('usage.dateEdge'), 'aria-label': props.t('usage.datePrev') }, '◀'),
391
+ h(
392
+ 'select',
393
+ {
394
+ className: 'acc-select',
395
+ value: props.selected,
396
+ 'aria-label': props.t('usage.dateLabel'),
397
+ title: props.t('usage.dateHint'),
398
+ onChange: (event) => props.onPick(event.target.value),
399
+ },
400
+ [...byMonth.entries()].map(([month, keys]) =>
401
+ h(
402
+ 'optgroup',
403
+ { key: month, label: month },
404
+ keys.map((key) => h('option', { key, value: key }, key === props.today ? `${props.t('usage.today')} · ${key.slice(5)}` : key.slice(5))),
405
+ ),
406
+ ),
407
+ ),
408
+ h(C.Btn, { tone: 'ghost', disabled: next === null, onClick: () => props.onPick(next), title: next ? monthDay(next) : props.t('usage.dateEdge'), 'aria-label': props.t('usage.dateNext') }, '▶'),
409
+ props.selected === props.today ? null : h(C.Btn, { tone: 'ghost', onClick: () => props.onPick(props.today), title: props.today }, props.t('usage.dateToday')),
245
410
  )
246
411
  }
247
412
 
@@ -294,13 +459,17 @@
294
459
  const t = props.t
295
460
  const [date, setDate] = useState('')
296
461
  const [switching, setSwitching] = useState(false)
462
+ const [openCaliber, setOpenCaliber] = useState(false)
463
+ const [toggleError, setToggleError] = useState(null)
297
464
  const state = useOverview({ date, enabled: true })
298
465
  const data = state.status === 'ready' ? state.data : null
299
466
  const enabled = data === null ? true : data.enabled !== false
300
467
  const reloadRef = useRef(state.reload)
301
468
  reloadRef.current = state.reload
469
+ const tz = String((data && data.calibration && data.calibration.timezone) || 'local')
302
470
 
303
- // Auto-refresh only while collection is enabled (spec D2-4 / acceptance 5).
471
+ // Auto-refresh only while collection is enabled (spec D2-4 / acceptance 5):
472
+ // a disabled ledger has nothing new to show, so the interval is torn down.
304
473
  useEffect(() => {
305
474
  if (!enabled) return undefined
306
475
  const timer = setInterval(() => {
@@ -324,32 +493,36 @@
324
493
  const day = overview.day || {}
325
494
  const totals = day.totals || {}
326
495
  const source = overview.source || {}
496
+ const consistency = overview.consistency || {}
327
497
  const availableDays = Array.isArray(overview.availableDays) ? overview.availableDays : []
328
498
  const today = overview.today && overview.today.date ? overview.today.date : ''
329
- const options = []
330
- if (today.length > 0) options.push({ value: today, label: t('usage.today') })
331
- for (const key of availableDays) if (key !== today) options.push({ value: key, label: monthDay(key) })
332
- const selected = date.length > 0 ? date : today
333
- const updatedAt = overview.updatedAt ? ACC.fmt.dateTime(overview.updatedAt) : t('usage.never')
334
- const empty = day.hasData !== true && Array.isArray(overview.trend && overview.trend.providers) && overview.trend.providers.length === 0
499
+ const dates = [...new Set([...availableDays, today].filter((key) => typeof key === 'string' && key.length === 10))].sort()
500
+ const selected = date.length > 0 && dates.includes(date) ? date : today
501
+ const updatedAt = overview.updatedAt ? ACC.l10n.dateTime(overview.updatedAt, t) : t('usage.never')
502
+ const hasDayData = day.hasData === true
503
+ const trendProviders = Array.isArray(overview.trend && overview.trend.providers) ? overview.trend.providers : []
504
+ const empty = hasDayData !== true && trendProviders.length === 0
335
505
 
336
506
  const toggle = async () => {
337
507
  setSwitching(true)
508
+ setToggleError(null)
338
509
  try {
339
510
  await ACC.api('usage.setEnabled', { enabled: !enabled })
340
511
  state.reload(true)
341
512
  } catch (error) {
513
+ setToggleError(error)
514
+ } finally {
342
515
  setSwitching(false)
343
- return
344
516
  }
345
- setSwitching(false)
346
517
  }
347
518
 
519
+ const cellValue = (value) => (hasDayData ? num(value) : '—')
520
+
348
521
  return pageRoot([
349
522
  h(
350
523
  C.Card,
351
524
  {
352
- title: t('usage.title'),
525
+ title: t('usage.cardTitle'),
353
526
  subtitle: t('usage.description'),
354
527
  actions: h(
355
528
  'div',
@@ -357,28 +530,19 @@
357
530
  h('span', { style: { fontSize: '11px', color: TOKENS.weak } }, t('usage.updatedAt', { time: updatedAt })),
358
531
  h(
359
532
  C.Btn,
360
- { onClick: () => state.reload(true), disabled: state.refreshing === true || switching, title: t('usage.refresh') },
533
+ { onClick: () => state.reload(true), disabled: state.refreshing === true || switching, title: t('usage.refresh'), ariaLabel: t('usage.refreshUsage') },
361
534
  state.refreshing === true ? t('usage.refreshing') : t('usage.refresh'),
362
535
  ),
363
536
  ),
364
537
  },
365
538
  h(
366
539
  'div',
367
- { className: 'acc-row', style: { justifyContent: 'space-between' } },
540
+ { className: 'acc-row', style: { justifyContent: 'space-between', alignItems: 'flex-end' } },
368
541
  h(
369
542
  'label',
370
543
  { style: { display: 'flex', alignItems: 'center', gap: '8px', fontSize: '12px' } },
371
544
  h('span', { style: { color: TOKENS.weak } }, t('usage.dateLabel')),
372
- h(
373
- 'select',
374
- {
375
- className: 'acc-select',
376
- value: selected,
377
- 'aria-label': t('usage.dateLabel'),
378
- onChange: (event) => setDate(event.target.value === today ? '' : event.target.value),
379
- },
380
- options.map((option) => h('option', { key: option.value, value: option.value }, `${option.label} ${monthDay(option.value)}`)),
381
- ),
545
+ h(DatePicker, { dates: dates.length > 0 ? dates : [today], today, selected, onPick: (key) => setDate(key === today ? '' : key), t }),
382
546
  ),
383
547
  h(
384
548
  'div',
@@ -389,14 +553,27 @@
389
553
  ),
390
554
  h('p', { style: { margin: 0, fontSize: '11px', color: TOKENS.faint } }, t('usage.switchHint')),
391
555
  enabled ? null : h(C.Notice, { tone: 'warn' }, `${t('usage.disabledTitle')} — ${t('usage.disabledHint')}`),
556
+ toggleError ? h(C.ErrorBox, { error: toggleError, label: t('usage.toggleFailed'), onRetry: toggle }) : null,
392
557
  source.historyReplay === false
393
558
  ? h(
394
559
  C.Notice,
395
560
  { tone: 'warn' },
396
561
  h('div', null, t('usage.since', { since: source.since ? ACC.fmt.dateTime(source.since) : t('usage.never') })),
397
- h('div', null, t('usage.sinceReason', { reason: String(source.sinceReason || t('usage.replayUnavailable')) })),
562
+ h('div', null, ACC.l10n.host('usage.sinceReasonGeneric', source.sinceReason) || t('usage.replayUnavailable')),
563
+ ACC.l10n.raw(t('usage.rawHostText'), source.sinceReason),
398
564
  )
399
565
  : null,
566
+ Number(consistency.invalidDayKeyCount) > 0
567
+ ? h(C.Notice, { tone: 'warn' }, t('usage.consistencyWarn', { count: num(consistency.invalidDayKeyCount) }))
568
+ : null,
569
+ hasDayData || empty
570
+ ? null
571
+ : h(
572
+ C.Notice,
573
+ { tone: 'info' },
574
+ h('div', null, t('usage.dayNoData', { date: selected })),
575
+ h('div', { style: { color: TOKENS.weak } }, t('usage.dayNoDataHint')),
576
+ ),
400
577
  ),
401
578
 
402
579
  empty
@@ -411,25 +588,25 @@
411
588
  : h(
412
589
  'div',
413
590
  { className: 'acc-stat-grid' },
414
- h(StatCell, { label: t('usage.statTotal'), value: num(totals.totalTokens) }),
591
+ h(StatCell, { label: t('usage.statTotal'), value: cellValue(totals.totalTokens), title: hasDayData ? undefined : t('usage.dayNoData', { date: selected }) }),
415
592
  h(StatCell, {
416
593
  label: t('usage.statInput'),
417
- value: num(totals.billedInputTokens),
594
+ value: cellValue(totals.billedInputTokens),
418
595
  hint: t('usage.inputHint', {
419
596
  uncached: num(totals.uncachedInputTokens),
420
597
  read: num(totals.cacheReadTokens),
421
598
  write: num(totals.cacheWriteTokens),
422
599
  }),
423
600
  }),
424
- h(StatCell, { label: t('usage.statOutput'), value: num(totals.outputTokens), hint: `${t('usage.caliberReasoning')}` }),
425
- h(StatCell, { label: t('usage.statCacheRead'), value: num(totals.cacheReadTokens) }),
426
- h(StatCell, { label: t('usage.statCacheWrite'), value: num(totals.cacheWriteTokens) }),
427
- h(StatCell, { label: t('usage.statCalls'), value: num(totals.calls), hint: t('usage.callsHint') }),
601
+ h(StatCell, { label: t('usage.statOutput'), value: cellValue(totals.outputTokens), hint: `${t('usage.caliberReasoning')}` }),
602
+ h(StatCell, { label: t('usage.statCacheRead'), value: cellValue(totals.cacheReadTokens) }),
603
+ h(StatCell, { label: t('usage.statCacheWrite'), value: cellValue(totals.cacheWriteTokens) }),
604
+ h(StatCell, { label: t('usage.statCalls'), value: cellValue(totals.calls), hint: t('usage.callsHint') }),
428
605
  ),
429
606
 
430
- empty ? null : h(TrendChart, { trend: overview.trend, t }),
607
+ empty ? null : h(TrendChart, { trend: overview.trend, t, tz }),
431
608
  empty ? null : h(DayTable, { day, t }),
432
- h(Caliber, { data: overview, t }),
609
+ h(Caliber, { data: overview, open: openCaliber, onToggle: () => setOpenCaliber((value) => !value), t, tz }),
433
610
  ])
434
611
  }
435
612
 
@@ -437,6 +614,7 @@
437
614
  id: 'usage',
438
615
  titleKey: 'nav.usage',
439
616
  order: 50,
617
+ group: 'insight',
440
618
  render: (props) => h(UsagePage, props),
441
619
  })
442
620
  })()