
    A'h&                         d dl mZ d dlmZmZ d dlmZ d dlmZm	Z	 d dl
mZ d dlmZmZmZmZ  G d dee	   ee	e	e	f         Z G d	 d
ee	   ee	e	ee	ef   f         Zy)    )Sequence)AnyGeneric)Self)BaseChannelValue)MISSING)EmptyChannelError	ErrorCodeInvalidUpdateErrorcreate_error_messagec                        e Zd ZdZdZddededd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 )	LastValuezGStores the last value received, can receive at most one value per step.valuetypkeyreturnNc                 <    t         |   ||       t        | _        y N)super__init__r	   r   selfr   r   	__class__s      d/home/kushmeetdev/Regenta/Chatbot/venv/lib/python3.12/site-packages/langgraph/channels/last_value.pyr   zLastValue.__init__   s    c"
    r   c                 "    t        |t              S r   )
isinstancer   r   r   s     r   __eq__zLastValue.__eq__   s    %++r   c                     | j                   S z,The type of the value stored in the channel.r   r   s    r   	ValueTypezLastValue.ValueType        xxr   c                     | j                   S z/The type of the update received by the channel.r$   r%   s    r   
UpdateTypezLastValue.UpdateType!   r'   r   c                 t    | j                  | j                  | j                        }| j                  |_        |S )zReturn a copy of the channel.)r   r   r   r   )r   emptys     r   copyzLastValue.copy&   s*    txx2jjr   
checkpointc                 p    | j                  | j                  | j                        }|t        ur||_        |S r   )r   r   r   r	   r   r   r.   r,   s      r   from_checkpointzLastValue.from_checkpoint,   s.    txx2W$$EKr   valuesc                     t        |      dk(  ryt        |      dk7  r4t        d| j                   dt        j                        }t        |      |d   | _        y)	Nr   F   zAt key 'zW': Can receive only one value per step. Use an Annotated key to handle multiple values.)message
error_codeT)lenr   r   r   INVALID_CONCURRENT_GRAPH_UPDATEr   r   )r   r2   msgs      r   updatezLastValue.update2   sb    v;!v;!&"488*  -D  E$DDC %S))BZ
r   c                 R    | j                   t        u r
t               | j                   S r   )r   r	   r
   r%   s    r   getzLastValue.get?   s!    :: #%%zzr   c                 &    | j                   t        uS r   )r   r	   r%   s    r   is_availablezLastValue.is_availableD   s    zz((r   c                     | j                   S r   r   r%   s    r   r.   zLastValue.checkpointG   s    zzr    )__name__
__module____qualname____doc__	__slots__r   strr   objectboolr!   propertytyper   r&   r*   r   r-   r1   r   r;   r=   r?   r.   __classcell__r   s   @r   r   r      s    QIC c 4 ,F ,t , 4;   DK  d % D Xe_  U 
)d )E r   r   c                        e Zd ZdZdZddededd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ee	f   fdZdeee	f   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de	fdZ xZS )LastValueAfterFinishzrStores the last value received, but only made available after finish().
    Once made available, clears the value.)r   finishedr   r   r   Nc                 J    t         |   ||       t        | _        d| _        y )NF)r   r   r	   r   rQ   r   s      r   r   zLastValueAfterFinish.__init__S   s     c"
r   r   c                 "    t        |t              S r   )r   rP   r    s     r   r!   zLastValueAfterFinish.__eq__X   s    %!566r   c                     | j                   S r#   r$   r%   s    r   r&   zLastValueAfterFinish.ValueType[   r'   r   c                     | j                   S r)   r$   r%   s    r   r*   zLastValueAfterFinish.UpdateType`   r'   r   c                 b    | j                   t        u rt        S | j                   | j                  fS r   r   r	   rQ   r%   s    r   r.   zLastValueAfterFinish.checkpointe   s&    :: N

DMM**r   r.   c                     | j                  | j                        }| j                  |_        |t        ur|\  |_        |_        |S r   )r   r   r   r	   r   rQ   r0   s      r   r1   z$LastValueAfterFinish.from_checkpointj   s:    txx(HH	W$*4'EKr   r2   c                 D    t        |      dk(  ryd| _        |d   | _        y)Nr   Fr7   T)r8   rQ   r   )r   r2   s     r   r;   zLastValueAfterFinish.updateq   s&    v;!BZ
r   c                 B    | j                   rd| _         t        | _        yy)NFT)rQ   r	   r   r%   s    r   consumezLastValueAfterFinish.consumey   s    ==!DM DJr   c                 P    | j                   s| j                  t        urd| _         yy)NTF)rQ   r   r	   r%   s    r   finishzLastValueAfterFinish.finish   s!    }}7!: DMr   c                 j    | j                   t        u s| j                  s
t               | j                   S r   )r   r	   rQ   r
   r%   s    r   r=   zLastValueAfterFinish.get   s'    :: #%%zzr   c                 B    | j                   t        uxr | j                  S r   rW   r%   s    r   r?   z!LastValueAfterFinish.is_available   s    zz(:T]]:r   rA   )rC   rD   rE   rF   rG   r   rH   r   rI   rJ   r!   rK   rL   r   r&   r*   tupler.   r   r1   r   r;   r[   r]   r=   r?   rM   rN   s   @r   rP   rP   K   s    . &IC c 4 
7F 7t 7 4;   DK  +E%+. +
%t*<  Xe_    U 
;d ;r   rP   N)collections.abcr   typingr   r   typing_extensionsr   langgraph.channels.baser   r   langgraph.constantsr	   langgraph.errorsr
   r   r   r   r   r`   rJ   rP    r   r   <module>rh      sg    $  " 6 ' 8E5%,? @ 8vC;ENKueE4K.@ @AC;r   