§
    šŠtjÁ  ã                  óØ   — d dl m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 d dlmZmZ d dlmZ dZ G d	„ d
e¦  «        Z G d„ de¦  «        Zeez  Zddddddœd'd„Zdd œd(d!„Zd)d&„ZdS )*é    )Úannotations)ÚAnyÚLiteralÚcast)Úuuid4)Ú
AnyMessage)Ú	TypedDict)Ú
get_configÚget_stream_writer)ÚCONF)Ú	UIMessageÚRemoveUIMessageÚAnyUIMessageÚpush_ui_messageÚdelete_ui_messageÚui_message_reducerc                  óF   — e Zd ZU dZded<   ded<   ded<   ded<   ded	<   d
S )r   aú  A message type for UI updates in LangGraph.

    This TypedDict represents a UI message that can be sent to update the UI state.
    It contains information about the UI component to render and its properties.

    Attributes:
        type: Literal type indicating this is a UI message.
        id: Unique identifier for the UI message.
        name: Name of the UI component to render.
        props: Properties to pass to the UI component.
        metadata: Additional metadata about the UI message.
    zLiteral['ui']ÚtypeÚstrÚidÚnameúdict[str, Any]ÚpropsÚmetadataN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__© ó    úP/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langgraph/graph/ui.pyr   r      sT   € € € € € € ðð ð ÐÐÑØ€G€G�GØ€I€I�IØÐÐÑØÐÐÑÐÐr"   r   c                  ó(   — e Zd ZU dZded<   ded<   dS )r   a:  A message type for removing UI components in LangGraph.

    This TypedDict represents a message that can be sent to remove a UI component
    from the current state.

    Attributes:
        type: Literal type indicating this is a remove-ui message.
        id: Unique identifier of the UI message to remove.
    zLiteral['remove-ui']r   r   r   Nr   r!   r"   r#   r   r   +   s1   € € € € € € ðð ð ÐÐÑØ€G€G�G€G€Gr"   r   NÚuiF)r   r   ÚmessageÚ	state_keyÚmerger   r   r   r   r   ú
str | Noner   údict[str, Any] | Noner&   úAnyMessage | Noner'   r(   ÚboolÚreturnc               ó  — ddl m} t          ¦   «         }t          ¦   «         }	d}
|rFt	          |t
          ¦  «        rd|v r|                     d¦  «        }
nt          |d¦  «        r|j        }
d|pt          t          ¦   «         ¦  «        | |||	                     dd¦  «        |	                     dd¦  «        |	                     dd¦  «        d	œ|pi ¥|
rd
|
ini ¥dœ} ||¦  «         |r |	t                   |         ||fg¦  «         |S )aÅ  Push a new UI message to update the UI state.

    This function creates and sends a UI message that will be rendered in the UI.
    It also updates the graph state with the new UI message.

    Args:
        name: Name of the UI component to render.
        props: Properties to pass to the UI component.
        id: Optional unique identifier for the UI message.
            If not provided, a random UUID will be generated.
        metadata: Optional additional metadata about the UI message.
        message: Optional message object to associate with the UI message.
        state_key: Key in the graph state where the UI messages are stored.
        merge: Whether to merge props with existing UI message (True) or replace
            them (False).

    Returns:
        The created UI message.

    Example:
        ```python
        push_ui_message(
            name="component-name",
            props={"content": "Hello world"},
        )
        ```

    r   ©ÚCONFIG_KEY_SENDNr   r%   Úrun_idÚtagsÚrun_name)r(   r1   r2   r   Ú
message_id)r   r   r   r   r   )Úlanggraph._internal._constantsr0   r   r
   Ú
isinstanceÚdictÚgetÚhasattrr   r   r   r   )r   r   r   r   r&   r'   r(   r0   ÚwriterÚconfigr4   Úevts               r#   r   r   =   sK  € ðL ?Ð>Ð>Ð>Ð>Ð>åÑ Ô €FÝ‰\Œ\€Fà€JØð $Ý�g�tÑ$Ô$ð 	$¨°¨¨Ø Ÿš TÑ*Ô*ˆJˆJÝ�W˜dÑ#Ô#ð 	$Ø œˆJð ØÐ •C�™œ‘L”LØØàØ—j’j ¨4Ñ0Ô0Ø—J’J˜v tÑ,Ô,Ø—J’J˜z¨4Ñ0Ô0ð	
ð 
ð
 ˆ~˜2ð
ð .8Ð?�˜jÐ)Ð)¸Rð
ðð €Cð €Fˆ3�K„K€KØð :Ø%ˆ�tŒ�_Ô%¨	°3Ð'7Ð&8Ñ9Ô9Ð9à€Jr"   )r'   c               ó¨   — ddl m} t          ¦   «         }t          ¦   «         }d| dœ} ||¦  «          |t                   |         ||fg¦  «         |S )aø  Delete a UI message by ID from the UI state.

    This function creates and sends a message to remove a UI component from the current state.
    It also updates the graph state to remove the UI message.

    Args:
        id: Unique identifier of the UI component to remove.
        state_key: Key in the graph state where the UI messages are stored. Defaults to "ui".

    Returns:
        The remove UI message.

    Example:
        ```python
        delete_ui_message("message-123")
        ```

    r   r/   ú	remove-ui)r   r   )r5   r0   r   r
   r   )r   r'   r0   r:   r;   r<   s         r#   r   r   …   sj   € ð& ?Ð>Ð>Ð>Ð>Ð>åÑ Ô €FÝ‰\Œ\€Fà$/°rÐ:Ð:€Cà
€Fˆ3�K„K€KØ!€F�4„L�Ô! I¨sÐ#3Ð"4Ñ5Ô5Ð5à€Jr"   Úleftú!list[AnyUIMessage] | AnyUIMessageÚrightúlist[AnyUIMessage]c                óv  ‡— t          | t          ¦  «        s| g} t          |t          ¦  «        s|g}|                      ¦   «         }d„ t          |¦  «        D ¦   «         }t	          ¦   «         Š|D �]:}|                     d¦  «        }|                     |¦  «        x}�¸|                     d¦  «        dk    r‰                     |¦  «         Œ^‰                     |¦  «         t          t          |¦  «                             di ¦  «                             dd¦  «        r1||         }|                     ¦   «         }i |d	         ¥|d	         ¥|d	<   |||<   Œç|                     d¦  «        dk    rt          d
|› d�¦  «        ‚t          |¦  «        ||<   |                     |¦  «         �Œ<ˆfd„|D ¦   «         }|S )aÖ  Merge two lists of UI messages, supporting removing UI messages.

    This function combines two lists of UI messages, handling both regular UI messages
    and `remove-ui` messages. When a `remove-ui` message is encountered, it removes any
    UI message with the matching ID from the current state.

    Args:
        left: First list of UI messages or single UI message.
        right: Second list of UI messages or single UI message.

    Returns:
        Combined list of UI messages with removals applied.

    Example:
        ```python
        messages = ui_message_reducer(
            [{"type": "ui", "id": "1", "name": "Chat", "props": {}}],
            {"type": "remove-ui", "id": "1"},
        )
        ```

    c                ó@   — i | ]\  }}|                      d ¦  «        |“ŒS ©r   ©r8   )Ú.0ÚiÚms      r#   ú
<dictcomp>z&ui_message_reducer.<locals>.<dictcomp>Ç   s(   € ÐAÐAÐA¡t q¨!�A—E’E˜$‘K”K ÐAÐAÐAr"   r   Nr   r>   r   r(   Fr   zCAttempting to delete an UI message with an ID that doesn't exist ('z')c                óB   •— g | ]}|                      d ¦  «        ‰v¯|‘ŒS rE   rF   )rG   rI   Úids_to_removes     €r#   ú
<listcomp>z&ui_message_reducer.<locals>.<listcomp>â   s-   ø€ ÐDÐDÐD�A 1§5¢5¨¡;¤;°mÐ#CÐ#CˆaÐ#CÐ#CÐ#Cr"   )r6   ÚlistÚcopyÚ	enumerateÚsetr8   ÚaddÚdiscardr   r   Ú
ValueErrorÚlenÚappend)	r?   rA   ÚmergedÚmerged_by_idÚmsgÚmsg_idÚexisting_idxÚprev_msgrL   s	           @r#   r   r   ¥   sÏ  ø€ õ4 �d�DÑ!Ô!ð Øˆvˆå�e�TÑ"Ô"ð Ø�ˆð �YŠY‰[Œ[€FØAÐA­y¸Ñ/@Ô/@ÐAÑAÔA€LÝ‘E”E€Màð ñ ˆØ—’˜‘”ˆà(×,Ò,¨VÑ4Ô4Ð4ˆLÐAØ�wŠw�v‰Œ +Ò-Ð-Ø×!Ò! &Ñ)Ô)Ð)Ð)à×%Ò% fÑ-Ô-Ð-å�	 3Ñ'Ô'×+Ò+¨J¸Ñ;Ô;×?Ò?ÀÈÑOÔOð IØ% lÔ3�HØŸ(š(™*œ*�CØ#H h¨wÔ&7Ð#H¸3¸w¼<Ð#H�C˜‘Là'*��|Ñ$Ð$à�wŠw�v‰Œ +Ò-Ð-Ý ØdÐZ`ÐdÐdÐdñô ð õ $' v¡;¤;ˆL˜Ñ Ø�MŠM˜#ÑÔÐÑàDÐDÐDÐD˜ÐDÑDÔD€FØ€Mr"   )r   r   r   r   r   r)   r   r*   r&   r+   r'   r)   r(   r,   r-   r   )r   r   r'   r   r-   r   )r?   r@   rA   r@   r-   rB   )Ú
__future__r   Útypingr   r   r   Úuuidr   Úlangchain_core.messagesr   Útyping_extensionsr	   Úlanggraph.configr
   r   Úlanggraph.constantsr   Ú__all__r   r   r   r   r   r   r!   r"   r#   ú<module>re      st  ðØ "Ð "Ð "Ð "Ð "Ð "à %Ð %Ð %Ð %Ð %Ð %Ð %Ð %Ð %Ð %Ø Ð Ð Ð Ð Ð à .Ð .Ð .Ð .Ð .Ð .Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'à :Ð :Ð :Ð :Ð :Ð :Ð :Ð :Ø $Ð $Ð $Ð $Ð $Ð $ð€ðð ð ð ð �	ñ ô ð ð*ð ð ð ð �iñ ô ð ð ˜?Ñ*€ð Ø&*Ø!%Ø ØðEð Eð Eð Eð Eð EðP 48ð ð ð ð ð ð ð@>ð >ð >ð >ð >ð >r"   