@lls-a1/dsh-balance-float 1.1.52 → 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 CHANGED
@@ -27,12 +27,10 @@ window.__ModuleLoader__.load({
27
27
  const h = React.createElement;
28
28
 
29
29
  const NS = 'balance-float';
30
+ /** The published name DSH's plugin manager lists this bundle under. */
31
+ const PACKAGE_NAME = '@lls-a1/dsh-balance-float';
30
32
  const ROUTE = '/balance-float/snapshot';
31
33
  const ROUTE_UPDATE = '/balance-float/update';
32
- const NPM_SPEC = '@lls-a1/dsh-balance-float';
33
- // Native modal support decides whether the mask lives in the top layer.
34
- const DIALOG_OK =
35
- typeof document !== 'undefined' && typeof document.createElement('dialog').showModal === 'function';
36
34
  const REPO_URL = 'https://github.com/ming-a1/dsh-balance-float';
37
35
  const POS_KEY = 'dsh.balance-float.position';
38
36
  // Official top-up page; the balance endpoint has no recharge API, so the
@@ -65,8 +63,9 @@ window.__ModuleLoader__.load({
65
63
  balance: '余额',
66
64
  topup: '充值 ↗',
67
65
  'topup.title': '打开 DeepSeek 官方充值页',
68
- 'balance.note': '今日 0 点 {start},已用 {used}',
66
+ 'balance.note': '总余额 {balance},已用 {used}',
69
67
  'balance.noStart': '今日已用 {used}',
68
+ 'balance.startHint': '今日 0 点余额 {start}',
70
69
  today: '今日已用',
71
70
  turn: '本轮消耗',
72
71
  'turn.label': '本轮',
@@ -109,23 +108,15 @@ window.__ModuleLoader__.load({
109
108
  'price.hit': '命中',
110
109
  'price.miss': '未命中',
111
110
  'price.out': '输出',
112
- history: '近 7 天',
111
+ history: '用量趋势',
112
+ 'history.window.7': '近7天',
113
+ 'history.window.30': '近30天',
114
+ 'history.window.month': '本月',
115
+ 'history.calls': '{calls} 次',
113
116
  'history.total': '合计 {total}',
114
117
  version: '版本',
115
- 'update.check': '点击检查更新',
116
- 'update.title': '检查更新',
117
- 'update.checking': '正在检查…',
118
- 'update.failed': '检查失败',
119
- 'update.found': '发现新版本 v{latest}(当前 v{current})',
120
- 'update.latest': '最新版本 v{current}',
121
- 'update.label.current': '当前',
122
- 'update.label.latest': '最新',
123
- 'update.now': '更新',
124
- 'update.copy': '复制安装链接',
125
- 'update.copied': '已复制 ✓',
126
- 'update.installHint': '复制后到插件管理器里粘贴安装(npm 包名,安装源可选用国内镜像)。',
127
- 'update.later': '稍后',
128
- 'update.retry': '点击重试',
118
+ 'version.open': '打开插件页(更新在这里)',
119
+ 'version.new': '发现新版本 v{latest},点击打开插件页更新',
129
120
  source: '本地账本',
130
121
  updated: '更新于 {time}',
131
122
  refreshing: '正在刷新',
@@ -164,8 +155,9 @@ window.__ModuleLoader__.load({
164
155
  balance: 'Balance',
165
156
  topup: 'Top up ↗',
166
157
  'topup.title': 'Open the official DeepSeek top-up page',
167
- 'balance.note': 'Started today at {start}, used {used}',
158
+ 'balance.note': 'Balance {balance}, used {used}',
168
159
  'balance.noStart': 'Used today {used}',
160
+ 'balance.startHint': 'Balance at midnight {start}',
169
161
  today: 'Used today',
170
162
  turn: 'Last turn',
171
163
  'turn.label': 'Turn',
@@ -208,23 +200,15 @@ window.__ModuleLoader__.load({
208
200
  'price.hit': 'Hit',
209
201
  'price.miss': 'Miss',
210
202
  'price.out': 'Out',
211
- history: 'Last 7 days',
203
+ history: 'Usage trend',
204
+ 'history.window.7': '7d',
205
+ 'history.window.30': '30d',
206
+ 'history.window.month': 'Month',
207
+ 'history.calls': '{calls} calls',
212
208
  'history.total': 'Total {total}',
213
209
  version: 'Version',
214
- 'update.check': 'Click to check for updates',
215
- 'update.title': 'Check for updates',
216
- 'update.checking': 'Checking…',
217
- 'update.failed': 'Update check failed',
218
- 'update.found': 'v{latest} is available (you have v{current})',
219
- 'update.latest': 'Latest version v{current}',
220
- 'update.label.current': 'Current',
221
- 'update.label.latest': 'Latest',
222
- 'update.now': 'Update',
223
- 'update.copy': 'Copy install spec',
224
- 'update.copied': 'Copied ✓',
225
- 'update.installHint': 'Paste this npm package name into the plugin manager to upgrade.',
226
- 'update.later': 'Later',
227
- 'update.retry': 'click to retry',
210
+ 'version.open': 'Open the plugin page (updates live there)',
211
+ 'version.new': 'v{latest} is available — click to open the plugin page',
228
212
  source: 'Local ledger',
229
213
  updated: 'Updated {time}',
230
214
  refreshing: 'Refreshing',
@@ -303,9 +287,10 @@ window.__ModuleLoader__.load({
303
287
  '.dbf-bubble.is-right-of .dbf-bubble-caret{top:50%;left:-4px;margin-top:-4px;transform:rotate(-45deg)}',
304
288
  '.dbf-bubble.is-left-of .dbf-bubble-caret{top:50%;right:-4px;left:auto;margin-top:-4px;transform:rotate(135deg)}',
305
289
  '@keyframes dbf-flash-side{0%{opacity:0}12%{opacity:1}84%{opacity:1}100%{opacity:0}}',
306
- '.dbf-switch{flex:none;width:34px;height:20px;padding:0;border-radius:999px;border:1px solid var(--dsw-alias-border-l3,var(--dsw-alias-border-l2));background:var(--dsw-alias-bg-layer-2,var(--dsw-alias-bg-overlay));position:relative;cursor:pointer;transition:background-color .15s ease,border-color .15s ease}',
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}',
307
291
  '.dbf-switch.is-on{background:var(--dsw-alias-brand-primary,#4d6bfe);border-color:transparent}',
308
- '.dbf-switch-knob{position:absolute;top:2px;left:2px;width:14px;height:14px;border-radius:50%;background:#fff;transition:transform .15s ease}',
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}',
309
294
  '.dbf-switch.is-on .dbf-switch-knob{transform:translateX(14px)}',
310
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}',
311
296
  '.dbf-topup:hover{border-color:var(--dsw-alias-brand-primary,#4d6bfe)}',
@@ -316,27 +301,6 @@ window.__ModuleLoader__.load({
316
301
  '.dbf-version-glyph{font-size:10px;opacity:.75}',
317
302
  '.dbf-version.has-update{color:var(--dsw-alias-state-error-primary)}',
318
303
  '.dbf-version.has-update .dbf-version-glyph{opacity:1}',
319
- '.dbf-modal{position:fixed;top:0;right:0;bottom:0;left:0;height:100dvh;z-index:10;display:flex;align-items:center;justify-content:center;padding:calc(12px + env(safe-area-inset-top,0px)) 12px calc(12px + env(safe-area-inset-bottom,0px));background:rgba(0,0,0,.45);overscroll-behavior:contain;touch-action:none}',
320
- '.dbf-dialog{position:fixed;top:0;left:0;width:100vw;height:100dvh;min-width:100vw;min-height:100dvh;max-width:none;max-height:none;margin:0;padding:calc(12px + env(safe-area-inset-top,0px)) 12px calc(12px + env(safe-area-inset-bottom,0px));border:0;box-sizing:border-box;background:transparent;color:inherit;display:flex;align-items:center;justify-content:center;overflow:hidden;overscroll-behavior:contain;outline:none}',
321
- '.dbf-dialog:focus,.dbf-dialog:focus-visible{outline:none}',
322
- '.dbf-modal-open{scrollbar-width:none}',
323
- '.dbf-modal-open ::-webkit-scrollbar{width:0;height:0;display:none}',
324
- '.dbf-dialog::backdrop{background:rgba(0,0,0,.45)}',
325
- '.dbf-modal-card{position:fixed;left:50%;top:50%;transform:translate(-50%,-50%);width:min(308px,calc(100vw - 24px));margin:0;max-height:calc(100dvh - 24px);overflow:auto;touch-action:auto;overscroll-behavior:contain;padding:16px;border-radius:14px;box-shadow:0 18px 48px rgba(0,0,0,calc(.34 * var(--dbf-shadow,1)));background:var(--dsw-alias-bg-layer-1,Canvas);color:var(--dsw-alias-label-primary,CanvasText)}',
326
- '.dbf-modal-head{display:flex;align-items:center;gap:8px;margin-bottom:10px}',
327
- '.dbf-modal-icon{width:22px;height:22px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;background:var(--dsw-alias-bg-layer-2,var(--dsw-alias-bg-overlay));color:var(--dsw-alias-brand-primary,#4d6bfe);font-size:12px;line-height:1}',
328
- '.dbf-modal-title{font-size:13px;font-weight:600}',
329
- '.dbf-modal-body{font-size:12px;line-height:18px}',
330
- '.dbf-modal-note{margin-top:6px;font-size:11px;line-height:16px;color:var(--dsw-alias-label-secondary,currentColor);opacity:.85}',
331
- '.dbf-modal-versions{display:flex;align-items:center;gap:8px;margin-top:8px}',
332
- '.dbf-modal-version{display:flex;flex-direction:column;gap:1px;padding:4px 8px;border-radius:8px;background:var(--dsw-alias-bg-layer-2,var(--dsw-alias-bg-overlay))}',
333
- '.dbf-modal-version.is-new{background:color-mix(in srgb,var(--dsw-alias-brand-primary,#4d6bfe) 14%,transparent)}',
334
- '.dbf-modal-version-label{font-size:10px;line-height:13px;color:var(--dsw-alias-label-secondary,currentColor);opacity:.8}',
335
- '.dbf-modal-version-value{font-size:12px;line-height:17px;font-weight:600;font-variant-numeric:tabular-nums}',
336
- '.dbf-modal-arrow{color:var(--dsw-alias-label-tertiary)}',
337
- '.dbf-btn-primary{padding:4px 12px;border:0;border-radius:8px;background:var(--dsw-alias-label-primary,CanvasText);color:var(--dsw-alias-bg-base,Canvas);font:inherit;font-size:12px;font-weight:600;line-height:18px;cursor:pointer}',
338
- '.dbf-btn-primary:hover{filter:brightness(1.06)}',
339
- '.dbf-modal-actions{display:flex;justify-content:flex-end;gap:8px;margin-top:12px}',
340
304
  '.dbf-fold-head{cursor:pointer;user-select:none}',
341
305
  '.dbf-fold-arrow{display:inline-block;width:10px;margin-right:3px;color:var(--dsw-alias-label-tertiary);font-size:9px}',
342
306
  '.dbf-fold-head:hover .dbf-row-title{color:var(--dsw-alias-label-primary)}',
@@ -370,11 +334,26 @@ window.__ModuleLoader__.load({
370
334
  '.dbf-valley{color:var(--dsw-alias-state-success-primary)}',
371
335
  '.dbf-badge.dbf-peak{border-color:currentColor}',
372
336
  '.dbf-badge.dbf-valley{border-color:currentColor}',
373
- '.dbf-bars{display:flex;align-items:flex-end;gap:5px;height:46px;margin-top:9px}',
374
- '.dbf-bar{flex:1;min-width:0;display:flex;flex-direction:column;justify-content:flex-end;align-items:center;gap:3px}',
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}',
375
353
  '.dbf-bar-fill{width:100%;min-height:2px;border-radius:3px 3px 0 0;background:var(--dsw-alias-border-l2)}',
376
354
  '.dbf-bar.is-today .dbf-bar-fill{background:var(--dsw-alias-brand-primary)}',
377
- '.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}',
378
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}',
379
358
  '.dbf-foot-path{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}',
380
359
  '.dbf-foot-time{margin-left:auto;white-space:nowrap}',
@@ -500,11 +479,31 @@ window.__ModuleLoader__.load({
500
479
  }
501
480
 
502
481
  /** Short model name for the price table. */
482
+ /** Compact label: vendor + version + tier, so similar ids stay distinct. */
503
483
  function modelLabel(model) {
504
- const key = String(model || '').toLowerCase();
505
- if (key.indexOf('pro') !== -1) return 'Pro';
506
- if (key.indexOf('flash') !== -1) return 'Flash';
507
- return String(model || '—');
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;
508
507
  }
509
508
 
510
509
  /** Persisted appearance, clamped to the sliders' own ranges. */
@@ -581,11 +580,12 @@ window.__ModuleLoader__.load({
581
580
  // The shell can re-mount the overlay when a run starts or stops. Component
582
581
  // state is lost then, so the live position lives at module scope too: a
583
582
  // remount must not snap the widget back to the stored default.
584
- const shared = { frame: null, dir: 'up', dock: '', update: null, updateOpen: false };
583
+ const shared = { frame: null, dir: 'up', dock: '' };
585
584
 
586
585
  /** The floating pill and its expanded card. */
587
586
  function BalanceFloat(props) {
588
587
  const t = props.t;
588
+ const openPluginPage = typeof props.openPluginPage === 'function' ? props.openPluginPage : () => {};
589
589
  const [snapshot, setSnapshot] = useState(null);
590
590
  const [failure, setFailure] = useState('');
591
591
  const [busy, setBusy] = useState(false);
@@ -608,38 +608,15 @@ window.__ModuleLoader__.load({
608
608
  const [bubbleUp, setBubbleUp] = useState(false);
609
609
  // «?» next to the current billing period: reveals the peak/valley windows.
610
610
  const [hintOpen, setHintOpen] = useState(false);
611
- // A bar of the 7-day chart opens that day's detail view.
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.
612
613
  const [selectedDay, setSelectedDay] = useState(null);
614
+ const [chartWindow, setChartWindow] = useState('7');
613
615
  // Token buckets are collapsed until asked for.
614
616
  const [tokensOpen, setTokensOpen] = useState(false);
615
- // Update check: null | {phase, latest, current, hasUpdate, error}
616
- const [update, setUpdate] = useState(shared.update);
617
- const [updateOpen, setUpdateOpen] = useState(shared.updateOpen);
617
+ // Auto check: null | {phase, latest, current, hasUpdate}
618
+ const [update, setUpdate] = useState(null);
618
619
  const updateCheckedAt = useRef(0);
619
- const [copied, setCopied] = useState(false);
620
- const modalRef = useRef(null);
621
-
622
- // A plain fixed <div> stays inside the shell's stacking context, so the
623
- // page header kept painting above the mask. showModal() moves the element
624
- // into the browser top layer, where the ::backdrop always covers the
625
- // whole viewport — no z-index can beat it.
626
- useEffect(() => {
627
- if (update === null || !updateOpen) return undefined;
628
- const root = document.documentElement;
629
- root.classList.add('dbf-modal-open');
630
- return () => root.classList.remove('dbf-modal-open');
631
- }, [update, updateOpen]);
632
-
633
- useEffect(() => {
634
- const element = modalRef.current;
635
- if (element === null || typeof element.showModal !== 'function' || element.open) return;
636
- try {
637
- element.showModal();
638
- } catch {
639
- // already open or detached — nothing to do
640
- }
641
- });
642
-
643
620
  const flashAtRef = useRef(null);
644
621
  const flashTimerRef = useRef(null);
645
622
  const leaveTimerRef = useRef(null);
@@ -653,11 +630,6 @@ window.__ModuleLoader__.load({
653
630
  useEffect(() => {
654
631
  shared.dock = dock;
655
632
  }, [dock]);
656
- useEffect(() => {
657
- shared.update = update;
658
- shared.updateOpen = updateOpen;
659
- }, [update, updateOpen]);
660
-
661
633
  // Forces a re-render so the countdown text follows the clock.
662
634
  const [, setTick] = useState(0);
663
635
  // Host/browser clock offset, so the switch countdown follows the Host.
@@ -766,43 +738,30 @@ window.__ModuleLoader__.load({
766
738
  }, 200);
767
739
  }, []);
768
740
 
769
- /** Ask the Host whether a newer published version exists. */
770
- const checkUpdate = useCallback(async (showModal) => {
771
- const manual = showModal === true;
772
- if (showModal) setUpdateOpen(true);
773
- setUpdate({ phase: 'checking', latest: '', current: '', hasUpdate: false, error: '' });
774
- updateCheckedAt.current = Date.now();
741
+ /** Silent check so the footer can flag a newer release before you click. */
742
+ const checkUpdate = useCallback(async () => {
743
+ updateCheckedAt.current = Date.now()
775
744
  try {
776
- const response = await fetch(ROUTE_UPDATE + (manual ? '?fresh=1' : ''), { headers: { accept: 'application/json' }, cache: 'no-store' });
745
+ const response = await fetch(ROUTE_UPDATE, { headers: { accept: 'application/json' }, cache: 'no-store' });
777
746
  const body = await response.json();
778
747
  if (!aliveRef.current) return;
779
- if (!response.ok || body?.ok === false) {
780
- setUpdate({ phase: 'error', latest: '', current: body?.current ?? '', hasUpdate: false, error: body?.error ?? 'HTTP ' + response.status });
781
- return;
782
- }
748
+ if (!response.ok || body?.ok === false) return;
783
749
  setUpdate({
784
750
  phase: 'done',
785
751
  latest: typeof body.latest === 'string' ? body.latest : '',
786
752
  current: typeof body.current === 'string' ? body.current : '',
787
753
  hasUpdate: body.hasUpdate === true,
788
- error: '',
789
754
  });
790
- } catch (error) {
791
- if (!aliveRef.current) return;
792
- setUpdate({ phase: 'error', latest: '', current: '', hasUpdate: false, error: error instanceof Error ? error.message : String(error) });
755
+ } catch {
756
+ // Silent: a failed check must not disturb the widget.
793
757
  }
794
758
  }, []);
795
759
 
796
- // Check quietly when the card opens so the hover text already knows, and
797
- // re-check whenever the local version changed since the last answer.
798
760
  useEffect(() => {
799
761
  if (!open) return;
800
- if (update !== null && update.phase === 'checking') return;
801
- const version = snapshot?.version ?? '';
802
- const answered = update !== null && update.phase !== 'checking' && (update.current || '') === version;
803
- if (answered && Date.now() - updateCheckedAt.current < 5 * 60 * 1000) return;
804
- void checkUpdate(false);
805
- }, [open, update, snapshot?.version, checkUpdate]);
762
+ if (Date.now() - updateCheckedAt.current < 5 * 60 * 1000) return;
763
+ void checkUpdate();
764
+ }, [open, snapshot?.version, checkUpdate]);
806
765
 
807
766
  const load = useCallback(async (manual) => {
808
767
  // Hold the spinner for at least one full turn: a local read returns in
@@ -1096,8 +1055,26 @@ window.__ModuleLoader__.load({
1096
1055
  const countdown = typeof nextAt === 'number' ? duration(t, nextAt - now) : '';
1097
1056
  const stale = typeof snapshot?.today === 'string' && snapshot.today !== new Date(now + 8 * 3600 * 1000).toISOString().slice(0, 10);
1098
1057
  const prices = Array.isArray(snapshot?.prices) ? snapshot.prices : [];
1099
- const history = Array.isArray(snapshot?.history) ? snapshot.history : [];
1100
- const historyMax = typeof snapshot?.historyMax === 'number' && snapshot.historyMax > 0 ? snapshot.historyMax : 0;
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
+ })();
1101
1078
  const models = Array.isArray(snapshot?.models) ? snapshot.models : [];
1102
1079
  const turn = snapshot?.turn ?? null;
1103
1080
 
@@ -1120,18 +1097,6 @@ window.__ModuleLoader__.load({
1120
1097
 
1121
1098
  const dot = h('span', { className: 'dbf-dot ' + (peakActive ? 'is-peak' : 'is-valley'), 'aria-hidden': true });
1122
1099
 
1123
- // The version control's hover text reports the last check's outcome.
1124
- const updateTitle =
1125
- update === null
1126
- ? t('update.check')
1127
- : update.phase === 'checking'
1128
- ? t('update.checking')
1129
- : update.phase === 'error'
1130
- ? t('update.failed') + ' · ' + t('update.retry')
1131
- : update.hasUpdate
1132
- ? t('update.found', { latest: update.latest, current: update.current }) + ' · ' + t('update.now')
1133
- : t('update.latest', { current: update.current || snapshot?.version || '—' });
1134
-
1135
1100
  // Docked to a side edge: a square ball that only shows the balance.
1136
1101
  const docked = appearance.dockBall && dock !== '';
1137
1102
  const balanceText = '¥' + money(snapshot?.balance);
@@ -1225,9 +1190,17 @@ window.__ModuleLoader__.load({
1225
1190
  ),
1226
1191
  h(
1227
1192
  'div',
1228
- { className: 'dbf-sub' },
1229
- typeof snapshot?.dayStart === 'number'
1230
- ? t('balance.note', { start: '¥' + money(snapshot.dayStart), used: '¥' + money(snapshot.todayUsed) })
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) })
1231
1204
  : t('balance.noStart', { used: '¥' + money(snapshot?.todayUsed) }),
1232
1205
  ),
1233
1206
  h(
@@ -1416,13 +1389,6 @@ window.__ModuleLoader__.load({
1416
1389
  ),
1417
1390
  ),
1418
1391
  ),
1419
- models.length > 0
1420
- ? h(
1421
- 'div',
1422
- { className: 'dbf-sub', style: { marginTop: '6px' } },
1423
- models.map((row) => modelLabel(row.model) + ' ¥' + money(row.cost)).join(' · '),
1424
- )
1425
- : null,
1426
1392
  );
1427
1393
 
1428
1394
  const historyBlock = h(
@@ -1432,14 +1398,58 @@ window.__ModuleLoader__.load({
1432
1398
  'div',
1433
1399
  { className: 'dbf-row' },
1434
1400
  h('span', { className: 'dbf-row-title' }, t('history')),
1435
- h('span', { className: 'dbf-sub' }, t('history.total', { total: '¥' + money(snapshot?.historyTotal) })),
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
+ ),
1436
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,
1437
1446
  h(
1438
1447
  'div',
1439
1448
  { className: 'dbf-bars' },
1440
1449
  history.map((row) => {
1441
1450
  const value = typeof row.cost === 'number' ? row.cost : 0;
1442
- const ratio = historyMax > 0 ? Math.max(2, Math.round((value / historyMax) * 38)) : 2;
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;
1443
1453
  const isToday = typeof snapshot?.today === 'string' && row.day === snapshot.today;
1444
1454
  return h(
1445
1455
  'div',
@@ -1458,7 +1468,7 @@ window.__ModuleLoader__.load({
1458
1468
  },
1459
1469
  },
1460
1470
  h('div', { className: 'dbf-bar-fill', style: { height: ratio + 'px' } }),
1461
- h('div', { className: 'dbf-bar-day' }, row.day.slice(5)),
1471
+ h('div', { className: 'dbf-bar-day' }, row.day.slice(8).replace(/^0/, '')),
1462
1472
  );
1463
1473
  }),
1464
1474
  ),
@@ -1543,12 +1553,15 @@ window.__ModuleLoader__.load({
1543
1553
  'button',
1544
1554
  {
1545
1555
  type: 'button',
1546
- className: 'dbf-version' + (update !== null && update.phase === 'done' && update.hasUpdate ? ' has-update' : ''),
1547
- title: updateTitle,
1548
- onClick: () => void checkUpdate(true),
1556
+ className: 'dbf-version' + (update !== null && update.hasUpdate ? ' has-update' : ''),
1557
+ title:
1558
+ update !== null && update.hasUpdate
1559
+ ? t('version.new', { latest: update.latest })
1560
+ : t('version.open'),
1561
+ onClick: () => openPluginPage(),
1549
1562
  },
1550
1563
  t('version') + ' v' + (snapshot?.version || '—'),
1551
- h('span', { className: 'dbf-version-glyph', 'aria-hidden': true }, '↻'),
1564
+ h('span', { className: 'dbf-version-glyph', 'aria-hidden': true }, '↗'),
1552
1565
  ),
1553
1566
  h(
1554
1567
  'span',
@@ -1709,106 +1722,6 @@ window.__ModuleLoader__.load({
1709
1722
  )
1710
1723
  : null;
1711
1724
 
1712
- const updateModal =
1713
- update === null || !updateOpen
1714
- ? null
1715
- : h(
1716
- DIALOG_OK ? 'dialog' : 'div',
1717
- {
1718
- ref: DIALOG_OK ? modalRef : undefined,
1719
- className: DIALOG_OK ? 'dbf-dialog' : 'dbf-modal',
1720
- role: 'dialog',
1721
- 'aria-modal': 'true',
1722
- 'aria-label': t('update.title'),
1723
- onCancel: (event) => {
1724
- event.preventDefault();
1725
- setUpdateOpen(false);
1726
- },
1727
- onClick: (event) => {
1728
- if (event.target === event.currentTarget) setUpdateOpen(false);
1729
- },
1730
- },
1731
- h(
1732
- 'div',
1733
- { className: 'dbf-modal-card dbf-surface' },
1734
- h(
1735
- 'div',
1736
- { className: 'dbf-modal-head' },
1737
- h('span', { className: 'dbf-modal-icon', 'aria-hidden': true }, '⟳'),
1738
- h('span', { className: 'dbf-modal-title' }, t('update.title')),
1739
- ),
1740
- update.phase === 'checking'
1741
- ? h('div', { className: 'dbf-modal-body' }, t('update.checking'))
1742
- : update.phase === 'error'
1743
- ? h(
1744
- 'div',
1745
- null,
1746
- h('div', { className: 'dbf-modal-body dbf-error' }, t('update.failed') + ': ' + update.error),
1747
- h(
1748
- 'div',
1749
- { className: 'dbf-modal-actions' },
1750
- h(
1751
- 'button',
1752
- { type: 'button', className: 'dbf-btn-primary', onClick: () => void checkUpdate(true) },
1753
- t('update.retry'),
1754
- ),
1755
- ),
1756
- )
1757
- : update.hasUpdate
1758
- ? h(
1759
- 'div',
1760
- null,
1761
- h('div', { className: 'dbf-modal-body' }, t('update.found', { latest: update.latest, current: update.current })),
1762
- h(
1763
- 'div',
1764
- { className: 'dbf-modal-versions' },
1765
- h(
1766
- 'span',
1767
- { className: 'dbf-modal-version' },
1768
- h('span', { className: 'dbf-modal-version-label' }, t('update.label.current')),
1769
- h('span', { className: 'dbf-modal-version-value' }, 'v' + (update.current || '—')),
1770
- ),
1771
- h('span', { className: 'dbf-modal-arrow', 'aria-hidden': true }, '→'),
1772
- h(
1773
- 'span',
1774
- { className: 'dbf-modal-version is-new' },
1775
- h('span', { className: 'dbf-modal-version-label' }, t('update.label.latest')),
1776
- h('span', { className: 'dbf-modal-version-value' }, 'v' + update.latest),
1777
- ),
1778
- ),
1779
- h('div', { className: 'dbf-modal-note' }, t('update.installHint')),
1780
- h(
1781
- 'div',
1782
- { className: 'dbf-modal-actions' },
1783
- h(
1784
- 'button',
1785
- { type: 'button', className: 'dbf-textbtn', onClick: () => setUpdateOpen(false) },
1786
- t('update.later'),
1787
- ),
1788
- h(
1789
- 'button',
1790
- { type: 'button', className: 'dbf-btn-primary', onClick: () => void copyInstallSpec() },
1791
- copied ? t('update.copied') : t('update.copy'),
1792
- ),
1793
- ),
1794
- )
1795
- : h(
1796
- 'div',
1797
- null,
1798
- h('div', { className: 'dbf-modal-body' }, t('update.latest', { current: update.current || snapshot?.version || '—' })),
1799
- h(
1800
- 'div',
1801
- { className: 'dbf-modal-actions' },
1802
- h(
1803
- 'button',
1804
- { type: 'button', className: 'dbf-btn-primary', onClick: () => setUpdateOpen(false) },
1805
- t('settings.done'),
1806
- ),
1807
- ),
1808
- ),
1809
- ),
1810
- );
1811
-
1812
1725
  const surface = settingsOpen ? settingsPanel : open ? card : pill;
1813
1726
 
1814
1727
  const tree = h(
@@ -1817,9 +1730,6 @@ window.__ModuleLoader__.load({
1817
1730
  h('style', { key: 'css' }, STYLE),
1818
1731
  surface,
1819
1732
  bubble,
1820
- createPortal !== null && typeof document !== 'undefined' && updateModal !== null
1821
- ? createPortal(updateModal, document.body)
1822
- : updateModal,
1823
1733
  );
1824
1734
  return createPortal !== null && typeof document !== 'undefined' ? createPortal(tree, document.body) : tree;
1825
1735
  }
@@ -1831,9 +1741,19 @@ window.__ModuleLoader__.load({
1831
1741
  function apply(ctx) {
1832
1742
  ctx.effect(() => ctx.locale.register(NS, { zh: ZH, en: EN }), 'balance-float: dictionaries');
1833
1743
  const t = ctx.locale.bind(NS);
1744
+ // The plugin page ships its own update button, so the footer version just
1745
+ // jumps there instead of running a second update flow.
1746
+ const openPluginPage = () => {
1747
+ try {
1748
+ const navigation = ctx.get('pluginNavigation');
1749
+ navigation?.openBundle?.(PACKAGE_NAME);
1750
+ } catch {
1751
+ // plugin manager UI not installed: nothing to open
1752
+ }
1753
+ };
1834
1754
  ctx.slots.inject('shell.overlay', () =>
1835
1755
  ctx.slots.register({ name: 'shell.overlay', id: 'balance-float', order: 60, locale: NS }, (props) =>
1836
- h(MemoBalanceFloat, { ...props, t }),
1756
+ h(MemoBalanceFloat, { ...props, t, openPluginPage }),
1837
1757
  ),
1838
1758
  );
1839
1759
  }
package/index.js CHANGED
@@ -57,39 +57,32 @@ function isNewer(a, b) {
57
57
  return false
58
58
  }
59
59
 
60
- /** Cached check against the published package.json on the default branch. */
60
+ /** Cached check against the version published on npm. */
61
61
  const UPDATE_TTL_MS = 5 * 60 * 1000
62
- // Only the *published* version is cached; `current` is re-read every call so a
63
- // locally bumped version never reports the value cached minutes ago.
62
+ // Only the published version is cached; `current` is re-read every call so a
63
+ // locally bumped version is compared against the fresh one.
64
64
  let updateCache = { at: 0, latest: null }
65
65
 
66
66
  async function checkUpdate({ fresh = false } = {}) {
67
67
  const now = Date.now()
68
68
  const current = packageVersion()
69
- // A manual click must never be answered from the cache: the published version
70
- // can change right after a silent check.
71
69
  if (!fresh && updateCache.latest !== null && now - updateCache.at < UPDATE_TTL_MS) {
72
70
  return { ok: true, current, latest: updateCache.latest, hasUpdate: isNewer(updateCache.latest, current) }
73
71
  }
74
72
  const controller = new AbortController()
75
73
  const timer = setTimeout(() => controller.abort(), 10000)
76
74
  try {
77
- // api.github.com is reachable on hosts where raw.githubusercontent.com is
78
- // not (and it needs no token for a public repo).
79
- const response = await fetch(
80
- 'https://api.github.com/repos/ming-a1/dsh-balance-float/contents/package.json?ref=main',
81
- {
82
- signal: controller.signal,
83
- headers: { accept: 'application/vnd.github.raw', 'user-agent': 'dsh-balance-float' },
84
- },
85
- )
75
+ const response = await fetch('https://registry.npmjs.org/@lls-a1/dsh-balance-float/latest', {
76
+ signal: controller.signal,
77
+ headers: { accept: 'application/json', 'user-agent': 'dsh-balance-float' },
78
+ })
86
79
  if (!response.ok) throw new Error(`HTTP ${response.status}`)
87
80
  const pkg = JSON.parse(await response.text())
88
81
  const latest = typeof pkg?.version === 'string' ? pkg.version : ''
89
82
  if (latest !== '') updateCache = { at: now, latest }
90
83
  return { ok: true, current, latest, hasUpdate: latest !== '' && isNewer(latest, current) }
91
84
  } catch (error) {
92
- // Do not cache failures: the next click retries.
85
+ // Do not cache failures: the next check retries.
93
86
  return { ok: false, current, latest: '', hasUpdate: false, error: error instanceof Error ? error.message : String(error) }
94
87
  } finally {
95
88
  clearTimeout(timer)
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(-7)
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) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lls-a1/dsh-balance-float",
3
- "version": "1.1.52",
3
+ "version": "1.1.54",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },