
    Pmj                    F    d Z ddlmZ ddl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.    )annotationsN)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                    r|dv rg }	|D ]}
t          |
t                    r|
}nrt          |
t                    r|
rdnd	}nVt          |
t          t          f          r9t          |
t                    s$t          j        |
          rt	          |
          }n||	vr|	                    |           |	r|	|d<   n|                    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     9/home/thesage/.hermes/hermes-agent/agent/gemini_schema.py
<listcomp>z*sanitize_gemini_schema.<locals>.<listcomp>F   s@       dD))&t,,      r   r   >   numberbooleanintegertruefalseNr   c                F    g | ]}t          |t                    r|v |S r!   )r"   str)r%   name
prop_namess     r'   r(   z*sanitize_gemini_schema.<locals>.<listcomp>z   s@     
 
 
$$$
)-);); );););r)   )r"   r#   r	   _GEMINI_SCHEMA_ALLOWED_KEYSr0   r$   listgetboolintfloatmathisfiniteappendpopsetkeyslen)r   cleanedkeyvalueprops	prop_nameprop_schemaenum_valtype_valstringifiedr&   required_val	props_valvalid_requiredr2   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 	* 	*D$$$ D$'' 	"&3G4#u.."4.. M$''
 D		K''""5))) 	&)GFOO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$   )rL   r@   s     r'   sanitize_gemini_tool_parametersrO      s,     %Z00G 4 333Nr)   )r   r   r   r   )rL   r   r   r   )
__doc__
__future__r   r9   typingr   r   r3   r$   rO   r!   r)   r'   <module>rS      s    R R " " " " " "         
   4^ ^ ^ ^B     r)   