/**
 * Circuit breaker — Hystrix-style state machine.
 *
 * Sprint-468. Wrap an unreliable async operation so N consecutive
 * failures trip the breaker OPEN (all subsequent calls fast-fail
 * without invoking the operation) for `resetAfterMs`. After that a
 * single probe call runs in HALF-OPEN state; success → back to CLOSED,
 * failure → back to OPEN.
 *
 *   CLOSED (normal)
 *     ├─ N failures ──► OPEN (fast-fail, window)
 *     └─ success ──► CLOSED
 *   OPEN
 *     └─ after resetAfterMs ──► HALF-OPEN (1 probe)
 *   HALF-OPEN
 *     ├─ probe success ──► CLOSED
 *     └─ probe failure ──► OPEN (new window)
 *
 * Usage:
 *   const safeArchive = circuitBreaker(brain.archiveKnowledge.bind(brain), {
 *     name: "brain.archive",
 *     failureThreshold: 5,
 *     resetAfterMs: 30_000,
 *   });
 */
export type CircuitState = "closed" | "open" | "half-open";
export interface CircuitBreakerOptions {
    /** Operation identifier for CircuitOpenError messages. */
    name: string;
    /** Consecutive failures required to trip OPEN. Default 5. */
    failureThreshold?: number;
    /** How long to stay OPEN before the HALF-OPEN probe. Default 30s. */
    resetAfterMs?: number;
    /** Optional clock for tests. */
    now?: () => number;
    /**
     * Predicate — classify an error as "should count as failure" vs
     * "fast-exit without tripping". Default: every thrown value counts.
     */
    isFailure?: (err: unknown) => boolean;
}
export declare class CircuitOpenError extends Error {
    readonly circuitName: string;
    readonly retryAfterMs: number;
    constructor(circuitName: string, retryAfterMs: number);
}
export interface CircuitBreaker<TArgs extends unknown[], TResult> {
    (...args: TArgs): Promise<TResult>;
    readonly state: CircuitState;
    /** Consecutive failures in the current CLOSED window. */
    readonly failureCount: number;
    /** Force back to CLOSED (for tests or operational reset). */
    reset(): void;
}
export declare function circuitBreaker<TArgs extends unknown[], TResult>(fn: (...args: TArgs) => Promise<TResult>, options: CircuitBreakerOptions): CircuitBreaker<TArgs, TResult>;
//# sourceMappingURL=circuit-breaker.d.ts.map