caplyr 0.2.0 → 0.2.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.js CHANGED
@@ -124,12 +124,25 @@ var Heartbeat = class {
124
124
  };
125
125
  /** Current protection status */
126
126
  this.status = "ACTIVE";
127
- this.endpoint = config.endpoint ?? "https://api.caplyr.com";
127
+ this.endpoint = config.endpoint ?? "https://caplyr.com";
128
128
  this.apiKey = config.apiKey;
129
129
  this.interval = config.heartbeatInterval ?? 6e4;
130
130
  this.onStatusChange = config.onStatusChange;
131
131
  this.onError = config.onError;
132
132
  }
133
+ /**
134
+ * Apply local budget limits from config.
135
+ * These act as client-side enforcement even if the server
136
+ * doesn't return limits (e.g. during heartbeat failures).
137
+ */
138
+ applyLocalLimits(budget) {
139
+ if (budget.daily !== void 0) {
140
+ this.budgetStatus.daily_limit = budget.daily;
141
+ }
142
+ if (budget.monthly !== void 0) {
143
+ this.budgetStatus.monthly_limit = budget.monthly;
144
+ }
145
+ }
133
146
  /**
134
147
  * Start the heartbeat loop.
135
148
  * Immediately sends first heartbeat, then repeats on interval.
@@ -665,8 +678,9 @@ function protect(client, config) {
665
678
  "Caplyr: apiKey is required. Get yours at https://app.caplyr.com"
666
679
  );
667
680
  }
681
+ const userWantsProtect = config.budget && !config.mode;
668
682
  const resolvedConfig = {
669
- mode: config.budget && !config.mode ? "cost_protect" : "alert_only",
683
+ mode: userWantsProtect ? "cost_protect" : "alert_only",
670
684
  downgradeThreshold: 0.8,
671
685
  batchSize: 10,
672
686
  flushInterval: 3e4,
@@ -682,6 +696,10 @@ function protect(client, config) {
682
696
  instances.set(resolvedConfig.apiKey, shared);
683
697
  }
684
698
  const { shipper, heartbeat } = shared;
699
+ if (resolvedConfig.budget) {
700
+ const budgetConfig = typeof resolvedConfig.budget === "number" ? { monthly: resolvedConfig.budget } : resolvedConfig.budget;
701
+ heartbeat.applyLocalLimits(budgetConfig);
702
+ }
685
703
  const provider = detectProvider(client);
686
704
  switch (provider) {
687
705
  case "anthropic":
package/dist/index.mjs CHANGED
@@ -91,12 +91,25 @@ var Heartbeat = class {
91
91
  };
92
92
  /** Current protection status */
93
93
  this.status = "ACTIVE";
94
- this.endpoint = config.endpoint ?? "https://api.caplyr.com";
94
+ this.endpoint = config.endpoint ?? "https://caplyr.com";
95
95
  this.apiKey = config.apiKey;
96
96
  this.interval = config.heartbeatInterval ?? 6e4;
97
97
  this.onStatusChange = config.onStatusChange;
98
98
  this.onError = config.onError;
99
99
  }
100
+ /**
101
+ * Apply local budget limits from config.
102
+ * These act as client-side enforcement even if the server
103
+ * doesn't return limits (e.g. during heartbeat failures).
104
+ */
105
+ applyLocalLimits(budget) {
106
+ if (budget.daily !== void 0) {
107
+ this.budgetStatus.daily_limit = budget.daily;
108
+ }
109
+ if (budget.monthly !== void 0) {
110
+ this.budgetStatus.monthly_limit = budget.monthly;
111
+ }
112
+ }
100
113
  /**
101
114
  * Start the heartbeat loop.
102
115
  * Immediately sends first heartbeat, then repeats on interval.
@@ -632,8 +645,9 @@ function protect(client, config) {
632
645
  "Caplyr: apiKey is required. Get yours at https://app.caplyr.com"
633
646
  );
634
647
  }
648
+ const userWantsProtect = config.budget && !config.mode;
635
649
  const resolvedConfig = {
636
- mode: config.budget && !config.mode ? "cost_protect" : "alert_only",
650
+ mode: userWantsProtect ? "cost_protect" : "alert_only",
637
651
  downgradeThreshold: 0.8,
638
652
  batchSize: 10,
639
653
  flushInterval: 3e4,
@@ -649,6 +663,10 @@ function protect(client, config) {
649
663
  instances.set(resolvedConfig.apiKey, shared);
650
664
  }
651
665
  const { shipper, heartbeat } = shared;
666
+ if (resolvedConfig.budget) {
667
+ const budgetConfig = typeof resolvedConfig.budget === "number" ? { monthly: resolvedConfig.budget } : resolvedConfig.budget;
668
+ heartbeat.applyLocalLimits(budgetConfig);
669
+ }
652
670
  const provider = detectProvider(client);
653
671
  switch (provider) {
654
672
  case "anthropic":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "caplyr",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "AI Cost Control Plane — budget guardrails, auto-downgrade, and kill switch for AI API calls",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",