@kya-os/agentshield-nextjs 0.1.36 → 0.1.37
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 +33 -2
- package/dist/create-middleware.js.map +1 -1
- package/dist/create-middleware.mjs +33 -2
- package/dist/create-middleware.mjs.map +1 -1
- package/dist/index.js +47 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -5
- package/dist/index.mjs.map +1 -1
- package/dist/middleware.js +33 -2
- package/dist/middleware.js.map +1 -1
- package/dist/middleware.mjs +33 -2
- package/dist/middleware.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -373,6 +373,21 @@ var wasmInstance = null;
|
|
|
373
373
|
var wasmExports = null;
|
|
374
374
|
var initPromise = null;
|
|
375
375
|
var WASM_PATH = "/wasm/agentshield_wasm_bg.wasm";
|
|
376
|
+
var baseUrl = null;
|
|
377
|
+
function setWasmBaseUrl(url) {
|
|
378
|
+
baseUrl = url;
|
|
379
|
+
}
|
|
380
|
+
function getWasmUrl() {
|
|
381
|
+
if (baseUrl) {
|
|
382
|
+
try {
|
|
383
|
+
const url = new URL(baseUrl);
|
|
384
|
+
return `${url.origin}${WASM_PATH}`;
|
|
385
|
+
} catch {
|
|
386
|
+
return WASM_PATH;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return WASM_PATH;
|
|
390
|
+
}
|
|
376
391
|
async function initWasm() {
|
|
377
392
|
if (wasmExports) return true;
|
|
378
393
|
if (initPromise) {
|
|
@@ -383,7 +398,8 @@ async function initWasm() {
|
|
|
383
398
|
try {
|
|
384
399
|
if (typeof WebAssembly.instantiateStreaming === "function") {
|
|
385
400
|
try {
|
|
386
|
-
const
|
|
401
|
+
const wasmUrl2 = getWasmUrl();
|
|
402
|
+
const response2 = await fetch(wasmUrl2);
|
|
387
403
|
if (!response2.ok) {
|
|
388
404
|
throw new Error(`Failed to fetch WASM: ${response2.status}`);
|
|
389
405
|
}
|
|
@@ -409,7 +425,8 @@ async function initWasm() {
|
|
|
409
425
|
console.log("[AgentShield] Streaming compilation failed, falling back to standard compilation");
|
|
410
426
|
}
|
|
411
427
|
}
|
|
412
|
-
const
|
|
428
|
+
const wasmUrl = getWasmUrl();
|
|
429
|
+
const response = await fetch(wasmUrl);
|
|
413
430
|
if (!response.ok) {
|
|
414
431
|
throw new Error(`Failed to fetch WASM: ${response.status}`);
|
|
415
432
|
}
|
|
@@ -508,6 +525,14 @@ var EdgeAgentDetectorWithWasm = class {
|
|
|
508
525
|
}
|
|
509
526
|
wasmEnabled = false;
|
|
510
527
|
initPromise = null;
|
|
528
|
+
baseUrl = null;
|
|
529
|
+
/**
|
|
530
|
+
* Set the base URL for WASM loading in Edge Runtime
|
|
531
|
+
*/
|
|
532
|
+
setBaseUrl(url) {
|
|
533
|
+
this.baseUrl = url;
|
|
534
|
+
setWasmBaseUrl(url);
|
|
535
|
+
}
|
|
511
536
|
/**
|
|
512
537
|
* Initialize the detector (including WASM if enabled)
|
|
513
538
|
*/
|
|
@@ -681,6 +706,12 @@ var EdgeAgentDetectorWrapperWithWasm = class {
|
|
|
681
706
|
events = /* @__PURE__ */ new Map();
|
|
682
707
|
constructor(config) {
|
|
683
708
|
this.detector = new EdgeAgentDetectorWithWasm(config?.enableWasm ?? true);
|
|
709
|
+
if (config?.baseUrl) {
|
|
710
|
+
this.detector.setBaseUrl(config.baseUrl);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
setBaseUrl(url) {
|
|
714
|
+
this.detector.setBaseUrl(url);
|
|
684
715
|
}
|
|
685
716
|
async analyze(input) {
|
|
686
717
|
const result = await this.detector.analyze(input);
|
|
@@ -1371,10 +1402,18 @@ function createEnhancedAgentShieldMiddleware(config = {}) {
|
|
|
1371
1402
|
};
|
|
1372
1403
|
let detector = null;
|
|
1373
1404
|
let detectorInitPromise = null;
|
|
1374
|
-
const getDetector = async () => {
|
|
1375
|
-
if (detector)
|
|
1405
|
+
const getDetector = async (requestUrl) => {
|
|
1406
|
+
if (detector) {
|
|
1407
|
+
if (requestUrl && "setBaseUrl" in detector) {
|
|
1408
|
+
detector.setBaseUrl(requestUrl);
|
|
1409
|
+
}
|
|
1410
|
+
return detector;
|
|
1411
|
+
}
|
|
1376
1412
|
if (detectorInitPromise) {
|
|
1377
1413
|
await detectorInitPromise;
|
|
1414
|
+
if (requestUrl && detector && "setBaseUrl" in detector) {
|
|
1415
|
+
detector.setBaseUrl(requestUrl);
|
|
1416
|
+
}
|
|
1378
1417
|
return detector;
|
|
1379
1418
|
}
|
|
1380
1419
|
detectorInitPromise = (async () => {
|
|
@@ -1393,6 +1432,9 @@ function createEnhancedAgentShieldMiddleware(config = {}) {
|
|
|
1393
1432
|
}
|
|
1394
1433
|
})();
|
|
1395
1434
|
await detectorInitPromise;
|
|
1435
|
+
if (requestUrl && detector && "setBaseUrl" in detector) {
|
|
1436
|
+
detector.setBaseUrl(requestUrl);
|
|
1437
|
+
}
|
|
1396
1438
|
return detector;
|
|
1397
1439
|
};
|
|
1398
1440
|
const sessionManager = new SessionManager();
|
|
@@ -1414,7 +1456,7 @@ function createEnhancedAgentShieldMiddleware(config = {}) {
|
|
|
1414
1456
|
method: request.method,
|
|
1415
1457
|
timestamp: /* @__PURE__ */ new Date()
|
|
1416
1458
|
};
|
|
1417
|
-
const activeDetector = await getDetector();
|
|
1459
|
+
const activeDetector = await getDetector(request.url);
|
|
1418
1460
|
const result = await activeDetector.analyze(context);
|
|
1419
1461
|
let finalConfidence = result.confidence;
|
|
1420
1462
|
let verificationMethod = result.verificationMethod || "pattern";
|