
    qiv                        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e      Z G d de      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d d e      Z G d! d"e      Z G d# d$e      Z G d% d&e      Z G d' d(e      Z G d) d*e      Z  G d+ d,e      Z! G d- d.e      Z" G d/ d0e      Z# G d1 d2e#      Z$ G d3 d4e#      Z% G d5 d6e#      Z& G d7 d8e#      Z' G d9 d:e#      Z( G d; d<e#      Z) G d= d>e#      Z* G d? d@e#      Z+ G dA dBe#      Z, G dC dDe#      Z- G dE dFe#      Z. G dG dHe#      Z/ G dI dJe#      Z0 G dK dLe#      Z1 G dM dNe#      Z2 G dO dPe#      Z3 G dQ dRe#      Z4 G dS dTe#      Z5 G dU dVe#      Z6 G dW dXe#      Z7 G dY dZe#      Z8 G d[ d\e#      Z9 G d] d^e#      Z: G d_ d`e#      Z; G da dbe#      Z< G dc dde#      Z= G de dfe#      Z> G dg dhe#      Z? G di dje#      Z@ G dk dle#      ZA G dm dne      ZB G do dpe      ZC G dq 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ZEd ZFy)zGEvent models and data structures for OpenAI Realtime API communication.    N)AnyDictListLiteralOptionalUnion)	BaseModel
ConfigDictFieldc                   z     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Z xZ	S )InputAudioTranscriptionz/Configuration for audio transcription settings.gpt-4o-transcribemodellanguagepromptc                 *    t         |   |||       y)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__s       ^/opt/pipecat/venv/lib/python3.12/site-packages/pipecat/services/openai_realtime_beta/events.pyr   z InputAudioTranscription.__init__   s     	uxG    )r   NN)
__name__
__module____qualname____doc__r   str__annotations__r   r   __classcell__r   s   @r   r   r      sf    9$E3$smSM  3"& $	H}H 3-H 	H Hr   r   c                   h    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	<   y
)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"   +   sI     -9D(7<(
)8!$Ix$'*x}*),#,r   r"   c                   n    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<   y)	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   r2   r3   boolr4   r*   r   r   r,   r,   ;   sO     /=D(7>*
+<DHIx ?@AH&*OXd^*)--r   r,   c                   (    e Zd ZU dZeed      ed<   y)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   r7   r7   K   s     745
66r   r7   c                   P   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      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<   y)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r1   nonerequiredtool_choicetemperatureinfmax_response_output_tokens)r   r   r   r   r?   r   r   r   r   r@   r   rA   rF   rG   rH   r   rI   r7   r   rK   r   r"   r,   r5   rL   r   rP   rQ   r(   rS   r)   r*   r   r   r;   r;   U   s
   " <@Jgo678?"&L(3-&E8C=OS)J!KLSPT'*K"LMTCGx(?@GFJ*B!CJRWSNHU=2G#MNO  #'E8DJ&AEK'"<=>E#'K%'GKsGEN/B)C DKr   r;   c                   ^    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<   y)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.
    )r=   r>   
input_textinput_audior$   Nr=   r>   
transcript)r   r   r   r   r   r   r=   r   r   r>   rX   r*   r   r   rU   rU   }   s?     >
??D(3-E8C= $J$r   rU   c                       e Zd ZU dZ e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<   y)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                  P    t        t        j                         j                        S N)r   uuiduuid4hexr*   r   r   <lambda>zConversationItem.<lambda>   s    C

0@0@,A r   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   rc   r   r   rd   r   r   rk   ro   rp   r   rU   rq   rr   rs   rt   r*   r   r   rZ   rZ      s     $ABBB15FHW_-.5
D
EEJNFHWEFGN=AD(789
:A+/GXd;'(/!GXc]!D(3-#Ix}# FHSM r   rZ   c                   ,    e Zd ZU dZeed<   ed   ed<   y)RealtimeConversationzA realtime conversation session.

    Parameters:
        id: Unique identifier for the conversation.
        object: Object type identifier, always "realtime.conversation".
    rc   zrealtime.conversationrd   N)r   r   r   r   r   r   r   r*   r   r   rv   rv      s     	G+,,r   rv   c                       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      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<   y)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.
    r>   r=   r<   r?   Nr@   rA   rB   rG   ra   rL   rM   rP   rQ   rR   rS   )r   r   r   r   r?   r   r   r   r   r@   r   rA   rG   r   listrL   r   rP   rQ   r(   rS   r   r)   r*   r   r   rx   rx      s     =DV;LJgo678L"&L(3-&E8C=PT'*K"LMT"'"=E8DJ=AEK'"<=>E#'K%'GKsGEN/B)C DKr   rx   c                   b    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<   y)	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$    codere   Nparamevent_id)
r   r   r   r   r   r   r}   r   r~   r   r*   r   r   r{   r{      s=     ID(3-LE8C="Hhsm"r   r{   c                   0    e Zd ZU dZ ed       Zeed<   y)ClientEventzBase class for client events sent to the realtime API.

    Parameters:
        event_id: Unique identifier for the event, auto-generated if not provided.
    c                  <    t        t        j                               S r\   )r   r]   r^   r*   r   r   r`   zClientEvent.<lambda>   s    #djjl2C r   ra   r   N)r   r   r   r   r   r   r   r   r*   r   r   r   r      s     *CDHcDr   r   c                   R     e Zd ZU dZdZed   ed<   eed<   dee	e
f   f fdZ xZS )SessionUpdateEventzEvent to update session properties.

    Parameters:
        type: Event type, always "session.update".
        session: Updated session properties.
    zsession.updater$   sessionreturnc                 X    t        |   |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.
        rK   r   FN)r   
model_dump)r   argskwargsdumpr   s       r   r   zSessionUpdateEvent.model_dump   sM     w!4262 tI.I/0E948Y 01r   )r   r   r   r   r$   r   r   r;   r   r   r   r   r   r    s   @r   r   r      s9     '7D'"
#6T#s(^  r   r   c                   0    e Zd ZU dZdZed   ed<   eed<   y)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$   r>   Nr   r   r   r   r$   r   r   r   r*   r   r   r   r     s     2MD'-
.LJr   r   c                   &    e Zd ZU dZdZed   ed<   y)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      s     2MD'-
.Lr   r   c                   &    e Zd ZU dZdZed   ed<   y)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   *  s     1KD',
-Jr   r   c                   D    e Zd ZU dZdZed   ed<   dZee	   ed<   e
ed<   y)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   rZ   r*   r   r   r   r   4  s/     1KD',
-J&*hsm*
r   r   c                   D    e Zd ZU dZdZed   ed<   eed<   eed<   eed<   y)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+     3OD'.
/NLr   r   c                   0    e Zd ZU dZdZed   ed<   eed<   y)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  s     1KD',
-JLr   r   c                   0    e Zd ZU dZdZed   ed<   eed<   y)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   ^  s     3OD'.
/NLr   r   c                   :    e Zd ZU dZdZed   ed<   dZee	   ed<   y)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   rx   r*   r   r   r   r   j  s)     (9D'#
$8-1Hh)*1r   r   c                   &    e Zd ZU dZdZed   ed<   y)ResponseCancelEventzyEvent to cancel the current assistant response.

    Parameters:
        type: Event type, always "response.cancel".
    zresponse.cancelr$   Nr   r*   r   r   r   r   v  s     (9D'#
$8r   r   c                   8    e Zd ZU dZ ed      Zeed<   eed<   y)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_allowedr   r$   N)r   r   r   r   r
   model_configr   r   r*   r   r   r   r     s     d;LM
Ir   r   c                   ,    e Zd ZU dZed   ed<   eed<   y)SessionCreatedEventzEvent indicating a session has been created.

    Parameters:
        type: Event type, always "session.created".
        session: The created session properties.
    session.createdr$   r   Nr   r   r   r   r   r   r;   r*   r   r   r   r          #
$$r   r   c                   ,    e Zd ZU dZed   ed<   eed<   y)SessionUpdatedEventzEvent indicating a session has been updated.

    Parameters:
        type: Event type, always "session.updated".
        session: The updated session properties.
    session.updatedr$   r   Nr   r*   r   r   r   r     r   r   r   c                   ,    e Zd ZU dZed   ed<   eed<   y)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   rv   r*   r   r   r   r     s     (
))&&r   r   c                   @    e Zd ZU dZed   ed<   dZee   ed<   e	ed<   y)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   rZ   r*   r   r   r   r     s*     -
..&*hsm*
r   r   c                   @    e Zd ZU dZed   ed<   eed<   eed<   eed<   y),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     s%     E
FFLJr   r   c                   @    e Zd ZU dZed   ed<   eed<   eed<   eed<   y)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   rX   Nr   r*   r   r   r   r     s%     I
JJLOr   r   c                   @    e Zd ZU dZed   ed<   eed<   eed<   eed<   y)-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)   r{   r*   r   r   r   r     s&     F
GGLr   r   c                   @    e Zd ZU dZed   ed<   eed<   eed<   eed<   y)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     s&     /
00Lr   r   c                   ,    e Zd ZU dZed   ed<   eed<   y)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     s     -
..Lr   r   c                   ,    e Zd ZU dZed   ed<   eed<   y)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   rZ   r*   r   r   r   r     s     /
00
r   r   c                   ,    e Zd ZU dZed   ed<   ded<   y)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     s     $
%%r   r   c                   ,    e Zd ZU dZed   ed<   ded<   y)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   )  s     /
""r   r   c                   @    e Zd ZU dZed   ed<   eed<   eed<   eed<   y)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)   rZ   r*   r   r   r   r   5  s'     .
//
r   r   c                   @    e Zd ZU dZed   ed<   eed<   eed<   eed<   y)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  s'     -
..
r   r   c                   T    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<   y	)
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)   rU   r*   r   r   r   r   U  s2    	 /
00L
r   r   c                   T    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<   y	)
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  s2    	 .
//L
r   r   c                   T    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<   y	)
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   }  s1    	 '
((LJr   r   c                   T    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<   y	)
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   r=   Nr   r*   r   r   r   r     s1    	 &
''L
Ir   r   c                   T    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<   y	)
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     s1    	 3
44LJr   r   c                   T    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<   y	)
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   rX   Nr   r*   r   r   r   r     s1    	 2
33LOr   r   c                   T    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<   y	)
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     s1    	 (
))LJr   r   c                   J    e Zd ZU dZed   ed<   eed<   eed<   eed<   eed<   y)	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,     '
((Lr   r   c                   T    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<   y	)
"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   rq   r   Nr   r*   r   r   r   r     s0    	 :
;;LLJr   r   c                   T    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<   y	)
!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   rq   rs   Nr   r*   r   r   r   r     s0    	 9
::LLNr   r   c                   6    e Zd ZU dZed   ed<   eed<   eed<   y)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     s      5
66Lr   r   c                   6    e Zd ZU dZed   ed<   eed<   eed<   y)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  )  s      5
66Lr   r  c                   @    e Zd ZU dZed   ed<   dZee   ed<   eed<   y)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  s)     0
11&*hsm*Lr   r  c                   "    e Zd ZU dZed   ed<   y)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   r  c                   ,    e Zd ZU dZed   ed<   eed<   y)
ErrorEventzEvent indicating an error occurred.

    Parameters:
        type: Event type, always "error".
        error: Error details.
    r   r$   N)r   r   r   r   r   r   r{   r*   r   r   r  r  O  s     '
r   r  c                   <    e Zd ZU dZed   ed<   eeee	f      ed<   y)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(     '
((d38n%%r   r  c                   `    e Zd ZU dZ ed      ZdZee   e	d<   dZ
ee   e	d<   dZee   e	d<   y)	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=     G,L#$M8C=$!"K#""#L(3-#r   r  c                   D    e Zd ZU dZeed<   eed<   eed<   eed<   eed<   y)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   r  c                   j    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
<   y	)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.
    rc   zrealtime.responserd   )rh   ri   rj   	cancelledfailedrk   status_detailsrt   Nusage)r   r   r   r   r   r   r   r   r   rZ   r%  r   r  r*   r   r   r   r     sF    	 	G'((STT!""!E8E?!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  c                     	 t        j                  |       }|d   }|t        vrt        d|       t        |   j	                  |      S # t        $ r}t        | d|        d}~ww xY 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es       r   parse_server_eventr/    su    *

36]
00?
|LMM":.==eDD *1#U3%())*s   AA
 
	A(A##A()Gr   r'  r]   typingr   r   r   r   r   r   pydanticr	   r
   r   r   r"   r,   r7   r;   rU   rZ   rv   rx   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*   r   r   <module>r2     s   N   < < 1 1Hi H.-I - .I . 7y 7 L	  LP%) % !y !<	-9 	-L L6#I #.E) E B	+ 	M+ MK K+ K  	+ 		K 		2+ 	29+ 9) 	+ 		+ 		'+ 	'k ;  {  K    	k 		 		k 		; 	k  [  { (k ( ({ (; (+ ( ( $ ( (K K  0k 0	 		& 	&$9 $ 'I '$"y "(Z* * /	
 #$= !"9 ()F ()F  !8 89e <=m 9:g "#<  !8 "#<  !" \#$ #:!7#;"9,*'C&A.,.P-N,= D*r   