o
    i                     @   sp   d dl Z d dlmZ d dlmZmZmZ d dlmZ d dl	m
Z
 d dlmZ eG dd dZG d	d
 d
ZdS )    N)	dataclass)AnyDictOptional)logger)_API)AgentStartErrorc                   @   sR   e Zd ZU dZdZeeeef  e	d< dZ
ee e	d< dZeeeef  e	d< dS )SessionParamsa  Parameters for configuring a Pipecat Cloud agent session.

    Args:
        data: Optional dictionary of data to pass to the agent.
        use_daily: If True, creates a Daily WebRTC room for the session.
        daily_room_properties: Optional dictionary of properties to configure the Daily room.
            Only used when use_daily=True. See Daily.co API documentation for available properties:
            https://docs.daily.co/reference/rest-api/rooms/config
    NdataF	use_dailydaily_room_properties)__name__
__module____qualname____doc__r
   r   r   strr   __annotations__r   boolr    r   r   H/home/ubuntu/.local/lib/python3.10/site-packages/pipecatcloud/session.pyr	      s
   
 
r	   c                   @   s6   e Zd ZdZ	d
dededee fddZdd	 ZdS )Sessiona  Client for starting and managing Pipecat Cloud agent sessions.

    This class provides methods to start agent sessions and interact with running agents.

    Args:
        agent_name: Name of the deployed agent to interact with.
        api_key: Public API key for authentication.
        params: Optional SessionParams object to configure the session.

    Raises:
        ValueError: If agent_name is not provided.
    N
agent_nameapi_keyparamsc                 C   s*   || _ || _| j std|pt | _d S )NzAgent name is required)r   r   
ValueErrorr	   r   )selfr   r   r   r   r   r   __init__0   s
   zSession.__init__c                    s   | j stdddtd| j  t }d}| jjdur2t| jjt	r.t
| jj}n| jj}d}| jjrO| jjrOt| jjt	rKt
| jj}n| jj}|j| j| j t| jj||dI dH \}}|rkt|d|S )a~  Start a new session with the specified agent.

        Initiates a new agent session with the configuration provided during initialization.
        If use_daily is True, creates a Daily room for WebRTC communication.

        Returns:
            dict: Response data containing session information. If use_daily is True,
                  includes 'dailyRoom' URL and 'dailyToken' for room access.

        Raises:
            AgentStartError: If the session fails to start, including:
                - Missing API key
                - Agent not found
                - Agent not ready
                - Capacity limits reached
        zPCC-1002zNo API key provided)codeerrorzStarting agent N)r   r   r   r
   daily_properties)r   )r   r   r   debugr   r   r   r
   
isinstancedictjsondumpsr   r   start_agentr   )r   api
data_paramdaily_properties_paramresultr   r   r   r   start>   s2   

zSession.start)N)	r   r   r   r   r   r   r	   r   r*   r   r   r   r   r   "   s    
r   )r#   dataclassesr   typingr   r   r   logurur   pipecatcloud.apir   pipecatcloud.exceptionr   r	   r   r   r   r   r   <module>   s   