@compilr-dev/sdk 0.9.17 → 0.9.19
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/agent.js +7 -2
- package/dist/entitlements/cache.js +26 -2
- package/package.json +2 -2
package/dist/agent.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Agent, ContextManager, createSuggestTool, } from '@compilr-dev/agents';
|
|
5
5
|
import { createCompressorHook } from './compressors/index.js';
|
|
6
|
+
import { createInjectionDetectionHook } from '@compilr-dev/agents';
|
|
6
7
|
import { resolveProvider } from './provider.js';
|
|
7
8
|
import { resolvePreset } from './presets/index.js';
|
|
8
9
|
import { assembleTools, deduplicateTools } from './tools.js';
|
|
@@ -242,13 +243,17 @@ class CompilrAgentImpl {
|
|
|
242
243
|
: [];
|
|
243
244
|
mergedHooks.beforeLLM = [...existingHooks, ...capabilityHooks];
|
|
244
245
|
}
|
|
245
|
-
// Add output compressor
|
|
246
|
+
// Add output compressor and injection detection as afterTool hooks
|
|
246
247
|
const existingAfterTool = config?.hooks?.afterTool
|
|
247
248
|
? Array.isArray(config.hooks.afterTool)
|
|
248
249
|
? config.hooks.afterTool
|
|
249
250
|
: [config.hooks.afterTool]
|
|
250
251
|
: [];
|
|
251
|
-
mergedHooks.afterTool = [
|
|
252
|
+
mergedHooks.afterTool = [
|
|
253
|
+
createCompressorHook(),
|
|
254
|
+
createInjectionDetectionHook(), // Scan tool results for prompt injection
|
|
255
|
+
...existingAfterTool,
|
|
256
|
+
];
|
|
252
257
|
// Build observation mask config — SDK defaults include platform tools
|
|
253
258
|
const observationMask = config?.context?.observationMask !== false
|
|
254
259
|
? {
|
|
@@ -65,7 +65,14 @@ export class EntitlementCache {
|
|
|
65
65
|
*/
|
|
66
66
|
checkLimit(field, currentCount) {
|
|
67
67
|
if (!this.entitlements) {
|
|
68
|
-
|
|
68
|
+
// No entitlements loaded — use offline fallback limits (fail closed, not open)
|
|
69
|
+
const fallbackLimit = OFFLINE_FALLBACK_LIMITS[field];
|
|
70
|
+
if (fallbackLimit === UNLIMITED)
|
|
71
|
+
return { allowed: true };
|
|
72
|
+
if (currentCount >= fallbackLimit) {
|
|
73
|
+
return { allowed: false, reason: 'Entitlements not loaded', current: currentCount, limit: fallbackLimit };
|
|
74
|
+
}
|
|
75
|
+
return { allowed: true, current: currentCount, limit: fallbackLimit };
|
|
69
76
|
}
|
|
70
77
|
const limit = this.entitlements.limits[field];
|
|
71
78
|
// Unlimited
|
|
@@ -169,7 +176,10 @@ export class EntitlementCache {
|
|
|
169
176
|
const age = Date.now() - parsed.fetchedAtWall;
|
|
170
177
|
if (age < this.offlineGraceMs) {
|
|
171
178
|
this.entitlements = parsed.response;
|
|
172
|
-
|
|
179
|
+
// Compute monotonic offset from wall-clock age so isWithinOfflineGrace()
|
|
180
|
+
// returns the correct remaining time (not a fresh 24h window on every restart)
|
|
181
|
+
const ageNs = BigInt(age) * 1000000n;
|
|
182
|
+
this.fetchedAtMonotonic = process.hrtime.bigint() - ageNs;
|
|
173
183
|
this.fetchedAtWall = parsed.fetchedAtWall;
|
|
174
184
|
return this.entitlements.limits;
|
|
175
185
|
}
|
|
@@ -180,6 +190,20 @@ export class EntitlementCache {
|
|
|
180
190
|
}
|
|
181
191
|
}
|
|
182
192
|
// 3. Offline grace expired or no store — degrade to minimal fallback
|
|
193
|
+
// MUST set this.entitlements so checkLimit() doesn't fail open
|
|
194
|
+
this.entitlements = {
|
|
195
|
+
tier: 'free',
|
|
196
|
+
beta: false,
|
|
197
|
+
limits: OFFLINE_FALLBACK_LIMITS,
|
|
198
|
+
pendingPayment: false,
|
|
199
|
+
trialEndsAt: null,
|
|
200
|
+
features: {},
|
|
201
|
+
issuedAt: new Date().toISOString(),
|
|
202
|
+
userId: '',
|
|
203
|
+
signature: '',
|
|
204
|
+
};
|
|
205
|
+
this.fetchedAtMonotonic = process.hrtime.bigint();
|
|
206
|
+
this.fetchedAtWall = Date.now();
|
|
183
207
|
return OFFLINE_FALLBACK_LIMITS;
|
|
184
208
|
}
|
|
185
209
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compilr-dev/sdk",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.19",
|
|
4
4
|
"description": "Universal agent runtime for building AI-powered applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"node": ">=22.0.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@compilr-dev/agents": "^0.5.
|
|
56
|
+
"@compilr-dev/agents": "^0.5.4",
|
|
57
57
|
"@compilr-dev/logger": "^0.1.0",
|
|
58
58
|
"ajv": "^6.14.0"
|
|
59
59
|
},
|