import type { ChatMessage, ProviderId, TokenUsage } from "../../../types.js"; import type { StreamRecoveryState } from "../../stream-recovery.js"; import { classifyStreamFailure } from "../../stream-recovery.js"; export interface StreamFailureDeferredCall { readonly eventId: string; readonly call: { readonly name: string; }; readonly shown: boolean; } export interface StreamFailureState { freeTierConsecutiveFailures: number; freeTierAdvisoryShown: boolean; lowYieldResumptions: number; interruptedVisible: string; interruptedReasoning: string; allowModelFallback: boolean; preferModelFallback: boolean; retryWithoutThinking: boolean; visibleCommitted: boolean; } export interface StreamFailurePorts { readonly messages: ChatMessage[]; readonly recoveryState: StreamRecoveryState; readonly provider: ProviderId; readonly notify: (level: "info" | "warn", message: string) => void; readonly emitStatus: (text: string) => void; readonly emitTokenUsage: (usage: TokenUsage, provider: ProviderId, model: string) => void; readonly emitEmptyAssistantMessage: () => void; readonly writeAssistantMessage: (text: string) => void; readonly writeThinkingBlock: (text: string) => void; readonly writeToolBlocked: (eventId: string, toolName: string, reason: string) => void; readonly rememberThinking: (text: string) => void; readonly sanitizeAssistantText: (text: string) => string; readonly finishDeltaParser: () => void; readonly recoveryUserMessage: (content: string) => ChatMessage; readonly forceCompact: (reason: string) => Promise; readonly delay: (ms: number) => Promise; } export interface StreamFailureAttemptUsage { readonly usage: TokenUsage; readonly provider: ProviderId; readonly model: string; } export interface StreamFailureInput { readonly kind: ReturnType; readonly error?: unknown; readonly alreadyEmitted: boolean; readonly attemptUsage: StreamFailureAttemptUsage | undefined; readonly accumulatedText: string; readonly streamedReasoningText: string; readonly deferredToolCalls: readonly StreamFailureDeferredCall[]; } export type StreamFailureDecision = "retry" | "rethrow"; export declare const recoverFromStreamFailure: (ports: StreamFailurePorts, state: StreamFailureState, input: StreamFailureInput) => Promise;