/** * RateLimiter — AI 请求频率限制 * * 防止单用户过度消耗 GPU/API 资源。 * * 策略: * 1. 滑动窗口速率限制 — 每分钟 N 次请求 * 2. 优雅降级 — 超限时返回友好提示而非静默丢弃 */ export interface RateLimitConfig { /** 每分钟最大请求数(默认 20) */ maxRequestsPerMinute?: number; /** 冷却时间(秒),超限后需等待(默认 10) */ cooldownSeconds?: number; } export interface RateLimitResult { allowed: boolean; /** 如果被拒绝,返回友好提示 */ message?: string; /** 需等待的秒数 */ retryAfterSeconds?: number; } export declare class RateLimiter { private config; private buckets; private cleanupTimer?; private disposed; constructor(config?: RateLimitConfig); /** * 检查请求是否被允许 */ check(userId: string): RateLimitResult; /** * 清理长期不活跃的 bucket。 * 即使 bucket 处于冷却期,如果最后一次请求距今超过 30 分钟,也将其清理。 */ private cleanup; dispose(): void; } //# sourceMappingURL=rate-limiter.d.ts.map