o
    ưiU                     @   sb   d Z ddlmZmZmZmZ ddlmZ er(ddlm	Z
 ddlmZmZmZmZ G dd dZ	dS )	zW
LiteLLM A2A Client class.

Provides a class-based interface for A2A agent invocation.
    )TYPE_CHECKINGAsyncIteratorDictOptional)LiteLLMSendMessageResponse)	A2AClient)	AgentCardSendMessageRequestSendStreamingMessageRequestSendStreamingMessageResponsec                
   @   st   e Zd ZdZ		ddededeeeef  fddZdddZ	dddZ
ddd	efddZddd	ed fddZdS )r   a  
    LiteLLM wrapper for A2A agent invocation.

    Creates the underlying A2A client once on first use and reuses it.

    Example:
        ```python
        from litellm.a2a_protocol import A2AClient
        from a2a.types import SendMessageRequest, MessageSendParams
        from uuid import uuid4

        client = A2AClient(base_url="http://localhost:10001")

        request = SendMessageRequest(
            id=str(uuid4()),
            params=MessageSendParams(
                message={
                    "role": "user",
                    "parts": [{"kind": "text", "text": "Hello!"}],
                    "messageId": uuid4().hex,
                }
            )
        )
        response = await client.send_message(request)
        ```
          N@Nbase_urltimeoutextra_headersc                 C   s   || _ || _|| _d| _dS )a&  
        Initialize the A2A client wrapper.

        Args:
            base_url: The base URL of the A2A agent (e.g., "http://localhost:10001")
            timeout: Request timeout in seconds (default: 60.0)
            extra_headers: Optional additional headers to include in requests
        N)r   r   r   _a2a_client)selfr   r   r    r   R/home/app/Keep/.python/lib/python3.10/site-packages/litellm/a2a_protocol/client.py__init__1   s   
zA2AClient.__init__returnA2AClientTypec                    s:   | j du rddlm} || j| j| jdI dH | _ | j S )z(Get or create the underlying A2A client.Nr   )create_a2a_clientr   r   r   )r   litellm.a2a_protocol.mainr   r   r   r   )r   r   r   r   r   _get_clientD   s   
zA2AClient._get_clientr   c                    s(   ddl m} || j| j| jdI dH S )z%Fetch the agent card from the server.r   )aget_agent_cardr   N)r   r   r   r   r   )r   r   r   r   r   get_agent_cardP   s   zA2AClient.get_agent_cardrequestr	   c                    s.   ddl m} |  I dH }|||dI dH S )z Send a message to the A2A agent.r   )asend_messageN
a2a_clientr   )r   r   r   )r   r   r   r    r   r   r   send_messageZ   s   zA2AClient.send_messager
   r   c                 C  sB   ddl m} |  I dH }|||d2 z	3 dH W }|V  q6 dS )z*Send a streaming message to the A2A agent.r   )asend_message_streamingNr   )r   r"   r   )r   r   r"   r    chunkr   r   r   send_message_streamingc   s   z A2AClient.send_message_streaming)r   N)r   r   )r   r   )__name__
__module____qualname____doc__strfloatr   r   r   r   r   r   r!   r   r$   r   r   r   r   r      s.    




	r   N)r(   typingr   r   r   r   Zlitellm.types.agentsr   Z
a2a.clientr   r   Z	a2a.typesr   r	   r
   r   r   r   r   r   <module>   s    