@lls-a1/dsh-balance-float 1.1.53 → 1.1.54
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/client.js +140 -29
- package/lib/snapshot.js +1 -1
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -63,8 +63,9 @@ window.__ModuleLoader__.load({
|
|
|
63
63
|
balance: '余额',
|
|
64
64
|
topup: '充值 ↗',
|
|
65
65
|
'topup.title': '打开 DeepSeek 官方充值页',
|
|
66
|
-
'balance.note': '
|
|
66
|
+
'balance.note': '总余额 {balance},已用 {used}',
|
|
67
67
|
'balance.noStart': '今日已用 {used}',
|
|
68
|
+
'balance.startHint': '今日 0 点余额 {start}',
|
|
68
69
|
today: '今日已用',
|
|
69
70
|
turn: '本轮消耗',
|
|
70
71
|
'turn.label': '本轮',
|
|
@@ -107,7 +108,11 @@ window.__ModuleLoader__.load({
|
|
|
107
108
|
'price.hit': '命中',
|
|
108
109
|
'price.miss': '未命中',
|
|
109
110
|
'price.out': '输出',
|
|
110
|
-
history: '
|
|
111
|
+
history: '用量趋势',
|
|
112
|
+
'history.window.7': '近7天',
|
|
113
|
+
'history.window.30': '近30天',
|
|
114
|
+
'history.window.month': '本月',
|
|
115
|
+
'history.calls': '{calls} 次',
|
|
111
116
|
'history.total': '合计 {total}',
|
|
112
117
|
version: '版本',
|
|
113
118
|
'version.open': '打开插件页(更新在这里)',
|
|
@@ -150,8 +155,9 @@ window.__ModuleLoader__.load({
|
|
|
150
155
|
balance: 'Balance',
|
|
151
156
|
topup: 'Top up ↗',
|
|
152
157
|
'topup.title': 'Open the official DeepSeek top-up page',
|
|
153
|
-
'balance.note': '
|
|
158
|
+
'balance.note': 'Balance {balance}, used {used}',
|
|
154
159
|
'balance.noStart': 'Used today {used}',
|
|
160
|
+
'balance.startHint': 'Balance at midnight {start}',
|
|
155
161
|
today: 'Used today',
|
|
156
162
|
turn: 'Last turn',
|
|
157
163
|
'turn.label': 'Turn',
|
|
@@ -194,7 +200,11 @@ window.__ModuleLoader__.load({
|
|
|
194
200
|
'price.hit': 'Hit',
|
|
195
201
|
'price.miss': 'Miss',
|
|
196
202
|
'price.out': 'Out',
|
|
197
|
-
history: '
|
|
203
|
+
history: 'Usage trend',
|
|
204
|
+
'history.window.7': '7d',
|
|
205
|
+
'history.window.30': '30d',
|
|
206
|
+
'history.window.month': 'Month',
|
|
207
|
+
'history.calls': '{calls} calls',
|
|
198
208
|
'history.total': 'Total {total}',
|
|
199
209
|
version: 'Version',
|
|
200
210
|
'version.open': 'Open the plugin page (updates live there)',
|
|
@@ -277,9 +287,10 @@ window.__ModuleLoader__.load({
|
|
|
277
287
|
'.dbf-bubble.is-right-of .dbf-bubble-caret{top:50%;left:-4px;margin-top:-4px;transform:rotate(-45deg)}',
|
|
278
288
|
'.dbf-bubble.is-left-of .dbf-bubble-caret{top:50%;right:-4px;left:auto;margin-top:-4px;transform:rotate(135deg)}',
|
|
279
289
|
'@keyframes dbf-flash-side{0%{opacity:0}12%{opacity:1}84%{opacity:1}100%{opacity:0}}',
|
|
280
|
-
'.dbf-switch{flex:none;width:34px;height:20px;padding:0;border-radius:999px;border:1px solid var(--dsw-alias-border-
|
|
290
|
+
'.dbf-switch{flex:none;width:34px;height:20px;padding:0;border-radius:999px;border:1px solid var(--dsw-alias-border-l2,#c9ced6);background:var(--dsw-alias-bg-layer-3,var(--dsw-alias-bg-layer-2));position:relative;cursor:pointer;transition:background-color .15s ease,border-color .15s ease}',
|
|
281
291
|
'.dbf-switch.is-on{background:var(--dsw-alias-brand-primary,#4d6bfe);border-color:transparent}',
|
|
282
|
-
'.dbf-switch-knob{position:absolute;top:2px;left:2px;width:14px;height:14px;border-radius:50%;background
|
|
292
|
+
'.dbf-switch-knob{position:absolute;top:2px;left:2px;width:14px;height:14px;border-radius:50%;background:var(--dsw-alias-label-primary,#111);box-shadow:0 1px 2px rgba(0,0,0,.18);transition:transform .15s ease,background-color .15s ease}',
|
|
293
|
+
'.dbf-switch.is-on .dbf-switch-knob{background:#fff}',
|
|
283
294
|
'.dbf-switch.is-on .dbf-switch-knob{transform:translateX(14px)}',
|
|
284
295
|
'.dbf-topup{flex:none;padding:3px 10px;border-radius:999px;border:1px solid var(--dsw-alias-border-l3,var(--dsw-alias-border-l2,currentColor));background:var(--dsw-alias-button-primary-dimmed,var(--dsw-alias-bg-layer-2));color:var(--dsw-alias-label-primary);font:inherit;font-size:11px;font-weight:600;line-height:16px;cursor:pointer;transition:background-color .15s ease,border-color .15s ease}',
|
|
285
296
|
'.dbf-topup:hover{border-color:var(--dsw-alias-brand-primary,#4d6bfe)}',
|
|
@@ -323,11 +334,26 @@ window.__ModuleLoader__.load({
|
|
|
323
334
|
'.dbf-valley{color:var(--dsw-alias-state-success-primary)}',
|
|
324
335
|
'.dbf-badge.dbf-peak{border-color:currentColor}',
|
|
325
336
|
'.dbf-badge.dbf-valley{border-color:currentColor}',
|
|
326
|
-
'.dbf-
|
|
327
|
-
'.dbf-
|
|
337
|
+
'.dbf-windows{display:inline-flex;gap:2px}',
|
|
338
|
+
'.dbf-models-window{margin-top:6px}',
|
|
339
|
+
'.dbf-mrow{display:flex;align-items:center;gap:6px;font-size:11px;line-height:16px}',
|
|
340
|
+
'.dbf-mname{min-width:66px;color:var(--dsw-alias-label-secondary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}',
|
|
341
|
+
'.dbf-mbar-track{flex:1 1 auto;height:4px;border-radius:2px;background:var(--dsw-alias-border-l1);overflow:hidden}',
|
|
342
|
+
'.dbf-mbar{display:block;height:100%;border-radius:2px;background:var(--dsw-alias-brand-primary,#4d6bfe);opacity:.75}',
|
|
343
|
+
'.dbf-mcost{font-variant-numeric:tabular-nums}',
|
|
344
|
+
'.dbf-mshare{min-width:30px;text-align:right;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}',
|
|
345
|
+
'.dbf-window{padding:0 8px;border:0;border-radius:6px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:11px;line-height:20px;cursor:pointer}',
|
|
346
|
+
'.dbf-window:hover{color:var(--dsw-alias-label-primary)}',
|
|
347
|
+
'.dbf-window.is-active{background:color-mix(in srgb,var(--dsw-alias-brand-primary,#4d6bfe) 16%,transparent);color:var(--dsw-alias-label-primary);font-weight:600}',
|
|
348
|
+
'.dbf-trend-meta{display:flex;align-items:baseline;gap:8px;margin-top:5px}',
|
|
349
|
+
'.dbf-trend-total{font-size:13px;font-weight:600;font-variant-numeric:tabular-nums}',
|
|
350
|
+
'.dbf-trend-calls{font-size:11px;color:var(--dsw-alias-label-secondary)}',
|
|
351
|
+
'.dbf-bars{display:flex;align-items:flex-end;justify-content:space-between;gap:4px;height:58px;margin-top:8px;padding-bottom:2px;overflow-x:auto;scrollbar-width:none}',
|
|
352
|
+
'.dbf-bar{flex:1 0 auto;min-width:13px;max-width:32px;height:100%;display:flex;flex-direction:column;justify-content:flex-end;align-items:center;gap:4px}',
|
|
328
353
|
'.dbf-bar-fill{width:100%;min-height:2px;border-radius:3px 3px 0 0;background:var(--dsw-alias-border-l2)}',
|
|
329
354
|
'.dbf-bar.is-today .dbf-bar-fill{background:var(--dsw-alias-brand-primary)}',
|
|
330
|
-
'.dbf-bar-day{color:var(--dsw-alias-label-secondary);font-size:9.5px;line-height:12px;font-variant-numeric:tabular-nums}',
|
|
355
|
+
'.dbf-bar-day{color:var(--dsw-alias-label-secondary);font-size:9.5px;line-height:12px;white-space:nowrap;font-variant-numeric:tabular-nums}',
|
|
356
|
+
'.dbf-bar.is-today .dbf-bar-day{color:var(--dsw-alias-label-primary);font-weight:600}',
|
|
331
357
|
'.dbf-foot{display:flex;align-items:center;justify-content:space-between;gap:6px;padding:7px 11px;background:transparent;border-top:.5px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);font-size:10.5px;line-height:14px}',
|
|
332
358
|
'.dbf-foot-path{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
333
359
|
'.dbf-foot-time{margin-left:auto;white-space:nowrap}',
|
|
@@ -453,11 +479,31 @@ window.__ModuleLoader__.load({
|
|
|
453
479
|
}
|
|
454
480
|
|
|
455
481
|
/** Short model name for the price table. */
|
|
482
|
+
/** Compact label: vendor + version + tier, so similar ids stay distinct. */
|
|
456
483
|
function modelLabel(model) {
|
|
457
|
-
const
|
|
458
|
-
if (
|
|
459
|
-
|
|
460
|
-
|
|
484
|
+
const raw = String(model || '');
|
|
485
|
+
if (raw === '') return '—';
|
|
486
|
+
const key = raw.toLowerCase();
|
|
487
|
+
let vendor = '';
|
|
488
|
+
let rest = key;
|
|
489
|
+
if (rest.startsWith('deepseek')) {
|
|
490
|
+
vendor = 'DS';
|
|
491
|
+
rest = rest.replace(/^deepseek[-_]?/, '');
|
|
492
|
+
} else if (rest.startsWith('glm')) {
|
|
493
|
+
vendor = 'GLM';
|
|
494
|
+
rest = rest.replace(/^glm[-_]?/, '');
|
|
495
|
+
} else if (rest.startsWith('claude')) {
|
|
496
|
+
vendor = 'Claude';
|
|
497
|
+
rest = rest.replace(/^claude[-_]?/, '');
|
|
498
|
+
} else if (rest.startsWith('gpt')) {
|
|
499
|
+
vendor = 'GPT';
|
|
500
|
+
rest = rest.replace(/^gpt[-_]?/, '');
|
|
501
|
+
}
|
|
502
|
+
const tier = rest.includes('pro') ? 'Pro' : rest.includes('flash') ? 'Flash' : '';
|
|
503
|
+
// First version-like token that is not a date/build stamp (four digits).
|
|
504
|
+
const version = (rest.match(/v?\d+(?:\.\d+)?/g) ?? []).find((token) => !/^\d{4}$/.test(token)) ?? '';
|
|
505
|
+
const label = [vendor, version, tier].filter((part) => part !== '').join(' ');
|
|
506
|
+
return label === '' ? raw : label;
|
|
461
507
|
}
|
|
462
508
|
|
|
463
509
|
/** Persisted appearance, clamped to the sliders' own ranges. */
|
|
@@ -562,8 +608,10 @@ window.__ModuleLoader__.load({
|
|
|
562
608
|
const [bubbleUp, setBubbleUp] = useState(false);
|
|
563
609
|
// «?» next to the current billing period: reveals the peak/valley windows.
|
|
564
610
|
const [hintOpen, setHintOpen] = useState(false);
|
|
565
|
-
// A bar of the
|
|
611
|
+
// A bar of the chart opens that day's detail view; the chart shows 7 or
|
|
612
|
+
// 30 days (or the current month) depending on the chosen window.
|
|
566
613
|
const [selectedDay, setSelectedDay] = useState(null);
|
|
614
|
+
const [chartWindow, setChartWindow] = useState('7');
|
|
567
615
|
// Token buckets are collapsed until asked for.
|
|
568
616
|
const [tokensOpen, setTokensOpen] = useState(false);
|
|
569
617
|
// Auto check: null | {phase, latest, current, hasUpdate}
|
|
@@ -1007,8 +1055,26 @@ window.__ModuleLoader__.load({
|
|
|
1007
1055
|
const countdown = typeof nextAt === 'number' ? duration(t, nextAt - now) : '';
|
|
1008
1056
|
const stale = typeof snapshot?.today === 'string' && snapshot.today !== new Date(now + 8 * 3600 * 1000).toISOString().slice(0, 10);
|
|
1009
1057
|
const prices = Array.isArray(snapshot?.prices) ? snapshot.prices : [];
|
|
1010
|
-
const
|
|
1011
|
-
const
|
|
1058
|
+
const allHistory = Array.isArray(snapshot?.history) ? snapshot.history : [];
|
|
1059
|
+
const history =
|
|
1060
|
+
chartWindow === 'month'
|
|
1061
|
+
? (() => {
|
|
1062
|
+
const prefix = (snapshot?.today ?? '').slice(0, 7);
|
|
1063
|
+
return allHistory.filter((row) => row.day.startsWith(prefix));
|
|
1064
|
+
})()
|
|
1065
|
+
: allHistory.slice(-Number(chartWindow));
|
|
1066
|
+
const windowTotal = history.reduce((sum, row) => sum + (row.cost ?? 0), 0);
|
|
1067
|
+
const windowModels = (() => {
|
|
1068
|
+
const table = {};
|
|
1069
|
+
for (const row of history) {
|
|
1070
|
+
for (const model of row.models ?? []) {
|
|
1071
|
+
const entry = table[model.model] ?? (table[model.model] = { model: model.model, cost: 0, tokens: 0 });
|
|
1072
|
+
entry.cost += model.cost ?? 0;
|
|
1073
|
+
entry.tokens += model.tokens ?? 0;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
return Object.values(table).sort((a, b) => b.cost - a.cost);
|
|
1077
|
+
})();
|
|
1012
1078
|
const models = Array.isArray(snapshot?.models) ? snapshot.models : [];
|
|
1013
1079
|
const turn = snapshot?.turn ?? null;
|
|
1014
1080
|
|
|
@@ -1124,9 +1190,17 @@ window.__ModuleLoader__.load({
|
|
|
1124
1190
|
),
|
|
1125
1191
|
h(
|
|
1126
1192
|
'div',
|
|
1127
|
-
{
|
|
1128
|
-
|
|
1129
|
-
|
|
1193
|
+
{
|
|
1194
|
+
className: 'dbf-sub',
|
|
1195
|
+
// The midnight baseline stays available on hover for anyone who
|
|
1196
|
+
// wants to check how "today used" was derived.
|
|
1197
|
+
title:
|
|
1198
|
+
typeof snapshot?.dayStart === 'number'
|
|
1199
|
+
? t('balance.startHint', { start: '¥' + money(snapshot.dayStart) })
|
|
1200
|
+
: undefined,
|
|
1201
|
+
},
|
|
1202
|
+
typeof snapshot?.balance === 'number'
|
|
1203
|
+
? t('balance.note', { balance: '¥' + money(snapshot.balance), used: '¥' + money(snapshot.todayUsed) })
|
|
1130
1204
|
: t('balance.noStart', { used: '¥' + money(snapshot?.todayUsed) }),
|
|
1131
1205
|
),
|
|
1132
1206
|
h(
|
|
@@ -1315,13 +1389,6 @@ window.__ModuleLoader__.load({
|
|
|
1315
1389
|
),
|
|
1316
1390
|
),
|
|
1317
1391
|
),
|
|
1318
|
-
models.length > 0
|
|
1319
|
-
? h(
|
|
1320
|
-
'div',
|
|
1321
|
-
{ className: 'dbf-sub', style: { marginTop: '6px' } },
|
|
1322
|
-
models.map((row) => modelLabel(row.model) + ' ¥' + money(row.cost)).join(' · '),
|
|
1323
|
-
)
|
|
1324
|
-
: null,
|
|
1325
1392
|
);
|
|
1326
1393
|
|
|
1327
1394
|
const historyBlock = h(
|
|
@@ -1331,14 +1398,58 @@ window.__ModuleLoader__.load({
|
|
|
1331
1398
|
'div',
|
|
1332
1399
|
{ className: 'dbf-row' },
|
|
1333
1400
|
h('span', { className: 'dbf-row-title' }, t('history')),
|
|
1334
|
-
h(
|
|
1401
|
+
h(
|
|
1402
|
+
'span',
|
|
1403
|
+
{ className: 'dbf-windows' },
|
|
1404
|
+
['7', '30', 'month'].map((key) =>
|
|
1405
|
+
h(
|
|
1406
|
+
'button',
|
|
1407
|
+
{
|
|
1408
|
+
key,
|
|
1409
|
+
type: 'button',
|
|
1410
|
+
className: 'dbf-window' + (chartWindow === key ? ' is-active' : ''),
|
|
1411
|
+
onClick: () => setChartWindow(key),
|
|
1412
|
+
},
|
|
1413
|
+
t('history.window.' + key),
|
|
1414
|
+
),
|
|
1415
|
+
),
|
|
1416
|
+
),
|
|
1335
1417
|
),
|
|
1418
|
+
h(
|
|
1419
|
+
'div',
|
|
1420
|
+
{ className: 'dbf-trend-meta' },
|
|
1421
|
+
h('span', { className: 'dbf-trend-total' }, '¥' + money(windowTotal)),
|
|
1422
|
+
h(
|
|
1423
|
+
'span',
|
|
1424
|
+
{ className: 'dbf-trend-calls' },
|
|
1425
|
+
t('history.calls', { calls: history.reduce((sum, row) => sum + (row.calls ?? 0), 0) }),
|
|
1426
|
+
),
|
|
1427
|
+
),
|
|
1428
|
+
windowModels.length > 0
|
|
1429
|
+
? h(
|
|
1430
|
+
'div',
|
|
1431
|
+
{ className: 'dbf-models dbf-models-window' },
|
|
1432
|
+
windowModels.map((row) => {
|
|
1433
|
+
const total = windowTotal > 0 ? windowTotal : 1;
|
|
1434
|
+
const share = Math.max(2, Math.round(((row.cost ?? 0) / total) * 100));
|
|
1435
|
+
return h(
|
|
1436
|
+
'div',
|
|
1437
|
+
{ key: row.model, className: 'dbf-mrow' },
|
|
1438
|
+
h('span', { className: 'dbf-mname', title: row.model }, modelLabel(row.model)),
|
|
1439
|
+
h('span', { className: 'dbf-mbar-track' }, h('span', { className: 'dbf-mbar', style: { width: share + '%' } })),
|
|
1440
|
+
h('span', { className: 'dbf-mcost' }, '¥' + money(row.cost)),
|
|
1441
|
+
h('span', { className: 'dbf-mshare' }, share + '%'),
|
|
1442
|
+
);
|
|
1443
|
+
}),
|
|
1444
|
+
)
|
|
1445
|
+
: null,
|
|
1336
1446
|
h(
|
|
1337
1447
|
'div',
|
|
1338
1448
|
{ className: 'dbf-bars' },
|
|
1339
1449
|
history.map((row) => {
|
|
1340
1450
|
const value = typeof row.cost === 'number' ? row.cost : 0;
|
|
1341
|
-
const
|
|
1451
|
+
const windowMax = Math.max(...history.map((entry) => entry.cost ?? 0), 0);
|
|
1452
|
+
const ratio = windowMax > 0 ? Math.max(2, Math.round((value / windowMax) * 38)) : 2;
|
|
1342
1453
|
const isToday = typeof snapshot?.today === 'string' && row.day === snapshot.today;
|
|
1343
1454
|
return h(
|
|
1344
1455
|
'div',
|
|
@@ -1357,7 +1468,7 @@ window.__ModuleLoader__.load({
|
|
|
1357
1468
|
},
|
|
1358
1469
|
},
|
|
1359
1470
|
h('div', { className: 'dbf-bar-fill', style: { height: ratio + 'px' } }),
|
|
1360
|
-
h('div', { className: 'dbf-bar-day' }, row.day.slice(
|
|
1471
|
+
h('div', { className: 'dbf-bar-day' }, row.day.slice(8).replace(/^0/, '')),
|
|
1361
1472
|
);
|
|
1362
1473
|
}),
|
|
1363
1474
|
),
|
package/lib/snapshot.js
CHANGED
|
@@ -145,7 +145,7 @@ export function buildSnapshot({ ledger, sourcePath, mtimeMs, serverNow = Date.no
|
|
|
145
145
|
const days = Object.keys(history)
|
|
146
146
|
.filter((day) => /^\d{4}-\d{2}-\d{2}$/.test(day))
|
|
147
147
|
.sort()
|
|
148
|
-
.slice(-
|
|
148
|
+
.slice(-30)
|
|
149
149
|
// Each bar carries its own breakdown (folded from the stored events); old
|
|
150
150
|
// days whose events rolled out of MAX_EVENTS fall back to the stored total.
|
|
151
151
|
const recent = days.map((day) => {
|