
    }
i                    h    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d	S )
z@Replay state for subgraph checkpoint loading during time-travel.    )annotations)TYPE_CHECKING)NS_END)RunnableConfig)BaseCheckpointSaverCheckpointTuplec                  6    e Zd ZdZdZddZdd
ZddZddZdS )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_nsr   strreturnNonec                :    || _         t                      | _        d S )N)r   setr   )selfr   s     C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\langgraph/_internal/_replay.py__init__zReplayState.__init__   s    * &)UU    checkpoint_nsboolc                    t           |v r!|                    t           d          d         n|}|| j        v rdS | j                            |           dS )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   r   	stable_nss      r   _is_first_visitzReplayState._is_first_visit"   se     &&   ++A.. 	
 (((5Y'''tr   checkpointerr   checkpoint_configr   CheckpointTuple | Nonec                    |                      |          r)|                    |dd| j        iid          D ]}|c S dS |                    |          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   r   r   saveds        r   get_checkpointzReplayState.get_checkpoint4   sy     .. 	%**!&$:L(MN +    
 4%%&7888r   c                   K   |                      |          r/|                    |dd| j        iid          2 3 d{V }|c S 6 dS |                    |           d{V S )z"Async version of `get_checkpoint`.r"   r   r   r#   N)r   alistr   
aget_tupler(   s        r   aget_checkpointzReplayState.aget_checkpointK   s       .. 	+11!&$:L(MN  2           e
   4!,,->?????????s   AN)r   r   r   r   )r   r   r   r   )r   r   r   r   r   r   r   r    )	__name__
__module____qualname____doc__	__slots__r   r   r*   r.    r   r   r
   r
      s{        	 	 1I+ + + +   $9 9 9 9.@ @ @ @ @ @r   r
   N)r2   
__future__r   typingr   langgraph._internal._constantsr   langchain_core.runnablesr   langgraph.checkpoint.baser   r   r
   r4   r   r   <module>r:      s    F F " " " " " "             1 1 1 1 1 1 O777777NNNNNNNNL@ L@ L@ L@ L@ L@ L@ L@ L@ L@r   