dsh-cost-meter 1.9.71 → 1.9.73
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 +4 -4
- package/README.zh-CN.md +4 -4
- package/docs/plugin-compatibility-watch.md +8 -0
- package/docs/update-notes-1.9.71.md +3 -3
- package/docs/update-notes-1.9.72.md +29 -0
- package/docs/update-notes-1.9.73.md +29 -0
- package/lib/backfill.js +17 -3
- package/lib/billing-history.js +13 -4
- package/lib/bootstrap.js +1 -1
- package/lib/client.js +1 -1
- package/lib/index.js +34 -3
- package/lib/ledger-writer-worker.js +1 -1
- package/lib/pricing.js +28 -5
- package/lib/session-storage-compat.js +53 -9
- package/lib/turn-cost.js +2 -2
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<p align="center">Cost tracking and subscription quotas for DeepSeek Harness</p>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
|
-
<a href="https://github.com/Han-1413141/dsh-cost-meter/releases/latest"><img src="https://img.shields.io/badge/version-1.9.
|
|
6
|
+
<a href="https://github.com/Han-1413141/dsh-cost-meter/releases/latest"><img src="https://img.shields.io/badge/version-1.9.73-4176E6?style=flat-square" alt="version"></a>
|
|
7
7
|
<a href="https://www.npmjs.com/package/dsh-cost-meter"><img src="https://img.shields.io/npm/dm/dsh-cost-meter?label=downloads&style=flat-square&color=4176E6" alt="npm monthly downloads"></a>
|
|
8
8
|
<a href="https://github.com/Han-1413141/dsh-cost-meter/stargazers"><img src="https://img.shields.io/github/stars/Han-1413141/dsh-cost-meter?label=stars&style=flat-square&color=D9A400" alt="GitHub stars"></a>
|
|
9
9
|
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-green?style=flat-square" alt="MIT license"></a>
|
|
@@ -42,20 +42,20 @@ Restart `dsh web` after installation or updates. **Desktop** uses its bundled CL
|
|
|
42
42
|
The PowerShell installer checks pnpm and Git and uses the `web` profile by default:
|
|
43
43
|
|
|
44
44
|
```powershell
|
|
45
|
-
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.9.
|
|
45
|
+
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.9.73/install.ps1 | iex
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
Install a pinned Git tag:
|
|
49
49
|
|
|
50
50
|
```sh
|
|
51
|
-
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.9.
|
|
51
|
+
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.9.73
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
See [installation and updates](docs/install.en.md) for uninstalling or installing without Git.
|
|
55
55
|
|
|
56
56
|
</details>
|
|
57
57
|
|
|
58
|
-
Current release **v1.9.
|
|
58
|
+
Current release **v1.9.73**: [release notes](docs/update-notes-1.9.73.md#english) · [troubleshooting](docs/install-troubleshooting.md)
|
|
59
59
|
|
|
60
60
|
## Feature overview
|
|
61
61
|
|
package/README.zh-CN.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<p align="center">DeepSeek Harness 费用统计与订阅额度插件</p>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
|
-
<a href="https://github.com/Han-1413141/dsh-cost-meter/releases/latest"><img src="https://img.shields.io/badge/version-1.9.
|
|
6
|
+
<a href="https://github.com/Han-1413141/dsh-cost-meter/releases/latest"><img src="https://img.shields.io/badge/version-1.9.73-4176E6?style=flat-square" alt="version"></a>
|
|
7
7
|
<a href="https://www.npmjs.com/package/dsh-cost-meter"><img src="https://img.shields.io/npm/dm/dsh-cost-meter?label=downloads&style=flat-square&color=4176E6" alt="npm monthly downloads"></a>
|
|
8
8
|
<a href="https://github.com/Han-1413141/dsh-cost-meter/stargazers"><img src="https://img.shields.io/github/stars/Han-1413141/dsh-cost-meter?label=stars&style=flat-square&color=D9A400" alt="GitHub stars"></a>
|
|
9
9
|
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-green?style=flat-square" alt="MIT license"></a>
|
|
@@ -42,20 +42,20 @@ dsh plugin --profile web add dsh-cost-meter
|
|
|
42
42
|
PowerShell 脚本自动检查 pnpm 和 Git,默认安装到 `web` Profile:
|
|
43
43
|
|
|
44
44
|
```powershell
|
|
45
|
-
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.9.
|
|
45
|
+
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.9.73/install.ps1 | iex
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
固定 Git tag 安装:
|
|
49
49
|
|
|
50
50
|
```sh
|
|
51
|
-
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.9.
|
|
51
|
+
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.9.73
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
更新、卸载及无 Git 的安装方法见[安装说明](docs/install.md)。
|
|
55
55
|
|
|
56
56
|
</details>
|
|
57
57
|
|
|
58
|
-
当前版本 **v1.9.
|
|
58
|
+
当前版本 **v1.9.73**:[更新说明](docs/update-notes-1.9.73.md#中文) · [安装排障](docs/install-troubleshooting.md)
|
|
59
59
|
|
|
60
60
|
## 功能总览
|
|
61
61
|
|
|
@@ -104,3 +104,11 @@ SHA-512 校验、静态契约检查和实际发布包回归通过:原生及代
|
|
|
104
104
|
### 2026-11-17:Codex Subscription 3.2.19 与 Connect 0.2.0-alpha.15
|
|
105
105
|
|
|
106
106
|
处理 github-actions[bot] 的 [#520](https://github.com/Han-1413141/dsh-cost-meter/issues/520)、[#521](https://github.com/Han-1413141/dsh-cost-meter/issues/521)。两个官方 npm 包的 SHA-512 与元数据一致,静态契约匹配;实际发布包的额度解析、单周和双窗口、账号切换、刷新、失败处理及只读 HTTP/RPC 检查通过。Connect 的记录类型判断函数由打包器重新编号,测试按发布包中的原始声明读取,不改写函数。费用插件运行时代码无需调整。基线与 CI 保留旧版本并加入上述版本,外部账户及模型请求为 0。
|
|
107
|
+
|
|
108
|
+
### 2026-11-17:billion-context 0.1.216
|
|
109
|
+
|
|
110
|
+
处理 github-actions[bot] 在 [#524](https://github.com/Han-1413141/dsh-cost-meter/issues/524) 报告的版本变化。官方发布包 SHA-512 校验通过,接入函数指纹未变。实际发布包的原生与代理计费、四种协议、压缩、重试、缓存、父子会话、API/Plan 分类、回放、重启、取消及原版 CLI 自动接入检查通过。检查使用合成数据和本机服务,外部模型请求为 0。现有 v1.9.71 运行时代码已兼容;本次更新兼容基线并将 0.1.216 加入 CI。
|
|
111
|
+
|
|
112
|
+
### 2026-11-18:Codex Subscription 3.2.21
|
|
113
|
+
|
|
114
|
+
官方发布包 SHA-512 校验通过,四个额度接入函数语法指纹及静态契约未变。实际发布包的额度解析、单周和双窗口、默认缓存、强制刷新、账号切换、共享请求取消、登录失效及只读 HTTP/RPC 检查通过;测试仅使用合成数据与本机服务,外部账户及模型请求为 0。兼容基线更新至 `3.2.21`,两个既有宿主的 CI 矩阵均保留旧版本并加入 `3.2.21`。
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
- 图标模式加入 DeepSeek、Claude、OpenAI/Codex、OpenCode 和 13 个常见套餐来源的品牌 Logo,离线内嵌并跟随主题前景色;金额组排在图标之后,其他图标保留已保存的相对顺序。
|
|
10
10
|
- 验证 dsh-codex-subscription 3.2.19 和 dsh-codex-connect 0.2.0-alpha.15,更新兼容基线与 CI。
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
发布后更正(2026-11-17):[#522 的报告者已确认](https://github.com/Han-1413141/dsh-cost-meter/issues/522#issuecomment-6947573099),Go chip 在真实手指点击下正常打开,消息行用量图标属于 DSH 宿主;原报告已撤回并关闭。本版 Go 详情属于交互改进,不再列为已确认故障的修复。
|
|
13
13
|
|
|
14
14
|
感谢以下贡献者:
|
|
15
15
|
|
|
16
16
|
- [@chanyuenpang](https://github.com/chanyuenpang) 在 [#517](https://github.com/Han-1413141/dsh-cost-meter/pull/517) 提供品牌 Logo 和图标布局代码。
|
|
17
17
|
- [@T0TT](https://github.com/T0TT) 在 [#518](https://github.com/Han-1413141/dsh-cost-meter/issues/518) 报告同行文字对齐问题并提供 CSS 建议。
|
|
18
18
|
- [@MCXCC303](https://github.com/MCXCC303) 在 [#519](https://github.com/Han-1413141/dsh-cost-meter/issues/519) 报告 MiniMax 已用 99% 显示为 0% 的问题。
|
|
19
|
-
- [@seeker-Chh](https://github.com/seeker-Chh) 在 [#522](https://github.com/Han-1413141/dsh-cost-meter/issues/522) 提供 Android
|
|
19
|
+
- [@seeker-Chh](https://github.com/seeker-Chh) 在 [#522](https://github.com/Han-1413141/dsh-cost-meter/issues/522) 提供 Android 点击排查信息,并[更正问题归属、撤回原报告](https://github.com/Han-1413141/dsh-cost-meter/issues/522#issuecomment-6947573099)。
|
|
20
20
|
- [@github-actions[bot]](https://github.com/apps/github-actions) 通过 [#520](https://github.com/Han-1413141/dsh-cost-meter/issues/520) 和 [#521](https://github.com/Han-1413141/dsh-cost-meter/issues/521) 报告上游插件版本变化。
|
|
21
21
|
|
|
22
22
|
## English
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
- Bundle theme-aware provider logos offline. Keep the value group after all icons while preserving the other icons' saved relative order.
|
|
29
29
|
- Verify dsh-codex-subscription 3.2.19 and dsh-codex-connect 0.2.0-alpha.15, and update compatibility baselines and CI.
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
Post-release correction (2026-11-17): the reporter [withdrew and closed #522](https://github.com/Han-1413141/dsh-cost-meter/issues/522#issuecomment-6947573099). Real taps open the Go chip normally, and the message-row usage icon belongs to the DSH host. The Go details change is an interaction improvement, not a confirmed bug fix.
|
|
32
32
|
|
|
33
33
|
## 升级 / Upgrade
|
|
34
34
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# v1.9.72
|
|
2
|
+
|
|
3
|
+
## 中文
|
|
4
|
+
|
|
5
|
+
- 修复官方账户渠道 `deepseek-account` 及 `llm-deepseek-account` 的价格匹配:精确模式直接使用官方模型目录,自动模式不再受其他渠道的同名价格干扰。
|
|
6
|
+
- 同步修复实际记账、客户端价格显示与消息下方本轮费用,保留官方峰谷计价、人民币计价、渠道自有价格和手动覆盖。
|
|
7
|
+
- 未知模型仍显示缺价提示,本地零消耗继续保持零费用和正常 Token 统计。已保存的账单不会自动改写。
|
|
8
|
+
- 验证 billion-context 0.1.216,更新兼容基线与 CI。
|
|
9
|
+
- 根据报告者的后续更正,将 #522 标为已撤回并关闭;v1.9.71 的 Go 点击详情按交互改进记录。
|
|
10
|
+
|
|
11
|
+
感谢 [@pb-pang](https://github.com/pb-pang) 在 [#526](https://github.com/Han-1413141/dsh-cost-meter/issues/526) 提供官方账户渠道、模型、升级前后账本和环境信息。
|
|
12
|
+
|
|
13
|
+
## English
|
|
14
|
+
|
|
15
|
+
- Restore official price lookup for `deepseek-account` and `llm-deepseek-account`. Exact mode now uses the official model catalog; auto mode no longer treats another provider's quote for the same model as an ambiguity.
|
|
16
|
+
- Apply the fix to ledger billing, client price displays and per-turn costs while preserving official peak/off-peak schedules, CNY pricing, provider-specific quotes and manual overrides.
|
|
17
|
+
- Keep unknown models unpriced and local inference at known zero prices with token counts retained. Saved bills are not rewritten automatically.
|
|
18
|
+
- Verify billion-context 0.1.216 and update the compatibility baseline and CI.
|
|
19
|
+
- Record the withdrawal and closure of #522. The Go details change in v1.9.71 is an interaction improvement, not a confirmed bug fix.
|
|
20
|
+
|
|
21
|
+
Thanks to [@pb-pang](https://github.com/pb-pang) for the provider/model details, before-and-after ledger records and environment information in [#526](https://github.com/Han-1413141/dsh-cost-meter/issues/526).
|
|
22
|
+
|
|
23
|
+
## 升级 / Upgrade
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
dsh plugin --profile web add dsh-cost-meter@latest
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
更新后重启 DSH。Desktop 用户参见 [安装与更新](https://github.com/Han-1413141/dsh-cost-meter/blob/v1.9.72/docs/install-troubleshooting.md#desktop-安装与更新)。
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# v1.9.73
|
|
2
|
+
|
|
3
|
+
## 中文
|
|
4
|
+
|
|
5
|
+
- 修复旧版本升级账本缺少 `deepseek-flash` 条目导致 `magpie:deepseek/deepseek-flash` 等转发路由无法自动匹配 DeepSeek 官方价格的问题:启动时一次性补齐缺失的官方 Flash 规范模型名,保留用户自定义单价及主动移除设置。
|
|
6
|
+
- 修复长会话在历史重算、回填和 RDB 会话读取时,因内存中展开超过 20 万条流式文本/推理增量块而触发事件上限并被误判为“日志缺失”的问题。
|
|
7
|
+
- 修复此前未定价(金额为 0)的会话因宿主自动标题生成等未写入会话日志的附属调用残差而无法重算的问题:按已记录调用重算金额并同步更新本会话费用明细(消除 `0 + ?`),保留账本原有 Token 与调用次数,且重启后仍可继续重算;已有正数费用的不完整日志继续保留原金额。
|
|
8
|
+
- 当插件文件已在磁盘更新但宿主尚未重启时,历史重算提示会明确提醒重启 DSH 使新版服务生效。
|
|
9
|
+
- 验证 `dsh-codex-subscription` 3.2.21,更新兼容基线与 CI。
|
|
10
|
+
|
|
11
|
+
感谢 [@JokerQyou](https://github.com/JokerQyou) 在 [#499 评论](https://github.com/Han-1413141/dsh-cost-meter/issues/499#issuecomment-6967300277) 反馈 `magpie:deepseek/deepseek-flash` 自动匹配缺失及 651 次长会话历史重算问题并提供截图。
|
|
12
|
+
|
|
13
|
+
## English
|
|
14
|
+
|
|
15
|
+
- Mount missing canonical `deepseek-flash` entries once on upgraded pre-v1.8.33 ledgers when existing DeepSeek Flash models are present, restoring automatic official price matching for routes such as `magpie:deepseek/deepseek-flash` without overwriting custom rates or resurrecting cleared catalogs.
|
|
16
|
+
- Filter unpacked streaming text, reasoning and tool-input delta chunks before applying session event limits in backfill, historical recalculation and RDB usage reads, preventing large conversations (e.g. 650+ calls with >200k raw stream chunks) from aborting as missing logs.
|
|
17
|
+
- Allow explicit historical recalculation for previously unpriced (`cost = 0`) model buckets whose ledger totals include unlogged host auxiliary calls (such as automatic title generation), preserving recorded token/call counts, updating per-session billing details (`0 + ?`) and keeping subsequent recalculations idempotent across restarts; already-priced partial logs remain protected.
|
|
18
|
+
- Append a restart reminder when historical recalculation runs while updated plugin files on disk have not yet been loaded by DSH.
|
|
19
|
+
- Verify `dsh-codex-subscription` 3.2.21 and update the compatibility baseline and CI.
|
|
20
|
+
|
|
21
|
+
Thanks to [@JokerQyou](https://github.com/JokerQyou) for reporting the `magpie:deepseek/deepseek-flash` auto-matching gap and large-session historical recalculation failure with screenshots in [#499 (comment)](https://github.com/Han-1413141/dsh-cost-meter/issues/499#issuecomment-6967300277).
|
|
22
|
+
|
|
23
|
+
## 升级 / Upgrade
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
dsh plugin --profile web add dsh-cost-meter@latest
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
更新后请**完全退出并重启 DSH** 以加载新版宿主服务。Desktop 用户参见 [安装与更新](https://github.com/Han-1413141/dsh-cost-meter/blob/v1.9.73/docs/install-troubleshooting.md#desktop-安装与更新)。
|
package/lib/backfill.js
CHANGED
|
@@ -24,7 +24,7 @@ import { isWebRequestModel } from './web-request-pricing.js'
|
|
|
24
24
|
import { listSessionLogFiles } from './session-log-files.js'
|
|
25
25
|
import { listNativeSearchHistory, readNativeSearchHistory, nativeSearchRecordsFor } from './native-search-history.js'
|
|
26
26
|
import { BILLION_USAGE_EVENT, billionRecordsFor, excludeBillionReportedUsage, listBillionFiles, iterateBillionCalls } from './billion-context-history.js'
|
|
27
|
-
import { pricingConfigAt, recordPricingRevision, currentPricingConfig, pricingSnapshot, pricingHistoryFingerprint } from './billing-history.js'
|
|
27
|
+
import { pricingConfigAt, recordPricingRevision, hasUnloggedResidualRevision, currentPricingConfig, pricingSnapshot, pricingHistoryFingerprint } from './billing-history.js'
|
|
28
28
|
|
|
29
29
|
const ZSTD_MAGIC = 4247762216
|
|
30
30
|
/** 打包行(文本/推理/工具调用增量游程)不含 header 与 usage,回放时跳过。 */
|
|
@@ -1166,6 +1166,7 @@ export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeB
|
|
|
1166
1166
|
const dayPm = day.byProviderModel !== null && typeof day.byProviderModel === 'object' ? day.byProviderModel : {}
|
|
1167
1167
|
// Token 计价只要求五桶一致;按请求收费仍须核对 calls。重算只改金额,保留账本计量。
|
|
1168
1168
|
let replaceable = newKeys.length > 0 && newKeys.length === Object.keys(oldPm).length
|
|
1169
|
+
const residualModels = []
|
|
1169
1170
|
for (const key of new Set([...Object.keys(oldPm), ...newKeys])) {
|
|
1170
1171
|
const oldBucket = oldPm[key]
|
|
1171
1172
|
const dayBucket = dayPm[key]
|
|
@@ -1175,10 +1176,22 @@ export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeB
|
|
|
1175
1176
|
detail(sessionId, date, key, oldBucket === undefined ? 'ledgerModelMissing' : newBucket === undefined ? 'logModelMissing' : 'dayModelMissing')
|
|
1176
1177
|
continue
|
|
1177
1178
|
}
|
|
1179
|
+
if (model && key !== model) continue
|
|
1178
1180
|
const fields = [...tokenFields, 'calls'].map(field => ({ field, ledger: Number(oldBucket[field]) || 0, log: Number(newBucket[field]) || 0 }))
|
|
1179
1181
|
.filter(row => row.ledger !== row.log)
|
|
1180
1182
|
const colon = key.indexOf(':')
|
|
1181
|
-
|
|
1183
|
+
const webRequest = isWebRequestModel(key.slice(0, colon), key.slice(colon + 1))
|
|
1184
|
+
if (fields.some(row => row.field !== 'calls' || webRequest)) {
|
|
1185
|
+
// 此前未定价(cost=0)的会话若仅有宿主未写入日志的附属调用残差(如自动标题生成,账本五桶 ≥ 日志五桶且日志有实际调用),
|
|
1186
|
+
// 允许按已记录日志调用重算并在价格修订中登记该模型,避免整段历史与本会话明细永久卡在 0 + ?;已记过正数金额的桶仍严格保留原值。
|
|
1187
|
+
const wasUnpriced = ((Number(oldBucket.cost) || 0) === 0 && (Number(oldBucket.apiCost) || 0) === 0)
|
|
1188
|
+
|| hasUnloggedResidualRevision(ledger.pricingHistory, sessionId, date, key)
|
|
1189
|
+
const logIsSubset = !webRequest && (Number(newBucket.calls) || 0) > 0
|
|
1190
|
+
&& tokenFields.every(field => (Number(oldBucket[field]) || 0) >= (Number(newBucket[field]) || 0))
|
|
1191
|
+
if (explicit && wasUnpriced && logIsSubset) {
|
|
1192
|
+
residualModels.push(key)
|
|
1193
|
+
continue
|
|
1194
|
+
}
|
|
1182
1195
|
replaceable = false
|
|
1183
1196
|
detail(sessionId, date, key, 'usage', fields)
|
|
1184
1197
|
}
|
|
@@ -1212,7 +1225,8 @@ export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeB
|
|
|
1212
1225
|
}
|
|
1213
1226
|
result.recostedSessions += 1
|
|
1214
1227
|
touchedDates.add(date)
|
|
1215
|
-
|
|
1228
|
+
const selectedResiduals = residualModels.filter(key => selected.includes(key))
|
|
1229
|
+
if (explicit && ledger.pricingHistory) recordPricingRevision(ledger.pricingHistory, pricingConfig, sessionId, date, startedAt, previousAmount, { cost: row.cost, apiCost: row.apiCost }, model, selectedResiduals)
|
|
1216
1230
|
}
|
|
1217
1231
|
}
|
|
1218
1232
|
result.recostedDays = touchedDates.size
|
package/lib/billing-history.js
CHANGED
|
@@ -35,12 +35,15 @@ const compare = (a, b) => a.at - b.at || (a.sequence ?? 0) - (b.sequence ?? 0) |
|
|
|
35
35
|
function indexOf(history) {
|
|
36
36
|
let index = indexes.get(history)
|
|
37
37
|
if (index) return index
|
|
38
|
-
const revisions = new Map()
|
|
38
|
+
const revisions = new Map(), residualModels = new Set()
|
|
39
39
|
for (const row of Object.values(history.revisions)) {
|
|
40
40
|
const key = JSON.stringify([row.sessionId, row.date, row.model ?? '']), previous = revisions.get(key)
|
|
41
41
|
if (!previous || compare(row, previous) >= 0) revisions.set(key, row)
|
|
42
|
+
if (Array.isArray(row.unloggedResidualModels)) {
|
|
43
|
+
for (const item of row.unloggedResidualModels) residualModels.add(JSON.stringify([row.sessionId, row.date, item]))
|
|
44
|
+
}
|
|
42
45
|
}
|
|
43
|
-
index = { changes: Object.values(history.changes).sort(compare), revisions, fingerprint: hash([history.changes, history.revisions, history.fxChanges]), fx: Object.values(history.fxChanges ?? {}).sort((a, b) => a.at - b.at || (a.sequence ?? 0) - (b.sequence ?? 0)) }
|
|
46
|
+
index = { changes: Object.values(history.changes).sort(compare), revisions, residualModels, fingerprint: hash([history.changes, history.revisions, history.fxChanges]), fx: Object.values(history.fxChanges ?? {}).sort((a, b) => a.at - b.at || (a.sequence ?? 0) - (b.sequence ?? 0)) }
|
|
44
47
|
indexes.set(history, index)
|
|
45
48
|
return index
|
|
46
49
|
}
|
|
@@ -100,6 +103,7 @@ export function normalizePricingHistory(raw, config, previous, stored = false) {
|
|
|
100
103
|
}
|
|
101
104
|
const revisions = Object.fromEntries(Object.entries(raw.revisions ?? {}).filter(([id, row]) => safe(id) && typeof row?.sessionId === 'string'
|
|
102
105
|
&& (row.model === undefined || (typeof row.model === 'string' && row.model.includes(':') && row.model.length <= 2048))
|
|
106
|
+
&& (row.unloggedResidualModels === undefined || (Array.isArray(row.unloggedResidualModels) && row.unloggedResidualModels.every(item => typeof item === 'string' && item.includes(':') && item.length <= 2048)))
|
|
103
107
|
&& /^\d{4}-\d{2}-\d{2}$/.test(row.date) && Number.isFinite(row.at) && versions[row.version]))
|
|
104
108
|
const runs = Object.fromEntries(Object.entries(object(raw.runs) ? raw.runs : {}).filter(([id, row]) => safe(id) && runFields.every(key => Number.isFinite(row?.[key]) && row[key] >= 0))
|
|
105
109
|
.map(([id, row]) => [id, { ...Object.fromEntries([...runFields, ...['beforeCny', 'afterCny', 'beforeEur', 'afterEur'].filter(key => Number.isFinite(row[key]) && row[key] >= 0)].map(key => [key, row[key]])), ...(typeof row.model === 'string' ? { model: row.model } : {}),
|
|
@@ -169,13 +173,18 @@ export function pricingConfigAt(config, at, sessionId = '', model = '') {
|
|
|
169
173
|
}
|
|
170
174
|
|
|
171
175
|
/** Repricing affects only fully replayable session/day records explicitly accepted by the user. */
|
|
172
|
-
export function recordPricingRevision(history, config, sessionId, date, at, before, after, model = '') {
|
|
176
|
+
export function recordPricingRevision(history, config, sessionId, date, at, before, after, model = '', unloggedResidualModels = []) {
|
|
173
177
|
const pricing = pricingSnapshot(config), version = hash(pricing)
|
|
174
178
|
rememberPriceVersion(history.versions, version, pricing, indexOf(history).changes.at(-1)?.version)
|
|
175
|
-
|
|
179
|
+
const residuals = Array.isArray(unloggedResidualModels) && unloggedResidualModels.length ? [...new Set(unloggedResidualModels)] : null
|
|
180
|
+
history.revisions[randomUUID()] = { sessionId, date, at, ...(model ? { model, preserveFx: true } : { fxRates: fxHistoryRatesOf(config) }), ...(residuals ? { unloggedResidualModels: residuals } : {}), sequence: Object.keys(history.revisions).length + 1, version, before, after }
|
|
176
181
|
indexes.delete(history)
|
|
177
182
|
}
|
|
178
183
|
|
|
184
|
+
export function hasUnloggedResidualRevision(history, sessionId, date, model) {
|
|
185
|
+
return Boolean(history && typeof model === 'string' && model.length > 0 && indexOf(history).residualModels.has(JSON.stringify([sessionId, date, model])))
|
|
186
|
+
}
|
|
187
|
+
|
|
179
188
|
export function mergePricingHistory(local, disk) {
|
|
180
189
|
if (!local) return disk
|
|
181
190
|
if (!disk) return local
|
package/lib/bootstrap.js
CHANGED
|
@@ -38,4 +38,4 @@ Issue: `+wi);return i.code=e==="version_too_old"?"BILLION_VERSION_TOO_OLD":"BILL
|
|
|
38
38
|
`}else{N(t==="native","unknown_runtime_kind");let c=u("installNativeFetchIntercept"),x=Q(c.body,"send"),g=!1;$(c.body,b=>{b.type==="CallExpression"&&b.callee.type==="MemberExpression"&&b.callee.object.name==="Object"&&b.callee.property.name==="defineProperty"&&b.arguments[1]?.value==="fetch"&&(g=!0)});let v=Q(c.body,"installFetchChain").length;N(x.length>0&&(v===1||v===0&&g&&Q(c.body,"makeChain").length>0)&&Q(c.body,"fetch").length===0,"native_transport_changed");for(let{item:b}of x)N(b.arguments.length>=1&&!b.optional,"native_send_changed"),n.push({start:b.start,end:b.end,text:"__dshCmSend(send, "+b.arguments.map(k=>e.slice(k.start,k.end)).join(", ")+")"});o.nativeSends=x.length,o.nativeTransport=v?"chain":"global-fetch-accessor",d=`import { sendWithBillionMeter as __dshCmSend } from ${JSON.stringify(i.native??"./cost-meter-native.js")};
|
|
39
39
|
`}n.sort((c,x)=>x.start-c.start||x.end-c.end);for(let c=1;c<n.length;c++)N(n[c].end<=n[c-1].start,"overlapping_runtime_hooks");for(let c of n)e=e.slice(0,c.start)+c.text+e.slice(c.end);let y=e.startsWith("#!")?e.indexOf(`
|
|
40
40
|
`)+1:0;e=e.slice(0,y)+d+e.slice(y);try{Oe(e,{sourceType:"module",ecmaVersion:"latest"})}catch{throw ge("patched_syntax_changed")}return{source:e,capabilities:o}}var be=Symbol.for("dsh-cost-meter.billion-context.auto.v1"),Ti=Symbol.for("dsh-cost-meter.billion-context.peers.v1"),Vt=Symbol.for("dsh-cost-meter.billion-context.v1"),Fe="x-dsh-cost-meter-group",Li=new URL("./billion-context-preload.js",import.meta.url).href,Ri=e=>["127.0.0.1","localhost","[::1]","::1"].includes(e.hostname);function Tt(e){if(!Number.isSafeInteger(e)||e<1)return!1;try{return process.kill(e,0),!0}catch(t){return t.code==="EPERM"}}function Lt(e){try{let t=new URL(e.path,String(e.origin));return Ri(t)&&t.protocol==="http:"?t:null}catch{return null}}function ve(e,t){if(Array.isArray(e)){for(let i=0;i<e.length;i+=2)if(String(e[i]).toLowerCase()===t)return String(e[i+1])}else if(typeof e=="string"){for(let i of e.split(`\r
|
|
41
|
-
`))if(i.slice(0,i.indexOf(":")).toLowerCase()===t)return i.slice(i.indexOf(":")+1).trim()}else if(e&&typeof e=="object")return e[t]==null?null:String(e[t]);return null}function Me(e){if(Ue(e).size>32*1024*1024)throw Error("runtime_size_changed");return Pi(e,"utf8")}function Oi(e,t={},i=new Map){if(!Array.isArray(e)||typeof e[0]!="string"||e[0].startsWith("-"))return null;let s;try{s=Ni(Vi(t.cwd??process.cwd(),e[0]))}catch{return null}if(je(s)!=="index.js"||je(De(s))!=="dist")return null;let a=De(De(s)),n;try{n=JSON.parse(Me(Nt(a,"package.json")))}catch{return null}if(n.name!=="billion-context"||n.dshCostMeterCompatibility)return null;if(Pt(n.version)!==!0)return{version:n.version,reason:"needs_update"};if(typeof Rt.register!="function")return{version:n.version,reason:"bridge_missing"};try{let o=Nt(a,"dist/agent/dsh-native.js"),u=[Ue(s),Ue(o)],h=s+":"+u.map(y=>[y.size,y.mtimeMs,y.ctimeMs].join(":")).join(":");if(i.has(h))return i.get(h);let f=Me(s);Be(f,"proxy"),Be(Me(o),"native");let d={script:s,version:n.version,fingerprint:Ii("sha256").update(f).digest("hex")};return i.set(h,d),i.size>8&&i.delete(i.keys().next().value),d}catch{return{version:n.version,reason:"changed"}}}function Ot(){let e=!1,t=c=>()=>{e||(e=!0,Bi(c))},i=globalThis[be];if(i)return i.references++,i.issue&&globalThis[Vt]?.adapterStatus?.(i.issue.version,i.issue.reason),t(i);let s=Ai.ChildProcess.prototype,a=s.spawn,n=new Map,o=new WeakMap,u=new Map,h=globalThis[Ti]??=new Map;i={references:1,original:a,subscriptions:[],children:u,prototype:s};let f=()=>globalThis[Vt],d=function(c){if(i.references<=0||!c||!Array.isArray(c.args)||!Array.isArray(c.envPairs))return a.apply(this,arguments);let x=c.file,g=c.args.slice(1);if(typeof x!="string"||!["node","node.exe","nodejs"].includes(je(x).toLowerCase())&&!c.envPairs.includes("ELECTRON_RUN_AS_NODE=1"))return a.apply(this,arguments);let v;try{v=Oi(g,c,n)}catch{}try{v?.reason&&(i.issue=v,f()?.adapterStatus?.(v.version,v.reason))}catch{}if(!v||v.reason)return a.apply(this,arguments);i.issue=void 0;let b=c.envPairs.filter(ye=>!ye.startsWith("DSH_COST_METER_BILLION_LOADER="));b.push("DSH_COST_METER_BILLION_LOADER="+JSON.stringify({script:v.script,fingerprint:v.fingerprint}));let k=a.call(this,{...c,args:[c.args[0],"--import",Li,...g],envPairs:b}),E=this;u.set(E.pid,E);let ee=()=>{u.delete(E.pid);for(let[ye,Ft]of h)Ft.pid===E.pid&&h.delete(ye)};return E.once("exit",ee),E.once("error",ee),k};i.wrapped=d,s.spawn=d;let y=(c,x)=>{let g=b=>{try{x(b)}catch{}},v=Ei(c);v.subscribe(g),i.subscriptions.push(()=>v.unsubscribe(g))};return y("undici:request:create",({request:c})=>{let x=Lt(c);if(c.method!=="POST")return;if(!x||!x.pathname.startsWith("/bili/")){f()?.begin?.(new URL(c.path,String(c.origin)).href);return}if(ve(c.headers,Fe))return;let g=h.get(x.origin);if(!g||!Tt(g.pid)){h.delete(x.origin),f()?.unsupported?.({changed:!1,missing:!g});return}let v=f(),b=v?.begin(x.href);b&&(c.addHeader(Fe,b),o.set(c,{bridge:v,id:b,origin:x.origin}))}),y("undici:request:headers",({request:c,response:x})=>{let g=Lt(c);if(g&&c.method==="GET"&&g.pathname==="/__bili/health"){let k=Number(ve(x.headers,"x-dsh-cost-meter-pid"));x.statusCode===200&&ve(x.headers,"x-dsh-cost-meter-protocol")==="1"&&Tt(k)?(h.set(g.origin,{pid:k}),h.size>128&&h.delete(h.keys().next().value)):h.delete(g.origin)}let v=o.get(c);if(!v)return;o.delete(c);let b=ve(x.headers,Fe)===v.id;v.bridge.ack(v.id,b),b||h.delete(v.origin)}),y("undici:request:error",({request:c})=>{let x=o.get(c);x&&(o.delete(c),x.bridge.ack(x.id,!1,{transient:!0}),h.delete(x.origin))}),globalThis[be]=i,t(i)}function Bi(e){if(!(--e.references>0||globalThis[be]!==e)){for(let t of e.subscriptions)t();e.prototype.spawn===e.wrapped&&(e.prototype.spawn=e.original),delete globalThis[be]}}var qe=Ot(),Bt;try{Bt=await import("./index.js")}catch(e){throw qe(),e}var Dt=setTimeout(qe,0);Dt.unref?.();var Zi="cost-meter";function Ji(e){clearTimeout(Dt);try{return Bt.apply(e)}finally{qe()}}export{Ji as apply,Zi as name};
|
|
41
|
+
`))if(i.slice(0,i.indexOf(":")).toLowerCase()===t)return i.slice(i.indexOf(":")+1).trim()}else if(e&&typeof e=="object")return e[t]==null?null:String(e[t]);return null}function Me(e){if(Ue(e).size>32*1024*1024)throw Error("runtime_size_changed");return Pi(e,"utf8")}function Oi(e,t={},i=new Map){if(!Array.isArray(e)||typeof e[0]!="string"||e[0].startsWith("-"))return null;let s;try{s=Ni(Vi(t.cwd??process.cwd(),e[0]))}catch{return null}if(je(s)!=="index.js"||je(De(s))!=="dist")return null;let a=De(De(s)),n;try{n=JSON.parse(Me(Nt(a,"package.json")))}catch{return null}if(n.name!=="billion-context"||n.dshCostMeterCompatibility)return null;if(Pt(n.version)!==!0)return{version:n.version,reason:"needs_update"};if(typeof Rt.register!="function")return{version:n.version,reason:"bridge_missing"};try{let o=Nt(a,"dist/agent/dsh-native.js"),u=[Ue(s),Ue(o)],h=s+":"+u.map(y=>[y.size,y.mtimeMs,y.ctimeMs].join(":")).join(":");if(i.has(h))return i.get(h);let f=Me(s);Be(f,"proxy"),Be(Me(o),"native");let d={script:s,version:n.version,fingerprint:Ii("sha256").update(f).digest("hex")};return i.set(h,d),i.size>8&&i.delete(i.keys().next().value),d}catch{return{version:n.version,reason:"changed"}}}function Ot(){let e=!1,t=c=>()=>{e||(e=!0,Bi(c))},i=globalThis[be];if(i)return i.references++,i.issue&&globalThis[Vt]?.adapterStatus?.(i.issue.version,i.issue.reason),t(i);let s=Ai.ChildProcess.prototype,a=s.spawn,n=new Map,o=new WeakMap,u=new Map,h=globalThis[Ti]??=new Map;i={references:1,original:a,subscriptions:[],children:u,prototype:s};let f=()=>globalThis[Vt],d=function(c){if(i.references<=0||!c||!Array.isArray(c.args)||!Array.isArray(c.envPairs))return a.apply(this,arguments);let x=c.file,g=c.args.slice(1);if(typeof x!="string"||!["node","node.exe","nodejs"].includes(je(x).toLowerCase())&&!c.envPairs.includes("ELECTRON_RUN_AS_NODE=1"))return a.apply(this,arguments);let v;try{v=Oi(g,c,n)}catch{}try{v?.reason&&(i.issue=v,f()?.adapterStatus?.(v.version,v.reason))}catch{}if(!v||v.reason)return a.apply(this,arguments);i.issue=void 0;let b=c.envPairs.filter(ye=>!ye.startsWith("DSH_COST_METER_BILLION_LOADER="));b.push("DSH_COST_METER_BILLION_LOADER="+JSON.stringify({script:v.script,fingerprint:v.fingerprint}));let k=a.call(this,{...c,args:[c.args[0],"--import",Li,...g],envPairs:b}),E=this;u.set(E.pid,E);let ee=()=>{u.delete(E.pid);for(let[ye,Ft]of h)Ft.pid===E.pid&&h.delete(ye)};return E.once("exit",ee),E.once("error",ee),k};i.wrapped=d,s.spawn=d;let y=(c,x)=>{let g=b=>{try{x(b)}catch{}},v=Ei(c);v.subscribe(g),i.subscriptions.push(()=>v.unsubscribe(g))};return y("undici:request:create",({request:c})=>{let x=Lt(c);if(c.method!=="POST")return;if(!x||!x.pathname.startsWith("/bili/")){f()?.begin?.(new URL(c.path,String(c.origin)).href);return}if(ve(c.headers,Fe))return;let g=h.get(x.origin);if(!g||!Tt(g.pid)){h.delete(x.origin),f()?.unsupported?.({changed:!1,missing:!g});return}let v=f(),b=v?.begin(x.href);b&&(c.addHeader(Fe,b),o.set(c,{bridge:v,id:b,origin:x.origin}))}),y("undici:request:headers",({request:c,response:x})=>{let g=Lt(c);if(g&&c.method==="GET"&&g.pathname==="/__bili/health"){let k=Number(ve(x.headers,"x-dsh-cost-meter-pid"));x.statusCode===200&&ve(x.headers,"x-dsh-cost-meter-protocol")==="1"&&Tt(k)?(h.set(g.origin,{pid:k}),h.size>128&&h.delete(h.keys().next().value)):h.delete(g.origin)}let v=o.get(c);if(!v)return;o.delete(c);let b=ve(x.headers,Fe)===v.id;v.bridge.ack(v.id,b),b||h.delete(v.origin)}),y("undici:request:error",({request:c})=>{let x=o.get(c);x&&(o.delete(c),x.bridge.ack(x.id,!1,{transient:!0}),h.delete(x.origin))}),globalThis[be]=i,t(i)}function Bi(e){if(!(--e.references>0||globalThis[be]!==e)){for(let t of e.subscriptions)t();e.prototype.spawn===e.wrapped&&(e.prototype.spawn=e.original),delete globalThis[be]}}var qe=Ot(),Bt;try{Bt=await import(new URL("./index.js"+new URL(import.meta.url).search,import.meta.url).href)}catch(e){throw qe(),e}var Dt=setTimeout(qe,0);Dt.unref?.();var Zi="cost-meter";function Ji(e){clearTimeout(Dt);try{return Bt.apply(e)}finally{qe()}}export{Ji as apply,Zi as name};
|