
    Áj                        d dl mZ d dlZd dlmZmZmZmZ d dlm	Z	 d dl
Z
ddlmZ ed   Zh dZ	 	 	 	 dd	Z	 	 	 	 dd
Zy)    )annotationsN)AnyLiteralOptionalcast)assert_never   )is_list)objectarraystringintegernumberbooleannull>
   	date-timeuridateipv4ipv6timeuuidemaildurationhostnamec                @    | j                  d      dk(  r	d| vrd| d<   | S )aU  Transforms a JSON schema of type string to ensure it conforms to the API's expectations.

    Specifically, it ensures that if the schema is of type "string" and does not already
    specify a "format", it sets the format to "text".

    Args:
        schema: The original JSON schema.

    Returns:
        The transformed JSON schema.
    typer   formattext)get)schemas    F/tmp/pip-target-k_scjv0h/lib/python/anthropic/lib/_parse/_transform.pyget_transformed_stringr#   #   s+     zz&X%(&*@!xM    c           	        t        j                  |       r*t        | t        j                        r| j                         } i }i | } | j                  dd      }|-i }||d<   |j                         D ]  \  }}t        |      ||<    | j                  dd      }|||d<   |S | j                  dd      }| j                  dd      }| j                  dd      }	| j                  dd      }
t        |      r'|D cg c]  }t        t        d|             c}|d<   nvt        |	      r'|	D cg c]  }t        t        d|             c}|d<   nDt        |
      r'|
D cg c]  }t        t        d|             c}|d<   n|t        d	      ||d<   | j                  d
d      }t        |      r||d
<   | j                  dd      }|||d<   | j                  dd      }|||d<   |dk(  rq| j                  di       j                         D ci c]  \  }}|t        |       c}}|d<   | j                  dd       d|d<   | j                  dd      }|||d<   n|dk(  r*| j                  dd      }|r|t        v r||d<   n}|r{|| d<   nu|dk(  rN| j                  dd      }|t        |      |d<   | j                  dd      }||dk(  s|dk(  r||d<   n*|(|| d<   n"|dk(  s|dk(  s|dk(  s|dk(  s|nt        |       | rJ|j                  d      }||dz   nddz   d j                  d! | j                         D              z   d"z   |d<   |S c c}w c c}w c c}w c c}}w )#a  
    Transforms a JSON schema to ensure it conforms to the API's expectations.

    Args:
        json_schema (Dict[str, Any]): The original JSON schema.

    Returns:
        The transformed JSON schema.

    Examples:
        >>> transform_schema(
        ...     {
        ...         "type": "integer",
        ...         "minimum": 1,
        ...         "maximum": 10,
        ...         "description": "A number",
        ...     }
        ... )
        {'type': 'integer', 'description': 'A number

{minimum: 1, maximum: 10}'}
    z$defsNz$refr   anyOfoneOfallOfdict[str, Any]z>Schema must have a 'type', 'anyOf', 'oneOf', or 'allOf' field.enumdescriptiontitler   
propertiesadditionalPropertiesFrequiredr   r   r   itemsminItemsr      r   r   r   r   z

 {z, c              3  0   K   | ]  \  }}| d |   yw)z: N ).0keyvalues      r"   	<genexpr>z#transform_schema.<locals>.<genexpr>   s     Pjc53%r%)Ps   })inspectisclass
issubclasspydantic	BaseModelmodel_json_schemapopr0   transform_schemar
   r   
ValueErrorSupportedStringFormatsr   r    join)json_schemastrict_schemadefsstrict_defsnamer!   reftype_any_ofone_ofall_ofvariantr*   r+   r,   r8   prop_schemar/   r   r0   	min_itemss                        r"   rC   rC   6   s   . {#
;@R@R(S!335$&M![/K
 ??7D)D&(!,g JJL 	9LD& 0 8K	9 //&$
'C
 #f&1oofd&CE__Wd+F__Wd+F__Wd+Fvci!jX_"248H'3R"S!jg	ci!jX_"248H'3R"S!jg	ci!jX_"248H'3R"S!jg=]^^ %f??64(Dt} $f//-6K'2m$OOGT*E!&gGRWcegGhGnGnGp'
3C3C!+..'
l# 	.505,-??:t4(0M*%	(	40f 66&,M(#$*K!	'	.%5e%<M'"OOJ5	 Y!^yA~(1M*%"&/K
#	)	u	1Uh5F%SY/]b]jU #''6%0%<[6!"iiPK<M<M<OPPQ  	m$ K "k!j!j('
s   9M+MMM)r!   r)   returnr)   )rG   z)type[pydantic.BaseModel] | dict[str, Any]rT   r)   )
__future__r   r<   typingr   r   r   r   typing_extensionsr   r?   _utilsr
   SupportedTypesrE   r#   rC   r6   r$   r"   <module>rZ      s^    "  / / *   &x:xxr$   