
    [j&                    >    d Z ddlmZ ddlmZmZ h dZdd	ZddZdS )zLHelpers for translating OpenAI-style tool schemas to Gemini's schema subset.    )annotations)AnyDict>   enumtypeanyOfitemstitleformatdefaultexamplemaximumminimumpatternmaxItemsminItemsnullablerequired	maxLength	minLength
propertiesdescriptionmaxPropertiesminPropertiespropertyOrderingschemar   returnDict[str, Any]c                d   t          | t                    si S i }|                                 D ]\  }}|t          vr|dk    r`t          |t                    s+i }|                                D ]-\  }}t          |t                    st          |          ||<   .|||<   u|dk    rt          |          ||<   |dk    r&t          |t                    sd |D             ||<   |||<   |                    d          }|                    d          }t          |t                    r3|dv r/t          d |D                       r|	                    dd	           |                    d
          }	t          |	t                    r|                    d          }
t          |
t                    r!t          |
                                          nt                      fd|	D             }|s|	                    d
d	           n%t          |          t          |	          k    r||d
<   |S )a  Return a Gemini-compatible copy of a tool parameter schema.

    Hermes tool schemas are OpenAI-flavored JSON Schema and may contain keys
    such as ``$schema`` or ``additionalProperties`` that Google's Gemini
    ``Schema`` object rejects.  This helper preserves the documented Gemini
    subset and recursively sanitizes nested ``properties`` / ``items`` /
    ``anyOf`` definitions.
    r   r	   r   c                V    g | ]&}t          |t                    t          |          'S  )
isinstancedictsanitize_gemini_schema.0items     5/home/ice/.hermes/hermes-agent/agent/gemini_schema.py
<listcomp>z*sanitize_gemini_schema.<locals>.<listcomp>E   s@       dD))&t,,      r   r   >   numberbooleanintegerc              3  B   K   | ]}t          |t                     V  d S )Nr"   strr%   s     r(   	<genexpr>z)sanitize_gemini_schema.<locals>.<genexpr>W   s/      >>T:dC(((>>>>>>r*   Nr   c                F    g | ]}t          |t                    r|v |S r!   r/   )r&   name
prop_namess     r(   r)   z*sanitize_gemini_schema.<locals>.<listcomp>i   s@     
 
 
$$$
)-);); );););r*   )r"   r#   r	   _GEMINI_SCHEMA_ALLOWED_KEYSr0   r$   listgetanypopsetkeyslen)r   cleanedkeyvalueprops	prop_nameprop_schemaenum_valtype_valrequired_val	props_valvalid_requiredr4   s               @r(   r$   r$   $   s}    fd## 	 Gllnn  
U111,eT** $&E*/++-- G G&	;!)S11 #9+#F#Fi   GCL'>>1%88GCL'>>eT**  !  GCL
  {{6""H{{6""H(D!! &h2R&R&R>>X>>>>> 	&KK%%% ;;z**L,%% 
1KK--	.8D.I.ITS))***suu

 
 
 
)
 
 
  	1KK
D))))  C$5$555"0GJNr*   
parametersc                2    t          |           }|sdi dS |S )z:Normalize tool parameters to a valid Gemini object schema.object)r   r   )r$   )rH   r=   s     r(   sanitize_gemini_tool_parametersrK   u   s,     %Z00G 4 333Nr*   N)r   r   r   r   )rH   r   r   r   )	__doc__
__future__r   typingr   r   r5   r$   rK   r!   r*   r(   <module>rO      s~    R R " " " " " "        
   4N N N Nb     r*   