dsh-cost-meter 1.9.39 → 1.9.41
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/ledger-lock-recovery.md +12 -0
- package/docs/update-notes-1.9.31.md +1 -1
- package/docs/update-notes-1.9.40.md +25 -0
- package/docs/update-notes-1.9.41.md +29 -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-persistence.js +43 -7
- package/lib/ledger-totals.js +57 -57
- package/lib/ledger-writer-worker.js +1 -1
- package/lib/store.js +27 -2
- package/package.json +4 -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 可在今日组件中单独开启;两项保留悬停详情,余额进度条照常显示,隐藏官方余额时使用第一条可见的自定义余额。排序在设置预览中调整,关闭开关恢复各组件独立排列。
|
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## English
|
|
4
4
|
|
|
5
|
+
### Configuration recovery after an abnormal shutdown
|
|
6
|
+
|
|
7
|
+
The ledger and its independent `ledger.json.config-bak` are written to temporary files in the same directory, flushed, and then renamed over their destinations. POSIX systems also flush the directory after replacement. The backup stores only configuration and migration markers, using the ledger's existing secret filtering; credentials remain in the DSH credential store and configuration placeholders are preserved. Usage-only updates do not rewrite an unchanged backup.
|
|
8
|
+
|
|
9
|
+
A healthy existing ledger creates or updates this backup when loaded. If the ledger is corrupt, the original `.corrupt-*` file is retained and settings are recovered from the backup. A missing ledger can also use the backup. The log reports successful restoration and the number of custom balance sources; an unreadable backup is reported and defaults are used. Usage history continues through the existing backfill mechanism. An already zeroed file from before this protection, with no backup, contains no settings to recover. See [#412](https://github.com/Han-1413141/dsh-cost-meter/issues/412).
|
|
10
|
+
|
|
5
11
|
Issue [#237](https://github.com/Han-1413141/dsh-cost-meter/issues/237) reports a startup failure with **Ledger is busy; preserving pending changes for retry**. The sidebar balance and quota widgets disappear because the cost-meter loader entry did not activate. An old lock can name a PID that now belongs to a different process; checking only whether that PID exists cannot identify the original owner.
|
|
6
12
|
|
|
7
13
|
### Update and recover
|
|
@@ -25,6 +31,12 @@ Implementation references: [Linux process start ticks](https://man7.org/linux/ma
|
|
|
25
31
|
|
|
26
32
|
## 简体中文
|
|
27
33
|
|
|
34
|
+
### 异常退出后的配置恢复
|
|
35
|
+
|
|
36
|
+
账本及独立的 `ledger.json.config-bak` 均先写入同目录临时文件,刷盘后再替换目标文件;POSIX 系统同时同步目录。备份只保存配置和迁移记录,沿用账本的脱敏规则,凭据仍由 DSH 凭据库保存,配置中的占位符保留。仅用量变化时不重写配置备份。
|
|
37
|
+
|
|
38
|
+
已有的正常账本加载时即建立或更新备份。账本损坏后保留原始 `.corrupt-*` 文件,并从备份恢复设置;账本缺失时同样读取备份。日志显示恢复结果及自定义余额源数量;备份也无法读取时记录错误并使用默认配置。用量历史继续由现有补录流程处理。启用此保护之前已经全零且没有备份的文件,没有可恢复的配置内容。问题来源:[#412](https://github.com/Han-1413141/dsh-cost-meter/issues/412)。
|
|
39
|
+
|
|
28
40
|
Issue [#237](https://github.com/Han-1413141/dsh-cost-meter/issues/237) 报告启动时出现 **Ledger is busy; preserving pending changes for retry**。费用插件未成功挂载,侧栏余额和额度卡片随之消失。旧锁中的 PID 可能已经被系统分配给另一个进程,仅检查 PID 是否存在不能确认原锁持有者。
|
|
29
41
|
|
|
30
42
|
### 升级与恢复
|
|
@@ -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,29 @@
|
|
|
1
|
+
# v1.9.41:Web 启动修复与账本配置恢复
|
|
2
|
+
|
|
3
|
+
## 中文
|
|
4
|
+
|
|
5
|
+
本次更新修复 Web 端插件加载失败,并增加账本配置的独立备份与恢复。
|
|
6
|
+
|
|
7
|
+
- 为 `conversation.chat.turnTail` 补齐 chain 插槽要求的 `select`,修复启动时的 `requires options.select` 报错。
|
|
8
|
+
- 账本与 `ledger.json.config-bak` 均先写入同目录临时文件、刷盘,再替换目标文件。POSIX 系统同时同步目录;临时文件刷盘或替换失败时保留原文件。
|
|
9
|
+
- 正常账本加载时建立配置备份,之后仅在配置或迁移记录变化时更新。备份沿用现有脱敏规则,保留凭据占位符。
|
|
10
|
+
- 账本损坏或缺失时,从备份恢复自定义余额源等设置;保留损坏账本,并在日志中显示恢复结果。用量历史继续由现有补录流程处理。
|
|
11
|
+
|
|
12
|
+
此前已经全零且没有备份的文件,没有可恢复的配置内容。
|
|
13
|
+
|
|
14
|
+
感谢 [@korion3](https://github.com/korion3) 在 [#413](https://github.com/Han-1413141/dsh-cost-meter/issues/413) 报告、定位 Web 启动故障,并在 [#414](https://github.com/Han-1413141/dsh-cost-meter/pull/414) 提供修复;感谢 [@kevindawn11-hash](https://github.com/kevindawn11-hash) 在 [#412](https://github.com/Han-1413141/dsh-cost-meter/issues/412) 提供账本损坏证据与配置备份建议。
|
|
15
|
+
|
|
16
|
+
更新后完全重启 DSH,使插件服务端加载新版本。
|
|
17
|
+
|
|
18
|
+
## English
|
|
19
|
+
|
|
20
|
+
This update fixes Web plugin startup and adds independent configuration backup and recovery.
|
|
21
|
+
|
|
22
|
+
- Add the required `select` function to the `conversation.chat.turnTail` chain slot, fixing the startup error `requires options.select`.
|
|
23
|
+
- Write the ledger and `ledger.json.config-bak` to temporary files in the same directory, flush them, then replace their destinations. POSIX systems also flush the directory; file-sync or replacement failures preserve the original file.
|
|
24
|
+
- Create a configuration backup when a healthy ledger loads, then update it only when configuration or migration markers change. The backup uses existing secret filtering and preserves credential placeholders.
|
|
25
|
+
- Restore settings, including custom balance sources, when the ledger is corrupt or missing. Keep the corrupt ledger and log the restoration result. Usage history continues through the existing backfill process.
|
|
26
|
+
|
|
27
|
+
A file that was already zeroed before this protection, with no backup, contains no configuration to recover.
|
|
28
|
+
|
|
29
|
+
Thanks to [@korion3](https://github.com/korion3) for the report and diagnosis in [#413](https://github.com/Han-1413141/dsh-cost-meter/issues/413) and the fix in [#414](https://github.com/Han-1413141/dsh-cost-meter/pull/414), and to [@kevindawn11-hash](https://github.com/kevindawn11-hash) for the corruption evidence and backup suggestions in [#412](https://github.com/Han-1413141/dsh-cost-meter/issues/412). 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
|
+
}
|