import { StreamSource } from '@agentskit/core';

/**
 * Retry knobs for adapter fetches. Tunable per call to createStreamSource.
 *
 * Default behavior:
 *   - 3 attempts total (1 initial + 2 retries)
 *   - exponential backoff: 500ms, 1000ms, 2000ms ... (capped at maxDelayMs)
 *   - full jitter on each delay
 *   - retry on HTTP 408, 429, 500, 502, 503, 504
 *   - retry on network errors (fetch throws)
 *   - DO NOT retry on 4xx other than 408/429 (those are bad requests / auth)
 *   - retries only the initial fetch — never mid-stream
 *   - respects Retry-After header when present
 */
interface RetryOptions {
    maxAttempts?: number;
    baseDelayMs?: number;
    maxDelayMs?: number;
    jitter?: boolean;
    retryOn?: (info: {
        error?: unknown;
        response?: Response;
        attempt: number;
    }) => boolean;
    /** Hook for tests + logging. Called after every failed attempt. */
    onRetry?: (info: {
        attempt: number;
        delayMs: number;
        reason: string;
    }) => void;
    /** Sleep override for tests. Defaults to setTimeout. */
    sleep?: (ms: number) => Promise<void>;
}
/**
 * Run a fetch with retries on transient failures. Returns the final
 * Response (whether successful or not — caller decides), or throws if
 * the AbortSignal fires or all attempts fail with a thrown error.
 */
declare function fetchWithRetry(doFetch: (signal: AbortSignal) => Promise<Response>, signal: AbortSignal, retryOpt?: RetryOptions): Promise<Response>;
/**
 * Chunk-splitter that turns one large string into N streamable text chunks.
 * Useful when a provider returns the full response in one shot and you
 * want to feed it to a UI that expects streaming.
 *
 * Default splits by whitespace boundaries with a target chunk size of ~32
 * characters.
 */
declare function chunkText(text: string, targetSize?: number): string[];
/**
 * Build a StreamSource from a non-streaming fetch. The adapter is
 * auto-completing: it fetches once, then yields the text as a sequence
 * of chunks so UIs see the same streaming shape they'd see from a
 * native streaming provider.
 *
 * Use this when you're wiring a provider that only has a non-streaming
 * endpoint but you want consumers (useChat, the runtime) to get
 * identical ergonomics.
 */
declare function simulateStream(doFetch: (signal: AbortSignal) => Promise<Response>, extractText: (response: Response) => Promise<string>, errorLabel: string, options?: {
    chunkSize?: number;
    delayMs?: number;
    retry?: RetryOptions;
}): StreamSource;

export { type RetryOptions as R, chunkText as c, fetchWithRetry as f, simulateStream as s };
