
    Yj                     z    d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	m
Z
  G d de          Z G d d	e          Zd
S )z$Mixins for common SDK functionality.    )annotations)ABCabstractmethod)Any)Fieldvalidate_callc                     e Zd ZU dZded<   ded<   edd            Zedd	            Zedd
            Zed d            Z	ed!d            Z
d"dZe edd          fd#d            Zd"dZe edd          fd$d            Zd%dZdS )&MetadataConfigMixina  
    Mixin providing get/set/refresh methods for metadata and configuration.

    Classes using this mixin must implement:
    - _get_http_client() -> HTTPClientProtocol
    - _get_fetch_route() -> str
    - _get_update_route() -> str
    - _get_fetch_body() -> dict[str, Any]
    - _parse_response(data: dict[str, Any]) -> tuple[dict, dict]

    And must have these attributes:
    - _metadata: dict[str, object] | None
    - _configuration: dict[str, object] | None
    zdict[str, object] | None	_metadata_configurationreturnr   c                    dS )z(Get the HTTP client for making requests.N selfs    T/home/ubuntu/.hermes/hermes-agent/venv/lib/python3.11/site-packages/honcho/mixins.py_get_http_clientz$MetadataConfigMixin._get_http_client   	     	    strc                    dS z2Get the route for fetching metadata/configuration.Nr   r   s    r   _get_fetch_routez$MetadataConfigMixin._get_fetch_route#   r   r   c                    dS z2Get the route for updating metadata/configuration.Nr   r   s    r   _get_update_routez%MetadataConfigMixin._get_update_route(   r   r   dict[str, Any]c                    dS z1Get the body for fetching metadata/configuration.Nr   r   s    r   _get_fetch_bodyz#MetadataConfigMixin._get_fetch_body-   r   r   data+tuple[dict[str, object], dict[str, object]]c                    dS z9Parse the response to extract metadata and configuration.Nr   r   r!   s     r   _parse_responsez#MetadataConfigMixin._parse_response2   	    
 	r   dict[str, object]c                    |                                                      |                                 |                                           }|                     |          \  }}|| _        || _        | j        S )z
        Get metadata from the server and update the cache.

        Returns:
            A dictionary containing the metadata. Returns an empty dictionary
            if no metadata is set.
        bodyr   postr   r    r&   r   r   r   r!   metadataconfigurations       r   get_metadataz MetadataConfigMixin.get_metadata9   sx     $$&&++!!##$*>*>*@*@ , 
 
 #'"6"6t"<"<-!+~r   .zMetadata dictionary to set)descriptionr/   Nonec                    |                                                      |                                 d|i           || _        dS )z
        Set metadata on the server and update the cache.

        Args:
            metadata: A dictionary of metadata to set.
                      Keys must be strings, values can be any JSON-serializable type.
        r/   r*   N)r   putr   r   r   r/   s     r   set_metadataz MetadataConfigMixin.set_metadataI   sQ     	##""$$h' 	$ 	
 	
 	
 "r   c                    |                                                      |                                 |                                           }|                     |          \  }}|| _        || _        | j        S )z
        Get configuration from the server and update the cache.

        Returns:
            A dictionary containing the configuration. Returns an empty dictionary
            if no configuration is set.
        r*   r,   r.   s       r   get_configurationz%MetadataConfigMixin.get_configuration]   sy     $$&&++!!##$*>*>*@*@ , 
 
 #'"6"6t"<"<-!+""r   zConfiguration dictionary to setr0   c                    |                                                      |                                 d|i           || _        dS )z
        Set configuration on the server and update the cache.

        Args:
            configuration: A dictionary of configuration to set.
                    Keys must be strings, values can be any JSON-serializable type.
        r0   r*   N)r   r5   r   r   r   r0   s     r   set_configurationz%MetadataConfigMixin.set_configurationm   sT     	##""$$!=1 	$ 	
 	
 	
 ,r   c                    |                                                      |                                 |                                           }|                     |          \  }}|| _        || _        dS )z
        Refresh cached metadata and configuration from the server.

        Makes a single API call to retrieve the latest metadata and configuration
        and updates the cached attributes.
        r*   Nr,   r.   s       r   refreshzMetadataConfigMixin.refresh   sv     $$&&++!!##$*>*>*@*@ , 
 
 #'"6"6t"<"<-!+r   Nr   r   r   r   r   r   r!   r   r   r"   r   r(   r/   r(   r   r3   r0   r(   r   r3   r   r3   )__name__
__module____qualname____doc____annotations__r   r   r   r   r    r&   r1   r   r   r7   r9   r<   r>   r   r   r   r
   r
      s          (''',,,,   ^    ^    ^    ^    ^      ',e9'
 '
 '
" " " " ]"&# # # #   ,15>,
 ,
 ,
, , , , ],&, , , , , ,r   r
   c                     e Zd ZdZedd            Zedd            Zedd            Zedd	            Zedd            Z	edd            Z
ed d            Zed!d            Zed!d            Zd!dZddZd!dZd dZd"dZdS )#AsyncMetadataConfigMixina  
    Async mixin providing get/set/refresh methods for metadata and configuration.

    Classes using this mixin must implement:
    - _get_async_http_client() -> AsyncHTTPClientProtocol
    - _get_fetch_route() -> str
    - _get_update_route() -> str
    - _get_fetch_body() -> dict[str, Any]
    - _parse_response(data: dict[str, Any]) -> tuple[dict, dict]
    - _set_metadata(metadata: dict[str, object]) -> None
    - _set_configuration(configuration: dict[str, object]) -> None
    r   r   c                    dS )z.Get the async HTTP client for making requests.Nr   r   s    r   _get_async_http_clientz/AsyncMetadataConfigMixin._get_async_http_client   r   r   r   c                    dS r   r   r   s    r   r   z)AsyncMetadataConfigMixin._get_fetch_route   r   r   c                    dS r   r   r   s    r   r   z*AsyncMetadataConfigMixin._get_update_route   r   r   r   c                    dS r   r   r   s    r   r    z(AsyncMetadataConfigMixin._get_fetch_body   r   r   r!   r"   c                    dS r$   r   r%   s     r   r&   z(AsyncMetadataConfigMixin._parse_response   r'   r   r/   r(   r3   c                    dS )z"Set metadata on the parent object.Nr   r6   s     r   _set_metadataz&AsyncMetadataConfigMixin._set_metadata   r   r   r0   c                    dS )z'Set configuration on the parent object.Nr   r;   s     r   _set_configurationz+AsyncMetadataConfigMixin._set_configuration   r   r   c                    dS )z+Get cached metadata from the parent object.Nr   r   s    r   _get_metadataz&AsyncMetadataConfigMixin._get_metadata   r   r   c                    dS )z0Get cached configuration from the parent object.Nr   r   s    r   _get_configurationz+AsyncMetadataConfigMixin._get_configuration   r   r   c                X  K   |                                                      |                                 |                                            d{V }|                     |          \  }}|                     |           |                     |           |                                 S )z,Get metadata from the server asynchronously.r*   N)rO   r-   r   r    r&   rU   rW   rY   r.   s       r   r1   z%AsyncMetadataConfigMixin.get_metadata   s      002277!!##$*>*>*@*@ 8 
 
 
 
 
 
 
 
 #'"6"6t"<"<-8$$$...!!###r   c                   K   |                                                      |                                 d|i           d{V  |                     |           dS )z*Set metadata on the server asynchronously.r/   r*   N)rO   r5   r   rU   r6   s     r   r7   z%AsyncMetadataConfigMixin.set_metadata   s      ))++//""$$h' 0 
 
 	
 	
 	
 	
 	
 	
 	
 	8$$$$$r   c                X  K   |                                                      |                                 |                                            d{V }|                     |          \  }}|                     |           |                     |           |                                 S )z1Get configuration from the server asynchronously.r*   N)rO   r-   r   r    r&   rU   rW   r[   r.   s       r   r9   z*AsyncMetadataConfigMixin.get_configuration   s      002277!!##$*>*>*@*@ 8 
 
 
 
 
 
 
 
 #'"6"6t"<"<-8$$$...&&(((r   c                   K   |                                                      |                                 d|i           d{V  |                     |           dS )z/Set configuration on the server asynchronously.r0   r*   N)rO   r5   r   rW   r;   s     r   r<   z*AsyncMetadataConfigMixin.set_configuration   s      ))++//""$$!=1 0 
 
 	
 	
 	
 	
 	
 	
 	
 	.....r   c                4  K   |                                                      |                                 |                                            d{V }|                     |          \  }}|                     |           |                     |           dS )z9Refresh cached metadata and configuration asynchronously.r*   N)rO   r-   r   r    r&   rU   rW   r.   s       r   r>   z AsyncMetadataConfigMixin.refresh   s      002277!!##$*>*>*@*@ 8 
 
 
 
 
 
 
 
 #'"6"6t"<"<-8$$$.....r   Nr?   r@   rA   rB   rD   rE   rC   rF   )rG   rH   rI   rJ   r   rO   r   r   r    r&   rU   rW   rY   r[   r1   r7   r9   r<   r>   r   r   r   rM   rM      s            ^    ^    ^    ^    ^    ^    ^    ^    ^$ $ $ $% % % %) ) ) )/ / / // / / / / /r   rM   N)rJ   
__future__r   abcr   r   typingr   pydanticr   r   r
   rM   r   r   r   <module>re      s    * * " " " " " " # # # # # # # #       ) ) ) ) ) ) ) )B, B, B, B, B,# B, B, B,Jh/ h/ h/ h/ h/s h/ h/ h/ h/ h/r   