dsh-token-receipt 1.1.0 → 1.2.0
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/CHANGELOG.md +16 -0
- package/README.ja.md +4 -0
- package/README.md +4 -0
- package/README.zh.md +4 -0
- package/client.js +103 -19
- package/index.js +8 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are documented in this file.
|
|
4
4
|
|
|
5
|
+
## 1.2.0
|
|
6
|
+
|
|
7
|
+
Released on 2026-11-17.
|
|
8
|
+
|
|
9
|
+
- Show the full receipt generation timestamp with year, month, day, hour, minute, and second.
|
|
10
|
+
- Remove the fixed `1 USD ≈ 6.67 CNY` exchange-rate note from CNY receipts.
|
|
11
|
+
- Increase receipt paper font sizes by 1–2px across headings, model rows, totals, metadata, and barcode text for better readability.
|
|
12
|
+
|
|
13
|
+
## 1.1.1
|
|
14
|
+
|
|
15
|
+
Released on 2026-11-17.
|
|
16
|
+
|
|
17
|
+
- Add a client/server version guard. The running panel now probes `/api/token-receipt?version=1` on startup, on window focus, and every 30 seconds; when the installed plugin is newer than the loaded browser bundle it shows a localized banner with a one-click **Reload UI** action instead of silently keeping old code.
|
|
18
|
+
- Document the DSH Desktop update behavior: after updating a plugin's browser bundle, fully quit and reopen DeepSeek Harness; closing the plugin panel or toggling the plugin does not reload `client.js`.
|
|
19
|
+
- Add a regression test that keeps the embedded client version in sync with `package.json`.
|
|
20
|
+
|
|
5
21
|
## 1.1.0
|
|
6
22
|
|
|
7
23
|
Released on 2026-11-17.
|
package/README.ja.md
CHANGED
|
@@ -63,6 +63,10 @@ dsh-token-receipt
|
|
|
63
63
|
|
|
64
64
|
DeepSeek Harness に `restart-required` と表示された場合は、アプリを一度再起動してください。
|
|
65
65
|
|
|
66
|
+
### DSH Desktop での更新
|
|
67
|
+
|
|
68
|
+
ブラウザ側の UI(`client.js`)を含む更新の後は、DeepSeek Harness を完全に終了してから再度開いてください。プラグインページを閉じる、プラグインを無効/有効にする、ウィンドウを閉じるだけでは不十分です。DSH Desktop はアプリウィンドウの起動時にのみブラウザ側のプラグインバンドルを読み込みます。アンインストールと再インストールは不要です。1.1.1 以降は、インストール済みバージョンが現在のページより新しいことを検出すると、**画面を更新** ボタン付きの通知を表示します。
|
|
69
|
+
|
|
66
70
|
## 使い方
|
|
67
71
|
|
|
68
72
|
DeepSeek Harness の言語設定で **日本語** を選択すると、日本語インターフェースに切り替わります。
|
package/README.md
CHANGED
|
@@ -63,6 +63,10 @@ Pass the local repository path to `plugin_manager`:
|
|
|
63
63
|
|
|
64
64
|
If DeepSeek Harness reports `restart-required`, restart the app once to activate the plugin.
|
|
65
65
|
|
|
66
|
+
### Updating on DSH Desktop
|
|
67
|
+
|
|
68
|
+
After an update that changes the plugin's browser UI (`client.js`), fully quit DeepSeek Harness and reopen it. Closing the plugin panel, toggling the plugin, or closing the window is not enough: DSH Desktop loads browser plugin bundles only when the app window starts. Uninstalling and reinstalling is not required. Version 1.1.1 and later show a **Reload UI** banner when they detect that the installed version is newer than the loaded page.
|
|
69
|
+
|
|
66
70
|
## Usage
|
|
67
71
|
|
|
68
72
|
1. Open **Token receipt** from the left sidebar.
|
package/README.zh.md
CHANGED
|
@@ -63,6 +63,10 @@ dsh-token-receipt
|
|
|
63
63
|
|
|
64
64
|
如果 DeepSeek Harness 提示 `restart-required`,重启一次应用即可启用插件。
|
|
65
65
|
|
|
66
|
+
### 在 DSH Desktop 上更新
|
|
67
|
+
|
|
68
|
+
如果更新包含浏览器端界面(`client.js`),请完全退出 DeepSeek Harness 后重新打开。仅关闭插件页面、禁用/启用插件或关闭窗口都不够:DSH Desktop 只会在应用窗口启动时加载浏览器端的插件 bundle。不需要卸载重装。1.1.1 及以后版本检测到「已安装版本比当前页面新」时,会显示带 **刷新界面** 按钮的提示。
|
|
69
|
+
|
|
66
70
|
## 使用
|
|
67
71
|
|
|
68
72
|
1. 在左侧边栏打开 **Token 账单**。
|
package/client.js
CHANGED
|
@@ -10,6 +10,8 @@ window.__ModuleLoader__.load({
|
|
|
10
10
|
const h = React.createElement
|
|
11
11
|
const NS = 'token-receipt'
|
|
12
12
|
const PANEL = 'token-receipt'
|
|
13
|
+
/** Kept in sync with package.json by tests/version-guard.test.js. */
|
|
14
|
+
const CLIENT_VERSION = '1.2.0'
|
|
13
15
|
const DAY_MS = 24 * 60 * 60 * 1000
|
|
14
16
|
const MIN_PROCESSING_MS = 850
|
|
15
17
|
const EXPORT_SCALE = 3
|
|
@@ -99,7 +101,6 @@ window.__ModuleLoader__.load({
|
|
|
99
101
|
partialPrice: '有 {n} 次请求未计价,金额为部分小计。',
|
|
100
102
|
unavailablePrice: '价格暂不可用,用量已保留。',
|
|
101
103
|
stalePrice: '使用上次获取的价格,稍后可重试。',
|
|
102
|
-
exchangeRate: '人民币按 1 USD ≈ 6.67 CNY 换算。',
|
|
103
104
|
unpriced: '未计价',
|
|
104
105
|
priceRetry: '重新获取价格',
|
|
105
106
|
fetchError: '读取用量失败',
|
|
@@ -110,6 +111,8 @@ window.__ModuleLoader__.load({
|
|
|
110
111
|
exportClosed: '导出完成前账单已关闭',
|
|
111
112
|
exportChanged: '保存过程中语言或币种已变更,请重试。',
|
|
112
113
|
exportFailed: '生成 PNG 失败',
|
|
114
|
+
updateAvailable: 'Token 账单已更新到 {version},当前界面仍是旧版。',
|
|
115
|
+
updateReload: '刷新界面',
|
|
113
116
|
},
|
|
114
117
|
en: {
|
|
115
118
|
nav: 'Token receipt',
|
|
@@ -173,7 +176,6 @@ window.__ModuleLoader__.load({
|
|
|
173
176
|
partialPrice: '{n} requests unpriced; subtotal excludes them.',
|
|
174
177
|
unavailablePrice: 'Prices unavailable. Usage is still recorded.',
|
|
175
178
|
stalePrice: 'Using previously fetched prices. Retry to refresh.',
|
|
176
|
-
exchangeRate: 'CNY converted at 1 USD ≈ 6.67 CNY.',
|
|
177
179
|
unpriced: 'Unpriced',
|
|
178
180
|
priceRetry: 'Retry prices',
|
|
179
181
|
fetchError: 'Could not read usage',
|
|
@@ -184,6 +186,8 @@ window.__ModuleLoader__.load({
|
|
|
184
186
|
exportClosed: 'Receipt was closed before export completed',
|
|
185
187
|
exportChanged: 'Receipt language or currency changed while saving. Please retry.',
|
|
186
188
|
exportFailed: 'Canvas export failed',
|
|
189
|
+
updateAvailable: 'Token receipt has been updated to {version}. This window is still showing the old version.',
|
|
190
|
+
updateReload: 'Reload UI',
|
|
187
191
|
},
|
|
188
192
|
ja: {
|
|
189
193
|
nav: "トークン明細",
|
|
@@ -247,7 +251,6 @@ window.__ModuleLoader__.load({
|
|
|
247
251
|
partialPrice: "{n} 件は料金未計算のため、小計に含まれません。",
|
|
248
252
|
unavailablePrice: "料金を取得できません。使用量は保持されています。",
|
|
249
253
|
stalePrice: "前回取得した料金を使用中です。後ほど再試行してください。",
|
|
250
|
-
exchangeRate: "人民元は 1 USD ≈ 6.67 CNY で換算。",
|
|
251
254
|
unpriced: "料金未計算",
|
|
252
255
|
priceRetry: "料金を再取得",
|
|
253
256
|
fetchError: "使用量を読み込めませんでした",
|
|
@@ -258,6 +261,8 @@ window.__ModuleLoader__.load({
|
|
|
258
261
|
exportClosed: "出力完了前に明細が閉じられました",
|
|
259
262
|
exportChanged: "保存中に言語または通貨が変更されました。もう一度お試しください。",
|
|
260
263
|
exportFailed: "PNG の書き出しに失敗しました",
|
|
264
|
+
updateAvailable: 'Token レシートは {version} に更新されました。この画面はまだ旧バージョンです。',
|
|
265
|
+
updateReload: '画面を更新',
|
|
261
266
|
},
|
|
262
267
|
}
|
|
263
268
|
|
|
@@ -463,39 +468,39 @@ body[data-ds-dark-theme] .tr-slot { border-color: var(--tr-g1); background: var(
|
|
|
463
468
|
100% { transform: translateY(0); }
|
|
464
469
|
}
|
|
465
470
|
|
|
466
|
-
.tr-paper { position: relative; z-index: 1; width: 100%; min-height: 20rem; padding: 28px 24px 32px; background-color: var(--tr-paper-bg); background-image: url("data:image/svg+xml;base64,${PAPER_TEXTURE}"); background-size: cover; background-blend-mode: soft-light; color: var(--tr-paper-ink); font-family: "TokenReceiptMono", "JetBrains Mono", "JetBrains Mono Fallback", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", ui-monospace, SFMono-Regular, Menlo, monospace; font-size:
|
|
471
|
+
.tr-paper { position: relative; z-index: 1; width: 100%; min-height: 20rem; padding: 28px 24px 32px; background-color: var(--tr-paper-bg); background-image: url("data:image/svg+xml;base64,${PAPER_TEXTURE}"); background-size: cover; background-blend-mode: soft-light; color: var(--tr-paper-ink); font-family: "TokenReceiptMono", "JetBrains Mono", "JetBrains Mono Fallback", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 18px; clip-path: polygon(0 0, 100% 0, 100% calc(100% - 4px), 98.75% 100%, 97.5% calc(100% - 4px), 96.25% 100%, 95% calc(100% - 4px), 93.75% 100%, 92.5% calc(100% - 4px), 91.25% 100%, 90% calc(100% - 4px), 88.75% 100%, 87.5% calc(100% - 4px), 86.25% 100%, 85% calc(100% - 4px), 83.75% 100%, 82.5% calc(100% - 4px), 81.25% 100%, 80% calc(100% - 4px), 78.75% 100%, 77.5% calc(100% - 4px), 76.25% 100%, 75% calc(100% - 4px), 73.75% 100%, 72.5% calc(100% - 4px), 71.25% 100%, 70% calc(100% - 4px), 68.75% 100%, 67.5% calc(100% - 4px), 66.25% 100%, 65% calc(100% - 4px), 63.75% 100%, 62.5% calc(100% - 4px), 61.25% 100%, 60% calc(100% - 4px), 58.75% 100%, 57.5% calc(100% - 4px), 56.25% 100%, 55% calc(100% - 4px), 53.75% 100%, 52.5% calc(100% - 4px), 51.25% 100%, 50% calc(100% - 4px), 48.75% 100%, 47.5% calc(100% - 4px), 46.25% 100%, 45% calc(100% - 4px), 43.75% 100%, 42.5% calc(100% - 4px), 41.25% 100%, 40% calc(100% - 4px), 38.75% 100%, 37.5% calc(100% - 4px), 36.25% 100%, 35% calc(100% - 4px), 33.75% 100%, 32.5% calc(100% - 4px), 31.25% 100%, 30% calc(100% - 4px), 28.75% 100%, 27.5% calc(100% - 4px), 26.25% 100%, 25% calc(100% - 4px), 23.75% 100%, 22.5% calc(100% - 4px), 21.25% 100%, 20% calc(100% - 4px), 18.75% 100%, 17.5% calc(100% - 4px), 16.25% 100%, 15% calc(100% - 4px), 13.75% 100%, 12.5% calc(100% - 4px), 11.25% 100%, 10% calc(100% - 4px), 8.75% 100%, 7.5% calc(100% - 4px), 6.25% 100%, 5% calc(100% - 4px), 3.75% 100%, 2.5% calc(100% - 4px), 1.25% 100%, 0% calc(100% - 4px)); }
|
|
467
472
|
.tr-page:lang(ja) { font-family: "TokenReceiptInter", Inter, "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, "Noto Sans JP", sans-serif; }
|
|
468
473
|
.tr-page:lang(ja) .tr-paper { font-family: "TokenReceiptMono", "JetBrains Mono", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, "Noto Sans JP", monospace; }
|
|
469
474
|
.tr-paper-head { text-align: center; }
|
|
470
475
|
.tr-paper-logo { display: block; width: 40px; height: 40px; margin: 0 auto; color: var(--tr-paper-ink); opacity: .9; }
|
|
471
|
-
.tr-paper-kicker { margin: 13px 0 0; font-size:
|
|
472
|
-
.tr-paper-date { margin: 4px 0 0; color: var(--tr-paper-ink); opacity: .55; font-size:
|
|
476
|
+
.tr-paper-kicker { margin: 13px 0 0; font-size: 11px; font-weight: 700; letter-spacing: .22em; text-transform: uppercase; }
|
|
477
|
+
.tr-paper-date { margin: 4px 0 0; color: var(--tr-paper-ink); opacity: .55; font-size: 11px; letter-spacing: .09em; text-transform: uppercase; }
|
|
473
478
|
.tr-rule { margin: 20px 0; border-top: 1px dashed color-mix(in oklab, var(--tr-paper-ink) 25%, transparent); }
|
|
474
479
|
.tr-rule.tight { margin: 16px 0; }
|
|
475
|
-
.tr-section-label { margin: 0 0 7px; color: var(--tr-paper-ink); opacity: .55; font-size:
|
|
480
|
+
.tr-section-label { margin: 0 0 7px; color: var(--tr-paper-ink); opacity: .55; font-size: 11px; font-weight: 700; letter-spacing: .72px; text-transform: uppercase; }
|
|
476
481
|
.tr-items { display: flex; flex-direction: column; gap: 9px; }
|
|
477
482
|
.tr-item-block { min-width: 0; }
|
|
478
|
-
.tr-item-detail { margin: 0; font-size:
|
|
483
|
+
.tr-item-detail { margin: 0; font-size: 11px; line-height: 17px; opacity: .55; }
|
|
479
484
|
.tr-price-notes { margin-top: 12px; }
|
|
480
|
-
.tr-price-notes p { margin: 0; font-size:
|
|
481
|
-
.tr-item { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; font-size:
|
|
485
|
+
.tr-price-notes p { margin: 0; font-size: 9px; line-height: 13px; opacity: .55; overflow-wrap: anywhere; }
|
|
486
|
+
.tr-item { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; font-size: 11px; line-height: 17px; }
|
|
482
487
|
.tr-item-name { min-width: 0; flex: 1; letter-spacing: .08em; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
|
|
483
488
|
.tr-item-value { flex: none; font-variant-numeric: tabular-nums; font-weight: 700; }
|
|
484
|
-
.tr-empty { padding: 6px 0; text-align: center; color: var(--tr-paper-ink); opacity: .55; font-size:
|
|
489
|
+
.tr-empty { padding: 6px 0; text-align: center; color: var(--tr-paper-ink); opacity: .55; font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
|
|
485
490
|
.tr-summary { display: flex; flex-direction: column; gap: 6px; margin: 0; }
|
|
486
|
-
.tr-summary-row { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; font-size:
|
|
491
|
+
.tr-summary-row { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; font-size: 11px; line-height: 11px; }
|
|
487
492
|
.tr-summary-row dt { margin: 0; color: var(--tr-paper-ink); opacity: .55; }
|
|
488
493
|
.tr-summary-row dd { margin: 0; font-variant-numeric: tabular-nums; }
|
|
489
494
|
.tr-total { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding-top: 8px; }
|
|
490
|
-
.tr-total dt { margin: 0; font-size:
|
|
491
|
-
.tr-total dd { margin: 0; white-space: nowrap; font-size:
|
|
492
|
-
.tr-meta { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 4px 16px; font-size:
|
|
495
|
+
.tr-total dt { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; }
|
|
496
|
+
.tr-total dd { margin: 0; white-space: nowrap; font-size: 17px; font-weight: 700; line-height: 17px; letter-spacing: -.6px; font-variant-numeric: tabular-nums; }
|
|
497
|
+
.tr-meta { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 4px 16px; font-size: 9px; line-height: 12px; }
|
|
493
498
|
.tr-meta dt { margin: 0; color: var(--tr-paper-ink); opacity: .55; }
|
|
494
499
|
.tr-meta dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
|
|
495
500
|
.tr-barcodewrap { margin-top: 14px; text-align: center; }
|
|
496
501
|
.tr-barcode { width: 128px; height: 28px; margin: 0 auto; background-image: repeating-linear-gradient(90deg, currentColor 0 1px, transparent 1px 3px, currentColor 3px 5px, transparent 5px 7px, currentColor 7px 8px, transparent 8px 11px); opacity: .85; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
|
|
497
|
-
.tr-barcode-label { margin: 4px 0 0; color: var(--tr-paper-ink); opacity: .5; font-size:
|
|
498
|
-
.tr-thanks { margin: 8px 0 0; text-align: center; color: var(--tr-paper-ink); opacity: .5; font-size:
|
|
502
|
+
.tr-barcode-label { margin: 4px 0 0; color: var(--tr-paper-ink); opacity: .5; font-size: 9px; line-height: 12px; letter-spacing: 1.26px; text-transform: uppercase; }
|
|
503
|
+
.tr-thanks { margin: 8px 0 0; text-align: center; color: var(--tr-paper-ink); opacity: .5; font-size: 9px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; }
|
|
499
504
|
|
|
500
505
|
.tr-error { width: 100%; max-width: 540px; margin: 14px auto 0; padding: 13px 16px; border: 1px solid color-mix(in srgb, #e5484d 34%, var(--tr-g3)); border-radius: 10px; background: color-mix(in srgb, #e5484d 7%, var(--tr-g2)); color: var(--tr-page-ink); font-size: 12.5px; line-height: 1.5; text-align: center; }
|
|
501
506
|
.tr-sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }
|
|
@@ -684,6 +689,78 @@ body[data-ds-dark-theme] .tr-slot { border-color: var(--tr-g1); background: var(
|
|
|
684
689
|
return out
|
|
685
690
|
}
|
|
686
691
|
|
|
692
|
+
/**
|
|
693
|
+
* Watch the Host's package version while this page keeps running. DSH Desktop
|
|
694
|
+
* does not refresh an installed plugin's browser bundle in place, so when the
|
|
695
|
+
* Host has been updated this banner offers the page reload that activates it.
|
|
696
|
+
*/
|
|
697
|
+
function installUpdateGuard(ctx) {
|
|
698
|
+
if (
|
|
699
|
+
typeof window === 'undefined' ||
|
|
700
|
+
typeof document === 'undefined' ||
|
|
701
|
+
typeof window.addEventListener !== 'function' ||
|
|
702
|
+
typeof window.removeEventListener !== 'function' ||
|
|
703
|
+
typeof document.createElement !== 'function' ||
|
|
704
|
+
!document.body
|
|
705
|
+
) return undefined
|
|
706
|
+
let banner = null
|
|
707
|
+
let checking = false
|
|
708
|
+
let timer = null
|
|
709
|
+
const copy = translatedCopy(ctx)
|
|
710
|
+
const showBanner = (version) => {
|
|
711
|
+
if (banner !== null && String(banner.dataset.version) === version) return
|
|
712
|
+
const text = String(copy.updateAvailable || 'Token receipt has been updated to {version}.').replace('{version}', version)
|
|
713
|
+
if (banner === null) {
|
|
714
|
+
banner = document.createElement('div')
|
|
715
|
+
banner.id = 'dsh-token-receipt-update'
|
|
716
|
+
banner.setAttribute('role', 'status')
|
|
717
|
+
banner.setAttribute('data-token-receipt-update', '')
|
|
718
|
+
banner.style.cssText = 'position:fixed;z-index:2147483647;left:50%;bottom:20px;transform:translateX(-50%);display:flex;align-items:center;gap:12px;max-width:min(560px,calc(100vw - 32px));box-sizing:border-box;padding:10px 14px;border-radius:10px;border:1px solid var(--dsw-alias-border-l2,#3a3a3a);background:var(--dsw-alias-bg-layer-1,#1f1f1f);color:var(--dsw-alias-label-primary,#fff);box-shadow:0 8px 24px rgba(0,0,0,.28);font:500 13px/1.45 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif'
|
|
719
|
+
const message = document.createElement('span')
|
|
720
|
+
message.setAttribute('data-token-receipt-update-message', '')
|
|
721
|
+
const button = document.createElement('button')
|
|
722
|
+
button.type = 'button'
|
|
723
|
+
button.setAttribute('data-token-receipt-update-reload', '')
|
|
724
|
+
button.style.cssText = 'flex:none;border:0;border-radius:7px;padding:5px 10px;background:var(--dsw-alias-label-primary,#fff);color:var(--dsw-alias-bg-layer-1,#1f1f1f);font:600 12px/1.3 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;cursor:pointer'
|
|
725
|
+
button.textContent = copy.updateReload || 'Reload UI'
|
|
726
|
+
button.addEventListener('click', () => window.location.reload())
|
|
727
|
+
banner.appendChild(message)
|
|
728
|
+
banner.appendChild(button)
|
|
729
|
+
document.body.appendChild(banner)
|
|
730
|
+
}
|
|
731
|
+
const message = banner.querySelector('[data-token-receipt-update-message]')
|
|
732
|
+
if (message !== null) message.textContent = text
|
|
733
|
+
banner.dataset.version = version
|
|
734
|
+
}
|
|
735
|
+
const check = async () => {
|
|
736
|
+
if (checking) return
|
|
737
|
+
checking = true
|
|
738
|
+
try {
|
|
739
|
+
const response = await fetch('/api/token-receipt?version=1', { cache: 'no-store', headers: { accept: 'application/json' } })
|
|
740
|
+
if (!response.ok) return
|
|
741
|
+
const payload = await response.json().catch(() => null)
|
|
742
|
+
const version = payload && payload.ok === true && typeof payload.version === 'string' ? payload.version : null
|
|
743
|
+
if (version !== null && version !== CLIENT_VERSION) showBanner(version)
|
|
744
|
+
} catch {
|
|
745
|
+
// A stale page must not throw because the host is restarting or the probe is unavailable.
|
|
746
|
+
} finally {
|
|
747
|
+
checking = false
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
const onFocus = () => { void check() }
|
|
751
|
+
const onVisibility = () => { if (document.visibilityState === 'visible') void check() }
|
|
752
|
+
timer = window.setInterval(check, 30000)
|
|
753
|
+
window.addEventListener('focus', onFocus)
|
|
754
|
+
document.addEventListener('visibilitychange', onVisibility)
|
|
755
|
+
void check()
|
|
756
|
+
return () => {
|
|
757
|
+
if (timer !== null) window.clearInterval(timer)
|
|
758
|
+
window.removeEventListener('focus', onFocus)
|
|
759
|
+
document.removeEventListener('visibilitychange', onVisibility)
|
|
760
|
+
if (banner !== null) { banner.remove(); banner = null }
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
687
764
|
function pad(n) {
|
|
688
765
|
return String(n).padStart(2, '0')
|
|
689
766
|
}
|
|
@@ -803,6 +880,13 @@ body[data-ds-dark-theme] .tr-slot { border-color: var(--tr-g1); background: var(
|
|
|
803
880
|
return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })
|
|
804
881
|
}
|
|
805
882
|
|
|
883
|
+
function dateTime(date, locale) {
|
|
884
|
+
const lang = normalizeLocale(locale)
|
|
885
|
+
const time = `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
|
|
886
|
+
if (lang === 'zh' || lang === 'ja') return `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日 ${time}`
|
|
887
|
+
return `${date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })} ${time}`
|
|
888
|
+
}
|
|
889
|
+
|
|
806
890
|
function shortDate(date, locale) {
|
|
807
891
|
const lang = normalizeLocale(locale)
|
|
808
892
|
if (lang === 'zh' || lang === 'ja') return `${date.getMonth() + 1}月${date.getDate()}日`
|
|
@@ -1004,7 +1088,7 @@ body[data-ds-dark-theme] .tr-slot { border-color: var(--tr-g1); background: var(
|
|
|
1004
1088
|
const rangeEnd = new Date(data.to)
|
|
1005
1089
|
const displayStart = resolveDisplayStart(period, rangeStart, data)
|
|
1006
1090
|
const issued = new Date(data.generatedAt)
|
|
1007
|
-
const issuedText = Number.isNaN(issued.getTime()) ? '—' :
|
|
1091
|
+
const issuedText = Number.isNaN(issued.getTime()) ? '—' : dateTime(issued, lang)
|
|
1008
1092
|
const billNo = billNumber(period, data.date, totals.totalTokens, totals.requests)
|
|
1009
1093
|
const partial = pricing?.status === 'partial'
|
|
1010
1094
|
const hasPrice = typeof pricing?.totalUsd === 'number' && Number.isFinite(pricing.totalUsd)
|
|
@@ -1012,7 +1096,6 @@ body[data-ds-dark-theme] .tr-slot { border-color: var(--tr-g1); background: var(
|
|
|
1012
1096
|
if (!hasPrice) notes.push(copy.unavailablePrice)
|
|
1013
1097
|
else if (partial) notes.push(copy.partialPrice.replace('{n}', pricing.unpricedRequests))
|
|
1014
1098
|
if (pricing?.stale) notes.push(copy.stalePrice)
|
|
1015
|
-
if (currency === 'cny') notes.push(copy.exchangeRate)
|
|
1016
1099
|
if (currency === 'jpy') notes.push(copy.exchangeRateJpy.replace('{rate}', DISPLAY_RATES.jpy).replace('{date}', JPY_RATE_DATE))
|
|
1017
1100
|
const modelRow = (model) => h(
|
|
1018
1101
|
'div',
|
|
@@ -1770,6 +1853,7 @@ body[data-ds-dark-theme] .tr-slot { border-color: var(--tr-g1); background: var(
|
|
|
1770
1853
|
}
|
|
1771
1854
|
|
|
1772
1855
|
function apply(ctx) {
|
|
1856
|
+
ctx.effect(() => installUpdateGuard(ctx), 'token-receipt: update guard')
|
|
1773
1857
|
ctx.effect(() => {
|
|
1774
1858
|
if (typeof document === 'undefined' || !document.head || typeof document.createElement !== 'function') return
|
|
1775
1859
|
const existing = typeof document.getElementById === 'function' ? document.getElementById('dsh-token-receipt-fonts') : null
|
package/index.js
CHANGED
|
@@ -6,10 +6,12 @@
|
|
|
6
6
|
* half renders the receipt printer; only the public model price catalogue is fetched.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { statSync } from 'node:fs'
|
|
9
|
+
import { readFileSync, statSync } from 'node:fs'
|
|
10
10
|
import { createPricingCatalog, createPricingAccumulator } from './pricing.js'
|
|
11
11
|
|
|
12
12
|
const ROUTE = '/api/token-receipt'
|
|
13
|
+
/** The installed package version, served to the browser half for update detection. */
|
|
14
|
+
export const PACKAGE_VERSION = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')).version
|
|
13
15
|
const DAY_MS = 24 * 60 * 60 * 1000
|
|
14
16
|
const MAX_TS = 8_640_000_000_000_000
|
|
15
17
|
const CACHE_TTL_MS = 10_000
|
|
@@ -444,6 +446,11 @@ export function createReceiptService(ctx, options = {}) {
|
|
|
444
446
|
} catch {
|
|
445
447
|
return sendJson(res, 400, { ok: false, error: 'Invalid request.' }, headOnly)
|
|
446
448
|
}
|
|
449
|
+
// A tiny, cache-free probe used by the browser half to notice a package update
|
|
450
|
+
// while the WebView still holds an older client bundle.
|
|
451
|
+
if (url.searchParams.get('version') === '1') {
|
|
452
|
+
return sendJson(res, 200, { ok: true, version: PACKAGE_VERSION }, headOnly)
|
|
453
|
+
}
|
|
447
454
|
const requestedPeriod = url.searchParams.get('period')
|
|
448
455
|
const period = VALID_PERIODS.has(requestedPeriod) ? requestedPeriod : 'day'
|
|
449
456
|
const defaultBounds = defaultPeriodBounds(period, new Date(now()))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-token-receipt",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Print daily, weekly, monthly, 30-day, 90-day, or all-time token usage and estimated model costs as a tactile receipt, with clipboard copy and PNG export.",
|
|
6
6
|
"type": "module",
|