
    qig                         d Z ddlmZmZmZ ddlmZ ddlmZ ddl	m
Z
mZmZ ddlmZmZ  G d de      Z G d	 d
e      Z G d de
      Z G d de      Zy)zGoogle RTVI processor and observer implementation.

This module provides integration with Google's services through the RTVI framework,
including models for search responses and an observer for handling Google-specific
frame types.
    )ListLiteralOptional)	BaseModel)FramePushed)RTVIObserverRTVIObserverParamsRTVIProcessor)LLMSearchOriginLLMSearchResponseFramec                   B    e Zd ZU dZee   ed<   ee   ed<   ee   ed<   y)RTVISearchResponseMessageDataa  Data payload for search response messages in RTVI protocol.

    Parameters:
        search_result: The search result text, if available.
        rendered_content: The rendered content from the search, if available.
        origins: List of search result origins with metadata.
    search_resultrendered_contentoriginsN)	__name__
__module____qualname____doc__r   str__annotations__r   r        N/opt/pipecat/venv/lib/python3.12/site-packages/pipecat/services/google/rtvi.pyr   r      s(     C= sm#/""r   r   c                   D    e Zd ZU dZdZed   ed<   dZed   ed<   eed<   y)RTVIBotLLMSearchResponseMessagezRTVI message for bot LLM search responses.

    Parameters:
        label: Always "rtvi-ai" for RTVI protocol messages.
        type: Always "bot-llm-search-response" for this message type.
        data: The search response data payload.
    zrtvi-ailabelzbot-llm-search-responsetypedataN)	r   r   r   r   r   r   r   r   r   r   r   r   r   r   %   s.     !*E79)/HD'+
,H
''r   r   c                   D     e Zd ZdZdef fdZdef fdZdefdZ	 xZ
S )GoogleRTVIObserverzRTVI observer for Google service integration.

    Extends the base RTVIObserver to handle Google-specific frame types,
    particularly LLM search response frames from Google services.
    rtvic                 $    t         |   |       y)z{Initialize the Google RTVI observer.

        Args:
            rtvi: The RTVI processor to send messages through.
        N)super__init__)selfr"   	__class__s     r   r%   zGoogleRTVIObserver.__init__:   s     	r   r   c                    K   t         |   |       d{    |j                  }t        |t              r| j                  |       d{    yy7 ;7 w)zProcess frames being pushed through the pipeline.

        Handles Google-specific frames in addition to the base RTVI frame types.

        Args:
            data: Frame push event data containing frame and metadata.
        N)r$   on_push_frameframe
isinstancer   !_handle_llm_search_response_frame)r&   r   r*   r'   s      r   r)   z GoogleRTVIObserver.on_push_frameB   sU      g#D)))

e3488??? 5	 	*
 @s!   AA4AAAAr*   c                    K   t        t        |j                  |j                  |j                              }| j                  |       d {    y 7 w)N)r   r   r   )r   )r   r   r   r   r   send_rtvi_message)r&   r*   messages      r   r,   z4GoogleRTVIObserver._handle_llm_search_response_frameQ   sG     1.#11!&!7!7
 $$W---s   AAAA)r   r   r   r   r
   r%   r   r)   r   r,   __classcell__)r'   s   @r   r!   r!   3   s/    ] @ @.=S .r   r!   c                   (    e Zd ZdZdddee   fdZy)GoogleRTVIProcessorzaRTVI processor for Google service integration.

    Creates a specific Google RTVI Observer.
    N)paramsr3   c                    t        |       S )zCreates a new RTVI Observer.

        Args:
            params: Settings to enable/disable specific messages.
            **kwargs: Additional arguments passed to the observer.

        Returns:
            A new RTVI observer.
        )r!   )r&   r3   kwargss      r   create_rtvi_observerz(GoogleRTVIProcessor.create_rtvi_observerb   s     "$''r   )r   r   r   r   r   r	   r6   r   r   r   r2   r2   \   s     
 NR 
(h7I.J 
(r   r2   N)r   typingr   r   r   pydanticr   pipecat.observers.base_observerr   "pipecat.processors.frameworks.rtvir   r	   r
   pipecat.services.google.framesr   r   r   r   r!   r2   r   r   r   <module>r<      sR    + *  7 ^ ^ R#I #(i (&. &.R(- (r   