
    A'h              *          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
 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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" d dl#m$Z$ d dl%m&Z&m'Z'm(Z(m)Z)m*Z* d dl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZI d dlJmKZK d dlLmMZM d dlNmOZOmPZP d dlQmRZR d dlSmTZT d dlUmVZVmWZW d dlXmYZY d dlZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZa d dlbmcZcmdZd eee*   e$ge*f   Zeej                  dk\  Zg G d de      Zh G d de      Zi G d d      Zjde(d ee[e
ek   f   d!ee^   d"ele^   fd#Zm	 ddd%e	eke$f   d&eMd'ehd(eelek   ekf   d)end"eeoekef   ef   fd*Zpd+ee
eqekef      gdf   d,eek   d-e
eqekef      d"dfd.Zrd/ees   d0e$d"esfd1Ztde(d%e	eke$f   d!eeh   d2eee   d3e	eke
ek   f   d"eqeoekele   f   euek   f   fd4Zvd3e	eke
ek   f   d5euek   de(d"enfd6Zwedddddd7dd8de(d9ele)   d:e	ekeWf   d%e	eke$f   d&eMd;e d<esd=ed$   d>ed   d?ed   d@ed   d3ee	eke
ek   f      d5eeuek      dAe
ea   dBed   d"eoeke`f   f dC       Zxeddd7ddDde(d9ele)   d:e	ekeWf   d%e	eke$f   d&eMd;e d<esd=edE   d>eeY   d?ee&   d@edeef   d3ee	eke
ek   f      d5eeuek      dAe
ea   dBee]   d"eoeke^f   f dF       Zxdddddd7dd8de(d9ele)   d:e	ekeWf   d%e	eke$f   d&eMd;e d<esd=end>eeY   d?ee&   d@edeef   d3ee	eke
ek   f      d5eeuek      dAe
ea   dBee]   d"eeoeke`f   eoeke^f   f   f dGZxeCfZydddddd7dHdIeqedJf   dKeek   de(dLezdMee*   d9ele)   d:e	ekeWf   d%e	eke$f   d&eMd;e d<esd=end>eeY   d?ee&   d@edeef   dNeeoeVef      dBee]   dAe
ea   d"ede`e^f   f&dOZ{de(d"ee*   fdPZ|d%e	eke$f   dQe'dRee'   dSe*dTeWd"e
ek   fdUZ}dVee_   d9ele)   dWekdXekdYeeoekef      d"e_fdZZ~dTeWd&eMd%e	eke$f   d=endNeeoeVef      d"efd[Zd\ezd]eekezf   d"ekfd^Zd\ezd]eekezf   d"ekfd_Zd`eekeseqf   d"ekfdaZ ej                         Z G db dc      Zy)e    N)defaultdictdeque)IterableMappingSequence)copy)partial)sha1)	AnyCallableLiteral
NamedTupleOptionalProtocolUnioncastoverload)	Callbacks)AsyncParentRunManagerParentRunManager)RunnableConfig)xxh3_128_hexdigest)BaseChannel)BaseCheckpointSaverChannelVersions
CheckpointPendingWriteV)CACHE_NS_WRITESCONFCONFIG_KEY_CHECKPOINT_IDCONFIG_KEY_CHECKPOINT_MAPCONFIG_KEY_CHECKPOINT_NSCONFIG_KEY_CHECKPOINTERCONFIG_KEY_PREVIOUSCONFIG_KEY_READCONFIG_KEY_RESUME_MAPCONFIG_KEY_SCRATCHPADCONFIG_KEY_SENDCONFIG_KEY_STORECONFIG_KEY_TASK_ID	EMPTY_SEQERROR	INTERRUPTMISSING	NO_WRITESNS_ENDNS_SEPNULL_TASK_IDPREVIOUSPULLPUSHRESERVEDRESUMERETURN
TAG_HIDDENTASKSSend)InvalidUpdateError)ManagedValueMapping)get_runnable_for_task
identifier)read_channels)logger)INPUT_CACHE_KEY_TYPE
PregelNode)	BaseStore)AllCacheKeyCachePolicyPregelExecutableTaskPregelScratchpad
PregelTaskRetryPolicy)merge_configspatch_config)      c                       e Zd ZdZedeeeeef   df   fd       Z	edefd       Z
edeeeef      fd       Zedee   fd       Zy)	WritesProtocolzProtocol for objects containing writes to be applied to checkpoint.
    Implemented by PregelTaskWrites and PregelExecutableTask.return.c                      y N selfs    \/home/kushmeetdev/Regenta/Chatbot/venv/lib/python3.12/site-packages/langgraph/pregel/algo.pypathzWritesProtocol.path]   s    :=    c                      y rU   rV   rW   s    rY   namezWritesProtocol.name`   s    r[   c                      y rU   rV   rW   s    rY   writeszWritesProtocol.writesc   s    36r[   c                      y rU   rV   rW   s    rY   triggerszWritesProtocol.triggersf   s    ),r[   N)__name__
__module____qualname____doc__propertytupler   strintrZ   r]   r   r   r_   ra   rV   r[   rY   rR   rR   Y   s|    A =eE#sE/2C78= =c 6sCx16 6,(3-, ,r[   rR   c                   f    e Zd ZU dZeeeeef   df   ed<   eed<   e	eee
f      ed<   e	e   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..rZ   r]   r_   ra   N)rb   rc   rd   re   rg   r   rh   ri   __annotations__r   r   rV   r[   rY   rk   rk   j   sG    Q c3o&+
,,
IU38_%%smr[   rk   c                       e Zd ZU dZeed<   eeedf   ee	ef   f   ed<   e
ee      ed<   e
e   ed<   eed<   dedeeedf   ee	ef   f   de
ee      de
e   dedd	fd
Zy	)Callfuncinputretrycache_policy	callbacksrp   .rq   rr   rs   rt   rS   Nc                J    || _         || _        || _        || _        || _        y rU   ro   )rX   rp   rq   rr   rs   rt   s         rY   __init__zCall.__init__}   s(     	

("r[   )rb   rc   rd   	__slots__r   rl   rg   r   dictrh   r   r   rL   rH   r   rv   rV   r[   rY   rn   rn   t   s    GI
NsCx$sCx.011H[)**;''## U38_d38n45#
 -.# {+# # 
#r[   rn   
checkpointinterrupt_nodestasksrS   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]   )ry   rz   r{   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Fchannelsmanagedr   selectfreshc           	      z   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                  |         |rN|rLi }
| D ]8  }	|	|v r(| |	   j                         }|j                  ||	          n| |	   }||
|	<   : t        |
|      }nt        | |      }|r(|j                  |D 	ci c]  }	|	 ||	           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
isinstancerh   r_   appendr   updaterA   )r   r   r   r   r   updatedmanaged_keyscvklocal_channelsccr   s                rY   
local_readr      s[    %0$5G&#KK 	%DAqF{
!!!$	% $*:aQ'\::#8q'7!88KK 	%DAqF{
!!!$	% 13 	#AG|a[%%'		'!*%a[ "N1	# ~v6x0=1q*'!*,=>M+ ;8& >s   	D.D.)	D33D3D8commitprocess_keysr_   c                     |D ]\  \  }}|t         t        fv s|t        |t              st	        d|       |j
                  |vsEt	        d|j
                   d        | |       y)zFunction injected under CONFIG_KEY_SEND in task config, to write to channels.
    Validates writes and forwards them to `commit` function.NzExpected Send, got zInvalid node name z
 in packet)r6   r;   r   r<   r=   node)r   r   r_   r   values        rY   local_writer      su      VeD%= U%6eT*(+>ug)FGGzz-(+=ejj\)TUUV 6Nr[   currentchannelc                     | | dz   S dS )zHDefault channel versioning function, increments the current int version.   rV   )r   r   s     rY   	incrementr      s    !-7Q;414r[   get_next_versiontrigger_to_nodesc           	         t        |d       }t        d |D              }|D ]V  }| d   j                  |j                  i       j	                  |j
                  D ci c]  }|| d   v r	|| d   |    c}       X | d   rt        | d   j                               }nd}|D ch c]!  }|j
                  D ]  }|t        vr||v r| # c}}D ]+  }||   j                         s| ||||         | d   |<   - | d   r|r| d   j                          t        t              }	t        t              }
|D ]  }|j                  D ]s  \  }}|t        t        t         t"        t$        t&        fv r)|t(        k(  r| d   j+                  |       G||v r|	|   j+                  |       `|
|   j+                  |       u  | d   rt        | d   j                               }nd}t-               }|	j/                         D ]Y  \  }}||v s||   j	                  |      s |# ||||         | d   |<   ||   j1                         sI|j3                  |       [ |rs|D ]n  }||   j1                         s||vs||   j	                  t4              s5|8 ||||         | d   |<   ||   j1                         s^|j3                  |       p |rk| d   sf|j7                  |      rU|D ]P  }||   j9                         s| ||||         | d   |<   ||   j1                         s@|j3                  |       R |
|fS c c}w c c}}w )a6  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.

    Returns:
        A tuple containing the managed values writes to be applied externally, and
        the set of channels that were updated in this step.
    c                 2    t        | j                  d d       S )NrO   )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}   Npending_sends)sortedr   
setdefaultr]   r   ra   maxr   r7   consumeclearr   r   r_   r0   r6   r8   r.   r9   r-   r;   r   setr   is_availableaddr,   
isdisjointfinish)ry   r   r{   r   r   	bump_stepr   r   max_versionpending_writes_by_channelpending_writes_by_managedvalupdated_channelsvalss                 rY   apply_writesr      s   0 5ABE ...I  
?#..tyy"=DD !MM:&899 j!34T::	

 $%*%78??AB
 MM xDH$4 	 
 D>!!#(8(D3C4J)*40
 /"y?#))+ 7B$6G6A$6G 	< 	<ID#	4FEJJ?+2237!)$/66s;)$/66s;	<	< $%*%78??AB "%/557 	/
d8~$$T*/?/K7GTN8
-.t4
 D>..0$((.	/  		3D~**,=M1MD>((38H8T;K# <J1248
  ~224(,,T2		3 	?+''(89 	/D~$$&+;+G7GTN8
-.t4
 D>..0$((.	/ %&666{s   L>
%&Mr   c                 F    t        |d         xs |j                  |        S )zACheck if there are any tasks that should be run in the next step.r   )boolr   )r   r   ry   s      rY   has_next_tasksr   l  s1     
?+, 4D4O4O5 1 r[   rV   )storecheckpointermanagerr   r   retry_policyrs   pending_writes	processesr   stepfor_executionr   r   r   r   rs   c                     y rU   rV   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   rs   s                  rY   prepare_next_tasksr   w  s    $  r[   )r   r   r   rs   Tc                     y rU   rV   r   s                  rY   r   r     s    $ '*r[   c                   i }t        j                  | d   j                  dd            }t        |       }g }t	        | d         D ]Z  \  }}t        t        |fdfi d| d|d|d	|d
|d|d|d|d|d|d|d|	d|
d|d|d|x}sJ|j                  |       \ |rD|rBt               }|D ]'  }|j                  |      x}s|j                  |       ) t        |      }n| d   sd}n|j                         }|D ]W  }t        t        |fdfi d| d|d|d	|d
|d|d|d|d|d|d|d|	d|
d|d|d|x}sG|j                  |       Y |D ci c]  }|j                  | c}S c c}w )aw  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- r   Nry   checkpoint_id_bytescheckpoint_null_versionr   r   r   r   r   r   r   r   r   r   input_cachers   r   r}   rV   )binascii	unhexlifyreplacer   	enumerateprepare_single_taskr6   r   r   r   r   r   keysr5   r   )ry   r   r   r   r   r   r   r   r   r   r   r   r   r   rs   r   r   r   r{   idx_r   triggered_nodesr   node_idscandidate_nodesr]   r   s                               rY   r   r     s   X 46K",,Z-=-E-Ec2-NO*:6L;=EJ78 Q&3K
 "
 !4	

 %1
 *
  
 
 
 
 
 (
 
 &
 
  $!
" &#
$ &%
 
4 
( LL+< ,$'E' 	1G+//88x8&&x0	1 *0)@*+#..*   &4L
 "
 !4	

 %1
 *
  
 
 
 
 
 (
 
 &
 
  $!
" &#
$ &%
 
4 
( LL+, ##ADD!G###s   !E8)r   r   r   r   rs   r   	task_path.task_id_checksumr   r   r   c          %      `   |	j                  t        i       }|j                  t        d      }|d   dkD  rt        nt        }| d   t
        k(  r%t        | d   t              rt        t        t        t        t        t        t        f   |       }|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/        t0        t3        |j                        xs dft5        t        |t              r|j7                         n|      |j8                        } nd} t;        ||j,                  ||t=        t?        |	d|i      ||j@                  xs |r|jC                  d|
       ndtD        |tF        tI        tJ        |jL                  |jO                               tP        tI        tR        ||tU        | |||            tV        |xs |j                  tV              tX        |xs |j                  tX              tZ        i |j                  tZ        i       ||d   it\        dt        |t^        ta        |	t           j                  t^              ||t5        |j7                               |	t           j                  tb                    i	      ||jd                  xs || || 
      S tg        |||       S | d   t
        k(  rti        |       dk(  rt        t        | d         }!|!ti        |d         k\  ry|d   |!   }"t        |"tj              s#tm        jn                  dtq        |"       d       y|"jr                  |vr$tm        jn                  d|"jr                   d       y||"jr                     }#|#jr                  }$|$yt         }|r| t"         |"jr                   n|"jr                  } |||t        |
      |"jr                  t
        t        |!            }ntm        jn                  d|         y| d	| }g | dd
 d} |
|"jr                  || |d}|||k(  sJ | d|        |r|#jt                  r|jw                  |#jt                         t'               }|#j(                  xs |}|rz|j+                  |"jx                        }t/        t0        t3        |#      xs d|"jr                  ft5        t        |t              r|j7                         n|      |j8                        } nd} t;        |"jr                  |"jx                  |$|t=        t?        |	||#jz                  d      |"jr                  |r|jC                  d|
       ndtD        |tF        tI        tJ        |jL                  |jO                               tP        tI        tR        ||tU        | |"jr                  ||            tV        |xs |j                  tV              tX        |xs |j                  tX              tZ        i |j                  tZ        i       ||d   it\        dt        |t^        ta        |	t           j                  t^              ||t5        |j7                               |	t           j                  tb                    t|        |d   j                  t~        d      i
      ||#j                  xs || || |#j                  |#j                        S tg        ||"jr                  |       S | d   t        k(  r\t        t        | d         }||vry||   }#|yt        ||d   |d   j                  |      ||#      rt        t        |#j                              }	 t        |#||||      }%|%t        u ry	 |r| t"         | n|} |||t        |
      |t        g| }| t         | }|
||| dd
 |d}|||k(  sJ | d|        |rv|#jr                  x}'rf|#jt                  r|jw                  |#jt                         t'               }|#j(                  xs |}|rf|j+                  |%      }t/        t0        t3        |#      xs d|ft5        t        |t              r|j7                         n|      |j8                        } nd} t;        ||%|'|t=        t?        |	||#jz                  d      ||r|jC                  d|
       ndtD        |tF        tI        tJ        |jL                  t        |jO                                     tP        tI        tR        ||tU        | dd
 |||            tV        |xs |j                  tV              tX        |xs |j                  tX              tZ        i |j                  tZ        i       ||d   it\        dt        |t^        ta        |	t           j                  t^              ||t5        |j7                               |	t           j                  tb                    t|        |d   j                  t~        d      i
      ||#j                  xs || || dd
 |#j                  |#j                        S ytg        ||| dd
       S yy# t        $ r'}&t        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   Nz1`call` functions must have a `__name__` attribute   :rO   T)langgraph_steplanggraph_nodelanggraph_triggerslanggraph_pathlanggraph_checkpoint_nsz != __dynamic__metadatazgraph:step:r   )run_namert   configurabler   zIgnoring invalid packet type z in pending sendszIgnoring unknown node name z Ignoring invalid PUSH task path F)r   r   channel_values)writers	subgraphsr}   r~   )r   r   zBefore task with name 'z' and path '')Mr   r    r#   _xxhash_str
_uuid5_strr6   r   rn   r   rg   rh   ri   r?   rp   r]   
ValueErrorPUSH_TRIGGERr2   r   r   rs   key_funcrq   rG   r   r@   r   encodettlrI   rN   rM   rt   	get_childr+   r)   r	   r   extendr   r&   r   rk   r*   r$   r"   r!   r(   _scratchpadr'   rr   rK   lenr<   rB   warningr   r   r   r   argr   r%   r4   r   flat_writersr   r5   	_triggersr   ra   _proc_inputr/   	ExceptionSUPPORTS_EXC_NOTESadd_noter1   )(r   r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   rs   r   r   	parent_nstask_id_functask_path_tcallproc_r]   ra   checkpoint_nstask_idtask_checkpoint_nsr   r_   args_key	cache_keyr   packetproc	proc_noder   excr   s(                                           rY   r   r     s   . ::dB'L  !92>I",S/A"5;:L|t
9R=$ ?5eS#t!;<iH2%dii0zz<PQQ".8A9+fXdV4tI)A,'	!
 !.ay9 +im*T*	"""*''9
 '..R7)4@P?Q0RR.-2WF,,<L0<00$**Q-Q4::a=Q08'#DII.?- '-7#-F)H !$$	1	 !	'

!&:x*@A!"nn VCJ))Kv*>?PT*G''"MM%NN,*
 (&$#,YfhO	* )5+VL4D4DEU4V/(UL,<,<=T,U1 4*../H"M4%z$'74 1$02D-{"4L,,-BC*#./A/H/H/JK"4L,,-BC01"%L 

*l_0 0d gtY77	1	y>Q sIaL)Cc*_56605Ffd+3DL>ARS {{)+1&++>OP V[[)D		I #H7@9+fXfkk]3fkk  ##D	CG NN=i[IJ -ay9 ,im+U+	"$kk"*''9
 '..R7)4@P?Q0RR.}}.WF,,<L'00<$'#D):]
 '-7#-F)H !$$
	 !	'

!&x*ST#[[CJ))Kv*>?PT +G''"MM%NN,*
 (&$#,YVXV	* )5+VL4D4DEU4V/(UL,<,<=T,U1 4*../H"M4%z$'74 1$02D-{"4L,,-BC*#./A/H/H/JK"4L,,-BC0 ,Z8H-I-M-M$d.?"")T !!1\))..k6 6p gv{{I>>	1	C1&y "*)*'++D1#
 VDMM23H!"/ + '> " =Fyk&$84M"#D	 G %2?6(7)!D"&"&&."+BQ-+=H  +"22VwitDTCU4VV299$4$}} 6"WF#'#4#4#DL##/#8#8#=$, /!+D!1!B] $
 /#-h#< !) 1%-
 ),,%	 %)	/$) &Xtyy(Q &* $+ !( 1 1Kv2F G%) !3G /$/$*MM$))..*:$;2"
 !0$.$,$+$4(1"1(,(.(0	%&	
2" !1$)$O\-=-=>N-O 7$0 %Q'3'7'78O'P 9 <"&2&6&67PRT&U<"$-z$/?<" !9$ 8:L 5{$*4L$4$45J$K$2$+$67I7P7P7R$S$*4L$4$45J$K8" !4Z@P5Q5U5U$,d6"O**5l !))9\!!"1 $ 1 1"&..CB B- %t "'42A??Q
 
6  %LL1$|IbqM?RST s   k= =	l-"l((l-c                 V    | d   j                         D ]  } t        |             c S  y)z6Get the null version for the checkpoint, if available.r}   N)r   r   )ry   r   s     rY   r   r     s3     0188: tG}r[   versionsr   r   r  c                    |/|j                   D ]  }| |   j                         s|fc S  t        S |j                   D ]@  }| |   j                         s|j                  ||      |j                  ||      kD  s=|fc S  t        S rU   )ra   r   r   r,   )r   r"  r   r   r  r   s         rY   r  r    s     |MM 	D~**,w	  MM 	D~**,l2|,2- w		
 r[   parent_scratchpadr  namespace_hash
resume_mapc                    	 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t        dt        f	 fd}t        t               t               ||t                     S )	Nr   r   r   r   rS   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_writer$  r   s    rY   r)  z$_scratchpad.<locals>.get_null_resume  sf    $ ,(88AA%%&78(++ !##  s   6 	AA)call_counterinterrupt_counterresumer)  subgraph_counterF)
r
  r3   r8   r   r   r   r   r   rJ   LazyAtomicCounter)
r$  r   r  r%  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              rai }| j                  j                         D ]A  \  }}||v r+||   j                         s||   j                         ||<   5 ||          ||<   C nt        | j                  t              rO| j                  D ]:  }||v r)||   j                         s||   j                         } n+ ||          } n 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   rx   r   r   r   r   r/   RuntimeErrormapper)r  r   r   r   r   r   r   r   s           rY   r  r    s\    4#7#7;#FK 4 4566 $--& }}**, 	&GAtxD>..0%d^//1CF#A	& 
DMM4	(MM 		DxD>..0"4.,,.C#gdmo		 N@P
 	

 0kk# ,/D(()Jr[   	namespacepartsc                     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   rh   r  r   ps     rY   r   z_uuid5_str.<locals>.<genexpr>B  s$     OAjC&8
a?O   ,.N   r                )r
   r   join	hexdigest)r9  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   r>  r?  s     rY   r   z_xxhash_str.<locals>.<genexpr>J  s$     T:a+=QXXZ1DTrA  NrB  r   rC  rD  rE  rF  )r   rG  )r9  r:  rJ  s      rY   r   r   G  sf    
CHHTeTTTC "1gYaAb	{!C2J<qRAc"Rj\JJr[   tupc                     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>R  s     41mA&4s   010d)r   rg   r   rG  ri   rh   )rM  s    rY   r   r   O  s[     cE4=) DII44456 c3 Dz
 Xr[   c                   @    e Zd ZU dZeeg ef      ed<   ddZdefdZ	y)r1  _counterrU  rS   Nc                     d | _         y rU   rT  rW   s    rY   rv   zLazyAtomicCounter.__init__b  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   )rU  LAZY_ATOMIC_COUNTER_LOCK	itertoolscount__next__rW   s    rY   __call__zLazyAtomicCounter.__call__e  si    == ) @==($-OOA$6$?$?DM@ }}t}}@ }}s   1A,,B)rS   N)
rb   rc   rd   rw   r   r   ri   rl   rv   r\  rV   r[   rY   r1  r1  ]  s,    IxC())# r[   r1  r0  )r   rY  sys	threadingcollectionsr   r   collections.abcr   r   r   r   	functoolsr	   hashlibr
   typingr   r   r   r   r   r   r   r   r   langchain_core.callbacksr    langchain_core.callbacks.managerr   r   langchain_core.runnables.configr   xxhashr   langgraph.channels.baser   langgraph.checkpoint.baser   r   r   r   r   langgraph.constantsr   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   langgraph.errorsr=   langgraph.managed.baser>   langgraph.pregel.callr?   r@   langgraph.pregel.iorA   langgraph.pregel.logrB   langgraph.pregel.readrC   rD   langgraph.store.baserE   langgraph.typesrF   rG   rH   rI   rJ   rK   rL   langgraph.utils.configrM   rN   GetNextVersionversion_infor  rR   rk   rn   rh   r   r   r   rx   r   rg   r   ri   r   r   r   r   r   r  bytesr   r   r  r	  r  r  r   r   LockrX  r1  rV   r[   rY   <module>rx     sW	     
  * 7 7   
 
 
 / T : % /        @ 0 6 C - ' B *   ?8A;4a78%%0 -X -"z # #23-. () 

	L &c;&'& & & $s)S.!	&
 & 4S>3&RhuS#X/0$673- U38_% 
	 5x} 5{ 5s 5
}7}7c;&'}7 N#}7 ~.	}7
 c8C=01}7 4T#YS)*}7@c8C=01#h  
	 
  "&!>B+/*,"&!  &  sJ'  c;&'	 
 !      5>  4=  $-  T]  wsHSM'9:;  s3x(  ;'   $-! " 
#z/#  
 ( 
 ?C+/*,*.!**&* sJ'* c;&'	*
 !* * * 4=* I* ./* 4)+@@A* wsHSM'9:;* s3x(* ;'*  ;'!*" 
##
#$#* 
*< "&26DH>B+/*,*.!t$t$&t$ sJ't$ c;&'	t$
 !t$ t$ t$ t$ It$ ./t$ 4)+@@At$ wsHSM'9:;t$ s3x(t$ ;'t$  ;'!t$" 4Z $s,@'@"AAB#t$n w" "&26DH=A*.*,'R@S#XR@smR@ 	R@
 R@ &a[R@ &R@ sJ'R@ c;&'R@ !R@ R@ R@ R@ IR@ ./R@  4)+@@A!R@" $3S89:#R@$ ;'%R@& ;''R@( 4112)R@ja[c;&' ?
# 	
  c](= 01=&= = 	=
 c3h(= =@.
. . c;&'.
 . $3S89:. 	.bK% KsEz): Ks KK5 K%U
*; K KuS#u_- #  *9>>+  r[   