
    b\j
                        S r SSKJr  SSKrSSKJrJrJrJr  SSK	J
r
  SSKJrJr  / SQr " S	 S
\
5      r " S S\
5      r\" S\S9rSS jrSS jrSS jrg)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                  ,    \ rS rSrSr\SS j5       rSrg)
_NamedTool   uH   Anything with a ``name`` — the shape :func:`tool_registry` indexes on.c                    g N )selfs    X/var/www/website/venv/lib/python3.13/site-packages/anthropic/lib/tools/_tool_dispatch.pyname_NamedTool.name   s        r   N)returnstr)__name__
__module____qualname____firstlineno____doc__propertyr   __static_attributes__r   r   r   r   r      s    R r   r   c                  "    \ rS rSrSrSS jrSrg)_CallableTool   zdA runnable tool: ``call`` may be sync or async (it returns either the
result or an awaitable of it).c                    g r   r   )r   inputs     r   call_CallableTool.call"   s    orr   r   N)r'   objectr   zHUnion[BetaFunctionToolResultType, Awaitable[BetaFunctionToolResultType]])r   r   r   r   r    r(   r"   r   r   r   r$   r$      s    & sr   r$   
NamedToolT)boundc                F    U  Vs0 s H  oR                   U_M     sn$ s  snf )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"    
 )..IItO...s   c                Z    [        U [        5      (       a  U R                  $ [        U 5      $ )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                ~   #    U R                  U5      n[        R                  " U5      (       a
  UI Sh  vN $ U$  N7f)zCall ``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   <   s8      YYuF6""|M s   2=;=)r.   zIterable[NamedToolT]r   zdict[str, NamedToolT])r4   BaseExceptionr   r   )r/   r$   r'   zdict[str, object]r   r   )r    
__future__r   r6   typingr   r   r   r   typing_extensionsr   _beta_functionsr
   r   __all__r   r$   r+   r   r   r   r   r   r   <module>r?      sZ   	 #  6 6 & B
F sH s \4
/	
r   