ó
    lQj+  ã                  ó–   • % 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      ÚV/home/mande/repo/quber/.venv/lib/python3.13/site-packages/langsmith/_internal/_uuid.pyÚ_to_timestamp_and_nanosr      s   € ä˜KÔ):Ó;�N€GØˆ>Ðó    c                óH   • U c
  [        5       $ [        U 5      u  p[        XS9$ )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.
)Ú	timestampr   )Ú_uuid_utils_uuid7r   r	   s      r   r   r      s*   € ð, ÑÜ Ó"Ð"Ü,¨[Ó9�N€GÜ wÑ<Ð<r   c                ó    • U R                   S:H  $ )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)Ú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)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   Ú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   ÿÿÿ Úbigép   é   é   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  �=  # Ð'×.Ñ.Ó0€JÜ�Š˜
Ó#×*Ñ*Ó,€Aô 	�"‹€Aô �+×Ñà×"Ñ" 1 QÐ'ˆˆ!ˆ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ˆ€Gä�9Š9œ5 ›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   