Ë
    òÏjè  ã                  ó`   — d Z ddlmZ ddlmZ ddlmZ erddlmZ ddl	m
Z
mZ  G d„ d«      Zy	)
z@Replay state for subgraph checkpoint loading during time-travel.é    )Úannotations)ÚTYPE_CHECKING)ÚNS_END)ÚRunnableConfig)ÚBaseCheckpointSaverÚCheckpointTuplec                  óT   — e Zd ZdZdZdd„Zd	d„Z	 	 	 	 	 	 	 	 d
d„Z	 	 	 	 	 	 	 	 d
d„Zy)ÚReplayStateaÛ  Tracks which subgraphs have already loaded their pre-replay checkpoint.

    During a parent replay, each subgraph's first invocation should restore the
    checkpoint from before the replay point. Subsequent invocations of the same
    subgraph (e.g. in a loop) should use normal checkpoint loading so they pick
    up freshly created checkpoints.

    The single `ReplayState` instance is shared by reference across all derived
    configs within one parent execution.
    )Úcheckpoint_idÚ_visited_nsc                ó0   — || _         t        «       | _        y )N)r   Úsetr   )Úselfr   s     úX/var/www/html/gaurav-v2/venv/lib/python3.12/site-packages/langgraph/_internal/_replay.pyÚ__init__zReplayState.__init__   s   € Ø*ˆÔô &)£UˆÕó    c                óž   — t         |v r|j                  t         d«      d   n|}|| j                  v ry| j                  j                  |«       y)a
  Return True the first time a subgraph namespace is seen.

        The task-id suffix is stripped so that the same logical subgraph
        (e.g. ``"sub_node"``) is recognized across loop iterations even
        though each iteration has a different task id.
        é   r   FT)r   Úrsplitr   Úadd)r   Úcheckpoint_nsÚ	stable_nss      r   Ú_is_first_visitzReplayState._is_first_visit"   sU   € ô ˜Ñ&ð × Ñ ¤¨Ó+¨AÒ.àð 	ð
 ˜×(Ñ(Ñ(ØØ×Ñ×Ñ˜YÔ'Ør   c                óœ   — | j                  |«      r+|j                  |dd| j                  iid¬«      D ]  }|c S  y|j                  |«      S )aL  Load the right checkpoint for a subgraph during replay.

        On the first call for a given subgraph namespace, returns the latest
        checkpoint created *before* the replay point. On subsequent calls
        (e.g. the same subgraph in a later loop iteration), falls back to
        normal latest-checkpoint loading.
        Úconfigurabler   r   ©ÚbeforeÚlimitN)r   Úlistr   Ú	get_tuple©r   r   ÚcheckpointerÚcheckpoint_configÚsaveds        r   Úget_checkpointzReplayState.get_checkpoint4   sc   € ð ×Ñ Ô.Ø%×*Ñ*Ø!Ø&¨¸$×:LÑ:LÐ(MÐNØð +ö �ð
 ’ðð Ø×%Ñ%Ð&7Ó8Ð8r   c              ƒ  óÈ   K  — | j                  |«      r/|j                  |dd| j                  iid¬«      2 3 d{  –—† }|c S |j                  |«      ƒ d{  –—† S 7 Œ!6 y7 Œ­w)z"Async version of `get_checkpoint`.r   r   r   r   N)r   Úalistr   Ú
aget_tupler!   s        r   Úaget_checkpointzReplayState.aget_checkpointK   sx   è ø€ ð ×Ñ Ô.Ø+×1Ñ1Ø!Ø&¨¸$×:LÑ:LÐ(MÐNØð  2ô  ÷ �eð
 ’à!×,Ñ,Ð->Ó?×?Ð?ðøð  ð Ø?ús1   ‚4A"¶AºA»A¾A"ÁA ÁA"ÁAÁA"N)r   ÚstrÚreturnÚNone)r   r*   r+   Úbool)r   r*   r"   r   r#   r   r+   zCheckpointTuple | None)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r%   r)   © r   r   r
   r
      ss   „ ñ	ð 1€Ió+óð$9àð9ð *ð9ð *ð	9ð
 
 ó9ð.@àð@ð *ð@ð *ð	@ð
 
 ô@r   r
   N)r1   Ú
__future__r   Útypingr   Úlanggraph._internal._constantsr   Úlangchain_core.runnablesr   Úlanggraph.checkpoint.baser   r   r
   r3   r   r   Ú<module>r9      s(   ðÙ Få "å  å 1áÝ7ßN÷L@ò L@r   