dsh-tokenlens 1.6.0 → 1.6.2

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,15 +4,26 @@
4
4
 
5
5
  **版本记录约定**:同一发布日只保留一个章节,标题取当日**最后一个**已发布版本号;当日多次发布的改动合并到该章节,并在标题下注明当日实际发布过的版本号(npm 上仍可安装这些独立版本)。若当日已有发布,后续小改动不再单独增加版本号,而是并入下一篇日志。这样日志按天规整、不出现同日多个小版本。
6
6
 
7
+ ## 1.6.2 — 2026-11-04
8
+
9
+ (当日已发布版本:v1.6.2。v1.6.1 的混合模型修复未单独发版,已并入本节)
10
+
11
+ - **fix(open-design): 混合模型按 credits 加权取额度,不再取最高倍率**——原实现取「用过的最高倍率」当口径,实测 0.5× 与 4× 各占一半 credits 时会把月额度报成 $15(正确应为 **$67.50**),严重低估。现改为按实际消耗加权的调和平均:`m_eff = Σcredits / Σ(credits/m)`,`月额度 = $60 / m_eff`。90% credits 走 0.5× 时是 **$97.89**,99% 时 **$117.92**,偶尔用一次 4× 模型不再摧毁额度
12
+ - fix(open-design): 单一模型时加权公式**精确退化**为官方表格值(0.5×→$120、1×→$60、2×→$30、4×→$15),纯模型场景不受影响
13
+ - fix(open-design): 无消费权重(仅知道模型列表)时回退到最高倍率,即保守口径(承诺最少剩余额度)
14
+ - **fix(open-design): 未收录价格的模型不再静默少算金额**——`unpricedModels` 此前算出来却没有用上,含未知模型时金额会**偏低却不提示**。现在置 `partial: true`,弹窗显示「含未收录价格的模型,金额为下限」,绝不把下限当完整值
15
+ - 测试:328 → 332(切换模型时金额与额度反向变化、未收录模型使金额成为下限、加权混合三种比例、单一模型退化、无权重回退最高倍率)
16
+ - 备注:`600,000 credits/月` 是插件由「7 天窗口上限 × 4」推算的值(官方定价表月/周 = $120/$30 = 4),**不是服务端字段**;服务端只返回 5 小时 50,000 与 7 天 150,000 两个窗口
17
+
7
18
  ## 1.6.0 — 2026-11-03
8
19
 
9
20
  - **feat(open-design): 「本期 Design Plan 累计」改按官方定价表的模型单价计算**——原来是 `usedCredits ÷ creditsPerUsd`,这个算法隐含「按 1× 倍率消耗」的假设,而官方倍率表跨度 0.25×–4×:对 DeepSeek V4.1 Flash(0.5×)会**少算一半**,对 GPT-6 Luna(4×)会**多算 4 倍**。现在按每个模型的实际 Token × 官方单价(输入/输出/缓存读分别计价)累加,结果可直接与定价表比对
10
21
  - **feat(open-design): 给出与倍率匹配的月额度**——定价表里 $120 是**列表价**口径且按倍率消耗:只用 0.5× 模型(DeepSeek V4.1 Flash)可动用**完整 $120**,1× 用 $60,2× 用 $30,4× 用 $15。弹窗改为显示「**已用 / 月额度 + 百分比**」(如 `$27.31 / $120.00 22.8%`),并注明「按 0.5× 倍率模型计价」
11
- - feat(open-design): 混合模型时按**最高**倍率取额度(不是平均)——4× 模型的每一单位消耗其份额的速度是 4 倍,约束由它决定
22
+ - feat(open-design): 混合模型取额度口径(v1.6.2 修正为按 credits 加权,不再是最高倍率)
12
23
  - feat(wire): `designPlan` 新增 `monthlyCapUsd` / `capPercent` / `multiplier` / `creditsUsd`;`estimatedUsd` 语义改为「官方单价口径的消费额」,旧算法结果保留在 `creditsUsd` 便于对照
13
24
  - feat(stats): `models[].last30Days` 增加 `input` / `output` / `cacheRead` / `cacheWrite` 拆分,供按单价计价使用(此前只有 total)
14
25
  - fix(open-design): 单价表按官方文档转录 13 个 Design Plan 模型;`hunyuan-h4-preview` / `glm-5.3-flash-x` 不在公开价目接口里,价格缺失时按「未定价」处理并如实上报,绝不臆造
15
- - 测试:318 → 328(倍率阶梯 0.5×→$120 / 1×→$60 / 2×→$30 / 4×→$15、混合取最高倍率、未知模型不臆造倍率与额度、按 token 种类计价、**用控制台真实账单核对:$0.0048 列表价 × 0.5 = $0.0024 实扣**、未定价模型上报)
26
+ - 测试:318 → 328(倍率阶梯 0.5×→$120 / 1×→$60 / 2×→$30 / 4×→$15、未知模型不臆造倍率与额度、按 token 种类计价、**用控制台真实账单核对:$0.0048 列表价 × 0.5 = $0.0024 实扣**、未定价模型上报)
16
27
 
17
28
  ## 1.5.3 — 2026-11-03
18
29
 
package/README.md CHANGED
@@ -440,7 +440,7 @@ Host 半注册 `tokenlens_usage`,参数 `action`(默认 `snapshot`)与可
440
440
 
441
441
  ## 验证
442
442
 
443
- - `node --test`:**328 个自动化用例**,覆盖 Host 数据层、供应商适配器、统计折叠、各 harness 读取、Design Plan 周期账本与官方单价计价、窗口锚点切片、工作区自动识别、插件集成与浏览器端渲染 / 交互。
443
+ - `node --test`:**332 个自动化用例**,覆盖 Host 数据层、供应商适配器、统计折叠、各 harness 读取、Design Plan 周期账本与官方单价计价、窗口锚点切片、工作区自动识别、插件集成与浏览器端渲染 / 交互。
444
444
  - 在真实环境中验证过 **5 个 harness** 的数据源;本机统计与独立的 SQLite 查询、独立的日志解析逐项对账(差额为 0),跨 harness 合并与供应商映射算术自洽。
445
445
  - 供应商接口按各官方文档与参考客户端行为验证;未配置凭据时 chip 静默隐藏,接口异常时按可重试错误降级。
446
446
 
package/client.js CHANGED
@@ -343,6 +343,7 @@ window.__ModuleLoader__.load({
343
343
  designPlanHint:
344
344
  '按官方定价表的模型单价换算本机实际消耗的 Token(不是 usedCredits ÷ 汇率)。Open Design 没有月度用量接口,此值由插件在本机累计观测到的 7 天窗口得出,仅供参考',
345
345
  designPlanMultiplier: '按 {multiplier}× 倍率模型计价',
346
+ designPlanPartialPricing: '含未收录价格的模型,金额为下限',
346
347
  designPlanComplete: '已覆盖本账期全部窗口',
347
348
  designPlanPartial: '仅统计已观测的 {count} 个窗口',
348
349
  providerSave: '保存',
@@ -605,6 +606,7 @@ window.__ModuleLoader__.load({
605
606
  designPlanHint:
606
607
  'Priced from the official per-model rates over the tokens this machine actually consumed (not usedCredits ÷ rate). Open Design serves no period-usage endpoint, so the window total is accumulated locally; treat it as an estimate.',
607
608
  designPlanMultiplier: 'priced at the {multiplier}× model rate',
609
+ designPlanPartialPricing: 'includes models with no documented price; the amount is a lower bound',
608
610
  designPlanComplete: 'covers every window of this period',
609
611
  designPlanPartial: 'only {count} observed window(s)',
610
612
  providerConsoleURLPlaceholder: 'Leave empty for the built-in default',
@@ -1107,6 +1109,9 @@ window.__ModuleLoader__.load({
1107
1109
  monthlyCapUsd: monthlyCapUsd !== null && monthlyCapUsd > 0 ? monthlyCapUsd : null,
1108
1110
  capPercent,
1109
1111
  multiplier: multiplier !== null && multiplier > 0 ? multiplier : null,
1112
+ // v1.6.2: some consumed model had no documented price, so the dollar
1113
+ // figure is a lower bound and must not read as complete.
1114
+ partial: raw.partial === true,
1110
1115
  }
1111
1116
  }
1112
1117
 
@@ -4073,6 +4078,9 @@ window.__ModuleLoader__.load({
4073
4078
  if (designPlan.multiplier !== null) {
4074
4079
  notes.push(t('designPlanMultiplier', { multiplier: designPlan.multiplier }))
4075
4080
  }
4081
+ // v1.6.2: a model without a documented price makes the figure a lower bound.
4082
+ // Say it rather than letting the number read as complete.
4083
+ if (designPlan.partial === true) notes.push(t('designPlanPartialPricing'))
4076
4084
  if (designPlan.complete === true) notes.push(t('designPlanComplete'))
4077
4085
  else if (designPlan.windows > 0) notes.push(t('designPlanPartial', { count: designPlan.windows }))
4078
4086
  return h(
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.6.0'
87
+ export const PLUGIN_VERSION = '1.6.2'
88
88
 
89
89
  /** Documented defaults; every field of the raw row config is optional. */
90
90
  const DEFAULTS = {
@@ -483,12 +483,16 @@ export function apply(ctx, rawConfig) {
483
483
  models[modelId] = bucket
484
484
  }
485
485
  const cost = designPlanCostUsd(models)
486
- const caps = capsForModels(Object.keys(models))
486
+ // v1.6.1: weight the cap by actual per-model consumption, not the worst
487
+ // multiplier. The caps are credit-denominated, so a mostly-0.5x account that
488
+ // touched a 4x model once keeps nearly the full $120.
489
+ const caps = capsForModels(Object.keys(models), cost.mixes)
487
490
  return {
488
491
  listPriceUsd: cost.priced === true ? cost.usd : null,
489
492
  monthlyCapUsd: caps.monthlyCapUsd,
490
493
  multiplier: caps.multiplier,
491
494
  unpricedModels: cost.unpricedModels,
495
+ partial: cost.unpricedModels.length > 0,
492
496
  }
493
497
  }
494
498
 
@@ -73,30 +73,73 @@ export const DESIGN_PLAN_CAPS_USD = { rolling: 10, weekly: 30, monthly: 120 }
73
73
  * The $120 monthly cap is entirely Design Plan value and is consumed at the
74
74
  * model's multiplier, so using ONLY a 0.5x model (DeepSeek V4.1 Flash) unlocks
75
75
  * the full $120 of list-price usage; a 1x model reaches $60; 2x reaches $30.
76
- * With a mixed history the binding constraint is the WORST (highest) multiplier
77
- * the account actually used, because every unit of that model spends its share
78
- * faster. That is why this returns the max multiplier seen, not an average.
76
+ * With a mixed history the binding constraint is NOT simply the highest
77
+ * multiplier: the caps are denominated in credits (600,000/month at 10,000
78
+ * credits per list-price dollar), and each model burns those credits at its own
79
+ * rate. The account's spendable list-price value is therefore
79
80
  *
81
+ * 600,000 credits / m_effective
82
+ *
83
+ * where `m_effective` is the credit-weighted harmonic mean of the multipliers
84
+ * actually used:
85
+ *
86
+ * m_eff = Σ credits_i / Σ (credits_i / m_i), credits_i = listUsd_i × 10000 × m_i
87
+ *
88
+ * Using the plain maximum would understate a mostly-0.5x account that touched a
89
+ * 4x model once: 90% of the credits at 0.5x plus 10% at 4x gives $97.89, not
90
+ * $15. With a single model the formula reduces exactly to that model's
91
+ * documented cap, so the pure cases still match the pricing page.
92
+ *
93
+ * @param modelIds - the model ids in the mix, or
94
+ * @param mixes - a per-model `{ listUsd, multiplier }` split (preferred: it
95
+ * weights by real consumption). `modelIds` is used only when no split is given.
80
96
  * @returns `{ monthlyCapUsd, weeklyCapUsd, fiveHourCapUsd, multiplier }` where
81
- * `multiplier` is the max documented multiplier among `modelIds` (0 when none),
82
- * or all-null caps when no model is known.
97
+ * `multiplier` is the effective multiplier, or all-null caps when no model is
98
+ * known.
83
99
  */
84
- export function capsForModels(modelIds) {
85
- let worst = 0
86
- for (const id of Array.isArray(modelIds) ? modelIds : []) {
87
- const model = DESIGN_PLAN_MODELS[normalizeModelId(id)]
88
- if (model === undefined || !Number.isFinite(model.multiplier) || model.multiplier <= 0) continue
89
- if (model.multiplier > worst) worst = model.multiplier
100
+ export function capsForModels(modelIds, mixes = null) {
101
+ const rows = Array.isArray(mixes)
102
+ ? mixes
103
+ .map((mix) => ({
104
+ listUsd: typeof mix?.listUsd === 'number' && Number.isFinite(mix.listUsd) && mix.listUsd > 0 ? mix.listUsd : 0,
105
+ multiplier:
106
+ typeof mix?.multiplier === 'number' && Number.isFinite(mix.multiplier) && mix.multiplier > 0
107
+ ? mix.multiplier
108
+ : null,
109
+ }))
110
+ .filter((row) => row.multiplier !== null && row.listUsd > 0)
111
+ : null
112
+ let effective = 0
113
+ if (rows !== null && rows.length > 0) {
114
+ // Credit-weighted harmonic mean (see the doc comment).
115
+ let credits = 0
116
+ let inverse = 0
117
+ for (const row of rows) {
118
+ const rowCredits = row.listUsd * row.multiplier
119
+ credits += rowCredits
120
+ inverse += rowCredits / row.multiplier
121
+ }
122
+ effective = credits > 0 && inverse > 0 ? credits / inverse : 0
123
+ } else {
124
+ // No consumption weighting available: fall back to the highest multiplier,
125
+ // the conservative reading (it promises the LEAST remaining capacity).
126
+ let worst = 0
127
+ for (const id of Array.isArray(modelIds) ? modelIds : []) {
128
+ const model = DESIGN_PLAN_MODELS[normalizeModelId(id)]
129
+ if (model === undefined || !Number.isFinite(model.multiplier) || model.multiplier <= 0) continue
130
+ if (model.multiplier > worst) worst = model.multiplier
131
+ }
132
+ effective = worst
90
133
  }
91
- if (worst === 0) {
134
+ if (!(effective > 0)) {
92
135
  return { monthlyCapUsd: null, weeklyCapUsd: null, fiveHourCapUsd: null, multiplier: null }
93
136
  }
94
137
  return {
95
- // 600,000 credits / mult at 10,000 credits per dollar == $60 / mult.
96
- monthlyCapUsd: 60 / worst,
97
- weeklyCapUsd: 15 / worst,
98
- fiveHourCapUsd: 5 / worst,
99
- multiplier: worst,
138
+ // 600,000 credits / m at 10,000 credits per list-price dollar == $60 / m.
139
+ monthlyCapUsd: 60 / effective,
140
+ weeklyCapUsd: 15 / effective,
141
+ fiveHourCapUsd: 5 / effective,
142
+ multiplier: effective,
100
143
  }
101
144
  }
102
145
 
@@ -153,6 +196,7 @@ export function designPlanCostUsd(models) {
153
196
  let usd = 0
154
197
  let priced = false
155
198
  const unpricedModels = []
199
+ const mixes = []
156
200
  for (const [modelId, bucket] of Object.entries(models ?? {})) {
157
201
  const total = tokens(bucket?.input) + tokens(bucket?.output) + tokens(bucket?.cacheRead) + tokens(bucket?.cacheWrite)
158
202
  if (total === 0) continue
@@ -163,6 +207,11 @@ export function designPlanCostUsd(models) {
163
207
  }
164
208
  usd += cost.usd
165
209
  priced = true
210
+ // Per-model list-price spend, so the cap can be weighted by real consumption.
211
+ const model = designPlanModel(modelId)
212
+ if (model !== null && Number.isFinite(model.multiplier) && model.multiplier > 0 && cost.usd > 0) {
213
+ mixes.push({ modelId: normalizeModelId(modelId), listUsd: cost.usd, multiplier: model.multiplier })
214
+ }
166
215
  }
167
- return { usd, priced, unpricedModels }
216
+ return { usd, priced, unpricedModels, mixes }
168
217
  }
@@ -292,6 +292,9 @@ export function summarizeDesignPlan(ledger, periodStart, input = null) {
292
292
  monthlyCapUsd,
293
293
  multiplier: Number.isFinite(input?.multiplier) ? input.multiplier : null,
294
294
  capPercent,
295
+ // v1.6.2: true when some consumed model has no documented price, so
296
+ // `estimatedUsd` is a lower bound and the UI must say so.
297
+ partial: input?.partial === true,
295
298
  windows,
296
299
  complete: since === key,
297
300
  since,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-tokenlens",
3
- "version": "1.6.0",
3
+ "version": "1.6.2",
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",