@kya-os/agentshield-nextjs 0.1.34 → 0.1.36
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 +39 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +18 -17
package/dist/index.mjs
CHANGED
|
@@ -1061,18 +1061,9 @@ async function checkWasmAvailability() {
|
|
|
1061
1061
|
if (typeof WebAssembly === "undefined") {
|
|
1062
1062
|
return false;
|
|
1063
1063
|
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
115,
|
|
1068
|
-
109,
|
|
1069
|
-
1,
|
|
1070
|
-
0,
|
|
1071
|
-
0,
|
|
1072
|
-
0
|
|
1073
|
-
]);
|
|
1074
|
-
const module = await WebAssembly.compile(wasmCode);
|
|
1075
|
-
await WebAssembly.instantiate(module);
|
|
1064
|
+
if (!WebAssembly.instantiate || !WebAssembly.Module) {
|
|
1065
|
+
return false;
|
|
1066
|
+
}
|
|
1076
1067
|
return true;
|
|
1077
1068
|
} catch {
|
|
1078
1069
|
return false;
|
|
@@ -1378,14 +1369,32 @@ function createEnhancedAgentShieldMiddleware(config = {}) {
|
|
|
1378
1369
|
});
|
|
1379
1370
|
return storageInitPromise;
|
|
1380
1371
|
};
|
|
1381
|
-
let
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
if (
|
|
1385
|
-
|
|
1372
|
+
let detector = null;
|
|
1373
|
+
let detectorInitPromise = null;
|
|
1374
|
+
const getDetector = async () => {
|
|
1375
|
+
if (detector) return detector;
|
|
1376
|
+
if (detectorInitPromise) {
|
|
1377
|
+
await detectorInitPromise;
|
|
1378
|
+
return detector;
|
|
1386
1379
|
}
|
|
1387
|
-
|
|
1388
|
-
|
|
1380
|
+
detectorInitPromise = (async () => {
|
|
1381
|
+
try {
|
|
1382
|
+
const wasmAvailable = await checkWasmAvailability();
|
|
1383
|
+
if (wasmAvailable) {
|
|
1384
|
+
console.log("[AgentShield] \u2705 WASM support detected - enhanced detection enabled");
|
|
1385
|
+
detector = new EdgeAgentDetectorWrapperWithWasm({ enableWasm: true });
|
|
1386
|
+
} else {
|
|
1387
|
+
console.log("[AgentShield] \u2139\uFE0F Using pattern-based detection (WASM not available)");
|
|
1388
|
+
detector = new EdgeAgentDetectorWrapper({});
|
|
1389
|
+
}
|
|
1390
|
+
} catch (error) {
|
|
1391
|
+
console.warn("[AgentShield] Failed to initialize WASM, using fallback:", error);
|
|
1392
|
+
detector = new EdgeAgentDetectorWrapper({});
|
|
1393
|
+
}
|
|
1394
|
+
})();
|
|
1395
|
+
await detectorInitPromise;
|
|
1396
|
+
return detector;
|
|
1397
|
+
};
|
|
1389
1398
|
const sessionManager = new SessionManager();
|
|
1390
1399
|
const sessionTrackingEnabled = config.sessionTracking?.enabled !== false;
|
|
1391
1400
|
return async (request) => {
|
|
@@ -1405,7 +1414,8 @@ function createEnhancedAgentShieldMiddleware(config = {}) {
|
|
|
1405
1414
|
method: request.method,
|
|
1406
1415
|
timestamp: /* @__PURE__ */ new Date()
|
|
1407
1416
|
};
|
|
1408
|
-
const
|
|
1417
|
+
const activeDetector = await getDetector();
|
|
1418
|
+
const result = await activeDetector.analyze(context);
|
|
1409
1419
|
let finalConfidence = result.confidence;
|
|
1410
1420
|
let verificationMethod = result.verificationMethod || "pattern";
|
|
1411
1421
|
if (result.isAgent) {
|
|
@@ -1490,12 +1500,15 @@ function createEnhancedAgentShieldMiddleware(config = {}) {
|
|
|
1490
1500
|
return response2;
|
|
1491
1501
|
}
|
|
1492
1502
|
case "log":
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1503
|
+
const isInteresting = finalConfidence >= 0.9 || result.detectedAgent?.name?.toLowerCase().includes("chatgpt") || result.detectedAgent?.name?.toLowerCase().includes("perplexity") || verificationMethod === "signature";
|
|
1504
|
+
if (isInteresting) {
|
|
1505
|
+
console.log(`[AgentShield] \u{1F916} AI Agent detected (${verificationMethod}):`, {
|
|
1506
|
+
agent: result.detectedAgent?.name,
|
|
1507
|
+
confidence: `${(finalConfidence * 100).toFixed(0)}%`,
|
|
1508
|
+
path: pathWithQuery,
|
|
1509
|
+
verification: verificationMethod
|
|
1510
|
+
});
|
|
1511
|
+
}
|
|
1499
1512
|
break;
|
|
1500
1513
|
}
|
|
1501
1514
|
}
|