§
    ~Štj+  ã                  óŒ   — U d Z ddlmZ ddlZddlZddlZddlmZ ddlZddl	m
Z dZded<   dd„Zddd„Z
dd„Zdad d„Zd!d„ZdS )"z"UUID helpers backed by uuid-utils.é    )ÚannotationsN)ÚFinal)Úuuid7i Êš;r   Ú_NANOS_PER_SECONDÚnanosecondsÚintÚreturnútuple[int, int]c                ó:   — t          | t          ¦  «        \  }}||fS )zDSplit a nanosecond timestamp into seconds and remaining nanoseconds.)Údivmodr   ©r   ÚsecondsÚnanoss      úW/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langsmith/_internal/_uuid.pyÚ_to_timestamp_and_nanosr      s    € å˜KÕ):Ñ;Ô;�N€GˆUØ�Eˆ>Ðó    ú
int | Noneú	uuid.UUIDc                óh   — | €t          ¦   «         S t          | ¦  «        \  }}t          ||¬¦  «        S )zäGenerate a UUID from a Unix timestamp in nanoseconds and random bits.

    UUIDv7 objects feature monotonicity within a millisecond.

    Args:
        nanoseconds: Optional ns timestamp. If not provided, uses current time.
    N)Ú	timestampr   )Ú_uuid_utils_uuid7r   r   s      r   r   r      s:   € ð, ÐÝ Ñ"Ô"Ð"Ý,¨[Ñ9Ô9�N€GˆUÝ w°eÐ<Ñ<Ô<Ð<r   Úuuid_objÚboolc                ó   — | j         dk    S )z˜Check if a UUID is version 7.

    Args:
        uuid_obj: The UUID to check.

    Returns:
        True if the UUID is version 7, False otherwise.
    é   )Úversion)r   s    r   Ú
is_uuid_v7r   2   s   € ð Ô˜qÒ Ð r   FÚid_typeÚstrÚNonec                óv   — t          | ¦  «        s't          s"dat          j        dt          d¬¦  «         dS dS dS )z«Warn if a UUID is not version 7.

    Args:
        uuid_obj: The UUID to check.
        id_type: The type of ID (e.g., "run_id", "trace_id") for the warning message.
    TzÎLangSmith now uses UUID v7 for run and trace identifiers. This warning appears when passing custom IDs. Please use: from langsmith import uuid7
            id = uuid7()
Future versions will require UUID v7.é   )Ú
stacklevelN)r   Ú_UUID_V7_WARNING_EMITTEDÚwarningsÚwarnÚUserWarning)r   r   s     r   Úwarn_if_not_uuid_v7r(   A   sf   € õ �hÑÔð 
Õ(@ð 
Ø#'Ð ÝŒð8õ Øð
	
ñ 
	
ô 
	
ð 
	
ð 
	
ð 
	
ð
ð 
ð 
ð 
r   Úoriginal_idÚkeyc                ó  — | › d|› �                      ¦   «         }t          j        |¦  «                             ¦   «         }t	          d¦  «        }t          | ¦  «        r| j        dd…         |dd…<   n6t          j        ¦   «         dz  }|dz  }| 	                    dd¦  «        |dd…<   d|d         d	z  z  |d<   |d
         |d<   d|d         dz  z  |d<   |dd…         |dd…<   t          j        t          |¦  «        ¬¦  «        S )a  Generate a deterministic UUID7 derived from an original UUID and a key.

    This function creates a new UUID that:
    - Preserves the timestamp from the original UUID if it's UUID v7
    - Uses current time if the original is not UUID v7
    - Uses deterministic bits derived from hashing the original + key with XXH3-128
    - Is valid UUID v7 format

    This is used for creating replica IDs that maintain time-ordering properties
    while being deterministic across distributed systems.

    Args:
        original_id: The source UUID (ideally UUID v7 to preserve timestamp).
        key: A string key used for deterministic derivation (e.g., project name).

    Returns:
        A new UUID v7 with preserved timestamp (if original is v7) and
        deterministic random bits.

    Example:
        >>> original = uuid7()
        >>> replica_id = uuid7_deterministic(original, "replica-project")
        >>> # Same inputs always produce same output
        >>> assert uuid7_deterministic(original, "replica-project") == replica_id
    ú:é   r   é   i@B l   ÿÿÿ Úbigép   é   é   r   é€   é   é?   é   r"   é
   é	   )Úbytes)ÚencodeÚxxhashÚxxh3_128ÚdigestÚ	bytearrayr   r9   ÚtimeÚtime_nsÚto_bytesÚuuidÚUUID)r)   r*   Ú
hash_inputÚhÚbÚtimestamp_msÚ
unix_ts_mss          r   Úuuid7_deterministicrI   X   s!  € ð6  Ð'Ð' #Ð'Ð'×.Ò.Ñ0Ô0€JÝŒ˜
Ñ#Ô#×*Ò*Ñ,Ô,€Aõ 	�"‰Œ€Aõ �+ÑÔð /àÔ" 1 Q 3Ô'ˆˆ!ˆAˆ#‰ˆõ ”|‘~”~¨Ñ2ˆà!Ð$4Ñ4ˆ
Ø×$Ò$ Q¨Ñ.Ô.ˆˆ!ˆAˆ#‰ð �1�Q”4˜$‘;Ñ€A€a�Dð ˆQŒ4€A€a�Dð �1�Q”4˜$‘;Ñ€A€a�Dð ��"�Œg€A€aˆ€d�GåŒ9�5 ™8œ8Ð$Ñ$Ô$Ð$r   )r   r   r	   r
   )N)r   r   r	   r   )r   r   r	   r   )r   r   r   r   r	   r    )r)   r   r*   r   r	   r   )Ú__doc__Ú
__future__r   r?   rB   r%   Útypingr   r;   Úuuid_utils.compatr   r   r   Ú__annotations__r   r   r$   r(   rI   © r   r   ú<module>rP      sû   ðØ (Ð (Ð (à "Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€Ø €€€Ø Ð Ð Ð Ð Ð à €€€Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8à(Ð Ð (Ð (Ð (Ñ (ðð ð ð ð=ð =ð =ð =ð =ð8	!ð 	!ð 	!ð 	!ð !Ð ð
ð 
ð 
ð 
ð.C%ð C%ð C%ð C%ð C%ð C%r   