dsh-continue-cost 1.2.0 → 1.3.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/README.md CHANGED
@@ -14,6 +14,31 @@
14
14
 
15
15
  差额是纯增量信息,和已有的费用统计插件共存不冲突。
16
16
 
17
+ ## 先统一口径:这两个数字是「下一轮」,不是「总共」
18
+
19
+ 最常见的误解是把它读成“每轮都要多花这么多钱,所以很贵”。准确的说法是:
20
+
21
+ | 做法 | 历史消息 | 这笔钱付几次 |
22
+ |---|---|---|
23
+ | **继续当前对话** | 全部带上 | **每一轮都付一次**,历史越长越贵 |
24
+ | **新开对话(同一轮上下文)** | 不带 | 不用再付;新对话从“系统提示 + 工具 + 这一轮”的底价重新开始 |
25
+
26
+ 所以胶囊上的差额 = **续聊比新开,下一轮(以及之后每一轮)为历史多付的钱**:
27
+
28
+ ```text
29
+ 胶囊金额 ≈ 历史上下文 token × 平均 token 单价
30
+ ```
31
+
32
+ 它不是一次性的“切换成本”,而是**待在这条对话里的每轮门票**:只要还在这条对话里发消息,每轮都要再交一次。
33
+
34
+ 三点补充,免得把估算当账单:
35
+
36
+ 1. 面板里的两行是**同一轮对话**在两种做法下的**输入**费;回答本身的费用两边一样,因此既不计入,也不影响差额。
37
+ 2. 续聊的历史绝大多数命中缓存,命中价比未命中便宜一个数量级,再叠上谷时半价,真实差价常常只有几厘钱(示例:6 万 token、97% 命中、谷时 `deepseek-flash` ≈ ¥0.0014)。峰时或缓存命中率下降时会明显变大。
38
+ 3. 全部按“历史 token × 本会话平均单价”估算,实际以账户扣费为准。
39
+
40
+ 结论:把胶囊当成“留在这条对话里的每轮成本”。超过你觉得值的阈值(默认 ¥0.05 黄 / ¥0.15 红)就写个交接摘要、新开对话;没超过就继续聊,更省事。
41
+
17
42
  ## 两个数字到底是什么
18
43
 
19
44
  胶囊显示二选一,点开面板顶部可以切换。
@@ -46,11 +71,29 @@
46
71
  - 已完成轮数、差额(继续 − 新开)
47
72
  - 继续当前对话(下一轮上下文)费用、新开对话(同一轮上下文)费用
48
73
  - 历史上下文、下一轮上下文预计、本会话平均 token 单价、计价模型(含峰/谷标注)
74
+ - **当前时段:峰时 / 谷时 + 计算所用的北京时间**,下面一行写明官方峰谷规则
49
75
  - 价格表来源、节假日表来源(官方在线 / 本地缓存 / 内置)
50
76
 
51
77
  点击胶囊固定面板:顶部切换「对话轮数 / 多花金额」,下方设置绿色上限、黄色上限;「恢复默认」回到 5 / 10 轮、¥0.05 / ¥0.15。阈值存在 `localStorage`。
52
78
 
53
- 圆点在数值前面,按当前显示值着色:不超过绿色上限为绿,不超过黄色上限为黄,超过为红。每 30 秒重算一次,跨过峰谷边界会自动变色。
79
+ 圆点在数值前面,按当前显示值着色:不超过绿色上限为绿,不超过黄色上限为黄,超过为红。峰谷切换不再依赖“正好赶上一次轮询”:跨过 09:00 / 12:00 / 14:00 / 18:00 或零点时会立即重算,最多 30 秒兜底;窗口从睡眠、最小化或后台恢复时也会马上重算。
80
+
81
+ ## 峰谷自动切换
82
+
83
+ 官方口径(价格页原文):**北京时间周一至周五(不含中国法定节假日)09:00–12:00、14:00–18:00 为高峰时段,其余时段——包括 12:00–14:00 午间、周末和法定节假日全天——都是空闲时段**;空闲时段价格是高峰时段的一半。
84
+
85
+ 插件按这个规则自动切换:
86
+
87
+ | 时间(北京时间) | 时段 | 胶囊上的标记 |
88
+ |---|---|---|
89
+ | 周一至周五 09:00–12:00、14:00–18:00 | 峰时(价格 ×2) | 峰 |
90
+ | 周一至周五 12:00–14:00 | 谷时 | 谷 |
91
+ | 周末、调休上班周末、法定节假日全天 | 谷时 | 谷 |
92
+
93
+ - **胶囊上直接标「峰/谷」**,不用悬停也能看出当前按哪档计价。
94
+ - 面板「当前时段」一行同时给出北京时间(如 `峰时 · 北京时间 14:23`),方便核对是不是时钟/时区问题。
95
+ - 切换是精确到边界的:09:00、12:00、14:00、18:00 和零点都会重算;`focus` / `visibilitychange` / `pageshow` 也会触发一次,所以睡眠唤醒、最小化恢复后不会沿用旧价。
96
+ - 判断用的是「当前时刻换算成 UTC+8 后读时钟」,与浏览器/系统时区无关;系统时间本身错了才会算错。
54
97
 
55
98
  ## 估算口径
56
99
 
@@ -65,9 +108,9 @@
65
108
 
66
109
  - 平均 token 单价按本会话累计 `tokenUsage` 的缓存命中/未命中比例,套用当前时段官方单价。
67
110
  - 回答本身在两种做法下费用相同,不计入差额;只比较输入侧。
68
- - 峰时:北京时间周一至周五(不含法定节假日)09:00–12:00、14:00–18:00;其余时段、周末、调休上班周末、法定节假日全天为谷时。
111
+ - 峰时:北京时间周一至周五(不含法定节假日)09:00–12:00、14:00–18:00;其余时段、周末、调休上班周末、法定节假日全天为谷时(见上一节)。
69
112
  - 下一轮上下文取 `contextPressure.projectedTokens`(缺失时退回 `pressureTokens`),历史消息占比取 `contextBreakdown`;两者都没有时显示「上下文数据还没准备好」,而不是硬猜。
70
- - 每 30 秒重算一次,跨过峰谷边界会自动更新。
113
+ - 跨过峰谷边界会在半秒内自动更新,另有 30 秒轮询兜底。
71
114
 
72
115
  ## 安装
73
116
 
@@ -75,13 +118,13 @@
75
118
 
76
119
  **1. 本地文件夹(推荐给朋友之间分享)**
77
120
 
78
- 1. 下载 `dsh-continue-cost-1.2.0.zip` 并解压,得到 `dsh-continue-cost` 文件夹,放到固定位置。
121
+ 1. 下载 `dsh-continue-cost-1.3.1.zip` 并解压,得到 `dsh-continue-cost` 文件夹,放到固定位置。
79
122
  2. DSH:**设置 → 插件 → 添加插件**,选择这个包含 `package.json` 的文件夹。
80
123
  3. **完全退出 DSH 再打开**(Host 端的价格/节假日路由要重启才挂载)。
81
124
 
82
125
  **2. npm(发布后可用)**
83
126
 
84
- 在 DSH 里用插件管理器安装:`plugin_manager` 的 `install_bundle`,target 填 `dsh-continue-cost@1.2.0`;如果这台 DSH 自带 `dsh` 命令,也可以 `dsh plugin add dsh-continue-cost`(profile 名按你的安装,桌面版一般是 `desktop`)。
127
+ 在 DSH 里用插件管理器安装:`plugin_manager` 的 `install_bundle`,target 填 `dsh-continue-cost@1.3.1`;如果这台 DSH 自带 `dsh` 命令,也可以 `dsh plugin add dsh-continue-cost`(profile 名按你的安装,桌面版一般是 `desktop`)。
85
128
 
86
129
  **3. GitHub Release**:从 Releases 下载 zip,按方式 1 安装。
87
130
 
@@ -113,18 +156,21 @@
113
156
  - 中途切换模型时累计用量按当前模型价格折算。
114
157
  - 节假日解析依赖 gov.cn 通知的固定文本结构;结构变化时回退缓存/内置。
115
158
  - 已内置 2026 年表;2027 年表来自官方通知;更久远年份依赖自动发现。
159
+ - 峰谷按系统时钟换算成北京时间;系统时间本身错误时判断也会错,面板「当前时段」会显示所用的北京时间,便于核对。
116
160
 
117
161
  ## 开发
118
162
 
119
163
  - `client.js` 是浏览器端(module factory,无构建),`host-1.2.0.js` 是 Host 端。
120
164
  - DSH 会缓存 Host 模块:改 Host 时复制成新版本文件(如 `host-1.3.0.js`),改 `package.json` 的 `main`/`exports`/`files`,重启 DSH。
121
165
  - 改包名时要同步:`client.js` 的 `NAME`/`NS` 与两个路由常量、`host-1.2.0.js` 的 `BASE_PATH`、`cordis.patch.yml` 的 `id`/`name`。
122
- - 自检:`node --check client.js`、`node -e "import('./host-1.2.0.js')"`、重启后两个路由返回 `ok:true`。
166
+ - 自检:`npm test`(12 个用例:峰谷边界、周末/节假日、跨边界自动切换、唤醒重算、alias 解析、Host 解析器)、`node --check client.js`、`node -e "import('./host-1.2.0.js')"`、重启后两个路由返回 `ok:true`。
123
167
 
124
168
  ## English
125
169
 
126
170
  **dsh-continue-cost** is a DeepSeek Harness plugin that shows the completed turn count and, more importantly, the extra context cost of **continuing this conversation instead of starting a fresh one** — priced from the official peak/off-peak CNY table and the session's cache-hit mix. Most cost plugins report money already spent; this one helps you decide whether to start over. Badge thresholds (green/yellow/red) apply to turns or to the delta.
127
171
 
172
+ The chip carries a small **peak / off** badge that flips by itself at the official boundaries (09:00 / 12:00 / 14:00 / 18:00 Beijing on weekdays, and midnight for weekends and statutory holidays), and refreshes immediately when the window is restored after sleep or minimisation. The panel spells out the tariff in force together with the Beijing time it was derived from.
173
+
128
174
  Install: unzip into a folder and add it from **Settings → Plugins → Add plugin**, then fully restart DSH.
129
175
 
130
176
  ## License
package/client.js CHANGED
@@ -264,6 +264,9 @@
264
264
  'panel.holidayCache': '本地缓存',
265
265
  'panel.holidayBuiltin': '内置',
266
266
  'panel.perMillion': '/ 百万 tokens',
267
+ 'panel.tariff': '当前时段',
268
+ 'panel.tariffRule': '工作日北京时间 9:00–12:00、14:00–18:00 为峰时;午间、周末与法定节假日全天为谷时。跨过边界后这里与胶囊上的「峰/谷」会自动切换。',
269
+ 'panel.beijingTime': '北京时间',
267
270
  'panel.noPrice': '未收录该模型价格',
268
271
  'panel.noContext': '上下文数据还没准备好,暂时无法估算历史占比。',
269
272
  'panel.waiting': '还没有可用的 token 用量,先按未命中缓存的单价估算。',
@@ -278,6 +281,8 @@
278
281
  'tone.idle': '等待数据',
279
282
  'tariff.peak': '峰时',
280
283
  'tariff.off': '谷时',
284
+ 'tariff.peakShort': '峰',
285
+ 'tariff.offShort': '谷',
281
286
  'settings.title': '阈值设置',
282
287
  'settings.turns': '对话轮数',
283
288
  'settings.cost': '多花金额',
@@ -318,6 +323,9 @@
318
323
  'panel.holidayCache': 'Local cache',
319
324
  'panel.holidayBuiltin': 'Built-in',
320
325
  'panel.perMillion': '/ 1M tokens',
326
+ 'panel.tariff': 'Current tariff',
327
+ 'panel.tariffRule': 'Peak is 09:00–12:00 and 14:00–18:00 Beijing weekdays; the midday break, weekends and public holidays are off-peak. The chip badge and this row follow the clock automatically.',
328
+ 'panel.beijingTime': 'Beijing',
321
329
  'panel.noPrice': 'No listed price for this model',
322
330
  'panel.noContext': 'Context data is not ready yet; the history share is unknown for now.',
323
331
  'panel.waiting': 'No token usage yet; pricing the history at the cache-miss rate.',
@@ -332,6 +340,8 @@
332
340
  'tone.idle': 'waiting for data',
333
341
  'tariff.peak': 'peak',
334
342
  'tariff.off': 'off-peak',
343
+ 'tariff.peakShort': 'peak',
344
+ 'tariff.offShort': 'off',
335
345
  'settings.title': 'Thresholds',
336
346
  'settings.turns': 'Turns',
337
347
  'settings.cost': 'Extra cost',
@@ -405,6 +415,8 @@
405
415
  const fullKey = raw.toLowerCase()
406
416
  const id = PRICING[bareKey] === undefined ? fullKey : bareKey
407
417
  const alias = PRICING_ALIASES[id]
418
+ ?? PRICING_ALIASES[bareKey]
419
+ ?? PRICING_ALIASES[fullKey]
408
420
  return PRICING[id] ?? (alias === undefined ? undefined : PRICING[alias])
409
421
  }
410
422
 
@@ -416,6 +428,53 @@
416
428
  return slash === -1 ? raw : raw.slice(slash + 1)
417
429
  }
418
430
 
431
+ /**
432
+ * Peak windows as Beijing wall-clock `[start, end)` hour pairs, straight from
433
+ * the official pricing page: "北京时间周一至周五(不含中国法定节假日)
434
+ * 9:00 - 12:00、14:00 - 18:00 为高峰时段". Everything else — including the
435
+ * 12:00-14:00 midday break, weekends and statutory holidays — is off-peak.
436
+ */
437
+ const PEAK_WINDOWS = [
438
+ [9, 12],
439
+ [14, 18],
440
+ ]
441
+
442
+ /** Hours at which the tariff can change: window edges plus midnight. */
443
+ const TARIFF_BOUNDARY_HOURS = [0, ...PEAK_WINDOWS.flat()]
444
+
445
+ /** How far ahead the boundary search looks (a weekend plus a holiday run). */
446
+ const BOUNDARY_LOOKAHEAD_DAYS = 12
447
+
448
+ /**
449
+ * Read an instant as Beijing wall-clock fields. Shifting the epoch by eight
450
+ * hours and reading the UTC fields makes the answer independent of the
451
+ * browser's own time zone.
452
+ * @param now - instant to read.
453
+ * @returns `{ day, hour, minute, timeKey, dateKey }` in Beijing time.
454
+ */
455
+ function beijingClock(now = new Date()) {
456
+ const shifted = new Date(now.getTime() + 8 * 60 * 60 * 1000)
457
+ const hour = shifted.getUTCHours()
458
+ const minute = shifted.getUTCMinutes()
459
+ return {
460
+ day: shifted.getUTCDay(),
461
+ hour,
462
+ minute,
463
+ dateKey: shifted.toISOString().slice(0, 10),
464
+ timeKey: `${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}`,
465
+ }
466
+ }
467
+
468
+ /**
469
+ * @param clock - Beijing wall-clock fields from {@link beijingClock}.
470
+ * @returns true when the provider charges the peak tariff then.
471
+ */
472
+ function isPeakAtClock(clock) {
473
+ if (clock.day === 0 || clock.day === 6) return false
474
+ if (isChineseHoliday(clock.dateKey)) return false
475
+ return PEAK_WINDOWS.some(([start, end]) => clock.hour >= start && clock.hour < end)
476
+ }
477
+
419
478
  /**
420
479
  * Which provider tariff is in force now: peak 09:00-12:00 and 14:00-18:00
421
480
  * Beijing time on weekdays, off-peak on weekends, make-up working weekends,
@@ -426,18 +485,42 @@
426
485
  */
427
486
  function isPeakTariff(now = new Date()) {
428
487
  try {
429
- const beijing = new Date(now.getTime() + 8 * 60 * 60 * 1000)
430
- const day = beijing.getUTCDay()
431
- if (day === 0 || day === 6) return false
432
- const dateKey = beijing.toISOString().slice(0, 10)
433
- if (isChineseHoliday(dateKey)) return false
434
- const hour = beijing.getUTCHours()
435
- return (hour >= 9 && hour < 12) || (hour >= 14 && hour < 18)
488
+ return isPeakAtClock(beijingClock(now))
436
489
  } catch {
437
490
  return true
438
491
  }
439
492
  }
440
493
 
494
+ /**
495
+ * Milliseconds until the tariff next changes, so the chip can switch exactly
496
+ * at 09:00 / 12:00 / 14:00 / 18:00 and at midnight (weekend or holiday
497
+ * starts) instead of waiting for the next poll. Returns the poll interval
498
+ * when the search fails.
499
+ * @param now - instant to measure from.
500
+ * @returns a positive delay in milliseconds.
501
+ */
502
+ function msUntilNextTariffChange(now = new Date()) {
503
+ try {
504
+ const base = now.getTime()
505
+ const shifted = new Date(base + 8 * 60 * 60 * 1000)
506
+ const year = shifted.getUTCFullYear()
507
+ const month = shifted.getUTCMonth()
508
+ const date = shifted.getUTCDate()
509
+ let next = Number.POSITIVE_INFINITY
510
+ for (let offset = 0; offset <= BOUNDARY_LOOKAHEAD_DAYS; offset += 1) {
511
+ const day = new Date(Date.UTC(year, month, date + offset))
512
+ for (const hour of TARIFF_BOUNDARY_HOURS) {
513
+ const at = Date.UTC(day.getUTCFullYear(), day.getUTCMonth(), day.getUTCDate(), hour)
514
+ - 8 * 60 * 60 * 1000
515
+ if (at > base + 1_000 && at < next) next = at
516
+ }
517
+ }
518
+ return Number.isFinite(next) ? next - base : 30_000
519
+ } catch {
520
+ return 30_000
521
+ }
522
+ }
523
+
441
524
  /**
442
525
  * Estimate the next turn's input side and the extra part caused by carrying
443
526
  * the current history into it.
@@ -690,7 +773,7 @@
690
773
  display: inline-flex;
691
774
  align-items: stretch;
692
775
  height: 28px;
693
- max-width: 180px;
776
+ max-width: 200px;
694
777
  padding: 0;
695
778
  border: 1px solid var(--dsw-alias-border-l1);
696
779
  border-radius: var(--dsw-radius-sm);
@@ -732,6 +815,18 @@
732
815
  .dshTurnCost_chip[data-tone="yellow"] .dshTurnCost_dot { background: var(--dsw-alias-state-warn-primary); }
733
816
  .dshTurnCost_chip[data-tone="red"] .dshTurnCost_dot { background: var(--dsw-alias-state-error-primary); }
734
817
  .dshTurnCost_amount { font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
818
+ .dshTurnCost_tariff {
819
+ flex: none;
820
+ align-self: center;
821
+ padding: 1px 3px;
822
+ border-radius: 3px;
823
+ background: var(--dsw-alias-bg-layer-2);
824
+ color: var(--dsw-alias-label-secondary);
825
+ font-size: 10px;
826
+ line-height: 12px;
827
+ letter-spacing: .02em;
828
+ }
829
+ .dshTurnCost_tariff[data-tariff="peak"] { color: var(--dsw-alias-label-primary); }
735
830
  .dshTurnCost_panel {
736
831
  position: absolute;
737
832
  bottom: calc(100% + 8px);
@@ -918,18 +1013,19 @@
918
1013
  }
919
1014
  }
920
1015
 
921
- /** @param amount - non-negative CNY. @returns a cost value with a stable four decimals. */
1016
+ /** @param amount - non-negative CNY. @returns a cost value with four decimals (five below ¥0.0001). */
922
1017
  function formatCost(amount) {
923
1018
  if (typeof amount !== 'number' || !Number.isFinite(amount)) return '—'
1019
+ const digits = amount > 0 && amount < 0.0001 ? 5 : 4
924
1020
  try {
925
1021
  return new Intl.NumberFormat(undefined, {
926
1022
  style: 'currency',
927
1023
  currency: 'CNY',
928
- minimumFractionDigits: 4,
929
- maximumFractionDigits: 4,
1024
+ minimumFractionDigits: digits,
1025
+ maximumFractionDigits: digits,
930
1026
  }).format(amount)
931
1027
  } catch {
932
- return `¥${amount.toFixed(4)}`
1028
+ return `¥${amount.toFixed(digits)}`
933
1029
  }
934
1030
  }
935
1031
 
@@ -1059,6 +1155,7 @@
1059
1155
  settings,
1060
1156
  priceSource,
1061
1157
  holidaySource,
1158
+ tariffTime,
1062
1159
  t,
1063
1160
  pinned,
1064
1161
  onUnpin,
@@ -1132,6 +1229,12 @@
1132
1229
  value: estimate.rate === undefined ? '—' : `${formatRate(estimate.rate)} ${t('panel.perMillion')}`,
1133
1230
  }),
1134
1231
  h(Line, { key: 'model', label: t('panel.model'), value: modelText }),
1232
+ h(Line, {
1233
+ key: 'tariff',
1234
+ label: t('panel.tariff'),
1235
+ value: `${tariff} · ${t('panel.beijingTime')} ${tariffTime}`,
1236
+ }),
1237
+ h('div', { key: 'tariffRule', className: 'dshTurnCost_note' }, t('panel.tariffRule')),
1135
1238
  h(Line, {
1136
1239
  key: 'priceSource',
1137
1240
  label: t('panel.priceTable'),
@@ -1365,16 +1468,54 @@
1365
1468
 
1366
1469
  const rawTurns = stats?.turns
1367
1470
  const turns = typeof rawTurns === 'number' && Number.isFinite(rawTurns) && rawTurns >= 0 ? Math.floor(rawTurns) : 0
1368
- const peak = isPeakTariff()
1471
+ const now = new Date()
1472
+ const peak = isPeakTariff(now)
1473
+ let tariffTime = ''
1474
+ try {
1475
+ tariffTime = beijingClock(now).timeKey
1476
+ } catch {
1477
+ tariffTime = ''
1478
+ }
1369
1479
  const estimate = estimateNextTurn({ usage, breakdown, pressure, selection, peak })
1370
1480
  const tone = toneOf(settings, turns, estimate, stats !== undefined)
1371
1481
  const open = hovered || pinned || focusWithin
1482
+ /**
1483
+ * Keep the displayed tariff honest without polling blindly: wake up at
1484
+ * the exact next change (window edge or midnight, so weekends and
1485
+ * holidays flip too), fall back to a 30 s poll, and recompute as soon
1486
+ * as the window is visible again after sleep, minimise or a background
1487
+ * tab — the case where a stale "谷价" used to survive into peak hours.
1488
+ */
1372
1489
  useEffect(() => {
1373
- const timer = window.setInterval(() => {
1490
+ let timer = 0
1491
+ let disposed = false
1492
+ const schedule = () => {
1493
+ if (disposed) return
1494
+ if (timer !== 0) window.clearTimeout(timer)
1495
+ const delay = Math.min(30_000, Math.max(500, msUntilNextTariffChange() + 400))
1496
+ timer = window.setTimeout(() => {
1497
+ if (disposed) return
1498
+ setClock((value) => value + 1)
1499
+ schedule()
1500
+ }, delay)
1501
+ }
1502
+ const refreshNow = () => {
1374
1503
  setClock((value) => value + 1)
1375
- }, 30_000)
1504
+ schedule()
1505
+ }
1506
+ const onVisibility = () => {
1507
+ if (document.visibilityState === 'visible') refreshNow()
1508
+ }
1509
+ document.addEventListener('visibilitychange', onVisibility)
1510
+ window.addEventListener('focus', refreshNow)
1511
+ window.addEventListener('pageshow', refreshNow)
1512
+ schedule()
1376
1513
  return () => {
1377
- window.clearInterval(timer)
1514
+ disposed = true
1515
+ if (timer !== 0) window.clearTimeout(timer)
1516
+ document.removeEventListener('visibilitychange', onVisibility)
1517
+ window.removeEventListener('focus', refreshNow)
1518
+ window.removeEventListener('pageshow', refreshNow)
1378
1519
  }
1379
1520
  }, [])
1380
1521
  const turnsLabel = stats === undefined ? t('chip.turnsLoading') : `${turns} ${t('chip.unit')}`
@@ -1392,7 +1533,9 @@
1392
1533
  ? t('tone.red')
1393
1534
  : t('tone.idle')
1394
1535
  const basisLabel = settings.metric === 'cost' ? t('settings.cost') : t('settings.turns')
1395
- const summary = `${t('chip.title')} · ${valueLabel} · ${t('panel.colorBy')}: ${basisLabel} (${toneText}) · ${t('chip.pinHint')}`
1536
+ const tariffLabel = peak ? t('tariff.peak') : t('tariff.off')
1537
+ const tariffBadge = peak ? t('tariff.peakShort') : t('tariff.offShort')
1538
+ const summary = `${t('chip.title')} · ${valueLabel} · ${tariffLabel} · ${t('panel.colorBy')}: ${basisLabel} (${toneText}) · ${t('chip.pinHint')}`
1396
1539
 
1397
1540
  const updateMetric = (metric) => {
1398
1541
  publishSettings({ ...settings, metric })
@@ -1480,6 +1623,15 @@
1480
1623
  },
1481
1624
  h('span', { className: 'dshTurnCost_dot', 'aria-hidden': true }),
1482
1625
  h('span', { className: 'dshTurnCost_amount' }, valueLabel),
1626
+ h(
1627
+ 'span',
1628
+ {
1629
+ className: 'dshTurnCost_tariff',
1630
+ 'data-tariff': peak ? 'peak' : 'off',
1631
+ 'aria-hidden': true,
1632
+ },
1633
+ tariffBadge,
1634
+ ),
1483
1635
  ),
1484
1636
  ),
1485
1637
  open
@@ -1490,6 +1642,7 @@
1490
1642
  settings,
1491
1643
  priceSource: priceInfo.source,
1492
1644
  holidaySource: holidayInfo.source,
1645
+ tariffTime,
1493
1646
  t,
1494
1647
  pinned,
1495
1648
  onUnpin: dismiss,
@@ -1511,6 +1664,28 @@
1511
1664
  ctx.effect(() => ctx.locale.register(NS, 'en', EN), 'dsh-continue-cost: en dictionary')
1512
1665
  const t = ctx.locale.bind(NS)
1513
1666
 
1667
+ /* Thresholds are shared through localStorage, so a second window or tab
1668
+ * picks up a change without a reload. Echo suppression comes from
1669
+ * comparing the normalized value before writing again. */
1670
+ ctx.effect(() => {
1671
+ const onStorage = (event) => {
1672
+ if (event.key !== STORAGE_KEY) return
1673
+ let parsed
1674
+ try {
1675
+ parsed = event.newValue === null ? undefined : JSON.parse(event.newValue)
1676
+ } catch {
1677
+ return
1678
+ }
1679
+ const next = normalizeSettings(parsed)
1680
+ if (JSON.stringify(next) === JSON.stringify(getSettings())) return
1681
+ publishSettings(next)
1682
+ }
1683
+ window.addEventListener('storage', onStorage)
1684
+ return () => {
1685
+ window.removeEventListener('storage', onStorage)
1686
+ }
1687
+ }, 'dsh-continue-cost: threshold sync')
1688
+
1514
1689
  ctx.effect(() => {
1515
1690
  void refreshPrices()
1516
1691
  void refreshHolidays()
package/locale/en.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Turn count & carry-over delta",
4
- "description": "Shows the completed turn count at the right of the composer, or switches to the extra cost of continuing this conversation instead of starting a fresh one. Hover for the estimate; click the chip to pin the panel, switch the display, and set green, yellow, and red thresholds for turns or cost. Price and Chinese holiday tables update daily from public DeepSeek and gov.cn pages, falling back to a local cache or built-in table; no conversation content is sent and no API key is read."
4
+ "description": "Shows the completed turn count at the right of the composer, or switches to the extra cost of continuing this conversation instead of starting a fresh one. A small badge on the chip names the tariff in force and flips automatically across the official peak boundaries (09:00–12:00 and 14:00–18:00 Beijing time on workdays). Hover for the estimate; click the chip to pin the panel, switch the display, and set green, yellow, and red thresholds for turns or cost. Price and Chinese holiday tables update daily from public DeepSeek and gov.cn pages, falling back to a local cache or built-in table; no conversation content is sent and no API key is read."
5
5
  }
6
6
  }
package/locale/zh.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "对话轮数与续聊差价",
4
- "description": "在输入框右侧显示已完成的对话轮数,也可切换为显示继续当前对话比新开对话多花的金额;悬停查看估算明细,点击胶囊固定面板后切换显示并设置轮数或金额的绿、黄、红阈值。价格表和法定节假日表每天从 DeepSeek 与中国政府网的公开页面自动更新,失败时使用本地缓存或内置表;不发送会话内容,不读取 API Key。"
4
+ "description": "在输入框右侧显示已完成的对话轮数,也可切换为显示继续当前对话比新开对话多花的金额;胶囊上直接标出当前是峰时还是谷时,跨过官方峰谷边界(工作日北京时间 9:00–12:00、14:00–18:00 为峰时)会自动切换。悬停查看估算明细,点击胶囊固定面板后切换显示并设置轮数或金额的绿、黄、红阈值。价格表和法定节假日表每天从 DeepSeek 与中国政府网的公开页面自动更新,失败时使用本地缓存或内置表;不发送会话内容,不读取 API Key。"
5
5
  }
6
6
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "dsh-continue-cost",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "private": false,
5
5
  "license": "MIT",
6
- "description": "DSH 插件:显示对话轮数与续聊差价 —— 继续当前对话比新开一次多花多少钱。Turn count and the extra context cost of continuing this chat instead of starting fresh.",
6
+ "description": "DSH 插件:显示对话轮数与续聊差价 —— 继续当前对话比新开一次多花多少钱,按官方峰谷时段自动切换。Turn count and the extra context cost of continuing this chat instead of starting fresh, switching between peak and off-peak tariffs automatically.",
7
7
  "author": {
8
8
  "name": "0345-0433",
9
9
  "url": "https://github.com/0345-0433"
@@ -30,6 +30,9 @@
30
30
  "type": "module",
31
31
  "icon": "./icon.svg",
32
32
  "main": "./host-1.2.0.js",
33
+ "scripts": {
34
+ "test": "node test/client.test.mjs"
35
+ },
33
36
  "exports": {
34
37
  ".": "./host-1.2.0.js",
35
38
  "./host": "./host-1.2.0.js",