
    AHj                     t    d Z ddlmZ ddlZ G d de      Z G d de      Z G d d	e      Z G d
 de      Zy)zv
A2A Protocol Exceptions.

Custom exception types for A2A protocol operations, following LiteLLM's exception pattern.
    )OptionalNc                        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
Z	defdZ
defdZ xZS )A2AErrorzm
    Base exception for A2A protocol errors.

    Follows the same pattern as LiteLLM's main exceptions.
    messagestatus_codellm_providermodelresponselitellm_debug_infomax_retriesnum_retriesc	                    || _         d| | _        || _        || _        || _        || _        || _        |xs6 t        j                  | j                   t        j                  dd            | _
        t        	| 1  | j                         y )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__s
            W/root/tools/cai/cai_env/lib/python3.12/site-packages/litellm/a2a_protocol/exceptions.pyr   zA2AError.__init__   s     '+G95(
"4&&  
ENN((MM5IJ%
 	&    returnc                     | j                   }| j                  r|d| j                   dz  }| j                  r|d| j                   z  }|S )Nz LiteLLM Retried: z timesz, LiteLLM Max Retries: )r   r   r   )r   _messages     r   __str__zA2AError.__str__+   sV    <<,T-=-=,>fEEH1$2B2B1CDDHr   c                 "    | j                         S )N)r   )r   s    r   __repr__zA2AError.__repr__3   s    ||~r   )i  	a2a_agentNNNNN)__name__
__module____qualname____doc__strintr   r   r   r   r   r!   __classcell__r   s   @r   r   r      s     '#-1,0%)%)'' ' 	'
 }' 5>>*' %SM' c]' c]'0 # r   r   c                        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	Z	 x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
    r   r   r	   r
   r   r   r   c           
      B    || _         t        | 	  |dd|||||       y )Ni  r"   )r   r   r   r	   r
   r   r   r   r   r   r   )	r   r   r   r	   r
   r   r   r   r   s	           r   r   zA2AConnectionError.__init__A   s6     $1## 	 		
r   )NNNNNN)r#   r$   r%   r&   r'   r   r   r   r(   r   r)   r*   s   @r   r,   r,   7   s     "#-1,0%)%)

 c]
 }	

 5>>*
 %SM
 c]
 c]
 
r   r,   c                   n     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Z x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
    r   r   r	   r
   r   c                 >    || _         t        | 	  |dd|||       y )Ni  r"   )r   r   r   r	   r
   r   r.   )r   r   r   r	   r
   r   r   s         r   r   zA2AAgentCardError.__init__b   s0     $1 	 	
r   )NNNN)
r#   r$   r%   r&   r'   r   r   r   r   r)   r*   s   @r   r0   r0   X   se     "#-1,0

 c]
 }	

 5>>*
 %SM
 
r   r0   c            
       F     e Zd ZdZ	 	 ddededee   dee   f fdZ x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
    localhost_urlbase_urloriginal_errorr	   c                 f    || _         || _        || _        d| d| d}t        |   |||       y )Nz,Agent card contains localhost/internal URL 'z'. Retrying with base URL 'z'.)r   r   r	   )r4   r5   r6   r   r   )r   r4   r5   r6   r	   r   r   s         r   r   zA2ALocalhostURLError.__init__   sY     + , ;=/ J''/j4 	 	 	 	
r   )NN)	r#   r$   r%   r&   r'   r   	Exceptionr   r)   r*   s   @r   r3   r3   u   sI    " /3#

 
 !+	

 }
 
r   r3   )	r&   typingr   r   r8   r   r,   r0   r3    r   r   <module>r;      sE     (y (V
 
B
 
:!
- !
r   