@kya-os/checkpoint-wasm-runtime 1.2.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.
- package/CHANGELOG.md +176 -0
- package/dist/adapters.d.mts +1 -1
- package/dist/adapters.d.ts +1 -1
- package/dist/engine-edge.d.mts +2 -2
- package/dist/engine-edge.d.ts +2 -2
- package/dist/engine-edge.js +3 -509
- package/dist/engine-edge.mjs +3 -508
- package/dist/engine-node.d.mts +46 -0
- package/dist/engine-node.d.ts +46 -0
- package/dist/engine-node.js +31 -0
- package/dist/engine-node.mjs +10 -0
- package/dist/engine.d.mts +25 -4
- package/dist/engine.d.ts +25 -4
- package/dist/engine.js +2 -457
- package/dist/engine.mjs +2 -464
- package/dist/index.d.mts +531 -3
- package/dist/index.d.ts +531 -3
- package/dist/index.js +2 -28
- package/dist/index.mjs +2 -29
- package/dist/node.d.mts +524 -3
- package/dist/node.d.ts +524 -3
- package/dist/node.js +2 -26
- package/dist/node.mjs +2 -26
- package/dist/orchestrator-edge.d.mts +24 -10
- package/dist/orchestrator-edge.d.ts +24 -10
- package/dist/orchestrator-edge.js +5 -510
- package/dist/orchestrator-edge.mjs +5 -509
- package/dist/orchestrator-node.d.mts +60 -52
- package/dist/orchestrator-node.d.ts +60 -52
- package/dist/orchestrator-node.js +50 -487
- package/dist/orchestrator-node.mjs +34 -497
- package/dist/orchestrator.d.mts +356 -4
- package/dist/orchestrator.d.ts +356 -4
- package/dist/orchestrator.js +37 -1001
- package/dist/orchestrator.mjs +37 -1005
- package/dist/{types-ByrdPLL2.d.ts → types-KPEcVvac.d.mts} +31 -1
- package/dist/{types-ByrdPLL2.d.mts → types-KPEcVvac.d.ts} +31 -1
- package/package.json +13 -2
- package/wasm/agentshield_wasm_bg.wasm +0 -0
- package/wasm/kya-os-engine/kya_os_engine_bg.wasm +0 -0
- package/wasm/kya-os-engine/package.json +24 -4
- package/wasm/kya-os-engine-bundler/kya_os_engine.d.ts +24 -0
- package/wasm/kya-os-engine-bundler/kya_os_engine.js +4 -0
- package/wasm/kya-os-engine-bundler/kya_os_engine_bg.js +522 -0
- package/wasm/kya-os-engine-bundler/kya_os_engine_bg.wasm +0 -0
- package/wasm/kya-os-engine-bundler/kya_os_engine_bg.wasm.d.ts +8 -0
- package/wasm/kya-os-engine-web/kya_os_engine_bg.wasm +0 -0
- package/wasm/kya-os-engine-web/package.json +25 -3
- package/dist/kya_os_engine_bg.wasm +0 -0
- package/dist/rules-detector-ZIKHN-_y.d.mts +0 -532
- package/dist/rules-detector-ZIKHN-_y.d.ts +0 -532
package/dist/node.d.ts
CHANGED
|
@@ -1,5 +1,526 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
+
* Create a policy loader with default configuration
|
|
456
|
+
*/
|
|
457
|
+
declare function createPolicyLoader(config?: PolicyLoaderConfig): PolicyLoader;
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Rules-Based Fallback Detector
|
|
461
|
+
*
|
|
462
|
+
* JavaScript fallback detector that uses merged-rules.json when WASM is unavailable.
|
|
463
|
+
* This provides consistent detection using the same rules as WASM, just implemented in JS.
|
|
464
|
+
*/
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Rules-Based Fallback Detector
|
|
468
|
+
*
|
|
469
|
+
* Uses the same merged-rules.json as the WASM engine to provide
|
|
470
|
+
* consistent detection when WASM is not available.
|
|
471
|
+
*/
|
|
472
|
+
declare class RulesDetector implements IDetector {
|
|
473
|
+
private rules;
|
|
474
|
+
private ready;
|
|
475
|
+
/**
|
|
476
|
+
* Analyze a request and detect if it's from an agent
|
|
477
|
+
*/
|
|
478
|
+
detect(input: IDetectionInput): Promise<IDetectionResult>;
|
|
479
|
+
/**
|
|
480
|
+
* Check if the detector is ready
|
|
481
|
+
*/
|
|
482
|
+
isReady(): boolean;
|
|
483
|
+
/**
|
|
484
|
+
* Ensure the detector is initialized
|
|
485
|
+
*/
|
|
486
|
+
ensureReady(): Promise<void>;
|
|
487
|
+
/**
|
|
488
|
+
* Get detector version
|
|
489
|
+
*/
|
|
490
|
+
getVersion(): Promise<string>;
|
|
491
|
+
/**
|
|
492
|
+
* Normalize headers to lowercase keys
|
|
493
|
+
*/
|
|
494
|
+
private normalizeHeaders;
|
|
495
|
+
/**
|
|
496
|
+
* Match user agent against rules
|
|
497
|
+
*/
|
|
498
|
+
private matchUserAgent;
|
|
499
|
+
/**
|
|
500
|
+
* Match headers against suspicious header rules
|
|
501
|
+
*/
|
|
502
|
+
private matchHeaders;
|
|
503
|
+
/**
|
|
504
|
+
* Check if signature headers are present
|
|
505
|
+
*/
|
|
506
|
+
private hasSignatureHeaders;
|
|
507
|
+
/**
|
|
508
|
+
* Get human-readable agent name from rule key
|
|
509
|
+
*/
|
|
510
|
+
private getAgentName;
|
|
511
|
+
/**
|
|
512
|
+
* Infer agent type from name
|
|
513
|
+
*/
|
|
514
|
+
private inferAgentType;
|
|
515
|
+
/**
|
|
516
|
+
* Determine detection class
|
|
517
|
+
*/
|
|
518
|
+
private determineDetectionClass;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Create a rules-based fallback detector
|
|
522
|
+
*/
|
|
523
|
+
declare function createRulesDetector(): RulesDetector;
|
|
3
524
|
|
|
4
525
|
/**
|
|
5
526
|
* Create a detector for Node.js with dynamic WASM loading
|
|
@@ -22,4 +543,4 @@ declare function extractInputFromExpressRequest(req: {
|
|
|
22
543
|
method?: string;
|
|
23
544
|
}): IDetectionInput;
|
|
24
545
|
|
|
25
|
-
export { IDetectionInput, IDetector, IDetectorOptions, createFallbackDetector, createNodeDetector, extractInputFromExpressRequest };
|
|
546
|
+
export { CONFIDENCE, type DetectionClass, DynamicWasmLoader, type ForgeabilityRisk, type ICustomerPolicy, type IDetectedAgent, type IDetectionInput, type IDetectionResult, type IDetector, type IDetectorOptions, type IPolicyLoader, type IWasmLoader, PolicyLoader, RulesDetector, type VerificationMethod, WasmDetector, createDynamicLoader, createFallbackDetector, createNodeDetector, createPolicyLoader, createRulesDetector, extractInputFromExpressRequest };
|
package/dist/node.js
CHANGED
|
@@ -352,24 +352,6 @@ async function findWasmModule() {
|
|
|
352
352
|
try {
|
|
353
353
|
const fs = await import('fs/promises');
|
|
354
354
|
const nodePath = await import('path');
|
|
355
|
-
let moduleDir = null;
|
|
356
|
-
try {
|
|
357
|
-
const importMetaUrl = eval('typeof import.meta !== "undefined" && import.meta.url');
|
|
358
|
-
if (importMetaUrl) {
|
|
359
|
-
const url = await import('url');
|
|
360
|
-
moduleDir = nodePath.dirname(url.fileURLToPath(importMetaUrl));
|
|
361
|
-
}
|
|
362
|
-
} catch {
|
|
363
|
-
}
|
|
364
|
-
if (!moduleDir) {
|
|
365
|
-
try {
|
|
366
|
-
const cjsDirname = eval('typeof __dirname !== "undefined" && __dirname');
|
|
367
|
-
if (cjsDirname) {
|
|
368
|
-
moduleDir = cjsDirname;
|
|
369
|
-
}
|
|
370
|
-
} catch {
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
355
|
const fsWasmPaths = [
|
|
374
356
|
nodePath.resolve(
|
|
375
357
|
process.cwd(),
|
|
@@ -380,12 +362,6 @@ async function findWasmModule() {
|
|
|
380
362
|
"node_modules/@kya-os/checkpoint/dist/wasm/agentshield_wasm_bg.wasm"
|
|
381
363
|
)
|
|
382
364
|
];
|
|
383
|
-
if (moduleDir) {
|
|
384
|
-
fsWasmPaths.unshift(
|
|
385
|
-
nodePath.resolve(moduleDir, "../wasm/agentshield_wasm_bg.wasm"),
|
|
386
|
-
nodePath.resolve(moduleDir, "../../wasm/agentshield_wasm_bg.wasm")
|
|
387
|
-
);
|
|
388
|
-
}
|
|
389
365
|
for (const wasmPath of fsWasmPaths) {
|
|
390
366
|
try {
|
|
391
367
|
const buffer = await fs.readFile(wasmPath);
|
|
@@ -442,8 +418,8 @@ var DynamicWasmLoader = class {
|
|
|
442
418
|
try {
|
|
443
419
|
let wasmBuffer;
|
|
444
420
|
if (this.wasmPath) {
|
|
445
|
-
const
|
|
446
|
-
const buffer = await
|
|
421
|
+
const fs = await import('fs/promises');
|
|
422
|
+
const buffer = await fs.readFile(this.wasmPath);
|
|
447
423
|
wasmBuffer = new ArrayBuffer(buffer.byteLength);
|
|
448
424
|
new Uint8Array(wasmBuffer).set(buffer);
|
|
449
425
|
} else {
|
package/dist/node.mjs
CHANGED
|
@@ -353,24 +353,6 @@ async function findWasmModule() {
|
|
|
353
353
|
try {
|
|
354
354
|
const fs = await import('fs/promises');
|
|
355
355
|
const nodePath = await import('path');
|
|
356
|
-
let moduleDir = null;
|
|
357
|
-
try {
|
|
358
|
-
const importMetaUrl = eval('typeof import.meta !== "undefined" && import.meta.url');
|
|
359
|
-
if (importMetaUrl) {
|
|
360
|
-
const url = await import('url');
|
|
361
|
-
moduleDir = nodePath.dirname(url.fileURLToPath(importMetaUrl));
|
|
362
|
-
}
|
|
363
|
-
} catch {
|
|
364
|
-
}
|
|
365
|
-
if (!moduleDir) {
|
|
366
|
-
try {
|
|
367
|
-
const cjsDirname = eval('typeof __dirname !== "undefined" && __dirname');
|
|
368
|
-
if (cjsDirname) {
|
|
369
|
-
moduleDir = cjsDirname;
|
|
370
|
-
}
|
|
371
|
-
} catch {
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
356
|
const fsWasmPaths = [
|
|
375
357
|
nodePath.resolve(
|
|
376
358
|
process.cwd(),
|
|
@@ -381,12 +363,6 @@ async function findWasmModule() {
|
|
|
381
363
|
"node_modules/@kya-os/checkpoint/dist/wasm/agentshield_wasm_bg.wasm"
|
|
382
364
|
)
|
|
383
365
|
];
|
|
384
|
-
if (moduleDir) {
|
|
385
|
-
fsWasmPaths.unshift(
|
|
386
|
-
nodePath.resolve(moduleDir, "../wasm/agentshield_wasm_bg.wasm"),
|
|
387
|
-
nodePath.resolve(moduleDir, "../../wasm/agentshield_wasm_bg.wasm")
|
|
388
|
-
);
|
|
389
|
-
}
|
|
390
366
|
for (const wasmPath of fsWasmPaths) {
|
|
391
367
|
try {
|
|
392
368
|
const buffer = await fs.readFile(wasmPath);
|
|
@@ -443,8 +419,8 @@ var DynamicWasmLoader = class {
|
|
|
443
419
|
try {
|
|
444
420
|
let wasmBuffer;
|
|
445
421
|
if (this.wasmPath) {
|
|
446
|
-
const
|
|
447
|
-
const buffer = await
|
|
422
|
+
const fs = await import('fs/promises');
|
|
423
|
+
const buffer = await fs.readFile(this.wasmPath);
|
|
448
424
|
wasmBuffer = new ArrayBuffer(buffer.byteLength);
|
|
449
425
|
new Uint8Array(wasmBuffer).set(buffer);
|
|
450
426
|
} else {
|
|
@@ -1,17 +1,8 @@
|
|
|
1
1
|
export { initEngineEdge } from './engine-edge.mjs';
|
|
2
|
-
import { E as EnforcementMode, A as AgentRequest, V as VerifyResult } from './types-
|
|
2
|
+
import { E as EnforcementMode, A as AgentRequest, C as ContextSpec, V as VerifyResult, e as EngineConfig } from './types-KPEcVvac.mjs';
|
|
3
3
|
import { DidResolverAdapter, StatusListCacheAdapter, ReputationOracleAdapter, PolicyEvaluatorAdapter, ClockAdapter } from './adapters.mjs';
|
|
4
4
|
import '@kya-os/checkpoint-shared';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Orchestrator-layer types — Phase C, host-side only.
|
|
8
|
-
*
|
|
9
|
-
* Nothing here crosses the WASM boundary. The engine ABI types live
|
|
10
|
-
* in `../types.ts`; the adapter interfaces live in
|
|
11
|
-
* `../adapters/index.ts`. This file is the host-wrapper-facing
|
|
12
|
-
* surface — what Phase D (Next.js) and Phase E (Express) import.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
6
|
/**
|
|
16
7
|
* Framework-agnostic HTTP request shape.
|
|
17
8
|
*
|
|
@@ -68,6 +59,29 @@ interface VerifyRequestOpts {
|
|
|
68
59
|
argusUrl?: string;
|
|
69
60
|
/** Injectable for the once-only Argus configuration warning. */
|
|
70
61
|
logger?: (msg: string) => void;
|
|
62
|
+
/**
|
|
63
|
+
* Override the engine WASM-bridge function used during the sync
|
|
64
|
+
* `verify()` call. Defaults to the wasm-bindgen `--target bundler`
|
|
65
|
+
* variant imported by `./verify-request.ts` from `'../index'`.
|
|
66
|
+
*
|
|
67
|
+
* The `./orchestrator/node` subpath (SDK-Next.js-Integration-Audit-1
|
|
68
|
+
* / #2618 safety net) injects the `--target nodejs` variant here so
|
|
69
|
+
* Webpack-without-asyncWebAssembly consumers don't transitively pull
|
|
70
|
+
* the bundler artifact through the orchestrator's verify call.
|
|
71
|
+
*/
|
|
72
|
+
engineVerifyFn?: (input: AgentRequest, ctx: ContextSpec) => VerifyResult;
|
|
73
|
+
/**
|
|
74
|
+
* Engine-default behaviour knobs forwarded onto every composed
|
|
75
|
+
* `ContextSpec`. Defaults to `{ tier3Action: 'monitor' }` so a host
|
|
76
|
+
* installing `@kya-os/checkpoint-*` with minimal config preserves
|
|
77
|
+
* 1.3.0 behaviour — tenant policy is the arbiter, the engine does
|
|
78
|
+
* not short-circuit known-agent UAs with an engine-default Block.
|
|
79
|
+
*
|
|
80
|
+
* Host wrappers that want the calibrated engine-default block opt
|
|
81
|
+
* into `{ tier3Action: 'block' }`. The bench harness is the
|
|
82
|
+
* canonical opt-in consumer. See the wasm-runtime 1.4.0 CHANGELOG.
|
|
83
|
+
*/
|
|
84
|
+
engineConfig?: EngineConfig;
|
|
71
85
|
}
|
|
72
86
|
/**
|
|
73
87
|
* Transport-agnostic response shape `renderDecisionAsResponse`
|