import type { CircuitBreakerConfig, CircuitBreakerDecision, CircuitState, CounterStoreLike, ScanContext, ToolCall, ViolationType } from "../types.js"; export interface CircuitBreakerOptions { /** Optional distributed counter store (ioredis-compatible). */ counterStore?: CounterStoreLike; /** * Cap on the number of (tool, scope) pairs tracked in-process. * Prevents unbounded growth in long-lived runtimes. Default: 5_000. * Override via env `AI_SHIELD_CIRCUIT_MAX_KEYS`. */ maxKeys?: number; } /** * Registry of breakers keyed by `${tool}::${scope}`. The registry * owns config + state; per-(tool, scope) breakers are created lazily. */ export declare class CircuitBreakerRegistry { private configs; private states; /** * Reserved for distributed-counter mode (e.g. cross-replica state). * The in-process path is the supported v0.2 surface; the store is * accepted so callers wiring up an `ioredis`-shaped backend get a * stable constructor option, and downstream releases can swap the * internal accounting to use it without breaking the API. */ protected readonly store: CounterStoreLike; private readonly maxKeys; constructor(configs?: CircuitBreakerConfig[], options?: CircuitBreakerOptions); /** Configure (or re-configure) a breaker. Idempotent. */ configure(config: CircuitBreakerConfig): void; /** * Check whether a tool call is allowed. Records the attempt either * way; callers must invoke `recordSuccess()`/`recordFailure()` AFTER * the actual call so anomaly counts stay honest. */ check(tool: ToolCall, context?: ScanContext): Promise; /** Record a successful tool invocation. Closes a half-open breaker. */ recordSuccess(toolName: string, context?: ScanContext): void; /** * Record a failed tool invocation. Trips the breaker once * `failureThreshold` failures accumulate within the window. */ recordFailure(toolName: string, context?: ScanContext): void; /** Manually force a breaker into a state — useful for tests / ops. */ trip(toolName: string, scope?: string): void; reset(toolName: string, scope?: string): void; /** Inspect current state — for dashboards / audit. */ inspect(toolName: string, scope?: string): { state: CircuitState; callsInWindow: number; writesInWindow: number; failuresInWindow: number; } | null; /** Suggested ViolationType for a denied decision — useful in audit logs. */ static violationType(decision: CircuitBreakerDecision): ViolationType; private getOrInitState; } /** * Build the scope string the circuit breaker uses internally for a * given (agentId, sessionId) pair. Exposed so callers of `inspect()`, * `trip()`, and `reset()` don't have to know the separator convention. * * @example * ```ts * const scope = makeBreakerScope("agent-a", "session-1"); * const snap = registry.inspect("delete_user", scope); * ``` */ export declare function makeBreakerScope(agentId?: string, sessionId?: string): string; //# sourceMappingURL=circuit-breaker.d.ts.map