
    9i\              	      \   d dl mZ d dlZd dlZd dlZd dl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 dlmZ d dlmZ d dlmZmZmZmZ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%m&Z& d dl'm(Z( d dl)m*Z* d dl+m,Z,m-Z- d dl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZG d dlHmIZI d dlJmKZKmLZL d dlMmNZN d dlOmPZP d dlQmRZR d dlSmTZT d dlUmVZV d dlWmXZXmYZY d dlZm[Z[ d dl\m]Z] d dl^m_Z_m`Z` d dlambZbmcZc d dldmeZemfZfmgZgmhZhmiZimjZjmkZk e
e&dz  dge&f   Zlej                  dk\  Zn G d d e      Zo G d! d"e      Zp G d# d$      Zq	 	 	 	 	 	 	 	 d@d%Zr	 dA	 	 	 	 	 	 	 	 	 	 	 	 	 dBd&ZsdCd'Zt	 	 	 	 	 	 	 	 	 	 	 	 dDd(Zuedddddd)dd*	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dEd+       Zveddd)dd,	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dFd-       Zvdddddd)dd*	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dGd.ZveCfZw G d/ d0e      Zxdddddd)d1	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dHd2Zyddddd)d3	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dId4Zzddddd)d3	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dJd5Z{	 	 	 	 dKd6Z|	 	 	 	 	 	 	 	 	 	 	 	 dLd7Z}	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dMd8Z~	 	 	 	 	 	 	 	 	 	 	 	 	 	 dNd9ZdOd:ZdOd;ZdPd<Z ej                         Z G d= d>      Z	 	 	 	 	 	 dQd?Zy)R    )annotationsN)defaultdictdeque)CallableIterableMappingSequence)copy)partial)sha1)AnyLiteral
NamedTupleProtocolcastoverload)	Callbacks)AsyncParentRunManagerParentRunManager)RunnableConfig)BaseCheckpointSaverChannelVersions
CheckpointPendingWriteV)	BaseStore)xxh3_128_hexdigest)merge_configspatch_config)CACHE_NS_WRITESCONFCONFIG_KEY_CHECKPOINT_IDCONFIG_KEY_CHECKPOINT_MAPCONFIG_KEY_CHECKPOINT_NSCONFIG_KEY_CHECKPOINTERCONFIG_KEY_READCONFIG_KEY_RESUME_MAPCONFIG_KEY_RUNTIMECONFIG_KEY_SCRATCHPADCONFIG_KEY_SENDCONFIG_KEY_TASK_IDERROR	INTERRUPT	NO_WRITESNS_ENDNS_SEPNULL_TASK_IDPREVIOUSPULLPUSHRESERVEDRESUMERETURNTASKS)PregelScratchpad)	EMPTY_SEQMISSING)BaseChannel)Topic)UntrackedValue)
TAG_HIDDEN)ManagedValueMapping)get_runnable_for_task
identifier)read_channels)logger)INPUT_CACHE_KEY_TYPE
PregelNode)DEFAULT_RUNTIMERuntime)AllCacheKeyCachePolicyPregelExecutableTask
PregelTaskRetryPolicySend)      c                  X    e Zd ZdZedd       Zedd       Zed	d       Zed
d       Zy)WritesProtocolzProtocol for objects containing writes to be applied to checkpoint.
    Implemented by PregelTaskWrites and PregelExecutableTask.c                     y N selfs    `/var/www/html/backtest/airagagent/rag_env/lib/python3.12/site-packages/langgraph/pregel/_algo.pypathzWritesProtocol.path\   s    58    c                     y rU   rV   rW   s    rY   namezWritesProtocol.name_   s    r[   c                     y rU   rV   rW   s    rY   writeszWritesProtocol.writesb   s    36r[   c                     y rU   rV   rW   s    rY   triggerszWritesProtocol.triggerse   s    ),r[   N)returntuple[str | int | tuple, ...])rb   str)rb   Sequence[tuple[str, Any]])rb   Sequence[str])	__name__
__module____qualname____doc__propertyrZ   r]   r_   ra   rV   r[   rY   rS   rS   X   sB    A 8 8 6 6, ,r[   rS   c                  :    e Zd ZU dZded<   ded<   ded<   ded	<   y
)PregelTaskWriteszSimplest implementation of WritesProtocol, for usage with writes that
    don't originate from a runnable task, eg. graph input, update_state, etc.rc   rZ   rd   r]   re   r_   rf   ra   N)rg   rh   ri   rj   __annotations__rV   r[   rY   rm   rm   i   s!    Q ('
I%%r[   rm   c                  d    e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   	 	 	 	 	 	 	 	 	 	 	 	 ddZy)Callfuncinputretry_policycache_policy	callbacksr   rr   &tuple[tuple[Any, ...], dict[str, Any]]rs   Sequence[RetryPolicy] | Nonert   CachePolicy | Noneru   r   rv   c               J    || _         || _        || _        || _        || _        y rU   rq   )rX   rr   rs   rt   ru   rv   s         rY   __init__zCall.__init__|   s)     	
(("r[   N)rr   r   rs   rw   rt   rx   ru   ry   rv   r   rb   None)rg   rh   ri   	__slots__rn   r{   rV   r[   rY   rp   rp   s   sc    NI
N11..$$## 6#
 3# )# # 
#r[   rp   c                   t        t        t        | d   j                               d            } |       | d   j	                  t
        i       t        fd| d   j                         D              }|rV|D cg c]J  }|dk(  r3|j                  r5t        |j                  j	                  dt              vrn|j                  |v r|L c}S g S c c}w )z@Check if the graph should be interrupted based on current state.channel_versionsNversions_seenc              3  N   K   | ]  \  }}|j                  |      kD    y wrU   )get).0chanversionnull_versionseens      rY   	<genexpr>z#should_interrupt.<locals>.<genexpr>   s-      +D' 	$((4..+s   "%*tags)typenextitervaluesr   r-   anyitemsconfigr?   r:   r]   )
checkpointinterrupt_nodestasksversion_type any_updates_since_prev_interrupttaskr   r   s         @@rY   should_interruptr      s     T*-?"@"G"G"IJDQRL>Lo&**9b9D'* +'(:;AAC+ ($$ , 	
 #c) !)KK YY/1 	
 	
s   >ACc           	     v   t        t              }t        |t              r1g }|j                  D ]  \  }}	||k(  s||   j                  |	       ! nU|D 
cg c]	  }
|
|v s|
 }}
|D 
cg c]	  }
|
|vs|
 }}
|j                  D ]  \  }}	||v s||   j                  |	         |rBi }|D ].  }
||
   j                         }|j                  ||
          |||
<   0 t        ||      }nt        ||      }|r2|j                  |D 
ci c]  }
|
||
   j                  |        c}
       |S c c}
w c c}
w c c}
w )zFunction injected under CONFIG_KEY_READ in task config, to read current state.
    Used by conditional edges to read a copy of the state with reflecting the writes
    from that node only.)
r   list
isinstancerd   r_   appendr
   updaterC   r   )
scratchpadchannelsmanagedr   selectfreshupdatedmanaged_keyscvklocal_channelsccr   s                 rY   
local_readr      sP    %0$5G&#KK 	%DAqF{
!!!$	% $*:aQ'\::#8q'7!88KK 	%DAqF{
!!!$	% 13 	#A!!!#BIIgaj! "N1	#
 ~v6x0lKq'!*..44KLM% ;8  Ls   	D,D,)	D13D1D6c                    | | dz   S dS )zHDefault channel versioning function, increments the current int version.   rV   )currentchannels     rY   	incrementr      s    !-7Q;414r[   c                   t        |d       }t        d |D              }|D ]V  }| d   j                  |j                  i       j	                  |j
                  D ci c]  }|| d   v r	|| d   |    c}       X |d}n* || d   rt        | d   j                               ndd      }|D ch c]!  }|j
                  D ]  }|t        vr||v r| # c}}D ]!  }||   j                         s||| d   |<   # t        t              }	|D ]  }|j                  D ]t  \  }}
|t        t        t        t         t"        t$        fv r)||v r|	|   j'                  |
       Bt)        j*                  d|j                   d|j,                   d	| d
       v  t/               }|	j1                         D ]O  \  }}||v s||   j	                  |      s |#|| d   |<   ||   j3                         s?|j5                  |       Q |ri|D ]d  }||   j3                         s||vs||   j	                  t6              s5|8|| d   |<   ||   j3                         sT|j5                  |       f |r\|j9                  |      rK|D ]F  }||   j;                         s||| d   |<   ||   j3                         s6|j5                  |       H |S c c}w c c}}w )aX  Apply writes from a set of tasks (usually the tasks from a Pregel step)
    to the checkpoint and channels, and return managed values writes to be applied
    externally.

    Args:
        checkpoint: The checkpoint to update.
        channels: The channels to update.
        tasks: The tasks to apply writes from.
        get_next_version: Optional function to determine the next version of a channel.
        trigger_to_nodes: Mapping of channel names to the set of nodes that can be triggered by updates to that channel.

    Returns:
        Set of channels that were updated in this step.
    c                2    t        | j                  d d       S )NrP   )task_path_strrZ   )ts    rY   <lambda>zapply_writes.<locals>.<lambda>   s    affRaj(A r[   )keyc              3  4   K   | ]  }|j                     y wrU   )ra   )r   r   s     rY   r   zapply_writes.<locals>.<genexpr>   s     .1AJJ.s   r   r   NzTask z with path z wrote to unknown channel z, ignoring it.)sortedr   
setdefaultr]   r   ra   maxr   r5   consumer   r   r_   r.   r4   r6   r-   r7   r,   r   rD   warningrZ   setr   is_availableaddr:   
isdisjointfinish)r   r   r   get_next_versiontrigger_to_nodes	bump_stepr   r   next_versionpending_writes_by_channelvalupdated_channelsvalss                rY   apply_writesr      s<   0 5ABE ...I  
?#..tyy"=DD !MM:&899 j!34T::	

 ' 01 J1299;<
 MM xDH$4 	 @ D>!!#(@3?J)*40@ 7B$6G 	 	ID#	4FEJJ!)$/66s;DII;k$))<VW[V\\jk		 "%/557 /
d8~$$T*|/G7C
-.t4D>..0$((./  	3D~**,=M1MD>((38P;GJ1248~224(,,T2	3 %001AB 	/D~$$&<+C7C
-.t4D>..0$((.	/ S*s   K
0&KrV   )storecheckpointermanagerr   r   rt   ru   c                    y rU   rV   r   pending_writes	processesr   r   r   stepstopfor_executionr   r   r   r   r   rt   ru   s                   rY   prepare_next_tasksr   E  s    &  r[   )r   r   rt   ru   c                    y rU   rV   r   s                   rY   r   r   [  s    & '*r[   c                  i }t        j                  | d   j                  dd            }t        |       }g }t	        t
        t           dz  |j                  t                    }|r|j                         ryt        |j                               D ]]  \  }}t        t        |fdfi d| d|d|d|d	|d
|d|d|d|d|d|d|	d|
d|d|d|d|x}sM|j                  |       _ |rD|rBt               }|D ]'  }|j                  |      x}s|j                  |       ) t!        |      }n| d   sd}n|j#                         }|D ]Z  }t        t$        |fdfi d| d|d|d|d	|d
|d|d|d|d|d|d|	d|
d|d|d|d|x}sJ|j                  |       \ |D ci c]  }|j&                  | c}S c c}w )a{  Prepare the set of tasks that will make up the next Pregel step.

    Args:
        checkpoint: The current checkpoint.
        pending_writes: The list of pending writes.
        processes: The mapping of process names to PregelNode instances.
        channels: The mapping of channel names to BaseChannel instances.
        managed: The mapping of managed value names to functions.
        config: The `Runnable` configuration.
        step: The current step.
        for_execution: Whether the tasks are being prepared for execution.
        store: An instance of BaseStore to make it available for usage within tasks.
        checkpointer: `Checkpointer` instance used for saving checkpoints.
        manager: The parent run manager to use for the tasks.
        trigger_to_nodes: Optional: Mapping of channel names to the set of nodes
            that are can be triggered by that channel.
        updated_channels: Optional. Set of channel names that have been updated during
            the previous step. Using in conjunction with trigger_to_nodes to speed
            up the process of determining which nodes should be triggered in the next
            step.

    Returns:
        A dictionary of tasks to be executed. The keys are the task ids and the values
        are the tasks themselves. This is the union of all PUSH tasks (Sends)
        and PULL tasks (nodes triggered by edges).
    id- Nr   checkpoint_id_bytescheckpoint_null_versionr   r   r   r   r   r   r   r   r   r   r   input_cacheru   rt   r   rV   )binascii	unhexlifyreplacer   r   r=   rO   r   r8   r   	enumerateprepare_single_taskr4   r   r   r   r   keysr3   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   rt   ru   r   r   r   r   tasks_channelidx_r   triggered_nodesr   node_idscandidate_nodesr]   r   s                                 rY   r   r   q  s   Z 46K",,Z-=-E-Ec2-NO*:6L57Ett+X\\%-@AM335 1 1 34 	#FC*s & %8	
 )5  . $ "      ,  *   !" (#$ *%& *' t * T"-	#> ,$'E' 	1G+//88x8&&x0	1 *0)@*+#..*   &4L
 "
 !4	

 %1
 *
  
 
 
 
 
 
 (
 
 &
  !
" $#
$ &%
& &'
 
4 
* LL-. ##ADD!G###s   1Gc                      e Zd ZddZy)	_TaskIDFnc                     y rU   rV   )rX   	namespacepartss      rY   __call__z_TaskIDFn.__call__  s    r[   Nr   bytesr   zstr | bytesrb   rd   )rg   rh   ri   r   rV   r[   rY   r   r     s    r[   r   )r   r   r   r   ru   rt   c               	   |	j                  t        i       }|j                  t        d      }|d   dkD  rt        nt        }| d   t
        k(  rxt        | d   t              ret        t        t        t        t        t        t        t        f   |       |fi d|d|d|d	|d
|d|	d|
d|d|d|d|d|d|d|d|d|S | d   t
        k(  rYt        t        t        t        t        f   |       |fi d|d|d|d	|d
|d|	d|
d|d|d|d|d|d|d|d|d|d|S | d   t        k(  rjt        t        | d         }||vry||   }|yt        ||d   |d   j                  |      ||      r$t        t!        |j"                              }|r| t$         | n|} |||t        |
      |t        g| }| t&         | }t)        |	t           j                  t*              ||t-        |j/                               |	t           j                  t0              |
|      }	 t3        ||||||      }|t4        u ry	 |
||| dd |d}|||k(  sJ | d |        |r'|j<                  x} r|j>                  r|jA                  |j>                         tC               }!|jD                  xs |}|rf|jG                  |      }"tI        tJ        tM        |      xs d!|ft-        t        |"t              r|"j/                         n|"      |jN                        }#nd}#t        tP        |j                  tR        tT                    }$|$jW                  |d"   j                  tX        d      |#      }$||jZ                  d$}%t]        ||| |!t_        ta        |	t        tb        |%            ||r|je                  d%|
       ndtf        |th        |!jj                  tl        to        tp        |||ts        | dd ||!|            tt        |xs |j                  tt              tv        i |j                  tv        i       ||d&   itx        dt        |t*        |tR        |$i	'      ||jz                  xs ||#|| dd |j|                  |j~                  (      S yt        ||| dd       S yy# t6        $ r'}t8        r|j;                  d| d| dd  d        d}~ww xY w))zPrepares a single task for the next Pregel step, given a task path, which
    uniquely identifies a PUSH or PULL task within the graph.r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ru   rt   	parent_nstask_id_funcr   Nr   r   )r   r   r   zBefore task with name 'z' and path 'rP   'langgraph_steplanggraph_nodelanggraph_triggerslanggraph_pathlanggraph_checkpoint_ns != __dynamic__channel_values)previousr   metadatar   graph:step:r   run_namerv   configurablewriters	subgraphs)Ar   r!   r$   _xxhash_str
_uuid5_strr4   r   rp   prepare_push_task_functionalr   tuplerd   intprepare_push_task_sendr3   	_triggersr   ra   r0   r/   _scratchpadr)   r   encoder'   _proc_inputr;   	ExceptionSUPPORTS_EXC_NOTESadd_notenoder  r   r   ru   key_funcrJ   r    rB   ttlrH   r(   rG   overrider2   r   rL   r   r   r   	get_childr+   r*   extendr&   r   r   rm   r%   r#   r"   rt   flat_writersr  rM   )&	task_pathtask_id_checksumr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ru   rt   r  r   r   r]   procra   checkpoint_nstask_idtask_checkpoint_nsr   r   excr  r  r_   args_key	cache_keyruntimeadditional_configs&                                         rY   r   r     s:   0 ::dB'L  !92>I",S/A"5;:L|t
9R=$ ?+sE3T12I>
 "
 !4	

 *
 
 
 
 
 
 (
 
 &
 
 &
  &!
"  #
$ &%
 	
* 
1	%sEz"I.
 "
 !4	

 *
 
 
 
 
  
 
 (
 
 &
 
  &!
" &#
$  %
& &'
 	
, 
1	C1&y "*)*'++D1#
 VDMM23H<Eyk&$84M"#D	 G %2?6(7)!D$t  !67"#5#<#<#>?t  !67J!"/ +) '> " #'"&&."+BQ-+=H  +"22VwitDTCU4VV299$4$}} 65:WF#'#4#4#DL##/#8#8#=$, /!+D!1!B] $
 / (2(C'@ %-OO$5)1	 ),,%	  %)	"!1!12Do!VG &..!+,<!=!A!A(D!Q# / G
 %- $		)% 0$) &^=N(O &* $+ !( 1 1Kv2F G%) !3G / /$.$.$,$+$4(1"1(,(.(0	%&2" !8$0 %Q'3'7'78O'P 9 <"&2&6&67PRT&U<"$-z$/?<" !9$ 8:L 5z 2G7*'P !))9\!!"1 $ 1 1"&..g4 4G %r "'42A??g
 
d  %LL1$|IbqM?RST s   -R" "	S+"SS)r   r   r   ru   rt   c                  |j                  t        i       }| d   }t        |j                        }|j                  }|t        d      t        }|r| t         | n|} |||t        |      |t        t        | d         t        | d               }| d| }g | dd d}|||||d	}|||k(  sJ | d
|        |
r*t               }|j                  xs |}|r |j                  |j                  d   i |j                  d   }t        t         t#        |j                        xs dft%        t'        |t              r|j)                         n|      |j*                        }nd}t-        |j                  t.              ||t%        |j)                               |j                  t0              ||	      }t3        t4        |j                  t6        t8                    } | j;                  |      } t=        ||j                  ||t?        tA        |d|i      ||jB                  xs |r|jE                  d|       ndtF        |tH        |jJ                  tL        tO        tP        |||tS        ||||            tT        |xs |j                  tT              tV        i |j                  tV        i       ||d   itX        dtZ        |t.        |t6        | i	      ||j\                  xs ||||
      S t_        |||      S )zIPrepare a push task with an attached caller. Used for the functional API.r   Nz1`call` functions must have a `__name__` attributer      :rP   Tr   r   r   r   )r   r  r  r   r  )0r   r!   rA   rr   r]   
ValueErrorPUSH_TRIGGERr0   rd   r4   r   r   ru   r  rs   rJ   r    rB   r   r   r  r  r  r)   r'   r   rH   r(   rG   r  rL   r   r   rv   r  r+   r*   r  r&   r   r   rm   r%   r#   r"   r$   rt   rM   )!r  r  r   r   r   r   r   r   r   r   r   r   r   r   ru   rt   r   r   r  callproc_r]   ra   r   r!  r"  in_progress_task_pathr  r_   r$  r%  r   r&  s!                                    rY   r  r    s.   0 ::dB'LR=D!$)),E::D|LMM*H4=yk&$04MD	il#IaLG *?!G95 3im2T2&/#5H #**Nwit<L;M,NN*).((8L,|,,djjmMtzz!}MH)1#		*;m #)3Hc)BHOO%   	*I I 23188:;23

 w 0 01C_ UV"""/#JJfz8&<=.. R?FG%%D6&:;D&#V]]#W"" ()>fhW& ,$Q(8(89P(Q- 0&**+DbI0!:d#30 -d,.@):&+: -!M'
 '	
R '4)>??r[   c                  t        |       dk(  r6t        t        | d         }|t           j	                         sy |t           j                         }|dk  s|t        |      k\  ry ||   }t        |t              s#t        j                  dt        |       d       y |j                  |vr$t        j                  d|j                   d       y ||j                     }|j                  }|y t        }|r| t         |j                   n|j                  } |||t        |      |j                  t        t        |            }nt        j                  d|         y |j                  t         i       }| d| }g | d d	 d
}||j                  |||d}|||k(  sJ | d|        |
r|j"                  r|j%                  |j"                         t'               }|j(                  xs |}|rz|j+                  |j,                        } t/        t0        t3        |      xs d|j                  ft5        t        | t              r| j7                         n|       |j8                        }!nd }!t;        |t            j                  t<              ||t5        |j7                               |t            j                  t>              ||	      }"t        t@        |j                  tB        tD                    }#|#jG                  ||d   j                  tH        d             }#||jJ                  d}$tM        |j                  |j,                  ||tO        tQ        ||$      |j                  |r|jS                  d|       nd tT        |tV        |jX                  tZ        t]        t^        |"||ta        ||j                  ||            tb        |xs |j                  tb              td        i |j                  td        i       ||d   itf        d th        |t<        |"tB        |#i	      ||jj                  xs ||!|||jl                  |jn                        S tq        ||j                  |      S )Nr)  r   r   zIgnoring invalid packet type z in pending sendszIgnoring unknown node name z Ignoring invalid PUSH task path r*  rP   Fr   r   r   r   )r   r   r   r  r   r  r  )9lenr   r  r8   r   r   r   rO   rD   r   r   r  r,  r0   rd   r4   r!   r  r   r   ru   r  argrJ   r    rB   r   r  r  r  r)   r'   rH   r(   rG   r  r2   r   rL   r   r   r  r+   r*   r  r&   r   r   rm   r%   r#   r"   r$   rt   r  r  rM   )%r  r  r   r   r   r   r   r   r   r   r   r   r   r   ru   rt   r   r   r   r   sendspacketr  	proc_nodera   r   r!  r  r"  translated_task_pathr  r_   r$  r%  r   r&  r'  s%                                        rY   r  r  ]  sB   . 9~ 3	!%++- ( 3 3 57cSZ's&$'NN/V~=NO ;;i'NN8EVWX%II	3<yk&&++/&++ 	 IKKH
 	9)EF::dB'L)?!G95 3Yr]2E2 ++&.#5H #**Nwit<L;M,NN*==OODMM*).((8L#,,VZZ8H #%6KK
 #)3Hc)BHOO%   
I I 4L23188:;4L23

 w 0 01C_ UV""*-=">"B"B8T"R # 
 !II-
 $KKJJf&78?FG%%D6&:;D '#V]]#W"" (0&++vx& ,$Q(8(89P(Q- 0&**+DbI0!:d#30 -d,.@):&/@ - %%nnW,
 ,	
\ '6;;0DEEr[   c                V    | d   j                         D ]  } t        |             c S  y)z6Get the null version for the checkpoint, if available.r   N)r   r   )r   r   s     rY   r   r      s3     0188: tG}r[   c                    |'|j                   D ]  }| |   j                         s y y|j                   D ]=  }| |   j                         s|j                  ||      |j                  ||      kD  s= y y)NTF)ra   r   r   )r   versionsr   r   r  r   s         rY   r  r  	  s     |MM 	D~**,	  MM 	D~**,l2|,2- 		
 r[   c           
         t              dkD  r|D ]  }|d   t        k(  s|d   t        k(  s| n d D ]1  }|d   |k(  s|d   t        k(  s|d   }t        |t              s|g} n g }~|r||v r||   }	|j                  |	       nd g }dd fd}
t        ||t               t               ||
t                     S )Nr   r   r)  c                    j                  |       S y | r	 j                         d   S d   S # t        $ r Y y w xY w)Nr)  )get_null_resumeremover+  )r   null_resume_writeparent_scratchpadr   s    rY   r<  z$_scratchpad.<locals>.get_null_resumeE  sf    $ ,(88AA%%&78(++ !##  s   6 	AA)r   r   call_counterinterrupt_counterresumer<  subgraph_counterF)r   boolrb   r   )r1  r1   r6   r   r   r   r9   LazyAtomicCounter)r?  r   r!  namespace_hash
resume_mapr   r   wtask_resume_writemapped_resume_writer<  r>  s   ``         @rY   r  r    s    >Q 	%At|#!$%!	% !%   	#Atw1Q46>$%aD!!"3T:):(;%	# !# .J6",^"<$$%89 !$ $ &(+- '*, r[   c                  |&| j                   |v rt        || j                            S t        | j                  t              rZi }| j                  D ]H  }||v r+||   j                         s||   j                         ||<   2||   j                  |      ||<   J nt        | j                  t              rU| j                  |v rA|| j                     j                         r|| j                     j                         }n$t        S t        S t        d| j                         |r| j                  | j                  |      }|||| j                   <   |S )zLPrepare input for a PULL task, based on the process's channels and triggers.z2Invalid channels type, expected list or dict, got )input_cache_keyr
   r   r   r   r   r   rd   r;   RuntimeErrormapper)r  r   r   r   r   r   r   r   s           rY   r  r  a  sA    4#7#7;#FK 4 4566 $--& MM 	:DxD>..0 ( 2 2 4CI#DM--j9D		: 
DMM3	'==H$&335t}}-113N@P
 	

 0kk# ,/D(()Jr[   c                    t        | d      }|j                  dj                  d |D                     |j                         }|dd  d|dd  d|dd	  d|d	d
  d|d
d  	S )zAGenerate a UUID from the SHA-1 hash of a namespace and str parts.F)usedforsecurityr[   c              3  `   K   | ]&  }t        |t              r|j                         n| ( y wrU   r   rd   r  r   ps     rY   r   z_uuid5_str.<locals>.<genexpr>  s$     OAjC&8
a?O   ,.N   r                )r   r   join	hexdigest)r   r   shahexs       rY   r
  r
    sw     y%
0CJJsxxOOOP
--/C"1gYaAb	{!C2J<qRAc"Rj\JJr[   c                    t        | dj                  d |D              z         }|dd  d|dd  d|dd  d|dd  d|dd	  	S )
z@Generate a UUID from the XXH3 hash of a namespace and str parts.r[   c              3  `   K   | ]&  }t        |t              r|j                         n| ( y wrU   rS  rT  s     rY   r   z_xxhash_str.<locals>.<genexpr>  s$     T:a+=QXXZ1DTrV  NrW  r   rX  rY  rZ  r[  )r   r\  )r   r   r_  s      rY   r	  r	    sf    
CHHTeTTTC "1gYaAb	{!C2J<qRAc"Rj\JJr[   c                    t        | t        t        f      rddj                  d | D               S t        | t              r| dS t        |       S )z2Generate a string representation of the task path.~z, c              3  2   K   | ]  }t        |        y wrU   )r   )r   xs     rY   r   z task_path_str.<locals>.<genexpr>  s     41mA&4s   010d)r   r  r   r\  r  rd   )tups    rY   r   r     s[     cE4=) DII44456 c3 Dz
 Xr[   c                  ,    e Zd ZU dZded<   ddZddZy)	rF  _counterzCallable[[], int] | Nonerj  c                    d | _         y rU   ri  rW   s    rY   r{   zLazyAtomicCounter.__init__  s	    r[   c                   | j                   Ot        5  | j                   $t        j                  d      j                  | _         d d d        | j                         S | j                         S # 1 sw Y   | j                         S xY w)Nr   )rj  LAZY_ATOMIC_COUNTER_LOCK	itertoolscount__next__rW   s    rY   r   zLazyAtomicCounter.__call__  si    == ) @==($-OOA$6$?$?DM@ }}t}}@ }}s   1A,,BN)rb   r|   )rb   r  )rg   rh   ri   r}   rn   r{   r   rV   r[   rY   rF  rF    s    I&&r[   rF  c           	        t        | j                  t              s| S | j                  j                         D ci c]'  \  }}t        |j	                  |      t
              s||) }}}t        | j                  |      S c c}}w )a  Pop any values belonging to UntrackedValue channels in Send.arg for safe checkpointing.

    Send is often called with state to be passed to the dest node, which may contain
    UntrackedValues at the top level. Send is not typed and arg may be a nested dict.)r  r2  )r   r2  dictr   r   r>   rO   r  )r4  r   r   r   sanitized_args        rY   !sanitize_untracked_values_in_sendrt    su     fjj$'
 JJ$$&Aq(,,q/>: 	
1M 
 V[[m44s   ,B )r   r   r   zAll | Sequence[str]r   zIterable[PregelExecutableTask]rb   zlist[PregelExecutableTask]rD  )r   r9   r   Mapping[str, BaseChannel]r   r@   r   rS   r   zlist[str] | strr   rE  rb   zdict[str, Any] | Any)r   z
int | Noner   r|   rb   r  )r   r   r   ru  r   zIterable[WritesProtocol]r   zGetNextVersion | Noner   zMapping[str, Sequence[str]]rb   zset[str])"r   r   r   list[PendingWrite]r   Mapping[str, PregelNode]r   ru  r   r@   r   r   r   r  r   r  r   zLiteral[False]r   Literal[None]r   rx  r   rx  r   "Mapping[str, Sequence[str]] | Noner   set[str] | Nonert   Sequence[RetryPolicy]ru   rx  rb   zdict[str, PregelTask])"r   r   r   rv  r   rw  r   ru  r   r@   r   r   r   r  r   r  r   zLiteral[True]r   BaseStore | Noner   BaseCheckpointSaver | Noner   /None | ParentRunManager | AsyncParentRunManagerr   ry  r   rz  rt   r{  ru   ry   rb   zdict[str, PregelExecutableTask])"r   r   r   rv  r   rw  r   ru  r   r@   r   r   r   r  r   r  r   rE  r   r|  r   r}  r   r~  r   ry  r   rz  rt   r{  ru   ry   rb   z7dict[str, PregelTask] | dict[str, PregelExecutableTask])(r  ztuple[Any, ...]r  
str | Noner   r   r   r   r   V | Noner   rv  r   rw  r   ru  r   r@   r   r   r   r  r   r  r   rE  r   r|  r   r}  r   r~  r   &dict[INPUT_CACHE_KEY_TYPE, Any] | Noneru   ry   rt   r{  rb   z(None | PregelTask | PregelExecutableTask)&r  z!tuple[str, tuple, int, str, Call]r  r  r   r   r   r   r   rv  r   ru  r   r@   r   r   r   r  r   r  r   rE  r   r|  r   r}  r   r~  ru   ry   rt   r{  r   rd   r   r   rb   z!PregelTask | PregelExecutableTask)(r  ztuple[str, tuple]r  r  r   r   r   r   r   rv  r   ru  r   r@   r   r   r   r  r   r  r   rE  r   r|  r   r}  r   r~  ru   ry   rt   r{  r   rd   r   r   r   rw  rb   z(PregelTask | PregelExecutableTask | None)r   r   rb   r  )r   ru  r9  r   r   zChannelVersions | Noner   r   r  rF   rb   rE  )r?  zPregelScratchpad | Noner   rv  r!  rd   rG  rd   rH  zdict[str, Any] | Noner   r  r   r  rb   r9   )r  rF   r   r@   r   ru  r   rE  r   r9   r   r  rb   r   r   )rg  zstr | int | tuplerb   rd   )r4  rO   r   ru  rb   rO   )
__future__r   r   rn  sys	threadingcollectionsr   r   collections.abcr   r   r   r	   r
   	functoolsr   hashlibr   typingr   r   r   r   r   r   langchain_core.callbacksr    langchain_core.callbacks.managerr   r   langchain_core.runnables.configr   langgraph.checkpoint.baser   r   r   r   r   langgraph.store.baser   xxhashr   langgraph._internal._configr   r   langgraph._internal._constantsr    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   langgraph._internal._scratchpadr9   langgraph._internal._typingr:   r;   langgraph.channels.baser<   langgraph.channels.topicr=   "langgraph.channels.untracked_valuer>   langgraph.constantsr?   langgraph.managed.baser@   langgraph.pregel._callrA   rB   langgraph.pregel._iorC   langgraph.pregel._logrD   langgraph.pregel._readrE   rF   langgraph.runtimerG   rH   langgraph.typesrI   rJ   rK   rL   rM   rN   rO   GetNextVersionversion_infor  rS   rm   rp   r   r   r   r   r   r,  r   r   r  r  r   r  r  r  r
  r	  r   Lockrm  rF  rt  rV   r[   rY   <module>r     s   "   
  * A A     / T :  + % C      6 = : / * = * 6 D . ( C 6   1t8T*A-.%%0 -X -"z # #2( *  	N $ $'$ !$ 	$
 $ $ $N5
ii'i $i ,	i
 2i iX 
  "&!;?(,*,"&#  &  (  (	 
 !        "         9  &   (! "  # $ %  
 * 
 <@(,*,'+#**&* (* (	*
 !* * * * !* * -* =* 9* &*  (!*" %#*$ %%* 
*@ #/3?C;?(,*,'+#y$y$&y$ (y$ (	y$
 !y$ y$ y$ y$ y$ y$ -y$ =y$ 9y$ &y$  (!y$" %#y$$ =%y$x w ( #/3?C:>'+*,)e@e@ e@ 	e@
 e@ &e@ 'e@ (e@ (e@ !e@ e@ e@ e@ e@ e@  -!e@" =#e@$ 8%e@& %'e@( ()e@* .+e@l #/3?C'+*,%}@0}@ !}@
 }@ }@ '}@ (}@ !}@ }@ }@ }@ }@ }@ -}@  =!}@" %#}@$ (%}@& '}@* +}@, '-}@\ #/3?C'+*,%`F `F !`F
 `F `F '`F (`F !`F `F `F `F `F `F -`F  =!`F" %#`F$ (%`F& '`F( )`F* (+`F, .-`FF' ! 	
  
(A.A&A A 	A
 &A A A AH,
, , (,
 , !, 8, 	,^KK *9>>+   5555	5r[   