@kya-os/agentshield-nextjs 0.1.37 → 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/index.js CHANGED
@@ -398,55 +398,71 @@ async function initWasm() {
398
398
  }
399
399
  initPromise = (async () => {
400
400
  try {
401
- if (typeof WebAssembly.instantiateStreaming === "function") {
402
- try {
403
- const wasmUrl2 = getWasmUrl();
404
- const response2 = await fetch(wasmUrl2);
405
- if (!response2.ok) {
406
- throw new Error(`Failed to fetch WASM: ${response2.status}`);
407
- }
408
- const streamResponse = response2.clone();
409
- const { instance } = await WebAssembly.instantiateStreaming(
410
- streamResponse,
411
- {
412
- wbg: {
413
- __wbg_log_1d3ae13c3d5e6b8e: (ptr, len) => {
414
- console.log("WASM:", ptr, len);
415
- },
416
- __wbindgen_throw: (ptr, len) => {
417
- throw new Error(`WASM Error at ${ptr}, length ${len}`);
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
- const wasmUrl = getWasmUrl();
431
- const response = await fetch(wasmUrl);
432
- if (!response.ok) {
433
- throw new Error(`Failed to fetch WASM: ${response.status}`);
434
- }
435
- const wasmArrayBuffer = await response.arrayBuffer();
436
- const compiledModule = await WebAssembly.compile(wasmArrayBuffer);
437
- const imports = {
438
- wbg: {
439
- __wbg_log_1d3ae13c3d5e6b8e: (ptr, len) => {
440
- console.log("WASM:", ptr, len);
441
- },
442
- __wbindgen_throw: (ptr, len) => {
443
- throw new Error(`WASM Error at ${ptr}, length ${len}`);
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
- wasmInstance = await WebAssembly.instantiate(compiledModule, imports);
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;