
    qiq                        d Z ddlZddlmZmZ ddlmZ ddlmZm	Z	m
Z
mZmZmZmZmZ ddlmZ ddlmZ ddlmc mc mc mZ ddlmZ dd	lmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 dd
l6m7Z7m8Z8m9Z9m:Z: ddl;m<Z<m=Z= ddl>m?Z? ddl@mAZAmBZB ddlCmDZDmEZE ddlFmGZG ddlHmIZI erddlJmKZK  G d deLe      ZMe G d d             ZN G d de<      ZOy)zGRTVI observer for converting pipeline frames to outgoing RTVI messages.    N)	dataclassfield)Enum)TYPE_CHECKING	AwaitableCallableDictListOptionalSetTuple)logger)	BaseModel)calculate_audio_volume)AggregatedTextFrameAggregationTypeBotStartedSpeakingFrameBotStoppedSpeakingFrameFrameFunctionCallCancelFrameFunctionCallInProgressFrameFunctionCallResultFrameFunctionCallsStartedFrameInputAudioRawFrameInterimTranscriptionFrameLLMContextFrameLLMFullResponseEndFrameLLMFullResponseStartFrameLLMTextFrameMetricsFrameTranscriptionFrameTTSAudioRawFrameTTSStartedFrameTTSStoppedFrameTTSTextFrameUserMuteStartedFrameUserMuteStoppedFrameUserStartedSpeakingFrameUserStoppedSpeakingFrame)LLMUsageMetricsDataProcessingMetricsDataTTFBMetricsDataTTSUsageMetricsData)BaseObserverFramePushed)OpenAILLMContextFrame)FrameDirectionFrameProcessor)RTVIServerMessageFrameRTVIServerResponseFrame)BaseOutputTransport)match_endofsentence)RTVIProcessorc                        e Zd ZdZdZdZdZdZy)RTVIFunctionCallReportLevela  Level of detail to include in function call RTVI events.

    Controls what information is exposed in function call events for security.

    Values:
        DISABLED: No events emitted for this function call.
        NONE: Events only with tool_call_id, no function name or metadata (most secure).
        NAME: Events with function name, no arguments or results.
        FULL: Events with function name, arguments, and results.
    disablednonenamefullN)__name__
__module____qualname____doc__DISABLEDNONENAMEFULL     ]/opt/pipecat/venv/lib/python3.12/site-packages/pipecat/processors/frameworks/rtvi/observer.pyr9   r9   K   s    	 HDDDrG   r9   c                      e Zd ZU dZdZeed<   dZeed<   dZeed<   dZ	eed<   dZ
eed<   dZeed	<   dZeed
<   dZeed<   dZeed<   dZeed<   dZeed<   dZeed<   dZee   ed<    ee      Zee   ed<   dZeeeez        ed<   dZeeeeez  eeeez  gee   f   f         ed<   dZ e!ed<    ed       Z"e#ee$f   ed<   y)RTVIObserverParamsa6  Parameters for configuring RTVI Observer behavior.

    .. deprecated:: 0.0.87
        Parameter `errors_enabled` is deprecated. Error messages are always enabled.

    Parameters:
        bot_output_enabled: Indicates if bot output messages should be sent.
        bot_llm_enabled: Indicates if the bot's LLM messages should be sent.
        bot_tts_enabled: Indicates if the bot's TTS messages should be sent.
        bot_speaking_enabled: Indicates if the bot's started/stopped speaking messages should be sent.
        bot_audio_level_enabled: Indicates if bot's audio level messages should be sent.
        user_llm_enabled: Indicates if the user's LLM input messages should be sent.
        user_speaking_enabled: Indicates if the user's started/stopped speaking messages should be sent.
        user_transcription_enabled: Indicates if user's transcription messages should be sent.
        user_audio_level_enabled: Indicates if user's audio level messages should be sent.
        metrics_enabled: Indicates if metrics messages should be sent.
        system_logs_enabled: Indicates if system logs should be sent.
        errors_enabled: [Deprecated] Indicates if errors messages should be sent.
        ignored_sources: List of frame processors whose frames should be silently ignored
            by this observer. Useful for suppressing RTVI messages from secondary pipeline
            branches (e.g. a silent evaluation LLM) that should not be visible to clients.
            Sources can also be added and removed dynamically via ``add_ignored_source()``
            and ``remove_ignored_source()``.
        skip_aggregator_types: List of aggregation types to skip sending as tts/output messages.
            Note: if using this to avoid sending secure information, be sure to also disable
            bot_llm_enabled to avoid leaking through LLM messages.
        bot_output_transforms: A list of callables to transform text before just before sending it
            to TTS. Each callable takes the aggregated text and its type, and returns the
            transformed text. To register, provide a list of tuples of
            (aggregation_type | '*', transform_function).
        audio_level_period_secs: How often audio levels should be sent if enabled.
        function_call_report_level: Controls what information is exposed in function call
            events for security. A dict mapping function names to levels, where ``"*"``
            sets the default level for unlisted functions::

                function_call_report_level={
                    "*": RTVIFunctionCallReportLevel.NONE,  # Default: events with no metadata
                    "get_weather": RTVIFunctionCallReportLevel.FULL,  # Expose everything
                }

            Levels:
                - DISABLED: No events emitted for this function.
                - NONE: Events with tool_call_id only (most secure when events needed).
                - NAME: Adds function name to events.
                - FULL: Adds function name, arguments, and results.

            Defaults to ``{"*": RTVIFunctionCallReportLevel.NONE}``.
    Tbot_output_enabledbot_llm_enabledbot_tts_enabledbot_speaking_enabledFbot_audio_level_enableduser_llm_enableduser_speaking_enableduser_mute_enableduser_transcription_enableduser_audio_level_enabledmetrics_enabledsystem_logs_enabledNerrors_enabled)default_factoryignored_sourcesskip_aggregator_typesbot_output_transformsg333333?audio_level_period_secsc                  &    dt         j                  iS )N*)r9   rC   rF   rG   rH   <lambda>zRTVIObserverParams.<lambda>   s    &A&F&F G rG   function_call_report_level)%r>   r?   r@   rA   rK   bool__annotations__rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   r   r   listrY   r
   r2   rZ   r   strr[   r   r   r   r\   floatr`   r	   r9   rF   rG   rH   rJ   rJ   ]   sD   /b  $# OT  OT !%$%$)T)!d!"&4&"t"'++%*d* OT  %%%)NHTN),1$,GOT.)GCG8D3)>$?@G 	 8#%#45y~EFH	
  &*U)INGJS*E%E F rG   rJ   c                       e Zd ZdZ	 d%ddded   dee   f fdZ	 d&deee	ez  ge
e   f   d	e	ez  fd
Z	 d&deee	ez  ge
e   f   d	e	ez  fdZdefdZdefdZdedefdZd Z fdZd'dedefdZdefdZdefdZdefdZdefdZdefdZdefdZde fdZ!defd Z"de#e$z  fd!Z%de&fd"Z'de(fd#Z)de(fd$Z* xZ+S )(RTVIObservera  Pipeline frame observer for RTVI server message handling.

    This observer monitors pipeline frames and converts them into appropriate RTVI messages
    for client communication. It handles various frame types including speech events,
    transcriptions, LLM responses, and TTS events.

    Note:
        This observer only handles outgoing messages. Incoming RTVI client messages
        are handled by the RTVIProcessor.
    N)paramsrtvir7   rh   c                   t        |   di | || _        |xs
 t               | _        t        | j                  j                        | _        t               | _        d| _	        d| _
        d| _        d| _        g | _        | j                  j                  r$t        j                   | j"                        | _        | j                  j&                  Dddl}|j+                         5  |j-                  d       |j/                  dt0               ddd       | j                  j2                  xs g | _        y# 1 sw Y   )xY w)zInitialize the RTVI observer.

        Args:
            rtvi: The RTVI processor to push frames to.
            params: Settings to enable/disable specific messages.
            **kwargs: Additional arguments passed to parent class.
         r   FNalwayszLParameter `errors_enabled` is deprecated. Error messages are always enabled.rF   )super__init___rtvirJ   _paramssetrY   _ignored_sources_frames_seen_bot_transcription_last_user_audio_level_last_bot_audio_level_bot_is_speaking_queued_aggregated_text_framesrV   r   add_logger_sink_system_logger_idrW   warningscatch_warningssimplefilterwarnDeprecationWarningr[   _aggregation_transforms)selfri   rh   kwargsr|   	__class__s        rH   rn   zRTVIObserver.__init__   s    	"6"
5!3!5589U9U5VE"$&'#%&" !&IK+<<++%+ZZ0A0A%BD"<<&&2((* %%h/b& LL..4" 	$ s   %(D55D>transform_functionaggregation_typec                 >    | j                   j                  ||f       y)a  Transform text for a specific aggregation type before sending as Bot Output or TTS.

        Args:
            transform_function: The function to apply for transformation. This function should take
                the text and aggregation type as input and return the transformed text.
                Ex.: async def my_transform(text: str, aggregation_type: str) -> str:
            aggregation_type: The type of aggregation to transform. This value defaults to "*" to
                handle all text before sending to the client.
        N)r   append)r   r   r   s      rH   add_bot_output_transformerz'RTVIObserver.add_bot_output_transformer   s     	$$++-=?Q,RSrG   c                 p    | j                   D cg c]  \  }}||k(  r||k(  s||f c}}| _         yc c}}w )zRemove a text transformer for a specific aggregation type.

        Args:
            transform_function: The function to remove.
            aggregation_type: The type of aggregation to remove the transformer for.
        N)r   )r   r   r   agg_typefuncs        rH   remove_bot_output_transformerz*RTVIObserver.remove_bot_output_transformer   sD     #'">">(
$ 00T=O5O t(
$ (
s   2sourcec                 :    | j                   j                  |       y)a  Ignore all frames pushed by the given processor.

        Any frame whose source matches ``source`` will be silently skipped,
        preventing RTVI messages from being emitted for activity in that
        processor. Useful for suppressing events from secondary pipeline
        branches (e.g. a silent evaluation LLM) that should not be visible
        to clients.

        Args:
            source: The frame processor to ignore.
        N)rr   ry   r   r   s     rH   add_ignored_sourcezRTVIObserver.add_ignored_source  s     	!!&)rG   c                 :    | j                   j                  |       y)a  Stop ignoring frames pushed by the given processor.

        Reverses a previous call to ``add_ignored_source()``. If ``source``
        was not previously ignored this is a no-op.

        Args:
            source: The frame processor to stop ignoring.
        N)rr   discardr   s     rH   remove_ignored_sourcez"RTVIObserver.remove_ignored_source  s     	%%f-rG   function_namereturnc                     | j                   j                  }||v r||   S |j                  dt        j                        S )a1  Get the report level for a specific function call.

        Args:
            function_name: The name of the function to get the report level for.

        Returns:
            The report level for the function. Looks up the function name first,
            then falls back to "*" key, then NONE.
        r^   )rp   r`   getr9   rC   )r   r   levelss      rH   _get_function_call_report_levelz,RTVIObserver._get_function_call_report_level!  s>     88F"-((zz#:??@@rG   c                    K   t        j                  t        j                  |            }| j                  |       d{    y7 w)z7Logger sink so we can send system logs to RTVI clients.textdataN)RTVISystemLogMessageTextMessageDatasend_rtvi_message)r   messages     rH   rz   zRTVIObserver._logger_sink0  s5     ''T-A-Aw-OP$$W---s   ?A	AA	c                    K   t         |           d{    | j                  j                  r t	        j
                  | j                         yy7 ;w)z Cleanup RTVI observer resources.N)rm   cleanuprp   rV   r   remover{   )r   r   s    rH   r   zRTVIObserver.cleanup5  s@     go<<++MM$001 , 	 s   AA<Amodelexclude_nonec                 r   K   | j                   r%| j                   j                  ||       d{    yy7 w)a5  Send an RTVI message.

        By default, we push a transport frame. But this function can be
        overridden by subclass to send RTVI messages in different ways.

        Args:
            model: The message to send.
            exclude_none: Whether to exclude None values from the model dump.

        N)ro   push_transport_message)r   r   r   s      rH   r   zRTVIObserver.send_rtvi_message;  s1      ::**33E<HHH Hs   ,757r   c                 d  K   |j                   }|j                  }|j                  }| j                  r|| j                  v ry|j                  |t
        j                  k7  ry|j                  | j                  v ryd}t        |t        t        f      r1| j                  j                  r| j                  |       d{    	nt        |t        t         f      r1| j                  j"                  r| j%                  |       d{    nt        |t&        t(        f      r1| j                  j*                  r| j-                  |       d{    nwt        |t.        t0        f      r1| j                  j2                  r| j5                  |       d{    n0t        |t6        t8        f      r1| j                  j:                  r| j=                  |       d{    nt        |t>              rC| j                  j@                  r-| jC                  tE        jF                                d{    nt        |tH              rC| j                  j@                  r-| jC                  tE        jJ                                d{    nCt        |tL              r1| j                  j@                  r| jO                  |       d{    nt        |tP              rC| j                  jR                  r-| jC                  tE        jT                                d{    nt        |tV              rC| j                  jR                  r-| jC                  tE        jX                                d{    n\t        |tZ              rk| j                  j\                  s| j                  jR                  r?t        |t^              rt        |t`              sd}n| jc                  |       d{    nt        |td              r1| j                  jf                  r| ji                  |       d{    nt        |tj              r|jl                  D ]  }| jo                  |jp                        }|tr        jt                  k(  r2tE        jv                         }|tr        jx                  tr        jz                  fv r|jp                  |_8        tE        j|                  |      }| jC                  |       d{     nt        |t~              r| jo                  |jp                        }|tr        jt                  k7  rtE        j                  |j                        }|tr        jx                  tr        jz                  fv r|jp                  |_8        |tr        jz                  k(  r|j                  |_B        tE        j                  |      }| jC                  |       d{    nt        |t              r| jo                  |jp                        }|tr        jt                  k7  rtE        j                  |j                  d      }|tr        jx                  tr        jz                  fv r|jp                  |_8        tE        j                  |      }| jC                  |       d{    n-t        |t              r| jo                  |jp                        }|tr        jt                  k7  rtE        j                  |j                  d      }|tr        jx                  tr        jz                  fv r|jp                  |_8        |tr        jz                  k(  r|j                  r|j                  nd|_H        tE        j                  |      }| jC                  |       d{    n7t        |t              r;tE        j                  |j                        }| jC                  |       d{    nt        |t              rB|j                  | j                  |       d{    n| j                  |       d{    nt        |t              r| j                  j                  rt        j                         }	|	| j                  z
  }
|
| j                  j                  kD  r7t        |j                  |j                        }tE        j                  tE        j                  |            }| jC                  |       d{    |	| _S        nt        |t              r| j                  j                  rt        j                         }	|	| j                  z
  }
|
| j                  j                  kD  rjt        |j                  |j                        }tE        j                  tE        j                  |            }| jC                  |       d{    |	| _\        |r&| j                  j                  |j                         yy7 	57 7 7 i7 %7 7 7 G7 7 7 /7 7 .7 H7 7 7 L7 7  7 ;7 pw)zProcess a frame being pushed through the pipeline.

        Args:
            data: Frame push event data containing source, frame, direction, and timestamp.
        NTFr   )tool_call_id)r   	cancelled)value)_r   frame	directionrr   broadcast_sibling_idr1   
DOWNSTREAMidrs   
isinstancer(   r)   rp   rQ   _handle_interruptionsr&   r'   rR   _handle_user_muter   r   rN   _handle_bot_speakingr!   r   rS   _handle_user_transcriptionsr0   r   rP   _handle_contextr   rL   r   r   BotLLMStartedMessager   BotLLMStoppedMessager   _handle_llm_text_framer#   rM   BotTTSStartedMessager$   BotTTSStoppedMessager   rK   r%   r5   _handle_aggregated_llm_textr    rU   _handle_metricsr   function_callsr   r   r9   rB   LLMFunctionCallStartMessageDatarD   rE   LLMFunctionCallStartMessager   $LLMFunctionCallInProgressMessageDatar   	arguments LLMFunctionCallInProgressMessager   !LLMFunctionCallStoppedMessageDataLLMFunctionCallStoppedMessager   resultr3   ServerMessager   r4   error_send_error_response_send_server_responser   rT   timeru   r\   r   audiosample_rateUserAudioLevelMessageAudioLevelMessageDatar"   rO   rv   BotAudioLevelMessagery   )r   r   srcr   r   mark_as_seenfunction_callreport_levelr   	curr_time	diff_timelevels               rH   on_push_framezRTVIObserver.on_push_frameI  s     kk

NN	   SD,A,A%A %%1i>C\C\6\ 88t(((  u79QRS22,,U333u35IJK..((///u68OPQ11++E222u13LMN77225999u4oFG--&&u---89dll>Z>Z(()B)B)DEEE67DLL<X<X(()B)B)DEEE|,1M1M--e444/DLL4P4P(()B)B)DEEE/DLL4P4P(()B)B)DEEE23LL++t||/K/K%.z#GZ7[  %66u===|,1M1M&&u---89!&!5!5 6#CCMD_D_`#>#G#GG;;=/44/44$  *7)D)DD&::E,,W5556 :;??@S@STL:CCC@@eN`N`a/44/44$  */)<)<D&#>#C#CC%*__DN??TJ,,W55567??@S@STL:CCC==!&!3!3"  /44/44$  */)<)<D&<<$G,,W55567??@S@STL:CCC==!&!3!3#  /44/44$  */)<)<D&#>#C#CC27,,%,,DDK<<$G,,W55556((ejj9G((11167{{&//6660077712t||7\7\		I!D$?$??I4<<???.u{{E<M<MN44$:T:T[`:ab,,W555.7+/0T\\5Y5Y		I!D$>$>>I4<<???.u{{E<M<MN339S9SZ_9`a,,W555-6*!!%((+ w 4
 0
 3
 :
 .EE4EE >- 6 6 6  6 2 77 6 6s  B;h0=g2>Ah0g5Ah0g8Ah0g;Ah0g>Ah0,h-Ah0?h A h0 hAh0h
Ah0&h'A:h0!h"A h0"h#Ch0(h)C(h0hCh0hC5h0hA
h0h"6h0h%h0(h()Ch00h+1Ch0=h.>5h05h08h0;h0>h0h0h0h0
h0h0h0h0h0h0h0h0"h0%h0(h0+h0.h0r   c                    K   d}t        |t              rt        j                         }n$t        |t              rt        j
                         }|r| j                  |       d{    yy7 w)z)Handle user speaking interruption frames.N)r   r(   r   UserStartedSpeakingMessager)   UserStoppedSpeakingMessager   r   r   r   s      rH   r   z"RTVIObserver._handle_interruptions  s\     e56557G78557G((111 1   A"A-$A+%A-c                    K   d}t        |t              rt        j                         }n$t        |t              rt        j
                         }|r| j                  |       d{    yy7 w)zHandle user mute/unmute frames.N)r   r&   r   UserMuteStartedMessager'   UserMuteStoppedMessager   r   s      rH   r   zRTVIObserver._handle_user_mute  s\     e12113G34113G((111 1r   c                   K   t        |t              ryt        j                         }| j	                  |       d{    | j
                  D ]  }| j                  |       d{     | j
                  j                          d| _        yt        |t              r5t        j                         }| j	                  |       d{    d| _        yy7 7 p7 w)z!Handle bot speaking event frames.NTF)r   r   r   BotStartedSpeakingMessager   rx   _send_aggregated_llm_textclearrw   r   BotStoppedSpeakingMessage)r   r   r   queued_frames       rH   r   z!RTVIObserver._handle_bot_speaking  s     e45446G((111 $ C C C44\BBBC//557$(D!67446G((111$)D! 8 2 C
 2s4   9CC'C#C$A CCCCCc                    K   | j                   r| j                  |       d{    y| j                  j                  |       y7 !w)z)Handle aggregated LLM text output frames.N)rw   r   rx   r   )r   r   s     rH   r   z(RTVIObserver._handle_aggregated_llm_text  s>       00777 //66u= 8s   !AA"Ac                   K   | j                   j                  r#|j                  | j                   j                  v ry|j                  }|j                  }| j                  D ]!  \  }}||k(  s|dk(  s |||       d{   }# t        |t              }| j                   j                  rEt        j                  t        j                  |||            }| j                  |       d{    |r[| j                   j                  rDt        j                  t        j                  |            }| j                  |       d{    yyy7 7 d7 w)z"Send aggregated LLM text messages.Nr^   )r   spokenaggregated_byr   r   )rp   rZ   r   r   r   r   r%   rK   r   BotOutputMessageBotOutputMessageDatar   rM   BotTTSTextMessager   )	r   r   r   r   r   	transformisTTSr   tts_messages	            rH   r   z&RTVIObserver._send_aggregated_llm_text  s)     LL..##t||'I'IIzz&&+/+G+G 	7'i8+/?3/F&tX66	7 5,/<<**++..DV^_G ((111T\\1100d6J6JPT6UVK((555 25 7 2 6s>   A.E1E=E>A,E*E+AEEEEEc                   K   t        j                  t        j                  |j                              }| j	                  |       d{    | xj
                  |j                  z  c_        t        | j
                        rlt        | j
                        dkD  rS| j	                  t        j                  t        j                  | j
                                     d{    d| _        yyy7 7 w)zHandle LLM text output frames.r   r   Nr   rk   )	r   BotLLMTextMessager   r   r   rt   r6   lenBotTranscriptionMessager   s      rH   r   z#RTVIObserver._handle_llm_text_frame.  s     ((d.B.B

.ST$$W--- 	5::-t667C@W@W<X[\<\((,,--43J3JK  
 ')D# =]7 	.s%   A	C5C1BC5"C3#C53C5c                   K   d}t        |t              rLt        j                  t        j                  |j
                  |j                  |j                  d            }n[t        |t              rKt        j                  t        j                  |j
                  |j                  |j                  d            }|r| j                  |       d{    yy7 w)z!Handle user transcription frames.NT)r   user_id	timestampfinalr   F)
r   r!   r   UserTranscriptionMessageUserTranscriptionMessageDatar   r   r   r   r   r   s      rH   r   z(RTVIObserver._handle_user_transcriptions>  s     e/03366U]]eoo]aG
 893366U]]eoo]bG ((111 1s   CCCCc                 >  K   	 t        |t              r|j                  j                  }n|j                  j	                         }|sy|d   }t        |d      r|j                  dk(  rtt        |d      rhdj                  d |j                  D              }|rt        j                  t        j                  |      	      }| j                  |       d{    yt        |t              r}|d   dk(  rt|d
   }t        |t              rdj                  d |D              }n|}t        j                  t        j                  |      	      }| j                  |       d{    yyyy7 7 
# t        $ r"}t!        j"                  d|        Y d}~yd}~ww xY ww)zHProcess LLM context frames to extract user messages for the RTVI client.Nroleuserpartsrk   c              3   N   K   | ]  }t        |d       s|j                    ywr   N)hasattrr   ).0parts     rH   	<genexpr>z/RTVIObserver._handle_context.<locals>.<genexpr>`  s     \TgdTZF[tyy\s   %%r   r   content c              3   0   K   | ]  }d |v s|d      ywr  rF   )r  items     rH   r	  z/RTVIObserver._handle_context.<locals>.<genexpr>j  s     '[FVZNV'[s   	
z0Caught an error while trying to handle context: )r   r0   contextmessagesget_messagesr  r  joinr  r   UserLLMTextMessager   r   dictrc   	Exceptionr   warning)r   r   r  r   r   rtvi_messager
  es           rH   r   zRTVIObserver._handle_contextQ  sh    	S%!67 ==11 ==557rlG w'GLLF,BwwX_G`ww\W]]\\#'#:#:@T@TZ^@_#`L00>>> GT*6?f,%i0G!'40"xx'['[[&#'#:#:@T@TZ^@_#`L00>>> - + > ? 	SNNMaSQRR	Ssm   FAE/ FBE/ E+E/ FBE/ "E-#E/ 'F+E/ -E/ /	F8FFFFc                   K   i }|j                   D ]  }t        |t              r.d|vrg |d<   |d   j                  |j	                  d             Bt        |t
              r.d|vrg |d<   |d   j                  |j	                  d             t        |t              r8d|vrg |d<   |d   j                  |j                  j	                  d             t        |t              sd|vrg |d<   |d   j                  |j	                  d              t        j                  |      }| j                  |       d{    y7 w)	z;Handle metrics frames and convert to RTVI metrics messages.ttfbT)r   
processingtokens
charactersr   N)r   r   r,   r   
model_dumpr+   r*   r   r-   r   MetricsMessager   )r   r   metricsdr   s        rH   r   zRTVIObserver._handle_metricss  s6     	NA!_-(&(GFO&&q|||'FGA45w.,.GL)%,,Q\\t\-LMA237*(*GH%!(();););)NOA23w.,.GL)%,,Q\\t\-LM!	N$ %%73$$W---s   C'E*AEE
Ec                   K   t        j                  t        |j                  j                        t        j
                  |j                  j                  |j                              }| j                  |       d{    y7 w)5Send a response to the client for a specific request.)tr   r   r   N)	r   ServerResponserd   
client_msgmsg_idRawServerResponseDatatyper   r   r   s      rH   r   z"RTVIObserver._send_server_response  s`     %%5##**+++e.>.>.C.CuzzR
 $$W---s   A<B>B?Bc                    K   t        j                  t        |j                  j                        t        j
                  |j                              }| j                  |       d{    y7 w)r"  )r   r$  N)r   ErrorResponserd   r&  r'  ErrorResponseDatar   r   r   s      rH   r   z!RTVIObserver._send_error_response  sQ     $$5##**+$2H2Hu{{2[
 $$W---s   A'A1)A/*A1)N)r^   )T),r>   r?   r@   rA   r   rJ   rn   r   rd   r   r   r   r   r2   r   r   r9   r   rz   r   r   ra   r   r/   r   r   r   r   r   r   r   r   r   r   r   r0   r   r   r    r   r4   r   r   __classcell__)r   s   @rH   rg   rg      s   	 +/,5 04	,5',5 +,	,5b 36T$c?S+@%A9S>%QRT *C/T& 36
$c?S+@%A9S>%QR
 *C/
"* *	.N 	.AS AE` A.
2IY Id I[, [,z	2 	2	2U 	2* *>7J >65H 64), ) 2u 2& S+@?+R  SD.< .0.1H ..0G .rG   rg   )PrA   r   dataclassesr   r   enumr   typingr   r   r   r	   r
   r   r   r   logurur   pydanticr   )pipecat.processors.frameworks.rtvi.models
processors
frameworksri   modelsr   pipecat.audio.utilsr   pipecat.frames.framesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   pipecat.metrics.metricsr*   r+   r,   r-   pipecat.observers.base_observerr.   r/   1pipecat.processors.aggregators.openai_llm_contextr0   "pipecat.processors.frame_processorr1   r2   )pipecat.processors.frameworks.rtvi.framesr3   r4   pipecat.transports.base_outputr5   pipecat.utils.stringr6   ,pipecat.processors.frameworks.rtvi.processorr7   rd   r9   rJ   rg   rF   rG   rH   <module>rA     s    N  ( 	 	 	   8 8 6      6  F S M ? 4J#t $ L L L^k.< k.rG   