@kya-os/agentshield-nextjs
Version:
Next.js middleware for AgentShield AI agent detection
50 lines (46 loc) • 1.66 kB
text/typescript
import { NextRequest } from 'next/server';
/**
* Edge Runtime Compatible WASM Loader for AgentShield
*
* This module provides a pre-built solution for loading WASM in Edge Runtime.
* It requires the WASM file to be manually placed in the project.
*/
interface WasmModule {
default: WebAssembly.Module;
}
interface DetectionResult {
isAgent: boolean;
confidence: number;
agent?: string;
verificationMethod: 'cryptographic' | 'pattern';
riskLevel?: 'low' | 'medium' | 'high' | 'critical';
timestamp: string;
}
interface AgentShieldConfig {
wasmModule?: WebAssembly.Module;
enableWasm?: boolean;
onAgentDetected?: (result: DetectionResult) => void;
blockAgents?: boolean;
allowedAgents?: string[];
debug?: boolean;
}
declare class EdgeRuntimeAgentShield {
private wasmInstance;
private wasmMemory;
private config;
private initialized;
constructor(config?: AgentShieldConfig);
init(wasmModule?: WebAssembly.Module): Promise<void>;
private readString;
private writeString;
detect(request: NextRequest): Promise<DetectionResult>;
private patternDetection;
isInitialized(): boolean;
getVerificationMethod(): 'cryptographic' | 'pattern';
}
/**
* Factory function to create an AgentShield instance for Edge Runtime
*/
declare function createEdgeAgentShield(config?: AgentShieldConfig): EdgeRuntimeAgentShield;
declare function getDefaultAgentShield(config?: AgentShieldConfig): EdgeRuntimeAgentShield;
export { type AgentShieldConfig, type DetectionResult, type WasmModule, createEdgeAgentShield, createEdgeAgentShield as default, getDefaultAgentShield };