
    jKj                    b    d Z ddlmZ ddlZddlZddlZddlmZ ed   Zd
dZ	ddZ
ddZdd	Zy)a  ID generation for MCP analytics.

``new_prefixed_id`` mints ``evt_<uuidv7>`` / ``ses_<uuidv7>`` ids.
``deterministic_prefixed_id`` maps an MCP protocol session id to a stable SDK
session id so the same MCP session reuses the same ``$session_id`` across server
restarts. UUIDv7 is implemented inline (RFC 9562) so we take on no extra
dependency; the FNV-1a hash is a faithful port of the TypeScript SDK.
    )annotationsN)Literal)evtsesc                 n   t        t        j                         dz        dz  } t         j                  t        j                  d      d      dz  }t         j                  t        j                  d      d      dz  }| dz  }|d	z  }||d
z  z  }|dz  }||z  }t        t        j                  |            S )zKGenerate a UUIDv7 (time-ordered) per RFC 9562, with no external dependency.i  l       bigi     l    P   l              @   l            )int)r   time
from_bytesosurandomstruuidUUID)
unix_ts_msrand_arand_bvalues       a/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/posthog/mcp/_ids.py_uuid7r      s    TYY[4'(M:J^^BJJqM51F:F^^BJJqM51]CF"E	YE	Vr\E	ZE	VOEtyyU#$$    c                     |  dt                S )N_)r   )prefixs    r   new_prefixed_idr   &   s    XQvxj!!r   c                >    |  dt        |       t        | d       S )zDeterministic id derived from an arbitrary string.

    Uses the FNV-1a 64-bit hash (mixed twice to fill 32 hex chars). Not
    cryptographic; we only need a stable, low-collision input -> output mapping.
    r   z::salt)
_fnv1a_hex)r   r   s     r   deterministic_prefixed_idr"   *   s,     XQz%()*wf5E*F)GHHr   c                j    d}d}| D ]#  }t        |      }||z  dz  dz  }||z  dz  dz  }% |d|dS )Nl   %#D l    i  l    i  08x)ord)r   h1h2chcs        r   r!   r!   3   sZ    	B	BGAv#z1Av#z1  XbXr   )returnr   )r   MCPAnalyticsIDPrefixr*   r   )r   r+   r   r   r*   r   )r   r   r*   r   )__doc__
__future__r   r   r   r   typingr   r+   r   r   r"   r!    r   r   <module>r0      s;   
 # 	   |, %"Ir   