import type { AudioFrame } from '@livekit/rtc-node';
import { EventEmitter } from 'events';
import type { ReadableStream } from 'node:stream/web';
import type { TimedString } from '../voice/io.js';
import type { ChatContext, FunctionCall } from './chat_context.js';
import type { ToolChoice, ToolContext } from './tool_context.js';
export type InputSpeechStartedEvent = object;
export interface InputSpeechStoppedEvent {
    userTranscriptionEnabled: boolean;
}
export interface MessageGeneration {
    messageId: string;
    /**
     * Text stream that may contain plain strings or TimedString objects with timestamps.
     */
    textStream: ReadableStream<string | TimedString>;
    audioStream: ReadableStream<AudioFrame>;
    modalities?: Promise<('text' | 'audio')[]>;
}
export interface GenerationCreatedEvent {
    messageStream: ReadableStream<MessageGeneration>;
    functionStream: ReadableStream<FunctionCall>;
    userInitiated: boolean;
    /** Response ID for correlating metrics with spans */
    responseId?: string;
}
export interface RealtimeModelError {
    type: 'realtime_model_error';
    timestamp: number;
    label: string;
    error: Error;
    recoverable: boolean;
}
export interface RealtimeCapabilities {
    /** Whether generated assistant messages can be truncated after interruption. */
    messageTruncation: boolean;
    /** Whether the model emits server-side speech start and stop events for turn taking. */
    turnDetection: boolean;
    /** Whether the model may speak over the caller and decides when to yield. Defaults to false. */
    supportsOverlappingSpeech?: boolean;
    /** Whether the model emits user audio transcription events. */
    userTranscription: boolean;
    /** Whether the model automatically generates a reply after receiving tool results. */
    autoToolReplyGeneration: boolean;
    /** Whether the model can produce audio output directly. */
    audioOutput: boolean;
    /** Whether function call items already in the chat context can be resumed. */
    manualFunctionCalls: boolean;
    /** Whether the chat context can be updated mid-session. */
    midSessionChatCtxUpdate?: boolean;
    /** Whether the instructions can be updated mid-session. */
    midSessionInstructionsUpdate?: boolean;
    /** Whether the tools can be updated mid-session. */
    midSessionToolsUpdate?: boolean;
    /** Whether the tool and tool choice can be specified per response. */
    perResponseToolChoice?: boolean;
    /**
     * Whether the model synchronizes generated transcript timing natively.
     * @deprecated Native transcript synchronization is no longer used by built-in models.
     */
    nativeTranscriptSync?: boolean;
}
/**
 * Error raised by a realtime provider when an operation fails or times out
 * (for example a chat-context update or reply generation).
 */
export declare class RealtimeError extends Error {
    constructor(message: string, options?: ErrorOptions);
}
export interface InputTranscriptionCompleted {
    itemId: string;
    transcript: string;
    isFinal: boolean;
    /** Confidence in the user transcript, when the provider supplies it. */
    confidence?: number;
    /**
     * When the turn this transcript belongs to began, in milliseconds since epoch.
     *
     * A provider that withholds the final transcript until its reply has finished
     * generating should set this, so the user message can be placed on the session
     * timeline where the turn happened rather than where the transcript arrived.
     */
    turnStartedAt?: number;
}
export interface RealtimeSessionReconnectedEvent {
}
export declare abstract class RealtimeModel {
    private _capabilities;
    constructor(capabilities: RealtimeCapabilities);
    get capabilities(): RealtimeCapabilities;
    /** The model name/identifier used by this realtime model */
    abstract get model(): string;
    get provider(): string;
    label(): string;
    abstract session(): RealtimeSession;
    abstract close(): Promise<void>;
}
export declare abstract class RealtimeSession extends EventEmitter {
    protected _realtimeModel: RealtimeModel;
    protected logger: import("pino").Logger;
    private inputAudioStream;
    private inputAudioStreamId?;
    private _mainTask;
    constructor(realtimeModel: RealtimeModel);
    get realtimeModel(): RealtimeModel;
    abstract get chatCtx(): ChatContext;
    abstract get tools(): ToolContext;
    abstract updateInstructions(instructions: string): Promise<void>;
    /**
     * @throws RealtimeError on Timeout
     */
    abstract updateChatCtx(chatCtx: ChatContext): Promise<void>;
    abstract updateTools(tools: ToolContext): Promise<void>;
    abstract updateOptions(options: {
        toolChoice?: ToolChoice | null;
    }): void;
    abstract pushAudio(frame: AudioFrame): void;
    /**
     * @throws RealtimeError on Timeout
     */
    abstract generateReply(instructions?: string, options?: {
        signal?: AbortSignal;
    }): Promise<GenerationCreatedEvent>;
    /**
     * Commit the input audio buffer to the server
     */
    abstract commitAudio(): Promise<void>;
    /**
     * Clear the input audio buffer to the server
     */
    abstract clearAudio(): Promise<void>;
    /**
     * Cancel the current generation (do nothing if no generation is in progress)
     */
    abstract interrupt(): Promise<void>;
    /**
     * Truncate the message at the given audio end time
     */
    abstract truncate(options: {
        messageId: string;
        audioEndMs: number;
        modalities?: ('text' | 'audio')[];
        audioTranscript?: string;
    }): Promise<void>;
    _updateSession(instructions?: string, chatCtx?: ChatContext, tools?: ToolContext): Promise<void>;
    close(): Promise<void>;
    /**
     * Notifies the model that user activity has started
     */
    startUserActivity(): void;
    private _mainTaskImpl;
    setInputAudioStream(audioStream: ReadableStream<AudioFrame>): void;
}
//# sourceMappingURL=realtime.d.ts.map