o
    i                     @  s   d dl mZ d dlZd dlmZmZ d dlmZ d dl	m
Z
 d dlm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 eeZG dd dZdS )    )annotationsN)	AwaitableCallable)Any)GetPromptResult)settings)NotFoundErrorPromptError)FunctionPromptPromptPromptResult)DuplicateBehavior)
get_loggerc                   @  sh   e Zd ZdZ		d'd(ddZd)ddZd*ddZd+ddZ			d,d-ddZd.d d!Z		d/d0d%d&Z
dS )1PromptManagerzManages FastMCP prompts.Nduplicate_behaviorDuplicateBehavior | Nonemask_error_detailsbool | Nonec                 C  sN   i | _ |ptj| _|d u rd}|tjvr"td| ddtj || _d S )NwarnzInvalid duplicate_behavior: z. Must be one of: z, )_promptsr   r   r   __args__
ValueErrorjoinr   )selfr   r    r   d/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/fastmcp/prompts/prompt_manager.py__init__   s   


zPromptManager.__init__keystrreturnboolc                   s   |   I dH }||v S )zCheck if a prompt exists.N)get_promptsr   r   promptsr   r   r   
has_prompt)   s   zPromptManager.has_promptr   c                   s.   |   I dH }||v r|| S td| )zGet prompt by key.NzUnknown prompt: )r!   r   r"   r   r   r   
get_prompt.   s
   zPromptManager.get_promptdict[str, Prompt]c                   s   t | jS )zK
        Gets the complete, unfiltered inventory of local prompts.
        )dictr   )r   r   r   r   r!   5   s   
zPromptManager.get_promptsfn5Callable[..., PromptResult | Awaitable[PromptResult]]name
str | Nonedescriptiontagsset[str] | Noner
   c                 C  s2   t jrtjdtdd tj||||d}| |S )z Create a prompt from a function.zkPromptManager.add_prompt_from_fn() is deprecated. Use Prompt.from_function() and call add_prompt() instead.   )
stacklevel)r*   r,   r-   )r   deprecation_warningswarningsr   DeprecationWarningr
   from_function
add_prompt)r   r(   r*   r,   r-   promptr   r   r   add_prompt_from_fn;   s   	
z PromptManager.add_prompt_from_fnr6   c                 C  s   | j |j}|rB| jdkrtd|j  || j |j< |S | jdkr,|| j |j< |S | jdkr9td|j | jdkr@|S |S || j |j< |S )zAdd a prompt to the manager.r   zPrompt already exists: replaceerrorignore)r   getr   r   loggerwarningr   )r   r6   existingr   r   r   r5   O   s    
	


zPromptManager.add_prompt	argumentsdict[str, Any] | Noner   c              
     s   |  |I dH }z||I dH }t|j|dW S  ty/ } z
td| |d}~w tyX } ztd| | jrItd||td|d| |d}~ww )zv
        Internal API for servers: Finds and renders a prompt, respecting the
        filtered protocol path.
        N)r,   messageszError rendering prompt z: )	r%   renderr   r,   r	   r<   	exception	Exceptionr   )r   r*   r?   r6   rA   er   r   r   render_prompta   s    	zPromptManager.render_prompt)NN)r   r   r   r   )r   r   r   r    )r   r   r   r   )r   r&   )NNN)
r(   r)   r*   r+   r,   r+   r-   r.   r   r
   )r6   r   r   r   )N)r*   r   r?   r@   r   r   )__name__
__module____qualname____doc__r   r$   r%   r!   r7   r5   rF   r   r   r   r   r      s    


	
r   )
__future__r   _annotationsr2   collections.abcr   r   typingr   mcpr   fastmcpr   fastmcp.exceptionsr   r	   fastmcp.prompts.promptr
   r   r   fastmcp.settingsr   fastmcp.utilities.loggingr   rG   r<   r   r   r   r   r   <module>   s    