/** * A single OpenAI Realtime event exchanged over the WebRTC data channel. * `type` is always present; `event_id` and `timestamp` are auto-populated * by the hook when missing. Any additional fields defined by the OpenAI * Realtime API are passed through unchanged. */ export type OpenAIEvent = { type: string; event_id?: string; timestamp?: string; [key: string]: any; }; /** * Return type of {@link useOpenAIWebRTC}. Exposes the live session state * and imperative controls for opening/closing a realtime voice session. * * @property isSessionActive Whether the peer connection is currently * `connected` — updates in real time. * @property startSession Opens a new peer connection to the OpenAI * Realtime API and attaches the configured audio * element. Resolves once the data channel is * open and safe to send on. * @property stopSession Stops microphone tracks, closes the peer * connection, and releases all resources. * @property sendTextMessage Queues a `conversation.item.create` + `response.create` * pair on the data channel, waiting for the * channel to open if necessary. */ export type UseOpenAIWebRTCReturn = { isSessionActive: boolean; startSession: (ephemeralKey: string, useMicrophone?: boolean) => Promise; stopSession: () => void; sendTextMessage: (text: string) => void; }; /** * React hook that manages a realtime voice session with the OpenAI Realtime * API over WebRTC. * * Usage flow: * 1. Render an `