o
    h                     @  s   d dl mZ d dlmZ d dlmZ d dlmZ ddlm	Z	 ddi g d	Z
d'ddZd(ddZd)ddZd*ddZd+dd Zd,d$d%Zd&S )-    )annotations)Any)	NOT_GIVEN)	TypeGuard   )	UserErrorFobject)additionalPropertiestype
propertiesrequiredschemadict[str, Any]returnc                 C  s   | i krt S t| d| dS )zrMutates the given JSON schema to ensure it conforms to the `strict` standard
    that the OpenAI API expects.
     pathroot)_EMPTY_SCHEMA_ensure_strict_json_schema)r   r   r   U/var/www/html/openai_agents/venv/lib/python3.10/site-packages/agents/strict_schema.pyensure_strict_json_schema   s   r   json_schemar   tuple[str, ...]r   dict[str, object]c                  s  t | std|  d  | d}t |r.| D ]\}}t|g  d|R d q| d}t |rN| D ]\}}t|g  d|R d q;| d}	|	dkr`d| vr`d	| d< n|	dkrpd| v rp| d rptd
| d}
t |
rt|
 | d<  fdd|
 D | d< | d}t |rt|g  dR d| d< | d}t|r fddt	|D | d< | d}t|rt
|dkr| t|d g  ddR d | d n fddt	|D | d< | dtd u r| d | d}|rFt| drFt|tsJ d| t|d}t |s1td| d| | i ||  | d t|  dS | S )Nz	Expected z to be a dictionary; path=z$defsr   definitionsr
   r   r	   Fa  additionalProperties should not be set for object types. This could be because you're using an older version of Pydantic, or because you configured additional properties to be allowed. If you really need this, update the function or output tool to not use a strict schema.r   r   c                   s.   i | ]\}}|t |g  d |R dqS )r   r   )r   ).0keyprop_schemar   r   r   
<dictcomp>G   s    z._ensure_strict_json_schema.<locals>.<dictcomp>itemsanyOfc                   0   g | ]\}}t |g  d t|R dqS )r!   r   r   str)r   ivariantr   r   r   
<listcomp>U       z._ensure_strict_json_schema.<locals>.<listcomp>allOfr   r   0c                   r"   )r)   r   r#   )r   r%   entryr   r   r   r'   c   r(   defaultz$refzReceived non-string $ref - )r   refzExpected `$ref: z&` to resolved to a dictionary but got )is_dict	TypeErrorgetr    r   r   listkeysis_list	enumeratelenupdatepopr   has_more_than_n_keys
isinstancer$   resolve_ref
ValueError)r   r   r   defsdef_name
def_schemar   definition_namedefinition_schematypr   r    any_ofall_ofr-   resolvedr   r   r   r      sx   




	









r   r-   r$   c                 C  sf   | dstd|d|dd  d}| }|D ]}|| }t|s.J d| d| |}q|S )Nz#/zUnexpected $ref format z; Does not start with #/   /z1encountered non-dictionary entry while resolving z - )
startswithr;   splitr.   )r   r-   r   rD   r   valuer   r   r   r:      s   

r:   objTypeGuard[dict[str, object]]c                 C  
   t | tS N)r9   dictrJ   r   r   r   r.      s   
r.   TypeGuard[list[object]]c                 C  rL   rM   )r9   r1   rO   r   r   r   r3      s   
r3   nintboolc                 C  s,   d}|   D ]}|d7 }||kr dS qdS )Nr   r   TF)r2   )rJ   rQ   r%   _r   r   r   r8      s   r8   N)r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r-   r$   r   r   )rJ   r   r   rK   )rJ   r   r   rP   )rJ   r   rQ   rR   r   rS   )
__future__r   typingr   openair   typing_extensionsr   
exceptionsr   r   r   r   r:   r.   r3   r8   r   r   r   r   <module>   s     


i

