Ë
    òÏj›�  ã                  ój  — d dl mZ d dlZd dlZd dlmZmZ d dlmZm	Z	  ej                  de	j                  ¬«      Z ej                  de	j                  ¬«      Z G d„ d	«      Z ej                  d
d¬«      Z G d„ dej"                  e   «      Z ej                  d«      Z G d„ dej(                  e   «      Z ej                  dd¬«      Z ej                  dd¬«      Z ej                  dd¬«      Z ej                  dd¬«      Z ej                  dd¬«      Z ej                  de¬«      Zej:                  d   Zeej:                  d   z  Z G d„ dej(                  eeeeeef   «      Z  G d„ de e	jB                  e	jD                  e	jF                  e	jH                  e	jJ                  ef   «      Z& G d„ d e e	jN                  e	jP                  e	jR                  e	jT                  e	jV                  ef   «      Z, G d!„ d"e e	jZ                  e	j\                  e	j^                  e	j`                  e	jb                  ef   «      Z2 G d#„ d$ej(                  e   «      Z3 G d%„ d&«      Z4 ej                  d'ee5eejl                  f      ¬«      Z7 G d(„ d)«      Z8	 	 	 	 	 	 	 	 	 	 d.d*„Z9d/d+„Z:	 	 	 	 d0d,„Z;g d-¢Z<y)1é    )ÚannotationsN)ÚCallableÚSequence)Ú
exceptionsÚtypesÚTH)ÚboundÚAHc                  ó0   — e Zd ZdZdZeZ	 eZ	 dd„Zdd„Zy)ÚAutha  Add custom authentication and authorization management to your LangGraph application.

    The Auth class provides a unified system for handling authentication and
    authorization in LangGraph applications. It supports custom user authentication
    protocols and fine-grained authorization rules for different resources and
    actions.

    To use, create a separate python file and add the path to the file to your
    LangGraph API configuration file (`langgraph.json`). Within that file, create
    an instance of the Auth class and register authentication and authorization
    handlers as needed.

    Example `langgraph.json` file:

    ```json
    {
      "dependencies": ["."],
      "graphs": {
        "agent": "./my_agent/agent.py:graph"
      },
      "env": ".env",
      "auth": {
        "path": "./auth.py:my_auth"
      }
    ```

    Then the LangGraph server will load your auth file and run it server-side whenever a request comes in.

    ???+ example "Basic Usage"

        ```python
        from langgraph_sdk import Auth

        my_auth = Auth()

        @my_auth.authenticate
        async def authenticate(authorization: str) -> Auth.types.MinimalUserDict:
            user = await verify_token(authorization)  # Your token verification logic
            if not user:
                raise Auth.exceptions.HTTPException(
                    status_code=401, detail="Unauthorized"
                )
            return {
                "identity": user["id"],
                "permissions": user.get("permissions", []),
            }

        # Default deny: reject all requests that don't have a specific handler
        @my_auth.on
        async def deny_all(ctx: Auth.types.AuthContext, value: Any) -> False:
            return False

        # Allow users to create threads with their own identity as owner
        @my_auth.on.threads.create
        async def allow_thread_create(
            ctx: Auth.types.AuthContext, value: Auth.types.on.threads.create.value
        ):
            metadata = value.setdefault("metadata", {})
            metadata["owner"] = ctx.user.identity

        # Allow users to read and search their own threads
        @my_auth.on.threads.read
        async def allow_thread_read(
            ctx: Auth.types.AuthContext, value: Auth.types.on.threads.read.value
        ) -> Auth.types.FilterType:
            return {"owner": ctx.user.identity}

        @my_auth.on.threads.search
        async def allow_thread_search(
            ctx: Auth.types.AuthContext, value: Auth.types.on.threads.search.value
        ) -> Auth.types.FilterType:
            return {"owner": ctx.user.identity}

        # Scope all store operations to the user's namespace
        @my_auth.on.store
        async def scope_store(ctx: Auth.types.AuthContext, value: Auth.types.on.store.value):
            namespace = tuple(value["namespace"]) if value.get("namespace") else ()
            if not namespace or namespace[0] != ctx.user.identity:
                namespace = (ctx.user.identity, *namespace)
            value["namespace"] = namespace
        ```

    ???+ note "Request Processing Flow"

        1. Authentication (your `@auth.authenticate` handler) is performed first on **every request**
        2. For authorization, the most specific matching handler is called:
            * If a handler exists for the exact resource and action, it is used (e.g., `@auth.on.threads.create`)
            * Otherwise, if a handler exists for the resource with any action, it is used (e.g., `@auth.on.threads`)
            * Finally, if no specific handlers match, the global handler is used (e.g., `@auth.on`)
            * If no global handler is set, the request is accepted

        This allows you to set default behavior with a global handler while
        overriding specific routes as needed.
    )Ú_authenticate_handlerÚ_global_handlersÚ_handler_cacheÚ	_handlersÚonc                ó^   — t        | «      | _        	 i | _        g | _        d | _        i | _        y ©N)Ú_Onr   r   r   r   r   )Úselfs    úX/var/www/html/gaurav-v2/venv/lib/python3.12/site-packages/langgraph_sdk/auth/__init__.pyÚ__init__zAuth.__init__�   s7   € Ü�d“)ˆŒðV	ðr FHˆŒØ57ˆÔØAEˆÔ"ØDFˆÕó    c                ó^   — | j                   �t        d| j                   › d�«      ‚|| _         |S )a×
  Register an authentication handler function.

        The authentication handler is responsible for verifying credentials
        and returning user scopes. It can accept any of the following parameters
        by name:

            - request (Request): The raw ASGI request object
            - path (str): The request path, e.g., "/threads/abcd-1234-abcd-1234/runs/abcd-1234-abcd-1234/stream"
            - method (str): The HTTP method, e.g., "GET"
            - path_params (dict[str, str]): URL path parameters, e.g., {"thread_id": "abcd-1234-abcd-1234", "run_id": "abcd-1234-abcd-1234"}
            - query_params (dict[str, str]): URL query parameters, e.g., {"stream": "true"}
            - headers (dict[bytes, bytes]): Request headers
            - authorization (str | None): The Authorization header value (e.g., "Bearer <token>")

        Args:
            fn: The authentication handler function to register.
                Must return a representation of the user. This could be a:
                    - string (the user id)
                    - dict containing {"identity": str, "permissions": list[str]}
                    - or an object with identity and permissions properties
                Permissions can be optionally used by your handlers downstream.

        Returns:
            The registered handler function.

        Raises:
            ValueError: If an authentication handler is already registered.

        ???+ example "Examples"

            Basic token authentication:

            ```python
            @auth.authenticate
            async def authenticate(authorization: str) -> str:
                user_id = verify_token(authorization)
                return user_id
            ```

            Accept the full request context:

            ```python
            @auth.authenticate
            async def authenticate(
                method: str,
                path: str,
                headers: dict[str, bytes]
            ) -> str:
                user = await verify_request(method, path, headers)
                return user
            ```

            Return user name and permissions:

            ```python
            @auth.authenticate
            async def authenticate(
                method: str,
                path: str,
                headers: dict[str, bytes]
            ) -> Auth.types.MinimalUserDict:
                permissions, user = await verify_request(method, path, headers)
                # Permissions could be things like ["runs:read", "runs:write", "threads:read", "threads:write"]
                return {
                    "identity": user["id"],
                    "permissions": permissions,
                    "display_name": user["name"],
                }
            ```
        z&Authentication handler already set as Ú.)r   Ú
ValueError©r   Úfns     r   ÚauthenticatezAuth.authenticateá   sA   € ðN ×%Ñ%Ð1ÜØ8¸×9SÑ9SÐ8TÐTUÐVóð ð &(ˆÔ"Øˆ	r   N)ÚreturnÚNone)r   r
   r   r
   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r   r   © r   r   r   r      s6   „ ñ]ð~€Ið €Eð0ð
 €Jðó^Gô@Lr   r   ÚVT)Úcontravariantc                  ó    — e Zd Z	 	 	 	 	 	 dd„Zy)Ú_ActionHandlerc             ƒ  ó   K  — y ­wr   r&   )r   ÚctxÚvalues      r   Ú__call__z_ActionHandler.__call__6  s	   è ø€ à!ùs   ‚N)r,   ztypes.AuthContextr-   r'   r   ztypes.HandlerResult)r!   r"   r#   r.   r&   r   r   r*   r*   5  s   „ ð"Ø'ð"Ø01ð"à	ô"r   r*   ÚTc                  ó0   — e Zd Z	 	 	 	 	 	 	 	 	 	 dd„Zdd„Zy)Ú_ResourceActionOnc                ó<   — || _         || _        || _        || _        y r   )ÚauthÚresourceÚactionr-   )r   r3   r4   r5   r-   s        r   r   z_ResourceActionOn.__init__?  s    € ð ˆŒ	Ø ˆŒØˆŒØˆ�
r   c                ót   — t        |«       t        | j                  | j                  | j                  |«       |S r   )Ú_validate_handlerÚ_register_handlerr3   r4   r5   r   s     r   r.   z_ResourceActionOn.__call__M  s)   € Ü˜"ÔÜ˜$Ÿ)™) T§]¡]°D·K±KÀÔDØˆ	r   N)
r3   r   r4   ú0typing.Literal['threads', 'crons', 'assistants']r5   zLtyping.Literal['create', 'read', 'update', 'delete', 'search', 'create_run']r-   útype[T]r   r    ©r   ú_ActionHandler[T]r   r<   )r!   r"   r#   r   r.   r&   r   r   r1   r1   >  s=   „ ðàðð Cðð
ð	ð ðð 
óôr   r1   ÚVCreate)Ú	covariantÚVUpdateÚVReadÚVDeleteÚVSearchÚResourceActionT)ÚcreateÚreadÚupdateÚdeleteÚsearchÚ
create_runc                  óê   — e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ded<   	 	 	 	 	 	 dd„Zej                  	 	 	 	 dd„«       Zej                  dddœ	 	 	 	 	 dd„«       Z	 ddddœ	 	 	 	 	 	 	 dd„Zy)Ú_ResourceOnz<
    Generic base class for resource-specific handlers.
    z3type[VCreate | VUpdate | VRead | VDelete | VSearch]r-   ztype[VCreate]ÚCreateztype[VRead]ÚReadztype[VUpdate]ÚUpdateztype[VDelete]ÚDeleteztype[VSearch]ÚSearchc                óB  — || _         || _        t        ||d| j                  «      | _        t        ||d| j
                  «      | _        t        ||d| j                  «      | _        t        ||d| j                  «      | _
        t        ||d| j                  «      | _        y )NrD   rE   rF   rG   rH   )r3   r4   r1   rL   rD   rM   rE   rN   rF   rO   rG   rP   rH   )r   r3   r4   s      r   r   z_ResourceOn.__init__m  s›   € ð
 ˆŒ	Ø ˆŒÜ2CØ�(˜H d§k¡kó3
ˆŒô /@Ø�(˜F D§I¡Ió/
ˆŒ	ô 3DØ�(˜H d§k¡kó3
ˆŒô 3DØ�(˜H d§k¡kó3
ˆŒô 3DØ�(˜H d§k¡kó3
ˆ�r   c                 ó   — y r   r&   r   s     r   r.   z_ResourceOn.__call__„  s	   € ð ILr   N©Ú	resourcesÚactionsc                ó   — y r   r&   ©r   rT   rU   s      r   r.   z_ResourceOn.__call__�  s   € ð r   c               ó`   ‡ ‡‡— 	 	 	 	 dˆˆˆ fd„}|� |t        j                  d|«      «      S |S )Nú=_ActionHandler[VCreate | VUpdate | VRead | VDelete | VSearch]c                ó0  •— t        | «       ‰€‰	j                  g}n;t        ‰t        «      r‰g}n't        ‰t        «      rt        ‰«      }nt        d«      ‚|‰	j                  gk7  rt        d‰	j                  ›d|›d�«      ‚‰€dg}n;t        ‰t        «      r‰g}n't        ‰t        «      rt        ‰«      }nt        d«      ‚|st        d«      ‚t        d„ |D «       «      st        d«      ‚t        ‰	«      j                  «       D �ch c]  }t        |t        «      r|j                  ’Œ  }}‰�t        t        |«      |z
  «      ng }|r*t        d	‰	j                  › d
dj                  |«      › �«      ‚t!        |«      t!        t        |«      «      k7  rt        d«      ‚|D ]B  }‰	j                  |f‰	j"                  j$                  v sŒ(t        d‰	j                  › d|› d�«      ‚ |D ]$  }t'        ‰	j"                  ‰	j                  || «       Œ& | S c c}w )Nz1resources must be a string or sequence of stringsz Resource-specific decorator for z cannot register handlers for z4. Use @auth.on(...) for other or multiple resources.Ú*z/actions must be a string or sequence of stringszactions must not be emptyc              3  ó<   K  — | ]  }t        |t        «      –— Œ y ­wr   )Ú
isinstanceÚstr)Ú.0r5   s     r   Ú	<genexpr>z:_ResourceOn.__call__.<locals>.decorator.<locals>.<genexpr>Å  s   è ø€ ÐI¹[°6”z &¬#×.¹[ùs   ‚zInvalid action(s) for z: ú, z#actions must not contain duplicatesútypes.Handler already set for r   )r7   r4   r]   r^   r   ÚlistÚ	TypeErrorr   ÚallÚvarsÚvaluesr1   r5   ÚsortedÚsetÚjoinÚlenr3   r   r8   )
ÚhandlerÚresource_listÚaction_listr-   Úvalid_actionsÚinvalid_actionsr5   rU   rT   r   s
          €€€r   Ú	decoratorz'_ResourceOn.__call__.<locals>.decorator©  s  ø€ ô ˜gÔ&ØÐ Ø!%§¡ ‘Ü˜I¤sÔ+Ø!* ‘Ü˜I¤xÔ0Ü $ Y£‘äÐ SÓTÐTØ §¡ Ò/Ü Ø6°t·}±}Ð6Gð H-Ø-:Ð,=ð >7ð7óð ð
 ˆØ"˜e‘Ü˜G¤SÔ)Ø&˜i‘Ü˜G¤XÔ.Ü" 7›m‘äÐ QÓRÐRÙÜ Ð!<Ó=Ð=ÜÑI¹[ÓIÔIÜÐ QÓRÐRô " $›Z×.Ñ.Ô0óá0�EÜ˜eÔ%6Ô7ð —“Ø0ð ð ð =DÐ<O””s˜;Ó'¨-Ñ7Ô8ÐUWð ñ Ü Ø,¨T¯]©]¨O¸2¸d¿i¹iÈÓ>XÐ=YÐZóð ô �;Ó¤3¤s¨;Ó'7Ó#8Ò8Ü Ð!FÓGÐGÛ%�Ø—M‘M 6Ð*¨d¯i©i×.AÑ.AÒAÜ$Ø8¸¿¹¸ÀrÈ&ÈÐQRÐSóð ð &ó
 &�Ü! $§)¡)¨T¯]©]¸FÀGÕLð &àˆNùò+s   Ä
#H)rl   rY   r   rY   )ÚtypingÚcast©r   r   rT   rU   rq   s   ` `` r   r.   z_ResourceOn.__call__˜  sG   ú€ ð"3	ØRð3	àJ÷3	ðj ˆ>ÙÜ—‘ØSØóóð ð Ðr   ©r3   r   r4   r9   r   r    )r   ze_ActionHandler[VCreate | VUpdate | VRead | VDelete | VSearch] | _ActionHandler[dict[str, typing.Any]]r   rY   )rT   ústr | Sequence[str] | NonerU   ú2ResourceActionT | Sequence[ResourceActionT] | Noner   zˆCallable[[_ActionHandler[VCreate | VUpdate | VRead | VDelete | VSearch]], _ActionHandler[VCreate | VUpdate | VRead | VDelete | VSearch]]r   )r   zl_ActionHandler[VCreate | VUpdate | VRead | VDelete | VSearch] | _ActionHandler[dict[str, typing.Any]] | NonerT   rv   rU   rw   r   zÈ_ActionHandler[VCreate | VUpdate | VRead | VDelete | VSearch] | Callable[[_ActionHandler[VCreate | VUpdate | VRead | VDelete | VSearch]], _ActionHandler[VCreate | VUpdate | VRead | VDelete | VSearch]])	r!   r"   r#   r$   Ú__annotations__r   rr   Úoverloadr.   r&   r   r   rK   rK   ^  s  … ñð ?Ó>àÓØ
ÓØÓØÓØÓð
àð
ð Cð
ð 
ó	
ð. ‡_�_ðLð4ðLð 
GòLó ðLð ‡_�_ð 15ØFJñ	ð .ðð Dð	ð

òó ðð  ðMð 15ØFJñMððMð .ðMð DðMð	
ôMr   rK   c                  ó  — e Zd Zej                  ej
                  z  ej                  z  ej                  z  ej                  z  Z	ej                  Z
ej
                  Zej                  Zej                  Zej                  Zy)Ú_AssistantsOnN)r!   r"   r#   r   ÚAssistantsCreateÚAssistantsReadÚAssistantsUpdateÚAssistantsDeleteÚAssistantsSearchr-   rL   rM   rN   rO   rP   r&   r   r   r{   r{   è  s‡   „ ð 	×ÑØ
×
Ñ
ñ	à
×
 Ñ
 ñ	!ð ×
 Ñ
 ñ	!ð ×
 Ñ
 ñ		!ð 
ð ×#Ñ#€FØ×Ñ€DØ×#Ñ#€FØ×#Ñ#€FØ×#Ñ#�Fr   r{   c                  óV  ‡ — e Zd Zej                  ej
                  z  ej                  z  ej                  z  ej                  z  ej                  z  Z
ej                  Zej
                  Zej                  Zej                  Zej                  Zej                  Z	 	 	 	 	 	 dˆ fd„Zˆ xZS )Ú
_ThreadsOnc                ó`   •— t         ‰| �  ||«       t        ||d| j                  «      | _        y )NrI   )Úsuperr   r1   Ú	CreateRunrI   )r   r3   r4   Ú	__class__s      €r   r   z_ThreadsOn.__init__  s.   ø€ ô
 	‰Ñ˜˜xÔ(Ü?PØ�(˜L¨$¯.©.ó@
ˆ�r   ru   )r!   r"   r#   r   ÚThreadsCreateÚThreadsReadÚThreadsUpdateÚThreadsDeleteÚThreadsSearchÚ
RunsCreater-   rL   rM   rN   rO   rP   r…   r   Ú__classcell__)r†   s   @r   r‚   r‚      sÊ   ø„ ð 	×ÑØ
×
Ñ
ñ	à
×
Ñ
ñ	ð ×
Ñ
ñ	ð ×
Ñ
ñ		ð
 ×
Ñ
ñ	ð 
ð × Ñ €FØ×Ñ€DØ× Ñ €FØ× Ñ €FØ× Ñ €FØ× Ñ €Ið
àð
ð Cð
ð 
÷	
ñ 
r   r‚   c                  ó
  — e Zd Zeej
                  ej                  z  ej                  z  ej                  z  ej                  z     Z
ej
                  Zej                  Zej                  Zej                  Zej                  Zy)Ú_CronsOnN)r!   r"   r#   Útyper   ÚCronsCreateÚ	CronsReadÚCronsUpdateÚCronsDeleteÚCronsSearchr-   rL   rM   rN   rO   rP   r&   r   r   r�   r�   $  sˆ   „ ð Ø×ÑØ
�/‰/ñ	à
×
Ñ
ñ	ð ×
Ñ
ñ	ð ×
Ñ
ñ		ñ€Eð ×Ñ€FØ�?‰?€DØ×Ñ€FØ×Ñ€FØ×Ñ�Fr   r�   c                  ó0   — e Zd ZdZ	 	 	 	 	 	 	 	 dd„Zdd„Zy)Ú_StoreActionOnz@Decorator for registering a handler for a specific store action.c                ó.   — || _         || _        || _        y r   )r3   r5   r-   )r   r3   r5   r-   s       r   r   z_StoreActionOn.__init__@  s   € ð ˆŒ	ØˆŒØˆ�
r   c                ó`   — t        |«       t        | j                  d| j                  |«       |S )NÚstore)r7   r8   r3   r5   r   s     r   r.   z_StoreActionOn.__call__J  s%   € Ü˜"ÔÜ˜$Ÿ)™) W¨d¯k©k¸2Ô>Øˆ	r   N)r3   r   r5   zCtyping.Literal['put', 'get', 'search', 'delete', 'list_namespaces']r-   r:   r   r    r;   )r!   r"   r#   r$   r   r.   r&   r   r   r—   r—   =  s6   „ ÙJðàðð Tðð ð	ð
 
óôr   r—   c                  óˆ   — e Zd Zdd„Zej
                  ddœ	 	 	 dd„«       Zej
                  d	d„«       Z	 d
ddœ	 	 	 	 	 dd„Zy)Ú_StoreOnc                óZ  — || _         t        |dt        j                  «      | _        	 t        |dt        j
                  «      | _        	 t        |dt        j                  «      | _        	 t        |dt        j                  «      | _
        	 t        |dt        j                  «      | _        y )NÚputÚgetrH   rG   Úlist_namespaces)Ú_authr—   r   ÚStorePutrž   ÚStoreGetrŸ   ÚStoreSearchrH   ÚStoreDeleterG   ÚStoreListNamespacesr    ©r   r3   s     r   r   z_StoreOn.__init__Q  s™   € ØˆŒ
Ü! $¨¬u¯~©~Ó>ˆŒð	ô " $¨¬u¯~©~Ó>ˆŒð	ô % T¨8´U×5FÑ5FÓGˆŒð	ô % T¨8´U×5FÑ5FÓGˆŒð	ô  .ØÐ#¤U×%>Ñ%>ó 
ˆÔð	r   N©rU   c                ó   — y r   r&   )r   rU   s     r   r.   z_StoreOn.__call__œ  s   € ð  #r   c                 ó   — y r   r&   r   s     r   r.   z_StoreOn.__call__©  ó   € Ø(+r   c               óX   ‡ ‡— |�t        ‰ j                  dd|«       |S 	 	 	 	 dˆˆ fd„}|S )aµ  Register a handler for specific resources and actions.

        Can be used as a decorator or with explicit resource/action parameters:

        @auth.on.store
        async def handler(): ... # Handle all store ops

        @auth.on.store(actions=("put", "get", "search", "delete"))
        async def handler(): ... # Handle specific store ops

        @auth.on.store.put
        async def handler(): ... # Handle store.put ops
        Nrš   c                óŽ   •— t        ‰t        «      r‰g}n‰�t        ‰«      ndg}|D ]  }t        ‰j                  d|| «       Œ | S )Nr[   rš   ©r]   r^   rc   r8   r¡   )rl   rn   r5   rU   r   s      €€r   rq   z$_StoreOn.__call__.<locals>.decoratorË  sI   ø€ ô ˜'¤3Ô'Ø&˜i‘à/6Ð/Bœd 7œmÈÈ�Û%�Ü! $§*¡*¨g°v¸wÕGð &àˆNr   ©rl   ÚAHOr   r°   ©r8   r¡   )r   r   rU   rq   s   ` ` r   r.   z_StoreOn.__call__¬  s>   ù€ ð2 ˆ>ä˜dŸj™j¨'°4¸Ô<ØˆIð		Øð		àö		ð Ðr   ©r3   r   r   r    )rU   úštyping.Literal['put', 'get', 'search', 'list_namespaces', 'delete'] | Sequence[typing.Literal['put', 'get', 'search', 'list_namespaces', 'delete']] | Noner   úCallable[[AHO], AHO]©r   r°   r   r°   r   )r   ú
AHO | NonerU   r³   r   úAHO | Callable[[AHO], AHO])r!   r"   r#   r   rr   ry   r.   r&   r   r   rœ   rœ   P  s~   „ óIðV ‡_�_ð ñ
#ðð	
#ð 
ò
#ó ð
#ð ‡_�_Ú+ó Ø+ð ð*ð ñ*àð*ð
ð*ð 
$ô*r   rœ   r°   c                  óš   — e Zd ZdZdZd
d„Zej                  ddœ	 	 	 	 	 dd„«       Zej                  dd„«       Z	 ddddœ	 	 	 	 	 	 	 dd	„Zy)r   aÒ  Entry point for authorization handlers that control access to specific resources.

    The _On class provides a flexible way to define authorization rules for different resources
    and actions in your application. It supports three main usage patterns:

    1. Global handlers that run for all resources and actions
    2. Resource-specific handlers that run for all actions on a resource
    3. Resource and action specific handlers for fine-grained control

    Each handler must be an async function that accepts two parameters:
    - ctx (AuthContext): Contains request context and authenticated user info
    - value: The data being authorized (type varies by endpoint)

    The handler should return one of:
        - None or True: Accept the request
        - False: Reject with 403 error
        - FilterType: Apply filtering rules to the response

    ???+ example "Examples"

        Start by denying all requests by default with a global handler,
        then add specific handlers to allow access:

        ```python
        # Default deny: reject all requests without a specific handler
        @auth.on
        async def deny_all(ctx: AuthContext, value: Any) -> False:
            return False
        ```

        Resource-specific handler to allow access (takes precedence
        over the global deny handler):

        ```python
        @auth.on.threads
        async def allow_thread_access(ctx: AuthContext, value: Any) -> Auth.types.FilterType:
            # Allow access only to threads owned by the user
            return {"owner": ctx.user.identity}
        ```

        Resource and action specific handler:

        ```python
        @auth.on.threads.create
        async def allow_thread_create(ctx: AuthContext, value: Any) -> None:
            # Allow thread creation, stamping the owner
            value.setdefault("metadata", {})["owner"] = ctx.user.identity
        ```

        Multiple resources or actions:

        ```python
        @auth.on(resources=["threads", "assistants"], actions=["read", "search"])
        async def allow_reads(ctx: AuthContext, value: Any) -> Auth.types.FilterType:
            # Allow read/search, scoped to user's resources
            return {"owner": ctx.user.identity}
        ```
    )r¡   Ú
assistantsÚcronsÚrunsrš   Úthreadsr-   c                óÜ   — || _         t        |d«      | _        t        |d«      | _        t        |d«      | _        t        |«      | _        t        t        t        j                  f   | _        y )Nr¹   r¼   rº   )r¡   r{   r¹   r‚   r¼   r�   rº   rœ   rš   Údictr^   rr   ÚAnyr-   r§   s     r   r   z_On.__init__"  sR   € ØˆŒ
Ü'¨¨lÓ;ˆŒÜ! $¨	Ó2ˆŒÜ˜d GÓ,ˆŒ
Ü˜d“^ˆŒ
Üœ#œvŸz™z˜/Ñ*ˆ�
r   Nr¨   c                ó   — y r   r&   rW   s      r   r.   z_On.__call__*  s   € ð  #r   c                 ó   — y r   r&   r   s     r   r.   z_On.__call__2  r«   r   rS   c               ó\   ‡ ‡‡— |�t        ‰ j                  dd|«       |S 	 	 	 	 dˆˆˆ fd„}|S )aÄ  Register a handler for specific resources and actions.

        Can be used as a decorator or with explicit resource/action parameters:

        @auth.on
        async def handler(): ...  # Global handler

        @auth.on(resources="threads")
        async def handler(): ...  # types.Handler for all thread actions

        @auth.on(resources="threads", actions="create")
        async def handler(): ...  # types.Handler for thread creation
        Nc                óä   •— t        ‰t        «      r‰g}n‰�t        ‰«      ndg}t        ‰t        «      r‰g}n‰�t        ‰«      ndg}|D ]!  }|D ]  }t        ‰j                  ||| «       Œ Œ# | S )Nr[   r®   )rl   rm   rn   r4   r5   rU   rT   r   s        €€€r   rq   z_On.__call__.<locals>.decoratorO  sx   ø€ ô ˜)¤SÔ)Ø!* ‘à3<Ð3H¤ Y¤ÈsÈe�ä˜'¤3Ô'Ø&˜i‘à/6Ð/Bœd 7œmÈÈ�Û)�Û)�FÜ% d§j¡j°(¸FÀGÕLñ *ð *ð ˆNr   r¯   r±   rt   s   ` `` r   r.   z_On.__call__5  s>   ú€ ð( ˆ>ä˜dŸj™j¨$°°bÔ9ØˆIð	Øð	à÷	ð" Ðr   r²   )rT   zstr | Sequence[str]rU   rv   r   r´   rµ   r   )r   r¶   rT   rv   rU   rv   r   r·   )	r!   r"   r#   r$   r%   r   rr   ry   r.   r&   r   r   r   r   Ü  s    „ ñ9ðv€Ió+ð ‡_�_ð
 /3ñ	#ð 'ð#ð ,ð	#ð
 
ò#ó ð#ð ‡_�_Ú+ó Ø+ð ð+ð 15Ø.2ñ+àð+ð .ð	+ð
 ,ð+ð 
$ô+r   r   c                ó0  — t        |«       |xs d}|xs d}|dk(  r9|dk(  r4| j                  rt        d«      ‚| j                  j                  |«       |S |�|nd}|�|nd}||f| j                  v rt        d|› d|› d�«      ‚|g| j                  ||f<   |S )Nr[   zGlobal handler already set.rb   ra   r   )r7   r   r   Úappendr   )r3   r4   r5   r   ÚrÚas         r   r8   r8   c  s¹   € ô �bÔØŠ˜3€HØŠ]�s€FØ�3‚˜6 Sš=Ø× Ò ÜÐ:Ó;Ð;Ø×Ñ×$Ñ$ RÔ(ð €Ið !Ð,‰H°#ˆØÐ(‰F¨cˆØˆqˆ6�T—^‘^Ñ#ÜÐ=¸a¸SÀÀ1À#ÀQÐGÓHÐHØ"$ ˆ�‰˜˜1�vÑØ€Ir   c                ó,  — t        j                  | «      st        dt        | d| «      › d�«      ‚t        j                  | «      }d|j
                  vrt        dt        | d| «      › d�«      ‚d|j
                  vrt        dt        | d| «      › d�«      ‚y)	zíValidates that an auth handler function meets the required signature.

    Auth handlers must:
    1. Be async functions
    2. Accept a ctx parameter of type AuthContext
    3. Accept a value parameter for the data being authorized
    zAuth handler 'r!   z|' must be an async function. Add 'async' before 'def' to make it asynchronous and ensure any IO operations are non-blocking.r,   zm' must have a 'ctx: AuthContext' parameter. Update the function signature to include this required parameter.r-   z¢' must have a 'value' parameter.  The value contains the mutable data being sent to the endpoint.Update the function signature to include this required parameter.N)ÚinspectÚiscoroutinefunctionr   ÚgetattrÚ	signatureÚ
parameters)r   Úsigs     r   r7   r7   y  s¿   € ô ×&Ñ& rÔ*ÜØœW R¨°RÓ8Ð9ð :3ð 3ó
ð 	
ô ×
Ñ
˜BÓ
€CØ�C—N‘NÑ"ÜØœW R¨°RÓ8Ð9ð :Pð Pó
ð 	
ð �c—n‘nÑ$ÜØœW R¨°RÓ8Ð9ð :Pð Pó
ð 	
ð %r   c                ó†   — t        | t        j                  «      xs& t        | t        «      xr | j	                  d«      dk(  S )NÚkindÚ
StudioUser)r]   r   rÑ   r¾   rŸ   )Úusers    r   Úis_studio_userrÓ   –  s;   € ô �dœE×,Ñ,Ó-ò Ü�4œÓÒC 4§8¡8¨FÓ#3°|Ñ#Cðr   )r   r   r   )
r3   r   r4   ú
str | Noner5   rÔ   r   útypes.Handlerr   rÕ   )r   zCallable[..., typing.Any]r   r    )rÒ   z:types.MinimalUser | types.BaseUser | types.MinimalUserDictr   Úbool)=Ú
__future__r   rÉ   rr   Úcollections.abcr   r   Úlanggraph_sdk.authr   r   ÚTypeVarÚHandlerr   ÚAuthenticatorr
   r   r'   ÚProtocolr*   r/   ÚGenericr1   r=   r?   r@   rA   rB   r^   rC   ÚLiteralÚ_ResourceActionÚ_ThreadActionrK   r|   r}   r~   r   r€   r{   r‡   rˆ   r‰   rŠ   r‹   r‚   r‘   r’   r“   r”   r•   r�   r—   rœ   r¾   r¿   r°   r   r8   r7   rÓ   Ú__all__r&   r   r   Ú<module>rã      sÓ  ðÝ "ã Û ß .ç 0à€V‡^�^�D §¡Ô.€Ø€V‡^�^�D × 3Ñ 3Ô4€÷`ñ `ðJ	 €F‡N�N�3 dÔ+€ô"�V—_‘_ QÑ'ô "ð €F‡N�N�3Ó€ô˜Ÿ™ qÑ)ô ð* ˆ&�.‰.˜¨dÔ
3€Ø
ˆ&�.‰.˜¨dÔ
3€Øˆ�‰�w¨$Ô/€Ø
ˆ&�.‰.˜¨dÔ
3€Ø
ˆ&�.‰.˜¨dÔ
3€Ø �&—.‘.Ð!2¸#Ô>€à—.‘.Ð!OÑP€Ø &§.¡.°Ñ">Ñ>€ôGØ
‡N�N�7˜E 7¨G°W¸oÐMÑNôGôT$ØØ×ÑØ×ÑØ×ÑØ×ÑØ×ÑØð	ñô$ô0!
ØØ×ÑØ×ÑØ×ÑØ×ÑØ×ÑØð	ñô!
ôHØØ×ÑØ�‰Ø×ÑØ×ÑØ×ÑØð	ñôô2�V—^‘^ AÑ&ô ÷&Fñ FðR €f‡n�n�U .°°c¸6¿:¹:°oÑ1FÑ"GÔH€÷Dñ DðNØ
ðàðð ðð 	ð	ð
 óó,
ð:Ø
Dðà	óò *�r   