@kya-os/agentshield-nextjs 0.2.9 → 0.2.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kya-os/agentshield-nextjs",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "description": "Next.js middleware for AgentShield AI agent detection",
5
5
  "keywords": [
6
6
  "nextjs",
@@ -95,6 +95,22 @@
95
95
  "engines": {
96
96
  "node": ">=18.0.0"
97
97
  },
98
+ "scripts": {
99
+ "build": "tsup",
100
+ "build:watch": "tsup --watch",
101
+ "predev": "pnpm --filter=@kya-os/agentshield-shared build && pnpm --filter=@kya-os/agentshield build",
102
+ "dev": "tsup --watch",
103
+ "clean": "rimraf dist .tsbuildinfo",
104
+ "test": "vitest run",
105
+ "test:watch": "vitest",
106
+ "test:coverage": "vitest run --coverage",
107
+ "type-check": "tsc --noEmit",
108
+ "lint": "eslint src --ext .ts,.tsx",
109
+ "lint:fix": "eslint src --ext .ts,.tsx --fix",
110
+ "format": "prettier --write \"src/**/*.{ts,tsx,json,md}\"",
111
+ "format:check": "prettier --check \"src/**/*.{ts,tsx,json,md}\"",
112
+ "prepublishOnly": "pnpm build && pnpm test"
113
+ },
98
114
  "devDependencies": {
99
115
  "@testing-library/react": "^14.2.1",
100
116
  "@testing-library/react-hooks": "^8.0.1",
@@ -125,25 +141,10 @@
125
141
  },
126
142
  "sideEffects": false,
127
143
  "dependencies": {
144
+ "@kya-os/agentshield": "workspace:*",
145
+ "@kya-os/agentshield-shared": "workspace:*",
146
+ "@kya-os/agentshield-wasm-runtime": "workspace:*",
128
147
  "@noble/ed25519": "^2.2.3",
129
- "@noble/hashes": "^2.0.1",
130
- "@kya-os/agentshield": "0.1.39",
131
- "@kya-os/agentshield-shared": "0.2.3",
132
- "@kya-os/agentshield-wasm-runtime": "0.1.6"
133
- },
134
- "scripts": {
135
- "build": "tsup",
136
- "build:watch": "tsup --watch",
137
- "predev": "pnpm --filter=@kya-os/agentshield-shared build && pnpm --filter=@kya-os/agentshield build",
138
- "dev": "tsup --watch",
139
- "clean": "rimraf dist .tsbuildinfo",
140
- "test": "vitest run",
141
- "test:watch": "vitest",
142
- "test:coverage": "vitest run --coverage",
143
- "type-check": "tsc --noEmit",
144
- "lint": "eslint src --ext .ts,.tsx",
145
- "lint:fix": "eslint src --ext .ts,.tsx --fix",
146
- "format": "prettier --write \"src/**/*.{ts,tsx,json,md}\"",
147
- "format:check": "prettier --check \"src/**/*.{ts,tsx,json,md}\""
148
+ "@noble/hashes": "^2.0.1"
148
149
  }
149
- }
150
+ }
@@ -12,24 +12,156 @@ export function detect_agent(metadata: JsRequestMetadata): JsDetectionResult;
12
12
  * Get the version of the AgentShield library
13
13
  */
14
14
  export function version(): string;
15
+ /**
16
+ * Get the version of the AgentShield library
17
+ */
18
+ export function get_version(): string;
19
+ /**
20
+ * Get build information
21
+ */
22
+ export function get_build_info(): string;
23
+ /**
24
+ * Verify an MCP-I proof (VC-JWT token)
25
+ *
26
+ * This function verifies a Verifiable Credential JWT and extracts the
27
+ * principal (issuer) and agent (subject) DIDs.
28
+ *
29
+ * # Arguments
30
+ *
31
+ * * `vc_jwt` - The VC-JWT token string (header.payload.signature)
32
+ * * `current_time_secs` - Current Unix timestamp in seconds (for expiration check)
33
+ *
34
+ * # Returns
35
+ *
36
+ * A `JsMcpIVerificationResult` with verification status and extracted DIDs.
37
+ */
38
+ export function verify_mcp_i_proof(
39
+ vc_jwt: string,
40
+ current_time_secs: bigint
41
+ ): JsMcpIVerificationResult;
42
+ /**
43
+ * Resolve a did:key identifier to its public key
44
+ *
45
+ * # Arguments
46
+ *
47
+ * * `did` - The did:key identifier (e.g., "did:key:z6Mkf...")
48
+ *
49
+ * # Returns
50
+ *
51
+ * A `JsDidKeyResult` with the resolved public key or an error.
52
+ */
53
+ export function resolve_did_key_wasm(did: string): JsDidKeyResult;
54
+ /**
55
+ * Check if a requested scope is permitted by granted scopes
56
+ *
57
+ * # Arguments
58
+ *
59
+ * * `requested` - The scope being requested (e.g., "read:email")
60
+ * * `granted_json` - JSON array of granted scopes (e.g., "[\"read:*\", \"write:calendar\"]")
61
+ *
62
+ * # Returns
63
+ *
64
+ * A `JsScopeCheckResult` indicating whether the scope is permitted.
65
+ */
66
+ export function check_delegation_scope(requested: string, granted_json: string): JsScopeCheckResult;
67
+ /**
68
+ * Verify a delegation with time constraints
69
+ *
70
+ * # Arguments
71
+ *
72
+ * * `requested` - The scope being requested
73
+ * * `granted_json` - JSON array of granted scopes
74
+ * * `not_before` - Optional Unix timestamp (0 to skip)
75
+ * * `not_after` - Optional Unix timestamp (0 to skip)
76
+ * * `current_time` - Current Unix timestamp (0 to skip time checks)
77
+ *
78
+ * # Returns
79
+ *
80
+ * A `JsScopeCheckResult` indicating whether the delegation is valid.
81
+ */
82
+ export function verify_delegation_scope(
83
+ requested: string,
84
+ granted_json: string,
85
+ not_before: bigint,
86
+ not_after: bigint,
87
+ current_time: bigint
88
+ ): JsScopeCheckResult;
89
+ /**
90
+ * Evaluate a request against a policy configuration
91
+ *
92
+ * # Arguments
93
+ *
94
+ * * `policy_json` - Policy configuration as JSON string
95
+ * * `context_json` - Evaluation context as JSON string
96
+ *
97
+ * # Returns
98
+ *
99
+ * A `JsPolicyEvaluationResult` with the enforcement action and reason.
100
+ *
101
+ * # Example
102
+ *
103
+ * ```javascript
104
+ * const policy = JSON.stringify({
105
+ * version: "1.0.0",
106
+ * enabled: true,
107
+ * defaultAction: "allow",
108
+ * thresholds: { confidenceThreshold: 80, confidenceAction: "block" },
109
+ * denyList: [],
110
+ * allowList: [],
111
+ * rules: []
112
+ * });
113
+ *
114
+ * const context = JSON.stringify({
115
+ * agentType: "ai_agent",
116
+ * agentName: "ChatGPT",
117
+ * confidence: 95
118
+ * });
119
+ *
120
+ * const result = evaluate_policy(policy, context);
121
+ * console.log(result.action); // "block" (confidence exceeded threshold)
122
+ * ```
123
+ */
124
+ export function evaluate_policy(
125
+ policy_json: string,
126
+ context_json: string
127
+ ): JsPolicyEvaluationResult;
128
+ /**
129
+ * Check if a policy allows a request (convenience function)
130
+ *
131
+ * # Arguments
132
+ *
133
+ * * `policy_json` - Policy configuration as JSON string
134
+ * * `context_json` - Evaluation context as JSON string
135
+ *
136
+ * # Returns
137
+ *
138
+ * `true` if the request is allowed, `false` otherwise.
139
+ */
140
+ export function policy_allows(policy_json: string, context_json: string): boolean;
15
141
  /**
16
142
  * JavaScript-compatible detection result
17
143
  */
18
144
  export class JsDetectionResult {
19
145
  private constructor();
20
146
  free(): void;
147
+ [Symbol.dispose](): void;
21
148
  /**
22
149
  * Whether the request was identified as coming from an agent
23
150
  */
24
151
  is_agent: boolean;
25
152
  /**
26
- * Confidence score (0.0 to 1.0)
153
+ * Confidence score (0.0 to 1.0 scale)
27
154
  */
28
155
  confidence: number;
29
156
  /**
30
157
  * Get the detected agent name
31
158
  */
32
159
  readonly agent: string | undefined;
160
+ /**
161
+ * Get the detection class for database storage
162
+ * Returns: 'human', 'ai_agent', 'bot', 'automation', or 'unknown'
163
+ */
164
+ readonly detection_class: string;
33
165
  /**
34
166
  * Get the verification method as a string
35
167
  */
@@ -43,15 +175,127 @@ export class JsDetectionResult {
43
175
  */
44
176
  readonly timestamp: string;
45
177
  }
178
+ /**
179
+ * JavaScript-compatible result from did:key resolution
180
+ */
181
+ export class JsDidKeyResult {
182
+ private constructor();
183
+ free(): void;
184
+ [Symbol.dispose](): void;
185
+ /**
186
+ * Whether the resolution was successful
187
+ */
188
+ success: boolean;
189
+ /**
190
+ * Get the public key as hex string
191
+ */
192
+ readonly public_key_hex: string | undefined;
193
+ /**
194
+ * Get the key type
195
+ */
196
+ readonly key_type: string | undefined;
197
+ /**
198
+ * Get the error message
199
+ */
200
+ readonly error: string | undefined;
201
+ }
202
+ /**
203
+ * JavaScript-compatible result from MCP-I verification
204
+ */
205
+ export class JsMcpIVerificationResult {
206
+ private constructor();
207
+ free(): void;
208
+ [Symbol.dispose](): void;
209
+ /**
210
+ * Whether the verification was successful
211
+ */
212
+ verified: boolean;
213
+ /**
214
+ * Confidence score (0.0 to 1.0 scale) - 0.99 for verified MCP-I
215
+ */
216
+ confidence: number;
217
+ /**
218
+ * Get the issuer DID (principal)
219
+ */
220
+ readonly issuer_did: string | undefined;
221
+ /**
222
+ * Get the subject DID (agent)
223
+ */
224
+ readonly subject_did: string | undefined;
225
+ /**
226
+ * Get the error message
227
+ */
228
+ readonly error: string | undefined;
229
+ }
230
+ /**
231
+ * JavaScript-compatible policy evaluation result
232
+ */
233
+ export class JsPolicyEvaluationResult {
234
+ private constructor();
235
+ free(): void;
236
+ [Symbol.dispose](): void;
237
+ /**
238
+ * Check if the action permits the request to proceed
239
+ * Returns true for 'allow' and 'log' (allow but log for monitoring)
240
+ */
241
+ is_allowed(): boolean;
242
+ /**
243
+ * Check if the action blocks the request
244
+ * Returns true for 'block', 'redirect', and 'challenge'
245
+ */
246
+ is_blocked(): boolean;
247
+ /**
248
+ * Convert to JSON string for serialization
249
+ */
250
+ to_json(): string;
251
+ /**
252
+ * Get the enforcement action
253
+ */
254
+ readonly action: string;
255
+ /**
256
+ * Get the reason for the action
257
+ */
258
+ readonly reason: string;
259
+ /**
260
+ * Get the matched rule ID
261
+ */
262
+ readonly rule_id: string | undefined;
263
+ /**
264
+ * Get the matched rule name
265
+ */
266
+ readonly rule_name: string | undefined;
267
+ /**
268
+ * Get the redirect URL
269
+ */
270
+ readonly redirect_url: string | undefined;
271
+ /**
272
+ * Get the custom message
273
+ */
274
+ readonly message: string | undefined;
275
+ /**
276
+ * Get the match type
277
+ */
278
+ readonly match_type: string;
279
+ }
46
280
  /**
47
281
  * JavaScript-compatible request metadata
48
282
  */
49
283
  export class JsRequestMetadata {
50
284
  free(): void;
285
+ [Symbol.dispose](): void;
51
286
  /**
52
287
  * Constructor for JsRequestMetadata
53
288
  */
54
- constructor(user_agent: string | null | undefined, ip_address: string | null | undefined, headers: string, timestamp: string);
289
+ constructor(
290
+ user_agent: string | null | undefined,
291
+ ip_address: string | null | undefined,
292
+ headers: string,
293
+ timestamp: string,
294
+ url?: string | null,
295
+ method?: string | null,
296
+ client_fingerprint?: string | null,
297
+ tls_fingerprint?: string | null
298
+ );
55
299
  /**
56
300
  * Get the user agent
57
301
  */
@@ -68,6 +312,46 @@ export class JsRequestMetadata {
68
312
  * Get the timestamp
69
313
  */
70
314
  readonly timestamp: string;
315
+ /**
316
+ * Get the URL
317
+ */
318
+ readonly url: string | undefined;
319
+ /**
320
+ * Get the method
321
+ */
322
+ readonly method: string | undefined;
323
+ /**
324
+ * Get the client fingerprint
325
+ */
326
+ readonly client_fingerprint: string | undefined;
327
+ /**
328
+ * Get the TLS fingerprint
329
+ */
330
+ readonly tls_fingerprint: string | undefined;
331
+ }
332
+ /**
333
+ * JavaScript-compatible result from scope check
334
+ */
335
+ export class JsScopeCheckResult {
336
+ private constructor();
337
+ free(): void;
338
+ [Symbol.dispose](): void;
339
+ /**
340
+ * Whether the scope is permitted
341
+ */
342
+ permitted: boolean;
343
+ /**
344
+ * Get the matching scope
345
+ */
346
+ readonly matched_by: string | undefined;
347
+ /**
348
+ * Get the match type
349
+ */
350
+ readonly match_type: string;
351
+ /**
352
+ * Get the error message
353
+ */
354
+ readonly error: string | undefined;
71
355
  }
72
356
 
73
357
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
@@ -80,42 +364,116 @@ export interface InitOutput {
80
364
  readonly __wbg_get_jsdetectionresult_confidence: (a: number) => number;
81
365
  readonly __wbg_set_jsdetectionresult_confidence: (a: number, b: number) => void;
82
366
  readonly jsdetectionresult_agent: (a: number, b: number) => void;
367
+ readonly jsdetectionresult_detection_class: (a: number, b: number) => void;
83
368
  readonly jsdetectionresult_verification_method: (a: number, b: number) => void;
84
369
  readonly jsdetectionresult_risk_level: (a: number, b: number) => void;
85
370
  readonly jsdetectionresult_timestamp: (a: number, b: number) => void;
86
371
  readonly __wbg_jsrequestmetadata_free: (a: number, b: number) => void;
87
- readonly jsrequestmetadata_new: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
372
+ readonly jsrequestmetadata_new: (
373
+ a: number,
374
+ b: number,
375
+ c: number,
376
+ d: number,
377
+ e: number,
378
+ f: number,
379
+ g: number,
380
+ h: number,
381
+ i: number,
382
+ j: number,
383
+ k: number,
384
+ l: number,
385
+ m: number,
386
+ n: number,
387
+ o: number,
388
+ p: number
389
+ ) => number;
88
390
  readonly jsrequestmetadata_user_agent: (a: number, b: number) => void;
89
391
  readonly jsrequestmetadata_ip_address: (a: number, b: number) => void;
90
392
  readonly jsrequestmetadata_headers: (a: number, b: number) => void;
91
393
  readonly jsrequestmetadata_timestamp: (a: number, b: number) => void;
394
+ readonly jsrequestmetadata_url: (a: number, b: number) => void;
395
+ readonly jsrequestmetadata_method: (a: number, b: number) => void;
396
+ readonly jsrequestmetadata_client_fingerprint: (a: number, b: number) => void;
397
+ readonly jsrequestmetadata_tls_fingerprint: (a: number, b: number) => void;
92
398
  readonly init: () => void;
93
399
  readonly detect_agent: (a: number, b: number) => void;
400
+ readonly get_version: (a: number) => void;
401
+ readonly get_build_info: (a: number) => void;
402
+ readonly __wbg_jsmcpiverificationresult_free: (a: number, b: number) => void;
403
+ readonly __wbg_get_jsmcpiverificationresult_verified: (a: number) => number;
404
+ readonly __wbg_set_jsmcpiverificationresult_verified: (a: number, b: number) => void;
405
+ readonly jsmcpiverificationresult_issuer_did: (a: number, b: number) => void;
406
+ readonly jsmcpiverificationresult_subject_did: (a: number, b: number) => void;
407
+ readonly jsmcpiverificationresult_error: (a: number, b: number) => void;
408
+ readonly verify_mcp_i_proof: (a: number, b: number, c: bigint) => number;
409
+ readonly __wbg_jsdidkeyresult_free: (a: number, b: number) => void;
410
+ readonly __wbg_get_jsdidkeyresult_success: (a: number) => number;
411
+ readonly __wbg_set_jsdidkeyresult_success: (a: number, b: number) => void;
412
+ readonly jsdidkeyresult_public_key_hex: (a: number, b: number) => void;
413
+ readonly jsdidkeyresult_key_type: (a: number, b: number) => void;
414
+ readonly jsdidkeyresult_error: (a: number, b: number) => void;
415
+ readonly resolve_did_key_wasm: (a: number, b: number) => number;
416
+ readonly __wbg_jsscopecheckresult_free: (a: number, b: number) => void;
417
+ readonly jsscopecheckresult_matched_by: (a: number, b: number) => void;
418
+ readonly jsscopecheckresult_match_type: (a: number, b: number) => void;
419
+ readonly jsscopecheckresult_error: (a: number, b: number) => void;
420
+ readonly check_delegation_scope: (a: number, b: number, c: number, d: number) => number;
421
+ readonly verify_delegation_scope: (
422
+ a: number,
423
+ b: number,
424
+ c: number,
425
+ d: number,
426
+ e: bigint,
427
+ f: bigint,
428
+ g: bigint
429
+ ) => number;
430
+ readonly __wbg_jspolicyevaluationresult_free: (a: number, b: number) => void;
431
+ readonly jspolicyevaluationresult_action: (a: number, b: number) => void;
432
+ readonly jspolicyevaluationresult_reason: (a: number, b: number) => void;
433
+ readonly jspolicyevaluationresult_rule_id: (a: number, b: number) => void;
434
+ readonly jspolicyevaluationresult_rule_name: (a: number, b: number) => void;
435
+ readonly jspolicyevaluationresult_redirect_url: (a: number, b: number) => void;
436
+ readonly jspolicyevaluationresult_message: (a: number, b: number) => void;
437
+ readonly jspolicyevaluationresult_match_type: (a: number, b: number) => void;
438
+ readonly jspolicyevaluationresult_is_allowed: (a: number) => number;
439
+ readonly jspolicyevaluationresult_is_blocked: (a: number) => number;
440
+ readonly jspolicyevaluationresult_to_json: (a: number, b: number) => void;
441
+ readonly evaluate_policy: (a: number, b: number, c: number, d: number, e: number) => void;
442
+ readonly policy_allows: (a: number, b: number, c: number, d: number) => number;
94
443
  readonly version: (a: number) => void;
95
- readonly __wbindgen_export_0: (a: number, b: number, c: number) => void;
96
- readonly __wbindgen_export_1: (a: number, b: number) => number;
97
- readonly __wbindgen_export_2: (a: number, b: number, c: number, d: number) => number;
444
+ readonly __wbg_get_jsscopecheckresult_permitted: (a: number) => number;
445
+ readonly __wbg_set_jsscopecheckresult_permitted: (a: number, b: number) => void;
446
+ readonly __wbg_set_jsmcpiverificationresult_confidence: (a: number, b: number) => void;
447
+ readonly __wbg_get_jsmcpiverificationresult_confidence: (a: number) => number;
448
+ readonly __wbindgen_export: (a: number, b: number, c: number) => void;
449
+ readonly __wbindgen_export2: (a: number, b: number) => number;
450
+ readonly __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
98
451
  readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
99
452
  readonly __wbindgen_start: () => void;
100
453
  }
101
454
 
102
455
  export type SyncInitInput = BufferSource | WebAssembly.Module;
103
456
  /**
104
- * Instantiates the given `module`, which can either be bytes or
105
- * a precompiled `WebAssembly.Module`.
106
- *
107
- * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
108
- *
109
- * @returns {InitOutput}
110
- */
457
+ * Instantiates the given `module`, which can either be bytes or
458
+ * a precompiled `WebAssembly.Module`.
459
+ *
460
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
461
+ *
462
+ * @returns {InitOutput}
463
+ */
111
464
  export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
112
465
 
113
466
  /**
114
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
115
- * for everything else, calls `WebAssembly.instantiate` directly.
116
- *
117
- * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
118
- *
119
- * @returns {Promise<InitOutput>}
120
- */
121
- export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
467
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
468
+ * for everything else, calls `WebAssembly.instantiate` directly.
469
+ *
470
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
471
+ *
472
+ * @returns {Promise<InitOutput>}
473
+ */
474
+ export default function __wbg_init(
475
+ module_or_path?:
476
+ | { module_or_path: InitInput | Promise<InitInput> }
477
+ | InitInput
478
+ | Promise<InitInput>
479
+ ): Promise<InitOutput>;