§
    ­eîiS  ã                  óÚ   — d Z ddlmZ ddlZddl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mZ ddlmZmZ dd	lmZ dd
l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e¦  «        Z dS )z Resource template functionality.é    )ÚannotationsN)ÚCallable)ÚTYPE_CHECKINGÚAny)Ú	BaseModelÚFieldÚvalidate_call)ÚFunctionResourceÚResource)Úfind_context_parameterÚinject_context)Úfunc_metadata)ÚAnnotationsÚIcon)ÚContext)ÚServerSessionT)ÚLifespanContextTÚRequestTc                  óÔ  — e Zd ZU dZ ed¬¦  «        Zded<    ed¬¦  «        Zded<    edd	¬
¦  «        Zded<    ed¬¦  «        Z	ded<    edd¬¦  «        Z
ded<    ed	d¬¦  «        Zded<    ed	d¬¦  «        Zded<    ed	d¬¦  «        Zded<    ed¬¦  «        Zded<    ed ¬¦  «        Zd!ed"<    ed	d#¬¦  «        Zded$<   e	 	 	 	 	 	 	 	 d.d/d&„¦   «         Zd0d(„Z	 d1d2d-„Zd	S )3ÚResourceTemplatez.A template for dynamically creating resources.z<URI template with parameters (e.g. weather://{city}/current))ÚdescriptionÚstrÚuri_templatezName of the resourceÚnamez$Human-readable title of the resourceN)r   Údefaultú
str | NoneÚtitlez%Description of what the resource doesr   ú
text/plainz!MIME type of the resource content)r   r   Ú	mime_typez0Optional list of icons for the resource templateúlist[Icon] | NoneÚiconsz.Optional annotations for the resource templateúAnnotations | Noner   z,Optional metadata for this resource templateúdict[str, Any] | NoneÚmetaT)ÚexcludeúCallable[..., Any]Úfnz#JSON schema for function parametersúdict[str, Any]Ú
parametersz-Name of the kwarg that should receive contextÚcontext_kwargÚreturnc                ó  — |p|j         }|dk    rt          d¦  «        ‚|
€t          |¦  «        }
t          ||
�|
gng ¬¦  «        }|j                             ¦   «         }t          |¦  «        } | ||||p|j        pd|pd|||	|||
¬¦  «        S )z"Create a template from a function.z<lambda>z,You must provide a name for lambda functionsN)Ú
skip_namesÚ r   )r   r   r   r   r   r!   r   r$   r'   r)   r*   )Ú__name__Ú
ValueErrorr   r   Ú	arg_modelÚmodel_json_schemar	   Ú__doc__)Úclsr'   r   r   r   r   r   r!   r   r$   r*   Ú	func_nameÚfunc_arg_metadatar)   s                 új/home/div/.hermes/hermes-agent/venv/lib/python3.11/site-packages/mcp/server/fastmcp/resources/templates.pyÚfrom_functionzResourceTemplate.from_function&   s×   € ð Ð'˜BœKˆ	Ø˜
Ò"Ð"ÝÐKÑLÔLÐLð Ð Ý2°2Ñ6Ô6ˆMõ *ØØ*7Ð*C˜��Èð
ñ 
ô 
Ðð 'Ô0×BÒBÑDÔDˆ
õ ˜2ÑÔˆàˆsØ%ØØØ#Ð7 r¤zÐ7°RØÐ/ <ØØ#ØØØ!Ø'ð
ñ 
ô 
ð 	
ó    Úuric                óÂ   — | j                              dd¦  «                             dd¦  «        }t          j        d|› d�|¦  «        }|r|                     ¦   «         S dS )z5Check if URI matches template and extract parameters.Ú{z(?P<Ú}z>[^/]+)ú^ú$N)r   ÚreplaceÚreÚmatchÚ	groupdict)Úselfr:   ÚpatternrB   s       r7   ÚmatcheszResourceTemplate.matchesU   sb   € ð Ô#×+Ò+¨C°Ñ8Ô8×@Ò@ÀÀiÑPÔPˆÝ”˜˜W˜˜˜¨Ñ-Ô-ˆØð 	%Ø—?’?Ñ$Ô$Ð$Øˆtr9   ÚparamsÚcontextú:Context[ServerSessionT, LifespanContextT, RequestT] | Noner   c              ƒ  óX  ‡K  — 	 t          | j        ||| j        ¦  «        } | j        di |¤ŽŠt          j        ‰¦  «        r‰ƒ d{V —†Št          || j        | j        | j        | j	        | j
        | j        | j        ˆfd„¬¦	  «	        S # t          $ r}t          d|› �¦  «        ‚d}~ww xY w)z>Create a resource from the template with the given parameters.Nc                 ó   •— ‰ S ©N© )Úresults   €r7   ú<lambda>z2ResourceTemplate.create_resource.<locals>.<lambda>w   s   ø€ ˜6€ r9   )	r:   r   r   r   r   r!   r   r$   r'   z'Error creating resource from template: rM   )r   r'   r*   ÚinspectÚiscoroutiner
   r   r   r   r   r!   r   r$   Ú	Exceptionr0   )rD   r:   rG   rH   ÚerN   s        @r7   Úcreate_resourcez ResourceTemplate.create_resource^   sæ   øè è € ð	Lå# D¤G¨V°W¸dÔ>PÑQÔQˆFð �T”WÐ&Ð&˜vÐ&Ð&ˆFÝÔ" 6Ñ*Ô*ð &Ø%˜˜˜˜˜˜�å#ØØ”YØ”jØ Ô,Øœ.Ø”jØ Ô,Ø”YØ!�>�>�>ð
ñ 
ô 
ð 
øõ ð 	Lð 	Lð 	LÝÐJÀqÐJÐJÑKÔKÐKøøøøð	Løøøs   …BB Â
B)ÂB$Â$B))NNNNNNNN)r'   r&   r   r   r   r   r   r   r   r   r   r   r!   r    r   r"   r$   r#   r*   r   r+   r   )r:   r   r+   r#   rL   )r:   r   rG   r(   rH   rI   r+   r   )r/   Ú
__module__Ú__qualname__r3   r   r   Ú__annotations__r   r   r   r   r!   r   r$   r'   r)   r*   Úclassmethodr8   rF   rT   rM   r9   r7   r   r      sö  € € € € € € Ø8Ð8à˜Ð*hÐiÑiÔi€LÐiÐiÐiÑiØ�Ð"8Ð9Ñ9Ô9€DÐ9Ð9Ð9Ñ9Ø˜Ð*PÐZ^Ð_Ñ_Ô_€EÐ_Ð_Ð_Ñ_Ø#˜eÐ0WÐXÑXÔX€KÐXÐXÐXÑXØ�U <Ð=`ÐaÑaÔa€IÐaÐaÐaÑaØ$˜u¨TÐ?qÐrÑrÔr€EÐrÐrÐrÑrØ&+ e°DÐFvÐ&wÑ&wÔ&w€KÐwÐwÐwÑwØ"' %°ÐBpÐ"qÑ"qÔ"q€DÐqÐqÐqÑqØ"˜U¨4Ð0Ñ0Ô0€BÐ0Ð0Ð0Ñ0Ø!& Ð3XÐ!YÑ!YÔ!Y€JÐYÐYÐYÑYØ %  dÐ8gÐ hÑ hÔ h€MÐhÐhÐhÑhàð
  Ø Ø"&Ø $Ø#'Ø*.Ø&*Ø$(ð,
ð ,
ð ,
ð ,
ñ „[ð,
ð\ð ð ð ð OSð	Lð Lð Lð Lð Lð Lð Lr9   r   )!r3   Ú
__future__r   rP   rA   Úcollections.abcr   Útypingr   r   Úpydanticr   r   r	   Ú"mcp.server.fastmcp.resources.typesr
   r   Ú.mcp.server.fastmcp.utilities.context_injectionr   r   Ú*mcp.server.fastmcp.utilities.func_metadatar   Ú	mcp.typesr   r   Úmcp.server.fastmcp.serverr   Úmcp.server.sessionr   Úmcp.shared.contextr   r   r   rM   r9   r7   ú<module>rd      s]  ðØ &Ð &à "Ð "Ð "Ð "Ð "Ð "à €€€Ø 	€	€	€	Ø $Ð $Ð $Ð $Ð $Ð $Ø %Ð %Ð %Ð %Ð %Ð %Ð %Ð %à 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4à IÐ IÐ IÐ IÐ IÐ IÐ IÐ IØ aÐ aÐ aÐ aÐ aÐ aÐ aÐ aØ DÐ DÐ DÐ DÐ DÐ DØ 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'àð >Ø1Ð1Ð1Ð1Ð1Ð1Ø1Ð1Ð1Ð1Ð1Ð1Ø=Ð=Ð=Ð=Ð=Ð=Ð=Ð=ðcLð cLð cLð cLð cL�yñ cLô cLð cLð cLð cLr9   