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