
    %i5                     h    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e
      Zy)	    N)Optional)CreateAgentDispatchRequestAgentDispatchDeleteAgentDispatchRequestListAgentDispatchRequestListAgentDispatchResponse   )Service)VideoGrantsAgentDispatchServicec                        e Zd ZdZdej
                  dededef fdZdede	fd	Z
d
edede	fdZdedee	   fdZd
ededee	   fdZ x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                 *    t         |   ||||       y )N)super__init__)selfr   r   r   r   	__class__s        \/var/www/html/engine/venv/lib/python3.12/site-packages/livekit/api/agent_dispatch_service.pyr   zAgentDispatchService.__init__   s    #w
;    reqreturnc                    K   | j                   j                  t        d|| j                  t	        d|j
                              t               d{   S 7 w)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   s     r   create_dispatchz$AgentDispatchService.create_dispatch    sN      \\))kTIJ
 
 	
 
s   AAAAdispatch_id	room_namec                    K   | j                   j                  t        dt        ||      | j	                  t        d|            t               d{   S 7 w)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&   s      r   delete_dispatchz$AgentDispatchService.delete_dispatch3   sW      \\))&' kT	JK	
 	
 		
 	
s   AAAAc                    K   | j                   j                  t        dt        |      | j	                  t        d|            t               d{   }t        |j                        S 7 w)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&   ress      r   list_dispatchz"AgentDispatchService.list_dispatchH   s_      LL(($)4kT	JK%
 
 C(())
s   AA-A+A-c                   K   | j                   j                  t        dt        ||      | j	                  t        d|            t               d{   }t        |j                        dkD  r|j                  d   S y7 ,w)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/   s       r   get_dispatchz!AgentDispatchService.get_dispatchZ   sw      LL(($9MkT	JK%
 
 s##$q(''**
s   ABA?-B)__name__
__module____qualname____doc__aiohttpClientSessionstrr   r   r   r$   r*   r-   r0   r   r3   __classcell__)r   s   @r   r   r      s    	< 5 5 <C <# <[^ <
)C 
 
&
 
 
 
**S *T-5H *$c c h}F] r   )r8   typingr   livekit.protocol.agent_dispatchr   r   r   r   r   _servicer
   access_tokenr   r"   r    r   r   <module>rA      s3        % \7 \r   