/** * [WHO]: RetryCoordinator class, auto-retry with exponential backoff, in-loop retry preparation * [FROM]: Depends on agent-core (AssistantMessage), ai (isContextOverflow), core/runtime/utils/sleep * [TO]: Consumed by core/runtime/agent-session.ts * [HERE]: core/runtime/retry-coordinator.ts - retry orchestration extracted from AgentSession */ import type { AssistantMessage } from "@catui/ai/types"; /** Retry settings from SettingsManager */ export interface RetrySettings { enabled: boolean; maxRetries: number; baseDelayMs: number; } /** Callbacks the coordinator needs from its host */ export interface RetryCoordinatorHost { /** Get current model's context window (for overflow detection) */ getContextWindow(): number; /** Get current retry settings */ getRetrySettings(): RetrySettings; /** Remove the last message from agent state (error cleanup) */ removeLastAssistantMessage(): void; /** Trigger agent.continue() for retry */ triggerContinue(): void; /** Emit a session event */ emitEvent(event: RetrySessionEvent): void; } /** Events emitted by RetryCoordinator (subset of AgentSessionEvent) */ export type RetrySessionEvent = { type: "auto_retry_start"; attempt: number; maxAttempts: number; delayMs: number; errorMessage: string; } | { type: "auto_retry_end"; success: boolean; attempt: number; finalError?: string; }; /** * RetryCoordinator — manages auto-retry with exponential backoff. * Extracted from AgentSession to isolate retry state and logic. */ export declare class RetryCoordinator { private _host; private _retryAbortController; private _retryAttempt; private _retryPromise; private _retryResolve; constructor(host: RetryCoordinatorHost); /** Current retry attempt (0 if not retrying) */ get attempt(): number; /** Whether a retry is currently in progress */ get isActive(): boolean; /** * Check if an assistant message represents a retryable error. * Context overflow errors are NOT retryable (handled by compaction). */ isRetryableError(message: AssistantMessage): boolean; /** * Handle a retryable error with exponential backoff. * @returns true if retry was initiated, false if max retries exceeded or disabled */ handleError(message: AssistantMessage): Promise; /** * Handle a retryable error inside an active agent loop. * * Unlike handleError(), this does not mutate host messages and does not * schedule agent.continue(); the caller remains responsible for replacing * loop context and continuing in-place. */ handleErrorInLoop(message: AssistantMessage): Promise; private _prepareRetry; /** * Called when an assistant response succeeds — resets retry counter * and resolves the pending retry promise. */ onSuccess(): void; /** Abort in-progress retry. */ abort(): void; /** Wait for any in-progress retry to complete. */ waitForCompletion(): Promise; private _resolveRetry; }