floe-guard 0.15.4 → 0.15.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { B as BudgetGuard, a as BudgetExceeded } from '../guard-B05gDZ3g.cjs';
1
+ import { B as BudgetGuard, a as BudgetExceeded } from '../guard-BPIqdSVt.cjs';
2
2
 
3
3
  /**
4
4
  * LiveKit Agents adapter (optional peer: `npm i @livekit/agents`).
@@ -1,4 +1,4 @@
1
- import { B as BudgetGuard, a as BudgetExceeded } from '../guard-B05gDZ3g.js';
1
+ import { B as BudgetGuard, a as BudgetExceeded } from '../guard-BPIqdSVt.js';
2
2
 
3
3
  /**
4
4
  * LiveKit Agents adapter (optional peer: `npm i @livekit/agents`).
@@ -1,4 +1,4 @@
1
- import { B as BudgetGuard, a as BudgetExceeded } from '../guard-B05gDZ3g.cjs';
1
+ import { B as BudgetGuard, a as BudgetExceeded } from '../guard-BPIqdSVt.cjs';
2
2
 
3
3
  /**
4
4
  * Retell custom-LLM WebSocket adapter (optional peer: the `ws` server your custom
@@ -1,4 +1,4 @@
1
- import { B as BudgetGuard, a as BudgetExceeded } from '../guard-B05gDZ3g.js';
1
+ import { B as BudgetGuard, a as BudgetExceeded } from '../guard-BPIqdSVt.js';
2
2
 
3
3
  /**
4
4
  * Retell custom-LLM WebSocket adapter (optional peer: the `ws` server your custom
@@ -1506,7 +1506,10 @@ var VapiBudgetGuard = class {
1506
1506
  this.guard.release(reserved);
1507
1507
  throw new VapiUsageMissingError(model);
1508
1508
  }
1509
- this.guard.settle(model, usage.prompt, usage.completion, { reserved });
1509
+ this.guard.settle(model, usage.prompt, usage.completion, {
1510
+ reserved,
1511
+ cacheReadInputTokens: usage.cacheRead
1512
+ });
1510
1513
  return completion;
1511
1514
  }
1512
1515
  /**
@@ -1543,7 +1546,10 @@ var VapiBudgetGuard = class {
1543
1546
  }
1544
1547
  if (usage === null) throw new VapiUsageMissingError(model);
1545
1548
  settled = true;
1546
- this.guard.settle(model, usage.prompt, usage.completion, { reserved });
1549
+ this.guard.settle(model, usage.prompt, usage.completion, {
1550
+ reserved,
1551
+ cacheReadInputTokens: usage.cacheRead
1552
+ });
1547
1553
  } finally {
1548
1554
  if (!settled) this.guard.release(reserved);
1549
1555
  }
@@ -1606,7 +1612,12 @@ function readUsage(usage) {
1606
1612
  const completion = usage.completion_tokens;
1607
1613
  if (typeof prompt !== "number" || !Number.isFinite(prompt)) return null;
1608
1614
  if (typeof completion !== "number" || !Number.isFinite(completion)) return null;
1609
- return { prompt, completion };
1615
+ const promptClamped = Math.max(0, prompt);
1616
+ const completionClamped = Math.max(0, completion);
1617
+ const cachedRaw = usage.prompt_tokens_details?.cached_tokens;
1618
+ const cached = typeof cachedRaw === "number" && Number.isFinite(cachedRaw) ? Math.max(0, cachedRaw) : 0;
1619
+ const cacheRead = Math.min(cached, promptClamped);
1620
+ return { prompt: promptClamped - cacheRead, completion: completionClamped, cacheRead };
1610
1621
  }
1611
1622
  // Annotate the CommonJS export names for ESM import in node:
1612
1623
  0 && (module.exports = {