UNPKG

@mickdarling/dollhousemcp

Version:

DollhouseMCP - A Model Context Protocol (MCP) server that enables dynamic AI persona management from markdown files, allowing Claude and other compatible AI assistants to activate and switch between different behavioral personas.

80 lines 2.24 kB
/** * RateLimiter - Implements rate limiting for API calls to prevent abuse * * Features: * - Token bucket algorithm for flexible rate limiting * - Configurable limits per time window * - Memory-efficient implementation * - Thread-safe for concurrent requests */ export interface RateLimiterConfig { maxRequests: number; windowMs: number; minDelayMs?: number; } export interface RateLimitStatus { allowed: boolean; retryAfterMs?: number; remainingTokens: number; resetTime: Date; } export declare class RateLimiter { private tokens; private lastRefill; private lastRequest; private readonly maxTokens; private readonly refillRate; private readonly minDelay; constructor(config: RateLimiterConfig); /** * Check if a request is allowed under the rate limit * @returns Status object indicating if request is allowed */ checkLimit(): RateLimitStatus; /** * Consume a token for an allowed request * Should be called after checkLimit() returns allowed: true */ consumeToken(): void; /** * Get current rate limit status without consuming a token */ getStatus(): RateLimitStatus; /** * Reset the rate limiter to full capacity * Useful for testing or manual intervention */ reset(): void; /** * Refill tokens based on time elapsed */ private refillTokens; /** * Calculate when the rate limit window will reset */ private getResetTime; /** * Get human-readable rate limit information */ toString(): string; } /** * Factory function to create common rate limiters */ export declare class RateLimiterFactory { /** * GitHub API rate limiter (60 requests per hour for unauthenticated) */ static createGitHubLimiter(): RateLimiter; /** * Conservative rate limiter for update checks * Allows 10 checks per hour with 30 second minimum delay */ static createUpdateCheckLimiter(): RateLimiter; /** * Strict rate limiter for sensitive operations * Allows 5 requests per hour with 1 minute minimum delay */ static createStrictLimiter(): RateLimiter; } //# sourceMappingURL=RateLimiter.d.ts.map