import { type APIConnectOptions, Future, type TimedString, llm, stream } from '@livekit/agents';
import { AudioFrame } from '@livekit/rtc-node';
import * as api_proto from './api_proto.js';
type Modality = 'text' | 'audio';
interface RealtimeOptions {
    model: api_proto.Model;
    voice: api_proto.Voice;
    toolChoice?: llm.ToolChoice;
    inputAudioTranscription?: api_proto.InputAudioTranscription | null;
    inputAudioNoiseReduction?: api_proto.NoiseReduction | null;
    turnDetection?: api_proto.TurnDetectionType | null;
    maxResponseOutputTokens?: number | 'inf';
    speed?: number;
    tracing?: api_proto.TracingConfig | null;
    reasoning?: api_proto.Reasoning;
    apiKey?: string;
    baseURL: string;
    isAzure: boolean;
    azureDeployment?: string;
    entraToken?: string;
    apiVersion?: string;
    maxSessionDuration: number;
    connOptions: APIConnectOptions;
    modalities: Modality[];
}
/** @internal */
export interface MessageGeneration {
    messageId: string;
    textChannel: stream.StreamChannel<string | TimedString>;
    audioChannel: stream.StreamChannel<AudioFrame>;
    audioTranscript: string;
    modalities: Future<('text' | 'audio')[]>;
}
/** @internal */
export interface ResponseGeneration {
    messageChannel: stream.StreamChannel<llm.MessageGeneration>;
    functionChannel: stream.StreamChannel<llm.FunctionCall>;
    messages: Map<string, MessageGeneration>;
    /** @internal */
    _doneFut: Future;
    /** @internal */
    _createdTimestamp: number;
    /** @internal */
    _firstTokenTimestamp?: number;
}
/** @internal */
export declare class DiscardedGeneration {
    readonly discarded = true;
}
/** @internal Exported for testing purposes */
export declare function isFatalError(error: unknown): boolean;
export declare class RealtimeModel extends llm.RealtimeModel {
    sampleRate: number;
    numChannels: number;
    inFrameSize: number;
    outFrameSize: number;
    _options: RealtimeOptions;
    get model(): string;
    get provider(): string;
    label(): string;
    constructor(options?: {
        model?: string;
        reasoning?: api_proto.Reasoning;
        voice?: string;
        /** @deprecated Unused in GA API (v1). Temperature is no longer supported. */
        temperature?: number;
        toolChoice?: llm.ToolChoice;
        baseURL?: string;
        modalities?: Modality[];
        inputAudioTranscription?: api_proto.InputAudioTranscription | null;
        inputAudioNoiseReduction?: api_proto.NoiseReduction | null;
        turnDetection?: api_proto.TurnDetectionType | null;
        speed?: number;
        tracing?: api_proto.TracingConfig | null;
        azureDeployment?: string;
        apiKey?: string;
        entraToken?: string;
        apiVersion?: string;
        maxSessionDuration?: number;
        connOptions?: APIConnectOptions;
    });
    /**
     * Create a RealtimeModel instance configured for Azure OpenAI Service.
     *
     * @param azureDeployment - The name of your Azure OpenAI deployment.
     * @param azureEndpoint - The endpoint URL for your Azure OpenAI resource. If undefined, will attempt to read from the environment variable AZURE_OPENAI_ENDPOINT.
     * @param apiVersion - **Deprecated.** API version for legacy Azure OpenAI preview models. Will be removed on April 30, 2026. Omit for GA models.
     * @param apiKey - Azure OpenAI API key. If undefined, will attempt to read from the environment variable AZURE_OPENAI_API_KEY.
     * @param entraToken - Azure Entra authentication token. Required if not using API key authentication.
     * @param baseURL - Base URL for the API endpoint. If undefined, constructed from the azure_endpoint.
     * @param voice - Voice setting for audio outputs. Defaults to "marin".
     * @param inputAudioTranscription - Options for transcribing input audio. Defaults to @see DEFAULT_INPUT_AUDIO_TRANSCRIPTION.
     * @param inputAudioNoiseReduction - Options for noise reduction. Defaults to undefined.
     * @param turnDetection - Options for server-based voice activity detection (VAD). Defaults to @see DEFAULT_SERVER_VAD_OPTIONS.
     * @param speed - Speed of the audio output. Defaults to 1.0.
     * @param tracing - Tracing configuration. Defaults to undefined.
     *
     * @returns A RealtimeModel instance configured for Azure OpenAI Service.
     *
     * @throws Error if required Azure parameters are missing or invalid.
     */
    static withAzure({ azureDeployment, azureEndpoint, apiVersion, apiKey, entraToken, baseURL, voice, temperature, // eslint-disable-line @typescript-eslint/no-unused-vars
    inputAudioTranscription, inputAudioNoiseReduction, turnDetection, speed, tracing, }: {
        azureDeployment: string;
        azureEndpoint?: string;
        apiVersion?: string;
        apiKey?: string;
        entraToken?: string;
        baseURL?: string;
        voice?: string;
        /** @deprecated Unused in GA API (v1). Temperature is no longer supported. */
        temperature?: number;
        inputAudioTranscription?: api_proto.InputAudioTranscription;
        inputAudioNoiseReduction?: api_proto.NoiseReduction;
        turnDetection?: api_proto.TurnDetectionType;
        speed?: number;
        tracing?: api_proto.TracingConfig;
    }): RealtimeModel;
    session(): RealtimeSession;
    close(): Promise<void>;
}
/**
 * Build the conversational Realtime API WebSocket URL.
 *
 * The scheme of `baseURL` is respected: `http://` maps to `ws://`
 * and `https://` maps to `wss://`.
 *
 * @internal
 */
export declare function processBaseURL({ baseURL, model, isAzure, azureDeployment, apiVersion, }: {
    baseURL: string;
    model: string;
    isAzure: boolean;
    azureDeployment?: string;
    apiVersion?: string;
}): string;
/**
 * A session for the OpenAI Realtime API.
 *
 * This class is used to interact with the OpenAI Realtime API.
 * It is responsible for sending events to the OpenAI Realtime API and receiving events from it.
 *
 * It exposes two more events:
 * - openai_server_event_received: expose the raw server events from the OpenAI Realtime API
 * - openai_client_event_queued: expose the raw client events sent to the OpenAI Realtime API
 */
export declare class RealtimeSession extends llm.RealtimeSession {
    #private;
    private _tools;
    protected remoteChatCtx: llm.RemoteChatContext;
    private messageChannel;
    private inputResampler?;
    private instructions?;
    private oaiRealtimeModel;
    private _options;
    protected currentGeneration?: ResponseGeneration | DiscardedGeneration;
    private responseCreatedFutures;
    private discardedEventIds;
    private textModeRecoveryRetries;
    private itemCreateFutures;
    private itemDeleteFutures;
    private chatCtxEventFutures;
    private inputTranscriptAccumulators;
    private audioCapableItemIds;
    private updateChatCtxLock;
    private updateFuncCtxLock;
    private bstream;
    private pushedDurationMs;
    constructor(realtimeModel: RealtimeModel);
    private hasInflightResponse;
    sendEvent(command: api_proto.ClientEvent): void;
    private createSessionUpdateEvent;
    get chatCtx(): llm.ChatContext;
    get tools(): llm.ToolContext<unknown>;
    updateChatCtx(_chatCtx: llm.ChatContext): Promise<void>;
    protected createChatCtxUpdateEvents(chatCtx: llm.ChatContext, addMockAudio?: boolean): Promise<(api_proto.ConversationItemCreateEvent | api_proto.ConversationItemDeleteEvent)[]>;
    updateTools(_tools: llm.ToolContext): Promise<void>;
    private createToolsUpdateEvent;
    updateInstructions(_instructions: string): Promise<void>;
    updateOptions({ toolChoice }: {
        toolChoice?: llm.ToolChoice;
    }): void;
    pushAudio(frame: AudioFrame): void;
    commitAudio(): Promise<void>;
    clearAudio(): Promise<void>;
    generateReply(instructions?: string, options?: {
        signal?: AbortSignal;
    }): Promise<llm.GenerationCreatedEvent>;
    interrupt(): Promise<void>;
    truncate(_options: {
        messageId: string;
        audioEndMs: number;
        modalities?: Modality[];
        audioTranscript?: string;
    }): Promise<void>;
    private loggableEvent;
    protected closeCurrentGeneration(reason?: string): void;
    private rejectResponseCreatedFutures;
    private createWsConn;
    private runWs;
    close(): Promise<void>;
    protected resetInputTurnState(): void;
    protected handleInputAudioBufferSpeechStarted(_event: api_proto.InputAudioBufferSpeechStartedEvent): void;
    private handleInputAudioBufferSpeechStopped;
    protected handleResponseCreated(event: api_proto.ResponseCreatedEvent): void;
    private handleResponseOutputItemAdded;
    protected handleConversationItemCreated(event: api_proto.ConversationItemCreatedEvent): void;
    private handleConversationItemDeleted;
    private handleConversationItemInputAudioTranscriptionDelta;
    private clearAccumulator;
    protected handleConversationItemInputAudioTranscriptionCompleted(event: api_proto.ConversationItemInputAudioTranscriptionCompletedEvent): void;
    private handleConversationItemInputAudioTranscriptionFailed;
    private finalizePartialOnTranscriptionFailure;
    private handleResponseContentPartAdded;
    private handleResponseContentPartDone;
    protected handleResponseTextDelta(event: api_proto.ResponseTextDeltaEvent): void;
    private handleResponseTextDone;
    private handleResponseAudioTranscriptDelta;
    protected handleResponseAudioDelta(event: api_proto.ResponseAudioDeltaEvent): void;
    private handleResponseAudioTranscriptDone;
    private handleResponseAudioDone;
    private handleResponseOutputItemDone;
    private handleResponseDone;
    private handleResponseDoneButNotComplete;
    private handleError;
    private emitError;
    private resampleAudio;
    private createResponse;
}
/** @internal Exported for testing purposes */
export declare function livekitItemToOpenAIItem(item: llm.ChatItem): Promise<api_proto.ItemResource>;
export {};
//# sourceMappingURL=realtime_model.d.ts.map