route-claudecode
Version:
Advanced routing and transformation system for Claude Code outputs to multiple AI providers
122 lines • 4.38 kB
TypeScript
/**
* Simple Provider Manager with Round-Robin and Failover
* Replaces complex concurrency management with simple blacklisting
* Task 1 Implementation: Multi-provider round-robin with failure-based blacklisting
*/
export interface SimpleProviderBlacklist {
providerId: string;
model?: string;
blacklistedUntil: Date;
reason: 'rate_limit' | 'auth_failure' | 'network_error' | 'server_error';
errorCount: number;
consecutiveErrors?: number;
}
export interface WeightedProvider {
providerId: string;
model?: string;
weight: number;
keyCount?: number;
}
export interface ProviderKeyStatus {
providerId: string;
keyIndex: number;
isBlacklisted: boolean;
consecutiveErrors: number;
lastError?: string;
blacklistedUntil?: Date;
}
export declare class SimpleProviderManager {
private roundRobinIndex;
private blacklist;
private consecutiveFailures;
private keyRoundRobinIndex;
private keyBlacklist;
private readonly RATE_LIMIT_BLACKLIST_DURATION;
private readonly AUTH_FAILURE_BLACKLIST_DURATION;
private readonly NETWORK_ERROR_BLACKLIST_DURATION;
private readonly SERVER_ERROR_BLACKLIST_DURATION;
private readonly CONSECUTIVE_429_THRESHOLD;
constructor();
/**
* Select next provider using weighted selection with blacklist filtering
* Supports both weight-based and round-robin selection
*/
selectProviderWeighted(providers: WeightedProvider[], category: string): WeightedProvider | null;
/**
* Select next provider using round-robin with blacklist filtering
* Now supports model-specific blacklisting (legacy method)
*/
selectProvider(providers: string[], category: string, model?: string): string | null;
/**
* Report provider failure and apply blacklisting if needed
* Now supports model-specific blacklisting when model is provided
* Enhanced with consecutive 429 detection
*/
reportFailure(providerId: string, error: string, httpCode?: number, model?: string): void;
/**
* Report provider success (removes from blacklist if temporary)
* Now supports model-specific recovery and resets consecutive failure counts
*/
reportSuccess(providerId: string, model?: string): void;
/**
* Check if provider is currently blacklisted
* Now supports model-specific blacklisting
*/
isBlacklisted(providerId: string, model?: string): boolean;
/**
* Get blacklist status for all providers
*/
getBlacklistStatus(): Record<string, SimpleProviderBlacklist | null>;
/**
* Clear all blacklists (for testing or emergency recovery)
*/
clearAllBlacklists(): void;
/**
* Get round-robin state for monitoring
*/
getRoundRobinState(): Record<string, number>;
private blacklistProvider;
private categorizeFailure;
private getBlacklistDuration;
/**
* Redistribute weights among available providers
* When providers are blacklisted, their weights are redistributed proportionally
*/
private redistributeWeights;
/**
* Weighted random selection algorithm
* Uses cumulative weight distribution for O(n) selection
*/
private weightedRandomSelection;
/**
* Get consecutive failure count for a provider
*/
getConsecutiveFailures(providerId: string, model?: string): number;
/**
* Clear consecutive failure counters (for testing or recovery)
*/
clearConsecutiveFailures(): void;
/**
* Initialize key-level tracking for a provider
*/
initializeProviderKeys(providerId: string, keyCount: number): void;
/**
* Select next available key for a provider using round-robin
*/
selectProviderKey(providerId: string): number | null;
/**
* Report key-level failure for a specific provider key
*/
reportKeyFailure(providerId: string, keyIndex: number, error: string, httpCode?: number): void;
/**
* Report key-level success for a specific provider key
*/
reportKeySuccess(providerId: string, keyIndex: number): void;
/**
* Get key-level status for a provider
*/
getProviderKeyStatus(providerId: string): ProviderKeyStatus[] | null;
private blacklistProviderKey;
private cleanExpiredKeyBlacklists;
}
//# sourceMappingURL=simple-provider-manager.d.ts.map