ó
    lQj  ã                  ó¶   • S r SSKJr  SSKrSSKJs  Jr  SSK	J
r
JrJrJr  \
(       a  SSKJr  \S   r " S S5      r\" 5       q S   SS	 jjrSS
 jrSS jrg)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).
é    )ÚannotationsN)ÚTYPE_CHECKINGÚAnyÚCallableÚOptional)Ú	Awaitable).zAwaitable[Any]c                  ó.   • \ rS rSrSrSr S SS jjrSrg)ÚRuntimeOverridesé   aH  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_threadNc                ó   • Xl         g)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     ÚY/home/mande/repo/quber/.venv/lib/python3.13/site-packages/langsmith/_runtime_overrides.pyÚ__init__ÚRuntimeOverrides.__init__0   s
   € ð" +Õó    ©N)r   úOptional[AioToThread])Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú	__slots__r   Ú__static_attributes__© r   r   r
   r
      s%   † ñð0 #€Ið 04ð+à,÷+ð +r   r
   c                ó   • [        U S9qg)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Ñr   c                 ó   • [         $ )z"Get the current runtime overrides.)r   r   r   r   Úget_runtime_overridesr"   {   s   € äÐr   c                 ó&   • [         R                  SL$ )ai  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   ÚreturnÚNone)r%   r
   )r%   Úbool)r   Ú
__future__r   ÚbuiltinsÚ@py_builtinsÚ_pytest.assertion.rewriteÚ	assertionÚrewriteÚ
@pytest_arÚtypingr   r   r   r   Úcollections.abcr   ÚAioToThreadr
   r   r    r"   r$   r   r   r   Ú<module>r2      so   ðñõ #ç  „ × 9Ó 9æÝ)ð ðñ€÷,+ñ ,+ñ^ &Ó'Ð ð ,0ð1GØ(ð1Gà	õ1Gôhõ
	8r   