dsh-cost-meter 1.9.39 → 1.9.40
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.md +588 -588
- package/README.zh-CN.md +592 -592
- package/docs/billion-context-billing.md +4 -4
- package/docs/display-settings.md +1 -1
- package/docs/update-notes-1.9.31.md +1 -1
- package/docs/update-notes-1.9.40.md +25 -0
- package/lib/balance-retry.js +23 -0
- package/lib/client.display.js +3 -3
- package/lib/client.js +6 -6
- package/lib/client.settings-overview.js +1 -1
- package/lib/client.statistics.js +8 -8
- package/lib/custom-balance.js +2 -1
- package/lib/external-usage.js +119 -119
- package/lib/index.js +12 -8
- package/lib/ledger-totals.js +57 -57
- package/lib/ledger-writer-worker.js +1 -1
- package/package.json +3 -2
|
@@ -41,14 +41,14 @@ Checks use original npm packages, isolated local responses, both plugin loading
|
|
|
41
41
|
|
|
42
42
|
**费用插件从 1.8.28 起直接接入原版 billion-context,支持 0.1.181 及更新版本,无需额外安装配套兼容包。**保留已安装的原版插件,更新费用插件,然后完全重启 DSH,让本地代理启动时自动接入计费。
|
|
43
43
|
|
|
44
|
-
###
|
|
44
|
+
### 自动兼容与统计说明
|
|
45
45
|
|
|
46
46
|
接入时检查原版代理和原生请求拦截的实际接口,不再使用版本白名单。后续版本保持相关接口时自动接入;源码校验值只用于确认启动时加载的是已检查的代码,不限制版本号。
|
|
47
47
|
|
|
48
|
-
- **0.1.180
|
|
49
|
-
- **必需接口变化:**停止接入内部计费,保留普通 DSH
|
|
48
|
+
- **0.1.180 及更早版本:**升级到 **0.1.181 或更新版本**后可接入内部计费。
|
|
49
|
+
- **必需接口变化:**停止接入内部计费,保留普通 DSH 计费。
|
|
50
50
|
- **旧代理已经运行:**完全重启 DSH 及其本地 billion-context 代理。仅更新或重载费用插件,无法给已经启动且未接入的代理补装运行中的观察器。
|
|
51
|
-
-
|
|
51
|
+
- 用量记录不完整或尚未接入内部计费时,在“费用 → 概览”以普通灰色文字说明统计可能存在偏差,不再自动弹窗。临时连接失败不会直接判定为接口变化。
|
|
52
52
|
|
|
53
53
|
接入只在已验证的本地 Node 代理启动时加载内存中的计费观察器,不修改原版插件文件,不替换安装包,不设置全局 `NODE_OPTIONS`,不改变模型路由。继续使用原版的请求拦截功能。此接入需要 Node 20.6 或更新版本。
|
|
54
54
|
|
package/docs/display-settings.md
CHANGED
|
@@ -42,6 +42,6 @@ Codex 额度的真实数据来自已启用并登录的 `dsh-codex-subscription`
|
|
|
42
42
|
|
|
43
43
|
拖动排序仅在显示设置的侧栏预览中提供,主界面侧栏按保存顺序正常展示,不显示拖动手柄。预览中可拖动组件,拖到目标卡片的上半部或下半部决定放在前面或后面。手柄聚焦后也可用上下方向键移动。顺序保存到 `sidebarOrder`,重启、切换样式和暂时隐藏组件后保留;不同 Coding Plan 与网关卡片分别排序。Go 与预算使用独立卡片。原模型花费位置选项用于旧配置;手动使用该选项会清除拖动顺序并恢复原位置规则。
|
|
44
44
|
|
|
45
|
-
“合并卡片”将今日 Token 与费用、余额和峰谷进度放入同一外框。选择时默认开启今日双项显示,之后仍可分别关闭。Codex
|
|
45
|
+
“合并卡片”将今日 Token 与费用、余额和峰谷进度放入同一外框。选择时默认开启今日双项显示,之后仍可分别关闭。Codex 组件提供额度查询总开关;显式开启其显示时会启用查询。billion-context 的统计偏差说明放在“费用 → 概览”,使用普通灰色文字,不再自动弹窗或提供弹窗开关。
|
|
46
46
|
|
|
47
47
|
“费用 → 显示 → 侧栏”中的“今日消费与余额同行”是独立开关,可与现有布局组合使用。开启时默认只显示今日费用,Token 可在今日组件中单独开启;两项保留悬停详情,余额进度条照常显示,隐藏官方余额时使用第一条可见的自定义余额。排序在设置预览中调整,关闭开关恢复各组件独立排列。
|
|
@@ -42,4 +42,4 @@ This patch adds the complete cost settings to plugin details, sharing the compon
|
|
|
42
42
|
- Use the CNY conversion rate for CNY-priced external calls and legacy pricing repair, regardless of the display currency.
|
|
43
43
|
- Update frozen CNY/EUR amounts alongside repaired USD costs, retaining recorded FX rates and unrelated amounts. Reconcile complete model currency totals even when USD totals already match; missing legacy currency fields do not imply zero.
|
|
44
44
|
|
|
45
|
-
No new full-ledger repricing task is introduced. Tests cover currencies, idempotence, partial legacy rows, concurrent/failed saves, slot lifecycle and responsive read-only rendering with synthetic data. Update to **1.9.31** and restart DSH.
|
|
45
|
+
No new full-ledger repricing task is introduced. Tests cover currencies, idempotence, partial legacy rows, concurrent/failed saves, slot lifecycle and responsive read-only rendering with synthetic data. Update to **1.9.31** and restart DSH.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# v1.9.40:费用提示与余额查询优化
|
|
2
|
+
|
|
3
|
+
## 中文
|
|
4
|
+
|
|
5
|
+
本次更新调整费用说明的展示位置,并优化余额查询的等待策略,减少无效重复请求及相关使用风险。
|
|
6
|
+
|
|
7
|
+
- billion-context 用量记录不完整时,在“设置 → 费用 → 概览”显示一行普通灰字:“billion-context 部分用量记录不完整,费用统计可能存在偏差。”正常状态下隐藏,不再自动弹窗。
|
|
8
|
+
- 官方余额与通用 HTTP 自定义余额收到 401/403 后,自动查询等待配置的刷新间隔;修正认证后仍可手动刷新。
|
|
9
|
+
- 收到 429 时,自动查询、连续手动刷新和排队刷新都遵守服务端 `Retry-After`。支持秒数和 HTTP 日期;缺失或无效时使用配置间隔,避免短时间反复请求。
|
|
10
|
+
- 查询恢复成功或切换凭据、查询来源后清除对应等待状态,错误信息保持可见,原有费用记录不变。
|
|
11
|
+
|
|
12
|
+
感谢 [@qingyu-ye](https://github.com/qingyu-ye) 在 [issue #409](https://github.com/Han-1413141/dsh-cost-meter/issues/409) 提供问题报告、截图和日志附件。
|
|
13
|
+
|
|
14
|
+
更新后完全重启 DSH,使插件服务端加载新版本。
|
|
15
|
+
|
|
16
|
+
## English
|
|
17
|
+
|
|
18
|
+
This update moves billing guidance into settings and improves balance-query backoff to reduce redundant requests and related operational risks.
|
|
19
|
+
|
|
20
|
+
- Show a brief, muted accuracy note in Settings → Cost → Overview when billion-context usage records are incomplete. Hide it when coverage is normal and remove automatic popups.
|
|
21
|
+
- After HTTP 401/403, official and generic HTTP custom balance queries wait for the configured refresh interval. Manual refresh remains available after correcting authentication.
|
|
22
|
+
- After HTTP 429, automatic, manual and queued refreshes respect `Retry-After`, supporting both seconds and HTTP dates. Missing or invalid headers fall back to the configured interval.
|
|
23
|
+
- Clear the corresponding wait state after recovery or a credential/source change, retain visible error information and preserve existing cost records.
|
|
24
|
+
|
|
25
|
+
Thanks to [@qingyu-ye](https://github.com/qingyu-ye) for the report, screenshots and log attachments in [issue #409](https://github.com/Han-1413141/dsh-cost-meter/issues/409). Fully restart DSH after updating.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Keep HTTP rejection metadata separate from response bodies and credentials. */
|
|
2
|
+
export function balanceHttpError(message, response, now = Date.now()) {
|
|
3
|
+
const error = new Error(message)
|
|
4
|
+
const status = response.status
|
|
5
|
+
if (![401, 403, 429].includes(status)) return error
|
|
6
|
+
error.balanceRetry = true
|
|
7
|
+
if (status === 429) {
|
|
8
|
+
const raw = String(response.headers?.get?.('retry-after') ?? '').trim()
|
|
9
|
+
const deadline = /^\d+$/.test(raw) ? now + Number(raw) * 1000 : Date.parse(raw)
|
|
10
|
+
error.balanceRateLimited = true
|
|
11
|
+
error.balanceRetryAt = Number.isFinite(deadline) && deadline > now ? deadline : 0
|
|
12
|
+
}
|
|
13
|
+
return error
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Authentication failures wait between polls; rate limits also gate manual refresh. */
|
|
17
|
+
export function balanceRetryState(error, interval, now = Date.now()) {
|
|
18
|
+
if (!error?.balanceRetry) return {}
|
|
19
|
+
return {
|
|
20
|
+
fetchedAt: now,
|
|
21
|
+
...(error.balanceRateLimited ? { retryUntil: Math.max(now + interval, error.balanceRetryAt || 0) } : {}),
|
|
22
|
+
}
|
|
23
|
+
}
|