o
    ưi                     @   s\   d Z ddlmZ ddlZG dd deZG dd deZG dd	 d	eZG d
d deZdS )zv
A2A Protocol Exceptions.

Custom exception types for A2A protocol operations, following LiteLLM's exception pattern.
    )OptionalNc                       s   e Zd ZdZ							ddedededee d	eej d
ee dee dee f fddZ	defddZ
defddZ  ZS )A2AErrorzm
    Base exception for A2A protocol errors.

    Follows the same pattern as LiteLLM's main exceptions.
      	a2a_agentNmessagestatus_codellm_providermodelresponselitellm_debug_infomax_retriesnum_retriesc	           	         sb   || _ d| | _|| _|| _|| _|| _|| _|p&tj| j tj	dddd| _
t | j d S )Nzlitellm.A2AError: POSTzhttps://litellm.ai)methodurl)r   request)r   r   r   r	   r   r   r   httpxResponseRequestr
   super__init__)	selfr   r   r   r	   r
   r   r   r   	__class__ V/home/app/Keep/.python/lib/python3.10/site-packages/litellm/a2a_protocol/exceptions.pyr      s   zA2AError.__init__returnc                 C   s8   | j }| jr|d| j d7 }| jr|d| j 7 }|S )Nz LiteLLM Retried: z timesz, LiteLLM Max Retries: )r   r   r   )r   _messager   r   r   __str__+   s   zA2AError.__str__c                 C   s   |   S )N)r   )r   r   r   r   __repr__3   s   zA2AError.__repr__)r   r   NNNNN)__name__
__module____qualname____doc__strintr   r   r   r   r   r   __classcell__r   r   r   r   r      s8    		r   c                       sf   e Zd ZdZ						ddedee dee deej dee dee d	ee f fd
dZ	  Z
S )A2AConnectionErrorz
    Raised when connection to an A2A agent fails.

    This typically occurs when:
    - The agent is unreachable
    - The agent card contains a localhost/internal URL
    - Network issues prevent connection
    Nr   r   r	   r
   r   r   r   c              
      s&   || _ t j|dd|||||d d S )Ni  r   )r   r   r   r	   r
   r   r   r   r   r   r   )r   r   r   r	   r
   r   r   r   r   r   r   r   A   s   

zA2AConnectionError.__init__)NNNNNN)r    r!   r"   r#   r$   r   r   r   r%   r   r&   r   r   r   r   r'   7   s.    r'   c                       sR   e Zd ZdZ				d
dedee dee deej dee f
 fdd	Z  Z	S )A2AAgentCardErrorz
    Raised when there's an issue with the agent card.

    This includes:
    - Failed to fetch agent card
    - Invalid agent card format
    - Missing required fields
    Nr   r   r	   r
   r   c                    s"   || _ t j|dd|||d d S )Ni  r   )r   r   r   r	   r
   r   r(   )r   r   r   r	   r
   r   r   r   r   r   b   s   
zA2AAgentCardError.__init__)NNNN)
r    r!   r"   r#   r$   r   r   r   r   r&   r   r   r   r   r)   X   s"    r)   c                
       s@   e Zd ZdZ		d	dededee dee f fddZ  ZS )
A2ALocalhostURLErrora  
    Raised when an agent card contains a localhost/internal URL.

    Many A2A agents are deployed with agent cards that contain internal URLs
    like "http://0.0.0.0:8001/" or "http://localhost:8000/". This error
    indicates that the URL needs to be corrected and the request should be retried.

    Attributes:
        localhost_url: The localhost/internal URL found in the agent card
        base_url: The public base URL that should be used instead
        original_error: The original connection error that was raised
    Nlocalhost_urlbase_urloriginal_errorr	   c                    s:   || _ || _|| _d| d| d}t j|||d d S )Nz,Agent card contains localhost/internal URL 'z'. Retrying with base URL 'z'.)r   r   r	   )r+   r,   r-   r   r   )r   r+   r,   r-   r	   r   r   r   r   r      s   
zA2ALocalhostURLError.__init__)NN)	r    r!   r"   r#   r$   r   	Exceptionr   r&   r   r   r   r   r*   u   s    r*   )	r#   typingr   r   r.   r   r'   r)   r*   r   r   r   r   <module>   s    +!