@lls-a1/dsh-balance-float 1.1.53 → 1.1.55
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 +155 -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,13 @@ 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} 次',
|
|
116
|
+
'history.peak': '峰段 {cost}',
|
|
117
|
+
'history.valley': '谷段 {cost}',
|
|
111
118
|
'history.total': '合计 {total}',
|
|
112
119
|
version: '版本',
|
|
113
120
|
'version.open': '打开插件页(更新在这里)',
|
|
@@ -150,8 +157,9 @@ window.__ModuleLoader__.load({
|
|
|
150
157
|
balance: 'Balance',
|
|
151
158
|
topup: 'Top up ↗',
|
|
152
159
|
'topup.title': 'Open the official DeepSeek top-up page',
|
|
153
|
-
'balance.note': '
|
|
160
|
+
'balance.note': 'Balance {balance}, used {used}',
|
|
154
161
|
'balance.noStart': 'Used today {used}',
|
|
162
|
+
'balance.startHint': 'Balance at midnight {start}',
|
|
155
163
|
today: 'Used today',
|
|
156
164
|
turn: 'Last turn',
|
|
157
165
|
'turn.label': 'Turn',
|
|
@@ -194,7 +202,13 @@ window.__ModuleLoader__.load({
|
|
|
194
202
|
'price.hit': 'Hit',
|
|
195
203
|
'price.miss': 'Miss',
|
|
196
204
|
'price.out': 'Out',
|
|
197
|
-
history: '
|
|
205
|
+
history: 'Usage trend',
|
|
206
|
+
'history.window.7': '7d',
|
|
207
|
+
'history.window.30': '30d',
|
|
208
|
+
'history.window.month': 'Month',
|
|
209
|
+
'history.calls': '{calls} calls',
|
|
210
|
+
'history.peak': 'Peak {cost}',
|
|
211
|
+
'history.valley': 'Valley {cost}',
|
|
198
212
|
'history.total': 'Total {total}',
|
|
199
213
|
version: 'Version',
|
|
200
214
|
'version.open': 'Open the plugin page (updates live there)',
|
|
@@ -277,9 +291,10 @@ window.__ModuleLoader__.load({
|
|
|
277
291
|
'.dbf-bubble.is-right-of .dbf-bubble-caret{top:50%;left:-4px;margin-top:-4px;transform:rotate(-45deg)}',
|
|
278
292
|
'.dbf-bubble.is-left-of .dbf-bubble-caret{top:50%;right:-4px;left:auto;margin-top:-4px;transform:rotate(135deg)}',
|
|
279
293
|
'@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-
|
|
294
|
+
'.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
295
|
'.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
|
|
296
|
+
'.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}',
|
|
297
|
+
'.dbf-switch.is-on .dbf-switch-knob{background:#fff}',
|
|
283
298
|
'.dbf-switch.is-on .dbf-switch-knob{transform:translateX(14px)}',
|
|
284
299
|
'.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
300
|
'.dbf-topup:hover{border-color:var(--dsw-alias-brand-primary,#4d6bfe)}',
|
|
@@ -323,11 +338,28 @@ window.__ModuleLoader__.load({
|
|
|
323
338
|
'.dbf-valley{color:var(--dsw-alias-state-success-primary)}',
|
|
324
339
|
'.dbf-badge.dbf-peak{border-color:currentColor}',
|
|
325
340
|
'.dbf-badge.dbf-valley{border-color:currentColor}',
|
|
326
|
-
'.dbf-
|
|
327
|
-
'.dbf-
|
|
341
|
+
'.dbf-windows{display:inline-flex;gap:2px}',
|
|
342
|
+
'.dbf-models-window{margin-top:6px}',
|
|
343
|
+
'.dbf-mrow{display:flex;align-items:center;gap:6px;font-size:11px;line-height:16px}',
|
|
344
|
+
'.dbf-mname{min-width:66px;color:var(--dsw-alias-label-secondary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}',
|
|
345
|
+
'.dbf-mbar-track{flex:1 1 auto;height:4px;border-radius:2px;background:var(--dsw-alias-border-l1);overflow:hidden}',
|
|
346
|
+
'.dbf-mbar{display:block;height:100%;border-radius:2px;background:var(--dsw-alias-brand-primary,#4d6bfe);opacity:.75}',
|
|
347
|
+
'.dbf-mcost{font-variant-numeric:tabular-nums}',
|
|
348
|
+
'.dbf-mshare{min-width:30px;text-align:right;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums}',
|
|
349
|
+
'.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}',
|
|
350
|
+
'.dbf-window:hover{color:var(--dsw-alias-label-primary)}',
|
|
351
|
+
'.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}',
|
|
352
|
+
'.dbf-trend-meta{display:flex;align-items:baseline;gap:8px;margin-top:5px}',
|
|
353
|
+
'.dbf-trend-total{font-size:13px;font-weight:600;font-variant-numeric:tabular-nums}',
|
|
354
|
+
'.dbf-trend-calls{font-size:11px;color:var(--dsw-alias-label-secondary)}',
|
|
355
|
+
'.dbf-trend-split{display:flex;align-items:center;gap:6px;margin-top:2px;font-size:11px;line-height:16px;font-variant-numeric:tabular-nums}',
|
|
356
|
+
'.dbf-trend-dot{color:var(--dsw-alias-label-secondary);opacity:.6}',
|
|
357
|
+
'.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}',
|
|
358
|
+
'.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
359
|
'.dbf-bar-fill{width:100%;min-height:2px;border-radius:3px 3px 0 0;background:var(--dsw-alias-border-l2)}',
|
|
329
360
|
'.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}',
|
|
361
|
+
'.dbf-bar-day{color:var(--dsw-alias-label-secondary);font-size:9.5px;line-height:12px;white-space:nowrap;font-variant-numeric:tabular-nums}',
|
|
362
|
+
'.dbf-bar.is-today .dbf-bar-day{color:var(--dsw-alias-label-primary);font-weight:600}',
|
|
331
363
|
'.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
364
|
'.dbf-foot-path{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
|
|
333
365
|
'.dbf-foot-time{margin-left:auto;white-space:nowrap}',
|
|
@@ -453,11 +485,31 @@ window.__ModuleLoader__.load({
|
|
|
453
485
|
}
|
|
454
486
|
|
|
455
487
|
/** Short model name for the price table. */
|
|
488
|
+
/** Compact label: vendor + version + tier, so similar ids stay distinct. */
|
|
456
489
|
function modelLabel(model) {
|
|
457
|
-
const
|
|
458
|
-
if (
|
|
459
|
-
|
|
460
|
-
|
|
490
|
+
const raw = String(model || '');
|
|
491
|
+
if (raw === '') return '—';
|
|
492
|
+
const key = raw.toLowerCase();
|
|
493
|
+
let vendor = '';
|
|
494
|
+
let rest = key;
|
|
495
|
+
if (rest.startsWith('deepseek')) {
|
|
496
|
+
vendor = 'DS';
|
|
497
|
+
rest = rest.replace(/^deepseek[-_]?/, '');
|
|
498
|
+
} else if (rest.startsWith('glm')) {
|
|
499
|
+
vendor = 'GLM';
|
|
500
|
+
rest = rest.replace(/^glm[-_]?/, '');
|
|
501
|
+
} else if (rest.startsWith('claude')) {
|
|
502
|
+
vendor = 'Claude';
|
|
503
|
+
rest = rest.replace(/^claude[-_]?/, '');
|
|
504
|
+
} else if (rest.startsWith('gpt')) {
|
|
505
|
+
vendor = 'GPT';
|
|
506
|
+
rest = rest.replace(/^gpt[-_]?/, '');
|
|
507
|
+
}
|
|
508
|
+
const tier = rest.includes('pro') ? 'Pro' : rest.includes('flash') ? 'Flash' : '';
|
|
509
|
+
// First version-like token that is not a date/build stamp (four digits).
|
|
510
|
+
const version = (rest.match(/v?\d+(?:\.\d+)?/g) ?? []).find((token) => !/^\d{4}$/.test(token)) ?? '';
|
|
511
|
+
const label = [vendor, version, tier].filter((part) => part !== '').join(' ');
|
|
512
|
+
return label === '' ? raw : label;
|
|
461
513
|
}
|
|
462
514
|
|
|
463
515
|
/** Persisted appearance, clamped to the sliders' own ranges. */
|
|
@@ -562,8 +614,10 @@ window.__ModuleLoader__.load({
|
|
|
562
614
|
const [bubbleUp, setBubbleUp] = useState(false);
|
|
563
615
|
// «?» next to the current billing period: reveals the peak/valley windows.
|
|
564
616
|
const [hintOpen, setHintOpen] = useState(false);
|
|
565
|
-
// A bar of the
|
|
617
|
+
// A bar of the chart opens that day's detail view; the chart shows 7 or
|
|
618
|
+
// 30 days (or the current month) depending on the chosen window.
|
|
566
619
|
const [selectedDay, setSelectedDay] = useState(null);
|
|
620
|
+
const [chartWindow, setChartWindow] = useState('7');
|
|
567
621
|
// Token buckets are collapsed until asked for.
|
|
568
622
|
const [tokensOpen, setTokensOpen] = useState(false);
|
|
569
623
|
// Auto check: null | {phase, latest, current, hasUpdate}
|
|
@@ -1007,8 +1061,28 @@ window.__ModuleLoader__.load({
|
|
|
1007
1061
|
const countdown = typeof nextAt === 'number' ? duration(t, nextAt - now) : '';
|
|
1008
1062
|
const stale = typeof snapshot?.today === 'string' && snapshot.today !== new Date(now + 8 * 3600 * 1000).toISOString().slice(0, 10);
|
|
1009
1063
|
const prices = Array.isArray(snapshot?.prices) ? snapshot.prices : [];
|
|
1010
|
-
const
|
|
1011
|
-
const
|
|
1064
|
+
const allHistory = Array.isArray(snapshot?.history) ? snapshot.history : [];
|
|
1065
|
+
const history =
|
|
1066
|
+
chartWindow === 'month'
|
|
1067
|
+
? (() => {
|
|
1068
|
+
const prefix = (snapshot?.today ?? '').slice(0, 7);
|
|
1069
|
+
return allHistory.filter((row) => row.day.startsWith(prefix));
|
|
1070
|
+
})()
|
|
1071
|
+
: allHistory.slice(-Number(chartWindow));
|
|
1072
|
+
const windowTotal = history.reduce((sum, row) => sum + (row.cost ?? 0), 0);
|
|
1073
|
+
const windowPeakCost = history.reduce((sum, row) => sum + (row.peakCost ?? 0), 0);
|
|
1074
|
+
const windowValleyCost = history.reduce((sum, row) => sum + (row.valleyCost ?? 0), 0);
|
|
1075
|
+
const windowModels = (() => {
|
|
1076
|
+
const table = {};
|
|
1077
|
+
for (const row of history) {
|
|
1078
|
+
for (const model of row.models ?? []) {
|
|
1079
|
+
const entry = table[model.model] ?? (table[model.model] = { model: model.model, cost: 0, tokens: 0 });
|
|
1080
|
+
entry.cost += model.cost ?? 0;
|
|
1081
|
+
entry.tokens += model.tokens ?? 0;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
return Object.values(table).sort((a, b) => b.cost - a.cost);
|
|
1085
|
+
})();
|
|
1012
1086
|
const models = Array.isArray(snapshot?.models) ? snapshot.models : [];
|
|
1013
1087
|
const turn = snapshot?.turn ?? null;
|
|
1014
1088
|
|
|
@@ -1124,9 +1198,17 @@ window.__ModuleLoader__.load({
|
|
|
1124
1198
|
),
|
|
1125
1199
|
h(
|
|
1126
1200
|
'div',
|
|
1127
|
-
{
|
|
1128
|
-
|
|
1129
|
-
|
|
1201
|
+
{
|
|
1202
|
+
className: 'dbf-sub',
|
|
1203
|
+
// The midnight baseline stays available on hover for anyone who
|
|
1204
|
+
// wants to check how "today used" was derived.
|
|
1205
|
+
title:
|
|
1206
|
+
typeof snapshot?.dayStart === 'number'
|
|
1207
|
+
? t('balance.startHint', { start: '¥' + money(snapshot.dayStart) })
|
|
1208
|
+
: undefined,
|
|
1209
|
+
},
|
|
1210
|
+
typeof snapshot?.balance === 'number'
|
|
1211
|
+
? t('balance.note', { balance: '¥' + money(snapshot.balance), used: '¥' + money(snapshot.todayUsed) })
|
|
1130
1212
|
: t('balance.noStart', { used: '¥' + money(snapshot?.todayUsed) }),
|
|
1131
1213
|
),
|
|
1132
1214
|
h(
|
|
@@ -1315,13 +1397,6 @@ window.__ModuleLoader__.load({
|
|
|
1315
1397
|
),
|
|
1316
1398
|
),
|
|
1317
1399
|
),
|
|
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
1400
|
);
|
|
1326
1401
|
|
|
1327
1402
|
const historyBlock = h(
|
|
@@ -1331,14 +1406,65 @@ window.__ModuleLoader__.load({
|
|
|
1331
1406
|
'div',
|
|
1332
1407
|
{ className: 'dbf-row' },
|
|
1333
1408
|
h('span', { className: 'dbf-row-title' }, t('history')),
|
|
1334
|
-
h(
|
|
1409
|
+
h(
|
|
1410
|
+
'span',
|
|
1411
|
+
{ className: 'dbf-windows' },
|
|
1412
|
+
['7', '30', 'month'].map((key) =>
|
|
1413
|
+
h(
|
|
1414
|
+
'button',
|
|
1415
|
+
{
|
|
1416
|
+
key,
|
|
1417
|
+
type: 'button',
|
|
1418
|
+
className: 'dbf-window' + (chartWindow === key ? ' is-active' : ''),
|
|
1419
|
+
onClick: () => setChartWindow(key),
|
|
1420
|
+
},
|
|
1421
|
+
t('history.window.' + key),
|
|
1422
|
+
),
|
|
1423
|
+
),
|
|
1424
|
+
),
|
|
1425
|
+
),
|
|
1426
|
+
h(
|
|
1427
|
+
'div',
|
|
1428
|
+
{ className: 'dbf-trend-meta' },
|
|
1429
|
+
h('span', { className: 'dbf-trend-total' }, '¥' + money(windowTotal)),
|
|
1430
|
+
h(
|
|
1431
|
+
'span',
|
|
1432
|
+
{ className: 'dbf-trend-calls' },
|
|
1433
|
+
t('history.calls', { calls: history.reduce((sum, row) => sum + (row.calls ?? 0), 0) }),
|
|
1434
|
+
),
|
|
1435
|
+
),
|
|
1436
|
+
h(
|
|
1437
|
+
'div',
|
|
1438
|
+
{ className: 'dbf-trend-split' },
|
|
1439
|
+
h('span', { className: 'dbf-peak' }, t('history.peak', { cost: '¥' + money(windowPeakCost) })),
|
|
1440
|
+
h('span', { className: 'dbf-trend-dot' }, '·'),
|
|
1441
|
+
h('span', { className: 'dbf-valley' }, t('history.valley', { cost: '¥' + money(windowValleyCost) })),
|
|
1335
1442
|
),
|
|
1443
|
+
windowModels.length > 0
|
|
1444
|
+
? h(
|
|
1445
|
+
'div',
|
|
1446
|
+
{ className: 'dbf-models dbf-models-window' },
|
|
1447
|
+
windowModels.map((row) => {
|
|
1448
|
+
const total = windowTotal > 0 ? windowTotal : 1;
|
|
1449
|
+
const share = Math.max(2, Math.round(((row.cost ?? 0) / total) * 100));
|
|
1450
|
+
return h(
|
|
1451
|
+
'div',
|
|
1452
|
+
{ key: row.model, className: 'dbf-mrow' },
|
|
1453
|
+
h('span', { className: 'dbf-mname', title: row.model }, modelLabel(row.model)),
|
|
1454
|
+
h('span', { className: 'dbf-mbar-track' }, h('span', { className: 'dbf-mbar', style: { width: share + '%' } })),
|
|
1455
|
+
h('span', { className: 'dbf-mcost' }, '¥' + money(row.cost)),
|
|
1456
|
+
h('span', { className: 'dbf-mshare' }, share + '%'),
|
|
1457
|
+
);
|
|
1458
|
+
}),
|
|
1459
|
+
)
|
|
1460
|
+
: null,
|
|
1336
1461
|
h(
|
|
1337
1462
|
'div',
|
|
1338
1463
|
{ className: 'dbf-bars' },
|
|
1339
1464
|
history.map((row) => {
|
|
1340
1465
|
const value = typeof row.cost === 'number' ? row.cost : 0;
|
|
1341
|
-
const
|
|
1466
|
+
const windowMax = Math.max(...history.map((entry) => entry.cost ?? 0), 0);
|
|
1467
|
+
const ratio = windowMax > 0 ? Math.max(2, Math.round((value / windowMax) * 38)) : 2;
|
|
1342
1468
|
const isToday = typeof snapshot?.today === 'string' && row.day === snapshot.today;
|
|
1343
1469
|
return h(
|
|
1344
1470
|
'div',
|
|
@@ -1357,7 +1483,7 @@ window.__ModuleLoader__.load({
|
|
|
1357
1483
|
},
|
|
1358
1484
|
},
|
|
1359
1485
|
h('div', { className: 'dbf-bar-fill', style: { height: ratio + 'px' } }),
|
|
1360
|
-
h('div', { className: 'dbf-bar-day' }, row.day.slice(
|
|
1486
|
+
h('div', { className: 'dbf-bar-day' }, row.day.slice(8).replace(/^0/, '')),
|
|
1361
1487
|
);
|
|
1362
1488
|
}),
|
|
1363
1489
|
),
|
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) => {
|