@kya-os/checkpoint-wasm-runtime 1.1.1 → 1.1.2
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/CHANGELOG.md +55 -0
- package/dist/edge.d.mts +531 -4
- package/dist/edge.d.ts +531 -4
- package/dist/engine.js +11 -0
- package/dist/engine.mjs +17 -1
- package/dist/index.d.mts +72 -5
- package/dist/index.d.ts +72 -5
- package/dist/index.js +2 -0
- package/dist/node.d.mts +2 -3
- package/dist/node.d.ts +2 -3
- package/dist/orchestrator-edge.d.mts +199 -5
- package/dist/orchestrator-edge.d.ts +199 -5
- package/dist/orchestrator-node.d.mts +313 -5
- package/dist/orchestrator-node.d.ts +313 -5
- package/dist/orchestrator-node.js +23 -0
- package/dist/orchestrator-node.mjs +29 -1
- package/dist/orchestrator.d.mts +86 -6
- package/dist/orchestrator.d.ts +86 -6
- package/dist/orchestrator.js +29 -2
- package/dist/orchestrator.mjs +31 -1
- package/dist/{rules-detector-DjbTJ1-Q.d.mts → rules-detector-ZIKHN-_y.d.mts} +63 -1
- package/dist/{rules-detector-DjbTJ1-Q.d.ts → rules-detector-ZIKHN-_y.d.ts} +63 -1
- package/package.json +1 -1
- package/dist/dynamic-loader-cS-pUisw.d.ts +0 -65
- package/dist/dynamic-loader-qGJacfEC.d.mts +0 -65
- package/dist/render-decision-C1a-iuiW.d.mts +0 -200
- package/dist/render-decision-Dsjwt96g.d.ts +0 -200
- package/dist/static-loader-C1hUlksK.d.ts +0 -72
- package/dist/static-loader-Ds4iNw7c.d.mts +0 -72
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,60 @@
|
|
|
1
1
|
# @kya-os/checkpoint-wasm-runtime
|
|
2
2
|
|
|
3
|
+
## 1.1.2 — 2026-05-17
|
|
4
|
+
|
|
5
|
+
Fourth in the SDK-WASM-Bundler-Loader sequence. The 1.1.1 fix made
|
|
6
|
+
`engineVerify` reference the real wasm binding, but Node's strict
|
|
7
|
+
ESM loader at Vercel runtime still failed with:
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
ReferenceError: __dirname is not defined in ES module scope
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The wasm-bindgen `--target nodejs` glue uses CJS-only globals
|
|
14
|
+
(`__dirname`, `__require`) which don't exist in ESM scope. When
|
|
15
|
+
tsup inlines that CJS code into the .mjs bundle, ESM execution
|
|
16
|
+
breaks.
|
|
17
|
+
|
|
18
|
+
### Fix
|
|
19
|
+
|
|
20
|
+
`shims: true` in tsup config. Injects the standard polyfills at the
|
|
21
|
+
top of every ESM output:
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
25
|
+
const __dirname = dirname(__filename);
|
|
26
|
+
const require = createRequire(import.meta.url);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Bundle proof:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
var getFilename, getDirname, __dirname$1;
|
|
33
|
+
getFilename = () => fileURLToPath(import.meta.url);
|
|
34
|
+
__dirname$1 = getDirname();
|
|
35
|
+
// ...
|
|
36
|
+
var wasmPath = `${__dirname$1}/kya_os_engine_bg.wasm`;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Edge bundle caveat
|
|
40
|
+
|
|
41
|
+
`shims: true` applies to ALL ESM outputs, including the Edge entry.
|
|
42
|
+
The Edge bundle now has `import 'path'` + `import 'url'` at the top.
|
|
43
|
+
`path` is not available in Vercel Edge runtime — could be an issue
|
|
44
|
+
for Edge consumers. Bench-new uses Node runtime so this doesn't
|
|
45
|
+
affect the immediate measurement, but a follow-up should split the
|
|
46
|
+
tsup build into per-runtime configs (Node-only entries get shims;
|
|
47
|
+
Edge entries don't). Filing as SDK-WASM-Bundler-Loader-4.
|
|
48
|
+
|
|
49
|
+
### Consumers
|
|
50
|
+
|
|
51
|
+
No package.json changes needed in `@kya-os/checkpoint-{nextjs,express}` —
|
|
52
|
+
both already use `workspace:^` to depend on `^1.1.0`, so fresh
|
|
53
|
+
installs automatically pull 1.1.2 transitively. Bench-new needs
|
|
54
|
+
a lockfile bump + redeploy.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
3
58
|
## 1.1.1 — 2026-05-17
|
|
4
59
|
|
|
5
60
|
**Critical runtime fix.** 1.1.0 (and all prior versions back to 1.0.0)
|
package/dist/edge.d.mts
CHANGED
|
@@ -1,6 +1,533 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* AgentShield WASM Runtime Types
|
|
3
|
+
*
|
|
4
|
+
* Core interfaces following SOLID principles:
|
|
5
|
+
* - Interface Segregation: Small, focused interfaces
|
|
6
|
+
* - Dependency Inversion: Depend on abstractions
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Detection input - information about the request to analyze
|
|
10
|
+
*/
|
|
11
|
+
interface IDetectionInput {
|
|
12
|
+
/** User-Agent header value */
|
|
13
|
+
userAgent?: string;
|
|
14
|
+
/** Client IP address */
|
|
15
|
+
ipAddress?: string;
|
|
16
|
+
/** All request headers */
|
|
17
|
+
headers: Record<string, string>;
|
|
18
|
+
/** Request URL path */
|
|
19
|
+
url?: string;
|
|
20
|
+
/** HTTP method (GET, POST, etc.) */
|
|
21
|
+
method?: string;
|
|
22
|
+
/** Client fingerprint data (for browser detection) */
|
|
23
|
+
clientFingerprint?: string;
|
|
24
|
+
/** Request timestamp */
|
|
25
|
+
timestamp?: Date;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Verification method used to detect the agent
|
|
29
|
+
*/
|
|
30
|
+
type VerificationMethod = 'signature' | 'pattern' | 'behavioral' | 'network' | 'mcp_i_handshake' | 'none';
|
|
31
|
+
/**
|
|
32
|
+
* Detection class - categorization of the detected entity
|
|
33
|
+
*/
|
|
34
|
+
type DetectionClass = {
|
|
35
|
+
type: 'Human';
|
|
36
|
+
} | {
|
|
37
|
+
type: 'AiAgent';
|
|
38
|
+
agentType: string;
|
|
39
|
+
} | {
|
|
40
|
+
type: 'Bot';
|
|
41
|
+
botType?: string;
|
|
42
|
+
} | {
|
|
43
|
+
type: 'Automation';
|
|
44
|
+
toolType?: string;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'Unknown';
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Forgeability risk level
|
|
50
|
+
* How easy it is to spoof the detection signals
|
|
51
|
+
*/
|
|
52
|
+
type ForgeabilityRisk = 'low' | 'medium' | 'high';
|
|
53
|
+
/**
|
|
54
|
+
* Detected agent information
|
|
55
|
+
*/
|
|
56
|
+
interface IDetectedAgent {
|
|
57
|
+
/** Agent type identifier (e.g., 'openai', 'anthropic') */
|
|
58
|
+
type: string;
|
|
59
|
+
/** Human-readable agent name (e.g., 'ChatGPT', 'Claude') */
|
|
60
|
+
name: string;
|
|
61
|
+
/** Vendor/company name */
|
|
62
|
+
vendor?: string;
|
|
63
|
+
/** Model identifier if known */
|
|
64
|
+
model?: string;
|
|
65
|
+
/** Version if known */
|
|
66
|
+
version?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Detection result - output from the detection engine
|
|
70
|
+
* Confidence is ALWAYS on 0-100 scale
|
|
71
|
+
*/
|
|
72
|
+
interface IDetectionResult {
|
|
73
|
+
/** Whether the request was identified as coming from an agent */
|
|
74
|
+
isAgent: boolean;
|
|
75
|
+
/** Confidence score on 0-100 scale (NOT 0-1) */
|
|
76
|
+
confidence: number;
|
|
77
|
+
/** Detection classification */
|
|
78
|
+
detectionClass: DetectionClass;
|
|
79
|
+
/** Detected agent details if identified */
|
|
80
|
+
detectedAgent?: IDetectedAgent;
|
|
81
|
+
/** Method used for verification */
|
|
82
|
+
verificationMethod: VerificationMethod;
|
|
83
|
+
/** Risk level of signal forgeability */
|
|
84
|
+
forgeabilityRisk: ForgeabilityRisk;
|
|
85
|
+
/** Reasons/signals that contributed to detection */
|
|
86
|
+
reasons: string[];
|
|
87
|
+
/** Detection timestamp */
|
|
88
|
+
timestamp: Date;
|
|
89
|
+
/** Whether the request should be blocked (set by policy) */
|
|
90
|
+
shouldBlock?: boolean;
|
|
91
|
+
/** Reason for blocking (set by policy) */
|
|
92
|
+
blockReason?: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* WASM bindings interface - functions exposed by the WASM module
|
|
96
|
+
*/
|
|
97
|
+
interface IWasmBindings {
|
|
98
|
+
/** Detect an agent from request metadata */
|
|
99
|
+
detect_agent(metadata: IWasmRequestMetadata): IWasmDetectionResult;
|
|
100
|
+
/** Get WASM module version */
|
|
101
|
+
get_version(): string;
|
|
102
|
+
/** Get build information */
|
|
103
|
+
get_build_info(): string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* WASM request metadata - input to WASM detect_agent function
|
|
107
|
+
*/
|
|
108
|
+
interface IWasmRequestMetadata {
|
|
109
|
+
user_agent: string | null;
|
|
110
|
+
ip_address: string | null;
|
|
111
|
+
headers: string;
|
|
112
|
+
timestamp: string;
|
|
113
|
+
url: string | null;
|
|
114
|
+
method: string | null;
|
|
115
|
+
client_fingerprint: string | null;
|
|
116
|
+
free(): void;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* WASM detection result - output from WASM detect_agent function
|
|
120
|
+
*/
|
|
121
|
+
interface IWasmDetectionResult {
|
|
122
|
+
is_agent: boolean;
|
|
123
|
+
confidence: number;
|
|
124
|
+
agent: string | null;
|
|
125
|
+
verification_method: string;
|
|
126
|
+
risk_level: string;
|
|
127
|
+
timestamp: string;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* WASM loader interface - abstracts WASM loading strategy
|
|
131
|
+
*/
|
|
132
|
+
interface IWasmLoader {
|
|
133
|
+
/** Load the WASM module */
|
|
134
|
+
load(): Promise<void>;
|
|
135
|
+
/** Get the WASM bindings after loading */
|
|
136
|
+
getBindings(): IWasmBindings;
|
|
137
|
+
/** Check if WASM is loaded */
|
|
138
|
+
isLoaded(): boolean;
|
|
139
|
+
/** Get the loading strategy name */
|
|
140
|
+
getStrategy(): string;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Agent detector interface - main detection API
|
|
144
|
+
*/
|
|
145
|
+
interface IDetector {
|
|
146
|
+
/** Analyze a request and detect if it's from an agent */
|
|
147
|
+
detect(input: IDetectionInput): Promise<IDetectionResult>;
|
|
148
|
+
/** Check if the detector is ready */
|
|
149
|
+
isReady(): boolean;
|
|
150
|
+
/** Ensure the detector is initialized */
|
|
151
|
+
ensureReady(): Promise<void>;
|
|
152
|
+
/** Get detector version */
|
|
153
|
+
getVersion(): Promise<string>;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Customer policy - rules for agent handling
|
|
157
|
+
*/
|
|
158
|
+
interface ICustomerPolicy {
|
|
159
|
+
/** Project ID */
|
|
160
|
+
projectId: string;
|
|
161
|
+
/** Agents to always block */
|
|
162
|
+
denyList?: string[];
|
|
163
|
+
/** Agents to always allow (if set, blocks all others) */
|
|
164
|
+
allowList?: string[];
|
|
165
|
+
/** Minimum confidence to trigger blocking */
|
|
166
|
+
blockThreshold?: number;
|
|
167
|
+
/** Path-based rules */
|
|
168
|
+
pathRules?: IPathRule[];
|
|
169
|
+
/** Policy version for cache invalidation */
|
|
170
|
+
version?: string;
|
|
171
|
+
/** Last updated timestamp */
|
|
172
|
+
updatedAt?: Date;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Path-based rule for policy
|
|
176
|
+
*/
|
|
177
|
+
interface IPathRule {
|
|
178
|
+
/** Path pattern (glob or regex) */
|
|
179
|
+
pattern: string;
|
|
180
|
+
/** Action for matching paths */
|
|
181
|
+
action: 'allow' | 'block' | 'challenge';
|
|
182
|
+
/** Specific agents this rule applies to */
|
|
183
|
+
agents?: string[];
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Policy loader interface - loads customer policies
|
|
187
|
+
*/
|
|
188
|
+
interface IPolicyLoader {
|
|
189
|
+
/** Load policy for an API key */
|
|
190
|
+
loadPolicy(apiKey: string): Promise<ICustomerPolicy>;
|
|
191
|
+
/** Get cached policy if available */
|
|
192
|
+
getCachedPolicy(apiKey: string): ICustomerPolicy | null;
|
|
193
|
+
/** Invalidate cached policy */
|
|
194
|
+
invalidateCache(apiKey: string): void;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Detector configuration options
|
|
198
|
+
*/
|
|
199
|
+
interface IDetectorOptions {
|
|
200
|
+
/** API key for loading customer policies */
|
|
201
|
+
apiKey?: string;
|
|
202
|
+
/** Custom WASM loader (for Edge Runtime static imports) */
|
|
203
|
+
wasmLoader?: IWasmLoader;
|
|
204
|
+
/** Whether to fall back to JavaScript if WASM fails */
|
|
205
|
+
fallbackToJS?: boolean;
|
|
206
|
+
/** Whether to cache policies */
|
|
207
|
+
cachePolicy?: boolean;
|
|
208
|
+
/** Policy cache TTL in milliseconds */
|
|
209
|
+
policyTTL?: number;
|
|
210
|
+
/** Base URL for policy API */
|
|
211
|
+
policyApiUrl?: string;
|
|
212
|
+
/** Enable debug logging */
|
|
213
|
+
debug?: boolean;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Confidence thresholds - centralized constants
|
|
217
|
+
*/
|
|
218
|
+
declare const CONFIDENCE: {
|
|
219
|
+
/** Minimum confidence for isAgent=true */
|
|
220
|
+
readonly THRESHOLD_AGENT: 30;
|
|
221
|
+
/** Cryptographic signature verified */
|
|
222
|
+
readonly SIGNATURE_VERIFIED: 100;
|
|
223
|
+
/** Signature header present but not verified */
|
|
224
|
+
readonly SIGNATURE_PRESENT: 85;
|
|
225
|
+
/** Strong pattern match */
|
|
226
|
+
readonly PATTERN_HIGH: 85;
|
|
227
|
+
/** Moderate pattern match */
|
|
228
|
+
readonly PATTERN_MEDIUM: 60;
|
|
229
|
+
/** Weak pattern match */
|
|
230
|
+
readonly PATTERN_LOW: 40;
|
|
231
|
+
/** Cloud IP detection only */
|
|
232
|
+
readonly CLOUD_IP: 30;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Unified WASM Detector
|
|
237
|
+
*
|
|
238
|
+
* Single implementation of the AgentShield detection engine used by all packages.
|
|
239
|
+
* Follows the Single Responsibility Principle: this class only handles detection.
|
|
240
|
+
*
|
|
241
|
+
* Key design decisions:
|
|
242
|
+
* - Confidence is ALWAYS on 0-100 scale (no conversions needed)
|
|
243
|
+
* - WASM output is used directly (no post-processing adjustments)
|
|
244
|
+
* - Policy application is optional and happens after detection
|
|
245
|
+
*/
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Unified WASM Detector
|
|
249
|
+
*
|
|
250
|
+
* Main detection class that wraps the WASM engine and provides
|
|
251
|
+
* a consistent interface across all AgentShield packages.
|
|
252
|
+
*/
|
|
253
|
+
declare class WasmDetector implements IDetector {
|
|
254
|
+
private readonly loader;
|
|
255
|
+
private readonly policyLoader?;
|
|
256
|
+
private readonly options;
|
|
257
|
+
private ready;
|
|
258
|
+
private loadPromise;
|
|
259
|
+
/**
|
|
260
|
+
* Create a new WasmDetector
|
|
261
|
+
* @param loader - WASM loader (static for Edge, dynamic for Node.js)
|
|
262
|
+
* @param policyLoader - Optional policy loader for API key support
|
|
263
|
+
* @param options - Detector configuration options
|
|
264
|
+
*/
|
|
265
|
+
constructor(loader: IWasmLoader, policyLoader?: IPolicyLoader | undefined, options?: IDetectorOptions);
|
|
266
|
+
/**
|
|
267
|
+
* Analyze a request and detect if it's from an agent
|
|
268
|
+
*/
|
|
269
|
+
detect(input: IDetectionInput): Promise<IDetectionResult>;
|
|
270
|
+
/**
|
|
271
|
+
* Check if the detector is ready
|
|
272
|
+
*/
|
|
273
|
+
isReady(): boolean;
|
|
274
|
+
/**
|
|
275
|
+
* Ensure the detector is initialized
|
|
276
|
+
*/
|
|
277
|
+
ensureReady(): Promise<void>;
|
|
278
|
+
/**
|
|
279
|
+
* Get detector version
|
|
280
|
+
*/
|
|
281
|
+
getVersion(): Promise<string>;
|
|
282
|
+
/**
|
|
283
|
+
* Initialize the detector
|
|
284
|
+
*/
|
|
285
|
+
private initialize;
|
|
286
|
+
/**
|
|
287
|
+
* Apply customer policy to detection result
|
|
288
|
+
*/
|
|
289
|
+
private applyPolicy;
|
|
290
|
+
/**
|
|
291
|
+
* Check if agent name matches a policy list entry
|
|
292
|
+
* Uses exact match or word-boundary prefix match to avoid false positives
|
|
293
|
+
* e.g., "gpt" matches "ChatGPT" and "GPT-4" but not "EgyptBot"
|
|
294
|
+
*/
|
|
295
|
+
private matchesPolicyEntry;
|
|
296
|
+
/**
|
|
297
|
+
* Escape special regex characters in a string
|
|
298
|
+
*/
|
|
299
|
+
private escapeRegex;
|
|
300
|
+
/**
|
|
301
|
+
* Apply policy rules to detection result
|
|
302
|
+
*/
|
|
303
|
+
private applyPolicyRules;
|
|
304
|
+
/**
|
|
305
|
+
* Infer agent type from name
|
|
306
|
+
*/
|
|
307
|
+
private inferAgentType;
|
|
308
|
+
/**
|
|
309
|
+
* Extract reasons from WASM result
|
|
310
|
+
*/
|
|
311
|
+
private extractReasons;
|
|
312
|
+
/**
|
|
313
|
+
* Create default result (assumed human)
|
|
314
|
+
*/
|
|
315
|
+
private createDefaultResult;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Static WASM Loader for Edge Runtime
|
|
320
|
+
*
|
|
321
|
+
* This loader is designed for environments that require static WASM imports,
|
|
322
|
+
* such as Vercel Edge Runtime and Cloudflare Workers.
|
|
323
|
+
*
|
|
324
|
+
* Usage:
|
|
325
|
+
* ```typescript
|
|
326
|
+
* // In your middleware.ts:
|
|
327
|
+
* import wasmModule from '@kya-os/checkpoint-wasm-runtime/wasm?module';
|
|
328
|
+
* import { StaticWasmLoader, WasmDetector } from '@kya-os/checkpoint-wasm-runtime/edge';
|
|
329
|
+
*
|
|
330
|
+
* const loader = new StaticWasmLoader(wasmModule);
|
|
331
|
+
* const detector = new WasmDetector(loader);
|
|
332
|
+
* ```
|
|
333
|
+
*
|
|
334
|
+
* The `?module` suffix tells bundlers (webpack, esbuild) to import the WASM
|
|
335
|
+
* as a pre-compiled WebAssembly.Module, which is required for Edge Runtime.
|
|
336
|
+
*/
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Static WASM Loader
|
|
340
|
+
*
|
|
341
|
+
* For Edge Runtime environments that require pre-compiled WASM modules.
|
|
342
|
+
* The consumer must provide the WASM module via a static import with `?module` suffix.
|
|
343
|
+
*
|
|
344
|
+
* This loader uses the wasm-bindgen generated JS glue code to properly
|
|
345
|
+
* initialize the WASM module with all required imports.
|
|
346
|
+
*/
|
|
347
|
+
declare class StaticWasmLoader implements IWasmLoader {
|
|
348
|
+
private readonly wasmModule;
|
|
349
|
+
private bindings;
|
|
350
|
+
private loadPromise;
|
|
351
|
+
private wasmExports;
|
|
352
|
+
/**
|
|
353
|
+
* Create a new StaticWasmLoader
|
|
354
|
+
* @param wasmModule - Pre-compiled WebAssembly.Module from static import
|
|
355
|
+
*/
|
|
356
|
+
constructor(wasmModule: WebAssembly.Module);
|
|
357
|
+
/**
|
|
358
|
+
* Load and instantiate the WASM module
|
|
359
|
+
*/
|
|
360
|
+
load(): Promise<void>;
|
|
361
|
+
/**
|
|
362
|
+
* Internal load implementation using wasm-bindgen initSync
|
|
363
|
+
*/
|
|
364
|
+
private doLoad;
|
|
365
|
+
/**
|
|
366
|
+
* Get the WASM bindings after loading
|
|
367
|
+
*/
|
|
368
|
+
getBindings(): IWasmBindings;
|
|
369
|
+
/**
|
|
370
|
+
* Check if WASM is loaded
|
|
371
|
+
*/
|
|
372
|
+
isLoaded(): boolean;
|
|
373
|
+
/**
|
|
374
|
+
* Get the loading strategy name
|
|
375
|
+
*/
|
|
376
|
+
getStrategy(): string;
|
|
377
|
+
/**
|
|
378
|
+
* Create bindings wrapper using wasm-bindgen exports
|
|
379
|
+
*/
|
|
380
|
+
private createBindings;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Create a static loader with validation
|
|
384
|
+
*/
|
|
385
|
+
declare function createStaticLoader(wasmModule: WebAssembly.Module): StaticWasmLoader;
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Policy Loader
|
|
389
|
+
*
|
|
390
|
+
* Loads customer policies from the AgentShield API.
|
|
391
|
+
* Supports LRU caching with background refresh.
|
|
392
|
+
*/
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Policy loader configuration
|
|
396
|
+
*/
|
|
397
|
+
interface PolicyLoaderConfig {
|
|
398
|
+
/** Base URL for the policy API */
|
|
399
|
+
apiUrl?: string;
|
|
400
|
+
/** Cache TTL in milliseconds (default: 5 minutes) */
|
|
401
|
+
cacheTTL?: number;
|
|
402
|
+
/** Maximum number of policies to cache (default: 100) */
|
|
403
|
+
maxCacheSize?: number;
|
|
404
|
+
/** Enable background refresh (default: true) */
|
|
405
|
+
backgroundRefresh?: boolean;
|
|
406
|
+
/** Timeout for API requests in milliseconds (default: 5000) */
|
|
407
|
+
timeout?: number;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Policy Loader
|
|
411
|
+
*
|
|
412
|
+
* Loads and caches customer policies from the AgentShield API.
|
|
413
|
+
* Follows Single Responsibility Principle: only handles policy loading.
|
|
414
|
+
*/
|
|
415
|
+
declare class PolicyLoader implements IPolicyLoader {
|
|
416
|
+
private cache;
|
|
417
|
+
private config;
|
|
418
|
+
constructor(config?: PolicyLoaderConfig);
|
|
419
|
+
/**
|
|
420
|
+
* Load policy for an API key
|
|
421
|
+
*/
|
|
422
|
+
loadPolicy(apiKey: string): Promise<ICustomerPolicy>;
|
|
423
|
+
/**
|
|
424
|
+
* Get cached policy if available and not expired
|
|
425
|
+
*/
|
|
426
|
+
getCachedPolicy(apiKey: string): ICustomerPolicy | null;
|
|
427
|
+
/**
|
|
428
|
+
* Invalidate cached policy
|
|
429
|
+
*/
|
|
430
|
+
invalidateCache(apiKey: string): void;
|
|
431
|
+
/**
|
|
432
|
+
* Fetch policy from API and cache it
|
|
433
|
+
*/
|
|
434
|
+
private fetchPolicy;
|
|
435
|
+
/**
|
|
436
|
+
* Fetch policy from API without caching
|
|
437
|
+
* Used internally for both direct fetches and background refreshes
|
|
438
|
+
*/
|
|
439
|
+
private fetchPolicyFromApi;
|
|
440
|
+
/**
|
|
441
|
+
* Cache a policy
|
|
442
|
+
*/
|
|
443
|
+
private cachePolicy;
|
|
444
|
+
/**
|
|
445
|
+
* Check if cached entry is expired
|
|
446
|
+
*/
|
|
447
|
+
private isExpired;
|
|
448
|
+
/**
|
|
449
|
+
* Check if cache entry should be refreshed
|
|
450
|
+
*/
|
|
451
|
+
private shouldRefresh;
|
|
452
|
+
/**
|
|
453
|
+
* Refresh policy in background
|
|
454
|
+
*/
|
|
455
|
+
private refreshInBackground;
|
|
456
|
+
/**
|
|
457
|
+
* Get default policy for a project
|
|
458
|
+
*/
|
|
459
|
+
private getDefaultPolicy;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Create a policy loader with default configuration
|
|
463
|
+
*/
|
|
464
|
+
declare function createPolicyLoader(config?: PolicyLoaderConfig): PolicyLoader;
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Rules-Based Fallback Detector
|
|
468
|
+
*
|
|
469
|
+
* JavaScript fallback detector that uses merged-rules.json when WASM is unavailable.
|
|
470
|
+
* This provides consistent detection using the same rules as WASM, just implemented in JS.
|
|
471
|
+
*/
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Rules-Based Fallback Detector
|
|
475
|
+
*
|
|
476
|
+
* Uses the same merged-rules.json as the WASM engine to provide
|
|
477
|
+
* consistent detection when WASM is not available.
|
|
478
|
+
*/
|
|
479
|
+
declare class RulesDetector implements IDetector {
|
|
480
|
+
private rules;
|
|
481
|
+
private ready;
|
|
482
|
+
/**
|
|
483
|
+
* Analyze a request and detect if it's from an agent
|
|
484
|
+
*/
|
|
485
|
+
detect(input: IDetectionInput): Promise<IDetectionResult>;
|
|
486
|
+
/**
|
|
487
|
+
* Check if the detector is ready
|
|
488
|
+
*/
|
|
489
|
+
isReady(): boolean;
|
|
490
|
+
/**
|
|
491
|
+
* Ensure the detector is initialized
|
|
492
|
+
*/
|
|
493
|
+
ensureReady(): Promise<void>;
|
|
494
|
+
/**
|
|
495
|
+
* Get detector version
|
|
496
|
+
*/
|
|
497
|
+
getVersion(): Promise<string>;
|
|
498
|
+
/**
|
|
499
|
+
* Normalize headers to lowercase keys
|
|
500
|
+
*/
|
|
501
|
+
private normalizeHeaders;
|
|
502
|
+
/**
|
|
503
|
+
* Match user agent against rules
|
|
504
|
+
*/
|
|
505
|
+
private matchUserAgent;
|
|
506
|
+
/**
|
|
507
|
+
* Match headers against suspicious header rules
|
|
508
|
+
*/
|
|
509
|
+
private matchHeaders;
|
|
510
|
+
/**
|
|
511
|
+
* Check if signature headers are present
|
|
512
|
+
*/
|
|
513
|
+
private hasSignatureHeaders;
|
|
514
|
+
/**
|
|
515
|
+
* Get human-readable agent name from rule key
|
|
516
|
+
*/
|
|
517
|
+
private getAgentName;
|
|
518
|
+
/**
|
|
519
|
+
* Infer agent type from name
|
|
520
|
+
*/
|
|
521
|
+
private inferAgentType;
|
|
522
|
+
/**
|
|
523
|
+
* Determine detection class
|
|
524
|
+
*/
|
|
525
|
+
private determineDetectionClass;
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Create a rules-based fallback detector
|
|
529
|
+
*/
|
|
530
|
+
declare function createRulesDetector(): RulesDetector;
|
|
4
531
|
|
|
5
532
|
/**
|
|
6
533
|
* Create a detector for Edge Runtime with static WASM import
|
|
@@ -19,4 +546,4 @@ declare function createFallbackDetector(): IDetector;
|
|
|
19
546
|
*/
|
|
20
547
|
declare function extractInputFromRequest(request: Request): IDetectionInput;
|
|
21
548
|
|
|
22
|
-
export { IDetectionInput, IDetector, IDetectorOptions, createEdgeDetector, createFallbackDetector, extractInputFromRequest };
|
|
549
|
+
export { CONFIDENCE, type DetectionClass, type ForgeabilityRisk, type ICustomerPolicy, type IDetectedAgent, type IDetectionInput, type IDetectionResult, type IDetector, type IDetectorOptions, type IPolicyLoader, type IWasmLoader, PolicyLoader, RulesDetector, StaticWasmLoader, type VerificationMethod, WasmDetector, createEdgeDetector, createFallbackDetector, createPolicyLoader, createRulesDetector, createStaticLoader, extractInputFromRequest };
|