
    i<                       S SK Jr  S SKJrJrJrJr  S SKJrJ	r	J
r
JrJrJr  S SKJr  S SKJr  S SKJrJr  S SKJr  S SKJrJrJrJrJr  \" S	\\\5      r \!\\\4   r" " S
 S\SS9r#\$\\\-  \-  4   r% " S S\5      r&S$S jr' " S S\5      r( " S S\	\    5      r) " S S\*5      r+S%S jr,      S&S jr-      S&S jr. \S\S\S\S0r/1 Skr0Sr1S'S  jr2S!S".         S(S# jjr3g!))    )annotations)AsyncIteratorIteratorMappingSequence)AnyGenericLiteral
NamedTuple	TypedDictTypeVar)RunnableConfig)uuid6)SerializerProtocolmaybe_add_typed_methods)JsonPlusSerializer)ERROR	INTERRUPTRESUME	SCHEDULEDChannelProtocolVc                  <    \ rS rSr% SrS\S'    S\S'    S\S'   S	rg
)CheckpointMetadata   z&Metadata associated with a checkpoint.z*Literal['input', 'loop', 'update', 'fork']sourceintstepzdict[str, str]parents N__name__
__module____qualname____firstlineno____doc____annotations____static_attributes__r        \/home/james-whalen/.local/lib/python3.13/site-packages/langgraph/checkpoint/base/__init__.pyr   r      s)    066 I r)   r   F)totalc                  l    \ rS rSr% SrS\S'    S\S'    S\S'    S\S	'    S
\S'    S\S'    S\S'   Srg)
Checkpoint;   z(State snapshot at a given point in time.r   vstridtszdict[str, Any]channel_valuesChannelVersionschannel_versionszdict[str, ChannelVersions]versions_seenzlist[str] | Noneupdated_channelsr    Nr!   r    r)   r*   r-   r-   ;   sR    2
F<GNG="" &% .- '&r)   r-   c                H   [        U S   U S   U S   U S   R                  5       U S   R                  5       U S   R                  5        VVs0 s H  u  pXR                  5       _M     snnU R                  S/ 5      R                  5       U R                  SS 5      S	9$ s  snnf )
Nr/   r2   r1   r3   r5   r6   pending_sendsr7   r/   r2   r1   r3   r5   r6   r9   r7   )r-   copyitemsget)
checkpointkr/   s      r*   copy_checkpointr@   X   s    
S/dd!"2388:#$67<<>/9//J/P/P/RS/Rtqq&&({/RS nn_b9>>@#(:DA	 	 Ts   Bc                  T    \ rS rSr% SrS\S'   S\S'   S\S'   S	rS
\S'   S	rS\S'   Srg	)CheckpointTuplee   z8A tuple containing a checkpoint and its associated data.r   configr-   r>   r   metadataNRunnableConfig | Noneparent_configzlist[PendingWrite] | Nonepending_writesr    )	r"   r#   r$   r%   r&   r'   rG   rH   r(   r    r)   r*   rB   rB   e   s-    B  +/M(/04N-4r)   rB   c                     \ rS rSr% Sr\" 5       rS\S'   SS.   SS jjr\	SS j5       r
SS	 jrSS
 jrSSSS.         SS jjr          SS jr S         SS jjr    SS jrSS jrSS jrSSSS.         S S jjr          SS jr S         SS jjr    SS jrS!S jrSrg)"BaseCheckpointSavero   ao  Base class for creating a graph checkpointer.

Checkpointers allow LangGraph agents to persist their state
within and across multiple interactions.

Attributes:
    serde (SerializerProtocol): Serializer for encoding/decoding checkpoints.

Note:
    When creating a custom checkpoint saver, consider implementing async
    versions to avoid blocking the main thread.
r   serdeN)rL   c               J    [        U=(       d    U R                  5      U l        g )N)r   rL   )selfrL   s     r*   __init__BaseCheckpointSaver.__init__   s    
 -U-@djjA
r)   c                    / $ )zrDefine the configuration options for the checkpoint saver.

Returns:
    list: List of configuration field specs.
r    )rN   s    r*   config_specs BaseCheckpointSaver.config_specs   s	     	r)   c                L    U R                  U5      =n(       a  UR                  $ g)zFetch a checkpoint using the given configuration.

Args:
    config: Configuration specifying which checkpoint to retrieve.

Returns:
    The requested checkpoint, or `None` if not found.
N)	get_tupler>   rN   rD   values      r*   r=   BaseCheckpointSaver.get   s)     NN6**5*### +r)   c                    [         e)a!  Fetch a checkpoint tuple using the given configuration.

Args:
    config: Configuration specifying which checkpoint to retrieve.

Returns:
    The requested checkpoint tuple, or `None` if not found.

Raises:
    NotImplementedError: Implement this method in your custom checkpoint saver.
NotImplementedErrorrN   rD   s     r*   rU   BaseCheckpointSaver.get_tuple   s
     "!r)   )filterbeforelimitc                   [         e)a  List checkpoints that match the given criteria.

Args:
    config: Base configuration for filtering checkpoints.
    filter: Additional filtering criteria.
    before: List checkpoints created before this configuration.
    limit: Maximum number of checkpoints to return.

Returns:
    Iterator of matching checkpoint tuples.

Raises:
    NotImplementedError: Implement this method in your custom checkpoint saver.
rZ   rN   rD   r^   r_   r`   s        r*   listBaseCheckpointSaver.list   s
    , "!r)   c                    [         e)a  Store a checkpoint with its configuration and metadata.

Args:
    config: Configuration for the checkpoint.
    checkpoint: The checkpoint to store.
    metadata: Additional metadata for the checkpoint.
    new_versions: New channel versions as of this write.

Returns:
    RunnableConfig: Updated configuration after storing the checkpoint.

Raises:
    NotImplementedError: Implement this method in your custom checkpoint saver.
rZ   rN   rD   r>   rE   new_versionss        r*   putBaseCheckpointSaver.put   s
    * "!r)   c                    [         e)a[  Store intermediate writes linked to a checkpoint.

Args:
    config: Configuration of the related checkpoint.
    writes: List of writes to store.
    task_id: Identifier for the task creating the writes.
    task_path: Path of the task creating the writes.

Raises:
    NotImplementedError: Implement this method in your custom checkpoint saver.
rZ   rN   rD   writestask_id	task_paths        r*   
put_writesBaseCheckpointSaver.put_writes   s
    $ "!r)   c                    [         ezDelete all checkpoints and writes associated with a specific thread ID.

Args:
    thread_id: The thread ID whose checkpoints should be deleted.
rZ   rN   	thread_ids     r*   delete_thread!BaseCheckpointSaver.delete_thread   s
     "!r)   c                h   #    U R                  U5      I Sh  vN =n(       a  UR                  $ g N7f)zAsynchronously fetch a checkpoint using the given configuration.

Args:
    config: Configuration specifying which checkpoint to retrieve.

Returns:
    The requested checkpoint, or `None` if not found.
N)
aget_tupler>   rV   s      r*   agetBaseCheckpointSaver.aget   s2      //&11151### 21s   202c                   #    [         e7f)a0  Asynchronously fetch a checkpoint tuple using the given configuration.

Args:
    config: Configuration specifying which checkpoint to retrieve.

Returns:
    The requested checkpoint tuple, or `None` if not found.

Raises:
    NotImplementedError: Implement this method in your custom checkpoint saver.
rZ   r\   s     r*   rx   BaseCheckpointSaver.aget_tuple  s      "!   	c                 #    [         e7f)a  Asynchronously list checkpoints that match the given criteria.

Args:
    config: Base configuration for filtering checkpoints.
    filter: Additional filtering criteria for metadata.
    before: List checkpoints created before this configuration.
    limit: Maximum number of checkpoints to return.

Returns:
    Async iterator of matching checkpoint tuples.

Raises:
    NotImplementedError: Implement this method in your custom checkpoint saver.
rZ   rb   s        r*   alistBaseCheckpointSaver.alist  s     , "!r}   c                   #    [         e7f)a  Asynchronously store a checkpoint with its configuration and metadata.

Args:
    config: Configuration for the checkpoint.
    checkpoint: The checkpoint to store.
    metadata: Additional metadata for the checkpoint.
    new_versions: New channel versions as of this write.

Returns:
    RunnableConfig: Updated configuration after storing the checkpoint.

Raises:
    NotImplementedError: Implement this method in your custom checkpoint saver.
rZ   rf   s        r*   aputBaseCheckpointSaver.aput*  s     * "!r}   c                   #    [         e7f)aj  Asynchronously store intermediate writes linked to a checkpoint.

Args:
    config: Configuration of the related checkpoint.
    writes: List of writes to store.
    task_id: Identifier for the task creating the writes.
    task_path: Path of the task creating the writes.

Raises:
    NotImplementedError: Implement this method in your custom checkpoint saver.
rZ   rk   s        r*   aput_writesBaseCheckpointSaver.aput_writesA  s     $ "!r}   c                   #    [         e7frr   rZ   rs   s     r*   adelete_thread"BaseCheckpointSaver.adelete_threadU  s      "!r}   c                J    [        U[        5      (       a  [        eUc  gUS-   $ )a  Generate the next version ID for a channel.

Default is to use integer versions, incrementing by `1`. If you override, you can use `str`/`int`/`float`
versions, as long as they are monotonically increasing.

Args:
    current: The current version identifier (`int`, `float`, or `str`).
    channel: Deprecated argument, kept for backwards compatibility.

Returns:
    V: The next version identifier, which must be increasing.
   )
isinstancer0   r[   )rN   currentchannels      r*   get_next_version$BaseCheckpointSaver.get_next_version`  s)     gs##%%_Q;r)   )rL   zSerializerProtocol | NonereturnNone)r   rc   )rD   r   r   zCheckpoint | None)rD   r   r   zCheckpointTuple | None)
rD   rF   r^   dict[str, Any] | Noner_   rF   r`   
int | Noner   zIterator[CheckpointTuple])
rD   r   r>   r-   rE   r   rg   r4   r   r   ) )
rD   r   rl   zSequence[tuple[str, Any]]rm   r0   rn   r0   r   r   )rt   r0   r   r   )
rD   rF   r^   r   r_   rF   r`   r   r   zAsyncIterator[CheckpointTuple])r   zV | Noner   r   r   r   )r"   r#   r$   r%   r&   r   rL   r'   rO   propertyrR   r=   rU   rc   rh   ro   ru   ry   rx   r   r   r   r   r   r(   r    r)   r*   rJ   rJ   o   s    !3 4E4
 ,0B )B 
	B  
$"$ )-(, "%" &	"
 &" " 
#"0"" " %	"
 &" 
"8 "" *" 	"
 " 
"(	"	" 
	"
$"$ )-(, % &	
 &  
(2"" " %	"
 &" 
"8 "" *" 	"
 " 
"(	"	" 
	"r)   rJ   c                      \ rS rSrSrSrg)EmptyChannelErroriu  zeRaised when attempting to get the value of a channel that hasn't been updated
for the first time yet.r    N)r"   r#   r$   r%   r&   r(   r    r)   r*   r   r   u  s     	r)   r   c                *    U S   R                  S5      $ )zGet checkpoint ID.configurablecheckpoint_id)r=   )rD   s    r*   get_checkpoint_idr   |  s    .!%%o66r)   c           	     0   UR                  5        VVs0 s H/  u  p#U[        U[        5      (       a  UR                  SS5      OU_M1     nnnU R	                  S5      U R	                  S5      4 H  nU(       d  M  UR                  5        H}  u  pSXQ;   d   U[
        ;   d  UR                  S5      (       a  M,  [        U[        5      (       a  UR                  SS5      X'   MW  [        U[        [        [        45      (       d  My  X1U'   M     M     U$ s  snnf )9Get checkpoint metadata in a backwards-compatible manner. r   rE   r   __)
r<   r   r0   replacer=   EXCLUDED_METADATA_KEYS
startswithr   boolfloat)rD   rE   r?   r/   objkeys         r*   get_checkpoint_metadatar     s     NN$$DA 	
jC&8&8199Xr"a?$   

:&

>(BCiikFC#)?"?3>>RVCWCWAs## !		(B 7AT5122 ! " D Os   6Dc                J    [        X5      nSU;   a  UR                  S5        U$ )r   rl   )r   pop)rD   rE   checkpoint_metadatas      r*   $get_serializable_checkpoint_metadatar     s,     2&C&&)r)   >	   rt   r   checkpoint_nscheckpoint_maplanggraph_nodelanggraph_pathlanggraph_steplanggraph_triggerslanggraph_checkpoint_ns   c                     SSK J n Jn  [        [        [	        [        SS95      U R                  UR                  5      R                  5       0 0 0 / S S9$ )Nr   datetimetimezoner   	clock_seq)r/   r1   r2   r3   r5   r6   r9   r7   )	r   r   r-   LATEST_VERSIONr0   r   nowutc	isoformatr   s     r*   empty_checkpointr     sJ    +
ur"#<<%//1	 	r)   N)r1   c                  SSK J nJn  UR                  UR                  5      R	                  5       nUc  U S   nO80 nUR                  5        H"  u  pXS   ;  a  M   U	R                  5       Xx'   M$     [        [        UU=(       d    [        [        US95      UU S   U S   U R                  S/ 5      SS	9$ ! [         a     Mv  f = f)
z+Create a checkpoint for the given channels.r   r   Nr3   r5   r   r6   r9   r:   )r   r   r   r   r   r<   r>   r   r-   r   r0   r   r=   )
r>   channelsr   r1   r   r   r2   valuesr?   r/   s
             r*   create_checkpointr     s     ,	hll	#	-	-	/B,-NN$DA#566LLN		 % 
+UT*+#$67 1 nn_b9	 	 % s   B66
CC)r>   r-   r   r-   )rD   r   r   
str | None)rD   r   rE   r   r   r   )r   r-   )
r>   r-   r   z$Mapping[str, ChannelProtocol] | Noner   r   r1   r   r   r-   )4
__future__r   collections.abcr   r   r   r   typingr   r	   r
   r   r   r   langchain_core.runnablesr   langgraph.checkpoint.base.idr   langgraph.checkpoint.serde.baser   r   #langgraph.checkpoint.serde.jsonplusr    langgraph.checkpoint.serde.typesr   r   r   r   r   r   r   r0   r   tuplePendingWriter   dictr4   r-   r@   rB   rJ   	Exceptionr   r   r   r   WRITES_IDX_MAPr   r   r   r   r    r)   r*   <module>r      s^   " F F  4 . W B  CeS!S#s]#% 2 sC#I--. :
5j 5C'!* CL		 	7
&8*&8 YIr62F
  ( 2 
 	 r)   