@kya-os/agentshield-nextjs 0.1.38 → 0.1.40
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/dist/create-middleware.js +59 -43
- package/dist/create-middleware.js.map +1 -1
- package/dist/create-middleware.mjs +59 -43
- package/dist/create-middleware.mjs.map +1 -1
- package/dist/index.js +59 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -43
- package/dist/index.mjs.map +1 -1
- package/dist/middleware.js +59 -43
- package/dist/middleware.js.map +1 -1
- package/dist/middleware.mjs +59 -43
- package/dist/middleware.mjs.map +1 -1
- package/package.json +16 -17
package/dist/index.mjs
CHANGED
|
@@ -396,55 +396,71 @@ async function initWasm() {
|
|
|
396
396
|
}
|
|
397
397
|
initPromise = (async () => {
|
|
398
398
|
try {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
399
|
+
const controller = new AbortController();
|
|
400
|
+
const timeout = setTimeout(() => controller.abort(), 3e3);
|
|
401
|
+
try {
|
|
402
|
+
const wasmUrl = getWasmUrl();
|
|
403
|
+
if (typeof WebAssembly.instantiateStreaming === "function") {
|
|
404
|
+
try {
|
|
405
|
+
const response2 = await fetch(wasmUrl, { signal: controller.signal });
|
|
406
|
+
clearTimeout(timeout);
|
|
407
|
+
if (!response2.ok) {
|
|
408
|
+
throw new Error(`Failed to fetch WASM: ${response2.status}`);
|
|
409
|
+
}
|
|
410
|
+
const streamResponse = response2.clone();
|
|
411
|
+
const { instance } = await WebAssembly.instantiateStreaming(
|
|
412
|
+
streamResponse,
|
|
413
|
+
{
|
|
414
|
+
wbg: {
|
|
415
|
+
__wbg_log_1d3ae13c3d5e6b8e: (ptr, len) => {
|
|
416
|
+
console.log("WASM:", ptr, len);
|
|
417
|
+
},
|
|
418
|
+
__wbindgen_throw: (ptr, len) => {
|
|
419
|
+
throw new Error(`WASM Error at ${ptr}, length ${len}`);
|
|
420
|
+
}
|
|
416
421
|
}
|
|
417
422
|
}
|
|
423
|
+
);
|
|
424
|
+
wasmInstance = instance;
|
|
425
|
+
wasmExports = instance.exports;
|
|
426
|
+
console.log("[AgentShield] \u2705 WASM module initialized with streaming");
|
|
427
|
+
return;
|
|
428
|
+
} catch (streamError) {
|
|
429
|
+
if (!controller.signal.aborted) {
|
|
430
|
+
console.log("[AgentShield] Streaming compilation failed, falling back to standard compilation");
|
|
431
|
+
} else {
|
|
432
|
+
throw streamError;
|
|
418
433
|
}
|
|
419
|
-
|
|
420
|
-
wasmInstance = instance;
|
|
421
|
-
wasmExports = instance.exports;
|
|
422
|
-
console.log("[AgentShield] \u2705 WASM module initialized with streaming");
|
|
423
|
-
return;
|
|
424
|
-
} catch (streamError) {
|
|
425
|
-
console.log("[AgentShield] Streaming compilation failed, falling back to standard compilation");
|
|
434
|
+
}
|
|
426
435
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
436
|
+
const response = await fetch(wasmUrl, { signal: controller.signal });
|
|
437
|
+
clearTimeout(timeout);
|
|
438
|
+
if (!response.ok) {
|
|
439
|
+
throw new Error(`Failed to fetch WASM: ${response.status}`);
|
|
440
|
+
}
|
|
441
|
+
const wasmArrayBuffer = await response.arrayBuffer();
|
|
442
|
+
const compiledModule = await WebAssembly.compile(wasmArrayBuffer);
|
|
443
|
+
const imports = {
|
|
444
|
+
wbg: {
|
|
445
|
+
__wbg_log_1d3ae13c3d5e6b8e: (ptr, len) => {
|
|
446
|
+
console.log("WASM:", ptr, len);
|
|
447
|
+
},
|
|
448
|
+
__wbindgen_throw: (ptr, len) => {
|
|
449
|
+
throw new Error(`WASM Error at ${ptr}, length ${len}`);
|
|
450
|
+
}
|
|
442
451
|
}
|
|
452
|
+
};
|
|
453
|
+
wasmInstance = await WebAssembly.instantiate(compiledModule, imports);
|
|
454
|
+
wasmExports = wasmInstance.exports;
|
|
455
|
+
console.log("[AgentShield] \u2705 WASM module initialized via fallback");
|
|
456
|
+
} catch (fetchError) {
|
|
457
|
+
if (fetchError.name === "AbortError") {
|
|
458
|
+
console.warn("[AgentShield] WASM fetch timed out after 3 seconds - using pattern detection");
|
|
459
|
+
} else {
|
|
460
|
+
console.warn("[AgentShield] Failed to fetch WASM file:", fetchError.message);
|
|
443
461
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
wasmExports = wasmInstance.exports;
|
|
447
|
-
console.log("[AgentShield] \u2705 WASM module initialized via fallback");
|
|
462
|
+
wasmExports = null;
|
|
463
|
+
}
|
|
448
464
|
} catch (error) {
|
|
449
465
|
console.error("[AgentShield] Failed to initialize WASM:", error);
|
|
450
466
|
wasmExports = null;
|