
    qi                     j   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 ddl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 d0 d1e!      Z% G d2 d3e!      Z& G d4 d5e!      Z' G d6 d7e!      Z( G d8 d9e!      Z) G d: d;e!      Z* G d< d=e!      Z+ G d> d?e      Z, G d@ dAe,      Z- G dB dCe,      Z. G dD dEe,      Z/ G dF dGe,      Z0 G dH dIe,      Z1 G dJ dKe,      Z2 G dL dMe,      Z3 G dN dOe,      Z4 G dP dQe,      Z5 G dR dSe,      Z6 G dT dUe,      Z7 G dV dWe,      Z8 G dX dYe,      Z9 G dZ d[e,      Z: G d\ d]e,      Z; G d^ d_e,      Z< G d` dae,      Z= G db dce,      Z> G dd dee,      Z? G df dge,      Z@ G dh die,      ZA G dj dke,      ZB G dl dme,      ZC G dn doe,      ZD G dp dqe,      ZE G dr dse,      ZF G dt due,      ZG G dv dwe,      ZH G dx dye,      ZI G dz d{e,      ZJ G d| d}e,      ZK G d~ de      ZL G d de      ZM G d de      ZN G d de      ZOi deJde-de.de/deHdeIdeFdeGde0de1de2de3de4de5de6de7de8e9e:e;e<e=e>e?e@eAeBeCeDeEeKdZPd ZQy)zGEvent models and data structures for OpenAI Realtime API communication.    N)AnyDictListLiteralOptionalUnion)	BaseModel
ConfigDictField)ToolsSchemac                       e Zd ZU dZeed<   y)AudioFormatz*Base class for audio format configuration.typeN)__name__
__module____qualname____doc__str__annotations__     Y/opt/pipecat/venv/lib/python3.12/site-packages/pipecat/services/openai/realtime/events.pyr   r      s
    4
Ir   r   c                   :    e Zd ZU dZdZed   ed<   dZed   ed<   y)PCMAudioFormatzPCM audio format configuration.

    Parameters:
        type: Audio format type, always "audio/pcm".
        rate: Sample rate, always 24000 for PCM.
    z	audio/pcmr   i]  rateN)r   r   r   r   r   r   r   r   r   r   r   r   r      s&     "-D'+
, D'%. r   r   c                   &    e Zd ZU dZdZed   ed<   y)PCMUAudioFormatu{   PCMU (G.711 μ-law) audio format configuration.

    Parameters:
        type: Audio format type, always "audio/pcmu".
    z
audio/pcmur   Nr   r   r   r   r   r   r   r   r   r   r   r   (        #/D',
.r   r   c                   &    e Zd ZU dZdZed   ed<   y)PCMAAudioFormatzzPCMA (G.711 A-law) audio format configuration.

    Parameters:
        type: Audio format type, always "audio/pcma".
    z
audio/pcmar   Nr   r   r   r   r!   r!   2   r   r   r!   c                   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       r   r*   z InputAudioTranscription.__init__C   s     	uxGr   )r$   NN)
r   r   r   r   r%   r   r   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 500.
    
server_vadr   g      ?	thresholdi,  prefix_padding_msi  silence_duration_msN)r   r   r   r   r   r   r   r   r2   floatr3   intr4   r   r   r   r0   r0   S   sI     -9D(7<(
)8!$Ix$'*x}*),#,r   r0   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   r>   r?   boolr@   r   r   r   r8   r8   c   sO     /=D(7>*
+<DHIx ?@AH&*OXd^*)--r   r8   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   rC   rC   s   s     745
66r   rC   c                   z    e Zd ZU dZdZeeeee	f      e
d<   dZee   e
d<   dZee   e
d<   dZeeeeef      e
d<   y)
AudioInputa:  Audio input configuration.

    Parameters:
        format: The format of the input audio.
        transcription: Configuration for input audio transcription.
        noise_reduction: Configuration for input audio noise reduction.
        turn_detection: Configuration for turn detection, or False to disable.
    Nformattranscriptionnoise_reductionturn_detection)r   r   r   r   rH   r   r   r   r   r!   r   rI   r#   rJ   rC   rK   r0   r8   rA   r   r   r   rG   rG   }   sb     QUFHU>?OKLMT7;M834;:>OX67>RVNHU=2G#MNOVr   rG   c                   Z    e Zd ZU dZdZeeeee	f      e
d<   dZee   e
d<   dZee   e
d<   y)AudioOutputzAudio output configuration.

    Parameters:
        format: The format of the output audio.
        voice: The voice the model uses to respond.
        speed: The speed of the model's spoken response.
    NrH   voicespeed)r   r   r   r   rH   r   r   r   r   r!   r   rN   r   rO   r5   r   r   r   rM   rM      sB     QUFHU>?OKLMTE8C=!E8E?!r   rM   c                   :    e Zd ZU dZdZee   ed<   dZee	   ed<   y)AudioConfigurationzAudio configuration for input and output.

    Parameters:
        input: Configuration for input audio.
        output: Configuration for output audio.
    Ninputoutput)
r   r   r   r   rR   r   rG   r   rS   rM   r   r   r   rQ   rQ      s'     #'E8J&$(FH[!(r   rQ   c                      e Zd ZU dZ e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Zeeed         e	d<   dZee   e	d<   dZee   e	d<   dZeeee   z     e	d<   dZeed      e	d<   dZeeeed   f      e	d<   dZeeed   ef      e	d<   dZee   e	d<   dZee   e	d<   dZeee      e	d<   y)SessionPropertiesa4  Configuration properties for an OpenAI Realtime session.

    Parameters:
        type: The type of session, always "realtime".
        object: Object type identifier, always "realtime.session".
        id: Unique identifier for the session.
        model: The Realtime model used for this session.
            Note: The model is set at connection time via model arg in __init__
            and cannot be changed during the session.
        output_modalities: The set of modalities the model can respond with.
        instructions: System instructions for the assistant.
        audio: Configuration for input and output audio.
        tools: Available function tools for the assistant.
        tool_choice: Tool usage strategy ("auto", "none", or "required").
        max_output_tokens: Maximum tokens in response or "inf" for unlimited.
        tracing: Configuration options for tracing.
        prompt: Reference to a prompt template and its variables.
        expires_at: Session expiration timestamp.
        include: Additional fields to include in server outputs.
    Tarbitrary_types_allowedrealtimer   Nzrealtime.sessionobjectidr%   textaudiooutput_modalitiesinstructionsr]   toolsr=   nonerequiredtool_choiceinfmax_output_tokensr=   tracingr'   
expires_atinclude)r   r   r   r   r
   model_configr   r   r   r   rY   rZ   r   r%   r^   r   r_   r]   rQ   r`   r   r   rd   rf   r   r6   rg   r'   rh   ri   r   r   r   rU   rU      s)   , d;L*4D(7:&
'448FHW/018BE8C=BFxW_%= >?F"&L(3-&*.E8&'. 15E8K$t*,-4AEK'"<=>E>Bxc75>&9 :;B6:GXeGFOT123:!FHTN! $J$#'GXd3i 'r   rU   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<   dZee   ed<   dZeed	      ed
<   y)ItemContenta  Content within a conversation item.

    Parameters:
        type: Content type (text, audio, input_text, input_audio, input_image, output_text, or output_audio).
        text: Text content for text-based items.
        audio: Base64-encoded audio data for audio items.
        transcript: Transcribed text for audio items.
        image_url: Base64-encoded image data as a data URI for input_image items.
        detail: Detail level for image processing ("auto", "low", or "high").
    )r\   r]   
input_textinput_audioinput_imageoutput_textoutput_audior   Nr\   r]   
transcript	image_url)r=   r:   r<   detail)r   r   r   r   r   r   r\   r   r   r]   rr   rs   rt   r   r   r   rl   rl      sh    	 b  D(3-E8C= $J$#Ix}#7;FHW234;r   rl   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_factoryrZ   Nzrealtime.itemrY   )messagefunction_callfunction_call_outputr   )	completedin_progress
incompletestatus)user	assistantsystemrolecontentcall_idname	argumentsrS   )r   r   r   r   r   rZ   r   r   rY   r   r   r   r   r   r   rl   r   r   r   rS   r   r   r   rv   rv      s     $ABBB15FHW_-.5
D
EEJNFHWEFGN=AD(789
:A+/GXd;'(/!GXc]!D(3-#Ix}# FHSM r   rv   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".
    rZ   zrealtime.conversationrY   N)r   r   r   r   r   r   r   r   r   r   r   r     s     	G+,,r   r   c                       e Zd ZU dZ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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)ResponsePropertiesa  Properties for configuring assistant responses.

    Parameters:
        output_modalities: Output modalities for the response. Must be either ["text"] or ["audio"]. Defaults to ["audio"].
        instructions: Specific instructions for this response.
        audio: Audio configuration for this response.
        tools: Available tools for this response.
        tool_choice: Tool usage strategy for this response.
        temperature: Sampling temperature for this response.
        max_output_tokens: Maximum tokens for this response.
    r]   r[   r^   Nr_   r`   ra   rd   temperaturere   rf   )r   r   r   r   r^   r   r   r   r   r_   r   r]   rQ   r`   r   rd   r   r5   rf   r   r6   r   r   r   r   r     s    
 DK)xW_%= >?K"&L(3-&*.E8&'."&E8DJ&AEK'"<=>E#'K%'>Bxc75>&9 :;Br   r   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    coder   Nparamevent_id)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   1  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 rx   )r   ry   rz   r   r   r   r|   zClientEvent.<lambda>O  s    #djjl2C r   r}   r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   H  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                     t        |   |i |}d|d   v rH|d   d   r@d|d   d   v r6|d   d   d   r+d|d   d   d   v r|d   d   d   d   du rd|d   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.
        r]   r   rR   rK   FN)r)   
model_dump)r+   argskwargsdumpr,   s       r   r   zSessionUpdateEvent.model_dump]  s     w!4262 d9o%$y/'*B$y/'22tIw7OPW7X#tIw'?'HHIw/89IJeSNRY09:JKr   )r   r   r   r   r   r   r   rU   r   r   r   r   r-   r.   s   @r   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   u  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   Nr   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   rv   r   r   r   r   r     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   r6   r   r   r   r   r     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     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   r   r   r   r   r   r     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     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.
    TrV   r   r   N)r   r   r   r   r
   rj   r   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   rU   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   r   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)ConversationItemAddedzEvent indicating a conversation item has been added.

    Parameters:
        type: Event type, always "conversation.item.added".
        previous_item_id: ID of the previous item, if any.
        item: The added conversation item.
    conversation.item.addedr   Nr   r   
r   r   r   r   r   r   r   r   r   rv   r   r   r   r   r     s*     +
,,&*hsm*
r   r   c                   @    e Zd ZU dZed   ed<   dZee   ed<   e	ed<   y)ConversationItemDonezEvent indicating a conversation item is done processing.

    Parameters:
        type: Event type, always "conversation.item.done".
        previous_item_id: ID of the previous item, if any.
        item: The completed conversation item.
    conversation.item.doner   Nr   r   r   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   r6   r   r   r   r   r   4  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   rr   Nr   r   r   r   r   r   D  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   r6   r   r   r   r   r   r   T  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   d  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   t  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   rv   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   r6   rv   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)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     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   r6   rl   r   r   r   r   r     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     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	)
ResponseTextDeltaai  Event containing incremental text from a response.

    Parameters:
        type: Event type, always "response.output_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.output_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	)
ResponseTextDonea\  Event indicating text content is complete.

    Parameters:
        type: Event type, always "response.output_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.output_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.output_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.output_audio_transcript.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	)
ResponseAudioTranscriptDoneau  Event indicating audio transcript is complete.

    Parameters:
        type: Event type, always "response.output_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.output_audio_transcript.doner   r   r   r   r   rr   Nr   r   r   r   r  r  (  s1    	 9
::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	)
ResponseAudioDeltaa}  Event containing incremental audio data from a response.

    Parameters:
        type: Event type, always "response.output_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.output_audio.deltar   r   r   r   r   r   Nr   r   r   r   r  r  <  s1    	 /
00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)	ResponseAudioDonea9  Event indicating audio content is complete.

    Parameters:
        type: Event type, always "response.output_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.output_audio.doner   r   r   r   r   Nr   r   r   r   r  r  P  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   r   r   Nr   r   r   r   r  r  b  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   r   r   Nr   r   r   r   r  r  v  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   r6   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"    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%    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(    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dZee   ed<   dZee   ed<   y)CachedTokensDetailszDetails about cached tokens.

    Parameters:
        text_tokens: Number of cached text tokens.
        audio_tokens: Number of cached audio tokens.
    r   text_tokensaudio_tokensN)	r   r   r   r   r/  r   r6   r   r0  r   r   r   r.  r.    s%     "#K#""#L(3-#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<   dZee   e	d	<   dZee   e	d
<   y)TokenDetailsa  Detailed 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.
        cached_tokens_details: Detailed breakdown of cached tokens.
        image_tokens: Number of image tokens used (for input only).
    allow)extrar   cached_tokensr/  r0  Ncached_tokens_detailsimage_tokens)r   r   r   r   r
   rj   r5  r   r6   r   r/  r0  r6  r.  r7  r   r   r   r2  r2    s\     G,L#$M8C=$!"K#""#L(3-#;?8$78?"#L(3-#r   r2  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   r6   r   r2  r   r   r   r9  r9    s'     %%&&r   r9  c                       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
         ed<   d	Zeeeed   f      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	Zee   ed<   y	)r   a.  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.
        conversation_id: Which conversation the response is added to.
        output_modalities: The set of modalities the model used to respond.
        max_output_tokens: Maximum number of output tokens used.
        audio: Audio configuration for the response.
        usage: Token usage statistics for the response.
        voice: The voice the model used to respond.
        temperature: Sampling temperature used for the response.
        output_audio_format: The format of output audio.
    rZ   zrealtime.responserY   )r   r   r   	cancelledfailedr   status_detailsrS   Nr[   r^   re   rf   r]   usagerN   r   output_audio_format)r   r   r   r   r   r   r   r   r   rv   r^   r   rf   r   r6   r]   rQ   rC  r9  rN   r   r5   rD  r   r   r   r   r     s    $ 	G'((STT!""BFxW_%= >?F>Bxc75>&9 :;B*.E8&'.!E8E?!E8C=#'K%')-#-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+  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_eventrN  L  su    *

36]
00?
|LMM":.==eDD *1#U3%())*s   AA
 
	A(A##A()Rr   rF  ry   typingr   r   r   r   r   r   pydanticr	   r
   r   %pipecat.adapters.schemas.tools_schemar   r   r   r   r!   r#   r0   r8   rC   rG   rM   rQ   rU   rl   rv   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.  r2  r9  r   rH  rN  r   r   r   <module>rR     sE   N   < < 1 1 =) 	![ 	!/k //k /Hi H.-I - .I . 7y 7W W ") "	) 	))(	 )(b<) <,!y !<	-9 	-C C2#I #.E) E   F	+ 	M+ MK K+ K  	+ 		K 		2+ 	29+ 9) 	+ 		+ 		'+ 	'K ; ;  {  K    	k 		 		k 		; 	k  [  { (k ( ({ (; (+ ( ( $ ( (K K  0k 0	 		& 	&	$) 	$$9 $('I '$.y .B Z *  *  /	 
 #$=  !"9  ()F  ()F  4  2  89e  <=m  9:g  "#<   !8   "#<! " # $ ""9!7#;"9"3!1.J-H#5"3.P-N,?  F*r   