
    {h                     @   d Z ddl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mZmZmZ ddlmZmZ  G d de      Z G d	 d
e      Z G d de      Z eeez     eez        Zeez  eeef   z  eeez  eeef   z     z  Zeee   z  Z G d de      Z G d de      Zy)z!Base classes for FastMCP prompts.    N)	AwaitableCallableSequence)AnyLiteral)	BaseModelFieldTypeAdaptervalidate_call)ContentBlockTextContentc                   N     e Zd ZU dZed   ed<   eed<   deez  def fdZ	 xZ
S )Messagez#Base class for all prompt messages.user	assistantrolecontentkwargsc                 b    t        |t              rt        d|      }t        |   dd|i| y )Ntexttyper   r    )
isinstancestrr   super__init__selfr   r   	__class__s      `/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/mcp/server/fastmcp/prompts/base.pyr   zMessage.__init__   s.    gs#!vG<G33F3    )__name__
__module____qualname____doc__r   __annotations__r   r   r   r   __classcell__r!   s   @r"   r   r      s5    -
%
&&4l 2 4c 4 4r#   r   c                   H     e Zd ZU dZdZed   ed<   deez  de	f fdZ
 xZS )UserMessagezA message from the user.r   r   r   r   r   c                 (    t        |   dd|i| y Nr   r   r   r   r   s      r"   r   zUserMessage.__init__       33F3r#   r$   r%   r&   r'   r   r   r(   r   r   r   r   r)   r*   s   @r"   r,   r,      s3    ")/D'%
&/4l 2 4c 4 4r#   r,   c                   H     e Zd ZU dZdZed   ed<   deez  de	f fdZ
 xZS )AssistantMessagezA message from the assistant.r   r   r   r   r   c                 (    t        |   dd|i| y r.   r/   r   s      r"   r   zAssistantMessage.__init__'   r0   r#   r1   r*   s   @r"   r3   r3   "   s3    ')4D'%
&44l 2 4c 4 4r#   r3   c                   p    e Zd ZU dZ ed      Zeed<    edd      Zedz  ed<    edd	
      Z	e
ed<   y)PromptArgumentz+An argument that can be passed to a prompt.zName of the argumentdescriptionnameNz%Description of what the argument doesr8   Fz Whether the argument is required)defaultr8   required)r$   r%   r&   r'   r	   r9   r   r(   r8   r;   boolr   r#   r"   r6   r6   1   s=    5"89D#9#D6]^Kt^56XYHdYr#   r6   c                   P   e Zd ZU dZ ed      Zeed<    edd      Zedz  ed<    edd      Z	edz  ed	<    edd
      Z
ee   dz  ed<    ed      Zedeee   z  f   ed<   e	 	 	 ddedeee   z  f   dedz  dedz  d	edz  dd f
d       Zddeeef   dz  dee   fdZy)Promptz7A prompt template that can be rendered with parameters.zName of the promptr7   r9   Nz"Human-readable title of the prompttitlez#Description of what the prompt doesr8   z*Arguments that can be passed to the prompt	argumentsT)exclude.fnreturnc           	         |xs |j                   }|dk(  rt        d      t        |      j                         }g }d|v r[|d   j	                         D ]E  \  }}	||j                  dg       v }
|j                  t        ||	j                  d      |
             G t        |      } | |||xs |j                  xs 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 functions
propertiesr;   r8   )r9   r8   r;    )r9   r?   r8   r@   rB   )
r$   
ValueErrorr
   json_schemaitemsgetappendr6   r   r'   )clsrB   r9   r?   r8   	func_name
parametersr@   
param_nameparamr;   s              r"   from_functionzPrompt.from_functionB   s      'BKK	
"KLL !_002
 +-	:%%/%=%C%C%E !
E%
B)GG  "'$)IIm$<!) 2#7rzz7R
 	
r#   c                   K   | j                   rT| j                   D ch c]  }|j                  s|j                   }}t        |xs i       }||z
  }|rt	        d|       	  | j
                  di |xs i }t        j                  |      r
| d{   }t        |t        t        z        s|g}g }|D ]  }	 t        |t              r|j                  |       nt        |t              r%|j                  t        j                  |             nt        |t               r)t#        d|      }	|j                  t%        |	             nFt'        j(                  |t         d      j+                         }	|j                  t        d|		              |S c c}w 7 # t,        $ r t	        d
|       w xY w# t,        $ r }
t	        d| j                   d|
       d}
~
ww xY ww)z!Render the prompt with arguments.zMissing required arguments: Nr   r   )r      )fallbackindentr   )r   r   z,Could not convert prompt result to message: zError rendering prompt z: r   )r@   r;   r9   setrG   rB   inspectiscoroutiner   listtupler   rK   dictmessage_validatorvalidate_pythonr   r   r,   pydantic_coreto_jsondecode	Exception)r    r@   argr;   providedmissingresultmessagesmsgr   es              r"   renderzPrompt.renderr   s     >>,0NNKScllKHK9?+H)G #?y!IJJ	ITWW1	R1F""6*% fdUl3  ')H [[!#w/ ,#C. (9(I(I#(NO#C-"-6"D G(DE"/"7"7cRS"T"["["] VW(MN[ OC L &( ! [$'STWSX%YZZ[  	I6tyykA3GHH	Isc   G$FF&G$$0F8 F%F8 ;CFF8 G$F8 F55F8 8	G!GG!!G$)NNN)N)r$   r%   r&   r'   r	   r9   r   r(   r?   r8   r@   rY   r6   rB   r   PromptResultr   classmethodrQ   r[   r   r   ri   r   r#   r"   r>   r>   9   s   A"67D#7d0TUE3:U#D6[\Kt\-24Eq-rItN#d*r@Ed@SBlY|%<<<=S   "&-
S,<)@@@A-
 Dj-
 Tz	-

 4Z-
 
-
 -
^'Id38nt&; 'ItG} 'Ir#   r>   )r'   rW   collections.abcr   r   r   typingr   r   r^   pydanticr   r	   r
   r   	mcp.typesr   r   r   r,   r3   r\   r   r[   SyncPromptResultrj   r6   r>   r   r#   r"   <module>rq      s    '  9 9   A A /	4i 	44' 44w 4 @K.> >?N^@^_ =4S>1HS7]TRUWZRZ^=[4\\ ),<"==ZY Z`IY `Ir#   