dsh-tokenlens 1.6.6 → 1.6.7
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 +7 -2
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/index.js +1 -1
- package/lib/providers.mjs +16 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,9 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
**版本记录约定**:同一发布日只保留一个章节,标题取当日**最后一个**已发布版本号;当日多次发布的改动合并到该章节,并在标题下注明当日实际发布过的版本号(npm 上仍可安装这些独立版本)。若当日已有发布,后续小改动不再单独增加版本号,而是并入下一篇日志。这样日志按天规整、不出现同日多个小版本。
|
|
6
6
|
|
|
7
|
-
## 1.6.
|
|
7
|
+
## 1.6.7 — 2026-11-05
|
|
8
8
|
|
|
9
|
-
(当日已发布版本:v1.6.5 / v1.6.6)
|
|
9
|
+
(当日已发布版本:v1.6.5 / v1.6.6 / v1.6.7)
|
|
10
|
+
|
|
11
|
+
- **fix(commandcode): 用实时窗口用量校正滞后的 `usage summary`**——`/alpha/usage/summary` 是聚合接口,比滚动窗口**滞后几美分**(实测 summary `$1.1248` vs 实时 `$1.2802`),直接拿它反推会让额度偏小、百分比偏低约 0.2 个百分点。现在取「summary 与实时窗口用量」中的**最大值**作为本期消费下界——summary 提供锚点,实时窗口只会把估计值推向真值。实测修正后月额度精确回到 **$70.00**、百分比 `1.85%`,与该平台控制台一致
|
|
12
|
+
- fix(commandcode): **仅在 summary 存在时才用窗口用量校正**——没有 summary 就没有锚点,此时周窗口可能并不覆盖整个账期,用它反推会把额度放大、百分比压向 0,因此该情况仍保持 `null`
|
|
13
|
+
|
|
14
|
+
### v1.6.6 同日内容
|
|
10
15
|
|
|
11
16
|
- **feat(commandcode): 补上月用量百分比**——该平台付费套餐**不下发** `monthlyCreditsGranted`(额度分母),此前月窗口只能是 `unknown`。现在同时读 `GET /alpha/usage/summary`(控制台自己用的那个接口),用两个字段反推额度:`grant = credits.monthlyCredits(余额)+ totalMonthlyCredits(本期消费)`。实测 `69.1272003646 + 0.8727996354 = 70.0000000000`(多时点复核均精确 70),与控制台前端内置的 `totalCredits: 70` 一致
|
|
12
17
|
- feat(commandcode): 月窗口因此同时具备**已用 / 额度 / 百分比 / 重置时间**(`$0.99 / $70.00 · 1.4%`),与 5 小时、每周两个窗口口径一致
|
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
|
|
147
|
+
Node.js ≥ 24, zero runtime dependencies: `node --test` runs the 357 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`:**
|
|
448
|
+
- `node --test`:**357 个自动化用例**,覆盖 Host 数据层、供应商适配器(含小米 MiMo 控制台 Cookie 适配器、Command Code 月度额度反推)、统计折叠、各 harness 读取、Design Plan 周期账本与额度计价、窗口锚点切片、工作区自动识别、插件集成与浏览器端渲染 / 交互。
|
|
449
449
|
- 在真实环境中验证过 **5 个 harness** 的数据源;本机统计与独立的 SQLite 查询、独立的日志解析逐项对账(差额为 0),跨 harness 合并与供应商映射算术自洽。
|
|
450
450
|
- 供应商接口按各官方文档与参考客户端行为验证;未配置凭据时 chip 静默隐藏,接口异常时按可重试错误降级。
|
|
451
451
|
|
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.
|
|
87
|
+
export const PLUGIN_VERSION = '1.6.7'
|
|
88
88
|
|
|
89
89
|
/** Documented defaults; every field of the raw row config is optional. */
|
|
90
90
|
const DEFAULTS = {
|
package/lib/providers.mjs
CHANGED
|
@@ -549,14 +549,27 @@ export function parseCommandCode({ credits, subscription, whoami, usageSummary }
|
|
|
549
549
|
// meter jump while the account did not move, so it never does that here.
|
|
550
550
|
const summary = usageSummary !== null && typeof usageSummary === 'object' ? usageSummary : {}
|
|
551
551
|
const periodSpend = toNumber(summary.totalMonthlyCredits) ?? toNumber(summary.totalCredits)
|
|
552
|
+
// `/alpha/usage/summary` is an aggregate and LAGS the live windows by up to a
|
|
553
|
+
// few cents (observed $1.12 vs $1.28 live), which would understate the derived
|
|
554
|
+
// grant and therefore the percentage. When the summary is present it anchors
|
|
555
|
+
// the period, and a rolling window's `used` — always a subset of the period —
|
|
556
|
+
// can then only raise the estimate towards the truth, so the largest of them is
|
|
557
|
+
// taken. WITHOUT the summary the windows are NOT usable this way: a weekly
|
|
558
|
+
// window that does not cover the whole period would inflate the grant and drive
|
|
559
|
+
// the percentage towards zero, so that case stays `null`.
|
|
560
|
+
const liveWindowSpend =
|
|
561
|
+
periodSpend === null
|
|
562
|
+
? []
|
|
563
|
+
: [toNumber(limits.fiveHour?.used), toNumber(limits.weekly?.used)].filter((value) => value !== null)
|
|
564
|
+
const spend = periodSpend === null ? null : Math.max(periodSpend, ...liveWindowSpend)
|
|
552
565
|
const reportedGrant = toNumber(credit.monthlyCreditsGranted)
|
|
553
566
|
const granted =
|
|
554
567
|
reportedGrant !== null && reportedGrant > 0
|
|
555
568
|
? reportedGrant
|
|
556
|
-
: remaining !== null &&
|
|
557
|
-
? remaining +
|
|
569
|
+
: remaining !== null && spend !== null
|
|
570
|
+
? remaining + spend
|
|
558
571
|
: null
|
|
559
|
-
const monthlyUsed = granted !== null && remaining !== null ? Math.max(0, granted - remaining) :
|
|
572
|
+
const monthlyUsed = granted !== null && remaining !== null ? Math.max(0, granted - remaining) : spend
|
|
560
573
|
const monthlyPercent =
|
|
561
574
|
granted !== null && granted > 0 && monthlyUsed !== null
|
|
562
575
|
? normalizePercent((monthlyUsed / granted) * 100)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-tokenlens",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.7",
|
|
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",
|