Ë
    ñÏj£  ã                  óì   — U d Z ddlmZ ddlZddlmZ ddgZdZ	  e«       Z	de
d	<   	 d
ZdZ G d„ de«      Zdd„Zdd„ZeD ]  Z eee ee«      «       Œ eD ]  Z eee ee«      «       Œ dd„Zdd„Zy)zúMark a value as a secret, so LangSmith masks it instead of tracing it.

::

    from langsmith import LangSmithSecret

    API_KEY = LangSmithSecret(os.environ["VENDOR_API_KEY"])

See :class:`LangSmithSecret` for the guarantees and the known limits.
é    )ÚannotationsN)ÚAnyÚLANGSMITH_SECRET_MASKÚLangSmithSecretz[LANGSMITH SECRET]r   Ú_NOT_HANDLED)Ú__add__Ú
__format__Ú__getitem__Ú__mod__Ú__mul__Ú__rmul__Ú
capitalizeÚcasefoldÚcenterÚ
expandtabsÚformatÚ
format_mapÚjoinÚljustÚlowerÚlstripÚremoveprefixÚremovesuffixÚreplaceÚrjustÚrstripÚstripÚswapcaseÚtitleÚ	translateÚupperÚzfill)Ú	partitionÚ
rpartitionÚrsplitÚsplitÚ
splitlinesc                  ó4   — e Zd ZdZdZdd„Zd	d„Zd
d„Zd
d„Zy)r   aÒ  A string that LangSmith serializes as ``[LANGSMITH SECRET]``.

    Wrap a credential once, where it is read, and LangSmith masks it wherever
    it appears in a trace, at any nesting depth::

        @traceable
        def call_vendor(api_key: str, prompt: str) -> str: ...


        call_vendor(api_key=LangSmithSecret(key), prompt="hi")
        # traced inputs: {"api_key": "[LANGSMITH SECRET]", "prompt": "hi"}

    It is a real ``str`` everywhere else: ``json.dumps``, logging and
    third-party clients all see the true value. Operations that derive a new
    string return a ``LangSmithSecret`` again, so the marker is not lost by
    ``.strip()`` or slicing.

    Known limits:

    - ``f"Bearer {secret}"``, ``"".join([secret])`` and
      ``"Bearer {}".format(secret)`` yield a plain ``str``: those build the
      result in C, where the operand gets no say in its type. Wrap the finished
      value instead -- ``LangSmithSecret(f"Bearer {key}")``. Concatenation and
      ``%`` are covered, in either operand order.
    - ``secret.encode()`` returns the real bytes, by design.
    - A secret used as a **dict key** is masked, but two of them in one dict
      collapse to a single entry. A key held inside a dataclass is not masked:
      orjson serializes those itself.
    - An object whose own ``__str__`` interpolates a secret leaks it wherever
      LangSmith stringifies that object. ``__repr__`` is masked; ``__str__``
      belongs to the object.
    - Nothing inside a **pydantic model** is masked. Pydantic serializes its
      own fields and LangSmith deliberately does not override that: a hook
      there would also replace the credential with the mask when a vendor
      client dumps the model to build a request.
    © c                ó   — | S )z/Return the plaintext, still marked as a secret.r)   ©Úselfs    úM/var/www/html/gaurav-v2/venv/lib/python3.12/site-packages/langsmith/secret.pyÚ__str__zLangSmithSecret.__str__d   s   € àˆó    c                ó@   — t        | «      j                  › dt        ›d�S )z Mask the plaintext.

        So an object whose own ``__repr__`` interpolates a secret does not leak
        it when LangSmith stringifies that object.
        Ú(Ú))ÚtypeÚ__name__r   r+   s    r-   Ú__repr__zLangSmithSecret.__repr__h   s$   € ô �t“*×%Ñ%Ð& aÔ(=Ð'@ÀÐBÐBr/   c                ól   — t        |t        «      st        S t        t        j	                  || «      «      S )z*Keep the marker on ``"Bearer " + secret``.)Ú
isinstanceÚstrÚNotImplementedr   r   ©r,   Úothers     r-   Ú__radd__zLangSmithSecret.__radd__s   ó(   € ä˜%¤Ô%Ü!Ð!ÜœsŸ{™{¨5°$Ó7Ó8Ð8r/   c                ól   — t        |t        «      st        S t        t        j	                  || «      «      S )z,Keep the marker on ``"Bearer %s" % secret``.)r7   r8   r9   r   r   r:   s     r-   Ú__rmod__zLangSmithSecret.__rmod__y   r=   r/   N)Úreturnr   )r@   r8   )r;   r   r@   r   )	r4   Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r.   r5   r<   r?   r)   r/   r-   r   r   <   s$   „ ñ#ðJ €IóóCó9ô9r/   c                óV   ‡— t        t        | «      Šdˆfd„}| |_        d| › �|_        |S )Nc                óX   •—  ‰| g|¢­i |¤Ž}t        |«      t        u rt        |«      S |S ©N©r3   r8   r   ©r,   ÚargsÚkwargsÚresultÚbases       €r-   Úwrapperz"_make_str_wrapper.<locals>.wrapperƒ   s2   ø€ Ù�dÐ,˜TÒ, VÑ,ˆÜ*.¨v«,¼#Ñ*=Œ˜vÓ&ÐIÀ6ÐIr/   úLangSmithSecret.©r,   r   rJ   r   rK   r   r@   r   ©Úgetattrr8   r4   rB   ©ÚnamerN   rM   s     @r-   Ú_make_str_wrapperrU   €   s3   ø€ Ü”3˜Ó€DõJð €GÔØ-¨d¨VÐ4€GÔØ€Nr/   c                óV   ‡— t        t        | «      Šdˆfd„}| |_        d| › �|_        |S )Nc                óL   •—  ‰| g|¢­i |¤Ž} t        |«      d„ |D «       «      S )Nc              3  óX   K  — | ]"  }t        |«      t        u rt        |«      n|–— Œ$ y ­wrG   rH   )Ú.0Úitems     r-   Ú	<genexpr>z:_make_sequence_wrapper.<locals>.wrapper.<locals>.<genexpr>‘   s)   è ø€ ð 
ÙMSÀT¤T¨$£Z´3Ñ%6ŒO˜DÔ!¸DÓ@ÉVùs   ‚(*)r3   rI   s       €r-   rN   z'_make_sequence_wrapper.<locals>.wrapper�   s7   ø€ Ù�dÐ,˜TÒ, VÑ,ˆØŒt�F‹|ñ 
ÙMSó
ó 
ð 	
r/   rO   rP   rQ   rS   s     @r-   Ú_make_sequence_wrapperr\   Œ   s2   ø€ Ü”3˜Ó€Dõ
ð €GÔØ-¨d¨VÐ4€GÔØ€Nr/   c                ó&  — t        | t        «      rt        S t        | t        «      rt        j	                  | «      S t        | t
        «      rt        | «      S t        | t        «      rt        | «      S t        | t        «      rt        | «      S t        S )a¹  Mask a secret, or coerce a builtin subclass back to its exact type.

    orjson's ``OPT_PASSTHROUGH_SUBCLASS`` is what routes a
    :class:`~langsmith.LangSmithSecret` to LangSmith's ``default`` hook, but it
    diverts *every* ``str``/``int``/``dict``/``list`` subclass there as a side
    effect. Coercing those back reproduces the output orjson wrote natively, so
    enabling the option changes nothing for payloads without secrets.
    )	r7   r   r   r8   r.   ÚintÚdictÚlistr   )Úobjs    r-   Ú_coerce_builtin_subclassrb   ¡   sr   € ô �#”Ô'Ü$Ð$Ü�#”sÔô �{‰{˜3ÓÐÜ�#”sÔÜ�3‹xˆÜ�#”tÔÜ�C‹yÐÜ�#”tÔÜ�C‹yÐô Ðr/   c                óÖ  — t        | t        «      rt        S t        | t        «      r6| j	                  «       D ��ci c]  \  }}t        |«      t        |«      “Œ c}}S t        | t        «      r| D �cg c]  }t        |«      ‘Œ c}S t        | t        «      rt        d„ | D «       «      S t        | t        j                  «      rt        j                  d„ | D «       «      S | S c c}}w c c}w )a-  Return a copy of ``obj`` with every :class:`LangSmithSecret` masked.

    For the places no ``default`` hook can intercept a secret: the stdlib
    ``json`` fallback, which writes ``str`` subclasses natively, OpenTelemetry
    span attributes, and dict keys, which orjson never routes through it.
    c              3  ó2   K  — | ]  }t        |«      –— Œ y ­wrG   ©Ú_redact_secrets©rY   Úvalues     r-   r[   z"_redact_secrets.<locals>.<genexpr>Ë   s   è ø€ Ð=¹°”_ U×+¹ùó   ‚c              3  ó2   K  — | ]  }t        |«      –— Œ y ­wrG   re   rg   s     r-   r[   z"_redact_secrets.<locals>.<genexpr>Í   s   è ø€ Ð IÁS¸E¤°×!7ÁSùri   )
r7   r   r   r_   Úitemsrf   r`   ÚtupleÚcollectionsÚdeque)ra   Úkeyrh   s      r-   rf   rf   »   sÊ   € ô �#”Ô'Ü$Ð$Ü�#”tÔàKNÏ9É9Ì;ô
ÙKV¹Z¸SÀ%ŒO˜CÓ ¤/°%Ó"8Ñ8È;ò
ð 	
ô �#”tÔÙ47Ó8±C¨5” Õ&°CÑ8Ð8Ü�#”uÔÜÑ=¹Ó=Ó=Ð=Ü�#”{×(Ñ(Ô)Ü× Ñ Ñ IÁSÓ IÓIÐIØ€Jùó
ùò 9s   ºC Á1C&)rT   r8   r@   r   )ra   r   r@   r   )rC   Ú
__future__r   rm   Útypingr   Ú__all__r   Úobjectr   Ú__annotations__Ú_STR_RETURNINGÚ_SEQUENCE_RETURNINGr8   r   rU   r\   Ú_nameÚsetattrrb   rf   r)   r/   r-   Ú<module>ry      sª   ðò	õ #ã Ý à"Ð$5Ð
6€à,Ð ðOñ “H€ˆcÓ Ø Jð€ð: SÐ ôA9�cô A9óH	óó €EÙˆO˜UÑ$5°eÓ$<Õ=ð ã €EÙˆO˜UÑ$:¸5Ó$AÕBð !óô4r/   