
    <i                        S SK Jr  S SKJrJrJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJrJr  S SKJr  Sr " S	 S
\5      r " S S\5      r\\-  rSSSSSS.               SS jjrSS.SS jjr      SS jrg)    )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                  L    \ rS rSr% SrS\S'   S\S'   S\S'   S\S	'   S\S
'   Srg)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metadata N__name__
__module____qualname____firstlineno____doc____annotations____static_attributes__r       b/home/dmtnaga/Documents/work/airagagent/rag_env/lib/python3.13/site-packages/langgraph/graph/ui.pyr   r      s%     G
Ir%   r   c                  .    \ rS rSr% SrS\S'   S\S'   Srg)	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   r   Nr   r   r%   r&   r   r   +   s     Gr%   r   NuiF)r   r   message	state_keymergec                  SSK Jn  [        5       n[        5       n	Sn
U(       aJ  [	        U[
        5      (       a  SU;   a  UR                  S5      n
O[        US5      (       a  UR                  n
SU=(       d    [        [        5       5      U UUU	R                  SS5      U	R                  SS5      U	R                  SS5      S	.U=(       d    0 EU
(       a  S
U
0O0 ES.nU" U5        U(       a  U	[           U   " X[4/5        U$ )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.
        Defaults to "ui".
    merge: Whether to merge props with existing UI message (True) or replace
        them (False). Defaults to 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,   r0   r1   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configr3   evts               r&   r   r   =   s    N ? F\FJgt$$ T*JWd## J  CLjj40JJvt,JJz40	

 ~2
 .8j)R
C 3Kt_%	'7&89Jr%   )r+   c               |    SSK Jn  [        5       n[        5       nSU S.nU" U5        U[           U   " X4/5        U$ )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   )r4   r/   r   r
   r   )r   r+   r/   r9   r:   r;   s         r&   r   r      sC    & ? F\F$/r:C
3K
4L!I#3"45Jr%   c                p   [        U [        5      (       d  U /n [        U[        5      (       d  U/nU R                  5       n[        U5       VVs0 s H  u  p4UR	                  S5      U_M     nnn[        5       nU GH  nUR	                  S5      nUR	                  U5      =n	b  UR	                  S5      S:X  a  UR                  U5        MQ  UR                  U5        [        [        U5      R	                  S0 5      R	                  SS5      (       a#  X)   n
UR                  5       n0 U
S   EUS   EUS'   XrU	'   M  UR	                  S5      S:X  a  [        SU S	35      e[        U5      XX'   UR                  U5        GM     U Vs/ s H  oDR	                  S5      U;  d  M  UPM     nnU$ s  snnf s  snf )
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   r=   r   r,   Fr   zCAttempting to delete an UI message with an ID that doesn't exist ('z'))r5   listcopy	enumerater7   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 dD!!veT"" YY[F/8/@A/@tqAEE$KN/@LAEM(,,V44LAwwv+-!!&)%%f-	3'++J;??OO%3H((*C#Hhw&7#H3w<#HCL'*|$wwv+- YZ`Yaacd  $'v;L MM#- 0  DA55;m#CaFDM9 B6 Es   F-F3#F3)r   r   r   r   r   
str | Noner   zdict[str, Any] | Noner*   zAnyMessage | Noner+   rS   r,   boolreturnr   )r   r   r+   r   rU   r   )rH   !list[AnyUIMessage] | AnyUIMessagerI   rV   rU   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  ?* &*!% F
FF 		F
 $F F F F FR 48 @>
+>,> >r%   