@blockrun/clawrouter 0.12.55 → 0.12.60

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.d.ts CHANGED
@@ -522,6 +522,7 @@ type SessionEntry = {
522
522
  recentHashes: string[];
523
523
  strikes: number;
524
524
  escalated: boolean;
525
+ sessionCostMicros: bigint;
525
526
  };
526
527
  type SessionConfig = {
527
528
  /** Enable session persistence (default: false) */
@@ -590,6 +591,17 @@ declare class SessionStore {
590
591
  model: string;
591
592
  tier: string;
592
593
  } | null;
594
+ /**
595
+ * Add cost to a session's running total for maxCostPerRun tracking.
596
+ * Cost is in USDC 6-decimal units (micros).
597
+ * Creates a cost-tracking-only entry if none exists (e.g., explicit model requests
598
+ * that never go through the routing path).
599
+ */
600
+ addSessionCost(sessionId: string, additionalMicros: bigint): void;
601
+ /**
602
+ * Get the total accumulated cost for a session in USD.
603
+ */
604
+ getSessionCostUsd(sessionId: string): number;
593
605
  /**
594
606
  * Stop the cleanup interval.
595
607
  */
@@ -693,6 +705,18 @@ type ProxyOptions = {
693
705
  * Default: enabled with 10 minute TTL, 200 max entries.
694
706
  */
695
707
  cacheConfig?: ResponseCacheConfig;
708
+ /**
709
+ * Maximum total spend (in USD) per session run.
710
+ * Default: undefined (no limit). Example: 0.5 = $0.50 per session.
711
+ */
712
+ maxCostPerRunUsd?: number;
713
+ /**
714
+ * How to enforce the per-run cost cap.
715
+ * - 'graceful' (default): when budget runs low, downgrade to cheaper models; use free model
716
+ * as last resort. Only hard-stops when no model can serve the request.
717
+ * - 'strict': immediately return 429 once the session spend reaches the cap.
718
+ */
719
+ maxCostPerRunMode?: "graceful" | "strict";
696
720
  onReady?: (port: number) => void;
697
721
  onError?: (error: Error) => void;
698
722
  onPayment?: (info: {