
    qi                     @    d Z ddlmZmZ ddlZddlmZ  G d d      Zy)zLemonSlice API utilities for session management.

This module provides helper classes for interacting with the LemonSlice API,
including session creation and termination.
    )AnyOptionalN)loggerc                       e Zd ZdZdZdedej                  fdZddddddddde	e   d	e	e   d
e	e   de	e
   de	e   de	e   de	eeef      defdZdedefdZy)LemonSliceApizHelper class for interacting with the LemonSlice API.

    Provides methods for creating and managing sessions with LemonSlice avatars.
    z*https://lemonslice.com/api/liveai/sessionsapi_keysessionc                 H    || _         || _        d| j                   d| _        y)zInitialize the LemonSliceApi client.

        Args:
            api_key: LemonSlice API key for authentication.
            session: An aiohttp session for making HTTP requests.
        zapplication/json)zContent-Typez	x-api-keyN)_api_key_session_headers)selfr   r	   s      S/opt/pipecat/venv/lib/python3.12/site-packages/pipecat/transports/lemonslice/api.py__init__zLemonSliceApi.__init__   s"      );$--X    N)agent_image_urlagent_idagent_promptidle_timeoutdaily_room_urldaily_token
propertiesr   r   r   r   r   r   r   returnc                n  K   |s|st        j                  d       d}|r|rt        d      t        j                  d| d|        ddi}|||d	<   |||d
<   |||d<   |||d<   |rt        |      ni }	|||	d<   |||	d<   |	r|	|d<   | j                  j                  | j                  | j                  |      4 d{   }
|
j                          |
j                          d{   }t        j                  d|        |cddd      d{    S 7 W7 17 	# 1 d{  7  sw Y   yxY ww)uc  Create a new session with the specified agent_id or agent_image_url.

        Args:
            agent_image_url: The URL to an agent image. Provide either agent_id or agent_image_url.
            agent_id: ID of a LemonSlice agent. Provide either agent_id or agent_image_url.
            agent_prompt: A high-level system prompt that subtly influences the avatar’s movements, expressions, and emotional demeanor.
            idle_timeout: Idle timeout in seconds.
            daily_room_url: Daily room URL to use for the session.
            daily_token: Daily token for authenticating with the room.
            properties: Additional properties to pass to the session.

        Returns:
            Dictionary containing session_id, room_url, and control_url.

        Raises:
            ValueError: If neither agent_id nor agent_image_url is provided.
        z<No agent_id or agent_image_url provided, using default agentagent_080308d8b6e99f47z<Provide exactly one of agent_id or agent_image_url, not bothz&Creating LemonSlice session: agent_id=z, agent_image_url=transport_typedailyNr   r   r   r   	daily_urlr   r   headersjsonzCreated LemonSlice session: )
r   debug
ValueErrordictr   postLEMONSLICE_URLr   raise_for_statusr!   )r   r   r   r   r   r   r   r   payloadproperties_dictrresponses               r   create_sessionzLemonSliceApi.create_session&   sg    8 LLWX/H[\\4XJ>PQ`Pab	
 '7%@"*GJ&)8G%&#&2GN##&2GN#>H$z*:b%+9OK("-8OM*$3GL!==%%W & 
 	 	 VVX~HLL7zBC	 	 	 &		 	 	 	sZ   C D5DD5$D *D+D D5DD5D D5 D2&D)'D2.D5
session_idcontrol_urlc                   K   ddi}| j                   j                  || j                  |      4 d{   }|j                          t	        j
                  d|        ddd      d{    y7 =7 # 1 d{  7  sw Y   yxY ww)zEnd an existing session.

        Args:
            session_id: ID of the session to end.
            control_url: The control URL from the create_session response.
        event	terminater   NzEnded LemonSlice session )r   r%   r   r'   r   r"   )r   r-   r.   r(   r*   s        r   end_sessionzLemonSliceApi.end_sessiond   s      K(==%%k4==w%W 	C 	C[\ LL4ZLAB	C 	C 	C 	C 	C 	C 	CsD   1B
A1B
)A5 B
+A3,B
3B
5B;A><BB
)__name__
__module____qualname____doc__r&   straiohttpClientSessionr   r   intr$   r   r,   r2    r   r   r   r      s    
 BN	Y 	Yg.C.C 	Y *."&&*&*(,%)/3< "#< 3-	<
 sm< sm< !< c]< T#s(^,< 
<|
CC 
Cc 
Cr   r   )r6   typingr   r   r8   logurur   r   r;   r   r   <module>r>      s#    !  [C [Cr   