dsh-token-receipt 1.1.0 → 1.1.1

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 CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  All notable changes to this project are documented in this file.
4
4
 
5
+ ## 1.1.1
6
+
7
+ Released on 2026-11-17.
8
+
9
+ - 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.
10
+ - 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`.
11
+ - Add a regression test that keeps the embedded client version in sync with `package.json`.
12
+
5
13
  ## 1.1.0
6
14
 
7
15
  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.1.1'
13
15
  const DAY_MS = 24 * 60 * 60 * 1000
14
16
  const MIN_PROCESSING_MS = 850
15
17
  const EXPORT_SCALE = 3
@@ -110,6 +112,8 @@ window.__ModuleLoader__.load({
110
112
  exportClosed: '导出完成前账单已关闭',
111
113
  exportChanged: '保存过程中语言或币种已变更,请重试。',
112
114
  exportFailed: '生成 PNG 失败',
115
+ updateAvailable: 'Token 账单已更新到 {version},当前界面仍是旧版。',
116
+ updateReload: '刷新界面',
113
117
  },
114
118
  en: {
115
119
  nav: 'Token receipt',
@@ -184,6 +188,8 @@ window.__ModuleLoader__.load({
184
188
  exportClosed: 'Receipt was closed before export completed',
185
189
  exportChanged: 'Receipt language or currency changed while saving. Please retry.',
186
190
  exportFailed: 'Canvas export failed',
191
+ updateAvailable: 'Token receipt has been updated to {version}. This window is still showing the old version.',
192
+ updateReload: 'Reload UI',
187
193
  },
188
194
  ja: {
189
195
  nav: "トークン明細",
@@ -258,6 +264,8 @@ window.__ModuleLoader__.load({
258
264
  exportClosed: "出力完了前に明細が閉じられました",
259
265
  exportChanged: "保存中に言語または通貨が変更されました。もう一度お試しください。",
260
266
  exportFailed: "PNG の書き出しに失敗しました",
267
+ updateAvailable: 'Token レシートは {version} に更新されました。この画面はまだ旧バージョンです。',
268
+ updateReload: '画面を更新',
261
269
  },
262
270
  }
263
271
 
@@ -684,6 +692,78 @@ body[data-ds-dark-theme] .tr-slot { border-color: var(--tr-g1); background: var(
684
692
  return out
685
693
  }
686
694
 
695
+ /**
696
+ * Watch the Host's package version while this page keeps running. DSH Desktop
697
+ * does not refresh an installed plugin's browser bundle in place, so when the
698
+ * Host has been updated this banner offers the page reload that activates it.
699
+ */
700
+ function installUpdateGuard(ctx) {
701
+ if (
702
+ typeof window === 'undefined' ||
703
+ typeof document === 'undefined' ||
704
+ typeof window.addEventListener !== 'function' ||
705
+ typeof window.removeEventListener !== 'function' ||
706
+ typeof document.createElement !== 'function' ||
707
+ !document.body
708
+ ) return undefined
709
+ let banner = null
710
+ let checking = false
711
+ let timer = null
712
+ const copy = translatedCopy(ctx)
713
+ const showBanner = (version) => {
714
+ if (banner !== null && String(banner.dataset.version) === version) return
715
+ const text = String(copy.updateAvailable || 'Token receipt has been updated to {version}.').replace('{version}', version)
716
+ if (banner === null) {
717
+ banner = document.createElement('div')
718
+ banner.id = 'dsh-token-receipt-update'
719
+ banner.setAttribute('role', 'status')
720
+ banner.setAttribute('data-token-receipt-update', '')
721
+ 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'
722
+ const message = document.createElement('span')
723
+ message.setAttribute('data-token-receipt-update-message', '')
724
+ const button = document.createElement('button')
725
+ button.type = 'button'
726
+ button.setAttribute('data-token-receipt-update-reload', '')
727
+ 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'
728
+ button.textContent = copy.updateReload || 'Reload UI'
729
+ button.addEventListener('click', () => window.location.reload())
730
+ banner.appendChild(message)
731
+ banner.appendChild(button)
732
+ document.body.appendChild(banner)
733
+ }
734
+ const message = banner.querySelector('[data-token-receipt-update-message]')
735
+ if (message !== null) message.textContent = text
736
+ banner.dataset.version = version
737
+ }
738
+ const check = async () => {
739
+ if (checking) return
740
+ checking = true
741
+ try {
742
+ const response = await fetch('/api/token-receipt?version=1', { cache: 'no-store', headers: { accept: 'application/json' } })
743
+ if (!response.ok) return
744
+ const payload = await response.json().catch(() => null)
745
+ const version = payload && payload.ok === true && typeof payload.version === 'string' ? payload.version : null
746
+ if (version !== null && version !== CLIENT_VERSION) showBanner(version)
747
+ } catch {
748
+ // A stale page must not throw because the host is restarting or the probe is unavailable.
749
+ } finally {
750
+ checking = false
751
+ }
752
+ }
753
+ const onFocus = () => { void check() }
754
+ const onVisibility = () => { if (document.visibilityState === 'visible') void check() }
755
+ timer = window.setInterval(check, 30000)
756
+ window.addEventListener('focus', onFocus)
757
+ document.addEventListener('visibilitychange', onVisibility)
758
+ void check()
759
+ return () => {
760
+ if (timer !== null) window.clearInterval(timer)
761
+ window.removeEventListener('focus', onFocus)
762
+ document.removeEventListener('visibilitychange', onVisibility)
763
+ if (banner !== null) { banner.remove(); banner = null }
764
+ }
765
+ }
766
+
687
767
  function pad(n) {
688
768
  return String(n).padStart(2, '0')
689
769
  }
@@ -1770,6 +1850,7 @@ body[data-ds-dark-theme] .tr-slot { border-color: var(--tr-g1); background: var(
1770
1850
  }
1771
1851
 
1772
1852
  function apply(ctx) {
1853
+ ctx.effect(() => installUpdateGuard(ctx), 'token-receipt: update guard')
1773
1854
  ctx.effect(() => {
1774
1855
  if (typeof document === 'undefined' || !document.head || typeof document.createElement !== 'function') return
1775
1856
  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.1.0",
3
+ "version": "1.1.1",
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",