Ë
    òÏjÁ  ã                  óô   — 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y)é    )Ú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                  óD   — e Zd ZU dZded<   ded<   ded<   ded<   ded	<   y
)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__© ó    úO/var/www/html/gaurav-v2/venv/lib/python3.12/site-packages/langgraph/graph/ui.pyr   r      s%   … ñð ÓØƒGØ
ƒIØÓØÔr"   r   c                  ó&   — e Zd ZU dZded<   ded<   y)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   +   s   … ñð ÓØ„Gr"   r   NÚuiF)r   r   ÚmessageÚ	state_keyÚmergec               ó¼  — ddl m} t        «       }t        «       }	d}
|r>t	        |t
        «      rd|v r|j                  d«      }
nt        |d«      r|j                  }
d|xs t        t        «       «      | |||	j                  dd«      |	j                  dd«      |	j                  dd«      d	œ|xs 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(   r,   r-   r   Ú
message_id)r   r   r   r   r   )Úlanggraph._internal._constantsr+   r   r
   Ú
isinstanceÚdictÚgetÚhasattrr   r   r   r   )r   r   r   r   r&   r'   r(   r+   ÚwriterÚconfigr/   Úevts               r#   r   r   =   sï   € õL ?äÓ €FÜ‹\€Fà€JÙÜ�gœtÔ$¨°©Ø Ÿ™ TÓ*‰JÜ�W˜dÔ#Ø Ÿ™ˆJð ØÒ ”Cœ›“LØØàØ—j‘j ¨4Ó0Ø—J‘J˜v tÓ,Ø—J‘J˜z¨4Ó0ñ	
ð
 Š~˜2ð
ñ .8�˜jÑ)¸Rð
ñ€Cñ ˆ3„KÙØ%ˆŒt‰�_Ñ%¨	°3Ð'7Ð&8Ô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   )r0   r+   r   r
   r   )r   r'   r+   r5   r6   r7   s         r#   r   r   …   sG   € õ& ?äÓ €FÜ‹\€Fà$/°rÑ:€Cá
ˆ3„KØ!€FŒ4�L�Ñ! I¨sÐ#3Ð"4Ô5à€Jr"   c                ó8  — t        | t        «      s| g} t        |t        «      s|g}| j                  «       }t        |«      D ��ci c]  \  }}|j	                  d«      |“Œ }}}t        «       }|D ]ù  }|j	                  d«      }|j	                  |«      x}	�‘|j	                  d«      dk(  r|j                  |«       ŒM|j                  |«       t        t        |«      j	                  di «      j	                  dd«      r$||	   }
|j                  «       }i |
d   ¥|d   ¥|d<   |||	<   Œ¸|j	                  d«      dk(  rt        d|› d	�«      ‚t        |«      ||<   |j                  |«       Œû |D �cg c]  }|j	                  d«      |vsŒ|‘Œ }}|S c c}}w c c}w )
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"},
        )
        ```

    r   r   r9   r   r(   Fr   zCAttempting to delete an UI message with an ID that doesn't exist ('z'))r1   ÚlistÚcopyÚ	enumerater3   ÚsetÚaddÚdiscardr   r   Ú
ValueErrorÚlenÚappend)ÚleftÚrightÚmergedÚiÚmÚmerged_by_idÚids_to_removeÚmsgÚmsg_idÚexisting_idxÚprev_msgs              r#   r   r   ¥   s›  € ô4 �dœDÔ!Øˆvˆä�eœTÔ"Ø�ˆð �Y‰Y‹[€FÜ/8¸Ô/@ÔAÑ/@¡t q¨!�A—E‘E˜$“K ‘NÐ/@€LÑAÜ“E€MãˆØ—‘˜“ˆà(×,Ñ,¨VÓ4Ð4ˆLÐAØ�w‰w�v‹ +Ò-Ø×!Ñ! &Õ)à×%Ñ% fÔ-äœ	 3Ó'×+Ñ+¨J¸Ó;×?Ñ?ÀÈÔOØ% lÑ3�HØŸ(™(›*�CØ#H h¨wÑ&7Ð#H¸3¸w¹<Ð#H�C˜‘Là'*��|Ò$à�w‰w�v‹ +Ò-Ü ØYÐZ`ÐYaÐacÐdóð ô $' v£;ˆL˜Ñ Ø�M‰M˜#Õð- ñ0  ÓD™�A 1§5¡5¨£;°mÒ#CŠa˜€FÐDØ€Mùó9 Bùò6 Es   ÁFÅ0FÆ	F)r   r   r   r   r   ú
str | Noner   zdict[str, Any] | Noner&   zAnyMessage | Noner'   rO   r(   ÚboolÚreturnr   )r   r   r'   r   rQ   r   )rD   ú!list[AnyUIMessage] | AnyUIMessagerE   rR   rQ   zlist[AnyUIMessage])Ú
__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>r[      sÞ   ðÝ "ç %Ñ %Ý å .Ý 'ç :Ý $ð€ô�	ô ô*�iô ð ˜?Ñ*€ð Ø&*Ø!%Ø ØñEØ
ðEàðEð 	ð	Eð
 $ðEð ðEð ðEð ðEð óEðP 48õ ð@>Ø
+ð>à,ð>ð ô>r"   