dsh-cost-meter 1.8.24 → 1.8.26
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 +19 -8
- package/README.zh-CN.md +18 -7
- package/docs/factory-quota.md +33 -0
- package/lib/backfill.js +46 -1
- package/lib/client.community.js +1 -0
- package/lib/client.js +5 -5
- package/lib/coding-plans.js +15 -7
- package/lib/factory-quota.js +69 -0
- package/lib/index.js +42 -4
- package/lib/ledger-persistence.js +26 -2
- package/lib/plan-billing.js +19 -5
- package/lib/plan-provider-match.js +18 -0
- package/lib/store.js +35 -3
- package/lib/typert.host.js +5 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
**English** | [简体中文](README.zh-CN.md)
|
|
4
4
|
|
|
5
|
+
Community and feedback: [Join the WeChat group →](#community). The WeChat group is open. You're welcome to join.
|
|
6
|
+
|
|
5
7
|
<div align="center">
|
|
6
8
|
|
|
7
9
|
**Session cost tracking plugin for the DeepSeek Harness web GUI (bilingual UI)**
|
|
8
10
|
|
|
9
|
-
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; weekends and Chinese public holidays are off-peak all day, with separate labels) · 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 170+ model-ID catalog with auto-matching) · mainstream Coding Plan quota queries & display (Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet / Volcano Ark / Qwen / Xiaomi MiMo) plan/API dual-track billing (subscription quota vs pay-as-you-go money separated, per-1% & full-window token/equivalent-cost estimates with daily/weekly/monthly curves) · · quota strip above the input box (budget / Go / coding-plan usage in one row, toggleable)
|
|
11
|
+
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; weekends and Chinese public holidays are off-peak all day, with separate labels) · 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 170+ model-ID catalog with auto-matching) · mainstream Coding Plan quota queries & display (Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet / Volcano Ark / Qwen / Xiaomi MiMo / Factory Droid) plan/API dual-track billing (subscription quota vs pay-as-you-go money separated, per-1% & full-window token/equivalent-cost estimates with daily/weekly/monthly curves) · · quota strip above the input box (budget / Go / coding-plan usage in one row, toggleable)
|
|
10
12
|
|
|
11
|
-
[](https://github.com/Han-1413141/dsh-cost-meter)
|
|
12
14
|
|
|
13
|
-
**v1.8.
|
|
15
|
+
**v1.8.26** fixes custom-provider plan matching with manual plan assignment, explicit name-based detection and recovery of fully covered recent usage. See the [plan assignment guide](docs/token-plan-stats.md#assigning-custom-providers-to-a-plan).
|
|
14
16
|
|
|
15
17
|
Desktop users: follow the [Desktop installation instructions](docs/install-troubleshooting.md#desktop-安装与更新) for the application's own CLI and `desktop` Profile.
|
|
16
18
|
|
|
@@ -90,7 +92,7 @@ For Qianwen / Alibaba Cloud fund accounts, use **Add Qianwen / Alibaba Cloud bal
|
|
|
90
92
|
|
|
91
93
|
Qwen Token Plan can use the [official CLI subscription quota](docs/qwen-cli-quota.md#english). Install the CLI on the DSH host and run `qianwen auth login` as the same OS user. Local estimates remain the default; CLI mode shows current account credits without changing the local ledger.
|
|
92
94
|
|
|
93
|
-
Local Qwen Token Plan credits include
|
|
95
|
+
Local Qwen Token Plan credits include Plan calls assigned to Qwen. Existing subscription aliases such as `qwen` and `qwen-tokenplan` remain supported; custom providers can select Qwen under Model statistics → Billing class, or use an explicit vendor name and plan marker for auto detection. Explicit API calls are excluded. The pay-as-you-go `qianwen` provider is not assigned merely because its model ID is identical. Models outside the credits table need all three rates configured.
|
|
94
96
|
|
|
95
97
|
Xiaomi MiMo Token Plan quotas are queried with the **MiMo console cookie**, not an API key: log in at `platform.xiaomimimo.com`, press F12 → Network → find the `balanceAlertConfig` request and paste the full `cookie` request header into the MiMo card in Settings → Cost → Quotas (it must include `serviceToken` and `userId`; the DSH credential store keeps it as `MIMO_COOKIE`). The card shows the plan/compensation credit windows with the period-end reset (Beijing time) plus a balance row. Copy a fresh console cookie when the card reports an expired login. Token Plan inference keys (`tp-*` / `ttp-*`) are not accepted by this console adapter. Local plan statistics use the calendar month; compensation and balance are displayed without estimates because local calls cannot be attributed to those pools.
|
|
96
98
|
|
|
@@ -323,22 +325,22 @@ On Node.js 20, use `npm install -g pnpm@10` instead. See [pnpm installation and
|
|
|
323
325
|
dsh plugin --profile web add dsh-cost-meter
|
|
324
326
|
```
|
|
325
327
|
|
|
326
|
-
**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.8.
|
|
328
|
+
**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.8.26`** — review the script before running):
|
|
327
329
|
|
|
328
330
|
```powershell
|
|
329
|
-
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.
|
|
331
|
+
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.26/install.ps1 | iex
|
|
330
332
|
```
|
|
331
333
|
|
|
332
334
|
**Or a plain command line** (the machine must already have pnpm and git; also pinned to the tag):
|
|
333
335
|
|
|
334
336
|
```sh
|
|
335
|
-
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.
|
|
337
|
+
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.26
|
|
336
338
|
```
|
|
337
339
|
|
|
338
340
|
Without git, use the GitHub tag archive:
|
|
339
341
|
|
|
340
342
|
```sh
|
|
341
|
-
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.
|
|
343
|
+
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.26.tar.gz
|
|
342
344
|
```
|
|
343
345
|
|
|
344
346
|
After installing, **restart** `dsh web` (plugin rows, the Typert manifest and the client bundle are all scanned at startup):
|
|
@@ -509,6 +511,15 @@ Check and clear the host search before changing stored data.
|
|
|
509
511
|
- Plan/API classification is inferred from channel and config; mixed subscription/PAYG usage of one vendor (e.g. Kimi) can be overridden per provider:model in settings.
|
|
510
512
|
- A restart of `dsh web` is required after installing/updating the plugin.
|
|
511
513
|
|
|
514
|
+
## Community
|
|
515
|
+
|
|
516
|
+
Join the WeChat group to discuss the plugin, share feedback, and suggest features.
|
|
517
|
+
|
|
518
|
+
<p align="center">
|
|
519
|
+
<a href="docs/community-wechat.jpg"><img src="docs/community-wechat.jpg" alt="dsh-cost-meter WeChat community QR code" width="320" /></a><br />
|
|
520
|
+
<a href="docs/community-wechat.jpg">View full-size QR code</a>
|
|
521
|
+
</p>
|
|
522
|
+
|
|
512
523
|
## Update history
|
|
513
524
|
|
|
514
525
|
A per-version overview and the community-issue resolution log live in [docs/UPDATE-HISTORY.md](docs/UPDATE-HISTORY.md) (中文); the itemized changelog is [CHANGELOG.md](CHANGELOG.md).
|
package/README.zh-CN.md
CHANGED
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
[English](README.md) | **简体中文**
|
|
4
4
|
|
|
5
|
+
交流与反馈:[加入微信交流群 →](#交流与反馈) · 微信交流群已开放,欢迎您加入。
|
|
6
|
+
|
|
5
7
|
<div align="center">
|
|
6
8
|
|
|
7
9
|
**DeepSeek Harness 会话费用统计插件(界面中英双语)**
|
|
8
10
|
|
|
9
11
|
本会话费用 · 当日费用 · OpenCode Go 订阅额度显示 · 预算与已用百分比 · 官方账户余额 · 自定义 Provider 余额查询(可配任意 HTTP 端点) · 余额三段进度条 · 历史记录 · 峰谷计价时段显示(UTC 01:00–04:00、06:00–10:00 为峰时段;周末与中国法定假日全天按谷价,分别标注) · 峰/谷切换前弹窗与系统通知提醒(位置/提前量/提醒类型可配) · 官方价格一键同步 · 类 Codex Token 用量热图 · 多厂商多模型价格计费(内置 170+ 模型 ID 价格目录与自动匹配) · 主流 Coding Plan 额度查询与显示(Anthropic / Z.ai / MiniMax / Kimi / OpenRouter / SiliconFlow / CommandCode / SCNet / 火山方舟 / 千问 / 小米 MiMo 十一家,含 Volcano Ark AK/SK 签名与 MiMo 控制台 Cookie 查询) · Plan/API 双轨计费(订阅额度与按量金额分离统计,每 1% 额度与满窗的 token/等值金额估算及日/周/月曲线) · 输入框上方额度横条(预算/Go/Coding Plan 用量一条横排显示,可开关)
|
|
10
12
|
|
|
11
|
-
[](https://github.com/Han-1413141/dsh-cost-meter)
|
|
12
14
|
|
|
13
|
-
**v1.8.
|
|
15
|
+
**v1.8.26** 修复自定义渠道的套餐匹配,支持手动选择套餐和按名称特征自动归属,并恢复能完整核对的近期用量。详见 [套餐归属说明](docs/token-plan-stats.md#自定义渠道如何关联套餐)。
|
|
14
16
|
|
|
15
17
|
桌面端用户请按 [Desktop 安装说明](docs/install-troubleshooting.md#desktop-安装与更新),使用应用自带的 CLI 和 `desktop` Profile。
|
|
16
18
|
|
|
@@ -89,7 +91,7 @@
|
|
|
89
91
|
|
|
90
92
|
千问 Token Plan 可在卡片内选择[官方 CLI 订阅额度](docs/qwen-cli-quota.md),需在 DSH 主机以同一系统账号安装 CLI 并运行 `qianwen auth login`。默认保留本地估算;CLI 模式显示账号当前 Credits,不修改本地账本。
|
|
91
93
|
|
|
92
|
-
千问 Token Plan 的本地 Credits
|
|
94
|
+
千问 Token Plan 的本地 Credits 统计归属千问套餐的 Plan 调用。保留 `qwen`、`qwen-tokenplan` 等订阅别名,自定义渠道也可在「按模型统计 → 计费方式」选择千问套餐,或使用明确的厂商名与套餐特征自动识别。显式 API 调用不计;`qianwen` 按量渠道不会仅因同名模型自动归入。模型不在抵扣表中时需补充三项费率。
|
|
93
95
|
|
|
94
96
|
小米 MiMo Token Plan 的额度查询使用**控制台 Cookie**(而非 API Key):登录 `platform.xiaomimimo.com` 后按 F12 →「网络」→ 找到 `balanceAlertConfig` 请求,把请求头 `cookie` 整段粘贴进「设置 → 费用 → 额度」的 MiMo 卡片(需含 `serviceToken` 与 `userId`,DSH 凭据库以 `MIMO_COOKIE` 托管)。卡片显示套餐/补偿积分窗口与周期截止重置(北京时间)及余额行。控制台 Cookie 过期后,按卡片提示重新复制。此控制台查询不接受 Token Plan 推理专用 Key(`tp-*` / `ttp-*`)。本地套餐统计按自然月汇总;补偿积分和余额只展示查询结果,不用无法区分归属的本地调用估算。
|
|
95
97
|
|
|
@@ -323,22 +325,22 @@ Node.js 20 请改用 `npm install -g pnpm@10`。版本要求见 [pnpm 官方安
|
|
|
323
325
|
dsh plugin --profile web add dsh-cost-meter
|
|
324
326
|
```
|
|
325
327
|
|
|
326
|
-
**PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.8.
|
|
328
|
+
**PowerShell 一键脚本**(复制整行粘贴回车;自动补齐 pnpm、自动探测 git,无需克隆仓库;安装链**固定到发布 tag `v1.8.26`**,建议先下载审阅再运行):
|
|
327
329
|
|
|
328
330
|
```powershell
|
|
329
|
-
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.
|
|
331
|
+
irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.8.26/install.ps1 | iex
|
|
330
332
|
```
|
|
331
333
|
|
|
332
334
|
**或直接命令行**(机器上需已有 pnpm 与 git;同样固定到 tag):
|
|
333
335
|
|
|
334
336
|
```sh
|
|
335
|
-
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.
|
|
337
|
+
dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.8.26
|
|
336
338
|
```
|
|
337
339
|
|
|
338
340
|
没有 git 时可用 GitHub tag 打包直链:
|
|
339
341
|
|
|
340
342
|
```sh
|
|
341
|
-
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.
|
|
343
|
+
dsh plugin --profile web add https://github.com/Han-1413141/dsh-cost-meter/archive/refs/tags/v1.8.26.tar.gz
|
|
342
344
|
```
|
|
343
345
|
|
|
344
346
|
安装后**重启** `dsh web`(插件行、Typert 清单与客户端 bundle 均在启动时扫描):
|
|
@@ -513,6 +515,15 @@ dsh --profile web --port 3099 # 真机启动(观察启
|
|
|
513
515
|
- Plan/API 双轨分类基于渠道与配置推断,混合订阅/按量使用同一厂商 Key 的场景(如 Kimi 订阅 + PAYG 混用)可在设置中按 provider:model 手动覆盖。
|
|
514
516
|
- 安装/更新插件后需重启 `dsh web` 生效。
|
|
515
517
|
|
|
518
|
+
## 交流与反馈
|
|
519
|
+
|
|
520
|
+
使用交流、问题反馈和功能建议,欢迎加入微信交流群。
|
|
521
|
+
|
|
522
|
+
<p align="center">
|
|
523
|
+
<a href="docs/community-wechat.jpg"><img src="docs/community-wechat.jpg" alt="dsh-cost-meter 微信交流群二维码" width="320" /></a><br />
|
|
524
|
+
<a href="docs/community-wechat.jpg">查看二维码大图</a>
|
|
525
|
+
</p>
|
|
526
|
+
|
|
516
527
|
## 更新历史
|
|
517
528
|
|
|
518
529
|
各版本更新总览与社区 issue 处理记录见 [docs/UPDATE-HISTORY.md](docs/UPDATE-HISTORY.md);逐条开发记录见 [CHANGELOG.md](CHANGELOG.md)。
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Factory(Droid)订阅额度
|
|
2
|
+
|
|
3
|
+
在「设置 → 费用 → 额度」启用 **Factory (Droid)**。展开卡片后可设置额度类型、组织 ID、显示位置和刷新间隔。
|
|
4
|
+
|
|
5
|
+
- **Standard**:默认显示 5 小时、每周、每月三个已用百分比及重置时间。
|
|
6
|
+
- **Droid Core**:显示独立 Core 额度,同样包含三个窗口。
|
|
7
|
+
- **Standard + Core**:分别显示两套额度。输入框上方横条分为两个标签,各含三个窗口;点击任一标签刷新该账号额度。
|
|
8
|
+
|
|
9
|
+
## 凭据与组织
|
|
10
|
+
|
|
11
|
+
点击卡片中的「编辑凭据」,填写有权读取该账号额度的 Factory Bearer 凭据,保存到 DSH 凭据库的 `FACTORY_API_KEY`。也可由 DSH 进程读取同名环境变量。无须另加自定义 ref;凭据库命名与 `dsh-factory-provider` 的默认 `keyEnv` 一致。
|
|
12
|
+
|
|
13
|
+
`dsh-factory-provider` 自己账号库中选中的 key 不会自动复制到 DSH 凭据库。使用其账号时,需在本卡片存入对应凭据;组织 ID 可从该账号信息填写,未填写时不发送组织请求头。凭据失效或无权读取额度时显示认证提示,推理凭据是否可查额度由 Factory 接口决定。
|
|
14
|
+
|
|
15
|
+
凭据只写入 DSH 凭据库,既不回显也不保存到费用账本。关闭来源或将显示位置改为「关闭」即停止查询;组织、额度类型或凭据变化会清空旧缓存并取消旧请求。
|
|
16
|
+
|
|
17
|
+
## 查询与显示
|
|
18
|
+
|
|
19
|
+
只读 `GET https://api.factory.ai/api/billing/limits`,使用 `Authorization: Bearer …`、`x-client-version: 0.231.0`、`x-factory-client: cli` 和可选 `x-factory-org-id`。固定官方域名,拒绝重定向;15 秒单次请求超时,沿用网络重试和有界 JSON 读取。自动查询按卡片设置的 1–1440 分钟间隔缓存,默认 15 分钟;手动刷新立即查询。
|
|
20
|
+
|
|
21
|
+
`usedPercent` 已是 0–100 百分比,不乘以 100。优先使用 `windowEnd`,缺少有效绝对时间时使用 `secondsRemaining`;无重置字段时仍显示用量。缺失/无效窗口省略,不补造 0%;选择 Standard 时不偷偷回退到 Core。
|
|
22
|
+
|
|
23
|
+
账户百分比与 DSH 的调用记录分别统计。Factory 的 `factory-a`、`factory-g`、`factory-o` 归为同一套餐提供商;启用后可按既有 Plan/API 设置分类。由于本地记录无法逐次归属到 Standard/Core 池及其滚动周期,Factory 不生成每 1%/满窗 Token 与费用估算。
|
|
24
|
+
|
|
25
|
+
来源:[Factory 个人计划](https://docs.factory.ai/pricing/individuals)、[核验的提供商查询源码](https://github.com/Dalizi2026/dsh-factory-provider/blob/801c3a2be1927e804ad9e0e493c52e9aa13421df/lib/quota.js)。回归使用响应夹具与模拟网络,验证 DSH 服务、双端 codec、缓存、取消、落盘与真实 Chromium 界面;未使用真实付费账号验证。
|
|
26
|
+
|
|
27
|
+
## English
|
|
28
|
+
|
|
29
|
+
Enable **Factory (Droid)** under Settings → Cost → Quotas. Choose Standard (default), Droid Core, or both. Each pool has independent 5-hour, weekly and monthly windows. The sidebar shows all selected windows; the composer quota strip uses separate Standard/Core chips with three windows each. Either chip refreshes the Factory source.
|
|
30
|
+
|
|
31
|
+
Save a Factory Bearer credential with access to billing limits through the card's credential editor. It uses DSH's `FACTORY_API_KEY` credential ref or the same host environment variable. Keys selected in the provider plugin's private account store are not copied automatically. An optional organization ID scopes the request. Credentials are never echoed or stored in the ledger.
|
|
32
|
+
|
|
33
|
+
The adapter sends only a fixed read-only GET to the official billing-limits endpoint, rejects redirects, bounds response size and request time, and reuses the configured refresh cache. Disabling the source stops queries; credential, organization or pool changes cancel old work. Percentages are already on a 0–100 scale; reset time prefers `windowEnd`, then `secondsRemaining`. Missing windows remain absent. Account quota data does not become recorded DSH usage or a per-1% cost estimate without pool attribution. Tests use synthetic account data and network mocks plus real Chromium; no live paid account was queried.
|
package/lib/backfill.js
CHANGED
|
@@ -14,7 +14,7 @@ import { open } from 'node:fs/promises'
|
|
|
14
14
|
import * as zlib from 'node:zlib'
|
|
15
15
|
import { costOf, providerPriceEntryFor, usdFromCost, isWrapperProviderId, wrapperUpstreamProvider } from './pricing.js'
|
|
16
16
|
import { localDayKey, zeroDay, splitLedgerApiCost } from './store.js'
|
|
17
|
-
import { billingClassOf, enabledPlanSetOf } from './plan-billing.js'
|
|
17
|
+
import { billingClassOf, enabledPlanSetOf, planProviderIdOf, isRoutedThirdPartyCall, appendHourBucket, planUsageFingerprint, HOUR_BUCKET_RETENTION_MS, localMidnightMs } from './plan-billing.js'
|
|
18
18
|
import { USAGE_DEDUP_WINDOW_MS, usageFingerprint } from './usage-dedup.js'
|
|
19
19
|
import { isNativeSearchUsageEvent } from './native-search-events.js'
|
|
20
20
|
import { listSessionLogFiles } from './session-log-files.js'
|
|
@@ -279,6 +279,51 @@ async function* sessionBillingRecords(ledger, sessionsRoot, onlySessionIds = nul
|
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
+
/** Recover only recent, fully covered days. Neither calls nor recorded costs change. */
|
|
283
|
+
export async function repairPlanHourBuckets(ledger, sessionsRoot, { nowMs = Date.now(), isActive = () => true } = {}) {
|
|
284
|
+
const config = structuredClone(ledger.config), fingerprint = planUsageFingerprint(config)
|
|
285
|
+
const historyReset = structuredClone(ledger.historyReset ?? null)
|
|
286
|
+
const from = nowMs - HOUR_BUCKET_RETENTION_MS
|
|
287
|
+
const sessionIds = new Set(), dates = new Set()
|
|
288
|
+
for (const [date, day] of Object.entries(ledger.days ?? {})) {
|
|
289
|
+
if (date < localDayKey(from) || date > localDayKey(nowMs)) continue
|
|
290
|
+
dates.add(date)
|
|
291
|
+
for (const session of day.sessions ?? []) if (typeof session.id === 'string') sessionIds.add(session.id)
|
|
292
|
+
}
|
|
293
|
+
if (!sessionIds.size || !isActive() || ledger.closed) return { days: 0 }
|
|
294
|
+
const byDay = new Map(), enabled = enabledPlanSetOf(config)
|
|
295
|
+
for await (const records of sessionBillingRecords(ledger, sessionsRoot, sessionIds)) {
|
|
296
|
+
if (!isActive() || ledger.closed || planUsageFingerprint(ledger.config) !== fingerprint) return { days: 0 }
|
|
297
|
+
if (!records) continue
|
|
298
|
+
const replay = replaySessionRecords(records, config, dates, true)
|
|
299
|
+
for (const [date, models] of Object.entries(replay.days)) {
|
|
300
|
+
if (!dates.has(date)) continue
|
|
301
|
+
const entry = byDay.get(date) ?? { expected: zeroDay(date), buckets: {} }
|
|
302
|
+
mergeBucketsInto(entry.expected.byProviderModel, models)
|
|
303
|
+
for (const values of Object.values(models))
|
|
304
|
+
for (const key of ['input', 'output', 'cacheRead', 'cacheWrite', 'reasoning', 'calls', 'cost']) entry.expected[key] += Number(values[key]) || 0
|
|
305
|
+
byDay.set(date, entry)
|
|
306
|
+
}
|
|
307
|
+
for (const call of replay.samples ?? []) {
|
|
308
|
+
if (call.seed || call.atMs < from || call.atMs > nowMs || !dates.has(call.date)
|
|
309
|
+
|| billingClassOf(call.provider, call.model, config.planBilling, enabled, config.prices) !== 'plan') continue
|
|
310
|
+
const id = planProviderIdOf(call.provider, config.planBilling, call.model)
|
|
311
|
+
?? (isRoutedThirdPartyCall(call.provider, call.model, config.prices) ? 'go' : null)
|
|
312
|
+
const entry = byDay.get(call.date)
|
|
313
|
+
if (id && entry) entry.buckets = appendHourBucket(entry.buckets, id, call.atMs,
|
|
314
|
+
['input', 'output', 'cacheRead', 'cacheWrite', 'reasoning'].reduce((sum, key) => sum + (Number(call.buckets[key]) || 0), 0), call.cost)
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
if (!isActive() || ledger.closed) return { days: 0 }
|
|
318
|
+
const repairs = [...byDay].map(([date, entry]) => {
|
|
319
|
+
const start = localMidnightMs(Date.parse(date + 'T12:00:00'))
|
|
320
|
+
const end = new Date(new Date(start).getFullYear(), new Date(start).getMonth(), new Date(start).getDate() + 1).getTime()
|
|
321
|
+
return { date, start, end, ...entry, fingerprint, historyReset }
|
|
322
|
+
})
|
|
323
|
+
ledger.repairPlanHours(repairs)
|
|
324
|
+
return { days: repairs.length }
|
|
325
|
+
}
|
|
326
|
+
|
|
282
327
|
/**
|
|
283
328
|
* 回放单个会话的事件流,重建逐次用量。与 costUsage 投影同规则:
|
|
284
329
|
* request/header 切换当前 provider/model;usage 块按 (turn, step) 去重,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.community.js",factory:d=>{const y=d("react"),{createElement:e,useState:p,useEffect:f}=y,a="dsh-cost-meter:community-notice-seen",r=new Set;let i=!1;function b(){if(i)return!0;try{return window.localStorage.getItem(a)==="1"}catch{return!1}}function w({locale:s,footer:t=!1}){const[m,c]=p(b),n=s==="en",h="https://github.com/Han-1413141/dsh-cost-meter/blob/master/"+(n?"README.md#community":"README.zh-CN.md#交流与反馈"),g=()=>{i=!0;try{window.localStorage.setItem(a,"1")}catch{}c(!0);for(const o of r)o(!0)};f(()=>{r.add(c);const o=u=>{if(u.key===a&&u.newValue==="1"){i=!0;for(const v of r)v(!0)}};return window.addEventListener("storage",o),()=>{r.delete(c),window.removeEventListener("storage",o)}},[]);const l={href:h,target:"_blank",rel:"noopener noreferrer"};return t?m?e("footer",{className:"cm-community-entry"},e("a",l,n?"Community & feedback ↗":"交流与反馈 ↗")):null:m?null:e("aside",{className:"cm-community-notice",role:"status"},e("span",null,n?"The plugin WeChat group is open":"插件交流群已开放"),e("a",l,n?"View QR code ↗":"查看二维码 ↗"),e("button",{type:"button",className:"cm-btn small","aria-label":n?"Dismiss community notice":"关闭交流群提示",onClick:g},"×"))}function x(s){const t=document.createElement("style");return t.textContent=".cm-community-notice{display:flex;align-items:center;gap:12px;flex-wrap:wrap;padding:10px 12px;border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-1);font-size:12px;color:var(--dsw-alias-label-secondary)}.cm-community-notice button{margin-left:auto;flex:none;min-width:28px;min-height:28px}.cm-community-notice a,.cm-community-entry a{color:var(--dsw-alias-state-business-primary,var(--dsw-alias-brand-primary,#4d6bfe));text-decoration:none}.cm-community-notice a:hover,.cm-community-entry a:hover{text-decoration:underline}.cm-community-entry{display:flex;border-top:1px solid var(--dsw-alias-border-l1);padding-top:12px;font-size:12px}.cm-community-notice :focus-visible,.cm-community-entry a:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4d6bfe);outline-offset:3px;border-radius:4px}",document.head.appendChild(t),s.effect(()=>()=>t.remove(),"cost-meter: community styles"),w}return{mount:x}}});
|