/** * Shared rate-limit / fallback / wait-and-retry handler. * * Both the connector path (sessions/manager.ts → runSession) and the web path * (gateway/api.ts → runWebSession) need to: * 1. Detect an engine usage-limit response. * 2. Hand the turn to the first engine in the limited one's chain that can serve one. * 3. Otherwise enter a "waiting" loop: sleep until the reset window, retry on the same engine, * keep the session's lastActivity heartbeat fresh, and loop again if still limited. * 4. Bail out when the deadline passes without recovery. * * The state machine, engine invocations, retry math, heartbeat cadence, deadline * computation, and `transportMeta.engineOverride` bookkeeping are identical between * the two call sites — only the transport-side UI/notification details differ. * This module owns the common bits; per-transport behavior is injected via hooks. * * Per-engine thread ids live in the typed `engineSessions` refs the registry owns * (read with getEngineSessionRef, written with nextEngineSessionFields folded into * this module's existing attempt fences) — never in a transport-meta blob. * * Behavior is intentionally preserved verbatim from the original inlined * implementations — do not "improve" the wait math, the per-step state writes, * or the order of side effects without auditing both call sites. */ import type { RateLimitHandlerOpts, RateLimitOutcome } from "./rate-limit-contract.js"; export type { RateLimitHandlerHooks, RateLimitHandlerOpts, RateLimitInfo, RateLimitOutcome, } from "./rate-limit-contract.js"; /** * Drive the rate-limit recovery state machine. Returns once the situation * resolves (success, fallback completion, timeout, or cancellation). * * The caller has ALREADY detected the rate limit and confirmed it should be * handled (i.e. not a dead session, not an interrupted turn). */ export declare function handleRateLimit(opts: RateLimitHandlerOpts): Promise; //# sourceMappingURL=rate-limit-handler.d.ts.map