
    =Ki+                        % S r SSKJr  SSKrSSKrSSKrSSKJr  SSKrSSK	J
r  SrS\S'   SS	 jrSSS
 jjr
SS jrSqSS jrSS jrg)z"UUID helpers backed by uuid-utils.    )annotationsN)Final)uuid7i ʚ;r   _NANOS_PER_SECONDc                ,    [        U [        5      u  pX4$ )zDSplit a nanosecond timestamp into seconds and remaining nanoseconds.)divmodr   nanosecondssecondsnanoss      [/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/langsmith/_internal/_uuid.py_to_timestamp_and_nanosr      s    K):;NG>    c                H    U c
  [        5       $ [        U 5      u  p[        XS9$ )zGenerate 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.
)	timestampr   )_uuid_utils_uuid7r   r	   s      r   r   r      s*    ,  "",[9NGw<<r   c                     U R                   S:H  $ )zCheck if a UUID is version 7.

Args:
    uuid_obj: The UUID to check.

Returns:
    True if the UUID is version 7, False otherwise.
   )version)uuid_objs    r   
is_uuid_v7r   2   s     q  r   Fc                v    [        U 5      (       d)  [        (       d  Sq[        R                  " S[        SS9  ggg)zWarn 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.
TzLangSmith 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   id_types     r   warn_if_not_uuid_v7r    A   s=     h(@(@#' 8 
	
 )Ar   c                   U  SU 3R                  5       n[        R                  " U5      R                  5       n[	        S5      n[        U 5      (       a  U R                  SS USS& O2[        R                  " 5       S-  nUS-  nUR                  SS5      USS& SUS   S	-  -  US'   US
   US'   SUS   S-  -  US'   USS USS& [        R                  " [        U5      S9$ )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    bigp         r         ?      r   
   	   )bytes)encodexxhashxxh3_128digest	bytearrayr   r/   timetime_nsto_bytesuuidUUID)original_idkey
hash_inputhbtimestamp_ms
unix_ts_mss          r   uuid7_deterministicrA   X   s    6  =#'..0J
#**,A 	"A +""1Q'!A ||~2!$44
$$Q.!A 1Q4$;AaD Q4AaD 1Q4$;AaD "gAaG9958$$r   )r
   intreturnztuple[int, int])N)r
   z
int | NonerC   	uuid.UUID)r   rD   rC   bool)r   rD   r   strrC   None)r:   rD   r;   rF   rC   rD   )__doc__
__future__r   r5   r8   r   typingr   r1   uuid_utils.compatr   r   r   __annotations__r   r   r   r    rA    r   r   <module>rN      sJ    ( "      8( 5 (=8	! ! 
.C%r   