Ë
    uPêj  ã                   óŒ   — d Z ddlmZmZ ddlmZmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ er	ddlmZ eZneZ G d	„ d
e	«      Zy)aB  
Transformation for Bedrock Mantle (Claude Mythos Preview)

https://docs.aws.amazon.com/bedrock/latest/userguide/model-card-anthropic-claude-mythos-preview.html

The bedrock-mantle endpoint uses the Anthropic Messages API format but is served
at a different endpoint (bedrock-mantle.{region}.api.aws) with AWS SigV4 auth.
é    )ÚAsyncIteratorÚIterator)ÚTYPE_CHECKINGÚAnyÚFinal)ÚAmazonAnthropicClaudeConfig)Úbuild_mantle_messages_url)ÚAllMessageValues)ÚModelResponse)ÚLoggingc                   óT  ‡ — e Zd ZdZ	 ddedz  dedz  dededededz  d	efd
„Z	 	 ddededee	   dedededz  dedz  d	efˆ fd„Z
dedee	   dededed	efd„Zdedee	   dededed	efd„Zedededed	efd„«       Zed	efd„«       Z	 ddee   ee   z  ez  dededz  d	efd„Zˆ xZS )ÚAmazonMantleConfiga&  
    Config for the bedrock-mantle endpoint (Claude Mythos Preview).

    Uses the Anthropic Messages API format with AWS SigV4 auth, but at a
    different endpoint from bedrock-runtime. Model ID goes in the request body.

    Usage: model="bedrock/mantle/anthropic.claude-mythos-preview"
    NÚapi_baseÚapi_keyÚmodelÚoptional_paramsÚlitellm_paramsÚstreamÚreturnc                 ób   — | j                  ||¬«      }t        ||j                  d«      |¬«      S )N)r   r   Úaws_bedrock_runtime_endpoint)r   r   Úregion)Ú_get_aws_region_namer	   Úget)Úselfr   r   r   r   r   r   r   s           út/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/bedrock/chat/mantle/transformation.pyÚget_complete_urlz#AmazonMantleConfig.get_complete_url&   s<   € ð ×1Ñ1À/ÐY^Ð1Ó_ˆÜ(ØØ)8×)<Ñ)<Ð=[Ó)\Øô
ð 	
ó    ÚheadersÚmessagesc           	      ód   •— t         ‰	| �  |||||||¬«      }|j                  d«      }|r||d<   |S )N)r   r   r    r   r   r   r   Úaws_bedrock_project_idzanthropic-workspace)ÚsuperÚvalidate_environmentr   )
r   r   r   r    r   r   r   r   Ú
project_idÚ	__class__s
            €r   r$   z'AmazonMantleConfig.validate_environment6   sT   ø€ ô ‘'Ñ.ØØØØ+Ø)ØØð /ó 
ˆð +×.Ñ.Ð/GÓHˆ
ÙØ-7ˆGÐ)Ñ*Øˆr   c                 ó|   — |j                  ddd«      }| j                  |||||¬«      }| j                  |||¬«      S ©Nzmantle/Ú é   )r   r    r   r   r   )ÚrequestÚmodel_idr   )ÚreplaceÚ%_build_bedrock_anthropic_request_baseÚ_restore_mantle_body_fields©r   r   r    r   r   r   r,   r+   s           r   Útransform_requestz$AmazonMantleConfig.transform_requestN   s^   € ð  Ÿ-™-¨	°2°qÓ9ˆà×CÑCØØØ+Ø)Øð Dó 
ˆð ×/Ñ/ØØØ+ð 0ó 
ð 	
r   c              ƒ   óº   K  — |j                  ddd«      }| j                  |||||¬«      }| j                  |«      ƒ d {  –—†  | j                  |||¬«      S 7 Œ­wr(   )r-   r.   Ú-_async_convert_document_url_sources_to_base64r/   r0   s           r   Úasync_transform_requestz*AmazonMantleConfig.async_transform_requesti   s|   è ø€ ð  Ÿ-™-¨	°2°qÓ9ˆà×CÑCØØØ+Ø)Øð Dó 
ˆð ×@Ñ@ÀÓI×IÐIØ×/Ñ/ØØØ+ð 0ó 
ð 	
ð 	Jús   ‚>AÁ AÁAr+   r,   c                 óH   — |j                  d«      du rddini }i | ¥d|i¥|¥S )Nr   Tr   )r   )r+   r,   r   Ústream_fieldss       r   r/   z.AmazonMantleConfig._restore_mantle_body_fields�   s9   € à9H×9LÑ9LÈXÓ9VÐZ^Ñ9^ h°Ñ%5ÐdfˆØ>�'Ð>˜7 HÑ>°Ð>Ð>r   c                  ó   — y)NF© )r   s    r   Úhas_custom_stream_wrapperz,AmazonMantleConfig.has_custom_stream_wrapper†   s   € àr   Ústreaming_responseÚsync_streamÚ	json_modec                 ó$   — ddl m}  ||||¬«      S )Nr   )ÚModelResponseIterator)r:   r;   r<   )Ú#litellm.llms.anthropic.chat.handlerr>   )r   r:   r;   r<   r>   s        r   Úget_model_response_iteratorz.AmazonMantleConfig.get_model_response_iteratorŠ   s   € õ 	Ná$Ø1Ø#Øô
ð 	
r   )N)NN)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstrÚdictÚboolr   Úlistr
   r$   r1   r4   Ústaticmethodr/   Úpropertyr9   r   r   r   r   r@   Ú__classcell__)r&   s   @r   r   r      sé  ø„ ñð  #ñ
à˜‘*ð
ð �t‘ð
ð ð	
ð
 ð
ð ð
ð �t‘ð
ð 
ó
ð. #Ø#ñàðð ðð Ð'Ñ(ð	ð
 ðð ðð �t‘ðð ˜‘*ðð 
õð0
àð
ð Ð'Ñ(ð
ð ð	
ð
 ð
ð ð
ð 
ó
ð6
àð
ð Ð'Ñ(ð
ð ð	
ð
 ð
ð ð
ð 
ó
ð0 ð?¨Tð ?¸Sð ?ÐSWð ?Ð\`ò ?ó ð?ð ð¨4ò ó ðð "'ñ	
à$ S™M¨M¸#Ñ,>Ñ>ÀÑNð
ð ð
ð ˜$‘;ð	
ð
 
÷
r   r   N)rD   Úcollections.abcr   r   Útypingr   r   r   ÚQlitellm.llms.bedrock.chat.invoke_transformations.anthropic_claude3_transformationr   Ú!litellm.llms.bedrock.common_utilsr	   Úlitellm.types.llms.openair
   Úlitellm.types.utilsr   Ú*litellm.litellm_core_utils.litellm_loggingr   Ú_LiteLLMLoggingObjÚLiteLLMLoggingObjr   r8   r   r   ú<module>rU      sG   ðñ÷ 4ß ,Ñ ,õõ HÝ 6Ý -áÝXà*ÑàÐôz
Ð4õ z
r   