/**
 * AI-Specific Rate Limiting
 * Token-based, cost-based, and quota-based rate limiting for AI models
 * Vorion Security Platform
 */
import { EventEmitter } from 'events';
import { RateLimitConfig, RateLimitRule, RateLimitStatus, BurstConfig, CostLimit } from './types';
/**
 * Rate limiter configuration
 */
export interface RateLimiterConfig {
    enabled: boolean;
    defaultLimits: RateLimitRule[];
    defaultBurstConfig: BurstConfig;
    defaultCostLimits: CostLimit[];
    enforcementMode: 'strict' | 'warn' | 'log-only';
    gracePeriodMs: number;
    cleanupIntervalMs: number;
}
/**
 * Usage window for tracking
 */
interface UsageWindow {
    tokens: number;
    requests: number;
    cost: number;
    windowStart: Date;
    burstTokens: number;
    burstStart?: Date;
}
/**
 * Rate limit storage interface
 */
export interface RateLimitStorage {
    getUsage(key: string): Promise<UsageWindow | null>;
    setUsage(key: string, usage: UsageWindow, ttlSeconds: number): Promise<void>;
    incrementUsage(key: string, tokens: number, cost: number, ttlSeconds: number): Promise<UsageWindow>;
    getConfig(modelId: string): Promise<RateLimitConfig | null>;
    setConfig(modelId: string, config: RateLimitConfig): Promise<void>;
}
/**
 * In-memory rate limit storage
 */
export declare class InMemoryRateLimitStorage implements RateLimitStorage {
    private usage;
    private configs;
    private cleanupInterval?;
    constructor(cleanupIntervalMs?: number);
    getUsage(key: string): Promise<UsageWindow | null>;
    setUsage(key: string, usage: UsageWindow, _ttlSeconds: number): Promise<void>;
    incrementUsage(key: string, tokens: number, cost: number, ttlSeconds: number): Promise<UsageWindow>;
    getConfig(modelId: string): Promise<RateLimitConfig | null>;
    setConfig(modelId: string, config: RateLimitConfig): Promise<void>;
    private cleanup;
    destroy(): void;
}
/**
 * Rate limit check result
 */
export interface RateLimitCheckResult {
    allowed: boolean;
    status: RateLimitStatus;
    violatedRules: RateLimitRule[];
    warnings: string[];
}
/**
 * AI Rate Limiter
 * Enforces rate limits based on tokens, requests, and cost
 */
export declare class AIRateLimiter extends EventEmitter {
    private config;
    private storage;
    private modelConfigs;
    constructor(config?: Partial<RateLimiterConfig>, storage?: RateLimitStorage);
    /**
     * Configure rate limits for a specific model
     */
    configureModel(modelId: string, config: RateLimitConfig): Promise<void>;
    /**
     * Get rate limit configuration for a model
     */
    getModelConfig(modelId: string): Promise<RateLimitConfig>;
    /**
     * Check if a request is allowed
     */
    checkLimit(modelId: string, userId: string, estimatedTokens: number, estimatedCost: number, department?: string, organization?: string): Promise<RateLimitCheckResult>;
    /**
     * Record usage after a successful request
     */
    recordUsage(modelId: string, userId: string, tokens: number, cost: number, department?: string, organization?: string): Promise<void>;
    /**
     * Get current rate limit status
     */
    getStatus(modelId: string, userId: string, department?: string, organization?: string): Promise<RateLimitStatus>;
    /**
     * Reset rate limits for a user
     */
    resetLimits(modelId: string, userId: string, department?: string, organization?: string): Promise<void>;
    /**
     * Build storage key for rate limit tracking
     */
    private buildKey;
    /**
     * Calculate effective burst limit
     */
    private calculateBurstLimit;
    /**
     * Calculate remaining quota
     */
    private calculateRemainingQuota;
    /**
     * Get maximum window from config
     */
    private getMaxWindow;
    /**
     * Create an allowed result when rate limiting is disabled
     */
    private createAllowedResult;
    /**
     * Update global configuration
     */
    updateConfig(updates: Partial<RateLimiterConfig>): void;
    /**
     * Get current configuration
     */
    getConfig(): RateLimiterConfig;
    /**
     * Set cost limits for a scope
     */
    setCostLimits(modelId: string, costLimits: CostLimit[]): Promise<void>;
    /**
     * Get usage statistics for a model
     */
    getModelUsageStats(modelId: string, scope: RateLimitRule['scope'], scopeId?: string): Promise<{
        totalTokens: number;
        totalRequests: number;
        totalCost: number;
        windowStart: Date;
        utilizationPercent: number;
    }>;
    /**
     * Create a temporary limit override
     */
    createOverride(modelId: string, userId: string, overrideLimits: Partial<RateLimitRule>[], durationSeconds: number): Promise<void>;
    /**
     * Estimate if a request would exceed limits
     */
    estimateRequest(modelId: string, userId: string, estimatedTokens: number, estimatedCost: number): Promise<{
        wouldExceed: boolean;
        tokensRemaining: number;
        costRemaining: number;
        requestsRemaining: number;
    }>;
}
export default AIRateLimiter;
//# sourceMappingURL=rate-limiter.d.ts.map