Ë
    òÏjî  ã                  óP   — d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	  G d„ d«      Z
y)	u]  In-process handle for a single tool call's streaming execution.

Mirrors the shape of `ChatModelStream` from langchain-core but simpler â€”
a tool has one output channel, no content-block multiplexing. Populated
by `ToolCallTransformer` as `tool-started` / `tool-output-delta` /
`tool-finished` / `tool-error` events flow in on the `tools` channel.
é    )Úannotations)ÚAsyncIteratorÚIterator)ÚAny)ÚStreamChannelc                  ót   — e Zd ZdZ	 d	 	 	 	 	 	 	 dd„Zedd„«       Zdd„Zdd„Zdd„Z	dd„Z
dd	„Zdd
„Zdd„Zy)ÚToolCallStreamuL  Scoped view of a single tool call's lifecycle.

    Yielded on `run.tool_calls` once per `tool-started` event. Fields
    are populated as events arrive:

    - `tool_call_id`, `tool_name`, `input`: stable from the start event.
    - `output_deltas`: a `StreamChannel` of delta chunks. Iterate (sync or
      async) to consume partial output in arrival order.
    - `output`: terminal payload from `tool-finished`, or `None` if the
      call failed or is still in flight.
    - `error`: terminal error string from `tool-error`, or `None` if the
      call succeeded or is still in flight.
    - `completed`: True once a terminal event (`tool-finished` or
      `tool-error`) has been observed.

    `ToolCallStream` is not meant to be constructed by end users â€” it's
    produced by `ToolCallTransformer` as events flow through the mux.
    Nc                óv   — || _         || _        || _        t        «       | _        d| _        d| _        d| _        y)a,  Initialize a fresh handle for a tool call.

        Args:
            tool_call_id: The `tool_call_id` from the AIMessage.
            tool_name: The tool's name.
            input: The tool's input arguments (as reported by
                `on_tool_start`), or `None` if none were captured.
        NF)Útool_call_idÚ	tool_nameÚinputr   Ú_output_deltasÚoutputÚerrorÚ	completed)Úselfr   r   r   s       úa/var/www/html/gaurav-v2/venv/lib/python3.12/site-packages/langgraph/prebuilt/_tool_call_stream.pyÚ__init__zToolCallStream.__init__%   s9   € ð )ˆÔØ"ˆŒØˆŒ
Ü2?³/ˆÔØˆŒØ!%ˆŒ
Øˆ�ó    c                ó   — | j                   S )zñThe channel of streamed `tool-output-delta` payloads.

        Iterate (sync or async depending on how the run was started)
        to consume partial output in arrival order. The log closes when
        the tool finishes or errors.
        )r   ©r   s    r   Úoutput_deltaszToolCallStream.output_deltas;   s   € ð ×"Ñ"Ð"r   c               ó<   — | j                   j                  |¬«       y)z´Bind the deltas log to sync or async iteration.

        Called by `ToolCallTransformer` when constructing this handle so
        the log matches the enclosing mux's mode.
        )Úis_asyncN)r   Ú_bind)r   r   s     r   r   zToolCallStream._bindE   s   € ð 	×Ñ×!Ñ!¨8Ð!Õ4r   c                ó:   — | j                   j                  |«       y ©N)r   Úpush)r   Údeltas     r   Ú_push_deltazToolCallStream._push_deltaM   s   € Ø×Ñ× Ñ  Õ'r   c                óT   — || _         d| _        | j                  j                  «        y ©NT)r   r   r   Úclose)r   r   s     r   Ú_finishzToolCallStream._finishP   s"   € ØˆŒØˆŒØ×Ñ×!Ñ!Õ#r   c                óT   — || _         d| _        | j                  j                  «        y r"   )r   r   r   r#   )r   Úmessages     r   Ú_failzToolCallStream._failU   s"   € ØˆŒ
ØˆŒØ×Ñ×!Ñ!Õ#r   c                ó,   — t        | j                  «      S )z¨Iterate delta chunks synchronously.

        Equivalent to `iter(self.output_deltas)`. Raises `TypeError` if
        the underlying log is bound to async mode.
        )Úiterr   r   s    r   Ú__iter__zToolCallStream.__iter__Z   s   € ô �D×'Ñ'Ó(Ð(r   c                ó6   — | j                   j                  «       S )z©Iterate delta chunks asynchronously.

        Equivalent to `aiter(self.output_deltas)`. Raises `TypeError`
        if the underlying log is bound to sync mode.
        )r   Ú	__aiter__r   s    r   r,   zToolCallStream.__aiter__b   s   € ð ×"Ñ"×,Ñ,Ó.Ð.r   c                ó–   — | j                   r| j                  €dn| j                   rdnd}d| j                  ›d| j                  ›d|› d�S )Nr   ÚfailedÚrunningzToolCallStream(tool_call_id=z, tool_name=z	, status=Ú))r   r   r   r   )r   Ústatuss     r   Ú__repr__zToolCallStream.__repr__j   sa   € ð �~Š~ $§*¡*Ð"4ñ ð �~Š~ñ àð 	ð +¨4×+<Ñ+<Ð*?ð @ØŸ™Ð*¨)°F°8¸1ð>ð	
r   r   )r   Ústrr   r3   r   zdict[str, Any] | NoneÚreturnÚNone)r4   zStreamChannel[Any])r   Úboolr4   r5   )r   r   r4   r5   )r   r   r4   r5   )r&   r3   r4   r5   )r4   zIterator[Any])r4   zAsyncIterator[Any])r4   r3   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   r    r$   r'   r*   r,   r2   © r   r   r	   r	      sn   „ ñð. (,ð	àðð ðð %ð	ð
 
óð, ò#ó ð#ó5ó(ó$ó
$ó
)ó/ô
r   r	   N)r:   Ú
__future__r   Úcollections.abcr   r   Útypingr   Úlanggraph.stream.stream_channelr   r	   r<   r   r   Ú<module>rA      s$   ðñõ #ç 3Ý å 9÷d
ò d
r   