o
    iv                     @   sN  d Z ddlZddlZddlmZmZmZmZmZm	Z	 ddl
mZmZmZ G dd deZG dd deZG d	d
 d
eZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd  d eZG d!d" d"eZG d#d$ d$eZG d%d& d&eZG d'd( d(eZG d)d* d*eZ G d+d, d,eZ!G d-d. d.eZ"G d/d0 d0eZ#G d1d2 d2e#Z$G d3d4 d4e#Z%G d5d6 d6e#Z&G d7d8 d8e#Z'G d9d: d:e#Z(G d;d< d<e#Z)G d=d> d>e#Z*G d?d@ d@e#Z+G dAdB dBe#Z,G dCdD dDe#Z-G dEdF dFe#Z.G dGdH dHe#Z/G dIdJ dJe#Z0G dKdL dLe#Z1G dMdN dNe#Z2G dOdP dPe#Z3G dQdR dRe#Z4G dSdT dTe#Z5G dUdV dVe#Z6G dWdX dXe#Z7G dYdZ dZe#Z8G d[d\ d\e#Z9G d]d^ d^e#Z:G d_d` d`e#Z;G dadb dbe#Z<G dcdd dde#Z=G dedf dfe#Z>G dgdh dhe#Z?G didj dje#Z@G dkdl dle#ZAG dmdn dneZBG dodp dpeZCG dqdr dreZDi dse@dte$due%dve&dwe>dxe?dye<dze=d{e'd|e(d}e)d~e*de+de,de-de.de/e0e1e2e3e4e5e6e7e8e9e:e;eAdZEdd ZFdS )zGEvent models and data structures for OpenAI Realtime API communication.    N)AnyDictListLiteralOptionalUnion)	BaseModel
ConfigDictFieldc                       sh   e Zd ZU dZdZeed< ee ed< ee ed< 			d	dee dee dee f fddZ  Z	S )
InputAudioTranscriptionz/Configuration for audio transcription settings.gpt-4o-transcribemodellanguagepromptNc                    s   t  j|||d dS )a	  Initialize InputAudioTranscription.

        Args:
            model: Transcription model to use (e.g., "gpt-4o-transcribe", "whisper-1").
            language: Optional language code for transcription.
            prompt: Optional transcription hint text.
        )r   r   r   N)super__init__)selfr   r   r   	__class__ `/home/ubuntu/.local/lib/python3.10/site-packages/pipecat/services/openai_realtime_beta/events.pyr      s   z InputAudioTranscription.__init__)r   NN)
__name__
__module____qualname____doc__r   str__annotations__r   r   __classcell__r   r   r   r   r      s   
 r   c                   @   sV   e Zd ZU dZdZeed  ed< dZee	 ed< dZ
ee ed< dZee ed	< d
S )TurnDetectiona  Server-side voice activity detection configuration.

    Parameters:
        type: Detection type, must be "server_vad".
        threshold: Voice activity detection threshold (0.0-1.0). Defaults to 0.5.
        prefix_padding_ms: Padding before speech starts in milliseconds. Defaults to 300.
        silence_duration_ms: Silence duration to detect speech end in milliseconds. Defaults to 800.
    
server_vadtypeg      ?	thresholdi,  prefix_padding_msi   silence_duration_msN)r   r   r   r   r    r   r   r   r!   floatr"   intr#   r   r   r   r   r   +   s   
 	r   c                   @   sZ   e Zd ZU dZdZeed  ed< dZeed  ed< dZ	ee
 ed< dZee
 ed< dS )	SemanticTurnDetectiona  Semantic-based turn detection configuration.

    Parameters:
        type: Detection type, must be "semantic_vad".
        eagerness: Turn detection eagerness level. Can be "low", "medium", "high", or "auto".
        create_response: Whether to automatically create responses on turn detection.
        interrupt_response: Whether to interrupt ongoing responses on turn detection.
    semantic_vadr    N)lowmediumhighauto	eagernesscreate_responseinterrupt_response)r   r   r   r   r    r   r   r   r,   r-   boolr.   r   r   r   r   r&   ;   s   
 	r&   c                   @   s"   e Zd ZU dZeed  ed< dS )InputAudioNoiseReductionzInput audio noise reduction configuration.

    Parameters:
        type: Noise reduction type for different microphone scenarios.
    )
near_field	far_fieldr    N)r   r   r   r   r   r   r   r   r   r   r   r0   K      
 r0   c                   @   s  e Zd ZU dZdZeeed   ed< dZ	ee
 ed< dZee
 ed< dZeed  ed< dZeed  ed	< dZee ed
< dZee ed< eddZeeeeef  ed< dZeee  ed< dZeed  ed< dZee ed< dZeeeed f  ed< dS )SessionPropertiesa  Configuration properties for an OpenAI Realtime session.

    Parameters:
        modalities: Communication modalities to enable (text, audio, or both).
        instructions: System instructions for the assistant.
        voice: Voice ID for text-to-speech output.
        input_audio_format: Format for input audio data.
        output_audio_format: Format for output audio data.
        input_audio_transcription: Configuration for input audio transcription.
        input_audio_noise_reduction: Configuration for input audio noise reduction.
        turn_detection: Turn detection configuration or False to disable.
        tools: Available function tools for the assistant.
        tool_choice: Tool usage strategy ("auto", "none", or "required").
        temperature: Sampling temperature for response generation.
        max_response_output_tokens: Maximum tokens in response or "inf" for unlimited.
    Ntextaudio
modalitiesinstructionsvoicepcm16	g711_ulaw	g711_alawinput_audio_formatoutput_audio_formatinput_audio_transcriptioninput_audio_noise_reduction)defaultturn_detectiontoolsr+   nonerequiredtool_choicetemperatureinfmax_response_output_tokens)r   r   r   r   r8   r   r   r   r   r9   r   r:   r?   r@   rA   r   rB   r0   r
   rD   r   r   r&   r/   rE   r   rI   rJ   r$   rL   r%   r   r   r   r   r4   U   s    
  r4   c                   @   sN   e Zd ZU dZed ed< dZee ed< dZ	ee ed< dZ
ee ed< dS )ItemContenta   Content within a conversation item.

    Parameters:
        type: Content type (text, audio, input_text, or input_audio).
        text: Text content for text-based items.
        audio: Base64-encoded audio data for audio items.
        transcript: Transcribed text for audio items.
    )r6   r7   
input_textinput_audior    Nr6   r7   
transcript)r   r   r   r   r   r   r6   r   r   r7   rP   r   r   r   r   rM   }   s   
 	rM   c                   @   s   e Zd ZU dZedd dZeed< dZe	e
d  ed< e
d	 ed
< dZe	e
d  ed< dZe	e
d  ed< dZe	ee  ed< dZe	e ed< dZe	e ed< dZe	e ed< dZe	e ed< dS )ConversationItema  A conversation item in the realtime session.

    Parameters:
        id: Unique identifier for the item, auto-generated if not provided.
        object: Object type identifier for the realtime API.
        type: Item type (message, function_call, or function_call_output).
        status: Current status of the item.
        role: Speaker role for message items (user, assistant, or system).
        content: Content list for message items.
        call_id: Function call identifier for function_call items.
        name: Function name for function_call items.
        arguments: Function arguments as JSON string for function_call items.
        output: Function output as JSON string for function_call_output items.
    c                   C   s   t t jS N)r   uuiduuid4hexr   r   r   r   <lambda>   s    zConversationItem.<lambda>default_factoryidNzrealtime.itemobject)messagefunction_callfunction_call_outputr    )	completedin_progress
incompletestatus)user	assistantsystemrolecontentcall_idname	argumentsoutput)r   r   r   r   r
   rY   r   r   rZ   r   r   ra   re   rf   r   rM   rg   rh   ri   rj   r   r   r   r   rQ      s   
 rQ   c                   @   s&   e Zd ZU dZeed< ed ed< dS )RealtimeConversationzA realtime conversation session.

    Parameters:
        id: Unique identifier for the conversation.
        object: Object type identifier, always "realtime.conversation".
    rY   zrealtime.conversationrZ   N)r   r   r   r   r   r   r   r   r   r   r   rk      s   
 rk   c                   @   s   e Zd ZU dZddgZeeed   ed< dZ	ee
 ed< dZee
 ed< dZeed	  ed
< eedZeee  ed< dZeed  ed< dZee ed< dZeeeed f  ed< dS )ResponsePropertiesaF  Properties for configuring assistant responses.

    Parameters:
        modalities: Output modalities for the response. Defaults to ["audio", "text"].
        instructions: Specific instructions for this response.
        voice: Voice ID for text-to-speech in this response.
        output_audio_format: Audio format for this response.
        tools: Available tools for this response.
        tool_choice: Tool usage strategy for this response.
        temperature: Sampling temperature for this response.
        max_response_output_tokens: Maximum tokens for this response.
    r7   r6   r5   r8   Nr9   r:   r;   r@   rW   rE   rF   rI   rJ   rK   rL   )r   r   r   r   r8   r   r   r   r   r9   r   r:   r@   r
   listrE   r   rI   rJ   r$   rL   r   r%   r   r   r   r   rl      s   
  rl   c                   @   sR   e Zd ZU dZeed< dZee ed< eed< dZee ed< dZ	ee ed< dS )	RealtimeErrora>  Error information from the realtime API.

    Parameters:
        type: Error type identifier.
        code: Specific error code.
        message: Human-readable error message.
        param: Parameter name that caused the error, if applicable.
        event_id: Event ID associated with the error, if applicable.
    r     coder[   Nparamevent_id)
r   r   r   r   r   r   rp   r   rq   rr   r   r   r   r   rn      s   
 
rn   c                   @   s(   e Zd ZU dZedd dZeed< dS )ClientEventzBase class for client events sent to the realtime API.

    Parameters:
        event_id: Unique identifier for the event, auto-generated if not provided.
    c                   C   s   t t S rR   )r   rS   rT   r   r   r   r   rV      s    zClientEvent.<lambda>rW   rr   N)r   r   r   r   r
   rr   r   r   r   r   r   r   rs      s   
 rs   c                       sH   e Zd ZU dZdZed ed< eed< dee	e
f f fddZ  ZS )SessionUpdateEventzEvent to update session properties.

    Parameters:
        type: Event type, always "session.update".
        session: Updated session properties.
    zsession.updater    sessionreturnc                    s>   t  j|i |}d|d v r|d d du rd|d d< |S )a`  Serialize the event to a dictionary.

        Handles special serialization for turn_detection where False becomes null.

        Args:
            *args: Positional arguments passed to parent model_dump.
            **kwargs: Keyword arguments passed to parent model_dump.

        Returns:
            Dictionary representation of the event.
        rD   ru   FN)r   
model_dump)r   argskwargsdumpr   r   r   rw      s
   zSessionUpdateEvent.model_dump)r   r   r   r   r    r   r   r4   r   r   r   rw   r   r   r   r   r   rt      s
   
 "rt   c                   @   *   e Zd ZU dZdZed ed< eed< dS )InputAudioBufferAppendEventzEvent to append audio data to the input buffer.

    Parameters:
        type: Event type, always "input_audio_buffer.append".
        audio: Base64-encoded audio data to append.
    zinput_audio_buffer.appendr    r7   Nr   r   r   r   r    r   r   r   r   r   r   r   r|        
 r|   c                   @   "   e Zd ZU dZdZed ed< dS )InputAudioBufferCommitEventzEvent to commit the current input audio buffer.

    Parameters:
        type: Event type, always "input_audio_buffer.commit".
    zinput_audio_buffer.commitr    Nr   r   r   r   r    r   r   r   r   r   r   r      r3   r   c                   @   r   )InputAudioBufferClearEventzyEvent to clear the input audio buffer.

    Parameters:
        type: Event type, always "input_audio_buffer.clear".
    zinput_audio_buffer.clearr    Nr   r   r   r   r   r   *  r3   r   c                   @   s:   e Zd ZU dZdZed ed< dZee	 ed< e
ed< dS )ConversationItemCreateEventzEvent to create a new conversation item.

    Parameters:
        type: Event type, always "conversation.item.create".
        previous_item_id: ID of the item to insert after, if any.
        item: The conversation item to create.
    zconversation.item.creater    Nprevious_item_iditem)r   r   r   r   r    r   r   r   r   r   rQ   r   r   r   r   r   4  s
   
 r   c                   @   s:   e Zd ZU dZdZed ed< eed< eed< eed< dS )ConversationItemTruncateEventaI  Event to truncate a conversation item's audio content.

    Parameters:
        type: Event type, always "conversation.item.truncate".
        item_id: ID of the item to truncate.
        content_index: Index of the content to truncate within the item.
        audio_end_ms: End time in milliseconds for the truncated audio.
    zconversation.item.truncater    item_idcontent_indexaudio_end_msN)	r   r   r   r   r    r   r   r   r%   r   r   r   r   r   B  s   
 	r   c                   @   r{   )ConversationItemDeleteEventzEvent to delete a conversation item.

    Parameters:
        type: Event type, always "conversation.item.delete".
        item_id: ID of the item to delete.
    zconversation.item.deleter    r   Nr}   r   r   r   r   r   R  r~   r   c                   @   r{   )ConversationItemRetrieveEventzEvent to retrieve a conversation item by ID.

    Parameters:
        type: Event type, always "conversation.item.retrieve".
        item_id: ID of the item to retrieve.
    zconversation.item.retriever    r   Nr}   r   r   r   r   r   ^  r~   r   c                   @   s2   e Zd ZU dZdZed ed< dZee	 ed< dS )ResponseCreateEventzEvent to create a new assistant response.

    Parameters:
        type: Event type, always "response.create".
        response: Optional response configuration properties.
    zresponse.creater    Nresponse)
r   r   r   r   r    r   r   r   r   rl   r   r   r   r   r   j  s   
 r   c                   @   r   )ResponseCancelEventzyEvent to cancel the current assistant response.

    Parameters:
        type: Event type, always "response.cancel".
    zresponse.cancelr    Nr   r   r   r   r   r   v  r3   r   c                   @   s,   e Zd ZU dZeddZeed< eed< dS )ServerEventzBase class for server events received from the realtime API.

    Parameters:
        event_id: Unique identifier for the event.
        type: Type of the server event.
    T)arbitrary_types_allowedrr   r    N)r   r   r   r   r	   model_configr   r   r   r   r   r   r     s
   
 
r   c                   @   &   e Zd ZU dZed ed< eed< dS )SessionCreatedEventzEvent indicating a session has been created.

    Parameters:
        type: Event type, always "session.created".
        session: The created session properties.
    session.createdr    ru   Nr   r   r   r   r   r   r4   r   r   r   r   r        
 r   c                   @   r   )SessionUpdatedEventzEvent indicating a session has been updated.

    Parameters:
        type: Event type, always "session.updated".
        session: The updated session properties.
    session.updatedr    ru   Nr   r   r   r   r   r     r   r   c                   @   r   )ConversationCreatedzEvent indicating a conversation has been created.

    Parameters:
        type: Event type, always "conversation.created".
        conversation: The created conversation.
    conversation.createdr    conversationN)r   r   r   r   r   r   rk   r   r   r   r   r     r   r   c                   @   s6   e Zd ZU dZed ed< dZee ed< e	ed< dS )ConversationItemCreatedzEvent indicating a conversation item has been created.

    Parameters:
        type: Event type, always "conversation.item.created".
        previous_item_id: ID of the previous item, if any.
        item: The created conversation item.
    conversation.item.createdr    Nr   r   )
r   r   r   r   r   r   r   r   r   rQ   r   r   r   r   r     
   
 r   c                   @   6   e Zd ZU dZed ed< eed< eed< eed< dS ),ConversationItemInputAudioTranscriptionDeltaaO  Event containing incremental input audio transcription.

    Parameters:
        type: Event type, always "conversation.item.input_audio_transcription.delta".
        item_id: ID of the conversation item being transcribed.
        content_index: Index of the content within the item.
        delta: Incremental transcription text.
    1conversation.item.input_audio_transcription.deltar    r   r   deltaNr   r   r   r   r   r   r   r%   r   r   r   r   r        
 	r   c                   @   r   )0ConversationItemInputAudioTranscriptionCompletedaX  Event indicating input audio transcription is complete.

    Parameters:
        type: Event type, always "conversation.item.input_audio_transcription.completed".
        item_id: ID of the conversation item that was transcribed.
        content_index: Index of the content within the item.
        transcript: Complete transcription text.
    5conversation.item.input_audio_transcription.completedr    r   r   rP   Nr   r   r   r   r   r     r   r   c                   @   6   e Zd ZU dZed ed< eed< eed< eed< dS )-ConversationItemInputAudioTranscriptionFaileda`  Event indicating input audio transcription failed.

    Parameters:
        type: Event type, always "conversation.item.input_audio_transcription.failed".
        item_id: ID of the conversation item that failed transcription.
        content_index: Index of the content within the item.
        error: Error details for the transcription failure.
    2conversation.item.input_audio_transcription.failedr    r   r   errorN)	r   r   r   r   r   r   r   r%   rn   r   r   r   r   r     r   r   c                   @   s6   e Zd ZU dZed ed< eed< eed< eed< dS )ConversationItemTruncatedaK  Event indicating a conversation item has been truncated.

    Parameters:
        type: Event type, always "conversation.item.truncated".
        item_id: ID of the truncated conversation item.
        content_index: Index of the content within the item.
        audio_end_ms: End time in milliseconds for the truncated audio.
    conversation.item.truncatedr    r   r   r   Nr   r   r   r   r   r     r   r   c                   @   r   )ConversationItemDeletedzEvent indicating a conversation item has been deleted.

    Parameters:
        type: Event type, always "conversation.item.deleted".
        item_id: ID of the deleted conversation item.
    conversation.item.deletedr    r   N)r   r   r   r   r   r   r   r   r   r   r   r     r   r   c                   @   r   )ConversationItemRetrievedzEvent containing a retrieved conversation item.

    Parameters:
        type: Event type, always "conversation.item.retrieved".
        item: The retrieved conversation item.
    conversation.item.retrievedr    r   N)r   r   r   r   r   r   rQ   r   r   r   r   r     r   r   c                   @   &   e Zd ZU dZed ed< ded< dS )ResponseCreatedzEvent indicating an assistant response has been created.

    Parameters:
        type: Event type, always "response.created".
        response: The created response object.
    response.createdr    Responser   Nr   r   r   r   r   r   r   r   r   r   r     r   r   c                   @   r   )ResponseDonezEvent indicating an assistant response is complete.

    Parameters:
        type: Event type, always "response.done".
        response: The completed response object.
    response.doner    r   r   Nr   r   r   r   r   r   )  r   r   c                   @   r   )ResponseOutputItemAddeda  Event indicating an output item has been added to a response.

    Parameters:
        type: Event type, always "response.output_item.added".
        response_id: ID of the response.
        output_index: Index of the output item.
        item: The added conversation item.
    response.output_item.addedr    response_idoutput_indexr   N	r   r   r   r   r   r   r   r%   rQ   r   r   r   r   r   5  r   r   c                   @   r   )ResponseOutputItemDonea  Event indicating an output item is complete.

    Parameters:
        type: Event type, always "response.output_item.done".
        response_id: ID of the response.
        output_index: Index of the output item.
        item: The completed conversation item.
    response.output_item.doner    r   r   r   Nr   r   r   r   r   r   E  r   r   c                   @   F   e Zd ZU dZed ed< eed< eed< eed< eed< eed< d	S )
ResponseContentPartAddedar  Event indicating a content part has been added to a response.

    Parameters:
        type: Event type, always "response.content_part.added".
        response_id: ID of the response.
        item_id: ID of the conversation item.
        output_index: Index of the output item.
        content_index: Index of the content part.
        part: The added content part.
    response.content_part.addedr    r   r   r   r   partN	r   r   r   r   r   r   r   r%   rM   r   r   r   r   r   U     
 r   c                   @   r   )
ResponseContentPartDonead  Event indicating a content part is complete.

    Parameters:
        type: Event type, always "response.content_part.done".
        response_id: ID of the response.
        item_id: ID of the conversation item.
        output_index: Index of the output item.
        content_index: Index of the content part.
        part: The completed content part.
    response.content_part.doner    r   r   r   r   r   Nr   r   r   r   r   r   i  r   r   c                   @   F   e Zd ZU dZed ed< eed< eed< eed< eed< eed< d	S )
ResponseTextDeltaab  Event containing incremental text from a response.

    Parameters:
        type: Event type, always "response.text.delta".
        response_id: ID of the response.
        item_id: ID of the conversation item.
        output_index: Index of the output item.
        content_index: Index of the content part.
        delta: Incremental text content.
    response.text.deltar    r   r   r   r   r   Nr   r   r   r   r   r   }  r   r   c                   @   r   )
ResponseTextDoneaU  Event indicating text content is complete.

    Parameters:
        type: Event type, always "response.text.done".
        response_id: ID of the response.
        item_id: ID of the conversation item.
        output_index: Index of the output item.
        content_index: Index of the content part.
        text: Complete text content.
    response.text.doner    r   r   r   r   r6   Nr   r   r   r   r   r     r   r   c                   @   r   )
ResponseAudioTranscriptDeltaa}  Event containing incremental audio transcript from a response.

    Parameters:
        type: Event type, always "response.audio_transcript.delta".
        response_id: ID of the response.
        item_id: ID of the conversation item.
        output_index: Index of the output item.
        content_index: Index of the content part.
        delta: Incremental transcript text.
    response.audio_transcript.deltar    r   r   r   r   r   Nr   r   r   r   r   r     r   r   c                   @   r   )
ResponseAudioTranscriptDonean  Event indicating audio transcript is complete.

    Parameters:
        type: Event type, always "response.audio_transcript.done".
        response_id: ID of the response.
        item_id: ID of the conversation item.
        output_index: Index of the output item.
        content_index: Index of the content part.
        transcript: Complete transcript text.
    response.audio_transcript.doner    r   r   r   r   rP   Nr   r   r   r   r   r     r   r   c                   @   r   )
ResponseAudioDeltaav  Event containing incremental audio data from a response.

    Parameters:
        type: Event type, always "response.audio.delta".
        response_id: ID of the response.
        item_id: ID of the conversation item.
        output_index: Index of the output item.
        content_index: Index of the content part.
        delta: Base64-encoded incremental audio data.
    response.audio.deltar    r   r   r   r   r   Nr   r   r   r   r   r     r   r   c                   @   s>   e Zd ZU dZed ed< eed< eed< eed< eed< dS )	ResponseAudioDonea2  Event indicating audio content is complete.

    Parameters:
        type: Event type, always "response.audio.done".
        response_id: ID of the response.
        item_id: ID of the conversation item.
        output_index: Index of the output item.
        content_index: Index of the content part.
    response.audio.doner    r   r   r   r   Nr   r   r   r   r   r     s   
 
r   c                   @   F   e Zd ZU dZed ed< eed< eed< eed< eed< eed< d	S )
"ResponseFunctionCallArgumentsDeltaa~  Event containing incremental function call arguments.

    Parameters:
        type: Event type, always "response.function_call_arguments.delta".
        response_id: ID of the response.
        item_id: ID of the conversation item.
        output_index: Index of the output item.
        call_id: ID of the function call.
        delta: Incremental function arguments as JSON.
    &response.function_call_arguments.deltar    r   r   r   rg   r   Nr   r   r   r   r   r     r   r   c                   @   r   )
!ResponseFunctionCallArgumentsDonea  Event indicating function call arguments are complete.

    Parameters:
        type: Event type, always "response.function_call_arguments.done".
        response_id: ID of the response.
        item_id: ID of the conversation item.
        output_index: Index of the output item.
        call_id: ID of the function call.
        arguments: Complete function arguments as JSON string.
    %response.function_call_arguments.doner    r   r   r   rg   ri   Nr   r   r   r   r   r     r   r   c                   @   .   e Zd ZU dZed ed< eed< eed< dS )InputAudioBufferSpeechStarteda  Event indicating speech has started in the input audio buffer.

    Parameters:
        type: Event type, always "input_audio_buffer.speech_started".
        audio_start_ms: Start time of speech in milliseconds.
        item_id: ID of the associated conversation item.
    !input_audio_buffer.speech_startedr    audio_start_msr   Nr   r   r   r   r   r   r%   r   r   r   r   r   r     
   
 r   c                   @   r   )InputAudioBufferSpeechStoppeda  Event indicating speech has stopped in the input audio buffer.

    Parameters:
        type: Event type, always "input_audio_buffer.speech_stopped".
        audio_end_ms: End time of speech in milliseconds.
        item_id: ID of the associated conversation item.
    !input_audio_buffer.speech_stoppedr    r   r   Nr   r   r   r   r   r   )  r   r   c                   @   s6   e Zd ZU dZed ed< dZee ed< eed< dS )InputAudioBufferCommitteda  Event indicating the input audio buffer has been committed.

    Parameters:
        type: Event type, always "input_audio_buffer.committed".
        previous_item_id: ID of the previous item, if any.
        item_id: ID of the committed conversation item.
    input_audio_buffer.committedr    Nr   r   )	r   r   r   r   r   r   r   r   r   r   r   r   r   r   7  r   r   c                   @   s   e Zd ZU dZed ed< dS )InputAudioBufferClearedzEvent indicating the input audio buffer has been cleared.

    Parameters:
        type: Event type, always "input_audio_buffer.cleared".
    input_audio_buffer.clearedr    Nr   r   r   r   r   r   E  s   
 r   c                   @   s&   e Zd ZU dZed ed< eed< dS )
ErrorEventzEvent indicating an error occurred.

    Parameters:
        type: Event type, always "error".
        error: Error details.
    r   r    N)r   r   r   r   r   r   rn   r   r   r   r   r   O  r   r   c                   @   s2   e Zd ZU dZed ed< eeee	f  ed< dS )RateLimitsUpdatedzEvent indicating rate limits have been updated.

    Parameters:
        type: Event type, always "rate_limits.updated".
        rate_limits: List of rate limit information.
    rate_limits.updatedr    rate_limitsN)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   [  s   
 r   c                   @   sL   e Zd ZU dZeddZdZee e	d< dZ
ee e	d< dZee e	d< dS )	TokenDetailszDetailed token usage information.

    Parameters:
        cached_tokens: Number of cached tokens used. Defaults to 0.
        text_tokens: Number of text tokens used. Defaults to 0.
        audio_tokens: Number of audio tokens used. Defaults to 0.
    allow)extrar   cached_tokenstext_tokensaudio_tokensN)r   r   r   r   r	   r   r   r   r%   r   r   r   r   r   r   r   r   g  s   
 
r   c                   @   s:   e Zd ZU dZeed< eed< eed< eed< eed< dS )Usageae  Token usage statistics for a response.

    Parameters:
        total_tokens: Total number of tokens used.
        input_tokens: Number of input tokens used.
        output_tokens: Number of output tokens used.
        input_token_details: Detailed breakdown of input token usage.
        output_token_details: Detailed breakdown of output token usage.
    total_tokensinput_tokensoutput_tokensinput_token_detailsoutput_token_detailsN)r   r   r   r   r%   r   r   r   r   r   r   r   w  s   
 
r   c                   @   sV   e Zd ZU dZeed< ed ed< ed ed< eed< ee	 ed< d	Z
ee ed
< d	S )r   ax  A complete assistant response.

    Parameters:
        id: Unique identifier for the response.
        object: Object type, always "realtime.response".
        status: Current status of the response.
        status_details: Additional status information.
        output: List of conversation items in the response.
        usage: Token usage statistics for the response.
    rY   zrealtime.responserZ   )r^   r_   r`   	cancelledfailedra   status_detailsrj   Nusage)r   r   r   r   r   r   r   r   r   rQ   r   r   r   r   r   r   r   r     s   
 r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   c              
   C   sd   zt | }|d }|tvrtd| t| |W S  ty1 } z	t| d|  d}~ww )a  Parse a server event from JSON string.

    Args:
        str: JSON string containing the server event.

    Returns:
        Parsed server event object of the appropriate type.

    Raises:
        Exception: If the event type is unimplemented or parsing fails.
    r    z!Unimplemented server event type: z 

N)jsonloads_server_event_types	Exceptionmodel_validate)r   event
event_typeer   r   r   parse_server_event  s   
r  )Gr   r   rS   typingr   r   r   r   r   r   pydanticr   r	   r
   r   r   r&   r0   r4   rM   rQ   rk   rl   rn   rs   rt   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   <module>   s    
(
!


	
"