
    AHj                     L    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      Z
y)z*Teams management client for LiteLLM proxy.    )AnyDictListOptionalUnionN   )UnauthorizedErrorc                       e Zd ZdZddedee   fdZdeeef   fdZ	 	 ddee   d	ee   de	eee
f      f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Zde	eee
f      fdZy)TeamsManagementClientz+Client for managing teams in LiteLLM proxy.Nbase_urlapi_keyc                 >    |j                  d      | _        || _        y)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   s      R/root/tools/cai/cai_env/lib/python3.12/site-packages/litellm/proxy/client/teams.py__init__zTeamsManagementClient.__init__   s     "-    returnc                 J    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   headerss     r   _get_headersz"TeamsManagementClient._get_headers   s0     "#56==)0'@GO$r   user_idorganization_idc                     | j                    d}i }|r||d<   |r||d<   t        j                  || j                         |      }|j                  dk(  rt        d      |j                          |j                         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    responses         r   listzTeamsManagementClient.list$   s    &  
+ 'F9(7F$%<<T->->-@P3&#$PQQ!!#}}r   team_id
team_aliaspage	page_sizesort_by
sort_orderc	                 2   | j                    d}	|||d}
|r||
d<   |r||
d<   |r||
d<   |r||
d<   |r||
d<   t        j                  |	| j                         |
      }|j                  d	k(  rt        d
      |j                          |j                         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/   r1   r   r   r,   r-   r0   r   r!   r"   r#   )r   r   r   r,   r-   r.   r/   r0   r1   r)   r    r*   s               r   list_v2zTeamsManagementClient.list_v2F   s    >  ."$.
  'F9(7F$% 'F9#-F<  'F9<<T->->-@P3&#$PQQ!!#}}r   c                     | j                    d}t        j                  || j                               }|j                  dk(  rt        d      |j                          |j                         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*   s      r   get_availablez#TeamsManagementClient.get_available   s`      0<<T->->-@A3&#$PQQ!!#}}r   )N)NN)NNNNr   
   Nasc)__name__
__module____qualname____doc__strr   r   r   r   r   r   r+   intr3   r5    r   r   r   r   
   s   5	  	 x} 	 
d38n 
 "&)- #  "#  
d38n		 H "&)-!%$(!%7#7 "#7 #	7
 SM7 7 7 #7 7 
c3h7rtDcN3 r   r   )r;   typingr   r   r   r   r   r$   
exceptionsr	   r   r>   r   r   <module>rA      s     0 3 3  )H Hr   