@kenz1117/dsh-ui-usage-billing 1.2.4 → 1.2.6
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.en.md +6 -6
- package/README.md +9 -9
- package/lib/client.js +5 -5
- package/lib/index.js +62 -37
- package/lib/types/aggregate.d.ts +1 -1
- package/lib/types/client/pricing.d.ts +11 -13
- package/package.json +3 -2
package/lib/index.js
CHANGED
|
@@ -243,24 +243,13 @@ const WEEKEND_OFFPEAK_START_MS = Date.parse("2026-08-22T16:00:00Z");
|
|
|
243
243
|
* 1/0.02/4(峰 = 谷 × 2)。目录条目写现行(新)价;分界前的历史事件由
|
|
244
244
|
* {@link computeCostAt} 按 {@link FLASH_REPRICED_OFFPEAK} 回算旧价,与
|
|
245
245
|
* {@link PEAK_ERA_START_MS} 同一「按事件时刻分段适用规则」口径。
|
|
246
|
-
*
|
|
247
|
-
* 09-10 的路由时点推迟到 09-14 12:00),不在本分界切换。
|
|
246
|
+
* V4 Pro 不在本分界内:官方取消了 09-14 的路由计划,pro 长期按刊例计费。
|
|
248
247
|
*/
|
|
249
248
|
const FLASH_REPRICE_MS = Date.parse("2026-09-10T04:00:00Z");
|
|
250
249
|
/**
|
|
251
|
-
* V4 Pro 下线路由分界(UTC 2026-09-14T04:00:00Z,即北京时间 2026-09-14
|
|
252
|
-
* 12:00):官方价目页注释明确,此后至 V4.1 Pro 上线前,`deepseek-v4-pro`
|
|
253
|
-
* 的请求全部路由至 V4.1 Flash 并按其单价计费——此前的请求仍按 V4 Pro
|
|
254
|
-
* 峰谷刊例计费(官方原定 09-10 路由,后推迟到 09-14)。
|
|
255
|
-
*/
|
|
256
|
-
const PRO_OFFLINE_MS = Date.parse("2026-09-14T04:00:00Z");
|
|
257
|
-
/**
|
|
258
250
|
* flash 系调价前的官方谷档价(CNY / 1M tokens):{@link FLASH_REPRICE_MS}
|
|
259
|
-
* 之前的 flash / flash-vision-exp 事件按此回算(峰档 = 谷档 × 2)。
|
|
260
|
-
*
|
|
261
|
-
* {@link PRO_OFFLINE_MS} 起(原定 09-10,后推迟)把 V4 Pro 请求全部路由至
|
|
262
|
-
* V4.1 Flash 并按其单价计费(V4.1 Pro 上线前),故分界前回算 V4 Pro 刊例、
|
|
263
|
-
* 分界后走目录的 Flash 价。用户价 = 实付价,与 legacy 口径相同地跳过本表。
|
|
251
|
+
* 之前的 flash / flash-vision-exp 事件按此回算(峰档 = 谷档 × 2)。
|
|
252
|
+
* 用户价 = 实付价,与 legacy 口径相同地跳过本表。
|
|
264
253
|
*/
|
|
265
254
|
const FLASH_PRE_REPRICE_BAND = {
|
|
266
255
|
input: 1.5,
|
|
@@ -269,12 +258,7 @@ const FLASH_PRE_REPRICE_BAND = {
|
|
|
269
258
|
};
|
|
270
259
|
const FLASH_REPRICED_OFFPEAK = {
|
|
271
260
|
flash: FLASH_PRE_REPRICE_BAND,
|
|
272
|
-
"flash-vision-exp": FLASH_PRE_REPRICE_BAND
|
|
273
|
-
pro: {
|
|
274
|
-
input: 4.5,
|
|
275
|
-
cacheHit: .15,
|
|
276
|
-
output: 13.5
|
|
277
|
-
}
|
|
261
|
+
"flash-vision-exp": FLASH_PRE_REPRICE_BAND
|
|
278
262
|
};
|
|
279
263
|
/**
|
|
280
264
|
* DeepSeek V4 峰谷时代之前的官方基础价(CNY / 1M tokens):官方中文定价页
|
|
@@ -387,13 +371,13 @@ const MODEL_CATALOG = [
|
|
|
387
371
|
colorVar: "dsw-static-deepseek-500",
|
|
388
372
|
price: {
|
|
389
373
|
currency: "CNY",
|
|
390
|
-
input:
|
|
391
|
-
cacheHit: .
|
|
392
|
-
output:
|
|
374
|
+
input: 9,
|
|
375
|
+
cacheHit: .3,
|
|
376
|
+
output: 27,
|
|
393
377
|
offPeak: {
|
|
394
|
-
input:
|
|
395
|
-
cacheHit: .
|
|
396
|
-
output:
|
|
378
|
+
input: 4.5,
|
|
379
|
+
cacheHit: .15,
|
|
380
|
+
output: 13.5
|
|
397
381
|
}
|
|
398
382
|
},
|
|
399
383
|
peakHours: DEEPSEEK_PEAK_HOURS
|
|
@@ -949,6 +933,18 @@ const MODEL_CATALOG = [
|
|
|
949
933
|
output: 9
|
|
950
934
|
}
|
|
951
935
|
},
|
|
936
|
+
{
|
|
937
|
+
key: "gpt-6-astra",
|
|
938
|
+
name: "GPT-6 Astra",
|
|
939
|
+
provider: "OpenAI",
|
|
940
|
+
colorVar: "dsw-static-green-500",
|
|
941
|
+
price: {
|
|
942
|
+
currency: "USD",
|
|
943
|
+
input: 10,
|
|
944
|
+
cacheHit: 1,
|
|
945
|
+
output: 50
|
|
946
|
+
}
|
|
947
|
+
},
|
|
952
948
|
{
|
|
953
949
|
key: "gpt-5.6-sol",
|
|
954
950
|
name: "GPT-5.6 Sol",
|
|
@@ -959,6 +955,12 @@ const MODEL_CATALOG = [
|
|
|
959
955
|
input: 5,
|
|
960
956
|
cacheHit: .5,
|
|
961
957
|
output: 30
|
|
958
|
+
},
|
|
959
|
+
promo: {
|
|
960
|
+
factor: .8,
|
|
961
|
+
factors: { output: 2 / 3 },
|
|
962
|
+
endsAtMs: Date.UTC(2026, 10, 21, 16, 0, 0),
|
|
963
|
+
note: "限时促销至 2026-11-21"
|
|
962
964
|
}
|
|
963
965
|
},
|
|
964
966
|
{
|
|
@@ -1346,6 +1348,19 @@ const MODEL_CATALOG = [
|
|
|
1346
1348
|
},
|
|
1347
1349
|
estimated: true
|
|
1348
1350
|
},
|
|
1351
|
+
{
|
|
1352
|
+
key: "kimi-k2.8-preview",
|
|
1353
|
+
name: "Kimi K2.8 Preview",
|
|
1354
|
+
provider: "月之暗面",
|
|
1355
|
+
colorVar: "dsw-static-cyan-400",
|
|
1356
|
+
price: {
|
|
1357
|
+
currency: "CNY",
|
|
1358
|
+
input: 6.5,
|
|
1359
|
+
cacheHit: 1.3,
|
|
1360
|
+
output: 27
|
|
1361
|
+
},
|
|
1362
|
+
estimated: true
|
|
1363
|
+
},
|
|
1349
1364
|
{
|
|
1350
1365
|
key: "kimi-k2.6-fast",
|
|
1351
1366
|
name: "Kimi K2.6 Fast",
|
|
@@ -1508,6 +1523,12 @@ const MODEL_KEY_ALIASES = {
|
|
|
1508
1523
|
"seed-2.0-mini": "doubao-mini",
|
|
1509
1524
|
"k3": "kimi-k3",
|
|
1510
1525
|
"kimi-k3": "kimi-k3",
|
|
1526
|
+
"kimi-k2.8-preview": "kimi-k2.8-preview",
|
|
1527
|
+
"kimi-k2.8": "kimi-k2.8-preview",
|
|
1528
|
+
"kimi-k2-8-preview": "kimi-k2.8-preview",
|
|
1529
|
+
"kimi-k2-8": "kimi-k2.8-preview",
|
|
1530
|
+
"k2.8-preview": "kimi-k2.8-preview",
|
|
1531
|
+
"k2.8": "kimi-k2.8-preview",
|
|
1511
1532
|
"minimax-m1": "minimax",
|
|
1512
1533
|
"minimax-m2": "minimax",
|
|
1513
1534
|
"minimax-m3": "minimax",
|
|
@@ -1516,7 +1537,9 @@ const MODEL_KEY_ALIASES = {
|
|
|
1516
1537
|
"minimax-m2.7-high-speed": "minimax-m2.7-highspeed",
|
|
1517
1538
|
"minimax-m2-7": "minimax-m2.7",
|
|
1518
1539
|
"minimax-m2-7-highspeed": "minimax-m2.7-highspeed",
|
|
1519
|
-
"minimax-m2-7-high-speed": "minimax-m2.7-highspeed"
|
|
1540
|
+
"minimax-m2-7-high-speed": "minimax-m2.7-highspeed",
|
|
1541
|
+
"gpt-6": "gpt-6-astra",
|
|
1542
|
+
"gpt-6-astra": "gpt-6-astra"
|
|
1520
1543
|
};
|
|
1521
1544
|
/**
|
|
1522
1545
|
* 模型 id 归一化:小写、去括号附注(如 `gpt5.6 luna(go)` 只看主体)、再去所有
|
|
@@ -1681,8 +1704,9 @@ function isPromoActive(promo, nowMs) {
|
|
|
1681
1704
|
return Number.isFinite(nowMs) && !expired && promo.factor > 0 && promo.factor < 1;
|
|
1682
1705
|
}
|
|
1683
1706
|
/**
|
|
1684
|
-
* 把限时促销折入条目单价:生效期内返回 price 主档与 offPeak
|
|
1685
|
-
*
|
|
1707
|
+
* 把限时促销折入条目单价:生效期内返回 price 主档与 offPeak 逐档乘折扣系数的
|
|
1708
|
+
* 副本(某档在 promo.factors 有合法覆盖时用覆盖值,否则用 promo.factor),
|
|
1709
|
+
* 其余字段原样保留;不在促销期(过期/未开始/factor 非法)原样返回。
|
|
1686
1710
|
* 幂等由调用方保证——计价与费率表显示各自只折一次,勿对已折价副本重复应用。
|
|
1687
1711
|
* @param entry - 目录条目(price 保持刊例价口径)。
|
|
1688
1712
|
* @param nowMs - 判定时刻(epoch ms)。
|
|
@@ -1690,11 +1714,12 @@ function isPromoActive(promo, nowMs) {
|
|
|
1690
1714
|
function applyPromo(entry, nowMs) {
|
|
1691
1715
|
const { promo } = entry;
|
|
1692
1716
|
if (promo === void 0 || !isPromoActive(promo, nowMs)) return entry;
|
|
1717
|
+
const factorOf = (field) => promo.factors?.[field] ?? promo.factor;
|
|
1693
1718
|
const scaled = (band) => ({
|
|
1694
|
-
input: band.input *
|
|
1695
|
-
cacheHit: band.cacheHit *
|
|
1696
|
-
...band.cacheMiss !== void 0 ? { cacheMiss: band.cacheMiss *
|
|
1697
|
-
output: band.output *
|
|
1719
|
+
input: band.input * factorOf("input"),
|
|
1720
|
+
cacheHit: band.cacheHit * factorOf("cacheHit"),
|
|
1721
|
+
...band.cacheMiss !== void 0 ? { cacheMiss: band.cacheMiss * factorOf("cacheMiss") } : {},
|
|
1722
|
+
output: band.output * factorOf("output")
|
|
1698
1723
|
});
|
|
1699
1724
|
return {
|
|
1700
1725
|
...entry,
|
|
@@ -1771,7 +1796,7 @@ function computeCostAt(entry, buckets, timeMs, peakShare = DEFAULT_PEAK_SHARE) {
|
|
|
1771
1796
|
const priced = applyPromo(entry, timeMs);
|
|
1772
1797
|
const legacy = timeMs < PEAK_ERA_START_MS && entry.userPriced !== true ? LEGACY_DEEPSEEK_BANDS[entry.key] : void 0;
|
|
1773
1798
|
if (legacy !== void 0) return priceBandCost(legacy, buckets, "CNY");
|
|
1774
|
-
const repriced = timeMs <
|
|
1799
|
+
const repriced = timeMs < FLASH_REPRICE_MS && entry.userPriced !== true ? FLASH_REPRICED_OFFPEAK[entry.key] : void 0;
|
|
1775
1800
|
if (repriced !== void 0) return priceBandCost((timeMs < WEEKEND_OFFPEAK_START_MS ? tariffV1At(timeMs) : tierAt(timeMs)) === "peak" ? {
|
|
1776
1801
|
input: repriced.input * 2,
|
|
1777
1802
|
cacheHit: repriced.cacheHit * 2,
|
|
@@ -2511,7 +2536,7 @@ function createUsageAggregator(persistence, options = {}) {
|
|
|
2511
2536
|
id,
|
|
2512
2537
|
...cwd === void 0 ? {} : { cwd },
|
|
2513
2538
|
...stamp === null ? {} : { stamp },
|
|
2514
|
-
foldVersion:
|
|
2539
|
+
foldVersion: 15,
|
|
2515
2540
|
fingerprint: foldFingerprint,
|
|
2516
2541
|
fold: serializeFold(fold)
|
|
2517
2542
|
};
|
|
@@ -2608,7 +2633,7 @@ function createUsageAggregator(persistence, options = {}) {
|
|
|
2608
2633
|
try {
|
|
2609
2634
|
const cwd = meta.cwd;
|
|
2610
2635
|
const ledgerRow = ledger.get(id);
|
|
2611
|
-
if (ledgerRow !== void 0 && ledgerRow.stamp !== void 0 && stamp !== null && ledgerRow.stamp === stamp && (ledgerRow.foldVersion ?? 1) ===
|
|
2636
|
+
if (ledgerRow !== void 0 && ledgerRow.stamp !== void 0 && stamp !== null && ledgerRow.stamp === stamp && (ledgerRow.foldVersion ?? 1) === 15 && ledgerRow.fingerprint === foldFingerprint) {
|
|
2612
2637
|
const fold = deserializeFold(ledgerRow.fold);
|
|
2613
2638
|
folds.push({
|
|
2614
2639
|
id,
|
|
@@ -2690,7 +2715,7 @@ function createUsageAggregator(persistence, options = {}) {
|
|
|
2690
2715
|
for (const entry of ledger.values()) {
|
|
2691
2716
|
if (included.has(entry.id)) continue;
|
|
2692
2717
|
try {
|
|
2693
|
-
const stale = (entry.foldVersion ?? 1) <
|
|
2718
|
+
const stale = (entry.foldVersion ?? 1) < 15 || entry.fingerprint !== foldFingerprint;
|
|
2694
2719
|
folds.push({
|
|
2695
2720
|
id: entry.id,
|
|
2696
2721
|
...entry.cwd === void 0 ? {} : { cwd: entry.cwd },
|
package/lib/types/aggregate.d.ts
CHANGED
|
@@ -491,7 +491,7 @@ export interface UsageLedgerDocument {
|
|
|
491
491
|
* 会话费用只剩最近一段,issue #29)。
|
|
492
492
|
* 持久账本行据此区分新旧算法:日志已删/不可读而只能沿用旧行时,UI 标注置信度提示。
|
|
493
493
|
*/
|
|
494
|
-
export declare const FOLD_VERSION =
|
|
494
|
+
export declare const FOLD_VERSION = 15;
|
|
495
495
|
/**
|
|
496
496
|
* 一次性账本迁移:id 唯一,apply 在加载边界对原始文档执行,已应用过的跳过。
|
|
497
497
|
* 未来账本/schema 字段变更(重命名、拆桶、语义调整)时,在此追加一条迁移并
|
|
@@ -159,17 +159,9 @@ export declare const WEEKEND_OFFPEAK_START_MS: number;
|
|
|
159
159
|
* 1/0.02/4(峰 = 谷 × 2)。目录条目写现行(新)价;分界前的历史事件由
|
|
160
160
|
* {@link computeCostAt} 按 {@link FLASH_REPRICED_OFFPEAK} 回算旧价,与
|
|
161
161
|
* {@link PEAK_ERA_START_MS} 同一「按事件时刻分段适用规则」口径。
|
|
162
|
-
*
|
|
163
|
-
* 09-10 的路由时点推迟到 09-14 12:00),不在本分界切换。
|
|
162
|
+
* V4 Pro 不在本分界内:官方取消了 09-14 的路由计划,pro 长期按刊例计费。
|
|
164
163
|
*/
|
|
165
164
|
export declare const FLASH_REPRICE_MS: number;
|
|
166
|
-
/**
|
|
167
|
-
* V4 Pro 下线路由分界(UTC 2026-09-14T04:00:00Z,即北京时间 2026-09-14
|
|
168
|
-
* 12:00):官方价目页注释明确,此后至 V4.1 Pro 上线前,`deepseek-v4-pro`
|
|
169
|
-
* 的请求全部路由至 V4.1 Flash 并按其单价计费——此前的请求仍按 V4 Pro
|
|
170
|
-
* 峰谷刊例计费(官方原定 09-10 路由,后推迟到 09-14)。
|
|
171
|
-
*/
|
|
172
|
-
export declare const PRO_OFFLINE_MS: number;
|
|
173
165
|
/** 计费时段档位:高峰 / 空闲(官方 DeepSeek 刊例价:高峰 = 空闲 × 2)。 */
|
|
174
166
|
export type PriceTierId = 'peak' | 'offPeak';
|
|
175
167
|
/** 成本显示币种:人民币(国内模型直价)/ 美元(国外模型直价或换算显示)。 */
|
|
@@ -253,6 +245,12 @@ export interface ModelPrice extends PriceBand {
|
|
|
253
245
|
export interface PricePromo {
|
|
254
246
|
/** 折扣系数(0.5 = 五折);仅 (0,1) 区间有效,非法值视为无促销。 */
|
|
255
247
|
factor: number;
|
|
248
|
+
/**
|
|
249
|
+
* 分档折扣覆盖:厂商对不同档位给不同折扣时逐档指定(如 GPT-5.6 Sol 促销为
|
|
250
|
+
* 缓存 0.8 / 输入 0.8 / 输出 2/3)。缺省档位沿用 {@link factor};单档取值
|
|
251
|
+
* 仅 (0,1) 区间有效,非法值回落 factor。
|
|
252
|
+
*/
|
|
253
|
+
factors?: Partial<Record<'input' | 'cacheHit' | 'cacheMiss' | 'output', number>>;
|
|
256
254
|
/**
|
|
257
255
|
* 截止时刻(epoch ms):该时刻及之后恢复刊例价。缺省表示厂商未公布截止日
|
|
258
256
|
* 的长期活动(如「限时 5 折直至另行通知」),持续生效直至收到公告后补填。
|
|
@@ -354,8 +352,9 @@ export declare function isPriced(key: string): boolean;
|
|
|
354
352
|
*/
|
|
355
353
|
export declare function isPromoActive(promo: PricePromo, nowMs: number): boolean;
|
|
356
354
|
/**
|
|
357
|
-
* 把限时促销折入条目单价:生效期内返回 price 主档与 offPeak
|
|
358
|
-
*
|
|
355
|
+
* 把限时促销折入条目单价:生效期内返回 price 主档与 offPeak 逐档乘折扣系数的
|
|
356
|
+
* 副本(某档在 promo.factors 有合法覆盖时用覆盖值,否则用 promo.factor),
|
|
357
|
+
* 其余字段原样保留;不在促销期(过期/未开始/factor 非法)原样返回。
|
|
359
358
|
* 幂等由调用方保证——计价与费率表显示各自只折一次,勿对已折价副本重复应用。
|
|
360
359
|
* @param entry - 目录条目(price 保持刊例价口径)。
|
|
361
360
|
* @param nowMs - 判定时刻(epoch ms)。
|
|
@@ -368,8 +367,7 @@ export declare function applyPromo(entry: ModelEntry, nowMs: number): ModelEntry
|
|
|
368
367
|
* {@link modelOf})。探活模型在此逐个对价:内置已有的跳过去重;目录外但
|
|
369
368
|
* models.dev 有价的按归一化 id 复用其 USD 价;两者皆无的标 `uncatalogued`。
|
|
370
369
|
* 内置条目按 nowMs 折算限时促销(生效中的条目显示折后单价,过期自动恢复刊例价),
|
|
371
|
-
*
|
|
372
|
-
* 已下线条目(retired:官方下线的型号不进面板,目录与历史回算保留)。
|
|
370
|
+
* 并滤除已下线条目(retired:官方下线的型号不进面板,目录与历史回算保留)。
|
|
373
371
|
* @param nowMs - 促销判定时刻;缺省当前时刻。
|
|
374
372
|
*/
|
|
375
373
|
export declare function catalogEntries(nowMs?: number): readonly ModelEntry[];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kenz1117/dsh-ui-usage-billing",
|
|
3
3
|
"description": "Usage billing dashboard for DeepSeek Harness: sidebar cost metrics plus a full dashboard modal, priced from a current multi-provider catalog with real usage aggregated from session logs.",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.6",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|
|
7
7
|
"deepseek",
|
|
@@ -64,7 +64,8 @@
|
|
|
64
64
|
"0.1.3-alpha.2": "compatible",
|
|
65
65
|
"0.1.5-alpha.1": "compatible",
|
|
66
66
|
"0.1.5-alpha.2": "compatible",
|
|
67
|
-
"0.1.5-rc.1": "compatible"
|
|
67
|
+
"0.1.5-rc.1": "compatible",
|
|
68
|
+
"0.1.5-rc.2": "compatible"
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
},
|