/**
 * 0.14.4 — non-streaming → streaming fallback with SSE-to-JSON assembler.
 *
 * The mirror of 0.14.2 (stream-fallback.ts). When the proxy's non-
 * streaming wall-clock timer fires (handleMessagesInner catch at
 * messages.ts:160-176), retry the same body with `stream: true`,
 * consume the SSE event stream, and assemble back into an
 * AnthropicMessagesResponse JSON shape so we can write a normal
 * non-streaming response to the client.
 *
 * Why this matters:
 *
 *   The native REPL (`src/native/conversation.ts:2692`) hardcodes
 *   `stream: false` on its main turn requests. When the model takes
 *   too long to produce a complete response (e.g. the 33K-input
 *   MES-AI architecture review that hit 300.5s on 0.14.1 / would have
 *   needed 400s+), there's no way for the proxy's adaptive budget to
 *   help — the model genuinely needs more wall-clock than any
 *   reasonable single-request budget. Streaming sidesteps this
 *   entirely: chunks arrive incrementally, the per-chunk idle timer
 *   is the only wall-clock bound (and it resets on each chunk).
 *
 *   We can't change the REPL request shape from here (different
 *   process), but we CAN convert the proxy's view: receive non-
 *   streaming from the client, route as streaming to the upstream,
 *   assemble events back to JSON. Client never sees the difference.
 *
 * This is opt-in via `middleware.nonStreamFallbackToStreamingEnabled`
 * (default true). Disable for routes whose streaming path is known
 * to be broken / OOM-prone (some kimi/deepseek long-context streams
 * have been reported to misbehave — see comments in conversation.ts
 * around kimi-code 700K context).
 *
 * Constraints (locked):
 *   - NOT a route-config knob. Single global switch.
 *   - NOT used when the original request already had stream:true.
 *     Streaming requests go through handleMessagesStream which has
 *     its own fallback layer (0.14.2).
 *   - NOT a multi-shot retry loop. Single best-effort attempt; if
 *     the streaming fallback also fails, surface the original
 *     non-streaming timeout diagnostic unchanged.
 *   - The assembler is defensive — malformed events / missing
 *     fields / partial JSON in tool_use deltas all degrade
 *     gracefully (best-effort).
 */
import type { AnthropicMessagesRequest, AnthropicMessagesResponse } from '../types.js';
export declare function isNonStreamFallbackEnabled(middleware: {
    nonStreamFallbackToStreamingEnabled?: boolean;
} | undefined): boolean;
/** Build the streaming retry body. Same shape as `body` with
 *  `stream` forced to `true`. */
export declare function buildStreamingRetryBody(body: AnthropicMessagesRequest): AnthropicMessagesRequest;
/**
 * Consume an SSE stream from an Anthropic Messages streaming response
 * and assemble it back into an AnthropicMessagesResponse JSON.
 *
 * Returns null if assembly fails (e.g. stream closed before
 * message_stop, malformed events, unexpected shape). Caller should
 * fall through to the original non-streaming timeout path on null.
 */
export declare function assembleJsonFromSseStream(stream: ReadableStream<Uint8Array>, options?: {
    signal?: AbortSignal;
}): Promise<AnthropicMessagesResponse | null>;
/**
 * 0.14.7 — OpenAI-protocol variant. For routes with `translate: true`
 * (most cloud relays like DeepSeek / Kimi / Qwen / Moonshot), the
 * upstream returns OpenAI Chat Completion SSE chunks. This variant
 * pipes them through StreamTranslator to produce Anthropic events
 * the assembler can consume.
 */
export declare function assembleJsonFromOpenAiSseStream(stream: ReadableStream<Uint8Array>, requestModel: string, inputTokenEstimate: number, options?: {
    signal?: AbortSignal;
}): Promise<AnthropicMessagesResponse | null>;
/**
 * Route metadata needed for protocol-aware fallback dispatch.
 * `translate=true` means owlcoda is the Anthropic-shape adapter for
 * an OpenAI-protocol upstream (kimi / deepseek / qwen / moonshot
 * etc); the body needs OpenAI shape and the SSE response is OpenAI
 * delta events. `translate=false` (or undefined) means a native
 * Anthropic upstream and both shapes pass through unchanged.
 */
export interface FallbackRouteInfo {
    endpointUrl: string;
    headers: Record<string, string>;
    translate: boolean;
    backendModel: string;
}
/**
 * Attempt the streaming fallback fetch. Returns the assembled
 * AnthropicMessagesResponse on success, or null to signal the caller
 * should proceed with the existing timeout-diagnostic path.
 *
 * 0.14.7: protocol-aware. For Anthropic-native routes, posts the
 * body unchanged and parses Anthropic SSE. For OpenAI-translated
 * routes (translate=true), translates the body via translateRequest
 * before posting, and pipes the OpenAI SSE response through
 * StreamTranslator before assembling.
 */
export declare function fetchStreamingFallback(route: FallbackRouteInfo, retryBody: AnthropicMessagesRequest, signal: AbortSignal, budgetMs: number): Promise<AnthropicMessagesResponse | null>;
