Ë
    òÏjx  ã                  ó0  — d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	m
Z
mZmZ  ed«      Zed   Z	 ddlmZ dd	lmZ 	 ddlmZ ddlmZ g d¢Zdd„Zd
dœdd„Zd
d
d
dœ	 	 	 	 	 	 	 	 	 	 	 dd„Zy
# e$ r d
Zd
ZY Œ<w xY w# e$ r d
Z G d„ de
e   «      ZY ŒJw xY w)z»Key/value cache for use inside LangGraph deployments.

Thin wrapper around ``langgraph_api.cache``.
Values must be JSON-serializable (dicts, lists, strings, numbers, booleans,
``None``).
é    )Úannotations)Ú	AwaitableÚCallable)Ú	timedelta)ÚAnyÚGenericÚLiteralÚTypeVarÚT)ÚmissÚfreshÚstaleÚexpired)Ú	cache_get)Ú	cache_setN)Ú	SWRResult)Úswrc                  ó8   — e Zd ZU dZded<   ded<   	 d	 	 	 d	d„Zy)
r   z'Result wrapper returned by :func:`swr`.r   ÚvalueÚCacheStatusÚstatusc              ƒ  ó   K  — y­w)z&Update or revalidate the cached value.N© )Úselfr   s     úP/var/www/html/gaurav-v2/venv/lib/python3.12/site-packages/langgraph_sdk/cache.pyÚmutatezSWRResult.mutate+   s   è ø€ ð
 ùs   ‚N).)r   r   Úreturnr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   ó    r   r   r   %   s,   … Ù5à‹ØÓð ð	àð	ð ô	r#   r   )r   r   r   r   c              ƒ  óV   K  — t         €t        d«      ‚t        | «      ƒ d{  –—† S 7 Œ­w)z¯Get a value from the cache.

    Returns the deserialized value, or ``None`` if the key is missing or expired.

    Requires Agent Server runtime version 0.7.29 or later.
    NúyCache is only available server-side within the LangGraph Agent Server (https://docs.langchain.com/langsmith/deployments).)Ú
_cache_getÚRuntimeError)Úkeys    r   r   r   ;   s3   è ø€ ô ÐÜðBó
ð 	
ô ˜C“× Ð Ð ús   ‚ )¢'£))Úttlc             ƒ  ó\   K  — t         €t        d«      ‚t        | ||«      ƒ d{  –—†  y7 Œ­w)a%  Set a value in the cache.

    Args:
        key: The cache key.
        value: The value to cache (must be JSON-serializable).
        ttl: Optional time-to-live. Capped at 1 day; ``None`` or zero
            defaults to 1 day.

    Requires Agent Server runtime version 0.7.29 or later.
    Nr%   )Ú
_cache_setr'   )r(   r   r)   s      r   r   r   J   s5   è ø€ ô ÐÜðBó
ð 	
ô �S˜% Ó
%×%Ò%ús   ‚",¤*¥,©Ú	fresh_forÚmax_ageÚmodelc             ƒ  ó–   K  — t         €t        d«      ‚|€t        d«      }|€t        d¬«      }t        | ||||¬«      ƒ d{  –—† S 7 Œ­w)a  Load a cached value using stale-while-revalidate semantics.

    This helper is server-side only and is intended for caching internal async
    dependencies such as auth or metadata lookups.

    Args:
        key: Cache key.
        loader: Async callable that fetches the value on miss/revalidation.
        fresh_for: How long a cached value is considered fresh (no revalidation).
            Defaults to ``timedelta(0)`` so every access triggers a background
            revalidate while still returning the cached value instantly. Values
            above :data:`MAX_CACHE_TTL` are clamped to the backend maximum.
        max_age: Total lifetime of a cached entry. After this, the next access
            blocks on the loader. Defaults to :data:`MAX_CACHE_TTL` (24 h by
            default). Values above :data:`MAX_CACHE_TTL` are clamped to the
            backend maximum.
        model: Optional Pydantic model class. When provided, values are
            serialized via ``model_dump(mode="json")`` before storage and
            deserialized via ``model.model_validate()`` on read.

    Returns:
        An :class:`SWRResult` with ``.value``, ``.status``, and an async
        ``.mutate()`` method.

    Semantics:
    - cache miss: await ``loader()``, store the value, return it
    - fresh hit (age < fresh_for): return the cached value
    - stale hit (fresh_for <= age < max_age): return the cached value
      immediately and trigger a best-effort background refresh
    - expired (age >= max_age): await ``loader()``, store the value, return it
    Nr%   r   é   )Údaysr,   )Ú_api_swrr'   r   )r(   Úloaderr-   r.   r/   s        r   r   r   ]   sd   è ø€ ôN ÐÜðBó
ð 	
ð ÐÜ˜a“Lˆ	Ø€Ü Ô#ˆÜØˆV˜y°'Àô÷ ð ð ús   ‚A A	ÁAÁA	)r(   Ústrr   z
Any | None)r(   r5   r   r   r)   útimedelta | Noner   ÚNone)r(   r5   r4   zCallable[[], Awaitable[T]]r-   r6   r.   r6   r/   ztype[T] | Noner   zSWRResult[T])r!   Ú
__future__r   Úcollections.abcr   r   Údatetimer   Útypingr   r   r	   r
   r   r   Úlanggraph_api.cacher   r&   r   r+   ÚImportErrorr   r   r3   Ú__all__r   r#   r   Ú<module>r?      sê   ðñõ #ç /Ý ß 1Ó 1áˆCƒL€àÐ9Ñ:€ð	õõðÝ-Ý3ò&€ó!ð FJõ &ð. #'Ø $Ø ñ2Ø	ð2à&ð2ð  ð	2ð
 ð2ð ð2ð ô2øðI ò Ø€JØ‚Jðûð ò Ø€Hô�G˜A‘Jö ðús"   ±A. ¾A= Á.	A:Á9A:Á=BÂB