O(1) sliding-window rate limiter and bot-detection middleware for aihu agent services.
createBotDetectionMiddlewarefunction createBotDetectionMiddleware( options?: BotDetectionOptions, ): (req: Request, next: () => Response | Promise<Response>) => Response | Promise<Response>Returns a middleware function that inspects the `User-Agent` header.
createRateLimiterfunction createRateLimiter(options?: RateLimiterOptions): RateLimitPluginCreate an O(1) fixed-window rate limiter that satisfies `RateLimitPlugin`.
createRateLimitPluginfunction createRateLimiter(options?: RateLimiterOptions): RateLimitPluginCreate an O(1) fixed-window rate limiter that satisfies `RateLimitPlugin`.
BotDetectionOptionsinterface BotDetectionOptions {
/** Additional UA substrings to block (appended to the default list). */
blockList?: string[]
/**
* When true, requests with no User-Agent header are allowed through.
* Default: false (block missing UA).
*/
allowNoUserAgent?: boolean
}`@aihu/scraping` — Fetch-API-compatible bot-detection middleware.
RateLimiterOptionsinterface RateLimiterOptions {
/** Maximum map size (for memory safety). Default: 100_000. */
maxKeys?: number
/** Clock override for testing. Default: Date.now. */
now?: () => number
}`@aihu/scraping` — O(1) sliding-window rate limiter.
RateLimitPlugininterface RateLimitPlugin {
checkRateLimit(rateSpec: string, key: string): boolean
}