@kenz1117/dsh-ui-usage-billing 1.8.4 → 1.8.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/lib/index.js CHANGED
@@ -529,8 +529,16 @@ function extraModelByKey() {
529
529
  * - 剥离组织前缀(`deepseek/deepseek-v4-flash` → `deepseek-v4-flash`);
530
530
  * - 剥离尾部纯数字段(`deepseek-v4-flash-202605` / `-0731` → `deepseek-v4-flash`,
531
531
  * 覆盖 TokenHub / 官方按日期滚动的快照 id);
532
+ * - 剥离冒号分段:中转站路由前缀(`cn:deepseek-v4.1-flash` → `deepseek-v4.1-flash`)与
533
+ * 变体后缀(`deepseek-v4.1-flash:fast` → `deepseek-v4.1-flash`)——中转站
534
+ * 常按线路给模型加前缀(cn:/us:),网关常加变体后缀(:free / :1017),
535
+ * 这些形态此前一律落「未收录」记 0(issue #125);
532
536
  * - 两者组合派生。目录键本身(如 `mistral-large-2512`、`command-a-03-2025`)
533
537
  * 在直接查就已命中,永不进入派生分支,不受剥段影响。
538
+ *
539
+ * 口径纪律:候选必须**原样**命中目录键(精确别名或归一化索引)才算数——剥段
540
+ * 只是找同一模型的另一种写法,不做「相近即认」的模糊猜测;剥完仍未命中就
541
+ * 保持原 id(回退 other,不计费)。
534
542
  */
535
543
  function derivedKeyCandidates(id) {
536
544
  const out = [];
@@ -552,6 +560,19 @@ function derivedKeyCandidates(id) {
552
560
  push(bare);
553
561
  stripTrailingDigits(bare);
554
562
  }
563
+ const segments = id.split(/[::]/u);
564
+ if (segments.length > 1) {
565
+ for (let i = 1; i < segments.length; i += 1) {
566
+ const tail = segments.slice(i).join(":");
567
+ push(tail);
568
+ stripTrailingDigits(tail);
569
+ }
570
+ for (let i = 0; i < segments.length - 1; i += 1) {
571
+ const head = segments.slice(i, segments.length - 1).join(":");
572
+ push(head);
573
+ stripTrailingDigits(head);
574
+ }
575
+ }
555
576
  stripTrailingDigits(id);
556
577
  return out;
557
578
  }
@@ -604,13 +625,15 @@ function modelOf(key) {
604
625
  const live = livePriceOf(resolved);
605
626
  if (live === void 0) return base;
606
627
  if (base.price.offPeak !== void 0) return base;
628
+ const cacheWrite = base.price.cacheWrite !== void 0 && base.price.input > 0 ? live.input * (base.price.cacheWrite / base.price.input) : void 0;
607
629
  return {
608
630
  ...base,
609
631
  price: {
610
632
  currency: "USD",
611
633
  input: live.input,
612
634
  cacheHit: live.cacheHit,
613
- output: live.output
635
+ output: live.output,
636
+ ...cacheWrite !== void 0 ? { cacheWrite } : {}
614
637
  }
615
638
  };
616
639
  }
@@ -625,7 +648,8 @@ function extraEntryOf(extra) {
625
648
  currency: "USD",
626
649
  input: extra.price.input,
627
650
  cacheHit: extra.price.cacheHit,
628
- output: extra.price.output
651
+ output: extra.price.output,
652
+ ...extra.price.cacheWrite !== void 0 ? { cacheWrite: extra.price.cacheWrite } : {}
629
653
  }
630
654
  };
631
655
  }
@@ -671,6 +695,7 @@ function applyPromo(entry, nowMs) {
671
695
  input: band.input * factorOf("input"),
672
696
  cacheHit: band.cacheHit * factorOf("cacheHit"),
673
697
  ...band.cacheMiss !== void 0 ? { cacheMiss: band.cacheMiss * factorOf("cacheMiss") } : {},
698
+ ...band.cacheWrite !== void 0 ? { cacheWrite: band.cacheWrite * factorOf("cacheWrite") } : {},
674
699
  output: band.output * factorOf("output")
675
700
  });
676
701
  return {
@@ -689,11 +714,18 @@ function applyPromo(entry, nowMs) {
689
714
  * Providers that report only disjoint buckets carry `cacheMiss` explicitly;
690
715
  * otherwise the miss share is derived as `input - cacheHit`. Only USD-priced
691
716
  * bands go through the exchange rate.
717
+ *
718
+ * 缓存写入单列(issue #123):`cacheWrite` 是 `cacheMiss` 的子集,厂商对它
719
+ * 单独计价(`band.cacheWrite`,缺省按输入价)。拆分后普通未命中按
720
+ * `band.cacheMiss ?? band.input`、缓存写入按 `band.cacheWrite ?? band.input`
721
+ * ——`cacheWrite` 缺省时两者同价,与旧口径逐字一致。
692
722
  */
693
723
  function priceBandCost(band, buckets, currency) {
694
- const miss = buckets.cacheMiss > 0 ? buckets.cacheMiss : Math.max(0, buckets.input - buckets.cacheHit);
724
+ const missTotal = buckets.cacheMiss > 0 ? buckets.cacheMiss : Math.max(0, buckets.input - buckets.cacheHit);
725
+ const write = Math.min(buckets.cacheWrite ?? 0, missTotal);
726
+ const miss = missTotal - write;
695
727
  const hit = Math.min(buckets.cacheHit, buckets.input);
696
- const raw = (miss * (band.cacheMiss ?? band.input) + hit * band.cacheHit + buckets.output * band.output) / 1e6;
728
+ const raw = (miss * (band.cacheMiss ?? band.input) + write * (band.cacheWrite ?? band.input) + hit * band.cacheHit + buckets.output * band.output) / 1e6;
697
729
  return currency === "USD" ? raw * currentRate() : raw;
698
730
  }
699
731
  /**
@@ -819,6 +851,56 @@ function formatTokens(value) {
819
851
  /** DeepSeek 官方高峰时段说明(峰谷分时计费目录条目共用)。 */
820
852
  const DEEPSEEK_PEAK_HOURS = "09:00-12:00 / 14:00-18:00";
821
853
  const GEMINI_PEAK_HOURS = "Standard / Flex";
854
+ /**
855
+ * 厂商「缓存写入」加价系数(issue #123):厂商对「把内容写入缓存」按输入价的
856
+ * 倍数单独计费,models.dev 原生字段 `cache_write` 即该倍率。
857
+ * 2026-11-14 核对 models.dev 实时目录:OpenAI 11/11 恒为 125%、Anthropic 18/18
858
+ * 恒为 125%、百炼(阿里通义)约 125%(`qwen3.8-flash` 例外 156%)。
859
+ * 未列的厂商不落数值 → 缓存写入按输入价计(DeepSeek、月之暗面等本就不单列
860
+ * 缓存写入费,与旧口径逐字一致;MiniMax 高速档倍率不恒定,故不给规则)。
861
+ */
862
+ const CACHE_WRITE_FACTORS = {
863
+ "OpenAI": 1.25,
864
+ "Anthropic": 1.25,
865
+ "阿里通义": 1.25
866
+ };
867
+ /** 条目内官方「显式缓存创建」价(extraRows 行标签)——厂商公布的缓存写入单价。 */
868
+ const CACHE_WRITE_ROW_LABEL = "显式缓存创建";
869
+ /** 单价取整到 6 位小数:消除浮点乘法的尾数噪声(0.3 × 1.25 = 0.375 而非 0.37499…)。 */
870
+ function roundUnitPrice(value) {
871
+ return Number(value.toFixed(6));
872
+ }
873
+ /**
874
+ * 给目录条目补出缓存写入单价(issue #123):条目自带官方「显式缓存创建」价时
875
+ * 以官方值为准(百炼各档比例不恒定),否则按厂商加价系数从输入价派生;
876
+ * 两者皆无 → 不落该字段,计价回退按输入价(与旧口径一致)。
877
+ * 只动主档:分时计价(offPeak)目前只有 DeepSeek,其缓存写入本就按输入价。
878
+ */
879
+ function withCacheWritePrice(entry) {
880
+ if (entry.price.cacheWrite !== void 0) return entry;
881
+ const official = entry.extraRows?.find((row) => row.label === CACHE_WRITE_ROW_LABEL)?.input;
882
+ if (official !== void 0 && official > 0) return {
883
+ ...entry,
884
+ price: {
885
+ ...entry.price,
886
+ cacheWrite: official
887
+ }
888
+ };
889
+ const factor = CACHE_WRITE_FACTORS[entry.provider];
890
+ if (factor === void 0 || !(entry.price.input > 0)) return entry;
891
+ return {
892
+ ...entry,
893
+ price: {
894
+ ...entry.price,
895
+ cacheWrite: roundUnitPrice(entry.price.input * factor)
896
+ }
897
+ };
898
+ }
899
+ /**
900
+ * 内置计费目录(导出态):在原始条目上派生缓存写入单价(issue #123),
901
+ * 使「缓存写入」成为独立计价维度——厂商对写入缓存单独计价时(OpenAI/
902
+ * Anthropic/百炼),缓存写入 token 不再按普通输入价估算。
903
+ */
822
904
  const BUILTIN_MODEL_CATALOG = [
823
905
  {
824
906
  key: "flash",
@@ -4024,7 +4106,7 @@ const BUILTIN_MODEL_CATALOG = [
4024
4106
  output: 0
4025
4107
  }
4026
4108
  }
4027
- ];
4109
+ ].map(withCacheWritePrice);
4028
4110
  /**
4029
4111
  * 真实 provider model id → 计费目录键(`MODEL_CATALOG[].key`)的映射。未知 id
4030
4112
  * 原样保留并落回 `other`(未知模型不估算费用)。聚合层(aggregate.ts)在折叠时
@@ -4055,6 +4137,7 @@ const BUILTIN_MODEL_KEY_ALIASES = {
4055
4137
  "deepseek-v4-flash": "flash",
4056
4138
  "deepseek-v4-flash-vision-exp": "flash-vision-exp",
4057
4139
  "deepseek-v4.1-flash": "flash",
4140
+ "deepseek-v4.1": "flash",
4058
4141
  "deepseek-v4.1-flash-expires-on-0910": "flash",
4059
4142
  "deepseek-flash": "flash",
4060
4143
  "deepseek-v4.1-flash-1017": "flash",
@@ -4420,14 +4503,15 @@ function emptyUsage() {
4420
4503
  */
4421
4504
  function foldUsage(acc, usage, key, subscription, timeMs, official = false, pricedCost, unverifiedChannel = false) {
4422
4505
  const cacheHit = usage.cacheReadTokens ?? 0;
4423
- const cacheMiss = usage.inputTokens + (usage.cacheWriteTokens ?? 0);
4506
+ const cacheWrite = usage.cacheWriteTokens ?? 0;
4507
+ const cacheMiss = usage.inputTokens + cacheWrite;
4424
4508
  acc.calls += 1;
4425
- acc.input += usage.inputTokens + cacheHit + (usage.cacheWriteTokens ?? 0);
4509
+ acc.input += usage.inputTokens + cacheHit + cacheWrite;
4426
4510
  acc.output += usage.outputTokens;
4427
4511
  acc.reasoning += usage.reasoningTokens ?? 0;
4428
4512
  acc.cacheHit += cacheHit;
4429
4513
  acc.cacheMiss += cacheMiss;
4430
- if ((usage.cacheWriteTokens ?? 0) > 0) acc.cacheWrite = (acc.cacheWrite ?? 0) + (usage.cacheWriteTokens ?? 0);
4514
+ if (cacheWrite > 0) acc.cacheWrite = (acc.cacheWrite ?? 0) + cacheWrite;
4431
4515
  if (official) acc.officialCalls += 1;
4432
4516
  if (pricedCost !== void 0) {
4433
4517
  acc.cost += pricedCost;
@@ -4439,6 +4523,7 @@ function foldUsage(acc, usage, key, subscription, timeMs, official = false, pric
4439
4523
  input: cacheHit + cacheMiss,
4440
4524
  cacheHit,
4441
4525
  cacheMiss,
4526
+ cacheWrite,
4442
4527
  output: usage.outputTokens
4443
4528
  }, timeMs);
4444
4529
  acc.cost += thisCost;
@@ -4446,6 +4531,54 @@ function foldUsage(acc, usage, key, subscription, timeMs, official = false, pric
4446
4531
  }
4447
4532
  }
4448
4533
  /**
4534
+ * 折叠一次模型调用:token 分桶 + 计价 + 订阅/官方标记 + 角色归因。
4535
+ *
4536
+ * `assistant/message`(对话主循环)与 `compaction/summary`(上下文压缩摘要,
4537
+ * issue #123)都是真实的模型调用——后者是宿主落盘的压缩摘要事件,自带
4538
+ * `provider`/`model`/`usage`,此前整段被跳过,压缩调用的次数与费用零计入。
4539
+ * 两者共用本函数,保证计费口径逐字一致。
4540
+ * @returns 本次调用的目录条目与费用(未计价时为 undefined)。
4541
+ */
4542
+ function foldModelCall(ctx) {
4543
+ const { fold, usage, modelKey, subscription, official, siteBucket, unverifiedChannel, timeMs, day } = ctx;
4544
+ const priced = !subscription && !unverifiedChannel && isPriced(modelKey);
4545
+ if (!subscription && !isPriced(modelKey)) fold.unpricedModels.add(modelKey);
4546
+ const entry = modelOf(modelKey);
4547
+ const thisCost = priced ? computeCostAt(entry, {
4548
+ input: (usage.cacheReadTokens ?? 0) + usage.inputTokens + (usage.cacheWriteTokens ?? 0),
4549
+ cacheHit: usage.cacheReadTokens ?? 0,
4550
+ cacheMiss: usage.inputTokens + (usage.cacheWriteTokens ?? 0),
4551
+ cacheWrite: usage.cacheWriteTokens ?? 0,
4552
+ output: usage.outputTokens
4553
+ }, timeMs) : void 0;
4554
+ foldUsage(fold.total, usage, modelKey, subscription, timeMs, official, thisCost, unverifiedChannel);
4555
+ foldUsage(usageCell(fold.byModel, modelKey), usage, modelKey, subscription, timeMs, official, thisCost, unverifiedChannel);
4556
+ foldUsage(usageCell(fold.byDay, day), usage, modelKey, subscription, timeMs, official, thisCost, unverifiedChannel);
4557
+ foldUsage(modelDayCell(fold.byDayModels, day, modelKey), usage, modelKey, subscription, timeMs, official, thisCost, unverifiedChannel);
4558
+ foldUsage(modelDaySiteCell(fold.byDayModelsSite, day, modelKey, siteBucket), usage, modelKey, subscription, timeMs, official, thisCost, unverifiedChannel);
4559
+ foldUsage(usageCell(fold.bySite, siteBucket), usage, modelKey, subscription, timeMs, official, thisCost, unverifiedChannel);
4560
+ if (entry.tierSemantics !== "latency") foldUsage(usageCell(fold.byTier, tierAt(timeMs)), usage, modelKey, subscription, timeMs, official, thisCost, unverifiedChannel);
4561
+ if (subscription) fold.planCalls.set(modelKey, (fold.planCalls.get(modelKey) ?? 0) + 1);
4562
+ if (subscription) {
4563
+ const sitePlanKey = planSiteKey(day, modelKey, siteBucket);
4564
+ fold.planSiteCalls.set(sitePlanKey, (fold.planSiteCalls.get(sitePlanKey) ?? 0) + 1);
4565
+ }
4566
+ if (thisCost !== void 0 && entry !== void 0) {
4567
+ const outputCost = computeCostAt(entry, {
4568
+ input: 0,
4569
+ cacheHit: 0,
4570
+ cacheMiss: 0,
4571
+ output: usage.outputTokens
4572
+ }, timeMs);
4573
+ fold.roles.outputCost += outputCost;
4574
+ fold.roles.inputCost += thisCost - outputCost;
4575
+ }
4576
+ return {
4577
+ entry,
4578
+ cost: thisCost
4579
+ };
4580
+ }
4581
+ /**
4449
4582
  * Fold one auxiliary web-search LLM request (issue #15) into an accumulator.
4450
4583
  * 这类调用绕过对话通道直连官方端点,日志只记请求(无响应/用量事件),token
4451
4584
  * 不可知:按「每次估值」计入费用并单独累计 `searchCalls`,不产生 token 维度。
@@ -5077,6 +5210,30 @@ function foldInto(fold, machine, events, subscriptionProviders, officialProvider
5077
5210
  }
5078
5211
  continue;
5079
5212
  }
5213
+ if (event.type === "compaction/summary") {
5214
+ const data = event.data;
5215
+ const compactionUsage = data.usage;
5216
+ if (compactionUsage === void 0) continue;
5217
+ if (typeof data.provider !== "string" || typeof data.model !== "string") continue;
5218
+ const provider = routeAliases[data.provider] ?? data.provider;
5219
+ const modelKey = resolveCatalogKey(data.model);
5220
+ const compactionSubscription = isSubscriptionCall(subscriptionProviders, provider);
5221
+ const siteRef = siteRefOf(provider, routes, { subscription: compactionSubscription });
5222
+ const compactionOfficial = officialChannelOf(provider, siteRef, officialProviderIds);
5223
+ const compactionSiteBucket = siteBucketKey(siteRef);
5224
+ foldModelCall({
5225
+ fold,
5226
+ usage: compactionUsage,
5227
+ modelKey,
5228
+ subscription: compactionSubscription,
5229
+ official: compactionOfficial,
5230
+ siteBucket: compactionSiteBucket,
5231
+ unverifiedChannel: compactionSiteBucket === "unknown",
5232
+ timeMs: event.time,
5233
+ day: dayStamp(event.time)
5234
+ });
5235
+ continue;
5236
+ }
5080
5237
  if (event.type !== "assistant/message") continue;
5081
5238
  const usage = event.data.usage;
5082
5239
  if (usage === void 0) continue;
@@ -5091,28 +5248,17 @@ function foldInto(fold, machine, events, subscriptionProviders, officialProvider
5091
5248
  }
5092
5249
  const modelKey = key;
5093
5250
  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
- }
5251
+ const { entry, cost: thisCost } = foldModelCall({
5252
+ fold,
5253
+ usage,
5254
+ modelKey,
5255
+ subscription,
5256
+ official,
5257
+ siteBucket,
5258
+ unverifiedChannel: siteBucket === "unknown",
5259
+ timeMs: event.time,
5260
+ day
5261
+ });
5116
5262
  const turn = event.data.turn ?? -1;
5117
5263
  const state = turnState(turns, turn);
5118
5264
  state.model = modelKey;
@@ -5120,17 +5266,7 @@ function foldInto(fold, machine, events, subscriptionProviders, officialProvider
5120
5266
  state.output += usage.outputTokens;
5121
5267
  state.cacheHit += usage.cacheReadTokens ?? 0;
5122
5268
  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
- }
5269
+ if (thisCost !== void 0 && entry !== void 0) state.cost += thisCost;
5134
5270
  if (state.startedAt === Number.MAX_SAFE_INTEGER) state.startedAt = event.time;
5135
5271
  const stepNum = event.data.step;
5136
5272
  if (typeof stepNum === "number") {
@@ -5383,7 +5519,7 @@ function createUsageAggregator(persistence, options = {}) {
5383
5519
  ...cwd === void 0 ? {} : { cwd },
5384
5520
  ...subOf === void 0 ? {} : { subOf },
5385
5521
  ...stamp === null ? {} : { stamp },
5386
- foldVersion: 23,
5522
+ foldVersion: 24,
5387
5523
  fingerprint: foldFingerprint,
5388
5524
  foldedAt: Date.now(),
5389
5525
  fold: serializeFold(fold)
@@ -5510,7 +5646,7 @@ function createUsageAggregator(persistence, options = {}) {
5510
5646
  const cwd = meta.cwd;
5511
5647
  const subOf = subParentOf(meta);
5512
5648
  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)) {
5649
+ if (ledgerRow !== void 0 && ledgerRow.stamp !== void 0 && stamp !== null && ledgerRow.stamp === stamp && (ledgerRow.foldVersion ?? 1) === 24 && ledgerRow.fingerprint === foldFingerprint && !foldNeedsReprice(ledgerRow.fold)) {
5514
5650
  const fold = deserializedFoldOf(ledgerRow.fold);
5515
5651
  folds.push({
5516
5652
  id,
@@ -5639,7 +5775,7 @@ function createUsageAggregator(persistence, options = {}) {
5639
5775
  }
5640
5776
  if (included.has(entry.id)) continue;
5641
5777
  try {
5642
- const stale = (entry.foldVersion ?? 1) < 23 || entry.fingerprint !== foldFingerprint;
5778
+ const stale = (entry.foldVersion ?? 1) < 24 || entry.fingerprint !== foldFingerprint;
5643
5779
  const fold = deserializedFoldOf(entry.fold);
5644
5780
  const hint = titleHints.get(entry.id);
5645
5781
  folds.push({
@@ -7479,6 +7615,7 @@ function buildExtraModels(data) {
7479
7615
  if (input === void 0 || output === void 0) continue;
7480
7616
  const declaredCacheRead = asPrice(cost.cache_read);
7481
7617
  const cacheRead = declaredCacheRead ?? input * .1;
7618
+ const declaredCacheWrite = asPrice(cost.cache_write);
7482
7619
  const name = modelDoc.name;
7483
7620
  const familyValue = modelDoc.family;
7484
7621
  const family = typeof familyValue === "string" && familyValue !== "" ? familyValue : void 0;
@@ -7506,7 +7643,8 @@ function buildExtraModels(data) {
7506
7643
  price: {
7507
7644
  input,
7508
7645
  cacheHit: cacheRead,
7509
- output
7646
+ output,
7647
+ ...declaredCacheWrite !== void 0 ? { cacheWrite: declaredCacheWrite } : {}
7510
7648
  }
7511
7649
  },
7512
7650
  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
@@ -15,6 +15,15 @@ export declare const STATS_REFRESH_INTERVAL_MS = 30000;
15
15
  /** 弹窗关闭后的统计刷新间隔(毫秒):侧栏触发器只需大致最新值,降到 5 分钟
16
16
  * 省宿主聚合(每轮都是折叠 + 五个端点的串行响应)。 */
17
17
  export declare const STATS_REFRESH_CLOSED_MS = 300000;
18
+ /**
19
+ * 插件自有 DOM 根容器标记(issue #124):动效压制规则只在本插件根容器内生效。
20
+ *
21
+ * 此前「动效强度」开关把 data-motion 写在 <html> 上,配 `*` 通配符 + !important,
22
+ * 会把宿主与第三方插件的全部动画一起压平(报告者实测右键菜单动画消失)。改为
23
+ * 给每个自有根容器挂这个类,压制规则收进根容器内,宿主与其他插件不受影响。
24
+ * 新增挂载点时记得一并打标——漏标只会让该处动画不再被压制,不会外溢。
25
+ */
26
+ export declare const BILLING_ROOT_CLASS = "dsh-billing-root";
18
27
  /** Empty snapshot: shown before (or without) real host data — zeros, never fabricated samples. */
19
28
  export declare const EMPTY_STATS: UsageStats;
20
29
  /**
@@ -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;
@@ -1,5 +1,5 @@
1
1
  /** Locale dictionaries for the usage billing surface. */
2
- export type UsageBillingKey = 'title' | 'cost' | 'todayCost' | 'monthCost' | 'yearCost' | 'monthProjected' | 'monthProjectedHint' | 'liveTurn' | 'liveSession' | 'liveSessionSub' | 'calls' | 'cacheHitRate' | 'tokens' | 'inputTokens' | 'outputTokens' | 'avgCost' | 'kpiRange' | 'avgRangeToday' | 'avgRange7d' | 'avgRangeWeek' | 'avgRangeMonth' | 'avgRangeAll' | 'avgRangeCustom' | 'customRangeStart' | 'customRangeEnd' | 'trend' | 'trend7d' | 'trend30d' | 'trendMetric' | 'trendMetricCost' | 'trendMetricTokens' | 'pricingSearch' | 'bandPinHint' | 'trendEmpty' | 'trendTotal' | 'roundsUnit' | 'healthModelsLive' | 'healthVendorsDown' | 'healthVendorsUnavailable' | 'budget' | 'budgetRemain' | 'budgetAmount' | 'budgetSummary' | 'sessions' | 'sessionTitle' | 'lastActive' | 'sessionOverflow' | 'budgetTierBody' | 'models' | 'providerBilling' | 'channelUnknown' | 'directTag' | 'relayTag' | 'unknownTag' | 'unknownChannelHint' | 'planCountUnit' | 'actual' | 'pricing' | 'input' | 'output' | 'cacheHit' | 'peak' | 'offPeak' | 'flat' | 'band' | 'close' | 'footer' | 'footerCredit' | 'lastUpdated' | 'noData' | 'todayRate' | 'rateLive' | 'rateBuiltin' | 'pricingSyncedAt' | 'pricingSyncNow' | 'pricingSyncing' | 'promoBadge' | 'promoUntil' | 'promoOpenEnded' | 'pricingTip' | 'pricingUnit' | 'pricingNotes' | 'ubPeak' | 'ubOff' | 'ubStd' | 'peakBand' | 'pricingSource' | 'noteCache' | 'noteBand' | 'noteSource' | 'balance' | 'recharge' | 'rechargeHint' | 'balanceUnconfigured' | 'balanceUnauthorized' | 'balanceUnreachable' | 'uncatalogued' | 'estimatedPricing' | 'balanceDays' | 'balanceLowBody' | 'reconcileDrift' | 'reconcileDismiss' | 'subscriptionNotConfigured' | 'subscriptionUnauthorized' | 'subscriptionUnavailable' | 'subscriptionInvalid' | 'subscriptionRateLimited' | 'subscriptionSession' | 'subscriptionWeekly' | 'subscriptionMonthly' | 'subscriptionBilling' | 'subscriptionRemaining' | 'subscriptionExhausted' | 'subscriptionReset' | 'subscriptionNoApi' | 'floatWindow' | 'floatModeCombined' | 'floatModeSubscription' | 'floatMode' | 'floatTargets' | 'floatWindowHint' | 'floatPrimaryToday' | 'floatPrimaryWeek' | 'floatPrimaryMonth' | 'floatNoTargets' | 'floatNoTargetsHint' | 'cardDisplay' | 'cardDisplayHint' | 'cardMode' | 'cardModeFull' | 'cardModeCompact' | 'cardModeHidden' | 'cardModeHiddenHint' | 'cardModeFallback' | 'nativeSettingsNav' | 'nativeSettingsIntro' | 'nativeSettingsHiddenHint' | 'cardMetric' | 'cardMetricMoney' | 'cardMetricTokens' | 'cardSpan' | 'cardSpanDay' | 'cardSpanWeek' | 'cardSpanMonth' | 'cardDeltaBadge' | 'cardDeltaShow' | 'cardDeltaHide' | 'triggerMonthTokens' | 'triggerTodayTokens' | 'triggerWeekTokens' | 'subscriptionsStale' | 'balanceStaleNotice' | 'staleLedgerNotice' | 'staleSnapshotNotice' | 'statsLoadFailed' | 'unreadableNotice' | 'unreadableFormatNotice' | 'unreadableNoLedgerNotice' | 'tokenCacheWrite' | 'toolRank' | 'toolName' | 'userPrices' | 'userPricesHint' | 'userPriceSave' | 'userPriceModel' | 'userPriceSource' | 'userPriceSourceHint' | 'userPriceOffPeak' | 'userPriceNormal' | 'userPriceCurrency' | 'userPriceAdd' | 'userPriceRemoveSelected' | 'userPriceSelect' | 'sessionStaleBadge' | 'sessionUntitled' | 'sessionSubCost' | 'sessionSubCalls' | 'sessionSubRow' | 'heatmapLess' | 'heatmapMore' | 'currency' | 'currencyCny' | 'currencyUsd' | 'currencyEur' | 'language' | 'heatmap' | 'rounds' | 'roundsHint' | 'anomaly' | 'model' | 'thModel' | 'thInputMiss' | 'thInputHit' | 'costAbbr' | 'tabOverview' | 'tabTrends' | 'tabProviders' | 'tabPricing' | 'tabSettings' | 'budgetHint' | 'peakAlertHint' | 'peakAlertDescPeak' | 'peakAlertDescOff' | 'peakAlertDescPeakZhipu' | 'peakAlertDescOffZhipu' | 'peakAlertQueuePeak' | 'peakAlertQueueOff' | 'export' | 'exportCsvDay' | 'exportCsvSession' | 'exportJson' | 'peakShare' | 'peakSharePerCall' | 'offPeakSavings' | 'perfMax' | 'weekCost' | 'roleCost' | 'roleUser' | 'roleAssistant' | 'roleTool' | 'roleHint' | 'tierPeak' | 'tierOff' | 'tierToPeak' | 'tierToOff' | 'tierAlertEnterPeak' | 'tierAlertEnterOff' | 'tierAlertEnterPeakZhipu' | 'tierAlertEnterOffZhipu' | 'peakAlertTitlePeak' | 'peakAlertTitleOff' | 'peakAlert' | 'peakAlertLeadMin' | 'peakAlertPos' | 'peakAlertMode' | 'peakAlertPosCorner' | 'peakAlertPosCenter' | 'peakAlertModePeak' | 'peakAlertModeOff' | 'peakAlertModeBoth' | 'peakAlertWebNotify' | 'peakAlertPreview' | 'planTypeCode' | 'planTypeToken' | 'subscriptionFeePerMonth' | 'triggerToday' | 'triggerMonth' | 'subscriptionTag' | 'cellEstimateHint' | 'free' | 'perfSamples' | 'perfTtft' | 'perfP50' | 'perfP90' | 'perfTps' | 'perfLatency' | 'perfEstimated' | 'perfEmpty' | 'perfTpsUnit' | 'perfTitle' | 'perfHint' | 'perfAll' | 'perfChartEmpty' | 'heatmapYear' | 'heatmapHalf' | 'heatmapMonth' | 'metricCost' | 'metricTokens' | 'heatmapTotal' | 'activeDays' | 'streakDays' | 'subscriptionAutoDetect' | 'pluginAuthor' | 'pluginRepository' | 'pluginNpm' | 'pluginLicense' | 'tabToken' | 'tokenExport' | 'tokenExportCsv' | 'tokenReasoningShare' | 'tokenReasoningShort' | 'tokenIo' | 'tokenPeak' | 'densityLabel' | 'densityHint' | 'densityCompact' | 'densityDefault' | 'densityComfortable' | 'motionLabel' | 'motionHint' | 'motionOff' | 'motionSubtle' | 'motionRich' | 'settingsNavDisplayPref' | 'settingsNavBudget' | 'settingsNavAlert' | 'settingsNavDisplay' | 'settingsNavAdvanced' | 'settingsNavAbout' | 'settingsSearchPlaceholder' | 'settingsSearchEmpty' | 'sessionsViewAll' | 'sessionViewerSearch' | 'modelBudgetTitle' | 'modelBudgetHint' | 'modelBudgetBody' | 'modelBudgetPlaceholder' | 'moreWorksTitle' | 'adEngramName' | 'adEngramDesc' | 'adRainbowName' | 'adRainbowDesc' | 'kpiDescCacheHit' | 'kpiDescTokens' | 'kpiDescAvgCost' | 'kpiDescCalls' | 'kpiDescReasoning' | 'kpiDescIo' | 'kpiDescPeak' | 'healthDotLive' | 'healthDotFailed' | 'healthDotUnknown' | 'settingsSectionDisplay' | 'emptyHint' | 'tokenDaily' | 'tokenByModel' | 'tokenMiss' | 'tokenHit' | 'tokenOutput' | 'tokenViewStructure' | 'tokenViewModel' | 'tokenHitShort' | 'tokenMissShort' | 'tokenTotal' | 'tokenShare' | 'usageStatsTool' | 'usageStatsToolHint' | 'balanceGranted' | 'balanceTopped' | 'balanceDaily' | 'balanceDaysLong' | 'balanceDaysUnit' | 'popTodayModel' | 'popNoConsumption' | 'popTitle' | 'popDirectLead' | 'popSubLead' | 'unpricedHint' | 'searchEstimateHint' | 'siteListDisplay' | 'siteListDisplayHint' | 'liveCostBar' | 'liveCostBarHint' | 'liveCostBarPosition' | 'liveCostBarPosBelow' | 'liveCostBarPosAbove' | 'liveCostBarPosToolbar' | 'exportCsvSite' | 'panelRelayQuota' | 'relayBalance' | 'relayNoQuota' | 'relayWindowUsed' | 'relayKindNewApi' | 'relayKindSub2Api' | 'relayKindUnknown' | 'expandAll' | 'collapseAll' | 'todayOnly' | 'todayNoConsumption' | 'commandUsageLabel' | 'commandUsageDescription' | 'sessionOpen' | 'sessionOpenFailed' | 'sessionOpenUnavailable' | 'tabAgents' | 'tabQueue' | 'queueSubtitle' | 'queueUntilPeak' | 'queueUntilOffPeak' | 'queueUnsupportedTitle' | 'queueUnsupportedBody' | 'queueSafety' | 'queueSafetyIsolated' | 'queueSafetyReuse' | 'queueReusePlanned' | 'queueReuseDone' | 'queueFallbackReason' | 'queueReuseModelNote' | 'queueWorkspace' | 'queueModel' | 'queueNoOptions' | 'queuePromptLabel' | 'queuePromptPlaceholder' | 'queuePrivacy' | 'queueEnqueue' | 'queueImport' | 'queueImportHint' | 'queueImported' | 'queueImportFormat' | 'queueImportTooLarge' | 'queueActive' | 'queueClearFinished' | 'queueEmpty' | 'queueLoading' | 'queueOpenSession' | 'queueRemoveQueued' | 'queueRemoveHistory' | 'queueStatusQueued' | 'queueStatusStarting' | 'queueStatusRunning' | 'queueStatusCompleted' | 'queueStatusFailed' | 'quickQueueToggle' | 'quickQueueEntry' | 'quickQueueEntryHint' | 'quickQueueReuseEntry' | 'quickQueueReuseEntryHint' | 'quickQueueEnqueue' | 'quickQueueEnqueueing' | 'quickQueueWaiting' | 'quickQueueClear' | 'quickQueueEnqueued' | 'quickQueueEmpty' | 'quickQueueBusy' | 'quickQueueAttachments' | 'quickQueueContext' | 'quickQueueRoute' | 'quickQueueDraftChanged' | 'quickQueueUnsupported' | 'quickQueueFailed' | 'agentsSummary' | 'agentsCount' | 'agentsDelegations' | 'agentsRoots' | 'agentsMostExpensive' | 'agentsChainTotal' | 'agentsNoData' | 'agentsSubagent' | 'agentsRoot';
2
+ export type UsageBillingKey = 'title' | 'cost' | 'todayCost' | 'monthCost' | 'yearCost' | 'monthProjected' | 'monthProjectedHint' | 'liveTurn' | 'liveSession' | 'liveSessionSub' | 'calls' | 'cacheHitRate' | 'tokens' | 'inputTokens' | 'outputTokens' | 'avgCost' | 'kpiRange' | 'avgRangeToday' | 'avgRange7d' | 'avgRangeWeek' | 'avgRangeMonth' | 'avgRangeAll' | 'avgRangeCustom' | 'customRangeStart' | 'customRangeEnd' | 'trend' | 'trend7d' | 'trend30d' | 'trendMetric' | 'trendMetricCost' | 'trendMetricTokens' | 'pricingSearch' | 'bandPinHint' | 'trendEmpty' | 'trendTotal' | 'roundsUnit' | 'healthModelsLive' | 'healthVendorsDown' | 'healthVendorsUnavailable' | 'budget' | 'budgetRemain' | 'budgetAmount' | 'budgetSummary' | 'sessions' | 'sessionTitle' | 'lastActive' | 'sessionOverflow' | 'budgetTierBody' | 'models' | 'providerBilling' | 'channelUnknown' | 'directTag' | 'relayTag' | 'unknownTag' | 'unknownChannelHint' | 'planCountUnit' | 'actual' | 'pricing' | 'input' | 'output' | 'cacheHit' | 'peak' | 'offPeak' | 'flat' | 'band' | 'close' | 'footer' | 'footerCredit' | 'lastUpdated' | 'noData' | 'todayRate' | 'rateLive' | 'rateBuiltin' | 'pricingSyncedAt' | 'pricingSyncNow' | 'pricingSyncing' | 'promoBadge' | 'promoUntil' | 'promoOpenEnded' | 'pricingTip' | 'pricingUnit' | 'pricingNotes' | 'ubPeak' | 'ubOff' | 'ubStd' | 'peakBand' | 'pricingSource' | 'noteCache' | 'noteBand' | 'noteSource' | 'balance' | 'recharge' | 'rechargeHint' | 'balanceUnconfigured' | 'balanceUnauthorized' | 'balanceUnreachable' | 'uncatalogued' | 'estimatedPricing' | 'balanceDays' | 'balanceLowBody' | 'reconcileDrift' | 'reconcileDismiss' | 'subscriptionNotConfigured' | 'subscriptionUnauthorized' | 'subscriptionUnavailable' | 'subscriptionInvalid' | 'subscriptionRateLimited' | 'subscriptionSession' | 'subscriptionWeekly' | 'subscriptionMonthly' | 'subscriptionBilling' | 'subscriptionRemaining' | 'subscriptionExhausted' | 'subscriptionReset' | 'subscriptionNoApi' | 'floatWindow' | 'floatModeCombined' | 'floatModeSubscription' | 'floatMode' | 'floatTargets' | 'floatWindowHint' | 'floatPrimaryToday' | 'floatPrimaryWeek' | 'floatPrimaryMonth' | 'floatNoTargets' | 'floatNoTargetsHint' | 'cardDisplay' | 'cardDisplayHint' | 'cardMode' | 'cardModeFull' | 'cardModeCompact' | 'cardModeHidden' | 'cardModeHiddenHint' | 'cardModeFallback' | 'nativeSettingsNav' | 'nativeSettingsIntro' | 'nativeSettingsHiddenHint' | 'cardMetric' | 'cardMetricMoney' | 'cardMetricTokens' | 'cardSpan' | 'cardSpanDay' | 'cardSpanWeek' | 'cardSpanMonth' | 'cardDeltaBadge' | 'cardDeltaShow' | 'cardDeltaHide' | 'triggerMonthTokens' | 'triggerTodayTokens' | 'triggerWeekTokens' | 'subscriptionsStale' | 'balanceStaleNotice' | 'staleLedgerNotice' | 'staleSnapshotNotice' | 'statsLoadFailed' | 'unreadableNotice' | 'unreadableFormatNotice' | 'unreadableNoLedgerNotice' | 'tokenCacheWrite' | 'toolRank' | 'toolName' | 'userPrices' | 'userPricesHint' | 'userPriceSave' | 'userPriceModel' | 'userPriceSource' | 'userPriceSourceHint' | 'userPriceOffPeak' | 'userPriceNormal' | 'userPriceCurrency' | 'userPriceAdd' | 'userPriceRemoveSelected' | 'userPriceSelect' | 'sessionStaleBadge' | 'sessionUntitled' | 'sessionSubCost' | 'sessionSubCalls' | 'sessionSubRow' | 'heatmapLess' | 'heatmapMore' | 'currency' | 'currencyCny' | 'currencyUsd' | 'currencyEur' | 'language' | 'heatmap' | 'rounds' | 'roundsHint' | 'anomaly' | 'model' | 'thModel' | 'thInputMiss' | 'thInputHit' | 'costAbbr' | 'tabOverview' | 'tabTrends' | 'tabProviders' | 'tabPricing' | 'tabSettings' | 'budgetHint' | 'peakAlertHint' | 'peakAlertDescPeak' | 'peakAlertDescOff' | 'peakAlertDescPeakZhipu' | 'peakAlertDescOffZhipu' | 'peakAlertQueuePeak' | 'peakAlertQueueOff' | 'export' | 'exportCsvDay' | 'exportCsvSession' | 'exportJson' | 'peakShare' | 'peakSharePerCall' | 'offPeakSavings' | 'perfMax' | 'weekCost' | 'roleCost' | 'roleUser' | 'roleAssistant' | 'roleTool' | 'roleHint' | 'tierPeak' | 'tierOff' | 'tierToPeak' | 'tierToOff' | 'tierAlertEnterPeak' | 'tierAlertEnterOff' | 'tierAlertEnterPeakZhipu' | 'tierAlertEnterOffZhipu' | 'peakAlertTitlePeak' | 'peakAlertTitleOff' | 'peakAlert' | 'peakAlertLeadMin' | 'peakAlertPos' | 'peakAlertMode' | 'peakAlertPosCorner' | 'peakAlertPosCenter' | 'peakAlertModePeak' | 'peakAlertModeOff' | 'peakAlertModeBoth' | 'peakAlertWebNotify' | 'peakAlertPreview' | 'planTypeCode' | 'planTypeToken' | 'subscriptionFeePerMonth' | 'triggerToday' | 'triggerMonth' | 'subscriptionTag' | 'cellEstimateHint' | 'free' | 'perfSamples' | 'perfTtft' | 'perfP50' | 'perfP90' | 'perfTps' | 'perfLatency' | 'perfEstimated' | 'perfEmpty' | 'perfTpsUnit' | 'perfTitle' | 'perfHint' | 'perfAll' | 'perfChartEmpty' | 'heatmapYear' | 'heatmapHalf' | 'heatmapMonth' | 'metricCost' | 'metricTokens' | 'heatmapTotal' | 'activeDays' | 'streakDays' | 'subscriptionAutoDetect' | 'pluginAuthor' | 'pluginRepository' | 'pluginNpm' | 'pluginLicense' | 'tabToken' | 'tokenExport' | 'tokenExportCsv' | 'tokenReasoningShare' | 'tokenReasoningShort' | 'tokenIo' | 'tokenPeak' | 'densityLabel' | 'densityHint' | 'densityCompact' | 'densityDefault' | 'densityComfortable' | 'motionLabel' | 'motionHint' | 'motionOff' | 'motionSubtle' | 'motionRich' | 'settingsNavDisplayPref' | 'settingsNavBudget' | 'settingsNavAlert' | 'settingsNavDisplay' | 'settingsNavAdvanced' | 'settingsNavAbout' | 'settingsSearchPlaceholder' | 'settingsSearchEmpty' | 'sessionsViewAll' | 'sessionViewerSearch' | 'modelBudgetTitle' | 'modelBudgetHint' | 'modelBudgetBody' | 'modelBudgetPlaceholder' | 'moreWorksTitle' | 'adEngramName' | 'adEngramDesc' | 'adRainbowName' | 'adRainbowDesc' | 'kpiDescCacheHit' | 'kpiDescTokens' | 'kpiDescAvgCost' | 'kpiDescCalls' | 'kpiDescReasoning' | 'kpiDescIo' | 'kpiDescPeak' | 'healthDotLive' | 'healthDotFailed' | 'healthDotUnknown' | 'settingsSectionDisplay' | 'emptyHint' | 'tokenDaily' | 'tokenByModel' | 'tokenMiss' | 'tokenHit' | 'tokenOutput' | 'tokenViewStructure' | 'tokenViewModel' | 'tokenHitShort' | 'tokenMissShort' | 'tokenTotal' | 'tokenShare' | 'usageStatsTool' | 'usageStatsToolHint' | 'balanceGranted' | 'balanceTopped' | 'balanceDaily' | 'balanceDaysLong' | 'balanceDaysUnit' | 'popTodayModel' | 'popNoConsumption' | 'popTitle' | 'popDirectLead' | 'popSubLead' | 'unpricedHint' | 'unpricedMore' | 'unpricedFix' | 'searchEstimateHint' | 'siteListDisplay' | 'siteListDisplayHint' | 'liveCostBar' | 'liveCostBarHint' | 'liveCostBarPosition' | 'liveCostBarPosBelow' | 'liveCostBarPosAbove' | 'liveCostBarPosToolbar' | 'exportCsvSite' | 'panelRelayQuota' | 'relayBalance' | 'relayNoQuota' | 'relayWindowUsed' | 'relayKindNewApi' | 'relayKindSub2Api' | 'relayKindUnknown' | 'expandAll' | 'collapseAll' | 'todayOnly' | 'todayNoConsumption' | 'commandUsageLabel' | 'commandUsageDescription' | 'sessionOpen' | 'sessionOpenFailed' | 'sessionOpenUnavailable' | 'tabAgents' | 'tabQueue' | 'queueSubtitle' | 'queueUntilPeak' | 'queueUntilOffPeak' | 'queueUnsupportedTitle' | 'queueUnsupportedBody' | 'queueSafety' | 'queueSafetyIsolated' | 'queueSafetyReuse' | 'queueReusePlanned' | 'queueReuseDone' | 'queueFallbackReason' | 'queueReuseModelNote' | 'queueWorkspace' | 'queueModel' | 'queueNoOptions' | 'queuePromptLabel' | 'queuePromptPlaceholder' | 'queuePrivacy' | 'queueEnqueue' | 'queueImport' | 'queueImportHint' | 'queueImported' | 'queueImportFormat' | 'queueImportTooLarge' | 'queueActive' | 'queueClearFinished' | 'queueEmpty' | 'queueLoading' | 'queueOpenSession' | 'queueRemoveQueued' | 'queueRemoveHistory' | 'queueStatusQueued' | 'queueStatusStarting' | 'queueStatusRunning' | 'queueStatusCompleted' | 'queueStatusFailed' | 'quickQueueToggle' | 'quickQueueEntry' | 'quickQueueEntryHint' | 'quickQueueReuseEntry' | 'quickQueueReuseEntryHint' | 'quickQueueEnqueue' | 'quickQueueEnqueueing' | 'quickQueueWaiting' | 'quickQueueClear' | 'quickQueueEnqueued' | 'quickQueueEmpty' | 'quickQueueBusy' | 'quickQueueAttachments' | 'quickQueueContext' | 'quickQueueRoute' | 'quickQueueDraftChanged' | 'quickQueueUnsupported' | 'quickQueueFailed' | 'agentsSummary' | 'agentsCount' | 'agentsDelegations' | 'agentsRoots' | 'agentsMostExpensive' | 'agentsChainTotal' | 'agentsNoData' | 'agentsSubagent' | 'agentsRoot';
3
3
  export declare const NS = "usageBilling";
4
4
  export declare const zh: Record<UsageBillingKey, string>;
5
5
  export declare const en: Record<UsageBillingKey, string>;
@@ -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 折直至另行通知」),持续生效直至收到公告后补填。
@@ -234,8 +234,9 @@ export declare function loadPerfViewPrefs(): PerfViewPrefs;
234
234
  export declare function savePerfViewPrefs(prefs: PerfViewPrefs): void;
235
235
  /**
236
236
  * 显示密度档位(v1.5 新增)。紧凑档减小行高/字号/内边距,舒适档加大;
237
- * 默认档保持历史感官。client 端写到 `documentElement.dataset.density`,
238
- * CSS `[data-density="..."]` 选择器派生 `--ds-density-*` 变量。
237
+ * 默认档保持历史感官。client 端写到 `documentElement.dataset.dshBillingDensity`
238
+ * (= `data-dsh-billing-density`,命名空间化防同名属性互相覆盖,issue #124),
239
+ * CSS `[data-dsh-billing-density="..."]` 选择器派生 `--ds-density-*` 变量。
239
240
  */
240
241
  export type DensityPref = 'compact' | 'default' | 'comfortable';
241
242
  /** localStorage key(与其他 `dsh.ui-usage-billing.*` 偏好同命名空间)。 */
@@ -250,9 +251,11 @@ export declare function loadDensity(): DensityPref;
250
251
  * 失败静默(展示偏好非关键)。 */
251
252
  export declare function saveDensity(density: DensityPref): void;
252
253
  /**
253
- * 动效强度档位(v1.5 新增)。`off` 冻结全部 transition+animation,
254
- * `subtle` 抑制 240ms 以上的入场/计数动画但保留 160ms 微交互,
255
- * `rich` 即默认(全开)。写到 `documentElement.dataset.motion`。
254
+ * 动效强度档位(v1.5 新增)。`off` 冻结本插件内的全部 transition+animation,
255
+ * `subtle` 保留 transition 微交互、把关键帧动画压成瞬时,`rich` 即默认(全开)。
256
+ * 写到 `documentElement.dataset.dshBillingMotion`(= `data-dsh-billing-motion`),
257
+ * 且压制规则只作用在本插件根容器 `.dsh-billing-root` 之内(issue #124:
258
+ * 此前通用属性 + 通配符会把宿主与第三方插件的动画一起压平)。
256
259
  */
257
260
  export type MotionPref = 'off' | 'subtle' | 'rich';
258
261
  /** localStorage key(与其他 `dsh.ui-usage-billing.*` 偏好同命名空间)。 */
@@ -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 {