
    i
                    >    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                   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	           |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     8/home/ubuntu/.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*   N)
r"   r#   r	   _GEMINI_SCHEMA_ALLOWED_KEYSr/   r$   listgetanypop)	r   cleanedkeyvalueprops	prop_nameprop_schemaenum_valtype_vals	            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%%%Nr*   
parametersc                2    t          |           }|sdi dS |S )z:Normalize tool parameters to a valid Gemini object schema.object)r   r   )r$   )r>   r6   s     r(   sanitize_gemini_tool_parametersrA   ]   s,     %Z00G 4 333Nr*   N)r   r   r   r   )r>   r   r   r   )	__doc__
__future__r   typingr   r   r1   r$   rA   r!   r*   r(   <module>rE      sz    R R " " " " " "        
   46 6 6 6r     r*   