
    qi^                        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 ed   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e	eeeeeeef   f   Zed   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.      Z0 G dB dCe.      Z1 G dD dEe.      Z2 G dF dGe.      Z3 G dH dIe.      Z4 G dJ dKe.      Z5 G dL dMe.      Z6 G dN dOe.      Z7 G dP dQe.      Z8 G dR dSe.      Z9 G dT dUe.      Z: G dV dWe.      Z; G dX dYe.      Z< G dZ d[e.      Z= G d\ d]e.      Z> G d^ d_e      Z? G d` dae      Z@ G db dOe.      Z7 G dc dde.      ZA G de dfe.      ZB G dg dhe      ZC G di dje.      ZD G dk dle.      ZE G dm dne.      ZF G do dpe.      ZGi dqeGdreFdse/dte0due1dve2dwe3dxe4dye5dze6d{e7d|e8d}eBd~eDdeEde9de:e;e<e=e>eAdZHdefdZIy)zEvent models and data structures for Grok Voice Agent API communication.

Based on xAI's Grok Voice Agent API documentation:
https://docs.x.ai/docs/guides/voice/agent
    N)AnyDictListLiteralOptionalUnion)	BaseModel
ConfigDictField)ToolsSchema)i@  i>  i:R  ]  i }  iD  i  c                       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__     W/opt/pipecat/venv/lib/python3.12/site-packages/pipecat/services/grok/realtime/events.pyr   r      s
    4
Ir   r   c                   4    e Zd ZU dZdZed   ed<   dZeed<   y)PCMAudioFormata  PCM audio format configuration with configurable sample rate.

    Grok supports: 8000, 16000, 21050, 24000, 32000, 44100, 48000 Hz

    Parameters:
        type: Audio format type, always "audio/pcm".
        rate: Sample rate in Hz. Defaults to 24000.
    z	audio/pcmr   r   rateN)	r   r   r   r   r   r   r   r   SUPPORTED_SAMPLE_RATESr   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.

    Fixed at 8000 Hz sample rate.

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

    Fixed at 8000 Hz sample rate.

    Parameters:
        type: Audio format type, always "audio/pcma".
    z
audio/pcmar   Nr    r   r   r   r#   r#   =   r!   r   r#   c                   ,    e Zd ZU dZdZeed      ed<   y)TurnDetectionzServer-side voice activity detection configuration.

    Parameters:
        type: Detection type, must be "server_vad" or None for manual.
    
server_vadr   N)r   r   r   r   r   r   r   r   r   r   r   r%   r%   N   s     -9D(7<(
)8r   r%   c                   2    e Zd ZU dZdZeeeee	f      e
d<   y)
AudioInputzjAudio input configuration.

    Parameters:
        format: The format configuration for input audio.
    Nformatr   r   r   r   r)   r   r   r   r   r#   r   r   r   r   r(   r(   ]   &     QUFHU>?OKLMTr   r(   c                   2    e Zd ZU dZdZeeeee	f      e
d<   y)AudioOutputzlAudio output configuration.

    Parameters:
        format: The format configuration for output audio.
    Nr)   r*   r   r   r   r-   r-   g   r+   r   r-   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   r0   r   r(   r   r1   r-   r   r   r   r/   r/   q   s'     #'E8J&$(FH[!(r   r/   c                   &    e Zd ZU dZdZed   ed<   y)WebSearchToolzkWeb search tool configuration.

    Enables the voice agent to search the web for current information.
    
web_searchr   Nr    r   r   r   r3   r3      s    
 #/D',
.r   r3   c                   @    e Zd ZU dZdZed   ed<   dZee	e
      ed<   y)XSearchToolzX (Twitter) search tool configuration.

    Enables the voice agent to search X for posts and information.

    Parameters:
        type: Tool type, always "x_search".
        allowed_x_handles: Optional list of X handles to filter search results.
    x_searchr   Nallowed_x_handles)r   r   r   r   r   r   r   r8   r   r   r   r   r   r   r6   r6      s,     !+D'*
*-1xS	*1r   r6   c                   J    e Zd ZU dZdZed   ed<   ee   ed<   dZ	e
e   ed<   y)FileSearchToola7  File/Collection search tool configuration.

    Enables the voice agent to search through uploaded document collections.

    Parameters:
        type: Tool type, always "file_search".
        vector_store_ids: List of collection IDs to search.
        max_num_results: Maximum number of results to return.
    file_searchr   vector_store_ids
   max_num_resultsN)r   r   r   r   r   r   r   r   r   r>   r   intr   r   r   r:   r:      s0     $1D'-
 03i%'OXc]'r   r:   c                   N    e Zd ZU dZdZed   ed<   eed<   eed<   eee	f   ed<   y)FunctionToolzCustom function tool configuration.

    Parameters:
        type: Tool type, always "function".
        name: Name of the function.
        description: Description of what the function does.
        parameters: JSON schema for function parameters.
    functionr   namedescription
parametersN)
r   r   r   r   r   r   r   r   r   r   r   r   r   rA   rA      s1     !+D'*
*
IS#Xr   rA   )AraRexSalEveLeoc                       e Zd ZU dZ ed      ZdZee   e	d<   dZ
eeez     e	d<    ed 	      Zee   e	d
<   dZee   e	d<   dZeeee   z     e	d<   y)SessionPropertiesa#  Configuration properties for a Grok Voice Agent session.

    Parameters:
        instructions: System instructions for the assistant.
        voice: The voice the model uses to respond. Options: Ara, Rex, Sal, Eve, Leo.
            Defaults to "Ara".
        turn_detection: Configuration for turn detection. Defaults to server-side VAD.
            Set to None for manual turn detection.
        audio: Configuration for input and output audio.
        tools: Available tools for the assistant (web_search, x_search, file_search, function).
    Tarbitrary_types_allowedNinstructionsrF   voicec                      t        d      S )Nr&   )r   )r%   r   r   r   <lambda>zSessionProperties.<lambda>   s    < @ r   default_factoryturn_detectionaudiotools)r   r   r   r   r
   model_configrO   r   r   r   rP   	GrokVoicer   rU   r%   rV   r/   rW   r   r   GrokToolr   r   r   rL   rL      sw    
 d;L"&L(3-&',E8IO$,.3@/NH]+  +/E8&'.48E8K$x.018r   rL   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 (input_text, input_audio, text, audio).
        text: Text content for text-based items.
        audio: Base64-encoded audio data for audio items.
        transcript: Transcribed text for audio items.
    )textrV   
input_textinput_audiooutput_textoutput_audior   Nr]   rV   
transcript)r   r   r   r   r   r   r]   r   r   rV   rb   r   r   r   r\   r\      s?     ]
^^D(3-E8C= $J$r   r\   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   rR   zConversationItem.<lambda>	  s    C

0@0@,A r   rS   idNzrealtime.itemobject)messagefunction_callfunction_call_outputr   )	completedin_progress
incompletestatus)user	assistantsystemtoolrolecontentcall_idrC   	argumentsr1   )r   r   r   r   r   rj   r   r   rk   r   r   rr   rw   rx   r   r\   ry   rC   rz   r1   r   r   r   rd   rd      s     $ABBB15FHW_-.5
D
EEJNFHWEFGNEID(7@A
BI+/GXd;'(/!GXc]!D(3-#Ix}# FHSM r   rd   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".
    rj   zrealtime.conversationrk   N)r   r   r   r   r   r   r   r   r   r   r|   r|     s     	G+,,r   r|   c                   6    e Zd ZU dZddgZeeed         ed<   y)ResponsePropertieszProperties for configuring assistant responses.

    Parameters:
        modalities: Output modalities for the response (text, audio, or both).
    r]   rV   )r]   rV   
modalitiesN)	r   r   r   r   r   r   r   r   r   r   r   r   r~   r~   !  s(     =CG;LJgo678Lr   r~   c                   l    e Zd ZU dZdZe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.
    Nr    coderl   paramevent_id)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   0  sF     D(3-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 rf   )r   rg   rh   r   r   r   rR   zClientEvent.<lambda>N  s    #djjl2C r   rS   r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   G  s     *CDHcDr   r   c                   0    e Zd ZU dZdZed   ed<   eed<   y)SessionUpdateEventzEvent to update session properties.

    Parameters:
        type: Event type, always "session.update".
        session: Updated session properties.
    zsession.updater   sessionN)r   r   r   r   r   r   r   rL   r   r   r   r   r   Q  s     '7D'"
#6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   rV   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.

    Used when turn_detection is null (manual mode).

    Parameters:
        type: Event type, always "input_audio_buffer.commit".
    zinput_audio_buffer.commitr   Nr    r   r   r   r   r   i  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   u  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   rd   r   r   r   r   r     s/     1KD',
-J&*hsm*
r   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.
    TrM   r   r   N)r   r   r   r   r
   rX   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)SessionUpdatedEventzEvent indicating a session has been updated.

    Parameters:
        type: Event type, always "session.updated".
        session: The updated session properties.
    session.updatedr   r   N)r   r   r   r   r   r   rL   r   r   r   r   r     s     #
$$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.

    This is the first message received after connecting.

    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   rd   r   r   r   r   r     s*     +
,,&*hsm*
r   r   c                   6    e Zd ZU dZed   ed<   eed<   eed<   y)0ConversationItemInputAudioTranscriptionCompleteda  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.
        transcript: Complete transcription text.
    5conversation.item.input_audio_transcription.completedr   item_idrb   Nr   r   r   r   r   r   r   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<   y)InputAudioBufferSpeechStarteda  Event indicating speech has started in the input audio buffer.

    Only sent when turn_detection is "server_vad".

    Parameters:
        type: Event type, always "input_audio_buffer.speech_started".
        item_id: ID of the associated conversation item.
    !input_audio_buffer.speech_startedr   r   Nr   r   r   r   r   r          5
66Lr   r   c                   ,    e Zd ZU dZed   ed<   eed<   y)InputAudioBufferSpeechStoppeda  Event indicating speech has stopped in the input audio buffer.

    Only sent when turn_detection is "server_vad".

    Parameters:
        type: Event type, always "input_audio_buffer.speech_stopped".
        item_id: ID of the associated conversation item.
    !input_audio_buffer.speech_stoppedr   r   Nr   r   r   r   r   r     r   r   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   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)ResponseCreatedEvent indicating an assistant response has been created.

    Parameters:
        type: Event type, always "response.created".
        response: The created response object.
    response.createdr   Responser   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?   rd   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)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.
        delta: Incremental transcript text.
    &response.output_audio_transcript.deltar   r   r   deltaNr   r   r   r   r   r   <  s%     :
;;LJr   r   c                   6    e Zd ZU dZed   ed<   eed<   eed<   y)ResponseAudioTranscriptDonezEvent 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.
    %response.output_audio_transcript.doner   r   r   Nr   r   r   r   r   r   L  s      9
::Lr   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   content_indexr   Nr   r   r   r   r   r   r   r?   r   r   r   r   r   Z  s1    	 /
00LJr   r   c                   6    e Zd ZU dZed   ed<   eed<   eed<   y)ResponseAudioDonezEvent 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.
    response.output_audio.doner   r   r   Nr   r   r   r   r   r   n  s      .
//Lr   r   c                   r    e Zd ZU dZed   ed<   dZee   ed<   dZ	ee   ed<   eed<   eed<   dZ
e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.
        call_id: ID of the function call.
        delta: Incremental function arguments as JSON.
        previous_item_id: ID of the previous item, if any.
    &response.function_call_arguments.deltar   Nr   r   ry   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   |  sJ    	 :
;;!%K#%!GXc]!LJ&*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)!ResponseFunctionCallArgumentsDonea0  Event indicating function call arguments are complete.

    Parameters:
        type: Event type, always "response.function_call_arguments.done".
        call_id: ID of the function call.
        name: Name of the function being called.
        arguments: Complete function arguments as JSON string.
    %response.function_call_arguments.doner   ry   rC   rz   Nr   r   r   r   r   r     s$     9
::L
INr   r   c                   N    e Zd ZU dZdZee   ed<   dZee   ed<   dZ	ee   ed<   y)Usagea#  Token usage statistics for a response.

    All fields are optional because Grok sends empty usage in some events.

    Parameters:
        total_tokens: Total number of tokens used.
        input_tokens: Number of input tokens used.
        output_tokens: Number of output tokens used.
    Ntotal_tokensinput_tokensoutput_tokens)
r   r   r   r   r   r   r?   r   r   r   r   r   r   r   r     s3     #'L(3-&"&L(3-&#'M8C='r   r   c                   t    e Zd ZU dZeed<   ed   ed<   ed   ed<   dZee	   ed<   e
e   ed	<   dZee   ed
<   y)r   aA  A complete assistant response.

    Parameters:
        id: Unique identifier for the response.
        object: Object type, always "realtime.response".
        status: Current status of the response.
        output: List of conversation items in the response.
        usage: Token usage statistics for the response.
    rj   zrealtime.responserk   )ro   rp   rq   	cancelledfailedrr   Nstatus_detailsr1   usage)r   r   r   r   r   r   r   r   r   r   r   rd   r   r   r   r   r   r   r     sN     	G'((STT$(NHSM(!""!E8E?!r   r   c                   ,    e Zd ZU dZed   ed<   eed<   y)r   r   r   r   r   N)r   r   r   r   r   r   r   r   r   r   r   r     s     $
%%r   c                   @    e Zd ZU dZed   ed<   eed<   dZee	   ed<   y)ResponseDonezEvent indicating an assistant response is complete.

    Parameters:
        type: Event type, always "response.done".
        response: The completed response object.
        usage: Token usage (also available at top level in Grok).
    response.doner   r   Nr   )
r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s(     /
""!E8E?!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                   0    e Zd ZU dZeed<   dZee   ed<   y)ContentPartzA content part within a response.

    Parameters:
        type: Type of the content part (audio, text).
        transcript: Transcript text if applicable.
    r   Nrb   )r   r   r   r   r   r   rb   r   r   r   r   r   r     s     I $J$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.
        content_index: Index of the content part.
        output_index: Index of the output item.
        part: The added content part.
    response.content_part.addedr   r   r   r   r   partN)	r   r   r   r   r   r   r   r?   r   r   r   r   r   r     s2    	 /
00L
r   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)	ResponseContentPartDonea:  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.
        content_index: Index of the content part.
        output_index: Index of the output item.
    response.content_part.doner   r   r   r   r   Nr   r   r   r   r   r     s,     .
//Lr   r   c                   ,    e Zd ZU dZed   ed<   eed<   y)	PingEventzKeep-alive ping event from the server.

    Parameters:
        type: Event type, always "ping".
        timestamp: Server timestamp in milliseconds.
    pingr   	timestampN)r   r   r   r   r   r   r?   r   r   r   r   r     s     &/Nr   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.
    errorr   N)r   r   r   r   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   datac                     	 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:
        data: 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  U  sv    +

4 6]
00?
|LMM":.==eDD +1#U4&)**+s   AA
 
	A(A##A()Jr   r   rg   typingr   r   r   r   r   r   pydanticr	   r
   r   %pipecat.adapters.schemas.tools_schemar   r   r   r   r   r#   r%   r(   r-   r/   r3   r6   r:   rA   r   rZ   rY   rL   r\   rd   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>r	     s     < < 1 1 = !!OP ) )[ )	/k 	/	/k 	/"9I 9U UU) U	) 	)"/I /2) 2(Y ( 9 " ^\4PSUXPX>YZ 56	9	 9>%) % !y !8	-9 	-M M#I #.E) E	 		+ 		M+ 	MK K+ 	2+ 	29+ 9) 	+ 	'+ 'K { K K  0k 0	k 	k  ;  +  ( + +(  (I ( "y "&	k 	"; "[  	%) 	%{ (k $	 		 	 Z
I * /	
 4 <=m ()F ()F #$= !"9  !"9  !7 "#; !"9  -.J!" ,-H#$ $6"3.P-N!- 4+S +r   