@kya-os/checkpoint-wasm-runtime 1.3.0 → 1.4.0

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +110 -1
  2. package/dist/adapters.d.mts +1 -1
  3. package/dist/adapters.d.ts +1 -1
  4. package/dist/engine-edge.d.mts +2 -2
  5. package/dist/engine-edge.d.ts +2 -2
  6. package/dist/engine-edge.js +3 -509
  7. package/dist/engine-edge.mjs +3 -508
  8. package/dist/engine-node.d.mts +46 -0
  9. package/dist/engine-node.d.ts +46 -0
  10. package/dist/engine-node.js +31 -0
  11. package/dist/engine-node.mjs +10 -0
  12. package/dist/engine.d.mts +25 -4
  13. package/dist/engine.d.ts +25 -4
  14. package/dist/engine.js +2 -457
  15. package/dist/engine.mjs +2 -464
  16. package/dist/index.d.mts +531 -3
  17. package/dist/index.d.ts +531 -3
  18. package/dist/index.js +2 -28
  19. package/dist/index.mjs +2 -29
  20. package/dist/node.d.mts +524 -3
  21. package/dist/node.d.ts +524 -3
  22. package/dist/node.js +2 -26
  23. package/dist/node.mjs +2 -26
  24. package/dist/orchestrator-edge.d.mts +24 -10
  25. package/dist/orchestrator-edge.d.ts +24 -10
  26. package/dist/orchestrator-edge.js +5 -510
  27. package/dist/orchestrator-edge.mjs +5 -509
  28. package/dist/orchestrator-node.d.mts +60 -52
  29. package/dist/orchestrator-node.d.ts +60 -52
  30. package/dist/orchestrator-node.js +50 -487
  31. package/dist/orchestrator-node.mjs +34 -497
  32. package/dist/orchestrator.d.mts +356 -4
  33. package/dist/orchestrator.d.ts +356 -4
  34. package/dist/orchestrator.js +37 -1001
  35. package/dist/orchestrator.mjs +37 -1005
  36. package/dist/{types-ByrdPLL2.d.ts → types-KPEcVvac.d.mts} +31 -1
  37. package/dist/{types-ByrdPLL2.d.mts → types-KPEcVvac.d.ts} +31 -1
  38. package/package.json +13 -2
  39. package/wasm/kya-os-engine/kya_os_engine_bg.wasm +0 -0
  40. package/wasm/kya-os-engine/package.json +24 -4
  41. package/wasm/kya-os-engine-bundler/kya_os_engine.d.ts +24 -0
  42. package/wasm/kya-os-engine-bundler/kya_os_engine.js +4 -0
  43. package/wasm/kya-os-engine-bundler/kya_os_engine_bg.js +522 -0
  44. package/wasm/kya-os-engine-bundler/kya_os_engine_bg.wasm +0 -0
  45. package/wasm/kya-os-engine-bundler/kya_os_engine_bg.wasm.d.ts +8 -0
  46. package/wasm/kya-os-engine-web/kya_os_engine_bg.wasm +0 -0
  47. package/wasm/kya-os-engine-web/package.json +25 -3
  48. package/dist/kya_os_engine_bg.wasm +0 -0
  49. package/dist/rules-detector-ZIKHN-_y.d.mts +0 -532
  50. package/dist/rules-detector-ZIKHN-_y.d.ts +0 -532
@@ -1,532 +0,0 @@
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
- * Dynamic WASM Loader for Node.js
320
- *
321
- * This loader dynamically loads and compiles WASM at runtime,
322
- * which is supported in Node.js but NOT in Edge Runtime.
323
- *
324
- * Usage:
325
- * ```typescript
326
- * import { DynamicWasmLoader, WasmDetector } from '@kya-os/checkpoint-wasm-runtime/node';
327
- *
328
- * const loader = new DynamicWasmLoader();
329
- * const detector = new WasmDetector(loader);
330
- * ```
331
- */
332
-
333
- /**
334
- * Dynamic WASM Loader
335
- *
336
- * For Node.js environments that support dynamic WASM compilation.
337
- * Automatically finds and loads the WASM module.
338
- */
339
- declare class DynamicWasmLoader implements IWasmLoader {
340
- private readonly wasmPath?;
341
- private bindings;
342
- private instance;
343
- private loadPromise;
344
- /**
345
- * Create a new DynamicWasmLoader
346
- * @param wasmPath - Optional custom path to WASM file
347
- */
348
- constructor(wasmPath?: string | undefined);
349
- /**
350
- * Load and compile the WASM module
351
- */
352
- load(): Promise<void>;
353
- private doLoad;
354
- /**
355
- * Get the WASM bindings after loading
356
- */
357
- getBindings(): IWasmBindings;
358
- /**
359
- * Check if WASM is loaded
360
- */
361
- isLoaded(): boolean;
362
- /**
363
- * Get the loading strategy name
364
- */
365
- getStrategy(): string;
366
- /**
367
- * Create wasm-bindgen required imports
368
- */
369
- private createWasmBindgenImports;
370
- /**
371
- * Create bindings wrapper from WASM exports
372
- */
373
- private createBindings;
374
- }
375
- /**
376
- * Create a dynamic loader
377
- */
378
- declare function createDynamicLoader(wasmPath?: string): DynamicWasmLoader;
379
-
380
- /**
381
- * Policy Loader
382
- *
383
- * Loads customer policies from the AgentShield API.
384
- * Supports LRU caching with background refresh.
385
- */
386
-
387
- /**
388
- * Policy loader configuration
389
- */
390
- interface PolicyLoaderConfig {
391
- /** Base URL for the policy API */
392
- apiUrl?: string;
393
- /** Cache TTL in milliseconds (default: 5 minutes) */
394
- cacheTTL?: number;
395
- /** Maximum number of policies to cache (default: 100) */
396
- maxCacheSize?: number;
397
- /** Enable background refresh (default: true) */
398
- backgroundRefresh?: boolean;
399
- /** Timeout for API requests in milliseconds (default: 5000) */
400
- timeout?: number;
401
- }
402
- /**
403
- * Policy Loader
404
- *
405
- * Loads and caches customer policies from the AgentShield API.
406
- * Follows Single Responsibility Principle: only handles policy loading.
407
- */
408
- declare class PolicyLoader implements IPolicyLoader {
409
- private cache;
410
- private config;
411
- constructor(config?: PolicyLoaderConfig);
412
- /**
413
- * Load policy for an API key
414
- */
415
- loadPolicy(apiKey: string): Promise<ICustomerPolicy>;
416
- /**
417
- * Get cached policy if available and not expired
418
- */
419
- getCachedPolicy(apiKey: string): ICustomerPolicy | null;
420
- /**
421
- * Invalidate cached policy
422
- */
423
- invalidateCache(apiKey: string): void;
424
- /**
425
- * Fetch policy from API and cache it
426
- */
427
- private fetchPolicy;
428
- /**
429
- * Fetch policy from API without caching
430
- * Used internally for both direct fetches and background refreshes
431
- */
432
- private fetchPolicyFromApi;
433
- /**
434
- * Cache a policy
435
- */
436
- private cachePolicy;
437
- /**
438
- * Check if cached entry is expired
439
- */
440
- private isExpired;
441
- /**
442
- * Check if cache entry should be refreshed
443
- */
444
- private shouldRefresh;
445
- /**
446
- * Refresh policy in background
447
- */
448
- private refreshInBackground;
449
- /**
450
- * Get default policy for a project
451
- */
452
- private getDefaultPolicy;
453
- }
454
- /**
455
- * Policy load error
456
- */
457
- declare class PolicyLoadError extends Error {
458
- readonly code: 'INVALID_API_KEY' | 'API_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT';
459
- constructor(message: string, code: 'INVALID_API_KEY' | 'API_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT');
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;
531
-
532
- export { CONFIDENCE as C, type DetectionClass as D, type ForgeabilityRisk as F, type IDetector as I, PolicyLoader as P, RulesDetector as R, type VerificationMethod as V, WasmDetector as W, type IDetectorOptions as a, type IDetectionInput as b, DynamicWasmLoader as c, type ICustomerPolicy as d, type IDetectedAgent as e, type IDetectionResult as f, type IPolicyLoader as g, type IWasmLoader as h, createDynamicLoader as i, createPolicyLoader as j, createRulesDetector as k, type IWasmBindings as l, type IPathRule as m, PolicyLoadError as n, type PolicyLoaderConfig as o };