Ë
    òÏjy)  ã                  óx   — d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZ  G d„ d	«      Zy
)z%Async Store client for LangGraph SDK.é    )Úannotations)ÚMappingÚSequence)ÚAnyÚLiteral)Ú
HttpClient)Ú_provided_vals)ÚItemÚListNamespaceResponseÚQueryParamTypesÚSearchItemsResponsec                  ó   — e Zd ZdZd
d„Z	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zddddœ	 	 	 	 	 	 	 	 	 	 	 dd„Z	 	 d	 	 	 	 	 	 	 	 	 dd„Z	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Z	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd	„Z	y)ÚStoreClientaÂ  Client for interacting with the graph's shared storage.

    The Store provides a key-value storage system for persisting data across graph executions,
    allowing for stateful operations and data sharing across threads.

    ???+ example "Example"

        ```python
        client = get_client(url="http://localhost:2024")
        await client.store.put_item(["users", "user123"], "mem-123451342", {"name": "Alice", "score": 100})
        ```
    c                ó   — || _         y )N)Úhttp)Úselfr   s     úW/var/www/html/gaurav-v2/venv/lib/python3.12/site-packages/langgraph_sdk/_async/store.pyÚ__init__zStoreClient.__init__    s	   € Øˆ�	ó    Nc             ƒ  ó´   K  — |D ]  }d|v sŒt        d|› d�«      ‚ |||||dœ}	| j                  j                  dt        |	«      ||¬«      ƒ d{  –—†  y7 Œ­w)aÝ  Store or update an item.

        Args:
            namespace: A list of strings representing the namespace path.
            key: The unique identifier for the item within the namespace.
            value: A dictionary containing the item's data.
            index: Controls search indexing - None (use defaults), False (disable), or list of field paths to index.
            ttl: Optional time-to-live in minutes for the item, or None for no expiration.
            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.store.put_item(
                ["documents", "user123"],
                key="item456",
                value={"title": "My Document", "content": "Hello World"}
            )
            ```
        Ú.úInvalid namespace label 'ú1'. Namespace labels cannot contain periods ('.').)Ú	namespaceÚkeyÚvalueÚindexÚttlú/store/items©ÚjsonÚheadersÚparamsN)Ú
ValueErrorr   Úputr	   )
r   r   r   r   r   r   r"   r#   ÚlabelÚpayloads
             r   Úput_itemzStoreClient.put_item#   s|   è ø€ óH ˆEØ�eŠ|Ü Ø/°¨wÐ6gÐhóð ð ð #ØØØØñ
ˆð �i‰i�m‰mØ¤°Ó!8À'ÐRXð ó 
÷ 	
ò 	
ús   ‚
A�AAÁAÁA)Úrefresh_ttlr"   r#   c            ƒ  óæ   K  — |D ]  }d|v sŒt        d|› d�«      ‚ dj                  |«      |dœ}|�||d<   |ri |¥t        |«      ¥}| j                  j	                  d||¬«      ƒ d{  –—† S 7 Œ­w)	aÆ  Retrieve a single item.

        Args:
            key: The unique identifier for the item.
            namespace: Optional list of strings representing the namespace path.
            refresh_ttl: Whether to refresh the TTL on this read operation. If `None`, uses the store's default behavior.

        Returns:
            Item: The retrieved item.
            headers: Optional custom headers to include with the request.
            params: Optional query parameters to include with the request.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            item = await client.store.get_item(
                ["documents", "user123"],
                key="item456",
            )
            print(item)
            ```
            ```shell

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

            {
                'namespace': ['documents', 'user123'],
                'key': 'item456',
                'value': {'title': 'My Document', 'content': 'Hello World'},
                'created_at': '2024-07-30T12:00:00Z',
                'updated_at': '2024-07-30T12:00:00Z'
            }
            ```
        r   r   r   ©r   r   Nr)   r   )r#   r"   )r$   ÚjoinÚdictr   Úget)r   r   r   r)   r"   r#   r&   Ú
get_paramss           r   Úget_itemzStoreClient.get_itemW   sŽ   è ø€ óZ ˆEØ�eŠ|Ü Ø/°¨wÐ6gÐhóð ð ð
 47·8±8¸IÓ3FÈsÑ%Sˆ
ØÐ"Ø(3ˆJ�}Ñ%ÙØ7˜JÐ7¬$¨v«,Ð7ˆJØ—Y‘Y—]‘] >¸*Èg�]ÓV×VÐVÐVús   ‚
A1�AA1Á*A/Á+A1c             ƒ  ód   K  — | j                   j                  d||dœ||¬«      ƒ d{  –—†  y7 Œ­w)at  Delete an item.

        Args:
            key: The unique identifier for the item.
            namespace: Optional list of strings representing the namespace path.
            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.store.delete_item(
                ["documents", "user123"],
                key="item456",
            )
            ```
        r   r+   r    N)r   Údelete)r   r   r   r"   r#   s        r   Údelete_itemzStoreClient.delete_item�   s:   è ø€ ð: �i‰i×ÑØØ(°Ñ5ØØð	 ó 
÷ 	
ò 	
ús   ‚&0¨.©0c	             ƒ  ó€   K  — ||||||dœ}	| j                   j                  dt        |	«      ||¬«      ƒ d{  –—† S 7 Œ­w)a,  Search for items within a namespace prefix.

        Args:
            namespace_prefix: List of strings representing the namespace prefix.
            filter: Optional dictionary of key-value pairs to filter results.
            limit: Maximum number of items to return (default is 10).
            offset: Number of items to skip before returning results (default is 0).
            query: Optional query for natural language search.
            refresh_ttl: Whether to refresh the TTL on items returned by this search. If `None`, uses the store's default behavior.
            headers: Optional custom headers to include with the request.
            params: Optional query parameters to include with the request.

        Returns:
            A list of items matching the search criteria.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            items = await client.store.search_items(
                ["documents"],
                filter={"author": "John Doe"},
                limit=5,
                offset=0
            )
            print(items)
            ```
            ```shell

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

            {
                "items": [
                    {
                        "namespace": ["documents", "user123"],
                        "key": "item789",
                        "value": {
                            "title": "Another Document",
                            "author": "John Doe"
                        },
                        "created_at": "2024-07-30T12:00:00Z",
                        "updated_at": "2024-07-30T12:00:00Z"
                    },
                    # ... additional items ...
                ]
            }
            ```
        )Únamespace_prefixÚfilterÚlimitÚoffsetÚqueryr)   z/store/items/searchr    N©r   Úpostr	   )
r   r5   r6   r7   r8   r9   r)   r"   r#   r'   s
             r   Úsearch_itemszStoreClient.search_items´   sY   è ø€ ðz !1ØØØØØ&ñ
ˆð —Y‘Y—^‘^Ø!Ü Ó(ØØð	 $ó 
÷ 
ð 	
ð 
ús   ‚5>·<¸>c              ƒ  ó~   K  — |||||dœ}| j                   j                  dt        |«      ||¬«      ƒ d{  –—† S 7 Œ­w)a3  List namespaces with optional match conditions.

        Args:
            prefix: Optional list of strings representing the prefix to filter namespaces.
            suffix: Optional list of strings representing the suffix to filter namespaces.
            max_depth: Optional integer specifying the maximum depth of namespaces to return.
            limit: Maximum number of namespaces to return (default is 100).
            offset: Number of namespaces to skip before returning results (default is 0).
            headers: Optional custom headers to include with the request.
            params: Optional query parameters to include with the request.

        Returns:
            A list of namespaces matching the criteria.

        ???+ example "Example Usage"

            ```python
            client = get_client(url="http://localhost:2024")
            namespaces = await client.store.list_namespaces(
                prefix=["documents"],
                max_depth=3,
                limit=10,
                offset=0
            )
            print(namespaces)

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

            [
                ["documents", "user123", "reports"],
                ["documents", "user456", "invoices"],
                ...
            ]
            ```
        )ÚprefixÚsuffixÚ	max_depthr7   r8   z/store/namespacesr    Nr:   )	r   r>   r?   r@   r7   r8   r"   r#   r'   s	            r   Úlist_namespaceszStoreClient.list_namespaces   sV   è ø€ ð\ ØØ"ØØñ
ˆð —Y‘Y—^‘^ØÜ Ó(ØØð	 $ó 
÷ 
ð 	
ð 
ús   ‚4=¶;·=)r   r   ÚreturnÚNone)NNNN)r   Ústrr   zMapping[str, Any]r   z!Literal[False] | list[str] | Noner   ú
int | Noner"   úMapping[str, str] | Noner#   úQueryParamTypes | Noner   úSequence[str]rB   rC   )r   rD   r   rH   r)   úbool | Noner"   rF   r#   rG   rB   r
   )NN)
r   rD   r"   rF   r#   rG   r   rH   rB   rC   )Né
   r   NNNN)r6   zMapping[str, Any] | Noner7   Úintr8   rK   r9   z
str | Noner)   rI   r"   rF   r#   rG   r5   rH   rB   r   )NNNéd   r   NN)r>   úlist[str] | Noner?   rM   r@   rE   r7   rK   r8   rK   r"   rF   r#   rG   rB   r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r(   r0   r3   r<   rA   © r   r   r   r      sç  „ ñóð 48ØØ,0Ø)-ð2
ð ð	2
ð
 !ð2
ð 1ð2
ð ð2
ð *ð2
ð 'ð2
à ð2
ð 
ó2
ðt $(Ø,0Ø)-ñ7Wð ð	7Wà ð7Wð !ð7Wð *ð7Wð 'ð7Wð 
ó7Wð| -1Ø)-ð"
ð ð	"
ð
 *ð"
ð 'ð"
à ð"
ð 
ó"
ðP ,0ØØØ Ø#'Ø,0Ø)-ðJ
ð )ð	J
ð
 ðJ
ð ðJ
ð ðJ
ð !ðJ
ð *ðJ
ð 'ðJ
à'ðJ
ð 
óJ
ð\ $(Ø#'Ø $ØØØ,0Ø)-ð9
à ð9
ð !ð9
ð ð	9
ð
 ð9
ð ð9
ð *ð9
ð 'ð9
ð 
ô9
r   r   N)rQ   Ú
__future__r   Úcollections.abcr   r   Útypingr   r   Úlanggraph_sdk._async.httpr   Úlanggraph_sdk._shared.utilitiesr	   Úlanggraph_sdk.schemar
   r   r   r   r   rR   r   r   Ú<module>rY      s-   ðÙ +å "ç -ß å 0Ý :÷ó ÷g
ò g
r   