o
    î6Wjä  ã                   @  s¤   d Z ddlmZ ddlmZmZ ddlmZ g d¢ZdZ		 dZ
	 dZ	 d	Zed
 Z	 d'dd„ZdZd(dd„Zd)dd„Z		d*d+d d!„Z		d*d,d"d#„Zd-d%d&„ZdS ).ac  Tracking for SDK helper usage via the x-stainless-helper header.

This module is the single source of truth for the helper-telemetry header
keys and the closed tag vocabulary. The append-don't-clobber merge for the
header itself lives in :func:`anthropic._base_client.merge_headers`; here
we only carry the constants and the per-object tagging machinery.
é    )Úannotations)ÚAnyÚcast)ÚLiteral)ÚSTAINLESS_HELPER_HEADERÚSTAINLESS_HELPER_METHOD_HEADERÚSTAINLESS_STREAM_HELPER_HEADERÚHELPER_METHOD_STREAMÚStainlessHelperHeaderValueÚhelper_headerÚ
tag_helperÚget_helper_tagÚcollect_helpersÚstainless_helper_headerÚ!stainless_helper_header_from_filezx-stainless-helperzx-stainless-helper-methodzx-stainless-stream-helperÚstream)zbeta.messages.parseÚBetaToolRunnerÚ
compactionzenvironments-work-pollerzenvironments-workerzfallback-refusal-middlewareÚmcp_contentÚmcp_messageÚmcp_resource_to_contentÚmcp_resource_to_fileÚmcp_toolzmessages.parsezsession-tool-runnerÚvaluer
   Úreturnúdict[str, str]c                 C  s   t | iS )zÔThe ``x-stainless-helper: <value>`` header dict, for passing into a
    ``merge_headers`` call or as ``extra_headers``/``default_headers``.

    Typing keeps the value drawn from the closed vocabulary above.
    )r   )r   © r   úo/home/esfera/Documents/content_generation/venv/lib/python3.10/site-packages/anthropic/lib/_stainless_helpers.pyr   H   s   r   Ú_stainless_helperÚobjr   ÚnameÚNonec              	   C  s.   z
t  | t|¡ W dS  ttfy   Y dS w )z0Mark an object as created by a named SDK helper.N)ÚobjectÚ__setattr__Ú_HELPER_ATTRÚAttributeErrorÚ	TypeError)r   r    r   r   r   r   T   s
   ÿr   r"   ú
str | Nonec                 C  s   t | tdƒS )z+Get the helper name from an object, if any.N)Úgetattrr$   )r   r   r   r   r   \   s   r   NÚtoolsÚmessagesú	list[str]c                   s¤   g ‰ d	‡ fdd„}| r| D ]}|t |ƒƒ q|rP|D ]5}|t |ƒƒ t|tƒr4ttttf |ƒ d¡}nt|ddƒ}t|tƒrOttt	 |ƒD ]}|t |ƒƒ qFqˆ S )
z:Collect deduplicated helper names from tools and messages.Útagr'   r   r!   c                   s&   | d ur| ˆ vrˆ   | ¡ d S d S d S )N)Úappend)r,   ©Úhelpersr   r   Ú_addh   s   ÿzcollect_helpers.<locals>._addÚcontentN)r,   r'   r   r!   )
r   Ú
isinstanceÚdictr   Ústrr   Úgetr(   Úlistr"   )r)   r*   r0   ÚtoolÚmessageÚblocksÚblockr   r.   r   r   a   s    

€r   c                 C  s    t | |ƒ}|s	i S td |¡iS )zvBuild x-stainless-helper header dict from tools and messages.

    Returns an empty dict if no helpers are found.
    z, )r   r   Újoin)r)   r*   r/   r   r   r   r   €   s   
r   Úfilec                 C  s   t | ƒ}|du r
i S t|iS )z8Build x-stainless-helper header dict from a file object.N)r   r   )r<   r,   r   r   r   r   Ž   s   r   )r   r
   r   r   )r   r   r    r
   r   r!   )r   r"   r   r'   )NN)r)   r   r*   r   r   r+   )r)   r   r*   r   r   r   )r<   r"   r   r   )Ú__doc__Ú
__future__r   Útypingr   r   Útyping_extensionsr   Ú__all__r   r   r   r	   r
   r   r$   r   r   r   r   r   r   r   r   r   Ú<module>   s6    ÿ

	

þ þ