dsh-cost-meter 1.9.37 → 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 -586
- package/README.zh-CN.md +592 -590
- package/docs/update-notes-1.9.31.md +1 -1
- package/docs/update-notes-1.9.38.md +31 -0
- 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/client.js +1 -1
- package/lib/client.plan-settings.js +1 -1
- package/lib/coding-plans.js +1 -1
- package/lib/external-usage.js +119 -119
- package/lib/gateway-quotas.js +33 -14
- package/lib/index.js +22 -13
- package/lib/journal-storage.js +7 -1
- package/lib/ledger-totals.js +57 -57
- package/lib/ledger-writer-worker.js +1 -1
- package/lib/plan-billing.js +1 -1
- package/lib/pricing.js +6 -5
- package/lib/store.js +2 -0
- package/lib/typert.host.js +1 -0
- package/lib/workbuddy-accounts.js +32 -12
- package/package.json +5 -3
package/lib/plan-billing.js
CHANGED
|
@@ -43,7 +43,7 @@ export const PLAN_PROVIDER_ALIASES = {
|
|
|
43
43
|
kimi: ['kimi', 'kimi-code'],
|
|
44
44
|
commandcode: ['commandcode', 'command-code'],
|
|
45
45
|
clinepass: ['clinepass', 'cline-pass'],
|
|
46
|
-
workbuddy: ['workbuddy', 'workbuddy-subscription', 'workbuddy-ai', 'workbuddy-global'],
|
|
46
|
+
workbuddy: ['workbuddy', 'workbuddy-subscription', 'workbuddy-ai', 'workbuddy-global', 'xdpool', 'xdpool-global'],
|
|
47
47
|
antigravity: ['antigravity'],
|
|
48
48
|
stepfun: ['stepfun', 'step-code'],
|
|
49
49
|
'volcengine-agent': ['volcengine-agent', 'ark-agent-plan', 'volcengine-agent-plan'],
|
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
|
package/lib/store.js
CHANGED
|
@@ -1195,6 +1195,7 @@ export function applyConfigPatch(current, rawPatch) {
|
|
|
1195
1195
|
entry.refreshMinutes = Number.isFinite(minutes) && minutes >= 1 && minutes <= 1440 ? minutes : 15
|
|
1196
1196
|
entry.apiKey = typeof entry.apiKey === 'string' ? entry.apiKey : ''
|
|
1197
1197
|
if (id === 'workbuddy') {
|
|
1198
|
+
if (entry.accountSource !== undefined && !['auto', 'connect', 'xdpool'].includes(entry.accountSource)) errors.push('Invalid WorkBuddy account source')
|
|
1198
1199
|
if (entry.accountScope !== undefined && !['current', 'all', 'selected'].includes(entry.accountScope)) errors.push('Invalid WorkBuddy account scope')
|
|
1199
1200
|
if (entry.accountIds !== undefined && (!Array.isArray(entry.accountIds) || entry.accountIds.length > 400 || entry.accountIds.some(id => !validWorkBuddyAccountId(id)))) errors.push('Invalid WorkBuddy account selection')
|
|
1200
1201
|
}
|
|
@@ -1889,6 +1890,7 @@ export function sanitizeConfig(raw) {
|
|
|
1889
1890
|
if (origin === null) plans[id].enabled = false // 无效磁盘配置不能悄悄向默认站点发送 Key。
|
|
1890
1891
|
}
|
|
1891
1892
|
if (id === 'workbuddy') {
|
|
1893
|
+
if (entry.accountSource !== undefined) plans[id].accountSource = oneOf(entry.accountSource, ['auto', 'connect', 'xdpool'], 'auto')
|
|
1892
1894
|
plans[id].accountScope = oneOf(entry.accountScope, ['current', 'all', 'selected'], 'current')
|
|
1893
1895
|
plans[id].accountIds = Array.isArray(entry.accountIds) ? [...new Set(entry.accountIds.filter(validWorkBuddyAccountId))].slice(0, 400) : []
|
|
1894
1896
|
}
|
package/lib/typert.host.js
CHANGED
|
@@ -311,6 +311,7 @@ const configSchema = z.object({
|
|
|
311
311
|
workspaceId: z.string().optional(),
|
|
312
312
|
factoryPool: z.enum(['standard', 'core', 'both']).optional(),
|
|
313
313
|
accountScope: z.enum(['current', 'all', 'selected']).optional(),
|
|
314
|
+
accountSource: z.enum(['auto', 'connect', 'xdpool']).optional(),
|
|
314
315
|
accountIds: z.array(z.string().max(263)).max(400).optional(),
|
|
315
316
|
// SCNet 本地计量专用(issue #26):月度 Credits 额度与订阅起始日;其余厂商无此二键。
|
|
316
317
|
planCredits: num.optional(),
|
|
@@ -4,31 +4,51 @@ import { fetchWithRetry, readJsonBounded } from './net.js'
|
|
|
4
4
|
export const validWorkBuddyAccountId = id => typeof id === 'string' && /^(cn|global):[^\s\u0000-\u001f\u007f]{1,256}$/.test(id)
|
|
5
5
|
const amount = value => typeof value === 'number' && Number.isFinite(value) && value >= 0
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const origin = workBuddyOrigin(hostOrigin)
|
|
11
|
-
const results = await Promise.all(['cn', 'global'].map(async region => {
|
|
7
|
+
/** Published local GET endpoints only; selection and credentials stay with the peer. */
|
|
8
|
+
async function readAccounts(origin, source, { signal, fetchImpl }) {
|
|
9
|
+
return Promise.all(['cn', 'global'].map(async region => {
|
|
12
10
|
try {
|
|
13
|
-
const
|
|
11
|
+
const path = source === 'xdpool' ? '/plugins/dsh-xdpool/status' : '/plugins/dsh-connect-workbuddy/account-credits'
|
|
12
|
+
const response = await fetchWithRetry(new URL(path + '?region=' + region, origin),
|
|
14
13
|
{ method: 'GET', redirect: 'error', signal }, { attempts: 1, timeoutMs: 35000, fetchImpl })
|
|
15
14
|
if (response.status === 404 || response.headers.get('content-type')?.includes('text/html')) { await response.body?.cancel?.(); return { missing: true } }
|
|
16
15
|
if (!response.ok) { await response.body?.cancel?.(); return { failed: true } }
|
|
17
|
-
const body = await readJsonBounded(response)
|
|
16
|
+
const body = await readJsonBounded(response, 262144, { signal })
|
|
17
|
+
signal?.throwIfAborted()
|
|
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 }
|
|
20
|
+
if (source === 'xdpool' && body.region !== region) return { failed: true }
|
|
19
21
|
const seen = new Set(), accounts = []
|
|
20
22
|
for (const row of body.accounts) {
|
|
21
|
-
const id = region + ':' + row?.id
|
|
23
|
+
const id = region + ':' + (source === 'xdpool' ? 'xdpool:' : '') + row?.id
|
|
22
24
|
if (!validWorkBuddyAccountId(id) || typeof row?.id !== 'string' || seen.has(id)) return { failed: true }
|
|
23
25
|
seen.add(id)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
const name = source === 'xdpool' ? row.label : row.accountName
|
|
27
|
+
const credits = source === 'xdpool' ? row.creditsError || row.credentialDead === true ? null : row.credits?.total : row.credits
|
|
28
|
+
accounts.push({ id, region, name: typeof name === 'string' ? (source === 'xdpool' ? 'XD Pool · ' + name : name).slice(0, 160) : '',
|
|
29
|
+
current: source === 'xdpool' ? row.id === body.activeAccountId : row.selected === true,
|
|
30
|
+
remaining: amount(credits) ? credits : null })
|
|
26
31
|
}
|
|
27
32
|
return { accounts }
|
|
28
33
|
} catch { signal?.throwIfAborted(); return { failed: true } }
|
|
29
34
|
}))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function fetchWorkBuddyAccounts(hostOrigin, config = {}, { signal, fetchImpl = fetchWorkBuddyLocal } = {}) {
|
|
38
|
+
signal?.throwIfAborted()
|
|
39
|
+
const source = config.accountSource ?? 'auto'
|
|
40
|
+
const unavailable = () => Object.assign(new Error('workbuddyConnectUnavailable'), { code: 'workbuddyConnectUnavailable' })
|
|
41
|
+
if (!hostOrigin) { if (source === 'xdpool') throw unavailable(); return null }
|
|
42
|
+
const origin = workBuddyOrigin(hostOrigin), options = { signal, fetchImpl }
|
|
43
|
+
let usingPool = source === 'xdpool'
|
|
44
|
+
let results = await readAccounts(origin, usingPool ? 'xdpool' : 'connect', options)
|
|
45
|
+
signal?.throwIfAborted()
|
|
46
|
+
if (source === 'auto' && !results.some(row => row.accounts?.length)) {
|
|
47
|
+
const pool = await readAccounts(origin, 'xdpool', options)
|
|
48
|
+
if (pool.some(row => row.accounts?.length) || !results.some(row => row.accounts) && pool.some(row => !row.missing)) { results = pool; usingPool = true }
|
|
49
|
+
}
|
|
30
50
|
// An older connector has no account list; its selected-account route remains usable.
|
|
31
|
-
if (!results.some(result => result.accounts)) return null
|
|
51
|
+
if (!results.some(result => result.accounts)) { if (usingPool) throw unavailable(); return null }
|
|
32
52
|
const accounts = results.flatMap(result => result.accounts ?? [])
|
|
33
53
|
const scope = ['all', 'selected'].includes(config.accountScope) ? config.accountScope : 'current'
|
|
34
54
|
const ids = new Set(Array.isArray(config.accountIds) ? config.accountIds : [])
|
|
@@ -40,5 +60,5 @@ export async function fetchWorkBuddyAccounts(hostOrigin, config = {}, { signal,
|
|
|
40
60
|
return { scope, accounts, selectedIds: selected.map(row => row.id),
|
|
41
61
|
knownRemaining: known.reduce((sum, row) => sum + row.remaining, 0),
|
|
42
62
|
unknownCount: selected.length - known.length,
|
|
43
|
-
incomplete: results.some(result => result.failed), fetchedAt: Date.now() }
|
|
63
|
+
incomplete: results.some(result => result.failed || usingPool && result.missing), fetchedAt: Date.now() }
|
|
44
64
|
}
|
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",
|
|
@@ -182,11 +182,13 @@
|
|
|
182
182
|
"docs/update-notes-1.9.34.md",
|
|
183
183
|
"docs/update-notes-1.9.35.md",
|
|
184
184
|
"docs/update-notes-1.9.36.md",
|
|
185
|
-
"docs/update-notes-1.9.37.md"
|
|
185
|
+
"docs/update-notes-1.9.37.md",
|
|
186
|
+
"docs/update-notes-1.9.38.md",
|
|
187
|
+
"docs/update-notes-1.9.39.md"
|
|
186
188
|
],
|
|
187
189
|
"dependencies": {
|
|
188
190
|
"acorn": "8.15.0",
|
|
189
|
-
"zod": "4.6.
|
|
191
|
+
"zod": "4.6.6"
|
|
190
192
|
},
|
|
191
193
|
"peerDependencies": {
|
|
192
194
|
"@deepseek-ai/dsh-credentials": ">=0.2.0-rc.1 <0.3.0-0 || >=0.2.1-0 <0.3.0-0",
|