o
    h6                     @  s\  d Z ddlmZ ddlZddlmZmZmZ ddlm	Z	m
Z
mZ ddlZddlmZmZmZmZ ddlmZmZ ddlmZ dd	lmZmZmZ e	r^dd
lmZ ddlmZ ddlm Z m!Z! G dd deZ"G dd de"Z#G dd de"Z$ee#e$B  e#e$B Z%e&e"B e'e&e
f B ee&e"B e'e&e
f B  B Z(e(ee( B Z)G dd deZ*G dd deZ+dS )z!Base classes for FastMCP prompts.    )annotationsN)	AwaitableCallableSequence)TYPE_CHECKINGAnyLiteral)	BaseModelFieldTypeAdaptervalidate_call)find_context_parameterinject_context)func_metadata)ContentBlockIconTextContent)Context)ServerSessionT)LifespanContextTRequestTc                      s4   e Zd ZU dZded< ded< d fd	d
Z  ZS )Messagez#Base class for all prompt messages.Literal['user', 'assistant']roler   contentstr | ContentBlockkwargsr   c                   s0   t |trtd|d}t jdd|i| d S )Ntexttyper   r    )
isinstancestrr   super__init__selfr   r   	__class__r    `/var/www/html/openai_agents/venv/lib/python3.10/site-packages/mcp/server/fastmcp/prompts/base.pyr$      s   
zMessage.__init__r   r   r   r   )__name__
__module____qualname____doc____annotations__r$   __classcell__r    r    r'   r)   r      s
   
 r   c                      0   e Zd ZU dZdZded< d fd	d
Z  ZS )UserMessagezA message from the user.userr   r   r   r   r   r   c                      t  jdd|i| d S Nr   r    r#   r$   r%   r'   r    r)   r$   '      zUserMessage.__init__r*   r+   r,   r-   r.   r   r/   r$   r0   r    r    r'   r)   r2   "      
 r2   c                      r1   )AssistantMessagezA message from the assistant.	assistantr   r   r   r   r   r   c                   r4   r5   r6   r%   r'   r    r)   r$   0   r7   zAssistantMessage.__init__r*   r8   r    r    r'   r)   r:   +   r9   r:   c                   @  sL   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< dS )PromptArgumentz+An argument that can be passed to a prompt.zName of the argumentdescriptionr"   nameNz%Description of what the argument does
str | Noner>   Fz Whether the argument is requireddefaultr>   boolrequired)	r+   r,   r-   r.   r
   r?   r/   r>   rD   r    r    r    r)   r<   :   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ddZ
ded< edddZded< eddddZded< e					d#d$ddZ		d%d&d!d"ZdS )'Promptz7A prompt template that can be rendered with parameters.zName of the promptr=   r"   r?   Nz"Human-readable title of the promptr@   titlez#Description of what the prompt doesr>   z*Arguments that can be passed to the promptzlist[PromptArgument] | None	argumentsT)exclude5Callable[..., PromptResult | Awaitable[PromptResult]]fnz&Optional list of icons for this promptrA   list[Icon] | Noneiconsz-Name of the kwarg that should receive context)r>   rH   context_kwargreturnc              	   C  s   |p|j }|dkrtd|du rt|}t||dur|gng d}|j }	g }
d|	v rM|	d  D ]\}}||	dg v }|
t	||d|d q3t
|}| |||pZ|jpZd	|
|||d
S )zCreate a Prompt from a function.

        The function can return:
        - A string (converted to a message)
        - A Message object
        - A dict (converted to a message)
        - A sequence of any of the above
        z<lambda>z,You must provide a name for lambda functionsN)
skip_names
propertiesrD   r>   )r?   r>   rD    )r?   rF   r>   rG   rJ   rL   rM   )r+   
ValueErrorr   r   	arg_modelmodel_json_schemaitemsgetappendr<   r   r.   )clsrJ   r?   rF   r>   rL   rM   	func_namefunc_arg_metadata
parametersrG   
param_nameparamrD   r    r    r)   from_functionM   s>   

	zPrompt.from_functiondict[str, Any] | Nonecontext:Context[ServerSessionT, LifespanContextT, RequestT] | Nonelist[Message]c              
     sp  | j rdd | j D }t|pi }|| }|rtd| zt| j|p&i || j}| jdi |}t|r=|I dH }t|t	t
B sG|g}g }|D ]R}	zBt|	trY||	 n5t|	trg|t|	 n't|	tr{td|	d}
|t|
d ntj|	tdd	 }
|td
|
d W qK ty   td|	 w |W S  ty } ztd| j d| d}~ww )z!Render the prompt with arguments.c                 S  s   h | ]}|j r|jqS r    )rD   r?   ).0argr    r    r)   	<setcomp>   s    z Prompt.render.<locals>.<setcomp>zMissing required arguments: Nr   r   )r      )fallbackindentr3   )r   r   z,Could not convert prompt result to message: zError rendering prompt z: r    )rG   setrR   r   rJ   rM   inspectiscoroutiner!   listtupler   rW   dictmessage_validatorvalidate_pythonr"   r   r2   pydantic_coreto_jsondecode	Exceptionr?   )r&   rG   r`   rD   providedmissing	call_argsresultmessagesmsgr   er    r    r)   render   sF   




zPrompt.render)NNNNN)rJ   rI   r?   r@   rF   r@   r>   r@   rL   rK   rM   r@   rN   rE   )NN)rG   r_   r`   ra   rN   rb   )r+   r,   r-   r.   r
   r?   r/   rF   r>   rG   rJ   rL   rM   classmethodr^   r|   r    r    r    r)   rE   B   s&   
 =rE   ),r.   
__future__r   rj   collections.abcr   r   r   typingr   r   r   rq   pydanticr	   r
   r   r   .mcp.server.fastmcp.utilities.context_injectionr   r   *mcp.server.fastmcp.utilities.func_metadatar   	mcp.typesr   r   r   mcp.server.fastmcp.serverr   mcp.server.sessionr   mcp.shared.contextr   r   r   r2   r:   ro   r"   rn   SyncPromptResultPromptResultr<   rE   r    r    r    r)   <module>   s,    		,