
    LKid                         S SK JrJrJr  S SKrS SKrS SKJr  S SKJ	r	  S SK
JrJr  S SKJr  S SKJr  \R"                  " \5      r " S S	5      rg)
    )ClassVarDictOptionalN)	ServerAPI)BaseHTTPClient)SettingsSystem)ProductTelemetryClient)ClientStartEventc                   (   \ rS rSr% 0 r\\\\4      \	S'   \\	S'   \
" 5       4S\
SS4S jjr\S\S\
S\4S	 j5       r\S\
S\4S
 j5       r\S\S\4S j5       r\S\SS 4S j5       r\SS j5       r\S\4S j5       rSS jr\S\\   4S j5       rSrg)SharedSystemClient   _identifier_to_system_identifiersettingsreturnNc                 x    [         R                  U5      U l        [         R                  U R                  U5        g N)r   _get_identifier_from_settingsr   _create_system_if_not_exists)selfr   s     c/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/chromadb/api/shared_system_client.py__init__SharedSystemClient.__init__   s-     .KKHU778H8H(S    
identifierc                 B   XR                   ;  aT  [        U5      nX0R                   U'   UR                  [        5        UR                  [        5        UR                  5         O.U R                   U   nUR                  U:w  a  [        SU S35      eU R                   U   $ )Nz)An instance of Chroma already exists for z with different settings)r   r	   instancer
   r   startr   
ValueError)clsr   r   
new_systemprevious_systems        r   r   /SharedSystemClient._create_system_if_not_exists   s     666)J4>%%j1 67	*!77
CO ''83 ?
|Kcd  ((44r   c                     SnU R                   nUc  [        S5      eUS;   a$  U R                  (       a  U R                  nU$ Sn U$ US;   a   [	        [
        R                  " 5       5      nU$ [        SU 35      e)N z1Chroma API implementation must be set in settings)zchromadb.api.segment.SegmentAPIz!chromadb.api.rust.RustBindingsAPI	ephemeral)zchromadb.api.fastapi.FastAPIz'chromadb.api.async_fastapi.AsyncFastAPIz&Unsupported Chroma API implementation )chroma_api_implr    is_persistentpersist_directorystruuiduuid4)r   r   api_impls      r   r   0SharedSystemClient._get_identifier_from_settings/   s    
++PQQ 
 
 %%%77
       
 

 TZZ\*J  EhZPQQr   systemc                 j    [         R                  U R                  5      nU [         R                  U'   U$ r   )r   r   r   r   )r0   r   s     r   _populate_data_from_system-SharedSystemClient._populate_data_from_systemK   s-    'EEfooV
?E00<r   c                 T    [         R                  U5        U " UR                  5      nU$ )zRCreate a client from an existing system. This is useful for testing and debugging.)r   r2   r   )r!   r0   r   s      r   from_systemSharedSystemClient.from_systemQ   s%     	55f=v'r   c                      0 [         l        g r   )r   r    r   r   clear_system_cache%SharedSystemClient.clear_system_cacheY   s    350r   c                 <    [         R                  U R                     $ r   )r   r   r   )r   s    r   _systemSharedSystemClient._system]   s    !778H8HIIr   c                 t    U R                   R                  [        5      nUR                  [	        5       5        g r   )r<   r   r
   capturer   )r   telemetry_clients     r   _submit_client_start_event-SharedSystemClient._submit_client_start_eventa   s*    <<001GH  !1!34r   c                  N   / n [        [        R                  R                  5       5      nU H  n UR	                  [
        5      n[        U[        5      (       d  M0  UR                  5       nSU;  a  SU;  a  MN  UR                  5       nSnUR                  5        H  u  pxUR                  5       S:X  d  M  Un  O   U(       a  U R                  U5        M  M     U (       d  g[        U 5      S:  a  [        R!                  SU S   SS  S	35        U S   $ ! [         a     M  f = f)
a  
Try to extract api key from existing client instances by checking httpx session headers.

Requirements to pull api key:
- must be a BaseHTTPClient instance (ignore RustBindingsAPI and SegmentAPI)
- must have "api.trychroma.com" or "gcp.trychroma.com" in the _api_url (ignore local/self-hosted instances)
- must have "x-chroma-token" or "X-Chroma-Token" in the headers

Returns:
    The first api key found, or None if no client instances have api keys set.
zapi.trychroma.comzgcp.trychroma.comNzx-chroma-token   zAMultiple Chroma Cloud clients found, using API key starting with r      z...)listr   r   valuesr   r   
isinstancer   get_api_urlget_request_headersitemslowerappend	Exceptionlenloggerinfo)	api_keyssystems_snapshotr0   
server_apiapi_urlheadersapi_keykeyvalues	            r   %get_chroma_cloud_api_key_from_clients8SharedSystemClient.get_chroma_cloud_api_key_from_clientse   s&    ! 2 H H O O QR&F#__Y7
!*n== %002'w6+7:$88:")--/JCyy{&66"' #2
 OOG, / ':  x=1KKST\]^T_`babTcSddgh {  s#   *DD:9D7D
D$#D$)r   )r   N)__name__
__module____qualname____firstlineno__r   r   r   r+   r	   __annotations__r   r   classmethodr   staticmethodr   r2   r5   r9   propertyr<   rA   r   rZ   __static_attributes__r8   r   r   r   r      s+   9;8Df$56; &ZTT 
T 55(05	5 5,  S  6 6 c  
  ,@   6 6 J J J5 58C= 5 5r   r   )typingr   r   r   loggingr,   chromadb.apir   chromadb.api.base_http_clientr   chromadb.configr   r	   chromadb.telemetry.productr
   !chromadb.telemetry.product.eventsr   	getLoggerr\   rP   r   r8   r   r   <module>rm      s<    + +   " 8 , = >			8	$N Nr   