@kenz1117/dsh-ui-usage-billing 1.2.5 → 1.2.7
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 +365 -86
- package/lib/types/aggregate.d.ts +60 -4
- package/lib/types/client/pricing.d.ts +11 -13
- package/package.json +1 -1
package/lib/types/aggregate.d.ts
CHANGED
|
@@ -392,6 +392,36 @@ export interface PerfSample {
|
|
|
392
392
|
/** 无独立 request/header,以 step/start 起算(工具续写步骤)。 */
|
|
393
393
|
estimated: boolean;
|
|
394
394
|
}
|
|
395
|
+
/**
|
|
396
|
+
* 会话级性能摘要(per model):账本持久化形态——替代逐样本持久化,体积
|
|
397
|
+
* O(模型数) 而非 O(样本数)。计数/求和/极值精确合并;分位数(P50/P90)
|
|
398
|
+
* 在跨会话合并时按样本数加权(展示级近似)。进程内折叠的会话仍保留
|
|
399
|
+
* 完整样本(doc 生成走精确插值),仅账本恢复行以摘要参与聚合。
|
|
400
|
+
*/
|
|
401
|
+
export interface PerfModelDigest {
|
|
402
|
+
/** 样本数。 */
|
|
403
|
+
samples: number;
|
|
404
|
+
ttftSum: number;
|
|
405
|
+
ttftMax: number;
|
|
406
|
+
ttftSpikes: number;
|
|
407
|
+
ttftP50: number;
|
|
408
|
+
ttftP90: number;
|
|
409
|
+
/** 有可测生成速度的样本数。 */
|
|
410
|
+
tpsCount: number;
|
|
411
|
+
tpsSum: number;
|
|
412
|
+
/** 有可测总延迟的样本数。 */
|
|
413
|
+
latencyCount: number;
|
|
414
|
+
latencySum: number;
|
|
415
|
+
/** 以 step/start 估算的样本数。 */
|
|
416
|
+
estimated: number;
|
|
417
|
+
}
|
|
418
|
+
/** 会话级 小时×模型 性能摘要(只用均值,合并无损)。 */
|
|
419
|
+
export interface PerfHourDigest {
|
|
420
|
+
samples: number;
|
|
421
|
+
ttftSum: number;
|
|
422
|
+
tpsCount: number;
|
|
423
|
+
tpsSum: number;
|
|
424
|
+
}
|
|
395
425
|
/** One persisted session's folded usage plus drill-down metadata. */
|
|
396
426
|
export interface SessionFold {
|
|
397
427
|
total: ModelUsage;
|
|
@@ -412,8 +442,13 @@ export interface SessionFold {
|
|
|
412
442
|
planCalls: Map<string, number>;
|
|
413
443
|
/** 每轮费用明细(按轮次号升序,不含 sessionId);sessionId 在合并时补齐。 */
|
|
414
444
|
turns: SessionTurnRow[];
|
|
415
|
-
/** 性能样本(有可测 TTFT
|
|
445
|
+
/** 性能样本(有可测 TTFT 的调用,按事件次序折叠);仅进程内折叠产生,
|
|
446
|
+
* 账本恢复行恒为空(其性能在 {@link SessionFold.perfDigest} 里)。 */
|
|
416
447
|
perf: PerfSample[];
|
|
448
|
+
/** 账本恢复行的模型级性能摘要;进程内折叠恒为空(序列化时从样本构建)。 */
|
|
449
|
+
perfDigest: Map<string, PerfModelDigest>;
|
|
450
|
+
/** 账本恢复行的小时×模型性能摘要;进程内折叠恒为空。 */
|
|
451
|
+
perfHourDigest: Map<string, Map<string, PerfHourDigest>>;
|
|
417
452
|
/** 角色归因中间量:消息文本长度(user/tool)与输入/输出成本实测拆分。 */
|
|
418
453
|
roles: RoleFold;
|
|
419
454
|
/** 日志里最新的 session/title 文本(无标题事件时 undefined)。 */
|
|
@@ -447,7 +482,11 @@ export interface SerializedSessionFold {
|
|
|
447
482
|
unpricedModels: string[];
|
|
448
483
|
planCalls: Record<string, number>;
|
|
449
484
|
turns: SessionTurnRow[];
|
|
450
|
-
|
|
485
|
+
/** v16 起以摘要持久化性能(体积 O(模型数) 而非 O(样本数));旧行的
|
|
486
|
+
* `perf` 逐样本数组由加载边界迁移转换为摘要。 */
|
|
487
|
+
perfDigest: Record<string, PerfModelDigest>;
|
|
488
|
+
/** 小时×模型摘要(键 = {@link hourStamp});同上由迁移补齐。 */
|
|
489
|
+
perfHourDigest: Record<string, Record<string, PerfHourDigest>>;
|
|
451
490
|
roles: RoleFold;
|
|
452
491
|
lastActive: number;
|
|
453
492
|
}
|
|
@@ -491,7 +530,7 @@ export interface UsageLedgerDocument {
|
|
|
491
530
|
* 会话费用只剩最近一段,issue #29)。
|
|
492
531
|
* 持久账本行据此区分新旧算法:日志已删/不可读而只能沿用旧行时,UI 标注置信度提示。
|
|
493
532
|
*/
|
|
494
|
-
export declare const FOLD_VERSION =
|
|
533
|
+
export declare const FOLD_VERSION = 16;
|
|
495
534
|
/**
|
|
496
535
|
* 一次性账本迁移:id 唯一,apply 在加载边界对原始文档执行,已应用过的跳过。
|
|
497
536
|
* 未来账本/schema 字段变更(重命名、拆桶、语义调整)时,在此追加一条迁移并
|
|
@@ -505,7 +544,9 @@ export interface LedgerMigration {
|
|
|
505
544
|
}
|
|
506
545
|
/**
|
|
507
546
|
* 账本迁移注册表。首条迁移给 1.0.6 及更早的行回填 foldVersion = 1(它们全部出自
|
|
508
|
-
* header
|
|
547
|
+
* header 归因算法);perf 摘要化迁移把 v15 及更早行的逐样本 `perf` 数组转换为
|
|
548
|
+
* `perfDigest`/`perfHourDigest` 摘要(日志已删的行不再被重折,迁移是它们唯一的
|
|
549
|
+
* 收缩机会);此后新写入的行总带当前 {@link FOLD_VERSION} 与摘要形态。
|
|
509
550
|
*/
|
|
510
551
|
export declare const LEDGER_MIGRATIONS: readonly LedgerMigration[];
|
|
511
552
|
/**
|
|
@@ -560,10 +601,25 @@ export interface UsageAggregator {
|
|
|
560
601
|
/** Aggregate current usage, reusing cached per-session folds when their logs are untouched.
|
|
561
602
|
* 并发调用共享同一次进行中的折叠(in-flight 去重),不会多倍全量重读。 */
|
|
562
603
|
aggregate(): Promise<UsageStatsDocument>;
|
|
604
|
+
/**
|
|
605
|
+
* 按会话 id 取该会话的完整累计用量。doc 的 `byTurn` 封顶(最近 200 轮),
|
|
606
|
+
* 用户回到旧会话续聊时其轮次已被挤出,从 doc 反推会低估——这里直接读该
|
|
607
|
+
* 会话的缓存/账本折叠,是该会话的精确值(含联网搜索估算,口径与 total 一致)。
|
|
608
|
+
* @param sessionId - 会话 id(String(SessionId) 形态,与账本键同口径)。
|
|
609
|
+
* @returns 会话累计;日志与账本均无该会话时 undefined(调用方自行兜底)。
|
|
610
|
+
*/
|
|
611
|
+
sessionUsageOf(sessionId: string): Promise<SessionUsageSummary | undefined>;
|
|
563
612
|
/** 立刻落盘未保存的账本改动(无视节流),供插件卸载时调用;
|
|
564
613
|
* 进行中的聚合先等完再存,折叠失败仍保存已成功部分。 */
|
|
565
614
|
flush(): Promise<void>;
|
|
566
615
|
}
|
|
616
|
+
/** 单会话累计用量({@link UsageAggregator.sessionUsageOf} 的返回)。 */
|
|
617
|
+
export interface SessionUsageSummary {
|
|
618
|
+
calls: number;
|
|
619
|
+
cost: number;
|
|
620
|
+
input: number;
|
|
621
|
+
output: number;
|
|
622
|
+
}
|
|
567
623
|
/**
|
|
568
624
|
* 聚合配置指纹:影响折叠语义的全部配置(订阅豁免、官方名单、路由别名、搜索估值)
|
|
569
625
|
* 的稳定序列化。账本行的复用判定携带该指纹——用户改配置后(如为 grok build 加
|
|
@@ -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.7",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|
|
7
7
|
"deepseek",
|