import { type APIConnectOptions } from '../types.js';
import { Task } from '../utils.js';
import type { VAD } from '../vad.js';
import type { ConversationItemAddedEvent } from '../voice/events.js';
import { STT, type SpeechEvent, SpeechStream } from './stt.js';
/**
 * Internal status tracking for each STT instance.
 * @internal
 */
interface STTStatus {
    available: boolean;
    recoveringRecognizeTask: Task<void> | null;
    recoveringStreamTask: Task<void> | null;
    waitingStreams: Set<FallbackSpeechStream>;
    recoveryClosed: boolean;
}
/**
 * Options for creating a {@link FallbackAdapter}.
 */
export interface FallbackAdapterOptions {
    /** List of STT instances to use for fallback (in priority order). At least one is required. */
    sttInstances: STT[];
    /**
     * VAD used to auto-wrap non-streaming STTs with {@link StreamAdapter}. Required
     * when any of the supplied STT instances does not support streaming.
     */
    vad?: VAD;
    /** Per-attempt timeout in milliseconds. Defaults to 10000. */
    attemptTimeoutMs?: number;
    /** Number of internal retries per STT instance before moving to the next one. Defaults to 1. */
    maxRetryPerSTT?: number;
    /** Delay in milliseconds between internal retries. Defaults to 5000. */
    retryIntervalMs?: number;
}
/**
 * Event emitted when an STT instance's availability changes.
 */
export interface AvailabilityChangedEvent {
    /** The STT instance whose availability changed. */
    stt: STT;
    /** Whether the STT instance is now available. */
    available: boolean;
}
/**
 * Agent Fallback Adapter for STT. Manages multiple STT instances with automatic
 * fallback when the primary provider fails.
 *
 * When the primary STT fails, the adapter switches to the next available
 * provider in the list for the active session. Failed providers are monitored
 * by one probe stream per provider. The probe receives its owner's live audio;
 * another waiting stream takes over if the owner closes. A non-empty
 * FINAL_TRANSCRIPT marks the provider available again.
 * If every provider is unavailable, normal streams retry them in priority order.
 *
 * Non-streaming STTs are automatically wrapped with {@link StreamAdapter}
 * provided a `vad` is passed in.
 *
 * @example
 * ```typescript
 * import { FallbackAdapter } from '@livekit/agents';
 * import { STT as DeepgramSTT } from '@livekit/agents-plugin-deepgram';
 * import { STT as AssemblyAISTT } from '@livekit/agents-plugin-assemblyai';
 *
 * const fallbackSTT = new FallbackAdapter({
 *   sttInstances: [
 *     new AssemblyAISTT(),  // Primary
 *     new DeepgramSTT(),    // Fallback
 *   ],
 * });
 * ```
 */
export declare class FallbackAdapter extends STT {
    readonly sttInstances: STT[];
    readonly attemptTimeoutMs: number;
    readonly maxRetryPerSTT: number;
    readonly retryIntervalMs: number;
    private _status;
    private _logger;
    private _metricsForwarders;
    private _activeStt;
    label: string;
    constructor(opts: FallbackAdapterOptions);
    get model(): string;
    get provider(): string;
    /**
     * Record the child that most recently produced output. Called by
     * `_recognize()` on a successful return and by the streaming path on
     * every event yielded by the elected child.
     * @internal
     */
    _setActiveStt(stt: STT): void;
    /**
     * Returns the current status of all STT instances, including availability
     * and background recovery state.
     */
    get status(): STTStatus[];
    _updateSessionKeyterms(keyterms: string[]): void;
    _pushConversationItem(ev: ConversationItemAddedEvent): void;
    private setupEventForwarding;
    emitAvailabilityChanged(stt: STT, available: boolean): void;
    private tryRecoverRecognize;
    recognize(frame: Parameters<STT['recognize']>[0], abortSignal?: AbortSignal): Promise<SpeechEvent>;
    protected _recognize(frame: Parameters<STT['recognize']>[0], abortSignal?: AbortSignal): Promise<SpeechEvent>;
    stream(options?: {
        connOptions?: APIConnectOptions;
    }): SpeechStream;
    close(): Promise<void>;
}
declare class FallbackSpeechStream extends SpeechStream {
    label: string;
    private fallbackAdapter;
    private recoveringStreams;
    private inputEnded;
    private _logger;
    constructor(adapter: FallbackAdapter, connOptions: APIConnectOptions);
    protected monitorMetrics(): Promise<void>;
    private tryRecoverStream;
    protected run(): Promise<void>;
}
export {};
//# sourceMappingURL=fallback_adapter.d.ts.map