import type { ITransportAdapter } from '../engine/remoting/ITransportAdapter';
/**
 * Circuit breaker states.
 */
export type CircuitState = 'closed' | 'open' | 'half-open';
/**
 * Circuit breaker options.
 */
export interface ICircuitBreakerOptions {
    /**
     * Number of failures before opening circuit.
     * Default: 5
     */
    failureThreshold?: number;
    /**
     * Time to wait before trying half-open in ms.
     * Default: 30000 (30 seconds)
     */
    resetTimeoutMs?: number;
    /**
     * Number of successful calls needed to close circuit from half-open.
     * Default: 2
     */
    successThreshold?: number;
    /**
     * Topic patterns to monitor (regex).
     * If not specified, monitors all topics.
     */
    topicPatterns?: RegExp[];
    /**
     * Called when circuit state changes.
     */
    onStateChange?: (from: CircuitState, to: CircuitState, stats: ICircuitStats) => void;
}
/**
 * Circuit statistics.
 */
export interface ICircuitStats {
    state: CircuitState;
    failures: number;
    successes: number;
    lastFailure?: number;
    lastSuccess?: number;
    openedAt?: number;
    closedAt?: number;
}
/**
 * Circuit breaker error thrown when circuit is open.
 */
export declare class CircuitOpenError extends Error {
    readonly circuitState: CircuitState;
    readonly stats: ICircuitStats;
    constructor(message: string, stats: ICircuitStats);
}
/**
 * CircuitBreaker - Protects against cascading failures.
 *
 * States:
 * - CLOSED: Normal operation, failures counted
 * - OPEN: Requests fail fast, waiting for reset timeout
 * - HALF-OPEN: Testing with limited requests
 */
export declare class CircuitBreaker {
    private _state;
    private _failures;
    private _successes;
    private _lastFailure?;
    private _lastSuccess?;
    private _openedAt?;
    private _closedAt?;
    private readonly _options;
    constructor(options?: ICircuitBreakerOptions);
    /**
     * Get current circuit state.
     */
    get state(): CircuitState;
    /**
     * Get circuit statistics.
     */
    get stats(): ICircuitStats;
    /**
     * Check if a topic should be monitored.
     */
    shouldMonitor(topic: string): boolean;
    /**
     * Check if request can proceed.
     * Throws CircuitOpenError if circuit is open.
     */
    canProceed(topic: string): boolean;
    /**
     * Record a successful operation.
     */
    recordSuccess(topic: string): void;
    /**
     * Record a failed operation.
     */
    recordFailure(topic: string): void;
    /**
     * Manually reset the circuit to closed.
     */
    reset(): void;
    /**
     * Manually trip the circuit to open.
     */
    trip(): void;
    /**
     * Transition to a new state.
     */
    private _transitionTo;
}
/**
 * Create a circuit breaker middleware for transport.
 */
export declare function withCircuitBreaker(transport: ITransportAdapter, options?: ICircuitBreakerOptions): ITransportAdapter;
/**
 * Create a circuit breaker that can be shared across transports.
 */
export declare function createCircuitBreaker(options?: ICircuitBreakerOptions): CircuitBreaker;
//# sourceMappingURL=circuitBreaker.d.ts.map