dsh-cost-meter 1.9.38 → 1.9.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +588 -588
- package/README.zh-CN.md +592 -592
- package/docs/update-notes-1.9.31.md +1 -1
- package/docs/update-notes-1.9.39.md +33 -0
- package/lib/billing-export.js +49 -13
- package/lib/billion-context-billing.js +82 -58
- package/lib/billion-context-history.js +5 -2
- package/lib/billion-context-inventory.js +8 -5
- package/lib/external-usage.js +119 -119
- package/lib/gateway-quotas.js +33 -14
- package/lib/index.js +10 -7
- package/lib/journal-storage.js +7 -1
- package/lib/ledger-totals.js +57 -57
- package/lib/ledger-writer-worker.js +1 -1
- package/lib/pricing.js +6 -5
- package/lib/workbuddy-accounts.js +4 -1
- package/package.json +4 -3
package/lib/pricing.js
CHANGED
|
@@ -1303,11 +1303,12 @@ export function tierFor(entry, atMs, peak) {
|
|
|
1303
1303
|
*/
|
|
1304
1304
|
export function costOf(tokens, entry, atMs, peak) {
|
|
1305
1305
|
let tier = tierFor(entry, atMs, peak)
|
|
1306
|
-
const
|
|
1307
|
-
const
|
|
1308
|
-
const
|
|
1309
|
-
const
|
|
1310
|
-
const
|
|
1306
|
+
const amount = value => { const n = Number(value); return Number.isFinite(n) && n > 0 ? n : 0 }
|
|
1307
|
+
const input = amount(tokens?.input)
|
|
1308
|
+
const output = amount(tokens?.output)
|
|
1309
|
+
const cacheRead = amount(tokens?.cacheRead)
|
|
1310
|
+
const cacheWrite = amount(tokens?.cacheWrite)
|
|
1311
|
+
const reasoning = amount(tokens?.reasoning)
|
|
1311
1312
|
// 宿主的 input/cacheRead/cacheWrite 是互斥桶;输入长度包含缓存,输出不参与阈值。
|
|
1312
1313
|
// 此处必须传单次调用,日/会话聚合无法还原每次请求的上下文档位。
|
|
1313
1314
|
if (tier.longContext && input + cacheRead + cacheWrite > tier.longContext.aboveInputTokens) tier = tier.longContext
|
|
@@ -13,7 +13,8 @@ async function readAccounts(origin, source, { signal, fetchImpl }) {
|
|
|
13
13
|
{ method: 'GET', redirect: 'error', signal }, { attempts: 1, timeoutMs: 35000, fetchImpl })
|
|
14
14
|
if (response.status === 404 || response.headers.get('content-type')?.includes('text/html')) { await response.body?.cancel?.(); return { missing: true } }
|
|
15
15
|
if (!response.ok) { await response.body?.cancel?.(); return { failed: true } }
|
|
16
|
-
const body = await readJsonBounded(response)
|
|
16
|
+
const body = await readJsonBounded(response, 262144, { signal })
|
|
17
|
+
signal?.throwIfAborted()
|
|
17
18
|
if (source === 'xdpool' && (!['cn', 'global'].includes(body?.region) || typeof body.ok !== 'boolean')) return { missing: true }
|
|
18
19
|
if (!Array.isArray(body?.accounts) || body.accounts.length > 200) return { failed: true }
|
|
19
20
|
if (source === 'xdpool' && body.region !== region) return { failed: true }
|
|
@@ -34,12 +35,14 @@ async function readAccounts(origin, source, { signal, fetchImpl }) {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
export async function fetchWorkBuddyAccounts(hostOrigin, config = {}, { signal, fetchImpl = fetchWorkBuddyLocal } = {}) {
|
|
38
|
+
signal?.throwIfAborted()
|
|
37
39
|
const source = config.accountSource ?? 'auto'
|
|
38
40
|
const unavailable = () => Object.assign(new Error('workbuddyConnectUnavailable'), { code: 'workbuddyConnectUnavailable' })
|
|
39
41
|
if (!hostOrigin) { if (source === 'xdpool') throw unavailable(); return null }
|
|
40
42
|
const origin = workBuddyOrigin(hostOrigin), options = { signal, fetchImpl }
|
|
41
43
|
let usingPool = source === 'xdpool'
|
|
42
44
|
let results = await readAccounts(origin, usingPool ? 'xdpool' : 'connect', options)
|
|
45
|
+
signal?.throwIfAborted()
|
|
43
46
|
if (source === 'auto' && !results.some(row => row.accounts?.length)) {
|
|
44
47
|
const pool = await readAccounts(origin, 'xdpool', options)
|
|
45
48
|
if (pool.some(row => row.accounts?.length) || !results.some(row => row.accounts) && pool.some(row => !row.missing)) { results = pool; usingPool = true }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cost-meter",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.39",
|
|
4
4
|
"description": "DeepSeek Harness 会话费用统计插件:本会话成本、当日费用、历史记录与官方价格同步,支持多厂商多模型价格计费(内置 170+ 模型 ID 价格目录与自动匹配)、主流 Coding Plan 订阅额度查询与显示(14 家,含 WorkBuddy 官方积分、OpenDesign 工作区查询、含小米 MiMo Token Plan 控制台 Cookie 查询、SCNet Token Plan 本地 Credits 计量与火山方舟 Volcano Ark Coding Plan AK/SK 签名查询)、自定义 Provider 余额查询(可配任意 HTTP 端点)与余额进度条、峰谷计价时段显示与切换前弹窗/系统通知提醒(位置/提前量/类型可配),界面中英双语。Session cost tracking plugin for DeepSeek Harness: per-conversation cost, daily totals, history and official price sync, with multi-vendor model pricing (built-in 170+ model-ID catalog with auto-matching), Coding Plan quota queries & display for 14 vendors (incl. WorkBuddy official credits, OpenDesign workspace queries, Xiaomi MiMo Token Plan via console cookie, local credits metering for the SCNet Token Plan and Volcano Ark Coding Plan via AK/SK signature), plan/API dual-track billing with per-1% & full-window Token Plan usage estimates, custom provider balance lookup (configurable HTTP endpoint) and balance progress bar, plus peak/off-peak pricing display with pre-switch popup & system-notification alerts (position / lead time / type configurable), in a bilingual (Chinese/English) UI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/bootstrap.js",
|
|
@@ -183,11 +183,12 @@
|
|
|
183
183
|
"docs/update-notes-1.9.35.md",
|
|
184
184
|
"docs/update-notes-1.9.36.md",
|
|
185
185
|
"docs/update-notes-1.9.37.md",
|
|
186
|
-
"docs/update-notes-1.9.38.md"
|
|
186
|
+
"docs/update-notes-1.9.38.md",
|
|
187
|
+
"docs/update-notes-1.9.39.md"
|
|
187
188
|
],
|
|
188
189
|
"dependencies": {
|
|
189
190
|
"acorn": "8.15.0",
|
|
190
|
-
"zod": "4.6.
|
|
191
|
+
"zod": "4.6.6"
|
|
191
192
|
},
|
|
192
193
|
"peerDependencies": {
|
|
193
194
|
"@deepseek-ai/dsh-credentials": ">=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-0 <0.3.0-0",
|