codexmate 0.0.21 → 0.0.23
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 +390 -284
- package/README.zh.md +322 -0
- package/cli/agents-files.js +224 -162
- package/cli/archive-helpers.js +446 -446
- package/cli/auth-profiles.js +359 -359
- package/cli/builtin-proxy.js +1044 -580
- package/cli/claude-proxy.js +998 -998
- package/cli/config-bootstrap.js +384 -384
- package/cli/config-health.js +338 -338
- package/cli/openai-bridge.js +950 -0
- package/cli/openclaw-config.js +629 -629
- package/cli/session-usage.concurrent.js +28 -0
- package/cli/session-usage.js +112 -0
- package/cli/session-usage.models.js +176 -0
- package/cli/skills.js +1141 -1141
- package/cli/zip-commands.js +510 -510
- package/cli.js +13214 -13129
- package/lib/cli-file-utils.js +151 -151
- package/lib/cli-models-utils.js +419 -419
- package/lib/cli-network-utils.js +164 -164
- package/lib/cli-path-utils.js +69 -69
- package/lib/cli-session-utils.js +121 -121
- package/lib/cli-sessions.js +386 -386
- package/lib/cli-utils.js +155 -155
- package/lib/download-artifacts.js +77 -77
- package/lib/mcp-stdio.js +440 -440
- 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/res/json5.min.js +1 -1
- package/res/logo.png +0 -0
- package/res/vue.global.prod.js +13 -13
- package/web-ui/app.js +626 -530
- package/web-ui/index.html +34 -33
- 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 -124
- package/web-ui/logic.sessions.mjs +614 -581
- package/web-ui/modules/api.mjs +90 -90
- package/web-ui/modules/app.computed.dashboard.mjs +126 -113
- package/web-ui/modules/app.computed.index.mjs +17 -15
- package/web-ui/modules/app.computed.main-tabs.mjs +202 -195
- package/web-ui/modules/app.computed.session.mjs +653 -507
- package/web-ui/modules/app.constants.mjs +15 -15
- package/web-ui/modules/app.methods.agents.mjs +544 -493
- package/web-ui/modules/app.methods.claude-config.mjs +174 -174
- package/web-ui/modules/app.methods.codex-config.mjs +795 -640
- package/web-ui/modules/app.methods.index.mjs +92 -88
- package/web-ui/modules/app.methods.install.mjs +177 -149
- package/web-ui/modules/app.methods.navigation.mjs +662 -619
- 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 -363
- package/web-ui/modules/app.methods.runtime.mjs +323 -323
- package/web-ui/modules/app.methods.session-actions.mjs +537 -520
- package/web-ui/modules/app.methods.session-browser.mjs +691 -626
- package/web-ui/modules/app.methods.session-timeline.mjs +448 -448
- package/web-ui/modules/app.methods.session-trash.mjs +422 -422
- package/web-ui/modules/app.methods.startup-claude.mjs +417 -412
- package/web-ui/modules/app.methods.task-orchestration.mjs +556 -471
- package/web-ui/modules/config-mode.computed.mjs +126 -126
- package/web-ui/modules/config-template-confirm-pref.mjs +33 -0
- package/web-ui/modules/i18n.mjs +1823 -0
- package/web-ui/modules/plugins.computed.mjs +3 -0
- package/web-ui/modules/plugins.methods.mjs +3 -0
- package/web-ui/modules/plugins.storage.mjs +11 -0
- package/web-ui/modules/sessions-filters-url.mjs +85 -0
- 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 +461 -402
- package/web-ui/partials/index/modal-config-template-agents.html +175 -125
- package/web-ui/partials/index/modal-confirm-toast.html +32 -32
- package/web-ui/partials/index/modal-health-check.html +72 -72
- package/web-ui/partials/index/modal-openclaw-config.html +280 -280
- package/web-ui/partials/index/modal-skills.html +200 -184
- package/web-ui/partials/index/modals-basic.html +165 -156
- package/web-ui/partials/index/panel-config-claude.html +159 -126
- package/web-ui/partials/index/panel-config-codex.html +255 -237
- package/web-ui/partials/index/panel-config-openclaw.html +78 -78
- package/web-ui/partials/index/panel-docs.html +147 -130
- package/web-ui/partials/index/panel-market.html +174 -174
- package/web-ui/partials/index/panel-orchestration.html +388 -397
- package/web-ui/partials/index/panel-plugins.html +273 -0
- package/web-ui/partials/index/panel-sessions.html +298 -292
- package/web-ui/partials/index/panel-settings.html +258 -190
- package/web-ui/partials/index/panel-usage.html +353 -213
- package/web-ui/session-helpers.mjs +573 -559
- package/web-ui/source-bundle.cjs +233 -233
- package/web-ui/styles/base-theme.css +264 -271
- package/web-ui/styles/controls-forms.css +369 -360
- package/web-ui/styles/docs-panel.css +247 -182
- 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 +602 -376
- package/web-ui/styles/modals-core.css +464 -464
- package/web-ui/styles/navigation-panels.css +390 -348
- package/web-ui/styles/openclaw-structured.css +266 -266
- package/web-ui/styles/plugins-panel.css +523 -0
- package/web-ui/styles/responsive.css +456 -450
- package/web-ui/styles/sessions-list.css +400 -400
- package/web-ui/styles/sessions-preview.css +411 -411
- package/web-ui/styles/sessions-toolbar-trash.css +268 -243
- package/web-ui/styles/sessions-usage.css +879 -628
- package/web-ui/styles/settings-panel.css +166 -0
- package/web-ui/styles/skills-list.css +303 -296
- package/web-ui/styles/skills-market.css +406 -335
- package/web-ui/styles/task-orchestration.css +822 -776
- package/web-ui/styles/titles-cards.css +408 -408
- package/web-ui/styles.css +20 -18
- package/web-ui.html +17 -17
- package/README.en.md +0 -349
|
@@ -1,507 +1,653 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buildSessionTimelineNodes,
|
|
3
|
-
buildUsageChartGroups,
|
|
4
|
-
isSessionQueryEnabled
|
|
5
|
-
} from '../logic.mjs';
|
|
6
|
-
import { SESSION_TRASH_PAGE_SIZE } from './app.constants.mjs';
|
|
7
|
-
|
|
8
|
-
function formatUsageSummaryNumber(value) {
|
|
9
|
-
const numeric = Number(value);
|
|
10
|
-
if (!Number.isFinite(numeric) || numeric < 0) {
|
|
11
|
-
return '0';
|
|
12
|
-
}
|
|
13
|
-
return Math.floor(numeric).toLocaleString('en-US');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function formatCompactUsageSummaryNumber(value) {
|
|
17
|
-
const numeric = Number(value);
|
|
18
|
-
if (!Number.isFinite(numeric) || numeric < 0) {
|
|
19
|
-
return '0';
|
|
20
|
-
}
|
|
21
|
-
return new Intl.NumberFormat('en-US', {
|
|
22
|
-
notation: 'compact',
|
|
23
|
-
compactDisplay: 'short',
|
|
24
|
-
maximumFractionDigits: 1
|
|
25
|
-
}).format(Math.floor(numeric));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function readUsageCostNumber(value) {
|
|
29
|
-
const numeric = Number(value);
|
|
30
|
-
if (!Number.isFinite(numeric) || numeric < 0) {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
return numeric;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function formatUsageEstimatedCost(value, options = {}) {
|
|
37
|
-
const numeric = Number(value);
|
|
38
|
-
if (!Number.isFinite(numeric) || numeric <= 0) {
|
|
39
|
-
return '$0.00';
|
|
40
|
-
}
|
|
41
|
-
const precise = options && options.precise === true;
|
|
42
|
-
if (numeric < 0.0001) {
|
|
43
|
-
return '<$0.0001';
|
|
44
|
-
}
|
|
45
|
-
let fractionDigits = 2;
|
|
46
|
-
if (numeric < 1) {
|
|
47
|
-
fractionDigits = precise ? 6 : 4;
|
|
48
|
-
} else if (numeric >= 100) {
|
|
49
|
-
fractionDigits = 0;
|
|
50
|
-
}
|
|
51
|
-
return new Intl.NumberFormat('en-US', {
|
|
52
|
-
style: 'currency',
|
|
53
|
-
currency: 'USD',
|
|
54
|
-
minimumFractionDigits: fractionDigits,
|
|
55
|
-
maximumFractionDigits: fractionDigits
|
|
56
|
-
}).format(numeric);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function formatUsageRangeLabel(range) {
|
|
60
|
-
const normalized = typeof range === 'string' ? range.trim().toLowerCase() : '7d';
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
?
|
|
77
|
-
|
|
78
|
-
const
|
|
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
|
-
|
|
110
|
-
|
|
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
|
-
const
|
|
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
|
-
return
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function
|
|
196
|
-
if (!session || typeof session !== 'object') {
|
|
197
|
-
return
|
|
198
|
-
}
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const
|
|
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
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
totalTokens
|
|
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
|
-
const
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
if (
|
|
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
|
-
const
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
const
|
|
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
|
-
: this.
|
|
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
|
-
|
|
1
|
+
import {
|
|
2
|
+
buildSessionTimelineNodes,
|
|
3
|
+
buildUsageChartGroups,
|
|
4
|
+
isSessionQueryEnabled
|
|
5
|
+
} from '../logic.mjs';
|
|
6
|
+
import { SESSION_TRASH_PAGE_SIZE } from './app.constants.mjs';
|
|
7
|
+
|
|
8
|
+
function formatUsageSummaryNumber(value) {
|
|
9
|
+
const numeric = Number(value);
|
|
10
|
+
if (!Number.isFinite(numeric) || numeric < 0) {
|
|
11
|
+
return '0';
|
|
12
|
+
}
|
|
13
|
+
return Math.floor(numeric).toLocaleString('en-US');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function formatCompactUsageSummaryNumber(value) {
|
|
17
|
+
const numeric = Number(value);
|
|
18
|
+
if (!Number.isFinite(numeric) || numeric < 0) {
|
|
19
|
+
return '0';
|
|
20
|
+
}
|
|
21
|
+
return new Intl.NumberFormat('en-US', {
|
|
22
|
+
notation: 'compact',
|
|
23
|
+
compactDisplay: 'short',
|
|
24
|
+
maximumFractionDigits: 1
|
|
25
|
+
}).format(Math.floor(numeric));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function readUsageCostNumber(value) {
|
|
29
|
+
const numeric = Number(value);
|
|
30
|
+
if (!Number.isFinite(numeric) || numeric < 0) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return numeric;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function formatUsageEstimatedCost(value, options = {}) {
|
|
37
|
+
const numeric = Number(value);
|
|
38
|
+
if (!Number.isFinite(numeric) || numeric <= 0) {
|
|
39
|
+
return '$0.00';
|
|
40
|
+
}
|
|
41
|
+
const precise = options && options.precise === true;
|
|
42
|
+
if (numeric < 0.0001) {
|
|
43
|
+
return '<$0.0001';
|
|
44
|
+
}
|
|
45
|
+
let fractionDigits = 2;
|
|
46
|
+
if (numeric < 1) {
|
|
47
|
+
fractionDigits = precise ? 6 : 4;
|
|
48
|
+
} else if (numeric >= 100) {
|
|
49
|
+
fractionDigits = 0;
|
|
50
|
+
}
|
|
51
|
+
return new Intl.NumberFormat('en-US', {
|
|
52
|
+
style: 'currency',
|
|
53
|
+
currency: 'USD',
|
|
54
|
+
minimumFractionDigits: fractionDigits,
|
|
55
|
+
maximumFractionDigits: fractionDigits
|
|
56
|
+
}).format(numeric);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function formatUsageRangeLabel(range, t) {
|
|
60
|
+
const normalized = typeof range === 'string' ? range.trim().toLowerCase() : '7d';
|
|
61
|
+
if (typeof t === 'function') {
|
|
62
|
+
if (normalized === '30d') return t('usage.range.30d');
|
|
63
|
+
if (normalized === 'all') return t('usage.range.all');
|
|
64
|
+
return t('usage.range.7d');
|
|
65
|
+
}
|
|
66
|
+
if (normalized === '30d') return '近 30 天';
|
|
67
|
+
if (normalized === 'all') return '全部';
|
|
68
|
+
return '近 7 天';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function formatUsageDuration(value, options = {}) {
|
|
72
|
+
const normalizedLang = typeof options.lang === 'string' ? options.lang.trim().toLowerCase() : '';
|
|
73
|
+
const isEn = normalizedLang === 'en';
|
|
74
|
+
const numeric = Number(value);
|
|
75
|
+
if (!Number.isFinite(numeric) || numeric <= 0) {
|
|
76
|
+
return isEn ? '0m' : '0分';
|
|
77
|
+
}
|
|
78
|
+
const totalMinutes = Math.floor(numeric / 60000);
|
|
79
|
+
if (totalMinutes <= 0) {
|
|
80
|
+
return isEn ? '<1m' : '<1分';
|
|
81
|
+
}
|
|
82
|
+
const maxParts = Number.isFinite(Number(options.maxParts))
|
|
83
|
+
? Math.max(1, Math.floor(Number(options.maxParts)))
|
|
84
|
+
: 2;
|
|
85
|
+
const compact = options.compact !== false;
|
|
86
|
+
const units = compact
|
|
87
|
+
? (
|
|
88
|
+
isEn
|
|
89
|
+
? [
|
|
90
|
+
{ label: 'd', value: 24 * 60 },
|
|
91
|
+
{ label: 'h', value: 60 },
|
|
92
|
+
{ label: 'm', value: 1 }
|
|
93
|
+
]
|
|
94
|
+
: [
|
|
95
|
+
{ label: '天', value: 24 * 60 },
|
|
96
|
+
{ label: '时', value: 60 },
|
|
97
|
+
{ label: '分', value: 1 }
|
|
98
|
+
]
|
|
99
|
+
)
|
|
100
|
+
: (
|
|
101
|
+
isEn
|
|
102
|
+
? [
|
|
103
|
+
{ label: 'day', value: 24 * 60 },
|
|
104
|
+
{ label: 'hr', value: 60 },
|
|
105
|
+
{ label: 'min', value: 1 }
|
|
106
|
+
]
|
|
107
|
+
: [
|
|
108
|
+
{ label: '天', value: 24 * 60 },
|
|
109
|
+
{ label: '小时', value: 60 },
|
|
110
|
+
{ label: '分', value: 1 }
|
|
111
|
+
]
|
|
112
|
+
);
|
|
113
|
+
let remainingMinutes = totalMinutes;
|
|
114
|
+
const parts = [];
|
|
115
|
+
for (const unit of units) {
|
|
116
|
+
if (remainingMinutes < unit.value && unit.value !== 1) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const count = unit.value === 1 ? remainingMinutes : Math.floor(remainingMinutes / unit.value);
|
|
120
|
+
if (count <= 0) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
parts.push(compact ? `${count}${unit.label}` : (isEn ? `${count} ${unit.label}` : `${count}${unit.label}`));
|
|
124
|
+
remainingMinutes -= count * unit.value;
|
|
125
|
+
if (parts.length >= maxParts) {
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return parts.length ? parts.join(compact ? '' : ' ') : (isEn ? '0m' : '0分');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const KNOWN_USAGE_MODEL_PRICING = Object.freeze({
|
|
133
|
+
'gpt-5.4': Object.freeze({ input: 2.5, output: 15, cacheRead: 0.25, cacheWrite: 0 }),
|
|
134
|
+
'gpt-5.4-mini': Object.freeze({ input: 0.75, output: 4.5, cacheRead: 0.075, cacheWrite: 0 }),
|
|
135
|
+
'gpt-5.3-codex': Object.freeze({ input: 1.75, output: 14, cacheRead: 0.175, cacheWrite: 0 }),
|
|
136
|
+
'gpt-5.2-codex': Object.freeze({ input: 1.75, output: 14, cacheRead: 0.175, cacheWrite: 0 })
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
function createUsagePricingEntry(pricing, source) {
|
|
140
|
+
const resolvedSource = typeof source === 'string' && source.trim() ? source.trim() : 'provider-config';
|
|
141
|
+
return {
|
|
142
|
+
input: readUsageCostNumber(pricing && pricing.input),
|
|
143
|
+
output: readUsageCostNumber(pricing && pricing.output),
|
|
144
|
+
reasoningOutput: readUsageCostNumber(
|
|
145
|
+
pricing && (pricing.reasoningOutput != null ? pricing.reasoningOutput : pricing.reasoning)
|
|
146
|
+
),
|
|
147
|
+
cacheRead: readUsageCostNumber(pricing && pricing.cacheRead),
|
|
148
|
+
cacheWrite: readUsageCostNumber(pricing && pricing.cacheWrite),
|
|
149
|
+
source: resolvedSource
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function buildUsagePricingIndex(providersList = []) {
|
|
154
|
+
const byProvider = new Map();
|
|
155
|
+
const byModel = new Map();
|
|
156
|
+
const knownByModel = new Map();
|
|
157
|
+
const list = Array.isArray(providersList) ? providersList : [];
|
|
158
|
+
for (const provider of list) {
|
|
159
|
+
if (!provider || typeof provider !== 'object') continue;
|
|
160
|
+
const providerName = typeof provider.name === 'string' ? provider.name.trim() : '';
|
|
161
|
+
const models = Array.isArray(provider.models) ? provider.models : [];
|
|
162
|
+
const providerMap = new Map();
|
|
163
|
+
for (const model of models) {
|
|
164
|
+
if (!model || typeof model !== 'object') continue;
|
|
165
|
+
const modelId = typeof model.id === 'string' ? model.id.trim() : '';
|
|
166
|
+
if (!modelId) continue;
|
|
167
|
+
const pricing = createUsagePricingEntry(
|
|
168
|
+
model.cost && typeof model.cost === 'object' && !Array.isArray(model.cost)
|
|
169
|
+
? model.cost
|
|
170
|
+
: null,
|
|
171
|
+
'provider-config'
|
|
172
|
+
);
|
|
173
|
+
const hasKnownRate = [pricing.input, pricing.output, pricing.reasoningOutput, pricing.cacheRead, pricing.cacheWrite]
|
|
174
|
+
.some((value) => value !== null);
|
|
175
|
+
if (!hasKnownRate) continue;
|
|
176
|
+
providerMap.set(modelId, pricing);
|
|
177
|
+
const modelMatches = byModel.get(modelId) || [];
|
|
178
|
+
modelMatches.push({ provider: providerName, pricing });
|
|
179
|
+
byModel.set(modelId, modelMatches);
|
|
180
|
+
}
|
|
181
|
+
if (providerName && providerMap.size) {
|
|
182
|
+
byProvider.set(providerName, providerMap);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
for (const [modelId, pricing] of Object.entries(KNOWN_USAGE_MODEL_PRICING)) {
|
|
186
|
+
const normalizedModelId = typeof modelId === 'string' ? modelId.trim() : '';
|
|
187
|
+
if (!normalizedModelId || byModel.has(normalizedModelId)) {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
knownByModel.set(normalizedModelId, createUsagePricingEntry(pricing, 'public-catalog'));
|
|
191
|
+
}
|
|
192
|
+
return { byProvider, byModel, knownByModel };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function resolveUsagePricingForSession(session, pricingIndex, fallbackProvider = '') {
|
|
196
|
+
if (!session || typeof session !== 'object' || !pricingIndex || typeof pricingIndex !== 'object') {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
const model = typeof session.model === 'string' ? session.model.trim() : '';
|
|
200
|
+
if (!model) return null;
|
|
201
|
+
const provider = typeof session.provider === 'string' ? session.provider.trim() : '';
|
|
202
|
+
const effectiveProvider = provider || fallbackProvider;
|
|
203
|
+
if (effectiveProvider) {
|
|
204
|
+
const providerMap = pricingIndex.byProvider instanceof Map ? pricingIndex.byProvider.get(effectiveProvider) : null;
|
|
205
|
+
if (providerMap instanceof Map && providerMap.has(model)) {
|
|
206
|
+
return providerMap.get(model);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const modelMatches = pricingIndex.byModel instanceof Map ? pricingIndex.byModel.get(model) : null;
|
|
210
|
+
if (Array.isArray(modelMatches) && modelMatches.length === 1) {
|
|
211
|
+
return modelMatches[0].pricing;
|
|
212
|
+
}
|
|
213
|
+
const knownPricing = pricingIndex.knownByModel instanceof Map ? pricingIndex.knownByModel.get(model) : null;
|
|
214
|
+
if (knownPricing) {
|
|
215
|
+
return knownPricing;
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function shouldEstimateUsageCostForSession(session) {
|
|
221
|
+
if (!session || typeof session !== 'object') {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
const source = typeof session.source === 'string' ? session.source.trim().toLowerCase() : '';
|
|
225
|
+
const provider = typeof session.provider === 'string' ? session.provider.trim().toLowerCase() : '';
|
|
226
|
+
const model = typeof session.model === 'string' ? session.model.trim().toLowerCase() : '';
|
|
227
|
+
if (source === 'claude' || provider === 'claude') {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
if (/^claude(?:[-_]|$)/.test(model)) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function estimateUsageCostSummary(sessions, providersList, currentProvider) {
|
|
237
|
+
const list = Array.isArray(sessions) ? sessions : [];
|
|
238
|
+
const pricingIndex = buildUsagePricingIndex(providersList);
|
|
239
|
+
let totalCostUsd = 0;
|
|
240
|
+
let estimatedSessions = 0;
|
|
241
|
+
let totalTokens = 0;
|
|
242
|
+
let estimatedTokens = 0;
|
|
243
|
+
let configuredSessions = 0;
|
|
244
|
+
let catalogSessions = 0;
|
|
245
|
+
let missingPricingSessions = 0;
|
|
246
|
+
let missingTokenSessions = 0;
|
|
247
|
+
let supportedSessions = 0;
|
|
248
|
+
let skippedUnsupportedSessions = 0;
|
|
249
|
+
|
|
250
|
+
for (const session of list) {
|
|
251
|
+
if (!session || typeof session !== 'object') continue;
|
|
252
|
+
if (!shouldEstimateUsageCostForSession(session)) {
|
|
253
|
+
skippedUnsupportedSessions += 1;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
supportedSessions += 1;
|
|
257
|
+
const cost = estimateUsageCostForSession(session, pricingIndex, currentProvider);
|
|
258
|
+
totalTokens += cost.totalSessionTokens;
|
|
259
|
+
if (!cost.pricing) {
|
|
260
|
+
missingPricingSessions += 1;
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (!cost.hasTokenBreakdown) {
|
|
264
|
+
missingTokenSessions += 1;
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
totalCostUsd += cost.estimatedUsd;
|
|
268
|
+
estimatedSessions += 1;
|
|
269
|
+
estimatedTokens += cost.totalSessionTokens;
|
|
270
|
+
if (cost.pricing.source === 'public-catalog') catalogSessions += 1;
|
|
271
|
+
else configuredSessions += 1;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const coveragePercent = totalTokens > 0
|
|
275
|
+
? Math.round((estimatedTokens / totalTokens) * 100)
|
|
276
|
+
: (estimatedSessions > 0 ? 100 : 0);
|
|
277
|
+
return {
|
|
278
|
+
totalCostUsd,
|
|
279
|
+
estimatedSessions,
|
|
280
|
+
totalSessions: supportedSessions,
|
|
281
|
+
estimatedTokens,
|
|
282
|
+
totalTokens,
|
|
283
|
+
coveragePercent,
|
|
284
|
+
hasEstimate: estimatedSessions > 0,
|
|
285
|
+
configuredSessions,
|
|
286
|
+
catalogSessions,
|
|
287
|
+
missingPricingSessions,
|
|
288
|
+
missingTokenSessions,
|
|
289
|
+
skippedUnsupportedSessions
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function estimateUsageCostForSession(session, pricingIndex, currentProvider) {
|
|
294
|
+
const inputTokens = Number.isFinite(Number(session.inputTokens)) ? Math.max(0, Math.floor(Number(session.inputTokens))) : null;
|
|
295
|
+
const cachedInputTokens = Number.isFinite(Number(session.cachedInputTokens)) ? Math.max(0, Math.floor(Number(session.cachedInputTokens))) : 0;
|
|
296
|
+
const outputTokens = Number.isFinite(Number(session.outputTokens)) ? Math.max(0, Math.floor(Number(session.outputTokens))) : null;
|
|
297
|
+
const reasoningOutputTokens = Number.isFinite(Number(session.reasoningOutputTokens)) ? Math.max(0, Math.floor(Number(session.reasoningOutputTokens))) : 0;
|
|
298
|
+
const billableInputTokens = Math.max(0, (inputTokens || 0) - cachedInputTokens);
|
|
299
|
+
const fallbackSessionTokens = billableInputTokens + cachedInputTokens + (outputTokens || 0) + reasoningOutputTokens;
|
|
300
|
+
const totalSessionTokens = Number.isFinite(Number(session.totalTokens))
|
|
301
|
+
? Math.max(0, Math.floor(Number(session.totalTokens)))
|
|
302
|
+
: fallbackSessionTokens;
|
|
303
|
+
const pricing = resolveUsagePricingForSession(session, pricingIndex, currentProvider);
|
|
304
|
+
const hasTokenBreakdown = !(inputTokens === null && outputTokens === null && reasoningOutputTokens === 0);
|
|
305
|
+
const reasoningRate = pricing
|
|
306
|
+
? ((pricing.reasoningOutput != null ? pricing.reasoningOutput : pricing.output) || 0)
|
|
307
|
+
: 0;
|
|
308
|
+
const estimatedUsd = pricing && hasTokenBreakdown
|
|
309
|
+
? (
|
|
310
|
+
((pricing.input || 0) * billableInputTokens)
|
|
311
|
+
+ ((pricing.cacheRead || 0) * cachedInputTokens)
|
|
312
|
+
+ (reasoningRate * reasoningOutputTokens)
|
|
313
|
+
+ ((pricing.output || 0) * (outputTokens || 0))
|
|
314
|
+
) / 1000000
|
|
315
|
+
: 0;
|
|
316
|
+
return {
|
|
317
|
+
pricing,
|
|
318
|
+
hasTokenBreakdown,
|
|
319
|
+
totalSessionTokens,
|
|
320
|
+
estimatedUsd
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export function createSessionComputed() {
|
|
325
|
+
return {
|
|
326
|
+
isSessionQueryEnabled() {
|
|
327
|
+
return isSessionQueryEnabled(this.sessionFilterSource);
|
|
328
|
+
},
|
|
329
|
+
activeSessionExportKey() {
|
|
330
|
+
return this.activeSession ? this.getSessionExportKey(this.activeSession) : '';
|
|
331
|
+
},
|
|
332
|
+
sortedSessionsList() {
|
|
333
|
+
const list = Array.isArray(this.sessionsList) ? this.sessionsList : [];
|
|
334
|
+
if (list.length === 0) return [];
|
|
335
|
+
const pinnedMap = (this.sessionPinnedMap && typeof this.sessionPinnedMap === 'object')
|
|
336
|
+
? this.sessionPinnedMap
|
|
337
|
+
: {};
|
|
338
|
+
if (Object.keys(pinnedMap).length === 0) {
|
|
339
|
+
return list;
|
|
340
|
+
}
|
|
341
|
+
let hasPinned = false;
|
|
342
|
+
const decorated = list.map((session, index) => {
|
|
343
|
+
const key = session ? this.getSessionExportKey(session) : '';
|
|
344
|
+
const rawPinnedAt = key ? pinnedMap[key] : 0;
|
|
345
|
+
const pinnedAt = Number.isFinite(Number(rawPinnedAt))
|
|
346
|
+
? Math.floor(Number(rawPinnedAt))
|
|
347
|
+
: 0;
|
|
348
|
+
const isPinned = pinnedAt > 0;
|
|
349
|
+
if (isPinned) {
|
|
350
|
+
hasPinned = true;
|
|
351
|
+
}
|
|
352
|
+
return { session, index, pinnedAt, isPinned };
|
|
353
|
+
});
|
|
354
|
+
if (!hasPinned) return list;
|
|
355
|
+
decorated.sort((a, b) => {
|
|
356
|
+
if (a.isPinned !== b.isPinned) return a.isPinned ? -1 : 1;
|
|
357
|
+
if (a.isPinned && a.pinnedAt !== b.pinnedAt) return b.pinnedAt - a.pinnedAt;
|
|
358
|
+
return a.index - b.index;
|
|
359
|
+
});
|
|
360
|
+
return decorated.map(item => item.session);
|
|
361
|
+
},
|
|
362
|
+
visibleSessionsList() {
|
|
363
|
+
if (!this.sessionListRenderEnabled) {
|
|
364
|
+
return [];
|
|
365
|
+
}
|
|
366
|
+
const list = Array.isArray(this.sortedSessionsList) ? this.sortedSessionsList : [];
|
|
367
|
+
if (list.length === 0) {
|
|
368
|
+
return [];
|
|
369
|
+
}
|
|
370
|
+
const rawVisibleCount = Number(this.sessionListVisibleCount);
|
|
371
|
+
const visibleCount = Number.isFinite(rawVisibleCount)
|
|
372
|
+
? Math.max(0, Math.floor(rawVisibleCount))
|
|
373
|
+
: 0;
|
|
374
|
+
let targetCount = visibleCount > 0 ? Math.min(visibleCount, list.length) : Math.min(list.length, 1);
|
|
375
|
+
const activeKey = this.activeSession ? this.getSessionExportKey(this.activeSession) : '';
|
|
376
|
+
if (activeKey) {
|
|
377
|
+
const activeIndex = list.findIndex((session) => this.getSessionExportKey(session) === activeKey);
|
|
378
|
+
if (activeIndex >= 0) {
|
|
379
|
+
targetCount = Math.max(targetCount, activeIndex + 1);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
if (targetCount >= list.length) {
|
|
383
|
+
return list;
|
|
384
|
+
}
|
|
385
|
+
return list.slice(0, targetCount);
|
|
386
|
+
},
|
|
387
|
+
activeSessionVisibleMessages() {
|
|
388
|
+
if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
|
|
389
|
+
return [];
|
|
390
|
+
}
|
|
391
|
+
const list = Array.isArray(this.activeSessionMessages) ? this.activeSessionMessages : [];
|
|
392
|
+
const rawCount = Number(this.sessionPreviewVisibleCount);
|
|
393
|
+
const visibleCount = Number.isFinite(rawCount)
|
|
394
|
+
? Math.max(0, Math.floor(rawCount))
|
|
395
|
+
: 0;
|
|
396
|
+
if (visibleCount <= 0) {
|
|
397
|
+
const initialBatchSize = Number.isFinite(this.sessionPreviewInitialBatchSize)
|
|
398
|
+
? Math.max(1, Math.floor(this.sessionPreviewInitialBatchSize))
|
|
399
|
+
: 12;
|
|
400
|
+
return list.slice(0, Math.min(initialBatchSize, list.length));
|
|
401
|
+
}
|
|
402
|
+
if (visibleCount >= list.length) return list;
|
|
403
|
+
return list.slice(0, visibleCount);
|
|
404
|
+
},
|
|
405
|
+
canLoadMoreSessionMessages() {
|
|
406
|
+
if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
const total = Array.isArray(this.activeSessionMessages) ? this.activeSessionMessages.length : 0;
|
|
410
|
+
const visible = Array.isArray(this.activeSessionVisibleMessages) ? this.activeSessionVisibleMessages.length : 0;
|
|
411
|
+
return total > visible;
|
|
412
|
+
},
|
|
413
|
+
sessionPreviewRemainingCount() {
|
|
414
|
+
const total = Array.isArray(this.activeSessionMessages) ? this.activeSessionMessages.length : 0;
|
|
415
|
+
const visible = Array.isArray(this.activeSessionVisibleMessages) ? this.activeSessionVisibleMessages.length : 0;
|
|
416
|
+
return Math.max(0, total - visible);
|
|
417
|
+
},
|
|
418
|
+
sessionTimelineNodes() {
|
|
419
|
+
if (this.mainTab !== 'sessions' || !this.sessionPreviewRenderEnabled) {
|
|
420
|
+
return [];
|
|
421
|
+
}
|
|
422
|
+
return buildSessionTimelineNodes(this.activeSessionVisibleMessages, {
|
|
423
|
+
getKey: (message, index) => this.getRecordRenderKey(message, index)
|
|
424
|
+
});
|
|
425
|
+
},
|
|
426
|
+
sessionTimelineNodeKeyMap() {
|
|
427
|
+
const nodes = Array.isArray(this.sessionTimelineNodes) ? this.sessionTimelineNodes : [];
|
|
428
|
+
if (!nodes.length) {
|
|
429
|
+
return Object.create(null);
|
|
430
|
+
}
|
|
431
|
+
const map = Object.create(null);
|
|
432
|
+
for (const node of nodes) {
|
|
433
|
+
if (!node || !node.key) continue;
|
|
434
|
+
map[node.key] = true;
|
|
435
|
+
}
|
|
436
|
+
return map;
|
|
437
|
+
},
|
|
438
|
+
sessionTimelineActiveTitle() {
|
|
439
|
+
if (!this.sessionTimelineActiveKey) return '';
|
|
440
|
+
const nodes = Array.isArray(this.sessionTimelineNodes) ? this.sessionTimelineNodes : [];
|
|
441
|
+
const matched = nodes.find(node => node.key === this.sessionTimelineActiveKey);
|
|
442
|
+
return matched ? matched.title : '';
|
|
443
|
+
},
|
|
444
|
+
sessionQueryPlaceholder() {
|
|
445
|
+
if (this.isSessionQueryEnabled) {
|
|
446
|
+
return typeof this.t === 'function'
|
|
447
|
+
? this.t('sessions.query.placeholder.enabled')
|
|
448
|
+
: '关键词检索(支持 Codex/Claude,例:claude code)';
|
|
449
|
+
}
|
|
450
|
+
return typeof this.t === 'function'
|
|
451
|
+
? this.t('sessions.query.placeholder.disabled')
|
|
452
|
+
: '当前来源暂不支持关键词检索';
|
|
453
|
+
},
|
|
454
|
+
sessionUsageCharts() {
|
|
455
|
+
return buildUsageChartGroups(this.sessionsUsageList, {
|
|
456
|
+
range: this.sessionsUsageTimeRange
|
|
457
|
+
});
|
|
458
|
+
},
|
|
459
|
+
sessionUsageSummaryCards() {
|
|
460
|
+
const summary = this.sessionUsageCharts && this.sessionUsageCharts.summary
|
|
461
|
+
? this.sessionUsageCharts.summary
|
|
462
|
+
: { totalSessions: 0, totalMessages: 0, totalTokens: 0, totalContextWindow: 0, activeDurationMs: 0, totalDurationMs: 0, activeDays: 0, avgMessagesPerSession: 0, busiestDay: null, busiestHour: null };
|
|
463
|
+
const filteredUsageSessions = this.sessionUsageCharts && Array.isArray(this.sessionUsageCharts.filteredSessions)
|
|
464
|
+
? this.sessionUsageCharts.filteredSessions
|
|
465
|
+
: this.sessionsUsageList;
|
|
466
|
+
const t = typeof this.t === 'function' ? this.t : null;
|
|
467
|
+
const usageRangeLabel = formatUsageRangeLabel(this.sessionsUsageTimeRange, t);
|
|
468
|
+
const estimatedCost = estimateUsageCostSummary(
|
|
469
|
+
filteredUsageSessions,
|
|
470
|
+
this.providersList,
|
|
471
|
+
this.currentProvider
|
|
472
|
+
);
|
|
473
|
+
const noneLabel = t ? t('common.none') : '暂无';
|
|
474
|
+
const estimatedCostPrefix = estimatedCost.skippedUnsupportedSessions > 0
|
|
475
|
+
? (t ? t('usage.estimatedCost.note.excludesClaudePrefix') : '暂不含 Claude,')
|
|
476
|
+
: '';
|
|
477
|
+
const estimatedCostMethod = estimatedCost.catalogSessions > 0
|
|
478
|
+
? (estimatedCost.configuredSessions > 0
|
|
479
|
+
? (t ? t('usage.estimatedCost.method.configuredAndCatalog') : '按已配置单价 + 公开模型目录估算')
|
|
480
|
+
: (t ? t('usage.estimatedCost.method.catalog') : '按公开模型目录估算'))
|
|
481
|
+
: (t ? t('usage.estimatedCost.method.configured') : '按已配置单价估算');
|
|
482
|
+
const estimatedCostTitle = estimatedCost.hasEstimate
|
|
483
|
+
? (t ? t('usage.estimatedCost.detail.estimate', {
|
|
484
|
+
prefix: estimatedCostPrefix,
|
|
485
|
+
method: estimatedCostMethod,
|
|
486
|
+
estimate: formatUsageEstimatedCost(estimatedCost.totalCostUsd, { precise: true }),
|
|
487
|
+
covered: estimatedCost.estimatedSessions,
|
|
488
|
+
total: estimatedCost.totalSessions,
|
|
489
|
+
percent: estimatedCost.coveragePercent
|
|
490
|
+
}) : `${estimatedCostPrefix}${estimatedCostMethod},估算 ${formatUsageEstimatedCost(estimatedCost.totalCostUsd, { precise: true })},覆盖 ${estimatedCost.estimatedSessions}/${estimatedCost.totalSessions} 个会话,约 ${estimatedCost.coveragePercent}% token`)
|
|
491
|
+
: (t ? t('usage.estimatedCost.detail.missing', { prefix: estimatedCostPrefix }) : `${estimatedCostPrefix}缺少可匹配的模型单价或 token 拆分。请先补 models.cost,或确认会话已记录 input/output token。`);
|
|
492
|
+
return [
|
|
493
|
+
{ key: 'sessions', label: t ? t('usage.summary.sessions') : '总会话数', value: formatUsageSummaryNumber(summary.totalSessions || 0) },
|
|
494
|
+
{ key: 'messages', label: t ? t('usage.summary.messages') : '总消息数', value: formatUsageSummaryNumber(summary.totalMessages || 0) },
|
|
495
|
+
{
|
|
496
|
+
key: 'tokens',
|
|
497
|
+
label: t ? t('usage.summary.tokens') : '总 token 数',
|
|
498
|
+
value: formatCompactUsageSummaryNumber(summary.totalTokens || 0),
|
|
499
|
+
title: formatUsageSummaryNumber(summary.totalTokens || 0)
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
key: 'context-window',
|
|
503
|
+
label: t ? t('usage.summary.contextWindow') : '总上下文数',
|
|
504
|
+
value: formatCompactUsageSummaryNumber(summary.totalContextWindow || 0),
|
|
505
|
+
title: formatUsageSummaryNumber(summary.totalContextWindow || 0)
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
key: 'estimated-cost',
|
|
509
|
+
label: t ? t('usage.summary.estimatedCost', { range: usageRangeLabel }) : `预估费用 · ${usageRangeLabel}`,
|
|
510
|
+
value: estimatedCost.hasEstimate ? formatUsageEstimatedCost(estimatedCost.totalCostUsd) : '0',
|
|
511
|
+
title: estimatedCostTitle
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
key: 'active-duration',
|
|
515
|
+
label: t ? t('usage.summary.activeDuration') : '活跃时长',
|
|
516
|
+
value: formatUsageDuration(summary.activeDurationMs || 0, { compact: true, lang: this.lang }),
|
|
517
|
+
title: t
|
|
518
|
+
? t('usage.summary.activeDuration.title', {
|
|
519
|
+
value: formatUsageDuration(summary.activeDurationMs || 0, { maxParts: 3, compact: false, lang: this.lang })
|
|
520
|
+
})
|
|
521
|
+
: `累计会话跨度 ${formatUsageDuration(summary.activeDurationMs || 0, { maxParts: 3, compact: false, lang: this.lang })}`
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
key: 'total-duration',
|
|
525
|
+
label: t ? t('usage.summary.totalDuration') : '总时长',
|
|
526
|
+
value: formatUsageDuration(summary.totalDurationMs || 0, { compact: true, lang: this.lang }),
|
|
527
|
+
title: t
|
|
528
|
+
? t('usage.summary.totalDuration.title', {
|
|
529
|
+
value: formatUsageDuration(summary.totalDurationMs || 0, { maxParts: 3, compact: false, lang: this.lang })
|
|
530
|
+
})
|
|
531
|
+
: `整体时间跨度 ${formatUsageDuration(summary.totalDurationMs || 0, { maxParts: 3, compact: false, lang: this.lang })}`
|
|
532
|
+
},
|
|
533
|
+
{ key: 'days', label: t ? t('usage.summary.activeDays') : '活跃天数', value: formatUsageSummaryNumber(summary.activeDays || 0) },
|
|
534
|
+
{ key: 'avg-messages', label: t ? t('usage.summary.avgMessagesPerSession') : '平均每会话消息', value: summary.avgMessagesPerSession || 0 },
|
|
535
|
+
{
|
|
536
|
+
key: 'busiest-day',
|
|
537
|
+
label: t ? t('usage.summary.busiestDay') : '最忙日',
|
|
538
|
+
value: summary.busiestDay && summary.busiestDay.totalSessions > 0
|
|
539
|
+
? `${summary.busiestDay.label} · ${summary.busiestDay.totalSessions}`
|
|
540
|
+
: noneLabel
|
|
541
|
+
},
|
|
542
|
+
{
|
|
543
|
+
key: 'busiest-hour',
|
|
544
|
+
label: t ? t('usage.summary.busiestHour') : '高峰时段',
|
|
545
|
+
value: summary.busiestHour && summary.busiestHour.count > 0
|
|
546
|
+
? `${summary.busiestHour.label} · ${summary.busiestHour.count}`
|
|
547
|
+
: noneLabel
|
|
548
|
+
}
|
|
549
|
+
];
|
|
550
|
+
},
|
|
551
|
+
|
|
552
|
+
sessionUsageDaily() {
|
|
553
|
+
const baseBuckets = this.sessionUsageCharts && Array.isArray(this.sessionUsageCharts.buckets)
|
|
554
|
+
? this.sessionUsageCharts.buckets
|
|
555
|
+
: [];
|
|
556
|
+
const sessions = this.sessionUsageCharts && Array.isArray(this.sessionUsageCharts.filteredSessions)
|
|
557
|
+
? this.sessionUsageCharts.filteredSessions
|
|
558
|
+
: this.sessionsUsageList;
|
|
559
|
+
const pricingIndex = buildUsagePricingIndex(this.providersList);
|
|
560
|
+
const byDay = new Map();
|
|
561
|
+
|
|
562
|
+
for (const bucket of baseBuckets) {
|
|
563
|
+
if (!bucket || !bucket.key) continue;
|
|
564
|
+
byDay.set(bucket.key, {
|
|
565
|
+
key: bucket.key,
|
|
566
|
+
label: bucket.label || bucket.key.slice(5),
|
|
567
|
+
sessionCount: 0,
|
|
568
|
+
messageCount: 0,
|
|
569
|
+
tokenTotal: 0,
|
|
570
|
+
estimatedCostUsd: 0,
|
|
571
|
+
estimatedSessions: 0,
|
|
572
|
+
hasCostEstimate: false
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
for (const session of (Array.isArray(sessions) ? sessions : [])) {
|
|
577
|
+
if (!session || typeof session !== 'object') continue;
|
|
578
|
+
const updatedAtMs = Date.parse(session.updatedAt || '');
|
|
579
|
+
if (!Number.isFinite(updatedAtMs)) continue;
|
|
580
|
+
const dayKey = new Date(updatedAtMs).toISOString().slice(0, 10);
|
|
581
|
+
const row = byDay.get(dayKey);
|
|
582
|
+
if (!row) continue;
|
|
583
|
+
|
|
584
|
+
const messageCount = Number.isFinite(Number(session.messageCount))
|
|
585
|
+
? Math.max(0, Math.floor(Number(session.messageCount)))
|
|
586
|
+
: 0;
|
|
587
|
+
const tokenTotal = Number.isFinite(Number(session.totalTokens))
|
|
588
|
+
? Math.max(0, Math.floor(Number(session.totalTokens)))
|
|
589
|
+
: 0;
|
|
590
|
+
row.sessionCount += 1;
|
|
591
|
+
row.messageCount += messageCount;
|
|
592
|
+
row.tokenTotal += tokenTotal;
|
|
593
|
+
|
|
594
|
+
if (shouldEstimateUsageCostForSession(session)) {
|
|
595
|
+
const cost = estimateUsageCostForSession(session, pricingIndex, this.currentProvider);
|
|
596
|
+
if (cost.pricing && cost.hasTokenBreakdown) {
|
|
597
|
+
row.estimatedCostUsd += cost.estimatedUsd;
|
|
598
|
+
row.estimatedSessions += 1;
|
|
599
|
+
row.hasCostEstimate = true;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// UI 展示:当天在最上面(倒序)。
|
|
605
|
+
const rows = [...byDay.values()].sort((a, b) => b.key.localeCompare(a.key, 'en-US'));
|
|
606
|
+
const maxTokens = rows.reduce((max, item) => Math.max(max, item.tokenTotal), 0);
|
|
607
|
+
const maxCost = rows.reduce((max, item) => Math.max(max, item.estimatedCostUsd), 0);
|
|
608
|
+
|
|
609
|
+
return {
|
|
610
|
+
rows: rows.map((row) => ({
|
|
611
|
+
...row,
|
|
612
|
+
tokenLabel: formatCompactUsageSummaryNumber(row.tokenTotal),
|
|
613
|
+
tokenTitle: formatUsageSummaryNumber(row.tokenTotal),
|
|
614
|
+
tokenPercent: maxTokens > 0 ? Math.round((row.tokenTotal / maxTokens) * 1000) / 10 : 0,
|
|
615
|
+
costLabel: row.hasCostEstimate ? formatUsageEstimatedCost(row.estimatedCostUsd) : '0',
|
|
616
|
+
costTitle: row.hasCostEstimate ? formatUsageEstimatedCost(row.estimatedCostUsd, { precise: true }) : '0',
|
|
617
|
+
costPercent: maxCost > 0 ? Math.round((row.estimatedCostUsd / maxCost) * 1000) / 10 : 0
|
|
618
|
+
})),
|
|
619
|
+
maxTokens,
|
|
620
|
+
maxCost
|
|
621
|
+
};
|
|
622
|
+
},
|
|
623
|
+
|
|
624
|
+
sessionUsageDailyTableRows() {
|
|
625
|
+
const daily = this.sessionUsageDaily && typeof this.sessionUsageDaily === 'object'
|
|
626
|
+
? this.sessionUsageDaily
|
|
627
|
+
: null;
|
|
628
|
+
return daily && Array.isArray(daily.rows) ? daily.rows : [];
|
|
629
|
+
},
|
|
630
|
+
|
|
631
|
+
visibleSessionTrashItems() {
|
|
632
|
+
const items = Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems : [];
|
|
633
|
+
const visibleCount = Number(this.sessionTrashVisibleCount);
|
|
634
|
+
const safeVisibleCount = Number.isFinite(visibleCount) && visibleCount > 0
|
|
635
|
+
? Math.floor(visibleCount)
|
|
636
|
+
: SESSION_TRASH_PAGE_SIZE;
|
|
637
|
+
return items.slice(0, safeVisibleCount);
|
|
638
|
+
},
|
|
639
|
+
sessionTrashHasMoreItems() {
|
|
640
|
+
return this.visibleSessionTrashItems.length < this.sessionTrashCount;
|
|
641
|
+
},
|
|
642
|
+
sessionTrashHiddenCount() {
|
|
643
|
+
return Math.max(0, this.sessionTrashCount - this.visibleSessionTrashItems.length);
|
|
644
|
+
},
|
|
645
|
+
sessionTrashCount() {
|
|
646
|
+
const totalCount = Number(this.sessionTrashTotalCount);
|
|
647
|
+
if (Number.isFinite(totalCount) && totalCount >= 0) {
|
|
648
|
+
return Math.max(0, Math.floor(totalCount));
|
|
649
|
+
}
|
|
650
|
+
return Array.isArray(this.sessionTrashItems) ? this.sessionTrashItems.length : 0;
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
}
|