@kenz1117/dsh-ui-usage-billing 1.4.32 → 1.4.33

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.
Files changed (2) hide show
  1. package/lib/index.js +22 -13
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -3453,21 +3453,28 @@ function createUsageAggregator(persistence, options = {}) {
3453
3453
  let ledgerAppliedMigrations;
3454
3454
  let lastDoc;
3455
3455
  let lastAt = 0;
3456
+ const deserializedFoldOf = (() => {
3457
+ const memo = /* @__PURE__ */ new WeakMap();
3458
+ return (serialized) => {
3459
+ const hit = memo.get(serialized);
3460
+ if (hit !== void 0) return hit;
3461
+ const fold = deserializeFold(serialized);
3462
+ memo.set(serialized, fold);
3463
+ return fold;
3464
+ };
3465
+ })();
3456
3466
  /** 每次聚合取最新的 provider 路由视图(中转站零配置发现);缺省按空处理(全部未知路由)。
3457
3467
  * 叠加已注册 adapter 的通道(issue #91):宿主 llm 注册表里的 provider 合成无 baseURL
3458
3468
  * 的空路由视图——siteRefOf 的路由命中分支正是「无 origin 直连」的语义,归位
3459
3469
  * `direct:<provider>` 按官方目录价计费;llm-pi-ai 已有配置的路由优先(其 origin 可还原)。 */
3460
- const routesOf = () => {
3470
+ const routesOf = (registered) => {
3461
3471
  const routes = { ...options.resolveRoutes?.() };
3462
- const registered = options.resolveRegisteredProviders?.();
3463
- if (registered !== void 0) {
3464
- for (const provider of registered) if (routes[provider] === void 0) routes[provider] = {};
3465
- }
3472
+ for (const provider of registered) if (routes[provider] === void 0) routes[provider] = {};
3466
3473
  return routes;
3467
3474
  };
3468
3475
  const searchEstimate = options.searchCallEstimateCny ?? .02;
3469
- const foldFingerprintOf = () => configFingerprint(subscriptionMatcher, officialProviderIds, routeAliases, searchEstimate, options.modelKeyAliases, options.resolveRegisteredProviders?.() ?? /* @__PURE__ */ new Set());
3470
- let foldFingerprint = foldFingerprintOf();
3476
+ const foldFingerprintOf = (registered) => configFingerprint(subscriptionMatcher, officialProviderIds, routeAliases, searchEstimate, options.modelKeyAliases, registered);
3477
+ let foldFingerprint = foldFingerprintOf(/* @__PURE__ */ new Set());
3471
3478
  const FOLD_CHUNK_EVENTS = 8e3;
3472
3479
  /** 惰性失效(价目表时序):账本/缓存行若以「当时不可计价」的模型落盘,
3473
3480
  * 而价目表现在能计价了,该行必须重折——否则显示层按实时价算出的
@@ -3549,7 +3556,9 @@ function createUsageAggregator(persistence, options = {}) {
3549
3556
  const aggregateOnce = async () => {
3550
3557
  const now = Date.now();
3551
3558
  await ensureLedgerLoaded();
3552
- foldFingerprint = foldFingerprintOf();
3559
+ const registeredProviders = options.resolveRegisteredProviders?.() ?? /* @__PURE__ */ new Set();
3560
+ foldFingerprint = foldFingerprintOf(registeredProviders);
3561
+ const roundRoutes = routesOf(registeredProviders);
3553
3562
  let metas;
3554
3563
  try {
3555
3564
  metas = await persistence.list();
@@ -3582,7 +3591,7 @@ function createUsageAggregator(persistence, options = {}) {
3582
3591
  const cwd = meta.cwd;
3583
3592
  const ledgerRow = ledger.get(id);
3584
3593
  if (ledgerRow !== void 0 && ledgerRow.stamp !== void 0 && stamp !== null && ledgerRow.stamp === stamp && (ledgerRow.foldVersion ?? 1) === 22 && ledgerRow.fingerprint === foldFingerprint && !foldNeedsReprice(ledgerRow.fold)) {
3585
- const fold = deserializeFold(ledgerRow.fold);
3594
+ const fold = deserializedFoldOf(ledgerRow.fold);
3586
3595
  folds.push({
3587
3596
  id,
3588
3597
  ...cwd === void 0 ? {} : { cwd },
@@ -3617,7 +3626,7 @@ function createUsageAggregator(persistence, options = {}) {
3617
3626
  cache.delete(id);
3618
3627
  continue;
3619
3628
  }
3620
- foldInto(previous.fold, previous.machine, events, subscriptionMatcher, officialProviderIds, routesOf(), searchEstimate, inheritedEventCount, routeAliases);
3629
+ foldInto(previous.fold, previous.machine, events, subscriptionMatcher, officialProviderIds, roundRoutes, searchEstimate, inheritedEventCount, routeAliases);
3621
3630
  refreshTurns(previous.fold, previous.machine);
3622
3631
  previous.lastSeq = events[events.length - 1]?.seq ?? previous.lastSeq;
3623
3632
  previous.stamp = stamp;
@@ -3638,7 +3647,7 @@ function createUsageAggregator(persistence, options = {}) {
3638
3647
  const fold = freshFold();
3639
3648
  const machine = freshMachine();
3640
3649
  for (let start = 0; start < events.length; start += FOLD_CHUNK_EVENTS) {
3641
- foldInto(fold, machine, events.slice(start, start + FOLD_CHUNK_EVENTS), subscriptionMatcher, officialProviderIds, routesOf(), searchEstimate, inheritedEventCount, routeAliases);
3650
+ foldInto(fold, machine, events.slice(start, start + FOLD_CHUNK_EVENTS), subscriptionMatcher, officialProviderIds, roundRoutes, searchEstimate, inheritedEventCount, routeAliases);
3642
3651
  if (start + FOLD_CHUNK_EVENTS < events.length) await new Promise((resolve) => {
3643
3652
  setImmediate(resolve);
3644
3653
  });
@@ -3687,7 +3696,7 @@ function createUsageAggregator(persistence, options = {}) {
3687
3696
  id: entry.id,
3688
3697
  ...entry.cwd === void 0 ? {} : { cwd: entry.cwd },
3689
3698
  ...stale ? { staleLedger: true } : {},
3690
- fold: deserializeFold(entry.fold)
3699
+ fold: deserializedFoldOf(entry.fold)
3691
3700
  });
3692
3701
  included.add(entry.id);
3693
3702
  if (stale) staleLedgerSessions += 1;
@@ -3908,7 +3917,7 @@ function createUsageAggregator(persistence, options = {}) {
3908
3917
  const row = ledger.get(sessionId);
3909
3918
  if (row === void 0) return void 0;
3910
3919
  try {
3911
- const fold = deserializeFold(row.fold);
3920
+ const fold = deserializedFoldOf(row.fold);
3912
3921
  return {
3913
3922
  calls: fold.total.calls,
3914
3923
  cost: fold.total.cost,
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.4.32",
4
+ "version": "1.4.33",
5
5
  "keywords": [
6
6
  "deepseek-harness",
7
7
  "deepseek",