import type { RealtimeSession } from '../realtime/session.js'; import type { RealtimeAudioOptions } from '../realtime/types.js'; import type { TelephonyDtmfEvent, TelephonyOutboundAudioMessage, TelephonyStartEvent, TelephonyStopEvent } from '../types/telephony.js'; import type { TelephonyManager } from './manager.js'; /** * Audio settings that match what Twilio Media Streams actually send and accept: 8 kHz G.711 µ-law. * * Passing these to a realtime session lets the provider consume and produce telephony audio directly, * so the bridge forwards payloads without resampling or transcoding. Overriding them means the app * becomes responsible for converting every frame in both directions. */ export declare function twilioRealtimeAudioOptions(overrides?: RealtimeAudioOptions): RealtimeAudioOptions; /** * Audio settings that match what Telnyx media streams send and accept: 8 kHz G.711 µ-law, as * Twilio's do. The same settings as `twilioRealtimeAudioOptions()`, named for the provider. */ export declare const telnyxRealtimeAudioOptions: typeof twilioRealtimeAudioOptions; /** Options for `createTelephonyRealtimeBridge()`. */ export interface TelephonyRealtimeBridgeOptions { /** The realtime session driving the call. The bridge does not create it, so tools and instructions stay app-owned. */ session: RealtimeSession; /** Parses and formats the provider's media-stream messages. */ telephony: TelephonyManager; /** Registered provider name. Defaults to `twilio`. */ provider?: string; /** Sends one framed message back over the provider's media socket. Awaited, so ordering is preserved. */ send(message: TelephonyOutboundAudioMessage): void | Promise; /** Connect the session on the provider's `start` event. Defaults to true. */ autoConnect?: boolean; /** * On caller speech, discard audio already buffered at the provider and cancel the in-flight response. * Defaults to true. Without it the assistant keeps talking over the caller for as long as the * provider has audio queued. */ bargeIn?: boolean; /** Disconnect the session when the provider's stream stops. Defaults to true. */ autoDisconnect?: boolean; /** Called when the provider's stream starts. */ onStart?(event: TelephonyStartEvent): void | Promise; /** Called when the provider's stream stops. */ onStop?(event: TelephonyStopEvent): void | Promise; /** Called when the caller presses a key. */ onDtmf?(event: TelephonyDtmfEvent): void | Promise; /** Receives errors from message handling and outbound sends, which are never thrown at the socket. */ onError?(error: unknown): void; } /** * A phone call connected to a realtime voice session: caller audio goes to the model, and the * model's audio goes back to the caller. */ export interface TelephonyRealtimeBridge { /** Provider call identifier, available once the stream has started. */ readonly callId: string | undefined; /** Provider stream identifier, available once the stream has started. */ readonly streamId: string | undefined; /** Custom `` values from the provider's stream instruction. */ readonly parameters: Record; /** True once the stream has stopped or the bridge was closed. */ readonly closed: boolean; /** Feeds one raw media-socket message through the bridge. Safe to call before `start`. */ handleMessage(message: string | Record): Promise; /** Resolves once every queued outbound message has been sent. Send failures surface via `onError`. */ flush(): Promise; /** Detaches session listeners and, unless disabled, disconnects the session. Idempotent. */ close(): Promise; } /** * Connects a provider media stream to a realtime session: caller audio in, assistant audio out, * barge-in, playback marks, and stream lifecycle. * * The bridge owns only the audio path. Session configuration, tools, authorization, and any * post-call persistence stay with the application. */ export declare function createTelephonyRealtimeBridge(options: TelephonyRealtimeBridgeOptions): TelephonyRealtimeBridge;