dsh-cost-meter 1.9.71 → 1.9.73
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/plugin-compatibility-watch.md +8 -0
- package/docs/update-notes-1.9.71.md +3 -3
- package/docs/update-notes-1.9.72.md +29 -0
- package/docs/update-notes-1.9.73.md +29 -0
- package/lib/backfill.js +17 -3
- package/lib/billing-history.js +13 -4
- package/lib/bootstrap.js +1 -1
- package/lib/client.js +1 -1
- package/lib/index.js +34 -3
- package/lib/ledger-writer-worker.js +1 -1
- package/lib/pricing.js +28 -5
- package/lib/session-storage-compat.js +53 -9
- package/lib/turn-cost.js +2 -2
- package/package.json +4 -2
package/lib/index.js
CHANGED
|
@@ -33,7 +33,7 @@ import { createLlmStreamBilling } from './billing-stream.js'
|
|
|
33
33
|
import { contextActivity } from './context-activity.js'
|
|
34
34
|
import { installBillionContextBilling, syncBillionContextBilling, billionContextBillingStatus } from './billion-context-billing.js'
|
|
35
35
|
import { installNativeSearchBilling, nativeSearchReconcile, isNativeSearchUsageEvent } from './native-search-billing.js'
|
|
36
|
-
import { OFFICIAL_PRICING_URL, OFFICIAL_PRICING_URL_ZH, LEGACY_BASE_BOUNDARY, FLASH_PRICE_EFFECTIVE_AT, parsePricingHtml, repairDefaultPeakPrice, upgradeDeepSeekPriceTable, costOf, providerPriceEntryFor, buildPriceCatalog, usdFromCost, isWrapperProviderId, wrapperUpstreamProvider } from './pricing.js'
|
|
36
|
+
import { OFFICIAL_PRICING_URL, OFFICIAL_PRICING_URL_ZH, LEGACY_BASE_BOUNDARY, FLASH_PRICE_EFFECTIVE_AT, parsePricingHtml, repairDefaultPeakPrice, upgradeDeepSeekPriceTable, mountMissingDeepSeekFlashModels, costOf, providerPriceEntryFor, buildPriceCatalog, usdFromCost, isWrapperProviderId, wrapperUpstreamProvider } from './pricing.js'
|
|
37
37
|
import { createUsageDeduper, USAGE_DEDUP_WINDOW_MS, usageFingerprint } from './usage-dedup.js'
|
|
38
38
|
import { CODING_PLAN_PROVIDERS, CODING_PLAN_PROVIDER_IDS, queryCodingPlan, scnetTokenPlanWindows, qwenTokenPlanWindows, emptyCustomBalance, queryCustomBalance, normalizeVolcengineKey } from './coding-plans.js'
|
|
39
39
|
import { resolveWorkBuddyCredential } from './workbuddy.js'
|
|
@@ -82,6 +82,23 @@ import { repairBillionHostLedger } from './billion-context-repair.js'
|
|
|
82
82
|
|
|
83
83
|
export const name = 'cost-meter'
|
|
84
84
|
|
|
85
|
+
const LOADED_PACKAGE_VERSION = (() => {
|
|
86
|
+
try { return String(JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version ?? '') } catch { return '' }
|
|
87
|
+
})()
|
|
88
|
+
|
|
89
|
+
function diskPackageVersionNotice(en) {
|
|
90
|
+
if (!LOADED_PACKAGE_VERSION) return ''
|
|
91
|
+
try {
|
|
92
|
+
const current = String(JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version ?? '')
|
|
93
|
+
if (!current || current === LOADED_PACKAGE_VERSION) return ''
|
|
94
|
+
return en
|
|
95
|
+
? ` Plugin files on disk were updated (${LOADED_PACKAGE_VERSION} -> ${current}); restart DSH to load the updated service.`
|
|
96
|
+
: ` 检测到插件已更新(当前运行 ${LOADED_PACKAGE_VERSION},磁盘版本 ${current}),请重启 DSH 使新版本生效。`
|
|
97
|
+
} catch {
|
|
98
|
+
return ''
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
85
102
|
// ── 多语言(中/英) ─────────────────────────────────────────────────────────
|
|
86
103
|
|
|
87
104
|
/** 服务端用户可见文案(zh/en)。 */
|
|
@@ -2743,9 +2760,10 @@ function createService(ctx, ledger, openRouterPrices, openDesignPrices, codexSub
|
|
|
2743
2760
|
ledger.flush()
|
|
2744
2761
|
if (ledger.pendingWrite) throw new Error(en ? 'Could not save recalculation; original ledger backup retained.' : '重算结果未能写入,已保留原账本备份。')
|
|
2745
2762
|
schedulePlanHourRepair()
|
|
2746
|
-
|
|
2763
|
+
const restartNotice = diskPackageVersionNotice(en)
|
|
2764
|
+
return { ok: true, message: (en
|
|
2747
2765
|
? `${model ? model + ': ' : ''}Recalculated ${stats.recostedSessions} session/day records; ${stats.skippedSessions} unchanged.${stats.skippedSessions ? ' See details in recalculation records.' : ''}`
|
|
2748
|
-
: `${model ? model + ':' : ''}已重算 ${stats.recostedSessions} 条会话日期记录,${stats.skippedSessions} 条保留原金额。${stats.skippedSessions ? '差异见重算记录。' : ''}
|
|
2766
|
+
: `${model ? model + ':' : ''}已重算 ${stats.recostedSessions} 条会话日期记录,${stats.skippedSessions} 条保留原金额。${stats.skippedSessions ? '差异见重算记录。' : ''}`) + restartNotice, state: await build(false, true) }
|
|
2749
2767
|
} finally { repricing = false }
|
|
2750
2768
|
},
|
|
2751
2769
|
|
|
@@ -3582,6 +3600,7 @@ const DEFAULT_PRICE_MIGRATION_PENDING = 'default-peak-price-pending-v1'
|
|
|
3582
3600
|
const SEPTEMBER_PRICE_MIGRATION = 'deepseek-september-2026-prices-v1'
|
|
3583
3601
|
const SEPTEMBER_PRICE_PENDING = 'deepseek-september-2026-prices-pending-v1'
|
|
3584
3602
|
const DEEPSEEK_OFFICIAL_PRICE_FIX = 'deepseek-official-pro-prices-v1'
|
|
3603
|
+
const DEEPSEEK_FLASH_CATALOG_MIGRATION = 'deepseek-flash-catalog-v1'
|
|
3585
3604
|
|
|
3586
3605
|
function prepareOfficialDeepSeekPrices(ledger) {
|
|
3587
3606
|
if (ledger.migrations.includes(DEEPSEEK_OFFICIAL_PRICE_FIX)) return
|
|
@@ -3594,6 +3613,16 @@ function prepareOfficialDeepSeekPrices(ledger) {
|
|
|
3594
3613
|
ledger.scheduleWrite()
|
|
3595
3614
|
}
|
|
3596
3615
|
|
|
3616
|
+
function prepareDeepSeekFlashCatalog(ledger) {
|
|
3617
|
+
if (ledger.migrations.includes(DEEPSEEK_FLASH_CATALOG_MIGRATION)) return
|
|
3618
|
+
const prices = structuredClone(ledger.config.prices)
|
|
3619
|
+
if (mountMissingDeepSeekFlashModels(prices).length > 0) {
|
|
3620
|
+
ledger.config = { ...ledger.config, prices }
|
|
3621
|
+
}
|
|
3622
|
+
ledger.migrations.push(DEEPSEEK_FLASH_CATALOG_MIGRATION)
|
|
3623
|
+
ledger.scheduleWrite()
|
|
3624
|
+
}
|
|
3625
|
+
|
|
3597
3626
|
function prepareSeptemberPrices(ledger) {
|
|
3598
3627
|
if (ledger.migrations.includes(SEPTEMBER_PRICE_MIGRATION) || ledger.migrations.includes(SEPTEMBER_PRICE_PENDING)) return
|
|
3599
3628
|
const changed = upgradeDeepSeekPriceTable(ledger.config.prices)
|
|
@@ -3639,6 +3668,7 @@ export async function runStartupImports(ledger, sessionsRoot, sessionSource = nu
|
|
|
3639
3668
|
// RDB 空扫描不消费一次性标记(下次启动重试);JSONL 下保持原语义。
|
|
3640
3669
|
const jsonlBackend = isJsonlSessionBackend(sessionSource)
|
|
3641
3670
|
prepareOfficialDeepSeekPrices(ledger)
|
|
3671
|
+
prepareDeepSeekFlashCatalog(ledger)
|
|
3642
3672
|
prepareDefaultPeakPrice(ledger)
|
|
3643
3673
|
prepareSeptemberPrices(ledger)
|
|
3644
3674
|
// Versioned ledgers preserve recorded amounts. Old price migrations must not
|
|
@@ -3971,6 +4001,7 @@ function applyCore(ctx) {
|
|
|
3971
4001
|
ctx.effect(() => () => statisticsWarmup.dispose(), 'cost-meter: statistics warmup')
|
|
3972
4002
|
// 必须先于监听器/投影注册,避免延迟历史修复期间的新调用仍使用旧默认谷价。
|
|
3973
4003
|
prepareOfficialDeepSeekPrices(ledger)
|
|
4004
|
+
prepareDeepSeekFlashCatalog(ledger)
|
|
3974
4005
|
prepareDefaultPeakPrice(ledger)
|
|
3975
4006
|
prepareSeptemberPrices(ledger)
|
|
3976
4007
|
// Cache the installed package version; active runtime status is checked on every state read.
|