o
    iy                     @  s   d dl mZ d dlmZ d dlmZmZmZmZ d dl	m
Z
 d dlmZmZmZ d dlmZmZ d dlZd dlmZ ed	ed
ZG dd deddZdddZG dd deZG dd deZdS )    )annotations)Sequence)	AnnotatedAny	TypedDictcast)Icon)BeforeValidatorFieldPrivateAttr)SelfTypeVarN)FastMCPBaseModelTdefaultc                   @  s   e Zd ZU ded< dS )FastMCPMetaz	list[str]tagsN)__name__
__module____qualname____annotations__ r   r   b/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/fastmcp/utilities/components.pyr      s   
 r   F)total	maybe_setset[T] | Sequence[T] | Nonereturnset[T]c                 C  s$   | du rt  S t| t r| S t | S )z@Convert a sequence to a set, defaulting to an empty set if None.N)set
isinstance)r   r   r   r   _convert_set_default_none   s
   
r!   c                      s(  e Zd ZU dZeddZded< edddZd	ed
< edddZd	ed< edddZ	ded< ee
ddZded< edddZded< edddZded< e Zd	ed< ddd= fd"d#Zed>d$d%Z	d?d@d(d)Zdd*dd+dA fd/d0ZdBd3d4Zd>d5d6ZdCd7d8ZdCd9d:ZdDd;d<Z  ZS )EFastMCPComponentzIBase class for FastMCP tools, prompts, resources, and resource templates.zThe name of the component.)descriptionstrnameNz0The title of the component for display purposes.)r   r#   
str | Nonetitlez!The description of the component.r#   zHOptional list of icons for this component to display in user interfaces.zlist[Icon] | NoneiconszTags for the component.)default_factoryr#   z?Annotated[set[str], BeforeValidator(_convert_set_default_none)]r   z$Meta information about the componentdict[str, Any] | NonemetaTz!Whether the component is enabled.boolenabled_key)keyr/   kwargsr   r   Nonec                     t  jdi | || _d S Nr   )super__init__r.   )selfr/   r0   	__class__r   r   r5   =      
zFastMCPComponent.__init__c                 C  s   | j p| jS )a*  
        The key of the component. This is used for internal bookkeeping
        and may reflect e.g. prefixes or other identifiers. You should not depend on
        keys having a certain value, as the same tool loaded from different
        hierarchies of servers may have different keys.
        )r.   r%   r6   r   r   r   r/   A   s   zFastMCPComponent.keyinclude_fastmcp_metabool | Nonec                 C  sT   |du rt jj}| jpi }|r&tt| jd}|d }r"||B }||d< |p)dS )z
        Get the meta information about the component.

        If include_fastmcp_meta is True, a `_fastmcp` key will be added to the
        meta, containing a `tags` field with the tags of the component.
        N)r   _fastmcp)fastmcpsettingsr;   r+   r   sortedr   get)r6   r;   r+   fastmcp_metaupstream_metar   r   r   get_metaK   s   

zFastMCPComponent.get_metaF)updatedeepr/   rE   rF   r   c                  s(   t  j||d}|dur||_tt|S )z
        Create a copy of the component.

        Args:
            update: A dictionary of fields to update.
            deep: Whether to deep copy the component.
            key: The key to use for the copy.
        )rE   rF   N)r4   
model_copyr.   r   r   )r6   rE   rF   r/   copyr7   r   r   rG   c   s   
zFastMCPComponent.model_copyotherobjectc                 C  s6   t | t |ur
dS t|t | sdS |  | kS )NF)typer    
model_dump)r6   rI   r   r   r   __eq__z   s
   zFastMCPComponent.__eq__c                 C  s6   | j j d| jd| jd| jd| j d| j dS )Nz(name=z, title=z, description=z, tags=z
, enabled=))r8   r   r%   r'   r#   r   r-   r:   r   r   r   __repr__   s   6zFastMCPComponent.__repr__c                 C  
   d| _ dS )Enable the component.TNr-   r:   r   r   r   enable      
zFastMCPComponent.enablec                 C  rP   )Disable the component.FNrR   r:   r   r   r   disable   rT   zFastMCPComponent.disablec                 C  s   |   S )zCreate a copy of the component.)rG   r:   r   r   r   rH      s   zFastMCPComponent.copy)r/   r&   r0   r   r   r1   )r   r$   )N)r;   r<   r   r*   )rE   r*   rF   r,   r/   r&   r   r   )rI   rJ   r   r,   r   r1   r   r   )r   r   r   __doc__r
   r%   r   r'   r#   r(   r   r   r+   r-   r   r.   r5   propertyr/   rD   rG   rM   rO   rS   rV   rH   __classcell__r   r   r7   r   r"      sV   
 




r"   c                      sb   e Zd ZU dZeddZded< ddd fddZd fddZd fddZ	dddZ
  ZS )MirroredComponentzBase class for components that are mirrored from a remote server.

    Mirrored components cannot be enabled or disabled directly. Call copy() first
    to create a local version you can modify.
    Fr   r,   	_mirrored)r]   r0   r   r   r1   c                  r2   r3   )r4   r5   r]   )r6   r]   r0   r7   r   r   r5      r9   zMirroredComponent.__init__c                   .   | j rtd| j d| j dt   dS )rQ   z"Cannot enable mirrored component '"'. Create a local copy first with ".copy() and add it to your server.N)r]   RuntimeErrorr%   r4   rS   r:   r7   r   r   rS         
zMirroredComponent.enablec                   r^   )rU   z#Cannot disable mirrored component 'r_   r`   N)r]   ra   r%   r4   rV   r:   r7   r   r   rV      rb   zMirroredComponent.disabler   c                 C  s   |   }d|_|S )z4Create a copy of the component that can be modified.F)rG   r]   )r6   copiedr   r   r   rH      s   zMirroredComponent.copy)r]   r,   r0   r   r   r1   rW   rX   )r   r   r   rY   r   r]   r   r5   rS   rV   rH   r[   r   r   r7   r   r\      s   
 		r\   )r   r   r   r   )
__future__r   collections.abcr   typingr   r   r   r   	mcp.typesr   pydanticr	   r
   r   typing_extensionsr   r   r>   fastmcp.utilities.typesr   r   r   r!   r"   r\   r   r   r   r   <module>   s    
	t