import type { CircuitStateStore, SharedCircuitState } from './circuit-breaker.js'; export type { CircuitStateStore, SharedCircuitState } from './circuit-breaker.js'; /** * Shared circuit state in one process. * * For several `NexusAI` clients or workers inside one process, and for tests. Across processes use * `RedisCircuitStateStore` or the Postgres adapter. */ export declare class MemoryCircuitStateStore implements CircuitStateStore { private readonly now; private readonly states; private readonly probes; constructor(now?: () => number); /** Every provider's shared circuit state. */ read(): SharedCircuitState[]; /** * Writes a transition, unless a newer one is already stored. Releases the provider's probe claim. */ write(state: SharedCircuitState): void; /** * Claims the right to probe a provider for `ttlMs`. Resolves true for the claimant, including * when it already holds the claim. */ claimProbe(providerName: string, owner: string, ttlMs: number): boolean; } /** * The Redis commands the circuit store needs, in `ioredis` argument order. * * Structural, as with the other Redis adapters, so no Redis client becomes a dependency. A client * with a different `set` signature, such as `node-redis`, needs a one-line wrapper. */ export interface RedisCircuitLikeClient { /** Reads every hash field. */ hgetall(key: string): Promise | null> | Record | null; /** Reads a hash field. */ hget(key: string, field: string): Promise | string | null; /** Sets a hash field. */ hset(key: string, field: string, value: string): Promise | unknown; /** `SET key value PX ttl NX`, resolving to `'OK'` when the key was set. */ set(key: string, value: string, px: 'PX', ttlMs: number, nx: 'NX'): Promise | unknown; /** Reads a key. */ get(key: string): Promise | string | null; /** Deletes a key. */ del(key: string): Promise | unknown; /** Optional atomic primitive. Strongly preferred; see the class note. */ eval?(script: string, numKeys: number, ...args: string[]): Promise | unknown; } /** Options for the Redis circuit store. */ export interface RedisCircuitStateStoreOptions { /** Key prefix. Defaults to `nexus-ai-pro:circuits:`. */ prefix?: string; /** Disables the Lua path even when the client exposes `eval`. */ useEval?: boolean; } /** * Shared circuit state in Redis, so every worker behind a load balancer agrees on which providers * are down. * * Probe claims are `SET NX` with an expiry, which is atomic on every Redis. With `eval`, a * transition is written only when it is newer than the stored one, in one step; without it, the * store compares and writes separately, and a stale transition landing at the wrong moment can * briefly win. Workers heal that on their own — a stale "open" is probed and closed after one * cooldown — but prefer a client with `eval`. */ export declare class RedisCircuitStateStore implements CircuitStateStore { private readonly client; private readonly prefix; private readonly useEval; constructor(client: RedisCircuitLikeClient, options?: RedisCircuitStateStoreOptions); /** Every provider's shared circuit state. Unreadable entries are skipped. */ read(): Promise; /** * Writes a transition, unless a newer one is already stored. Releases the provider's probe claim. */ write(state: SharedCircuitState): Promise; /** * Claims the right to probe a provider for `ttlMs`. Resolves true for the claimant, including * when it already holds the claim. */ claimProbe(providerName: string, owner: string, ttlMs: number): Promise; private statesKey; private probeKey; }