import type { LanguageModelV4StreamPart, LanguageModelV4StreamResult } from "@ai-sdk/provider"; import type { FallbackStreamArgs } from "./stream-types.js"; export type { FallbackStreamArgs, ResolvedEntry } from "./stream-types.js"; export declare const FALLBACK_STREAM_ARG_KEYS: readonly ["acquireCandidate", "attemptsStarted", "attemptTimeout", "backoff", "budgetFailureObserved", "budgetSuppressed", "candidateAvailable", "candidateInFlight", "candidates", "classifyFailure", "concurrencyLimit", "firstContentTimeout", "firstResult", "isBudgetFailure", "logicalId", "maxAttempts", "nextOrderingToken", "onAdvance", "onAttempt", "onCandidateFailure", "onCandidateSuccess", "onError", "onRequestOutcome", "options", "prepareCandidate", "priorErrors", "releaseCandidate", "releaseProbeCandidate", "retryAfterOutput", "shouldRetry", "startAttemptStartedAt", "startIndex", "startInFlight", "startOrderingToken", "strictStreamValidation", "totalDeadline", "totalTimeout", "waitForCandidate"]; export declare function captureFallbackStreamArgPromises(value: unknown): asserts value is FallbackStreamArgs; export declare function fallbackStreamArgField(source: FallbackStreamArgs, key: (typeof FALLBACK_STREAM_ARG_KEYS)[number]): unknown; export declare function cancelLateStreamResult(result: LanguageModelV4StreamResult): void; /** Cancel a stream result that arrived after its opening attempt was abandoned. */ export declare function discardLateStreamResult(result: LanguageModelV4StreamResult): void; /** * Framing / metadata stream parts that carry NO visible model output. Before a * candidate "commits" (emits real content or a `finish`), these are BUFFERED: * if the candidate then fails pre-commit they are discarded (so the failed * candidate contributes nothing to the consumer), and if it commits they are * flushed ahead of the content. This is what lets a fallback be transparent — * the openai-compatible provider emits `response-metadata` (and often * `text-start`) on its first chunk before any `text-delta`, so a pre-content * error after them must still discard them and fall back cleanly, not leak a * half-open text block. `finish` is NOT framing — it is a commit + terminal. * * A conservative denylist: an unknown future part type is treated as content * (committing), so we never risk re-emitting it across a fallback. */ export declare function wrapStreamResult(args: FallbackStreamArgs): LanguageModelV4StreamResult; /** * Build the wrapped `ReadableStream`. We own the reader lifecycle (rather than * using a `TransformStream`) so the underlying source can be swapped mid-flight. * * Failure is detected two ways, both routed through `onFailure`: * 1. An in-band `{ type: 'error' }` part (the openai-compatible provider does * NOT reject the stream — it enqueues this and closes normally). * 2. A rejected `reader.read()` (transport abort / connection drop). * * Each candidate's leading framing parts are BUFFERED until it "commits" (emits * real content or a `finish`). A candidate that fails before committing has its * buffered framing DISCARDED and contributes nothing to the consumer — so a * fallback emits exactly one clean lifecycle (one stream-start, one text block), * never duplicate/half-open parts. Fallback only happens pre-commit unless * `retryAfterOutput` is set. */ export declare function createFallbackStream(args: FallbackStreamArgs, setActive: (result: LanguageModelV4StreamResult) => void, firstResult?: LanguageModelV4StreamResult): ReadableStream; /** * Drives one wrapped stream: pumps the active candidate, buffers its framing * until it commits, and falls back to the next candidate on a pre-commit * failure. Extracted to a class so each step is a small method (rather than one * deeply-nested closure). */