@kenz1117/dsh-ui-usage-billing 1.8.4 → 1.8.5

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/lib/index.js CHANGED
@@ -604,13 +604,15 @@ function modelOf(key) {
604
604
  const live = livePriceOf(resolved);
605
605
  if (live === void 0) return base;
606
606
  if (base.price.offPeak !== void 0) return base;
607
+ const cacheWrite = base.price.cacheWrite !== void 0 && base.price.input > 0 ? live.input * (base.price.cacheWrite / base.price.input) : void 0;
607
608
  return {
608
609
  ...base,
609
610
  price: {
610
611
  currency: "USD",
611
612
  input: live.input,
612
613
  cacheHit: live.cacheHit,
613
- output: live.output
614
+ output: live.output,
615
+ ...cacheWrite !== void 0 ? { cacheWrite } : {}
614
616
  }
615
617
  };
616
618
  }
@@ -625,7 +627,8 @@ function extraEntryOf(extra) {
625
627
  currency: "USD",
626
628
  input: extra.price.input,
627
629
  cacheHit: extra.price.cacheHit,
628
- output: extra.price.output
630
+ output: extra.price.output,
631
+ ...extra.price.cacheWrite !== void 0 ? { cacheWrite: extra.price.cacheWrite } : {}
629
632
  }
630
633
  };
631
634
  }
@@ -671,6 +674,7 @@ function applyPromo(entry, nowMs) {
671
674
  input: band.input * factorOf("input"),
672
675
  cacheHit: band.cacheHit * factorOf("cacheHit"),
673
676
  ...band.cacheMiss !== void 0 ? { cacheMiss: band.cacheMiss * factorOf("cacheMiss") } : {},
677
+ ...band.cacheWrite !== void 0 ? { cacheWrite: band.cacheWrite * factorOf("cacheWrite") } : {},
674
678
  output: band.output * factorOf("output")
675
679
  });
676
680
  return {
@@ -689,11 +693,18 @@ function applyPromo(entry, nowMs) {
689
693
  * Providers that report only disjoint buckets carry `cacheMiss` explicitly;
690
694
  * otherwise the miss share is derived as `input - cacheHit`. Only USD-priced
691
695
  * bands go through the exchange rate.
696
+ *
697
+ * 缓存写入单列(issue #123):`cacheWrite` 是 `cacheMiss` 的子集,厂商对它
698
+ * 单独计价(`band.cacheWrite`,缺省按输入价)。拆分后普通未命中按
699
+ * `band.cacheMiss ?? band.input`、缓存写入按 `band.cacheWrite ?? band.input`
700
+ * ——`cacheWrite` 缺省时两者同价,与旧口径逐字一致。
692
701
  */
693
702
  function priceBandCost(band, buckets, currency) {
694
- const miss = buckets.cacheMiss > 0 ? buckets.cacheMiss : Math.max(0, buckets.input - buckets.cacheHit);
703
+ const missTotal = buckets.cacheMiss > 0 ? buckets.cacheMiss : Math.max(0, buckets.input - buckets.cacheHit);
704
+ const write = Math.min(buckets.cacheWrite ?? 0, missTotal);
705
+ const miss = missTotal - write;
695
706
  const hit = Math.min(buckets.cacheHit, buckets.input);
696
- const raw = (miss * (band.cacheMiss ?? band.input) + hit * band.cacheHit + buckets.output * band.output) / 1e6;
707
+ const raw = (miss * (band.cacheMiss ?? band.input) + write * (band.cacheWrite ?? band.input) + hit * band.cacheHit + buckets.output * band.output) / 1e6;
697
708
  return currency === "USD" ? raw * currentRate() : raw;
698
709
  }
699
710
  /**
@@ -819,6 +830,56 @@ function formatTokens(value) {
819
830
  /** DeepSeek 官方高峰时段说明(峰谷分时计费目录条目共用)。 */
820
831
  const DEEPSEEK_PEAK_HOURS = "09:00-12:00 / 14:00-18:00";
821
832
  const GEMINI_PEAK_HOURS = "Standard / Flex";
833
+ /**
834
+ * 厂商「缓存写入」加价系数(issue #123):厂商对「把内容写入缓存」按输入价的
835
+ * 倍数单独计费,models.dev 原生字段 `cache_write` 即该倍率。
836
+ * 2026-11-14 核对 models.dev 实时目录:OpenAI 11/11 恒为 125%、Anthropic 18/18
837
+ * 恒为 125%、百炼(阿里通义)约 125%(`qwen3.8-flash` 例外 156%)。
838
+ * 未列的厂商不落数值 → 缓存写入按输入价计(DeepSeek、月之暗面等本就不单列
839
+ * 缓存写入费,与旧口径逐字一致;MiniMax 高速档倍率不恒定,故不给规则)。
840
+ */
841
+ const CACHE_WRITE_FACTORS = {
842
+ "OpenAI": 1.25,
843
+ "Anthropic": 1.25,
844
+ "阿里通义": 1.25
845
+ };
846
+ /** 条目内官方「显式缓存创建」价(extraRows 行标签)——厂商公布的缓存写入单价。 */
847
+ const CACHE_WRITE_ROW_LABEL = "显式缓存创建";
848
+ /** 单价取整到 6 位小数:消除浮点乘法的尾数噪声(0.3 × 1.25 = 0.375 而非 0.37499…)。 */
849
+ function roundUnitPrice(value) {
850
+ return Number(value.toFixed(6));
851
+ }
852
+ /**
853
+ * 给目录条目补出缓存写入单价(issue #123):条目自带官方「显式缓存创建」价时
854
+ * 以官方值为准(百炼各档比例不恒定),否则按厂商加价系数从输入价派生;
855
+ * 两者皆无 → 不落该字段,计价回退按输入价(与旧口径一致)。
856
+ * 只动主档:分时计价(offPeak)目前只有 DeepSeek,其缓存写入本就按输入价。
857
+ */
858
+ function withCacheWritePrice(entry) {
859
+ if (entry.price.cacheWrite !== void 0) return entry;
860
+ const official = entry.extraRows?.find((row) => row.label === CACHE_WRITE_ROW_LABEL)?.input;
861
+ if (official !== void 0 && official > 0) return {
862
+ ...entry,
863
+ price: {
864
+ ...entry.price,
865
+ cacheWrite: official
866
+ }
867
+ };
868
+ const factor = CACHE_WRITE_FACTORS[entry.provider];
869
+ if (factor === void 0 || !(entry.price.input > 0)) return entry;
870
+ return {
871
+ ...entry,
872
+ price: {
873
+ ...entry.price,
874
+ cacheWrite: roundUnitPrice(entry.price.input * factor)
875
+ }
876
+ };
877
+ }
878
+ /**
879
+ * 内置计费目录(导出态):在原始条目上派生缓存写入单价(issue #123),
880
+ * 使「缓存写入」成为独立计价维度——厂商对写入缓存单独计价时(OpenAI/
881
+ * Anthropic/百炼),缓存写入 token 不再按普通输入价估算。
882
+ */
822
883
  const BUILTIN_MODEL_CATALOG = [
823
884
  {
824
885
  key: "flash",
@@ -4024,7 +4085,7 @@ const BUILTIN_MODEL_CATALOG = [
4024
4085
  output: 0
4025
4086
  }
4026
4087
  }
4027
- ];
4088
+ ].map(withCacheWritePrice);
4028
4089
  /**
4029
4090
  * 真实 provider model id → 计费目录键(`MODEL_CATALOG[].key`)的映射。未知 id
4030
4091
  * 原样保留并落回 `other`(未知模型不估算费用)。聚合层(aggregate.ts)在折叠时
@@ -4420,14 +4481,15 @@ function emptyUsage() {
4420
4481
  */
4421
4482
  function foldUsage(acc, usage, key, subscription, timeMs, official = false, pricedCost, unverifiedChannel = false) {
4422
4483
  const cacheHit = usage.cacheReadTokens ?? 0;
4423
- const cacheMiss = usage.inputTokens + (usage.cacheWriteTokens ?? 0);
4484
+ const cacheWrite = usage.cacheWriteTokens ?? 0;
4485
+ const cacheMiss = usage.inputTokens + cacheWrite;
4424
4486
  acc.calls += 1;
4425
- acc.input += usage.inputTokens + cacheHit + (usage.cacheWriteTokens ?? 0);
4487
+ acc.input += usage.inputTokens + cacheHit + cacheWrite;
4426
4488
  acc.output += usage.outputTokens;
4427
4489
  acc.reasoning += usage.reasoningTokens ?? 0;
4428
4490
  acc.cacheHit += cacheHit;
4429
4491
  acc.cacheMiss += cacheMiss;
4430
- if ((usage.cacheWriteTokens ?? 0) > 0) acc.cacheWrite = (acc.cacheWrite ?? 0) + (usage.cacheWriteTokens ?? 0);
4492
+ if (cacheWrite > 0) acc.cacheWrite = (acc.cacheWrite ?? 0) + cacheWrite;
4431
4493
  if (official) acc.officialCalls += 1;
4432
4494
  if (pricedCost !== void 0) {
4433
4495
  acc.cost += pricedCost;
@@ -4439,6 +4501,7 @@ function foldUsage(acc, usage, key, subscription, timeMs, official = false, pric
4439
4501
  input: cacheHit + cacheMiss,
4440
4502
  cacheHit,
4441
4503
  cacheMiss,
4504
+ cacheWrite,
4442
4505
  output: usage.outputTokens
4443
4506
  }, timeMs);
4444
4507
  acc.cost += thisCost;
@@ -4446,6 +4509,54 @@ function foldUsage(acc, usage, key, subscription, timeMs, official = false, pric
4446
4509
  }
4447
4510
  }
4448
4511
  /**
4512
+ * 折叠一次模型调用:token 分桶 + 计价 + 订阅/官方标记 + 角色归因。
4513
+ *
4514
+ * `assistant/message`(对话主循环)与 `compaction/summary`(上下文压缩摘要,
4515
+ * issue #123)都是真实的模型调用——后者是宿主落盘的压缩摘要事件,自带
4516
+ * `provider`/`model`/`usage`,此前整段被跳过,压缩调用的次数与费用零计入。
4517
+ * 两者共用本函数,保证计费口径逐字一致。
4518
+ * @returns 本次调用的目录条目与费用(未计价时为 undefined)。
4519
+ */
4520
+ function foldModelCall(ctx) {
4521
+ const { fold, usage, modelKey, subscription, official, siteBucket, unverifiedChannel, timeMs, day } = ctx;
4522
+ const priced = !subscription && !unverifiedChannel && isPriced(modelKey);
4523
+ if (!subscription && !isPriced(modelKey)) fold.unpricedModels.add(modelKey);
4524
+ const entry = modelOf(modelKey);
4525
+ const thisCost = priced ? computeCostAt(entry, {
4526
+ input: (usage.cacheReadTokens ?? 0) + usage.inputTokens + (usage.cacheWriteTokens ?? 0),
4527
+ cacheHit: usage.cacheReadTokens ?? 0,
4528
+ cacheMiss: usage.inputTokens + (usage.cacheWriteTokens ?? 0),
4529
+ cacheWrite: usage.cacheWriteTokens ?? 0,
4530
+ output: usage.outputTokens
4531
+ }, timeMs) : void 0;
4532
+ foldUsage(fold.total, usage, modelKey, subscription, timeMs, official, thisCost, unverifiedChannel);
4533
+ foldUsage(usageCell(fold.byModel, modelKey), usage, modelKey, subscription, timeMs, official, thisCost, unverifiedChannel);
4534
+ foldUsage(usageCell(fold.byDay, day), usage, modelKey, subscription, timeMs, official, thisCost, unverifiedChannel);
4535
+ foldUsage(modelDayCell(fold.byDayModels, day, modelKey), usage, modelKey, subscription, timeMs, official, thisCost, unverifiedChannel);
4536
+ foldUsage(modelDaySiteCell(fold.byDayModelsSite, day, modelKey, siteBucket), usage, modelKey, subscription, timeMs, official, thisCost, unverifiedChannel);
4537
+ foldUsage(usageCell(fold.bySite, siteBucket), usage, modelKey, subscription, timeMs, official, thisCost, unverifiedChannel);
4538
+ if (entry.tierSemantics !== "latency") foldUsage(usageCell(fold.byTier, tierAt(timeMs)), usage, modelKey, subscription, timeMs, official, thisCost, unverifiedChannel);
4539
+ if (subscription) fold.planCalls.set(modelKey, (fold.planCalls.get(modelKey) ?? 0) + 1);
4540
+ if (subscription) {
4541
+ const sitePlanKey = planSiteKey(day, modelKey, siteBucket);
4542
+ fold.planSiteCalls.set(sitePlanKey, (fold.planSiteCalls.get(sitePlanKey) ?? 0) + 1);
4543
+ }
4544
+ if (thisCost !== void 0 && entry !== void 0) {
4545
+ const outputCost = computeCostAt(entry, {
4546
+ input: 0,
4547
+ cacheHit: 0,
4548
+ cacheMiss: 0,
4549
+ output: usage.outputTokens
4550
+ }, timeMs);
4551
+ fold.roles.outputCost += outputCost;
4552
+ fold.roles.inputCost += thisCost - outputCost;
4553
+ }
4554
+ return {
4555
+ entry,
4556
+ cost: thisCost
4557
+ };
4558
+ }
4559
+ /**
4449
4560
  * Fold one auxiliary web-search LLM request (issue #15) into an accumulator.
4450
4561
  * 这类调用绕过对话通道直连官方端点,日志只记请求(无响应/用量事件),token
4451
4562
  * 不可知:按「每次估值」计入费用并单独累计 `searchCalls`,不产生 token 维度。
@@ -5077,6 +5188,30 @@ function foldInto(fold, machine, events, subscriptionProviders, officialProvider
5077
5188
  }
5078
5189
  continue;
5079
5190
  }
5191
+ if (event.type === "compaction/summary") {
5192
+ const data = event.data;
5193
+ const compactionUsage = data.usage;
5194
+ if (compactionUsage === void 0) continue;
5195
+ if (typeof data.provider !== "string" || typeof data.model !== "string") continue;
5196
+ const provider = routeAliases[data.provider] ?? data.provider;
5197
+ const modelKey = resolveCatalogKey(data.model);
5198
+ const compactionSubscription = isSubscriptionCall(subscriptionProviders, provider);
5199
+ const siteRef = siteRefOf(provider, routes, { subscription: compactionSubscription });
5200
+ const compactionOfficial = officialChannelOf(provider, siteRef, officialProviderIds);
5201
+ const compactionSiteBucket = siteBucketKey(siteRef);
5202
+ foldModelCall({
5203
+ fold,
5204
+ usage: compactionUsage,
5205
+ modelKey,
5206
+ subscription: compactionSubscription,
5207
+ official: compactionOfficial,
5208
+ siteBucket: compactionSiteBucket,
5209
+ unverifiedChannel: compactionSiteBucket === "unknown",
5210
+ timeMs: event.time,
5211
+ day: dayStamp(event.time)
5212
+ });
5213
+ continue;
5214
+ }
5080
5215
  if (event.type !== "assistant/message") continue;
5081
5216
  const usage = event.data.usage;
5082
5217
  if (usage === void 0) continue;
@@ -5091,28 +5226,17 @@ function foldInto(fold, machine, events, subscriptionProviders, officialProvider
5091
5226
  }
5092
5227
  const modelKey = key;
5093
5228
  const day = dayStamp(event.time);
5094
- const unverifiedChannel = siteBucket === "unknown";
5095
- const priced = !subscription && !unverifiedChannel && isPriced(modelKey);
5096
- if (!subscription && !isPriced(modelKey)) fold.unpricedModels.add(modelKey);
5097
- const entry = modelOf(modelKey);
5098
- const thisCost = priced ? computeCostAt(entry, {
5099
- input: (usage.cacheReadTokens ?? 0) + usage.inputTokens + (usage.cacheWriteTokens ?? 0),
5100
- cacheHit: usage.cacheReadTokens ?? 0,
5101
- cacheMiss: usage.inputTokens + (usage.cacheWriteTokens ?? 0),
5102
- output: usage.outputTokens
5103
- }, event.time) : void 0;
5104
- foldUsage(fold.total, usage, modelKey, subscription, event.time, official, thisCost, unverifiedChannel);
5105
- foldUsage(usageCell(fold.byModel, modelKey), usage, modelKey, subscription, event.time, official, thisCost, unverifiedChannel);
5106
- foldUsage(usageCell(fold.byDay, day), usage, modelKey, subscription, event.time, official, thisCost, unverifiedChannel);
5107
- foldUsage(modelDayCell(fold.byDayModels, day, modelKey), usage, modelKey, subscription, event.time, official, thisCost, unverifiedChannel);
5108
- foldUsage(modelDaySiteCell(fold.byDayModelsSite, day, modelKey, siteBucket), usage, modelKey, subscription, event.time, official, thisCost, unverifiedChannel);
5109
- foldUsage(usageCell(fold.bySite, siteBucket), usage, modelKey, subscription, event.time, official, thisCost, unverifiedChannel);
5110
- if (entry.tierSemantics !== "latency") foldUsage(usageCell(fold.byTier, tierAt(event.time)), usage, modelKey, subscription, event.time, official, thisCost, unverifiedChannel);
5111
- if (subscription) fold.planCalls.set(modelKey, (fold.planCalls.get(modelKey) ?? 0) + 1);
5112
- if (subscription) {
5113
- const sitePlanKey = planSiteKey(day, modelKey, siteBucket);
5114
- fold.planSiteCalls.set(sitePlanKey, (fold.planSiteCalls.get(sitePlanKey) ?? 0) + 1);
5115
- }
5229
+ const { entry, cost: thisCost } = foldModelCall({
5230
+ fold,
5231
+ usage,
5232
+ modelKey,
5233
+ subscription,
5234
+ official,
5235
+ siteBucket,
5236
+ unverifiedChannel: siteBucket === "unknown",
5237
+ timeMs: event.time,
5238
+ day
5239
+ });
5116
5240
  const turn = event.data.turn ?? -1;
5117
5241
  const state = turnState(turns, turn);
5118
5242
  state.model = modelKey;
@@ -5120,17 +5244,7 @@ function foldInto(fold, machine, events, subscriptionProviders, officialProvider
5120
5244
  state.output += usage.outputTokens;
5121
5245
  state.cacheHit += usage.cacheReadTokens ?? 0;
5122
5246
  state.cacheMiss += usage.inputTokens + (usage.cacheWriteTokens ?? 0);
5123
- if (thisCost !== void 0 && entry !== void 0) {
5124
- state.cost += thisCost;
5125
- const outputCost = computeCostAt(entry, {
5126
- input: 0,
5127
- cacheHit: 0,
5128
- cacheMiss: 0,
5129
- output: usage.outputTokens
5130
- }, event.time);
5131
- fold.roles.outputCost += outputCost;
5132
- fold.roles.inputCost += thisCost - outputCost;
5133
- }
5247
+ if (thisCost !== void 0 && entry !== void 0) state.cost += thisCost;
5134
5248
  if (state.startedAt === Number.MAX_SAFE_INTEGER) state.startedAt = event.time;
5135
5249
  const stepNum = event.data.step;
5136
5250
  if (typeof stepNum === "number") {
@@ -5383,7 +5497,7 @@ function createUsageAggregator(persistence, options = {}) {
5383
5497
  ...cwd === void 0 ? {} : { cwd },
5384
5498
  ...subOf === void 0 ? {} : { subOf },
5385
5499
  ...stamp === null ? {} : { stamp },
5386
- foldVersion: 23,
5500
+ foldVersion: 24,
5387
5501
  fingerprint: foldFingerprint,
5388
5502
  foldedAt: Date.now(),
5389
5503
  fold: serializeFold(fold)
@@ -5510,7 +5624,7 @@ function createUsageAggregator(persistence, options = {}) {
5510
5624
  const cwd = meta.cwd;
5511
5625
  const subOf = subParentOf(meta);
5512
5626
  const ledgerRow = ledger.get(id);
5513
- if (ledgerRow !== void 0 && ledgerRow.stamp !== void 0 && stamp !== null && ledgerRow.stamp === stamp && (ledgerRow.foldVersion ?? 1) === 23 && ledgerRow.fingerprint === foldFingerprint && !foldNeedsReprice(ledgerRow.fold)) {
5627
+ if (ledgerRow !== void 0 && ledgerRow.stamp !== void 0 && stamp !== null && ledgerRow.stamp === stamp && (ledgerRow.foldVersion ?? 1) === 24 && ledgerRow.fingerprint === foldFingerprint && !foldNeedsReprice(ledgerRow.fold)) {
5514
5628
  const fold = deserializedFoldOf(ledgerRow.fold);
5515
5629
  folds.push({
5516
5630
  id,
@@ -5639,7 +5753,7 @@ function createUsageAggregator(persistence, options = {}) {
5639
5753
  }
5640
5754
  if (included.has(entry.id)) continue;
5641
5755
  try {
5642
- const stale = (entry.foldVersion ?? 1) < 23 || entry.fingerprint !== foldFingerprint;
5756
+ const stale = (entry.foldVersion ?? 1) < 24 || entry.fingerprint !== foldFingerprint;
5643
5757
  const fold = deserializedFoldOf(entry.fold);
5644
5758
  const hint = titleHints.get(entry.id);
5645
5759
  folds.push({
@@ -7479,6 +7593,7 @@ function buildExtraModels(data) {
7479
7593
  if (input === void 0 || output === void 0) continue;
7480
7594
  const declaredCacheRead = asPrice(cost.cache_read);
7481
7595
  const cacheRead = declaredCacheRead ?? input * .1;
7596
+ const declaredCacheWrite = asPrice(cost.cache_write);
7482
7597
  const name = modelDoc.name;
7483
7598
  const familyValue = modelDoc.family;
7484
7599
  const family = typeof familyValue === "string" && familyValue !== "" ? familyValue : void 0;
@@ -7506,7 +7621,8 @@ function buildExtraModels(data) {
7506
7621
  price: {
7507
7622
  input,
7508
7623
  cacheHit: cacheRead,
7509
- output
7624
+ output,
7625
+ ...declaredCacheWrite !== void 0 ? { cacheWrite: declaredCacheWrite } : {}
7510
7626
  }
7511
7627
  },
7512
7628
  input,
@@ -697,7 +697,7 @@ export declare function mergeUsageLedgerDocuments(document: UsageLedgerDocument,
697
697
  * 会话费用只剩最近一段,issue #29)。
698
698
  * 持久账本行据此区分新旧算法:日志已删/不可读而只能沿用旧行时,UI 标注置信度提示。
699
699
  */
700
- export declare const FOLD_VERSION = 23;
700
+ export declare const FOLD_VERSION = 24;
701
701
  /** 账本里拒读记录的条数上限:防异常环境(大量损坏日志)把账本撑爆;
702
702
  * 超限按 Map 插入序保留前 N 条(最早发现的先留,stamp 失效的自然被清理让位)。 */
703
703
  export declare const LEDGER_REFUSED_CAP = 500;
@@ -4,6 +4,11 @@
4
4
  * (瘦身:lib/client.js 约 -30 KiB)。条目结构与消费逻辑见 ./client/pricing.ts。
5
5
  */
6
6
  import type { ModelEntry } from './client/pricing.ts';
7
+ /**
8
+ * 内置计费目录(导出态):在原始条目上派生缓存写入单价(issue #123),
9
+ * 使「缓存写入」成为独立计价维度——厂商对写入缓存单独计价时(OpenAI/
10
+ * Anthropic/百炼),缓存写入 token 不再按普通输入价估算。
11
+ */
7
12
  export declare const BUILTIN_MODEL_CATALOG: readonly ModelEntry[];
8
13
  /**
9
14
  * 真实 provider model id → 计费目录键(`MODEL_CATALOG[].key`)的映射。未知 id
@@ -210,6 +210,8 @@ export interface UsageStats {
210
210
  output: number;
211
211
  cacheHit: number;
212
212
  cacheMiss: number;
213
+ /** 显式缓存写入(cacheMiss 子集,部分厂商单独报告);issue #123 起按其单价计价。 */
214
+ cacheWrite?: number;
213
215
  cost: number;
214
216
  reasoning: number;
215
217
  /** Billed through a subscription plan (no per-token cost). */
@@ -225,6 +227,8 @@ export interface UsageStats {
225
227
  output: number;
226
228
  cacheHit: number;
227
229
  cacheMiss: number;
230
+ /** 显式缓存写入(cacheMiss 子集);issue #123 起按其单价计价。 */
231
+ cacheWrite?: number;
228
232
  cost: number;
229
233
  reasoning: number;
230
234
  }>;
@@ -235,6 +239,8 @@ export interface UsageStats {
235
239
  output: number;
236
240
  cacheHit: number;
237
241
  cacheMiss: number;
242
+ /** 显式缓存写入(cacheMiss 子集);issue #123 起按其单价计价。 */
243
+ cacheWrite?: number;
238
244
  cost: number;
239
245
  }>>;
240
246
  /** 模型 × 日期 × 站点 三维统计([date][modelKey][siteKey]):按 origin 绑定自定义价的
@@ -245,6 +251,8 @@ export interface UsageStats {
245
251
  output: number;
246
252
  cacheHit: number;
247
253
  cacheMiss: number;
254
+ /** 显式缓存写入(cacheMiss 子集);issue #123 起按其单价计价。 */
255
+ cacheWrite?: number;
248
256
  cost: number;
249
257
  /** 该格全部调用都走订阅通道(聚合侧按三维格置位);旧快照缺失,回退全局口径。 */
250
258
  plan?: boolean;
@@ -252,6 +252,12 @@ export interface TokenUsageBuckets {
252
252
  cacheHit: number;
253
253
  /** Cache-miss input tokens (already included in `input` by some providers). */
254
254
  cacheMiss: number;
255
+ /**
256
+ * 显式缓存写入 token(issue #123):**已包含在 `cacheMiss` 内**的子集——
257
+ * 厂商对「写入缓存」单独计价时(OpenAI/Anthropic 恒为输入价 125%),
258
+ * 这部分按缓存写入价计,不再按普通输入价。
259
+ */
260
+ cacheWrite?: number;
255
261
  /** Output tokens. */
256
262
  output: number;
257
263
  }
@@ -263,6 +269,13 @@ export interface PriceBand {
263
269
  cacheHit: number;
264
270
  /** Cache-miss input price per 1M tokens (absent when folded into `input`). */
265
271
  cacheMiss?: number;
272
+ /**
273
+ * 缓存写入单价(每百万 token,issue #123):厂商对「把内容写入缓存」单独
274
+ * 计价时给出(models.dev 原生 `cache_write`:OpenAI/Anthropic 恒为输入价
275
+ * 125%)。**缺省 = 按 `input` 价计**——厂商不单列缓存写入费时(如 DeepSeek、
276
+ * 月之暗面)缓存写入本就按输入价出账,与旧口径一致。
277
+ */
278
+ cacheWrite?: number;
266
279
  /** Output price per 1M tokens. */
267
280
  output: number;
268
281
  }
@@ -293,7 +306,7 @@ export interface PricePromo {
293
306
  * 缓存 0.8 / 输入 0.8 / 输出 2/3)。缺省档位沿用 {@link factor};单档取值
294
307
  * 仅 [0,1) 区间有效(0 = 该档活动期免费),非法值回落 factor。
295
308
  */
296
- factors?: Partial<Record<'input' | 'cacheHit' | 'cacheMiss' | 'output', number>>;
309
+ factors?: Partial<Record<'input' | 'cacheHit' | 'cacheMiss' | 'cacheWrite' | 'output', number>>;
297
310
  /**
298
311
  * 截止时刻(epoch ms):该时刻及之后恢复刊例价。缺省表示厂商未公布截止日
299
312
  * 的长期活动(如「限时 5 折直至另行通知」),持续生效直至收到公告后补填。
@@ -12,6 +12,12 @@ export interface LivePrice {
12
12
  cacheHit: number;
13
13
  /** Output price per 1M tokens. */
14
14
  output: number;
15
+ /**
16
+ * 缓存写入单价(每百万 token,issue #123):厂商对「写入缓存」单独计价时给出
17
+ * (models.dev 原生 `cache_write`)。**缺省 = 按 `input` 价计**——上游未声明
18
+ * 时不猜(与 `cacheHit` 的声明优先口径一致)。
19
+ */
20
+ cacheWrite?: number;
15
21
  }
16
22
  /** Response of `/api/billing/pricing` consumed by the dashboard. */
17
23
  export interface LivePricing {
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.8.4",
4
+ "version": "1.8.5",
5
5
  "keywords": [
6
6
  "deepseek-harness",
7
7
  "deepseek",
@@ -88,7 +88,8 @@
88
88
  "0.2.2-alpha.2": "compatible",
89
89
  "0.2.2-alpha.3": "compatible",
90
90
  "0.2.2-rc.1": "compatible",
91
- "0.2.2-rc.2": "compatible"
91
+ "0.2.2-rc.2": "compatible",
92
+ "0.2.2-rc.3": "compatible"
92
93
  }
93
94
  }
94
95
  },
@@ -141,64 +142,64 @@
141
142
  "@deepseek-ai/cordis-plugin-group": "1.1.0",
142
143
  "@deepseek-ai/cordis-plugin-include": "1.1.0",
143
144
  "@deepseek-ai/cordis-plugin-loader": "1.1.0",
144
- "@deepseek-ai/dsh-agent": "0.2.2-rc.2",
145
- "@deepseek-ai/dsh-agent-default-model": "0.2.2-rc.2",
146
- "@deepseek-ai/dsh-agent-preset-registry": "0.2.2-rc.2",
147
- "@deepseek-ai/dsh-api-gateway": "0.2.2-rc.2",
148
- "@deepseek-ai/dsh-api-remotes": "0.2.2-rc.2",
149
- "@deepseek-ai/dsh-api-session-controller": "0.2.2-rc.2",
150
- "@deepseek-ai/dsh-app-boot": "0.2.2-rc.2",
151
- "@deepseek-ai/dsh-atomic-write": "0.2.2-rc.2",
152
- "@deepseek-ai/dsh-attachment": "0.2.2-rc.2",
153
- "@deepseek-ai/dsh-client-connection": "0.2.2-rc.2",
154
- "@deepseek-ai/dsh-client-file-upload": "0.2.2-rc.2",
155
- "@deepseek-ai/dsh-client-locale": "0.2.2-rc.2",
156
- "@deepseek-ai/dsh-client-store": "0.2.2-rc.2",
157
- "@deepseek-ai/dsh-client-ui-commands": "0.2.2-rc.2",
158
- "@deepseek-ai/dsh-client-ui-conversation": "0.2.2-rc.2",
159
- "@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.2",
160
- "@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.2",
161
- "@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.2",
162
- "@deepseek-ai/dsh-client-ui-sidebar": "0.2.2-rc.2",
163
- "@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.2",
164
- "@deepseek-ai/dsh-client-ui-workspace": "0.2.2-rc.2",
165
- "@deepseek-ai/dsh-commands": "0.2.2-rc.2",
166
- "@deepseek-ai/dsh-compaction": "0.2.2-rc.2",
167
- "@deepseek-ai/dsh-credentials": "0.2.2-rc.2",
168
- "@deepseek-ai/dsh-error": "0.2.2-rc.2",
169
- "@deepseek-ai/dsh-file-reference": "0.2.2-rc.2",
170
- "@deepseek-ai/dsh-fs": "0.2.2-rc.2",
171
- "@deepseek-ai/dsh-home-paths": "0.2.2-rc.2",
172
- "@deepseek-ai/dsh-host-webserver": "0.2.2-rc.2",
145
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.3",
146
+ "@deepseek-ai/dsh-agent-default-model": "0.2.2-rc.3",
147
+ "@deepseek-ai/dsh-agent-preset-registry": "0.2.2-rc.3",
148
+ "@deepseek-ai/dsh-api-gateway": "0.2.2-rc.3",
149
+ "@deepseek-ai/dsh-api-remotes": "0.2.2-rc.3",
150
+ "@deepseek-ai/dsh-api-session-controller": "0.2.2-rc.3",
151
+ "@deepseek-ai/dsh-app-boot": "0.2.2-rc.3",
152
+ "@deepseek-ai/dsh-atomic-write": "0.2.2-rc.3",
153
+ "@deepseek-ai/dsh-attachment": "0.2.2-rc.3",
154
+ "@deepseek-ai/dsh-client-connection": "0.2.2-rc.3",
155
+ "@deepseek-ai/dsh-client-file-upload": "0.2.2-rc.3",
156
+ "@deepseek-ai/dsh-client-locale": "0.2.2-rc.3",
157
+ "@deepseek-ai/dsh-client-store": "0.2.2-rc.3",
158
+ "@deepseek-ai/dsh-client-ui-commands": "0.2.2-rc.3",
159
+ "@deepseek-ai/dsh-client-ui-conversation": "0.2.2-rc.3",
160
+ "@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.3",
161
+ "@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.3",
162
+ "@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.3",
163
+ "@deepseek-ai/dsh-client-ui-sidebar": "0.2.2-rc.3",
164
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.3",
165
+ "@deepseek-ai/dsh-client-ui-workspace": "0.2.2-rc.3",
166
+ "@deepseek-ai/dsh-commands": "0.2.2-rc.3",
167
+ "@deepseek-ai/dsh-compaction": "0.2.2-rc.3",
168
+ "@deepseek-ai/dsh-credentials": "0.2.2-rc.3",
169
+ "@deepseek-ai/dsh-error": "0.2.2-rc.3",
170
+ "@deepseek-ai/dsh-file-reference": "0.2.2-rc.3",
171
+ "@deepseek-ai/dsh-fs": "0.2.2-rc.3",
172
+ "@deepseek-ai/dsh-home-paths": "0.2.2-rc.3",
173
+ "@deepseek-ai/dsh-host-webserver": "0.2.2-rc.3",
173
174
  "@deepseek-ai/dsh-invariants": "0.2.0-rc.2",
174
- "@deepseek-ai/dsh-launch-environment": "0.2.2-rc.2",
175
- "@deepseek-ai/dsh-llm": "0.2.2-rc.2",
176
- "@deepseek-ai/dsh-native-command": "0.2.2-rc.2",
177
- "@deepseek-ai/dsh-ptc-runtime": "0.2.2-rc.2",
178
- "@deepseek-ai/dsh-sandbox": "0.2.2-rc.2",
179
- "@deepseek-ai/dsh-sandbox-policy": "0.2.2-rc.2",
180
- "@deepseek-ai/dsh-scope": "0.2.2-rc.2",
181
- "@deepseek-ai/dsh-session": "0.2.2-rc.2",
182
- "@deepseek-ai/dsh-session-persistence": "0.2.2-rc.2",
183
- "@deepseek-ai/dsh-session-projection": "0.2.2-rc.2",
184
- "@deepseek-ai/dsh-session-query": "0.2.2-rc.2",
185
- "@deepseek-ai/dsh-session-title": "0.2.2-rc.2",
186
- "@deepseek-ai/dsh-settings": "0.2.2-rc.2",
187
- "@deepseek-ai/dsh-skill": "0.2.2-rc.2",
188
- "@deepseek-ai/dsh-storage": "0.2.2-rc.2",
189
- "@deepseek-ai/dsh-storage-domain": "0.2.2-rc.2",
190
- "@deepseek-ai/dsh-subagent": "0.2.2-rc.2",
191
- "@deepseek-ai/dsh-system-prompt": "0.2.2-rc.2",
192
- "@deepseek-ai/dsh-tool-todo": "0.2.2-rc.2",
193
- "@deepseek-ai/dsh-tools": "0.2.2-rc.2",
194
- "@deepseek-ai/dsh-typert-protocol": "0.2.2-rc.2",
195
- "@deepseek-ai/dsh-typert-registry": "0.2.2-rc.2",
196
- "@deepseek-ai/dsh-user-approval": "0.2.2-rc.2",
197
- "@deepseek-ai/dsh-util-code-language": "0.2.2-rc.2",
198
- "@deepseek-ai/dsh-util-time": "0.2.2-rc.2",
199
- "@deepseek-ai/dsh-util-workspace-path": "0.2.2-rc.2",
200
- "@deepseek-ai/dsh-working-directory": "0.2.2-rc.2",
201
- "@deepseek-ai/dsh-workspace": "0.2.2-rc.2",
175
+ "@deepseek-ai/dsh-launch-environment": "0.2.2-rc.3",
176
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.3",
177
+ "@deepseek-ai/dsh-native-command": "0.2.2-rc.3",
178
+ "@deepseek-ai/dsh-ptc-runtime": "0.2.2-rc.3",
179
+ "@deepseek-ai/dsh-sandbox": "0.2.2-rc.3",
180
+ "@deepseek-ai/dsh-sandbox-policy": "0.2.2-rc.3",
181
+ "@deepseek-ai/dsh-scope": "0.2.2-rc.3",
182
+ "@deepseek-ai/dsh-session": "0.2.2-rc.3",
183
+ "@deepseek-ai/dsh-session-persistence": "0.2.2-rc.3",
184
+ "@deepseek-ai/dsh-session-projection": "0.2.2-rc.3",
185
+ "@deepseek-ai/dsh-session-query": "0.2.2-rc.3",
186
+ "@deepseek-ai/dsh-session-title": "0.2.2-rc.3",
187
+ "@deepseek-ai/dsh-settings": "0.2.2-rc.3",
188
+ "@deepseek-ai/dsh-skill": "0.2.2-rc.3",
189
+ "@deepseek-ai/dsh-storage": "0.2.2-rc.3",
190
+ "@deepseek-ai/dsh-storage-domain": "0.2.2-rc.3",
191
+ "@deepseek-ai/dsh-subagent": "0.2.2-rc.3",
192
+ "@deepseek-ai/dsh-system-prompt": "0.2.2-rc.3",
193
+ "@deepseek-ai/dsh-tool-todo": "0.2.2-rc.3",
194
+ "@deepseek-ai/dsh-tools": "0.2.2-rc.3",
195
+ "@deepseek-ai/dsh-typert-protocol": "0.2.2-rc.3",
196
+ "@deepseek-ai/dsh-typert-registry": "0.2.2-rc.3",
197
+ "@deepseek-ai/dsh-user-approval": "0.2.2-rc.3",
198
+ "@deepseek-ai/dsh-util-code-language": "0.2.2-rc.3",
199
+ "@deepseek-ai/dsh-util-time": "0.2.2-rc.3",
200
+ "@deepseek-ai/dsh-util-workspace-path": "0.2.2-rc.3",
201
+ "@deepseek-ai/dsh-working-directory": "0.2.2-rc.3",
202
+ "@deepseek-ai/dsh-workspace": "0.2.2-rc.3",
202
203
  "@deepseek-ai/schemastery": "3.19.0",
203
204
  "@playwright/test": "^1.64.1",
204
205
  "@shikijs/langs": "^4.3.1",