dsh-cost-meter 1.9.67 → 1.9.68

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 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.67-4176E6?style=flat-square" alt="version"></a>
6
+ <a href="https://github.com/Han-1413141/dsh-cost-meter/releases/latest"><img src="https://img.shields.io/badge/version-1.9.68-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.67/install.ps1 | iex
45
+ irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.9.68/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.67
51
+ dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.9.68
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.67**: [release notes](docs/update-notes-1.9.67.md#english) · [troubleshooting](docs/install-troubleshooting.md)
58
+ Current release **v1.9.68**: [release notes](docs/update-notes-1.9.68.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.67-4176E6?style=flat-square" alt="version"></a>
6
+ <a href="https://github.com/Han-1413141/dsh-cost-meter/releases/latest"><img src="https://img.shields.io/badge/version-1.9.68-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.67/install.ps1 | iex
45
+ irm https://raw.githubusercontent.com/Han-1413141/dsh-cost-meter/v1.9.68/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.67
51
+ dsh plugin --profile web add github:Han-1413141/dsh-cost-meter#v1.9.68
52
52
  ```
53
53
 
54
54
  更新、卸载及无 Git 的安装方法见[安装说明](docs/install.md)。
55
55
 
56
56
  </details>
57
57
 
58
- 当前版本 **v1.9.67**:[更新说明](docs/update-notes-1.9.67.md#中文) · [安装排障](docs/install-troubleshooting.md)
58
+ 当前版本 **v1.9.68**:[更新说明](docs/update-notes-1.9.68.md#中文) · [安装排障](docs/install-troubleshooting.md)
59
59
 
60
60
  ## 功能总览
61
61
 
@@ -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-安装与更新)。
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
- * - 仅当回放桶与账本行键集合一致且逐键五桶+calls 相等才替换金额;不一致
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', 'calls']
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
- // 前置校验(全部通过才动账):键集合一致、逐键 token/calls 相等、日期聚合
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 || dayBucket === undefined) { replaceable = false; break }
1170
- for (const field of tokenFields) {
1171
- if ((Number(oldBucket[field]) || 0) !== (Number(newBucket[field]) || 0)) { replaceable = false; break }
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]) result.skippedSessions++
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
@@ -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 }