dsh-all-usage 1.0.8 → 1.1.1
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 +46 -0
- package/LICENSE +21 -21
- package/README.md +45 -9
- package/assets/screenshot-1.png +0 -0
- package/assets/screenshot-2.png +0 -0
- package/assets/screenshot-3.png +0 -0
- package/assets/screenshot-4.png +0 -0
- package/assets/screenshot-5.png +0 -0
- package/assets/screenshot-6.png +0 -0
- package/assets/screenshot-7.png +0 -0
- package/cordis.patch.yml +5 -5
- package/lib/client.js +2271 -1200
- package/lib/index.js +1572 -1039
- package/package.json +56 -55
- package/screenshots.json +9 -0
package/lib/client.js
CHANGED
|
@@ -1,1200 +1,2271 @@
|
|
|
1
|
-
// dsh-all-usage 插件 Client 半(永久版,浏览器 bundle)
|
|
2
|
-
// 客户端模块工厂格式:window.__ModuleLoader__.load({ id, factory })
|
|
3
|
-
window.__ModuleLoader__.load({
|
|
4
|
-
id: "dsh-all-usage",
|
|
5
|
-
factory: (require) => {
|
|
6
|
-
var module = { exports: {} };
|
|
7
|
-
var exports = module.exports;
|
|
8
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
9
|
-
const React = require("react");
|
|
10
|
-
|
|
11
|
-
function pad2(n) {
|
|
12
|
-
return String(n).padStart(2, '0')
|
|
13
|
-
}
|
|
14
|
-
function fmtDate(d, utc) {
|
|
15
|
-
const year = utc ? d.getUTCFullYear() : d.getFullYear()
|
|
16
|
-
const month = utc ? d.getUTCMonth() : d.getMonth()
|
|
17
|
-
const day = utc ? d.getUTCDate() : d.getDate()
|
|
18
|
-
return year + '-' + pad2(month + 1) + '-' + pad2(day)
|
|
19
|
-
}
|
|
20
|
-
function shiftCalendarDate(d, days, utc) {
|
|
21
|
-
if (utc) return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate() + days))
|
|
22
|
-
return new Date(d.getFullYear(), d.getMonth(), d.getDate() + days)
|
|
23
|
-
}
|
|
24
|
-
function isCalendarDate(value, utc) {
|
|
25
|
-
if (typeof value !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return false
|
|
26
|
-
const year = Number(value.slice(0, 4))
|
|
27
|
-
const month = Number(value.slice(5, 7))
|
|
28
|
-
const day = Number(value.slice(8, 10))
|
|
29
|
-
const date = utc ? new Date(Date.UTC(year, month - 1, day)) : new Date(year, month - 1, day)
|
|
30
|
-
return Number.isFinite(date.getTime()) && fmtDate(date, utc) === value
|
|
31
|
-
}
|
|
32
|
-
function normalizeCustomRange(range, utc) {
|
|
33
|
-
if (range === null || typeof range !== 'object') return null
|
|
34
|
-
const start = range.start
|
|
35
|
-
const end = range.end
|
|
36
|
-
if (!isCalendarDate(start, utc) || !isCalendarDate(end, utc) || start > end) return null
|
|
37
|
-
return { start, end }
|
|
38
|
-
}
|
|
39
|
-
function customRangeIssue(range, minDate, maxDate, utc) {
|
|
40
|
-
if (range === null || typeof range !== 'object' || !isCalendarDate(range.start, utc) || !isCalendarDate(range.end, utc)) return 'invalid'
|
|
41
|
-
if (range.start > range.end) return 'order'
|
|
42
|
-
if (range.start < minDate || range.end > maxDate) return 'bounds'
|
|
43
|
-
return ''
|
|
44
|
-
}
|
|
45
|
-
function availableDateBounds(days, maxDate) {
|
|
46
|
-
let min = maxDate
|
|
47
|
-
if (Array.isArray(days)) {
|
|
48
|
-
for (const day of days) {
|
|
49
|
-
if (day && isCalendarDate(day.date, true) && day.date <= maxDate && day.date < min) min = day.date
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return { min, max: maxDate }
|
|
53
|
-
}
|
|
54
|
-
function createRequestGate() {
|
|
55
|
-
let latest = 0
|
|
56
|
-
return {
|
|
57
|
-
next() { latest += 1; return latest },
|
|
58
|
-
isCurrent(seq) { return seq === latest },
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
function
|
|
62
|
-
if (
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
-
function
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (language === 'en')
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return
|
|
149
|
-
}
|
|
150
|
-
function
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
function
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
.
|
|
281
|
-
|
|
282
|
-
.
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
.
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
.
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
.
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
.
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
.
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
.
|
|
332
|
-
|
|
333
|
-
.
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
.
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
.
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
.
|
|
390
|
-
.
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
.
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
.
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
.
|
|
423
|
-
.
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
.
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
.
|
|
433
|
-
.
|
|
434
|
-
|
|
435
|
-
.
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
.
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
.
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
.
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
.
|
|
462
|
-
.
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
const
|
|
592
|
-
const
|
|
593
|
-
|
|
594
|
-
}
|
|
595
|
-
const
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
const
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
const
|
|
672
|
-
|
|
673
|
-
const
|
|
674
|
-
const
|
|
675
|
-
const
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
)
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
const
|
|
1162
|
-
const
|
|
1163
|
-
const
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1
|
+
// dsh-all-usage 插件 Client 半(永久版,浏览器 bundle)
|
|
2
|
+
// 客户端模块工厂格式:window.__ModuleLoader__.load({ id, factory })
|
|
3
|
+
window.__ModuleLoader__.load({
|
|
4
|
+
id: "dsh-all-usage",
|
|
5
|
+
factory: (require) => {
|
|
6
|
+
var module = { exports: {} };
|
|
7
|
+
var exports = module.exports;
|
|
8
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
9
|
+
const React = require("react");
|
|
10
|
+
|
|
11
|
+
function pad2(n) {
|
|
12
|
+
return String(n).padStart(2, '0')
|
|
13
|
+
}
|
|
14
|
+
function fmtDate(d, utc) {
|
|
15
|
+
const year = utc ? d.getUTCFullYear() : d.getFullYear()
|
|
16
|
+
const month = utc ? d.getUTCMonth() : d.getMonth()
|
|
17
|
+
const day = utc ? d.getUTCDate() : d.getDate()
|
|
18
|
+
return year + '-' + pad2(month + 1) + '-' + pad2(day)
|
|
19
|
+
}
|
|
20
|
+
function shiftCalendarDate(d, days, utc) {
|
|
21
|
+
if (utc) return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate() + days))
|
|
22
|
+
return new Date(d.getFullYear(), d.getMonth(), d.getDate() + days)
|
|
23
|
+
}
|
|
24
|
+
function isCalendarDate(value, utc) {
|
|
25
|
+
if (typeof value !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return false
|
|
26
|
+
const year = Number(value.slice(0, 4))
|
|
27
|
+
const month = Number(value.slice(5, 7))
|
|
28
|
+
const day = Number(value.slice(8, 10))
|
|
29
|
+
const date = utc ? new Date(Date.UTC(year, month - 1, day)) : new Date(year, month - 1, day)
|
|
30
|
+
return Number.isFinite(date.getTime()) && fmtDate(date, utc) === value
|
|
31
|
+
}
|
|
32
|
+
function normalizeCustomRange(range, utc) {
|
|
33
|
+
if (range === null || typeof range !== 'object') return null
|
|
34
|
+
const start = range.start
|
|
35
|
+
const end = range.end
|
|
36
|
+
if (!isCalendarDate(start, utc) || !isCalendarDate(end, utc) || start > end) return null
|
|
37
|
+
return { start, end }
|
|
38
|
+
}
|
|
39
|
+
function customRangeIssue(range, minDate, maxDate, utc) {
|
|
40
|
+
if (range === null || typeof range !== 'object' || !isCalendarDate(range.start, utc) || !isCalendarDate(range.end, utc)) return 'invalid'
|
|
41
|
+
if (range.start > range.end) return 'order'
|
|
42
|
+
if (range.start < minDate || range.end > maxDate) return 'bounds'
|
|
43
|
+
return ''
|
|
44
|
+
}
|
|
45
|
+
function availableDateBounds(days, maxDate) {
|
|
46
|
+
let min = maxDate
|
|
47
|
+
if (Array.isArray(days)) {
|
|
48
|
+
for (const day of days) {
|
|
49
|
+
if (day && isCalendarDate(day.date, true) && day.date <= maxDate && day.date < min) min = day.date
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return { min, max: maxDate }
|
|
53
|
+
}
|
|
54
|
+
function createRequestGate() {
|
|
55
|
+
let latest = 0
|
|
56
|
+
return {
|
|
57
|
+
next() { latest += 1; return latest },
|
|
58
|
+
isCurrent(seq) { return seq === latest },
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function snapshotVersion(data) {
|
|
62
|
+
if (data === null || typeof data !== 'object') return null
|
|
63
|
+
const instanceId = typeof data.instanceId === 'string' ? data.instanceId : ''
|
|
64
|
+
const revision = typeof data.revision === 'number' && Number.isFinite(data.revision) ? data.revision : null
|
|
65
|
+
return instanceId === '' || revision === null ? null : instanceId + ':' + revision
|
|
66
|
+
}
|
|
67
|
+
function statusRequiresFullSnapshot(status, snapshot) {
|
|
68
|
+
if (status === null || typeof status !== 'object' || snapshot === null || typeof snapshot !== 'object') return true
|
|
69
|
+
const statusVersion = snapshotVersion(status)
|
|
70
|
+
const snapshotVersionValue = snapshotVersion(snapshot)
|
|
71
|
+
if (statusVersion === null || snapshotVersionValue === null || statusVersion !== snapshotVersionValue) return true
|
|
72
|
+
const statusScan = status.scan
|
|
73
|
+
const snapshotScan = snapshot.scan
|
|
74
|
+
return !!(statusScan && snapshotScan && !!statusScan.done !== !!snapshotScan.done)
|
|
75
|
+
}
|
|
76
|
+
function retryDelayFor(failures) {
|
|
77
|
+
const count = Math.max(1, Math.min(4, typeof failures === 'number' && Number.isFinite(failures) ? failures : 1))
|
|
78
|
+
return 5000 * Math.pow(2, count - 1)
|
|
79
|
+
}
|
|
80
|
+
function rangeFilenamePart(range, customRange, utc) {
|
|
81
|
+
if (range !== 'custom') return range
|
|
82
|
+
const normalized = normalizeCustomRange(customRange, utc)
|
|
83
|
+
return normalized === null ? 'custom' : 'custom-' + normalized.start + '-to-' + normalized.end
|
|
84
|
+
}
|
|
85
|
+
function trim1(v) {
|
|
86
|
+
return String(Math.round(v * 10) / 10)
|
|
87
|
+
}
|
|
88
|
+
function fmtCompact(n) {
|
|
89
|
+
if (typeof n !== 'number' || !Number.isFinite(n)) return '0'
|
|
90
|
+
if (n < 1000) return String(n)
|
|
91
|
+
if (n < 1000000) return trim1(n / 1000) + 'k'
|
|
92
|
+
if (n < 1000000000) return trim1(n / 1000000) + 'M'
|
|
93
|
+
return trim1(n / 1000000000) + 'B'
|
|
94
|
+
}
|
|
95
|
+
function rateOf(input, cacheRead) {
|
|
96
|
+
const denom = input + cacheRead
|
|
97
|
+
if (denom <= 0) return 0
|
|
98
|
+
return (cacheRead / denom) * 100
|
|
99
|
+
}
|
|
100
|
+
function LineIcon(props) {
|
|
101
|
+
const size = props.size || 16
|
|
102
|
+
const base = { fill: 'none', stroke: 'currentColor', strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round' }
|
|
103
|
+
const paths = {
|
|
104
|
+
edit: [React.createElement('path', { key: 'a', d: 'M12.2 3.4l2.4 2.4M4 16l2.8-.6L15 7.2a1.7 1.7 0 0 0-2.4-2.4L4.4 13z', ...base })],
|
|
105
|
+
export: [React.createElement('path', { key: 'a', d: 'M12 3v11M8 7l4-4 4 4M5 13v5h14v-5', ...base })],
|
|
106
|
+
refresh: [React.createElement('path', { key: 'a', d: 'M19 9a7 7 0 1 0 1.1 5.2M19 4v5h-5', ...base })],
|
|
107
|
+
close: [React.createElement('path', { key: 'a', d: 'M6 6l12 12M18 6L6 18', ...base })],
|
|
108
|
+
chart: [React.createElement('path', { key: 'a', d: 'M4 19V5M4 19h16M7 15l3-4 3 2 5-7', ...base })],
|
|
109
|
+
list: [React.createElement('path', { key: 'a', d: 'M6 6h12M6 12h12M6 18h12', ...base }), React.createElement('circle', { key: 'b', cx: 3.5, cy: 6, r: .7, fill: 'currentColor' }), React.createElement('circle', { key: 'c', cx: 3.5, cy: 12, r: .7, fill: 'currentColor' }), React.createElement('circle', { key: 'd', cx: 3.5, cy: 18, r: .7, fill: 'currentColor' })],
|
|
110
|
+
cache: [React.createElement('path', { key: 'a', d: 'M12 4l7 4-7 4-7-4 7-4zM5 12l7 4 7-4M5 16l7 4 7-4', ...base })],
|
|
111
|
+
wallet: [React.createElement('path', { key: 'a', d: 'M4 7.5A2.5 2.5 0 0 1 6.5 5H18v14H6.5A2.5 2.5 0 0 1 4 16.5zM4 8h14M14 13h.01', ...base })],
|
|
112
|
+
clock: [React.createElement('path', { key: 'a', d: 'M12 6v6l4 2M20 12a8 8 0 1 1-16 0 8 8 0 0 1 16 0z', ...base })],
|
|
113
|
+
folder: [React.createElement('path', { key: 'a', d: 'M3.5 7.5h6l2 2h9v8.5a2 2 0 0 1-2 2h-13a2 2 0 0 1-2-2z', ...base })],
|
|
114
|
+
language: [React.createElement('circle', { key: 'a', cx: 12, cy: 12, r: 8, ...base }), React.createElement('path', { key: 'b', d: 'M4 12h16M12 4c2.1 2.2 3.2 4.9 3.2 8S14.1 17.8 12 20M12 4C9.9 6.2 8.8 8.9 8.8 12s1.1 5.8 3.2 8', ...base })],
|
|
115
|
+
chevron: [React.createElement('path', { key: 'a', d: 'M7 10l5 5 5-5', ...base })],
|
|
116
|
+
check: [React.createElement('path', { key: 'a', d: 'M5 12.5l4.2 4.1L19 7.3', ...base })],
|
|
117
|
+
calendar: [React.createElement('path', { key: 'a', d: 'M6 4v3M18 4v3M4 9h16M5 6h14a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1z', ...base })],
|
|
118
|
+
}
|
|
119
|
+
return React.createElement('svg', { className: 'uh-line-icon ' + (props.className || ''), width: size, height: size, viewBox: '0 0 24 24', 'aria-hidden': true }, paths[props.name] || paths.chart)
|
|
120
|
+
}
|
|
121
|
+
function chineseMagnitude(n, language) {
|
|
122
|
+
if (language === 'en' || typeof n !== 'number' || !Number.isFinite(n) || n < 10000) return ''
|
|
123
|
+
const value = n >= 100000000 ? n / 100000000 : n / 10000
|
|
124
|
+
const rounded = Math.round(value * 1000) / 1000
|
|
125
|
+
return String(rounded) + (n >= 100000000 ? '亿' : '万')
|
|
126
|
+
}
|
|
127
|
+
function valueWithMagnitude(value, raw, language) {
|
|
128
|
+
const magnitude = chineseMagnitude(raw, language)
|
|
129
|
+
return React.createElement(React.Fragment, null, value, magnitude ? React.createElement('span', { className: 'uh-unit' }, magnitude) : null)
|
|
130
|
+
}
|
|
131
|
+
function money(currency, n, language) {
|
|
132
|
+
if (n === null || n === undefined) return '—'
|
|
133
|
+
const sym = currency === 'CNY' ? '¥' : currency === 'USD' ? '$' : currency + ' '
|
|
134
|
+
return sym + n.toLocaleString(language === 'en' ? 'en-US' : 'zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
|
|
135
|
+
}
|
|
136
|
+
function humanDate(date, language) {
|
|
137
|
+
const parts = date.split('-')
|
|
138
|
+
const utc = language === 'en'
|
|
139
|
+
const d = utc ? new Date(Date.UTC(Number(parts[0]), Number(parts[1]) - 1, Number(parts[2]))) : new Date(Number(parts[0]), Number(parts[1]) - 1, Number(parts[2]))
|
|
140
|
+
const monthIndex = utc ? d.getUTCMonth() : d.getMonth()
|
|
141
|
+
const weekIndex = utc ? d.getUTCDay() : d.getDay()
|
|
142
|
+
if (language === 'en') {
|
|
143
|
+
const month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][monthIndex]
|
|
144
|
+
const week = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][weekIndex]
|
|
145
|
+
return month + ' ' + Number(parts[2]) + ', ' + parts[0] + ' (' + week + ', UTC)'
|
|
146
|
+
}
|
|
147
|
+
const week = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][weekIndex]
|
|
148
|
+
return parts[0] + '年' + Number(parts[1]) + '月' + Number(parts[2]) + '日 ' + week
|
|
149
|
+
}
|
|
150
|
+
function monthLabel(year, month, language) {
|
|
151
|
+
if (language === 'en') {
|
|
152
|
+
const label = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][month]
|
|
153
|
+
return month === 0 ? year + ' ' + label : label
|
|
154
|
+
}
|
|
155
|
+
return month === 0 ? year + '年1月' : (month + 1) + '月'
|
|
156
|
+
}
|
|
157
|
+
function levelOf(count) {
|
|
158
|
+
if (count >= 10) return 4
|
|
159
|
+
if (count >= 6) return 3
|
|
160
|
+
if (count >= 3) return 2
|
|
161
|
+
if (count >= 1) return 1
|
|
162
|
+
return 0
|
|
163
|
+
}
|
|
164
|
+
const GH_GREEN = '#2ea043'
|
|
165
|
+
const LEVEL_PCT = [20, 45, 70, 96]
|
|
166
|
+
function cellBg(level) {
|
|
167
|
+
if (level <= 0) return 'var(--dsw-alias-bg-layer-2)'
|
|
168
|
+
return 'color-mix(in srgb, ' + GH_GREEN + ' ' + LEVEL_PCT[level - 1] + '%, var(--dsw-alias-bg-layer-2))'
|
|
169
|
+
}
|
|
170
|
+
function wsColor(i) {
|
|
171
|
+
return 'hsl(' + ((i * 137) % 360) + ', 70%, 55%)'
|
|
172
|
+
}
|
|
173
|
+
function rangeAgg(stats, range, utc, customRange) {
|
|
174
|
+
const empty = { totals: { turns: 0, sessions: 0, input: 0, output: 0, cacheRead: 0, cacheWrite: 0, reasoning: 0 }, perWs: [], perModel: [] }
|
|
175
|
+
if (stats === null) return empty
|
|
176
|
+
if (range === 'all') return { totals: stats.totals, perWs: stats.perWorkspace, perModel: stats.perModel || [] }
|
|
177
|
+
const days = utc && Array.isArray(stats.byDayUtc) ? stats.byDayUtc : (Array.isArray(stats.byDay) ? stats.byDay : [])
|
|
178
|
+
let start
|
|
179
|
+
let end = null
|
|
180
|
+
if (range === 'custom') {
|
|
181
|
+
const normalized = normalizeCustomRange(customRange, utc)
|
|
182
|
+
if (normalized === null) return empty
|
|
183
|
+
start = normalized.start
|
|
184
|
+
end = normalized.end
|
|
185
|
+
} else if (range === 'today') {
|
|
186
|
+
start = fmtDate(new Date(), utc)
|
|
187
|
+
} else if (range === '30d') {
|
|
188
|
+
start = fmtDate(shiftCalendarDate(new Date(), -29, utc), utc)
|
|
189
|
+
} else {
|
|
190
|
+
start = fmtDate(shiftCalendarDate(new Date(), -89, utc), utc)
|
|
191
|
+
}
|
|
192
|
+
const t = { turns: 0, sessions: 0, input: 0, output: 0, cacheRead: 0, cacheWrite: 0, reasoning: 0 }
|
|
193
|
+
const per = new Map()
|
|
194
|
+
const models = new Map()
|
|
195
|
+
const sessionsInRange = new Set()
|
|
196
|
+
for (const day of days) {
|
|
197
|
+
if (day.date < start || (end !== null && day.date > end)) continue
|
|
198
|
+
const daySessionIds = Array.isArray(day.sessionIds) ? day.sessionIds : []
|
|
199
|
+
for (const sid of daySessionIds) sessionsInRange.add(sid)
|
|
200
|
+
t.turns += day.turns
|
|
201
|
+
t.input += day.tokens.input
|
|
202
|
+
t.output += day.tokens.output
|
|
203
|
+
t.cacheRead += day.tokens.cacheRead
|
|
204
|
+
t.cacheWrite += day.tokens.cacheWrite
|
|
205
|
+
t.reasoning += day.tokens.reasoning
|
|
206
|
+
for (const w of day.byWorkspace) {
|
|
207
|
+
let p = per.get(w.workspaceId)
|
|
208
|
+
if (p === undefined) { p = { workspaceId: w.workspaceId, turns: 0, input: 0, output: 0, cacheRead: 0, cacheWrite: 0, reasoning: 0 }; per.set(w.workspaceId, p) }
|
|
209
|
+
p.input += w.input
|
|
210
|
+
p.output += w.output
|
|
211
|
+
p.cacheRead += w.cacheRead
|
|
212
|
+
p.cacheWrite += w.cacheWrite
|
|
213
|
+
p.reasoning += w.reasoning
|
|
214
|
+
}
|
|
215
|
+
for (const w of day.perWorkspace) {
|
|
216
|
+
let p = per.get(w.workspaceId)
|
|
217
|
+
if (p === undefined) { p = { workspaceId: w.workspaceId, turns: 0, input: 0, output: 0, cacheRead: 0, cacheWrite: 0, reasoning: 0 }; per.set(w.workspaceId, p) }
|
|
218
|
+
p.turns += w.turns
|
|
219
|
+
}
|
|
220
|
+
for (const m of (day.byModel || [])) {
|
|
221
|
+
const key = m.identityKey || m.model
|
|
222
|
+
let p = models.get(key)
|
|
223
|
+
if (p === undefined) { p = { ...m, calls: 0, input: 0, output: 0, cacheRead: 0, cacheWrite: 0, reasoning: 0 }; models.set(key, p) }
|
|
224
|
+
p.calls += m.calls; p.input += m.input; p.output += m.output; p.cacheRead += m.cacheRead; p.cacheWrite += m.cacheWrite; p.reasoning += m.reasoning
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
t.sessions = sessionsInRange.size
|
|
228
|
+
return { totals: t, perWs: Array.from(per.values()), perModel: Array.from(models.values()) }
|
|
229
|
+
}
|
|
230
|
+
function resolveRangeBounds(stats, range, utc, customRange) {
|
|
231
|
+
const days = utc && Array.isArray(stats && stats.byDayUtc) ? stats.byDayUtc : (Array.isArray(stats && stats.byDay) ? stats.byDay : [])
|
|
232
|
+
const latest = fmtDate(new Date(), utc)
|
|
233
|
+
if (range === 'custom') {
|
|
234
|
+
const normalized = normalizeCustomRange(customRange, utc)
|
|
235
|
+
return normalized === null ? null : { start: normalized.start, end: normalized.end }
|
|
236
|
+
}
|
|
237
|
+
if (range === 'today') return { start: latest, end: latest }
|
|
238
|
+
if (range === '30d') return { start: fmtDate(shiftCalendarDate(new Date(), -29, utc), utc), end: latest }
|
|
239
|
+
if (range === '90d') return { start: fmtDate(shiftCalendarDate(new Date(), -89, utc), utc), end: latest }
|
|
240
|
+
const bounds = availableDateBounds(days, latest)
|
|
241
|
+
return { start: bounds.min, end: bounds.max }
|
|
242
|
+
}
|
|
243
|
+
function makeUsageScope(stats, range, utc, customRange, workspaceId, provider, modelKey) {
|
|
244
|
+
const bounds = resolveRangeBounds(stats, range, utc, customRange)
|
|
245
|
+
if (bounds === null) return null
|
|
246
|
+
return { start: bounds.start, end: bounds.end, utc: utc === true, workspaceId: workspaceId || null, provider: provider || null, modelKey: modelKey || null }
|
|
247
|
+
}
|
|
248
|
+
function usageScopeKey(scope) {
|
|
249
|
+
return scope === null ? '' : JSON.stringify({ start: scope.start, end: scope.end, utc: scope.utc === true, workspaceId: scope.workspaceId || null, provider: scope.provider || null, modelKey: scope.modelKey || null })
|
|
250
|
+
}
|
|
251
|
+
function rowTokens(row) {
|
|
252
|
+
const tokens = row && row.tokens && typeof row.tokens === 'object' ? row.tokens : row || {}
|
|
253
|
+
return { input: Number.isFinite(tokens.input) ? tokens.input : 0, output: Number.isFinite(tokens.output) ? tokens.output : 0, cacheRead: Number.isFinite(tokens.cacheRead) ? tokens.cacheRead : 0, cacheWrite: Number.isFinite(tokens.cacheWrite) ? tokens.cacheWrite : 0, reasoning: Number.isFinite(tokens.reasoning) ? tokens.reasoning : 0 }
|
|
254
|
+
}
|
|
255
|
+
function buildTrendRows(rows, bounds, utc) {
|
|
256
|
+
if (bounds === null || typeof bounds !== 'object') return []
|
|
257
|
+
const source = new Map((Array.isArray(rows) ? rows : []).filter((row) => row && typeof row.date === 'string').map((row) => [row.date, row]))
|
|
258
|
+
const startParts = bounds.start.split('-').map(Number)
|
|
259
|
+
const endParts = bounds.end.split('-').map(Number)
|
|
260
|
+
const cursor = utc ? new Date(Date.UTC(startParts[0], startParts[1] - 1, startParts[2])) : new Date(startParts[0], startParts[1] - 1, startParts[2])
|
|
261
|
+
const end = utc ? new Date(Date.UTC(endParts[0], endParts[1] - 1, endParts[2])) : new Date(endParts[0], endParts[1] - 1, endParts[2])
|
|
262
|
+
const result = []
|
|
263
|
+
while (cursor.getTime() <= end.getTime()) {
|
|
264
|
+
const date = fmtDate(cursor, utc)
|
|
265
|
+
const row = source.get(date)
|
|
266
|
+
const tokens = rowTokens(row)
|
|
267
|
+
result.push({ date, turns: row && Number.isFinite(row.turns) ? row.turns : 0, calls: row && Number.isFinite(row.calls) ? row.calls : 0, sessions: row && Number.isFinite(row.sessions) ? row.sessions : 0, tokens, total: tokens.input + tokens.output + tokens.cacheRead + tokens.cacheWrite + tokens.reasoning })
|
|
268
|
+
if (utc) cursor.setUTCDate(cursor.getUTCDate() + 1)
|
|
269
|
+
else cursor.setDate(cursor.getDate() + 1)
|
|
270
|
+
}
|
|
271
|
+
return result
|
|
272
|
+
}
|
|
273
|
+
function buildTrendHourlyRows(rows, utc) {
|
|
274
|
+
const result = []
|
|
275
|
+
for (const row of (Array.isArray(rows) ? rows : [])) {
|
|
276
|
+
if (row === null || typeof row !== 'object') continue
|
|
277
|
+
const time = Number.isFinite(row.time) ? row.time : (typeof row.date === 'string' ? Date.parse(row.date) : NaN)
|
|
278
|
+
if (!Number.isFinite(time)) continue
|
|
279
|
+
const tokens = rowTokens(row)
|
|
280
|
+
result.push({ date: fmtDate(new Date(time), utc), time, turns: Number.isFinite(row.turns) ? row.turns : 0, calls: Number.isFinite(row.calls) ? row.calls : 0, sessions: Number.isFinite(row.sessions) ? row.sessions : 0, tokens, total: tokens.input + tokens.output + tokens.cacheRead + tokens.cacheWrite + tokens.reasoning })
|
|
281
|
+
}
|
|
282
|
+
return result.sort((a, b) => a.time - b.time)
|
|
283
|
+
}
|
|
284
|
+
function trendHourLabel(time, language, detailed) {
|
|
285
|
+
const options = detailed
|
|
286
|
+
? { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false }
|
|
287
|
+
: { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false }
|
|
288
|
+
if (language === 'en') options.timeZone = 'UTC'
|
|
289
|
+
return new Date(time).toLocaleString(language === 'en' ? 'en-US' : 'zh-CN', options)
|
|
290
|
+
}
|
|
291
|
+
function trendRowLabel(row, language, detailed) {
|
|
292
|
+
if (row && Number.isFinite(row.time)) return trendHourLabel(row.time, language, detailed)
|
|
293
|
+
if (!row || typeof row.date !== 'string') return ''
|
|
294
|
+
return detailed ? humanDate(row.date, language) : row.date.slice(5)
|
|
295
|
+
}
|
|
296
|
+
function trendRowKey(row, index) {
|
|
297
|
+
return row && Number.isFinite(row.time) ? String(row.time) : (row && typeof row.date === 'string' ? row.date : String(index))
|
|
298
|
+
}
|
|
299
|
+
function trendRowDate(row) {
|
|
300
|
+
return row && typeof row.date === 'string' ? row.date : ''
|
|
301
|
+
}
|
|
302
|
+
function buildTrendGeometry(rows, visible, width = 900, height = 250) {
|
|
303
|
+
const keys = Array.isArray(visible) && visible.length > 0 ? visible : ['total']
|
|
304
|
+
const padding = { left: 46, right: 14, top: 14, bottom: 30 }
|
|
305
|
+
const innerWidth = Math.max(1, width - padding.left - padding.right)
|
|
306
|
+
const innerHeight = Math.max(1, height - padding.top - padding.bottom)
|
|
307
|
+
const values = (Array.isArray(rows) ? rows : []).flatMap((row) => keys.map((key) => key === 'total' ? row.total : row.tokens[key] || 0))
|
|
308
|
+
const max = Math.max(1, ...values)
|
|
309
|
+
const points = {}
|
|
310
|
+
for (const key of keys) points[key] = (Array.isArray(rows) ? rows : []).map((row, index) => ({ x: padding.left + (rows.length > 1 ? index * innerWidth / (rows.length - 1) : innerWidth / 2), y: padding.top + innerHeight - ((key === 'total' ? row.total : row.tokens[key] || 0) / max) * innerHeight, value: key === 'total' ? row.total : row.tokens[key] || 0 }))
|
|
311
|
+
return { width, height, padding, max, points }
|
|
312
|
+
}
|
|
313
|
+
function modelParts(row, unknownProvider, unknownModel) {
|
|
314
|
+
const provider = typeof row.provider === 'string' && row.provider !== '' ? row.provider : unknownProvider
|
|
315
|
+
const model = typeof row.actualModel === 'string' && row.actualModel !== '' ? row.actualModel : (typeof row.requestedModel === 'string' && row.requestedModel !== '' ? row.requestedModel : (typeof row.model === 'string' && row.model !== '' ? row.model : unknownModel))
|
|
316
|
+
return { provider, model }
|
|
317
|
+
}
|
|
318
|
+
function modelOptionLabel(row, unknownProvider, unknownModel) {
|
|
319
|
+
const parts = modelParts(row, unknownProvider, unknownModel)
|
|
320
|
+
const base = parts.provider + ' / ' + parts.model
|
|
321
|
+
return row && row.requestedModel && row.actualModel && row.requestedModel !== row.actualModel ? base + ' ← ' + row.requestedModel : base
|
|
322
|
+
}
|
|
323
|
+
function aggregateModelRows(rows, view, unknownProvider, unknownModel) {
|
|
324
|
+
if (view === 'route') return rows.slice()
|
|
325
|
+
const grouped = new Map()
|
|
326
|
+
for (const row of rows) {
|
|
327
|
+
const parts = modelParts(row, unknownProvider, unknownModel)
|
|
328
|
+
const key = view === 'model' ? parts.model : parts.provider
|
|
329
|
+
let item = grouped.get(key)
|
|
330
|
+
if (item === undefined) { item = { model: key, provider: view === 'provider' ? key : parts.provider, calls: 0, input: 0, output: 0, cacheRead: 0, cacheWrite: 0, reasoning: 0 }; grouped.set(key, item) }
|
|
331
|
+
item.calls += row.calls; item.input += row.input; item.output += row.output; item.cacheRead += row.cacheRead; item.cacheWrite += row.cacheWrite; item.reasoning += row.reasoning
|
|
332
|
+
}
|
|
333
|
+
return Array.from(grouped.values())
|
|
334
|
+
}
|
|
335
|
+
function streaks(dayMap, utc) {
|
|
336
|
+
const today = new Date()
|
|
337
|
+
let streak = 0
|
|
338
|
+
for (let i = 0; i < 371; i++) {
|
|
339
|
+
const d = shiftCalendarDate(today, -i, utc)
|
|
340
|
+
const day = dayMap.get(fmtDate(d, utc))
|
|
341
|
+
const active = day !== undefined && day.turns > 0
|
|
342
|
+
if (active) streak += 1
|
|
343
|
+
else if (i > 0) break
|
|
344
|
+
}
|
|
345
|
+
let best = 0
|
|
346
|
+
let run = 0
|
|
347
|
+
for (let i = 0; i < 371; i++) {
|
|
348
|
+
const d = shiftCalendarDate(today, -i, utc)
|
|
349
|
+
const day = dayMap.get(fmtDate(d, utc))
|
|
350
|
+
if (day !== undefined && day.turns > 0) {
|
|
351
|
+
run += 1
|
|
352
|
+
if (run > best) best = run
|
|
353
|
+
} else {
|
|
354
|
+
run = 0
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return { streak, best }
|
|
358
|
+
}
|
|
359
|
+
// 数字滚动动画:首次从 0 滚动到目标值,之后直接同步目标值
|
|
360
|
+
function useCountUp(target, timer) {
|
|
361
|
+
const [state, setState] = React.useState({ value: 0, done: false })
|
|
362
|
+
React.useEffect(() => {
|
|
363
|
+
if (typeof target !== 'number' || !Number.isFinite(target) || target <= 0) {
|
|
364
|
+
setState({ value: 0, done: false })
|
|
365
|
+
return undefined
|
|
366
|
+
}
|
|
367
|
+
if (state.done) {
|
|
368
|
+
setState({ value: target, done: true })
|
|
369
|
+
return undefined
|
|
370
|
+
}
|
|
371
|
+
const start = Date.now()
|
|
372
|
+
const duration = 700
|
|
373
|
+
const stop = timer.interval(() => {
|
|
374
|
+
const t = Math.min(1, (Date.now() - start) / duration)
|
|
375
|
+
const eased = 1 - Math.pow(1 - t, 3)
|
|
376
|
+
if (t >= 1) {
|
|
377
|
+
stop()
|
|
378
|
+
setState({ value: target, done: true })
|
|
379
|
+
} else {
|
|
380
|
+
setState({ value: Math.round(target * eased), done: false })
|
|
381
|
+
}
|
|
382
|
+
}, 32)
|
|
383
|
+
return stop
|
|
384
|
+
}, [target])
|
|
385
|
+
return state.value
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function smoothTrendPath(points) {
|
|
389
|
+
if (!Array.isArray(points) || points.length === 0) return ''
|
|
390
|
+
if (points.length === 1) return 'M' + points[0].x.toFixed(2) + ' ' + points[0].y.toFixed(2)
|
|
391
|
+
const slopes = []
|
|
392
|
+
for (let i = 0; i < points.length - 1; i += 1) {
|
|
393
|
+
const dx = points[i + 1].x - points[i].x
|
|
394
|
+
slopes.push(dx === 0 ? 0 : (points[i + 1].y - points[i].y) / dx)
|
|
395
|
+
}
|
|
396
|
+
const tangents = new Array(points.length).fill(0)
|
|
397
|
+
tangents[0] = slopes[0]
|
|
398
|
+
tangents[points.length - 1] = slopes[slopes.length - 1]
|
|
399
|
+
for (let i = 1; i < points.length - 1; i += 1) {
|
|
400
|
+
const before = slopes[i - 1]
|
|
401
|
+
const after = slopes[i]
|
|
402
|
+
tangents[i] = before * after <= 0 ? 0 : (before + after) / 2
|
|
403
|
+
}
|
|
404
|
+
// Fritsch-Carlson limiting keeps the smooth curve monotone between points.
|
|
405
|
+
for (let i = 0; i < slopes.length; i += 1) {
|
|
406
|
+
if (slopes[i] === 0) { tangents[i] = 0; tangents[i + 1] = 0; continue }
|
|
407
|
+
const a = tangents[i] / slopes[i]
|
|
408
|
+
const b = tangents[i + 1] / slopes[i]
|
|
409
|
+
const magnitude = a * a + b * b
|
|
410
|
+
if (magnitude > 9) {
|
|
411
|
+
const scale = 3 / Math.sqrt(magnitude)
|
|
412
|
+
tangents[i] = scale * a * slopes[i]
|
|
413
|
+
tangents[i + 1] = scale * b * slopes[i]
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
let path = 'M' + points[0].x.toFixed(2) + ' ' + points[0].y.toFixed(2)
|
|
417
|
+
for (let i = 0; i < points.length - 1; i += 1) {
|
|
418
|
+
const dx = points[i + 1].x - points[i].x
|
|
419
|
+
const c1x = points[i].x + dx / 3
|
|
420
|
+
const c1y = points[i].y + tangents[i] * dx / 3
|
|
421
|
+
const c2x = points[i + 1].x - dx / 3
|
|
422
|
+
const c2y = points[i + 1].y - tangents[i + 1] * dx / 3
|
|
423
|
+
path += ' C' + c1x.toFixed(2) + ' ' + c1y.toFixed(2) + ' ' + c2x.toFixed(2) + ' ' + c2y.toFixed(2) + ' ' + points[i + 1].x.toFixed(2) + ' ' + points[i + 1].y.toFixed(2)
|
|
424
|
+
}
|
|
425
|
+
return path
|
|
426
|
+
}
|
|
427
|
+
function trendPathLength(points) {
|
|
428
|
+
if (!Array.isArray(points) || points.length < 2) return 1
|
|
429
|
+
let length = 0
|
|
430
|
+
for (let i = 1; i < points.length; i += 1) {
|
|
431
|
+
const dx = points[i].x - points[i - 1].x
|
|
432
|
+
const dy = points[i].y - points[i - 1].y
|
|
433
|
+
length += Math.sqrt(dx * dx + dy * dy)
|
|
434
|
+
}
|
|
435
|
+
return Math.max(1, Math.ceil(length * 1.35 + 2))
|
|
436
|
+
}
|
|
437
|
+
const DONUT_COLORS = ['#0a84ff', '#30d158', '#bf5af2', '#ff9f0a', '#ff375f', '#64d2ff']
|
|
438
|
+
function tokenMagnitude(value, language) {
|
|
439
|
+
const magnitude = chineseMagnitude(value, language)
|
|
440
|
+
return magnitude !== '' ? magnitude : fmtCompact(value)
|
|
441
|
+
}
|
|
442
|
+
function tokenDisplay(value, language) {
|
|
443
|
+
return tokenMagnitude(value, language) + (language === 'en' ? ' tokens' : ' Token')
|
|
444
|
+
}
|
|
445
|
+
function buildDonutSegments(items, otherLabel, limit = 5) {
|
|
446
|
+
const topLimit = Math.max(1, Number.isInteger(limit) ? limit : 5)
|
|
447
|
+
const normalized = (Array.isArray(items) ? items : []).map((item, index) => ({
|
|
448
|
+
label: item && item.label !== undefined ? String(item.label) : '',
|
|
449
|
+
value: Number(item && item.value),
|
|
450
|
+
color: item && typeof item.color === 'string' && item.color !== '' ? item.color : DONUT_COLORS[index % DONUT_COLORS.length],
|
|
451
|
+
})).filter((item) => item.label !== '' && Number.isFinite(item.value) && item.value > 0).sort((a, b) => b.value - a.value)
|
|
452
|
+
const total = normalized.reduce((sum, item) => sum + item.value, 0)
|
|
453
|
+
if (total <= 0) return { total: 0, segments: [] }
|
|
454
|
+
const segments = normalized.slice(0, topLimit)
|
|
455
|
+
const remainder = normalized.slice(topLimit).reduce((sum, item) => sum + item.value, 0)
|
|
456
|
+
if (remainder > 0) segments.push({ label: otherLabel + ' (' + (normalized.length - topLimit) + ')', value: remainder, color: '#b8c2cf', other: true })
|
|
457
|
+
let angle = -Math.PI / 2
|
|
458
|
+
return {
|
|
459
|
+
total,
|
|
460
|
+
segments: segments.map((item, index) => {
|
|
461
|
+
const sweep = item.value / total * Math.PI * 2
|
|
462
|
+
const gap = segments.length > 1 ? Math.min(.018, sweep / 3) : 0
|
|
463
|
+
const startAngle = angle + gap
|
|
464
|
+
const endAngle = angle + sweep - gap
|
|
465
|
+
angle += sweep
|
|
466
|
+
return { ...item, index, percentage: item.value / total * 100, startAngle: endAngle <= startAngle ? angle - sweep : startAngle, endAngle: endAngle <= startAngle ? angle : endAngle }
|
|
467
|
+
}),
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
function donutArcPath(cx, cy, outerRadius, innerRadius, startAngle, endAngle) {
|
|
471
|
+
const sweep = Math.max(0, endAngle - startAngle)
|
|
472
|
+
const point = (radius, angle) => ({ x: cx + radius * Math.cos(angle), y: cy + radius * Math.sin(angle) })
|
|
473
|
+
const outerStart = point(outerRadius, startAngle)
|
|
474
|
+
const innerStart = point(innerRadius, startAngle)
|
|
475
|
+
if (sweep >= Math.PI * 2 - .0001) {
|
|
476
|
+
const outerMid = point(outerRadius, startAngle + Math.PI)
|
|
477
|
+
const innerMid = point(innerRadius, startAngle + Math.PI)
|
|
478
|
+
return 'M' + outerStart.x.toFixed(2) + ' ' + outerStart.y.toFixed(2) + ' A' + outerRadius + ' ' + outerRadius + ' 0 1 1 ' + outerMid.x.toFixed(2) + ' ' + outerMid.y.toFixed(2) + ' A' + outerRadius + ' ' + outerRadius + ' 0 1 1 ' + outerStart.x.toFixed(2) + ' ' + outerStart.y.toFixed(2) + ' L' + innerStart.x.toFixed(2) + ' ' + innerStart.y.toFixed(2) + ' A' + innerRadius + ' ' + innerRadius + ' 0 1 0 ' + innerMid.x.toFixed(2) + ' ' + innerMid.y.toFixed(2) + ' A' + innerRadius + ' ' + innerRadius + ' 0 1 0 ' + innerStart.x.toFixed(2) + ' ' + innerStart.y.toFixed(2) + ' Z'
|
|
479
|
+
}
|
|
480
|
+
const outerEnd = point(outerRadius, endAngle)
|
|
481
|
+
const innerEnd = point(innerRadius, endAngle)
|
|
482
|
+
const largeArc = sweep > Math.PI ? 1 : 0
|
|
483
|
+
return 'M' + outerStart.x.toFixed(2) + ' ' + outerStart.y.toFixed(2) + ' A' + outerRadius + ' ' + outerRadius + ' 0 ' + largeArc + ' 1 ' + outerEnd.x.toFixed(2) + ' ' + outerEnd.y.toFixed(2) + ' L' + innerEnd.x.toFixed(2) + ' ' + innerEnd.y.toFixed(2) + ' A' + innerRadius + ' ' + innerRadius + ' 0 ' + largeArc + ' 0 ' + innerStart.x.toFixed(2) + ' ' + innerStart.y.toFixed(2) + ' Z'
|
|
484
|
+
}
|
|
485
|
+
function donutArcLinePath(cx, cy, radius, startAngle, endAngle) {
|
|
486
|
+
const sweep = Math.max(0, endAngle - startAngle)
|
|
487
|
+
const point = (angle) => ({ x: cx + radius * Math.cos(angle), y: cy + radius * Math.sin(angle) })
|
|
488
|
+
const start = point(startAngle)
|
|
489
|
+
if (sweep >= Math.PI * 2 - .0001) {
|
|
490
|
+
const mid = point(startAngle + Math.PI)
|
|
491
|
+
return 'M' + start.x.toFixed(2) + ' ' + start.y.toFixed(2) + ' A' + radius + ' ' + radius + ' 0 1 1 ' + mid.x.toFixed(2) + ' ' + mid.y.toFixed(2) + ' A' + radius + ' ' + radius + ' 0 1 1 ' + start.x.toFixed(2) + ' ' + start.y.toFixed(2)
|
|
492
|
+
}
|
|
493
|
+
const end = point(endAngle)
|
|
494
|
+
return 'M' + start.x.toFixed(2) + ' ' + start.y.toFixed(2) + ' A' + radius + ' ' + radius + ' 0 ' + (sweep > Math.PI ? 1 : 0) + ' 1 ' + end.x.toFixed(2) + ' ' + end.y.toFixed(2)
|
|
495
|
+
}
|
|
496
|
+
function UsageDonutChart(props) {
|
|
497
|
+
const language = props.language === 'en' ? 'en' : 'zh'
|
|
498
|
+
const tr = (zh, en) => language === 'en' ? en : zh
|
|
499
|
+
const [activeIndex, setActiveIndex] = React.useState(null)
|
|
500
|
+
const [tooltipPosition, setTooltipPosition] = React.useState(null)
|
|
501
|
+
const data = buildDonutSegments(props.items, tr('其他', 'Other'))
|
|
502
|
+
const activeSegment = activeIndex === null ? null : (data.segments[activeIndex] || null)
|
|
503
|
+
if (data.total <= 0) return null
|
|
504
|
+
const cx = 130
|
|
505
|
+
const cy = 130
|
|
506
|
+
const outerRadius = 94
|
|
507
|
+
const innerRadius = 61
|
|
508
|
+
const percentText = (value) => (value >= 10 ? Math.round(value) : Math.round(value * 10) / 10) + '%'
|
|
509
|
+
const updatePointer = (event) => {
|
|
510
|
+
const visual = event.currentTarget.ownerSVGElement?.parentElement
|
|
511
|
+
const box = visual?.getBoundingClientRect()
|
|
512
|
+
if (!box) return
|
|
513
|
+
const tooltipWidth = 198
|
|
514
|
+
const tooltipHeight = 58
|
|
515
|
+
setTooltipPosition({ left: Math.max(8, Math.min(Math.max(8, box.width - tooltipWidth), event.clientX - box.left + 14)), top: Math.max(8, Math.min(Math.max(8, box.height - tooltipHeight), event.clientY - box.top + 14)) })
|
|
516
|
+
}
|
|
517
|
+
const clearPointer = () => { setActiveIndex(null); setTooltipPosition(null) }
|
|
518
|
+
return React.createElement('div', { className: 'uh-donut-chart', 'aria-label': props.title },
|
|
519
|
+
React.createElement('div', { className: 'uh-donut-title' }, React.createElement(LineIcon, { name: props.icon || 'chart', size: 16 }), props.title),
|
|
520
|
+
React.createElement('div', { className: 'uh-donut-layout' },
|
|
521
|
+
React.createElement('div', { className: 'uh-donut-visual' },
|
|
522
|
+
React.createElement('svg', { className: 'uh-donut-svg', viewBox: '0 0 260 260', role: 'img', 'aria-label': props.title + ' ' + tokenDisplay(data.total, language) },
|
|
523
|
+
React.createElement('circle', { cx, cy, r: (outerRadius + innerRadius) / 2, className: 'uh-donut-track', fill: 'none', stroke: 'var(--dsw-alias-bg-layer-2)', strokeWidth: outerRadius - innerRadius }),
|
|
524
|
+
data.segments.map((segment) => React.createElement('path', { key: 'donut-' + segment.index, d: donutArcLinePath(cx, cy, (outerRadius + innerRadius) / 2, segment.startAngle, segment.endAngle), className: 'uh-donut-segment' + (activeIndex === segment.index ? ' uh-active' : ''), fill: 'none', stroke: segment.color, strokeWidth: outerRadius - innerRadius, strokeLinecap: 'butt', strokeLinejoin: 'round', pathLength: 1, style: { animationDelay: (segment.index * 90) + 'ms' }, tabIndex: 0, 'aria-label': segment.label + ' ' + tokenDisplay(segment.value, language) + ' ' + percentText(segment.percentage), onMouseEnter: (event) => { setActiveIndex(segment.index); updatePointer(event) }, onMouseMove: updatePointer, onMouseLeave: clearPointer, onFocus: () => { setActiveIndex(segment.index); setTooltipPosition({ left: 12, top: 12 }) }, onBlur: clearPointer })),
|
|
525
|
+
),
|
|
526
|
+
activeSegment ? React.createElement('div', { className: 'uh-donut-tooltip', style: tooltipPosition ? { left: tooltipPosition.left, top: tooltipPosition.top } : undefined },
|
|
527
|
+
React.createElement('span', { className: 'uh-donut-dot', style: { background: activeSegment.color } }),
|
|
528
|
+
React.createElement('div', {},
|
|
529
|
+
React.createElement('strong', {}, activeSegment.label),
|
|
530
|
+
React.createElement('span', {}, tokenDisplay(activeSegment.value, language) + ' · ' + percentText(activeSegment.percentage)),
|
|
531
|
+
),
|
|
532
|
+
) : null,
|
|
533
|
+
React.createElement('div', { className: 'uh-donut-center' },
|
|
534
|
+
React.createElement('strong', {}, tokenMagnitude(data.total, language)),
|
|
535
|
+
React.createElement('span', {}, language === 'en' ? 'tokens' : 'Token'),
|
|
536
|
+
),
|
|
537
|
+
),
|
|
538
|
+
React.createElement('div', { className: 'uh-donut-legend', role: 'list' },
|
|
539
|
+
data.segments.map((segment) => React.createElement('div', { key: 'legend-' + segment.index, className: 'uh-donut-legend-row', role: 'listitem' },
|
|
540
|
+
React.createElement('span', { className: 'uh-donut-dot', style: { background: segment.color } }),
|
|
541
|
+
React.createElement('div', { className: 'uh-donut-legend-copy' },
|
|
542
|
+
React.createElement('strong', { title: segment.label }, segment.label),
|
|
543
|
+
React.createElement('span', {}, tokenDisplay(segment.value, language)),
|
|
544
|
+
),
|
|
545
|
+
React.createElement('strong', { className: 'uh-donut-percent' }, percentText(segment.percentage)),
|
|
546
|
+
)),
|
|
547
|
+
),
|
|
548
|
+
),
|
|
549
|
+
)
|
|
550
|
+
}
|
|
551
|
+
function trendSeriesLabel(key, language) {
|
|
552
|
+
const labels = {
|
|
553
|
+
total: language === 'en' ? 'Total' : '总处理',
|
|
554
|
+
input: language === 'en' ? 'Input' : '输入',
|
|
555
|
+
cacheRead: language === 'en' ? 'Cache hits' : '缓存命中',
|
|
556
|
+
cacheWrite: language === 'en' ? 'Cache writes' : '缓存写入',
|
|
557
|
+
output: language === 'en' ? 'Output' : '输出',
|
|
558
|
+
reasoning: language === 'en' ? 'Reasoning' : '推理',
|
|
559
|
+
}
|
|
560
|
+
return labels[key] || key
|
|
561
|
+
}
|
|
562
|
+
function trendSeriesValue(row, key) {
|
|
563
|
+
return key === 'total' ? row.total : (row.tokens && Number.isFinite(row.tokens[key]) ? row.tokens[key] : 0)
|
|
564
|
+
}
|
|
565
|
+
function UsageTrendChart(props) {
|
|
566
|
+
const language = props.language === 'en' ? 'en' : 'zh'
|
|
567
|
+
const tr = (zh, en) => language === 'en' ? en : zh
|
|
568
|
+
const rows = Array.isArray(props.rows) ? props.rows : []
|
|
569
|
+
const visible = Array.isArray(props.visible) && props.visible.length > 0 ? props.visible : ['total']
|
|
570
|
+
const [hoverIndex, setHoverIndex] = React.useState(null)
|
|
571
|
+
const [tooltipIndex, setTooltipIndex] = React.useState(null)
|
|
572
|
+
const width = 900
|
|
573
|
+
const height = 280
|
|
574
|
+
const geometry = buildTrendGeometry(rows, visible, width, height)
|
|
575
|
+
const colors = { total: '#f4c542', input: '#5aa9ff', cacheRead: '#44d483', cacheWrite: '#d98bff', output: '#ff8c66', reasoning: '#aab4c4' }
|
|
576
|
+
const pathFor = (points) => smoothTrendPath(points)
|
|
577
|
+
const bottomY = height - geometry.padding.bottom
|
|
578
|
+
const areaPathFor = (points) => {
|
|
579
|
+
if (!Array.isArray(points) || points.length === 0) return ''
|
|
580
|
+
return pathFor(points) + ' L' + points[points.length - 1].x.toFixed(2) + ' ' + bottomY + ' L' + points[0].x.toFixed(2) + ' ' + bottomY + ' Z'
|
|
581
|
+
}
|
|
582
|
+
const gradientOpacity = { total: .20, input: .16, cacheRead: .18, cacheWrite: .14, output: .16, reasoning: .10 }
|
|
583
|
+
const tickIndexes = rows.length <= 1 ? [0] : Array.from(new Set([0, Math.floor((rows.length - 1) / 4), Math.floor((rows.length - 1) / 2), Math.floor((rows.length - 1) * 3 / 4), rows.length - 1]))
|
|
584
|
+
const chartReady = !props.loading && !props.error && rows.length > 0
|
|
585
|
+
const hourly = rows.length > 0 && Number.isFinite(rows[0].time)
|
|
586
|
+
const chartAriaLabel = hourly ? tr('每小时 Token 使用趋势,选择小时查看当天请求日志', 'Hourly Token usage trend; select an hour to view request logs') : tr('每日 Token 使用趋势,选择日期查看请求日志', 'Daily Token usage trend; select a date to view request logs')
|
|
587
|
+
const hovered = hoverIndex === null ? null : (rows[hoverIndex] || null)
|
|
588
|
+
const hoverPoint = hoverIndex === null ? null : ((geometry.points[visible[0]] || [])[hoverIndex] || null)
|
|
589
|
+
const tooltipRow = tooltipIndex === null ? null : (rows[tooltipIndex] || null)
|
|
590
|
+
const tooltipPoint = tooltipIndex === null ? null : ((geometry.points[visible[0]] || [])[tooltipIndex] || null)
|
|
591
|
+
const tooltipVisible = hoverIndex !== null && tooltipRow !== null && tooltipPoint !== null
|
|
592
|
+
const tooltipSide = tooltipPoint !== null && tooltipPoint.x > width * .68 ? ' uh-left' : ' uh-right'
|
|
593
|
+
const tooltipStyle = tooltipPoint === null ? undefined : { left: (tooltipPoint.x / width * 100).toFixed(2) + '%', top: Math.max(23, Math.min(77, tooltipPoint.y / height * 100)).toFixed(2) + '%' }
|
|
594
|
+
const activateHover = (index) => { setHoverIndex(index); setTooltipIndex(index) }
|
|
595
|
+
const toggle = (key) => {
|
|
596
|
+
if (typeof props.onToggle === 'function') props.onToggle(key)
|
|
597
|
+
}
|
|
598
|
+
const chartBody = props.loading
|
|
599
|
+
? React.createElement('div', { className: 'uh-trend-stage uh-trend-loading', role: 'status', 'aria-label': tr('正在加载趋势', 'Loading trend') }, React.createElement('span', { className: 'uh-trend-spinner', 'aria-hidden': true }))
|
|
600
|
+
: props.error
|
|
601
|
+
? React.createElement('div', { className: 'uh-trend-stage uh-trend-message', role: 'alert' }, props.error)
|
|
602
|
+
: rows.length === 0
|
|
603
|
+
? React.createElement('div', { className: 'uh-trend-stage uh-trend-message' }, tr('该范围内暂无趋势数据', 'No trend data in this range'))
|
|
604
|
+
: React.createElement('div', { className: 'uh-trend-chart-wrap' },
|
|
605
|
+
React.createElement('svg', { className: 'uh-trend-svg', viewBox: '0 0 ' + width + ' ' + height, role: 'group', 'aria-label': chartAriaLabel },
|
|
606
|
+
[0, 0.5, 1].map((ratio) => React.createElement(React.Fragment, { key: ratio },
|
|
607
|
+
React.createElement('line', { x1: geometry.padding.left, x2: width - geometry.padding.right, y1: geometry.padding.top + (height - geometry.padding.top - geometry.padding.bottom) * ratio, y2: geometry.padding.top + (height - geometry.padding.top - geometry.padding.bottom) * ratio, className: 'uh-trend-grid' }),
|
|
608
|
+
React.createElement('text', { x: geometry.padding.left - 7, y: geometry.padding.top + (height - geometry.padding.top - geometry.padding.bottom) * ratio + 4, className: 'uh-trend-axis-label', textAnchor: 'end' }, fmtCompact(Math.round(geometry.max * (1 - ratio)))),
|
|
609
|
+
)),
|
|
610
|
+
React.createElement('defs', {},
|
|
611
|
+
visible.map((key) => React.createElement('linearGradient', { key: key, id: 'uh-trend-gradient-' + key, x1: '0', y1: '0', x2: '0', y2: '1' },
|
|
612
|
+
React.createElement('stop', { offset: '4%', stopColor: colors[key] || '#9aa4b2', stopOpacity: gradientOpacity[key] || .12 }),
|
|
613
|
+
React.createElement('stop', { offset: '96%', stopColor: colors[key] || '#9aa4b2', stopOpacity: 0 }),
|
|
614
|
+
)),
|
|
615
|
+
),
|
|
616
|
+
visible.map((key, seriesIndex) => {
|
|
617
|
+
const areaPath = areaPathFor(geometry.points[key] || [])
|
|
618
|
+
return areaPath === '' ? null : React.createElement('path', { key: 'area-' + key, d: areaPath, className: 'uh-trend-area', 'data-series': key, fill: 'url(#uh-trend-gradient-' + key + ')', style: { animationDelay: (80 + seriesIndex * 80) + 'ms' } })
|
|
619
|
+
}),
|
|
620
|
+
visible.map((key) => React.createElement('path', { key: 'line-base-' + key, d: pathFor(geometry.points[key] || []), className: 'uh-trend-line', 'data-series': key, stroke: colors[key] || '#9aa4b2' })),
|
|
621
|
+
visible.map((key, seriesIndex) => {
|
|
622
|
+
const points = geometry.points[key] || []
|
|
623
|
+
const drawLength = trendPathLength(points)
|
|
624
|
+
return React.createElement('path', { key: 'line-draw-' + key, d: pathFor(points), className: 'uh-trend-line-draw', 'data-series': key, stroke: colors[key] || '#9aa4b2', style: { '--uh-draw-length': drawLength + 'px', animationDelay: (seriesIndex * 90) + 'ms' } })
|
|
625
|
+
}),
|
|
626
|
+
visible.map((key) => {
|
|
627
|
+
const points = geometry.points[key] || []
|
|
628
|
+
if (points.length !== 1) return null
|
|
629
|
+
const point = points[0]
|
|
630
|
+
return React.createElement('circle', { key: 'single-point-' + key, cx: point.x, cy: point.y, r: 4, className: 'uh-trend-point', fill: colors[key] || '#9aa4b2' })
|
|
631
|
+
}),
|
|
632
|
+
hoverIndex !== null && hoverPoint ? React.createElement(React.Fragment, { key: 'hover-' + hoverIndex },
|
|
633
|
+
React.createElement('line', { x1: hoverPoint.x, x2: hoverPoint.x, y1: geometry.padding.top, y2: bottomY, className: 'uh-trend-cursor' }),
|
|
634
|
+
visible.map((key) => { const point = (geometry.points[key] || [])[hoverIndex]; return point ? React.createElement('circle', { key: key, cx: point.x, cy: point.y, r: 4, className: 'uh-trend-point', fill: colors[key] || '#9aa4b2' }) : null }),
|
|
635
|
+
) : null,
|
|
636
|
+
rows.map((row, index) => {
|
|
637
|
+
const point = (geometry.points[visible[0]] || [])[index]
|
|
638
|
+
if (!point) return null
|
|
639
|
+
const next = (geometry.points[visible[0]] || [])[index + 1]
|
|
640
|
+
const cellWidth = next ? Math.max(8, next.x - point.x) : (index > 0 ? Math.max(8, point.x - (geometry.points[visible[0]] || [])[index - 1].x) : 24)
|
|
641
|
+
return React.createElement('rect', { key: trendRowKey(row, index), x: Math.max(geometry.padding.left, point.x - cellWidth / 2), y: geometry.padding.top, width: cellWidth, height: height - geometry.padding.top - geometry.padding.bottom, className: 'uh-trend-hit', tabIndex: 0, role: 'button', 'aria-label': trendRowLabel(row, language, true) + ' ' + trendSeriesLabel('total', language) + ' ' + fmtCompact(row.total), onMouseEnter: () => activateHover(index), onMouseLeave: () => setHoverIndex(null), onFocus: () => activateHover(index), onBlur: () => setHoverIndex(null), onKeyDown: (event) => { if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); if (typeof props.onPointClick === 'function') props.onPointClick(trendRowDate(row)) } }, onClick: () => { if (typeof props.onPointClick === 'function') props.onPointClick(trendRowDate(row)) } })
|
|
642
|
+
}),
|
|
643
|
+
tickIndexes.map((index) => {
|
|
644
|
+
const point = (geometry.points[visible[0]] || [])[index]
|
|
645
|
+
const row = rows[index]
|
|
646
|
+
return point && row ? React.createElement('text', { key: trendRowKey(row, index), x: point.x, y: height - 8, className: 'uh-trend-axis-label', textAnchor: index === 0 ? 'start' : index === rows.length - 1 ? 'end' : 'middle' }, trendRowLabel(row, language, false)) : null
|
|
647
|
+
}),
|
|
648
|
+
),
|
|
649
|
+
tooltipRow && tooltipPoint ? React.createElement('div', { className: 'uh-trend-tooltip' + tooltipSide + (tooltipVisible ? ' uh-visible' : ''), style: tooltipStyle, 'aria-hidden': !tooltipVisible },
|
|
650
|
+
React.createElement('strong', { className: 'uh-trend-tooltip-title' }, trendRowLabel(tooltipRow, language, true)),
|
|
651
|
+
visible.map((key) => React.createElement('div', { key, className: 'uh-trend-tooltip-row', style: { color: colors[key] || '#9aa4b2' } },
|
|
652
|
+
React.createElement('span', { className: 'uh-trend-dot', style: { background: colors[key] || '#9aa4b2' } }),
|
|
653
|
+
React.createElement('span', { className: 'uh-trend-tooltip-label' }, trendSeriesLabel(key, language)),
|
|
654
|
+
React.createElement('strong', { className: 'uh-trend-tooltip-value' }, fmtCompact(trendSeriesValue(tooltipRow, key))),
|
|
655
|
+
)),
|
|
656
|
+
) : null,
|
|
657
|
+
)
|
|
658
|
+
return React.createElement('div', { className: 'uh-panel uh-trend-panel' },
|
|
659
|
+
React.createElement('div', { className: 'uh-trend-head' },
|
|
660
|
+
React.createElement('div', {}, React.createElement('h3', { className: 'uh-tbl-title uh-title-with-icon' }, React.createElement(LineIcon, { name: 'chart', size: 16 }), tr('Token 使用趋势', 'Token Usage Trend')), React.createElement('div', { className: 'uh-note' }, props.rangeLabel || '')),
|
|
661
|
+
chartReady ? React.createElement('div', { className: 'uh-note' }, tr('点击数据点查看当日明细', 'Click a point to inspect that day')) : null,
|
|
662
|
+
),
|
|
663
|
+
chartBody,
|
|
664
|
+
chartReady ? React.createElement('div', { className: 'uh-trend-legend' },
|
|
665
|
+
['total', 'input', 'cacheRead', 'cacheWrite', 'output', 'reasoning'].map((key) => React.createElement('button', { key, type: 'button', className: 'uh-trend-legend-item' + (visible.includes(key) ? ' uh-on' : ''), onClick: () => toggle(key), 'aria-pressed': visible.includes(key) }, React.createElement('span', { className: 'uh-trend-dot', style: { background: colors[key] || '#9aa4b2' } }), trendSeriesLabel(key, language))),
|
|
666
|
+
) : null,
|
|
667
|
+
)
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
function UsageFilterMenu(props) {
|
|
671
|
+
const options = Array.isArray(props.options) ? props.options : []
|
|
672
|
+
const value = props.value === undefined || props.value === null ? '' : String(props.value)
|
|
673
|
+
const selected = options.find((option) => String(option.value) === value)
|
|
674
|
+
const [open, setOpen] = React.useState(false)
|
|
675
|
+
const menuRef = React.useRef(null)
|
|
676
|
+
React.useEffect(() => {
|
|
677
|
+
if (!open || typeof document === 'undefined') return undefined
|
|
678
|
+
const closeMenu = (event) => {
|
|
679
|
+
if (menuRef.current && !menuRef.current.contains(event.target)) setOpen(false)
|
|
680
|
+
}
|
|
681
|
+
document.addEventListener('pointerdown', closeMenu)
|
|
682
|
+
return () => document.removeEventListener('pointerdown', closeMenu)
|
|
683
|
+
}, [open])
|
|
684
|
+
const choose = (next) => {
|
|
685
|
+
if (typeof props.onChange === 'function') props.onChange(next)
|
|
686
|
+
setOpen(false)
|
|
687
|
+
}
|
|
688
|
+
return React.createElement('div', { className: 'uh-language-menu uh-filter-menu' + (props.className ? ' ' + props.className : '') + (open ? ' uh-open' : ''), ref: menuRef, onKeyDown: (event) => { if (event.key === 'Escape' && open) { event.preventDefault(); event.stopPropagation(); setOpen(false) } } },
|
|
689
|
+
React.createElement('button', {
|
|
690
|
+
type: 'button',
|
|
691
|
+
className: 'uh-language-trigger uh-filter-trigger' + (open ? ' uh-open' : ''),
|
|
692
|
+
title: selected ? selected.label : props.label,
|
|
693
|
+
'aria-label': props.ariaLabel || props.label,
|
|
694
|
+
'aria-haspopup': 'listbox',
|
|
695
|
+
'aria-expanded': open,
|
|
696
|
+
onClick: () => setOpen((current) => !current),
|
|
697
|
+
},
|
|
698
|
+
React.createElement(LineIcon, { name: props.icon || 'chart', size: 14 }),
|
|
699
|
+
React.createElement('span', { className: 'uh-filter-label' }, selected ? selected.label : props.label),
|
|
700
|
+
React.createElement(LineIcon, { name: 'chevron', size: 13, className: 'uh-language-caret' }),
|
|
701
|
+
),
|
|
702
|
+
open ? React.createElement('div', { className: 'uh-language-options uh-filter-options', role: 'listbox', 'aria-label': props.ariaLabel || props.label },
|
|
703
|
+
options.map((option) => {
|
|
704
|
+
const optionValue = String(option.value)
|
|
705
|
+
const active = optionValue === value
|
|
706
|
+
return React.createElement('button', {
|
|
707
|
+
key: optionValue,
|
|
708
|
+
type: 'button',
|
|
709
|
+
role: 'option',
|
|
710
|
+
'aria-selected': active,
|
|
711
|
+
className: 'uh-language-option' + (active ? ' uh-on' : ''),
|
|
712
|
+
onClick: () => choose(optionValue),
|
|
713
|
+
},
|
|
714
|
+
React.createElement(LineIcon, { name: props.icon || 'chart', size: 14 }),
|
|
715
|
+
React.createElement('span', { className: 'uh-filter-option-label' }, option.label),
|
|
716
|
+
active ? React.createElement(LineIcon, { name: 'check', size: 14, className: 'uh-language-option-check' }) : null,
|
|
717
|
+
)
|
|
718
|
+
}),
|
|
719
|
+
) : null,
|
|
720
|
+
)
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
const CSS = `
|
|
724
|
+
.uh-page { display:flex; flex-direction:column; gap:14px; padding:2px 2px 28px; font-family:inherit; }
|
|
725
|
+
.uh-head { position:relative; z-index:20; display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap:wrap; }
|
|
726
|
+
.uh-title { margin:0; font-size:15px; font-weight:600; color:var(--dsw-alias-label-primary); }
|
|
727
|
+
.uh-actions { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
|
|
728
|
+
.uh-language-menu, .uh-filter-menu { position:relative; z-index:12; }
|
|
729
|
+
.uh-filter-menu { flex:0 1 auto; min-width:0; }
|
|
730
|
+
.uh-filter-workspace { width:180px; }
|
|
731
|
+
.uh-filter-provider { width:180px; }
|
|
732
|
+
.uh-filter-model { width:260px; }
|
|
733
|
+
.uh-filter-menu.uh-open { z-index:14; }
|
|
734
|
+
.uh-language-trigger { display:inline-flex; align-items:center; gap:6px; min-height:30px; padding:4px 9px 4px 10px; border:1px solid transparent; border-radius:15px; background:color-mix(in srgb, var(--dsw-alias-label-primary) 7%, var(--dsw-alias-bg-layer-1)); color:var(--dsw-alias-label-primary); font:inherit; font-size:12px; font-weight:600; line-height:1; cursor:pointer; transition:border-color .15s ease, background-color .15s ease, transform .1s ease; }
|
|
735
|
+
.uh-filter-trigger { width:100%; min-width:0; justify-content:flex-start; }
|
|
736
|
+
.uh-language-trigger:hover, .uh-language-trigger.uh-open { border-color:color-mix(in srgb, var(--dsw-alias-brand-primary) 58%, var(--dsw-alias-border-l2)); background:color-mix(in srgb, var(--dsw-alias-brand-primary) 13%, var(--dsw-alias-bg-layer-1)); }
|
|
737
|
+
.uh-language-trigger:active { transform:scale(.96); }
|
|
738
|
+
.uh-language-label { min-width:26px; text-align:left; }
|
|
739
|
+
.uh-filter-label { min-width:0; flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; text-align:left; }
|
|
740
|
+
.uh-language-caret { color:var(--dsw-alias-label-secondary); transition:transform .18s ease; }
|
|
741
|
+
.uh-language-trigger.uh-open .uh-language-caret { transform:rotate(180deg); }
|
|
742
|
+
.uh-language-menu.uh-open { z-index:30; }
|
|
743
|
+
.uh-language-options { position:absolute; top:calc(100% + 7px); right:0; min-width:142px; padding:5px; border:1px solid var(--dsw-alias-border-l2); border-radius:12px; background:var(--dsw-alias-bg-layer-1); box-shadow:0 14px 28px color-mix(in srgb, #000 24%, transparent); animation:uh-menu-in .16s ease both; }
|
|
744
|
+
.uh-filter-options { left:0; right:auto; min-width:100%; max-width:300px; }
|
|
745
|
+
.uh-language-option { display:flex; align-items:center; gap:8px; width:100%; min-height:32px; padding:6px 8px; border:0; border-radius:8px; background:transparent; color:var(--dsw-alias-label-primary); font:inherit; font-size:12px; text-align:left; cursor:pointer; transition:background-color .14s ease, color .14s ease; }
|
|
746
|
+
.uh-filter-option-label { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
|
747
|
+
.uh-language-option:hover, .uh-language-option:focus-visible { background:color-mix(in srgb, var(--dsw-alias-brand-primary) 14%, var(--dsw-alias-bg-layer-2)); outline:0; }
|
|
748
|
+
.uh-language-option.uh-on { background:color-mix(in srgb, var(--dsw-alias-brand-primary) 19%, var(--dsw-alias-bg-layer-2)); color:var(--dsw-alias-label-primary); font-weight:600; }
|
|
749
|
+
.uh-language-option-check { margin-left:auto; color:var(--dsw-alias-brand-primary); }
|
|
750
|
+
.uh-range { display:inline-flex; border:1px solid var(--dsw-alias-border-l2); border-radius:8px; overflow:hidden; }
|
|
751
|
+
.uh-range button { border:0; background:transparent; color:var(--dsw-alias-label-secondary); padding:4px 12px; font-size:12px; cursor:pointer; font-family:inherit; transition:background-color .15s ease, color .15s ease; }
|
|
752
|
+
.uh-range button + button { border-left:1px solid var(--dsw-alias-border-l2); }
|
|
753
|
+
.uh-range button.uh-on { background:color-mix(in srgb, var(--dsw-alias-brand-primary) 20%, var(--dsw-alias-bg-layer-2)); color:var(--dsw-alias-label-primary); font-weight:600; }
|
|
754
|
+
.uh-custom-range { display:grid; grid-template-columns:minmax(180px, 1fr) auto auto; gap:10px 14px; align-items:end; padding:12px; border:1px solid var(--dsw-alias-border-l1); border-radius:10px; background:var(--dsw-alias-bg-layer-1); }
|
|
755
|
+
.uh-custom-range-meta { min-width:0; }
|
|
756
|
+
.uh-custom-range-title { display:flex; align-items:center; gap:7px; color:var(--dsw-alias-label-primary); font-size:13px; font-weight:600; }
|
|
757
|
+
.uh-custom-range-note { margin-top:3px; color:var(--dsw-alias-label-secondary); font-size:11px; line-height:1.45; }
|
|
758
|
+
.uh-custom-range-fields { display:grid; grid-template-columns:repeat(2, minmax(136px, 1fr)); gap:8px; }
|
|
759
|
+
.uh-custom-range-field { display:flex; flex-direction:column; gap:4px; color:var(--dsw-alias-label-secondary); font-size:11px; }
|
|
760
|
+
.uh-custom-range-field input { min-width:0; min-height:30px; border:1px solid var(--dsw-alias-border-l2); border-radius:6px; padding:3px 7px; background:var(--dsw-alias-bg-base); color:var(--dsw-alias-label-primary); font:inherit; font-size:12px; outline:none; }
|
|
761
|
+
.uh-custom-range-field input:focus { border-color:var(--dsw-alias-brand-primary); }
|
|
762
|
+
.uh-custom-range-actions { display:flex; gap:6px; }
|
|
763
|
+
.uh-custom-range-cancel, .uh-custom-range-apply { min-height:30px; border-radius:6px; padding:4px 10px; font:inherit; font-size:12px; cursor:pointer; }
|
|
764
|
+
.uh-custom-range-cancel { border:1px solid var(--dsw-alias-border-l2); background:transparent; color:var(--dsw-alias-label-primary); }
|
|
765
|
+
.uh-custom-range-apply { border:1px solid var(--dsw-alias-brand-primary); background:color-mix(in srgb, var(--dsw-alias-brand-primary) 16%, transparent); color:var(--dsw-alias-label-primary); }
|
|
766
|
+
.uh-custom-range-apply:disabled { opacity:.48; cursor:not-allowed; }
|
|
767
|
+
.uh-custom-range-error { grid-column:1 / -1; color:#d92d20; font-size:12px; }
|
|
768
|
+
.uh-refresh { border:1px solid var(--dsw-alias-border-l2); background:var(--dsw-alias-bg-layer-1); color:var(--dsw-alias-label-primary); border-radius:8px; padding:4px 12px; font-size:12px; cursor:pointer; font-family:inherit; transition:border-color .15s ease, color .15s ease, transform .1s ease; }
|
|
769
|
+
.uh-refresh:hover { border-color:var(--dsw-alias-brand-primary); }
|
|
770
|
+
.uh-refresh:active, .uh-chip:active, .uh-range button:active { transform:scale(.96); }
|
|
771
|
+
.uh-alias-panel-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:10px; font-size:13px; font-weight:600; color:var(--dsw-alias-label-primary); }
|
|
772
|
+
.uh-alias-close { border:0; background:transparent; color:var(--dsw-alias-label-secondary); font-size:12px; cursor:pointer; font-family:inherit; padding:0; transition:color .15s ease; }
|
|
773
|
+
.uh-alias-close:hover { color:var(--dsw-alias-brand-primary); }
|
|
774
|
+
.uh-alias-list { display:grid; grid-template-columns:repeat(auto-fill, minmax(250px, 1fr)); gap:8px 16px; max-height:240px; overflow-y:auto; }
|
|
775
|
+
.uh-alias-item { display:flex; align-items:center; gap:8px; min-width:0; }
|
|
776
|
+
.uh-alias-folder { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:11px; color:var(--dsw-alias-label-secondary); }
|
|
777
|
+
.uh-alias-input { flex:none; width:150px; border:1px solid var(--dsw-alias-border-l2); background:var(--dsw-alias-bg-base); color:var(--dsw-alias-label-primary); border-radius:6px; padding:3px 8px; font-size:12px; font-family:inherit; outline:none; transition:border-color .15s ease; }
|
|
778
|
+
.uh-alias-input:focus { border-color:var(--dsw-alias-brand-primary); }
|
|
779
|
+
.uh-alias-panel-foot { display:flex; align-items:center; justify-content:space-between; gap:8px; margin-top:10px; padding-top:10px; border-top:1px solid var(--dsw-alias-border-l1); }
|
|
780
|
+
.uh-alias-ok { border:1px solid var(--dsw-alias-brand-primary); background:color-mix(in srgb, var(--dsw-alias-brand-primary) 16%, transparent); color:var(--dsw-alias-label-primary); border-radius:6px; font-size:12px; padding:3px 12px; cursor:pointer; font-family:inherit; flex:none; transition:transform .1s ease; }
|
|
781
|
+
.uh-alias-ok:active { transform:scale(.96); }
|
|
782
|
+
.uh-anim-panel { animation:uh-panel-in .28s ease both; }
|
|
783
|
+
.uh-progress { font-size:12px; color:var(--dsw-alias-label-secondary); display:flex; align-items:center; gap:10px; }
|
|
784
|
+
.uh-sync-health { margin-top:8px; padding:8px 12px; display:flex; align-items:center; flex-wrap:wrap; gap:6px; border:1px solid var(--dsw-alias-border-l1); border-radius:10px; color:var(--dsw-alias-label-secondary); background:var(--dsw-alias-bg-layer-1); font-size:11px; line-height:1.45; }
|
|
785
|
+
.uh-sync-health.uh-stale { color:var(--dsw-alias-warning, #a55b00); border-color:color-mix(in srgb, var(--dsw-alias-warning, #d9822b) 45%, var(--dsw-alias-border-l1)); }
|
|
786
|
+
.uh-sync-retry { border:0; background:transparent; color:inherit; font:inherit; text-decoration:underline; cursor:pointer; padding:0 2px; }
|
|
787
|
+
.uh-trend-panel { min-height:300px; animation:uh-panel-in .38s ease both; }
|
|
788
|
+
.uh-trend-head { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; margin-bottom:10px; }
|
|
789
|
+
.uh-trend-chart-wrap { position:relative; min-height:250px; width:100%; overflow:hidden; }
|
|
790
|
+
.uh-trend-stage { display:grid; place-items:center; min-height:250px; width:100%; }
|
|
791
|
+
.uh-trend-message { color:var(--dsw-alias-label-secondary); font-size:12px; }
|
|
792
|
+
.uh-trend-spinner { width:24px; height:24px; border:2px solid color-mix(in srgb, var(--dsw-alias-brand-primary) 22%, var(--dsw-alias-border-l2)); border-top-color:var(--dsw-alias-brand-primary); border-radius:50%; animation:uh-spinner-turn .78s linear infinite; }
|
|
793
|
+
.uh-trend-svg { display:block; width:100%; height:auto; min-height:220px; }
|
|
794
|
+
.uh-trend-grid { stroke:var(--dsw-alias-border-l1); stroke-width:1; stroke-dasharray:3 4; opacity:.8; }
|
|
795
|
+
.uh-trend-cursor { stroke:var(--dsw-alias-label-secondary); stroke-width:1; stroke-dasharray:3 4; opacity:.65; pointer-events:none; }
|
|
796
|
+
.uh-trend-point { stroke:var(--dsw-alias-bg-layer-1); stroke-width:2; vector-effect:non-scaling-stroke; pointer-events:none; }
|
|
797
|
+
.uh-trend-axis-label { fill:var(--dsw-alias-label-secondary); font-size:11px; font-family:inherit; }
|
|
798
|
+
.uh-trend-line { fill:none; stroke-width:2.2; vector-effect:non-scaling-stroke; stroke-linecap:round; stroke-linejoin:round; opacity:.22; }
|
|
799
|
+
.uh-trend-line-draw { fill:none; stroke-width:2.2; vector-effect:non-scaling-stroke; stroke-linecap:round; stroke-linejoin:round; stroke-dasharray:var(--uh-draw-length); stroke-dashoffset:var(--uh-draw-length); opacity:.96; pointer-events:none; animation:uh-trend-draw .95s cubic-bezier(.22,.61,.36,1) both; }
|
|
800
|
+
.uh-trend-area { opacity:1; animation:uh-trend-fill .8s ease; }
|
|
801
|
+
.uh-trend-hit { fill:transparent; cursor:crosshair; outline:none; }
|
|
802
|
+
.uh-trend-hit:focus { fill:color-mix(in srgb, var(--dsw-alias-brand-primary) 10%, transparent); outline:1px solid var(--dsw-alias-brand-primary); outline-offset:2px; }
|
|
803
|
+
.uh-trend-tooltip { position:absolute; z-index:4; min-width:166px; padding:10px 11px; border:1px solid color-mix(in srgb, var(--dsw-alias-border-l2) 88%, transparent); border-radius:8px; background:color-mix(in srgb, var(--dsw-alias-bg-layer-1) 94%, transparent); box-shadow:0 10px 24px rgba(0,0,0,.22); backdrop-filter:blur(10px); color:var(--dsw-alias-label-primary); font-size:12px; line-height:1.45; pointer-events:none; opacity:0; visibility:hidden; transform:translate(14px,-50%) scale(.985); transform-origin:left center; transition:left .16s cubic-bezier(.22,.61,.36,1), top .16s cubic-bezier(.22,.61,.36,1), opacity .12s ease, transform .16s cubic-bezier(.22,.61,.36,1), visibility 0s linear .16s; }
|
|
804
|
+
.uh-trend-tooltip.uh-left { transform:translate(calc(-100% - 14px),-50%) scale(.985); transform-origin:right center; }
|
|
805
|
+
.uh-trend-tooltip.uh-visible { opacity:1; visibility:visible; transform:translate(14px,-50%) scale(1); transition-delay:0s; }
|
|
806
|
+
.uh-trend-tooltip.uh-left.uh-visible { transform:translate(calc(-100% - 14px),-50%) scale(1); }
|
|
807
|
+
.uh-trend-tooltip-title { display:block; margin-bottom:6px; color:var(--dsw-alias-label-primary); font-size:12px; font-weight:650; }
|
|
808
|
+
.uh-trend-tooltip-row { display:grid; grid-template-columns:8px minmax(0,1fr) auto; align-items:center; gap:7px; min-width:0; margin-top:3px; font-size:11px; }
|
|
809
|
+
.uh-trend-tooltip-row .uh-trend-dot { width:8px; height:8px; margin:0; }
|
|
810
|
+
.uh-trend-tooltip-label { overflow:hidden; font-weight:600; text-overflow:ellipsis; white-space:nowrap; }
|
|
811
|
+
.uh-trend-tooltip-value { color:inherit; font-weight:600; font-variant-numeric:tabular-nums; white-space:nowrap; }
|
|
812
|
+
.uh-trend-dot { display:inline-block; width:7px; height:7px; margin-right:5px; border-radius:50%; vertical-align:1px; }
|
|
813
|
+
.uh-trend-legend { display:flex; flex-wrap:wrap; gap:5px 8px; margin-top:5px; }
|
|
814
|
+
.uh-trend-legend-item { display:inline-flex; align-items:center; gap:3px; border:0; border-radius:7px; padding:3px 6px; background:transparent; color:var(--dsw-alias-label-secondary); font:inherit; font-size:11px; cursor:pointer; transition:color .15s ease; }
|
|
815
|
+
.uh-trend-legend-item:hover { background:var(--dsw-alias-bg-layer-2); color:var(--dsw-alias-label-primary); }
|
|
816
|
+
.uh-trend-legend-item.uh-on { background:var(--dsw-alias-interactive-bg-hover); color:var(--dsw-alias-label-primary); }
|
|
817
|
+
.uh-filter-bar { position:relative; z-index:10; display:flex; align-items:center; flex-wrap:wrap; gap:7px; }
|
|
818
|
+
.uh-filter-clear { border:0; background:transparent; color:var(--dsw-alias-label-secondary); font:inherit; font-size:11px; cursor:pointer; text-decoration:underline; }
|
|
819
|
+
.uh-query-note { color:var(--dsw-alias-label-secondary); font-size:11px; }
|
|
820
|
+
.uh-detail-tabs { display:flex; align-items:center; flex-wrap:wrap; gap:4px; padding:4px; border:1px solid var(--dsw-alias-border-l1); border-radius:9px; background:color-mix(in srgb, var(--dsw-alias-bg-layer-2) 58%, transparent); }
|
|
821
|
+
.uh-detail-tab { display:inline-flex; align-items:center; gap:6px; min-height:32px; padding:5px 11px; border:0; border-radius:7px; background:transparent; color:var(--dsw-alias-label-secondary); font:inherit; font-size:12px; cursor:pointer; transition:background-color .15s ease, color .15s ease, transform .12s ease; }
|
|
822
|
+
.uh-detail-tab:hover { color:var(--dsw-alias-label-primary); background:var(--dsw-alias-bg-layer-2); }
|
|
823
|
+
.uh-detail-tab.uh-on { color:var(--dsw-alias-label-primary); background:var(--dsw-alias-bg-layer-1); box-shadow:0 1px 3px rgba(0,0,0,.14); }
|
|
824
|
+
.uh-records-panel { animation:uh-panel-in .28s ease both; }
|
|
825
|
+
.uh-records-head { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; margin-bottom:7px; }
|
|
826
|
+
.uh-records-note { margin:8px 0 10px; color:var(--dsw-alias-label-secondary); font-size:11px; line-height:1.45; }
|
|
827
|
+
.uh-records-error { margin:7px 0; color:var(--dsw-alias-warning, #a55b00); font-size:11px; }
|
|
828
|
+
.uh-records-scroll { overflow:auto; border:1px solid var(--dsw-alias-border-l1); border-radius:8px; }
|
|
829
|
+
.uh-record-grid { display:grid; grid-template-columns:112px minmax(190px,1.45fr) 78px repeat(4,minmax(76px,.72fr)) 82px; gap:0; min-width:820px; align-items:center; }
|
|
830
|
+
.uh-record-grid > div { min-width:0; padding:8px 7px; border-bottom:1px solid var(--dsw-alias-border-l1); font-size:11px; }
|
|
831
|
+
.uh-record-header { color:var(--dsw-alias-label-secondary); background:var(--dsw-alias-bg-layer-2); font-weight:600; }
|
|
832
|
+
.uh-record-header > div { white-space:nowrap; }
|
|
833
|
+
.uh-record-row { color:var(--dsw-alias-label-primary); cursor:pointer; outline:none; transition:background-color .14s ease, box-shadow .14s ease; }
|
|
834
|
+
.uh-record-row:hover { background:color-mix(in srgb, var(--dsw-alias-bg-layer-2) 68%, transparent); }
|
|
835
|
+
.uh-record-row.uh-on { background:color-mix(in srgb, var(--dsw-alias-brand-primary) 10%, var(--dsw-alias-bg-layer-1)); box-shadow:inset 3px 0 var(--dsw-alias-brand-primary); }
|
|
836
|
+
.uh-record-row:focus-visible { box-shadow:inset 0 0 0 1px var(--dsw-alias-brand-primary); }
|
|
837
|
+
.uh-record-row:last-child > div { border-bottom:0; }
|
|
838
|
+
.uh-record-time, .uh-record-num { color:var(--dsw-alias-label-secondary); font-variant-numeric:tabular-nums; white-space:nowrap; }
|
|
839
|
+
.uh-record-num { text-align:right; }
|
|
840
|
+
.uh-record-model { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-weight:550; }
|
|
841
|
+
.uh-record-model small { display:block; overflow:hidden; color:var(--dsw-alias-label-secondary); font-size:10px; font-weight:400; text-overflow:ellipsis; white-space:nowrap; }
|
|
842
|
+
.uh-record-source { color:var(--dsw-alias-label-secondary); white-space:nowrap; }
|
|
843
|
+
.uh-records-footer { display:flex; align-items:center; justify-content:space-between; gap:10px; margin-top:9px; }
|
|
844
|
+
.uh-record-detail { margin-top:12px; padding:10px 11px; border-top:1px solid var(--dsw-alias-border-l2); background:color-mix(in srgb, var(--dsw-alias-bg-layer-2) 42%, transparent); animation:uh-detail-in .24s ease both; }
|
|
845
|
+
.uh-record-detail-head, .uh-record-detail-meta { display:flex; align-items:center; flex-wrap:wrap; gap:7px 14px; }
|
|
846
|
+
.uh-record-detail-head { justify-content:space-between; margin-bottom:5px; color:var(--dsw-alias-label-primary); font-size:12px; }
|
|
847
|
+
.uh-record-detail-meta { color:var(--dsw-alias-label-secondary); font-size:11px; }
|
|
848
|
+
.uh-record-token-strip { display:grid; grid-template-columns:repeat(5,minmax(72px,1fr)) minmax(82px,1.1fr); gap:6px; margin-top:9px; }
|
|
849
|
+
.uh-record-token-strip > div { display:flex; flex-direction:column; gap:2px; min-width:0; padding:6px 7px; border-radius:6px; background:var(--dsw-alias-bg-layer-2); }
|
|
850
|
+
.uh-record-token-strip span { color:var(--dsw-alias-label-secondary); font-size:10px; }
|
|
851
|
+
.uh-record-token-strip strong { color:var(--dsw-alias-label-primary); font-size:12px; font-variant-numeric:tabular-nums; }
|
|
852
|
+
.uh-record-token-total { border:1px solid color-mix(in srgb, var(--dsw-alias-brand-primary) 38%, var(--dsw-alias-border-l1)) !important; }
|
|
853
|
+
@keyframes uh-detail-in { from { opacity:0; transform:translateY(-4px); } to { opacity:1; transform:translateY(0); } }
|
|
854
|
+
@media (max-width:640px) { .uh-trend-head { flex-direction:column; } .uh-filter-menu { flex:1 1 130px; width:auto; } .uh-filter-trigger { max-width:100%; } .uh-trend-tooltip { min-width:116px; } .uh-records-head { flex-direction:column; } .uh-record-token-strip { grid-template-columns:repeat(2,minmax(0,1fr)); } .uh-record-token-total { grid-column:1 / -1; } }
|
|
855
|
+
.uh-bar { flex:1; height:6px; border-radius:3px; background:var(--dsw-alias-bg-layer-2); overflow:hidden; max-width:340px; }
|
|
856
|
+
.uh-fill { height:100%; background:var(--dsw-alias-brand-primary); border-radius:3px; transition:width .3s ease; }
|
|
857
|
+
.uh-cards { display:grid; grid-template-columns:repeat(auto-fit, minmax(200px, 1fr)); gap:10px; }
|
|
858
|
+
.uh-card { background:var(--dsw-alias-bg-layer-1); border:1px solid var(--dsw-alias-border-l1); border-radius:12px; padding:12px 14px; display:flex; flex-direction:column; gap:6px; min-height:86px; animation:uh-card-in .45s ease both; transition:transform .18s ease, border-color .18s ease, box-shadow .18s ease; }
|
|
859
|
+
.uh-card:hover { transform:translateY(-2px); border-color:var(--dsw-alias-border-l2); box-shadow:0 6px 18px rgba(0,0,0,.10); }
|
|
860
|
+
.uh-card-label { font-size:12px; color:var(--dsw-alias-label-secondary); }
|
|
861
|
+
.uh-card-value { font-size:20px; font-weight:650; color:var(--dsw-alias-label-primary); line-height:1.2; }
|
|
862
|
+
.uh-card-sub { font-size:11px; color:var(--dsw-alias-label-secondary); line-height:1.55; }
|
|
863
|
+
.uh-wsbars { display:flex; flex-direction:column; gap:6px; margin-top:2px; }
|
|
864
|
+
.uh-wsbar { display:flex; flex-direction:column; gap:3px; cursor:pointer; padding:2px 6px; margin:0 -6px; border-radius:8px; transition:background-color .15s ease; }
|
|
865
|
+
.uh-wsbar:hover { background:var(--dsw-alias-bg-layer-2); }
|
|
866
|
+
.uh-wsbar.uh-sel { outline:1px solid var(--dsw-alias-brand-primary); }
|
|
867
|
+
.uh-wsbar-top { display:flex; align-items:center; gap:6px; min-width:0; }
|
|
868
|
+
.uh-wsbar-title { font-size:12px; color:var(--dsw-alias-label-primary); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; flex:1; min-width:0; }
|
|
869
|
+
.uh-wsbar-num { font-size:11px; font-variant-numeric:tabular-nums; color:var(--dsw-alias-label-secondary); flex:none; }
|
|
870
|
+
.uh-panel { background:var(--dsw-alias-bg-layer-1); border:1px solid var(--dsw-alias-border-l1); border-radius:12px; padding:14px; }
|
|
871
|
+
.uh-hm-head { display:flex; align-items:center; justify-content:space-between; gap:10px; flex-wrap:wrap; margin-bottom:10px; }
|
|
872
|
+
.uh-chips { display:flex; flex-wrap:wrap; gap:6px; }
|
|
873
|
+
.uh-chip { display:inline-flex; align-items:center; gap:6px; border:1px solid var(--dsw-alias-border-l2); background:transparent; color:var(--dsw-alias-label-primary); border-radius:999px; padding:2px 10px; font-size:11px; cursor:pointer; font-family:inherit; max-width:190px; transition:border-color .15s ease, background-color .15s ease, color .15s ease, transform .1s ease; }
|
|
874
|
+
.uh-chip .uh-chip-title { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
|
875
|
+
.uh-chip.uh-on { border-color:var(--dsw-alias-brand-primary); background:color-mix(in srgb, var(--dsw-alias-brand-primary) 14%, transparent); }
|
|
876
|
+
.uh-dot { width:8px; height:8px; border-radius:50%; flex:none; }
|
|
877
|
+
.uh-legend { display:flex; align-items:center; gap:4px; font-size:11px; color:var(--dsw-alias-label-secondary); }
|
|
878
|
+
.uh-legend .uh-cell { width:10px; height:10px; border-radius:2px; animation:none; }
|
|
879
|
+
.uh-hm-scroll { overflow-x:auto; padding-bottom:2px; }
|
|
880
|
+
.uh-months { position:relative; height:16px; margin-left:30px; width:calc(100% - 30px); min-width:686px; font-size:10px; color:var(--dsw-alias-label-secondary); }
|
|
881
|
+
.uh-months span { position:absolute; top:0; }
|
|
882
|
+
.uh-hm-body { display:flex; gap:6px; min-width:0; }
|
|
883
|
+
.uh-wdays { display:grid; grid-template-rows:repeat(7,10px); gap:3px; font-size:10px; color:var(--dsw-alias-label-secondary); text-align:right; width:24px; }
|
|
884
|
+
.uh-wdays span { line-height:10px; }
|
|
885
|
+
.uh-grid { flex:1 1 auto; min-width:686px; display:grid; grid-auto-flow:column; grid-template-columns:repeat(53,minmax(10px,1fr)); grid-template-rows:repeat(7,minmax(10px,auto)); gap:3px; }
|
|
886
|
+
.uh-cell { width:100%; height:auto; min-width:10px; aspect-ratio:1; border-radius:2px; background:var(--dsw-alias-bg-layer-2); animation:uh-cell-in .45s ease both; transition:transform .12s ease, box-shadow .12s ease; }
|
|
887
|
+
.uh-cell:hover { transform:scale(1.35); box-shadow:0 1px 6px rgba(0,0,0,.28); position:relative; z-index:2; }
|
|
888
|
+
.uh-tip { position:fixed; z-index:1200; background:var(--dsw-alias-bg-overlay); border:1px solid var(--dsw-alias-border-l2); border-radius:10px; padding:10px 12px; box-shadow:0 8px 24px rgba(0,0,0,.18); pointer-events:auto; min-width:200px; max-width:290px; animation:uh-tip-in .16s ease both; }
|
|
889
|
+
.uh-tip-date { font-size:12px; font-weight:600; color:var(--dsw-alias-label-primary); margin-bottom:6px; }
|
|
890
|
+
.uh-tip-row { display:flex; align-items:center; gap:6px; font-size:12px; color:var(--dsw-alias-label-primary); padding:3px 6px; margin:0 -6px; border-radius:6px; cursor:pointer; transition:background-color .12s ease; }
|
|
891
|
+
.uh-tip-row:hover { background:color-mix(in srgb, var(--dsw-alias-brand-primary) 12%, transparent); }
|
|
892
|
+
.uh-tip-row .uh-n { margin-left:auto; font-variant-numeric:tabular-nums; color:var(--dsw-alias-label-secondary); }
|
|
893
|
+
.uh-tip-tokens { font-size:11px; color:var(--dsw-alias-label-secondary); margin-top:6px; border-top:1px solid var(--dsw-alias-border-l1); padding-top:6px; }
|
|
894
|
+
.uh-tbl-title { font-size:13px; font-weight:600; color:var(--dsw-alias-label-primary); margin:0 0 10px; }
|
|
895
|
+
.uh-tbl-scroll { overflow-x:auto; }
|
|
896
|
+
.uh-hrow, .uh-row { display:grid; grid-template-columns:minmax(160px,2.2fr) .7fr .9fr .9fr .9fr .9fr 1.1fr .8fr 1fr; gap:8px; align-items:center; min-width:780px; padding:7px 10px; border-radius:8px; font-size:12px; }
|
|
897
|
+
.uh-model-hrow, .uh-model-row { display:grid; grid-template-columns:minmax(190px,2.2fr) .7fr .9fr .9fr .9fr .9fr 1.1fr .8fr; gap:8px; align-items:center; min-width:780px; padding:7px 10px; border-radius:8px; font-size:12px; }
|
|
898
|
+
.uh-hrow { color:var(--dsw-alias-label-secondary); font-size:11px; }
|
|
899
|
+
.uh-row { cursor:pointer; border:1px solid transparent; transition:background-color .15s ease, border-color .15s ease; }
|
|
900
|
+
.uh-row:hover { background:var(--dsw-alias-bg-layer-2); }
|
|
901
|
+
.uh-row.uh-sel { border-color:var(--dsw-alias-brand-primary); }
|
|
902
|
+
.uh-num { text-align:right; font-variant-numeric:tabular-nums; color:var(--dsw-alias-label-primary); }
|
|
903
|
+
.uh-hrow .uh-num { color:var(--dsw-alias-label-secondary); }
|
|
904
|
+
.uh-ws-title { color:var(--dsw-alias-label-primary); font-weight:550; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
|
905
|
+
.uh-row-title-wrap { min-width:0; }
|
|
906
|
+
.uh-ws-path { color:var(--dsw-alias-label-secondary); font-size:11px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
|
907
|
+
.uh-barwrap { height:5px; border-radius:3px; background:var(--dsw-alias-bg-layer-2); overflow:hidden; margin-top:3px; }
|
|
908
|
+
.uh-barwrap.uh-bar-thin { height:3px; margin-top:1px; }
|
|
909
|
+
.uh-barfill { height:100%; border-radius:3px; transform-origin:left center; animation:uh-bar-grow .7s cubic-bezier(.22,.61,.36,1) both; transition:width .5s cubic-bezier(.22,.61,.36,1); }
|
|
910
|
+
.uh-empty { color:var(--dsw-alias-label-secondary); font-size:12px; text-align:center; padding:26px 0; }
|
|
911
|
+
.uh-note { font-size:11px; color:var(--dsw-alias-label-secondary); line-height:1.6; }
|
|
912
|
+
.uh-side-entry { width:100%; border:0; background:transparent; color:var(--dsw-alias-label-secondary); border-radius:8px; min-height:36px; padding:7px 10px; display:flex; align-items:center; gap:9px; font:inherit; font-size:13px; cursor:pointer; text-align:left; }
|
|
913
|
+
.uh-side-entry:hover { background:var(--dsw-alias-interactive-bg-hover); color:var(--dsw-alias-label-primary); }
|
|
914
|
+
.uh-side-entry-icon { width:18px; text-align:center; flex:none; font-size:15px; }
|
|
915
|
+
.uh-side-entry-label { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
|
916
|
+
.uh-boundary-fallback { display:flex; flex-direction:column; align-items:center; justify-content:center; gap:12px; min-height:360px; padding:24px; border:1px solid var(--dsw-alias-border-l1); border-radius:12px; background:var(--dsw-alias-bg-layer-1); text-align:center; }
|
|
917
|
+
.uh-boundary-title { color:var(--dsw-alias-label-primary); font-size:15px; font-weight:650; }
|
|
918
|
+
.uh-boundary-note { max-width:420px; color:var(--dsw-alias-label-secondary); font-size:12px; line-height:1.6; }
|
|
919
|
+
.uh-side-modal { position:fixed; inset:0; z-index:1100; background:color-mix(in srgb, #000 44%, transparent); display:flex; align-items:stretch; justify-content:center; padding:26px; }
|
|
920
|
+
.uh-side-dialog { width:min(1120px, 100%); overflow:auto; background:var(--dsw-alias-bg-base); border:1px solid var(--dsw-alias-border-l2); border-radius:14px; box-shadow:0 18px 52px rgba(0,0,0,.35); padding:18px; }
|
|
921
|
+
.uh-side-dialog-head { display:flex; justify-content:flex-end; margin-bottom:8px; }
|
|
922
|
+
@media (max-width: 640px) { .uh-side-modal { padding:0; } .uh-side-dialog { border-radius:0; border:0; padding:14px; } }
|
|
923
|
+
/* iOS-style dashboard: grouped surfaces, tactile controls, and an elevated sheet. */
|
|
924
|
+
.uh-page { gap:18px; max-width:1160px; margin:0 auto; padding:4px 2px 34px; font-family:-apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif; }
|
|
925
|
+
.uh-head { position:sticky; top:-18px; z-index:20; margin:0 -2px; padding:18px 2px 14px; background:color-mix(in srgb, var(--dsw-alias-bg-base) 88%, transparent); backdrop-filter:blur(18px) saturate(150%); border-bottom:1px solid color-mix(in srgb, var(--dsw-alias-border-l1) 76%, transparent); }
|
|
926
|
+
.uh-title { font-size:22px; line-height:1.2; font-weight:700; letter-spacing:0; }
|
|
927
|
+
.uh-actions { gap:8px; }
|
|
928
|
+
.uh-range { padding:2px; gap:2px; border:0; border-radius:9px; background:color-mix(in srgb, var(--dsw-alias-label-primary) 10%, transparent); overflow:visible; }
|
|
929
|
+
.uh-range button, .uh-range button + button { min-height:28px; border:0; border-radius:7px; padding:4px 10px; }
|
|
930
|
+
.uh-range button.uh-on { background:var(--dsw-alias-bg-layer-1); box-shadow:0 1px 3px rgba(0,0,0,.16); }
|
|
931
|
+
.uh-refresh { min-height:30px; border:0; border-radius:15px; padding:5px 12px; display:inline-flex; align-items:center; justify-content:center; gap:6px; background:color-mix(in srgb, var(--dsw-alias-brand-primary) 14%, var(--dsw-alias-bg-layer-1)); color:var(--dsw-alias-brand-primary); font-weight:600; }
|
|
932
|
+
.uh-line-icon { flex:none; }
|
|
933
|
+
.uh-icon-button { width:30px; padding:0; }
|
|
934
|
+
.uh-refresh:hover { border:0; background:color-mix(in srgb, var(--dsw-alias-brand-primary) 22%, var(--dsw-alias-bg-layer-1)); }
|
|
935
|
+
.uh-progress { padding:10px 12px; background:color-mix(in srgb, var(--dsw-alias-brand-primary) 9%, var(--dsw-alias-bg-layer-1)); border:0; border-radius:12px; }
|
|
936
|
+
.uh-cards { grid-template-columns:repeat(auto-fit, minmax(180px, 1fr)); gap:10px; border:0; border-radius:0; overflow:visible; background:transparent; }
|
|
937
|
+
.uh-card { min-height:84px; padding:12px 14px; gap:4px; border:0; border-radius:18px; background:var(--dsw-alias-bg-layer-1); box-shadow:0 1px 2px rgba(0,0,0,.07), 0 8px 22px rgba(0,0,0,.05); animation:none; }
|
|
938
|
+
.uh-card:first-child { border:0; background:color-mix(in srgb, #0a84ff 15%, var(--dsw-alias-bg-layer-1)); }
|
|
939
|
+
.uh-card:nth-child(2) { background:color-mix(in srgb, #30d158 13%, var(--dsw-alias-bg-layer-1)); }
|
|
940
|
+
.uh-card:nth-child(3) { background:color-mix(in srgb, #ff9f0a 14%, var(--dsw-alias-bg-layer-1)); }
|
|
941
|
+
.uh-card:hover { transform:translateY(-2px); box-shadow:0 12px 28px rgba(0,0,0,.12); }
|
|
942
|
+
.uh-card-label { display:flex; align-items:center; gap:6px; font-size:12px; font-weight:600; letter-spacing:0; }
|
|
943
|
+
.uh-ios-summary-label, .uh-section-title, .uh-title-with-icon { display:flex; align-items:center; gap:7px; }
|
|
944
|
+
.uh-section-title { margin-bottom:12px; color:var(--dsw-alias-label-primary); font-size:14px; font-weight:650; }
|
|
945
|
+
/* Raise the complete reading scale without changing the data grid geometry. */
|
|
946
|
+
.uh-page { font-size:14px; }
|
|
947
|
+
.uh-range button, .uh-refresh { font-size:13px; }
|
|
948
|
+
.uh-card-label, .uh-ios-summary-label { font-size:13px; }
|
|
949
|
+
.uh-card-sub, .uh-ios-summary-caption, .uh-note { font-size:12px; }
|
|
950
|
+
.uh-hrow, .uh-row, .uh-model-hrow, .uh-model-row { font-size:13px; }
|
|
951
|
+
.uh-tbl-title { font-size:15px; }
|
|
952
|
+
.uh-num { font-variant-numeric:tabular-nums; }
|
|
953
|
+
.uh-card-value { font-size:23px; font-weight:700; letter-spacing:0; }
|
|
954
|
+
.uh-card-sub { font-size:11px; line-height:1.45; }
|
|
955
|
+
.uh-panel { padding:16px; border:0; border-radius:18px; background:var(--dsw-alias-bg-layer-1); box-shadow:0 1px 2px rgba(0,0,0,.06), 0 6px 18px rgba(0,0,0,.04); }
|
|
956
|
+
.uh-hm-head { margin-bottom:12px; }
|
|
957
|
+
.uh-chip { border:0; border-radius:14px; padding:5px 10px; background:color-mix(in srgb, var(--dsw-alias-label-primary) 7%, transparent); }
|
|
958
|
+
.uh-chip.uh-on { border:0; background:color-mix(in srgb, var(--dsw-alias-brand-primary) 18%, transparent); color:var(--dsw-alias-brand-primary); }
|
|
959
|
+
.uh-hrow, .uh-row, .uh-model-hrow, .uh-model-row { border-radius:10px; }
|
|
960
|
+
.uh-hrow, .uh-model-hrow { position:sticky; top:66px; z-index:2; background:var(--dsw-alias-bg-layer-1); border-bottom:1px solid var(--dsw-alias-border-l1); }
|
|
961
|
+
.uh-row, .uh-model-row { padding-top:9px; padding-bottom:9px; }
|
|
962
|
+
.uh-row:nth-child(even) { background:color-mix(in srgb, var(--dsw-alias-bg-layer-2) 52%, transparent); }
|
|
963
|
+
.uh-side-entry { min-height:40px; border:0; border-radius:12px; padding:8px 10px; background:color-mix(in srgb, var(--dsw-alias-brand-primary) 9%, transparent); color:var(--dsw-alias-brand-primary); font-weight:600; }
|
|
964
|
+
.uh-side-entry:hover { border:0; background:color-mix(in srgb, var(--dsw-alias-brand-primary) 17%, transparent); }
|
|
965
|
+
.uh-side-entry-icon { color:var(--dsw-alias-brand-primary); font-weight:700; }
|
|
966
|
+
.uh-side-modal { align-items:flex-end; padding:0; background:rgba(0,0,0,.34); backdrop-filter:blur(8px); }
|
|
967
|
+
.uh-side-dialog { width:min(1260px, 100%); max-height:calc(100vh - 44px); border:0; border-radius:24px 24px 0 0; padding:22px 24px 28px; background:color-mix(in srgb, var(--dsw-alias-bg-base) 94%, transparent); box-shadow:0 -10px 44px rgba(0,0,0,.25); }
|
|
968
|
+
.uh-side-dialog-head { position:sticky; top:-22px; z-index:8; justify-content:center; height:22px; margin:-22px -24px 8px; padding:8px 24px; background:color-mix(in srgb, var(--dsw-alias-bg-base) 94%, transparent); border:0; }
|
|
969
|
+
.uh-side-dialog-head::before { content:""; width:36px; height:5px; border-radius:3px; background:color-mix(in srgb, var(--dsw-alias-label-primary) 24%, transparent); }
|
|
970
|
+
.uh-side-dialog-head .uh-refresh { position:absolute; right:20px; top:7px; min-height:28px; background:transparent; }
|
|
971
|
+
.uh-close-button { width:30px; padding:0; font-size:22px; line-height:1; color:var(--dsw-alias-label-secondary); }
|
|
972
|
+
.uh-close-button:hover { color:var(--dsw-alias-label-primary); background:color-mix(in srgb, var(--dsw-alias-label-primary) 10%, transparent); }
|
|
973
|
+
@media (max-width:640px) { .uh-page { gap:14px; padding-bottom:20px; } .uh-head { position:static; padding:4px 0 10px; } .uh-title { font-size:20px; } .uh-custom-range { grid-template-columns:1fr; align-items:stretch; } .uh-custom-range-fields { grid-template-columns:repeat(2, minmax(0, 1fr)); } .uh-custom-range-actions { justify-content:flex-end; } .uh-side-dialog { max-height:calc(100vh - 8px); border-radius:20px 20px 0 0; padding:18px 14px 24px; } .uh-side-dialog-head { top:-18px; margin:-18px -14px 8px; padding:7px 14px; } .uh-card-value { font-size:22px; } }
|
|
974
|
+
/* Navigation separates the dashboard into three focused iOS-style surfaces. */
|
|
975
|
+
.uh-ios-tabs { display:grid; grid-template-columns:repeat(3, 1fr); gap:4px; padding:4px; border-radius:14px; background:color-mix(in srgb, var(--dsw-alias-label-primary) 9%, transparent); }
|
|
976
|
+
.uh-ios-tab { min-height:32px; border:0; border-radius:10px; background:transparent; color:var(--dsw-alias-label-secondary); font:inherit; font-size:13px; font-weight:600; cursor:pointer; }
|
|
977
|
+
.uh-ios-tab.uh-on { color:var(--dsw-alias-label-primary); background:var(--dsw-alias-bg-layer-1); box-shadow:0 1px 4px rgba(0,0,0,.16); }
|
|
978
|
+
.uh-ios-summary { display:grid; grid-template-columns:repeat(2, minmax(0, 1fr)); gap:10px; background:transparent; box-shadow:none; }
|
|
979
|
+
.uh-ios-summary-total, .uh-ios-summary-cache { min-height:104px; padding:16px 20px; border-radius:22px; display:flex; flex-direction:column; justify-content:center; box-shadow:0 14px 32px rgba(0,0,0,.08); }
|
|
980
|
+
.uh-ios-summary-total { background:color-mix(in srgb, #0a84ff 18%, var(--dsw-alias-bg-layer-1)); }
|
|
981
|
+
.uh-ios-summary-cache { background:color-mix(in srgb, #30d158 17%, var(--dsw-alias-bg-layer-1)); }
|
|
982
|
+
.uh-ios-summary-label { font-size:13px; font-weight:600; color:var(--dsw-alias-label-secondary); }
|
|
983
|
+
.uh-ios-summary-value { margin-top:4px; font-size:32px; line-height:1; font-weight:750; letter-spacing:0; color:var(--dsw-alias-label-primary); }
|
|
984
|
+
.uh-unit { margin-left:6px; color:var(--dsw-alias-label-secondary); font-size:.4em; font-weight:650; white-space:nowrap; vertical-align:baseline; }
|
|
985
|
+
.uh-wsbar-num .uh-unit { font-size:.78em; margin-left:3px; }
|
|
986
|
+
.uh-ios-summary-caption { margin-top:8px; font-size:12px; color:var(--dsw-alias-label-secondary); }
|
|
987
|
+
.uh-token-semantics { display:flex; align-items:flex-start; gap:8px; padding:10px 12px; border-radius:12px; background:color-mix(in srgb, var(--dsw-alias-brand-primary) 8%, var(--dsw-alias-bg-layer-1)); color:var(--dsw-alias-label-secondary); font-size:12px; line-height:1.55; }
|
|
988
|
+
.uh-token-semantics .uh-line-icon { margin-top:1px; color:var(--dsw-alias-brand-primary); }
|
|
989
|
+
.uh-ios-summary-meta { display:grid; align-content:center; grid-template-columns:1fr auto; gap:7px 12px; padding:20px 22px; background:color-mix(in srgb, var(--dsw-alias-bg-layer-1) 64%, transparent); font-size:12px; color:var(--dsw-alias-label-secondary); }
|
|
990
|
+
.uh-ios-summary-meta strong { color:var(--dsw-alias-label-primary); font-size:15px; font-variant-numeric:tabular-nums; }
|
|
991
|
+
.uh-ios-list-panel { min-height:360px; }
|
|
992
|
+
.uh-donut-chart { margin:0 0 18px; }
|
|
993
|
+
.uh-donut-title { display:flex; align-items:center; gap:7px; margin-bottom:12px; color:var(--dsw-alias-label-primary); font-size:14px; font-weight:650; }
|
|
994
|
+
.uh-donut-layout { display:grid; grid-template-columns:minmax(220px,300px) minmax(0,1fr); gap:24px; align-items:center; }
|
|
995
|
+
.uh-donut-visual { position:relative; width:min(100%,280px); aspect-ratio:1; margin:0 auto; }
|
|
996
|
+
.uh-donut-svg { display:block; width:100%; height:100%; overflow:visible; }
|
|
997
|
+
.uh-donut-track { opacity:.78; }
|
|
998
|
+
.uh-donut-segment { fill:none; stroke-dasharray:1; stroke-dashoffset:1; animation:uh-donut-draw .95s cubic-bezier(.22,.61,.36,1) both; cursor:pointer; outline:none; transition:filter .15s ease, opacity .15s ease; }
|
|
999
|
+
.uh-donut-segment:hover, .uh-donut-segment:focus-visible, .uh-donut-segment.uh-active { filter:brightness(1.12); }
|
|
1000
|
+
.uh-donut-tooltip { position:absolute; top:0; left:0; z-index:3; display:flex; align-items:flex-start; gap:8px; max-width:190px; padding:9px 10px; border:1px solid var(--dsw-alias-border-l2); border-radius:8px; background:color-mix(in srgb, var(--dsw-alias-bg-base) 94%, transparent); box-shadow:0 10px 24px rgba(0,0,0,.22); backdrop-filter:blur(10px); color:var(--dsw-alias-label-primary); pointer-events:none; font-size:12px; line-height:1.4; transition:left .12s cubic-bezier(.22,.61,.36,1), top .12s cubic-bezier(.22,.61,.36,1); }
|
|
1001
|
+
.uh-donut-tooltip > div { min-width:0; display:flex; flex-direction:column; gap:4px; }
|
|
1002
|
+
.uh-donut-tooltip strong { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:12px; }
|
|
1003
|
+
.uh-donut-tooltip span:not(.uh-donut-dot) { color:var(--dsw-alias-label-secondary); font-size:11px; }
|
|
1004
|
+
.uh-donut-center { position:absolute; inset:0; display:flex; flex-direction:column; align-items:center; justify-content:center; pointer-events:none; }
|
|
1005
|
+
.uh-donut-center strong { color:var(--dsw-alias-label-primary); font-size:28px; line-height:1; font-weight:750; font-variant-numeric:tabular-nums; }
|
|
1006
|
+
.uh-donut-center span { margin-top:5px; color:var(--dsw-alias-label-secondary); font-size:13px; }
|
|
1007
|
+
.uh-donut-legend { min-width:0; }
|
|
1008
|
+
.uh-donut-legend-row { display:grid; grid-template-columns:12px minmax(0,1fr) auto; gap:10px; align-items:center; min-height:58px; padding:8px 0; border-bottom:1px solid color-mix(in srgb, var(--dsw-alias-border-l1) 78%, transparent); }
|
|
1009
|
+
.uh-donut-legend-row:last-child { border-bottom:0; }
|
|
1010
|
+
.uh-donut-dot { width:12px; height:12px; border-radius:50%; }
|
|
1011
|
+
.uh-donut-legend-copy { min-width:0; display:flex; flex-direction:column; gap:5px; }
|
|
1012
|
+
.uh-donut-legend-copy strong { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:var(--dsw-alias-label-primary); font-size:13px; font-weight:650; }
|
|
1013
|
+
.uh-donut-legend-copy span { color:var(--dsw-alias-label-secondary); font-size:12px; }
|
|
1014
|
+
.uh-donut-percent { color:var(--dsw-alias-label-secondary); font-size:12px; font-variant-numeric:tabular-nums; }
|
|
1015
|
+
/* Each detail table owns its scrolling and sticky header; sections must not overlap in the page scroll. */
|
|
1016
|
+
.uh-tbl-scroll { max-height:360px; overflow:auto; border-radius:12px; background:color-mix(in srgb, var(--dsw-alias-bg-layer-2) 55%, transparent); }
|
|
1017
|
+
.uh-hrow, .uh-model-hrow { position:sticky; top:0; z-index:3; border-bottom:1px solid var(--dsw-alias-border-l1); box-shadow:0 1px 0 color-mix(in srgb, var(--dsw-alias-bg-base) 70%, transparent); }
|
|
1018
|
+
.uh-row, .uh-model-row { min-height:48px; border-bottom:1px solid color-mix(in srgb, var(--dsw-alias-border-l1) 72%, transparent); }
|
|
1019
|
+
.uh-row:last-child, .uh-model-row:last-child { border-bottom:0; }
|
|
1020
|
+
@media (max-width:640px) { .uh-tbl-scroll { max-height:300px; border-radius:10px; } }
|
|
1021
|
+
@media (max-width:640px) { .uh-hm-body { min-width:720px; } .uh-ios-summary { grid-template-columns:1fr; } .uh-ios-summary-total, .uh-ios-summary-cache { padding:18px; min-height:0; border-radius:18px; } .uh-ios-summary-value { font-size:31px; } .uh-donut-layout { grid-template-columns:1fr; gap:12px; } .uh-donut-visual { width:min(100%,250px); } }
|
|
1022
|
+
@keyframes uh-cell-in { from { opacity:0; transform:scale(.4); } to { opacity:1; transform:scale(1); } }
|
|
1023
|
+
@keyframes uh-glow { 0% { box-shadow:0 0 0 0 rgba(46,160,67,.5); } 70% { box-shadow:0 0 0 5px rgba(46,160,67,0); } 100% { box-shadow:0 0 0 0 rgba(46,160,67,0); } }
|
|
1024
|
+
@keyframes uh-card-in { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }
|
|
1025
|
+
@keyframes uh-bar-grow { from { transform:scaleX(0); } to { transform:scaleX(1); } }
|
|
1026
|
+
@keyframes uh-panel-in { from { opacity:0; transform:translateY(-6px); } to { opacity:1; transform:translateY(0); } }
|
|
1027
|
+
@keyframes uh-trend-draw { from { stroke-dashoffset:var(--uh-draw-length); opacity:.2; } to { stroke-dashoffset:0; opacity:1; } }
|
|
1028
|
+
@keyframes uh-trend-fill { from { opacity:0; } to { opacity:1; } }
|
|
1029
|
+
@keyframes uh-donut-draw { from { stroke-dashoffset:1; opacity:.25; } to { stroke-dashoffset:0; opacity:1; } }
|
|
1030
|
+
@keyframes uh-spinner-turn { to { transform:rotate(360deg); } }
|
|
1031
|
+
@keyframes uh-menu-in { from { opacity:0; transform:translateY(-4px) scale(.97); } to { opacity:1; transform:translateY(0) scale(1); } }
|
|
1032
|
+
@keyframes uh-tip-in { from { opacity:0; } to { opacity:1; } }
|
|
1033
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1034
|
+
.uh-cell, .uh-card, .uh-barfill, .uh-anim-panel, .uh-trend-panel, .uh-trend-line-draw, .uh-trend-area, .uh-trend-point, .uh-trend-spinner, .uh-donut-segment, .uh-records-panel, .uh-record-detail, .uh-tip, .uh-language-options { animation:none !important; stroke-dashoffset:0 !important; opacity:1 !important; }
|
|
1035
|
+
.uh-card, .uh-cell, .uh-barfill, .uh-fill, .uh-refresh, .uh-chip, .uh-row, .uh-tip-row, .uh-trend-tooltip, .uh-language-trigger, .uh-language-caret, .uh-language-option { transition:none !important; }
|
|
1036
|
+
}
|
|
1037
|
+
`
|
|
1038
|
+
const cssTagId = "dsh-all-usage/styles.css"
|
|
1039
|
+
if (typeof document !== "undefined") {
|
|
1040
|
+
let tag = document.querySelector("style[data-plugin-css=" + JSON.stringify(cssTagId) + "]")
|
|
1041
|
+
if (tag === null) {
|
|
1042
|
+
tag = document.createElement("style")
|
|
1043
|
+
tag.dataset.plugin = "dsh-all-usage"
|
|
1044
|
+
tag.dataset.pluginCss = cssTagId
|
|
1045
|
+
document.head.appendChild(tag)
|
|
1046
|
+
}
|
|
1047
|
+
tag.textContent = CSS
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
// 与 Host 半的数据接口(webServer 路由)
|
|
1051
|
+
const getStats = () => fetch('/api/all-usage', { headers: { accept: 'application/json' } }).then((r) => {
|
|
1052
|
+
if (!r.ok) throw new Error('HTTP ' + r.status)
|
|
1053
|
+
return r.json()
|
|
1054
|
+
})
|
|
1055
|
+
const getStatus = () => fetch('/api/all-usage/status', { headers: { accept: 'application/json' } }).then((r) => {
|
|
1056
|
+
if (!r.ok) throw new Error('HTTP ' + r.status)
|
|
1057
|
+
return r.json()
|
|
1058
|
+
})
|
|
1059
|
+
const getUsageQuery = (scope) => {
|
|
1060
|
+
const params = new URLSearchParams({ start: scope.start, end: scope.end, utc: scope.utc ? '1' : '0' })
|
|
1061
|
+
if (scope.workspaceId) params.set('workspaceId', scope.workspaceId)
|
|
1062
|
+
if (scope.provider) params.set('provider', scope.provider)
|
|
1063
|
+
if (scope.modelKey) params.set('modelKey', scope.modelKey)
|
|
1064
|
+
return fetch('/api/all-usage/query?' + params.toString(), { headers: { accept: 'application/json' } }).then((r) => {
|
|
1065
|
+
if (!r.ok) throw new Error('HTTP ' + r.status)
|
|
1066
|
+
return r.json()
|
|
1067
|
+
})
|
|
1068
|
+
}
|
|
1069
|
+
const getUsageRecords = (scope, cursor, limit) => {
|
|
1070
|
+
const params = new URLSearchParams({ start: scope.start, end: scope.end, utc: scope.utc ? '1' : '0', limit: String(limit || 100) })
|
|
1071
|
+
if (scope.workspaceId) params.set('workspaceId', scope.workspaceId)
|
|
1072
|
+
if (scope.provider) params.set('provider', scope.provider)
|
|
1073
|
+
if (scope.modelKey) params.set('modelKey', scope.modelKey)
|
|
1074
|
+
if (cursor) params.set('cursor', cursor)
|
|
1075
|
+
return fetch('/api/all-usage/records?' + params.toString(), { headers: { accept: 'application/json' } }).then((r) => {
|
|
1076
|
+
if (!r.ok) { const error = new Error('HTTP ' + r.status); error.status = r.status; throw error }
|
|
1077
|
+
return r.json()
|
|
1078
|
+
})
|
|
1079
|
+
}
|
|
1080
|
+
const getBalance = (force, requestToken) => fetch('/api/all-usage/balance' + (force ? '?force=1' : ''), { headers: { accept: 'application/json', 'x-all-usage-request-token': requestToken } }).then((r) => {
|
|
1081
|
+
if (!r.ok) throw new Error('HTTP ' + r.status)
|
|
1082
|
+
return r.json()
|
|
1083
|
+
})
|
|
1084
|
+
const setAliasRpc = (workspaceId, alias, writeToken) => fetch('/api/all-usage/alias', {
|
|
1085
|
+
method: 'POST',
|
|
1086
|
+
headers: { 'content-type': 'application/json', 'x-all-usage-request-token': writeToken },
|
|
1087
|
+
body: JSON.stringify({ workspaceId, alias }),
|
|
1088
|
+
}).then((r) => {
|
|
1089
|
+
if (!r.ok) throw new Error('HTTP ' + r.status)
|
|
1090
|
+
return r.json()
|
|
1091
|
+
})
|
|
1092
|
+
|
|
1093
|
+
const LANGUAGE_STORAGE_KEY = 'dsh-all-usage.language'
|
|
1094
|
+
function storedLanguage() {
|
|
1095
|
+
try { return window.localStorage.getItem(LANGUAGE_STORAGE_KEY) === 'en' ? 'en' : 'zh' } catch (_) { return 'zh' }
|
|
1096
|
+
}
|
|
1097
|
+
function persistLanguage(language) {
|
|
1098
|
+
try { window.localStorage.setItem(LANGUAGE_STORAGE_KEY, language) } catch (_) {}
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
function UsagePage(props) {
|
|
1102
|
+
const timer = props.timerCtx
|
|
1103
|
+
const language = props.language === 'en' ? 'en' : 'zh'
|
|
1104
|
+
const tr = (zh, en) => language === 'en' ? en : zh
|
|
1105
|
+
const useUtc = language === 'en'
|
|
1106
|
+
const calendarNow = new Date()
|
|
1107
|
+
const latestCalendarDate = fmtDate(calendarNow, useUtc)
|
|
1108
|
+
const [stats, setStats] = React.useState(null)
|
|
1109
|
+
const [status, setStatus] = React.useState(null)
|
|
1110
|
+
const [statsError, setStatsError] = React.useState('')
|
|
1111
|
+
const [lastStatsAt, setLastStatsAt] = React.useState(0)
|
|
1112
|
+
const [balance, setBalance] = React.useState(null)
|
|
1113
|
+
const [range, setRange] = React.useState('today')
|
|
1114
|
+
const [customRange, setCustomRange] = React.useState({ start: '', end: '' })
|
|
1115
|
+
const [customDraft, setCustomDraft] = React.useState({ start: '', end: '' })
|
|
1116
|
+
const [customRangeOpen, setCustomRangeOpen] = React.useState(false)
|
|
1117
|
+
const [modelView, setModelView] = React.useState('route')
|
|
1118
|
+
const [wsFilter, setWsFilter] = React.useState(null)
|
|
1119
|
+
const [providerFilter, setProviderFilter] = React.useState(null)
|
|
1120
|
+
const [modelFilter, setModelFilter] = React.useState(null)
|
|
1121
|
+
const [queryResult, setQueryResult] = React.useState(null)
|
|
1122
|
+
const [queryResultKey, setQueryResultKey] = React.useState('')
|
|
1123
|
+
const [queryLoading, setQueryLoading] = React.useState(false)
|
|
1124
|
+
const [queryError, setQueryError] = React.useState('')
|
|
1125
|
+
const [trendVisible, setTrendVisible] = React.useState(['total', 'input', 'cacheRead', 'output'])
|
|
1126
|
+
const [detailView, setDetailView] = React.useState('logs')
|
|
1127
|
+
const [detailSelection, setDetailSelection] = React.useState(null)
|
|
1128
|
+
const [auditSelectedId, setAuditSelectedId] = React.useState(null)
|
|
1129
|
+
const [auditRows, setAuditRows] = React.useState([])
|
|
1130
|
+
const [auditCursor, setAuditCursor] = React.useState(null)
|
|
1131
|
+
const [auditHasMore, setAuditHasMore] = React.useState(false)
|
|
1132
|
+
const [auditReload, setAuditReload] = React.useState(0)
|
|
1133
|
+
const [auditLoading, setAuditLoading] = React.useState(false)
|
|
1134
|
+
const [auditExporting, setAuditExporting] = React.useState(false)
|
|
1135
|
+
const [auditError, setAuditError] = React.useState('')
|
|
1136
|
+
const [hover, setHover] = React.useState(null)
|
|
1137
|
+
const [aliasOpen, setAliasOpen] = React.useState(false)
|
|
1138
|
+
const [aliasDrafts, setAliasDrafts] = React.useState({})
|
|
1139
|
+
const [languageMenuOpen, setLanguageMenuOpen] = React.useState(false)
|
|
1140
|
+
const languageMenuRef = React.useRef(null)
|
|
1141
|
+
const recordsPanelRef = React.useRef(null)
|
|
1142
|
+
const statsGateRef = React.useRef(null)
|
|
1143
|
+
if (statsGateRef.current === null) statsGateRef.current = createRequestGate()
|
|
1144
|
+
const statusGateRef = React.useRef(null)
|
|
1145
|
+
if (statusGateRef.current === null) statusGateRef.current = createRequestGate()
|
|
1146
|
+
const balanceGateRef = React.useRef(null)
|
|
1147
|
+
if (balanceGateRef.current === null) balanceGateRef.current = createRequestGate()
|
|
1148
|
+
const queryGateRef = React.useRef(null)
|
|
1149
|
+
if (queryGateRef.current === null) queryGateRef.current = createRequestGate()
|
|
1150
|
+
const recordsGateRef = React.useRef(null)
|
|
1151
|
+
if (recordsGateRef.current === null) recordsGateRef.current = createRequestGate()
|
|
1152
|
+
const statsGate = statsGateRef.current
|
|
1153
|
+
const statusGate = statusGateRef.current
|
|
1154
|
+
const balanceGate = balanceGateRef.current
|
|
1155
|
+
const queryGate = queryGateRef.current
|
|
1156
|
+
const recordsGate = recordsGateRef.current
|
|
1157
|
+
const refreshRef = React.useRef(() => {})
|
|
1158
|
+
const setLanguage = (next) => { if (typeof props.onLanguageChange === 'function') props.onLanguageChange(next === 'en' ? 'en' : 'zh') }
|
|
1159
|
+
const chooseLanguage = (next) => { setLanguage(next); setLanguageMenuOpen(false) }
|
|
1160
|
+
|
|
1161
|
+
const queryScope = stats === null ? null : makeUsageScope(stats, range, useUtc, customRange, wsFilter, providerFilter, modelFilter)
|
|
1162
|
+
const queryKey = usageScopeKey(queryScope)
|
|
1163
|
+
const selectedDetailScope = detailSelection !== null && detailSelection.baseKey === queryKey ? detailSelection.scope : queryScope
|
|
1164
|
+
const detailKey = usageScopeKey(selectedDetailScope)
|
|
1165
|
+
const previousQueryKeyRef = React.useRef(queryKey)
|
|
1166
|
+
React.useEffect(() => {
|
|
1167
|
+
if (previousQueryKeyRef.current !== queryKey) {
|
|
1168
|
+
previousQueryKeyRef.current = queryKey
|
|
1169
|
+
setDetailSelection(null)
|
|
1170
|
+
setAuditSelectedId(null)
|
|
1171
|
+
}
|
|
1172
|
+
}, [queryKey])
|
|
1173
|
+
|
|
1174
|
+
React.useEffect(() => {
|
|
1175
|
+
let alive = true
|
|
1176
|
+
let scanDone = false
|
|
1177
|
+
let requestToken = ''
|
|
1178
|
+
let appliedSnapshot = null
|
|
1179
|
+
let fullFailures = 0
|
|
1180
|
+
let statusFailures = 0
|
|
1181
|
+
let retryTimer = null
|
|
1182
|
+
const clearRetry = () => {
|
|
1183
|
+
if (retryTimer !== null) {
|
|
1184
|
+
clearTimeout(retryTimer)
|
|
1185
|
+
retryTimer = null
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
const refreshBalance = (force) => {
|
|
1189
|
+
if (requestToken === '') return
|
|
1190
|
+
const seq = balanceGate.next()
|
|
1191
|
+
getBalance(force === true, requestToken).then((data) => {
|
|
1192
|
+
if (!alive || !balanceGate.isCurrent(seq)) return
|
|
1193
|
+
if (data) setBalance(data)
|
|
1194
|
+
}, () => {})
|
|
1195
|
+
}
|
|
1196
|
+
const scheduleRetry = (kind) => {
|
|
1197
|
+
if (!alive || retryTimer !== null) return
|
|
1198
|
+
const failures = kind === 'full' ? (fullFailures += 1) : (statusFailures += 1)
|
|
1199
|
+
retryTimer = setTimeout(() => {
|
|
1200
|
+
retryTimer = null
|
|
1201
|
+
if (!alive) return
|
|
1202
|
+
if (kind === 'full') refreshStats()
|
|
1203
|
+
else refreshStatus()
|
|
1204
|
+
}, retryDelayFor(failures))
|
|
1205
|
+
}
|
|
1206
|
+
const refreshStats = () => {
|
|
1207
|
+
statusGate.next()
|
|
1208
|
+
const seq = statsGate.next()
|
|
1209
|
+
getStats().then((data) => {
|
|
1210
|
+
if (!alive || !statsGate.isCurrent(seq)) return
|
|
1211
|
+
if (data === null || typeof data !== 'object') {
|
|
1212
|
+
setStatsError('full')
|
|
1213
|
+
scheduleRetry('full')
|
|
1214
|
+
return
|
|
1215
|
+
}
|
|
1216
|
+
appliedSnapshot = data
|
|
1217
|
+
if (data.scan) scanDone = !!data.scan.done
|
|
1218
|
+
const nextToken = typeof data.requestToken === 'string' ? data.requestToken : ''
|
|
1219
|
+
const tokenChanged = nextToken !== '' && nextToken !== requestToken
|
|
1220
|
+
requestToken = nextToken
|
|
1221
|
+
fullFailures = 0
|
|
1222
|
+
clearRetry()
|
|
1223
|
+
setStatsError('')
|
|
1224
|
+
setLastStatsAt(Date.now())
|
|
1225
|
+
setStatus(data)
|
|
1226
|
+
setStats(data)
|
|
1227
|
+
if (tokenChanged) refreshBalance(false)
|
|
1228
|
+
}, () => {
|
|
1229
|
+
if (!alive || !statsGate.isCurrent(seq)) return
|
|
1230
|
+
setStatsError('full')
|
|
1231
|
+
scheduleRetry('full')
|
|
1232
|
+
})
|
|
1233
|
+
}
|
|
1234
|
+
const refreshStatus = () => {
|
|
1235
|
+
if (appliedSnapshot === null) { refreshStats(); return }
|
|
1236
|
+
const seq = statusGate.next()
|
|
1237
|
+
getStatus().then((data) => {
|
|
1238
|
+
if (!alive || !statusGate.isCurrent(seq)) return
|
|
1239
|
+
if (data === null || typeof data !== 'object') {
|
|
1240
|
+
setStatsError('status')
|
|
1241
|
+
scheduleRetry('status')
|
|
1242
|
+
return
|
|
1243
|
+
}
|
|
1244
|
+
statusFailures = 0
|
|
1245
|
+
const requiresFullSnapshot = statusRequiresFullSnapshot(data, appliedSnapshot)
|
|
1246
|
+
if (data.scan) scanDone = !!data.scan.done
|
|
1247
|
+
// Do not render a newer status beside an older full snapshot. A full
|
|
1248
|
+
// fetch owns the state transition when instance/revision diverges.
|
|
1249
|
+
if (requiresFullSnapshot) {
|
|
1250
|
+
refreshStats()
|
|
1251
|
+
return
|
|
1252
|
+
}
|
|
1253
|
+
setStatus(data)
|
|
1254
|
+
clearRetry()
|
|
1255
|
+
setStatsError('')
|
|
1256
|
+
}, () => {
|
|
1257
|
+
if (!alive || !statusGate.isCurrent(seq)) return
|
|
1258
|
+
setStatsError('status')
|
|
1259
|
+
scheduleRetry('status')
|
|
1260
|
+
})
|
|
1261
|
+
}
|
|
1262
|
+
refreshStats()
|
|
1263
|
+
const fast = timer.interval(() => { if (!scanDone && retryTimer === null) refreshStats() }, 2000)
|
|
1264
|
+
const slow = timer.interval(() => { if (scanDone && retryTimer === null) refreshStatus() }, 15000)
|
|
1265
|
+
const bal = timer.interval(() => { refreshBalance(false) }, 60000)
|
|
1266
|
+
refreshRef.current = () => {
|
|
1267
|
+
clearRetry()
|
|
1268
|
+
fullFailures = 0
|
|
1269
|
+
statusFailures = 0
|
|
1270
|
+
refreshStats()
|
|
1271
|
+
refreshBalance(true)
|
|
1272
|
+
}
|
|
1273
|
+
return () => { alive = false; clearRetry(); fast(); slow(); bal() }
|
|
1274
|
+
}, [])
|
|
1275
|
+
|
|
1276
|
+
React.useEffect(() => {
|
|
1277
|
+
if (!languageMenuOpen || typeof document === 'undefined') return undefined
|
|
1278
|
+
const closeLanguageMenu = (event) => {
|
|
1279
|
+
if (languageMenuRef.current && !languageMenuRef.current.contains(event.target)) setLanguageMenuOpen(false)
|
|
1280
|
+
}
|
|
1281
|
+
document.addEventListener('pointerdown', closeLanguageMenu)
|
|
1282
|
+
return () => document.removeEventListener('pointerdown', closeLanguageMenu)
|
|
1283
|
+
}, [languageMenuOpen])
|
|
1284
|
+
|
|
1285
|
+
React.useEffect(() => {
|
|
1286
|
+
if (queryScope === null || queryKey === '') return undefined
|
|
1287
|
+
const seq = queryGate.next()
|
|
1288
|
+
setQueryLoading(true)
|
|
1289
|
+
setQueryError('')
|
|
1290
|
+
getUsageQuery(queryScope).then((data) => {
|
|
1291
|
+
if (!queryGate.isCurrent(seq)) return
|
|
1292
|
+
if (data === null || typeof data !== 'object' || data.revision !== (stats && stats.revision)) {
|
|
1293
|
+
setQueryError('stale')
|
|
1294
|
+
setQueryLoading(false)
|
|
1295
|
+
return
|
|
1296
|
+
}
|
|
1297
|
+
setQueryResult(data)
|
|
1298
|
+
setQueryResultKey(queryKey)
|
|
1299
|
+
setQueryLoading(false)
|
|
1300
|
+
setQueryError('')
|
|
1301
|
+
}, () => {
|
|
1302
|
+
if (!queryGate.isCurrent(seq)) return
|
|
1303
|
+
setQueryLoading(false)
|
|
1304
|
+
setQueryError('query')
|
|
1305
|
+
})
|
|
1306
|
+
return undefined
|
|
1307
|
+
}, [queryKey, stats && stats.revision])
|
|
1308
|
+
|
|
1309
|
+
const openAuditForScope = (scope) => {
|
|
1310
|
+
if (scope === null || queryKey === '') return
|
|
1311
|
+
setDetailSelection({ baseKey: queryKey, scope: { ...scope } })
|
|
1312
|
+
setDetailView('logs')
|
|
1313
|
+
setAuditSelectedId(null)
|
|
1314
|
+
setAuditError('')
|
|
1315
|
+
}
|
|
1316
|
+
const openAuditForDate = (date) => {
|
|
1317
|
+
if (queryScope === null || typeof date !== 'string') return
|
|
1318
|
+
openAuditForScope({ ...queryScope, start: date, end: date })
|
|
1319
|
+
}
|
|
1320
|
+
React.useEffect(() => {
|
|
1321
|
+
if (selectedDetailScope === null || detailKey === '') return undefined
|
|
1322
|
+
const seq = recordsGate.next()
|
|
1323
|
+
setAuditLoading(true)
|
|
1324
|
+
setAuditError('')
|
|
1325
|
+
setAuditRows([])
|
|
1326
|
+
setAuditSelectedId(null)
|
|
1327
|
+
setAuditCursor(null)
|
|
1328
|
+
setAuditHasMore(false)
|
|
1329
|
+
getUsageRecords(selectedDetailScope, null, 20).then((data) => {
|
|
1330
|
+
if (!recordsGate.isCurrent(seq)) return
|
|
1331
|
+
if (data === null || typeof data !== 'object' || !Array.isArray(data.items)) {
|
|
1332
|
+
setAuditError('audit')
|
|
1333
|
+
setAuditLoading(false)
|
|
1334
|
+
return
|
|
1335
|
+
}
|
|
1336
|
+
setAuditRows(data.items)
|
|
1337
|
+
setAuditSelectedId(data.items[0] ? data.items[0].id : null)
|
|
1338
|
+
setAuditCursor(data.nextCursor || null)
|
|
1339
|
+
setAuditHasMore(data.hasMore === true)
|
|
1340
|
+
setAuditLoading(false)
|
|
1341
|
+
setAuditError('')
|
|
1342
|
+
}, (reason) => {
|
|
1343
|
+
if (!recordsGate.isCurrent(seq)) return
|
|
1344
|
+
if (reason && reason.status === 409) {
|
|
1345
|
+
setAuditError('stale')
|
|
1346
|
+
setAuditReload((value) => value + 1)
|
|
1347
|
+
return
|
|
1348
|
+
}
|
|
1349
|
+
setAuditLoading(false)
|
|
1350
|
+
setAuditError('audit')
|
|
1351
|
+
})
|
|
1352
|
+
return undefined
|
|
1353
|
+
}, [detailKey, stats && stats.revision, auditReload])
|
|
1354
|
+
const loadMoreAudit = () => {
|
|
1355
|
+
if (selectedDetailScope === null || auditCursor === null || auditLoading) return
|
|
1356
|
+
const seq = recordsGate.next()
|
|
1357
|
+
setAuditLoading(true)
|
|
1358
|
+
getUsageRecords(selectedDetailScope, auditCursor, 20).then((data) => {
|
|
1359
|
+
if (!recordsGate.isCurrent(seq)) return
|
|
1360
|
+
if (data === null || typeof data !== 'object' || !Array.isArray(data.items)) {
|
|
1361
|
+
setAuditError('audit')
|
|
1362
|
+
setAuditLoading(false)
|
|
1363
|
+
return
|
|
1364
|
+
}
|
|
1365
|
+
setAuditRows((prev) => prev.concat(data.items))
|
|
1366
|
+
setAuditCursor(data.nextCursor || null)
|
|
1367
|
+
setAuditHasMore(data.hasMore === true)
|
|
1368
|
+
setAuditLoading(false)
|
|
1369
|
+
setAuditError('')
|
|
1370
|
+
}, (reason) => {
|
|
1371
|
+
if (!recordsGate.isCurrent(seq)) return
|
|
1372
|
+
if (reason && reason.status === 409) {
|
|
1373
|
+
setAuditRows([])
|
|
1374
|
+
setAuditSelectedId(null)
|
|
1375
|
+
setAuditCursor(null)
|
|
1376
|
+
setAuditHasMore(false)
|
|
1377
|
+
setAuditError('stale')
|
|
1378
|
+
setAuditReload((value) => value + 1)
|
|
1379
|
+
return
|
|
1380
|
+
}
|
|
1381
|
+
setAuditLoading(false)
|
|
1382
|
+
setAuditError('audit')
|
|
1383
|
+
})
|
|
1384
|
+
}
|
|
1385
|
+
React.useEffect(() => {
|
|
1386
|
+
if (detailSelection === null || detailView !== 'logs' || recordsPanelRef.current === null) return undefined
|
|
1387
|
+
recordsPanelRef.current.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
|
1388
|
+
return undefined
|
|
1389
|
+
}, [detailSelection && usageScopeKey(detailSelection.scope), detailView])
|
|
1390
|
+
const onRefresh = () => { refreshRef.current() }
|
|
1391
|
+
const toggleFilter = (id) => {
|
|
1392
|
+
setWsFilter((prev) => (prev === id ? null : id))
|
|
1393
|
+
}
|
|
1394
|
+
const clearFilters = () => {
|
|
1395
|
+
setWsFilter(null)
|
|
1396
|
+
setProviderFilter(null)
|
|
1397
|
+
setModelFilter(null)
|
|
1398
|
+
}
|
|
1399
|
+
const chooseProvider = (value) => {
|
|
1400
|
+
setProviderFilter(value || null)
|
|
1401
|
+
}
|
|
1402
|
+
const chooseModel = (value) => {
|
|
1403
|
+
setModelFilter(value || null)
|
|
1404
|
+
}
|
|
1405
|
+
const activeDayRows = useUtc && Array.isArray(stats && stats.byDayUtc) ? stats.byDayUtc : (Array.isArray(stats && stats.byDay) ? stats.byDay : [])
|
|
1406
|
+
const availableDateRange = availableDateBounds(activeDayRows, latestCalendarDate)
|
|
1407
|
+
const earliestAvailableDate = availableDateRange.min
|
|
1408
|
+
const activeCustomRange = normalizeCustomRange(customRange, useUtc)
|
|
1409
|
+
const customDraftIssue = customRangeIssue(customDraft, earliestAvailableDate, latestCalendarDate, useUtc)
|
|
1410
|
+
const openCustomRange = () => {
|
|
1411
|
+
const current = normalizeCustomRange(customRange, useUtc)
|
|
1412
|
+
const defaultStart = fmtDate(shiftCalendarDate(calendarNow, -89, useUtc), useUtc)
|
|
1413
|
+
setCustomDraft(current || { start: defaultStart < earliestAvailableDate ? earliestAvailableDate : defaultStart, end: latestCalendarDate })
|
|
1414
|
+
setCustomRangeOpen(true)
|
|
1415
|
+
}
|
|
1416
|
+
const applyCustomRange = () => {
|
|
1417
|
+
if (customDraftIssue !== '') return
|
|
1418
|
+
const next = normalizeCustomRange(customDraft, useUtc)
|
|
1419
|
+
if (next === null) return
|
|
1420
|
+
setCustomRange(next)
|
|
1421
|
+
setRange('custom')
|
|
1422
|
+
setCustomRangeOpen(false)
|
|
1423
|
+
}
|
|
1424
|
+
const chooseRange = (next) => {
|
|
1425
|
+
setRange(next)
|
|
1426
|
+
setCustomRangeOpen(false)
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
const queryReady = queryResult !== null && queryResultKey === queryKey && queryResult.revision === (stats && stats.revision)
|
|
1430
|
+
const displayedDays = queryReady && Array.isArray(queryResult.daily) ? queryResult.daily : activeDayRows
|
|
1431
|
+
const displayedHeatmap = queryReady && Array.isArray(queryResult.heatmap) ? queryResult.heatmap : activeDayRows
|
|
1432
|
+
const activeCustomRangeKey = activeCustomRange === null ? '' : activeCustomRange.start + ':' + activeCustomRange.end
|
|
1433
|
+
const rangeOnlyAgg = React.useMemo(() => rangeAgg(stats, range, useUtc, activeCustomRange), [stats, range, useUtc, activeCustomRangeKey])
|
|
1434
|
+
const agg = React.useMemo(() => queryReady
|
|
1435
|
+
? { totals: queryResult.totals, perWs: queryResult.perWorkspace || [], perModel: queryResult.perModel || [] }
|
|
1436
|
+
: rangeOnlyAgg, [queryReady, queryResult, rangeOnlyAgg])
|
|
1437
|
+
const animatedTotal = useCountUp(agg.totals.input + agg.totals.output + agg.totals.cacheRead + agg.totals.cacheWrite + agg.totals.reasoning, timer)
|
|
1438
|
+
const animatedRate = useCountUp(Math.round(rateOf(agg.totals.input, agg.totals.cacheRead) * 10), timer)
|
|
1439
|
+
const scopedCountIsCalls = providerFilter !== null || modelFilter !== null
|
|
1440
|
+
const displayedCount = scopedCountIsCalls ? (agg.totals.calls || agg.totals.turns) : agg.totals.turns
|
|
1441
|
+
const animatedTurns = useCountUp(displayedCount, timer)
|
|
1442
|
+
const wsTotal = (w) => w.input + w.output + w.cacheRead + w.cacheWrite + w.reasoning
|
|
1443
|
+
const rows = React.useMemo(() => (Array.isArray(agg.perWs) ? agg.perWs : []).slice().sort((a, b) => wsTotal(b) - wsTotal(a)), [agg.perWs])
|
|
1444
|
+
const modelRows = React.useMemo(() => aggregateModelRows(agg.perModel || [], modelView, tr('未知供应商', 'Unknown provider'), tr('未知模型', 'Unknown model')).sort((a, b) => wsTotal(b) - wsTotal(a)), [agg.perModel, modelView, language])
|
|
1445
|
+
const rangeModelOptions = Array.isArray(rangeOnlyAgg.perModel) ? rangeOnlyAgg.perModel.filter((row) => row && typeof row === 'object') : []
|
|
1446
|
+
const providerOptions = Array.from(new Set(rangeModelOptions.map((row) => typeof row.provider === 'string' && row.provider !== '' ? row.provider : null).filter((value) => value !== null))).sort()
|
|
1447
|
+
const modelFilterValue = (row) => {
|
|
1448
|
+
const structured = typeof row.actualModel === 'string' && row.actualModel !== '' ? row.actualModel : typeof row.requestedModel === 'string' && row.requestedModel !== '' ? row.requestedModel : null
|
|
1449
|
+
if (structured !== null) return structured
|
|
1450
|
+
const display = typeof row.model === 'string' && row.model !== '' ? row.model : tr('未知模型', 'Unknown model')
|
|
1451
|
+
const separator = display.indexOf(' / ')
|
|
1452
|
+
const legacyProvider = separator > 0 ? display.slice(0, separator) : ''
|
|
1453
|
+
return separator > 0 && providerOptions.includes(legacyProvider) ? display.slice(separator + 3) : display
|
|
1454
|
+
}
|
|
1455
|
+
const modelOptions = Array.from(new Set(rangeModelOptions.map(modelFilterValue))).sort((a, b) => a.localeCompare(b))
|
|
1456
|
+
const workspaces = stats && Array.isArray(stats.workspaces) ? stats.workspaces : []
|
|
1457
|
+
const rangeWorkspaceTotals = new Map((Array.isArray(rangeOnlyAgg.perWs) ? rangeOnlyAgg.perWs : []).map((row) => [row.workspaceId, row]))
|
|
1458
|
+
const workspaceHasUsage = (row) => row !== undefined && (Number(row.turns) > 0 || Number(row.calls) > 0 || Number(row.input) > 0 || Number(row.output) > 0 || Number(row.cacheRead) > 0 || Number(row.cacheWrite) > 0 || Number(row.reasoning) > 0)
|
|
1459
|
+
const rangeWorkspaceOptions = workspaces.filter((workspace) => workspaceHasUsage(rangeWorkspaceTotals.get(workspace.id)))
|
|
1460
|
+
const rangeWorkspaceIds = new Set(rangeWorkspaceOptions.map((workspace) => workspace.id))
|
|
1461
|
+
React.useEffect(() => {
|
|
1462
|
+
if (wsFilter !== null && !rangeWorkspaceIds.has(wsFilter)) setWsFilter(null)
|
|
1463
|
+
if (providerFilter !== null && !providerOptions.includes(providerFilter)) setProviderFilter(null)
|
|
1464
|
+
if (modelFilter !== null && !modelOptions.includes(modelFilter)) setModelFilter(null)
|
|
1465
|
+
}, [wsFilter, providerFilter, modelFilter, Array.from(rangeWorkspaceIds).sort().join('\0'), providerOptions.join('\0'), modelOptions.join('\0')])
|
|
1466
|
+
|
|
1467
|
+
if (stats === null) {
|
|
1468
|
+
const failed = statsError !== ''
|
|
1469
|
+
return React.createElement('div', { className: 'uh-page' },
|
|
1470
|
+
React.createElement('div', { className: 'uh-panel' },
|
|
1471
|
+
React.createElement('div', { className: 'uh-empty' }, failed
|
|
1472
|
+
? tr('无法加载用量统计。请重试。', 'Unable to load usage statistics. Please retry.')
|
|
1473
|
+
: tr('正在加载用量统计…', 'Loading usage statistics…'),
|
|
1474
|
+
),
|
|
1475
|
+
failed ? React.createElement('div', { style: { textAlign: 'center' } },
|
|
1476
|
+
React.createElement('button', { className: 'uh-refresh', onClick: onRefresh }, React.createElement(LineIcon, { name: 'refresh', size: 14 }), tr('重试', 'Retry')),
|
|
1477
|
+
) : null,
|
|
1478
|
+
),
|
|
1479
|
+
)
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
const statusPayload = status !== null && typeof status === 'object' ? status : stats
|
|
1483
|
+
const scan = statusPayload && statusPayload.scan ? statusPayload.scan : (stats.scan || { done: true, started: true, scanned: 0, total: 0, failed: 0 })
|
|
1484
|
+
const sync = statusPayload && statusPayload.sync ? statusPayload.sync : (stats.sync || {})
|
|
1485
|
+
const aliases = stats.aliases && typeof stats.aliases === 'object' ? stats.aliases : {}
|
|
1486
|
+
const wsById = new Map()
|
|
1487
|
+
const wsIndex = new Map()
|
|
1488
|
+
workspaces.forEach((w, i) => { wsById.set(w.id, w); wsIndex.set(w.id, i) })
|
|
1489
|
+
const dayRows = displayedDays
|
|
1490
|
+
const heatmapMap = new Map()
|
|
1491
|
+
for (const d of displayedHeatmap) heatmapMap.set(d.date, d)
|
|
1492
|
+
const dayMap = new Map()
|
|
1493
|
+
for (const d of activeDayRows) dayMap.set(d.date, d)
|
|
1494
|
+
const wsTitle = (id) => {
|
|
1495
|
+
const alias = aliases[id]
|
|
1496
|
+
if (typeof alias === 'string' && alias !== '') return alias
|
|
1497
|
+
const meta = wsById.get(id)
|
|
1498
|
+
return meta ? meta.title : tr('未知工作区', 'Unknown workspace')
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
const saveAlias = (wsId, value) => {
|
|
1502
|
+
const requestToken = typeof stats.requestToken === 'string' ? stats.requestToken : ''
|
|
1503
|
+
if (requestToken === '') return
|
|
1504
|
+
setAliasRpc(wsId, String(value === undefined ? '' : value).trim(), requestToken).then((res) => {
|
|
1505
|
+
if (res && res.ok && res.aliases) {
|
|
1506
|
+
setStats((prev) => (prev === null ? prev : Object.assign({}, prev, { aliases: res.aliases })))
|
|
1507
|
+
}
|
|
1508
|
+
}, () => {})
|
|
1509
|
+
}
|
|
1510
|
+
const openAliasPanel = () => {
|
|
1511
|
+
const drafts = {}
|
|
1512
|
+
workspaces.forEach((w) => { drafts[w.id] = typeof aliases[w.id] === 'string' ? aliases[w.id] : '' })
|
|
1513
|
+
setAliasDrafts(drafts)
|
|
1514
|
+
setAliasOpen(true)
|
|
1515
|
+
}
|
|
1516
|
+
const saveAllAliases = () => {
|
|
1517
|
+
for (const id of Object.keys(aliasDrafts)) {
|
|
1518
|
+
const current = typeof aliases[id] === 'string' ? aliases[id] : ''
|
|
1519
|
+
if (aliasDrafts[id] !== current) saveAlias(id, aliasDrafts[id])
|
|
1520
|
+
}
|
|
1521
|
+
setAliasOpen(false)
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
const totalTokens = agg.totals.input + agg.totals.output + agg.totals.cacheRead + agg.totals.cacheWrite + agg.totals.reasoning
|
|
1525
|
+
const cacheRate = rateOf(agg.totals.input, agg.totals.cacheRead)
|
|
1526
|
+
const st = streaks(dayMap, useUtc)
|
|
1527
|
+
|
|
1528
|
+
const today = calendarNow
|
|
1529
|
+
const todayKey = latestCalendarDate
|
|
1530
|
+
const todayWeekday = useUtc ? today.getUTCDay() : today.getDay()
|
|
1531
|
+
const sunday = shiftCalendarDate(today, -todayWeekday, useUtc)
|
|
1532
|
+
const start = shiftCalendarDate(sunday, -52 * 7, useUtc)
|
|
1533
|
+
const cells = []
|
|
1534
|
+
for (let i = 0; i < 53 * 7; i++) {
|
|
1535
|
+
const d = shiftCalendarDate(start, i, useUtc)
|
|
1536
|
+
cells.push({ date: fmtDate(d, useUtc), month: useUtc ? d.getUTCMonth() : d.getMonth(), year: useUtc ? d.getUTCFullYear() : d.getFullYear() })
|
|
1537
|
+
}
|
|
1538
|
+
const monthLabels = []
|
|
1539
|
+
for (let j = 0; j < 53; j++) {
|
|
1540
|
+
const first = cells[j * 7]
|
|
1541
|
+
const prev = j > 0 ? cells[(j - 1) * 7] : null
|
|
1542
|
+
if (prev === null || first.month !== prev.month) {
|
|
1543
|
+
monthLabels.push({ left: (j * 100 / 53) + '%', text: monthLabel(first.year, first.month, language) })
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
const weekdayLabels = language === 'en' ? ['', 'Mon', '', 'Wed', '', 'Fri', ''] : ['', '周一', '', '周三', '', '周五', '']
|
|
1547
|
+
|
|
1548
|
+
const onEnter = (cell, ev) => {
|
|
1549
|
+
setHover({ date: cell.date, x: ev.clientX, y: ev.clientY, day: heatmapMap.get(cell.date) })
|
|
1550
|
+
}
|
|
1551
|
+
const onMove = (cell, ev) => {
|
|
1552
|
+
setHover((prev) => (prev !== null && prev.date === cell.date ? { date: prev.date, x: ev.clientX, y: ev.clientY, day: prev.day } : prev))
|
|
1553
|
+
}
|
|
1554
|
+
const onLeave = () => setHover(null)
|
|
1555
|
+
|
|
1556
|
+
const cellElements = cells.map((cell, i) => {
|
|
1557
|
+
const day = heatmapMap.get(cell.date)
|
|
1558
|
+
let count = 0
|
|
1559
|
+
if (day !== undefined) {
|
|
1560
|
+
if (queryReady || wsFilter === null) count = day.turns
|
|
1561
|
+
else {
|
|
1562
|
+
const w = Array.isArray(day.perWorkspace) ? day.perWorkspace.find((x) => x.workspaceId === wsFilter) : undefined
|
|
1563
|
+
if (w !== undefined) count = w.turns
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
const level = levelOf(count)
|
|
1567
|
+
const dim = wsFilter !== null && day !== undefined && day.turns > 0 && count === 0
|
|
1568
|
+
const isToday = cell.date === todayKey
|
|
1569
|
+
const style = {
|
|
1570
|
+
background: cellBg(level),
|
|
1571
|
+
opacity: dim ? 0.22 : 1,
|
|
1572
|
+
animationDelay: (i * 1.2) + 'ms',
|
|
1573
|
+
}
|
|
1574
|
+
if (isToday) style.animation = 'uh-cell-in .45s ease both, uh-glow 3s ease-in-out .7s infinite'
|
|
1575
|
+
return React.createElement('div', {
|
|
1576
|
+
key: cell.date,
|
|
1577
|
+
className: 'uh-cell',
|
|
1578
|
+
style,
|
|
1579
|
+
onMouseEnter: (ev) => onEnter(cell, ev),
|
|
1580
|
+
onMouseMove: (ev) => onMove(cell, ev),
|
|
1581
|
+
onMouseLeave: onLeave,
|
|
1582
|
+
onClick: () => openAuditForDate(cell.date),
|
|
1583
|
+
})
|
|
1584
|
+
})
|
|
1585
|
+
|
|
1586
|
+
let balanceValue = '—'
|
|
1587
|
+
let balanceSub = tr('查询中…', 'Checking…')
|
|
1588
|
+
if (balance !== null && balance !== undefined) {
|
|
1589
|
+
if (balance.status === 'missing-key') {
|
|
1590
|
+
balanceValue = tr('未配置', 'Not configured')
|
|
1591
|
+
balanceSub = tr('在 设置 → 模型 中填写 DeepSeek API Key 后可见', 'Available after you enter a DeepSeek API key in Settings → Models')
|
|
1592
|
+
} else if (balance.status === 'unavailable') {
|
|
1593
|
+
balanceValue = tr('不可用', 'Unavailable')
|
|
1594
|
+
balanceSub = balance.message || tr('DeepSeek 接口返回余额不可用', 'The DeepSeek API reported that balance information is unavailable')
|
|
1595
|
+
} else if (balance.status === 'error') {
|
|
1596
|
+
balanceValue = tr('查询失败', 'Lookup failed')
|
|
1597
|
+
const detail = balance.detail ? (language === 'en' ? ' (' + String(balance.detail).slice(0, 90) + ')' : '(' + String(balance.detail).slice(0, 90) + ')') : ''
|
|
1598
|
+
balanceSub = (balance.message || '') + detail + tr(' 点“刷新”重试', ' Click Refresh to try again')
|
|
1599
|
+
} else if (balance.status === 'ok' && Array.isArray(balance.currencies) && balance.currencies.length > 0) {
|
|
1600
|
+
const list = balance.currencies
|
|
1601
|
+
const primary = list.find((c) => c.currency === 'CNY') || list[0]
|
|
1602
|
+
const others = list.filter((c) => c !== primary)
|
|
1603
|
+
balanceValue = money(primary.currency, primary.total, language)
|
|
1604
|
+
let sub = primary.total !== null ? tr('赠送 ', 'Granted ') + money(primary.currency, primary.granted, language) + ' · ' + tr('充值 ', 'Top-up ') + money(primary.currency, primary.toppedUp, language) : ''
|
|
1605
|
+
if (others.length > 0) sub += (sub ? ' | ' : '') + others.map((c) => money(c.currency, c.total, language)).join(' ')
|
|
1606
|
+
balanceSub = sub
|
|
1607
|
+
} else {
|
|
1608
|
+
balanceValue = tr('无数据', 'No data')
|
|
1609
|
+
balanceSub = ''
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
const card = (label, value, sub, delay, icon) => React.createElement('div', { className: 'uh-card', style: { animationDelay: (delay * 70) + 'ms' } },
|
|
1614
|
+
React.createElement('div', { className: 'uh-card-label' }, icon ? React.createElement(LineIcon, { name: icon, size: 14 }) : null, label),
|
|
1615
|
+
React.createElement('div', { className: 'uh-card-value' }, value),
|
|
1616
|
+
React.createElement('div', { className: 'uh-card-sub' }, sub),
|
|
1617
|
+
)
|
|
1618
|
+
|
|
1619
|
+
const maxTotal = rows.length > 0 ? wsTotal(rows[0]) : 0
|
|
1620
|
+
|
|
1621
|
+
const tokenCardRows = rows.slice(0, 3).map((w) => {
|
|
1622
|
+
const total = wsTotal(w)
|
|
1623
|
+
const idx = wsIndex.get(w.workspaceId)
|
|
1624
|
+
const color = wsColor(idx === undefined ? 0 : idx)
|
|
1625
|
+
const selected = wsFilter === w.workspaceId
|
|
1626
|
+
return React.createElement('div', {
|
|
1627
|
+
key: w.workspaceId,
|
|
1628
|
+
className: 'uh-wsbar' + (selected ? ' uh-sel' : ''),
|
|
1629
|
+
onClick: () => toggleFilter(w.workspaceId),
|
|
1630
|
+
},
|
|
1631
|
+
React.createElement('div', { className: 'uh-wsbar-top' },
|
|
1632
|
+
React.createElement('span', { className: 'uh-dot', style: { background: color } }),
|
|
1633
|
+
React.createElement('span', { className: 'uh-wsbar-title' }, wsTitle(w.workspaceId)),
|
|
1634
|
+
React.createElement('span', { className: 'uh-wsbar-num' }, valueWithMagnitude(fmtCompact(total), total, language)),
|
|
1635
|
+
),
|
|
1636
|
+
React.createElement('div', { className: 'uh-barwrap uh-bar-thin' },
|
|
1637
|
+
React.createElement('div', { className: 'uh-barfill', style: { width: maxTotal > 0 ? Math.max(2, (total / maxTotal) * 100) + '%' : '0%', background: color } }),
|
|
1638
|
+
),
|
|
1639
|
+
)
|
|
1640
|
+
})
|
|
1641
|
+
const tokenCard = React.createElement('div', { className: 'uh-card', style: { animationDelay: '210ms' } },
|
|
1642
|
+
React.createElement('div', { className: 'uh-card-label' }, React.createElement(LineIcon, { name: 'folder', size: 14 }), tr('各工作区总处理量', 'Total Tokens Processed by Workspace')),
|
|
1643
|
+
rows.length === 0
|
|
1644
|
+
? React.createElement('div', { className: 'uh-empty', style: { padding: '8px 0' } }, tr('暂无数据', 'No data yet'))
|
|
1645
|
+
: React.createElement('div', { className: 'uh-wsbars' },
|
|
1646
|
+
tokenCardRows,
|
|
1647
|
+
rows.length > 3 ? React.createElement('div', { className: 'uh-card-sub' }, language === 'en' ? 'See the details table for the other ' + (rows.length - 3) + ' workspaces' : '其余 ' + (rows.length - 3) + ' 个工作区见明细表') : null,
|
|
1648
|
+
),
|
|
1649
|
+
)
|
|
1650
|
+
|
|
1651
|
+
const rowElements = rows.map((w) => {
|
|
1652
|
+
const meta = wsById.get(w.workspaceId)
|
|
1653
|
+
const alias = typeof aliases[w.workspaceId] === 'string' ? aliases[w.workspaceId] : ''
|
|
1654
|
+
const folderTitle = meta ? meta.title : tr('未知工作区', 'Unknown workspace')
|
|
1655
|
+
const path = meta ? meta.path : ''
|
|
1656
|
+
const title = alias !== '' ? alias : folderTitle
|
|
1657
|
+
const subText = alias !== '' ? folderTitle + ' · ' + path : path
|
|
1658
|
+
const total = wsTotal(w)
|
|
1659
|
+
const rate = rateOf(w.input, w.cacheRead)
|
|
1660
|
+
const idx = wsIndex.get(w.workspaceId)
|
|
1661
|
+
const color = wsColor(idx === undefined ? 0 : idx)
|
|
1662
|
+
const selected = wsFilter === w.workspaceId
|
|
1663
|
+
return React.createElement('div', {
|
|
1664
|
+
key: w.workspaceId,
|
|
1665
|
+
className: 'uh-row' + (selected ? ' uh-sel' : ''),
|
|
1666
|
+
onClick: () => toggleFilter(w.workspaceId),
|
|
1667
|
+
},
|
|
1668
|
+
React.createElement('div', { className: 'uh-row-title-wrap' },
|
|
1669
|
+
React.createElement('div', { className: 'uh-ws-title' }, title),
|
|
1670
|
+
React.createElement('div', { className: 'uh-ws-path' }, subText),
|
|
1671
|
+
),
|
|
1672
|
+
React.createElement('div', { className: 'uh-num' }, fmtCompact(w.turns)),
|
|
1673
|
+
React.createElement('div', { className: 'uh-num' }, fmtCompact(w.input)),
|
|
1674
|
+
React.createElement('div', { className: 'uh-num' }, fmtCompact(w.cacheRead)),
|
|
1675
|
+
React.createElement('div', { className: 'uh-num' }, fmtCompact(w.output)),
|
|
1676
|
+
React.createElement('div', { className: 'uh-num' }, fmtCompact(w.reasoning)),
|
|
1677
|
+
React.createElement('div', {},
|
|
1678
|
+
React.createElement('div', { className: 'uh-num' }, fmtCompact(total)),
|
|
1679
|
+
React.createElement('div', { className: 'uh-barwrap' },
|
|
1680
|
+
React.createElement('div', { className: 'uh-barfill', style: { width: maxTotal > 0 ? Math.max(2, (total / maxTotal) * 100) + '%' : '0%', background: color } }),
|
|
1681
|
+
),
|
|
1682
|
+
),
|
|
1683
|
+
React.createElement('div', { className: 'uh-num' }, rate.toFixed(1) + '%'),
|
|
1684
|
+
React.createElement('div', { className: 'uh-num' }, maxTotal > 0 ? ((total / maxTotal) * 100).toFixed(0) + '%' : '0%'),
|
|
1685
|
+
)
|
|
1686
|
+
})
|
|
1687
|
+
|
|
1688
|
+
const modelViewLabel = modelView === 'route' ? tr('混合查看', 'Combined View') : modelView === 'model' ? tr('按模型合并', 'Grouped by Model') : tr('按供应商汇总', 'Grouped by Provider')
|
|
1689
|
+
const modelColumnLabel = modelView === 'route' ? tr('供应商 / 模型', 'Provider / Model') : modelView === 'model' ? tr('模型', 'Model') : tr('供应商', 'Provider')
|
|
1690
|
+
const modelDonutChart = detailView !== 'model' || modelRows.length === 0 ? null : React.createElement(UsageDonutChart, {
|
|
1691
|
+
key: 'model-donut-' + detailView + ':' + queryKey + ':' + stats.revision + ':' + modelView,
|
|
1692
|
+
title: modelView === 'provider' ? tr('供应商用量', 'Provider Usage') : tr('模型用量', 'Model Usage'),
|
|
1693
|
+
icon: 'chart',
|
|
1694
|
+
language,
|
|
1695
|
+
items: modelRows.map((row, index) => ({ label: row.model, value: wsTotal(row), color: DONUT_COLORS[index % DONUT_COLORS.length] })),
|
|
1696
|
+
})
|
|
1697
|
+
const workspaceDonutChart = detailView !== 'workspace' || rows.length === 0 ? null : React.createElement(UsageDonutChart, {
|
|
1698
|
+
key: 'workspace-donut-' + detailView + ':' + queryKey + ':' + stats.revision,
|
|
1699
|
+
title: tr('工作区用量', 'Workspace Usage'),
|
|
1700
|
+
icon: 'folder',
|
|
1701
|
+
language,
|
|
1702
|
+
items: rows.map((row, index) => ({ label: wsTitle(row.workspaceId), value: wsTotal(row), color: DONUT_COLORS[index % DONUT_COLORS.length] })),
|
|
1703
|
+
})
|
|
1704
|
+
const exportCsv = () => {
|
|
1705
|
+
const quote = (value) => '"' + String(value === undefined || value === null ? '' : value).replace(/"/g, '""') + '"'
|
|
1706
|
+
const line = (values) => values.map(quote).join(',')
|
|
1707
|
+
const allTokens = (entry) => entry.input + entry.output + entry.cacheRead + entry.cacheWrite + entry.reasoning
|
|
1708
|
+
const tokenHeaders = [tr('输入 Token', 'Input Tokens'), tr('缓存命中 Token', 'Cache-Hit Tokens'), tr('缓存写入 Token', 'Cache-Write Tokens'), tr('输出 Token', 'Output Tokens'), tr('推理 Token', 'Reasoning Tokens'), tr('总处理 Token', 'Total Tokens Processed'), tr('缓存命中率', 'Cache Hit Rate')]
|
|
1709
|
+
const output = [
|
|
1710
|
+
line([tr('DSH 用量统计导出', 'DSH Usage Statistics Export')]),
|
|
1711
|
+
line([tr('导出时间', 'Exported At'), useUtc ? new Date().toLocaleString('en-US', { timeZone: 'UTC', timeZoneName: 'short' }) : new Date().toLocaleString('zh-CN')]),
|
|
1712
|
+
line([tr('时间范围', 'Time Range'), rangeLabel]),
|
|
1713
|
+
line([tr('时区', 'Timezone'), useUtc ? 'UTC' : tr('本地', 'Local')]),
|
|
1714
|
+
line([tr('工作区筛选', 'Workspace Filter'), wsFilter || tr('全部', 'All')]),
|
|
1715
|
+
line([tr('供应商筛选', 'Provider Filter'), providerFilter || tr('全部', 'All')]),
|
|
1716
|
+
line([tr('模型筛选', 'Model Filter'), modelFilter || tr('全部', 'All')]),
|
|
1717
|
+
line([tr('统计 revision', 'Stats Revision'), stats.revision || '']),
|
|
1718
|
+
line([tr('模型查看模式', 'Model View Mode'), modelViewLabel]),
|
|
1719
|
+
'',
|
|
1720
|
+
line([tr('汇总', 'Summary')]),
|
|
1721
|
+
line([tr('回合', 'Turns'), tr('会话', 'Sessions'), ...tokenHeaders]),
|
|
1722
|
+
line([agg.totals.turns, agg.totals.sessions, agg.totals.input, agg.totals.cacheRead, agg.totals.cacheWrite, agg.totals.output, agg.totals.reasoning, allTokens(agg.totals), rateOf(agg.totals.input, agg.totals.cacheRead).toFixed(2) + '%']),
|
|
1723
|
+
'',
|
|
1724
|
+
line([tr('模型用量明细', 'Model Usage Details')]),
|
|
1725
|
+
line([modelColumnLabel, tr('调用', 'Calls'), ...tokenHeaders]),
|
|
1726
|
+
...modelRows.map((m) => line([m.model, m.calls, m.input, m.cacheRead, m.cacheWrite, m.output, m.reasoning, allTokens(m), rateOf(m.input, m.cacheRead).toFixed(2) + '%'])),
|
|
1727
|
+
'',
|
|
1728
|
+
line([tr('工作区明细', 'Workspace Details')]),
|
|
1729
|
+
line([tr('工作区', 'Workspace'), tr('路径', 'Path'), tr('回合', 'Turns'), ...tokenHeaders]),
|
|
1730
|
+
...rows.map((w) => { const meta = wsById.get(w.workspaceId); return line([wsTitle(w.workspaceId), meta ? meta.path : '', w.turns, w.input, w.cacheRead, w.cacheWrite, w.output, w.reasoning, allTokens(w), rateOf(w.input, w.cacheRead).toFixed(2) + '%']) }),
|
|
1731
|
+
]
|
|
1732
|
+
const blob = new Blob(['\uFEFF' + output.join('\r\n')], { type: 'text/csv;charset=utf-8' })
|
|
1733
|
+
const url = URL.createObjectURL(blob)
|
|
1734
|
+
const anchor = document.createElement('a')
|
|
1735
|
+
anchor.href = url
|
|
1736
|
+
anchor.download = 'dsh-all-usage-' + rangeFilePart + '-' + modelView + '-' + fmtDate(new Date(), useUtc) + '.csv'
|
|
1737
|
+
document.body.appendChild(anchor); anchor.click(); anchor.remove()
|
|
1738
|
+
URL.revokeObjectURL(url)
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
const modelElements = detailView === 'model' ? modelRows.map((m) => {
|
|
1742
|
+
const total = wsTotal(m)
|
|
1743
|
+
const rate = rateOf(m.input, m.cacheRead)
|
|
1744
|
+
return React.createElement('div', { key: m.identityKey || m.model, className: 'uh-model-row uh-row' },
|
|
1745
|
+
React.createElement('div', { className: 'uh-row-title-wrap' },
|
|
1746
|
+
React.createElement('div', { className: 'uh-ws-title', title: m.model }, m.model),
|
|
1747
|
+
),
|
|
1748
|
+
React.createElement('div', { className: 'uh-num' }, fmtCompact(m.calls)),
|
|
1749
|
+
React.createElement('div', { className: 'uh-num' }, fmtCompact(m.input)),
|
|
1750
|
+
React.createElement('div', { className: 'uh-num' }, fmtCompact(m.cacheRead)),
|
|
1751
|
+
React.createElement('div', { className: 'uh-num' }, fmtCompact(m.output)),
|
|
1752
|
+
React.createElement('div', { className: 'uh-num' }, fmtCompact(m.reasoning)),
|
|
1753
|
+
React.createElement('div', { className: 'uh-num' }, fmtCompact(total)),
|
|
1754
|
+
React.createElement('div', { className: 'uh-num' }, rate.toFixed(1) + '%'),
|
|
1755
|
+
)
|
|
1756
|
+
}) : []
|
|
1757
|
+
|
|
1758
|
+
const aliasPanel = aliasOpen
|
|
1759
|
+
? React.createElement('div', { className: 'uh-panel uh-anim-panel' },
|
|
1760
|
+
React.createElement('div', { className: 'uh-alias-panel-head' },
|
|
1761
|
+
React.createElement('span', {}, tr('工作区别名', 'Workspace Aliases')),
|
|
1762
|
+
React.createElement('button', { className: 'uh-alias-close', onClick: () => setAliasOpen(false) }, tr('关闭', 'Close')),
|
|
1763
|
+
),
|
|
1764
|
+
workspaces.length === 0
|
|
1765
|
+
? React.createElement('div', { className: 'uh-empty', style: { padding: '10px 0' } }, tr('暂无工作区', 'No workspaces yet'))
|
|
1766
|
+
: React.createElement('div', { className: 'uh-alias-list' },
|
|
1767
|
+
workspaces.map((w, i) => React.createElement('div', { key: w.id, className: 'uh-alias-item' },
|
|
1768
|
+
React.createElement('span', { className: 'uh-dot', style: { background: wsColor(i) } }),
|
|
1769
|
+
React.createElement('span', { className: 'uh-alias-folder', title: w.path }, w.title || w.path),
|
|
1770
|
+
React.createElement('input', {
|
|
1771
|
+
className: 'uh-alias-input',
|
|
1772
|
+
value: aliasDrafts[w.id] !== undefined ? aliasDrafts[w.id] : '',
|
|
1773
|
+
placeholder: tr('项目别名', 'Project alias'),
|
|
1774
|
+
onChange: (e) => setAliasDrafts((prev) => Object.assign({}, prev, { [w.id]: e.target.value })),
|
|
1775
|
+
onKeyDown: (e) => { if (e.key === 'Enter') saveAlias(w.id, e.target.value) },
|
|
1776
|
+
}),
|
|
1777
|
+
)),
|
|
1778
|
+
),
|
|
1779
|
+
React.createElement('div', { className: 'uh-alias-panel-foot' },
|
|
1780
|
+
React.createElement('span', { className: 'uh-note' }, tr('回车保存单个;清空别名还原文件夹名', 'Press Enter to save one; clear an alias to restore the folder name')),
|
|
1781
|
+
React.createElement('button', { className: 'uh-alias-ok', onClick: saveAllAliases }, tr('全部保存', 'Save All')),
|
|
1782
|
+
),
|
|
1783
|
+
)
|
|
1784
|
+
: null
|
|
1785
|
+
|
|
1786
|
+
let tip = null
|
|
1787
|
+
if (hover !== null && hover !== undefined) {
|
|
1788
|
+
const day = hover.day
|
|
1789
|
+
let rowsContent = []
|
|
1790
|
+
let tokensText = ''
|
|
1791
|
+
if (day !== undefined) {
|
|
1792
|
+
const sorted = (Array.isArray(day.perWorkspace) ? day.perWorkspace : []).slice().sort((a, b) => b.turns - a.turns)
|
|
1793
|
+
rowsContent = sorted.map((entry) => {
|
|
1794
|
+
const idx = wsIndex.get(entry.workspaceId)
|
|
1795
|
+
return React.createElement('div', {
|
|
1796
|
+
key: entry.workspaceId,
|
|
1797
|
+
className: 'uh-tip-row',
|
|
1798
|
+
onClick: () => { toggleFilter(entry.workspaceId); setHover(null) },
|
|
1799
|
+
},
|
|
1800
|
+
React.createElement('span', { className: 'uh-dot', style: { background: wsColor(idx === undefined ? 0 : idx) } }),
|
|
1801
|
+
React.createElement('span', {}, wsTitle(entry.workspaceId)),
|
|
1802
|
+
React.createElement('span', { className: 'uh-n' }, language === 'en' ? entry.turns + ' uses' : entry.turns + ' 次'),
|
|
1803
|
+
)
|
|
1804
|
+
})
|
|
1805
|
+
const dayTokenValues = rowTokens(day)
|
|
1806
|
+
if (dayTokenValues.input + dayTokenValues.output + dayTokenValues.cacheRead > 0) {
|
|
1807
|
+
tokensText = language === 'en' ? 'Tokens: Input ' + fmtCompact(dayTokenValues.input) + ' · Cache hits ' + fmtCompact(dayTokenValues.cacheRead) + ' · Output ' + fmtCompact(dayTokenValues.output) : 'Token:输入 ' + fmtCompact(dayTokenValues.input) + ' · 缓存命中 ' + fmtCompact(dayTokenValues.cacheRead) + ' · 输出 ' + fmtCompact(dayTokenValues.output)
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
const flip = hover.x > 640
|
|
1811
|
+
tip = React.createElement('div', {
|
|
1812
|
+
key: hover.date,
|
|
1813
|
+
className: 'uh-tip',
|
|
1814
|
+
style: {
|
|
1815
|
+
left: hover.x + 14,
|
|
1816
|
+
top: hover.y + 12,
|
|
1817
|
+
transform: flip ? 'translateX(calc(-100% - 28px))' : 'none',
|
|
1818
|
+
},
|
|
1819
|
+
},
|
|
1820
|
+
React.createElement('div', { className: 'uh-tip-date' }, humanDate(hover.date, language)),
|
|
1821
|
+
day !== undefined && day.turns > 0
|
|
1822
|
+
? rowsContent
|
|
1823
|
+
: React.createElement('div', { className: 'uh-empty', style: { padding: '6px 0' } }, tr('这一天没有使用记录', 'No usage records for this day')),
|
|
1824
|
+
tokensText !== '' ? React.createElement('div', { className: 'uh-tip-tokens' }, tokensText) : null,
|
|
1825
|
+
)
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
const rangeLabel = range === 'custom' && activeCustomRange !== null
|
|
1829
|
+
? (language === 'en' ? activeCustomRange.start + ' to ' + activeCustomRange.end + ' (UTC)' : activeCustomRange.start + ' 至 ' + activeCustomRange.end)
|
|
1830
|
+
: range === 'today' ? tr('今日', 'Today') : range === '30d' ? tr('近 30 天', 'Last 30 Days') : range === '90d' ? tr('近 90 天', 'Last 90 Days') : tr('全部', 'All Time')
|
|
1831
|
+
const rangeFilePart = rangeFilenamePart(range, activeCustomRange, useUtc)
|
|
1832
|
+
const customRangeErrorText = customDraftIssue === 'invalid'
|
|
1833
|
+
? tr('请选择有效的开始日期和结束日期', 'Choose valid start and end dates')
|
|
1834
|
+
: customDraftIssue === 'order'
|
|
1835
|
+
? tr('结束日期不能早于开始日期', 'End date must be on or after the start date')
|
|
1836
|
+
: customDraftIssue === 'bounds'
|
|
1837
|
+
? tr('可选范围为 ' + earliestAvailableDate + ' 至 ' + latestCalendarDate, 'Choose a date from ' + earliestAvailableDate + ' to ' + latestCalendarDate)
|
|
1838
|
+
: ''
|
|
1839
|
+
const customRangePanel = customRangeOpen ? React.createElement('div', { className: 'uh-custom-range', role: 'group', 'aria-label': tr('自定义时间范围', 'Custom date range') },
|
|
1840
|
+
React.createElement('div', { className: 'uh-custom-range-meta' },
|
|
1841
|
+
React.createElement('div', { className: 'uh-custom-range-title' }, React.createElement(LineIcon, { name: 'calendar', size: 15 }), tr('自定义时间范围', 'Custom date range')),
|
|
1842
|
+
React.createElement('div', { className: 'uh-custom-range-note' }, tr('可查看全部可扫描历史日数据;中文按本地日期,English 按 UTC。热力图始终展示最近 53 周。', 'All available historical daily data can be selected. Chinese uses local dates; English uses UTC. The heatmap always shows the latest 53 weeks.')),
|
|
1843
|
+
),
|
|
1844
|
+
React.createElement('div', { className: 'uh-custom-range-fields' },
|
|
1845
|
+
React.createElement('label', { className: 'uh-custom-range-field' },
|
|
1846
|
+
React.createElement('span', {}, tr('开始日期', 'Start date')),
|
|
1847
|
+
React.createElement('input', { type: 'date', value: customDraft.start, min: earliestAvailableDate, max: latestCalendarDate, onChange: (event) => setCustomDraft((prev) => Object.assign({}, prev, { start: event.target.value })) }),
|
|
1848
|
+
),
|
|
1849
|
+
React.createElement('label', { className: 'uh-custom-range-field' },
|
|
1850
|
+
React.createElement('span', {}, tr('结束日期', 'End date')),
|
|
1851
|
+
React.createElement('input', { type: 'date', value: customDraft.end, min: earliestAvailableDate, max: latestCalendarDate, onChange: (event) => setCustomDraft((prev) => Object.assign({}, prev, { end: event.target.value })) }),
|
|
1852
|
+
),
|
|
1853
|
+
),
|
|
1854
|
+
React.createElement('div', { className: 'uh-custom-range-actions' },
|
|
1855
|
+
React.createElement('button', { type: 'button', className: 'uh-custom-range-cancel', onClick: () => setCustomRangeOpen(false) }, tr('取消', 'Cancel')),
|
|
1856
|
+
React.createElement('button', { type: 'button', className: 'uh-custom-range-apply', disabled: customDraftIssue !== '', onClick: applyCustomRange }, tr('应用', 'Apply')),
|
|
1857
|
+
),
|
|
1858
|
+
customRangeErrorText !== '' ? React.createElement('div', { className: 'uh-custom-range-error', role: 'alert' }, customRangeErrorText) : null,
|
|
1859
|
+
) : null
|
|
1860
|
+
const trendBounds = queryScope !== null ? { start: queryScope.start, end: queryScope.end } : resolveRangeBounds(stats, range, useUtc, activeCustomRange)
|
|
1861
|
+
const hourlyTrendRows = queryReady && queryScope !== null && queryScope.start === queryScope.end && queryResult && Array.isArray(queryResult.hourly) ? buildTrendHourlyRows(queryResult.hourly, useUtc) : []
|
|
1862
|
+
const trendRows = hourlyTrendRows.length > 0 ? hourlyTrendRows : buildTrendRows(queryReady && queryResult && Array.isArray(queryResult.daily) ? queryResult.daily : activeDayRows, trendBounds, useUtc)
|
|
1863
|
+
const trendAnimationKey = queryReady && queryResult ? queryKey + ':' + queryResult.revision : queryKey
|
|
1864
|
+
const toggleTrendSeries = (key) => {
|
|
1865
|
+
setTrendVisible((prev) => {
|
|
1866
|
+
if (prev.includes(key)) return prev.length <= 1 ? prev : prev.filter((item) => item !== key)
|
|
1867
|
+
return prev.concat(key)
|
|
1868
|
+
})
|
|
1869
|
+
}
|
|
1870
|
+
const trendPanel = React.createElement(UsageTrendChart, {
|
|
1871
|
+
key: trendAnimationKey,
|
|
1872
|
+
rows: trendRows,
|
|
1873
|
+
visible: trendVisible,
|
|
1874
|
+
language,
|
|
1875
|
+
rangeLabel,
|
|
1876
|
+
loading: queryLoading && !queryReady,
|
|
1877
|
+
error: queryError !== '' && queryError !== 'stale' && !queryReady ? tr('趋势数据加载失败', 'Trend data unavailable') : '',
|
|
1878
|
+
onToggle: toggleTrendSeries,
|
|
1879
|
+
onPointClick: openAuditForDate,
|
|
1880
|
+
})
|
|
1881
|
+
const detailScopeLabel = selectedDetailScope === null
|
|
1882
|
+
? rangeLabel
|
|
1883
|
+
: selectedDetailScope.start === selectedDetailScope.end
|
|
1884
|
+
? selectedDetailScope.start
|
|
1885
|
+
: selectedDetailScope.start + ' → ' + selectedDetailScope.end
|
|
1886
|
+
const auditToken = (row, key) => Number(row && row.values && row.values[key]) || 0
|
|
1887
|
+
const auditTotal = (row) => auditToken(row, 'input') + auditToken(row, 'cacheRead') + auditToken(row, 'cacheWrite') + auditToken(row, 'output') + auditToken(row, 'reasoning')
|
|
1888
|
+
const auditSource = (row) => row && row.materialization === 'ledger-recovery' ? tr('账本恢复', 'Ledger recovery') : row && row.materialization === 'ledger-reuse' ? tr('账本复用', 'Ledger reuse') : row && row.materialization === 'scan' ? tr('扫描', 'Scan') : row && row.materialization === 'live' ? tr('实时', 'Live') : tr('未知', 'Unknown')
|
|
1889
|
+
const auditTime = (row, detailed) => row && Number.isFinite(row.time) ? new Date(row.time).toLocaleString(language === 'en' ? 'en-US' : 'zh-CN', language === 'en' ? (detailed ? { timeZone: 'UTC' } : { timeZone: 'UTC', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' }) : (detailed ? undefined : { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' })) : '—'
|
|
1890
|
+
const selectedAudit = auditRows.find((row) => row.id === auditSelectedId) || auditRows[0] || null
|
|
1891
|
+
const exportAuditCsv = async () => {
|
|
1892
|
+
if (selectedDetailScope === null || auditExporting) return
|
|
1893
|
+
setAuditExporting(true)
|
|
1894
|
+
setAuditError('')
|
|
1895
|
+
try {
|
|
1896
|
+
let cursor = null
|
|
1897
|
+
const all = []
|
|
1898
|
+
for (let page = 0; page < 50; page += 1) {
|
|
1899
|
+
const data = await getUsageRecords(selectedDetailScope, cursor, 200)
|
|
1900
|
+
if (data === null || typeof data !== 'object' || !Array.isArray(data.items)) throw new Error('audit export failed')
|
|
1901
|
+
all.push(...data.items)
|
|
1902
|
+
if (!data.hasMore || !data.nextCursor) break
|
|
1903
|
+
cursor = data.nextCursor
|
|
1904
|
+
}
|
|
1905
|
+
const quote = (value) => '"' + String(value === undefined || value === null ? '' : value).replace(/"/g, '""') + '"'
|
|
1906
|
+
const line = (values) => values.map(quote).join(',')
|
|
1907
|
+
const headers = [tr('时间', 'Time'), tr('日期', 'Date'), tr('Provider', 'Provider'), tr('请求模型', 'Requested model'), tr('实际模型', 'Actual model'), tr('显示模型', 'Display model'), 'turn', 'step', 'seq', tr('输入', 'Input'), tr('缓存命中', 'Cache read'), tr('缓存写入', 'Cache write'), tr('输出', 'Output'), tr('推理', 'Reasoning'), tr('来源', 'Source')]
|
|
1908
|
+
const lines = [line([tr('DSH 用量明细导出', 'DSH Usage Audit Export')]), line([tr('范围', 'Scope'), selectedDetailScope.start + ' → ' + selectedDetailScope.end]), line([tr('时区', 'Timezone'), selectedDetailScope.utc ? 'UTC' : tr('本地', 'Local')]), line(headers)]
|
|
1909
|
+
for (const row of all) lines.push(line([row.time, row.date, row.provider, row.requestedModel, row.actualModel, row.model, row.turn, row.step, row.seq, auditToken(row, 'input'), auditToken(row, 'cacheRead'), auditToken(row, 'cacheWrite'), auditToken(row, 'output'), auditToken(row, 'reasoning'), row.materialization || 'unknown']))
|
|
1910
|
+
const blob = new Blob(['\uFEFF' + lines.join('\r\n')], { type: 'text/csv;charset=utf-8' })
|
|
1911
|
+
const url = URL.createObjectURL(blob)
|
|
1912
|
+
const anchor = document.createElement('a')
|
|
1913
|
+
anchor.href = url
|
|
1914
|
+
anchor.download = 'dsh-all-usage-audit-' + selectedDetailScope.start + '-to-' + selectedDetailScope.end + '.csv'
|
|
1915
|
+
document.body.appendChild(anchor); anchor.click(); anchor.remove()
|
|
1916
|
+
URL.revokeObjectURL(url)
|
|
1917
|
+
} catch (err) {
|
|
1918
|
+
setAuditError('audit-export')
|
|
1919
|
+
} finally {
|
|
1920
|
+
setAuditExporting(false)
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
const recordsPanel = React.createElement('div', { className: 'uh-panel uh-records-panel', ref: recordsPanelRef, style: { display: detailView === 'logs' ? 'block' : 'none' } },
|
|
1924
|
+
React.createElement('div', { className: 'uh-records-head' },
|
|
1925
|
+
React.createElement('div', {},
|
|
1926
|
+
React.createElement('h3', { className: 'uh-tbl-title uh-title-with-icon' }, React.createElement(LineIcon, { name: 'list', size: 16 }), tr('请求日志', 'Request Logs')),
|
|
1927
|
+
React.createElement('div', { className: 'uh-note' }, detailScopeLabel + (selectedDetailScope && selectedDetailScope.utc ? ' · UTC' : '')),
|
|
1928
|
+
),
|
|
1929
|
+
React.createElement('div', { className: 'uh-actions' },
|
|
1930
|
+
auditLoading ? React.createElement('span', { className: 'uh-query-note' }, tr('同步中…', 'Refreshing…')) : null,
|
|
1931
|
+
React.createElement('button', { type: 'button', className: 'uh-refresh', title: tr('导出当前日志', 'Export current logs'), onClick: exportAuditCsv, disabled: auditExporting || selectedDetailScope === null }, React.createElement(LineIcon, { name: 'export', size: 13 }), auditExporting ? tr('导出中…', 'Exporting…') : tr('导出日志', 'Export logs')),
|
|
1932
|
+
),
|
|
1933
|
+
),
|
|
1934
|
+
auditError !== '' ? React.createElement('div', { className: 'uh-records-error', role: 'alert' }, auditError === 'stale' ? tr('数据已更新,正在重新加载日志…', 'Data changed; reloading logs…') : auditError === 'audit-export' ? tr('日志导出失败', 'Unable to export logs') : tr('日志加载失败,请重试', 'Unable to load logs')) : null,
|
|
1935
|
+
React.createElement('div', { className: 'uh-records-note' }, tr('按时间倒序显示可审计的 Token 调用;选择一行查看 turn / step 和完整 Token 分桶。', 'Token calls are newest first; select a row to inspect its turn / step and token buckets.')),
|
|
1936
|
+
auditRows.length === 0 && !auditLoading ? React.createElement('div', { className: 'uh-empty' }, tr('当前范围没有可审计的 Token 调用', 'No auditable Token calls in this scope')) : React.createElement('div', { className: 'uh-records-scroll' },
|
|
1937
|
+
React.createElement('div', { className: 'uh-record-grid uh-record-header' },
|
|
1938
|
+
React.createElement('div', {}, tr('时间', 'Time')), React.createElement('div', {}, tr('Provider / 模型', 'Provider / Model')), React.createElement('div', { className: 'uh-record-num' }, 'turn / step'), React.createElement('div', { className: 'uh-record-num' }, tr('输入', 'Input')), React.createElement('div', { className: 'uh-record-num' }, tr('缓存命中', 'Cache read')), React.createElement('div', { className: 'uh-record-num' }, tr('缓存写入', 'Cache write')), React.createElement('div', { className: 'uh-record-num' }, tr('输出', 'Output')), React.createElement('div', {}, tr('来源', 'Source')),
|
|
1939
|
+
),
|
|
1940
|
+
auditRows.map((row) => React.createElement('div', { key: row.id, className: 'uh-record-grid uh-record-row' + (selectedAudit && selectedAudit.id === row.id ? ' uh-on' : ''), role: 'button', tabIndex: 0, 'aria-pressed': selectedAudit && selectedAudit.id === row.id, onClick: () => setAuditSelectedId(row.id), onKeyDown: (event) => { if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); setAuditSelectedId(row.id) } } },
|
|
1941
|
+
React.createElement('div', { className: 'uh-record-time' }, auditTime(row, false)),
|
|
1942
|
+
React.createElement('div', { className: 'uh-record-model', title: row.model || '' }, row.model || tr('未知模型', 'Unknown model'), row.requestedModel && row.actualModel && row.requestedModel !== row.actualModel ? React.createElement('small', {}, row.requestedModel + ' → ' + row.actualModel) : null),
|
|
1943
|
+
React.createElement('div', { className: 'uh-record-num' }, (row.turn === null || row.turn === undefined ? '—' : row.turn) + ' / ' + (row.step === null || row.step === undefined ? '—' : row.step)),
|
|
1944
|
+
React.createElement('div', { className: 'uh-record-num' }, fmtCompact(auditToken(row, 'input'))),
|
|
1945
|
+
React.createElement('div', { className: 'uh-record-num' }, fmtCompact(auditToken(row, 'cacheRead'))),
|
|
1946
|
+
React.createElement('div', { className: 'uh-record-num' }, fmtCompact(auditToken(row, 'cacheWrite'))),
|
|
1947
|
+
React.createElement('div', { className: 'uh-record-num' }, fmtCompact(auditToken(row, 'output'))),
|
|
1948
|
+
React.createElement('div', { className: 'uh-record-source' }, auditSource(row)),
|
|
1949
|
+
)),
|
|
1950
|
+
),
|
|
1951
|
+
React.createElement('div', { className: 'uh-records-footer' },
|
|
1952
|
+
React.createElement('span', { className: 'uh-note' }, auditRows.length > 0 ? (auditHasMore ? tr('已显示 ' + auditRows.length + ' 条,继续加载可查看更多', auditRows.length + ' shown; load more for additional records') : tr('共显示 ' + auditRows.length + ' 条', auditRows.length + ' records shown')) : ''),
|
|
1953
|
+
auditHasMore ? React.createElement('button', { type: 'button', className: 'uh-refresh', onClick: loadMoreAudit, disabled: auditLoading }, auditLoading ? tr('加载中…', 'Loading…') : tr('加载更多', 'Load more')) : null,
|
|
1954
|
+
),
|
|
1955
|
+
selectedAudit ? React.createElement('div', { className: 'uh-record-detail' },
|
|
1956
|
+
React.createElement('div', { className: 'uh-record-detail-head' }, React.createElement('strong', {}, tr('选中调用', 'Selected call')), React.createElement('span', { className: 'uh-note' }, auditTime(selectedAudit, true))),
|
|
1957
|
+
React.createElement('div', { className: 'uh-record-detail-meta' },
|
|
1958
|
+
React.createElement('span', {}, (selectedAudit.provider || tr('未知供应商', 'Unknown provider')) + ' / ' + (selectedAudit.actualModel || selectedAudit.requestedModel || selectedAudit.model || tr('未知模型', 'Unknown model'))),
|
|
1959
|
+
React.createElement('span', {}, 'turn ' + (selectedAudit.turn === null || selectedAudit.turn === undefined ? '—' : selectedAudit.turn) + ' · step ' + (selectedAudit.step === null || selectedAudit.step === undefined ? '—' : selectedAudit.step)),
|
|
1960
|
+
React.createElement('span', {}, tr('来源:', 'Source: ') + auditSource(selectedAudit)),
|
|
1961
|
+
),
|
|
1962
|
+
React.createElement('div', { className: 'uh-record-token-strip' },
|
|
1963
|
+
['input', 'cacheRead', 'cacheWrite', 'output', 'reasoning'].map((key) => React.createElement('div', { key }, React.createElement('span', {}, key === 'cacheRead' ? tr('缓存命中', 'Cache read') : key === 'cacheWrite' ? tr('缓存写入', 'Cache write') : key === 'reasoning' ? tr('推理', 'Reasoning') : key === 'input' ? tr('输入', 'Input') : tr('输出', 'Output')), React.createElement('strong', {}, fmtCompact(auditToken(selectedAudit, key))))),
|
|
1964
|
+
React.createElement('div', { className: 'uh-record-token-total' }, React.createElement('span', {}, tr('总处理', 'Total')), React.createElement('strong', {}, fmtCompact(auditTotal(selectedAudit)))),
|
|
1965
|
+
),
|
|
1966
|
+
) : null,
|
|
1967
|
+
)
|
|
1968
|
+
const scanning = !scan.done
|
|
1969
|
+
const pct = scan.total > 0 ? Math.min(100, Math.round((scan.scanned / scan.total) * 100)) : 40
|
|
1970
|
+
const isEmpty = scan.done && dayRows.length === 0 && agg.totals.turns === 0 && agg.totals.calls === 0
|
|
1971
|
+
const syncCompletedAt = typeof sync.lastCompletedAt === 'number' && sync.lastCompletedAt > 0 ? new Date(sync.lastCompletedAt).toLocaleString(language === 'en' ? 'en-US' : 'zh-CN') : ''
|
|
1972
|
+
const lastStatsText = lastStatsAt > 0 ? new Date(lastStatsAt).toLocaleString(language === 'en' ? 'en-US' : 'zh-CN') : ''
|
|
1973
|
+
const healthTitle = syncCompletedAt === '' ? undefined : (language === 'en' ? 'Historical scan completed ' + syncCompletedAt : '历史扫描完成于 ' + syncCompletedAt)
|
|
1974
|
+
const healthText = language === 'en'
|
|
1975
|
+
? (lastStatsText !== '' ? 'Updated ' + lastStatsText : (scanning ? 'Refreshing data' : 'Update state pending'))
|
|
1976
|
+
+ ' · ' + (sync.sessionsSkippedByRevision || 0) + ' revision reused'
|
|
1977
|
+
+ ' · ' + (sync.sessionsRead || 0) + ' read'
|
|
1978
|
+
+ ((sync.sessionsRestoredFromLedger || 0) > 0 ? ' · ' + sync.sessionsRestoredFromLedger + ' ledger restored' : '')
|
|
1979
|
+
+ ((sync.sessionsFailed || 0) > 0 ? ' · ' + sync.sessionsFailed + ' failed' : '')
|
|
1980
|
+
+ ' · ' + (sync.persistenceSnapshotsAvailable === true ? 'revision optimization on' : 'full-read fallback')
|
|
1981
|
+
: (lastStatsText !== '' ? '已更新 ' + lastStatsText : (scanning ? '正在更新数据' : '数据更新准备中'))
|
|
1982
|
+
+ ' · revision 复用 ' + (sync.sessionsSkippedByRevision || 0)
|
|
1983
|
+
+ ' · 实际读取 ' + (sync.sessionsRead || 0)
|
|
1984
|
+
+ ((sync.sessionsRestoredFromLedger || 0) > 0 ? ' · 账本恢复 ' + sync.sessionsRestoredFromLedger : '')
|
|
1985
|
+
+ ((sync.sessionsFailed || 0) > 0 ? ' · 失败 ' + sync.sessionsFailed : '')
|
|
1986
|
+
+ ' · ' + (sync.persistenceSnapshotsAvailable === true ? '免读优化已启用' : '全量读取回退')
|
|
1987
|
+
const staleText = statsError === '' ? '' : (language === 'en'
|
|
1988
|
+
? 'Usage data may be stale' + (lastStatsText !== '' ? '; last full update ' + lastStatsText : '')
|
|
1989
|
+
: '用量数据可能已过期' + (lastStatsText !== '' ? ';上次完整更新 ' + lastStatsText : ''))
|
|
1990
|
+
|
|
1991
|
+
return React.createElement('div', { className: 'uh-page' },
|
|
1992
|
+
React.createElement('div', { className: 'uh-head' },
|
|
1993
|
+
React.createElement('div', { className: 'uh-title-wrap' },
|
|
1994
|
+
React.createElement('h2', { className: 'uh-title' }, tr('用量统计', 'Usage Statistics')),
|
|
1995
|
+
),
|
|
1996
|
+
React.createElement('div', { className: 'uh-actions' },
|
|
1997
|
+
React.createElement('button', {
|
|
1998
|
+
className: 'uh-refresh',
|
|
1999
|
+
title: tr('管理工作区别名', 'Manage workspace aliases'),
|
|
2000
|
+
onClick: () => { if (aliasOpen) setAliasOpen(false); else openAliasPanel() },
|
|
2001
|
+
}, React.createElement(LineIcon, { name: 'edit', size: 14 }), tr('工作区别名', 'Workspace Aliases')),
|
|
2002
|
+
React.createElement('div', {
|
|
2003
|
+
className: 'uh-language-menu' + (languageMenuOpen ? ' uh-open' : ''),
|
|
2004
|
+
ref: languageMenuRef,
|
|
2005
|
+
onKeyDown: (event) => { if (event.key === 'Escape') { event.preventDefault(); setLanguageMenuOpen(false) } },
|
|
2006
|
+
},
|
|
2007
|
+
React.createElement('button', {
|
|
2008
|
+
type: 'button',
|
|
2009
|
+
className: 'uh-language-trigger' + (languageMenuOpen ? ' uh-open' : ''),
|
|
2010
|
+
title: tr('切换界面语言', 'Change interface language'),
|
|
2011
|
+
'aria-label': tr('界面语言', 'Interface language'),
|
|
2012
|
+
'aria-haspopup': 'menu',
|
|
2013
|
+
'aria-expanded': languageMenuOpen,
|
|
2014
|
+
onClick: () => setLanguageMenuOpen((open) => !open),
|
|
2015
|
+
},
|
|
2016
|
+
React.createElement(LineIcon, { name: 'language', size: 14 }),
|
|
2017
|
+
React.createElement('span', { className: 'uh-language-label' }, language === 'en' ? 'English' : '中文'),
|
|
2018
|
+
React.createElement(LineIcon, { name: 'chevron', size: 13, className: 'uh-language-caret' }),
|
|
2019
|
+
),
|
|
2020
|
+
languageMenuOpen ? React.createElement('div', { className: 'uh-language-options', role: 'menu', 'aria-label': tr('界面语言', 'Interface language') },
|
|
2021
|
+
[['zh', '中文'], ['en', 'English']].map((entry) => React.createElement('button', {
|
|
2022
|
+
key: entry[0],
|
|
2023
|
+
type: 'button',
|
|
2024
|
+
role: 'menuitemradio',
|
|
2025
|
+
'aria-checked': language === entry[0],
|
|
2026
|
+
className: 'uh-language-option' + (language === entry[0] ? ' uh-on' : ''),
|
|
2027
|
+
onClick: () => chooseLanguage(entry[0]),
|
|
2028
|
+
},
|
|
2029
|
+
React.createElement(LineIcon, { name: 'language', size: 14 }),
|
|
2030
|
+
React.createElement('span', {}, entry[1]),
|
|
2031
|
+
language === entry[0] ? React.createElement(LineIcon, { name: 'check', size: 14, className: 'uh-language-option-check' }) : null,
|
|
2032
|
+
)),
|
|
2033
|
+
) : null,
|
|
2034
|
+
),
|
|
2035
|
+
React.createElement('div', { className: 'uh-range' },
|
|
2036
|
+
['today', '30d', '90d', 'all', 'custom'].map((r) => React.createElement('button', {
|
|
2037
|
+
key: r,
|
|
2038
|
+
type: 'button',
|
|
2039
|
+
className: range === r ? 'uh-on' : '',
|
|
2040
|
+
title: r === 'custom' && range === 'custom' ? rangeLabel : undefined,
|
|
2041
|
+
onClick: () => { if (r === 'custom') openCustomRange(); else chooseRange(r) },
|
|
2042
|
+
}, r === 'today' ? tr('今日', 'Today') : r === '30d' ? tr('近 30 天', 'Last 30 Days') : r === '90d' ? tr('近 90 天', 'Last 90 Days') : r === 'all' ? tr('全部', 'All Time') : tr('自定义', 'Custom'))),
|
|
2043
|
+
),
|
|
2044
|
+
React.createElement('button', { className: 'uh-refresh', title: tr('导出当前时间范围与模型查看模式的 CSV 数据', 'Export CSV data for the current time range and model view'), onClick: exportCsv }, React.createElement(LineIcon, { name: 'export', size: 14 }), tr('导出数据', 'Export Data')),
|
|
2045
|
+
React.createElement('button', { className: 'uh-refresh uh-icon-button', title: tr('刷新统计数据', 'Refresh usage statistics'), 'aria-label': tr('刷新统计数据', 'Refresh usage statistics'), onClick: onRefresh }, React.createElement(LineIcon, { name: 'refresh', size: 16 })),
|
|
2046
|
+
),
|
|
2047
|
+
),
|
|
2048
|
+
React.createElement('div', { className: 'uh-filter-bar', role: 'group', 'aria-label': tr('统一筛选', 'Unified filters') },
|
|
2049
|
+
React.createElement(UsageFilterMenu, {
|
|
2050
|
+
label: tr('全部工作区', 'All workspaces'),
|
|
2051
|
+
ariaLabel: tr('工作区筛选', 'Workspace filter'),
|
|
2052
|
+
className: 'uh-filter-workspace',
|
|
2053
|
+
icon: 'folder',
|
|
2054
|
+
value: wsFilter || '',
|
|
2055
|
+
options: [{ value: '', label: tr('全部工作区', 'All workspaces') }].concat(rangeWorkspaceOptions.map((w) => ({ value: w.id, label: wsTitle(w.id) }))),
|
|
2056
|
+
onChange: (value) => setWsFilter(value || null),
|
|
2057
|
+
}),
|
|
2058
|
+
React.createElement(UsageFilterMenu, {
|
|
2059
|
+
label: tr('全部供应商', 'All providers'),
|
|
2060
|
+
ariaLabel: tr('供应商筛选', 'Provider filter'),
|
|
2061
|
+
className: 'uh-filter-provider',
|
|
2062
|
+
icon: 'chart',
|
|
2063
|
+
value: providerFilter || '',
|
|
2064
|
+
options: [{ value: '', label: tr('全部供应商', 'All providers') }].concat(providerOptions.map((value) => ({ value, label: value }))),
|
|
2065
|
+
onChange: (value) => chooseProvider(value),
|
|
2066
|
+
}),
|
|
2067
|
+
React.createElement(UsageFilterMenu, {
|
|
2068
|
+
label: tr('全部模型', 'All models'),
|
|
2069
|
+
ariaLabel: tr('模型筛选', 'Model filter'),
|
|
2070
|
+
className: 'uh-filter-model',
|
|
2071
|
+
icon: 'cache',
|
|
2072
|
+
value: modelFilter || '',
|
|
2073
|
+
options: [{ value: '', label: tr('全部模型', 'All models') }].concat(modelOptions.map((value) => ({ value, label: value }))),
|
|
2074
|
+
onChange: (value) => chooseModel(value),
|
|
2075
|
+
}),
|
|
2076
|
+
(wsFilter !== null || providerFilter !== null || modelFilter !== null) ? React.createElement('button', { type: 'button', className: 'uh-filter-clear', onClick: clearFilters }, tr('清除筛选', 'Clear filters')) : null,
|
|
2077
|
+
queryLoading ? React.createElement('span', { className: 'uh-query-note' }, tr('正在更新筛选结果…', 'Updating filtered data…')) : null,
|
|
2078
|
+
queryError !== '' && queryError !== 'stale' ? React.createElement('span', { className: 'uh-query-note', role: 'alert' }, tr('筛选结果加载失败', 'Filtered data unavailable')) : null,
|
|
2079
|
+
),
|
|
2080
|
+
aliasOpen ? aliasPanel : null,
|
|
2081
|
+
customRangePanel,
|
|
2082
|
+
scanning ? React.createElement('div', { className: 'uh-progress' },
|
|
2083
|
+
React.createElement('span', {}, language === 'en' ? 'Scanning historical sessions: ' + scan.scanned + ' / ' + scan.total + (scan.failed > 0 ? ' (' + scan.failed + ' failed to read)' : '') : '正在统计历史会话 ' + scan.scanned + ' / ' + scan.total + (scan.failed > 0 ? '(' + scan.failed + ' 个读取失败)' : '')),
|
|
2084
|
+
React.createElement('div', { className: 'uh-bar' }, React.createElement('div', { className: 'uh-fill', style: { width: pct + '%' } })),
|
|
2085
|
+
) : null,
|
|
2086
|
+
React.createElement('div', { className: 'uh-sync-health' + (staleText !== '' ? ' uh-stale' : ''), title: staleText !== '' ? undefined : healthTitle },
|
|
2087
|
+
React.createElement(LineIcon, { name: staleText !== '' ? 'refresh' : 'clock', size: 14 }),
|
|
2088
|
+
React.createElement('span', {}, staleText !== '' ? staleText : healthText),
|
|
2089
|
+
staleText !== '' ? React.createElement('button', { className: 'uh-sync-retry', onClick: onRefresh }, tr('重试', 'Retry')) : null,
|
|
2090
|
+
),
|
|
2091
|
+
isEmpty ? React.createElement('div', { className: 'uh-panel' },
|
|
2092
|
+
React.createElement('div', { className: 'uh-empty' }, tr('还没有使用记录。开始对话后,这里会点亮。', 'No usage recorded yet. This area will light up after you start a conversation.')),
|
|
2093
|
+
) : React.createElement(React.Fragment, null,
|
|
2094
|
+
React.createElement(React.Fragment, null,
|
|
2095
|
+
React.createElement('div', { className: 'uh-ios-summary' },
|
|
2096
|
+
React.createElement('div', { className: 'uh-ios-summary-total' },
|
|
2097
|
+
React.createElement('div', { className: 'uh-ios-summary-label' }, React.createElement(LineIcon, { name: 'chart', size: 15 }), tr('总处理 Token', 'Total Tokens Processed')),
|
|
2098
|
+
React.createElement('div', { className: 'uh-ios-summary-value' }, valueWithMagnitude(fmtCompact(animatedTotal), agg.totals.input + agg.totals.output + agg.totals.cacheRead + agg.totals.cacheWrite + agg.totals.reasoning, language)),
|
|
2099
|
+
React.createElement('div', { className: 'uh-ios-summary-caption' }, language === 'en' ? rangeLabel + ' · ' + fmtCompact(animatedTurns) + (scopedCountIsCalls ? ' calls' : ' uses') + ' · includes cache reads/writes and reasoning' : rangeLabel + ' · ' + fmtCompact(animatedTurns) + (scopedCountIsCalls ? ' 次调用' : ' 次使用') + ' · 含缓存读写与推理'),
|
|
2100
|
+
),
|
|
2101
|
+
React.createElement('div', { className: 'uh-ios-summary-cache' },
|
|
2102
|
+
React.createElement('div', { className: 'uh-ios-summary-label' }, React.createElement(LineIcon, { name: 'cache', size: 15 }), tr('缓存命中', 'Cache Hits')),
|
|
2103
|
+
React.createElement('div', { className: 'uh-ios-summary-value' }, (animatedRate / 10).toFixed(1) + '%'),
|
|
2104
|
+
React.createElement('div', { className: 'uh-ios-summary-caption' }, language === 'en' ? fmtCompact(agg.totals.cacheRead) + ' context tokens reused' : '复用上下文 ' + fmtCompact(agg.totals.cacheRead) + ' Token'),
|
|
2105
|
+
),
|
|
2106
|
+
),
|
|
2107
|
+
React.createElement('div', { className: 'uh-token-semantics' },
|
|
2108
|
+
React.createElement(LineIcon, { name: 'cache', size: 16 }),
|
|
2109
|
+
tr('总处理 Token = 输入 + 输出 + 缓存读写 + 推理。缓存命中代表复用上下文,不等于新生成 Token 或实际费用。', 'Total tokens processed = input + output + cache reads/writes + reasoning. Cache hits represent reused context; they are not newly generated tokens or actual cost.'),
|
|
2110
|
+
),
|
|
2111
|
+
React.createElement('div', { className: 'uh-cards' },
|
|
2112
|
+
card(tr('DeepSeek 账户余额', 'DeepSeek Account Balance'), balanceValue, balanceSub, 0, 'wallet'),
|
|
2113
|
+
card(scopedCountIsCalls ? tr('匹配调用次数', 'Matching Calls') : tr('总使用次数', 'Total Uses'), fmtCompact(animatedTurns), range === 'all' && !scopedCountIsCalls ? (language === 'en' ? agg.totals.sessions + ' sessions' : agg.totals.sessions + ' 个会话') : (language === 'en' ? (scopedCountIsCalls ? 'Calls in ' : 'Turns in ') + rangeLabel : rangeLabel + (scopedCountIsCalls ? '内的调用数' : '内的回合数')), 4, 'chart'),
|
|
2114
|
+
card(tr('连续使用', 'Current Streak'), language === 'en' ? st.streak + ' days' : st.streak + ' 天', language === 'en' ? 'Longest streak: ' + st.best + ' days' : '最长连续 ' + st.best + ' 天', 5, 'clock'),
|
|
2115
|
+
tokenCard,
|
|
2116
|
+
),
|
|
2117
|
+
trendPanel,
|
|
2118
|
+
React.createElement('div', { className: 'uh-panel' },
|
|
2119
|
+
React.createElement('div', { className: 'uh-section-title' }, React.createElement(LineIcon, { name: 'calendar', size: 16 }), tr('使用热力图', 'Usage Heatmap')),
|
|
2120
|
+
React.createElement('div', { className: 'uh-hm-head' },
|
|
2121
|
+
React.createElement('div', { className: 'uh-chips' }, workspaces.map((w, i) => {
|
|
2122
|
+
const on = wsFilter === w.id
|
|
2123
|
+
return React.createElement('button', {
|
|
2124
|
+
key: w.id,
|
|
2125
|
+
className: 'uh-chip' + (on ? ' uh-on' : ''),
|
|
2126
|
+
onClick: () => toggleFilter(w.id),
|
|
2127
|
+
title: w.path,
|
|
2128
|
+
},
|
|
2129
|
+
React.createElement('span', { className: 'uh-dot', style: { background: wsColor(i) } }),
|
|
2130
|
+
React.createElement('span', { className: 'uh-chip-title' }, wsTitle(w.id)),
|
|
2131
|
+
)
|
|
2132
|
+
})),
|
|
2133
|
+
React.createElement('div', { className: 'uh-legend' },
|
|
2134
|
+
React.createElement('span', {}, tr('少', 'Less')),
|
|
2135
|
+
[0, 1, 2, 3, 4].map((l) => React.createElement('span', { key: l, className: 'uh-cell', style: { background: cellBg(l) } })),
|
|
2136
|
+
React.createElement('span', {}, tr('多', 'More')),
|
|
2137
|
+
),
|
|
2138
|
+
),
|
|
2139
|
+
React.createElement('div', { className: 'uh-hm-scroll' },
|
|
2140
|
+
React.createElement('div', { className: 'uh-months' }, monthLabels.map((m, i) => React.createElement('span', { key: i, style: { left: m.left } }, m.text))),
|
|
2141
|
+
React.createElement('div', { className: 'uh-hm-body' },
|
|
2142
|
+
React.createElement('div', { className: 'uh-wdays' }, weekdayLabels.map((w, i) => React.createElement('span', { key: i }, w))),
|
|
2143
|
+
React.createElement('div', { className: 'uh-grid' }, cellElements),
|
|
2144
|
+
),
|
|
2145
|
+
),
|
|
2146
|
+
React.createElement('div', { className: 'uh-note', style: { marginTop: 10 } }, tr('口径:每完成一个回合点亮一次(含子代理会话);悬停查看按工作区明细,点击工作区可筛选热力图与明细表。日期按本地时区。', 'Methodology: one cell lights up for each completed turn, including subagent sessions. Hover to view workspace details; click a workspace to filter the heatmap and detail tables. English dates and day boundaries use UTC.')),
|
|
2147
|
+
),
|
|
2148
|
+
React.createElement('div', { className: 'uh-detail-tabs', role: 'tablist', 'aria-label': tr('用量明细视图', 'Usage detail views') },
|
|
2149
|
+
[['logs', tr('请求日志', 'Request Logs'), 'list'], ['model', tr('模型统计', 'Model Stats'), 'chart'], ['workspace', tr('工作区统计', 'Workspace Stats'), 'folder']].map((entry) => React.createElement('button', { key: entry[0], type: 'button', role: 'tab', 'aria-selected': detailView === entry[0], className: 'uh-detail-tab' + (detailView === entry[0] ? ' uh-on' : ''), onClick: () => setDetailView(entry[0]) }, React.createElement(LineIcon, { name: entry[2], size: 14 }), entry[1])),
|
|
2150
|
+
),
|
|
2151
|
+
recordsPanel,
|
|
2152
|
+
),
|
|
2153
|
+
detailView === 'model' ? React.createElement('div', { className: 'uh-panel uh-ios-list-panel' },
|
|
2154
|
+
React.createElement('div', { className: 'uh-hm-head' },
|
|
2155
|
+
React.createElement('h3', { className: 'uh-tbl-title uh-title-with-icon', style: { margin: 0 } }, React.createElement(LineIcon, { name: 'chart', size: 16 }), language === 'en' ? 'Model Usage Details (' + rangeLabel + ')' : '模型用量明细(' + rangeLabel + ')'),
|
|
2156
|
+
React.createElement('div', { className: 'uh-range' },
|
|
2157
|
+
[['route', tr('混合查看', 'Combined View')], ['model', tr('按模型', 'By Model')], ['provider', tr('按供应商', 'By Provider')]].map((entry) => React.createElement('button', {
|
|
2158
|
+
key: entry[0], className: modelView === entry[0] ? 'uh-on' : '', onClick: () => setModelView(entry[0]),
|
|
2159
|
+
}, entry[1])),
|
|
2160
|
+
),
|
|
2161
|
+
),
|
|
2162
|
+
modelRows.length === 0
|
|
2163
|
+
? React.createElement('div', { className: 'uh-empty' }, tr('尚无带模型路由信息的用量记录', 'No usage records with model-routing information yet'))
|
|
2164
|
+
: React.createElement(React.Fragment, null,
|
|
2165
|
+
modelDonutChart,
|
|
2166
|
+
React.createElement('div', { className: 'uh-tbl-scroll' },
|
|
2167
|
+
React.createElement('div', { className: 'uh-model-hrow uh-hrow' },
|
|
2168
|
+
React.createElement('div', {}, modelColumnLabel),
|
|
2169
|
+
React.createElement('div', { className: 'uh-num' }, tr('调用', 'Calls')),
|
|
2170
|
+
React.createElement('div', { className: 'uh-num' }, tr('输入', 'Input')),
|
|
2171
|
+
React.createElement('div', { className: 'uh-num' }, tr('缓存命中', 'Cache Hits')),
|
|
2172
|
+
React.createElement('div', { className: 'uh-num' }, tr('输出', 'Output')),
|
|
2173
|
+
React.createElement('div', { className: 'uh-num' }, tr('推理', 'Reasoning')),
|
|
2174
|
+
React.createElement('div', { className: 'uh-num' }, tr('总处理', 'Total Processed')),
|
|
2175
|
+
React.createElement('div', { className: 'uh-num' }, tr('命中率', 'Hit Rate')),
|
|
2176
|
+
),
|
|
2177
|
+
modelElements,
|
|
2178
|
+
),
|
|
2179
|
+
),
|
|
2180
|
+
React.createElement('div', { className: 'uh-note', style: { marginTop: 10 } }, language === 'en' ? modelViewLabel + ': Combined View distinguishes “Provider / Model”; By Model merges identically named models across providers; By Provider aggregates all of a provider’s models. Historical records without routing information are grouped as “Unknown.”' : modelViewLabel + ':混合查看按“供应商 / 模型”区分;按模型会跨供应商合并同名模型;按供应商则汇总其全部模型。缺少路由信息的历史记录会归为“未知”。'),
|
|
2181
|
+
) : null,
|
|
2182
|
+
detailView === 'workspace' ? React.createElement('div', { className: 'uh-panel uh-ios-list-panel' },
|
|
2183
|
+
React.createElement('h3', { className: 'uh-tbl-title uh-title-with-icon' }, React.createElement(LineIcon, { name: 'folder', size: 16 }), language === 'en' ? 'Workspace Details (' + rangeLabel + ')' : '工作区明细(' + rangeLabel + ')'),
|
|
2184
|
+
rows.length === 0
|
|
2185
|
+
? React.createElement('div', { className: 'uh-empty' }, tr('该时间范围内没有使用记录', 'No usage records in this time range'))
|
|
2186
|
+
: React.createElement(React.Fragment, null,
|
|
2187
|
+
workspaceDonutChart,
|
|
2188
|
+
React.createElement('div', { className: 'uh-tbl-scroll' },
|
|
2189
|
+
React.createElement('div', { className: 'uh-hrow' },
|
|
2190
|
+
React.createElement('div', {}, tr('工作区', 'Workspace')),
|
|
2191
|
+
React.createElement('div', { className: 'uh-num' }, tr('回合', 'Turns')),
|
|
2192
|
+
React.createElement('div', { className: 'uh-num' }, tr('输入', 'Input')),
|
|
2193
|
+
React.createElement('div', { className: 'uh-num' }, tr('缓存命中', 'Cache Hits')),
|
|
2194
|
+
React.createElement('div', { className: 'uh-num' }, tr('输出', 'Output')),
|
|
2195
|
+
React.createElement('div', { className: 'uh-num' }, tr('推理', 'Reasoning')),
|
|
2196
|
+
React.createElement('div', { className: 'uh-num' }, tr('总处理', 'Total Processed')),
|
|
2197
|
+
React.createElement('div', { className: 'uh-num' }, tr('命中率', 'Hit Rate')),
|
|
2198
|
+
React.createElement('div', { className: 'uh-num' }, tr('占比', 'Share')),
|
|
2199
|
+
),
|
|
2200
|
+
rowElements,
|
|
2201
|
+
),
|
|
2202
|
+
),
|
|
2203
|
+
) : null,
|
|
2204
|
+
),
|
|
2205
|
+
tip,
|
|
2206
|
+
)
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
class UsageDashboardBoundary extends React.Component {
|
|
2210
|
+
constructor(props) { super(props); this.state = { error: null, resetKey: props.resetKey } }
|
|
2211
|
+
static getDerivedStateFromError(error) { return { error } }
|
|
2212
|
+
componentDidUpdate(prevProps) {
|
|
2213
|
+
if (prevProps.resetKey !== this.props.resetKey && this.state.error !== null) this.setState({ error: null, resetKey: this.props.resetKey })
|
|
2214
|
+
}
|
|
2215
|
+
render() {
|
|
2216
|
+
if (this.state.error !== null) return this.props.fallback(this.state.error)
|
|
2217
|
+
return this.props.children
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
function UsageSidebarEntry(props) {
|
|
2221
|
+
const [open, setOpen] = React.useState(false)
|
|
2222
|
+
const [dashboardResetKey, setDashboardResetKey] = React.useState(0)
|
|
2223
|
+
const [language, setLanguage] = React.useState(storedLanguage)
|
|
2224
|
+
const tr = (zh, en) => language === 'en' ? en : zh
|
|
2225
|
+
const dashboardFallback = () => React.createElement('div', { className: 'uh-boundary-fallback', role: 'alert' },
|
|
2226
|
+
React.createElement('div', { className: 'uh-boundary-title' }, tr('用量统计暂时无法显示', 'Usage statistics is temporarily unavailable')),
|
|
2227
|
+
React.createElement('div', { className: 'uh-boundary-note' }, tr('当前范围加载失败,入口仍然可用。', 'The selected range failed to render; the sidebar entry is still available.')),
|
|
2228
|
+
React.createElement('div', { className: 'uh-actions' },
|
|
2229
|
+
React.createElement('button', { type: 'button', className: 'uh-refresh', onClick: () => setDashboardResetKey((value) => value + 1) }, React.createElement(LineIcon, { name: 'refresh', size: 14 }), tr('重试', 'Retry')),
|
|
2230
|
+
React.createElement('button', { type: 'button', className: 'uh-refresh', onClick: () => setOpen(false) }, React.createElement(LineIcon, { name: 'close', size: 14 }), tr('关闭', 'Close')),
|
|
2231
|
+
),
|
|
2232
|
+
)
|
|
2233
|
+
const changeLanguage = (next) => {
|
|
2234
|
+
const value = next === 'en' ? 'en' : 'zh'
|
|
2235
|
+
setLanguage(value)
|
|
2236
|
+
persistLanguage(value)
|
|
2237
|
+
}
|
|
2238
|
+
React.useEffect(() => {
|
|
2239
|
+
if (!open) return undefined
|
|
2240
|
+
const closeOnEscape = (event) => { if (event.key === 'Escape') setOpen(false) }
|
|
2241
|
+
document.addEventListener('keydown', closeOnEscape)
|
|
2242
|
+
return () => document.removeEventListener('keydown', closeOnEscape)
|
|
2243
|
+
}, [open])
|
|
2244
|
+
return React.createElement(React.Fragment, null,
|
|
2245
|
+
React.createElement('button', {
|
|
2246
|
+
type: 'button', className: 'uh-side-entry', title: tr('用量统计', 'Usage Statistics'), 'aria-label': tr('用量统计', 'Usage Statistics'), onClick: () => setOpen(true),
|
|
2247
|
+
}, React.createElement('span', { className: 'uh-side-entry-icon' }, React.createElement(LineIcon, { name: 'chart', size: 17 })), props.wide ? React.createElement('span', { className: 'uh-side-entry-label' }, tr('用量统计', 'Usage Statistics')) : null),
|
|
2248
|
+
open ? React.createElement('div', { className: 'uh-side-modal', role: 'presentation', onMouseDown: (event) => { if (event.target === event.currentTarget) setOpen(false) } },
|
|
2249
|
+
React.createElement('div', { className: 'uh-side-dialog', role: 'dialog', 'aria-modal': true, 'aria-label': tr('用量统计', 'Usage Statistics') },
|
|
2250
|
+
React.createElement('div', { className: 'uh-side-dialog-head' },
|
|
2251
|
+
React.createElement('button', { className: 'uh-refresh uh-close-button', type: 'button', title: tr('关闭用量统计', 'Close Usage Statistics'), 'aria-label': tr('关闭用量统计', 'Close Usage Statistics'), onClick: () => setOpen(false) }, React.createElement(LineIcon, { name: 'close', size: 18 })),
|
|
2252
|
+
),
|
|
2253
|
+
React.createElement(UsageDashboardBoundary, { resetKey: dashboardResetKey, fallback: dashboardFallback }, React.createElement(UsagePage, { timerCtx: props.timerCtx, language, onLanguageChange: changeLanguage })),
|
|
2254
|
+
),
|
|
2255
|
+
) : null,
|
|
2256
|
+
)
|
|
2257
|
+
}
|
|
2258
|
+
|
|
2259
|
+
exports.inject = ['timer', 'slots']
|
|
2260
|
+
exports.apply = (ctx) => {
|
|
2261
|
+
const slots = ctx.get('slots')
|
|
2262
|
+
const timer = ctx.get('timer')
|
|
2263
|
+
if (slots === undefined || timer === undefined) return
|
|
2264
|
+
slots.inject('sidebar.footer.action', () => slots.register(
|
|
2265
|
+
{ name: 'sidebar.footer.action', id: 'all-usage', order: 10 },
|
|
2266
|
+
(props) => React.createElement(UsageSidebarEntry, { wide: props.wide, timerCtx: timer }),
|
|
2267
|
+
))
|
|
2268
|
+
}
|
|
2269
|
+
return module.exports;
|
|
2270
|
+
}
|
|
2271
|
+
});
|