@kenz1117/dsh-ui-usage-billing 1.8.7 → 1.8.9

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
@@ -5001,6 +5001,312 @@ function deserializeFold(fold) {
5001
5001
  ...fold.title !== void 0 ? { title: fold.title } : {}
5002
5002
  };
5003
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;
5004
5310
  /** Runtime boundary for a user-editable/corrupt ledger file. Invalid rows are ignored. */
5005
5311
  function ledgerSessionsOf(value) {
5006
5312
  if (value === null || typeof value !== "object") return [];
@@ -5514,6 +5820,16 @@ function createUsageAggregator(persistence, options = {}) {
5514
5820
  return fold;
5515
5821
  };
5516
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
+ })();
5517
5833
  /** 每次聚合取最新的 provider 路由视图(中转站零配置发现);缺省按空处理(全部未知路由)。
5518
5834
  * 叠加已注册 adapter 的通道(issue #91):宿主 llm 注册表里的 provider 合成无 baseURL
5519
5835
  * 的空路由视图——siteRefOf 的路由命中分支正是「无 origin 直连」的语义,归位
@@ -5679,7 +5995,7 @@ function createUsageAggregator(persistence, options = {}) {
5679
5995
  const subOf = subParentOf(meta);
5680
5996
  const ledgerRow = ledger.get(id);
5681
5997
  if (ledgerRow !== void 0 && ledgerRow.stamp !== void 0 && stamp !== null && ledgerRow.stamp === stamp && (ledgerRow.foldVersion ?? 1) === 24 && ledgerRow.fingerprint === foldFingerprint && !foldNeedsReprice(ledgerRow.fold)) {
5682
- const fold = deserializedFoldOf(ledgerRow.fold);
5998
+ const fold = reconciledFoldOf(ledgerRow.fold);
5683
5999
  folds.push({
5684
6000
  id,
5685
6001
  ...cwd === void 0 ? {} : { cwd },
@@ -5808,7 +6124,7 @@ function createUsageAggregator(persistence, options = {}) {
5808
6124
  if (included.has(entry.id)) continue;
5809
6125
  try {
5810
6126
  const stale = (entry.foldVersion ?? 1) < 24 || entry.fingerprint !== foldFingerprint;
5811
- const fold = deserializedFoldOf(entry.fold);
6127
+ const fold = reconciledFoldOf(entry.fold);
5812
6128
  const hint = titleHints.get(entry.id);
5813
6129
  folds.push({
5814
6130
  id: entry.id,
@@ -6049,7 +6365,7 @@ function createUsageAggregator(persistence, options = {}) {
6049
6365
  const row = ledger.get(sessionId);
6050
6366
  if (row === void 0) return void 0;
6051
6367
  try {
6052
- const fold = deserializedFoldOf(row.fold);
6368
+ const fold = reconciledFoldOf(row.fold);
6053
6369
  return {
6054
6370
  calls: fold.total.calls,
6055
6371
  cost: fold.total.cost,
@@ -7381,27 +7697,40 @@ const pricingGate = createCooldownGate({
7381
7697
  cooldownMs: 6e4
7382
7698
  });
7383
7699
  /**
7384
- * USD → CNY 汇率源,按顺序尝试:国内可达的腾讯财经行情(免 key、`~` 分隔
7385
- * 第 4 个字段为价格)优先,国外 open.er-api.com 兜底。任一源失败自动落到
7386
- * 下一个;全部失败由调用方降级内置汇率。
7700
+ * 解析 `{ rates: { CNY: number } }` 结构的汇率 JSON(open.er-api.com 与 AllRatesToday 通用)。
7701
+ * @param text - 响应正文。
7702
+ * @returns CNY 汇率;结构不符或非正数时 undefined。
7387
7703
  */
7388
- const RATE_SOURCES = [{
7389
- url: "https://qt.gtimg.cn/q=whUSDCNY",
7390
- parse: (text) => {
7391
- const price = /"([^"]*)"/.exec(text)?.[1]?.split("~")[3];
7392
- return price !== void 0 && price !== "" ? Number(price) : void 0;
7704
+ function parseRatesJsonCny(text) {
7705
+ try {
7706
+ const cny = JSON.parse(text).rates?.CNY;
7707
+ return typeof cny === "number" && Number.isFinite(cny) && cny > 0 ? cny : void 0;
7708
+ } catch {
7709
+ return;
7393
7710
  }
7394
- }, {
7395
- url: "https://open.er-api.com/v6/latest/USD",
7396
- parse: (text) => {
7397
- try {
7398
- const cny = JSON.parse(text).rates?.CNY;
7399
- return typeof cny === "number" && Number.isFinite(cny) && cny > 0 ? cny : void 0;
7400
- } catch {
7401
- return;
7711
+ }
7712
+ /**
7713
+ * USD → CNY 汇率源,按顺序尝试:国内可达的腾讯财经行情(免 key、`~` 分隔
7714
+ * 第 4 个字段为价格)优先,国外 open.er-api.com 兜底,再退到 AllRatesToday
7715
+ * 免 key 端点(同结构)。任一源失败自动落到下一个;全部失败由调用方降级内置汇率。
7716
+ */
7717
+ const RATE_SOURCES = [
7718
+ {
7719
+ url: "https://qt.gtimg.cn/q=whUSDCNY",
7720
+ parse: (text) => {
7721
+ const price = /"([^"]*)"/.exec(text)?.[1]?.split("~")[3];
7722
+ return price !== void 0 && price !== "" ? Number(price) : void 0;
7402
7723
  }
7724
+ },
7725
+ {
7726
+ url: "https://open.er-api.com/v6/latest/USD",
7727
+ parse: parseRatesJsonCny
7728
+ },
7729
+ {
7730
+ url: "https://allratestoday.com/api/open/latest/USD",
7731
+ parse: parseRatesJsonCny
7403
7732
  }
7404
- }];
7733
+ ];
7405
7734
  /** OpenRouter's public model list: per-token USD prices, no key needed. */
7406
7735
  const ROUTER_URL = "https://openrouter.ai/api/v1/models";
7407
7736
  /** models.dev 公开目录:pi-ai 预制提供方的上游数据源(USD / 1M tokens)。
@@ -7506,25 +7835,25 @@ async function fetchJson(url) {
7506
7835
  /** Latest USD → CNY rate from the first working source, or undefined when none respond. */
7507
7836
  /**
7508
7837
  * EUR → CNY 汇率源。与 USD 同一套降级约定:腾讯行情优先(免 key、国内可达),
7509
- * open.er-api.com 兑底;全部失败由调用方降级内置汇率,不阻塞其他价格拉取。
7838
+ * open.er-api.com 兑底,AllRatesToday 再兜底;全部失败由调用方降级内置汇率,不阻塞其他价格拉取。
7510
7839
  */
7511
- const EUR_RATE_SOURCES = [{
7512
- url: "https://qt.gtimg.cn/q=whEURCNY",
7513
- parse: (text) => {
7514
- const price = /"([^"]*)"/.exec(text)?.[1]?.split("~")[3];
7515
- return price !== void 0 && price !== "" ? Number(price) : void 0;
7516
- }
7517
- }, {
7518
- url: "https://open.er-api.com/v6/latest/EUR",
7519
- parse: (text) => {
7520
- try {
7521
- const cny = JSON.parse(text).rates?.CNY;
7522
- return typeof cny === "number" && Number.isFinite(cny) && cny > 0 ? cny : void 0;
7523
- } catch {
7524
- return;
7840
+ const EUR_RATE_SOURCES = [
7841
+ {
7842
+ url: "https://qt.gtimg.cn/q=whEURCNY",
7843
+ parse: (text) => {
7844
+ const price = /"([^"]*)"/.exec(text)?.[1]?.split("~")[3];
7845
+ return price !== void 0 && price !== "" ? Number(price) : void 0;
7525
7846
  }
7847
+ },
7848
+ {
7849
+ url: "https://open.er-api.com/v6/latest/EUR",
7850
+ parse: parseRatesJsonCny
7851
+ },
7852
+ {
7853
+ url: "https://allratestoday.com/api/open/latest/EUR",
7854
+ parse: parseRatesJsonCny
7526
7855
  }
7527
- }];
7856
+ ];
7528
7857
  /**
7529
7858
  * 按顺序尝试汇率源,返回第一个合法正数。
7530
7859
  * @param sources - 待尝试的汇率源。
@@ -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' | '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';
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' | 'shortcutOpenDashboard' | '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>;
@@ -10,9 +10,10 @@
10
10
  * - `label` / `description` 是**函数**:菜单每次打开都重新读取,切换语言立即生效,
11
11
  * 无需重新注册。
12
12
  *
13
- * 取服务走 `ctx.get('commandUi')`(cordis 免 inject 读取):老宿主没有该服务时
14
- * **不注册命令**,面板功能完全不受影响——这是「服务缺席即降级、不得因此收窄兼容
15
- * 矩阵」的落点(宿主自己的 ui-permission-presets 也是 `ctx.get('commandUi')`)。
13
+ * 取服务走 `ctx.inject(['commandUi'])` 而非 apply 期的 `ctx.get`:该服务是宿主的
14
+ * Service,要等 inputTriggers / remote.commands 就绪才构造,晚于本插件 apply。
15
+ * 老宿主没有这个服务时注入分支永不执行,**不注册命令**、面板功能完全不受影响——
16
+ * 这是「服务缺席即降级、不得因此收窄兼容矩阵」的落点。
16
17
  */
17
18
  import type { Context } from '@deepseek-ai/cordis';
18
19
  /** 命令名(斜杠后不带斜杠):与宿主命令目录合并的键。 */
@@ -29,9 +30,13 @@ export interface UsageCommandOptions {
29
30
  /**
30
31
  * 注册 `/usage` 命令。
31
32
  *
33
+ * commandUi 是宿主的 Service,构造前要等 inputTriggers / sessions / remote.commands
34
+ * 就绪——这些都晚于本插件 apply。因此在 apply 期用 `ctx.get` 一次性采样必然拿到
35
+ * undefined,命令永远注册不上;改为 `ctx.inject` 等它就位再注册。
36
+ *
32
37
  * @param ctx - 客户端根 context。
33
38
  * @param options - 打开回调与文案。
34
- * @returns 是否注册成功(宿主无 commandUi 服务时返回 false,属正常降级)。
39
+ * @returns 查询当前是否已注册的 getter(宿主无 commandUi 服务时恒为 false,属正常降级)。
35
40
  */
36
- export declare function registerUsageCommand(ctx: Context, options: UsageCommandOptions): boolean;
41
+ export declare function registerUsageCommand(ctx: Context, options: UsageCommandOptions): () => boolean;
37
42
  //# sourceMappingURL=usage-command.d.ts.map