UNPKG

@kya-os/agentshield-nextjs

Version:

Next.js middleware for AgentShield AI agent detection

47 lines (45 loc) 1.47 kB
/** * WASM Setup for AgentShield in Next.js Edge Runtime * * This module handles WASM initialization for cryptographic signature verification. * Designed to work without top-level await to avoid Next.js middleware issues. * * Usage in middleware.ts: * ```typescript * import { setupWasm } from '@kya-os/agentshield-nextjs/wasm-setup'; * import { createAgentShieldMiddleware } from '@kya-os/agentshield-nextjs'; * * export async function middleware(request: NextRequest) { * // Initialize WASM inside the middleware function * await setupWasm(); * * const agentShieldMiddleware = createAgentShieldMiddleware({...}); * return agentShieldMiddleware(request); * } * ``` */ /** * Initialize WASM module for AgentShield * * This function: * - Loads WASM in production/Edge Runtime for cryptographic verification * - Skips WASM in test environments (Jest) automatically * - Is safe to call multiple times (idempotent) * - Handles errors gracefully with fallback to pattern detection * * @returns Promise that resolves when initialization is complete */ declare function setupWasm(): Promise<void>; /** * Check if WASM has been initialized * * @returns true if WASM setup has been attempted (success or failure) */ declare function isWasmInitialized(): boolean; /** * Reset WASM initialization state (mainly for testing) * * @internal */ declare function resetWasmState(): void; export { isWasmInitialized, resetWasmState, setupWasm };