§
    ~Štj  ã                  ó˜   — d Z ddlmZ ddlmZmZmZmZ erddlm	Z	 ed         Z
 G d„ d¦  «        Z e¦   «         a	 ddd„Zdd„Zdd„ZdS )z¼Runtime overrides for LangSmith.

This module provides hooks to override LangSmith's default runtime behavior,
primarily for environments with constrained async runtimes (e.g., Temporal).
é    )Úannotations)ÚTYPE_CHECKINGÚAnyÚCallableÚOptional)Ú	Awaitable).zAwaitable[Any]c                  ó"   — e Zd ZdZdZ	 ddd„ZdS )	ÚRuntimeOverridesa„  Overrides for LangSmith runtime behavior.

    This class allows overriding default async implementations for environments
    that don't support certain asyncio features (e.g., Temporal doesn't support
    ``run_in_executor``).

    Example:
        import langsmith
        import contextvars


        async def my_aio_to_thread(
            default_aio_to_thread, ctx, func, /, *args, **kwargs
        ):
            # Custom implementation
            return ctx.run(func, *args, **kwargs)


        langsmith.set_runtime_overrides(aio_to_thread=my_aio_to_thread)

        # Reset to defaults
        langsmith.set_runtime_overrides()
    ©Úaio_to_threadNr   úOptional[AioToThread]c                ó   — || _         dS )aã  Initialize runtime overrides.

        Args:
            aio_to_thread: Custom async-to-thread implementation, with signature
                ``async def (default_aio_to_thread, ctx, func, /, *args, **kwargs)``.
                ``default_aio_to_thread`` is LangSmith's default implementation, which
                the override can call to fall back to default behavior (e.g., when
                outside a constrained runtime context). ``ctx`` is the
                ``contextvars.Context`` LangSmith wants ``func`` to run inside;
                tracing state will be read back from this Context after the call.
                Override for runtimes like Temporal that don't support
                ``asyncio.run_in_executor``.
        Nr   )Úselfr   s     úZ/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langsmith/_runtime_overrides.pyÚ__init__zRuntimeOverrides.__init__0   s   € ð" +ˆÔÐÐó    ©N)r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   © r   r   r
   r
      sC   € € € € € ðð ð0 #€Ið 04ð+ð +ð +ð +ð +ð +ð +r   r
   Nr   r   ÚreturnÚNonec                ó&   — t          | ¬¦  «        adS )a„  Set LangSmith runtime overrides.

    This allows customizing LangSmith's async runtime behavior for environments
    with constrained async runtimes (e.g., Temporal, which doesn't support
    ``run_in_executor``).

    Args:
        aio_to_thread: Custom async function to run sync functions
            asynchronously. Should have signature:
            ``async def aio_to_thread(
                default_aio_to_thread, ctx, func, /, *args, **kwargs
            )``.
            ``default_aio_to_thread`` is LangSmith's default implementation, which
            the override can call to fall back to default behavior. The
            implementation must invoke ``func`` inside ``ctx`` (e.g.
            ``ctx.run(func, *args, **kwargs)``) so that LangSmith's tracing state,
            which is read back from ``ctx`` after the call, is visible to downstream
            code. Pass ``None`` to use the default implementation.

    Example:
        For Temporal or similar runtimes:

        ```python
        import langsmith


        async def temporal_aio_to_thread(
            default_aio_to_thread, ctx, func, /, *args, **kwargs
        ):
            # Use the default implementation when not in a workflow
            if not temporalio.workflow.in_workflow():
                return await default_aio_to_thread(ctx, func, *args, **kwargs)
            with temporalio.workflow.unsafe.sandbox_unrestricted():
                return ctx.run(func, *args, **kwargs)


        langsmith.set_runtime_overrides(aio_to_thread=temporal_aio_to_thread)
        ```

        Reset to defaults:

        ```python
        langsmith.set_runtime_overrides()
        ```
    r   N)r
   Ú_runtime_overridesr   s    r   Úset_runtime_overridesr   G   s   € õb *¸ÐFÑFÔFÐÐÐr   c                 ó   — t           S )z"Get the current runtime overrides.)r   r   r   r   Úget_runtime_overridesr    {   s   € åÐr   Úboolc                 ó   — t           j        duS )a�  Return True iff an ``aio_to_thread`` override is currently installed.

    Callers use this to select a loop-behavior-independent path for
    re-entering a LangSmith-mutated Context (the explicit
    ``tracing_context(**get_tracing_context(ctx))`` fallback), rather than
    relying on ``asyncio.create_task(coro, context=ctx)`` which some custom
    event loops silently ignore.
    N)r   r   r   r   r   Ú_aio_to_thread_override_activer#   €   s   € õ Ô+°4Ð7Ð7r   r   )r   r   r   r   )r   r
   )r   r!   )r   Ú
__future__r   Útypingr   r   r   r   Úcollections.abcr   ÚAioToThreadr
   r   r   r    r#   r   r   r   ú<module>r(      s  ððð ð #Ð "Ð "Ð "Ð "Ð "à 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9Ð 9àð *Ø)Ð)Ð)Ð)Ð)Ð)ð ðô€ð,+ð ,+ð ,+ð ,+ð ,+ñ ,+ô ,+ð ,+ð^ &Ð%Ñ'Ô'Ð ð ,0ð1Gð 1Gð 1Gð 1Gð 1Gðhð ð ð ð
	8ð 	8ð 	8ð 	8ð 	8ð 	8r   