import type { ConversationMetrics, RealtimeAnalyticsExport, RealtimeClientEvent, RealtimeConnectOptions, RealtimeConversation, RealtimeServerEvent, RealtimeSessionConfig, RealtimeSessionEvents, RealtimeSessionState, RealtimeToolResult } from './types.js'; /** * A realtime voice conversation: connects a transport, runs tools, handles barge-in, reconnects, * and keeps a record of everything said. */ export declare class RealtimeSession { private readonly config; /** This session's id. */ readonly id: string; /** Provider name, for records and telemetry. */ readonly provider: string; /** The realtime model. */ readonly model: string; private readonly emitter; private readonly clock; private readonly controller; private readonly transportUnsubscribers; private readonly rawEvents; private readonly pendingCalls; private readonly pendingConfirmations; private readonly seenToolCalls; private readonly interruptedResponses; private readonly outbox; private readonly toolExecutor; private connectPromise?; private reconnectPromise?; private eventQueue; private conversation; private sessionState; private providerSessionId?; private activeConnection?; private pendingConnectedEvent?; private hasConnected; private manualDisconnect; private connectionStartedAt; private speechEndedAt?; private turnStartedAt?; private toolResultAt?; private firstAudioRecorded; private activeResponseId?; private activeItemId?; private outputPlaybackStartedAt?; private sessionTimeout?; private audioLimitTriggered; private activeConnectionCounted; private connectionSpan?; constructor(config: RealtimeSessionConfig); /** The session's lifecycle state. */ get state(): RealtimeSessionState; /** The provider's session id once connected, otherwise this session's own id. */ get sessionId(): string; /** Subscribes to a session event. Returns a function that unsubscribes. */ on(event: Event, listener: (payload: RealtimeSessionEvents[Event]) => void): () => void; /** Subscribes to the next occurrence of a session event only. */ once(event: Event, listener: (payload: RealtimeSessionEvents[Event]) => void): () => void; /** A snapshot of the conversation record. */ getConversation(): RealtimeConversation; /** A snapshot of the conversation's metrics. */ getMetrics(): ConversationMetrics; /** Raw provider events retained so far. */ getRawEvents(): RealtimeServerEvent[]; /** Waits until all provider events already received by the session have been normalized. */ whenIdle(): Promise; /** * Exports the conversation: the record as JSON, the provider's events, a readable transcript, or * analytics without transcripts. */ export(format: 'json'): RealtimeConversation; export(format: 'openai-events'): RealtimeServerEvent[]; export(format: 'text'): string; export(format: 'analytics'): RealtimeAnalyticsExport; /** * Connects the transport, configures the provider session, and starts enforcing the session's * limits. */ connect(options?: RealtimeConnectOptions): Promise; /** Disconnects and stops reconnecting. */ disconnect(): Promise; /** Sends a raw provider event. */ sendEvent(event: RealtimeClientEvent): void; /** Sends a chunk of microphone audio. */ sendAudio(chunk: ArrayBuffer): void; /** Adds a user text message, and by default asks the model to answer it. */ sendText(text: string, createResponse?: boolean): void; /** * Commits buffered audio as a user turn, and by default asks the model to answer it. For * push-to-talk without server turn detection. */ commitAudio(createResponse?: boolean): void; /** Discards buffered audio that has not been committed. */ clearAudio(): void; /** Asks the model to respond now, optionally with response-level settings. */ createResponse(response?: Record): void; /** Changes provider session settings mid-conversation. */ updateSession(session: Record): void; /** * Stops the model speaking: cancels its response and truncates what was not heard, as configured. */ interrupt(reason?: 'barge_in' | 'manual'): void; private performInterruption; /** * Records when the first audio of a response actually started playing, which is the latency a * caller hears. Call it from your player. */ markAudioPlayed(at?: number): void; /** Answers a pending tool confirmation. Returns false when there was no such pending call. */ confirmTool(callId: string, approved: boolean): boolean; /** Runs a pending tool call yourself, for `toolExecution.mode: 'manual'`. */ executeTool(callId: string): Promise; /** Sends a tool result you produced yourself, for `toolExecution.mode: 'manual'`. */ submitToolResult(callId: string, result: unknown, error?: string): Promise; private bindTransport; private bindAbortSignal; private completeConnection; private handleRawEvent; private processProviderEvent; private applyPiiHook; private handleTransportAudio; private handleToolCall; private handleToolResult; private handleTransportDisconnected; private reconnect; private applyEvent; private finishDisconnect; private awaitConfirmation; private cleanupConfirmation; private resolveAllConfirmations; private sendProviderEvent; private flushOutbox; private assertConnected; private setState; private interruptionOptions; private effectiveSessionConfig; private withAudioDuration; private observeOutputBuffer; private finishOutputPlayback; private rememberInterruptedResponse; private recordInactiveConnection; private isLateInterruptedEvent; private retainRawEvent; private emitRaw; private emitNormalized; private emitConversation; private emitMetrics; private telemetryEvent; private telemetryAttributes; private recordMetricEvent; private runTelemetry; private updateUsage; private startSessionLimit; private enforceAudioLimit; } /** Creates a realtime session from its configuration. */ export declare function createRealtimeSession(config: RealtimeSessionConfig): RealtimeSession;