dsh-cost-meter 1.5.35 → 1.5.36
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.en.md +5 -5
- package/README.md +5 -5
- package/lib/client.js +1 -1
- package/lib/coding-plans.js +55 -5
- package/lib/index.js +8 -0
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
Per-conversation cost · daily totals · OpenCode Go subscription quota display · budget with usage percentage · official account balance · custom provider balance · balance progress bar · history · peak/off-peak pricing hours display (peak hours UTC 01:00–04:00, 06:00–10:00) · pre-switch popup & system-notification alerts for peak/off-peak changes (position / lead time / alert type configurable) · one-click price sync from the official docs · Codex-style token usage heat grid · multi-vendor model pricing (built-in 90+ model price catalog with auto-matching) · mainstream Coding Plan quota queries & display (Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet) · quota strip above the input box (budget / Go / coding-plan usage in one row, toggleable)
|
|
8
8
|
|
|
9
|
-
[](https://github.com/Han-1413141/dsh-cost-meter)
|
|
10
10
|
[](https://www.npmjs.com/package/dsh-cost-meter)
|
|
11
11
|
[](LICENSE)
|
|
12
12
|
[](https://github.com/deepseek-ai/deepseek-harness)
|
|
@@ -228,22 +228,22 @@ Real captures from an actual DSH sidebar of the period strip and collapsed verti
|
|
|
228
228
|
dsh plugin --profile web add dsh-cost-meter
|
|
229
229
|
```
|
|
230
230
|
|
|
231
|
-
**PowerShell one-click script** (copy the whole line, paste, press Enter; pnpm is provisioned automatically, git is auto-detected — no clone needed; the install chain is **pinned to the release tag `v1.5.
|
|
231
|
+
**PowerShell one-click script** (copy the whole line, paste, press Enter; pnpm is provisioned automatically, git is auto-detected — no clone needed; the install chain is **pinned to the release tag `v1.5.36`** — review the script before running):
|
|
232
232
|
|
|
233
233
|
```powershell
|
|
234
|
-
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.5.
|
|
234
|
+
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.5.36/install.ps1 | iex
|
|
235
235
|
```
|
|
236
236
|
|
|
237
237
|
**Or a plain command line** (the machine must already have pnpm and git; also pinned to the tag):
|
|
238
238
|
|
|
239
239
|
```sh
|
|
240
|
-
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.5.
|
|
240
|
+
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.5.36
|
|
241
241
|
```
|
|
242
242
|
|
|
243
243
|
Without git, use the GitHub tag archive:
|
|
244
244
|
|
|
245
245
|
```sh
|
|
246
|
-
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.5.
|
|
246
|
+
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.5.36.tar.gz
|
|
247
247
|
```
|
|
248
248
|
|
|
249
249
|
After installing, **restart** `dsh web` (plugin rows, the Typert manifest and the client bundle are all scanned at startup):
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
本会话费用 · 当日费用 · OpenCode Go 订阅额度显示 · 预算与已用百分比 · 官方账户余额 · 自定义 Provider 余额查询(可配任意 HTTP 端点) · 余额三段进度条 · 历史记录 · 峰谷计价时段显示(UTC 01:00–04:00、06:00–10:00 为峰时段) · 峰/谷切换前弹窗与系统通知提醒(位置/提前量/提醒类型可配) · 官方价格一键同步 · 类 Codex Token 用量热图 · 多厂商多模型价格计费(内置 90+ 模型价格目录与自动匹配) · 主流 Coding Plan 额度查询与显示(Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet 八家) · 输入框上方额度横条(预算/Go/Coding Plan 用量一条横排显示,可开关)
|
|
8
8
|
|
|
9
|
-
[](https://github.com/Han-1413141/dsh-cost-meter)
|
|
10
10
|
[](https://www.npmjs.com/package/dsh-cost-meter)
|
|
11
11
|
[](LICENSE)
|
|
12
12
|
[](https://github.com/deepseek-ai/deepseek-harness)
|
|
@@ -230,22 +230,22 @@
|
|
|
230
230
|
dsh plugin --profile web add dsh-cost-meter
|
|
231
231
|
```
|
|
232
232
|
|
|
233
|
-
**PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.5.
|
|
233
|
+
**PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.5.36`**,建议先下载审阅再运行):
|
|
234
234
|
|
|
235
235
|
```powershell
|
|
236
|
-
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.5.
|
|
236
|
+
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.5.36/install.ps1 | iex
|
|
237
237
|
```
|
|
238
238
|
|
|
239
239
|
**或直接命令行**(机器上需已有 pnpm 与 git;同样固定到 tag):
|
|
240
240
|
|
|
241
241
|
```sh
|
|
242
|
-
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.5.
|
|
242
|
+
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.5.36
|
|
243
243
|
```
|
|
244
244
|
|
|
245
245
|
没有 git 时可用 GitHub tag 打包直链:
|
|
246
246
|
|
|
247
247
|
```sh
|
|
248
|
-
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.5.
|
|
248
|
+
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.5.36.tar.gz
|
|
249
249
|
```
|
|
250
250
|
|
|
251
251
|
安装后**重启** `dsh web`(插件行、Typert 清单与客户端 bundle 均在启动时扫描):
|
package/lib/client.js
CHANGED
|
@@ -2435,7 +2435,7 @@ window.__ModuleLoader__.load({
|
|
|
2435
2435
|
body: el(Fragment, null,
|
|
2436
2436
|
el('div', { className: 'cm-bbox-head' },
|
|
2437
2437
|
el('span', { className: 'cm-bbox-label' }, t('goQuotaRowLabel') + ' ' + shortOf(mainKey)),
|
|
2438
|
-
el('span', { className: 'cm-bbox-pct cm-num' },
|
|
2438
|
+
el('span', { className: 'cm-bbox-pct cm-num' }, Math.round(pct) + '%')),
|
|
2439
2439
|
el('div', { className: 'cm-bbox-bar' },
|
|
2440
2440
|
el('div', { className: 'cm-bbox-fill', style: { width: Math.min(100, pct) + '%' } })),
|
|
2441
2441
|
detail
|
package/lib/coding-plans.js
CHANGED
|
@@ -124,16 +124,59 @@ export function parseAnthropicUsage(data) {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
|
-
* 解析 Z.ai / 智谱 GLM Coding Plan
|
|
128
|
-
* (
|
|
129
|
-
*
|
|
127
|
+
* 解析 Z.ai / 智谱 GLM Coding Plan 用量响应。
|
|
128
|
+
* 兼容三种已见形态(按优先级):
|
|
129
|
+
* - { data: { limits: [{ type: TOKENS_LIMIT|TIME_LIMIT, unit, number, percentage,
|
|
130
|
+
* nextResetTime, usage, currentValue, ... }], level } }(2026-08 起的监控端点
|
|
131
|
+
* /api/monitor/usage/quota/limit,issue #42;TOKENS_LIMIT 为 token 窗口,TIME_LIMIT
|
|
132
|
+
* 为 MCP/工具调用月度额度、量纲不同不纳入;unit 3=小时档,6=周档,缺失时按
|
|
133
|
+
* nextResetTime 排序兜底——0% 用量的滚动窗口不返回重置时间,排最前)
|
|
130
134
|
* - { plans: [{ status, total_units, used_units, available_units, period_end, capabilities }] }
|
|
131
|
-
* (period_end 语义按数值大小推断:重置跨度 >1 天视为周档,否则为 5 小时档)
|
|
135
|
+
* (旧计费端点;period_end 语义按数值大小推断:重置跨度 >1 天视为周档,否则为 5 小时档)
|
|
132
136
|
* - { five_hour: { utilization|percent, resets_at }, weekly|week|seven_day: {...} }
|
|
133
137
|
*/
|
|
134
138
|
export function parseZaiUsage(data) {
|
|
135
139
|
if (data === null || typeof data !== 'object') return null
|
|
136
140
|
const windows = {}
|
|
141
|
+
// 形态零:监控端点 quota/limit(issue #42)。
|
|
142
|
+
{
|
|
143
|
+
const limits = data.data !== null && typeof data.data === 'object' && Array.isArray(data.data.limits)
|
|
144
|
+
? data.data.limits : null
|
|
145
|
+
if (limits !== null) {
|
|
146
|
+
// 已按 unit 明确分配的窗口;unit 缺失/未知的条目留待重置时间排序兜底。
|
|
147
|
+
const monWindows = {}
|
|
148
|
+
const rest = []
|
|
149
|
+
for (const limit of limits) {
|
|
150
|
+
if (limit === null || typeof limit !== 'object' || limit.type !== 'TOKENS_LIMIT') continue
|
|
151
|
+
// percentage 已是 0-100 百分数;缺失时用 currentValue/usage 反推。
|
|
152
|
+
const pct = limit.percentage !== undefined ? clampPct(Number(limit.percentage))
|
|
153
|
+
: Number.isFinite(Number(limit.usage)) && Number(limit.usage) > 0 && Number.isFinite(Number(limit.currentValue))
|
|
154
|
+
? clampPct((Number(limit.currentValue) / Number(limit.usage)) * 100)
|
|
155
|
+
: null
|
|
156
|
+
if (pct === null) continue
|
|
157
|
+
const resetsAt = normalizeResetAt(limit.nextResetTime)
|
|
158
|
+
const unit = Number(limit.unit)
|
|
159
|
+
if (unit === 3 && monWindows.fiveHour === undefined) monWindows.fiveHour = { percent: pct, resetsAt }
|
|
160
|
+
else if (unit === 6 && monWindows.weekly === undefined) monWindows.weekly = { percent: pct, resetsAt }
|
|
161
|
+
else if (!Number.isFinite(unit)) rest.push({ pct, resetsAt, resetMs: Number(limit.nextResetTime) })
|
|
162
|
+
}
|
|
163
|
+
if (rest.length > 0) {
|
|
164
|
+
// 无 unit 条目:重置时间升序(0% 滚动窗口无重置时间视为最近,排最前),
|
|
165
|
+
// 依次补位到 5 小时档 → 周档(老套餐仅一条时只出 5 小时档)。
|
|
166
|
+
rest.sort((a, b) => {
|
|
167
|
+
const av = Number.isFinite(a.resetMs) && a.resetMs > 0 ? a.resetMs : 0
|
|
168
|
+
const bv = Number.isFinite(b.resetMs) && b.resetMs > 0 ? b.resetMs : 0
|
|
169
|
+
return av - bv
|
|
170
|
+
})
|
|
171
|
+
for (const item of rest) {
|
|
172
|
+
if (monWindows.fiveHour === undefined) monWindows.fiveHour = { percent: item.pct, resetsAt: item.resetsAt }
|
|
173
|
+
else if (monWindows.weekly === undefined) monWindows.weekly = { percent: item.pct, resetsAt: item.resetsAt }
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (Object.keys(monWindows).length > 0) return monWindows
|
|
177
|
+
// limits 中无可解析 token 窗口:落回后续形态,最终由调用方透传错误信封。
|
|
178
|
+
}
|
|
179
|
+
}
|
|
137
180
|
// 形态一:plans 数组(zcode 逆向确认的计费 API 形状)。
|
|
138
181
|
if (Array.isArray(data.plans)) {
|
|
139
182
|
for (const plan of data.plans) {
|
|
@@ -513,7 +556,11 @@ export function scnetTokenPlanWindows(days, entry, nowMs) {
|
|
|
513
556
|
export const CODING_PLAN_ENDPOINTS = {
|
|
514
557
|
anthropic: ['https://api.anthropic.com/api/oauth/usage'],
|
|
515
558
|
zai: [
|
|
516
|
-
// 2026-08
|
|
559
|
+
// 2026-08 接口变更(issue #42):额度查询迁移到监控端点 /api/monitor/usage/quota/limit(国内 Key 对应
|
|
560
|
+
// bigmodel.cn、国际 Key 对应 z.ai,两域 Key 不互通——401 时继续换域尝试,见 queryCodingPlan)。
|
|
561
|
+
'https://open.bigmodel.cn/api/monitor/usage/quota/limit',
|
|
562
|
+
'https://api.z.ai/api/monitor/usage/quota/limit',
|
|
563
|
+
// 旧计费端点兜底:v3 存活(issue #17)、v4 历史;monitor 端点不可达时仍可出数。
|
|
517
564
|
'https://api.z.ai/api/coding/paas/v3/dashboard/billing/coding_plan/usage',
|
|
518
565
|
'https://open.bigmodel.cn/api/coding/paas/v3/dashboard/billing/coding_plan/usage',
|
|
519
566
|
'https://api.z.ai/api/coding/paas/v4/dashboard/billing/coding_plan/usage',
|
|
@@ -580,6 +627,9 @@ export async function queryCodingPlan(provider, key, locale, t) {
|
|
|
580
627
|
if (response.status === 401 || response.status === 403) {
|
|
581
628
|
const error = new Error(t(locale, 'codingPlanUnauthorized', { provider: meta.label, code: String(response.status) }))
|
|
582
629
|
error.soft = true // Key 无效/无订阅属预期场景,面板中性提示
|
|
630
|
+
// zai 国内(bigmodel.cn)/国际(z.ai)域名 Key 不互通:单域 401 只说明 Key
|
|
631
|
+
// 不属于该域,继续尝试下一域;全部 401 才认定为凭据无效(issue #42)。
|
|
632
|
+
if (provider === 'zai') { lastError = error; continue }
|
|
583
633
|
throw error
|
|
584
634
|
}
|
|
585
635
|
if (!response.ok) {
|
package/lib/index.js
CHANGED
|
@@ -341,6 +341,14 @@ function makeCostUsageProjection(ledger) {
|
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
343
|
|
|
344
|
+
/**
|
|
345
|
+
* 测试导出(verify.mjs 行为级断言用;不参与宿主加载路径)。
|
|
346
|
+
* issue #43 教训:宿主 restore() 对版本匹配的 checkpoint 行调用
|
|
347
|
+
* stateSchema.parse(row.val) 且无 try-catch——schema 与真实 state 的
|
|
348
|
+
* 匹配性必须行为级验证,源码字符串断言不能发现字段漂移。
|
|
349
|
+
*/
|
|
350
|
+
export const __testProjection = { usageProjectionSchema, usageProjectionStateSchema, projectionView, makeCostUsageProjection }
|
|
351
|
+
|
|
344
352
|
// ── 服务 ───────────────────────────────────────────────────────────────────
|
|
345
353
|
|
|
346
354
|
/** 余额占位(未开启显示或查询失败时的空值)。 */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cost-meter",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.36",
|
|
4
4
|
"description": "DeepSeek Harness 会话费用统计插件:本会话成本、当日费用、历史记录与官方价格同步,支持多厂商多模型价格计费(内置 90+ 模型价格目录与自动匹配)、主流 Coding Plan 订阅额度查询与显示(7 家,含 SCNet Token Plan 本地 Credits 计量)、自定义 Provider 余额查询(可配任意 HTTP 端点)与余额进度条、峰谷计价时段显示与切换前弹窗/系统通知提醒(位置/提前量/类型可配),界面中英双语。Session cost tracking plugin for DeepSeek Harness: per-conversation cost, daily totals, history and official price sync, with multi-vendor model pricing (built-in 90+ model catalog with auto-matching), Coding Plan quota queries & display for 7 vendors (incl. local credits metering for the SCNet Token Plan), custom provider balance lookup (configurable HTTP endpoint) and balance progress bar, plus peak/off-peak pricing display with pre-switch popup & system-notification alerts (position / lead time / type configurable), in a bilingual (Chinese/English) UI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|