@kya-os/checkpoint-wasm-runtime 1.1.1 → 1.1.3
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 +116 -0
- package/dist/edge.d.mts +531 -4
- package/dist/edge.d.ts +531 -4
- package/dist/edge.js +1 -1
- package/dist/edge.mjs +2 -2
- package/dist/engine.js +11 -0
- package/dist/engine.mjs +22 -4
- package/dist/index.d.mts +72 -5
- package/dist/index.d.ts +72 -5
- package/dist/index.js +3 -1
- package/dist/index.mjs +5 -2
- package/dist/node.d.mts +2 -3
- package/dist/node.d.ts +2 -3
- package/dist/node.js +1 -1
- package/dist/node.mjs +5 -2
- 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 +34 -4
- package/dist/orchestrator.d.mts +86 -6
- package/dist/orchestrator.d.ts +86 -6
- package/dist/orchestrator.js +29 -2
- package/dist/orchestrator.mjs +36 -4
- 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/dist/edge.d.ts
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 };
|
package/dist/edge.js
CHANGED
|
@@ -1218,7 +1218,7 @@ var RulesDetector = class {
|
|
|
1218
1218
|
return;
|
|
1219
1219
|
}
|
|
1220
1220
|
try {
|
|
1221
|
-
this.rules = checkpointShared.
|
|
1221
|
+
this.rules = checkpointShared.RuleLoader.loadSync();
|
|
1222
1222
|
this.ready = true;
|
|
1223
1223
|
} catch (error) {
|
|
1224
1224
|
console.warn("[RulesDetector] Failed to load rules:", error);
|
package/dist/edge.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RuleLoader } from '@kya-os/checkpoint-shared';
|
|
2
2
|
|
|
3
3
|
// src/types.ts
|
|
4
4
|
var CONFIDENCE = {
|
|
@@ -1216,7 +1216,7 @@ var RulesDetector = class {
|
|
|
1216
1216
|
return;
|
|
1217
1217
|
}
|
|
1218
1218
|
try {
|
|
1219
|
-
this.rules =
|
|
1219
|
+
this.rules = RuleLoader.loadSync();
|
|
1220
1220
|
this.ready = true;
|
|
1221
1221
|
} catch (error) {
|
|
1222
1222
|
console.warn("[RulesDetector] Failed to load rules:", error);
|
package/dist/engine.js
CHANGED
|
@@ -12,6 +12,9 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
12
12
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
13
13
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
14
14
|
});
|
|
15
|
+
var __esm = (fn, res) => function __init() {
|
|
16
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
17
|
+
};
|
|
15
18
|
var __commonJS = (cb, mod) => function __require2() {
|
|
16
19
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
17
20
|
};
|
|
@@ -32,9 +35,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
32
35
|
mod
|
|
33
36
|
));
|
|
34
37
|
|
|
38
|
+
// ../../node_modules/.pnpm/tsup@8.5.0_@swc+core@1.15.32_jiti@2.6.1_postcss@8.5.8_tsx@4.21.0_typescript@5.9.3_yaml@2.8.3/node_modules/tsup/assets/cjs_shims.js
|
|
39
|
+
var init_cjs_shims = __esm({
|
|
40
|
+
"../../node_modules/.pnpm/tsup@8.5.0_@swc+core@1.15.32_jiti@2.6.1_postcss@8.5.8_tsx@4.21.0_typescript@5.9.3_yaml@2.8.3/node_modules/tsup/assets/cjs_shims.js"() {
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
35
44
|
// wasm/kya-os-engine/kya_os_engine.js
|
|
36
45
|
var require_kya_os_engine = __commonJS({
|
|
37
46
|
"wasm/kya-os-engine/kya_os_engine.js"(exports$1, module) {
|
|
47
|
+
init_cjs_shims();
|
|
38
48
|
var imports = {};
|
|
39
49
|
imports["__wbindgen_placeholder__"] = module.exports;
|
|
40
50
|
var cachedUint8ArrayMemory0 = null;
|
|
@@ -445,6 +455,7 @@ ${val.stack}`;
|
|
|
445
455
|
});
|
|
446
456
|
|
|
447
457
|
// src/engine/index.ts
|
|
458
|
+
init_cjs_shims();
|
|
448
459
|
var wasmModule = __toESM(require_kya_os_engine());
|
|
449
460
|
function engineVerify(input, ctx) {
|
|
450
461
|
const verify2 = wasmModule.verify;
|
package/dist/engine.mjs
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
|
|
5
|
+
const require$1 = createRequire(import.meta.url);
|
|
1
6
|
var __create = Object.create;
|
|
2
7
|
var __defProp = Object.defineProperty;
|
|
3
8
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
9
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
10
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
11
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
12
|
+
var __require = /* @__PURE__ */ ((x) => typeof require$1 !== "undefined" ? require$1 : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
13
|
+
get: (a, b) => (typeof require$1 !== "undefined" ? require$1 : a)[b]
|
|
9
14
|
}) : x)(function(x) {
|
|
10
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
15
|
+
if (typeof require$1 !== "undefined") return require$1.apply(this, arguments);
|
|
11
16
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
17
|
});
|
|
18
|
+
var __esm = (fn, res) => function __init() {
|
|
19
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
20
|
+
};
|
|
13
21
|
var __commonJS = (cb, mod) => function __require2() {
|
|
14
22
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
15
23
|
};
|
|
@@ -29,10 +37,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
37
|
!mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
38
|
mod
|
|
31
39
|
));
|
|
40
|
+
var getFilename, getDirname, __dirname$1;
|
|
41
|
+
var init_esm_shims = __esm({
|
|
42
|
+
"../../node_modules/.pnpm/tsup@8.5.0_@swc+core@1.15.32_jiti@2.6.1_postcss@8.5.8_tsx@4.21.0_typescript@5.9.3_yaml@2.8.3/node_modules/tsup/assets/esm_shims.js"() {
|
|
43
|
+
getFilename = () => fileURLToPath(import.meta.url);
|
|
44
|
+
getDirname = () => path.dirname(getFilename());
|
|
45
|
+
__dirname$1 = /* @__PURE__ */ getDirname();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
32
48
|
|
|
33
49
|
// wasm/kya-os-engine/kya_os_engine.js
|
|
34
50
|
var require_kya_os_engine = __commonJS({
|
|
35
51
|
"wasm/kya-os-engine/kya_os_engine.js"(exports$1, module) {
|
|
52
|
+
init_esm_shims();
|
|
36
53
|
var imports = {};
|
|
37
54
|
imports["__wbindgen_placeholder__"] = module.exports;
|
|
38
55
|
var cachedUint8ArrayMemory0 = null;
|
|
@@ -435,7 +452,7 @@ ${val.stack}`;
|
|
|
435
452
|
exports$1.__wbindgen_object_drop_ref = function(arg0) {
|
|
436
453
|
takeObject(arg0);
|
|
437
454
|
};
|
|
438
|
-
var wasmPath = `${__dirname}/kya_os_engine_bg.wasm`;
|
|
455
|
+
var wasmPath = `${__dirname$1}/kya_os_engine_bg.wasm`;
|
|
439
456
|
var wasmBytes = __require("fs").readFileSync(wasmPath);
|
|
440
457
|
var wasmModule2 = new WebAssembly.Module(wasmBytes);
|
|
441
458
|
var wasm = exports$1.__wasm = new WebAssembly.Instance(wasmModule2, imports).exports;
|
|
@@ -443,6 +460,7 @@ ${val.stack}`;
|
|
|
443
460
|
});
|
|
444
461
|
|
|
445
462
|
// src/engine/index.ts
|
|
463
|
+
init_esm_shims();
|
|
446
464
|
var wasmModule = __toESM(require_kya_os_engine());
|
|
447
465
|
function engineVerify(input, ctx) {
|
|
448
466
|
const verify2 = wasmModule.verify;
|