
    }
i                        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__     C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\langgraph/graph/ui.pyr   r      sT           GGGIII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           GGGGGr"   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 $gt$$ 	$ T**JJWd## 	$ J  CLLjj400JJvt,,JJz400	
 

 ~2
 .8?j))R
 C F3KKK :%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
F3KKK!F4L!Is#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Atq!AEE$KK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DA155;;m#C#Ca#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 dD!! veT""  YY[[FAAy/@/@AAALEEM  (,,V444LAwwv+--!!&))))%%f---	3''++J;;??OO I%l3H((**C#Hhw&7#H3w<#HCL'*|$$wwv+-- dZ`ddd   $'v;;L MM#DDDDDDDF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"   