
    "<i<                     T   d Z ddlZddlZddlmZ ddlmZmZmZ  ej	        e
          Z	 ddeded	ed
eez  fdZdeded
eeef         fdZdedz  d
efdZddeded
efdZ	 	 ddedee         dz  dedz  d
efdZ	 	 ddedeeef         dee         dz  dedz  d
ef
dZg dZdS )z6Parameter formatting functions for OpenAPI operations.    N)Any   )
JsonSchemaParameterInfoRequestBodyInfoFvaluesparameter_nameis_query_parameterreturnc           	      ,   t          d | D                       rd                    d | D                       S 	 g }| D ]}t          |t                    r_g }|                                D ]\  }}|                    | d|             |                    d                    |                     v|                    t          |                     d                    |          S # t          $ r}|rdnd}	t          	                    d|	 d	| d
|            |r| cY d}~S t          |           
                    dd          
                    dd          
                    dd          
                    dd          }
|
cY d}~S d}~ww xY w)aj  
    Format an array parameter according to OpenAPI specifications.

    Args:
        values: List of values to format
        parameter_name: Name of the parameter (for error messages)
        is_query_parameter: If True, can return list for explode=True behavior

    Returns:
        String (comma-separated) or list (for query params with explode=True)
    c              3   p   K   | ]1}t          |t          t          z  t          z  t          z            V  2d S N)
isinstancestrintfloatbool).0items     /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/fastmcp/utilities/openapi/formatters.py	<genexpr>z)format_array_parameter.<locals>.<genexpr>   s:      
I
I$:dC#I-455
I
I
I
I
I
I    ,c              3   4   K   | ]}t          |          V  d S r   )r   )r   vs     r   r   z)format_array_parameter.<locals>.<genexpr>   s(      //1A//////r   :.querypathzFailed to format complex array z parameter 'z': N[ ]'")alljoinr   dictitemsappendr   	Exceptionloggerwarningreplace)r   r	   r
   formatted_partsr   
item_partskr   e
param_type	str_values              r   format_array_parameterr4      s    
I
I&
I
I
III 0xx////////  	2 	2D$%% 2
 JJLL 2 2DAq%%jjQjj1111&&sxx
';';<<<<&&s4yy1111xx(((    2>WW
\j\\n\\YZ\\	
 	
 	
  	MMMMMM Fb!!b!!b!!b!!  %s+   B1C, ,
F6,F"F(A FFFparam_valuec                     t          | t                    s/t                              d| dt	          |                       i S i }|                                 D ]\  }}| d| d}t          |          ||<    |S )a  
    Format a dictionary parameter for deep-object style serialization.

    According to OpenAPI 3.0 spec, deepObject style with explode=true serializes
    object properties as separate query parameters with bracket notation.

    For example, `{"id": "123", "type": "user"}` becomes
    `param[id]=123&param[type]=user`.

    Args:
        param_value: Dictionary value to format
        parameter_name: Name of the parameter

    Returns:
        Dictionary with bracketed parameter names as keys
    zDeep-object style parameter 'z' expected dict, got r    r"   )r   r'   r+   r,   typer(   r   )r5   r	   resultkeyvaluebracketed_keys         r   format_deep_object_parameterr<   B   s    & k4(( dNddQUVaQbQbdd	
 	
 	
 	F!'')) + +
U)22C222 #E

}Mr   schemac                 \   | rt          | t                    sdS d| v r| d         S d| v r1t          | d         t                    r| d         r| d         d         S d| v r1t          | d         t                    r| d         r| d         d         S d| v r| d         S |                     d          }|dk    ri }|                     d	i           }t          |t                    rt	          |                     d
g                     }t          |                                          dd         }|D ]}||v rt          ||                   ||<   |D ]"}||vr||v rt          ||                   ||<   #|r|nddiS |dk    rC|                     d          }t          |t                    rt          |          }	|	|	gng S dgS |dk    r?|                     d          }
|
dk    rdS |
dk    rdS |
dk    rdS |
dk    rdS |
dk    rdS dS |dk    rdS |d k    rd!S |d"k    rd#S |d$k    rdS d%S )&zy
    Generate a simple example value from a JSON schema dictionary.
    Very basic implementation focusing on types.
    unknowndefaultenumr   examplesexampler7   object
propertiesrequiredN   r9   r:   arrayr(   example_itemstringformatz	date-timez2024-01-01T12:00:00Zdatez
2024-01-01emailzuser@example.comuuidz$123e4567-e89b-12d3-a456-426614174000bytezZXhhbXBsZQ==integerr   numberg      ?booleanTnullunknown_type)r   r'   listgetsetkeysgenerate_example_from_schema)r=   schema_typer8   rE   required_propsprops_to_include	prop_namereq_propitems_schemaitem_exampleformat_types              r   rY   rY   d   s   
  FD11 y Fi  Jvf~t<<f~a   	fvj)400 	: 	 j!!$$Fi  **V$$KhZZb11
j$'' 	 J!;!;<<N#JOO$5$566  .  	
**(D"9-) )F9% +  6))h*.D.D'C"8,( (F8$  5vveW%55			zz'**lD)) 	F7EEL%1%=L>>2E		 	 jj**+%%))&  <'!!%%&  99&  !>x			!	!q		 	 s			!	!t			t >r      dataindentc                 h    	 t          j        | |          }d| dS # t          $ r	 d|  dcY S w xY w)z8Formats Python data as a JSON string block for Markdown.rd   z```json
z
```z!```
Could not serialize to JSON: )jsondumps	TypeError)rc   rd   json_strs      r   format_json_for_descriptionrk      sc    @:d6222*8**** @ @ @?D??????@s    11base_description
parametersrequest_bodyc                     | g}|rMd |D             }|r?|                     d           |D ]'}|                     d|j         d|j                    (d                    |          S )a  
    Formats a simple description for MCP objects (tools, resources, prompts).
    Excludes response details, examples, and verbose status codes.

    Args:
        base_description (str): The initial description to be formatted.
        parameters (list[ParameterInfo] | None, optional): A list of parameter information.
        request_body (RequestBodyInfo | None, optional): Information about the request body.

    Returns:
        str: The formatted description string with minimal details.
    c                 6    g | ]}|j         d k    |j        |S r   )locationdescriptionr   ps     r   
<listcomp>z-format_simple_description.<locals>.<listcomp>   s+    WWWQ
f0D0D0Dq0D0D0Dr   

**Path Parameters:**
- ****: 
)r)   namers   r&   )rl   rm   rn   
desc_partspath_paramsparams         r   format_simple_descriptionr      s    " ##J  PWW*WWW 	P8999$ P P!!"N5:"N"N5;L"N"NOOOO
 99Z   r   	responsesc           
      d	   | g}|rd |D             }|rSd}|                     |           |D ]9}|j        rdnd}d|j         d| d|j        pd }	|                     |	           :d	 |D             }
|
rSd
}|                     |           |
D ]9}|j        rdnd}d|j         d| d|j        pd }	|                     |	           :|rC|j        r;d}|                     |           |j        rdnd}|                     d|j         |            |j        rd|j        v rdn!t          t          |j                  d          }|r|j                            |i           }t          |t                    rd|v r|                     d           |d         
                                D ]`\  }}t          |t                    rFd|v rB||                    dg           v }|rdnd}|                     d| d| d|d                     ard}d}h d}t          fd|D             d          }
                                }t          |          D ]B\  }}|s|                     |           d}||k    rdnd}|                     d| d| d|j        pd            |j        rd|j        v rdn!t          t          |j                  d          }|r|j                            |          }|                     d| d           t          |t                    r!|                    d          dk    rd|v r|d         }t          |t                    rsd|v ro|                     d           |d         
                                D ]?\  }}t          |t                    r%d|v r!|                     d| d |d                     @nsd|v ro|                     d!           |d         
                                D ]?\  }}t          |t                    r%d|v r!|                     d| d |d                     @|rPt          |          }|d"k    r;|9|                     d#           |                     t          |d$%                     Dd                    |          S )&aX  
    Formats the base description string with response, parameter, and request body information.

    Args:
        base_description (str): The initial description to be formatted.
        responses (dict[str, Any]): A dictionary of response information, keyed by status code.
        parameters (list[ParameterInfo] | None, optional): A list of parameter information,
            including path and query parameters. Each parameter includes details such as name,
            location, whether it is required, and a description.
        request_body (RequestBodyInfo | None, optional): Information about the request body,
            including its description, whether it is required, and its content schema.

    Returns:
        str: The formatted description string with additional details about responses, parameters,
        and the request body.
    c                 (    g | ]}|j         d k    |S rq   rr   rt   s     r   rv   z5format_description_with_responses.<locals>.<listcomp>   s$    EEEQ
f0D0Dq0D0D0Dr   rw   z (Required)r!   rx   z**z: zNo description.c                 (    g | ]}|j         d k    |S )r   r   rt   s     r   rv   z5format_description_with_responses.<locals>.<listcomp>  s$    GGGaw1F1F1F1F1Fr   z

**Query Parameters:**z

**Request Body:**rz   zapplication/jsonNrE   z

**Request Properties:**rs   rF   z

**Responses:**F>   200201202204c              3   $   K   | ]
}|v |V  d S r    )r   sr   s     r   r   z4format_description_with_responses.<locals>.<genexpr>5  s'      JJQ1	>>q>>>>JJr   Tz
 (Success)z  - Content-Type: ``r7   rH   r(   z"
  - **Response Item Properties:**z	
    - **ry   z
  - **Response Properties:**rT   z
  - **Example:**rb   rf   )r)   rF   r{   rs   content_schemanextiterrV   r   r'   r(   sortedrY   rk   r&   )rl   r   rm   rn   r|   r}   param_sectionr~   required_marker
param_descquery_paramsreq_body_section
media_typer=   r]   prop_schemarF   req_markresponse_sectionadded_response_sectionsuccess_codessuccess_statusresponses_to_processstatus_code	resp_infostatus_markerr_   rC   s    `                          r   !format_description_with_responsesr      s:   0 ##J  .EE*EEE 	.6Mm,,,$ . .38>"I--roejooOoouGXGm\moo
!!*---- HG:GGG 	.7Mm,,,% . .38>"I--roejooOoouGXGm\moo
!!*----  0 2*++++7+@H--bJ|7JJJKKK & 	 &)DDD #"$|:;;TBB 
  %488RHHfd++ 0F0F%%&CDDD282F2L2L2N2N 	 	.	;&{D99 - < <'0FJJz24N4N'NH8@'H}}bH&-- ^ ^ ^h ^ ^+mB\ ^ ^  
  I/!& 544JJJJ-JJJDQQ  )00&,-A&B&B >	 >	"K) .!!"2333)-&,7>,I,ILLrMeeeee9N9cRcee  
 ' 3 *Y-EEE '&d9#;<<dCC   +&599*EEF%%&IJ&I&I&IJJJ "&$// &!::f--88W=N=N+1'?L *< > >*$0L$@$@ * 1 12W X X X>J$0?""'%''	!* 	!*$:I{ )3;(E(E%*,9[,H,H(2(9(9,d,d,dTaHb,d,d)* )* )* *V33&--.NOOO:@:N:T:T:V:V & & 6	;$.{D$A$A!&(5(D(D$.$5$5(`Y(`(`KP]D^(`(`%& %& %&
  ">v"F"F"n449L&--.BCCC&-- ;GA N N N   99Z   r   )r4   r<   r   rk   r   rY   )F)rb   )NN)__doc__rg   loggingtypingr   modelsr   r   r   	getLogger__name__r+   rU   r   r   r4   r'   r<   rY   r   rk   r   r   __all__r   r   r   <module>r      s   < <         > > > > > > > > > >		8	$	$ CH3 33"%3;?34Z3 3 3 3l'*	#s(^   DPd): Ps P P P Pf@ @c @3 @s @ @ @ @ .2+/! !!]#d*! "D(! 		! ! ! !L .2+/Y! Y!Y!SY!
 ]#d*Y! "D(Y! 	Y! Y! Y! Y!z  r   