codexmate 0.0.25 → 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +416 -413
- package/README.zh.md +349 -346
- package/cli/agents-files.js +224 -224
- package/cli/archive-helpers.js +446 -446
- package/cli/auth-profiles.js +375 -375
- package/cli/builtin-proxy.js +1079 -1079
- package/cli/claude-proxy.js +1022 -1022
- package/cli/config-bootstrap.js +384 -384
- package/cli/config-health.js +338 -338
- package/cli/doctor-core.js +903 -903
- package/cli/import-skills-url.js +356 -356
- package/cli/openai-bridge.js +997 -997
- package/cli/openclaw-config.js +629 -629
- package/cli/session-convert-args.js +65 -0
- package/cli/session-convert-io.js +82 -0
- package/cli/session-convert.js +43 -0
- package/cli/session-usage.concurrent.js +28 -28
- package/cli/session-usage.js +118 -118
- package/cli/session-usage.models.js +176 -176
- package/cli/skills.js +1141 -1141
- package/cli/zip-commands.js +510 -510
- package/cli.js +15218 -14736
- package/lib/automation.js +404 -404
- package/lib/cli-file-utils.js +151 -151
- package/lib/cli-models-utils.js +379 -379
- package/lib/cli-network-utils.js +190 -190
- package/lib/cli-path-utils.js +85 -85
- package/lib/cli-session-utils.js +121 -121
- package/lib/cli-sessions.js +417 -417
- package/lib/cli-utils.js +155 -155
- package/lib/download-artifacts.js +92 -92
- package/lib/mcp-stdio.js +453 -453
- package/lib/task-orchestrator.js +869 -869
- package/lib/text-diff.js +303 -303
- package/lib/workflow-engine.js +340 -340
- package/package.json +74 -74
- package/plugins/README.md +20 -20
- package/plugins/README.zh-CN.md +20 -20
- package/plugins/prompt-templates/comment-polish/index.mjs +25 -25
- package/plugins/prompt-templates/computed.mjs +253 -253
- package/plugins/prompt-templates/index.mjs +8 -8
- package/plugins/prompt-templates/manifest.mjs +15 -15
- package/plugins/prompt-templates/methods.mjs +619 -619
- package/plugins/prompt-templates/overview.mjs +90 -90
- package/plugins/prompt-templates/ownership.mjs +19 -19
- package/plugins/prompt-templates/rule-ack/index.mjs +21 -21
- package/plugins/prompt-templates/storage.mjs +64 -64
- package/plugins/registry.mjs +16 -16
- package/web-ui/app.js +625 -612
- package/web-ui/index.html +35 -35
- package/web-ui/logic.agents-diff.mjs +386 -386
- package/web-ui/logic.claude.mjs +168 -168
- package/web-ui/logic.mjs +5 -5
- package/web-ui/logic.runtime.mjs +128 -128
- package/web-ui/logic.session-convert.mjs +70 -0
- package/web-ui/logic.sessions.mjs +709 -614
- package/web-ui/modules/api.mjs +90 -90
- package/web-ui/modules/app.computed.dashboard.mjs +171 -128
- package/web-ui/modules/app.computed.index.mjs +17 -17
- package/web-ui/modules/app.computed.main-tabs.mjs +205 -205
- package/web-ui/modules/app.computed.session.mjs +946 -670
- package/web-ui/modules/app.constants.mjs +15 -15
- package/web-ui/modules/app.methods.agents.mjs +632 -632
- package/web-ui/modules/app.methods.claude-config.mjs +179 -174
- package/web-ui/modules/app.methods.codex-config.mjs +860 -784
- package/web-ui/modules/app.methods.index.mjs +92 -92
- package/web-ui/modules/app.methods.install.mjs +205 -205
- package/web-ui/modules/app.methods.navigation.mjs +743 -695
- package/web-ui/modules/app.methods.openclaw-core.mjs +814 -814
- package/web-ui/modules/app.methods.openclaw-editing.mjs +372 -372
- package/web-ui/modules/app.methods.openclaw-persist.mjs +369 -369
- package/web-ui/modules/app.methods.providers.mjs +404 -404
- package/web-ui/modules/app.methods.runtime.mjs +345 -345
- package/web-ui/modules/app.methods.session-actions.mjs +596 -544
- package/web-ui/modules/app.methods.session-browser.mjs +985 -722
- package/web-ui/modules/app.methods.session-timeline.mjs +479 -448
- package/web-ui/modules/app.methods.session-trash.mjs +424 -424
- package/web-ui/modules/app.methods.startup-claude.mjs +522 -417
- package/web-ui/modules/app.methods.task-orchestration.mjs +556 -556
- package/web-ui/modules/config-mode.computed.mjs +124 -124
- package/web-ui/modules/config-template-confirm-pref.mjs +33 -33
- package/web-ui/modules/i18n.dict.mjs +2113 -2055
- package/web-ui/modules/i18n.mjs +56 -56
- package/web-ui/modules/plugins.computed.mjs +3 -3
- package/web-ui/modules/plugins.methods.mjs +3 -3
- package/web-ui/modules/plugins.storage.mjs +11 -11
- package/web-ui/modules/sessions-filters-url.mjs +85 -85
- package/web-ui/modules/skills.computed.mjs +107 -107
- package/web-ui/modules/skills.methods.mjs +481 -481
- package/web-ui/partials/index/layout-footer.html +13 -13
- package/web-ui/partials/index/layout-header.html +475 -475
- package/web-ui/partials/index/modal-config-template-agents.html +174 -174
- package/web-ui/partials/index/modal-confirm-toast.html +32 -32
- package/web-ui/partials/index/modal-health-check.html +45 -45
- package/web-ui/partials/index/modal-openclaw-config.html +280 -280
- package/web-ui/partials/index/modal-skills.html +200 -200
- package/web-ui/partials/index/modals-basic.html +165 -165
- package/web-ui/partials/index/panel-config-claude.html +184 -179
- package/web-ui/partials/index/panel-config-codex.html +283 -283
- package/web-ui/partials/index/panel-config-openclaw.html +83 -83
- package/web-ui/partials/index/panel-dashboard.html +186 -186
- package/web-ui/partials/index/panel-docs.html +147 -147
- package/web-ui/partials/index/panel-market.html +177 -177
- package/web-ui/partials/index/panel-orchestration.html +391 -391
- package/web-ui/partials/index/panel-plugins.html +279 -279
- package/web-ui/partials/index/panel-sessions.html +326 -303
- package/web-ui/partials/index/panel-settings.html +258 -258
- package/web-ui/partials/index/panel-usage.html +342 -361
- package/web-ui/res/json5.min.js +1 -1
- package/web-ui/res/vue.global.prod.js +13 -13
- package/web-ui/session-helpers.mjs +576 -573
- package/web-ui/source-bundle.cjs +233 -233
- package/web-ui/styles/base-theme.css +268 -264
- package/web-ui/styles/controls-forms.css +423 -423
- package/web-ui/styles/dashboard.css +274 -274
- package/web-ui/styles/docs-panel.css +247 -247
- package/web-ui/styles/feedback.css +108 -108
- package/web-ui/styles/health-check-dialog.css +144 -144
- package/web-ui/styles/layout-shell.css +603 -603
- package/web-ui/styles/modals-core.css +464 -464
- package/web-ui/styles/navigation-panels.css +390 -390
- package/web-ui/styles/openclaw-structured.css +266 -266
- package/web-ui/styles/plugins-panel.css +523 -523
- package/web-ui/styles/responsive.css +454 -454
- package/web-ui/styles/sessions-list.css +415 -398
- package/web-ui/styles/sessions-preview.css +411 -411
- package/web-ui/styles/sessions-toolbar-trash.css +330 -268
- package/web-ui/styles/sessions-usage.css +945 -912
- package/web-ui/styles/settings-panel.css +166 -166
- package/web-ui/styles/skills-list.css +303 -303
- package/web-ui/styles/skills-market.css +406 -406
- package/web-ui/styles/task-orchestration.css +822 -822
- package/web-ui/styles/titles-cards.css +408 -408
- package/web-ui/styles.css +21 -21
- package/web-ui.html +17 -17
|
@@ -1,670 +1,946 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildSessionTimelineNodes,
|
|
3
|
-
buildUsageChartGroups,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
{ label: '
|
|
110
|
-
{ label: '
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
if (
|
|
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
|
-
const
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
if (
|
|
389
|
-
return
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
if (
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
if (
|
|
407
|
-
return
|
|
408
|
-
}
|
|
409
|
-
const
|
|
410
|
-
const
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
const
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
},
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
return
|
|
443
|
-
},
|
|
444
|
-
|
|
445
|
-
if (this.
|
|
446
|
-
return
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
return
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
return
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
:
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
const
|
|
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
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
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
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
buildSessionTimelineNodes,
|
|
3
|
+
buildUsageChartGroups,
|
|
4
|
+
buildUsageHeatmap,
|
|
5
|
+
isSessionQueryEnabled
|
|
6
|
+
} from '../logic.mjs';
|
|
7
|
+
import { SESSION_TRASH_PAGE_SIZE } from './app.constants.mjs';
|
|
8
|
+
|
|
9
|
+
function formatUsageSummaryNumber(value) {
|
|
10
|
+
const numeric = Number(value);
|
|
11
|
+
if (!Number.isFinite(numeric) || numeric < 0) {
|
|
12
|
+
return '0';
|
|
13
|
+
}
|
|
14
|
+
return Math.floor(numeric).toLocaleString('en-US');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function formatCompactUsageSummaryNumber(value) {
|
|
18
|
+
const numeric = Number(value);
|
|
19
|
+
if (!Number.isFinite(numeric) || numeric < 0) {
|
|
20
|
+
return '0';
|
|
21
|
+
}
|
|
22
|
+
return new Intl.NumberFormat('en-US', {
|
|
23
|
+
notation: 'compact',
|
|
24
|
+
compactDisplay: 'short',
|
|
25
|
+
maximumFractionDigits: 1
|
|
26
|
+
}).format(Math.floor(numeric));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function readUsageCostNumber(value) {
|
|
30
|
+
const numeric = Number(value);
|
|
31
|
+
if (!Number.isFinite(numeric) || numeric < 0) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return numeric;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function formatUsageEstimatedCost(value, options = {}) {
|
|
38
|
+
const numeric = Number(value);
|
|
39
|
+
if (!Number.isFinite(numeric) || numeric <= 0) {
|
|
40
|
+
return '$0.00';
|
|
41
|
+
}
|
|
42
|
+
const precise = options && options.precise === true;
|
|
43
|
+
if (numeric < 0.0001) {
|
|
44
|
+
return '<$0.0001';
|
|
45
|
+
}
|
|
46
|
+
let fractionDigits = 2;
|
|
47
|
+
if (numeric < 1) {
|
|
48
|
+
fractionDigits = precise ? 6 : 4;
|
|
49
|
+
} else if (numeric >= 100) {
|
|
50
|
+
fractionDigits = 0;
|
|
51
|
+
}
|
|
52
|
+
return new Intl.NumberFormat('en-US', {
|
|
53
|
+
style: 'currency',
|
|
54
|
+
currency: 'USD',
|
|
55
|
+
minimumFractionDigits: fractionDigits,
|
|
56
|
+
maximumFractionDigits: fractionDigits
|
|
57
|
+
}).format(numeric);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function formatSignedUsageSummaryNumber(value) {
|
|
61
|
+
const numeric = Number(value);
|
|
62
|
+
if (!Number.isFinite(numeric) || numeric === 0) {
|
|
63
|
+
return '0';
|
|
64
|
+
}
|
|
65
|
+
const sign = numeric > 0 ? '+' : '-';
|
|
66
|
+
return `${sign}${formatUsageSummaryNumber(Math.abs(numeric))}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function formatSignedUsageEstimatedCost(value, options = {}) {
|
|
70
|
+
const numeric = Number(value);
|
|
71
|
+
if (!Number.isFinite(numeric) || numeric === 0) {
|
|
72
|
+
return '$0.00';
|
|
73
|
+
}
|
|
74
|
+
const sign = numeric > 0 ? '+' : '-';
|
|
75
|
+
return `${sign}${formatUsageEstimatedCost(Math.abs(numeric), options)}`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function formatUsageRangeLabel(range, t) {
|
|
79
|
+
const normalized = typeof range === 'string' ? range.trim().toLowerCase() : '7d';
|
|
80
|
+
if (typeof t === 'function') {
|
|
81
|
+
if (normalized === '30d') return t('usage.range.30d');
|
|
82
|
+
if (normalized === 'all') return t('usage.range.all');
|
|
83
|
+
return t('usage.range.7d');
|
|
84
|
+
}
|
|
85
|
+
if (normalized === '30d') return '近 30 天';
|
|
86
|
+
if (normalized === 'all') return '全部';
|
|
87
|
+
return '近 7 天';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function formatUsageDuration(value, options = {}) {
|
|
91
|
+
const normalizedLang = typeof options.lang === 'string' ? options.lang.trim().toLowerCase() : '';
|
|
92
|
+
const isEn = normalizedLang === 'en';
|
|
93
|
+
const numeric = Number(value);
|
|
94
|
+
if (!Number.isFinite(numeric) || numeric <= 0) {
|
|
95
|
+
return isEn ? '0m' : '0分';
|
|
96
|
+
}
|
|
97
|
+
const totalMinutes = Math.floor(numeric / 60000);
|
|
98
|
+
if (totalMinutes <= 0) {
|
|
99
|
+
return isEn ? '<1m' : '<1分';
|
|
100
|
+
}
|
|
101
|
+
const maxParts = Number.isFinite(Number(options.maxParts))
|
|
102
|
+
? Math.max(1, Math.floor(Number(options.maxParts)))
|
|
103
|
+
: 2;
|
|
104
|
+
const compact = options.compact !== false;
|
|
105
|
+
const units = compact
|
|
106
|
+
? (
|
|
107
|
+
isEn
|
|
108
|
+
? [
|
|
109
|
+
{ label: 'd', value: 24 * 60 },
|
|
110
|
+
{ label: 'h', value: 60 },
|
|
111
|
+
{ label: 'm', value: 1 }
|
|
112
|
+
]
|
|
113
|
+
: [
|
|
114
|
+
{ label: '天', value: 24 * 60 },
|
|
115
|
+
{ label: '时', value: 60 },
|
|
116
|
+
{ label: '分', value: 1 }
|
|
117
|
+
]
|
|
118
|
+
)
|
|
119
|
+
: (
|
|
120
|
+
isEn
|
|
121
|
+
? [
|
|
122
|
+
{ label: 'day', value: 24 * 60 },
|
|
123
|
+
{ label: 'hr', value: 60 },
|
|
124
|
+
{ label: 'min', value: 1 }
|
|
125
|
+
]
|
|
126
|
+
: [
|
|
127
|
+
{ label: '天', value: 24 * 60 },
|
|
128
|
+
{ label: '小时', value: 60 },
|
|
129
|
+
{ label: '分', value: 1 }
|
|
130
|
+
]
|
|
131
|
+
);
|
|
132
|
+
let remainingMinutes = totalMinutes;
|
|
133
|
+
const parts = [];
|
|
134
|
+
for (const unit of units) {
|
|
135
|
+
if (remainingMinutes < unit.value && unit.value !== 1) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const count = unit.value === 1 ? remainingMinutes : Math.floor(remainingMinutes / unit.value);
|
|
139
|
+
if (count <= 0) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
parts.push(compact ? `${count}${unit.label}` : (isEn ? `${count} ${unit.label}` : `${count}${unit.label}`));
|
|
143
|
+
remainingMinutes -= count * unit.value;
|
|
144
|
+
if (parts.length >= maxParts) {
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return parts.length ? parts.join(compact ? '' : ' ') : (isEn ? '0m' : '0分');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const KNOWN_USAGE_MODEL_PRICING = Object.freeze({
|
|
152
|
+
'gpt-5.4': Object.freeze({ input: 2.5, output: 15, cacheRead: 0.25, cacheWrite: 0 }),
|
|
153
|
+
'gpt-5.4-mini': Object.freeze({ input: 0.75, output: 4.5, cacheRead: 0.075, cacheWrite: 0 }),
|
|
154
|
+
'gpt-5.3-codex': Object.freeze({ input: 1.75, output: 14, cacheRead: 0.175, cacheWrite: 0 }),
|
|
155
|
+
'gpt-5.2-codex': Object.freeze({ input: 1.75, output: 14, cacheRead: 0.175, cacheWrite: 0 })
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
function createUsagePricingEntry(pricing, source) {
|
|
159
|
+
const resolvedSource = typeof source === 'string' && source.trim() ? source.trim() : 'provider-config';
|
|
160
|
+
return {
|
|
161
|
+
input: readUsageCostNumber(pricing && pricing.input),
|
|
162
|
+
output: readUsageCostNumber(pricing && pricing.output),
|
|
163
|
+
reasoningOutput: readUsageCostNumber(
|
|
164
|
+
pricing && (pricing.reasoningOutput != null ? pricing.reasoningOutput : pricing.reasoning)
|
|
165
|
+
),
|
|
166
|
+
cacheRead: readUsageCostNumber(pricing && pricing.cacheRead),
|
|
167
|
+
cacheWrite: readUsageCostNumber(pricing && pricing.cacheWrite),
|
|
168
|
+
source: resolvedSource
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function buildUsagePricingIndex(providersList = []) {
|
|
173
|
+
const byProvider = new Map();
|
|
174
|
+
const byModel = new Map();
|
|
175
|
+
const knownByModel = new Map();
|
|
176
|
+
const list = Array.isArray(providersList) ? providersList : [];
|
|
177
|
+
for (const provider of list) {
|
|
178
|
+
if (!provider || typeof provider !== 'object') continue;
|
|
179
|
+
const providerName = typeof provider.name === 'string' ? provider.name.trim() : '';
|
|
180
|
+
const models = Array.isArray(provider.models) ? provider.models : [];
|
|
181
|
+
const providerMap = new Map();
|
|
182
|
+
for (const model of models) {
|
|
183
|
+
if (!model || typeof model !== 'object') continue;
|
|
184
|
+
const modelId = typeof model.id === 'string' ? model.id.trim() : '';
|
|
185
|
+
if (!modelId) continue;
|
|
186
|
+
const pricing = createUsagePricingEntry(
|
|
187
|
+
model.cost && typeof model.cost === 'object' && !Array.isArray(model.cost)
|
|
188
|
+
? model.cost
|
|
189
|
+
: null,
|
|
190
|
+
'provider-config'
|
|
191
|
+
);
|
|
192
|
+
const hasKnownRate = [pricing.input, pricing.output, pricing.reasoningOutput, pricing.cacheRead, pricing.cacheWrite]
|
|
193
|
+
.some((value) => value !== null);
|
|
194
|
+
if (!hasKnownRate) continue;
|
|
195
|
+
providerMap.set(modelId, pricing);
|
|
196
|
+
const modelMatches = byModel.get(modelId) || [];
|
|
197
|
+
modelMatches.push({ provider: providerName, pricing });
|
|
198
|
+
byModel.set(modelId, modelMatches);
|
|
199
|
+
}
|
|
200
|
+
if (providerName && providerMap.size) {
|
|
201
|
+
byProvider.set(providerName, providerMap);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
for (const [modelId, pricing] of Object.entries(KNOWN_USAGE_MODEL_PRICING)) {
|
|
205
|
+
const normalizedModelId = typeof modelId === 'string' ? modelId.trim() : '';
|
|
206
|
+
if (!normalizedModelId || byModel.has(normalizedModelId)) {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
knownByModel.set(normalizedModelId, createUsagePricingEntry(pricing, 'public-catalog'));
|
|
210
|
+
}
|
|
211
|
+
return { byProvider, byModel, knownByModel };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function resolveUsagePricingForSession(session, pricingIndex, fallbackProvider = '') {
|
|
215
|
+
if (!session || typeof session !== 'object' || !pricingIndex || typeof pricingIndex !== 'object') {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
const model = typeof session.model === 'string' ? session.model.trim() : '';
|
|
219
|
+
if (!model) return null;
|
|
220
|
+
const provider = typeof session.provider === 'string' ? session.provider.trim() : '';
|
|
221
|
+
const effectiveProvider = provider || fallbackProvider;
|
|
222
|
+
if (effectiveProvider) {
|
|
223
|
+
const providerMap = pricingIndex.byProvider instanceof Map ? pricingIndex.byProvider.get(effectiveProvider) : null;
|
|
224
|
+
if (providerMap instanceof Map && providerMap.has(model)) {
|
|
225
|
+
return providerMap.get(model);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const modelMatches = pricingIndex.byModel instanceof Map ? pricingIndex.byModel.get(model) : null;
|
|
229
|
+
if (Array.isArray(modelMatches) && modelMatches.length === 1) {
|
|
230
|
+
return modelMatches[0].pricing;
|
|
231
|
+
}
|
|
232
|
+
const knownPricing = pricingIndex.knownByModel instanceof Map ? pricingIndex.knownByModel.get(model) : null;
|
|
233
|
+
if (knownPricing) {
|
|
234
|
+
return knownPricing;
|
|
235
|
+
}
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function shouldEstimateUsageCostForSession(session) {
|
|
240
|
+
if (!session || typeof session !== 'object') {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
const source = typeof session.source === 'string' ? session.source.trim().toLowerCase() : '';
|
|
244
|
+
const provider = typeof session.provider === 'string' ? session.provider.trim().toLowerCase() : '';
|
|
245
|
+
const model = typeof session.model === 'string' ? session.model.trim().toLowerCase() : '';
|
|
246
|
+
if (source === 'claude' || provider === 'claude') {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
if (/^claude(?:[-_]|$)/.test(model)) {
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function estimateUsageCostSummary(sessions, providersList, currentProvider) {
|
|
256
|
+
const list = Array.isArray(sessions) ? sessions : [];
|
|
257
|
+
const pricingIndex = buildUsagePricingIndex(providersList);
|
|
258
|
+
let totalCostUsd = 0;
|
|
259
|
+
let estimatedSessions = 0;
|
|
260
|
+
let totalTokens = 0;
|
|
261
|
+
let estimatedTokens = 0;
|
|
262
|
+
let configuredSessions = 0;
|
|
263
|
+
let catalogSessions = 0;
|
|
264
|
+
let missingPricingSessions = 0;
|
|
265
|
+
let missingTokenSessions = 0;
|
|
266
|
+
let supportedSessions = 0;
|
|
267
|
+
let skippedUnsupportedSessions = 0;
|
|
268
|
+
|
|
269
|
+
for (const session of list) {
|
|
270
|
+
if (!session || typeof session !== 'object') continue;
|
|
271
|
+
if (!shouldEstimateUsageCostForSession(session)) {
|
|
272
|
+
skippedUnsupportedSessions += 1;
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
supportedSessions += 1;
|
|
276
|
+
const cost = estimateUsageCostForSession(session, pricingIndex, currentProvider);
|
|
277
|
+
totalTokens += cost.totalSessionTokens;
|
|
278
|
+
if (!cost.pricing) {
|
|
279
|
+
missingPricingSessions += 1;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
if (!cost.hasTokenBreakdown) {
|
|
283
|
+
missingTokenSessions += 1;
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
totalCostUsd += cost.estimatedUsd;
|
|
287
|
+
estimatedSessions += 1;
|
|
288
|
+
estimatedTokens += cost.totalSessionTokens;
|
|
289
|
+
if (cost.pricing.source === 'public-catalog') catalogSessions += 1;
|
|
290
|
+
else configuredSessions += 1;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const coveragePercent = totalTokens > 0
|
|
294
|
+
? Math.round((estimatedTokens / totalTokens) * 100)
|
|
295
|
+
: (estimatedSessions > 0 ? 100 : 0);
|
|
296
|
+
return {
|
|
297
|
+
totalCostUsd,
|
|
298
|
+
estimatedSessions,
|
|
299
|
+
totalSessions: supportedSessions,
|
|
300
|
+
estimatedTokens,
|
|
301
|
+
totalTokens,
|
|
302
|
+
coveragePercent,
|
|
303
|
+
hasEstimate: estimatedSessions > 0,
|
|
304
|
+
configuredSessions,
|
|
305
|
+
catalogSessions,
|
|
306
|
+
missingPricingSessions,
|
|
307
|
+
missingTokenSessions,
|
|
308
|
+
skippedUnsupportedSessions
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function estimateUsageCostForSession(session, pricingIndex, currentProvider) {
|
|
313
|
+
const inputTokens = Number.isFinite(Number(session.inputTokens)) ? Math.max(0, Math.floor(Number(session.inputTokens))) : null;
|
|
314
|
+
const cachedInputTokens = Number.isFinite(Number(session.cachedInputTokens)) ? Math.max(0, Math.floor(Number(session.cachedInputTokens))) : 0;
|
|
315
|
+
const outputTokens = Number.isFinite(Number(session.outputTokens)) ? Math.max(0, Math.floor(Number(session.outputTokens))) : null;
|
|
316
|
+
const reasoningOutputTokens = Number.isFinite(Number(session.reasoningOutputTokens)) ? Math.max(0, Math.floor(Number(session.reasoningOutputTokens))) : 0;
|
|
317
|
+
const billableInputTokens = Math.max(0, (inputTokens || 0) - cachedInputTokens);
|
|
318
|
+
const fallbackSessionTokens = billableInputTokens + cachedInputTokens + (outputTokens || 0) + reasoningOutputTokens;
|
|
319
|
+
const totalSessionTokens = Number.isFinite(Number(session.totalTokens))
|
|
320
|
+
? Math.max(0, Math.floor(Number(session.totalTokens)))
|
|
321
|
+
: fallbackSessionTokens;
|
|
322
|
+
const pricing = resolveUsagePricingForSession(session, pricingIndex, currentProvider);
|
|
323
|
+
const hasTokenBreakdown = !(inputTokens === null && outputTokens === null && reasoningOutputTokens === 0);
|
|
324
|
+
const reasoningRate = pricing
|
|
325
|
+
? ((pricing.reasoningOutput != null ? pricing.reasoningOutput : pricing.output) || 0)
|
|
326
|
+
: 0;
|
|
327
|
+
const estimatedUsd = pricing && hasTokenBreakdown
|
|
328
|
+
? (
|
|
329
|
+
((pricing.input || 0) * billableInputTokens)
|
|
330
|
+
+ ((pricing.cacheRead || 0) * cachedInputTokens)
|
|
331
|
+
+ (reasoningRate * reasoningOutputTokens)
|
|
332
|
+
+ ((pricing.output || 0) * (outputTokens || 0))
|
|
333
|
+
) / 1000000
|
|
334
|
+
: 0;
|
|
335
|
+
return {
|
|
336
|
+
pricing,
|
|
337
|
+
hasTokenBreakdown,
|
|
338
|
+
totalSessionTokens,
|
|
339
|
+
estimatedUsd
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export function createSessionComputed() {
|
|
344
|
+
return {
|
|
345
|
+
isSessionQueryEnabled() {
|
|
346
|
+
return isSessionQueryEnabled(this.sessionFilterSource);
|
|
347
|
+
},
|
|
348
|
+
activeSessionExportKey() {
|
|
349
|
+
return this.activeSession ? this.getSessionExportKey(this.activeSession) : '';
|
|
350
|
+
},
|
|
351
|
+
sortedSessionsList() {
|
|
352
|
+
const list = Array.isArray(this.sessionsList) ? this.sessionsList : [];
|
|
353
|
+
if (list.length === 0) return [];
|
|
354
|
+
const pinnedMap = (this.sessionPinnedMap && typeof this.sessionPinnedMap === 'object')
|
|
355
|
+
? this.sessionPinnedMap
|
|
356
|
+
: {};
|
|
357
|
+
const sortMode = typeof this.sessionSortMode === 'string'
|
|
358
|
+
? this.sessionSortMode.trim().toLowerCase()
|
|
359
|
+
: 'time';
|
|
360
|
+
if (sortMode !== 'hot' && Object.keys(pinnedMap).length === 0) {
|
|
361
|
+
return list;
|
|
362
|
+
}
|
|
363
|
+
const now = Date.now();
|
|
364
|
+
let hasPinned = false;
|
|
365
|
+
const decorated = list.map((session, index) => {
|
|
366
|
+
const key = session ? this.getSessionExportKey(session) : '';
|
|
367
|
+
const rawPinnedAt = key ? pinnedMap[key] : 0;
|
|
368
|
+
const pinnedAt = Number.isFinite(Number(rawPinnedAt))
|
|
369
|
+
? Math.floor(Number(rawPinnedAt))
|
|
370
|
+
: 0;
|
|
371
|
+
const isPinned = pinnedAt > 0;
|
|
372
|
+
if (isPinned) {
|
|
373
|
+
hasPinned = true;
|
|
374
|
+
}
|
|
375
|
+
const updatedAtMs = session ? Date.parse(session.updatedAt || '') : NaN;
|
|
376
|
+
const safeUpdatedAtMs = Number.isFinite(updatedAtMs) ? updatedAtMs : 0;
|
|
377
|
+
const messageCount = session && Number.isFinite(Number(session.messageCount))
|
|
378
|
+
? Math.max(0, Math.floor(Number(session.messageCount)))
|
|
379
|
+
: 0;
|
|
380
|
+
const totalTokens = session && Number.isFinite(Number(session.totalTokens))
|
|
381
|
+
? Math.max(0, Math.floor(Number(session.totalTokens)))
|
|
382
|
+
: 0;
|
|
383
|
+
const ageHours = safeUpdatedAtMs > 0 ? Math.max(0, (now - safeUpdatedAtMs) / 3600000) : 1e9;
|
|
384
|
+
const activity = Math.sqrt(Math.max(1, totalTokens || (messageCount * 120)));
|
|
385
|
+
const hotScore = activity / (1 + (ageHours / 24));
|
|
386
|
+
return { session, index, pinnedAt, isPinned, safeUpdatedAtMs, hotScore };
|
|
387
|
+
});
|
|
388
|
+
if (!hasPinned && sortMode !== 'hot') {
|
|
389
|
+
return list;
|
|
390
|
+
}
|
|
391
|
+
decorated.sort((a, b) => {
|
|
392
|
+
if (a.isPinned !== b.isPinned) return a.isPinned ? -1 : 1;
|
|
393
|
+
if (a.isPinned && a.pinnedAt !== b.pinnedAt) return b.pinnedAt - a.pinnedAt;
|
|
394
|
+
if (sortMode === 'hot') {
|
|
395
|
+
if (a.hotScore !== b.hotScore) return b.hotScore - a.hotScore;
|
|
396
|
+
}
|
|
397
|
+
return a.index - b.index;
|
|
398
|
+
});
|
|
399
|
+
return decorated.map(item => item.session);
|
|
400
|
+
},
|
|
401
|
+
visibleSessionsList() {
|
|
402
|
+
if (!this.sessionListRenderEnabled) {
|
|
403
|
+
return [];
|
|
404
|
+
}
|
|
405
|
+
const list = Array.isArray(this.sortedSessionsList) ? this.sortedSessionsList : [];
|
|
406
|
+
if (list.length === 0) {
|
|
407
|
+
return [];
|
|
408
|
+
}
|
|
409
|
+
const rawVisibleCount = Number(this.sessionListVisibleCount);
|
|
410
|
+
const visibleCount = Number.isFinite(rawVisibleCount)
|
|
411
|
+
? Math.max(0, Math.floor(rawVisibleCount))
|
|
412
|
+
: 0;
|
|
413
|
+
let targetCount = visibleCount > 0 ? Math.min(visibleCount, list.length) : Math.min(list.length, 1);
|
|
414
|
+
const activeKey = this.activeSession ? this.getSessionExportKey(this.activeSession) : '';
|
|
415
|
+
if (activeKey) {
|
|
416
|
+
const activeIndex = list.findIndex((session) => this.getSessionExportKey(session) === activeKey);
|
|
417
|
+
if (activeIndex >= 0) {
|
|
418
|
+
targetCount = Math.max(targetCount, activeIndex + 1);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
if (targetCount >= list.length) {
|
|
422
|
+
return list;
|
|
423
|
+
}
|
|
424
|
+
return list.slice(0, targetCount);
|
|
425
|
+
},
|
|
426
|
+
activeSessionVisibleMessages() {
|
|
427
|
+
if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
|
|
428
|
+
return [];
|
|
429
|
+
}
|
|
430
|
+
const list = Array.isArray(this.activeSessionMessages) ? this.activeSessionMessages : [];
|
|
431
|
+
const rawCount = Number(this.sessionPreviewVisibleCount);
|
|
432
|
+
const visibleCount = Number.isFinite(rawCount)
|
|
433
|
+
? Math.max(0, Math.floor(rawCount))
|
|
434
|
+
: 0;
|
|
435
|
+
if (visibleCount <= 0) {
|
|
436
|
+
const initialBatchSize = Number.isFinite(this.sessionPreviewInitialBatchSize)
|
|
437
|
+
? Math.max(1, Math.floor(this.sessionPreviewInitialBatchSize))
|
|
438
|
+
: 12;
|
|
439
|
+
return list.slice(0, Math.min(initialBatchSize, list.length));
|
|
440
|
+
}
|
|
441
|
+
if (visibleCount >= list.length) return list;
|
|
442
|
+
return list.slice(0, visibleCount);
|
|
443
|
+
},
|
|
444
|
+
canLoadMoreSessionMessages() {
|
|
445
|
+
if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
const total = Array.isArray(this.activeSessionMessages) ? this.activeSessionMessages.length : 0;
|
|
449
|
+
const visible = Array.isArray(this.activeSessionVisibleMessages) ? this.activeSessionVisibleMessages.length : 0;
|
|
450
|
+
return total > visible;
|
|
451
|
+
},
|
|
452
|
+
sessionPreviewRemainingCount() {
|
|
453
|
+
const total = Array.isArray(this.activeSessionMessages) ? this.activeSessionMessages.length : 0;
|
|
454
|
+
const visible = Array.isArray(this.activeSessionVisibleMessages) ? this.activeSessionVisibleMessages.length : 0;
|
|
455
|
+
return Math.max(0, total - visible);
|
|
456
|
+
},
|
|
457
|
+
sessionTimelineNodes() {
|
|
458
|
+
if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
|
|
459
|
+
return [];
|
|
460
|
+
}
|
|
461
|
+
return buildSessionTimelineNodes(this.activeSessionVisibleMessages, {
|
|
462
|
+
getKey: (message, index) => this.getRecordRenderKey(message, index)
|
|
463
|
+
});
|
|
464
|
+
},
|
|
465
|
+
sessionTimelineNodeKeyMap() {
|
|
466
|
+
const nodes = Array.isArray(this.sessionTimelineNodes) ? this.sessionTimelineNodes : [];
|
|
467
|
+
if (!nodes.length) {
|
|
468
|
+
return Object.create(null);
|
|
469
|
+
}
|
|
470
|
+
const map = Object.create(null);
|
|
471
|
+
for (const node of nodes) {
|
|
472
|
+
if (!node || !node.key) continue;
|
|
473
|
+
map[node.key] = true;
|
|
474
|
+
}
|
|
475
|
+
return map;
|
|
476
|
+
},
|
|
477
|
+
sessionTimelineActiveTitle() {
|
|
478
|
+
if (!this.sessionTimelineActiveKey) return '';
|
|
479
|
+
const nodes = Array.isArray(this.sessionTimelineNodes) ? this.sessionTimelineNodes : [];
|
|
480
|
+
const matched = nodes.find(node => node.key === this.sessionTimelineActiveKey);
|
|
481
|
+
return matched ? matched.title : '';
|
|
482
|
+
},
|
|
483
|
+
sessionQueryPlaceholder() {
|
|
484
|
+
if (this.isSessionQueryEnabled) {
|
|
485
|
+
return typeof this.t === 'function'
|
|
486
|
+
? this.t('sessions.query.placeholder.enabled')
|
|
487
|
+
: '关键词检索(支持 Codex/Claude,例:claude code)';
|
|
488
|
+
}
|
|
489
|
+
return typeof this.t === 'function'
|
|
490
|
+
? this.t('sessions.query.placeholder.disabled')
|
|
491
|
+
: '当前来源暂不支持关键词检索';
|
|
492
|
+
},
|
|
493
|
+
sessionUsageCharts() {
|
|
494
|
+
return buildUsageChartGroups(this.sessionsUsageList, {
|
|
495
|
+
range: this.sessionsUsageTimeRange
|
|
496
|
+
});
|
|
497
|
+
},
|
|
498
|
+
sessionUsageHeatmap() {
|
|
499
|
+
const sessions = this.sessionUsageCharts && Array.isArray(this.sessionUsageCharts.filteredSessions)
|
|
500
|
+
? this.sessionUsageCharts.filteredSessions
|
|
501
|
+
: this.sessionsUsageList;
|
|
502
|
+
const heatmap = buildUsageHeatmap(sessions, { range: this.sessionsUsageTimeRange });
|
|
503
|
+
const t = typeof this.t === 'function' ? this.t : null;
|
|
504
|
+
const lang = typeof this.lang === 'string' ? this.lang.trim().toLowerCase() : '';
|
|
505
|
+
const weekdayAxis = lang === 'en'
|
|
506
|
+
? ['Mon', '', 'Wed', '', 'Fri', '', '']
|
|
507
|
+
: ['周一', '', '周三', '', '周五', '', ''];
|
|
508
|
+
const months = lang === 'en'
|
|
509
|
+
? ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
|
510
|
+
: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'];
|
|
511
|
+
const windowWeeks = 52;
|
|
512
|
+
const allWeeks = Array.isArray(heatmap.weeks) ? heatmap.weeks : [];
|
|
513
|
+
const safeWindowWeeks = Math.max(1, Math.min(windowWeeks, allWeeks.length));
|
|
514
|
+
const startIndex = Math.max(0, allWeeks.length - safeWindowWeeks);
|
|
515
|
+
const displayWeeksRaw = allWeeks.slice(startIndex);
|
|
516
|
+
let max = 0;
|
|
517
|
+
for (const week of displayWeeksRaw) {
|
|
518
|
+
const days = Array.isArray(week.days) ? week.days : [];
|
|
519
|
+
for (const cell of days) {
|
|
520
|
+
if (cell && cell.isInRange) {
|
|
521
|
+
max = Math.max(max, cell.sessionCount || 0);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
max = Math.max(1, max);
|
|
526
|
+
const dayMs = 24 * 60 * 60 * 1000;
|
|
527
|
+
let lastMonth = -1;
|
|
528
|
+
const weeks = displayWeeksRaw.map((week) => {
|
|
529
|
+
const idx = Number.isFinite(Number(week.weekIndex)) ? Number(week.weekIndex) : 0;
|
|
530
|
+
const weekStartMs = (Number.isFinite(Number(heatmap.alignedStart)) ? Number(heatmap.alignedStart) : 0) + (idx * 7 * dayMs);
|
|
531
|
+
const month = Number.isFinite(weekStartMs) ? new Date(weekStartMs).getUTCMonth() : -1;
|
|
532
|
+
const monthLabel = (month >= 0 && month <= 11 && month !== lastMonth) ? months[month] : '';
|
|
533
|
+
if (month >= 0 && month <= 11) {
|
|
534
|
+
lastMonth = month;
|
|
535
|
+
}
|
|
536
|
+
return {
|
|
537
|
+
...week,
|
|
538
|
+
monthLabel,
|
|
539
|
+
days: (Array.isArray(week.days) ? week.days : []).map((cell) => {
|
|
540
|
+
if (!cell) return null;
|
|
541
|
+
if (!cell.isInRange) {
|
|
542
|
+
return {
|
|
543
|
+
...cell,
|
|
544
|
+
level: -1,
|
|
545
|
+
title: '',
|
|
546
|
+
ariaLabel: ''
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
const ratio = cell.sessionCount > 0 ? (cell.sessionCount / max) : 0;
|
|
550
|
+
const level = cell.sessionCount <= 0
|
|
551
|
+
? 0
|
|
552
|
+
: (ratio <= 0.25 ? 1 : (ratio <= 0.5 ? 2 : (ratio <= 0.75 ? 3 : 4)));
|
|
553
|
+
const tokensTitle = formatUsageSummaryNumber(cell.tokenTotal || 0);
|
|
554
|
+
const title = t
|
|
555
|
+
? t('usage.heatmap.tooltip', {
|
|
556
|
+
date: cell.dateKey,
|
|
557
|
+
sessions: cell.sessionCount,
|
|
558
|
+
messages: cell.messageCount,
|
|
559
|
+
tokens: tokensTitle
|
|
560
|
+
})
|
|
561
|
+
: `${cell.dateKey} · sessions ${cell.sessionCount} · messages ${cell.messageCount} · tokens ${tokensTitle}`;
|
|
562
|
+
const ariaLabel = t
|
|
563
|
+
? t('usage.heatmap.aria', {
|
|
564
|
+
date: cell.dateKey,
|
|
565
|
+
sessions: cell.sessionCount
|
|
566
|
+
})
|
|
567
|
+
: `${cell.dateKey} sessions ${cell.sessionCount}`;
|
|
568
|
+
return {
|
|
569
|
+
...cell,
|
|
570
|
+
level,
|
|
571
|
+
title,
|
|
572
|
+
ariaLabel
|
|
573
|
+
};
|
|
574
|
+
})
|
|
575
|
+
};
|
|
576
|
+
});
|
|
577
|
+
return {
|
|
578
|
+
...heatmap,
|
|
579
|
+
weeks,
|
|
580
|
+
weekdayAxis
|
|
581
|
+
};
|
|
582
|
+
},
|
|
583
|
+
sessionUsageSummaryCards() {
|
|
584
|
+
const summary = this.sessionUsageCharts && this.sessionUsageCharts.summary
|
|
585
|
+
? this.sessionUsageCharts.summary
|
|
586
|
+
: { totalSessions: 0, totalMessages: 0, totalTokens: 0, totalContextWindow: 0, activeDurationMs: 0, totalDurationMs: 0, activeDays: 0, avgMessagesPerSession: 0, busiestDay: null, busiestHour: null };
|
|
587
|
+
const filteredUsageSessions = this.sessionUsageCharts && Array.isArray(this.sessionUsageCharts.filteredSessions)
|
|
588
|
+
? this.sessionUsageCharts.filteredSessions
|
|
589
|
+
: this.sessionsUsageList;
|
|
590
|
+
const t = typeof this.t === 'function' ? this.t : null;
|
|
591
|
+
const usageRangeLabel = formatUsageRangeLabel(this.sessionsUsageTimeRange, t);
|
|
592
|
+
const estimatedCost = estimateUsageCostSummary(
|
|
593
|
+
filteredUsageSessions,
|
|
594
|
+
this.providersList,
|
|
595
|
+
this.currentProvider
|
|
596
|
+
);
|
|
597
|
+
const noneLabel = t ? t('common.none') : '暂无';
|
|
598
|
+
const estimatedCostPrefix = estimatedCost.skippedUnsupportedSessions > 0
|
|
599
|
+
? (t ? t('usage.estimatedCost.note.excludesClaudePrefix') : '暂不含 Claude,')
|
|
600
|
+
: '';
|
|
601
|
+
const estimatedCostMethod = estimatedCost.catalogSessions > 0
|
|
602
|
+
? (estimatedCost.configuredSessions > 0
|
|
603
|
+
? (t ? t('usage.estimatedCost.method.configuredAndCatalog') : '按已配置单价 + 公开模型目录估算')
|
|
604
|
+
: (t ? t('usage.estimatedCost.method.catalog') : '按公开模型目录估算'))
|
|
605
|
+
: (t ? t('usage.estimatedCost.method.configured') : '按已配置单价估算');
|
|
606
|
+
const estimatedCostTitle = estimatedCost.hasEstimate
|
|
607
|
+
? (t ? t('usage.estimatedCost.detail.estimate', {
|
|
608
|
+
prefix: estimatedCostPrefix,
|
|
609
|
+
method: estimatedCostMethod,
|
|
610
|
+
estimate: formatUsageEstimatedCost(estimatedCost.totalCostUsd, { precise: true }),
|
|
611
|
+
covered: estimatedCost.estimatedSessions,
|
|
612
|
+
total: estimatedCost.totalSessions,
|
|
613
|
+
percent: estimatedCost.coveragePercent
|
|
614
|
+
}) : `${estimatedCostPrefix}${estimatedCostMethod},估算 ${formatUsageEstimatedCost(estimatedCost.totalCostUsd, { precise: true })},覆盖 ${estimatedCost.estimatedSessions}/${estimatedCost.totalSessions} 个会话,约 ${estimatedCost.coveragePercent}% token`)
|
|
615
|
+
: (t ? t('usage.estimatedCost.detail.missing', { prefix: estimatedCostPrefix }) : `${estimatedCostPrefix}缺少可匹配的模型单价或 token 拆分。请先补 models.cost,或确认会话已记录 input/output token。`);
|
|
616
|
+
return [
|
|
617
|
+
{ key: 'sessions', label: t ? t('usage.summary.sessions') : '总会话数', value: formatUsageSummaryNumber(summary.totalSessions || 0) },
|
|
618
|
+
{ key: 'messages', label: t ? t('usage.summary.messages') : '总消息数', value: formatUsageSummaryNumber(summary.totalMessages || 0) },
|
|
619
|
+
{
|
|
620
|
+
key: 'tokens',
|
|
621
|
+
label: t ? t('usage.summary.tokens') : '总 token 数',
|
|
622
|
+
value: formatCompactUsageSummaryNumber(summary.totalTokens || 0),
|
|
623
|
+
title: formatUsageSummaryNumber(summary.totalTokens || 0)
|
|
624
|
+
},
|
|
625
|
+
{
|
|
626
|
+
key: 'context-window',
|
|
627
|
+
label: t ? t('usage.summary.contextWindow') : '总上下文数',
|
|
628
|
+
value: formatCompactUsageSummaryNumber(summary.totalContextWindow || 0),
|
|
629
|
+
title: formatUsageSummaryNumber(summary.totalContextWindow || 0)
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
key: 'estimated-cost',
|
|
633
|
+
label: t ? t('usage.summary.estimatedCost', { range: usageRangeLabel }) : `预估费用 · ${usageRangeLabel}`,
|
|
634
|
+
value: estimatedCost.hasEstimate ? formatUsageEstimatedCost(estimatedCost.totalCostUsd) : '0',
|
|
635
|
+
title: estimatedCostTitle
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
key: 'active-duration',
|
|
639
|
+
label: t ? t('usage.summary.activeDuration') : '活跃时长',
|
|
640
|
+
value: formatUsageDuration(summary.activeDurationMs || 0, { compact: true, lang: this.lang }),
|
|
641
|
+
title: t
|
|
642
|
+
? t('usage.summary.activeDuration.title', {
|
|
643
|
+
value: formatUsageDuration(summary.activeDurationMs || 0, { maxParts: 3, compact: false, lang: this.lang })
|
|
644
|
+
})
|
|
645
|
+
: `累计会话跨度 ${formatUsageDuration(summary.activeDurationMs || 0, { maxParts: 3, compact: false, lang: this.lang })}`
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
key: 'total-duration',
|
|
649
|
+
label: t ? t('usage.summary.totalDuration') : '总时长',
|
|
650
|
+
value: formatUsageDuration(summary.totalDurationMs || 0, { compact: true, lang: this.lang }),
|
|
651
|
+
title: t
|
|
652
|
+
? t('usage.summary.totalDuration.title', {
|
|
653
|
+
value: formatUsageDuration(summary.totalDurationMs || 0, { maxParts: 3, compact: false, lang: this.lang })
|
|
654
|
+
})
|
|
655
|
+
: `整体时间跨度 ${formatUsageDuration(summary.totalDurationMs || 0, { maxParts: 3, compact: false, lang: this.lang })}`
|
|
656
|
+
},
|
|
657
|
+
{ key: 'days', label: t ? t('usage.summary.activeDays') : '活跃天数', value: formatUsageSummaryNumber(summary.activeDays || 0) },
|
|
658
|
+
{ key: 'avg-messages', label: t ? t('usage.summary.avgMessagesPerSession') : '平均每会话消息', value: summary.avgMessagesPerSession || 0 },
|
|
659
|
+
{
|
|
660
|
+
key: 'busiest-day',
|
|
661
|
+
label: t ? t('usage.summary.busiestDay') : '最忙日',
|
|
662
|
+
value: summary.busiestDay && summary.busiestDay.totalSessions > 0
|
|
663
|
+
? `${summary.busiestDay.label} · ${summary.busiestDay.totalSessions}`
|
|
664
|
+
: noneLabel
|
|
665
|
+
},
|
|
666
|
+
{
|
|
667
|
+
key: 'busiest-hour',
|
|
668
|
+
label: t ? t('usage.summary.busiestHour') : '高峰时段',
|
|
669
|
+
value: summary.busiestHour && summary.busiestHour.count > 0
|
|
670
|
+
? `${summary.busiestHour.label} · ${summary.busiestHour.count}`
|
|
671
|
+
: noneLabel
|
|
672
|
+
}
|
|
673
|
+
];
|
|
674
|
+
},
|
|
675
|
+
|
|
676
|
+
usageCurrentSessionStats() {
|
|
677
|
+
const summary = this.sessionUsageCharts && this.sessionUsageCharts.summary
|
|
678
|
+
? this.sessionUsageCharts.summary
|
|
679
|
+
: null;
|
|
680
|
+
if (!summary) return null;
|
|
681
|
+
const t = typeof this.t === 'function' ? this.t : null;
|
|
682
|
+
return {
|
|
683
|
+
apiDurationLabel: formatUsageDuration(summary.activeDurationMs || 0, { compact: true, lang: this.lang }),
|
|
684
|
+
totalDurationLabel: formatUsageDuration(summary.totalDurationMs || 0, { compact: true, lang: this.lang }),
|
|
685
|
+
tokenLabel: formatCompactUsageSummaryNumber(summary.totalTokens || 0),
|
|
686
|
+
label: t ? t('usage.currentSession.title') : '当前会话',
|
|
687
|
+
apiDurationText: t ? t('usage.currentSession.apiDuration') : 'API时长',
|
|
688
|
+
totalDurationText: t ? t('usage.currentSession.totalDuration') : '总时长',
|
|
689
|
+
tokenText: t ? t('usage.currentSession.tokens') : 'Token'
|
|
690
|
+
};
|
|
691
|
+
},
|
|
692
|
+
|
|
693
|
+
sessionUsageDaily() {
|
|
694
|
+
const baseBuckets = this.sessionUsageCharts && Array.isArray(this.sessionUsageCharts.buckets)
|
|
695
|
+
? this.sessionUsageCharts.buckets
|
|
696
|
+
: [];
|
|
697
|
+
const pricingIndex = buildUsagePricingIndex(this.providersList);
|
|
698
|
+
const compareEnabled = this.sessionsUsageCompareEnabled === true && this.sessionsUsageTimeRange !== 'all';
|
|
699
|
+
const sessions = compareEnabled
|
|
700
|
+
? this.sessionsUsageList
|
|
701
|
+
: (this.sessionUsageCharts && Array.isArray(this.sessionUsageCharts.filteredSessions)
|
|
702
|
+
? this.sessionUsageCharts.filteredSessions
|
|
703
|
+
: this.sessionsUsageList);
|
|
704
|
+
const rangeDays = this.sessionsUsageTimeRange === '30d' ? 30 : 7;
|
|
705
|
+
const dayMs = 24 * 60 * 60 * 1000;
|
|
706
|
+
const byDay = new Map();
|
|
707
|
+
|
|
708
|
+
for (const bucket of baseBuckets) {
|
|
709
|
+
if (!bucket || !bucket.key) continue;
|
|
710
|
+
byDay.set(bucket.key, {
|
|
711
|
+
key: bucket.key,
|
|
712
|
+
label: bucket.label || bucket.key.slice(5),
|
|
713
|
+
sessionCount: 0,
|
|
714
|
+
messageCount: 0,
|
|
715
|
+
tokenTotal: 0,
|
|
716
|
+
estimatedCostUsd: 0,
|
|
717
|
+
estimatedSessions: 0,
|
|
718
|
+
hasCostEstimate: false
|
|
719
|
+
});
|
|
720
|
+
if (compareEnabled) {
|
|
721
|
+
const baseMs = Date.parse(`${bucket.key}T00:00:00.000Z`);
|
|
722
|
+
if (Number.isFinite(baseMs)) {
|
|
723
|
+
const prevKey = new Date(baseMs - (rangeDays * dayMs)).toISOString().slice(0, 10);
|
|
724
|
+
if (!byDay.has(prevKey)) {
|
|
725
|
+
byDay.set(prevKey, {
|
|
726
|
+
key: prevKey,
|
|
727
|
+
label: prevKey.slice(5),
|
|
728
|
+
sessionCount: 0,
|
|
729
|
+
messageCount: 0,
|
|
730
|
+
tokenTotal: 0,
|
|
731
|
+
estimatedCostUsd: 0,
|
|
732
|
+
estimatedSessions: 0,
|
|
733
|
+
hasCostEstimate: false
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
for (const session of (Array.isArray(sessions) ? sessions : [])) {
|
|
741
|
+
if (!session || typeof session !== 'object') continue;
|
|
742
|
+
const updatedAtMs = Date.parse(session.updatedAt || '');
|
|
743
|
+
if (!Number.isFinite(updatedAtMs)) continue;
|
|
744
|
+
const dayKey = new Date(updatedAtMs).toISOString().slice(0, 10);
|
|
745
|
+
const row = byDay.get(dayKey);
|
|
746
|
+
if (!row) continue;
|
|
747
|
+
|
|
748
|
+
const messageCount = Number.isFinite(Number(session.messageCount))
|
|
749
|
+
? Math.max(0, Math.floor(Number(session.messageCount)))
|
|
750
|
+
: 0;
|
|
751
|
+
const tokenTotal = Number.isFinite(Number(session.totalTokens))
|
|
752
|
+
? Math.max(0, Math.floor(Number(session.totalTokens)))
|
|
753
|
+
: 0;
|
|
754
|
+
row.sessionCount += 1;
|
|
755
|
+
row.messageCount += messageCount;
|
|
756
|
+
row.tokenTotal += tokenTotal;
|
|
757
|
+
|
|
758
|
+
if (shouldEstimateUsageCostForSession(session)) {
|
|
759
|
+
const cost = estimateUsageCostForSession(session, pricingIndex, this.currentProvider);
|
|
760
|
+
if (cost.pricing && cost.hasTokenBreakdown) {
|
|
761
|
+
row.estimatedCostUsd += cost.estimatedUsd;
|
|
762
|
+
row.estimatedSessions += 1;
|
|
763
|
+
row.hasCostEstimate = true;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
const currentKeys = baseBuckets.map((bucket) => bucket && bucket.key).filter(Boolean);
|
|
769
|
+
const rows = currentKeys
|
|
770
|
+
.map((key) => byDay.get(key))
|
|
771
|
+
.filter(Boolean)
|
|
772
|
+
.sort((a, b) => b.key.localeCompare(a.key, 'en-US'));
|
|
773
|
+
const rowsWithCompare = rows.map((row) => {
|
|
774
|
+
if (!compareEnabled) {
|
|
775
|
+
return { ...row, compareEnabled: false, prevKey: '', prevTokenTotal: 0, prevCostUsd: 0 };
|
|
776
|
+
}
|
|
777
|
+
const baseMs = Date.parse(`${row.key}T00:00:00.000Z`);
|
|
778
|
+
const prevKey = Number.isFinite(baseMs)
|
|
779
|
+
? new Date(baseMs - (rangeDays * dayMs)).toISOString().slice(0, 10)
|
|
780
|
+
: '';
|
|
781
|
+
const prevRow = prevKey ? byDay.get(prevKey) : null;
|
|
782
|
+
return {
|
|
783
|
+
...row,
|
|
784
|
+
compareEnabled: true,
|
|
785
|
+
prevKey,
|
|
786
|
+
prevTokenTotal: prevRow ? prevRow.tokenTotal : 0,
|
|
787
|
+
prevCostUsd: prevRow ? prevRow.estimatedCostUsd : 0
|
|
788
|
+
};
|
|
789
|
+
});
|
|
790
|
+
const maxTokens = rowsWithCompare.reduce((max, item) => Math.max(max, item.tokenTotal, item.prevTokenTotal || 0), 0);
|
|
791
|
+
const maxCost = rowsWithCompare.reduce((max, item) => Math.max(max, item.estimatedCostUsd, item.prevCostUsd || 0), 0);
|
|
792
|
+
|
|
793
|
+
return {
|
|
794
|
+
rows: rowsWithCompare.map((row) => ({
|
|
795
|
+
...row,
|
|
796
|
+
tokenLabel: formatCompactUsageSummaryNumber(row.tokenTotal),
|
|
797
|
+
tokenTitle: formatUsageSummaryNumber(row.tokenTotal),
|
|
798
|
+
tokenPercent: maxTokens > 0 ? Math.round((row.tokenTotal / maxTokens) * 1000) / 10 : 0,
|
|
799
|
+
prevTokenPercent: row.compareEnabled && maxTokens > 0 ? Math.round(((row.prevTokenTotal || 0) / maxTokens) * 1000) / 10 : 0,
|
|
800
|
+
prevTokenTitle: row.compareEnabled ? formatUsageSummaryNumber(row.prevTokenTotal || 0) : '',
|
|
801
|
+
costLabel: row.hasCostEstimate ? formatUsageEstimatedCost(row.estimatedCostUsd) : '0',
|
|
802
|
+
costTitle: row.hasCostEstimate ? formatUsageEstimatedCost(row.estimatedCostUsd, { precise: true }) : '0',
|
|
803
|
+
costPercent: maxCost > 0 ? Math.round((row.estimatedCostUsd / maxCost) * 1000) / 10 : 0,
|
|
804
|
+
prevCostPercent: row.compareEnabled && maxCost > 0 ? Math.round(((row.prevCostUsd || 0) / maxCost) * 1000) / 10 : 0,
|
|
805
|
+
prevCostTitle: row.compareEnabled ? formatUsageEstimatedCost(row.prevCostUsd || 0, { precise: true }) : ''
|
|
806
|
+
})),
|
|
807
|
+
maxTokens,
|
|
808
|
+
maxCost
|
|
809
|
+
};
|
|
810
|
+
},
|
|
811
|
+
|
|
812
|
+
sessionUsageDailyTableRows() {
|
|
813
|
+
const daily = this.sessionUsageDaily && typeof this.sessionUsageDaily === 'object'
|
|
814
|
+
? this.sessionUsageDaily
|
|
815
|
+
: null;
|
|
816
|
+
return daily && Array.isArray(daily.rows) ? daily.rows : [];
|
|
817
|
+
},
|
|
818
|
+
|
|
819
|
+
sessionsUsageSelectedDaySummary() {
|
|
820
|
+
const dayKey = typeof this.sessionsUsageSelectedDayKey === 'string' ? this.sessionsUsageSelectedDayKey.trim() : '';
|
|
821
|
+
if (!dayKey) return null;
|
|
822
|
+
const sessions = this.sessionUsageCharts && Array.isArray(this.sessionUsageCharts.filteredSessions)
|
|
823
|
+
? this.sessionUsageCharts.filteredSessions
|
|
824
|
+
: this.sessionsUsageList;
|
|
825
|
+
const pricingIndex = buildUsagePricingIndex(this.providersList);
|
|
826
|
+
const compareEnabled = this.sessionsUsageCompareEnabled === true && this.sessionsUsageTimeRange !== 'all';
|
|
827
|
+
const rangeDays = this.sessionsUsageTimeRange === '30d' ? 30 : 7;
|
|
828
|
+
const dayMs = 24 * 60 * 60 * 1000;
|
|
829
|
+
const baseMs = Date.parse(`${dayKey}T00:00:00.000Z`);
|
|
830
|
+
const prevKey = compareEnabled && Number.isFinite(baseMs)
|
|
831
|
+
? new Date(baseMs - (rangeDays * dayMs)).toISOString().slice(0, 10)
|
|
832
|
+
: '';
|
|
833
|
+
let sessionCount = 0;
|
|
834
|
+
let messageCount = 0;
|
|
835
|
+
let tokenTotal = 0;
|
|
836
|
+
let estimatedCostUsd = 0;
|
|
837
|
+
let hasCostEstimate = false;
|
|
838
|
+
let prevTokenTotal = 0;
|
|
839
|
+
let prevEstimatedCostUsd = 0;
|
|
840
|
+
let prevHasCostEstimate = false;
|
|
841
|
+
const modelMap = new Map();
|
|
842
|
+
const sessionRows = [];
|
|
843
|
+
for (const session of (Array.isArray(sessions) ? sessions : [])) {
|
|
844
|
+
if (!session || typeof session !== 'object') continue;
|
|
845
|
+
const updatedAtMs = Date.parse(session.updatedAt || '');
|
|
846
|
+
if (!Number.isFinite(updatedAtMs)) continue;
|
|
847
|
+
const key = new Date(updatedAtMs).toISOString().slice(0, 10);
|
|
848
|
+
const isCurrent = key === dayKey;
|
|
849
|
+
const isPrev = !!prevKey && key === prevKey;
|
|
850
|
+
if (!isCurrent && !isPrev) continue;
|
|
851
|
+
const msgCount = Number.isFinite(Number(session.messageCount))
|
|
852
|
+
? Math.max(0, Math.floor(Number(session.messageCount)))
|
|
853
|
+
: 0;
|
|
854
|
+
const sessionTokens = Number.isFinite(Number(session.totalTokens))
|
|
855
|
+
? Math.max(0, Math.floor(Number(session.totalTokens)))
|
|
856
|
+
: 0;
|
|
857
|
+
if (isCurrent) {
|
|
858
|
+
sessionCount += 1;
|
|
859
|
+
messageCount += msgCount;
|
|
860
|
+
tokenTotal += sessionTokens;
|
|
861
|
+
} else if (isPrev) {
|
|
862
|
+
prevTokenTotal += sessionTokens;
|
|
863
|
+
}
|
|
864
|
+
if (shouldEstimateUsageCostForSession(session)) {
|
|
865
|
+
const cost = estimateUsageCostForSession(session, pricingIndex, this.currentProvider);
|
|
866
|
+
if (cost.pricing && cost.hasTokenBreakdown) {
|
|
867
|
+
if (isCurrent) {
|
|
868
|
+
estimatedCostUsd += cost.estimatedUsd;
|
|
869
|
+
hasCostEstimate = true;
|
|
870
|
+
} else if (isPrev) {
|
|
871
|
+
prevEstimatedCostUsd += cost.estimatedUsd;
|
|
872
|
+
prevHasCostEstimate = true;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
const model = typeof session.model === 'string' ? session.model.trim() : '';
|
|
877
|
+
if (isCurrent && model) {
|
|
878
|
+
modelMap.set(model, (modelMap.get(model) || 0) + 1);
|
|
879
|
+
}
|
|
880
|
+
const title = typeof session.title === 'string' && session.title.trim()
|
|
881
|
+
? session.title.trim()
|
|
882
|
+
: (typeof session.sessionId === 'string' && session.sessionId.trim() ? session.sessionId.trim() : '未命名会话');
|
|
883
|
+
if (isCurrent) {
|
|
884
|
+
sessionRows.push({
|
|
885
|
+
key: this.getSessionExportKey(session) || `${title}:${sessionCount}`,
|
|
886
|
+
title,
|
|
887
|
+
messageCount: msgCount
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
sessionRows.sort((a, b) => b.messageCount - a.messageCount);
|
|
892
|
+
const lang = typeof this.lang === 'string' ? this.lang.trim().toLowerCase() : '';
|
|
893
|
+
const suffix = lang === 'en' ? 'msgs' : '条';
|
|
894
|
+
const topSessions = sessionRows.slice(0, 8).map((item) => ({
|
|
895
|
+
...item,
|
|
896
|
+
messageCountLabel: `${item.messageCount} ${suffix}`
|
|
897
|
+
}));
|
|
898
|
+
const topModels = [...modelMap.entries()]
|
|
899
|
+
.sort((a, b) => b[1] - a[1])
|
|
900
|
+
.slice(0, 6)
|
|
901
|
+
.map(([model, count]) => ({
|
|
902
|
+
key: model,
|
|
903
|
+
label: `${model} · ${count}`
|
|
904
|
+
}));
|
|
905
|
+
return {
|
|
906
|
+
dayKey,
|
|
907
|
+
compareEnabled,
|
|
908
|
+
prevKey,
|
|
909
|
+
sessionCount,
|
|
910
|
+
messageCount,
|
|
911
|
+
tokenTotal,
|
|
912
|
+
tokenLabel: formatUsageSummaryNumber(tokenTotal),
|
|
913
|
+
costLabel: hasCostEstimate ? formatUsageEstimatedCost(estimatedCostUsd) : '0',
|
|
914
|
+
prevTokenTotal,
|
|
915
|
+
prevTokenLabel: compareEnabled ? formatUsageSummaryNumber(prevTokenTotal) : '0',
|
|
916
|
+
deltaTokenLabel: compareEnabled ? formatSignedUsageSummaryNumber(tokenTotal - prevTokenTotal) : '0',
|
|
917
|
+
prevCostLabel: compareEnabled ? (prevHasCostEstimate ? formatUsageEstimatedCost(prevEstimatedCostUsd) : '0') : '0',
|
|
918
|
+
deltaCostLabel: compareEnabled ? formatSignedUsageEstimatedCost(estimatedCostUsd - prevEstimatedCostUsd, { precise: true }) : '0',
|
|
919
|
+
topSessions,
|
|
920
|
+
topModels
|
|
921
|
+
};
|
|
922
|
+
},
|
|
923
|
+
|
|
924
|
+
visibleSessionTrashItems() {
|
|
925
|
+
const items = Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems : [];
|
|
926
|
+
const visibleCount = Number(this.sessionTrashVisibleCount);
|
|
927
|
+
const safeVisibleCount = Number.isFinite(visibleCount) && visibleCount > 0
|
|
928
|
+
? Math.floor(visibleCount)
|
|
929
|
+
: SESSION_TRASH_PAGE_SIZE;
|
|
930
|
+
return items.slice(0, safeVisibleCount);
|
|
931
|
+
},
|
|
932
|
+
sessionTrashHasMoreItems() {
|
|
933
|
+
return this.visibleSessionTrashItems.length < this.sessionTrashCount;
|
|
934
|
+
},
|
|
935
|
+
sessionTrashHiddenCount() {
|
|
936
|
+
return Math.max(0, this.sessionTrashCount - this.visibleSessionTrashItems.length);
|
|
937
|
+
},
|
|
938
|
+
sessionTrashCount() {
|
|
939
|
+
const totalCount = Number(this.sessionTrashTotalCount);
|
|
940
|
+
if (Number.isFinite(totalCount) && totalCount >= 0) {
|
|
941
|
+
return Math.max(0, Math.floor(totalCount));
|
|
942
|
+
}
|
|
943
|
+
return Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems.length : 0;
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
}
|