o
    i5                     @   sb   d dl Z d dlmZ d dlmZmZmZmZmZ ddl	m
Z
 ddlmZ dZ	 G dd de
ZdS )	    N)Optional)CreateAgentDispatchRequestAgentDispatchDeleteAgentDispatchRequestListAgentDispatchRequestListAgentDispatchResponse   )Service)VideoGrantsAgentDispatchServicec                       s   e Zd ZdZdejdededef fddZded	e	fd
dZ
deded	e	fddZded	ee	 fddZdeded	ee	 fddZ  ZS )r   a  Manage agent dispatches. Service APIs require roomAdmin permissions.

    Recommended way to use this service is via `livekit.api.LiveKitAPI`:

    ```python
    from livekit import api
    lkapi = api.LiveKitAPI()
    agent_dispatch = lkapi.agent_dispatch
    ```
    sessionurlapi_key
api_secretc                    s   t  |||| d S )N)super__init__)selfr   r   r   r   	__class__ d/var/www/html/livekit_bhavya/venv/lib/python3.10/site-packages/livekit/api/agent_dispatch_service.pyr      s   zAgentDispatchService.__init__reqreturnc                    s,   | j td|| td|jdtI dH S )aS  Create an explicit dispatch for an agent to join a room.

        To use explicit dispatch, your agent must be registered with an `agentName`.

        Args:
            req (CreateAgentDispatchRequest): Request containing dispatch creation parameters

        Returns:
            AgentDispatch: The created agent dispatch object
        CreateDispatchT
room_adminroomN)_clientrequestSVC_auth_headerr
   r   r   )r   r   r   r   r   create_dispatch    s   
z$AgentDispatchService.create_dispatchdispatch_id	room_namec                    s2   | j tdt||d| td|dtI dH S )a  Delete an explicit dispatch for an agent in a room.

        Args:
            dispatch_id (str): ID of the dispatch to delete
            room_name (str): Name of the room containing the dispatch

        Returns:
            AgentDispatch: The deleted agent dispatch object
        DeleteDispatchr"   r   Tr   N)r   r   r   r   r    r
   r   )r   r"   r#   r   r   r   delete_dispatch3   s   

z$AgentDispatchService.delete_dispatchc                    s:   | j tdt|d| td|dtI dH }t|jS )zList all agent dispatches in a room.

        Args:
            room_name (str): Name of the room to list dispatches from

        Returns:
            list[AgentDispatch]: List of agent dispatch objects in the room
        ListDispatch)r   Tr   N)	r   r   r   r   r    r
   r   listagent_dispatches)r   r#   resr   r   r   list_dispatchH   s   	

z"AgentDispatchService.list_dispatchc                    sN   | j tdt||d| td|dtI dH }t|jdkr%|jd S dS )a+  Get an Agent dispatch by ID

        Args:
            dispatch_id (str): ID of the dispatch to retrieve
            room_name (str): Name of the room containing the dispatch

        Returns:
            Optional[AgentDispatch]: The requested agent dispatch object if found, None otherwise
        r'   r%   Tr   Nr   )	r   r   r   r   r    r
   r   lenr)   )r   r"   r#   r*   r   r   r   get_dispatchZ   s   



z!AgentDispatchService.get_dispatch)__name__
__module____qualname____doc__aiohttpClientSessionstrr   r   r   r!   r&   r(   r+   r   r-   __classcell__r   r   r   r   r      s     ")r2   typingr   livekit.protocol.agent_dispatchr   r   r   r   r   _servicer	   access_tokenr
   r   r   r   r   r   r   <module>   s    