Ë
    uPêj+  ã            	       ó°   — d Z ddlmZmZ ddlmZ ddlmZ dededz  fd„Z	dd	e
e   d
edeeef   fd„Zdedeeef   dz  fd„Zdededz  dedz  defd„Zy)aG  
Tenant-isolation helpers for managed file/batch/vector-store resources.

Returns a Prisma filter and an ownership check that scope managed resources
to the caller's identity: proxy admins see everything, user-keyed callers
see records they created, service-account keys (no user_id) fall back to
the resource's owning team, and keys with neither a user_id nor a team_id
fall back to their own hashed token so they can still reach the resources
they created. Callers with no admin role and no identifying ids at all
are denied so an empty user_id can never select an unscoped query.
é    )ÚAnyÚFinal)ÚUserAPIKeyAuth)Úuser_api_key_has_admin_viewÚuser_api_key_dictÚreturnNc                 ó�   — | j                   �| j                   S | j                  �y| j                  xs | j                  }|rd|› �S y)aó  Return the identity to stamp on (and match against) a managed
    resource's ``created_by``.

    A key with neither a user_id nor a team_id would otherwise stamp
    ``created_by=None`` and be locked out of its own resources, so it owns
    them under its hashed token instead, using the ``key:`` scope prefix
    already used by ``proxy/common_utils/resource_ownership.py``. ``None``
    means the caller has no usable identity of its own and must fall back
    to team scoping, or be denied.
    Nzkey:)Úuser_idÚteam_idÚtokenÚapi_key)r   r   s     úv/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/base_llm/managed_resources/isolation.pyÚresolve_resource_owner_idr      sT   € ð × Ñ Ð,Ø ×(Ñ(Ð(à× Ñ Ð,Øà$×*Ñ*ÒGÐ.?×.GÑ.G€EÙØ�e�Wˆ~Ðàó    ÚitemsÚhas_morec                 ó\   — d| | r| d   j                   nd| r| d   j                   |dœS d|dœS )z»Build the OpenAI-style paginated list response shape used by managed
    file/batch/vector-store listings. ``first_id`` and ``last_id`` are
    sourced from each item's ``.id`` attribute.Úlistr   Néÿÿÿÿ)ÚobjectÚdataÚfirst_idÚlast_idr   )Úid)r   r   s     r   Úbuild_list_pager   1   sE   € ð
 ØÙ#(�E˜!‘H—K’K¨dÙ#(�5˜‘9—<‘<Øñð ð /3Øñð r   c                 ó˜   — t        | «      ri S | j                  }| j                  }|�|�
dd|id|igiS |�d|iS t        | «      }|�d|iS y)u¿  Return a Prisma `where` fragment that scopes a managed-resource listing
    to records the caller is allowed to see.

    - ``{}`` means no scoping (proxy admins).
    - ``{"created_by": <owner_id>}`` for user-keyed callers, and for keys
      with no user_id and no team_id (owner id is their hashed token).
    - ``{"team_id": <team_id>}`` for service-account callers
      that have a team but no user_id.
    - ``{"OR": [...]}`` when the caller has both â€” listing must include
      both their own resources and team-shared ones so it stays consistent
      with ``can_access_resource``.
    - ``None`` means deny: callers MUST skip the query rather than fall
      back to an unscoped fetch.
    NÚORÚ
created_byr   )Ú_user_has_admin_viewr
   r   r   )r   r
   r   Úowner_ids       r   Úbuild_owner_filterr!   >   s‡   € ô" Ð-Ô.Øˆ	à&×.Ñ.€GØ&×.Ñ.€GàÐ˜wÐ2àØ˜wÐ'Ø˜GÐ$ðð
ð 	
ð ÐØ˜7Ð#Ð#ä/Ð0AÓB€HØÐØ˜hÐ'Ð'àr   r   Úresource_team_idc                 ór   — t        | «      ryt        | «      }|�|�||k(  ry| j                  }|�|�||k(  ryy)u0  Return True iff the caller may read/modify a managed resource.

    The resource's ``created_by`` and ``team_id`` fields must be non-None
    to match the caller's identity â€” guarding against the ``None == None``
    bypass that previously let service-account keys read every keyless
    resource.
    TF)r   r   r   )r   r   r"   r    r   s        r   Úcan_access_resourcer$   g   sV   € ô Ð-Ô.Øä/Ð0AÓB€HØÐ 
Ð 6¸:ÈÒ;QØà&×.Ñ.€GØÐÐ/Ð;Ð@PÐT[Ò@[Øàr   )F)Ú__doc__Útypingr   r   Úlitellm.proxy._typesr   r   r   Ústrr   r   ÚboolÚdictr   r!   r$   © r   r   ú<module>r,      s¬   ðñ
÷ õõð
Ø%ðàˆ4�Zóñ4
˜4 ™9ð 
°ð 
ÀÀcÈ3ÀhÁó 
ð&Ø%ð&à	ˆ#ˆsˆ(�^�dÑó&ðRØ%ðà�d‘
ðð ˜D‘jðð 
ô	r   