
    i                     Z    d Z ddlmZmZ ddlmZmZmZmZ ddl	m
Z
  G d de          ZdS )u8  Abstract base for provider transports.

A transport owns the data path for one api_mode:
  convert_messages → convert_tools → build_kwargs → normalize_response

It does NOT own: client construction, streaming, credential refresh,
prompt caching, interrupt handling, or retry logic.  Those stay on AIAgent.
    )ABCabstractmethod)AnyDictListOptional)NormalizedResponsec                      e Zd ZdZeedefd                        Zedee	ee
f                  de
fd            Zedee	ee
f                  de
fd            Ze	 dd	edee	ee
f                  deee	ee
f                           de	ee
f         fd
            Zede
defd            Zde
defdZde
dee	eef                  fdZdedefdZdS )ProviderTransportzEBase class for provider-specific format conversion and normalization.returnc                     dS )zGThe api_mode string this transport handles (e.g. 'anthropic_messages').N )selfs    :/home/ubuntu/.hermes/hermes-agent/agent/transports/base.pyapi_modezProviderTransport.api_mode   s	     	    messagesc                     dS )zConvert OpenAI-format messages to provider-native format.

        Returns provider-specific structure (e.g. (system, messages) for Anthropic,
        or the messages list unchanged for chat_completions).
        Nr   )r   r   kwargss      r   convert_messagesz"ProviderTransport.convert_messages   s	     	r   toolsc                     dS )zConvert OpenAI-format tool definitions to provider-native format.

        Returns provider-specific tool list (e.g. Anthropic input_schema format).
        Nr   )r   r   s     r   convert_toolszProviderTransport.convert_tools"   	     	r   Nmodelc                     dS )u  Build the complete API call kwargs dict.

        This is the primary entry point — it typically calls convert_messages()
        and convert_tools() internally, then adds model-specific config.

        Returns a dict ready to be passed to the provider's SDK client.
        Nr   )r   r   r   r   paramss        r   build_kwargszProviderTransport.build_kwargs*   s	     	r   responsec                     dS )zNormalize a raw provider response to the shared NormalizedResponse type.

        This is the only method that returns a transport-layer type.
        Nr   )r   r   r   s      r   normalize_responsez$ProviderTransport.normalize_response;   r   r   c                     dS )zOptional: check if the raw response is structurally valid.

        Returns True if valid, False if the response should be treated as invalid.
        Default implementation always returns True.
        Tr   r   r   s     r   validate_responsez#ProviderTransport.validate_responseC   	     tr   c                     dS )zOptional: extract provider-specific cache hit/creation stats.

        Returns dict with 'cached_tokens' and 'creation_tokens', or None.
        Default returns None.
        Nr   r#   s     r   extract_cache_statsz%ProviderTransport.extract_cache_statsK   r%   r   
raw_reasonc                     |S )zOptional: map provider-specific stop reason to OpenAI equivalent.

        Default returns the raw reason unchanged.  Override for providers
        with different stop reason vocabularies.
        r   )r   r(   s     r   map_finish_reasonz#ProviderTransport.map_finish_reasonS   s
     r   )N)__name__
__module____qualname____doc__propertyr   strr   r   r   r   r   r   r   r   r	   r!   boolr$   intr'   r*   r   r   r   r   r      s       OO#    ^ X d38n)= C    ^ 4S#X#7 C    ^ 
 15	  tCH~& T#s(^,-	 
c3h   ^  3 =O    ^# $    C HT#s(^4L    C C      r   r   N)r.   abcr   r   typingr   r   r   r   agent.transports.typesr	   r   r   r   r   <module>r6      s     $ # # # # # # # , , , , , , , , , , , , 5 5 5 5 5 5I I I I I I I I I Ir   