import { type APIConnectOptions, llm } from '@livekit/agents';
import { AudioFrame } from '@livekit/rtc-node';
import { ReadableStream } from 'node:stream/web';
import type { ClientEvent, DelegationTarget, ResponsesConfig, ServerEvent } from './gpt_live_types.js';
/** Settings for the backend Responses model. Unset fields use the service defaults.
 * @public
 */
export interface ResponsesDelegationOptions {
    /** Defaults to gpt-5.6-luna. */
    model?: string;
    /** Backend instructions, separate from the voice persona. */
    instructions?: string;
    /** Restrict backend tool selection. Null restores automatic selection. */
    toolChoice?: llm.ToolChoice | null;
    /** Allow the backend to request multiple tools in one response. */
    parallelToolCalls?: boolean;
    /** Reasoning effort for the backend model. */
    reasoning?: ResponsesConfig['reasoning'];
    /** Text format and verbosity for backend responses. */
    text?: ResponsesConfig['text'];
    /** Processing tier for backend responses. */
    serviceTier?: ResponsesConfig['service_tier'];
    /** Maximum tokens per backend response; the service requires at least 16. */
    maxOutputTokens?: number;
}
/** Work handed to the application under client delegation.
 * @public
 */
export interface GPTLiveDelegation {
    /** Answer with GPTLiveSession.appendCommentary. Valid only on the connection that created it. */
    id: string;
    /** The caller's current turn, which may not yet be in the agent's chat context. */
    pendingTranscript: string;
}
/** Suggested GPT-Live voice names. Other supported names also pass through to the API. @public */
export type GPTLiveVoices = 'aster' | 'beacon' | 'cinder' | 'marin' | 'stone' | 'vesper';
/** Options for the OpenAI GPT-Live full-duplex voice model.
 * @public
 */
export interface GPTLiveModelOptions {
    /** Voice model identifier. Defaults to gpt-live-1. */
    model?: string;
    /**
     * A named voice (marin by default), or an authorized custom voice object. Fixed at startup.
     * Names pass through unchanged.
     */
    voice?: GPTLiveVoices | (string & NonNullable<unknown>) | Record<string, unknown>;
    /** Fixed at startup. Client delegation requires an agent with no tools. */
    delegation?: DelegationTarget;
    /** Backend configuration when delegation is responses (the default). */
    responsesOptions?: ResponsesDelegationOptions;
    /** Falls back to OPENAI_API_KEY. */
    apiKey?: string;
    /** Falls back to OPENAI_BASE_URL, then https://api.openai.com/v1. */
    baseURL?: string;
    /** Recycle the connection after this many milliseconds. Null (the default) disables the timer. */
    maxSessionDuration?: number | null;
    /** Connection/startup timeout and retry limits. Defaults to DEFAULT_API_CONNECT_OPTIONS. */
    connOptions?: APIConnectOptions;
}
/** OpenAI GPT-Live full-duplex voice model, ready to pass to AgentSession.
 * @public
 */
export declare class GPTLiveModel extends llm.DuplexModel {
    /** @internal */
    readonly _opts: Required<GPTLiveModelOptions>;
    /** Configure a voice model. Throws when no OpenAI API key is available. */
    constructor(options?: GPTLiveModelOptions);
    /** Voice model identifier used for sessions and metrics. */
    get model(): string;
    /** Host of the configured API endpoint. */
    get provider(): string;
    /** Keep output active through short pauses in speech. */
    audioGate(): llm.AudioGate;
    /** Create a connection that starts after the framework configures the session. */
    session(): GPTLiveSession;
    /** The model owns no shared resources. Close each session to release its connection. */
    close(): Promise<void>;
}
/**
 * GPT-Live WebSocket session, accessible through Agent.duplexSession.
 * Also emits openai_server_event_received, openai_client_event_queued and delegation_created.
 * Append methods queue context without waiting for acknowledgment. The appended events arrive
 * at the estimated context-injection end and do not indicate speech completion.
 * @public
 */
export declare class GPTLiveSession extends llm.DuplexSession<{
    openai_server_event_received: (event: ServerEvent) => void;
    openai_client_event_queued: (event: ClientEvent | Record<string, unknown>) => void;
    delegation_created: (event: GPTLiveDelegation) => void;
}> {
    private readonly opts;
    private readonly logger;
    private readonly debug;
    private readonly history;
    private readonly speech;
    private readonly backendRunningResponses;
    private readonly backendOpenCalls;
    private backendResponsePending;
    private readonly delegationIds;
    private readonly bstream;
    private inputResampler?;
    private inputRate?;
    private _tools;
    private instructions?;
    private askedItemId?;
    private _sessionId?;
    private usageSeconds;
    private sessionStartSent;
    private sessionStarted;
    private closing;
    private audioClosed;
    private queued;
    private ws?;
    private connectionDone?;
    private connectionDraining;
    private requestConnectionClose?;
    private readonly shutdown;
    private readonly mainTask;
    private audioController;
    private readonly output;
    /** Create a session using a copy of the model configuration. */
    constructor(model: GPTLiveModel);
    /** Provider session identifier. Changes when a replacement connection starts. */
    get sessionId(): string | undefined;
    /** Mono 24 kHz PCM output, retained across reconnects and closed on shutdown. */
    get audioStream(): ReadableStream<llm.DuplexAudioFrame>;
    /** Copy of the tools available to the backend Responses model. */
    get tools(): llm.ToolContext;
    /** Queue a wire event. Commands wait for session.started before being sent. */
    sendEvent(event: ClientEvent | Record<string, unknown>): void;
    private queueEvent;
    private flushQueued;
    private wsSend;
    private buildDelegation;
    private buildTools;
    private sessionStartEvent;
    private sendDelegationUpdate;
    private main;
    private runConnection;
    private handleEvent;
    private handleTranscript;
    private endSpeech;
    private handleResponseEvent;
    private handleResponseUsage;
    private maybeContinueResponse;
    private handleUsage;
    private emitError;
    /** Buffer microphone audio, mixing to mono and resampling to 24 kHz as needed. */
    pushAudio(frame: AudioFrame): void;
    private resetInputAudio;
    /** Add a standing rule retained in reconnect history. The service caps each append at 500 tokens. */
    appendInstructions(text: string, options?: {
        delegationId?: string | null;
    }): void;
    /** Add silent context retained in reconnect history. The service caps each append at 500 tokens. */
    appendThinking(text: string, options?: {
        delegationId?: string | null;
    }): void;
    /** Give the model text to paraphrase aloud, or answer a client delegation. Capped at 500 tokens by the service. */
    appendCommentary(text: string, options?: {
        delegationId?: string | null;
    }): void;
    private append;
    /** Replace microphone input with silence while the model continues speaking. */
    muteInput(): void;
    /** Restore microphone input. */
    unmuteInput(): void;
    /** Drain final provider usage, then close the transport and output stream. */
    protected closeConnection(): Promise<void>;
    /** Set the initial voice instructions. Changes after session.start are rejected. */
    _updateInstructions(instructions: string): Promise<void>;
    /** Update backend tools. Client delegation requires an empty tool context. */
    _updateTools(tools: llm.ToolContext): Promise<void>;
    /** Retain framework chat items for reconnects and send their context or tool results. */
    _appendItems(items: llm.ChatItem[]): Promise<void>;
    /** Prompt an immediate spoken reply to instructions or the newest typed user message. */
    _generateReply(instructions?: string): void;
    /** Update backend tool selection for this session and future reconnects. */
    _updateOptions(options: {
        toolChoice?: llm.ToolChoice | null;
    }): void;
}
//# sourceMappingURL=gpt_live_model.d.ts.map