
    4Rj
                        d Z ddlmZ ddlZddlmZmZmZmZ ddl	m
Z
 ddlmZmZ g dZ G d	 d
e
      Z G d de
      Z ede      ZddZddZddZy)a=  Shared tool-dispatch helpers for the tool runners.

Both ``client.beta.messages.tool_runner`` (the Messages tool runner) and
``client.beta.sessions.events.tool_runner`` (the sessions-side
:class:`~anthropic.lib.tools._beta_session_runner.SessionToolRunner`) do the
same three small things: index the supplied tools by name, run a runnable tool
over a JSON input, and turn an exception raised by a tool into tool-result
content. Those steps are factored out here so the two runners stay consistent
instead of each carrying its own copy. Consumed by the runner helpers only.
    )annotationsN)UnionTypeVarIterable	Awaitable)Protocol   )	ToolErrorBetaFunctionToolResultType)tool_registrytool_error_contentrun_runnable_toolc                  "    e Zd ZdZedd       Zy)
_NamedTooluH   Anything with a ``name`` — the shape :func:`tool_registry` indexes on.c                     y N )selfs    j/var/www/html/meridian/meridian-ai/venv/lib/python3.12/site-packages/anthropic/lib/tools/_tool_dispatch.pynamez_NamedTool.name   s        N)returnstr)__name__
__module____qualname____doc__propertyr   r   r   r   r   r      s    R r   r   c                      e Zd ZdZddZy)_CallableToolzhA runnable tool: ``call`` may be sync or async (it returns either the
    result or an awaitable of it).c                     y r   r   )r   inputs     r   callz_CallableTool.call"   s    r   N)r"   objectr   zHUnion[BetaFunctionToolResultType, Awaitable[BetaFunctionToolResultType]])r   r   r   r   r#   r   r   r   r    r       s    & sr   r    
NamedToolT)boundc                B    | D ci c]  }|j                   | c}S c c}w )zIndex ``tools`` by their ``name`` for O(1) dispatch lookup.

    On a duplicate name the later tool wins, matching a plain dict comprehension.
    )r   )toolstools     r   r   r   (   s     
 )..DIItO...s   c                P    t        | t              r| j                  S t        |       S )a  Render an exception raised by a tool as tool-result content.

    A :class:`ToolError` carries its own structured content; anything else is
    rendered with ``repr`` (which, unlike ``str``, keeps the exception type).
    The caller owns the ``is_error`` flag and any logging.
    )
isinstancer
   contentrepr)excs    r   r   r   0   s"     #y!{{9r   c                r   K   | j                  |      }t        j                  |      r
| d{   S |S 7 w)a  Call ``tool`` with ``input``, awaiting the result if the tool is async.

    Bridges the sync (:class:`~anthropic.lib.tools.BetaFunctionTool`) and async
    (:class:`~anthropic.lib.tools.BetaAsyncFunctionTool`) runnable-tool shapes
    behind a single ``await``.
    N)r#   inspectisawaitable)r)   r"   results      r   r   r   <   s6      YYuF6"|M s   ,757)r(   zIterable[NamedToolT]r   zdict[str, NamedToolT])r.   BaseExceptionr   r   )r)   r    r"   zdict[str, object]r   r   )r   
__future__r   r0   typingr   r   r   r   typing_extensionsr   _beta_functionsr
   r   __all__r   r    r%   r   r   r   r   r   r   <module>r9      sZ   	 #  6 6 & B
F sH s \4
/	
r   