
    9i              	           d dl Zd dl mZmZ d dlmZ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mZ d dlmZmZmZmZ d d	lmZ d
Zd Zdedeeef   fdZ G d dee   eeeef         Zy)    N)CallableSequence)AnyGeneric)NotRequiredRequiredSelf)	OVERWRITE)MISSING)BaseChannelValue)EmptyChannelError	ErrorCodeInvalidUpdateErrorcreate_error_message)	Overwrite)BinaryOperatorAggregatec                     t        | d      rt        | j                        S t        | d      r0| j                  t        t        fv rt        | j
                  d         S | S )z=Strips Annotated, Required and NotRequired from a given type.
__origin__r   )hasattr_strip_extrasr   r   r   __args__)ts    b/var/www/html/backtest/airagagent/rag_env/lib/python3.12/site-packages/langgraph/channels/binop.pyr   r      sM    q,Q\\**q,ALLX{4K$KQZZ]++H    valuereturnc                     t        | t              rd| j                  fS t        | t              r,t	        | j                               t        hk(  rd| t           fS y)zEInspects the given value and returns (is_overwrite, overwrite_value).T)FN)
isinstancer   r   dictsetkeysr
   r   s    r   _get_overwriter$       sL    %#U[[  %3uzz|#4#CU9%%%r   c                        e Zd ZdZdZdee   deeegef   f fdZde	de
fdZedee   fd	       Zedee   fd
       ZdefdZdedefdZdee   de
fdZdefdZde
fdZdefdZ xZS )r   zStores the result of applying a binary operator to the current value and each new value.

    ```python
    import operator

    total = Channels.BinaryOperatorAggregate(int, operator.add)
    ```
    )r   operatortypr&   c                    t         |   |       || _        t        |      }|t        j
                  j                  t        j
                  j                  fv rt        }|t        j
                  j                  t        j
                  j                  fv rt        }|t        j
                  j                  t        j
                  j                  fv rt        }	  |       | _        y # t         $ r t"        | _        Y y w xY wN)super__init__r&   r   collectionsabcr   MutableSequencelistSet
MutableSetr!   MappingMutableMappingr    r   	Exceptionr   )selfr'   r&   	__class__s      r   r+   z BinaryOperatorAggregate.__init__5   s      C ;??++[__-L-LMMC;??&&(B(BCCC;??**KOO,J,JKKC	!DJ 	! DJ	!s   C% %C<;C<r   r   c                     t        |t              xrL |j                  j                  dk7  r1| j                  j                  dk7  r|j                  | j                  u S dS )Nz<lambda>T)r   r   r&   __name__)r5   r   s     r   __eq__zBinaryOperatorAggregate.__eq__F   sW    %!89 
~~&&*4&&*4 NNdmm+	
 		
r   c                     | j                   S )z,The type of the value stored in the channel.r'   r5   s    r   	ValueTypez!BinaryOperatorAggregate.ValueTypeN        xxr   c                     | j                   S )z/The type of the update received by the channel.r;   r<   s    r   
UpdateTypez"BinaryOperatorAggregate.UpdateTypeS   r>   r   c                     | j                  | j                  | j                        }| j                  |_        | j                  |_        |S )zReturn a copy of the channel.)r6   r'   r&   keyr   )r5   emptys     r   copyzBinaryOperatorAggregate.copyX   s5    txx7HH	jjr   
checkpointc                     | j                  | j                  | j                        }| j                  |_        |t        ur||_        |S r)   )r6   r'   r&   rB   r   r   )r5   rE   rC   s      r   from_checkpointz'BinaryOperatorAggregate.from_checkpoint_   s9    txx7HH	W$$EKr   valuesc                 *   |sy| j                   t        u r|d   | _         |dd  }d}|D ]h  }t        |      \  }}|r2|r&t        dt        j
                        }t        |      || _         d}E|rH| j                  | j                   |      | _         j y)NFr      z4Can receive only one Overwrite value per super-step.)message
error_codeT)r   r   r$   r   r   INVALID_CONCURRENT_GRAPH_UPDATEr   r&   )r5   rH   seen_overwriter   is_overwriteoverwrite_valuemsgs          r   updatezBinaryOperatorAggregate.updatef   s    :: DJABZF$ 	>E,:5,A)L/!. V#,#L#LC -S11,
!%!!]]4::u=
	> r   c                 R    | j                   t        u r
t               | j                   S r)   )r   r   r   r<   s    r   getzBinaryOperatorAggregate.get}   s!    :: #%%zzr   c                 &    | j                   t        uS r)   )r   r   r<   s    r   is_availablez$BinaryOperatorAggregate.is_available   s    zz((r   c                     | j                   S r)   r#   r<   s    r   rE   z"BinaryOperatorAggregate.checkpoint   s    zzr   )r8   
__module____qualname____doc__	__slots__typer   r   r+   objectboolr9   propertyr=   r@   r	   rD   rG   r   rR   rT   rV   rE   __classcell__)r6   s   @r   r   r   )   s     &I!DK !8UENE<Q3R !"
F 
t 
 4;   DK  d % D Xe_  .U 
)d )E r   r   )collections.abcr,   r   r   typingr   r   typing_extensionsr   r   r	   langgraph._internal._constantsr
   langgraph._internal._typingr   langgraph.channels.baser   r   langgraph.errorsr   r   r   r   langgraph.typesr   __all__r   tupler^   r$   r    r   r   <module>rl      sr     .  9 9 4 / 6  &
&# %c	"2 ]genk%:M.N ]r   