
    .h                        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Zd"dZd#dZd$dZd%dZd&dZd S )'    )annotations)Any)	NOT_GIVEN)	TypeGuard   )	UserErrorFobject)additionalPropertiestype
propertiesrequiredschemadict[str, Any]returnc                @    | i k    rt           S t          | 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   s    Q/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/agents/strict_schema.pyensure_strict_json_schemar      s(     ||%f2FCCCC    json_schemar   tuple[str, ...]r   dict[str, object]c               ,   t          |           st          d|  d           |                     d          }t          |          r3|                                D ]\  }}t	          |g d|R            |                     d          }t          |          r3|                                D ]\  }}t	          |g d|R            |                     d          }	|	dk    r
d| vrd	| d<   n!|	dk    rd| v r| d         rt          d
          |                     d          }
t          |
          rHt          |
                                          | d<   fd|
                                D             | d<   |                     d          }t          |          rt	          |g dR           | d<   |                     d          }t          |          rfdt          |          D             | d<   |                     d          }t          |          rzt          |          dk    rH|                     t	          |d         g ddR                      |                     d           nfdt          |          D             | d<   |                     dt                    |                     d           |                     d          }|rt          | d          rt          |t                     sJ d|             t#          |          }t          |          st%          d| d|           |                     i ||            |                     d           t	          |           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                J    i | ]\  }}|t          |g d |R            S )r   r   )r   ).0keyprop_schemar   r   s      r   
<dictcomp>z._ensure_strict_json_schema.<locals>.<dictcomp>G   sT     %
 %
 %
 [ +K>X>Xl>XTW>X>X_cddd%
 %
 %
r   itemsanyOfc           	     b    g | ]+\  }}t          |g d t          |          R           ,S )r&   r   r   str)r!   ivariantr   r   s      r   
<listcomp>z._ensure_strict_json_schema.<locals>.<listcomp>U   sV      
  
  
7 'w5Mt5MW5Mc!ff5M5MTXYYY 
  
  
r   allOfr   r   0c           	     b    g | ]+\  }}t          |g d t          |          R           ,S )r-   r   r(   )r!   r*   entryr   r   s      r   r,   z._ensure_strict_json_schema.<locals>.<listcomp>c   sV     $ $ $Au +57O7Ow7OA7O7OVZ[[[$ $ $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_ofr2   resolveds    ``             r   r   r      s    ; SQKQQ4QQRRR??7##Dt}} _$(JJLL 	_ 	_ Hj&z8R$8R8R8R8RY]^^^^^//-00K{ 2=2C2C2E2E 	 	.O.&!(O$(O(O(O(OVZ     //&
!
!C
h1DD.3*++x"k11./ 2 *
 
 	
 ..Jz 
"&z'8'8"9"9J%
 %
 %
 %
 %
$.$4$4$6$6%
 %
 %
L! OOG$$Eu~~ c9%FVFVgFVFV]abbbG __W%%Fv 
 
  
  
  
  
'// 
  
  
G __W%%Fv 
v;;!*6!9;PT;P7;PC;P;PW[\\\   OOG$$$$$ $ $ $ $ )& 1 1$ $ $K  y),,4	""" //&
!
!C
 M#K33 M#s##HH%H3%H%HHHHDc222x   	X3XXhXX  
 	6h6+6777 *+DtLLLLr   r2   r)   c                    |                     d          st          d|d          |dd                              d          }| }|D ]+}||         }t          |          sJ d| d|             |},|S )Nz#/zUnexpected $ref format z; Does not start with #/   /z1encountered non-dictionary entry while resolving z - )
startswithr@   splitr3   )r   r2   r   rI   r"   values         r   r?   r?      s    >>$ TR3RRRSSSqrr7==DH  u~~ 	
 	
RRRRR	
 	
 	
 Or   objTypeGuard[dict[str, object]]c                ,    t          | t                    S N)r>   dictrP   s    r   r3   r3      s     c4   r   TypeGuard[list[object]]c                ,    t          | t                    S rS   )r>   r6   rU   s    r   r8   r8      s    c4   r   nintboolc                T    d}|                                  D ]}|dz  }||k    r dS dS )Nr   r   TF)r7   )rP   rX   r*   _s       r   r=   r=      sA    	AXXZZ  	Qq5544 5r   N)r   r   r   r   )r   r	   r   r   r   r   r   r   )r   r   r2   r)   r   r	   )rP   r	   r   rQ   )rP   r	   r   rV   )rP   r   rX   rY   r   rZ   )
__future__r   typingr   openair   typing_extensionsr   
exceptionsr   r   r   r   r?   r3   r8   r=   r   r   r   <module>rb      s   " " " " " "             ' ' ' ' ' ' ! ! ! ! ! ! "	 D D D Df f f fR    ! ! ! !! ! ! !     r   