Ë
    uPêj=  ã            	       óv   — U d Z ddlmZ ddlmZ ddlmZmZ dddd	d
ddddœZee	e
ef      ed<    G d„ d«      Zy)z¢
Utilities for mapping exceptions to Anthropic error format.

Similar to litellm/litellm_core_utils/exception_mapping_utils.py but for Anthropic response format.
é    )ÚFinal)Úsafe_json_loadsé   )ÚAnthropicErrorResponseÚAnthropicErrorTypeÚinvalid_request_errorÚauthentication_errorÚpermission_errorÚnot_found_errorÚrequest_too_largeÚrate_limit_errorÚ	api_errorÚoverloaded_error)i�  i‘  i“  i”  i�  i­  iô  i  ÚANTHROPIC_ERROR_TYPE_MAPc            
       óÔ   — e Zd ZdZededefd„«       Ze	 ddedededz  de	fd„«       Z
ed	edefd
„«       Zededefd„«       Zeded	edefd„«       Ze	 dded	ededz  de	fd„«       Zy)ÚAnthropicExceptionMappingz£
    Helper class for mapping exceptions to Anthropic error format.

    Similar pattern to ExceptionCheckers in litellm_core_utils/exception_mapping_utils.py
    Ústatus_codeÚreturnc                 ó.   — t         j                  | d«      S )z-Map HTTP status code to Anthropic error type.r   )r   Úget)r   s    úƒ/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/anthropic_interface/exceptions/exception_mapping_utils.pyÚget_error_typez(AnthropicExceptionMapping.get_error_type"   s   € ô (×+Ñ+¨K¸ÓEÐEó    NÚmessageÚ
request_idc                 óN   — t         j                  | «      }d||dœdœ}|r||d<   |S )zò
        Create an Anthropic-formatted error response dict.

        Anthropic error format:
        {
            "type": "error",
            "error": {"type": "...", "message": "..."},
            "request_id": "req_..."
        }
        Úerror)Útyper   )r   r   r   )r   r   )r   r   r   Ú
error_typeÚresponses        r   Úcreate_error_responsez/AnthropicExceptionMapping.create_error_response'   s?   € ô  6×DÑDÀ[ÓQˆ
ð à"Ø"ññ3
ˆñ Ø%/ˆH�\Ñ"àˆr   Úraw_messagec                 óä   — t        | «      }t        |t        «      rTd|v r(t        |d   t        «      r|d   j                  d| «      S |j                  d«      xs |j                  d«      xs | S | S )zó
        Extract error message from various provider response formats.

        Handles:
        - Bedrock: {"detail": {"message": "..."}}
        - AWS: {"Message": "..."}
        - Generic: {"message": "..."}
        - Plain strings
        Údetailr   ÚMessage)r   Ú
isinstanceÚdictr   )r"   Úparseds     r   Úextract_error_messagez/AnthropicExceptionMapping.extract_error_messageF   sn   € ô (¨Ó4ˆÜ�fœdÔ#à˜6Ñ!¤j°¸Ñ1AÄ4Ô&HØ˜hÑ'×+Ñ+¨I°{ÓCÐCà—:‘:˜iÓ(ÒP¨F¯J©J°yÓ,AÒPÀ[ÐPØÐr   r(   c                 ó�   — | j                  d«      dk(  xr1 t        | j                  d«      t        «      xr d| d   v xr d| d   v S )zÏ
        Check if a parsed dict is in Anthropic error format.

        Anthropic error format:
        {
            "type": "error",
            "error": {"type": "...", "message": "..."}
        }
        r   r   r   )r   r&   r'   )r(   s    r   Ú_is_anthropic_error_dictz2AnthropicExceptionMapping._is_anthropic_error_dictZ   sV   € ð �J‰J�vÓ 'Ñ)ò -Ü˜6Ÿ:™: gÓ.´Ó5ò-à˜& ™/Ð)ò-ð ˜V G™_Ð,ð		
r   c                 óª   — d| v r(t        | d   t        «      r| d   j                  d|«      S | j                  d«      xs | j                  d«      xs |S )zÙ
        Extract error message from a parsed provider-specific dict.

        Handles:
        - Bedrock: {"detail": {"message": "..."}}
        - AWS: {"Message": "..."}
        - Generic: {"message": "..."}
        r$   r   r%   )r&   r'   r   )r(   r"   s     r   Ú_extract_message_from_dictz4AnthropicExceptionMapping._extract_message_from_dictl   sT   € ð �vÑ¤*¨V°HÑ-=¼tÔ"DØ˜(Ñ#×'Ñ'¨	°;Ó?Ð?à�z‰z˜)Ó$ÒL¨¯
©
°9Ó(=ÒLÀÐLr   c                 óê   — t        |«      }t        |t        «      sd}|�"t        j	                  |«      r|r	d|vr||d<   |S |�t        j                  ||«      }n|}t        j                  | ||¬«      S )aé  
        Transform an error message to Anthropic format.

        - If already in Anthropic format: passthrough unchanged
        - Otherwise: extract message and create Anthropic error

        Parses JSON only once for efficiency.

        Args:
            status_code: HTTP status code
            raw_message: Raw error message (may be JSON string or plain text)
            request_id: Optional request ID to include

        Returns:
            AnthropicErrorResponse dict
        Nr   )r   r   r   )r   r&   r'   r   r+   r-   r!   )r   r"   r   r(   r   s        r   Útransform_to_anthropic_errorz6AnthropicExceptionMapping.transform_to_anthropic_error|   sŽ   € ô. .¨kÓ:ˆÜ˜&¤$Ô'ØˆFð ÐÔ";×"TÑ"TÐU[Ô"\á˜l°&Ñ8Ø'1��|Ñ$ØˆMð ÐÜ/×JÑJÈ6ÐS^Ó_‰Gà!ˆGä(×>Ñ>Ø#ØØ!ð ?ó 
ð 	
r   )N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstaticmethodÚintr   r   Ústrr   r!   r)   r'   Úboolr+   r-   r/   © r   r   r   r      s"  „ ñð ðF Cð FÐ,>ò Fó ðFð ð "&ñØðàðð ˜$‘Jðð 
 ò	ó ðð< ð¨3ð °3ò ó ðð& ð
¨ð 
°$ò 
ó ð
ð" ðM¨4ð M¸cð MÀcò Mó ðMð ð "&ñ+
Øð+
àð+
ð ˜$‘Jð+
ð 
 ò	+
ó ñ+
r   r   N)r3   Útypingr   Ú*litellm.litellm_core_utils.safe_json_loadsr   Ú
exceptionsr   r   r   r'   r5   Ú__annotations__r   r8   r   r   ú<module>r=      s[   ðòõ å Fç Bð
 
!Ø	Ø	Ø	Ø	Ø	Ø	Ø	ñ	BÐ ˜%  SÐ*<Ð%<Ñ =Ñ>ó 	÷M
ò M
r   