@kya-os/checkpoint-nextjs 1.1.0 → 1.1.4

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 (39) hide show
  1. package/CHANGELOG.md +178 -0
  2. package/EDGE_RUNTIME_WASM_SETUP.md +4 -10
  3. package/README.md +13 -0
  4. package/bin/setup-edge-wasm.js +40 -32
  5. package/dist/api-client.d.mts +10 -10
  6. package/dist/api-client.d.ts +10 -10
  7. package/dist/create-middleware.d.mts +7 -2
  8. package/dist/create-middleware.d.ts +7 -2
  9. package/dist/edge/index.d.mts +3 -3
  10. package/dist/edge/index.d.ts +3 -3
  11. package/dist/edge/index.js +16 -3
  12. package/dist/edge/index.mjs +16 -3
  13. package/dist/edge-runtime-loader.d.mts +43 -18
  14. package/dist/edge-runtime-loader.d.ts +43 -18
  15. package/dist/edge-runtime-loader.js +101 -58
  16. package/dist/edge-runtime-loader.mjs +98 -59
  17. package/dist/edge-wasm-middleware.d.mts +28 -34
  18. package/dist/edge-wasm-middleware.d.ts +28 -34
  19. package/dist/edge-wasm-middleware.js +16 -306
  20. package/dist/edge-wasm-middleware.mjs +16 -307
  21. package/dist/index.js +3 -1
  22. package/dist/index.mjs +4 -2
  23. package/dist/nodejs-wasm-loader.d.mts +26 -9
  24. package/dist/nodejs-wasm-loader.d.ts +26 -9
  25. package/dist/nodejs-wasm-loader.js +21 -78
  26. package/dist/nodejs-wasm-loader.mjs +21 -74
  27. package/dist/session-tracker.d.mts +2 -2
  28. package/dist/session-tracker.d.ts +2 -2
  29. package/dist/session-tracker.js +3 -1
  30. package/dist/session-tracker.mjs +4 -2
  31. package/dist/wasm-middleware.d.mts +19 -3
  32. package/dist/wasm-middleware.d.ts +19 -3
  33. package/dist/wasm-middleware.js +32 -3
  34. package/dist/wasm-middleware.mjs +32 -4
  35. package/dist/wasm-setup.js +29 -81
  36. package/dist/wasm-setup.mjs +29 -76
  37. package/package.json +4 -4
  38. package/templates/middleware-wasm-100.ts +11 -3
  39. package/dist/.tsbuildinfo +0 -1
@@ -1,15 +1,25 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
2
 
3
3
  /**
4
- * Edge Runtime Compatible WASM Middleware for AgentShield
4
+ * @deprecated Phase-D.9a — legacy Edge Runtime WASM middleware wrapping
5
+ * the retired `agentshield-wasm` Rust crate. This file shipped hand-
6
+ * written wasm-bindgen glue code that loaded the legacy detector's
7
+ * WASM binary; PR #2599's SSOT consolidation + PDM-1 #2560's engine
8
+ * move + AgentDetector-Deletion-1 PR #2610's class-deprecation made
9
+ * it structural dead weight.
5
10
  *
6
- * This module provides WASM-based AI agent detection with 95-100% confidence
7
- * in Next.js Edge Runtime and Vercel Edge Functions.
11
+ * Phase-D.9a converts the exports to throw-stubs (same precedent as
12
+ * PR #2610's `createWasmAgentShieldMiddleware` deprecation). Phase-D.9b
13
+ * (follow-up) deletes the underlying `agentshield-wasm` Rust crate
14
+ * after migrating the production Cloudflare gateway worker.
8
15
  *
9
- * IMPORTANT: WebAssembly.instantiate(module) IS supported in Edge Runtime
10
- * when using a pre-compiled module imported with ?module suffix.
16
+ * Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs/edge`
17
+ * engine-backed, runs the full kya-os-engine orchestrator including
18
+ * MCP-I envelope verification. See `packages/checkpoint-nextjs/README.md`
19
+ * for the canonical recipe.
11
20
  */
12
21
 
22
+ /** @deprecated See file header. Type-only surface preservation. */
13
23
  interface EdgeWasmDetectionResult {
14
24
  isAgent: boolean;
15
25
  isAiCrawler?: boolean;
@@ -20,17 +30,10 @@ interface EdgeWasmDetectionResult {
20
30
  timestamp: string;
21
31
  reasons?: string[];
22
32
  }
33
+ /** @deprecated See file header. Type-only surface preservation. */
23
34
  interface EdgeAgentShieldConfig {
24
35
  onAgentDetected?: (result: EdgeWasmDetectionResult) => void | Promise<void>;
25
36
  blockOnHighConfidence?: boolean;
26
- /**
27
- * Confidence threshold for blocking (0.0-1.0 scale).
28
- * Detection confidence above this threshold will be blocked if blockOnHighConfidence is true.
29
- * @default 0.9 (90% confidence)
30
- * @example
31
- * confidenceThreshold: 0.9 // Block if >= 90% confident
32
- * confidenceThreshold: 0.7 // Block if >= 70% confident
33
- */
34
37
  confidenceThreshold?: number;
35
38
  skipPaths?: string[];
36
39
  blockedResponse?: {
@@ -39,30 +42,21 @@ interface EdgeAgentShieldConfig {
39
42
  headers?: Record<string, string>;
40
43
  };
41
44
  }
45
+ /** @internal — test-only reset for the one-shot warn latch. */
46
+ declare function __resetEdgeWasmWarningForTests(): void;
42
47
  /**
43
- * Initialize WASM module with proper imports for Edge Runtime
48
+ * @deprecated Removed in Phase-D.9a. Use `withCheckpoint` from
49
+ * `@kya-os/checkpoint-nextjs/edge` instead. Throws on invocation;
50
+ * surface exists only so static analysis sees the historical export.
44
51
  */
45
- declare function initializeEdgeWasm(wasmModule: WebAssembly.Module): Promise<void>;
52
+ declare function initializeEdgeWasm(_wasmModule: WebAssembly.Module): Promise<void>;
46
53
  /**
47
- * Create Edge Runtime compatible WASM middleware
48
- *
49
- * @example
50
- * ```typescript
51
- * // middleware.ts
52
- * import wasmModule from '@kya-os/checkpoint/wasm?module';
53
- * import { createEdgeWasmMiddleware } from '@kya-os/checkpoint-nextjs/edge-wasm-middleware';
54
- *
55
- * export const middleware = createEdgeWasmMiddleware({
56
- * wasmModule,
57
- * onAgentDetected: (result) => {
58
- * // Note: result.confidence is 0.0-1.0 scale
59
- * console.log(`AI Agent: ${result.agent} (${Math.round(result.confidence * 100)}% confidence)`);
60
- * }
61
- * });
62
- * ```
54
+ * @deprecated Removed in Phase-D.9a. Use `withCheckpoint` from
55
+ * `@kya-os/checkpoint-nextjs/edge` instead. Throws on invocation;
56
+ * surface exists only so static analysis sees the historical export.
63
57
  */
64
- declare function createEdgeWasmMiddleware(config: EdgeAgentShieldConfig & {
58
+ declare function createEdgeWasmMiddleware(_config: EdgeAgentShieldConfig & {
65
59
  wasmModule: WebAssembly.Module;
66
- }): (request: NextRequest) => Promise<NextResponse<unknown>>;
60
+ }): (request: NextRequest) => Promise<NextResponse>;
67
61
 
68
- export { type EdgeAgentShieldConfig, type EdgeWasmDetectionResult, createEdgeWasmMiddleware, initializeEdgeWasm };
62
+ export { type EdgeAgentShieldConfig, type EdgeWasmDetectionResult, __resetEdgeWasmWarningForTests, createEdgeWasmMiddleware, initializeEdgeWasm };
@@ -1,15 +1,25 @@
1
1
  import { NextRequest, NextResponse } from 'next/server';
2
2
 
3
3
  /**
4
- * Edge Runtime Compatible WASM Middleware for AgentShield
4
+ * @deprecated Phase-D.9a — legacy Edge Runtime WASM middleware wrapping
5
+ * the retired `agentshield-wasm` Rust crate. This file shipped hand-
6
+ * written wasm-bindgen glue code that loaded the legacy detector's
7
+ * WASM binary; PR #2599's SSOT consolidation + PDM-1 #2560's engine
8
+ * move + AgentDetector-Deletion-1 PR #2610's class-deprecation made
9
+ * it structural dead weight.
5
10
  *
6
- * This module provides WASM-based AI agent detection with 95-100% confidence
7
- * in Next.js Edge Runtime and Vercel Edge Functions.
11
+ * Phase-D.9a converts the exports to throw-stubs (same precedent as
12
+ * PR #2610's `createWasmAgentShieldMiddleware` deprecation). Phase-D.9b
13
+ * (follow-up) deletes the underlying `agentshield-wasm` Rust crate
14
+ * after migrating the production Cloudflare gateway worker.
8
15
  *
9
- * IMPORTANT: WebAssembly.instantiate(module) IS supported in Edge Runtime
10
- * when using a pre-compiled module imported with ?module suffix.
16
+ * Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs/edge`
17
+ * engine-backed, runs the full kya-os-engine orchestrator including
18
+ * MCP-I envelope verification. See `packages/checkpoint-nextjs/README.md`
19
+ * for the canonical recipe.
11
20
  */
12
21
 
22
+ /** @deprecated See file header. Type-only surface preservation. */
13
23
  interface EdgeWasmDetectionResult {
14
24
  isAgent: boolean;
15
25
  isAiCrawler?: boolean;
@@ -20,17 +30,10 @@ interface EdgeWasmDetectionResult {
20
30
  timestamp: string;
21
31
  reasons?: string[];
22
32
  }
33
+ /** @deprecated See file header. Type-only surface preservation. */
23
34
  interface EdgeAgentShieldConfig {
24
35
  onAgentDetected?: (result: EdgeWasmDetectionResult) => void | Promise<void>;
25
36
  blockOnHighConfidence?: boolean;
26
- /**
27
- * Confidence threshold for blocking (0.0-1.0 scale).
28
- * Detection confidence above this threshold will be blocked if blockOnHighConfidence is true.
29
- * @default 0.9 (90% confidence)
30
- * @example
31
- * confidenceThreshold: 0.9 // Block if >= 90% confident
32
- * confidenceThreshold: 0.7 // Block if >= 70% confident
33
- */
34
37
  confidenceThreshold?: number;
35
38
  skipPaths?: string[];
36
39
  blockedResponse?: {
@@ -39,30 +42,21 @@ interface EdgeAgentShieldConfig {
39
42
  headers?: Record<string, string>;
40
43
  };
41
44
  }
45
+ /** @internal — test-only reset for the one-shot warn latch. */
46
+ declare function __resetEdgeWasmWarningForTests(): void;
42
47
  /**
43
- * Initialize WASM module with proper imports for Edge Runtime
48
+ * @deprecated Removed in Phase-D.9a. Use `withCheckpoint` from
49
+ * `@kya-os/checkpoint-nextjs/edge` instead. Throws on invocation;
50
+ * surface exists only so static analysis sees the historical export.
44
51
  */
45
- declare function initializeEdgeWasm(wasmModule: WebAssembly.Module): Promise<void>;
52
+ declare function initializeEdgeWasm(_wasmModule: WebAssembly.Module): Promise<void>;
46
53
  /**
47
- * Create Edge Runtime compatible WASM middleware
48
- *
49
- * @example
50
- * ```typescript
51
- * // middleware.ts
52
- * import wasmModule from '@kya-os/checkpoint/wasm?module';
53
- * import { createEdgeWasmMiddleware } from '@kya-os/checkpoint-nextjs/edge-wasm-middleware';
54
- *
55
- * export const middleware = createEdgeWasmMiddleware({
56
- * wasmModule,
57
- * onAgentDetected: (result) => {
58
- * // Note: result.confidence is 0.0-1.0 scale
59
- * console.log(`AI Agent: ${result.agent} (${Math.round(result.confidence * 100)}% confidence)`);
60
- * }
61
- * });
62
- * ```
54
+ * @deprecated Removed in Phase-D.9a. Use `withCheckpoint` from
55
+ * `@kya-os/checkpoint-nextjs/edge` instead. Throws on invocation;
56
+ * surface exists only so static analysis sees the historical export.
63
57
  */
64
- declare function createEdgeWasmMiddleware(config: EdgeAgentShieldConfig & {
58
+ declare function createEdgeWasmMiddleware(_config: EdgeAgentShieldConfig & {
65
59
  wasmModule: WebAssembly.Module;
66
- }): (request: NextRequest) => Promise<NextResponse<unknown>>;
60
+ }): (request: NextRequest) => Promise<NextResponse>;
67
61
 
68
- export { type EdgeAgentShieldConfig, type EdgeWasmDetectionResult, createEdgeWasmMiddleware, initializeEdgeWasm };
62
+ export { type EdgeAgentShieldConfig, type EdgeWasmDetectionResult, __resetEdgeWasmWarningForTests, createEdgeWasmMiddleware, initializeEdgeWasm };
@@ -1,316 +1,26 @@
1
1
  'use strict';
2
2
 
3
- var server = require('next/server');
4
- var checkpointShared = require('@kya-os/checkpoint-shared');
5
-
6
3
  // src/edge-wasm-middleware.ts
7
- var wasmExports = null;
8
- var wasmInitPromise = null;
9
- var heap = new Array(128).fill(void 0);
10
- heap.push(void 0, null, true, false);
11
- var heap_next = heap.length;
12
- function addHeapObject(obj) {
13
- if (heap_next === heap.length) heap.push(heap.length + 1);
14
- const idx = heap_next;
15
- heap_next = heap[idx];
16
- heap[idx] = obj;
17
- return idx;
18
- }
19
- function getObject(idx) {
20
- return heap[idx];
21
- }
22
- function dropObject(idx) {
23
- if (idx < 132) return;
24
- heap[idx] = heap_next;
25
- heap_next = idx;
26
- }
27
- function takeObject(idx) {
28
- const ret = getObject(idx);
29
- dropObject(idx);
30
- return ret;
31
- }
32
- var cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
33
- var cachedTextEncoder = new TextEncoder();
34
- var cachedUint8ArrayMemory0 = null;
35
- function getUint8ArrayMemory0() {
36
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
37
- cachedUint8ArrayMemory0 = new Uint8Array(wasmExports.memory.buffer);
38
- }
39
- return cachedUint8ArrayMemory0;
40
- }
41
- function getStringFromWasm0(ptr, len) {
42
- ptr = ptr >>> 0;
43
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
44
- }
45
- var WASM_VECTOR_LEN = 0;
46
- function passStringToWasm0(arg, malloc, realloc) {
47
- if (realloc === void 0) {
48
- const buf = cachedTextEncoder.encode(arg);
49
- const ptr2 = malloc(buf.length, 1) >>> 0;
50
- getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf);
51
- WASM_VECTOR_LEN = buf.length;
52
- return ptr2;
53
- }
54
- let len = arg.length;
55
- let ptr = malloc(len, 1) >>> 0;
56
- const mem = getUint8ArrayMemory0();
57
- let offset = 0;
58
- for (; offset < len; offset++) {
59
- const code = arg.charCodeAt(offset);
60
- if (code > 127) break;
61
- mem[ptr + offset] = code;
62
- }
63
- if (offset !== len) {
64
- if (offset !== 0) {
65
- arg = arg.slice(offset);
66
- }
67
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
68
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
69
- const ret = cachedTextEncoder.encodeInto(arg, view);
70
- offset += ret.written;
71
- }
72
- WASM_VECTOR_LEN = offset;
73
- return ptr;
74
- }
75
- var cachedDataViewMemory0 = null;
76
- function getDataViewMemory0() {
77
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer !== wasmExports.memory.buffer) {
78
- cachedDataViewMemory0 = new DataView(wasmExports.memory.buffer);
79
- }
80
- return cachedDataViewMemory0;
4
+ var MIGRATION_ERROR = "`@kya-os/checkpoint-nextjs/edge-wasm-middleware` was deprecated in Phase-D.9a (legacy `agentshield-wasm` Rust crate retirement). Migrate to `withCheckpoint` from `@kya-os/checkpoint-nextjs/edge` \u2014 engine-backed via the Rust `kya-os-engine` crate (PDM-1 #2560), runs the full orchestrator including MCP-I envelope verification. See packages/checkpoint-nextjs/README.md for the canonical recipe.";
5
+ var _edgeWasmWarned = false;
6
+ function warnEdgeWasmDeprecated() {
7
+ if (_edgeWasmWarned) return;
8
+ _edgeWasmWarned = true;
9
+ if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") return;
10
+ console.warn(`[Checkpoint] ${MIGRATION_ERROR}`);
81
11
  }
82
- async function initializeEdgeWasm(wasmModule) {
83
- if (wasmInitPromise) {
84
- return wasmInitPromise;
85
- }
86
- wasmInitPromise = (async () => {
87
- try {
88
- const imports = {
89
- "./agentshield_wasm_bg.js": {
90
- __wbindgen_object_drop_ref: function(arg0) {
91
- dropObject(arg0);
92
- },
93
- __wbindgen_string_new: function(arg0, arg1) {
94
- const ret = getStringFromWasm0(arg0, arg1);
95
- return addHeapObject(ret);
96
- },
97
- __wbindgen_string_get: function(arg0, arg1) {
98
- const obj = getObject(arg1);
99
- const ret = typeof obj === "string" ? obj : void 0;
100
- const ptr1 = ret ? passStringToWasm0(
101
- ret,
102
- wasmExports.__wbindgen_malloc,
103
- wasmExports.__wbindgen_realloc
104
- ) : 0;
105
- const len1 = WASM_VECTOR_LEN;
106
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
107
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
108
- },
109
- __wbindgen_throw: function(arg0, arg1) {
110
- throw new Error(getStringFromWasm0(arg0, arg1));
111
- }
112
- },
113
- wbg: {
114
- __wbindgen_object_drop_ref: function(arg0) {
115
- dropObject(arg0);
116
- },
117
- __wbindgen_string_new: function(arg0, arg1) {
118
- const ret = getStringFromWasm0(arg0, arg1);
119
- return addHeapObject(ret);
120
- },
121
- __wbindgen_string_get: function(arg0, arg1) {
122
- const obj = getObject(arg1);
123
- const ret = typeof obj === "string" ? obj : void 0;
124
- const ptr1 = ret ? passStringToWasm0(
125
- ret,
126
- wasmExports.__wbindgen_malloc,
127
- wasmExports.__wbindgen_realloc
128
- ) : 0;
129
- const len1 = WASM_VECTOR_LEN;
130
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
131
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
132
- },
133
- __wbindgen_throw: function(arg0, arg1) {
134
- throw new Error(getStringFromWasm0(arg0, arg1));
135
- }
136
- }
137
- };
138
- const instance = await WebAssembly.instantiate(wasmModule, imports);
139
- wasmExports = instance.exports;
140
- if (wasmExports.__wbindgen_start) {
141
- wasmExports.__wbindgen_start();
142
- }
143
- console.log(
144
- "\u2705 AgentShield: WASM module loaded successfully in Edge Runtime (95-100% confidence enabled)"
145
- );
146
- } catch (error) {
147
- console.error("\u274C AgentShield: Failed to initialize WASM in Edge Runtime:", error);
148
- throw error;
149
- }
150
- })();
151
- return wasmInitPromise;
12
+ function __resetEdgeWasmWarningForTests() {
13
+ _edgeWasmWarned = false;
152
14
  }
153
- async function detectWithWasm(metadata) {
154
- if (!wasmExports) {
155
- throw new Error("WASM not initialized. Call initializeEdgeWasm first.");
156
- }
157
- try {
158
- const userAgent = metadata.userAgent || "";
159
- const ipAddress = metadata.ipAddress || "";
160
- const headers = JSON.stringify(metadata.headers);
161
- const timestamp = metadata.timestamp;
162
- const url = metadata.url || "";
163
- const method = metadata.method || "";
164
- const clientFingerprint = metadata.clientFingerprint || "";
165
- const ptr0 = passStringToWasm0(
166
- userAgent,
167
- wasmExports.__wbindgen_malloc,
168
- wasmExports.__wbindgen_realloc
169
- );
170
- const len0 = WASM_VECTOR_LEN;
171
- const ptr1 = passStringToWasm0(
172
- ipAddress,
173
- wasmExports.__wbindgen_malloc,
174
- wasmExports.__wbindgen_realloc
175
- );
176
- const len1 = WASM_VECTOR_LEN;
177
- const ptr2 = passStringToWasm0(
178
- headers,
179
- wasmExports.__wbindgen_malloc,
180
- wasmExports.__wbindgen_realloc
181
- );
182
- const len2 = WASM_VECTOR_LEN;
183
- const ptr3 = passStringToWasm0(
184
- timestamp,
185
- wasmExports.__wbindgen_malloc,
186
- wasmExports.__wbindgen_realloc
187
- );
188
- const len3 = WASM_VECTOR_LEN;
189
- const ptr4 = passStringToWasm0(
190
- url,
191
- wasmExports.__wbindgen_malloc,
192
- wasmExports.__wbindgen_realloc
193
- );
194
- const len4 = WASM_VECTOR_LEN;
195
- const ptr5 = passStringToWasm0(
196
- method,
197
- wasmExports.__wbindgen_malloc,
198
- wasmExports.__wbindgen_realloc
199
- );
200
- const len5 = WASM_VECTOR_LEN;
201
- const ptr6 = passStringToWasm0(
202
- clientFingerprint,
203
- wasmExports.__wbindgen_malloc,
204
- wasmExports.__wbindgen_realloc
205
- );
206
- const len6 = WASM_VECTOR_LEN;
207
- const metadataPtr = wasmExports.jsrequestmetadata_new(
208
- ptr0,
209
- len0,
210
- ptr1,
211
- len1,
212
- ptr2,
213
- len2,
214
- ptr3,
215
- len3,
216
- ptr4,
217
- len4,
218
- ptr5,
219
- len5,
220
- ptr6,
221
- len6
222
- );
223
- const resultPtr = wasmExports.detect_agent(metadataPtr);
224
- const result = takeObject(resultPtr);
225
- wasmExports.__wbg_jsrequestmetadata_free(metadataPtr, 0);
226
- const parsedResult = typeof result === "string" ? JSON.parse(result) : result;
227
- return {
228
- isAgent: parsedResult.is_agent || false,
229
- isAiCrawler: parsedResult.is_ai_crawler || false,
230
- confidence: parsedResult.confidence || 0,
231
- agent: parsedResult.agent,
232
- verificationMethod: parsedResult.verification_method || "wasm",
233
- riskLevel: parsedResult.risk_level || "low",
234
- timestamp: parsedResult.timestamp || metadata.timestamp,
235
- reasons: parsedResult.reasons || []
236
- };
237
- } catch (error) {
238
- console.error("WASM detection failed:", error);
239
- return {
240
- isAgent: false,
241
- confidence: 0,
242
- verificationMethod: "pattern",
243
- riskLevel: "low",
244
- timestamp: metadata.timestamp
245
- };
246
- }
15
+ async function initializeEdgeWasm(_wasmModule) {
16
+ warnEdgeWasmDeprecated();
17
+ throw new Error(MIGRATION_ERROR);
247
18
  }
248
- function createEdgeWasmMiddleware(config) {
249
- const {
250
- wasmModule,
251
- onAgentDetected,
252
- blockOnHighConfidence = false,
253
- confidenceThreshold: configThreshold = 0.9,
254
- skipPaths = [],
255
- blockedResponse = {
256
- status: 403,
257
- message: "AI agent access restricted",
258
- headers: { "Content-Type": "application/json" }
259
- }
260
- } = config;
261
- const confidenceThreshold = checkpointShared.normalizeConfidence(configThreshold, "confidenceThreshold");
262
- const initPromise = initializeEdgeWasm(wasmModule);
263
- return async function middleware(request) {
264
- const path = request.nextUrl.pathname;
265
- if (skipPaths.some((skip) => path.startsWith(skip))) {
266
- return server.NextResponse.next();
267
- }
268
- try {
269
- await initPromise;
270
- const metadata = {
271
- userAgent: request.headers.get("user-agent") || void 0,
272
- ipAddress: request.headers.get("x-forwarded-for") || request.headers.get("x-real-ip") || void 0,
273
- headers: Object.fromEntries(request.headers.entries()),
274
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
275
- };
276
- const result = await detectWithWasm(metadata);
277
- const decision = checkpointShared.evaluateEnforcement(
278
- { ...result, confidence: result.confidence * 100 },
279
- {
280
- confidenceThreshold: confidenceThreshold * 100,
281
- defaultAction: blockOnHighConfidence ? "block" : "allow"
282
- }
283
- );
284
- if (onAgentDetected && checkpointShared.shouldEnforce(result)) {
285
- await onAgentDetected(result);
286
- }
287
- if (decision.action === "block") {
288
- return server.NextResponse.json(
289
- {
290
- error: blockedResponse.message,
291
- agent: result.agent,
292
- confidence: checkpointShared.toPercent(result.confidence)
293
- // Convert to 0-100 for display
294
- },
295
- {
296
- status: blockedResponse.status || 403,
297
- headers: blockedResponse.headers || {}
298
- }
299
- );
300
- }
301
- const response = server.NextResponse.next();
302
- if (result.isAgent) {
303
- response.headers.set("X-Agent-Detected", result.agent || "unknown");
304
- response.headers.set("X-Agent-Confidence", String(checkpointShared.toPercent(result.confidence)));
305
- response.headers.set("X-Agent-Verification", result.verificationMethod);
306
- }
307
- return response;
308
- } catch (error) {
309
- console.error("Edge WASM middleware error:", error);
310
- return server.NextResponse.next();
311
- }
312
- };
19
+ function createEdgeWasmMiddleware(_config) {
20
+ warnEdgeWasmDeprecated();
21
+ throw new Error(MIGRATION_ERROR);
313
22
  }
314
23
 
24
+ exports.__resetEdgeWasmWarningForTests = __resetEdgeWasmWarningForTests;
315
25
  exports.createEdgeWasmMiddleware = createEdgeWasmMiddleware;
316
26
  exports.initializeEdgeWasm = initializeEdgeWasm;