@dudousxd/nestjs-agent 1.26.0 → 1.27.1

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/dist/index.cjs CHANGED
@@ -5190,7 +5190,7 @@ var LedgerQuotaProvider = class {
5190
5190
  if (this.store.usageBetween !== void 0) {
5191
5191
  const range = (0, import_nestjs_agent_core28.quotaPeriodRange)("month", now);
5192
5192
  const used = await this.store.usageBetween(actorRef, range.fromDay, range.toDay);
5193
- windows.push(this.window("month", used.usedTokens, used.costUsd, range.resetsAt));
5193
+ windows.push(this.window("month", used.usedTokens, this.usd(used), range.resetsAt));
5194
5194
  }
5195
5195
  const blocked = (0, import_nestjs_agent_core28.exhaustedWindow)(windows);
5196
5196
  const warning = (0, import_nestjs_agent_core28.quotaWarning)(windows);
@@ -5206,8 +5206,15 @@ var LedgerQuotaProvider = class {
5206
5206
  }
5207
5207
  async dayWindow(actorRef, now) {
5208
5208
  const range = (0, import_nestjs_agent_core28.quotaPeriodRange)("day", now);
5209
- const { usedTokens, costUsd } = await this.store.quotaToday(actorRef, range.fromDay);
5210
- return this.window("day", usedTokens, costUsd, range.resetsAt);
5209
+ const used = await this.store.quotaToday(actorRef, range.fromDay);
5210
+ return this.window("day", used.usedTokens, this.usd(used), range.resetsAt);
5211
+ }
5212
+ /** The window's USD: every priced row, or (with `countEstimatedCost: false`) reported cost only. */
5213
+ usd(used) {
5214
+ if (this.options.countEstimatedCost === false) {
5215
+ return Math.max(0, used.costUsd - (used.estimatedCostUsd ?? 0));
5216
+ }
5217
+ return used.costUsd;
5211
5218
  }
5212
5219
  window(period, usedTokens, usedUsd, resetsAt) {
5213
5220
  const limits = this.limits[period] ?? {};
@@ -6312,9 +6319,14 @@ function sharedProviders(durable, engine) {
6312
6319
  // `quota` is either a provider of the host's own or ceilings for the built-in ledger one;
6313
6320
  // omitted, the ledger provider still reports usage, with no ceiling to block on.
6314
6321
  provide: import_nestjs_agent_core34.AGENT_QUOTA_PROVIDER,
6315
- useFactory: /* @__PURE__ */ __name((o, store) => isQuotaProvider(o.quota) ? o.quota : new LedgerQuotaProvider(store, o.quota?.limits, o.quota?.warnAt !== void 0 ? {
6316
- warnAt: o.quota.warnAt
6317
- } : {}), "useFactory"),
6322
+ useFactory: /* @__PURE__ */ __name((o, store) => isQuotaProvider(o.quota) ? o.quota : new LedgerQuotaProvider(store, o.quota?.limits, {
6323
+ ...o.quota?.warnAt !== void 0 ? {
6324
+ warnAt: o.quota.warnAt
6325
+ } : {},
6326
+ ...o.quota?.countEstimatedCost !== void 0 ? {
6327
+ countEstimatedCost: o.quota.countEstimatedCost
6328
+ } : {}
6329
+ }), "useFactory"),
6318
6330
  inject: [
6319
6331
  import_nestjs_agent_core34.AGENT_OPTIONS,
6320
6332
  import_nestjs_agent_core34.AGENT_STORE