dsh-deepseek-pricing 0.1.0 → 0.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/client.js CHANGED
@@ -1,12 +1,16 @@
1
1
  /**
2
2
  * Browser half of dsh-deepseek-pricing.
3
3
  *
4
- * Registers two seats in the DSH Web UI:
4
+ * Registers three seats in the DSH Web UI:
5
5
  * conversation.input.left — a compact peak/off-peak chip with a popover card
6
6
  * settings.section — the full price table, schedule and data sources
7
+ * plugins.detail.section — the compact feature switches on the plugin page
7
8
  *
8
9
  * The Host half owns every network call and every price/holiday calculation;
9
10
  * this module only renders the JSON it receives from /api/deepseek-pricing/*.
11
+ * Browser-only switches live in localStorage; switches that change Host
12
+ * behaviour are written back through /api/deepseek-pricing/config so the
13
+ * profile's cordis.patch.yml stays the one source of truth.
10
14
  */
11
15
 
12
16
  window.__ModuleLoader__.load({
@@ -17,8 +21,11 @@ window.__ModuleLoader__.load({
17
21
  const { useCallback, useEffect, useRef, useState } = React
18
22
 
19
23
  const NS = 'dsh-deepseek-pricing'
24
+ const PKG = 'dsh-deepseek-pricing'
25
+ const ROW_ID = 'deepseek-pricing'
20
26
  const API_STATE = '/api/deepseek-pricing/state'
21
27
  const API_REFRESH = '/api/deepseek-pricing/refresh'
28
+ const API_CONFIG = '/api/deepseek-pricing/config'
22
29
  const LS_CURRENCY = 'dsh-deepseek-pricing.currency'
23
30
  const RELOAD_INTERVAL_MS = 30 * 60 * 1000
24
31
 
@@ -66,10 +73,9 @@ window.__ModuleLoader__.load({
66
73
  holidaysSnapshot: '内置快照',
67
74
  holidaysUnpublished: '尚未发布',
68
75
  holidaysFailed: '获取失败',
69
- toolTitle: 'AI 查询工具',
70
- toolOn: '已开启',
71
- toolOff: '已关闭',
72
- toolHint: '在插件配置里把 tool 设为 true 即可让模型主动查询时段与价格:',
76
+ holidaysStale: '沿用上次',
77
+ holidaysPending: '检查中',
78
+ holidaysCached: '本地缓存',
73
79
  footnote: '价格为官方文档快照,实际扣费以 DeepSeek 账单为准。',
74
80
  searchFetch: '网页搜索 / 抓取',
75
81
  perThousand: '每 1000 次成功请求',
@@ -87,6 +93,80 @@ window.__ModuleLoader__.load({
87
93
  manualOnly: '仅手动',
88
94
  minutes: '分钟',
89
95
  close: '关闭',
96
+ costTitle: '花费估算',
97
+ costMappingSection: '模型映射',
98
+ costHint: '按每轮结束时刻的高峰/空闲单价估算;只对已完成且官方用量完整的轮次显示。',
99
+ costMappingHint: '每行填一个 provider/model(或只填模型名),选它该用哪套价目,靠上的行优先;没匹配到的按模型名里的 flash / pro 自动判断。',
100
+ costAddRow: '添加映射',
101
+ costClear: '清除本地设置',
102
+ costRemove: '删除',
103
+ costAuto: '自动',
104
+ costIgnore: '不计价',
105
+ costDetectedNone: '未识别',
106
+ costLocalOnly: '这些映射只在显示每轮花费时用来区分 flash / pro 的价目;不开启花费估算就不用管。设置只保存在本浏览器。',
107
+ numberSection: '数字格式',
108
+ numberIntro: '只改每轮预估花费的写法,不影响价格本身。',
109
+ numberSeparator: '分隔符',
110
+ numberGroup: '分组',
111
+ numberGroupHint: '整数与小数部分都按这个位数分组;不分隔时无效。',
112
+ numberGroup3: '每 3 位',
113
+ numberGroup4: '每 4 位',
114
+ numberDecimals: '小数位',
115
+ numberDecimalsHint: '四舍五入到指定位数,末尾零保留。',
116
+ numberTiny: '小额显示',
117
+ numberTinyHint: '四舍五入后为 0 但确实有花费时。',
118
+ numberPreview: '预览',
119
+ sepSpace: '空格',
120
+ sepComma: '英文逗号',
121
+ sepBar: '竖线',
122
+ sepDash: '竖虚线',
123
+ sepNone: '不分隔',
124
+ uninstallTitle: '卸载说明',
125
+ uninstallIntro: '卸载会删掉插件文件和节假日缓存,不会动 DSH 或其它插件。下面几项不属于插件本体,不清理也没有副作用;介意残留时按每一条下面的操作处理。',
126
+ uninstallLocal: '浏览器里的显示偏好',
127
+ uninstallLocalAction: '设置 → DeepSeek 价格 → 花费估算 →「清除本地设置」,会一并删掉 dsh-deepseek-pricing.cost(花费开关、模型映射、数字格式)与 dsh-deepseek-pricing.currency(¥/$)。',
128
+ uninstallRow: '配置覆盖',
129
+ uninstallRowAction: '只在界面里改过「查询工具 / 节假日 / 刷新间隔」时出现:删掉 profile 的 cordis.patch.yml 里 - id: deepseek-pricing 那一段。',
130
+ uninstallPnpm: 'pnpm 发布龄规则',
131
+ uninstallPnpmAction: '只在安装刚发布的版本时出现:删掉 profile 的 pnpm-workspace.yaml 里 minimumReleaseAgeExclude: dsh-deepseek-pricing@x.y.z 一行。',
132
+ uninstallCache: '节假日缓存',
133
+ uninstallCacheAction: '在包目录 .cache/holidays.json 里,随卸载一起删除,无需处理。',
134
+ costEstimate: '预估花费',
135
+ costUnavailable: '无法估算',
136
+ costReasonRoute: '缺少模型/路由信息',
137
+ costReasonCacheRead: '缺少缓存读取用量',
138
+ costReasonUnknownModel: '无法识别模型',
139
+ costReasonMixedModel: '混合模型,无法精确计价',
140
+ costReasonPrices: '价格数据不可用',
141
+ costReasonTime: '时间信息缺失',
142
+ costModel: '模型',
143
+ costUncached: '未缓存输入',
144
+ costCacheRead: '缓存读取',
145
+ costOutput: '输出',
146
+ costUnit: '每百万 tokens',
147
+ costSnapshot: '价格快照',
148
+ costStale: '离线',
149
+ costPeak: '高峰(全价)',
150
+ costOffPeak: '空闲(半价)',
151
+ featTitle: '功能开关',
152
+ featIntro: '这里只控制插件内部的功能。',
153
+ featCost: '每轮花费估算',
154
+ featCostHint: '在每轮结束的时间行上方右对齐显示预估花费,数据缺失时显示 ~。只保存在本浏览器。',
155
+ featTool: 'AI 查询工具 deepseek_pricing',
156
+ featToolHint: '开启后模型可以主动查询当前时段与单价。写入插件配置,保存后本插件会重新加载。',
157
+ featHoliday: '同步法定节假日',
158
+ featHolidayHint: '关闭后只用内置快照判断「节假日全天空闲」。写入插件配置,保存后本插件会重新加载。',
159
+ featRefresh: '价格自动刷新',
160
+ featRefreshHint: 'Host 按间隔抓取官方文档;选「仅手动」时只有点刷新才抓取。写入插件配置,保存后本插件会重新加载。',
161
+ featSaving: '已提交,插件正在重新加载…',
162
+ featSaved: '已保存。',
163
+ featFailed: '保存失败:',
164
+ featReloadTag: '需重载',
165
+ featLocalTag: '即时',
166
+ featHostUnavailable: '当前 DSH 版本不支持自动写入,请手动编辑 cordis.patch.yml。',
167
+ detailTitle: '功能开关',
168
+ detailIntro: '完整设置在「设置 → DeepSeek 价格」;这里放最常用的两个。',
169
+ detailUnsupported: '自动写入不可用,开关只在本页临时生效。',
90
170
  }
91
171
 
92
172
  const EN = {
@@ -133,10 +213,9 @@ window.__ModuleLoader__.load({
133
213
  holidaysSnapshot: 'Snapshot',
134
214
  holidaysUnpublished: 'Not published',
135
215
  holidaysFailed: 'Failed',
136
- toolTitle: 'AI query tool',
137
- toolOn: 'Enabled',
138
- toolOff: 'Disabled',
139
- toolHint: 'Set tool to true in the plugin config so the model can check the window and prices:',
216
+ holidaysStale: 'Kept last sync',
217
+ holidaysPending: 'Checking',
218
+ holidaysCached: 'Local cache',
140
219
  footnote: 'Prices are a snapshot of the official docs; billing always follows DeepSeek.',
141
220
  searchFetch: 'Search / Fetch',
142
221
  perThousand: 'per 1,000 successful requests',
@@ -154,6 +233,80 @@ window.__ModuleLoader__.load({
154
233
  manualOnly: 'Manual only',
155
234
  minutes: 'min',
156
235
  close: 'Close',
236
+ costTitle: 'Cost estimate',
237
+ costMappingSection: 'Model mappings',
238
+ costHint: 'Estimated with the peak/off-peak price at the turn end; shown only for completed turns with complete usage.',
239
+ costMappingHint: 'One provider/model per row (or just the model name) and which price list it uses; the first matching row wins. Unmatched routes fall back to flash / pro in the model name.',
240
+ costAddRow: 'Add mapping',
241
+ costClear: 'Clear local settings',
242
+ costRemove: 'Remove',
243
+ costAuto: 'Auto',
244
+ costIgnore: 'Ignore',
245
+ costDetectedNone: 'Unrecognized',
246
+ costLocalOnly: 'These mappings only pick the flash / pro price list for the per-turn cost estimate; ignore them when the estimate is off. Saved in this browser only.',
247
+ numberSection: 'Number format',
248
+ numberIntro: 'Only changes how the per-turn estimate is written, never the price itself.',
249
+ numberSeparator: 'Separator',
250
+ numberGroup: 'Grouping',
251
+ numberGroupHint: 'Applies to the integer and fraction part alike; ignored when not separating.',
252
+ numberGroup3: 'Every 3 digits',
253
+ numberGroup4: 'Every 4 digits',
254
+ numberDecimals: 'Decimals',
255
+ numberDecimalsHint: 'Rounded to this many places; trailing zeros are kept.',
256
+ numberTiny: 'Tiny amounts',
257
+ numberTinyHint: 'When rounding would show 0 but the turn did cost something.',
258
+ numberPreview: 'Preview',
259
+ sepSpace: 'Space',
260
+ sepComma: 'Comma',
261
+ sepBar: 'Pipe',
262
+ sepDash: 'Vertical dashed',
263
+ sepNone: 'None',
264
+ uninstallTitle: 'Before you uninstall',
265
+ uninstallIntro: 'Uninstalling removes the plugin files and the holiday cache; it never touches DSH or other plugins. The items below are not part of the plugin, so leaving them is harmless — clean them only if you dislike leftovers.',
266
+ uninstallLocal: 'Browser display preferences',
267
+ uninstallLocalAction: 'Settings → DeepSeek Pricing → Cost estimate → “Clear local settings” also drops dsh-deepseek-pricing.cost (cost toggle, model mappings, number format) and dsh-deepseek-pricing.currency (¥/$).',
268
+ uninstallRow: 'Config override',
269
+ uninstallRowAction: 'Only exists after changing “query tool / holidays / refresh interval”: delete the - id: deepseek-pricing block from the profile’s cordis.patch.yml.',
270
+ uninstallPnpm: 'pnpm release-age rule',
271
+ uninstallPnpmAction: 'Only appears when installing a just-published version: delete the minimumReleaseAgeExclude: dsh-deepseek-pricing@x.y.z line from the profile’s pnpm-workspace.yaml.',
272
+ uninstallCache: 'Holiday cache',
273
+ uninstallCacheAction: 'Lives in the package at .cache/holidays.json and goes away with the package — nothing to do.',
274
+ costEstimate: 'Estimated cost',
275
+ costUnavailable: 'Not available',
276
+ costReasonRoute: 'model/route missing',
277
+ costReasonCacheRead: 'cache-read usage missing',
278
+ costReasonUnknownModel: 'unrecognized model',
279
+ costReasonMixedModel: 'mixed models',
280
+ costReasonPrices: 'price data unavailable',
281
+ costReasonTime: 'time missing',
282
+ costModel: 'Model',
283
+ costUncached: 'Uncached input',
284
+ costCacheRead: 'Cache read',
285
+ costOutput: 'Output',
286
+ costUnit: 'per 1M tokens',
287
+ costSnapshot: 'Price snapshot',
288
+ costStale: 'offline',
289
+ costPeak: 'Peak (full price)',
290
+ costOffPeak: 'Off-peak (half price)',
291
+ featTitle: 'Feature switches',
292
+ featIntro: 'These switches only control this plugin’s own features.',
293
+ featCost: 'Per-turn cost estimate',
294
+ featCostHint: 'Shows an estimate above the turn’s time row, or ~ when data is missing. Saved in this browser only.',
295
+ featTool: 'AI query tool (deepseek_pricing)',
296
+ featToolHint: 'Lets the model check the current window and prices. Written to the plugin config; the plugin reloads after saving.',
297
+ featHoliday: 'Sync public holidays',
298
+ featHolidayHint: 'Off keeps the built-in snapshot only. Written to the plugin config; the plugin reloads after saving.',
299
+ featRefresh: 'Automatic price refresh',
300
+ featRefreshHint: 'How often the Host re-reads the official docs; “Manual only” fetches on demand. Written to the plugin config.',
301
+ featSaving: 'Submitted — the plugin is reloading…',
302
+ featSaved: 'Saved.',
303
+ featFailed: 'Save failed: ',
304
+ featReloadTag: 'reloads',
305
+ featLocalTag: 'instant',
306
+ featHostUnavailable: 'This DSH build cannot write config; edit cordis.patch.yml manually.',
307
+ detailTitle: 'Feature switches',
308
+ detailIntro: 'Full settings are under Settings → DeepSeek Pricing; the two most used switches are here.',
309
+ detailUnsupported: 'Config writing is unavailable, so the switch is temporary on this page.',
157
310
  }
158
311
 
159
312
  const CSS = `
@@ -197,8 +350,8 @@ window.__ModuleLoader__.load({
197
350
  .dp-card-title { font-size: 13px; font-weight: 600; margin: 0 0 8px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
198
351
  .dp-hero { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; }
199
352
  .dp-hero-status { display: inline-flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 600; }
200
- .dp-hero-status.is-peak .dp-dot { background: var(--dsw-alias-state-warn-primary); }
201
- .dp-hero-status.is-off .dp-dot { background: var(--dsw-alias-state-success-primary); }
353
+ .dp-hero.is-peak .dp-dot { background: var(--dsw-alias-state-warn-primary); }
354
+ .dp-hero.is-off .dp-dot { background: var(--dsw-alias-state-success-primary); }
202
355
  .dp-hero .dp-dot { width: 9px; height: 9px; }
203
356
  .dp-banner { border: 1px solid var(--dsw-alias-state-warn-primary); border-radius: 8px; padding: 8px 10px; color: var(--dsw-alias-label-primary); background: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 10%, transparent); font-size: 12px; display: flex; gap: 8px; align-items: center; justify-content: space-between; }
204
357
  .dp-banner.is-error { border-color: var(--dsw-alias-state-error-primary); background: color-mix(in srgb, var(--dsw-alias-state-error-primary) 10%, transparent); }
@@ -206,13 +359,20 @@ window.__ModuleLoader__.load({
206
359
  .dp-seg button { font: inherit; font-size: 12px; padding: 3px 10px; border: 0; background: transparent; color: var(--dsw-alias-label-secondary); cursor: pointer; }
207
360
  .dp-seg button.is-on { background: color-mix(in srgb, var(--dsw-alias-label-primary) 16%, transparent); color: var(--dsw-alias-label-primary); font-weight: 600; }
208
361
  .dp-seg button:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: -2px; }
362
+ .dp-seg button:disabled { opacity: .45; cursor: default; }
363
+ .dp-preview { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; padding: 6px 8px; border-radius: 6px; background: var(--dsw-alias-bg-layer-2); font-size: 12px; font-variant-numeric: tabular-nums; }
364
+ .dp-subblock + .dp-subblock { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--dsw-alias-border-l1); }
365
+ .dp-subtitle { font-size: 12.5px; font-weight: 600; margin: 0 0 4px; }
366
+ .dp-notes { margin: 4px 0 0; padding-left: 18px; font-size: 12px; line-height: 1.55; }
367
+ .dp-notes li + li { margin-top: 6px; }
368
+ .dp-notes li .dp-opt-title { display: block; }
369
+ .dp-notes-action { display: block; margin-top: 1px; color: var(--dsw-alias-label-secondary); font-size: 11px; }
209
370
  .dp-kv { display: grid; grid-template-columns: 112px 1fr; gap: 6px 12px; font-size: 12px; margin: 0; }
210
371
  .dp-kv dt { color: var(--dsw-alias-label-secondary); }
211
372
  .dp-kv dd { margin: 0; word-break: break-word; }
212
373
  .dp-footnote { color: var(--dsw-alias-label-secondary); font-size: 11px; margin: 0; }
213
374
  .dp-warn-list { margin: 0; padding-left: 18px; color: var(--dsw-alias-state-warn-primary); font-size: 12px; }
214
375
  .dp-warn-list li + li { margin-top: 2px; }
215
- .dp-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11px; white-space: pre-wrap; background: var(--dsw-alias-bg-layer-2); border-radius: 6px; padding: 6px 8px; margin: 6px 0 0; }
216
376
  .dp-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
217
377
  .dp-year { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--dsw-alias-border-l1); border-radius: 999px; padding: 2px 8px; font-size: 11px; }
218
378
  .dp-year .dp-year-status { color: var(--dsw-alias-label-secondary); }
@@ -223,6 +383,26 @@ window.__ModuleLoader__.load({
223
383
  .dp-schedule-bar { display: inline-block; height: 8px; border-radius: 4px; background: var(--dsw-alias-state-warn-primary); opacity: .75; }
224
384
  .dp-schedule-bar.is-off { background: var(--dsw-alias-state-success-primary); opacity: .45; }
225
385
  .dp-loading { color: var(--dsw-alias-label-secondary); font-size: 12px; padding: 6px 0; }
386
+ .dp-cost { display: flex; justify-content: flex-end; padding: 2px 2px 0; }
387
+ .dp-cost-chip { color: var(--dsw-alias-label-secondary); font-size: 11px; line-height: 1.4; font-variant-numeric: tabular-nums; cursor: default; }
388
+ .dp-cost-chip:hover { color: var(--dsw-alias-label-primary); }
389
+ .dp-map-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(96px, auto) auto; gap: 8px; align-items: center; margin-top: 6px; }
390
+ .dp-input { font: inherit; font-size: 12px; color: var(--dsw-alias-label-primary); background: var(--dsw-alias-bg-layer-2); border: 1px solid var(--dsw-alias-border-l1); border-radius: 6px; padding: 3px 8px; min-width: 0; }
391
+ .dp-input:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }
392
+ .dp-opt { display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; gap: 2px 8px; align-items: start; padding: 7px 0; border-top: 1px solid var(--dsw-alias-border-l1); cursor: pointer; }
393
+ .dp-opt:first-of-type { border-top: 0; }
394
+ .dp-opt input { margin: 2px 0 0; cursor: pointer; }
395
+ .dp-opt-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
396
+ .dp-opt-title { font-size: 12px; }
397
+ .dp-opt-hint { color: var(--dsw-alias-label-secondary); font-size: 11px; line-height: 1.45; }
398
+ .dp-opt-tag { color: var(--dsw-alias-label-secondary); font-size: 10px; border: 1px solid var(--dsw-alias-border-l1); border-radius: 999px; padding: 1px 6px; white-space: nowrap; }
399
+ .dp-opt.is-busy { opacity: .6; }
400
+ .dp-inline { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px solid var(--dsw-alias-border-l1); }
401
+ .dp-inline-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
402
+ .dp-status { font-size: 11px; color: var(--dsw-alias-label-secondary); margin: 6px 0 0; }
403
+ .dp-status.is-error { color: var(--dsw-alias-state-error-primary); }
404
+ .dp-status.is-busy { color: var(--dsw-alias-state-warn-primary); }
405
+ .dp-detail { border: 1px solid var(--dsw-alias-border-l1); border-radius: 10px; padding: 12px 14px; background: var(--dsw-alias-bg-layer-1); margin: 4px 0 8px; }
226
406
  `
227
407
 
228
408
  /* --------------------------------------------------------------------- */
@@ -335,14 +515,16 @@ window.__ModuleLoader__.load({
335
515
  // On a cold DSH start the page can be served before every plugin row has
336
516
  // activated, so the very first request may legitimately be a 404. Back
337
517
  // off and retry instead of pinning the chip to "unavailable" until the
338
- // next scheduled reload.
518
+ // next scheduled reload. This also heals the one-second window where
519
+ // writing a Host switch reloads this plugin's own row and the route
520
+ // briefly disappears: retry even when older data is still on screen.
339
521
  useEffect(() => {
340
- if (!state.error || state.data) return undefined
522
+ if (!state.error) return undefined
341
523
  const attempt = Math.min(state.attempt, 6)
342
524
  const delay = Math.min(30000, 1000 * 2 ** Math.max(0, attempt - 1))
343
525
  const timer = setTimeout(() => load(), delay)
344
526
  return () => clearTimeout(timer)
345
- }, [state.attempt, state.error, state.data, load])
527
+ }, [state.attempt, state.error, load])
346
528
 
347
529
  // Coming back to the tab is a cheap moment to heal an early failure.
348
530
  useEffect(() => {
@@ -358,6 +540,38 @@ window.__ModuleLoader__.load({
358
540
  return () => clearInterval(id)
359
541
  }, [load])
360
542
 
543
+ // The Host refreshes holidays behind the state read. While a year is still
544
+ // being checked, or was kept from an older sync, look again shortly
545
+ // instead of waiting for the 30-minute poll.
546
+ const holidayFollowUps = useRef(0)
547
+ useEffect(() => {
548
+ const years = state.data && state.data.holidays && state.data.holidays.years
549
+ const waiting =
550
+ Array.isArray(years) &&
551
+ years.some(
552
+ (entry) =>
553
+ entry.status === 'pending' ||
554
+ entry.status === 'stale' ||
555
+ entry.status === 'snapshot' ||
556
+ entry.status === 'unavailable',
557
+ )
558
+ if (!waiting) {
559
+ holidayFollowUps.current = 0
560
+ return undefined
561
+ }
562
+ if (holidayFollowUps.current >= 3) return undefined
563
+ holidayFollowUps.current += 1
564
+ const soon = setTimeout(() => load(), 5000)
565
+ const later = setTimeout(() => load(), 20000)
566
+ // The Host retries a failed fetch after a minute; look once after that.
567
+ const retried = setTimeout(() => load(), 75000)
568
+ return () => {
569
+ clearTimeout(soon)
570
+ clearTimeout(later)
571
+ clearTimeout(retried)
572
+ }
573
+ }, [state.data, load])
574
+
361
575
  return { ...state, reload: load }
362
576
  }
363
577
 
@@ -448,6 +662,1031 @@ window.__ModuleLoader__.load({
448
662
  return t(`weekday${isoWeekday}`)
449
663
  }
450
664
 
665
+ function beijingStamp(ms) {
666
+ if (!Number.isFinite(ms)) return '—'
667
+ return `${beijingDateKey(ms)} ${beijingClock(ms)}`
668
+ }
669
+
670
+ /* --------------------------------------------------------------------- */
671
+ /* cost estimate */
672
+ /* --------------------------------------------------------------------- */
673
+
674
+ const LS_COST = 'dsh-deepseek-pricing.cost'
675
+
676
+ // Kept here (not with the formatters) because COST_DEFAULT needs them at
677
+ // module evaluation time; the formatter functions themselves live below.
678
+ const SEPARATOR_CHARS = { space: ' ', comma: ',', bar: '|', dash: '┊', none: '' }
679
+ const SEPARATOR_IDS = ['space', 'comma', 'bar', 'dash', 'none']
680
+ const GROUP_SIZES = [3, 4]
681
+ const TINY_MODES = ['ellipsis', 'less']
682
+ const FORMAT_DEFAULT = { groupSize: 3, separator: 'space', decimals: 3, tiny: 'ellipsis' }
683
+
684
+ const COST_DEFAULT = { enabled: false, mappings: [], format: FORMAT_DEFAULT }
685
+ const costListeners = new Set()
686
+
687
+ function sanitizeCostPrefs(raw) {
688
+ const value = raw && typeof raw === 'object' ? raw : {}
689
+ const mappings = Array.isArray(value.mappings)
690
+ ? value.mappings
691
+ .filter((row) => row && typeof row.route === 'string')
692
+ .map((row) => ({
693
+ route: row.route.trim(),
694
+ model:
695
+ row.model === 'flash' || row.model === 'pro' || row.model === 'ignore'
696
+ ? row.model
697
+ : '',
698
+ }))
699
+ : []
700
+ return { enabled: value.enabled === true, mappings, format: sanitizeFormat(value.format) }
701
+ }
702
+
703
+ function readCostPrefs() {
704
+ try {
705
+ const raw = localStorage.getItem(LS_COST)
706
+ return raw ? sanitizeCostPrefs(JSON.parse(raw)) : COST_DEFAULT
707
+ } catch {
708
+ return COST_DEFAULT
709
+ }
710
+ }
711
+
712
+ function writeCostPrefs(next) {
713
+ const value = sanitizeCostPrefs(next)
714
+ try {
715
+ localStorage.setItem(LS_COST, JSON.stringify(value))
716
+ } catch {
717
+ /* storage unavailable */
718
+ }
719
+ for (const listener of Array.from(costListeners)) {
720
+ try {
721
+ listener(value)
722
+ } catch {
723
+ /* ignore listener failure */
724
+ }
725
+ }
726
+ return value
727
+ }
728
+
729
+ function useCostPrefs() {
730
+ const [prefs, setPrefs] = useState(readCostPrefs)
731
+ useEffect(() => {
732
+ const listener = (next) => setPrefs(next)
733
+ costListeners.add(listener)
734
+ return () => costListeners.delete(listener)
735
+ }, [])
736
+ const update = useCallback((next) => {
737
+ const value = writeCostPrefs(typeof next === 'function' ? next(readCostPrefs()) : next)
738
+ setPrefs(value)
739
+ }, [])
740
+ return [prefs, update]
741
+ }
742
+
743
+ /** Remove this plugin's browser preferences; profile files are removed by the bundle uninstall. */
744
+ function clearLocalSettings() {
745
+ try {
746
+ localStorage.removeItem(LS_COST)
747
+ localStorage.removeItem(LS_CURRENCY)
748
+ } catch {
749
+ /* storage unavailable */
750
+ }
751
+ for (const listener of Array.from(costListeners)) {
752
+ try {
753
+ listener(COST_DEFAULT)
754
+ } catch {
755
+ /* ignore listener failure */
756
+ }
757
+ }
758
+ for (const listener of Array.from(currencyListeners)) {
759
+ try {
760
+ listener(null)
761
+ } catch {
762
+ /* ignore listener failure */
763
+ }
764
+ }
765
+ }
766
+
767
+ // One shared price read for every mounted cost chip: the page may render
768
+ // dozens of turns, and each one must not issue its own request.
769
+ const sharedPriceCache = new Map()
770
+ const sharedPriceListeners = new Set()
771
+
772
+ function sharedPriceEntry(currency) {
773
+ return sharedPriceCache.get(currency || 'default') || null
774
+ }
775
+
776
+ function sharedPriceLoad(currency) {
777
+ const key = currency || 'default'
778
+ const entry = sharedPriceCache.get(key)
779
+ if (entry && entry.at && Date.now() - entry.at < RELOAD_INTERVAL_MS) {
780
+ return Promise.resolve(entry)
781
+ }
782
+ if (entry && entry.promise) return entry.promise
783
+ const promise = (async () => {
784
+ let next
785
+ try {
786
+ const query = currency ? `?currency=${encodeURIComponent(currency)}` : ''
787
+ const response = await fetch(API_STATE + query, { cache: 'no-store' })
788
+ const payload = await response.json().catch(() => null)
789
+ if (!response.ok || !payload || payload.ok !== true) {
790
+ throw new Error((payload && payload.error) || `HTTP ${response.status}`)
791
+ }
792
+ next = { state: payload, at: Date.now(), error: null, promise: null }
793
+ } catch (error) {
794
+ next = {
795
+ state: entry ? entry.state : null,
796
+ at: Date.now(),
797
+ error: describeError(error),
798
+ promise: null,
799
+ }
800
+ }
801
+ sharedPriceCache.set(key, next)
802
+ for (const listener of Array.from(sharedPriceListeners)) {
803
+ try {
804
+ listener(key)
805
+ } catch {
806
+ /* ignore listener failure */
807
+ }
808
+ }
809
+ return next
810
+ })()
811
+ sharedPriceCache.set(key, {
812
+ state: entry ? entry.state : null,
813
+ at: entry ? entry.at : 0,
814
+ error: entry ? entry.error : null,
815
+ promise,
816
+ })
817
+ return promise
818
+ }
819
+
820
+ function useSharedPrice(currency, enabled) {
821
+ const key = currency || 'default'
822
+ const [snap, setSnap] = useState(() => sharedPriceEntry(currency))
823
+ useEffect(() => {
824
+ const listener = (changed) => {
825
+ if (changed === key) setSnap(sharedPriceEntry(currency))
826
+ }
827
+ sharedPriceListeners.add(listener)
828
+ setSnap(sharedPriceEntry(currency))
829
+ return () => sharedPriceListeners.delete(listener)
830
+ }, [currency, key])
831
+ useEffect(() => {
832
+ if (!enabled) return
833
+ const entry = sharedPriceEntry(currency)
834
+ if (!entry || !entry.state || Date.now() - entry.at >= RELOAD_INTERVAL_MS) {
835
+ sharedPriceLoad(currency).catch(() => {})
836
+ }
837
+ }, [currency, enabled])
838
+ return snap
839
+ }
840
+
841
+ function findByEndSeq(turnEnds, seq) {
842
+ if (!turnEnds || typeof turnEnds.forEach !== 'function') return null
843
+ let found = null
844
+ turnEnds.forEach((end, turn) => {
845
+ if (found === null && end === seq) found = turn
846
+ })
847
+ return found
848
+ }
849
+
850
+ function detectPriceModel(text) {
851
+ const value = String(text || '').toLowerCase()
852
+ if (value.includes('flash')) return 'deepseek-flash'
853
+ if (value.includes('pro')) return 'deepseek-v4-pro'
854
+ return null
855
+ }
856
+
857
+ function routeLabel(route) {
858
+ return `${route.provider}/${route.model}`
859
+ }
860
+
861
+ function routePriceModel(route, prefs) {
862
+ const label = routeLabel(route)
863
+ for (const row of prefs.mappings) {
864
+ if (row.route !== label && row.route !== route.model) continue
865
+ if (row.model === 'ignore') return 'ignore'
866
+ if (row.model === 'flash') return 'deepseek-flash'
867
+ if (row.model === 'pro') return 'deepseek-v4-pro'
868
+ return detectPriceModel(route.model)
869
+ }
870
+ return detectPriceModel(route.model)
871
+ }
872
+
873
+ /** Peak/off-peak at one instant, using the same Beijing rule as the Host. */
874
+ function classifyPeakAt(ms, holidayDates) {
875
+ if (!Number.isFinite(ms)) return null
876
+ const dateKey = beijingDateKey(ms)
877
+ if (!dateKey) return null
878
+ const [year, month, day] = dateKey.split('-').map(Number)
879
+ const hour = Number(beijingClock(ms).slice(0, 2))
880
+ const utcDay = new Date(Date.UTC(year, month - 1, day)).getUTCDay()
881
+ const isoWeekday = utcDay === 0 ? 7 : utcDay
882
+ const holiday = holidayDates && holidayDates[dateKey]
883
+ const peak =
884
+ isoWeekday >= 1 &&
885
+ isoWeekday <= 5 &&
886
+ !holiday &&
887
+ ((hour >= 9 && hour < 12) || (hour >= 14 && hour < 18))
888
+ return {
889
+ peak,
890
+ period: peak ? 'peak' : 'off-peak',
891
+ holidayName: holiday && holiday.name ? holiday.name : '',
892
+ }
893
+ }
894
+
895
+ /**
896
+ * Price one completed Turn from its official usage. `units` is the exact
897
+ * cost scaled by 1e12 (tokens × price-micro-units), so money formatting
898
+ * stays integer-exact.
899
+ */
900
+ function computeTurnCost(tail, priceState, prefs) {
901
+ if (!tail || !tail.tokenUsage) return null
902
+ const usage = tail.tokenUsage
903
+ const routes = Array.isArray(usage.routes)
904
+ ? usage.routes.filter((route) => route && route.provider && route.model)
905
+ : []
906
+ if (routes.length === 0) return { unavailable: 'route', routes: [] }
907
+ if (usage.cacheReadTokens === undefined) return { unavailable: 'cacheRead', routes }
908
+ const models = routes.map((route) => routePriceModel(route, prefs))
909
+ if (models.includes('ignore')) return null
910
+ if (models.some((model) => !model)) return { unavailable: 'unknownModel', routes }
911
+ const unique = Array.from(new Set(models))
912
+ if (unique.length > 1) return { unavailable: 'mixedModel', routes }
913
+ const state = priceState && priceState.ok === true ? priceState : null
914
+ const model =
915
+ state && Array.isArray(state.prices.models)
916
+ ? state.prices.models.find((entry) => entry.id === unique[0])
917
+ : null
918
+ if (!model) return { unavailable: 'prices', routes }
919
+ const period = classifyPeakAt(tail.time, state.holidays && state.holidays.dates)
920
+ if (!period) return { unavailable: 'time', routes }
921
+ const price = model[period.peak ? 'peak' : 'offPeak']
922
+ if (!price) return { unavailable: 'prices', routes }
923
+ const pMiss = Math.round(price.cacheMiss * 1e6)
924
+ const pHit = Math.round(price.cacheHit * 1e6)
925
+ const pOut = Math.round(price.output * 1e6)
926
+ if (![pMiss, pHit, pOut].every((value) => Number.isFinite(value) && value > 0)) {
927
+ return { unavailable: 'prices', routes }
928
+ }
929
+ const uncached = Math.max(0, Math.round(usage.uncachedInputTokens || 0))
930
+ const cacheRead = Math.max(0, Math.round(usage.cacheReadTokens || 0))
931
+ const output = Math.max(0, Math.round(usage.outputTokens || 0))
932
+ const units = uncached * pMiss + cacheRead * pHit + output * pOut
933
+ if (!Number.isSafeInteger(units)) return { unavailable: 'prices', routes }
934
+ return {
935
+ units,
936
+ currency: state.prices.currency,
937
+ modelId: unique[0],
938
+ period: period.period,
939
+ holidayName: period.holidayName,
940
+ routes,
941
+ price: {
942
+ cacheMiss: price.cacheMiss,
943
+ cacheHit: price.cacheHit,
944
+ output: price.output,
945
+ },
946
+ buckets: { uncached, cacheRead, output },
947
+ fetchedAtMs: state.prices.fetchedAtMs,
948
+ stale: Boolean(state.prices.stale),
949
+ }
950
+ }
951
+
952
+ /* --------------------------------------------------------------------- */
953
+ /* number format (user selectable) */
954
+ /* --------------------------------------------------------------------- */
955
+
956
+ function sanitizeFormat(raw) {
957
+ const value = raw && typeof raw === 'object' ? raw : {}
958
+ const decimals = Number(value.decimals)
959
+ return {
960
+ groupSize: GROUP_SIZES.includes(value.groupSize) ? value.groupSize : FORMAT_DEFAULT.groupSize,
961
+ separator: SEPARATOR_IDS.includes(value.separator) ? value.separator : FORMAT_DEFAULT.separator,
962
+ decimals:
963
+ Number.isInteger(decimals) && decimals >= 1 && decimals <= 8
964
+ ? decimals
965
+ : FORMAT_DEFAULT.decimals,
966
+ tiny: TINY_MODES.includes(value.tiny) ? value.tiny : FORMAT_DEFAULT.tiny,
967
+ }
968
+ }
969
+
970
+ function separatorOf(format) {
971
+ const id = format && format.separator
972
+ return Object.prototype.hasOwnProperty.call(SEPARATOR_CHARS, id) ? SEPARATOR_CHARS[id] : ' '
973
+ }
974
+
975
+ /** Integer digits group from the decimal point outward (1 234 567). */
976
+ function groupInteger(digits, size, separator) {
977
+ const text = String(digits)
978
+ const width = Number(size)
979
+ if (!separator || !(width > 0) || text.length <= width) return text
980
+ return text.replace(new RegExp(`\\B(?=(\\d{${width}})+(?!\\d))`, 'g'), () => separator)
981
+ }
982
+
983
+ /** Fraction digits group from the decimal point inward (0.5827 7672). */
984
+ function groupFraction(digits, size, separator) {
985
+ const text = String(digits)
986
+ const width = Number(size)
987
+ if (!separator || !(width > 0) || text.length <= width) return text
988
+ return text.replace(new RegExp(`(\\d{${width}})(?=\\d)`, 'g'), (match) => match + separator)
989
+ }
990
+
991
+ function trimFraction(digits) {
992
+ return String(digits).replace(/0+$/, '')
993
+ }
994
+
995
+ function zeroText(format) {
996
+ return `0.${'0'.repeat(format.decimals)}`
997
+ }
998
+
999
+ /** Smallest positive amount representable at this precision: 0.001. */
1000
+ function lessText(format) {
1001
+ return `0.${'0'.repeat(format.decimals - 1)}1`
1002
+ }
1003
+
1004
+ /**
1005
+ * `units` is cost × 1e12, an exact integer. Rounding to N decimals is an
1006
+ * integer division so the result never drifts through a float.
1007
+ */
1008
+ function splitDigits(units, decimals) {
1009
+ const divisor = Math.pow(10, 12 - decimals)
1010
+ const rounded = Math.round(units / divisor)
1011
+ const digits = String(rounded).padStart(decimals + 1, '0')
1012
+ return {
1013
+ rounded,
1014
+ whole: digits.slice(0, digits.length - decimals),
1015
+ fraction: digits.slice(digits.length - decimals),
1016
+ }
1017
+ }
1018
+
1019
+ /**
1020
+ * The chip's number plus a marker the caller turns into `~` or `<`:
1021
+ * { text: '1 234.568', marker: null }
1022
+ * { text: '0.000', marker: 'ellipsis' } → ~¥0.000…
1023
+ * { text: '0.001', marker: 'less' } → <¥0.001
1024
+ */
1025
+ function formatChipCost(units, format) {
1026
+ const fmt = format || FORMAT_DEFAULT
1027
+ if (!Number.isFinite(units) || units <= 0) {
1028
+ return { text: zeroText(fmt), marker: null }
1029
+ }
1030
+ const { rounded, whole, fraction } = splitDigits(units, fmt.decimals)
1031
+ if (rounded <= 0) {
1032
+ return fmt.tiny === 'less'
1033
+ ? { text: lessText(fmt), marker: 'less' }
1034
+ : { text: zeroText(fmt), marker: 'ellipsis' }
1035
+ }
1036
+ const separator = separatorOf(fmt)
1037
+ return {
1038
+ text: `${groupInteger(whole, fmt.groupSize, separator)}.${groupFraction(
1039
+ fraction,
1040
+ fmt.groupSize,
1041
+ separator,
1042
+ )}`,
1043
+ marker: null,
1044
+ }
1045
+ }
1046
+
1047
+ /** Full precision for the tooltip; keeps the chosen grouping, drops trailing zeros. */
1048
+ function formatExactCost(units, format) {
1049
+ const fmt = format || FORMAT_DEFAULT
1050
+ if (!Number.isFinite(units) || units <= 0) return '0'
1051
+ const whole = Math.trunc(units / 1e12)
1052
+ const fraction = trimFraction(String(units % 1e12).padStart(12, '0'))
1053
+ const separator = separatorOf(fmt)
1054
+ const grouped = groupInteger(String(whole), fmt.groupSize, separator)
1055
+ return fraction ? `${grouped}.${groupFraction(fraction, fmt.groupSize, separator)}` : grouped
1056
+ }
1057
+
1058
+ function exactTokens(value) {
1059
+ const tokens = Math.max(0, Math.round(value || 0))
1060
+ return String(tokens).replace(/\B(?=(\d{3})+(?!\d))/g, ',')
1061
+ }
1062
+
1063
+ function costReasonText(reason, t) {
1064
+ const keys = {
1065
+ route: 'costReasonRoute',
1066
+ cacheRead: 'costReasonCacheRead',
1067
+ unknownModel: 'costReasonUnknownModel',
1068
+ mixedModel: 'costReasonMixedModel',
1069
+ prices: 'costReasonPrices',
1070
+ time: 'costReasonTime',
1071
+ }
1072
+ return t(keys[reason] || 'costUnavailable')
1073
+ }
1074
+
1075
+ function costTooltip(result, t, format) {
1076
+ if (!result || result.unavailable) {
1077
+ return `${t('costEstimate')}\n${t('costUnavailable')}:${costReasonText(
1078
+ result && result.unavailable,
1079
+ t,
1080
+ )}`
1081
+ }
1082
+ const symbol = result.currency === 'USD' ? '$' : '¥'
1083
+ const period = result.period === 'peak' ? t('costPeak') : t('costOffPeak')
1084
+ const exact = (value) => formatExactCost(value, format)
1085
+ const lines = [
1086
+ `${t('costEstimate')} · ${period}`,
1087
+ `~${symbol}${exact(result.units)}`,
1088
+ `${t('costModel')} ${result.modelId}(${result.routes.map(routeLabel).join(', ')})`,
1089
+ ]
1090
+ const line = (label, tokens, price, lineUnits) =>
1091
+ `${label} ${exactTokens(tokens)} × ${symbol}${formatNumber(price)}/${t('costUnit')} = ${symbol}${exact(
1092
+ lineUnits,
1093
+ )}`
1094
+ lines.push(line(t('costUncached'), result.buckets.uncached, result.price.cacheMiss, result.buckets.uncached * Math.round(result.price.cacheMiss * 1e6)))
1095
+ lines.push(line(t('costCacheRead'), result.buckets.cacheRead, result.price.cacheHit, result.buckets.cacheRead * Math.round(result.price.cacheHit * 1e6)))
1096
+ lines.push(line(t('costOutput'), result.buckets.output, result.price.output, result.buckets.output * Math.round(result.price.output * 1e6)))
1097
+ lines.push(
1098
+ `${t('costSnapshot')} ${beijingStamp(result.fetchedAtMs)}${result.stale ? ` · ${t('costStale')}` : ''}`,
1099
+ )
1100
+ return lines.join('\n')
1101
+ }
1102
+
1103
+ /**
1104
+ * Compact cost line above a completed Turn's footer. It reads the Turn's
1105
+ * official usage from the Chat node data source, so nothing extra is
1106
+ * fetched or folded; the chip only mounts while its Turn is rendered.
1107
+ */
1108
+ function CostChip(props) {
1109
+ const { t, turn, seq, useChat } = props
1110
+ const [prefs] = useCostPrefs()
1111
+ const [currency] = useCurrency()
1112
+ const fromProp = turn && typeof turn.turn === 'number' ? turn.turn : null
1113
+ const fromSeq = useChat((chat) => findByEndSeq(chat.legacy && chat.legacy.turnEnds, seq))
1114
+ const turnNumber = fromProp !== null ? fromProp : fromSeq
1115
+ const tail = useChat((chat) => {
1116
+ if (turnNumber === null || turnNumber === undefined) return null
1117
+ if (!chat.nodes || typeof chat.nodes.turnDataSource !== 'function') return null
1118
+ const list = chat.nodes.turnDataSource(turnNumber, 'turn-tail').getSnapshot()
1119
+ return list.length > 0 ? list[0] : null
1120
+ })
1121
+ const enabled = Boolean(prefs.enabled && tail && tail.tokenUsage)
1122
+ const prices = useSharedPrice(enabled ? currency : null, enabled)
1123
+ if (!enabled) return null
1124
+ // No reading yet (first mount) shows nothing instead of a flashing "~".
1125
+ const priceState = prices && prices.state ? prices.state : null
1126
+ if (!priceState && !(prices && prices.error)) return null
1127
+ const result = computeTurnCost(tail, priceState, prefs)
1128
+ if (!result) return null
1129
+ const format = prefs.format
1130
+ const full = costTooltip(result, t, format)
1131
+ if (result.unavailable) {
1132
+ return h(
1133
+ 'div',
1134
+ { className: 'dp-cost' },
1135
+ h('span', { className: 'dp-cost-chip', title: full, 'aria-label': full }, '~'),
1136
+ )
1137
+ }
1138
+ const symbol = result.currency === 'USD' ? '$' : '¥'
1139
+ const cost = formatChipCost(result.units, format)
1140
+ const text =
1141
+ cost.marker === 'less'
1142
+ ? `<${symbol}${cost.text}`
1143
+ : `~${symbol}${cost.text}${cost.marker === 'ellipsis' ? '…' : ''}`
1144
+ return h(
1145
+ 'div',
1146
+ { className: 'dp-cost' },
1147
+ h('span', { className: 'dp-cost-chip', title: full, 'aria-label': full }, text),
1148
+ )
1149
+ }
1150
+
1151
+ /* --------------------------------------------------------------------- */
1152
+ /* feature switches */
1153
+ /* --------------------------------------------------------------------- */
1154
+
1155
+ const REFRESH_CHOICES = [0, 15, 30, 60, 120, 360, 720]
1156
+
1157
+ /**
1158
+ * Mirror of the Host's writable subset. Kept as a pure function so the
1159
+ * browser validates before asking the Host to rewrite the profile patch,
1160
+ * and so the Node tests can pin the contract.
1161
+ */
1162
+ function sanitizeConfigPatch(raw) {
1163
+ const source = raw && typeof raw === 'object' ? raw : {}
1164
+ const patch = {}
1165
+ if (typeof source.tool === 'boolean') patch.tool = source.tool
1166
+ if (typeof source.holidayRefresh === 'boolean') patch.holidayRefresh = source.holidayRefresh
1167
+ if (source.refreshMinutes !== undefined && source.refreshMinutes !== null) {
1168
+ const number = Number(source.refreshMinutes)
1169
+ if (Number.isFinite(number)) {
1170
+ patch.refreshMinutes = Math.min(1440, Math.max(0, Math.round(number)))
1171
+ }
1172
+ }
1173
+ return patch
1174
+ }
1175
+
1176
+ /**
1177
+ * The plugin detail page hands each section its page subject. Loader builds
1178
+ * differ in whether a bundle page carries `pkg.name`, a row page carries
1179
+ * `entry.id`, or both, so accept every shape we know and stay silent when
1180
+ * none matches: a section that renders nothing is harmless, a section that
1181
+ * throws would take the page down.
1182
+ */
1183
+ function isOwnPluginSubject(subject) {
1184
+ if (!subject || typeof subject !== 'object') return false
1185
+ const entry = subject.entry || subject.row || null
1186
+ const options = (entry && entry.options) || {}
1187
+ const ids = [subject.id, subject.patchId, entry && entry.id, options.id]
1188
+ if (ids.includes(ROW_ID)) return true
1189
+ const bundle = subject.bundle || null
1190
+ const pkg = subject.pkg || subject.package || null
1191
+ const names = [
1192
+ subject.name,
1193
+ subject.pkgName,
1194
+ pkg && pkg.name,
1195
+ bundle && bundle.name,
1196
+ entry && entry.name,
1197
+ options.name,
1198
+ ]
1199
+ return names.includes(PKG)
1200
+ }
1201
+
1202
+ async function postHostConfig(patch) {
1203
+ const response = await fetch(API_CONFIG, {
1204
+ method: 'POST',
1205
+ headers: { 'content-type': 'application/json' },
1206
+ body: JSON.stringify(patch),
1207
+ cache: 'no-store',
1208
+ })
1209
+ const payload = await response.json().catch(() => null)
1210
+ if (!response.ok || !payload || payload.ok !== true) {
1211
+ throw new Error((payload && payload.error) || `HTTP ${response.status}`)
1212
+ }
1213
+ return payload
1214
+ }
1215
+
1216
+ /**
1217
+ * A Host-side switch is not a checkbox: the Host rewrites the profile patch
1218
+ * and DSH reloads this plugin row, so the write is fire-and-read. The row
1219
+ * answers 202 immediately and the panel re-reads /state after the reload
1220
+ * instead of flipping local state that may never have been persisted.
1221
+ */
1222
+ function useHostSwitch(onSaved) {
1223
+ const [pending, setPending] = useState(false)
1224
+ const [error, setError] = useState(null)
1225
+ const timers = useRef([])
1226
+ const later = (fn, ms) => {
1227
+ timers.current.push(setTimeout(fn, ms))
1228
+ }
1229
+ useEffect(
1230
+ () => () => {
1231
+ for (const id of timers.current) clearTimeout(id)
1232
+ timers.current = []
1233
+ },
1234
+ [],
1235
+ )
1236
+ const save = useCallback(
1237
+ async (patch) => {
1238
+ const clean = sanitizeConfigPatch(patch)
1239
+ if (Object.keys(clean).length === 0) return
1240
+ setError(null)
1241
+ setPending(true)
1242
+ try {
1243
+ await postHostConfig(clean)
1244
+ later(() => {
1245
+ setPending(false)
1246
+ if (onSaved) onSaved()
1247
+ }, 1200)
1248
+ later(() => {
1249
+ if (onSaved) onSaved()
1250
+ }, 3000)
1251
+ } catch (failure) {
1252
+ setPending(false)
1253
+ setError(describeError(failure))
1254
+ }
1255
+ },
1256
+ [onSaved],
1257
+ )
1258
+ return { pending, error, save }
1259
+ }
1260
+
1261
+ function OptionRow(props) {
1262
+ const { id, title, hint, checked, disabled, busy, tag, onChange } = props
1263
+ return h(
1264
+ 'label',
1265
+ { className: `dp-opt${busy ? ' is-busy' : ''}`, htmlFor: id },
1266
+ h('input', {
1267
+ id,
1268
+ type: 'checkbox',
1269
+ checked: checked === true,
1270
+ disabled: disabled === true,
1271
+ onChange: (event) => onChange(event.target.checked),
1272
+ }),
1273
+ h(
1274
+ 'span',
1275
+ { className: 'dp-opt-body' },
1276
+ h('span', { className: 'dp-opt-title' }, title),
1277
+ hint ? h('span', { className: 'dp-opt-hint' }, hint) : null,
1278
+ ),
1279
+ tag ? h('span', { className: 'dp-opt-tag' }, tag) : null,
1280
+ )
1281
+ }
1282
+
1283
+ function RefreshRow(props) {
1284
+ const { t, value, disabled, onChange } = props
1285
+ const choices = REFRESH_CHOICES.includes(value)
1286
+ ? REFRESH_CHOICES
1287
+ : REFRESH_CHOICES.concat([value]).sort((a, b) => a - b)
1288
+ return h(
1289
+ 'div',
1290
+ { className: 'dp-inline' },
1291
+ h(
1292
+ 'span',
1293
+ { className: 'dp-inline-text' },
1294
+ h('span', { className: 'dp-opt-title' }, t('featRefresh')),
1295
+ h('span', { className: 'dp-opt-hint' }, t('featRefreshHint')),
1296
+ ),
1297
+ h(
1298
+ 'select',
1299
+ {
1300
+ className: 'dp-input',
1301
+ value: String(value),
1302
+ disabled: disabled === true,
1303
+ 'aria-label': t('featRefresh'),
1304
+ onChange: (event) => onChange(Number(event.target.value)),
1305
+ },
1306
+ choices.map((minutes) =>
1307
+ h(
1308
+ 'option',
1309
+ { key: minutes, value: String(minutes) },
1310
+ minutes === 0 ? t('manualOnly') : `${minutes} ${t('minutes')}`,
1311
+ ),
1312
+ ),
1313
+ ),
1314
+ )
1315
+ }
1316
+
1317
+ function FeatureBoard(props) {
1318
+ const { t, state } = props
1319
+ const [prefs, updatePrefs] = useCostPrefs()
1320
+ const config = (state && state.data && state.data.config) || null
1321
+ const { pending, error, save } = useHostSwitch(state.reload)
1322
+ const busy = !config || pending
1323
+
1324
+ return h(
1325
+ 'div',
1326
+ { className: 'dp-card' },
1327
+ h('h3', { className: 'dp-card-title' }, t('featTitle')),
1328
+ h('p', { className: 'dp-footnote', style: { margin: '0 0 4px' } }, t('featIntro')),
1329
+ h(OptionRow, {
1330
+ id: 'dp-opt-cost',
1331
+ title: t('featCost'),
1332
+ hint: t('featCostHint'),
1333
+ tag: t('featLocalTag'),
1334
+ checked: prefs.enabled,
1335
+ onChange: (checked) => updatePrefs({ ...prefs, enabled: checked }),
1336
+ }),
1337
+ h(OptionRow, {
1338
+ id: 'dp-opt-tool',
1339
+ title: t('featTool'),
1340
+ hint: t('featToolHint'),
1341
+ tag: t('featReloadTag'),
1342
+ checked: config && config.tool === true,
1343
+ disabled: busy,
1344
+ busy: pending,
1345
+ onChange: (checked) => save({ tool: checked }),
1346
+ }),
1347
+ h(OptionRow, {
1348
+ id: 'dp-opt-holiday',
1349
+ title: t('featHoliday'),
1350
+ hint: t('featHolidayHint'),
1351
+ tag: t('featReloadTag'),
1352
+ checked: config && config.holidayRefresh !== false,
1353
+ disabled: busy,
1354
+ busy: pending,
1355
+ onChange: (checked) => save({ holidayRefresh: checked }),
1356
+ }),
1357
+ h(RefreshRow, {
1358
+ t,
1359
+ value: config ? config.refreshMinutes : 0,
1360
+ disabled: busy,
1361
+ onChange: (minutes) => save({ refreshMinutes: minutes }),
1362
+ }),
1363
+ pending ? h('p', { className: 'dp-status is-busy' }, t('featSaving')) : null,
1364
+ error ? h('p', { className: 'dp-status is-error' }, `${t('featFailed')}${error}`) : null,
1365
+ )
1366
+ }
1367
+
1368
+ function DetailCardBody(props) {
1369
+ const { t } = props
1370
+ const [currency] = useCurrency()
1371
+ const state = usePricing(currency)
1372
+ const [prefs, updatePrefs] = useCostPrefs()
1373
+ const config = state.data && state.data.config
1374
+ const { pending, error, save } = useHostSwitch(state.reload)
1375
+ const busy = !config || pending
1376
+
1377
+ return h(
1378
+ 'div',
1379
+ { className: 'dp-detail' },
1380
+ h('h3', { className: 'dp-card-title' }, t('detailTitle')),
1381
+ h('p', { className: 'dp-footnote', style: { margin: '0 0 4px' } }, t('detailIntro')),
1382
+ h(OptionRow, {
1383
+ id: 'dp-detail-cost',
1384
+ title: t('featCost'),
1385
+ hint: t('costHint'),
1386
+ tag: t('featLocalTag'),
1387
+ checked: prefs.enabled,
1388
+ onChange: (checked) => updatePrefs({ ...prefs, enabled: checked }),
1389
+ }),
1390
+ h(OptionRow, {
1391
+ id: 'dp-detail-tool',
1392
+ title: t('featTool'),
1393
+ hint: t('featToolHint'),
1394
+ tag: t('featReloadTag'),
1395
+ checked: config && config.tool === true,
1396
+ disabled: busy,
1397
+ busy: pending,
1398
+ onChange: (checked) => save({ tool: checked }),
1399
+ }),
1400
+ pending ? h('p', { className: 'dp-status is-busy' }, t('featSaving')) : null,
1401
+ error ? h('p', { className: 'dp-status is-error' }, `${t('featFailed')}${error}`) : null,
1402
+ )
1403
+ }
1404
+
1405
+ /** Hooks stay in the body so an unowned page can return null before them. */
1406
+ function PluginDetailCard(props) {
1407
+ const { t, subject } = props
1408
+ if (!isOwnPluginSubject(subject)) return null
1409
+ return h(DetailCardBody, { t })
1410
+ }
1411
+
1412
+ /**
1413
+ * Uninstall notes live on the plugin page (right where the uninstall control
1414
+ * is) rather than in the settings page, and they are phrased as optional:
1415
+ * every item below is harmless to leave behind, so nobody should feel that
1416
+ * uninstalling requires housekeeping first.
1417
+ */
1418
+ function UninstallNotes(props) {
1419
+ const { t, subject } = props
1420
+ if (!isOwnPluginSubject(subject)) return null
1421
+ const item = (key, label, action) =>
1422
+ h(
1423
+ 'li',
1424
+ { key },
1425
+ h('span', { className: 'dp-opt-title' }, label),
1426
+ h('span', { className: 'dp-notes-action' }, action),
1427
+ )
1428
+ return h(
1429
+ 'div',
1430
+ { className: 'dp-detail' },
1431
+ h('h3', { className: 'dp-card-title' }, t('uninstallTitle')),
1432
+ h('p', { className: 'dp-footnote', style: { margin: '0 0 6px' } }, t('uninstallIntro')),
1433
+ h(
1434
+ 'ul',
1435
+ { className: 'dp-notes' },
1436
+ item('local', t('uninstallLocal'), t('uninstallLocalAction')),
1437
+ item('row', t('uninstallRow'), t('uninstallRowAction')),
1438
+ item('pnpm', t('uninstallPnpm'), t('uninstallPnpmAction')),
1439
+ item('cache', t('uninstallCache'), t('uninstallCacheAction')),
1440
+ ),
1441
+ )
1442
+ }
1443
+
1444
+ function CostSettingsCard(props) {
1445
+ const { t } = props
1446
+ const [prefs, updatePrefs] = useCostPrefs()
1447
+ const mappings = prefs.mappings
1448
+ const rows = mappings.map((row, index) => {
1449
+ const detected = row.model === '' ? detectPriceModel(row.route) : null
1450
+ const detectedLabel =
1451
+ row.model === 'ignore'
1452
+ ? t('costIgnore')
1453
+ : row.model === 'flash'
1454
+ ? 'flash'
1455
+ : row.model === 'pro'
1456
+ ? 'pro'
1457
+ : detected || t('costDetectedNone')
1458
+ const updateRow = (patch) => {
1459
+ const next = mappings.slice()
1460
+ next[index] = { ...row, ...patch }
1461
+ updatePrefs({ ...prefs, mappings: next })
1462
+ }
1463
+ return h(
1464
+ 'div',
1465
+ { key: index, className: 'dp-map-row' },
1466
+ h('input', {
1467
+ className: 'dp-input',
1468
+ value: row.route,
1469
+ placeholder: 'provider/model',
1470
+ 'aria-label': t('costMappingHint'),
1471
+ onChange: (event) => updateRow({ route: event.target.value }),
1472
+ }),
1473
+ h('span', { className: 'dp-muted dp-small' }, detectedLabel),
1474
+ h(
1475
+ 'select',
1476
+ {
1477
+ className: 'dp-input',
1478
+ value: row.model,
1479
+ 'aria-label': t('costAuto'),
1480
+ onChange: (event) => updateRow({ model: event.target.value }),
1481
+ },
1482
+ h('option', { value: '' }, t('costAuto')),
1483
+ h('option', { value: 'flash' }, 'flash'),
1484
+ h('option', { value: 'pro' }, 'pro'),
1485
+ h('option', { value: 'ignore' }, t('costIgnore')),
1486
+ ),
1487
+ h(
1488
+ 'button',
1489
+ {
1490
+ type: 'button',
1491
+ className: 'dp-btn',
1492
+ onClick: () =>
1493
+ updatePrefs({ ...prefs, mappings: mappings.filter((_, i) => i !== index) }),
1494
+ },
1495
+ t('costRemove'),
1496
+ ),
1497
+ )
1498
+ })
1499
+ return h(
1500
+ 'div',
1501
+ { className: 'dp-subblock' },
1502
+ h('h4', { className: 'dp-subtitle' }, t('costMappingSection')),
1503
+ h('p', { className: 'dp-footnote', style: { margin: '0 0 6px' } }, t('costMappingHint')),
1504
+ rows,
1505
+ h(
1506
+ 'div',
1507
+ { className: 'dp-btn-row', style: { marginTop: 8 } },
1508
+ h(
1509
+ 'button',
1510
+ {
1511
+ type: 'button',
1512
+ className: 'dp-btn',
1513
+ onClick: () =>
1514
+ updatePrefs({ ...prefs, mappings: [...mappings, { route: '', model: '' }] }),
1515
+ },
1516
+ t('costAddRow'),
1517
+ ),
1518
+ ),
1519
+ )
1520
+ }
1521
+
1522
+ function NumberFormatCard(props) {
1523
+ const { t, currency } = props
1524
+ const [prefs, updatePrefs] = useCostPrefs()
1525
+ const format = prefs.format
1526
+ const setFormat = (patch) => updatePrefs({ ...prefs, format: { ...format, ...patch } })
1527
+ const symbol = currency === 'USD' ? '$' : '¥'
1528
+ const separator = separatorOf(format)
1529
+ const grouped = separator !== ''
1530
+
1531
+ const sampleNormal = formatChipCost(1234567890000000, format)
1532
+ const sampleTiny = formatChipCost(400000, format)
1533
+ const normalText = `~${symbol}${sampleNormal.text}`
1534
+ const tinyText =
1535
+ sampleTiny.marker === 'less'
1536
+ ? `<${symbol}${sampleTiny.text}`
1537
+ : `~${symbol}${sampleTiny.text}…`
1538
+
1539
+ const separatorOptions = SEPARATOR_IDS.map((id) =>
1540
+ h(
1541
+ 'option',
1542
+ { key: id, value: id },
1543
+ `${t(`sep${id.charAt(0).toUpperCase()}${id.slice(1)}`)}(${groupInteger(
1544
+ '1234567',
1545
+ format.groupSize,
1546
+ SEPARATOR_CHARS[id],
1547
+ )})`,
1548
+ ),
1549
+ )
1550
+
1551
+ const decimalsOptions = []
1552
+ for (let value = 1; value <= 8; value += 1) {
1553
+ decimalsOptions.push(h('option', { key: value, value: String(value) }, `${value}`))
1554
+ }
1555
+
1556
+ const tinyOptions = [
1557
+ h('option', { key: 'ellipsis', value: 'ellipsis' }, `~${symbol}${zeroText(format)}…`),
1558
+ h('option', { key: 'less', value: 'less' }, `<${symbol}${lessText(format)}`),
1559
+ ]
1560
+
1561
+ const groupButtons = [
1562
+ [3, t('numberGroup3')],
1563
+ [4, t('numberGroup4')],
1564
+ ].map(([size, label]) =>
1565
+ h(
1566
+ 'button',
1567
+ {
1568
+ key: size,
1569
+ type: 'button',
1570
+ className: format.groupSize === size ? 'is-on' : '',
1571
+ 'aria-pressed': format.groupSize === size,
1572
+ disabled: !grouped,
1573
+ onClick: () => setFormat({ groupSize: size }),
1574
+ },
1575
+ label,
1576
+ ),
1577
+ )
1578
+
1579
+ return h(
1580
+ 'div',
1581
+ { className: 'dp-subblock' },
1582
+ h('h4', { className: 'dp-subtitle' }, t('numberSection')),
1583
+ h('p', { className: 'dp-footnote', style: { margin: '0 0 6px' } }, t('numberIntro')),
1584
+ h(
1585
+ 'div',
1586
+ { className: 'dp-inline' },
1587
+ h(
1588
+ 'span',
1589
+ { className: 'dp-inline-text' },
1590
+ h('span', { className: 'dp-opt-title' }, t('numberSeparator')),
1591
+ ),
1592
+ h(
1593
+ 'select',
1594
+ {
1595
+ className: 'dp-input',
1596
+ value: format.separator,
1597
+ 'aria-label': t('numberSeparator'),
1598
+ onChange: (event) => setFormat({ separator: event.target.value }),
1599
+ },
1600
+ separatorOptions,
1601
+ ),
1602
+ ),
1603
+ h(
1604
+ 'div',
1605
+ { className: 'dp-inline' },
1606
+ h(
1607
+ 'span',
1608
+ { className: 'dp-inline-text' },
1609
+ h('span', { className: 'dp-opt-title' }, t('numberGroup')),
1610
+ h('span', { className: 'dp-opt-hint' }, t('numberGroupHint')),
1611
+ ),
1612
+ h('span', { className: 'dp-seg', role: 'group', 'aria-label': t('numberGroup') }, groupButtons),
1613
+ ),
1614
+ h(
1615
+ 'div',
1616
+ { className: 'dp-inline' },
1617
+ h(
1618
+ 'span',
1619
+ { className: 'dp-inline-text' },
1620
+ h('span', { className: 'dp-opt-title' }, t('numberDecimals')),
1621
+ h('span', { className: 'dp-opt-hint' }, t('numberDecimalsHint')),
1622
+ ),
1623
+ h(
1624
+ 'select',
1625
+ {
1626
+ className: 'dp-input',
1627
+ value: String(format.decimals),
1628
+ 'aria-label': t('numberDecimals'),
1629
+ onChange: (event) => setFormat({ decimals: Number(event.target.value) }),
1630
+ },
1631
+ decimalsOptions,
1632
+ ),
1633
+ ),
1634
+ h(
1635
+ 'div',
1636
+ { className: 'dp-inline' },
1637
+ h(
1638
+ 'span',
1639
+ { className: 'dp-inline-text' },
1640
+ h('span', { className: 'dp-opt-title' }, t('numberTiny')),
1641
+ h('span', { className: 'dp-opt-hint' }, t('numberTinyHint')),
1642
+ ),
1643
+ h(
1644
+ 'select',
1645
+ {
1646
+ className: 'dp-input',
1647
+ value: format.tiny,
1648
+ 'aria-label': t('numberTiny'),
1649
+ onChange: (event) => setFormat({ tiny: event.target.value }),
1650
+ },
1651
+ tinyOptions,
1652
+ ),
1653
+ ),
1654
+ h(
1655
+ 'div',
1656
+ { className: 'dp-preview' },
1657
+ h('span', { className: 'dp-muted' }, `${t('numberPreview')}:`),
1658
+ h('span', null, normalText),
1659
+ h('span', { className: 'dp-muted' }, '·'),
1660
+ h('span', null, tinyText),
1661
+ ),
1662
+ )
1663
+ }
1664
+
1665
+ /**
1666
+ * One card, two sub-blocks: the mapping table and the number format share
1667
+ * a single home so the cost settings read as one feature, not two.
1668
+ */
1669
+ function CostEstimateCard(props) {
1670
+ const { t, currency } = props
1671
+ return h(
1672
+ 'div',
1673
+ { className: 'dp-card' },
1674
+ h('h3', { className: 'dp-card-title' }, t('costTitle')),
1675
+ h(CostSettingsCard, { t }),
1676
+ h(NumberFormatCard, { t, currency }),
1677
+ h(
1678
+ 'div',
1679
+ { className: 'dp-btn-row', style: { marginTop: 12 } },
1680
+ h(
1681
+ 'button',
1682
+ { type: 'button', className: 'dp-btn', onClick: () => clearLocalSettings() },
1683
+ t('costClear'),
1684
+ ),
1685
+ ),
1686
+ h('p', { className: 'dp-footnote', style: { marginTop: 6 } }, t('costLocalOnly')),
1687
+ )
1688
+ }
1689
+
451
1690
  /* --------------------------------------------------------------------- */
452
1691
  /* rendering pieces */
453
1692
  /* --------------------------------------------------------------------- */
@@ -949,16 +2188,25 @@ window.__ModuleLoader__.load({
949
2188
  const statusText =
950
2189
  entry.status === 'fresh'
951
2190
  ? t('holidaysSynced')
952
- : entry.status === 'snapshot'
953
- ? t('holidaysSnapshot')
954
- : entry.status === 'unpublished'
955
- ? t('holidaysUnpublished')
956
- : t('holidaysFailed')
957
- const tone =
958
- entry.status === 'fresh' ? 'is-fresh' : entry.status === 'snapshot' || entry.status === 'unpublished' ? 'is-warn' : 'is-warn'
2191
+ : entry.status === 'stale'
2192
+ ? t('holidaysStale')
2193
+ : entry.status === 'cached'
2194
+ ? t('holidaysCached')
2195
+ : entry.status === 'snapshot'
2196
+ ? t('holidaysSnapshot')
2197
+ : entry.status === 'pending'
2198
+ ? t('holidaysPending')
2199
+ : entry.status === 'unpublished'
2200
+ ? t('holidaysUnpublished')
2201
+ : t('holidaysFailed')
2202
+ const tone = entry.status === 'fresh' ? 'is-fresh' : 'is-warn'
2203
+ const details = [`${entry.year} ${statusText}`]
2204
+ if (entry.source) details.push(entry.source)
2205
+ if (entry.updatedAtMs) details.push(`${t('updated')} ${beijingClock(entry.updatedAtMs)}`)
2206
+ if (entry.error) details.push(entry.error)
959
2207
  return h(
960
2208
  'span',
961
- { key: entry.year, className: `dp-year ${tone}` },
2209
+ { key: entry.year, className: `dp-year ${tone}`, title: details.join(' · ') },
962
2210
  h('span', null, `${entry.year}`),
963
2211
  h('span', { className: 'dp-year-status' }, statusText),
964
2212
  )
@@ -1018,23 +2266,6 @@ window.__ModuleLoader__.load({
1018
2266
  data ? warningsBlock(data, t) : null,
1019
2267
  )
1020
2268
 
1021
- const toolCard = h(
1022
- 'div',
1023
- { className: 'dp-card' },
1024
- h(
1025
- 'h3',
1026
- { className: 'dp-card-title' },
1027
- t('toolTitle'),
1028
- h('span', { className: 'dp-muted dp-small' }, data && data.config.tool ? t('toolOn') : t('toolOff')),
1029
- ),
1030
- h('p', { className: 'dp-footnote', style: { margin: 0 } }, t('toolHint')),
1031
- h(
1032
- 'pre',
1033
- { className: 'dp-code' },
1034
- '- id: deepseek-pricing\n name: dsh-deepseek-pricing\n config:\n tool: true',
1035
- ),
1036
- )
1037
-
1038
2269
  return h(
1039
2270
  'section',
1040
2271
  { className: 'dp-section', 'aria-label': t('section') },
@@ -1044,8 +2275,9 @@ window.__ModuleLoader__.load({
1044
2275
  hero,
1045
2276
  scheduleCard,
1046
2277
  priceCard,
2278
+ h(FeatureBoard, { t, state }),
2279
+ h(CostEstimateCard, { t, currency: activeCurrency }),
1047
2280
  dataCard,
1048
- toolCard,
1049
2281
  h('p', { className: 'dp-footnote' }, t('footnote')),
1050
2282
  )
1051
2283
  }
@@ -1089,6 +2321,21 @@ window.__ModuleLoader__.load({
1089
2321
  'deepseek-pricing: composer chip',
1090
2322
  )
1091
2323
 
2324
+ ctx.effect(
2325
+ () =>
2326
+ ctx.slots.inject('conversation.chat.turnTail', () =>
2327
+ ctx.slots.register(
2328
+ {
2329
+ name: 'conversation.chat.turnTail',
2330
+ id: 'deepseek-pricing-cost',
2331
+ order: 90,
2332
+ },
2333
+ (props) => h(CostChip, { ...props, t }),
2334
+ ),
2335
+ ),
2336
+ 'deepseek-pricing: turn cost',
2337
+ )
2338
+
1092
2339
  ctx.effect(
1093
2340
  () =>
1094
2341
  ctx.slots.inject('settings.section', () =>
@@ -1105,8 +2352,63 @@ window.__ModuleLoader__.load({
1105
2352
  ),
1106
2353
  'deepseek-pricing: settings section',
1107
2354
  )
2355
+
2356
+ // The plugin's own page under Settings → Plugins: the same switches the
2357
+ // dedicated page owns, minus the ones that need room. The slot exists on
2358
+ // both a bundle page and a row page; the card renders null for every
2359
+ // subject that is not this plugin.
2360
+ ctx.effect(
2361
+ () =>
2362
+ ctx.slots.inject('plugins.detail.section', () =>
2363
+ ctx.slots.register(
2364
+ {
2365
+ name: 'plugins.detail.section',
2366
+ id: 'deepseek-pricing-switches',
2367
+ order: 80,
2368
+ locale: NS,
2369
+ },
2370
+ (props) => h(PluginDetailCard, { ...props, t }),
2371
+ ),
2372
+ ),
2373
+ 'deepseek-pricing: plugin page switches',
2374
+ )
2375
+
2376
+ ctx.effect(
2377
+ () =>
2378
+ ctx.slots.inject('plugins.detail.section', () =>
2379
+ ctx.slots.register(
2380
+ {
2381
+ name: 'plugins.detail.section',
2382
+ id: 'deepseek-pricing-uninstall',
2383
+ order: 90,
2384
+ locale: NS,
2385
+ },
2386
+ (props) => h(UninstallNotes, { ...props, t }),
2387
+ ),
2388
+ ),
2389
+ 'deepseek-pricing: uninstall notes',
2390
+ )
1108
2391
  }
1109
2392
 
1110
- return { inject, apply }
2393
+ return {
2394
+ inject,
2395
+ apply,
2396
+ // Pure cost helpers, used by the Node tests; the loader ignores extras.
2397
+ __test: {
2398
+ detectPriceModel,
2399
+ classifyPeakAt,
2400
+ computeTurnCost,
2401
+ formatChipCost,
2402
+ formatExactCost,
2403
+ groupInteger,
2404
+ groupFraction,
2405
+ sanitizeFormat,
2406
+ sanitizeCostPrefs,
2407
+ sanitizeConfigPatch,
2408
+ isOwnPluginSubject,
2409
+ FORMAT_DEFAULT,
2410
+ SEPARATOR_CHARS,
2411
+ },
2412
+ }
1111
2413
  },
1112
2414
  })