dsh-cost-meter 1.9.67 → 1.9.69
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/display-settings.md +18 -1
- package/docs/plugin-compatibility-watch.md +4 -0
- package/docs/update-notes-1.9.68.md +25 -0
- package/docs/update-notes-1.9.69.md +27 -0
- package/lib/backfill.js +26 -11
- package/lib/billing-history.js +8 -1
- package/lib/client.display.js +2 -2
- package/lib/client.js +9 -9
- package/lib/client.pricing.js +3 -3
- package/lib/client.sidebar-icons.js +2 -0
- package/lib/index.js +3 -3
- package/lib/ledger-writer-worker.js +1 -1
- package/lib/store.js +4 -4
- package/lib/typert.host.js +5 -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.69-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.69/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.69
|
|
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.69**: [release notes](docs/update-notes-1.9.69.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.69-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.69/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.69
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
更新、卸载及无 Git 的安装方法见[安装说明](docs/install.md)。
|
|
55
55
|
|
|
56
56
|
</details>
|
|
57
57
|
|
|
58
|
-
当前版本 **v1.9.
|
|
58
|
+
当前版本 **v1.9.69**:[更新说明](docs/update-notes-1.9.69.md#中文) · [安装排障](docs/install-troubleshooting.md)
|
|
59
59
|
|
|
60
60
|
## 功能总览
|
|
61
61
|
|
package/docs/display-settings.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# 显示设置预览
|
|
2
2
|
|
|
3
|
+
## 图标 / Icons
|
|
4
|
+
|
|
5
|
+
在“费用 → 显示 → 侧栏 → 侧栏布局”主动选择“图标”。原有布局、简洁模式和查询偏好不会自动迁移。图标行沿用上游费用区块,在设置入口上方占用原有区域;不定位或重排设置按钮及其他插件。
|
|
6
|
+
|
|
7
|
+
每个已启用的余额、预算、Coding Plan、Go、Codex、网关、模型或本地节省组件保留一个图标入口。官方余额、自定义余额有独立图形;全部 16 个套餐来源使用可区分的简写标识(不是官方品牌徽标),网关使用来源名称标识,未知自定义来源保留通用兜底和完整名称提示。点击图标展开原有组件,继续使用完整的账户列表、充值链接、刷新、错误与重试操作;再次点击、“收起”或 Escape 关闭。今日用量复用原币种、精度和费用/Token/双项设置;有 Claude 用量时,今日图标的圆环表示 Claude 在今日费用中的占比。保存的组件顺序继续生效,数字紧跟对应图标右侧,整组按顺序排列而不单独吸附侧栏最右;图标较多可横向滚动。开启“今日消费与余额同行”时,点击今日或配对余额图标会在明细中同时展开原有两个组件,继续使用上游同行布局。
|
|
8
|
+
|
|
9
|
+
峰谷圆环不是整个计价阶段的归一化进度:它是固定的 8 小时感知窗口。距下一次切换超过 8 小时时保持满环,提示“距切换超过 8 小时”,不显示动态倒计时;剩余不超过 8 小时才按“剩余时间 / 8 小时”缩短。实际阶段和切换点复用渠道、周末、节假日和自定义时段规则,不修改计价。展开的原有峰谷组件保留其完整信息与原样式设置。
|
|
10
|
+
|
|
11
|
+
窄栏、1023px 及以下视口、粗指针触屏和强制 `data-dsh-pocket-layout="mobile"` 暂使用原有卡片;可随时切回其他布局。可选图标分块加载中或失败时也保留原有组件,失败可重试。样式随组件卸载移除,未新增账户请求或轮询器。
|
|
12
|
+
|
|
13
|
+
Choose **Cost → Display → Sidebar → Sidebar layout → Icons** explicitly. Existing layout preferences are not migrated. The existing full-width cost footer owns placement; this mode adds no host/sidebar class selectors. Every enabled sidebar component keeps an icon entry; click it to disclose its original component and actions, including all account rows, links, refresh, errors and retries. Collapse, the same icon or Escape closes details. Currency, decimal places, cost/token choices and saved component order remain effective. Values sit immediately after their icon, not in a separate right-edge bucket. When Today and balance on one line is enabled, opening either paired icon discloses both original cards in the upstream same-line container. The optional Claude share ring uses the existing cost conversion helper.
|
|
14
|
+
|
|
15
|
+
The peak ring uses a fixed eight-hour countdown horizon, not whole-period progress. Above eight hours it stays full with a threshold message; inside the window it shrinks as remaining time divided by eight hours. Provider calendars and switching times remain upstream-owned. The expanded original peak component keeps its saved presentation and full information.
|
|
16
|
+
|
|
17
|
+
Collapsed rails, viewports up to 1023px, coarse pointers and forced Pocket mobile mode retain the original cards. Loading/failure of the optional icon chunk also retains native content with retry. Cross-platform/theme geometry and real touch interaction require running-UI acceptance; logic/static tests alone do not certify them.
|
|
18
|
+
|
|
19
|
+
|
|
3
20
|
在“费用 → 显示 → 输入区 → 套餐进度条”关闭“显示套餐余额”,输入框上方只保留套餐进度条与百分比,隐藏余额等文本段。默认开启,悬浮详情保留完整信息;该开关不会修改侧栏或账户查询。设置预览同步显示开关效果,保存后重启仍生效。
|
|
4
21
|
|
|
5
22
|
在“费用 → 显示 → 通用设置”(或“侧栏 → 调整组件 → 通用设置”)的“货币单位”中可选择 26 种展示币种。切换时更新符号与该币种的每日参考汇率,小数位保持当前设置;关闭自动更新后使用输入的手动值,切换币种则改用该币种的目录汇率。旧版本保存的自定义币种仍作为一条选项显示。人民币与欧元保留调用时记录的金额,其他币种按最新参考汇率折算;完整说明见[每日汇率与历史金额](exchange-rates.md)。
|
|
@@ -30,7 +47,7 @@ Codex 额度的真实数据来自已启用并登录的 `dsh-codex-subscription`
|
|
|
30
47
|
|
|
31
48
|
预览分为侧栏、输入区和会话内容三个区域,使用正常字号,只渲染当前区域。点击虚线框,在右侧调整对应组件。示例模式下隐藏的组件保留淡化效果,方便再次选中;当前数据模式下未显示的组件保留淡色标签。组件菜单只列出可调整的组件,操作提示不再作为菜单选项。显示设置的更改自动保存。
|
|
32
49
|
|
|
33
|
-
|
|
50
|
+
右侧的“侧栏布局”默认展开,展示图标、合并卡片、简洁、标准和紧凑五种样式的小预览,复用实际预算与多时段额度的进度卡片。小预览标记为样式示例,未配置的额度使用本地示例数值。紧凑样式将多时段额度排成两列,预算卡片保持完整。点击峰谷条可切换细条或分段样式;点击“今日金额 · 模型数”可调整模型卡片的展开、周期、摘要、位置、行数、Token 和费用占比条。预算、余额、会话费用和额度条的选项各自放在对应组件旁。金额格式、换算和语言集中在下方。宽窗口将样式缩略图横向排列,窄窗口再改为竖向;右侧面板在空间不足时排到预览下方。放大预览中按 Escape 返回。
|
|
34
51
|
|
|
35
52
|
侧栏预览和真实侧栏共用完整的呈现函数与当前缓存数据,包含余额错误状态、独立的 Go 与预算卡片、预算摘要、今日用量和峰谷条、模型花费卡片。选择框使用独立覆盖层,不改变组件 DOM 层级和紧凑布局。打开时最多读取三个宿主表面的背景、圆角、字体等六项外观属性;主题属性变化时更新。共用插件组件、DSH 图标和主题变量,跟随这些外观的皮肤修改;其他插件的独立控件不重复挂载。
|
|
36
53
|
|
|
@@ -91,6 +91,10 @@ node test/codex-subscription-published.mjs
|
|
|
91
91
|
|
|
92
92
|
兼容基线更新为 3.2.4,两个既有宿主的 CI 矩阵均加入该实际发布包。
|
|
93
93
|
|
|
94
|
+
### 2026-11-16:billion-context 0.1.215、dsh-codex-subscription 3.2.17 / 3.2.18
|
|
95
|
+
|
|
96
|
+
两类插件接口指纹保持一致。billion-context 0.1.215 的原生与代理计费、原版 CLI 自动接入、重试、摘要、子代理、回放和重启检查通过。dsh-codex-subscription 3.2.17、3.2.18 的发布包 RPC、额度解析、刷新、账号缓存切换、认证错误和取消检查通过。测试使用本机服务与合成数据,外部请求为 0。基线和 CI 更新至 0.1.215、3.2.18。
|
|
97
|
+
|
|
94
98
|
### 2026-11-15:billion-context 0.1.214
|
|
95
99
|
|
|
96
100
|
处理 github-actions[bot] 在 [#504](https://github.com/Han-1413141/dsh-cost-meter/issues/504) 报告的五个接入函数变化。新版拆分首字节与响应体超时,调整摘要日志、错误响应清理,以及原生请求的代理选项和预填充请求头处理。
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# v1.9.68
|
|
2
|
+
|
|
3
|
+
## 中文
|
|
4
|
+
|
|
5
|
+
- 修复历史费用重算因调用次数差异而跳过 Token 完整记录的问题。按 Token 计价时,五类 Token 一致即可重算,账本原有调用次数保持不变;按请求收费的搜索和抓取仍核对请求次数。
|
|
6
|
+
- 重算记录可展开查看未重算的会话、日期、模型,以及账本与日志的用量差值。日志缺少 Token 时保留原金额。
|
|
7
|
+
- 本会话费用的悬停提示增加“仅主会话”或“含子代理”。开关位于「费用 → 显示 → 输入区 → 本会话费用 → 本会话费用包含子代理」。
|
|
8
|
+
|
|
9
|
+
感谢 [@PersueFree](https://github.com/PersueFree) 在 [#509](https://github.com/Han-1413141/dsh-cost-meter/issues/509) 提供三组账本与日志数据、重算判断定位、usage 存储形式及子代理统计范围反馈。
|
|
10
|
+
|
|
11
|
+
## English
|
|
12
|
+
|
|
13
|
+
- Recalculate Token-priced history when all five Token totals match, even if call counts differ. Preserve the ledger's original counts. Search and fetch request fees still require matching request counts.
|
|
14
|
+
- Expand recalculation records to see unchanged sessions, dates, models and ledger/log differences. Records with missing Tokens retain their original amounts.
|
|
15
|
+
- Session-cost tooltips now state “Main session only” or “Includes subagents”. The switch is under Costs → Display → Input area → Session cost → Include subagents in session cost.
|
|
16
|
+
|
|
17
|
+
Thanks to [@PersueFree](https://github.com/PersueFree) for the reproduction data, code location and subagent display feedback in [#509](https://github.com/Han-1413141/dsh-cost-meter/issues/509).
|
|
18
|
+
|
|
19
|
+
## 升级 / Upgrade
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
dsh plugin --profile web add dsh-cost-meter@latest
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
更新后重启 DSH。Desktop 用户参见 [安装与更新](https://github.com/Han-1413141/dsh-cost-meter/blob/v1.9.68/docs/install-troubleshooting.md#desktop-安装与更新)。
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# v1.9.69
|
|
2
|
+
|
|
3
|
+
## 中文
|
|
4
|
+
|
|
5
|
+
- 「费用 → 价格 → 模型定价 → 自定义 → 更多计费项」增加长上下文价格,可设置输入 Token 阈值,以及输入、缓存读取、输出、缓存写入和单独推理的单价。输入与缓存读写合计超过阈值时应用长档。
|
|
6
|
+
- 从参考价格复制或编辑自定义价格时,保留长上下文、峰谷等已支持字段,修复长档丢失的问题。
|
|
7
|
+
- 「费用 → 显示 → 侧栏 → 侧栏布局」新增“图标”。点击图标展开原有组件,支持多账号余额及原有操作;已有布局保持不变。峰谷圆环使用固定 8 小时窗口。
|
|
8
|
+
- 验证 billion-context 0.1.215 以及 dsh-codex-subscription 3.2.17 / 3.2.18,更新兼容性基线。
|
|
9
|
+
|
|
10
|
+
感谢 [@PersueFree](https://github.com/PersueFree) 在 [#511](https://github.com/Han-1413141/dsh-cost-meter/issues/511) 提供问题报告、复现和定位;感谢 [@chanyuenpang](https://github.com/chanyuenpang) 在 [#514](https://github.com/Han-1413141/dsh-cost-meter/pull/514) 提供图标布局、构建优化和测试。
|
|
11
|
+
|
|
12
|
+
## English
|
|
13
|
+
|
|
14
|
+
- Edit long-context thresholds and rates under Model pricing → Custom → More billing fields. The threshold includes input and cache read/write Tokens.
|
|
15
|
+
- Preserve long-context, peak/off-peak and other supported price fields when copying or editing custom quotes.
|
|
16
|
+
- Add an opt-in Icons sidebar layout. Click an icon for the original component and its actions, including multiple account balances. The peak ring uses a fixed eight-hour countdown window.
|
|
17
|
+
- Verify billion-context 0.1.215 and dsh-codex-subscription 3.2.17 / 3.2.18, and update compatibility baselines.
|
|
18
|
+
|
|
19
|
+
Thanks to [@PersueFree](https://github.com/PersueFree) for the report and reproduction in [#511](https://github.com/Han-1413141/dsh-cost-meter/issues/511), and [@chanyuenpang](https://github.com/chanyuenpang) for the implementation and tests in [#514](https://github.com/Han-1413141/dsh-cost-meter/pull/514).
|
|
20
|
+
|
|
21
|
+
## 升级 / Upgrade
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
dsh plugin --profile web add dsh-cost-meter@latest
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
更新后重启 DSH。Desktop 用户参见 [安装与更新](https://github.com/Han-1413141/dsh-cost-meter/blob/v1.9.69/docs/install-troubleshooting.md#desktop-安装与更新)。
|
package/lib/backfill.js
CHANGED
|
@@ -20,6 +20,7 @@ import { localDayKey, zeroDay, splitLedgerApiCost } from './store.js'
|
|
|
20
20
|
import { billingClassOf, enabledPlanSetOf, planProviderIdOf, isRoutedThirdPartyCall, appendHourBucket, planUsageFingerprint, HOUR_BUCKET_RETENTION_MS, localMidnightMs } from './plan-billing.js'
|
|
21
21
|
import { USAGE_DEDUP_WINDOW_MS, usageFingerprint } from './usage-dedup.js'
|
|
22
22
|
import { isNativeSearchUsageEvent } from './native-search-events.js'
|
|
23
|
+
import { isWebRequestModel } from './web-request-pricing.js'
|
|
23
24
|
import { listSessionLogFiles } from './session-log-files.js'
|
|
24
25
|
import { listNativeSearchHistory, readNativeSearchHistory, nativeSearchRecordsFor } from './native-search-history.js'
|
|
25
26
|
import { BILLION_USAGE_EVENT, billionRecordsFor, excludeBillionReportedUsage, listBillionFiles, iterateBillionCalls } from './billion-context-history.js'
|
|
@@ -1099,7 +1100,7 @@ export async function importLegacyHistory(ledger, sessionsRoot, sessionSource =
|
|
|
1099
1100
|
* 对比时表现为偏差扩大。本函数把存储口径统一到当前表,消除双口径。
|
|
1100
1101
|
*
|
|
1101
1102
|
* 安全边界(纯重定价,绝不改变 token 计量):
|
|
1102
|
-
* -
|
|
1103
|
+
* - 仅当回放桶与账本行键集合一致且逐键五桶相等才替换金额;按请求收费还需 calls 相等。不一致
|
|
1103
1104
|
* (日志缺失/新旧去重差异/数据异常)的会话保持旧口径,计入 skippedSessions;
|
|
1104
1105
|
* - 账本中不存在的会话不新增(避免与实时计费重复);回放不到的日期不动
|
|
1105
1106
|
* (日志已清理的历史保留原口径,作为残差);
|
|
@@ -1116,6 +1117,7 @@ export async function importLegacyHistory(ledger, sessionsRoot, sessionSource =
|
|
|
1116
1117
|
*/
|
|
1117
1118
|
export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeBucket, onlySessionIds = null, explicit = false, model = '', sessionSource = null) {
|
|
1118
1119
|
const result = { scanned: 0, recostedSessions: 0, skippedSessions: 0, recostedDays: 0 }
|
|
1120
|
+
if (explicit) result.skippedDetails = []
|
|
1119
1121
|
const pricingConfig = explicit ? currentPricingConfig(ledger.config) : ledger.config
|
|
1120
1122
|
if (explicit && model) pricingConfig._repriceFxConfig = ledger.config
|
|
1121
1123
|
const originalPricing = explicit ? JSON.stringify(pricingSnapshot(ledger.config)) : null
|
|
@@ -1149,7 +1151,10 @@ export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeB
|
|
|
1149
1151
|
const amount = day => model ? Number(day.byProviderModel?.[model]?.cost) || 0 : day.cost
|
|
1150
1152
|
if (explicit) result.before = Object.values(ledger.days).reduce((sum, day) => sum + amount(day), 0)
|
|
1151
1153
|
if (explicit && model) for (const [unit, field] of [['Cny', 'costCny'], ['Eur', 'costEur']]) result['before' + unit] = Object.values(ledger.days).reduce((sum, day) => sum + (Number(day.byProviderModel?.[model]?.[field]) || 0), 0)
|
|
1152
|
-
const tokenFields = ['input', 'output', 'cacheRead', 'cacheWrite', 'reasoning'
|
|
1154
|
+
const tokenFields = ['input', 'output', 'cacheRead', 'cacheWrite', 'reasoning']
|
|
1155
|
+
const detail = (sessionId, date, model, reason, fields = []) => {
|
|
1156
|
+
if (explicit) result.skippedDetails.push({ sessionId, date, model, reason, fields })
|
|
1157
|
+
}
|
|
1153
1158
|
for (const [sessionId, days] of bySession) {
|
|
1154
1159
|
for (const [date, pm] of Object.entries(days)) {
|
|
1155
1160
|
const day = ledger.days?.[date]
|
|
@@ -1159,18 +1164,24 @@ export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeB
|
|
|
1159
1164
|
if (model && !Object.hasOwn(oldPm, model)) continue
|
|
1160
1165
|
const newKeys = Object.keys(pm)
|
|
1161
1166
|
const dayPm = day.byProviderModel !== null && typeof day.byProviderModel === 'object' ? day.byProviderModel : {}
|
|
1162
|
-
//
|
|
1163
|
-
// 含全部键。任何一条不满足都保持旧口径,杜绝半改状态。
|
|
1167
|
+
// Token 计价只要求五桶一致;按请求收费仍须核对 calls。重算只改金额,保留账本计量。
|
|
1164
1168
|
let replaceable = newKeys.length > 0 && newKeys.length === Object.keys(oldPm).length
|
|
1165
|
-
for (const key of newKeys) {
|
|
1169
|
+
for (const key of new Set([...Object.keys(oldPm), ...newKeys])) {
|
|
1166
1170
|
const oldBucket = oldPm[key]
|
|
1167
1171
|
const dayBucket = dayPm[key]
|
|
1168
1172
|
const newBucket = pm[key]
|
|
1169
|
-
if (oldBucket === undefined ||
|
|
1170
|
-
|
|
1171
|
-
|
|
1173
|
+
if (oldBucket === undefined || newBucket === undefined || dayBucket === undefined) {
|
|
1174
|
+
replaceable = false
|
|
1175
|
+
detail(sessionId, date, key, oldBucket === undefined ? 'ledgerModelMissing' : newBucket === undefined ? 'logModelMissing' : 'dayModelMissing')
|
|
1176
|
+
continue
|
|
1177
|
+
}
|
|
1178
|
+
const fields = [...tokenFields, 'calls'].map(field => ({ field, ledger: Number(oldBucket[field]) || 0, log: Number(newBucket[field]) || 0 }))
|
|
1179
|
+
.filter(row => row.ledger !== row.log)
|
|
1180
|
+
const colon = key.indexOf(':')
|
|
1181
|
+
if (fields.some(row => row.field !== 'calls' || isWebRequestModel(key.slice(0, colon), key.slice(colon + 1)))) {
|
|
1182
|
+
replaceable = false
|
|
1183
|
+
detail(sessionId, date, key, 'usage', fields)
|
|
1172
1184
|
}
|
|
1173
|
-
if (!replaceable) break
|
|
1174
1185
|
}
|
|
1175
1186
|
if (!replaceable) {
|
|
1176
1187
|
result.skippedSessions += 1
|
|
@@ -1189,7 +1200,8 @@ export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeB
|
|
|
1189
1200
|
row[field] = (row[field] ?? 0) + delta; day[field] = (day[field] ?? 0) + delta
|
|
1190
1201
|
dayPm[key][field] = (dayPm[key][field] ?? 0) + delta
|
|
1191
1202
|
}
|
|
1192
|
-
row.byProviderModel[key] = { ...pm[key]
|
|
1203
|
+
row.byProviderModel[key] = { ...oldPm[key], cost: pm[key].cost, apiCost: pm[key].apiCost,
|
|
1204
|
+
...Object.fromEntries(FX_FIELDS.map(field => [field, pm[key][field] ?? 0])) }
|
|
1193
1205
|
row.cost = (Number(row.cost) || 0) + costDelta
|
|
1194
1206
|
row.apiCost = (Number(row.apiCost) || 0) + apiDelta
|
|
1195
1207
|
day.cost = (Number(day.cost) || 0) + costDelta
|
|
@@ -1208,7 +1220,10 @@ export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeB
|
|
|
1208
1220
|
result.after = Object.values(ledger.days).reduce((sum, day) => sum + amount(day), 0)
|
|
1209
1221
|
if (model) for (const [unit, field] of [['Cny', 'costCny'], ['Eur', 'costEur']]) result['after' + unit] = Object.values(ledger.days).reduce((sum, day) => sum + (Number(day.byProviderModel?.[model]?.[field]) || 0), 0)
|
|
1210
1222
|
for (const [date, day] of Object.entries(ledger.days)) for (const row of day.sessions ?? []) {
|
|
1211
|
-
if ((!model || Object.hasOwn(row.byProviderModel ?? {}, model)) && !bySession.get(row.id)?.[date])
|
|
1223
|
+
if ((!model || Object.hasOwn(row.byProviderModel ?? {}, model)) && !bySession.get(row.id)?.[date]) {
|
|
1224
|
+
result.skippedSessions++
|
|
1225
|
+
detail(row.id, date, model, 'logMissing')
|
|
1226
|
+
}
|
|
1212
1227
|
}
|
|
1213
1228
|
}
|
|
1214
1229
|
return result
|
package/lib/billing-history.js
CHANGED
|
@@ -25,6 +25,12 @@ const ratesOnly = (value, memo) => memoized(value, memo?.rates, () => Array.isAr
|
|
|
25
25
|
? Object.fromEntries(Object.entries(value).filter(([key]) => rateFields.has(key) || multiplierPath.test(key)).map(([key, child]) => [key, ratesOnly(child, memo)])) : value)
|
|
26
26
|
const modelsOnly = (models, memo) => memoized(models, memo?.models, () => Object.fromEntries(Object.entries(models ?? {}).filter(([key]) => safe(key)).map(([key, entry]) => [key, ratesOnly(entry, memo)])))
|
|
27
27
|
const runFields = ['at', 'before', 'after', 'days', 'sessions', 'skipped']
|
|
28
|
+
export function validRepricingDetail(row) {
|
|
29
|
+
return typeof row?.sessionId === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(row.date) && typeof row.model === 'string'
|
|
30
|
+
&& ['usage', 'ledgerModelMissing', 'logModelMissing', 'dayModelMissing', 'logMissing'].includes(row.reason)
|
|
31
|
+
&& Array.isArray(row.fields) && row.fields.every(item => ['input', 'output', 'cacheRead', 'cacheWrite', 'reasoning', 'calls'].includes(item?.field)
|
|
32
|
+
&& Number.isFinite(item.ledger) && item.ledger >= 0 && Number.isFinite(item.log) && item.log >= 0)
|
|
33
|
+
}
|
|
28
34
|
const compare = (a, b) => a.at - b.at || (a.sequence ?? 0) - (b.sequence ?? 0) || a.version.localeCompare(b.version)
|
|
29
35
|
function indexOf(history) {
|
|
30
36
|
let index = indexes.get(history)
|
|
@@ -94,7 +100,8 @@ export function normalizePricingHistory(raw, config, previous, stored = false) {
|
|
|
94
100
|
&& (row.model === undefined || (typeof row.model === 'string' && row.model.includes(':') && row.model.length <= 2048))
|
|
95
101
|
&& /^\d{4}-\d{2}-\d{2}$/.test(row.date) && Number.isFinite(row.at) && versions[row.version]))
|
|
96
102
|
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))
|
|
97
|
-
.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 } : {})
|
|
103
|
+
.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 } : {}),
|
|
104
|
+
...(Array.isArray(row.skippedDetails) ? { skippedDetails: row.skippedDetails.filter(validRepricingDetail) } : {}) }]))
|
|
98
105
|
const fxChanges = Object.fromEntries(Object.entries(raw.fxChanges ?? {}).filter(([id, row]) => safe(id) && Number.isFinite(row?.at) && row.at >= 0 && ['CNY', 'EUR'].every(key => Number.isFinite(row.rates?.[key]) && row.rates[key] > 0)))
|
|
99
106
|
if (!Object.keys(fxChanges).length) for (const [id, row] of Object.entries(changes)) fxChanges[id] = { at: row.at, sequence: row.sequence ?? 0, rates: fxHistoryRatesOf({ ...versions[row.version], currency: config.currency }) }
|
|
100
107
|
const history = { versions, changes, revisions, runs, fxChanges }
|