§
    ™ŠtjÐr  ã                  óÄ   — d Z ddlmZ ddlZddlmZmZmZ ddlm	Z	m
Z
mZ ddlmZ ddl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   G d
„ d¦  «        Z!dS )z/Async client for managing threads in LangGraph.é    )ÚannotationsN)ÚAsyncIteratorÚMappingÚSequence)ÚAnyÚLiteralÚoverload)Ú
HttpClient)ÚAsyncThreadStream)Ú_quote_path_param)Ú
CheckpointÚJsonÚOnConflictBehaviorÚPruneStrategyÚQueryParamTypesÚ	SortOrderÚ
StreamPartÚThreadÚThreadSelectFieldÚThreadSortByÚThreadStateÚThreadStatusÚThreadStreamModeÚThreadUpdateStateResponsec                  ó   — e Zd ZdZdod„Zddddœdpd„Zdddddddddœdqd„Zeddddd œdrd$„¦   «         Zedddd%œdsd'„¦   «         Zedddd%œdtd*„¦   «         Zddddd œdtd+„Zddd,œdud-„Z	ddddd.d/ddddddd0œdvdA„Z
ddddddBœdwdC„Zddd,œdudD„ZdEdddFœdxdL„Z	 	 dyddddMœdzdS„ZddddddTœd{dX„Zd.ddddddYœd|d^„Z	 d}ddd_d`œd~dg„Zddhdddiœddn„ZdS )€ÚThreadsClientaÍ  Client for managing threads in LangGraph.

    A thread maintains the state of a graph across multiple interactions/invocations (aka runs).
    It accumulates and persists the graph's state, allowing for continuity between separate
    invocations of the graph.

    ???+ example "Example"

        ```python
        client = get_client(url="http://localhost:2024"))
        new_thread = await client.threads.create(metadata={"user_id": "123"})
        ```
    Úhttpr
   ÚreturnÚNonec                ó   — || _         d S ©N)r   )Úselfr   s     úZ/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langgraph_sdk/_async/threads.pyÚ__init__zThreadsClient.__init__-   s   € ØˆŒ	ˆ	ˆ	ó    N)ÚincludeÚheadersÚparamsÚ	thread_idÚstrr&   úSequence[str] | Noner'   úMapping[str, str] | Noner(   úQueryParamTypes | Noner   c             ƒ  óÖ   K  — i }|rd                      |¦  «        |d<   |r|                     |¦  «         | j                             dt	          |¦  «        › �||pd¬¦  «        ƒ d{V —†S )a  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_client(url="http://localhost:2024")
            thread = await 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   Úgetr   )r"   r)   r&   r'   r(   Úquery_paramss         r#   r4   zThreadsClient.get0   s¢   è è € ðT (*ˆØð 	8Ø&)§h¢h¨wÑ&7Ô&7ˆL˜Ñ#Øð 	(Ø×Ò Ñ'Ô'Ð'Ø”Y—]’]Ø6Õ)¨)Ñ4Ô4Ð6Ð6ØØÐ' 4ð #ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
r%   )Úmetadatar)   Ú	if_existsÚ
superstepsÚgraph_idÚttlr'   r(   r6   r   ú
str | Noner7   úOnConflictBehavior | Noner8   ú4Sequence[dict[str, Sequence[dict[str, Any]]]] | Noner9   r:   úint | Mapping[str, Any] | Nonec             ƒ  ó  K  — i }	|r||	d<   |s|ri |pi ¥|rd|ini ¥|	d<   |r||	d<   |rd„ |D ¦   «         |	d<   |�*t          |t          t          f¦  «        r	|dd	œ|	d
<   n||	d
<   | j                             d|	||¬¦  «        ƒ d{V —†S )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.
            params: Optional query parameters to include with the request.

        Returns:
            The created thread.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            thread = await client.threads.create(
                metadata={"number":1},
                thread_id="my-thread-id",
                if_exists="raise"
            )
            ```
        r)   r9   r6   r7   c                ó6   — g | ]}d d„ |d          D ¦   «         i‘ŒS )Úupdatesc                óX   — g | ]'}|d          |                      d¦  «        |d         dœ‘Œ(S )ÚvaluesÚcommandÚas_node)rC   rD   rE   )r4   )Ú.0Úus     r#   ú
<listcomp>z3ThreadsClient.create.<locals>.<listcomp>.<listcomp>�   sN   € ð  ð  ð  ð ð	 '(¨¤kØ'(§u¢u¨YÑ'7Ô'7Ø'(¨¤|ðð ð ð  ð  r%   © )rF   Úss     r#   rH   z(ThreadsClient.create.<locals>.<listcomp>›   sQ   € ð %ð %ð %ð ð ð  ð  ð "# 9¤ð ñ  ô  ð	ð%ð %ð %r%   r8   NÚdelete©r:   Ústrategyr:   z/threads©Újsonr'   r(   )Ú
isinstanceÚintÚfloatr   Úpost)
r"   r6   r)   r7   r8   r9   r:   r'   r(   Úpayloads
             r#   ÚcreatezThreadsClient.createe   s  è è € ðV #%ˆØð 	-Ø#,ˆG�KÑ Øð 	�xð 	ð#Ø�>˜rð#à-5Ð=�J Ð)Ð)¸2ð#ˆG�JÑð ð 	-Ø#,ˆG�KÑ Øð 	ð%ð %ð $ð%ñ %ô %ˆG�LÑ!ð ˆ?Ý˜#¥¥U˜|Ñ,Ô,ð %Ø),¸(Ð!CÐ!C�˜‘�à!$�˜‘à”Y—^’^Ø˜W¨g¸fð $ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
r%   F)r:   Úreturn_minimalr'   r(   úMapping[str, Any]rV   úLiteral[False]c             ƒ  ó
   K  — d S r!   rI   ©r"   r)   r6   r:   rV   r'   r(   s          r#   r3   zThreadsClient.update²   s   è è € ð �r%   )r:   r'   r(   úLiteral[True]c             ƒ  ó
   K  — d S r!   rI   rZ   s          r#   r3   zThreadsClient.update¾   s   è è € ð ˆsr%   ÚboolúThread | Nonec             ƒ  ó
   K  — d S r!   rI   rZ   s          r#   r3   zThreadsClient.updateÊ   s   è è € ð ˜r%   c             ƒ  ó  K  — d|i}|�*t          |t          t          f¦  «        r	|ddœ|d<   n||d<   t          |pi ¦  «        }|rd|d<   | j                             dt          |¦  «        › �||pd|¬	¦  «        ƒ d{V —†S )
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").
            return_minimal: If `True`, request a 204 response with no body.
            headers: Optional custom headers to include with the request.
            params: Optional query parameters to include with the request.

        Returns:
            The updated thread, or `None` when `return_minimal=True`.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            thread = await client.threads.update(
                thread_id="my-thread-id",
                metadata={"number":1},
                ttl=43_200,
            )
            ```
        r6   NrK   rL   r:   zreturn=minimalÚPreferr0   rN   )rP   rQ   rR   Údictr   Úpatchr   )	r"   r)   r6   r:   rV   r'   r(   rT   Úrequest_headerss	            r#   r3   zThreadsClient.updateÖ   sÊ   è è € ðH $.¨xÐ"8ˆØˆ?Ý˜#¥¥U˜|Ñ,Ô,ð %Ø),¸(Ð!CÐ!C�˜‘�à!$�˜‘Ý˜w˜}¨"Ñ-Ô-ˆØð 	9Ø(8ˆO˜HÑ%Ø”Y—_’_Ø6Õ)¨)Ñ4Ô4Ð6Ð6ØØ#Ð+ tØð	 %ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
r%   r1   c             ƒ  óp   K  — | j                              dt          |¦  «        › �||¬¦  «        ƒ d{V —† dS )a  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 = get_client(url="http://localhost2024)
            await client.threads.delete(
                thread_id="my_thread_id"
            )
            ```

        r0   r1   N)r   rK   r   ©r"   r)   r'   r(   s       r#   rK   zThreadsClient.delete
  sh   è è € ð6 Œi×ÒØ6Õ)¨)Ñ4Ô4Ð6Ð6ÀÐPVð ñ 
ô 
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
ð 	
r%   é
   r   )r6   rC   ÚidsÚstatusÚlimitÚoffsetÚsort_byÚ
sort_orderÚselectÚextractr'   r(   rC   rh   ri   úThreadStatus | Nonerj   rQ   rk   rl   úThreadSortBy | Nonerm   úSortOrder | Nonern   úlist[ThreadSelectField] | Nonero   údict[str, str] | Noneúlist[Thread]c             ƒ  óÈ   K  — ||dœ}|r||d<   |r||d<   |r||d<   |r||d<   |r||d<   |r||d<   |	r|	|d<   |
r|
|d	<   | j                              d
|||¬¦  «        ƒ d{V —†S )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.
            sort_by: Sort by field.
            sort_order: Sort order.
            select: List of fields to include in the response.
            extract: Dictionary mapping aliases to JSONB paths to extract
                from thread data. Paths use dot notation for nested keys and
                bracket notation for array indices (e.g.,
                `{"last_msg": "values.messages[-1]"}`). Extracted values are
                returned in an `extracted` field on each thread. Maximum 10
                paths per request.
            headers: Optional custom headers to include with the request.
            params: Optional query parameters to include with the request.

        Returns:
            List of the threads matching the search parameters.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            threads = await client.threads.search(
                metadata={"number":1},
                status="interrupted",
                limit=15,
                offset=5
            )
            ```

        )rj   rk   r6   rC   rh   ri   rl   rm   rn   ro   z/threads/searchrN   N©r   rS   )r"   r6   rC   rh   ri   rj   rk   rl   rm   rn   ro   r'   r(   rT   s                 r#   ÚsearchzThreadsClient.search)  só   è è € ðn Øð#
ð #
ˆð ð 	+Ø"*ˆG�JÑØð 	'Ø &ˆG�HÑØð 	!Ø ˆG�E‰NØð 	'Ø &ˆG�HÑØð 	)Ø!(ˆG�IÑØð 	/Ø$.ˆG�LÑ!Øð 	'Ø &ˆG�HÑØð 	)Ø!(ˆG�IÑØ”Y—^’^ØØØØð	 $ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
r%   )r6   rC   ri   r'   r(   c             ƒ  ó|   K  — i }|r||d<   |r||d<   |r||d<   | j                              d|||¬¦  «        ƒ d{V —†S )a«  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.
        r6   rC   ri   z/threads/countrN   Nrw   )r"   r6   rC   ri   r'   r(   rT   s          r#   ÚcountzThreadsClient.countz  s‡   è è € ð* #%ˆØð 	+Ø"*ˆG�JÑØð 	'Ø &ˆG�HÑØð 	'Ø &ˆG�HÑØ”Y—^’^Ø 7°GÀFð $ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
r%   c             ƒ  óp   K  — | j                              dt          |¦  «        › d�d||¬¦  «        ƒ d{V —†S )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_client(url="http://localhost:2024)
            await client.threads.copy(
                thread_id="my_thread_id"
            )
            ```

        r0   z/copyNrN   ©r   rS   r   rf   s       r#   ÚcopyzThreadsClient.copyš  sc   è è € ð6 ”Y—^’^Ø;Õ)¨)Ñ4Ô4Ð;Ð;Ð;ØØØð	 $ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
r%   rK   )rM   r'   r(   Ú
thread_idsúSequence[str]rM   r   údict[str, Any]c             ƒ  ól   K  — d|i}|dk    r||d<   | j                              d|||¬¦  «        ƒ d{V —†S )aY  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_client(url="http://localhost:2024")
            result = await client.threads.prune(
                thread_ids=["thread_1", "thread_2"],
            )
            print(result)  # {'pruned_count': 2}
            ```

        r~   rK   rM   z/threads/prunerN   Nrw   )r"   r~   rM   r'   r(   rT   s         r#   ÚprunezThreadsClient.prune¼  sp   è è € ðB ˜*ð#
ˆð �xÒÐØ"*ˆG�JÑØ”Y—^’^Ø 7°GÀFð $ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
r%   )Ú	subgraphsr'   r(   Ú
checkpointúCheckpoint | NoneÚcheckpoint_idrƒ   r   c             ƒ  óÐ  K  — |r8| j                              dt          |¦  «        › d�||dœ||¬¦  «        ƒ d{V —†S |r\d|i}|ri |¥t          |¦  «        ¥}| j                              dt          |¦  «        › dt          |¦  «        › �||¬¦  «        ƒ d{V —†S d|i}|ri |¥t          |¦  «        ¥}| j                              dt          |¦  «        › d	�||¬¦  «        ƒ d{V —†S )
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.
            checkpoint_id: (deprecated) The checkpoint ID to get the state of.
            subgraphs: Include subgraphs states.
            headers: Optional custom headers to include with the request.
            params: Optional query parameters to include with the request.

        Returns:
            The thread of the state.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024)
            thread_state = await 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'
                    }
            }
            ```
        r0   z/state/checkpoint)r„   rƒ   rN   Nrƒ   z/state/)r(   r'   ú/state)r   rS   r   rb   r4   )r"   r)   r„   r†   rƒ   r'   r(   Ú
get_paramss           r#   Ú	get_statezThreadsClient.get_stateå  s�  è è € ð\ ð 	ØœŸšØKÕ-¨iÑ8Ô8ÐKÐKÐKØ$.¸YÐGÐGØØð	 (ñ ô ð ð ð ð ð ð ð ð ð 	Ø% yÐ1ˆJØð <Ø; 
Ð;­d°6©l¬lÐ;�
ØœŸšØcÕ-¨iÑ8Ô8ÐcÐcÕARÐS`ÑAaÔAaÐcÐcØ!Øð 'ñ ô ð ð ð ð ð ð ð ð & yÐ1ˆJØð <Ø; 
Ð;­d°6©l¬lÐ;�
ØœŸšØ@Õ-¨iÑ8Ô8Ð@Ð@Ð@Ø!Øð 'ñ ô ð ð ð ð ð ð ð r%   )rE   r„   r†   r'   r(   ú&dict[str, Any] | Sequence[dict] | NonerE   r   c             ƒ  ó¢   K  — d|i}|r||d<   |r||d<   |r||d<   | j                              dt          |¦  «        › d�|||¬¦  «        ƒ d{V —†S )	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.
            checkpoint_id: (deprecated) The checkpoint ID to update the state of.
            headers: Optional custom headers to include with the request.
            params: Optional query parameters to include with the request.

        Returns:
            Response after updating a thread's state.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024)
            response = await client.threads.update_state(
                thread_id="my_thread_id",
                values={"messages":[{"role": "user", "content": "hello!"}]},
                as_node="my_node",
            )
            print(response)
            ```
            ```shell

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

            {
                'checkpoint': {
                    'thread_id': 'e2496803-ecd5-4e0c-a779-3226296181c2',
                    'checkpoint_ns': '',
                    'checkpoint_id': '1ef4a9b8-e6fb-67b1-8001-abd5184439d1',
                    'checkpoint_map': {}
                }
            }
            ```
        rC   r†   r„   rE   r0   rˆ   rN   Nr|   )	r"   r)   rC   rE   r„   r†   r'   r(   rT   s	            r#   Úupdate_statezThreadsClient.update_statem  s¨   è è € ðf �fð#
ˆð ð 	5Ø'4ˆG�OÑ$Øð 	/Ø$.ˆG�LÑ!Øð 	)Ø!(ˆG�IÑØ”Y—^’^Ø<Õ)¨)Ñ4Ô4Ð<Ð<Ð<ØØØð	 $ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
r%   )rj   Úbeforer6   r„   r'   r(   rŽ   ústr | Checkpoint | NoneúMapping[str, Any] | Noneúlist[ThreadState]c             ƒ  ó¢   K  — d|i}|r||d<   |r||d<   |r||d<   | j                              dt          |¦  «        › d�|||¬¦  «        ƒ d{V —†S )	az  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.
            params: Optional query parameters to include with the request.

        Returns:
            The state history of the thread.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024)
            thread_state = await client.threads.get_history(
                thread_id="my_thread_id",
                limit=5,
            )
            ```

        rj   rŽ   r6   r„   r0   z/historyrN   Nr|   )	r"   r)   rj   rŽ   r6   r„   r'   r(   rT   s	            r#   Úget_historyzThreadsClient.get_history¯  s¨   è è € ðJ �Uð#
ˆð ð 	'Ø &ˆG�HÑØð 	+Ø"*ˆG�JÑØð 	/Ø$.ˆG�LÑ!Ø”Y—^’^Ø>Õ)¨)Ñ4Ô4Ð>Ð>Ð>ØØØð	 $ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ð 	
r%   Ússe)r'   Úrun_start_timeoutÚ	transportÚassistant_idr•   úfloat | Noner–   úLiteral['sse', 'websocket']r   c          	     ó¦   — |dvrt          d¦  «        ‚t          | j        |�|nt          t	          j        ¦   «         ¦  «        ||||du|¬¦  «        S )uÁ  Open a v3 thread-centric streaming session.

        When `thread_id` is None, a fresh UUIDv4 is minted client-side and
        included in the URL of subsequent `POST /threads/{thread_id}/...`
        calls. The server creates the thread row lazily on the first
        `run.start` (internal server detail â€” the SDK does not send any
        `if_not_exists` flag). The v3 protocol response carries only
        `run_id`, never `thread_id` â€” that's why the SDK mints the id
        client-side.

        Args:
            thread_id: optional explicit thread identifier. Defaults to a
                fresh UUIDv4.
            assistant_id: assistant the run will use. Required.
            headers: optional headers forwarded on every command and event
                request for this stream session.
            run_start_timeout: optional seconds to wait for an in-flight
                `run.start` before subscribing operations raise
                `asyncio.TimeoutError`. Defaults to `None` (wait forever).
            transport: event transport to use â€” `"sse"` (default) or
                `"websocket"`.

        Returns:
            An `AsyncThreadStream` to use as an async context manager.
        )r”   Ú	websocketz'transport must be 'sse' or 'websocket'.N)r   r)   r—   r'   r•   Úexplicit_thread_idÚtransport_kind)Ú
ValueErrorr   r   r*   ÚuuidÚuuid4)r"   r)   r—   r'   r•   r–   s         r#   ÚstreamzThreadsClient.streamã  sj   € ðD Ð0Ð0Ð0ÝÐFÑGÔGÐGÝ Ø”Ø#,Ð#8�i�i½cÅ$Ä*Á,Ä,Ñ>OÔ>OØ%ØØ/Ø(°Ð4Ø$ð
ñ 
ô 
ð 	
r%   Ú	run_modes)Úlast_event_idÚstream_moder'   r(   r£   r¤   ú-ThreadStreamMode | Sequence[ThreadStreamMode]úAsyncIterator[StreamPart]c             ƒ  ó²   K  — d|i}|r|                      |¦  «         | j                             dt          |¦  «        › d�di |rd|ini ¥|pi ¥|¬¦  «        S )a’  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",
            ):
                print(chunk)
            ```

        r¤   r0   z/streamÚGETzLast-Event-IDr1   )r3   r   r¡   r   )r"   r)   r£   r¤   r'   r(   r5   s          r#   Újoin_streamzThreadsClient.join_stream  s™   è è € ðB ˜;ð
ˆð ð 	(Ø×Ò Ñ'Ô'Ð'ØŒy×ÒØ=Õ)¨)Ñ4Ô4Ð=Ð=Ð=ØðØ7DÐL�O ]Ð3Ð3È"ðà�=˜bðð  ð  ñ 
ô 
ð 	
r%   )r   r
   r   r   )
r)   r*   r&   r+   r'   r,   r(   r-   r   r   )r6   r   r)   r;   r7   r<   r8   r=   r9   r;   r:   r>   r'   r,   r(   r-   r   r   )r)   r*   r6   rW   r:   r>   rV   rX   r'   r,   r(   r-   r   r   )r)   r*   r6   rW   r:   r>   rV   r[   r'   r,   r(   r-   r   r   )r)   r*   r6   rW   r:   r>   rV   r]   r'   r,   r(   r-   r   r^   )r)   r*   r'   r,   r(   r-   r   r   )r6   r   rC   r   rh   r+   ri   rp   rj   rQ   rk   rQ   rl   rq   rm   rr   rn   rs   ro   rt   r'   r,   r(   r-   r   ru   )r6   r   rC   r   ri   rp   r'   r,   r(   r-   r   rQ   )
r~   r   rM   r   r'   r,   r(   r-   r   r€   )NN)r)   r*   r„   r…   r†   r;   rƒ   r]   r'   r,   r(   r-   r   r   )r)   r*   rC   r‹   rE   r;   r„   r…   r†   r;   r'   r,   r(   r-   r   r   )r)   r*   rj   rQ   rŽ   r�   r6   r�   r„   r…   r'   r,   r(   r-   r   r‘   r!   )r)   r;   r—   r*   r'   r,   r•   r˜   r–   r™   r   r   )r)   r*   r£   r;   r¤   r¥   r'   r,   r(   r-   r   r¦   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r$   r4   rU   r	   r3   rK   rx   rz   r}   r‚   rŠ   r�   r“   r¡   r©   rI   r%   r#   r   r      sd  € € € € € ðð ðð ð ð ð )-Ø,0Ø)-ð3
ð 3
ð 3
ð 3
ð 3
ð 3
ðp Ø $Ø/3ØKOØ#Ø.2Ø,0Ø)-ðK
ð K
ð K
ð K
ð K
ð K
ðZ ð /3Ø).Ø,0Ø)-ð	ð 	ð 	ð 	ð 	ñ „Xð	ð ð /3à,0Ø)-ð	ð 	ð 	ð 	ð 	ñ „Xð	ð ð /3à,0Ø)-ð	ð 	ð 	ð 	ð 	ñ „Xð	ð  /3Ø$Ø,0Ø)-ð2
ð 2
ð 2
ð 2
ð 2
ð 2
ðp -1Ø)-ð
ð 
ð 
ð 
ð 
ð 
ðD ØØ$(Ø&*ØØØ'+Ø'+Ø15Ø)-Ø,0Ø)-ðO
ð O
ð O
ð O
ð O
ð O
ðh ØØ&*Ø,0Ø)-ð
ð 
ð 
ð 
ð 
ð 
ðH -1Ø)-ð 
ð  
ð  
ð  
ð  
ð  
ðL #+Ø,0Ø)-ð'
ð '
ð '
ð '
ð '
ð '
ðX )-Ø$(ð	Fð  Ø,0Ø)-ðFð Fð Fð Fð Fð FðZ #Ø(,Ø$(Ø,0Ø)-ð@
ð @
ð @
ð @
ð @
ð @
ðL Ø*.Ø-1Ø(,Ø,0Ø)-ð2
ð 2
ð 2
ð 2
ð 2
ð 2
ðl !%ð,
ð
 -1Ø*.Ø16ð,
ð ,
ð ,
ð ,
ð ,
ð ,
ðd %)ØEPØ,0Ø)-ð-
ð -
ð -
ð -
ð -
ð -
ð -
ð -
r%   r   )"r­   Ú
__future__r   rŸ   Úcollections.abcr   r   r   Útypingr   r   r	   Úlanggraph_sdk._async.httpr
   Úlanggraph_sdk._async.streamr   Úlanggraph_sdk._shared.utilitiesr   Úlanggraph_sdk.schemar   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rI   r%   r#   ú<module>rµ      st  ðØ 5Ð 5à "Ð "Ð "Ð "Ð "Ð "à €€€Ø <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ø )Ð )Ð )Ð )Ð )Ð )Ð )Ð )Ð )Ð )à 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø =Ð =Ð =Ð =Ð =Ð =ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð$`
ð `
ð `
ð `
ð `
ñ `
ô `
ð `
ð `
ð `
r%   