@kenz1117/dsh-ui-usage-billing 1.8.6 → 1.8.8
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 +4 -4
- package/README.md +8 -4
- package/lib/client.js +5 -5
- package/lib/index.js +352 -3
- package/lib/types/aggregate.d.ts +6 -0
- package/lib/types/client/TokenPanel.d.ts +2 -0
- package/lib/types/client/domain/channel-visibility.d.ts +68 -0
- package/lib/types/client/domain/types.d.ts +6 -0
- package/lib/types/client/locales.d.ts +1 -1
- package/lib/types/client/pricing.d.ts +0 -2
- package/lib/types/client/provider-display.d.ts +0 -2
- package/lib/types/client/round-chart.d.ts +4 -1
- package/lib/types/client/usage-billing-settings.d.ts +19 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -844,6 +844,18 @@ function formatTokens(value) {
|
|
|
844
844
|
* 价源 = 腾讯云 TokenHub「模型价格」页(2026-11-04 更新)的官方 CN 价。
|
|
845
845
|
* Hy4 preview 条目与其价格一律不动——同 id 不同模型的收录不构成调价。
|
|
846
846
|
*
|
|
847
|
+
* 2026-11-16 扩容:补录腾讯混元 TokenHub 新上架的 **Hy4 flash**(官方 id
|
|
848
|
+
* `hy4-flash`,刊例价 ¥0.5 / ¥0.02(缓存命中)/ ¥2 每百万 token;官方价目页
|
|
849
|
+
* 2026-11-16 更新)。价源 = 腾讯云 TokenHub「模型价格」页的官方 CN 价
|
|
850
|
+
* (models.dev 实时目录尚无该模型条目,国内厂商按官方 CN 价优先的价源口径取
|
|
851
|
+
* 官方价,不做 USD 折算)。官方同期挂出限时折扣:**自该说明发布之日起至
|
|
852
|
+
* 2026-11-30 12:00:00(北京时间)按目录价格的 50% 结算** —— 刊例价留在 price
|
|
853
|
+
* 表,折扣按 promo 建模(只在计价/显示出口折算)。折扣起点取官方价目页
|
|
854
|
+
* 「最近更新时间」2026-11-16 12:15:30(北京时间)——这是本仓能取证的该说明上线
|
|
855
|
+
* 时刻,官方未给出更早的明确日期,故不向前追溯(promo 起点规则同 Hy4)。
|
|
856
|
+
* 本批只加新条目:既有 Hy4 / Hy4 preview 条目的价格与折扣窗口一律不动
|
|
857
|
+
* (本次官方价目页上 Hy4 仍是 ¥6/¥0.3/¥18,与目录现状逐字一致,不构成调价)。
|
|
858
|
+
*
|
|
847
859
|
* Time-of-day billing (peak/off-peak) is now real: DeepSeek V4 officially
|
|
848
860
|
* splits peak (09:00-12:00 / 14:00-18:00 Beijing) at 2x the off-peak rate
|
|
849
861
|
* from 2026-08-17, and Gemini's Flex tier discounts spare-capacity traffic.
|
|
@@ -1658,6 +1670,24 @@ const BUILTIN_MODEL_CATALOG = [
|
|
|
1658
1670
|
note: "限时 5 折至 2026-12-31"
|
|
1659
1671
|
}
|
|
1660
1672
|
},
|
|
1673
|
+
{
|
|
1674
|
+
key: "hunyuan-hy4-flash",
|
|
1675
|
+
name: "混元 Hy4 flash",
|
|
1676
|
+
provider: "腾讯混元",
|
|
1677
|
+
colorVar: "dsw-static-amber-400",
|
|
1678
|
+
price: {
|
|
1679
|
+
currency: "CNY",
|
|
1680
|
+
input: .5,
|
|
1681
|
+
cacheHit: .02,
|
|
1682
|
+
output: 2
|
|
1683
|
+
},
|
|
1684
|
+
promo: {
|
|
1685
|
+
factor: .5,
|
|
1686
|
+
startsAtMs: Date.UTC(2026, 10, 16, 4, 15, 30),
|
|
1687
|
+
endsAtMs: Date.UTC(2026, 10, 30, 4, 0, 0),
|
|
1688
|
+
note: "限时 5 折至 2026-11-30 12:00"
|
|
1689
|
+
}
|
|
1690
|
+
},
|
|
1661
1691
|
{
|
|
1662
1692
|
key: "hy-mt2-pro",
|
|
1663
1693
|
name: "混元 MT2-Pro",
|
|
@@ -4199,6 +4229,8 @@ const BUILTIN_MODEL_KEY_ALIASES = {
|
|
|
4199
4229
|
"hunyuan-hy4": "hunyuan-hy4",
|
|
4200
4230
|
"hy4-preview": "hunyuan-hy4-preview",
|
|
4201
4231
|
"hunyuan-hy4-preview": "hunyuan-hy4-preview",
|
|
4232
|
+
"hy4-flash": "hunyuan-hy4-flash",
|
|
4233
|
+
"hunyuan-hy4-flash": "hunyuan-hy4-flash",
|
|
4202
4234
|
"longcat-2.0": "longcat-2.0",
|
|
4203
4235
|
"longcat-2": "longcat-2.0",
|
|
4204
4236
|
"minicpm-v-4.5": "minicpm-v-4.5",
|
|
@@ -4969,6 +5001,312 @@ function deserializeFold(fold) {
|
|
|
4969
5001
|
...fold.title !== void 0 ? { title: fold.title } : {}
|
|
4970
5002
|
};
|
|
4971
5003
|
}
|
|
5004
|
+
/**
|
|
5005
|
+
* 兜底账本行的模型键归一与按日补价(issue #127)。
|
|
5006
|
+
*
|
|
5007
|
+
* 日志已删的会话只剩账本行:行内各模型桶的键是**落盘当时的原始 model id**
|
|
5008
|
+
* (如 `cn:deepseek-v4.1-flash`),此前既不归一化(与已归一的 `flash` 分成两行
|
|
5009
|
+
* 同名模型),也不重新计价(落盘时未收录的模型恒记 0 费 → 概览仍弹「未收录
|
|
5010
|
+
* 计价」、账单少算这笔钱)。报告者实测:同一中转通道下两行同名
|
|
5011
|
+
* DeepSeek V4.1 Flash,token 数完全一致——同一批数据被拆成两个 byModel 键。
|
|
5012
|
+
*
|
|
5013
|
+
* 本函数做两件事:
|
|
5014
|
+
*
|
|
5015
|
+
* 1. **键归一**:按 {@link resolveCatalogKey} 把各模型桶的键归到目录键,同键合并
|
|
5016
|
+
* (含模型×日、模型×日×通道、订阅计数与性能摘要各桶)。归一后账单只剩一行,
|
|
5017
|
+
* 客户端 {@link modelOf} 的显示名也不会再撞车。
|
|
5018
|
+
* 2. **按日补价**:落盘时未收录、而当前目录已收录的模型,用账本里现成的 token
|
|
5019
|
+
* 桶按目录价补算费用——日志已删就没有请求级时间戳,只能按自然日取峰/谷两个
|
|
5020
|
+
* 探针时刻后按 {@link DEFAULT_PEAK_SHARE} 混合(与客户端「目录价预估」同一
|
|
5021
|
+
* 口径);价格时代分段(峰谷时代 / flash 调价分界)与促销窗口仍按该时刻判定,
|
|
5022
|
+
* 不套现行价重算历史。
|
|
5023
|
+
*
|
|
5024
|
+
* 只补「落盘时未收录」的那部分:落盘时已计价的用量其费用原样保留(历史事件按
|
|
5025
|
+
* 事件发生时刻的官方规则计价,不能被按日估算覆盖);订阅通道的调用恒免费,
|
|
5026
|
+
* 不在未收录集合里,因此不会被补价。
|
|
5027
|
+
*
|
|
5028
|
+
* @param fold - 从账本行反序列化出的折叠(不得原地修改)。
|
|
5029
|
+
* @param officialProviderIds - 官方直连 provider 名单(决定官方/三方拆分)。
|
|
5030
|
+
* @returns 归一并补价后的折叠;无需改动时原样返回。
|
|
5031
|
+
*/
|
|
5032
|
+
function reconcileLedgerFold(fold, officialProviderIds) {
|
|
5033
|
+
const rawKeys = /* @__PURE__ */ new Set();
|
|
5034
|
+
for (const key of fold.byModel.keys()) rawKeys.add(key);
|
|
5035
|
+
for (const models of fold.byDayModels.values()) for (const key of models.keys()) rawKeys.add(key);
|
|
5036
|
+
for (const models of fold.byDayModelsSite.values()) for (const key of models.keys()) rawKeys.add(key);
|
|
5037
|
+
for (const key of fold.unpricedModels) rawKeys.add(key);
|
|
5038
|
+
const resolvedOf = /* @__PURE__ */ new Map();
|
|
5039
|
+
let rekey = false;
|
|
5040
|
+
for (const key of rawKeys) {
|
|
5041
|
+
const resolved = resolveCatalogKey(key);
|
|
5042
|
+
resolvedOf.set(key, resolved);
|
|
5043
|
+
if (resolved !== key) rekey = true;
|
|
5044
|
+
}
|
|
5045
|
+
const resolvedKeyOf = (key) => resolvedOf.get(key) ?? resolveCatalogKey(key);
|
|
5046
|
+
const repriceKeys = /* @__PURE__ */ new Set();
|
|
5047
|
+
for (const key of fold.unpricedModels) if (isPriced(resolvedKeyOf(key))) repriceKeys.add(key);
|
|
5048
|
+
if (!rekey && repriceKeys.size === 0) return fold;
|
|
5049
|
+
const byModel = /* @__PURE__ */ new Map();
|
|
5050
|
+
const byDay = /* @__PURE__ */ new Map();
|
|
5051
|
+
const byDayModels = /* @__PURE__ */ new Map();
|
|
5052
|
+
const byDayModelsSite = /* @__PURE__ */ new Map();
|
|
5053
|
+
const bySite = /* @__PURE__ */ new Map();
|
|
5054
|
+
const byTier = /* @__PURE__ */ new Map();
|
|
5055
|
+
const unpricedModels = /* @__PURE__ */ new Set();
|
|
5056
|
+
const planCalls = /* @__PURE__ */ new Map();
|
|
5057
|
+
const planSiteCalls = /* @__PURE__ */ new Map();
|
|
5058
|
+
const perfDigest = /* @__PURE__ */ new Map();
|
|
5059
|
+
const perfHourDigest = /* @__PURE__ */ new Map();
|
|
5060
|
+
for (const [key, cell] of fold.byModel) mergeUsageInto(usageCell(byModel, resolvedKeyOf(key)), cell);
|
|
5061
|
+
for (const [day, cell] of fold.byDay) byDay.set(day, { ...cell });
|
|
5062
|
+
for (const [day, models] of fold.byDayModels) {
|
|
5063
|
+
const target = /* @__PURE__ */ new Map();
|
|
5064
|
+
for (const [key, cell] of models) mergeUsageInto(usageCell(target, resolvedKeyOf(key)), cell);
|
|
5065
|
+
byDayModels.set(day, target);
|
|
5066
|
+
}
|
|
5067
|
+
for (const [day, models] of fold.byDayModelsSite) {
|
|
5068
|
+
const target = /* @__PURE__ */ new Map();
|
|
5069
|
+
for (const [key, sites] of models) {
|
|
5070
|
+
const siteTarget = /* @__PURE__ */ new Map();
|
|
5071
|
+
for (const [site, cell] of sites) mergeUsageInto(usageCell(siteTarget, site), cell);
|
|
5072
|
+
const resolved = resolvedKeyOf(key);
|
|
5073
|
+
const existing = target.get(resolved);
|
|
5074
|
+
if (existing === void 0) target.set(resolved, siteTarget);
|
|
5075
|
+
else for (const [site, cell] of siteTarget) mergeUsageInto(usageCell(existing, site), cell);
|
|
5076
|
+
}
|
|
5077
|
+
byDayModelsSite.set(day, target);
|
|
5078
|
+
}
|
|
5079
|
+
for (const [site, cell] of fold.bySite) bySite.set(site, { ...cell });
|
|
5080
|
+
for (const [tier, cell] of fold.byTier) byTier.set(tier, { ...cell });
|
|
5081
|
+
for (const key of fold.unpricedModels) {
|
|
5082
|
+
const resolved = resolvedKeyOf(key);
|
|
5083
|
+
if (!isPriced(resolved)) unpricedModels.add(resolved);
|
|
5084
|
+
}
|
|
5085
|
+
for (const [key, count] of fold.planCalls) {
|
|
5086
|
+
const resolved = resolvedKeyOf(key);
|
|
5087
|
+
planCalls.set(resolved, (planCalls.get(resolved) ?? 0) + count);
|
|
5088
|
+
}
|
|
5089
|
+
for (const [key, count] of fold.planSiteCalls) {
|
|
5090
|
+
const parsed = parsePlanSiteKey(key);
|
|
5091
|
+
if (parsed === void 0) {
|
|
5092
|
+
planSiteCalls.set(key, count);
|
|
5093
|
+
continue;
|
|
5094
|
+
}
|
|
5095
|
+
const next = planSiteKey(parsed.day, resolvedKeyOf(parsed.model), parsed.site);
|
|
5096
|
+
planSiteCalls.set(next, (planSiteCalls.get(next) ?? 0) + count);
|
|
5097
|
+
}
|
|
5098
|
+
for (const [key, digest] of fold.perfDigest) {
|
|
5099
|
+
const resolved = resolvedKeyOf(key);
|
|
5100
|
+
const existing = perfDigest.get(resolved);
|
|
5101
|
+
perfDigest.set(resolved, existing === void 0 ? digest : mergeModelDigest(existing, digest));
|
|
5102
|
+
}
|
|
5103
|
+
for (const [hour, models] of fold.perfHourDigest) {
|
|
5104
|
+
const target = /* @__PURE__ */ new Map();
|
|
5105
|
+
for (const [key, digest] of models) {
|
|
5106
|
+
const resolved = resolvedKeyOf(key);
|
|
5107
|
+
const existing = target.get(resolved);
|
|
5108
|
+
target.set(resolved, existing === void 0 ? digest : mergeHourDigest(existing, digest));
|
|
5109
|
+
}
|
|
5110
|
+
perfHourDigest.set(hour, target);
|
|
5111
|
+
}
|
|
5112
|
+
let addedCost = 0;
|
|
5113
|
+
let addedInput = 0;
|
|
5114
|
+
let addedOutput = 0;
|
|
5115
|
+
let addedOfficial = 0;
|
|
5116
|
+
let addedPeak = 0;
|
|
5117
|
+
let addedOff = 0;
|
|
5118
|
+
for (const [day, models] of fold.byDayModels) for (const [rawKey, cell] of models) {
|
|
5119
|
+
if (!repriceKeys.has(rawKey)) continue;
|
|
5120
|
+
const resolved = resolvedKeyOf(rawKey);
|
|
5121
|
+
const entry = modelOf(resolved);
|
|
5122
|
+
const repriced = repriceCellByDay(entry, cell, day);
|
|
5123
|
+
const dayCost = repriced.cost;
|
|
5124
|
+
const dayInput = repriced.inputCost;
|
|
5125
|
+
const dayOutput = repriced.outputCost;
|
|
5126
|
+
const dayPeak = repriced.peakCost;
|
|
5127
|
+
const dayOff = repriced.offCost;
|
|
5128
|
+
let dayOfficial = 0;
|
|
5129
|
+
const siteCells = fold.byDayModelsSite.get(day)?.get(rawKey);
|
|
5130
|
+
if (siteCells !== void 0 && siteCells.size > 0) for (const [site, siteCell] of siteCells) {
|
|
5131
|
+
const siteRepriced = repriceCellByDay(entry, siteCell, day);
|
|
5132
|
+
const official = isOfficialSiteBucket(site, officialProviderIds);
|
|
5133
|
+
if (official) dayOfficial += siteRepriced.cost;
|
|
5134
|
+
const siteTarget = byDayModelsSite.get(day)?.get(resolved)?.get(site);
|
|
5135
|
+
if (siteTarget !== void 0) {
|
|
5136
|
+
siteTarget.cost += siteRepriced.cost;
|
|
5137
|
+
if (official) siteTarget.officialCost += siteRepriced.cost;
|
|
5138
|
+
}
|
|
5139
|
+
const siteBucketCell = bySite.get(site);
|
|
5140
|
+
if (siteBucketCell !== void 0) {
|
|
5141
|
+
siteBucketCell.cost += siteRepriced.cost;
|
|
5142
|
+
if (official) siteBucketCell.officialCost += siteRepriced.cost;
|
|
5143
|
+
}
|
|
5144
|
+
}
|
|
5145
|
+
const modelCell = byModel.get(resolved);
|
|
5146
|
+
if (modelCell !== void 0) {
|
|
5147
|
+
modelCell.cost += dayCost;
|
|
5148
|
+
modelCell.officialCost += dayOfficial;
|
|
5149
|
+
}
|
|
5150
|
+
const dayCell = byDay.get(day);
|
|
5151
|
+
if (dayCell !== void 0) {
|
|
5152
|
+
dayCell.cost += dayCost;
|
|
5153
|
+
dayCell.officialCost += dayOfficial;
|
|
5154
|
+
}
|
|
5155
|
+
const dayModelCell = byDayModels.get(day)?.get(resolved);
|
|
5156
|
+
if (dayModelCell !== void 0) {
|
|
5157
|
+
dayModelCell.cost += dayCost;
|
|
5158
|
+
dayModelCell.officialCost += dayOfficial;
|
|
5159
|
+
}
|
|
5160
|
+
addedCost += dayCost;
|
|
5161
|
+
addedInput += dayInput;
|
|
5162
|
+
addedOutput += dayOutput;
|
|
5163
|
+
addedOfficial += dayOfficial;
|
|
5164
|
+
addedPeak += dayPeak;
|
|
5165
|
+
addedOff += dayOff;
|
|
5166
|
+
}
|
|
5167
|
+
const tierPeak = byTier.get("peak");
|
|
5168
|
+
if (tierPeak !== void 0) tierPeak.cost += addedPeak;
|
|
5169
|
+
const tierOff = byTier.get("offPeak");
|
|
5170
|
+
if (tierOff !== void 0) tierOff.cost += addedOff;
|
|
5171
|
+
const turns = fold.turns.map((row) => {
|
|
5172
|
+
const resolved = resolvedKeyOf(row.model);
|
|
5173
|
+
if (!repriceKeys.has(row.model) || row.cost > 0) return {
|
|
5174
|
+
...row,
|
|
5175
|
+
model: resolved
|
|
5176
|
+
};
|
|
5177
|
+
const cost = computeCostAt(modelOf(resolved), {
|
|
5178
|
+
input: row.input,
|
|
5179
|
+
cacheHit: row.cacheHit,
|
|
5180
|
+
cacheMiss: row.cacheMiss,
|
|
5181
|
+
cacheWrite: 0,
|
|
5182
|
+
output: row.output
|
|
5183
|
+
}, row.startedAt);
|
|
5184
|
+
return {
|
|
5185
|
+
...row,
|
|
5186
|
+
model: resolved,
|
|
5187
|
+
cost
|
|
5188
|
+
};
|
|
5189
|
+
});
|
|
5190
|
+
const roles = {
|
|
5191
|
+
...fold.roles,
|
|
5192
|
+
inputCost: fold.roles.inputCost + addedInput,
|
|
5193
|
+
outputCost: fold.roles.outputCost + addedOutput
|
|
5194
|
+
};
|
|
5195
|
+
const total = {
|
|
5196
|
+
...fold.total,
|
|
5197
|
+
cost: fold.total.cost + addedCost,
|
|
5198
|
+
officialCost: fold.total.officialCost + addedOfficial
|
|
5199
|
+
};
|
|
5200
|
+
return {
|
|
5201
|
+
...fold,
|
|
5202
|
+
total,
|
|
5203
|
+
byModel,
|
|
5204
|
+
byDay,
|
|
5205
|
+
byDayModels,
|
|
5206
|
+
byDayModelsSite,
|
|
5207
|
+
bySite,
|
|
5208
|
+
byTier,
|
|
5209
|
+
unpricedModels,
|
|
5210
|
+
planCalls,
|
|
5211
|
+
planSiteCalls,
|
|
5212
|
+
perfDigest,
|
|
5213
|
+
perfHourDigest,
|
|
5214
|
+
turns,
|
|
5215
|
+
roles
|
|
5216
|
+
};
|
|
5217
|
+
}
|
|
5218
|
+
/**
|
|
5219
|
+
* 站点桶键能否还原官方直连(官方/三方费用拆分用)。
|
|
5220
|
+
*
|
|
5221
|
+
* 与 {@link officialChannelOf} 的通道判定同口径:配置了 officialProviderIds 时
|
|
5222
|
+
* 以名单为准(站点桶还原不出 provider,保守按三方计);未配置时
|
|
5223
|
+
* `direct:<provider>` 看 provider 是否官方、`site:<origin>` 看 origin 是否官方。
|
|
5224
|
+
*/
|
|
5225
|
+
function isOfficialSiteBucket(siteKey, officialProviderIds) {
|
|
5226
|
+
if (siteKey.startsWith("direct:")) {
|
|
5227
|
+
const provider = siteKey.slice(7);
|
|
5228
|
+
return officialProviderIds !== void 0 ? officialProviderIds.has(provider) : isOfficialProvider(provider);
|
|
5229
|
+
}
|
|
5230
|
+
if (siteKey.startsWith("site:")) {
|
|
5231
|
+
if (officialProviderIds !== void 0) return false;
|
|
5232
|
+
return siteKey.slice(5) === OFFICIAL_DEEPSEEK_ORIGIN;
|
|
5233
|
+
}
|
|
5234
|
+
return false;
|
|
5235
|
+
}
|
|
5236
|
+
/** 解析 {@link planSiteKey} 的 JSON 数组键;形状不符时返回 undefined。 */
|
|
5237
|
+
function parsePlanSiteKey(key) {
|
|
5238
|
+
try {
|
|
5239
|
+
const parsed = JSON.parse(key);
|
|
5240
|
+
if (!Array.isArray(parsed) || parsed.length !== 3) return void 0;
|
|
5241
|
+
const [day, model, site] = parsed;
|
|
5242
|
+
if (typeof day !== "string" || typeof model !== "string" || typeof site !== "string") return void 0;
|
|
5243
|
+
return {
|
|
5244
|
+
day,
|
|
5245
|
+
model,
|
|
5246
|
+
site
|
|
5247
|
+
};
|
|
5248
|
+
} catch {
|
|
5249
|
+
return;
|
|
5250
|
+
}
|
|
5251
|
+
}
|
|
5252
|
+
/**
|
|
5253
|
+
* 本地自然日(`YYYY-MM-DD`)内、北京时间某小时对应的时刻(epoch ms)。
|
|
5254
|
+
*
|
|
5255
|
+
* 兜底行按日补价时用两个探针时刻分别落峰档与谷档(北京时间 10:00 / 20:00):
|
|
5256
|
+
* 日志已删的会话没有请求级时间戳,只能按日估算(与客户端「目录价预估」同一口径)。
|
|
5257
|
+
*/
|
|
5258
|
+
function dayMomentAtBeijingHour(day, beijingHour) {
|
|
5259
|
+
const parts = day.split("-");
|
|
5260
|
+
const year = Number(parts[0]);
|
|
5261
|
+
const month = Number(parts[1]);
|
|
5262
|
+
const date = Number(parts[2]);
|
|
5263
|
+
if (!Number.isFinite(year) || !Number.isFinite(month) || !Number.isFinite(date)) return Date.now();
|
|
5264
|
+
const base = new Date(year, month - 1, date, 0, 0, 0, 0).getTime();
|
|
5265
|
+
if (!Number.isFinite(base)) return Date.now();
|
|
5266
|
+
return base + (beijingHour - (new Date(base + 288e5).getUTCHours() + 24) % 24 + 24) % 24 * 36e5;
|
|
5267
|
+
}
|
|
5268
|
+
/**
|
|
5269
|
+
* 按自然日给一个 token 桶补价:峰/谷两档各取一个探针时刻后按比例混合。
|
|
5270
|
+
*
|
|
5271
|
+
* 价格时代分段(峰谷时代起点、flash 调价分界)与促销窗口由
|
|
5272
|
+
* {@link computeCostAt} 按该时刻判定——不套现行价重算历史。输出侧费用单独算
|
|
5273
|
+
* 一遍(计价对 token 桶是线性的),供角色归因拆分输入/输出两侧。
|
|
5274
|
+
*/
|
|
5275
|
+
function repriceCellByDay(entry, cell, day) {
|
|
5276
|
+
const buckets = {
|
|
5277
|
+
input: cell.input,
|
|
5278
|
+
cacheHit: cell.cacheHit,
|
|
5279
|
+
cacheMiss: cell.cacheMiss,
|
|
5280
|
+
cacheWrite: cell.cacheWrite ?? 0,
|
|
5281
|
+
output: cell.output
|
|
5282
|
+
};
|
|
5283
|
+
const outputOnly = {
|
|
5284
|
+
input: 0,
|
|
5285
|
+
cacheHit: 0,
|
|
5286
|
+
cacheMiss: 0,
|
|
5287
|
+
cacheWrite: 0,
|
|
5288
|
+
output: cell.output
|
|
5289
|
+
};
|
|
5290
|
+
const tsPeak = dayMomentAtBeijingHour(day, LEDGER_PEAK_PROBE_HOUR);
|
|
5291
|
+
const tsOff = dayMomentAtBeijingHour(day, LEDGER_OFFPEAK_PROBE_HOUR);
|
|
5292
|
+
const peak = computeCostAt(entry, buckets, tsPeak);
|
|
5293
|
+
const off = computeCostAt(entry, buckets, tsOff);
|
|
5294
|
+
const peakOutput = computeCostAt(entry, outputOnly, tsPeak);
|
|
5295
|
+
const offOutput = computeCostAt(entry, outputOnly, tsOff);
|
|
5296
|
+
const cost = peak * DEFAULT_PEAK_SHARE + off * .5;
|
|
5297
|
+
const outputCost = peakOutput * DEFAULT_PEAK_SHARE + offOutput * .5;
|
|
5298
|
+
return {
|
|
5299
|
+
cost,
|
|
5300
|
+
inputCost: cost - outputCost,
|
|
5301
|
+
outputCost,
|
|
5302
|
+
peakCost: peak * DEFAULT_PEAK_SHARE,
|
|
5303
|
+
offCost: off * .5
|
|
5304
|
+
};
|
|
5305
|
+
}
|
|
5306
|
+
/** 兜底行补价时的峰档探针时刻(北京时间小时)。 */
|
|
5307
|
+
const LEDGER_PEAK_PROBE_HOUR = 10;
|
|
5308
|
+
/** 兜底行补价时的谷档探针时刻(北京时间小时)。 */
|
|
5309
|
+
const LEDGER_OFFPEAK_PROBE_HOUR = 20;
|
|
4972
5310
|
/** Runtime boundary for a user-editable/corrupt ledger file. Invalid rows are ignored. */
|
|
4973
5311
|
function ledgerSessionsOf(value) {
|
|
4974
5312
|
if (value === null || typeof value !== "object") return [];
|
|
@@ -5482,6 +5820,16 @@ function createUsageAggregator(persistence, options = {}) {
|
|
|
5482
5820
|
return fold;
|
|
5483
5821
|
};
|
|
5484
5822
|
})();
|
|
5823
|
+
const reconciledFoldOf = (() => {
|
|
5824
|
+
const memo = /* @__PURE__ */ new WeakMap();
|
|
5825
|
+
return (serialized) => {
|
|
5826
|
+
const hit = memo.get(serialized);
|
|
5827
|
+
if (hit !== void 0) return hit;
|
|
5828
|
+
const fold = reconcileLedgerFold(deserializedFoldOf(serialized), officialProviderIds);
|
|
5829
|
+
memo.set(serialized, fold);
|
|
5830
|
+
return fold;
|
|
5831
|
+
};
|
|
5832
|
+
})();
|
|
5485
5833
|
/** 每次聚合取最新的 provider 路由视图(中转站零配置发现);缺省按空处理(全部未知路由)。
|
|
5486
5834
|
* 叠加已注册 adapter 的通道(issue #91):宿主 llm 注册表里的 provider 合成无 baseURL
|
|
5487
5835
|
* 的空路由视图——siteRefOf 的路由命中分支正是「无 origin 直连」的语义,归位
|
|
@@ -5647,7 +5995,7 @@ function createUsageAggregator(persistence, options = {}) {
|
|
|
5647
5995
|
const subOf = subParentOf(meta);
|
|
5648
5996
|
const ledgerRow = ledger.get(id);
|
|
5649
5997
|
if (ledgerRow !== void 0 && ledgerRow.stamp !== void 0 && stamp !== null && ledgerRow.stamp === stamp && (ledgerRow.foldVersion ?? 1) === 24 && ledgerRow.fingerprint === foldFingerprint && !foldNeedsReprice(ledgerRow.fold)) {
|
|
5650
|
-
const fold =
|
|
5998
|
+
const fold = reconciledFoldOf(ledgerRow.fold);
|
|
5651
5999
|
folds.push({
|
|
5652
6000
|
id,
|
|
5653
6001
|
...cwd === void 0 ? {} : { cwd },
|
|
@@ -5776,7 +6124,7 @@ function createUsageAggregator(persistence, options = {}) {
|
|
|
5776
6124
|
if (included.has(entry.id)) continue;
|
|
5777
6125
|
try {
|
|
5778
6126
|
const stale = (entry.foldVersion ?? 1) < 24 || entry.fingerprint !== foldFingerprint;
|
|
5779
|
-
const fold =
|
|
6127
|
+
const fold = reconciledFoldOf(entry.fold);
|
|
5780
6128
|
const hint = titleHints.get(entry.id);
|
|
5781
6129
|
folds.push({
|
|
5782
6130
|
id: entry.id,
|
|
@@ -5961,6 +6309,7 @@ function createUsageAggregator(persistence, options = {}) {
|
|
|
5961
6309
|
byDayModels: toModelDayRecord(byDayModels),
|
|
5962
6310
|
...byDayModelsSite.size === 0 ? {} : { byDayModelsSite: toModelDaySiteRecord(byDayModelsSite) },
|
|
5963
6311
|
bySession: sessionRows.slice(0, 100),
|
|
6312
|
+
bySessionTotal: sessionRows.length,
|
|
5964
6313
|
byTurn: turnRows.slice(0, 200),
|
|
5965
6314
|
byWorkspace: workspaces.slice(0, 100),
|
|
5966
6315
|
...byTier.size === 0 ? {} : { byTier: {
|
|
@@ -6016,7 +6365,7 @@ function createUsageAggregator(persistence, options = {}) {
|
|
|
6016
6365
|
const row = ledger.get(sessionId);
|
|
6017
6366
|
if (row === void 0) return void 0;
|
|
6018
6367
|
try {
|
|
6019
|
-
const fold =
|
|
6368
|
+
const fold = reconciledFoldOf(row.fold);
|
|
6020
6369
|
return {
|
|
6021
6370
|
calls: fold.total.calls,
|
|
6022
6371
|
cost: fold.total.cost,
|
package/lib/types/aggregate.d.ts
CHANGED
|
@@ -324,6 +324,12 @@ export interface UsageStatsDocument {
|
|
|
324
324
|
byTool?: Record<string, number>;
|
|
325
325
|
/** 会话明细:按费用倒序,封顶 {@link SESSION_ROW_LIMIT} 行;旧快照可能缺失。 */
|
|
326
326
|
bySession: SessionUsageRow[];
|
|
327
|
+
/**
|
|
328
|
+
* 会话总数(未封顶):`bySession` 只带花费前 {@link SESSION_ROW_LIMIT} 行,
|
|
329
|
+
* 真实总数此前从未下发——会话数超过封顶时面板只能说「共 100 个会话」,是错的。
|
|
330
|
+
* 旧快照缺该字段,客户端回退按明细行数。
|
|
331
|
+
*/
|
|
332
|
+
bySessionTotal?: number;
|
|
327
333
|
/** 每轮费用明细:按起始时间倒序,封顶 {@link TURN_ROW_LIMIT} 行;旧快照可能缺失。 */
|
|
328
334
|
byTurn?: TurnUsageRow[];
|
|
329
335
|
/** 工作区聚合:按 cwd 末级目录归并,按费用倒序;旧快照可能缺失。 */
|
|
@@ -71,6 +71,8 @@ export declare function TokenPanel(props: {
|
|
|
71
71
|
models?: readonly TrendSeriesModel[];
|
|
72
72
|
/** 金额格式化(跟随仪表盘币种切换):费用构成区块展示用。 */
|
|
73
73
|
money: (cny: number) => string;
|
|
74
|
+
/** 通道桶 key → 通道显示名(issue #126:模型行标注提供方)。 */
|
|
75
|
+
channelName?: (siteKey: string) => string;
|
|
74
76
|
t: (key: UsageBillingKey) => string;
|
|
75
77
|
}): React.ReactNode;
|
|
76
78
|
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 通道可见性(issue #126 需求):按**通道桶**隐藏部分提供商 / 通道。
|
|
3
|
+
*
|
|
4
|
+
* 报告者场景:通道一多(官方、直连、几个中转、未知路由)时账单列表很长,希望
|
|
5
|
+
* 在设置里勾掉不常看的几个,只留常看的通道。
|
|
6
|
+
*
|
|
7
|
+
* 口径与边界(写死在这里,避免各视图各算一套):
|
|
8
|
+
* - **过滤粒度 = 通道桶 key**(`site:<origin>` / `direct:<provider>` / `unknown`),
|
|
9
|
+
* 不是显示名——显示名随界面语言变(中英),桶 key 稳定,偏好能跨语言沿用。
|
|
10
|
+
* - **只扣可归属的用量**:隐藏通道的用量从 total / byDay / byDayModels /
|
|
11
|
+
* byModel / bySite / byDayModelsSite 中扣除;**无法归属通道的用量保留**
|
|
12
|
+
* (旧格式会话的账本行没有三维维度,无从判断属于哪个通道——宁可多算,
|
|
13
|
+
* 不可静默丢数)。
|
|
14
|
+
* - **无通道维度的维度保持全量口径**:会话 / 工具 / 角色 / 工作区 / 性能 /
|
|
15
|
+
* 峰谷等没有通道切分,隐藏通道不影响它们;界面需注明这一口径差。
|
|
16
|
+
* - 三维数据缺失(旧快照)时**整体不生效**:没有可归属数据就无从过滤,
|
|
17
|
+
* 此时按未过滤渲染,而不是把用量显示成 0。
|
|
18
|
+
*/
|
|
19
|
+
import type { UsageStats } from './types.ts';
|
|
20
|
+
/** 一个通道桶的用量汇总(全量日期)。 */
|
|
21
|
+
export interface ChannelUsage {
|
|
22
|
+
/** 通道桶 key(`site:<origin>` / `direct:<provider>` / `unknown`)。 */
|
|
23
|
+
siteKey: string;
|
|
24
|
+
calls: number;
|
|
25
|
+
input: number;
|
|
26
|
+
output: number;
|
|
27
|
+
cacheHit: number;
|
|
28
|
+
cacheMiss: number;
|
|
29
|
+
cost: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 汇总各通道桶的用量(全量日期,按费用降序;同费用按桶 key 稳定排序)。
|
|
33
|
+
* @param stats - usage-stats 文档(读 byDayModelsSite 三维格)。
|
|
34
|
+
* @returns 每个通道桶一行;无三维数据时返回空数组。
|
|
35
|
+
*/
|
|
36
|
+
export declare function channelUsageOf(stats: UsageStats): readonly ChannelUsage[];
|
|
37
|
+
/**
|
|
38
|
+
* 按显示名归并的通道分组(同名多桶合并:直连与官方同名的两个桶归一行)。
|
|
39
|
+
*/
|
|
40
|
+
export interface ChannelGroup {
|
|
41
|
+
/** 显示名(界面语言下的通道名;未知路由由渲染层兜底文案)。 */
|
|
42
|
+
name: string;
|
|
43
|
+
/** 组内全部通道桶 key —— 隐藏任一即整组隐藏(用户看到的是「这个名字」)。 */
|
|
44
|
+
siteKeys: readonly string[];
|
|
45
|
+
calls: number;
|
|
46
|
+
/** 组内 token 合计(输入 + 输出)。 */
|
|
47
|
+
tokens: number;
|
|
48
|
+
cost: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 把通道桶按显示名归并成组(同名多桶合并),按费用降序。
|
|
52
|
+
* @param rows - 通道桶用量(channelUsageOf 的产物)。
|
|
53
|
+
* @param nameOf - 桶 key → 显示名的解析函数(界面语言相关)。
|
|
54
|
+
* @returns 通道分组列表。
|
|
55
|
+
*/
|
|
56
|
+
export declare function groupChannelsByName(rows: readonly ChannelUsage[], nameOf: (siteKey: string) => string): readonly ChannelGroup[];
|
|
57
|
+
/**
|
|
58
|
+
* 按隐藏通道过滤统计文档。
|
|
59
|
+
*
|
|
60
|
+
* 扣除隐藏通道在 total / byDay / byDayModels / byModel / bySite /
|
|
61
|
+
* byDayModelsSite 中的用量;无通道维度的维度(会话 / 工具 / 角色 / 工作区 /
|
|
62
|
+
* 性能 / 峰谷 / reasoning / 官方口径)保持全量。三维数据缺失时整体原样返回。
|
|
63
|
+
* @param stats - 原始统计文档。
|
|
64
|
+
* @param hidden - 隐藏的通道桶 key 集合。
|
|
65
|
+
* @returns 过滤后的统计文档(未命中任何隐藏通道时返回原对象引用)。
|
|
66
|
+
*/
|
|
67
|
+
export declare function filterStatsByChannels(stats: UsageStats, hidden: ReadonlySet<string>): UsageStats;
|
|
68
|
+
//# sourceMappingURL=channel-visibility.d.ts.map
|
|
@@ -190,6 +190,12 @@ export interface UsageStats {
|
|
|
190
190
|
lowBalanceThreshold?: number;
|
|
191
191
|
/** 会话明细(按费用倒序,服务端已封顶);旧快照可能缺失。 */
|
|
192
192
|
bySession?: readonly SessionBillingRow[];
|
|
193
|
+
/**
|
|
194
|
+
* 会话总数(未封顶):`bySession` 只带花费前 N 行,真实总数此前从未下发——
|
|
195
|
+
* 会话数超过封顶时面板只能说「共 100 个会话」,是错的。缺省回退按明细行数
|
|
196
|
+
* (旧快照没有该字段)。
|
|
197
|
+
*/
|
|
198
|
+
bySessionTotal?: number;
|
|
193
199
|
total: {
|
|
194
200
|
calls: number;
|
|
195
201
|
input: number;
|
|
@@ -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' | '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';
|
|
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' | 'sessionsViewTop' | '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' | 'channelVisibility' | 'channelVisibilityHint' | 'channelVisibilityShowAll' | 'channelVisibilityHidden' | 'channelVisibilityEmpty' | '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>;
|
|
@@ -431,8 +431,6 @@ export declare function applyPromo(entry: ModelEntry, nowMs: number): ModelEntry
|
|
|
431
431
|
* @param nowMs - 促销判定时刻;缺省当前时刻。
|
|
432
432
|
*/
|
|
433
433
|
export declare function catalogEntries(nowMs?: number): readonly ModelEntry[];
|
|
434
|
-
/** Resolve a price-table row by its CSS variable name (theme token or fallback color). */
|
|
435
|
-
export declare function resolveToken(name: string): string;
|
|
436
434
|
/**
|
|
437
435
|
* Estimate the CNY cost of one model's token usage, mixing the peak and
|
|
438
436
|
* off-peak bands by the given peak share (flat-priced models cost the same in
|
|
@@ -15,8 +15,6 @@ type ProviderLang = 'zh' | 'en';
|
|
|
15
15
|
* @returns 本地化后的显示名。
|
|
16
16
|
*/
|
|
17
17
|
export declare function localizeProviderName(name: string, lang: ProviderLang): string;
|
|
18
|
-
/** 判断一个厂商显示名是否包含中文(用于测试/守卫:保证映射覆盖完整)。 */
|
|
19
|
-
export declare function hasCjk(name: string): boolean;
|
|
20
18
|
/**
|
|
21
19
|
* 站点桶 key(`site:<origin>` / `direct:<provider>` / `unknown`)→ 通道显示名。
|
|
22
20
|
* @param siteKey - 聚合文档 bySite 的桶 key。
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
* maximum. Turns flagged by {@link flagAnomalies} get a warning outline and a
|
|
6
6
|
* corner marker; hover shows the turn's model, cost, and window time. Styling
|
|
7
7
|
* lives in the billing CSS module (`.rounds*`).
|
|
8
|
+
*
|
|
9
|
+
* 入参按服务端口径是**倒序**(`byTurn` 按 startedAt 倒序下发,最新在前),
|
|
10
|
+
* 组件内部排成升序再取末尾 N 轮——展示的是「最新 N 轮、最新在右」。
|
|
8
11
|
*/
|
|
9
12
|
import type { AnomalyFlag } from './anomaly.ts';
|
|
10
13
|
import { type CostCurrency } from './pricing.ts';
|
|
@@ -23,7 +26,7 @@ export interface RoundChartRow {
|
|
|
23
26
|
}
|
|
24
27
|
/**
|
|
25
28
|
* Render the per-turn cost bars.
|
|
26
|
-
* @param props.rounds -
|
|
29
|
+
* @param props.rounds - 逐轮行(服务端按 startedAt 倒序下发;组件内部排升序后取最新 N 轮)。
|
|
27
30
|
* @param props.flags - spike flags matched by sessionId+turn.
|
|
28
31
|
* @param props.currency - display currency for the amount labels.
|
|
29
32
|
* @param props.t - locale function for the model label.
|
|
@@ -109,6 +109,25 @@ export declare const SITE_LIST_STORAGE_KEY = "dsh.ui-usage-billing.sites";
|
|
|
109
109
|
export declare function loadSiteListPrefs(): SiteListPrefs;
|
|
110
110
|
/** 写入站点列表偏好。失败静默(展示偏好非关键)。 */
|
|
111
111
|
export declare function saveSiteListPrefs(prefs: SiteListPrefs): void;
|
|
112
|
+
/**
|
|
113
|
+
* 通道可见性偏好(issue #126 需求):隐藏部分提供商 / 通道。
|
|
114
|
+
* 纯 client 偏好,存 localStorage(不依赖 node 半区接口/设置 schema)。
|
|
115
|
+
*
|
|
116
|
+
* 存**通道桶 key**(`site:<origin>` / `direct:<provider>` / `unknown`)而不是
|
|
117
|
+
* 显示名——显示名随界面语言变(中英),桶 key 稳定,偏好能跨语言沿用。
|
|
118
|
+
*/
|
|
119
|
+
export interface ChannelVisibilityPrefs {
|
|
120
|
+
/** 隐藏的通道桶 key 列表;空 = 全部显示。 */
|
|
121
|
+
hidden: readonly string[];
|
|
122
|
+
}
|
|
123
|
+
/** 默认通道可见性偏好:全部显示(保持历史行为)。 */
|
|
124
|
+
export declare const DEFAULT_CHANNEL_VISIBILITY_PREFS: ChannelVisibilityPrefs;
|
|
125
|
+
/** localStorage key(与其他 `dsh.ui-usage-billing.*` 偏好同命名空间)。 */
|
|
126
|
+
export declare const CHANNEL_VISIBILITY_STORAGE_KEY = "dsh.ui-usage-billing.channels";
|
|
127
|
+
/** 读取通道可见性偏好(含损坏/缺失回退到默认)。仅在浏览器半区调用。 */
|
|
128
|
+
export declare function loadChannelVisibilityPrefs(): ChannelVisibilityPrefs;
|
|
129
|
+
/** 写入通道可见性偏好。失败静默(展示偏好非关键)。 */
|
|
130
|
+
export declare function saveChannelVisibilityPrefs(prefs: ChannelVisibilityPrefs): void;
|
|
112
131
|
/**
|
|
113
132
|
* 即时代费条(平价消耗胶囊,composer dock 的 LiveCostBar)的显示偏好。
|
|
114
133
|
* 纯 client 偏好,存 localStorage(不依赖 node 半区接口/设置 schema);
|
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
|
+
"version": "1.8.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|
|
7
7
|
"deepseek",
|