/** * Rate limiter for commands with sliding window and burst allowance support. * Keyed by scope: user (context.user.id), tenant (IR tenant resolver), or global. * * Default store is in-process memory. Pass a durable {@link RateLimitStore} * (e.g. PostgresRateLimitStore via `RuntimeOptions.rateLimitStore`) so limits * survive process restarts and span multiple engine instances. * * Spec: docs/spec/semantics.md § "Rate Limiting" */ /** * Result of a rate limit check. */ export interface RateLimitCheckResult { allowed: boolean; retryAfterMs?: number; scopeKey: string; } /** * Configuration for rate limiting (from IR). */ export interface RateLimitConfig { maxRequests: number; windowMs: number; scope: 'user' | 'tenant' | 'global'; burstAllowance?: number; } /** * Persisted sliding-window state for one scope key. */ export interface RateLimitBucketState { timestamps: number[]; windowStart: number; } /** * Durable (or memory) backing store for rate-limit buckets. * Adapters: MemoryRateLimitStore (default), PostgresRateLimitStore. * * Prefer implementing {@link mutate} for multi-writer correctness; when absent, * RateLimiter falls back to get+set (racy under concurrent writers). */ export interface RateLimitStore { get(scopeKey: string): Promise; set(scopeKey: string, state: RateLimitBucketState): Promise; /** Optional; used by tests and admin reset. */ clear?(): Promise; /** * Optional atomic read-modify-write. When present, RateLimiter uses this * instead of get+set so concurrent consumers share one coherent bucket. */ mutate?(scopeKey: string, fn: (current: RateLimitBucketState | undefined) => { next: RateLimitBucketState; result: T; }): Promise; } /** * In-memory RateLimitStore — default for tests and single-process hosts. */ export declare class MemoryRateLimitStore implements RateLimitStore { private logs; get(scopeKey: string): Promise; set(scopeKey: string, state: RateLimitBucketState): Promise; clear(): Promise; mutate(scopeKey: string, fn: (current: RateLimitBucketState | undefined) => { next: RateLimitBucketState; result: T; }): Promise; /** Sync size helper for tests (not part of RateLimitStore). */ size(): number; } /** * Sliding window rate limiter. * Effective limit = maxRequests + (burstAllowance ?? 0). */ export declare class RateLimiter { private readonly store; constructor(store?: RateLimitStore); /** * Check if a request should be allowed under the rate limit. * Prunes expired requests outside the window, then checks count. */ checkRateLimit(scopeKey: string, config: RateLimitConfig, now: number): Promise; clear(): Promise; getRequestCount(scopeKey: string): Promise; } //# sourceMappingURL=runtime-rate-limit.d.ts.map