
    a
i+                        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      C:\Users\Dell Inspiron 16\Desktop\tws\AgrotaPowerBi\back-agrota-powerbi\mcp-client-agrota\venv\Lib\site-packages\langsmith/_internal/_uuid.py_to_timestamp_and_nanosr      s     K):;;NGUE>    
int | None	uuid.UUIDc                h    | t                      S t          |           \  }}t          ||          S )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.
    N)	timestampr   )_uuid_utils_uuid7r   r   s      r   r   r      s:    ,  """,[99NGUwe<<<<r   uuid_objboolc                    | j         dk    S )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)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 )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   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    bigp         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0J
##**,,A 	"A + /"1Q3'!A# |~~2!$44
$$Q..!A# 1Q4$;AaD Q4AaD 1Q4$;AaD "gAadG9588$$$$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   