
    =Ki^                        S r SSKJr  SSKJrJrJr  SSKJr  SSK	J
r
  SSKJrJrJrJrJrJrJrJrJrJrJrJrJrJr   " S S5      rg	)
z5Synchronous client for managing threads in LangGraph.    )annotations)IteratorMappingSequence)Any)SyncHttpClient)
CheckpointJsonOnConflictBehaviorPruneStrategyQueryParamTypes	SortOrder
StreamPartThreadThreadSelectFieldThreadSortByThreadStateThreadStatusThreadStreamModeThreadUpdateStateResponsec                     \ rS rSrSrS"S jrSSSS.         S#S jjrSSSSSSSSS.                 S$S jjrSSSS	.           S%S
 jjrSSS.       S&S jjr	SSSSSSSSSSSS.                       S'S jjr
SSSSSS.           S(S jjrSSS.       S&S jjrSSSS.         S)S jjr  S*SSSS.             S+S jjjrSSSSSS.               S,S jjrSSSSSSS.               S-S jjrSSSSS.           S.S  jjrS!rg)/SyncThreadsClient   a]  Synchronous client for managing threads in LangGraph.

This class provides methods to create, retrieve, and manage threads,
which represent conversations or stateful interactions.

???+ example "Example"

    ```python
    client = get_sync_client(url="http://localhost:2024")
    thread = client.threads.create(metadata={"user_id": "123"})
    ```
c                    Xl         g )Nhttp)selfr   s     ]/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/langgraph_sdk/_sync/threads.py__init__SyncThreadsClient.__init__)   s    	    N)includeheadersparamsc                   0 nU(       a  SR                  U5      US'   U(       a  UR                  U5        U R                  R                  SU 3UU=(       d    SS9$ )a2  Get a thread by ID.

Args:
    thread_id: The ID of the thread to get.
    include: Additional fields to include in the response.
        Supported values: `"ttl"`.
    headers: Optional custom headers to include with the request.
    params: Optional query parameters to include with the request.

Returns:
    `Thread` object.

???+ example "Example Usage"

    ```python
    client = get_sync_client(url="http://localhost:2024")
    thread = client.threads.get(
        thread_id="my_thread_id"
    )
    print(thread)
    ```
    ```shell
    -----------------------------------------------------

    {
        'thread_id': 'my_thread_id',
        'created_at': '2024-07-18T18:35:15.540834+00:00',
        'updated_at': '2024-07-18T18:35:15.540834+00:00',
        'metadata': {'graph_id': 'agent'}
    }
    ```

,r"   	/threads/Nr#   r$   )joinupdater   get)r   	thread_idr"   r#   r$   query_paramss         r   r+   SyncThreadsClient.get,   s`    R (*&)hhw&7L#'yy}}	{#'4  
 	
r!   )metadatar,   	if_exists
superstepsgraph_idttlr#   r$   c                  0 n	U(       a  X)S'   U(       d  U(       a  0 U=(       d    0 EU(       a  SU0O0 EU	S'   U(       a  X9S'   U(       aG  U V
Vs/ s H4  n
SU
S    Vs/ s H  nUS   UR                  S5      US   S	.PM      sn0PM6     snn
U	S
'   Ub(  [        U[        [        45      (       a	  USS.U	S'   OXiS'   U R                  R                  SXUS9$ s  snf s  snn
f )a  Create a new thread.

Args:
    metadata: Metadata to add to thread.
    thread_id: ID of thread.
        If `None`, ID will be a randomly generated UUID.
    if_exists: How to handle duplicate creation. Defaults to 'raise' under the hood.
        Must be either 'raise' (raise error if duplicate), or 'do_nothing' (return existing thread).
    supersteps: Apply a list of supersteps when creating a thread, each containing a sequence of updates.
        Each update has `values` or `command` and `as_node`. Used for copying a thread between deployments.
    graph_id: Optional graph ID to associate with the thread.
    ttl: Optional time-to-live in minutes for the thread. You can pass an
        integer (minutes) or a mapping with keys `ttl` and optional
        `strategy` (defaults to "delete").
    headers: Optional custom headers to include with the request.

Returns:
    The created `Thread`.

???+ example "Example Usage"

    ```python
    client = get_sync_client(url="http://localhost:2024")
    thread = client.threads.create(
        metadata={"number":1},
        thread_id="my-thread-id",
        if_exists="raise"
    )
    ```
    )
r,   r2   r/   r0   updatesvaluescommandas_node)r6   r7   r8   r1   deleter3   strategyr3   z/threadsjsonr#   r$   )r+   
isinstanceintfloatr   post)r   r/   r,   r0   r1   r2   r3   r#   r$   payloadsus               r   createSyncThreadsClient.create`   s   V #%#,K x#>r#-5J)2#GJ #,K  $% $A  "#9  ".A	 '(k'(uuY'7'(|
 ". 	 $%GL! ?#U|,,),(!C!$yy~~jwPV~WW# %s   C%CCC)r3   r#   r$   c                   SU0nUb(  [        U[        [        45      (       a	  USS.US'   OX6S'   U R                  R	                  SU 3UUUS9$ )a  Update a thread.

Args:
    thread_id: ID of thread to update.
    metadata: Metadata to merge with existing thread metadata.
    ttl: Optional time-to-live in minutes for the thread. You can pass an
        integer (minutes) or a mapping with keys `ttl` and optional
        `strategy` (defaults to "delete").
    headers: Optional custom headers to include with the request.
    params: Optional query parameters to include with the request.

Returns:
    The created `Thread`.

???+ example "Example Usage"

    ```python
    client = get_sync_client(url="http://localhost:2024")
    thread = client.threads.update(
        thread_id="my-thread-id",
        metadata={"number":1},
        ttl=43_200,
    )
    ```
r/   r9   r:   r3   r'   r<   )r>   r?   r@   r   patch)r   r,   r/   r3   r#   r$   rB   s          r   r*   SyncThreadsClient.update   sg    D $.x"8?#U|,,),(!C!$yy	{#	  
 	
r!   r(   c               >    U R                   R                  SU 3X#S9  g)aY  Delete a thread.

Args:
    thread_id: The ID of the thread to delete.
    headers: Optional custom headers to include with the request.
    params: Optional query parameters to include with the request.

Returns:
    `None`

???+ example "Example Usage"

    ```python
    client.threads.delete(
        thread_id="my_thread_id"
    )
    ```

r'   r(   N)r   r9   r   r,   r#   r$   s       r   r9   SyncThreadsClient.delete   s"    4 			9YK0'Qr!   
   r   )r/   r6   idsstatuslimitoffsetsort_by
sort_orderselectr#   r$   c                   UUS.nU(       a  XS'   U(       a  X,S'   U(       a  X<S'   U(       a  XLS'   U(       a  X|S'   U(       a  XS'   U	(       a  XS'   U R                   R                  S	XUS
9$ )a  Search for threads.

Args:
    metadata: Thread metadata to filter on.
    values: State values to filter on.
    ids: List of thread IDs to filter by.
    status: Thread status to filter on.
        Must be one of 'idle', 'busy', 'interrupted' or 'error'.
    limit: Limit on number of threads to return.
    offset: Offset in threads table to start search from.
    headers: Optional custom headers to include with the request.

Returns:
    List of the threads matching the search parameters.

???+ example "Example Usage"

    ```python
    client = get_sync_client(url="http://localhost:2024")
    threads = client.threads.search(
        metadata={"number":1},
        status="interrupted",
        limit=15,
        offset=5
    )
    ```
)rP   rQ   r/   r6   rN   rO   rR   rS   rT   z/threads/searchr<   r   rA   )r   r/   r6   rN   rO   rP   rQ   rR   rS   rT   r#   r$   rB   s                r   searchSyncThreadsClient.search   s    V #
 "*J &H EN &H!(I$.L! &Hyy~~GV  
 	
r!   )r/   r6   rO   r#   r$   c               ~    0 nU(       a  XS'   U(       a  X&S'   U(       a  X6S'   U R                   R                  SXdUS9$ )ac  Count threads matching filters.

Args:
    metadata: Thread metadata to filter on.
    values: State values to filter on.
    status: Thread status to filter on.
    headers: Optional custom headers to include with the request.
    params: Optional query parameters to include with the request.

Returns:
    int: Number of threads matching the criteria.
r/   r6   rO   z/threads/countr<   rV   )r   r/   r6   rO   r#   r$   rB   s          r   countSyncThreadsClient.count6  sK    * #%"*J &H &Hyy~~7F  
 	
r!   c               @    U R                   R                  SU S3SX#S9$ )a  Copy a thread.

Args:
    thread_id: The ID of the thread to copy.
    headers: Optional custom headers to include with the request.
    params: Optional query parameters to include with the request.

Returns:
    `None`

???+ example "Example Usage"

    ```python
    client = get_sync_client(url="http://localhost:2024")
    client.threads.copy(
        thread_id="my_thread_id"
    )
    ```

r'   z/copyNr<   rV   rK   s       r   copySyncThreadsClient.copyV  s.    6 yy~~	{%(tW  
 	
r!   r9   )r;   r#   r$   c               T    SU0nUS:w  a  X%S'   U R                   R                  SXSUS9$ )a  Prune threads by ID.

Args:
    thread_ids: List of thread IDs to prune.
    strategy: The prune strategy. `"delete"` removes threads entirely.
        `"keep_latest"` prunes old checkpoints but keeps threads and their
        latest state. Defaults to `"delete"`.
    headers: Optional custom headers to include with the request.
    params: Optional query parameters to include with the request.

Returns:
    A dict containing `pruned_count` (number of threads pruned).

???+ example "Example Usage"

    ```python
    client = get_sync_client(url="http://localhost:2024")
    result = client.threads.prune(
        thread_ids=["thread_1", "thread_2"],
    )
    print(result)  # {'pruned_count': 2}
    ```


thread_idsr9   r;   z/threads/pruner<   rV   )r   r`   r;   r#   r$   rB   s         r   pruneSyncThreadsClient.pruneu  sD    B *#
 x"*Jyy~~7F  
 	
r!   F)	subgraphsr#   r$   c               J   U(       a"  U R                   R                  SU S3X$S.UUS9$ U(       a;  SU0nU(       a  0 UE[        U5      EnU R                   R                  SU SU 3UUS9$ SU0nU(       a  0 UE[        U5      EnU R                   R                  SU S3UUS9$ )	a  Get the state of a thread.

Args:
    thread_id: The ID of the thread to get the state of.
    checkpoint: The checkpoint to get the state of.
    subgraphs: Include subgraphs states.
    headers: Optional custom headers to include with the request.

Returns:
    The thread of the state.

???+ example "Example Usage"

    ```python
    client = get_sync_client(url="http://localhost:2024")
    thread_state = client.threads.get_state(
        thread_id="my_thread_id",
        checkpoint_id="my_checkpoint_id"
    )
    print(thread_state)
    ```

    ```shell
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

    {
        'values': {
            'messages': [
                {
                    'content': 'how are you?',
                    'additional_kwargs': {},
                    'response_metadata': {},
                    'type': 'human',
                    'name': None,
                    'id': 'fe0a5778-cfe9-42ee-b807-0adaa1873c10',
                    'example': False
                },
                {
                    'content': "I'm doing well, thanks for asking! I'm an AI assistant created by Anthropic to be helpful, honest, and harmless.",
                    'additional_kwargs': {},
                    'response_metadata': {},
                    'type': 'ai',
                    'name': None,
                    'id': 'run-159b782c-b679-4830-83c6-cef87798fe8b',
                    'example': False,
                    'tool_calls': [],
                    'invalid_tool_calls': [],
                    'usage_metadata': None
                }
            ]
        },
        'next': [],
        'checkpoint':
            {
                'thread_id': 'e2496803-ecd5-4e0c-a779-3226296181c2',
                'checkpoint_ns': '',
                'checkpoint_id': '1ef4a9b8-e6fb-67b1-8001-abd5184439d1'
            }
        'metadata':
            {
                'step': 1,
                'run_id': '1ef4a9b8-d7da-679a-a45a-872054341df2',
                'source': 'loop',
                'writes':
                    {
                        'agent':
                            {
                                'messages': [
                                    {
                                        'id': 'run-159b782c-b679-4830-83c6-cef87798fe8b',
                                        'name': None,
                                        'type': 'ai',
                                        'content': "I'm doing well, thanks for asking! I'm an AI assistant created by Anthropic to be helpful, honest, and harmless.",
                                        'example': False,
                                        'tool_calls': [],
                                        'usage_metadata': None,
                                        'additional_kwargs': {},
                                        'response_metadata': {},
                                        'invalid_tool_calls': []
                                    }
                                ]
                            }
                    },
        'user_id': None,
        'graph_id': 'agent',
        'thread_id': 'e2496803-ecd5-4e0c-a779-3226296181c2',
        'created_by': 'system',
        'assistant_id': 'fe096781-5601-53d2-b2f6-0d3403f7e9ca'},
        'created_at': '2024-07-25T15:35:44.184703+00:00',
        'parent_config':
            {
                'thread_id': 'e2496803-ecd5-4e0c-a779-3226296181c2',
                'checkpoint_ns': '',
                'checkpoint_id': '1ef4a9b8-d80d-6fa7-8000-9300467fad0f'
            }
    }
    ```

r'   z/state/checkpoint)
checkpointrc   r<   rc   z/state/)r$   r#   /state)r   rA   dictr+   )r   r,   re   checkpoint_idrc   r#   r$   
get_paramss           r   	get_stateSyncThreadsClient.get_state  s    Z 99>>I;&78$.G	 "   %y1J;
;d6l;
99==I;gm_=! !   &y1J;
;d6l;
99==I;f-! !  r!   )r8   re   rh   r#   r$   c                   SU0nU(       a  XXS'   U(       a  XHS'   U(       a  X8S'   U R                   R                  SU S3XUS9$ )a  Update the state of a thread.

Args:
    thread_id: The ID of the thread to update.
    values: The values to update the state with.
    as_node: Update the state as if this node had just executed.
    checkpoint: The checkpoint to update the state of.
    headers: Optional custom headers to include with the request.

Returns:
    Response after updating a thread's state.

???+ example "Example Usage"

    ```python

    response = await client.threads.update_state(
        thread_id="my_thread_id",
        values={"messages":[{"role": "user", "content": "hello!"}]},
        as_node="my_node",
    )
    print(response)

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

    {
        'checkpoint': {
            'thread_id': 'e2496803-ecd5-4e0c-a779-3226296181c2',
            'checkpoint_ns': '',
            'checkpoint_id': '1ef4a9b8-e6fb-67b1-8001-abd5184439d1',
            'checkpoint_map': {}
        }
    }
    ```

r6   rh   re   r8   r'   rf   r<   rV   )	r   r,   r6   r8   re   rh   r#   r$   rB   s	            r   update_stateSyncThreadsClient.update_state%  s_    ` f#
 '4O$$.L!!(Iyy~~	{&)QW  
 	
r!   )rP   beforer/   re   r#   r$   c                   SU0nU(       a  X8S'   U(       a  XHS'   U(       a  XXS'   U R                   R                  SU S3UUUS9$ )a  Get the state history of a thread.

Args:
    thread_id: The ID of the thread to get the state history for.
    checkpoint: Return states for this subgraph. If empty defaults to root.
    limit: The maximum number of states to return.
    before: Return states before this checkpoint.
    metadata: Filter states by metadata key-value pairs.
    headers: Optional custom headers to include with the request.

Returns:
    The state history of the `Thread`.

???+ example "Example Usage"

    ```python

    thread_state = client.threads.get_history(
        thread_id="my_thread_id",
        limit=5,
        before="my_timestamp",
        metadata={"name":"my_name"}
    )
    ```

rP   ro   r/   re   r'   z/historyr<   rV   )	r   r,   rP   ro   r/   re   r#   r$   rB   s	            r   get_historySyncThreadsClient.get_historya  sc    L U#
  &H"*J$.L!yy~~	{(+	  
 	
r!   	run_modes)stream_modelast_event_idr#   r$   c                   SU0nU(       a  UR                  U5        U R                  R                  SU S3S0 U(       a  SU0O0 EU=(       d    0 EUS9$ )a3  Get a stream of events for a thread.

Args:
    thread_id: The ID of the thread to get the stream for.
    last_event_id: The ID of the last event to get.
    headers: Optional custom headers to include with the request.
    params: Optional query parameters to include with the request.

Returns:
    An iterator of stream parts.

???+ example "Example Usage"

    ```python

    for chunk in client.threads.join_stream(
        thread_id="my_thread_id",
        last_event_id="my_event_id",
        stream_mode="run_modes",
    ):
        print(chunk)
    ```

rt   r'   z/streamGETzLast-Event-IDr(   )r*   r   stream)r   r,   rt   ru   r#   r$   r-   s          r   join_streamSyncThreadsClient.join_stream  sv    D ;
 'yy	{'*7DO]3"=b     
 	
r!   r   )r   r   returnNone)
r,   strr"   Sequence[str] | Noner#   Mapping[str, str] | Noner$   QueryParamTypes | Noner{   r   )r/   r
   r,   
str | Noner0   zOnConflictBehavior | Noner1   z4Sequence[dict[str, Sequence[dict[str, Any]]]] | Noner2   r   r3   int | Mapping[str, Any] | Noner#   r   r$   r   r{   r   )r,   r}   r/   zMapping[str, Any]r3   r   r#   r   r$   r   r{   r   )r,   r}   r#   r   r$   r   r{   r|   )r/   r
   r6   r
   rN   r~   rO   ThreadStatus | NonerP   r?   rQ   r?   rR   zThreadSortBy | NonerS   zSortOrder | NonerT   zlist[ThreadSelectField] | Noner#   r   r$   r   r{   zlist[Thread])r/   r
   r6   r
   rO   r   r#   r   r$   r   r{   r?   )
r`   zSequence[str]r;   r   r#   r   r$   r   r{   zdict[str, Any])NN)r,   r}   re   Checkpoint | Nonerh   r   rc   boolr#   r   r$   r   r{   r   )r,   r}   r6   z&dict[str, Any] | Sequence[dict] | Noner8   r   re   r   rh   r   r#   r   r$   r   r{   r   )r,   r}   rP   r?   ro   zstr | Checkpoint | Noner/   zMapping[str, Any] | Nonere   r   r#   r   r$   r   r{   zlist[ThreadState])r,   r}   rt   z-ThreadStreamMode | Sequence[ThreadStreamMode]ru   r   r#   r   r$   r   r{   zIterator[StreamPart])__name__
__module____qualname____firstlineno____doc__r   r+   rE   r*   r9   rW   rZ   r]   ra   rj   rm   rq   ry   __static_attributes__ r!   r   r   r      sU    )-,0)-2
2
 &	2

 *2
 '2
 
2
n  $/3KO#.2,0)-IX IX 	IX
 -IX IIX IX ,IX *IX 'IX 
IX` /3,0)--
-
 $	-

 ,-
 *-
 '-
 
-
f -1)-RR *	R
 'R 
R> $(&*'+'+15,0)->
 >
 	>

 ">
 $>
 >
 >
 %>
 %>
 />
 *>
 '>
 
>
F &*,0)-
 
 	

 $
 *
 '
 

H -1)-

 *	

 '
 

F #+,0)-'
!'
  	'

 *'
 ''
 
'
X )-$(	E  ,0)-EE &E "	E E *E 'E 
EX #(,$(,0)-:
:
 7:

 :
 &:
 ":
 *:
 ':
 
#:
@ *.-1(,,0)-3
3
 	3

 (3
 +3
 &3
 *3
 '3
 
3
r FQ$(,0)-.
.
 C	.

 ".
 *.
 '.
 
.
 .
r!   r   N)r   
__future__r   collections.abcr   r   r   typingr   langgraph_sdk._sync.httpr   langgraph_sdk.schemar	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r!   r   <module>r      s7    ; " 7 7  3   $i

 i

r!   