
    Y j                         S r SSKrSSKJr  SSKJrJr  SSKJr  SSK	J
r
  SSKJrJrJrJr  SS	KJr  \(       a  SS
KJr  SSS\4S jrS\S\4S jrS\\   S\\\\   4   4S jrg)z
Utility functions for MCPClient and Tiny Agents.

Formatting utilities taken from the JS SDK: https://github.com/huggingface/huggingface.js/blob/main/packages/mcp-client/src/ResultFormatter.ts.
    N)Path)TYPE_CHECKINGOptional)snapshot_download)EntryNotFoundError   )DEFAULT_AGENTDEFAULT_REPO_IDFILENAME_CONFIGPROMPT_FILENAMES)AgentConfig)typesresultzmcp_types.CallToolResultreturnc                 ~   U R                   n[        U5      S:X  a  g/ nU GH  nUR                  =S:X  a    UR                  UR                  5        M3  =S:X  a8    UR                  SUR
                   S[        UR                  5       S35        Mq  =S:X  a8    UR                  S	UR
                   S[        UR                  5       S35        M  S
:X  d  M  UR                  n[        US5      (       a=  [        UR                  [        5      (       a  UR                  UR                  5        GM  [        US5      (       ag  [        UR                  [        5      (       aE  UR                  SUR                   SUR
                   S[        UR                  5       S35        GM  GM  GM     SR                  U5      $ )z
Formats a mcp.types.CallToolResult content into a human-readable string.

Args:
    result (CallToolResult)
        Object returned by mcp.ClientSession.call_tool.

Returns:
    str
        A formatted string representing the content of the result.
r   z[No content]textimagez[Binary Content: Image z, zC bytes]
The task is complete and the content accessible to the Useraudioz[Binary Content: Audio resourceblobz[Binary Content (z): 
)contentlentypeappendr   mimeType_get_base64_sizedatar   hasattr
isinstancestrr   urijoin)r   r   formatted_partsitemr   s        u/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/huggingface_hub/inference/_mcp/utils.pyformat_resultr'      s~    nnG
7|q!#Oii&&tyy1&&-dmm_B?OPTPYPY?Z>[ \R S
 &&-dmm_B?OPTPYPY?Z>[ \R S
 ==8V,,HMM31O1O#**8==9Xv..:hmmS3Q3Q#**+HLL>X=N=N<O P,X]];< =VW 4R./ < 99_%%    
base64_strc                     SU ;   a  U R                  S5      S   n SnU R                  S5      (       a  SnOU R                  S5      (       a  Sn[        U 5      S-  S-  U-
  $ )	z2Estimate the byte size of a base64-encoded string.,r   r   z==   =      )splitendswithr   )r)   paddings     r&   r   r   J   sk     j%%c*1-
G4  			S	!	!
OaA%//r(   
agent_pathc                    S[         S[        [        [        [           4   4S jnU c  [
        S4$ [        U 5      R                  5       nUR                  5       (       a%  [        R                  " UR                  SS95      S4$ UR                  5       (       a  U" U5      $  [        [        [        U  S3SS	95      nU" X0-  5      $ ! [         a  n[        S
U  S35      UeSnAff = f)zLoad server config and prompt.	directoryr   c                    U [         -  nUR                  5       (       d  [        SU  S35      e[        R                  " UR                  SS95      nS n[         H/  nX-  nUR                  5       (       d  M  UR                  SS9n  X#4$    X#4$ )Nz Config file not found in z$! Please make sure it exists locallyutf-8encoding)r   existsFileNotFoundErrorjsonloads	read_textr   )r5   cfg_fileconfigpromptfilenameprompt_files         r&   	_read_dir%_load_agent_config.<locals>._read_dir\   s    .  #&@Ko$pqq"jj););W);)MN $(H#.K!!##$...@~ )
 ~r(   Nr7   r8   z/*dataset)repo_idallow_patterns	repo_typez Agent z} not found in tiny-agents/tiny-agents! Please make sure it exists in https://huggingface.co/datasets/tiny-agents/tiny-agents.)r   tupler   r   r!   r	   
expanduseris_filer<   r=   r>   is_dirr   r
   	Exceptionr   )r3   rD   pathrepo_direrrs        r&   _load_agent_configrR   Y   s    T eK#,F&G  d""
&&(D||~~zz$..'.:;TAA{{}}'",R0#
 .//  j\  "_  `
	s   "$C 
C&C!!C&)__doc__r<   pathlibr   typingr   r   huggingface_hubr   huggingface_hub.errorsr   	constantsr	   r
   r   r   r   r   mcp	mcp_typesr!   r'   intr   rJ   rR    r(   r&   <module>r]      sz      * - 5 X X  &1&4 1& 1&h0 0 0)8C= )U;QT;U5V )r(   