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