dsh-tokenlens 1.7.2 → 1.7.3

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
@@ -4,6 +4,15 @@
4
4
 
5
5
  **版本记录约定**:同一发布日只保留一个章节,标题取当日**最后一个**已发布版本号;当日多次发布的改动合并到该章节,并在标题下注明当日实际发布过的版本号(npm 上仍可安装这些独立版本)。若当日已有发布,后续小改动不再单独增加版本号,而是并入下一篇日志。这样日志按天规整、不出现同日多个小版本。
6
6
 
7
+ ## 1.7.3 — 2026-11-06
8
+
9
+ (当日已发布版本:v1.6.5 / v1.6.6 / v1.6.7 / v1.7.0 / v1.7.1 / v1.7.2 / v1.7.3)
10
+
11
+ - **fix(commandcode): 本月百分比改回按额度池计算**——v1.7.2 按「所选模型的额度」当分母(GOAT + DeepSeek V4.1 Flash = $100),但控制台自己的每月限额是按**额度池**算的。同一笔 $2.94 消费:`2.94 / 70 = 4.2%`(控制台显示 4%),`2.94 / 100 = 2.9%`(v1.7.2 显示 2.9%)——所以那一版与你在控制台看到的数对不上。现在分母回到额度池,实机读数 `$2.96 / $70.00 · 4.23%`,与控制台一致
12
+ - **feat(commandcode): 模型额度改为参考信息**——$100 不是分母,而是「该模型折扣后能覆盖多少消费」。控制台有这张按模型表(`assets/plan-tiers-*.js`,已转录到 `lib/commandcode-plans.mjs`),插件把当前模型的等效额度作为一行带标签的补充信息显示,并说明「控制台按额度池计百分比」,不再悄悄替换分母
13
+ - 同步修正测试:改用实机真值(剩余 `67.087370791` + 本期消费 `2.912629209` = 额度池 `70.000000000`)而不是自造数,并断言**切换模型不会移动仪表指针**
14
+ - 测试:369 → 370
15
+
7
16
  ## 1.7.2 — 2026-11-06
8
17
 
9
18
  (当日已发布版本:v1.6.5 / v1.6.6 / v1.6.7 / v1.7.0 / v1.7.1 / v1.7.2)
package/README.en.md CHANGED
@@ -144,7 +144,7 @@ Host bridge route: `/api/tokenlens`; agent tool: `tokenlens_usage`.
144
144
 
145
145
  ## Development
146
146
 
147
- Node.js ≥ 24, zero runtime dependencies: `node --test` runs the 369 tests.
147
+ Node.js ≥ 24, zero runtime dependencies: `node --test` runs the 370 tests.
148
148
 
149
149
  Release: `node scripts/bump-version.mjs <version> "<note>"` updates `package.json`, `PLUGIN_VERSION` and `CHANGELOG.md`; see [CONTRIBUTING.md](CONTRIBUTING.md) and [SECURITY.md](SECURITY.md).
150
150
 
package/README.md CHANGED
@@ -445,7 +445,7 @@ Host 半注册 `tokenlens_usage`,参数 `action`(默认 `snapshot`)与可
445
445
 
446
446
  ## 验证
447
447
 
448
- - `node --test`:**369 个自动化用例**,覆盖 Host 数据层、供应商适配器(含小米 MiMo 控制台 Cookie 适配器、Command Code 月度额度反推)、统计折叠、各 harness 读取、Design Plan 周期账本与额度计价、TPS 速度序列、窗口锚点切片、工作区自动识别、插件集成与浏览器端渲染 / 交互。
448
+ - `node --test`:**370 个自动化用例**,覆盖 Host 数据层、供应商适配器(含小米 MiMo 控制台 Cookie 适配器、Command Code 月度额度反推)、统计折叠、各 harness 读取、Design Plan 周期账本与额度计价、TPS 速度序列、窗口锚点切片、工作区自动识别、插件集成与浏览器端渲染 / 交互。
449
449
  - 在真实环境中验证过 **5 个 harness** 的数据源;本机统计与独立的 SQLite 查询、独立的日志解析逐项对账(差额为 0),跨 harness 合并与供应商映射算术自洽。
450
450
  - 供应商接口按各官方文档与参考客户端行为验证;未配置凭据时 chip 静默隐藏,接口异常时按可重试错误降级。
451
451
 
package/client.js CHANGED
@@ -199,6 +199,9 @@ window.__ModuleLoader__.load({
199
199
  balanceBonus: '奖励:{amounts}',
200
200
  creditsRemaining: '剩余 {amount}',
201
201
  creditsGranted: '本月额度 {amount}',
202
+ creditsModelAllowance: '{model} 等效额度 {amount}',
203
+ creditsModelAllowanceModel: '当前模型',
204
+ creditsModelAllowanceHint: '控制台的每月百分比按额度池计算;等效额度是该模型折扣后能覆盖的消费额',
202
205
  creditsPurchased: '加购 {amount}',
203
206
  refresh: '刷新',
204
207
  refreshing: '正在刷新…',
@@ -475,6 +478,10 @@ window.__ModuleLoader__.load({
475
478
  balanceBonus: 'Bonus: {amounts}',
476
479
  creditsRemaining: 'Remaining {amount}',
477
480
  creditsGranted: 'Granted {amount}',
481
+ creditsModelAllowance: '{model} equivalent {amount}',
482
+ creditsModelAllowanceModel: 'current model',
483
+ creditsModelAllowanceHint:
484
+ 'The console computes its monthly percentage from the credit pool; the equivalent allowance is what a discounted model can cover',
478
485
  creditsPurchased: 'Purchased {amount}',
479
486
  refresh: 'Refresh',
480
487
  refreshing: 'Refreshing…',
@@ -1096,6 +1103,13 @@ window.__ModuleLoader__.load({
1096
1103
  remaining: numberOrNull(raw.remaining),
1097
1104
  granted: numberOrNull(raw.granted),
1098
1105
  purchased: numberOrNull(raw.purchased),
1106
+ // v1.7.3: the per-model allowance is ADVERTISING, not the meter's
1107
+ // denominator — the console measures the monthly percentage against the
1108
+ // credit pool. It is kept only so the card can explain the difference.
1109
+ poolUsd: numberOrNull(raw.poolUsd),
1110
+ allowanceUsd: numberOrNull(raw.allowanceUsd),
1111
+ allowanceModel: typeof raw.allowanceModel === 'string' && raw.allowanceModel !== '' ? raw.allowanceModel : null,
1112
+ allowanceBasis: typeof raw.allowanceBasis === 'string' ? raw.allowanceBasis : null,
1099
1113
  }
1100
1114
  if (credits.remaining === null && credits.granted === null && credits.purchased === null) return null
1101
1115
  return credits
@@ -4369,6 +4383,31 @@ window.__ModuleLoader__.load({
4369
4383
  h('span', { key: 'purchased' }, t('creditsPurchased', { amount: formatMoney(credits.purchased, 'USD') })),
4370
4384
  )
4371
4385
  }
4386
+ // v1.7.3: the console advertises a larger allowance for discounted models
4387
+ // (DeepSeek V4.1 Flash: $100 on a $70 pool) but still prints the monthly
4388
+ // percentage against the POOL. Say so instead of silently disagreeing.
4389
+ if (
4390
+ credits.allowanceUsd !== null &&
4391
+ credits.granted !== null &&
4392
+ Math.abs(credits.allowanceUsd - credits.granted) > 0.005
4393
+ ) {
4394
+ const modelLabel = String(credits.allowanceModel ?? '').replace(/^[^/]+\//, '')
4395
+ parts.push(
4396
+ h(
4397
+ 'span',
4398
+ {
4399
+ key: 'allowance',
4400
+ className: 'dsh-tokenlens-credits-allowance',
4401
+ 'data-model-allowance': String(credits.allowanceUsd),
4402
+ title: t('creditsModelAllowanceHint'),
4403
+ },
4404
+ t('creditsModelAllowance', {
4405
+ model: modelLabel === '' ? t('creditsModelAllowanceModel') : modelLabel,
4406
+ amount: formatMoney(credits.allowanceUsd, 'USD'),
4407
+ }),
4408
+ ),
4409
+ )
4410
+ }
4372
4411
  if (parts.length === 0) return null
4373
4412
  return h('div', { key: 'credits', className: 'dsh-tokenlens-credits' }, parts)
4374
4413
  }
package/index.js CHANGED
@@ -84,7 +84,7 @@ export const inject = []
84
84
  export const PLUGIN_NAME = 'dsh-tokenlens'
85
85
 
86
86
  /** Plugin version; mirrors package.json (kept here so diagnostics need no fs read). */
87
- export const PLUGIN_VERSION = '1.7.2'
87
+ export const PLUGIN_VERSION = '1.7.3'
88
88
 
89
89
  /** Documented defaults; every field of the raw row config is optional. */
90
90
  const DEFAULTS = {
package/lib/providers.mjs CHANGED
@@ -573,12 +573,16 @@ export function parseCommandCode(
573
573
  : remaining !== null && spend !== null
574
574
  ? remaining + spend
575
575
  : null
576
- // v1.7.2: the SELECTED MODEL's allowance sizes the month when the plan has a
577
- // per-model table (GOAT + DeepSeek V4.1 Flash = $100 even though the credit
578
- // pool is $70 — a discounted model stretches the same pool further). Without a
579
- // known model or plan the pool is used, so nothing is invented.
576
+ // v1.7.2: the SELECTED MODEL's advertised allowance (GOAT + DeepSeek V4.1 Flash
577
+ // = $100 even though the credit pool is $70 — a discounted model stretches the
578
+ // same pool further).
579
+ // v1.7.3: it is NOT the month's denominator. The provider's own console prints
580
+ // 每月限额 4% for $2.94 spent, and 2.94/70 = 4.2% while 2.94/100 = 2.9% — the
581
+ // console measures the percentage against the CREDIT POOL. Using the allowance
582
+ // made the plugin disagree with the console the user checks, so the pool stays
583
+ // the denominator and the allowance is reported as context only.
580
584
  const allowance = commandcodeAllowance(planId, selectedModel)
581
- const granted = allowance.basis === 'model' && allowance.allowanceUsd !== null ? allowance.allowanceUsd : poolGrant
585
+ const granted = poolGrant
582
586
  const monthlyUsed = poolGrant !== null && remaining !== null ? Math.max(0, poolGrant - remaining) : spend
583
587
  const monthlyPercent =
584
588
  granted !== null && granted > 0 && monthlyUsed !== null
@@ -618,12 +622,14 @@ export function parseCommandCode(
618
622
  ? null
619
623
  : {
620
624
  remaining,
621
- // `granted` is the allowance the month is measured against, so the
622
- // credits card and the monthly row agree. `poolUsd` keeps the plan's
623
- // real credit pool visible when a model allowance is larger.
625
+ // `granted` is the credit pool the month is measured against — the
626
+ // same denominator the provider's console uses.
624
627
  granted,
625
628
  purchased,
626
629
  poolUsd: poolGrant,
630
+ // Advertising only (v1.7.3): the allowance the console lists for the
631
+ // selected model. Never used to compute a percentage.
632
+ allowanceUsd: allowance.allowanceUsd,
627
633
  allowanceModel: allowance.basis === 'model' ? allowance.matched : null,
628
634
  allowanceBasis: allowance.basis,
629
635
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-tokenlens",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "type": "module",
5
5
  "description": "dsh-TokenLens (词元透镜) — provider-aware plan capacity plus local token statistics (today/7d/30d/all-time, by harness/provider/model/workspace) for DSH.",
6
6
  "license": "MIT",