
    jKjd                    d    d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddZ
ddZdd	Zdd
ZddZy)a  Build PostHog error-tracking properties (``$exception_list`` /
``$exception_level``) from arbitrary thrown values, reusing posthog-python's own
``exceptions_from_error_tuple`` so MCP tool failures group and symbolicate the
same way as exceptions from any other PostHog SDK.
    )annotations)AnyList)exceptions_from_error_tuple   )ErrorPropertiesc                
   t        |       rt        t        |             S t        | t              r&t        |       | | j                  f}t        |      ddS t        | t              rt        |       S t        t        |             S )zwReturn the ``$exception_list`` shape for any thrown value (Exception,
    string, CallToolResult, or arbitrary object).errorz$exception_listz$exception_level)
_is_call_tool_result_from_message!_extract_call_tool_result_message
isinstanceBaseExceptiontype__traceback__r   str	_safe_str)r
   exc_infos     h/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/posthog/mcp/_exceptions.pycapture_exceptionr      sy    
 E">uEFF%'K(;(;<:8D '
 	

 %U##5)**    c                    dddd| dgddS )NgenericT)r   handledError)	mechanismr   valuer
   r    )messages    r   r   r   )   s+     '0DA 
 $	 	r   c                    t        | t              r%d| v xr t        | j                  d      t              S t	        | d      xr t        t        | dd      t              S )z{Detect a CallToolResult error (``{isError, content: [...]}``), whether a
    dict or a pydantic model from the ``mcp`` SDK.isErrorcontentN)r   dictgetlisthasattrgetattrr   s    r   r   r   6   sW     %E!Lj91Et&LL5)$ y$'* r   c                   t        | t              r| j                  d      nt        | dg       }g }|xs g D ]  }t        |t              r|j                  d      nt        |dd       }t        |t              r|j                  d      nt        |dd       }|dk(  set        |t              sv|j                  |        dj                  |      j                         xs dS )Nr#   r   text Unknown error)r   r$   r%   r(   r   appendjoinstrip)resultr#   textspart	part_typer+   s         r   r   r   @   s     fd# 	

9VY+ 
 E2 *4 6DHHVGD&RV<W 	 !+4 6DHHVGD&RV<W 	 :dC#8LL  88E?  "5o5r   c                8    	 t        |       S # t        $ r Y yw xY w)Nr-   )r   	Exceptionr)   s    r   r   r   S   s#    5z s   
 	N)r
   r   returnr   )r    r   r7   r   )r   r   r7   bool)r1   r   r7   r   )r   r   r7   r   )__doc__
__future__r   typingr   r   posthog.exception_utilsr   typesr   r   r   r   r   r   r   r   r   <module>r>      s1   
 #  ? "+*
6&r   