@codai/memorai-core
Version:
Simplified advanced memory engine - no tiers, just powerful semantic search with persistence
92 lines • 2.82 kB
TypeScript
/**
* Advanced error handling and resilience patterns for Memorai
* Includes retry mechanisms, circuit breakers, and graceful degradation
*/
export interface RetryOptions {
maxAttempts: number;
baseDelayMs: number;
maxDelayMs: number;
exponentialBackoff: boolean;
jitter: boolean;
retryableErrors?: string[];
}
export interface CircuitBreakerOptions {
failureThreshold: number;
resetTimeoutMs: number;
monitoringWindowMs: number;
minimumCalls: number;
}
export declare enum CircuitBreakerState {
CLOSED = "CLOSED",
OPEN = "OPEN",
HALF_OPEN = "HALF_OPEN"
}
export declare class RetryManager {
private defaultOptions;
/**
* Execute a function with retry logic
*/
executeWithRetry<T>(operation: () => Promise<T>, options?: Partial<RetryOptions>): Promise<T>;
private isRetryableError;
private calculateDelay;
private sleep;
}
export declare class CircuitBreaker {
private name;
private options;
private state;
private failures;
private lastFailureTime;
private nextAttemptTime;
private recentCalls;
constructor(name: string, options: CircuitBreakerOptions);
/**
* Execute a function with circuit breaker protection
*/
execute<T>(operation: () => Promise<T>): Promise<T>;
/**
* Get current circuit breaker status
*/
getStatus(): {
state: CircuitBreakerState;
failures: number;
successRate: number;
nextAttemptTime?: Date;
};
private shouldRejectCall;
private onSuccess;
private onFailure;
private shouldOpenCircuit;
private recordCall;
private getRecentCallsCount;
private calculateSuccessRate;
private getRecentCallsInWindow;
}
export declare class ResilienceManager {
private retryManager;
private circuitBreakers;
/**
* Execute operation with both retry and circuit breaker protection
*/
executeResilient<T>(operationName: string, operation: () => Promise<T>, options?: {
retry?: Partial<RetryOptions>;
circuitBreaker?: CircuitBreakerOptions;
}): Promise<T>;
/**
* Execute with graceful degradation fallback
*/
executeWithFallback<T>(operation: () => Promise<T>, fallback: () => Promise<T>, operationName?: string, options?: {
retry?: Partial<RetryOptions>;
circuitBreaker?: CircuitBreakerOptions;
}): Promise<T>;
/**
* Get status of all circuit breakers
*/
getAllCircuitBreakerStatus(): Record<string, ReturnType<CircuitBreaker['getStatus']>>;
/**
* Reset a specific circuit breaker
*/ resetCircuitBreaker(name: string): boolean;
private getOrCreateCircuitBreaker;
}
export declare const resilienceManager: ResilienceManager;
//# sourceMappingURL=ResilienceManager.d.ts.map