
    RX9i\                         S r SSKrSSKJr  SSKJrJr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ListOptionalTuple)snapshot_download)EntryNotFoundError   )DEFAULT_AGENTDEFAULT_REPO_IDFILENAME_CONFIGPROMPT_FILENAMES)AgentConfig)typesresultzmcp_types.CallToolResultreturnc                 2   U R                   n[        U5      S:X  a  g/ nU GHb  nUR                  S:X  a  UR                  UR                  5        M1  UR                  S:X  a7  UR                  SUR
                   S[        UR                  5       S35        Mx  UR                  S:X  a7  UR                  S	UR
                   S[        UR                  5       S35        M  UR                  S
:X  d  M  UR                  n[        US5      (       a  UR                  UR                  5        GM  [        US5      (       d  GM   UR                  SUR                   SUR
                   S[        UR                  5       S35        GMe     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urir   join)r   r   formatted_partsitemr   s        d/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/huggingface_hub/inference/_mcp/utils.pyformat_resultr'      sl    nnG
7|q!#O99""499-YY'!"")$--;KDII;V:W XN O
 YY'!"")$--;KDII;V:W XN O
 YY*$}}Hx((&&x}}56**&&'~S9J9J8K2N^_g_l_lNmMn oR S/ 8 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   H   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_dirZ   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   r   r   r   strr   
expanduseris_filer<   r=   r>   is_dirr   r   	Exceptionr	   )r3   rD   pathrepo_direrrs        r&   _load_agent_configrR   W   s    T eK#,F&G  d""
&&(D||~~zz$..'.:;TAA{{}}'",R0#
 .//  j\  "_  `
	s   "$C 
C&C!!C&)__doc__r<   pathlibr   typingr   r   r   r   huggingface_hubr   huggingface_hub.errorsr	   	constantsr   r   r   r   r   r   mcp	mcp_typesrJ   r'   intr   rR    r(   r&   <module>r]      s}      7 7 - 5 X X  &/&4 /& /&d0 0 0)8C= )U;QT;U5V )r(   