dsh-cost-meter 1.9.76 → 1.9.78
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/custom-balance-sources.md +8 -0
- package/docs/host-price-calculators.md +33 -0
- package/docs/release-notes/v1.9.78.md +19 -0
- package/lib/agy-link-pool.js +86 -0
- package/lib/agy-link-quota.js +20 -95
- package/lib/backfill.js +77 -12
- package/lib/billing-history.js +1 -1
- package/lib/client.agy-quota.js +1 -0
- package/lib/client.display.js +2 -2
- package/lib/client.js +10 -10
- package/lib/client.plan-settings.js +1 -1
- package/lib/client.pricing.js +2 -2
- package/lib/coding-plans.js +5 -9
- package/lib/currency-view.js +2 -1
- package/lib/custom-balance.js +4 -0
- package/lib/dynamic-pricing.js +75 -0
- package/lib/index.js +8 -3
- package/lib/ledger-persistence.js +2 -0
- package/lib/ledger-writer-worker.js +1 -1
- package/lib/session-billing-events.js +16 -0
- package/lib/session-storage-compat.js +10 -0
- package/lib/session-usage-cache.js +2 -2
- package/lib/store.js +15 -6
- package/lib/turn-cost.js +13 -9
- package/lib/typert.host.js +7 -3
- package/package.json +4 -2
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Only billing metadata is retained from host events.
|
|
2
|
+
export function forkSeedLength(header) {
|
|
3
|
+
const length = header?.seedLength
|
|
4
|
+
return Number.isSafeInteger(length) && length > 0 ? length : 0
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function attemptUsage(data) {
|
|
8
|
+
if (data?.usage) return data.usage
|
|
9
|
+
if (Array.isArray(data?.stream)) {
|
|
10
|
+
for (let i = data.stream.length - 1; i >= 0; i--) {
|
|
11
|
+
const chunk = data.stream[i]?.chunk
|
|
12
|
+
if (chunk?.type === 'usage' && chunk.usage) return chunk.usage
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return null
|
|
16
|
+
}
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* - 事件上限和取消异常向上传递,取消后不再降级到其他后端。
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
+
import { attemptUsage, forkSeedLength } from './session-billing-events.js'
|
|
26
27
|
import { basename, dirname, join } from 'node:path'
|
|
27
28
|
import { resolveDshHome } from '@deepseek-ai/dsh-home-paths'
|
|
28
29
|
import { detectSubscriptionPackage } from './codex-subscription-compat.js'
|
|
@@ -109,6 +110,7 @@ function finiteOr0(value) {
|
|
|
109
110
|
/** 构造 replaySessionRecords 需要的会话标记(首元素)。 */
|
|
110
111
|
function sessionMarker(sessionId, header) {
|
|
111
112
|
const marker = { type: 'session', id: sessionId, createdAt: Math.max(0, finiteOr0(header?.createdAt)) }
|
|
113
|
+
if (forkSeedLength(header)) marker.seedLength = forkSeedLength(header)
|
|
112
114
|
const parent = header?.parentSession
|
|
113
115
|
if (typeof parent === 'string' && parent.length > 0) marker.parentSession = parent
|
|
114
116
|
return marker
|
|
@@ -130,6 +132,12 @@ function isLimitError(error) {
|
|
|
130
132
|
export function billingSessionRecord(row) {
|
|
131
133
|
if (!row || typeof row !== 'object') return null
|
|
132
134
|
if (row.type === 'session') return row
|
|
135
|
+
if (row.type === 'session/title-llm-request') {
|
|
136
|
+
const { provider, model } = row.data?.route ?? {}
|
|
137
|
+
return { type: row.type, seq: row.seq, time: row.time, data: { route: { provider, model } } }
|
|
138
|
+
}
|
|
139
|
+
if (row.type === 'assistant/attempt') return { type: row.type, seq: row.seq, time: row.time,
|
|
140
|
+
data: { turn: row.data?.turn, step: row.data?.step, usage: attemptUsage(row.data) } }
|
|
133
141
|
if (row.type === 'session/title') return { type: 'session/title', seq: row.seq, time: row.time, data: { title: row.data?.title } }
|
|
134
142
|
if (row.type === 'request/header') return { type: 'request/header', seq: row.seq, time: row.time, data: { header: { config: { model: row.data?.header?.config?.model, provider: row.data?.header?.config?.provider } } } }
|
|
135
143
|
if (row.type === 'step/start') return { type: 'step/start', seq: row.seq, time: row.time, data: { turn: row.data?.turn, step: row.data?.step } }
|
|
@@ -409,6 +417,7 @@ async function recordsFromQuery(ctx, sessionId, options) {
|
|
|
409
417
|
const records = [sessionMarker(sessionId, snapshot.session)]
|
|
410
418
|
appendEvents(records, snapshot.events, maxEvents, options.transform)
|
|
411
419
|
const inherited = finiteOr0(snapshot.inheritedEventCount)
|
|
420
|
+
if (inherited > 0) records[0].seedLength = inherited
|
|
412
421
|
return { records, source: 'sessionQuery', inheritedEventCount: Math.max(0, inherited) }
|
|
413
422
|
}
|
|
414
423
|
|
|
@@ -435,6 +444,7 @@ async function recordsFromPersistence(ctx, sessionId, options) {
|
|
|
435
444
|
let inheritedEventCount = 0
|
|
436
445
|
try {
|
|
437
446
|
inheritedEventCount = Math.max(0, finiteOr0(handle.inheritedEventCount))
|
|
447
|
+
if (inheritedEventCount > 0) records[0].seedLength = inheritedEventCount
|
|
438
448
|
for (;;) {
|
|
439
449
|
throwIfAborted(options.signal)
|
|
440
450
|
const chunk = await handle.read(offset)
|
|
@@ -13,7 +13,7 @@ export async function readUsageCache(ledgerPath, sourcePath, source, sanitize) {
|
|
|
13
13
|
const [directory, info] = await Promise.all([lstat(root), lstat(join(root, key + '.json'))])
|
|
14
14
|
if (!directory.isDirectory() || directory.isSymbolicLink() || !safe(info)) return null
|
|
15
15
|
const saved = JSON.parse(await readFile(join(root, key + '.json'), 'utf8'))
|
|
16
|
-
if (saved.version !==
|
|
16
|
+
if (saved.version !== 2 || saved.source !== source || !Array.isArray(saved.records) || !saved.records.length || saved.records.length > 200_000) return null
|
|
17
17
|
const records = saved.records.map(sanitize)
|
|
18
18
|
if (records.some(row => !row) || !records.some(row => row.type === 'session' && typeof row.id === 'string' && row.id.length > 0 && row.id.length <= 512)) return null
|
|
19
19
|
return records
|
|
@@ -28,7 +28,7 @@ export async function saveUsageCache(ledgerPath, sourcePath, source, records) {
|
|
|
28
28
|
const pending = (async () => {
|
|
29
29
|
let temp
|
|
30
30
|
try {
|
|
31
|
-
const json = JSON.stringify({ version:
|
|
31
|
+
const json = JSON.stringify({ version: 2, source, records })
|
|
32
32
|
if (Buffer.byteLength(json) > MAX_BYTES) return
|
|
33
33
|
await mkdir(root, { recursive: true, mode: 0o700 })
|
|
34
34
|
const directory = await lstat(root)
|
package/lib/store.js
CHANGED
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
wrapperUpstreamProvider,
|
|
45
45
|
isLocalOriginProviderOrModel,
|
|
46
46
|
} from './pricing.js'
|
|
47
|
+
import { bindQuoteLedger, quoteUsage } from './dynamic-pricing.js'
|
|
47
48
|
import { CODING_PLAN_PROVIDER_IDS, normalizeMiniMaxBaseUrl } from './coding-plans.js'
|
|
48
49
|
import { normalizeFactoryOrgId } from './factory-quota.js'
|
|
49
50
|
import { normalizeOpenDesignWorkspace } from './opendesign.js'
|
|
@@ -897,7 +898,7 @@ const VALIDATION_MESSAGES = {
|
|
|
897
898
|
balanceSource: 'balance.source 必须是 auto / account',
|
|
898
899
|
goQuota: 'goQuota 非法',
|
|
899
900
|
customBalance: 'customBalance 非法',
|
|
900
|
-
customBalanceAdapter: 'customBalance.adapter 必须是 custom / aliyun / tokenrhythm / openai-credits',
|
|
901
|
+
customBalanceAdapter: 'customBalance.adapter 必须是 custom / aliyun / tokenrhythm / openai-credits / fireworks',
|
|
901
902
|
customBalanceEnabled: 'customBalance.enabled 必须是布尔值',
|
|
902
903
|
customBalanceDisplay: 'customBalance.display 必须是 sidebar / settings / both / off',
|
|
903
904
|
customBalanceRefresh: 'customBalance.refreshMinutes 必须是 1-1440 的整数',
|
|
@@ -1015,7 +1016,7 @@ const VALIDATION_MESSAGES = {
|
|
|
1015
1016
|
balanceSource: 'balance.source must be auto / account',
|
|
1016
1017
|
goQuota: 'Invalid goQuota',
|
|
1017
1018
|
customBalance: 'Invalid customBalance',
|
|
1018
|
-
customBalanceAdapter: 'customBalance.adapter must be custom / aliyun / tokenrhythm / openai-credits',
|
|
1019
|
+
customBalanceAdapter: 'customBalance.adapter must be custom / aliyun / tokenrhythm / openai-credits / fireworks',
|
|
1019
1020
|
customBalanceEnabled: 'customBalance.enabled must be a boolean',
|
|
1020
1021
|
customBalanceDisplay: 'customBalance.display must be sidebar / settings / both / off',
|
|
1021
1022
|
customBalanceRefresh: 'customBalance.refreshMinutes must be an integer from 1 to 1440',
|
|
@@ -1449,7 +1450,7 @@ export function applyConfigPatch(current, rawPatch) {
|
|
|
1449
1450
|
return
|
|
1450
1451
|
}
|
|
1451
1452
|
if (typeof entry.enabled !== 'boolean') errors.push(vmsg(locale, fieldPrefix + 'Enabled'))
|
|
1452
|
-
if (entry.adapter !== undefined && !['custom', 'aliyun', 'tokenrhythm', 'openai-credits'].includes(entry.adapter)) errors.push(vmsg(locale, fieldPrefix + 'Adapter'))
|
|
1453
|
+
if (entry.adapter !== undefined && !['custom', 'aliyun', 'tokenrhythm', 'openai-credits', 'fireworks'].includes(entry.adapter)) errors.push(vmsg(locale, fieldPrefix + 'Adapter'))
|
|
1453
1454
|
if (!['sidebar', 'settings', 'both', 'off'].includes(entry.display)) errors.push(vmsg(locale, fieldPrefix + 'Display'))
|
|
1454
1455
|
const refreshMinutes = Number(entry.refreshMinutes)
|
|
1455
1456
|
if (!Number.isInteger(refreshMinutes) || refreshMinutes < 1 || refreshMinutes > 1440) errors.push(vmsg(locale, fieldPrefix + 'Refresh'))
|
|
@@ -1872,7 +1873,7 @@ export function sanitizeConfig(raw) {
|
|
|
1872
1873
|
const sanitizeCustomEntry = (raw, baseEntry) => {
|
|
1873
1874
|
const entry = raw ?? {}
|
|
1874
1875
|
const clean = {
|
|
1875
|
-
...(['aliyun', 'tokenrhythm', 'openai-credits'].includes(entry.adapter) ? { adapter: entry.adapter } : {}),
|
|
1876
|
+
...(['aliyun', 'tokenrhythm', 'openai-credits', 'fireworks'].includes(entry.adapter) ? { adapter: entry.adapter } : {}),
|
|
1876
1877
|
enabled: entry.enabled === true,
|
|
1877
1878
|
display: oneOf(entry.display, ['sidebar', 'settings', 'both', 'off'], 'both'),
|
|
1878
1879
|
refreshMinutes: Math.min(1440, Math.max(1, Math.floor(Number(entry.refreshMinutes) || 15))),
|
|
@@ -1909,6 +1910,11 @@ export function sanitizeConfig(raw) {
|
|
|
1909
1910
|
clean.extract = { ...baseEntry.extract, ...entry.extract }
|
|
1910
1911
|
}
|
|
1911
1912
|
// 凭据外带白名单(v1.6.8)随行:字符串数组,仅保留非空串。
|
|
1913
|
+
if (Array.isArray(entry.channels)) {
|
|
1914
|
+
const channels = entry.channels.filter(id => typeof id === 'string').map(id => id.trim())
|
|
1915
|
+
.filter(id => id.length > 0 && id.length <= 128 && !/[\s:,]/.test(id))
|
|
1916
|
+
if (channels.length) clean.channels = [...new Set(channels)].slice(0, 32)
|
|
1917
|
+
}
|
|
1912
1918
|
if (Array.isArray(entry.allowedHosts)) {
|
|
1913
1919
|
const hosts = entry.allowedHosts.filter(h => typeof h === 'string' && h.length > 0)
|
|
1914
1920
|
if (hosts.length > 0) clean.allowedHosts = hosts
|
|
@@ -1970,6 +1976,7 @@ export function sanitizeConfig(raw) {
|
|
|
1970
1976
|
if (!CODING_PLAN_PROVIDER_IDS.includes(id) || entry === null || typeof entry !== 'object' || Array.isArray(entry)) continue
|
|
1971
1977
|
plans[id] = {
|
|
1972
1978
|
enabled: entry.enabled === true,
|
|
1979
|
+
...(typeof entry.sidebarAfterSuccess === 'boolean' ? { sidebarAfterSuccess: entry.sidebarAfterSuccess } : {}),
|
|
1973
1980
|
...(typeof entry.showInComposer === 'boolean' ? { showInComposer: entry.showInComposer } : {}),
|
|
1974
1981
|
display: oneOf(entry.display, ['sidebar', 'settings', 'both', 'off'], 'settings'),
|
|
1975
1982
|
refreshMinutes: Math.min(1440, Math.max(1, Math.floor(Number(entry.refreshMinutes) || 15))),
|
|
@@ -2321,7 +2328,7 @@ export class Ledger {
|
|
|
2321
2328
|
get config() { return this._config }
|
|
2322
2329
|
set config(value) {
|
|
2323
2330
|
if (this.pricingHistory) advancePricingHistory(this.pricingHistory, value)
|
|
2324
|
-
this._config = bindPricingHistory(value, this.pricingHistory)
|
|
2331
|
+
this._config = bindQuoteLedger(bindPricingHistory(value, this.pricingHistory), this)
|
|
2325
2332
|
}
|
|
2326
2333
|
|
|
2327
2334
|
/** 在 $DSH_HOME 下创建/加载账本。 */
|
|
@@ -2471,7 +2478,8 @@ export class Ledger {
|
|
|
2471
2478
|
// 兜底与跨厂商兑底命中)计出的成本为人民币,按展示汇率折算为美元入账;
|
|
2472
2479
|
// 第三方 flat 恒为美元价,直接入账。
|
|
2473
2480
|
const priced = requestFee ? requestFeeCostCny(requestFee, atMs) : resolved.priced ? costOf(tokens, entry, atMs, peak) : 0
|
|
2474
|
-
const
|
|
2481
|
+
const quote = requestFee ? null : quoteUsage(this, provider, modelId, tokens ?? {}, atMs, pricing)
|
|
2482
|
+
const cost = quote ? quote.total / quote.fx[quote.currency] : usdFromCost(priced, requestFee ? 'CNY' : resolved.currency, fxRatesOf(pricing).CNY)
|
|
2475
2483
|
// Plan/API 双轨分类(issue #64):plan 类调用金额只记等值(cost),apiCost 记真金白银部分;
|
|
2476
2484
|
// Plan 类调用同时进入 provider×小时聚合桶(供 5 小时滚动窗本地量聚合)。
|
|
2477
2485
|
const planBilling = this.config.planBilling
|
|
@@ -2493,6 +2501,7 @@ export class Ledger {
|
|
|
2493
2501
|
const planId = cls === 'plan' ? (planProviderIdOf(provider, planBilling, modelId)
|
|
2494
2502
|
?? (isRoutedThirdPartyCall(provider, modelId, this.config.prices) ? 'go' : null)) : null
|
|
2495
2503
|
const call = {
|
|
2504
|
+
...(quote ? { quote } : {}),
|
|
2496
2505
|
...(meter ? { meter } : {}),
|
|
2497
2506
|
date: localDayKey(atMs), sessionId, atMs, recordedAt: Date.now(), planId,
|
|
2498
2507
|
providerKey: `${typeof provider === 'string' && provider.length > 0 ? provider : 'deepseek'}:${String(modelId ?? 'default')}`,
|
package/lib/turn-cost.js
CHANGED
|
@@ -7,6 +7,7 @@ import { resolveDshHome } from '@deepseek-ai/dsh-home-paths'
|
|
|
7
7
|
import { listSessionLogs, iterateSessionRecords, replaySessionRecords } from './backfill.js'
|
|
8
8
|
import { nativeSearchRecordsFor } from './native-search-history.js'
|
|
9
9
|
import { BILLION_REPLACEMENT_EVENT, billionRecordsFor } from './billion-context-history.js'
|
|
10
|
+
import { attemptUsage, forkSeedLength } from './session-billing-events.js'
|
|
10
11
|
import { tierFor, usdFromCost } from './pricing.js'
|
|
11
12
|
import { isNativeSearchUsageEvent } from './native-search-events.js'
|
|
12
13
|
import { requestFeeRateCny } from './web-request-pricing.js'
|
|
@@ -68,11 +69,12 @@ export function costFromSamples(samples, config) {
|
|
|
68
69
|
for (const [bucket, priceKey] of Object.entries(fields)) {
|
|
69
70
|
const tokens = sample.buckets[bucket]
|
|
70
71
|
if (!tokens) continue
|
|
71
|
-
|
|
72
|
+
let rate = sample.resolved.priced ? usdFromCost(tier[priceKey] ?? (bucket === 'cacheWrite' ? tier.cacheHit : 0), sample.resolved.currency, sample.exchangeRate ?? config.exchangeRate) * (sample.displayFactor ?? 1) : 0
|
|
73
|
+
if (sample.quote) rate = (sample.quote.breakdown[bucket] ?? 0) / sample.quote.fx[sample.quote.currency] * (sample.displayFactor ?? 1) * 1e6 / tokens
|
|
72
74
|
const plan = sample.plan
|
|
73
|
-
call.rows.push({ provider: sample.provider, model: sample.model, bucket, tokens, rate, cost: tokens * rate / 1e6, priced: sample.resolved.priced, plan })
|
|
75
|
+
call.rows.push({ provider: sample.provider, model: sample.model, bucket, tokens, rate, cost: tokens * rate / 1e6, priced: sample.resolved.priced && (!sample.quote || Object.keys(sample.quote.breakdown).length > 0), plan })
|
|
74
76
|
const key = JSON.stringify([sample.provider, sample.model, bucket, rate, plan, sample.resolved.priced])
|
|
75
|
-
const row = parts.get(key) ?? { provider: sample.provider, model: sample.model, bucket, tokens: 0, rate, cost: 0, priced:
|
|
77
|
+
const row = parts.get(key) ?? { provider: sample.provider, model: sample.model, bucket, tokens: 0, rate, cost: 0, priced: call.rows.at(-1).priced, plan }
|
|
76
78
|
row.tokens += tokens; row.cost += tokens * rate / 1e6
|
|
77
79
|
parts.set(key, row)
|
|
78
80
|
}
|
|
@@ -94,7 +96,9 @@ export async function getTurnCost(ledger, ctx, sessionId, startSeq, endSeq, disp
|
|
|
94
96
|
|
|
95
97
|
function usageRecord(row) {
|
|
96
98
|
if (!row || typeof row !== 'object') return null
|
|
97
|
-
if (row.type === 'session') return { type: 'session', id: row.id, createdAt: row.createdAt }
|
|
99
|
+
if (row.type === 'session') return { type: 'session', id: row.id, createdAt: row.createdAt, ...(forkSeedLength(row) ? { seedLength: forkSeedLength(row) } : {}) }
|
|
100
|
+
if (row.type === 'assistant/attempt') return { type: row.type, seq: row.seq, time: row.time,
|
|
101
|
+
data: { turn: row.data?.turn, step: row.data?.step, usage: usageOnly(attemptUsage(row.data)) } }
|
|
98
102
|
if (isNativeSearchUsageEvent(row)) return { type: row.type, seq: row.seq, time: row.time, data: {
|
|
99
103
|
provider: row.data.provider, model: row.data.model, requestId: row.data.requestId, startedAtMs: row.data.startedAtMs, usage: usageOnly(row.data.usage),
|
|
100
104
|
...(row.data.requestFee ? { requestFee: row.data.requestFee } : {}),
|
|
@@ -113,13 +117,13 @@ export async function sessionUsageRecords(ctx, sessionId, ledgerPath = '') {
|
|
|
113
117
|
const session = ctx?.get?.('sessions')?.get?.(sessionId)
|
|
114
118
|
const live = session?.snapshotEvents?.()
|
|
115
119
|
if (Array.isArray(live)) {
|
|
116
|
-
const
|
|
120
|
+
const header = session.header ?? {}
|
|
117
121
|
// 切到会话时每个回合的费用小标签各查一次本会话用量。会话日志只增不改,session.seq 就是
|
|
118
122
|
// 天然版本号:同一版本内(一次切换的多个标签)共享一次遍历,日志推进后自动重算。
|
|
119
123
|
// 宿主快照不暴露 seq 时无法证明新鲜度,退回逐次读取,行为与未缓存一致。
|
|
120
|
-
if (!Number.isSafeInteger(session.seq)) return liveUsageRows(sessionId, live,
|
|
124
|
+
if (!Number.isSafeInteger(session.seq)) return liveUsageRows(sessionId, live, header)
|
|
121
125
|
const revision = `${session.seq}:${live.length}`
|
|
122
|
-
return cachedUsageRecords(JSON.stringify([ledgerPath, 'live', sessionId]), revision, () => liveUsageRows(sessionId, live,
|
|
126
|
+
return cachedUsageRecords(JSON.stringify([ledgerPath, 'live', sessionId]), revision, () => liveUsageRows(sessionId, live, header))
|
|
123
127
|
}
|
|
124
128
|
// RDB(会话 SQLite)宿主不落 JSONL 文件:通过兼容层读 records,按 revision 缓存。
|
|
125
129
|
if (probeSessionStorage(ctx).mode === 'rdb') return rdbSessionUsageRecords(ctx, sessionId, ledgerPath)
|
|
@@ -193,8 +197,8 @@ async function rdbSessionUsageRecords(ctx, sessionId, ledgerPath) {
|
|
|
193
197
|
}
|
|
194
198
|
|
|
195
199
|
/** live 快照逐条归一化;每 4096 条让出事件循环,避免长日志卡住其它请求。 */
|
|
196
|
-
async function liveUsageRows(sessionId, live,
|
|
197
|
-
const rows = [{ type: 'session', id: sessionId
|
|
200
|
+
async function liveUsageRows(sessionId, live, header) {
|
|
201
|
+
const rows = [usageRecord({ ...header, type: 'session', id: sessionId })]
|
|
198
202
|
for (let i = 0; i < live.length; i++) {
|
|
199
203
|
const row = usageRecord(live[i]); if (row) rows.push(row)
|
|
200
204
|
if (i % 4096 === 4095) await setImmediate()
|
package/lib/typert.host.js
CHANGED
|
@@ -319,6 +319,7 @@ const configSchema = z.object({
|
|
|
319
319
|
detail: z.boolean(),
|
|
320
320
|
}),
|
|
321
321
|
codingPlans: z.record(z.string(), z.object({
|
|
322
|
+
sidebarAfterSuccess: z.boolean().optional(),
|
|
322
323
|
enabled: z.boolean().optional(),
|
|
323
324
|
showInComposer: z.boolean().optional(),
|
|
324
325
|
display: z.enum(['sidebar', 'settings', 'both', 'off']).optional(),
|
|
@@ -378,7 +379,7 @@ const configSchema = z.object({
|
|
|
378
379
|
keySource: z.string().optional(),
|
|
379
380
|
}),
|
|
380
381
|
customBalance: z.object({
|
|
381
|
-
adapter: z.enum(['custom', 'aliyun', 'tokenrhythm', 'openai-credits']).optional(),
|
|
382
|
+
adapter: z.enum(['custom', 'aliyun', 'tokenrhythm', 'openai-credits', 'fireworks']).optional(),
|
|
382
383
|
grantAmount: num.optional(),
|
|
383
384
|
grantStart: z.string().optional(),
|
|
384
385
|
grantExpiry: z.string().optional(),
|
|
@@ -398,12 +399,13 @@ const configSchema = z.object({
|
|
|
398
399
|
body: z.unknown().optional(),
|
|
399
400
|
}),
|
|
400
401
|
extract: z.record(z.string(), z.unknown()),
|
|
402
|
+
channels: z.array(z.string()).optional(),
|
|
401
403
|
allowedHosts: z.array(z.string()).optional(),
|
|
402
404
|
}).optional(),
|
|
403
405
|
// 多配置形态(v1.7.0,issue #79):自定义 Provider 余额多条并行,数组为运行期
|
|
404
406
|
// 真源;customBalance 单配置键仅为旧客户端兼容保留(= entries[0] 的镜像)。
|
|
405
407
|
customBalances: z.array(z.object({
|
|
406
|
-
adapter: z.enum(['custom', 'aliyun', 'tokenrhythm', 'openai-credits']).optional(),
|
|
408
|
+
adapter: z.enum(['custom', 'aliyun', 'tokenrhythm', 'openai-credits', 'fireworks']).optional(),
|
|
407
409
|
grantAmount: num.optional(),
|
|
408
410
|
grantStart: z.string().optional(),
|
|
409
411
|
grantExpiry: z.string().optional(),
|
|
@@ -423,6 +425,7 @@ const configSchema = z.object({
|
|
|
423
425
|
body: z.unknown().optional(),
|
|
424
426
|
}),
|
|
425
427
|
extract: z.record(z.string(), z.unknown()),
|
|
428
|
+
channels: z.array(z.string()).optional(),
|
|
426
429
|
allowedHosts: z.array(z.string()).optional(),
|
|
427
430
|
})).optional(),
|
|
428
431
|
gatewayQuotas: z.object({
|
|
@@ -547,6 +550,7 @@ const gatewayAccountSchema = z.object({
|
|
|
547
550
|
plan: z.string().optional(), credits: gatewayCreditsSchema.optional(),
|
|
548
551
|
})
|
|
549
552
|
const gatewayQuotaSchema = z.object({
|
|
553
|
+
browserAccessDenied: z.boolean().optional(),
|
|
550
554
|
id: z.string().max(48), type: z.enum(['cliproxyapi', 'agy-link']), label: z.string().max(80),
|
|
551
555
|
status: z.enum(['off', 'loading', 'ok', 'partial', 'stale', 'error']),
|
|
552
556
|
message: z.string(), fetchedAt: num, attemptedAt: num,
|
|
@@ -736,7 +740,7 @@ const _state$codec = strictCodec('CostState', stateSchema)
|
|
|
736
740
|
const _patch$codec = strictCodec('ConfigPatch', patchSchema)
|
|
737
741
|
const _fetch$codec = strictCodec('FetchPricesResult', fetchPricesSchema)
|
|
738
742
|
const _repricingDetail = z.object({ sessionId: z.string(), date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/), model: z.string(),
|
|
739
|
-
reason: z.enum(['usage', 'ledgerModelMissing', 'logModelMissing', 'dayModelMissing', 'logMissing']),
|
|
743
|
+
reason: z.enum(['usage', 'auxiliaryUsage', 'dynamicQuote', 'ledgerModelMissing', 'logModelMissing', 'dayModelMissing', 'logMissing']),
|
|
740
744
|
fields: z.array(z.object({ field: z.enum(['input', 'output', 'cacheRead', 'cacheWrite', 'reasoning', 'calls']), ledger: z.number().finite().nonnegative(), log: z.number().finite().nonnegative() })) })
|
|
741
745
|
const _repricingHistory$codec = strictCodec('RepricingHistory', z.array(z.object({ ...Object.fromEntries(['at', 'before', 'after', 'days', 'sessions', 'skipped'].map(key => [key, z.number().finite().nonnegative()])), ...Object.fromEntries(['beforeCny', 'afterCny', 'beforeEur', 'afterEur'].map(key => [key, z.number().finite().nonnegative().optional()])), model: z.string().optional(), skippedDetails: z.array(_repricingDetail).optional() })))
|
|
742
746
|
const _repricingConfirmation$codec = strictCodec('RepricingConfirmation', z.boolean())
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cost-meter",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.78",
|
|
4
4
|
"description": "DeepSeek Harness 会话费用统计插件:本会话成本、当日费用、历史记录与官方价格同步,支持多厂商多模型价格计费(内置 170+ 模型 ID 价格目录与自动匹配)、主流 Coding Plan 订阅额度查询与显示(16 家,含 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 16 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",
|
|
@@ -99,6 +99,8 @@
|
|
|
99
99
|
},
|
|
100
100
|
"files": [
|
|
101
101
|
"docs/web-request-fees.md",
|
|
102
|
+
"docs/host-price-calculators.md",
|
|
103
|
+
"docs/release-notes/v1.9.78.md",
|
|
102
104
|
"locale",
|
|
103
105
|
"lib",
|
|
104
106
|
"cordis.patch.yml",
|
|
@@ -244,7 +246,7 @@
|
|
|
244
246
|
"docs/update-notes-1.9.70.md",
|
|
245
247
|
"docs/update-notes-1.9.71.md",
|
|
246
248
|
"docs/update-notes-1.9.72.md",
|
|
247
|
-
"docs/update-notes-1.9.
|
|
249
|
+
"docs/update-notes-1.9.77.md"
|
|
248
250
|
],
|
|
249
251
|
"dependencies": {
|
|
250
252
|
"acorn": "8.15.0",
|