
    c
i                        d Z ddlmZ ddlZddlZddlmZmZmZm	Z	 ddl
mZmZmZ ddlZddlmZ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mZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ ddZ, G d d          Z-dS )z2Synchronous client for managing runs in LangGraph.    )annotationsN)CallableIteratorMappingSequence)AnyLiteraloverload)_get_run_metadata_from_response_sse_to_v2_dict)SyncHttpClient)AllBulkCancelRunsStatusCancelAction
CheckpointCommandConfigContextDisconnectMode
DurabilityIfNotExistsInputMultitaskStrategyOnCompletionBehaviorQueryParamTypesRun	RunCreateRunCreateMetadataRunSelectField	RunStatus
StreamMode
StreamPartStreamPartV2StreamVersionrawIterator[StreamPart]returnIterator[StreamPartV2]c              #  T   K   | D ]"}t          |j        |j                  }||V  #dS )z:Wrap a raw SSE stream, converting each event to a v2 dict.N)r   eventdata)r%   partv2s      C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\langgraph_sdk/_sync/runs.py_wrap_stream_v2_syncr/   ,   sC         TZ33>HHH     c                  |   e Zd ZdZddZedddd	dddddddddddddddddd
ddd:            Zedddd	dddddddddddddddddd;dd>            Zedddd	d	dddddddddddddddd
d?ddC            Zedddd	d	ddddddddddddddddDddE            Zdddd	d	dddddddddddddddddddd
dFddKZedddd	d	ddddddddddddddLddN            Zedddd	d	ddddddddddddddddOddP            Zdddd	d	ddddddddddddddddddQddRZdddSddWZeddddddddddddddddXddddYdd\            Z	eddddddddddddddXdddd]dd^            Z	dddddddddddddddddXddddd_dd`Z	dadbdddddcddkZ
dddSddmZd	dndddoddsZddddndddtddwZdddSddyZd	dddddzdd~ZdddSddZdS )SyncRunsClienta~  Synchronous client for managing runs in LangGraph.

    This class provides methods to create, retrieve, and manage runs, which represent
    individual executions of graphs.

    ???+ example "Example"

        ```python
        client = get_sync_client(url="http://localhost:2024")
        run = client.runs.create(thread_id="thread_123", assistant_id="asst_456")
        ```
    httpr   r'   Nonec                    || _         d S N)r3   )selfr3   s     r.   __init__zSyncRunsClient.__init__D   s    			r0   NvaluesFv1)inputcommandstream_modestream_subgraphsmetadataconfigcontext
checkpointcheckpoint_idcheckpoint_duringinterrupt_beforeinterrupt_afterfeedback_keyson_disconnectwebhookmultitask_strategyif_not_existsafter_secondsheadersparamson_run_createdversion	thread_idstrassistant_idr;   Input | Noner<   Command | Noner=   !StreamMode | Sequence[StreamMode]r>   boolr?   Mapping[str, Any] | Noner@   Config | NonerA   Context | NonerB   Checkpoint | NonerC   
str | NonerD   bool | NonerE   All | Sequence[str] | NonerF   rG   Sequence[str] | NonerH   DisconnectMode | NonerI   rJ   MultitaskStrategy | NonerK   IfNotExists | NonerL   
int | NonerM   Mapping[str, str] | NonerN   QueryParamTypes | NonerO   *Callable[[RunCreateMetadata], None] | NonerP   Literal['v1']r&   c                   d S r6    r7   rQ   rS   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   s                            r.   streamzSyncRunsClient.streamG   s	    8  #sr0   )r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   Literal['v2']r(   c                   d S r6   ri   rj   s                            r.   rk   zSyncRunsClient.streame   s	    8 "%r0   )r;   r<   r=   r>   stream_resumabler?   r@   rA   rD   rE   rF   rG   rH   on_completionrK   rI   rL   rM   rN   rO   rP   rn   ro   OnCompletionBehavior | Nonec                   d S r6   ri   r7   rQ   rS   r;   r<   r=   r>   rn   r?   r@   rA   rD   rE   rF   rG   rH   ro   rK   rI   rL   rM   rN   rO   rP   s                           r.   rk   zSyncRunsClient.stream   s	    6  #sr0   )r;   r<   r=   r>   rn   r?   r@   rA   rD   rE   rF   rG   rH   ro   rK   rI   rL   rM   rN   rO   c                   d S r6   ri   rr   s                           r.   rk   zSyncRunsClient.stream   s	    6 "%r0   )r;   r<   r=   r>   rn   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   ro   rI   rJ   rK   rL   rM   rN   rO   
durabilityrP   rt   Durability | Noner$   #Iterator[StreamPart | StreamPartV2]c                  |t          j        dt          d           i d|d|rd |                                D             ndd|	d	|
d
|d|d|d|d|d|d|d|d|d|d|d|d||||||d}|d| dnd}d!fd}| j                            |dd |                                D             ||r|nd          }|d k    rt          |          S |S )"a:  Create a run and stream the results.

        Args:
            thread_id: the thread ID to assign to the thread.
                If `None` will create a stateless run.
            assistant_id: The assistant ID or graph name to stream from.
                If using graph name, will default to first assistant created from that graph.
            input: The input to the graph.
            command: The command to execute.
            stream_mode: The stream mode(s) to use.
            stream_subgraphs: Whether to stream output from subgraphs.
            stream_resumable: Whether the stream is considered resumable.
                If true, the stream can be resumed and replayed in its entirety even after disconnection.
            metadata: Metadata to assign to the run.
            config: The configuration for the assistant.
            context: Static context to add to the assistant.
                !!! version-added "Added in version 0.6.0"
            checkpoint: The checkpoint to resume from.
            checkpoint_during: (deprecated) Whether to checkpoint during the run (or only at the end/interruption).
            interrupt_before: Nodes to interrupt immediately before they get executed.
            interrupt_after: Nodes to Nodes to interrupt immediately after they get executed.
            feedback_keys: Feedback keys to assign to run.
            on_disconnect: The disconnect mode to use.
                Must be one of 'cancel' or 'continue'.
            on_completion: Whether to delete or keep the thread created for a stateless run.
                Must be one of 'delete' or 'keep'.
            webhook: Webhook to call after LangGraph API call is done.
            multitask_strategy: Multitask strategy to use.
                Must be one of 'reject', 'interrupt', 'rollback', or 'enqueue'.
            if_not_exists: How to handle missing thread. Defaults to 'reject'.
                Must be either 'reject' (raise error if missing), or 'create' (create new thread).
            after_seconds: The number of seconds to wait before starting the run.
                Use to schedule future runs.
            headers: Optional custom headers to include with the request.
            on_run_created: Optional callback to call when a run is created.
            durability: The durability to use for the run. Values are "sync", "async", or "exit".
                "async" means checkpoints are persisted async while next graph step executes, replaces checkpoint_during=True
                "sync" means checkpoints are persisted sync after graph step executes, replaces checkpoint_during=False
                "exit" means checkpoints are only persisted when the run exits, does not save intermediate steps
            version: Stream format version. "v1" (default) returns raw SSE StreamPart
                NamedTuples. "v2" returns typed dicts with `type`, `ns`, and `data` keys.

        Returns:
            Iterator of stream results.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            async for chunk in client.runs.stream(
                thread_id=None,
                assistant_id="agent",
                input={"messages": [{"role": "user", "content": "how are you?"}]},
                stream_mode=["values","debug"],
                metadata={"name":"my_run"},
                context={"model_name": "anthropic"},
                interrupt_before=["node_to_stop_before_1","node_to_stop_before_2"],
                interrupt_after=["node_to_stop_after_1","node_to_stop_after_2"],
                feedback_keys=["my_feedback_key_1","my_feedback_key_2"],
                webhook="https://my.fake.webhook.com",
                multitask_strategy="interrupt"
            ):
                print(chunk)
            ```
            ```shell
            ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

            StreamPart(event='metadata', data={'run_id': '1ef4a9b8-d7da-679a-a45a-872054341df2'})
            StreamPart(event='values', data={'messages': [{'content': 'how are you?', 'additional_kwargs': {}, 'response_metadata': {}, 'type': 'human', 'name': None, 'id': 'fe0a5778-cfe9-42ee-b807-0adaa1873c10', 'example': False}]})
            StreamPart(event='values', data={'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}]})
            StreamPart(event='end', data=None)
            ```
        Nd`checkpoint_during` is deprecated and will be removed in a future version. Use `durability` instead.   
stacklevelr;   r<   c                    i | ]
\  }}|||S r6   ri   .0kvs      r.   
<dictcomp>z)SyncRunsClient.stream.<locals>.<dictcomp>.      CCC$!QQ]A]]]r0   r@   rA   r?   r=   r>   rn   rS   rE   rF   rG   rI   rB   rC   rD   rJ   )rK   rH   ro   rL   rt   	/threads/z/runs/streamreshttpx.Responsec                L    rt          |           x}r |           dS dS dS z)Callback function to handle the response.Nr   r   r?   rO   s     r.   on_responsez*SyncRunsClient.stream.<locals>.on_responseK  J     )/Ns/S/S#S8 )x((((() ) ) )r0   POSTc                    i | ]
\  }}|||S r6   ri   r}   s      r.   r   z)SyncRunsClient.stream.<locals>.<dictcomp>S      DDD41aam!Qmmmr0   jsonrN   rM   r   r-   r   r   )warningswarnDeprecationWarningitemsr3   rk   r/   ) r7   rQ   rS   r;   r<   r=   r>   rn   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   ro   rI   rJ   rK   rL   rM   rN   rO   rt   rP   payloadendpointr   r%   s                             `      r.   rk   zSyncRunsClient.stream   s   P (Mv"   
#
U#
GNXCC'--//CCCCTX#

 f#
 w#
 #
 ;#
  0#
  0#
 L#
  0#
 #
 ]#
 w#
  *!#
" ]##
$  !2%#
& !"4'#
( +***$1#
 #
 #
8 $ 0	//// 		) 	) 	) 	) 	) 	)
 iDD7==??DDD'5?4  
 
 d??',,,
r0   )r;   r<   r=   r>   rn   r?   r@   rA   rD   rE   rF   rI   ro   rK   rL   rM   rN   rO   r   c                   d S r6   ri   )r7   rQ   rS   r;   r<   r=   r>   rn   r?   r@   rA   rD   rE   rF   rI   ro   rK   rL   rM   rN   rO   s                        r.   createzSyncRunsClient.create\  s	    0 cr0   )r;   r<   r=   r>   rn   r?   r@   rA   rB   rC   rD   rE   rF   rI   rJ   rK   rL   rM   rN   rO   c                   d S r6   ri   )r7   rQ   rS   r;   r<   r=   r>   rn   r?   r@   rA   rB   rC   rD   rE   rF   rI   rJ   rK   rL   rM   rN   rO   s                          r.   r   zSyncRunsClient.createv  s	    4 cr0   )r;   r<   r=   r>   rn   r?   r@   rA   rB   rC   rD   rE   rF   rI   rJ   rK   ro   rL   rM   rN   rO   rt   c                  |t          j        dt          d           i d|d|rd |                                D             ndd|d	|d
|d|	d|
d|d|d|d|d|d|d|d|d|d||||d}d |                                D             }dfd}| j                            |rd| dnd|||r|nd          S ) a\  Create a background run.

        Args:
            thread_id: the thread ID to assign to the thread.
                If `None` will create a stateless run.
            assistant_id: The assistant ID or graph name to stream from.
                If using graph name, will default to first assistant created from that graph.
            input: The input to the graph.
            command: The command to execute.
            stream_mode: The stream mode(s) to use.
            stream_subgraphs: Whether to stream output from subgraphs.
            stream_resumable: Whether the stream is considered resumable.
                If true, the stream can be resumed and replayed in its entirety even after disconnection.
            metadata: Metadata to assign to the run.
            config: The configuration for the assistant.
            context: Static context to add to the assistant.
                !!! version-added "Added in version 0.6.0"
            checkpoint: The checkpoint to resume from.
            checkpoint_during: (deprecated) Whether to checkpoint during the run (or only at the end/interruption).
            interrupt_before: Nodes to interrupt immediately before they get executed.
            interrupt_after: Nodes to Nodes to interrupt immediately after they get executed.
            webhook: Webhook to call after LangGraph API call is done.
            multitask_strategy: Multitask strategy to use.
                Must be one of 'reject', 'interrupt', 'rollback', or 'enqueue'.
            on_completion: Whether to delete or keep the thread created for a stateless run.
                Must be one of 'delete' or 'keep'.
            if_not_exists: How to handle missing thread. Defaults to 'reject'.
                Must be either 'reject' (raise error if missing), or 'create' (create new thread).
            after_seconds: The number of seconds to wait before starting the run.
                Use to schedule future runs.
            headers: Optional custom headers to include with the request.
            on_run_created: Optional callback to call when a run is created.
            durability: The durability to use for the run. Values are "sync", "async", or "exit".
                "async" means checkpoints are persisted async while next graph step executes, replaces checkpoint_during=True
                "sync" means checkpoints are persisted sync after graph step executes, replaces checkpoint_during=False
                "exit" means checkpoints are only persisted when the run exits, does not save intermediate steps

        Returns:
            The created background `Run`.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            background_run = client.runs.create(
                thread_id="my_thread_id",
                assistant_id="my_assistant_id",
                input={"messages": [{"role": "user", "content": "hello!"}]},
                metadata={"name":"my_run"},
                context={"model_name": "openai"},
                interrupt_before=["node_to_stop_before_1","node_to_stop_before_2"],
                interrupt_after=["node_to_stop_after_1","node_to_stop_after_2"],
                webhook="https://my.fake.webhook.com",
                multitask_strategy="interrupt"
            )
            print(background_run)
            ```

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

            {
                'run_id': 'my_run_id',
                'thread_id': 'my_thread_id',
                'assistant_id': 'my_assistant_id',
                'created_at': '2024-07-25T15:35:42.598503+00:00',
                'updated_at': '2024-07-25T15:35:42.598503+00:00',
                'metadata': {},
                'status': 'pending',
                'kwargs':
                    {
                        'input':
                            {
                                'messages': [
                                    {
                                        'role': 'user',
                                        'content': 'how are you?'
                                    }
                                ]
                            },
                        'config':
                            {
                                'metadata':
                                    {
                                        'created_by': 'system'
                                    },
                                'configurable':
                                    {
                                        'run_id': 'my_run_id',
                                        'user_id': None,
                                        'graph_id': 'agent',
                                        'thread_id': 'my_thread_id',
                                        'checkpoint_id': None,
                                        'assistant_id': 'my_assistant_id'
                                    }
                            },
                        'context':
                            {
                                'model_name': 'openai'
                            },
                        'webhook': "https://my.fake.webhook.com",
                        'temporary': False,
                        'stream_mode': ['values'],
                        'feedback_keys': None,
                        'interrupt_after': ["node_to_stop_after_1","node_to_stop_after_2"],
                        'interrupt_before': ["node_to_stop_before_1","node_to_stop_before_2"]
                    },
                'multitask_strategy': 'interrupt'
            }
            ```
        Nrx   ry   rz   r;   r<   c                    i | ]
\  }}|||S r6   ri   r}   s      r.   r   z)SyncRunsClient.create.<locals>.<dictcomp>&  r   r0   r=   r>   rn   r@   rA   r?   rS   rE   rF   rI   rB   rC   rD   rJ   rK   )ro   rL   rt   c                    i | ]
\  }}|||S r6   ri   r}   s      r.   r   z)SyncRunsClient.create.<locals>.<dictcomp>;  s    EEEDAqq}1a}}}r0   r   r   c                L    rt          |           x}r |           dS dS dS r   r   r   s     r.   r   z*SyncRunsClient.create.<locals>.on_response=  r   r0   r   /runsr   r   )r   r   r   r   r3   post)r7   rQ   rS   r;   r<   r=   r>   rn   r?   r@   rA   rB   rC   rD   rE   rF   rI   rJ   rK   ro   rL   rM   rN   rO   rt   r   r   s                          `   r.   r   zSyncRunsClient.create  s   V (Mv"   

U
GNXCC'--//CCCCTX

 ;
  0
  0
 f
 w
 
 L
  0
 
 w
 *
  ]!
"  !2#
$ !"4%
& ]'
( +*$-
 
 
0 FEGMMOOEEE	) 	) 	) 	) 	) 	)
 y~~,5B(	((((7'5?4  
 
 	
r0   rM   rN   payloadsbuiltins.list[RunCreate]builtins.list[Run]c               d    ddfd|D             }| j                             d|||          S )z,Create a batch of stateless background runs.r   r   c                >    d |                                  D             S )Nc                    i | ]
\  }}|||S r6   ri   r}   s      r.   r   zGSyncRunsClient.create_batch.<locals>.filter_payload.<locals>.<dictcomp>T  s    FFFTQAqr0   )r   )r   s    r.   filter_payloadz3SyncRunsClient.create_batch.<locals>.filter_payloadS  s    FFW]]__FFFFr0   c                &    g | ]} |          S ri   ri   )r~   r   r   s     r.   
<listcomp>z/SyncRunsClient.create_batch.<locals>.<listcomp>V  s#    DDDNN7++DDDr0   z/runs/batchr   rM   rN   )r   r   )r3   r   )r7   r   rM   rN   filteredr   s        @r.   create_batchzSyncRunsClient.create_batchJ  s]    	G 	G 	G 	G EDDD8DDDy~~'&  
 
 	
r0   T)r;   r<   r?   r@   rA   rB   rC   rD   rE   rF   rI   rH   rJ   rK   rL   raise_errorrM   rN   rO   r   $builtins.list[dict] | dict[str, Any]c                   d S r6   ri   )r7   rQ   rS   r;   r<   r?   r@   rA   rB   rC   rD   rE   rF   rI   rH   rJ   rK   rL   r   rM   rN   rO   s                         r.   waitzSyncRunsClient.wait[  s	    2 03sr0   )r;   r<   r?   r@   rA   rD   rE   rF   rI   rH   ro   rK   rL   r   rM   rN   rO   c                   d S r6   ri   )r7   rQ   rS   r;   r<   r?   r@   rA   rD   rE   rF   rI   rH   ro   rK   rL   r   rM   rN   rO   s                       r.   r   zSyncRunsClient.waitv  s	    . 03sr0   )r;   r<   r?   r@   rA   rD   rB   rC   rE   rF   rI   rH   ro   rJ   rK   rL   r   rM   rN   rO   rt   c                  |t          j        dt          d           i d|d|rd |                                D             ndd|d	|d
|d|d|d|d|d|	d|
d|d|d|d|d|d|||d}d fd}|d| dnd}| j                            |dd |                                D             ||r|nd          S )!a  Create a run, wait until it finishes and return the final state.

        Args:
            thread_id: the thread ID to create the run on.
                If `None` will create a stateless run.
            assistant_id: The assistant ID or graph name to run.
                If using graph name, will default to first assistant created from that graph.
            input: The input to the graph.
            command: The command to execute.
            metadata: Metadata to assign to the run.
            config: The configuration for the assistant.
            context: Static context to add to the assistant.
                !!! version-added "Added in version 0.6.0"
            checkpoint: The checkpoint to resume from.
            checkpoint_during: (deprecated) Whether to checkpoint during the run (or only at the end/interruption).
            interrupt_before: Nodes to interrupt immediately before they get executed.
            interrupt_after: Nodes to Nodes to interrupt immediately after they get executed.
            webhook: Webhook to call after LangGraph API call is done.
            on_disconnect: The disconnect mode to use.
                Must be one of 'cancel' or 'continue'.
            on_completion: Whether to delete or keep the thread created for a stateless run.
                Must be one of 'delete' or 'keep'.
            multitask_strategy: Multitask strategy to use.
                Must be one of 'reject', 'interrupt', 'rollback', or 'enqueue'.
            if_not_exists: How to handle missing thread. Defaults to 'reject'.
                Must be either 'reject' (raise error if missing), or 'create' (create new thread).
            after_seconds: The number of seconds to wait before starting the run.
                Use to schedule future runs.
            raise_error: Whether to raise an error if the run fails.
            headers: Optional custom headers to include with the request.
            on_run_created: Optional callback to call when a run is created.
            durability: The durability to use for the run. Values are "sync", "async", or "exit".
                "async" means checkpoints are persisted async while next graph step executes, replaces checkpoint_during=True
                "sync" means checkpoints are persisted sync after graph step executes, replaces checkpoint_during=False
                "exit" means checkpoints are only persisted when the run exits, does not save intermediate steps

        Returns:
            The output of the `Run`.

        ???+ example "Example Usage"

            ```python

            final_state_of_run = client.runs.wait(
                thread_id=None,
                assistant_id="agent",
                input={"messages": [{"role": "user", "content": "how are you?"}]},
                metadata={"name":"my_run"},
                context={"model_name": "anthropic"},
                interrupt_before=["node_to_stop_before_1","node_to_stop_before_2"],
                interrupt_after=["node_to_stop_after_1","node_to_stop_after_2"],
                webhook="https://my.fake.webhook.com",
                multitask_strategy="interrupt"
            )
            print(final_state_of_run)
            ```

            ```shell

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

            {
                'messages': [
                    {
                        'content': 'how are you?',
                        'additional_kwargs': {},
                        'response_metadata': {},
                        'type': 'human',
                        'name': None,
                        'id': 'f51a862c-62fe-4866-863b-b0863e8ad78a',
                        '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-bf1cd3c6-768f-4c16-b62d-ba6f17ad8b36',
                        'example': False,
                        'tool_calls': [],
                        'invalid_tool_calls': [],
                        'usage_metadata': None
                    }
                ]
            }
            ```

        Nrx   ry   rz   r;   r<   c                    i | ]
\  }}|||S r6   ri   r}   s      r.   r   z'SyncRunsClient.wait.<locals>.<dictcomp>  r   r0   r@   rA   r?   rS   rE   rF   rI   rB   rC   rJ   rK   rH   rD   ro   rL   )r   rt   r   r   c                L    rt          |           x}r |           dS dS dS r   r   r   s     r.   r   z(SyncRunsClient.wait.<locals>.on_response!  r   r0   r   z
/runs/waitr   c                    i | ]
\  }}|||S r6   ri   r}   s      r.   r   z'SyncRunsClient.wait.<locals>.<dictcomp>,  r   r0   r   r   )r   r   r   r   r3   request_reconnect)r7   rQ   rS   r;   r<   r?   r@   rA   rD   rB   rC   rE   rF   rI   rH   ro   rJ   rK   rL   r   rM   rN   rO   rt   r   r   r   s                         `    r.   r   zSyncRunsClient.wait  s   h (Mv"   

U
GNXCC'--//CCCCTX

 f
 w
 
 L
  0
 
 w
 *
 ]
 !"4
 ]
  ]!
"  !2#
$ ]%
& ]'
( '$+
 
 
0	) 	) 	) 	) 	) 	) 2;1F-	----L 	 y**DD7==??DDD'5?4 + 
 
 	
r0   
   r   )limitoffsetstatusselectrM   rN   r   intr   r   RunStatus | Noner   $builtins.list[RunSelectField] | Nonec                   ||d}|||d<   |r||d<   |r|                     |           | j                            d| d||          S )a  List runs.

        Args:
            thread_id: The thread ID to list runs for.
            limit: The maximum number of results to return.
            offset: The number of results to skip.
            headers: Optional custom headers to include with the request.
            params: Optional query parameters to include with the request.

        Returns:
            The runs for the thread.

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            client.runs.list(
                thread_id="thread_id",
                limit=5,
                offset=5,
            )
            ```

        )r   r   Nr   r   r   r   rN   rM   )updater3   get)	r7   rQ   r   r   r   r   rM   rN   query_paramss	            r.   listzSyncRunsClient.list2  s    F 27&'I'I%+L" 	,%+L" 	('''y}}(	(((w  
 
 	
r0   run_idc               H    | j                             d| d| ||          S )a  Get a run.

        Args:
            thread_id: The thread ID to get.
            run_id: The run ID to get.
            headers: Optional custom headers to include with the request.

        Returns:
            `Run` object.

        ???+ example "Example Usage"

            ```python

            run = client.runs.get(
                thread_id="thread_id_to_delete",
                run_id="run_id_to_delete",
            )
            ```
        r   /runs/r   )r3   r   r7   rQ   r   rM   rN   s        r.   r   zSyncRunsClient.get`  s8    : y}}1	111176  
 
 	
r0   	interrupt)r   actionrM   rN   r   r   r   c                   |rdnd|d}|r|                     |           |r&| j                            d| d| ddd||	          S | j                            d| d| dd||	          S )
a\  Get a run.

        Args:
            thread_id: The thread ID to cancel.
            run_id: The run ID to cancel.
            wait: Whether to wait until run has completed.
            action: Action to take when cancelling the run. Possible values
                are `interrupt` or `rollback`. Default is `interrupt`.
            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.runs.cancel(
                thread_id="thread_id_to_cancel",
                run_id="run_id_to_cancel",
                wait=True,
                action="interrupt"
            )
            ```

           r   )r   r   r   r   z/cancelr   N)r   rN   rM   )r   r3   r   r   )r7   rQ   r   r   r   rM   rN   r   s           r.   cancelzSyncRunsClient.cancel  s    L $AA1
 
  	(''' 	9..<I<<V<<<# /    y~~8	88888	  
 
 	
r0   )rQ   run_idsr   r   rM   rN   r   BulkCancelRunsStatus | Nonec                   i }|r||d<   |r||d<   |r||d<   d|i}|r|                     |           | j                            d|||           dS )a  Cancel one or more runs.

        Can cancel runs by thread ID and run IDs, or by status filter.

        Args:
            thread_id: The ID of the thread containing runs to cancel.
            run_ids: List of run IDs to cancel.
            status: Filter runs by status to cancel. Must be one of
                `"pending"`, `"running"`, or `"all"`.
            action: Action to take when cancelling the run. Possible values
                are `"interrupt"` or `"rollback"`. Default is `"interrupt"`.
            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")
            # Cancel all pending runs
            client.runs.cancel_many(status="pending")
            # Cancel specific runs on a thread
            client.runs.cancel_many(
                thread_id="my_thread_id",
                run_ids=["run_1", "run_2"],
                action="rollback",
            )
            ```

        rQ   r   r   r   z/runs/cancelr   N)r   r3   r   )	r7   rQ   r   r   r   rM   rN   r   r   s	            r.   cancel_manyzSyncRunsClient.cancel_many  s    T #% 	-#,GK  	)!(GI 	' &GH(0&'9 	('''		 	 	
 	
 	
 	
 	
r0   dictc               L    | j                             d| d| dd||          S )a|  Block until a run is done. Returns the final state of the thread.

        Args:
            thread_id: The thread ID to join.
            run_id: The run ID to join.
            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.runs.join(
                thread_id="thread_id_to_join",
                run_id="run_id_to_join"
            )
            ```

        r   r   z/joinGETr   )r3   r   r   s        r.   joinzSyncRunsClient.join  sB    < y**6	66666	 + 
 
 	
r0   )cancel_on_disconnectr=   rM   rN   last_event_idr   (StreamMode | Sequence[StreamMode] | Noner   c                   ||d}|r|                     |           | j                            d| d| dd|i |rd|ini |pi pd          S )	a  Stream output from a run in real-time, until the run is done.
        Output is not buffered, so any output produced before this call will
        not be received here.

        Args:
            thread_id: The thread ID to join.
            run_id: The run ID to join.
            stream_mode: The stream mode(s) to use. Must be a subset of the stream modes passed
                when creating the run. Background runs default to having the union of all
                stream modes.
            cancel_on_disconnect: Whether to cancel the run when the stream is disconnected.
            headers: Optional custom headers to include with the request.
            params: Optional query parameters to include with the request.
            last_event_id: The last event ID to use for the stream.

        Returns:
            `None`

        ???+ example "Example Usage"

            ```python
            client = get_sync_client(url="http://localhost:2024")
            client.runs.join_stream(
                thread_id="thread_id_to_join",
                run_id="run_id_to_join",
                stream_mode=["values", "debug"]
            )
            ```

        )r=   r   r   r   z/streamr   zLast-Event-IDNr   )r   r3   rk   )	r7   rQ   r   r   r=   rM   rN   r   r   s	            r.   join_streamzSyncRunsClient.join_stream  s    T '$8
 
  	('''y8	888887DLO]33"=b     	
 	
 		
r0   c               L    | j                             d| d| ||           dS )aR  Delete a run.

        Args:
            thread_id: The thread ID to delete.
            run_id: The run ID 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 = get_sync_client(url="http://localhost:2024")
            client.runs.delete(
                thread_id="thread_id_to_delete",
                run_id="run_id_to_delete"
            )
            ```

        r   r   r   N)r3   deleter   s        r.   r   zSyncRunsClient.deleteU  sD    < 		1	111176 	 	
 	
 	
 	
 	
r0   )r3   r   r'   r4   )2rQ   rR   rS   rR   r;   rT   r<   rU   r=   rV   r>   rW   r?   rX   r@   rY   rA   rZ   rB   r[   rC   r\   rD   r]   rE   r^   rF   r^   rG   r_   rH   r`   rI   r\   rJ   ra   rK   rb   rL   rc   rM   rd   rN   re   rO   rf   rP   rg   r'   r&   )2rQ   rR   rS   rR   r;   rT   r<   rU   r=   rV   r>   rW   r?   rX   r@   rY   rA   rZ   rB   r[   rC   r\   rD   r]   rE   r^   rF   r^   rG   r_   rH   r`   rI   r\   rJ   ra   rK   rb   rL   rc   rM   rd   rN   re   rO   rf   rP   rl   r'   r(   )0rQ   r4   rS   rR   r;   rT   r<   rU   r=   rV   r>   rW   rn   rW   r?   rX   r@   rY   rA   rZ   rD   r]   rE   r^   rF   r^   rG   r_   rH   r`   ro   rp   rK   rb   rI   r\   rL   rc   rM   rd   rN   re   rO   rf   rP   rg   r'   r&   )0rQ   r4   rS   rR   r;   rT   r<   rU   r=   rV   r>   rW   rn   rW   r?   rX   r@   rY   rA   rZ   rD   r]   rE   r^   rF   r^   rG   r_   rH   r`   ro   rp   rK   rb   rI   r\   rL   rc   rM   rd   rN   re   rO   rf   rP   rl   r'   r(   )8rQ   r\   rS   rR   r;   rT   r<   rU   r=   rV   r>   rW   rn   rW   r?   rX   r@   rY   rA   rZ   rB   r[   rC   r\   rD   r]   rE   r^   rF   r^   rG   r_   rH   r`   ro   rp   rI   r\   rJ   ra   rK   rb   rL   rc   rM   rd   rN   re   rO   rf   rt   ru   rP   r$   r'   rv   )*rQ   r4   rS   rR   r;   rT   r<   rU   r=   rV   r>   rW   rn   rW   r?   rX   r@   rY   rA   rZ   rD   r]   rE   r^   rF   r^   rI   r\   ro   rp   rK   rb   rL   rc   rM   rd   rN   re   rO   rf   r'   r   ).rQ   rR   rS   rR   r;   rT   r<   rU   r=   rV   r>   rW   rn   rW   r?   rX   r@   rY   rA   rZ   rB   r[   rC   r\   rD   r]   rE   r^   rF   r^   rI   r\   rJ   ra   rK   rb   rL   rc   rM   rd   rN   re   rO   rf   r'   r   )2rQ   r\   rS   rR   r;   rT   r<   rU   r=   rV   r>   rW   rn   rW   r?   rX   r@   rY   rA   rZ   rB   r[   rC   r\   rD   r]   rE   r^   rF   r^   rI   r\   rJ   ra   rK   rb   ro   rp   rL   rc   rM   rd   rN   re   rO   rf   rt   ru   r'   r   )r   r   rM   rd   rN   re   r'   r   ),rQ   rR   rS   rR   r;   rT   r<   rU   r?   rX   r@   rY   rA   rZ   rB   r[   rC   r\   rD   r]   rE   r^   rF   r^   rI   r\   rH   r`   rJ   ra   rK   rb   rL   rc   r   rW   rM   rd   rN   re   rO   rf   r'   r   )(rQ   r4   rS   rR   r;   rT   r<   rU   r?   rX   r@   rY   rA   rZ   rD   r]   rE   r^   rF   r^   rI   r\   rH   r`   ro   rp   rK   rb   rL   rc   r   rW   rM   rd   rN   re   rO   rf   r'   r   )0rQ   r\   rS   rR   r;   rT   r<   rU   r?   rX   r@   rY   rA   rZ   rD   r]   rB   r[   rC   r\   rE   r^   rF   r^   rI   r\   rH   r`   ro   rp   rJ   ra   rK   rb   rL   rc   r   rW   rM   rd   rN   re   rO   rf   rt   ru   r'   r   )rQ   rR   r   r   r   r   r   r   r   r   rM   rd   rN   re   r'   r   )
rQ   rR   r   rR   rM   rd   rN   re   r'   r   )rQ   rR   r   rR   r   rW   r   r   rM   rd   rN   re   r'   r4   )rQ   r\   r   r_   r   r   r   r   rM   rd   rN   re   r'   r4   )
rQ   rR   r   rR   rM   rd   rN   re   r'   r   )rQ   rR   r   rR   r   rW   r=   r   rM   rd   rN   re   r   r\   r'   r&   )
rQ   rR   r   rR   rM   rd   rN   re   r'   r4   )__name__
__module____qualname____doc__r8   r
   rk   r   r   r   r   r   r   r   r   r   r   ri   r0   r.   r2   r2   6   s             #"&9A!&-1 $"&(,$()-7;6:.2/3"7;,0$(,0)-EI!%5# # # # # X#:  #"&9A!&-1 $"&(,$()-7;6:.2/3"7;,0$(,0)-EI3% % % % % X%:  #"&9A!&!&-1 $"&)-7;6:.2/359,0"$(,0)-EI!%3# # # # # X#8  #"&9A!&!&-1 $"&)-7;6:.2/359,0"$(,0)-EI1% % % % % X%B #"&9A!&!&-1 $"&(,$()-7;6:.2/359"7;,0$(,0)-EI(,!%;] ] ] ] ] ]~  #"&9A!&!&-1 $"&)-7;6:"59,0$(,0)-EI-     X2  #"&9A!&!&-1 $"&(,$()-7;6:"7;,0$(,0)-EI1     X@ #"&9A!&!&-1 $"&(,$()-7;6:"7;,059$(,0)-EI(,5v
 v
 v
 v
 v
 v
x -1)-
 
 
 
 
 
"  #"&-1 $"&(,$()-7;6:"/37;,0$( ,0)-EI/3 3 3 3 3 X34  #"&-1 $"&)-7;6:"/359,0$( ,0)-EI+3 3 3 3 3 X3: #"&-1 $"&)-(,$(7;6:"/3597;,0$( ,0)-EI(,3a
 a
 a
 a
 a
 a
N #'7;,0)-,
 ,
 ,
 ,
 ,
 ,
f -1)-
 
 
 
 
 
L *,0)-8
 8
 8
 8
 8
 8
z !%(,.2*,0)-9
 9
 9
 9
 9
 9
@ -1)-#
 #
 #
 #
 #
 #
T &+@D,0)-$(8
 8
 8
 8
 8
 8
~ -1)- 
  
  
  
  
  
  
  
r0   r2   )r%   r&   r'   r(   ).r   
__future__r   builtinsr   collections.abcr   r   r   r   typingr   r	   r
   httpxlanggraph_sdk._shared.utilitiesr   r   langgraph_sdk._sync.httpr   langgraph_sdk.schemar   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r/   r2   ri   r0   r.   <module>r      s    8 8 " " " " " "   A A A A A A A A A A A A ) ) ) ) ) ) ) ) ) )         4 3 3 3 3 3                                                 6   
 
 
 
 
 
 
 
 
 
r0   