@kenz1117/dsh-ui-usage-billing 1.8.3 → 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/README.en.md +6 -6
- package/README.md +12 -8
- package/lib/client.js +3 -3
- package/lib/index.js +315 -59
- package/lib/types/aggregate.d.ts +18 -1
- package/lib/types/builtin-catalog.d.ts +5 -0
- package/lib/types/client/TaskQueuePanel.d.ts +5 -1
- package/lib/types/client/api/task-queue.d.ts +4 -0
- package/lib/types/client/api/usage-stats.d.ts +16 -2
- package/lib/types/client/domain/types.d.ts +18 -0
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/client/pricing.d.ts +14 -1
- package/lib/types/client/usage-billing-settings.d.ts +9 -0
- package/lib/types/pricing-shared.d.ts +6 -0
- package/lib/types/task-queue-shared.d.ts +11 -0
- package/lib/types/task-queue.d.ts +40 -3
- package/package.json +62 -59
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
|
|
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
|
|
4484
|
+
const cacheWrite = usage.cacheWriteTokens ?? 0;
|
|
4485
|
+
const cacheMiss = usage.inputTokens + cacheWrite;
|
|
4424
4486
|
acc.calls += 1;
|
|
4425
|
-
acc.input += usage.inputTokens + cacheHit +
|
|
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 (
|
|
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
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
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") {
|
|
@@ -5285,6 +5399,28 @@ function configFingerprint(subscriptionMatcher, officialProviderIds, routeAliase
|
|
|
5285
5399
|
origins
|
|
5286
5400
|
].join("|");
|
|
5287
5401
|
}
|
|
5402
|
+
/** 失败原因摘要:给文档与日志用的短文本(截断,避免超长路径撑爆响应体)。
|
|
5403
|
+
* Error 取 message;非 Error 取字符串化值。截断上限与 task-queue 路由一致(300)。 */
|
|
5404
|
+
function reasonOf(error) {
|
|
5405
|
+
const trimmed = (error instanceof Error ? error.message : String(error)).trim();
|
|
5406
|
+
return trimmed.length > 300 ? `${trimmed.slice(0, 300)}…` : trimmed;
|
|
5407
|
+
}
|
|
5408
|
+
/**
|
|
5409
|
+
* 会话列表整体读不到(issue #119):宿主持久化后端整体故障,或会话目录里有
|
|
5410
|
+
* 读不了/对不上的日志。聚合无法枚举会话,只能降级到持久账本或磁盘快照——
|
|
5411
|
+
* 但「降级」必须让用户看得见,否则新装用户看到的是一片 ¥0(分不清没花钱
|
|
5412
|
+
* 还是没读到)。携带原因随文档下发,客户端据此显示「读取失败」。
|
|
5413
|
+
*/
|
|
5414
|
+
var SessionListUnavailableError = class extends Error {
|
|
5415
|
+
/** 失败原因摘要(面向用户的中文/英文提示语,由调用方决定措辞)。 */
|
|
5416
|
+
reason;
|
|
5417
|
+
constructor(reason, cause) {
|
|
5418
|
+
super(`session list unavailable: ${reason}`);
|
|
5419
|
+
this.name = "SessionListUnavailableError";
|
|
5420
|
+
this.reason = reason;
|
|
5421
|
+
if (cause !== void 0) this.cause = cause;
|
|
5422
|
+
}
|
|
5423
|
+
};
|
|
5288
5424
|
/** 会话格式拒读(宿主 SessionFormatUnsupportedError):日志完好,仅本构建读不了。
|
|
5289
5425
|
* 宿主错误类显式落 error.name;经包装/重建的路径只在 message 里保留类名,两处都认。
|
|
5290
5426
|
* 据此把「格式不受支持」与「损坏/其他读取失败」分开计数,供面板按原因归因(issue #84)。 */
|
|
@@ -5361,7 +5497,7 @@ function createUsageAggregator(persistence, options = {}) {
|
|
|
5361
5497
|
...cwd === void 0 ? {} : { cwd },
|
|
5362
5498
|
...subOf === void 0 ? {} : { subOf },
|
|
5363
5499
|
...stamp === null ? {} : { stamp },
|
|
5364
|
-
foldVersion:
|
|
5500
|
+
foldVersion: 24,
|
|
5365
5501
|
fingerprint: foldFingerprint,
|
|
5366
5502
|
foldedAt: Date.now(),
|
|
5367
5503
|
fold: serializeFold(fold)
|
|
@@ -5454,13 +5590,16 @@ function createUsageAggregator(persistence, options = {}) {
|
|
|
5454
5590
|
let formatUnreadable = 0;
|
|
5455
5591
|
let noLedgerUnreadable = 0;
|
|
5456
5592
|
let staleLedgerSessions = 0;
|
|
5593
|
+
let sessionListError;
|
|
5457
5594
|
if (mode === "full") {
|
|
5458
5595
|
let metas;
|
|
5459
5596
|
try {
|
|
5460
5597
|
metas = await persistence.list();
|
|
5461
5598
|
} catch (error) {
|
|
5462
|
-
|
|
5599
|
+
const reason = reasonOf(error);
|
|
5600
|
+
sessionListError = reason;
|
|
5463
5601
|
console.warn("[usage-billing] session list unavailable; serving durable usage ledger:", error);
|
|
5602
|
+
if (options.ledger === void 0 || ledger.size === 0) throw new SessionListUnavailableError(reason, error);
|
|
5464
5603
|
metas = [];
|
|
5465
5604
|
}
|
|
5466
5605
|
let sliceAt = Date.now();
|
|
@@ -5485,7 +5624,7 @@ function createUsageAggregator(persistence, options = {}) {
|
|
|
5485
5624
|
const cwd = meta.cwd;
|
|
5486
5625
|
const subOf = subParentOf(meta);
|
|
5487
5626
|
const ledgerRow = ledger.get(id);
|
|
5488
|
-
if (ledgerRow !== void 0 && ledgerRow.stamp !== void 0 && stamp !== null && ledgerRow.stamp === stamp && (ledgerRow.foldVersion ?? 1) ===
|
|
5627
|
+
if (ledgerRow !== void 0 && ledgerRow.stamp !== void 0 && stamp !== null && ledgerRow.stamp === stamp && (ledgerRow.foldVersion ?? 1) === 24 && ledgerRow.fingerprint === foldFingerprint && !foldNeedsReprice(ledgerRow.fold)) {
|
|
5489
5628
|
const fold = deserializedFoldOf(ledgerRow.fold);
|
|
5490
5629
|
folds.push({
|
|
5491
5630
|
id,
|
|
@@ -5614,7 +5753,7 @@ function createUsageAggregator(persistence, options = {}) {
|
|
|
5614
5753
|
}
|
|
5615
5754
|
if (included.has(entry.id)) continue;
|
|
5616
5755
|
try {
|
|
5617
|
-
const stale = (entry.foldVersion ?? 1) <
|
|
5756
|
+
const stale = (entry.foldVersion ?? 1) < 24 || entry.fingerprint !== foldFingerprint;
|
|
5618
5757
|
const fold = deserializedFoldOf(entry.fold);
|
|
5619
5758
|
const hint = titleHints.get(entry.id);
|
|
5620
5759
|
folds.push({
|
|
@@ -5824,7 +5963,8 @@ function createUsageAggregator(persistence, options = {}) {
|
|
|
5824
5963
|
tool: roles.inputCost * (1 - userShare)
|
|
5825
5964
|
};
|
|
5826
5965
|
})(),
|
|
5827
|
-
...mode === "ledger-only" ? { staleSnapshot: true } : {}
|
|
5966
|
+
...mode === "ledger-only" ? { staleSnapshot: true } : {},
|
|
5967
|
+
...sessionListError === void 0 ? {} : { sessionListError }
|
|
5828
5968
|
};
|
|
5829
5969
|
if (mode === "full") {
|
|
5830
5970
|
lastDoc = document;
|
|
@@ -7453,6 +7593,7 @@ function buildExtraModels(data) {
|
|
|
7453
7593
|
if (input === void 0 || output === void 0) continue;
|
|
7454
7594
|
const declaredCacheRead = asPrice(cost.cache_read);
|
|
7455
7595
|
const cacheRead = declaredCacheRead ?? input * .1;
|
|
7596
|
+
const declaredCacheWrite = asPrice(cost.cache_write);
|
|
7456
7597
|
const name = modelDoc.name;
|
|
7457
7598
|
const familyValue = modelDoc.family;
|
|
7458
7599
|
const family = typeof familyValue === "string" && familyValue !== "" ? familyValue : void 0;
|
|
@@ -7480,7 +7621,8 @@ function buildExtraModels(data) {
|
|
|
7480
7621
|
price: {
|
|
7481
7622
|
input,
|
|
7482
7623
|
cacheHit: cacheRead,
|
|
7483
|
-
output
|
|
7624
|
+
output,
|
|
7625
|
+
...declaredCacheWrite !== void 0 ? { cacheWrite: declaredCacheWrite } : {}
|
|
7484
7626
|
}
|
|
7485
7627
|
},
|
|
7486
7628
|
input,
|
|
@@ -9442,6 +9584,7 @@ function registerUsageStatsRoute(ctx, deps) {
|
|
|
9442
9584
|
deps.persistSnapshot(decorate(stats));
|
|
9443
9585
|
}, () => {});
|
|
9444
9586
|
let fresh;
|
|
9587
|
+
let sessionListError;
|
|
9445
9588
|
try {
|
|
9446
9589
|
fresh = await Promise.race([aggregating.then((stats) => stats), new Promise((resolve) => {
|
|
9447
9590
|
setTimeout(() => {
|
|
@@ -9450,16 +9593,19 @@ function registerUsageStatsRoute(ctx, deps) {
|
|
|
9450
9593
|
})]);
|
|
9451
9594
|
} catch (error) {
|
|
9452
9595
|
console.error("[usage-billing] usage-stats aggregate failed, falling back to snapshot:", error);
|
|
9596
|
+
if (error instanceof SessionListUnavailableError) sessionListError = error.reason;
|
|
9453
9597
|
}
|
|
9454
9598
|
if (fresh !== void 0) {
|
|
9455
9599
|
res.end(statsBodyOf(fresh));
|
|
9456
9600
|
return;
|
|
9457
9601
|
}
|
|
9602
|
+
const degraded = sessionListError === void 0 ? {} : { sessionListError };
|
|
9458
9603
|
const recent = deps.lastDoc?.();
|
|
9459
9604
|
if (recent !== void 0) {
|
|
9460
9605
|
res.end(JSON.stringify({
|
|
9461
9606
|
...decorate(recent),
|
|
9462
|
-
staleSnapshot: true
|
|
9607
|
+
staleSnapshot: true,
|
|
9608
|
+
...degraded
|
|
9463
9609
|
}));
|
|
9464
9610
|
return;
|
|
9465
9611
|
}
|
|
@@ -9468,11 +9614,15 @@ function registerUsageStatsRoute(ctx, deps) {
|
|
|
9468
9614
|
if (doc === null) continue;
|
|
9469
9615
|
res.end(JSON.stringify({
|
|
9470
9616
|
...decorate(doc),
|
|
9471
|
-
staleSnapshot: true
|
|
9617
|
+
staleSnapshot: true,
|
|
9618
|
+
...degraded
|
|
9472
9619
|
}));
|
|
9473
9620
|
return;
|
|
9474
9621
|
}
|
|
9475
|
-
res.end(JSON.stringify({
|
|
9622
|
+
res.end(JSON.stringify({
|
|
9623
|
+
error: "usage stats unavailable",
|
|
9624
|
+
...degraded
|
|
9625
|
+
}));
|
|
9476
9626
|
}
|
|
9477
9627
|
}), "usage-billing: usage-stats route");
|
|
9478
9628
|
}
|
|
@@ -9490,6 +9640,15 @@ const QUEUE_VERSION = 1;
|
|
|
9490
9640
|
const MAX_TASKS = 100;
|
|
9491
9641
|
const MAX_QUEUED = 50;
|
|
9492
9642
|
const MAX_PROMPT_LENGTH = 32e3;
|
|
9643
|
+
/** 会话 id 长度上限(宿主的 id 是 uuid;超长的入参一律当作没有来源会话)。 */
|
|
9644
|
+
const MAX_SESSION_ID_LENGTH = 200;
|
|
9645
|
+
/** 会话列表读面的超时(毫秒):拿不到就降级新建会话,不让队列卡住。 */
|
|
9646
|
+
const SESSION_LIST_TIMEOUT_MS = 1e4;
|
|
9647
|
+
/** 目录是否落在某个项目内(相等或为其子目录)。 */
|
|
9648
|
+
function isInsideDirectory(cwd, project) {
|
|
9649
|
+
if (project === "") return false;
|
|
9650
|
+
return cwd === project || cwd.startsWith(`${project}/`);
|
|
9651
|
+
}
|
|
9493
9652
|
const LOCK_WAIT_MS = 5e3;
|
|
9494
9653
|
const LEASE_MS = 45e3;
|
|
9495
9654
|
const HEARTBEAT_MS = 15e3;
|
|
@@ -9517,7 +9676,7 @@ function validStoredTask(value) {
|
|
|
9517
9676
|
"running",
|
|
9518
9677
|
"completed",
|
|
9519
9678
|
"failed"
|
|
9520
|
-
].includes(task.status ?? "") && (task.sessionId === void 0 || typeof task.sessionId === "string") && (task.owner === void 0 || typeof task.owner === "string") && (task.leaseUntil === void 0 || typeof task.leaseUntil === "number");
|
|
9679
|
+
].includes(task.status ?? "") && (task.sessionId === void 0 || typeof task.sessionId === "string") && (task.sourceSessionId === void 0 || typeof task.sourceSessionId === "string") && (task.reuseSource === void 0 || typeof task.reuseSource === "boolean") && (task.fallbackReason === void 0 || typeof task.fallbackReason === "string") && (task.owner === void 0 || typeof task.owner === "string") && (task.leaseUntil === void 0 || typeof task.leaseUntil === "number");
|
|
9521
9680
|
}
|
|
9522
9681
|
function publicTask(task) {
|
|
9523
9682
|
const { owner: _owner, leaseUntil: _leaseUntil, ...pub } = task;
|
|
@@ -9628,11 +9787,14 @@ var TaskQueueEngine = class {
|
|
|
9628
9787
|
if (!workspaces.some((workspace) => workspace.path === cwd)) throw new TaskQueueError("workspace is no longer available", 409);
|
|
9629
9788
|
if (typeof provider !== "string" || typeof model !== "string") throw new TaskQueueError("model is required");
|
|
9630
9789
|
if (!models.some((candidate) => candidate.provider === provider && candidate.id === model)) throw new TaskQueueError("select an available DeepSeek time-of-day model", 409);
|
|
9790
|
+
const sourceSessionId = typeof input.sourceSessionId === "string" && input.sourceSessionId.trim() !== "" && input.sourceSessionId.length <= MAX_SESSION_ID_LENGTH ? input.sourceSessionId : void 0;
|
|
9631
9791
|
return {
|
|
9632
9792
|
prompt,
|
|
9633
9793
|
cwd,
|
|
9634
9794
|
provider,
|
|
9635
|
-
model
|
|
9795
|
+
model,
|
|
9796
|
+
sourceSessionId,
|
|
9797
|
+
reuseSource: input.reuseSource === true && sourceSessionId !== void 0
|
|
9636
9798
|
};
|
|
9637
9799
|
} catch (error) {
|
|
9638
9800
|
if (inputs.length > 1 && error instanceof TaskQueueError) throw new TaskQueueError(`task ${String(index + 1)}: ${error.message}`, error.status);
|
|
@@ -9767,11 +9929,21 @@ var TaskQueueEngine = class {
|
|
|
9767
9929
|
await this.requeue(claimed.id);
|
|
9768
9930
|
return;
|
|
9769
9931
|
}
|
|
9770
|
-
const
|
|
9771
|
-
|
|
9772
|
-
|
|
9773
|
-
|
|
9774
|
-
|
|
9932
|
+
const reuse = await this.resolveSourceSession(claimed, controller);
|
|
9933
|
+
let sessionId;
|
|
9934
|
+
if (reuse.ok) sessionId = reuse.sessionId;
|
|
9935
|
+
else {
|
|
9936
|
+
if (reuse.reason !== void 0) {
|
|
9937
|
+
if (!await this.patch(claimed.id, { fallbackReason: reuse.reason })) return;
|
|
9938
|
+
}
|
|
9939
|
+
const { models: availableModels } = await this.modelOptions(controller, true);
|
|
9940
|
+
if (!availableModels.some((model) => model.provider === claimed.provider && model.id === claimed.model)) throw new TaskQueueError("the selected official DeepSeek model is no longer available", 409);
|
|
9941
|
+
sessionId = (await this.createGroupedSession(controller, claimed.cwd)).sessionId;
|
|
9942
|
+
}
|
|
9943
|
+
const sessionPatch = { sessionId };
|
|
9944
|
+
if (reuse.ok) sessionPatch.fallbackReason = void 0;
|
|
9945
|
+
if (!await this.patch(claimed.id, sessionPatch)) return;
|
|
9946
|
+
if (!reuse.ok) await controller.selectModel({
|
|
9775
9947
|
sessionId,
|
|
9776
9948
|
provider: claimed.provider,
|
|
9777
9949
|
model: claimed.model
|
|
@@ -9810,6 +9982,74 @@ var TaskQueueEngine = class {
|
|
|
9810
9982
|
this.taskAbort = void 0;
|
|
9811
9983
|
}
|
|
9812
9984
|
}
|
|
9985
|
+
/**
|
|
9986
|
+
* issue #118:判断来源会话能否续跑。不能就给出降级原因(写进卡片)。
|
|
9987
|
+
*
|
|
9988
|
+
* 判据来自 issue 的安全边界:来源会话已删除 / 正在跑别的轮次 / 工作区变了时,
|
|
9989
|
+
* 回退为新建会话,不要往用户正在使用的会话里硬塞一轮。另外子智能体会话与
|
|
9990
|
+
* 归档会话也不能复用——前者归属子智能体路由,后者轮次会以 blocked 结束、
|
|
9991
|
+
* 看起来跑了其实没跑。
|
|
9992
|
+
*/
|
|
9993
|
+
async resolveSourceSession(claimed, controller) {
|
|
9994
|
+
if (claimed.reuseSource !== true) return { ok: false };
|
|
9995
|
+
const sourceSessionId = claimed.sourceSessionId;
|
|
9996
|
+
if (sourceSessionId === void 0) return { ok: false };
|
|
9997
|
+
const list = controller.list;
|
|
9998
|
+
if (typeof list !== "function") return {
|
|
9999
|
+
ok: false,
|
|
10000
|
+
reason: "this host cannot inspect Sessions"
|
|
10001
|
+
};
|
|
10002
|
+
let items;
|
|
10003
|
+
try {
|
|
10004
|
+
items = (await list.call(controller, {}, AbortSignal.timeout(SESSION_LIST_TIMEOUT_MS)))?.items ?? [];
|
|
10005
|
+
} catch (error) {
|
|
10006
|
+
return {
|
|
10007
|
+
ok: false,
|
|
10008
|
+
reason: `source session lookup failed: ${messageOf(error)}`
|
|
10009
|
+
};
|
|
10010
|
+
}
|
|
10011
|
+
const summary = items.find((item) => item.sessionId === sourceSessionId);
|
|
10012
|
+
if (summary === void 0) return {
|
|
10013
|
+
ok: false,
|
|
10014
|
+
reason: "source session no longer exists"
|
|
10015
|
+
};
|
|
10016
|
+
if (summary.origin === "subagent") return {
|
|
10017
|
+
ok: false,
|
|
10018
|
+
reason: "source session belongs to a subagent"
|
|
10019
|
+
};
|
|
10020
|
+
const archived = this.options.getWorkspaceContext?.()?.archivedSessionIds;
|
|
10021
|
+
if (archived !== void 0 && archived.includes(sourceSessionId)) return {
|
|
10022
|
+
ok: false,
|
|
10023
|
+
reason: "source session is archived"
|
|
10024
|
+
};
|
|
10025
|
+
if (summary.running === true) return {
|
|
10026
|
+
ok: false,
|
|
10027
|
+
reason: "source session is busy"
|
|
10028
|
+
};
|
|
10029
|
+
const project = typeof summary.cwd === "string" ? summary.cwd : void 0;
|
|
10030
|
+
if (project !== void 0 && !isInsideDirectory(claimed.cwd, project)) return {
|
|
10031
|
+
ok: false,
|
|
10032
|
+
reason: "source session working directory changed"
|
|
10033
|
+
};
|
|
10034
|
+
return {
|
|
10035
|
+
ok: true,
|
|
10036
|
+
sessionId: sourceSessionId
|
|
10037
|
+
};
|
|
10038
|
+
}
|
|
10039
|
+
/**
|
|
10040
|
+
* 新建会话:cwd 恰好等于某个工作区时用 create({ workspaceId }),让宿主把会话挂进
|
|
10041
|
+
* 该工作区——create({ cwd }) 从不归组,这正是队列会话在侧栏里没有分组的原因。
|
|
10042
|
+
* 两者互斥:带 workspaceId 时不能再带 cwd。
|
|
10043
|
+
*/
|
|
10044
|
+
async createGroupedSession(controller, cwd) {
|
|
10045
|
+
const workspaceId = this.options.getWorkspaceContext?.()?.workspaceIdOfPath(cwd);
|
|
10046
|
+
if (workspaceId !== void 0) try {
|
|
10047
|
+
return await controller.create({ workspaceId });
|
|
10048
|
+
} catch (error) {
|
|
10049
|
+
console.warn("[usage-billing] task queue workspace Session creation failed:", error);
|
|
10050
|
+
}
|
|
10051
|
+
return await controller.create({ cwd });
|
|
10052
|
+
}
|
|
9813
10053
|
async watch(frames, requestId) {
|
|
9814
10054
|
let admitted = false;
|
|
9815
10055
|
for await (const raw of frames) {
|
|
@@ -9847,7 +10087,8 @@ var TaskQueueEngine = class {
|
|
|
9847
10087
|
owner: void 0,
|
|
9848
10088
|
leaseUntil: void 0,
|
|
9849
10089
|
startedAt: void 0,
|
|
9850
|
-
sessionId: void 0
|
|
10090
|
+
sessionId: void 0,
|
|
10091
|
+
fallbackReason: void 0
|
|
9851
10092
|
});
|
|
9852
10093
|
}
|
|
9853
10094
|
async finish(id, status, error) {
|
|
@@ -10627,7 +10868,8 @@ function apply(ctx, config = {}) {
|
|
|
10627
10868
|
const now = Date.now();
|
|
10628
10869
|
if (now - lastSnapshotAt < SNAPSHOT_INTERVAL_MS) return;
|
|
10629
10870
|
lastSnapshotAt = now;
|
|
10630
|
-
const
|
|
10871
|
+
const { sessionListError: _liveError, ...data } = doc;
|
|
10872
|
+
const payload = JSON.stringify(data);
|
|
10631
10873
|
(async () => {
|
|
10632
10874
|
try {
|
|
10633
10875
|
const existing = await readFile(snapshotPath, "utf8");
|
|
@@ -10679,6 +10921,20 @@ function apply(ctx, config = {}) {
|
|
|
10679
10921
|
} catch {
|
|
10680
10922
|
return [];
|
|
10681
10923
|
}
|
|
10924
|
+
},
|
|
10925
|
+
getWorkspaceContext: () => {
|
|
10926
|
+
try {
|
|
10927
|
+
const registry = ctx.get("workspaceRegistry");
|
|
10928
|
+
if (registry === void 0) return void 0;
|
|
10929
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
10930
|
+
for (const workspace of registry.list?.() ?? []) if (typeof workspace.path === "string" && workspace.path !== "" && typeof workspace.id === "string") byPath.set(workspace.path, workspace.id);
|
|
10931
|
+
return {
|
|
10932
|
+
archivedSessionIds: registry.archivedSessionIds ?? [],
|
|
10933
|
+
workspaceIdOfPath: (path) => byPath.get(path)
|
|
10934
|
+
};
|
|
10935
|
+
} catch {
|
|
10936
|
+
return;
|
|
10937
|
+
}
|
|
10682
10938
|
}
|
|
10683
10939
|
});
|
|
10684
10940
|
registerTaskQueueRoute(ctx, {
|
package/lib/types/aggregate.d.ts
CHANGED
|
@@ -365,6 +365,12 @@ export interface UsageStatsDocument {
|
|
|
365
365
|
* (issue #103 加的 staleSnapshot 通道,此前无生产方),零新增客户端体积。
|
|
366
366
|
*/
|
|
367
367
|
staleSnapshot?: boolean;
|
|
368
|
+
/**
|
|
369
|
+
* 会话列表整体读不到时的降级原因(issue #119):目录里有读不了/对不上的
|
|
370
|
+
* 日志、宿主后端临时故障等。此时本档数字全部出自持久账本(可能是空),
|
|
371
|
+
* 客户端据此显示「读取失败」,而不是把空账本当成「没有用量」。
|
|
372
|
+
*/
|
|
373
|
+
sessionListError?: string;
|
|
368
374
|
}
|
|
369
375
|
/** 按角色费用归因:user / tool 为输入成本的启发式摊分,assistant 为输出成本实测。 */
|
|
370
376
|
export interface RoleCost {
|
|
@@ -691,7 +697,7 @@ export declare function mergeUsageLedgerDocuments(document: UsageLedgerDocument,
|
|
|
691
697
|
* 会话费用只剩最近一段,issue #29)。
|
|
692
698
|
* 持久账本行据此区分新旧算法:日志已删/不可读而只能沿用旧行时,UI 标注置信度提示。
|
|
693
699
|
*/
|
|
694
|
-
export declare const FOLD_VERSION =
|
|
700
|
+
export declare const FOLD_VERSION = 24;
|
|
695
701
|
/** 账本里拒读记录的条数上限:防异常环境(大量损坏日志)把账本撑爆;
|
|
696
702
|
* 超限按 Map 插入序保留前 N 条(最早发现的先留,stamp 失效的自然被清理让位)。 */
|
|
697
703
|
export declare const LEDGER_REFUSED_CAP = 500;
|
|
@@ -801,6 +807,17 @@ export interface SessionUsageSummary {
|
|
|
801
807
|
* 判定函数无法序列化,统一记为 `fn`(任何函数形态互视为同一指纹)。
|
|
802
808
|
*/
|
|
803
809
|
export declare function configFingerprint(subscriptionMatcher: SubscriptionMatcher, officialProviderIds: ReadonlySet<string> | undefined, routeAliases: Readonly<Record<string, string>>, searchEstimate: number, modelKeyAliases?: Readonly<Record<string, string>>, registeredProviders?: ReadonlySet<string>, routeOrigins?: Readonly<Record<string, string>>): string;
|
|
810
|
+
/**
|
|
811
|
+
* 会话列表整体读不到(issue #119):宿主持久化后端整体故障,或会话目录里有
|
|
812
|
+
* 读不了/对不上的日志。聚合无法枚举会话,只能降级到持久账本或磁盘快照——
|
|
813
|
+
* 但「降级」必须让用户看得见,否则新装用户看到的是一片 ¥0(分不清没花钱
|
|
814
|
+
* 还是没读到)。携带原因随文档下发,客户端据此显示「读取失败」。
|
|
815
|
+
*/
|
|
816
|
+
export declare class SessionListUnavailableError extends Error {
|
|
817
|
+
/** 失败原因摘要(面向用户的中文/英文提示语,由调用方决定措辞)。 */
|
|
818
|
+
readonly reason: string;
|
|
819
|
+
constructor(reason: string, cause?: unknown);
|
|
820
|
+
}
|
|
804
821
|
/**
|
|
805
822
|
* Create the incremental usage aggregator.
|
|
806
823
|
* @param persistence - the session persistence service.
|
|
@@ -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
|