o
    ưi                     @   sF   d Z ddlmZmZmZmZmZ ddlZddlm	Z	 G dd dZ
dS )z*Teams management client for LiteLLM proxy.    )AnyDictListOptionalUnionN   )UnauthorizedErrorc                   @   s   e Zd ZdZddedee fddZdeeef fdd	Z		dd
ee dee de	eee
f  fddZ								dd
ee dee dee dee dededee dedeee
f fddZde	eee
f  fddZdS )TeamsManagementClientz+Client for managing teams in LiteLLM proxy.Nbase_urlapi_keyc                 C   s   | d| _|| _dS )a  
        Initialize the TeamsManagementClient.

        Args:
            base_url (str): The base URL of the LiteLLM proxy server (e.g., "http://localhost:4000")
            api_key (Optional[str]): API key for authentication. If provided, it will be sent as a Bearer token.
        /N)rstrip	_base_url_api_key)selfr
   r    r   Q/home/app/Keep/.python/lib/python3.10/site-packages/litellm/proxy/client/teams.py__init__   s   
zTeamsManagementClient.__init__returnc                 C   s"   ddi}| j rd| j  |d< |S )z
        Get the headers for API requests, including authorization if api_key is set.

        Returns:
            Dict[str, str]: Headers to use for API requests
        zContent-Typezapplication/jsonzBearer Authorization)r   )r   headersr   r   r   _get_headers   s   z"TeamsManagementClient._get_headersuser_idorganization_idc                 C   s^   | j  d}i }|r||d< |r||d< tj||  |d}|jdkr'td|  | S )a  
        List teams that the user belongs to.

        Args:
            user_id (Optional[str]): Only return teams which this user belongs to
            organization_id (Optional[str]): Only return teams which belong to this organization

        Returns:
            List[Dict[str, Any]]: List of team objects

        Raises:
            requests.exceptions.HTTPError: If the request fails
            UnauthorizedError: If authentication fails
        z
/team/listr   r   r   params  *Authentication failed. Check your API key.r   requestsgetr   status_coder   raise_for_statusjson)r   r   r   urlr   responser   r   r   list$   s   
zTeamsManagementClient.listr   
   ascteam_id
team_aliaspage	page_sizesort_by
sort_orderc	                 C   s   | j  d}	|||d}
|r||
d< |r||
d< |r||
d< |r$||
d< |r*||
d< tj|	|  |
d}|jd	kr=td
|  | S )a  
        Get a paginated list of teams with filtering and sorting options.

        Args:
            user_id (Optional[str]): Only return teams which this user belongs to
            organization_id (Optional[str]): Only return teams which belong to this organization
            team_id (Optional[str]): Filter teams by exact team_id match
            team_alias (Optional[str]): Filter teams by partial team_alias match
            page (int): Page number for pagination
            page_size (int): Number of teams per page
            sort_by (Optional[str]): Column to sort by (e.g. 'team_id', 'team_alias', 'created_at')
            sort_order (str): Sort order ('asc' or 'desc')

        Returns:
            Dict[str, Any]: Paginated response containing teams and pagination info

        Raises:
            requests.exceptions.HTTPError: If the request fails
            UnauthorizedError: If authentication fails
        z/v2/team/list)r+   r,   r.   r   r   r)   r*   r-   r   r   r   r   )r   r   r   r)   r*   r+   r,   r-   r.   r$   r   r%   r   r   r   list_v2F   s(   
zTeamsManagementClient.list_v2c                 C   s@   | j  d}tj||  d}|jdkrtd|  | S )a   
        Get list of available teams that the user can join.

        Returns:
            List[Dict[str, Any]]: List of available team objects

        Raises:
            requests.exceptions.HTTPError: If the request fails
            UnauthorizedError: If authentication fails
        z/team/available)r   r   r   r   )r   r$   r%   r   r   r   get_available   s   
z#TeamsManagementClient.get_available)N)NN)NNNNr   r'   Nr(   )__name__
__module____qualname____doc__strr   r   r   r   r   r   r&   intr/   r0   r   r   r   r   r	   
   sR    
$	


9r	   )r4   typingr   r   r   r   r   r   
exceptionsr   r	   r   r   r   r   <module>   s
    