
    qil(                     P   d Z ddlZddlZddlZddlmZmZmZ ddlZddl	m
Z
 ddlmZ ddlmZmZmZmZmZmZ  G d de      Zdd	d	dd
ddddd	dej*                  dee   dee   dee   dee   dee   dee   deeeee   f      dee   ded   defdZddej*                  fdZy)a  Daily room and token configuration utilities.

This module provides helper functions for creating and configuring Daily rooms
and authentication tokens. It automatically creates temporary rooms for
development or uses existing rooms specified via environment variables.

Functions:

- configure(): Create a standard or SIP-enabled Daily room, returning a DailyRoomConfig object.

Environment variables:

- DAILY_API_KEY - Daily API key for room/token creation (required)
- DAILY_ROOM_URL (optional) - Existing room URL to use. If not provided,
  a temporary room will be created automatically.

Example::

    import aiohttp
    from pipecat.runner.daily import configure

    async with aiohttp.ClientSession() as session:
        # Standard room
        room_url, token = await configure(session)

        # SIP-enabled room for phone calls
        config = await configure(session, sip_caller_phone="+15551234567")
        # config contains: room_url, token, sip_endpoint
    N)DictListOptional)logger)	BaseModel)DailyMeetingTokenParamsDailyMeetingTokenPropertiesDailyRESTHelperDailyRoomParamsDailyRoomPropertiesDailyRoomSipParamsc                   @    e Zd ZU dZeed<   eed<   dZee   ed<   d Zy)DailyRoomConfiga   Configuration returned when creating a Daily room.

    Parameters:
        room_url: The Daily room URL for joining the meeting.
        token: Authentication token for the bot to join the room.
        sip_endpoint: SIP endpoint URI for phone connections (None for standard rooms).
    room_urltokenNsip_endpointc              #   D   K   | j                    | j                   yw)zwEnable tuple unpacking for backward compatibility.

        Allows: room_url, token = await configure(session)
        Nr   r   )selfs    F/opt/pipecat/venv/lib/python3.12/site-packages/pipecat/runner/daily.py__iter__zDailyRoomConfig.__iter__E   s     
 mmjjs    )	__name__
__module____qualname____doc__str__annotations__r   r   r        r   r   r   8   s&     MJ"&L(3-&r   r          @F   )	api_keyroom_exp_durationtoken_exp_durationsip_caller_phonesip_enable_videosip_num_endpoints
sip_codecsroom_propertiestoken_propertiesaiohttp_sessionr"   r#   r$   r%   r&   r'   r(   r)   r*   r	   returnc       	   	      F  K   |xs t        j                  d      }|st        d      |7t        |dk7  |dk7  |du|du|dk7  |dug      }
|
rt	        j
                  d       |du}|r|j                  rd}t        |t        j                  d	d
      |       }t        j                  d      }|r]|s[t	        j                  d|        |}|dz  dz  }d}|	rt        |	      }|j                  |||       d{   }t        ||      S |rdnd}| dt        j                         j                  dd  }t	        j                  d|        |Rt        j                         |dz  dz  z   }t!        |d      }|r&t#        ||d||      }||_        d|_        | |_        t)        ||      }	 |j+                  |       d{   }|j,                  }t	        j                  d|        |dz  dz  }d}|	rt        |	      }|j                  |||       d{   }|r<|j.                  j0                  }t	        j                  d|        t        |||      S t        ||      S 7 t7 7 T# t        $ r }d| }t	        j2                  |        d}~ww xY ww)a  Configure Daily room URL and token with optional SIP capabilities.

    This function will either:
    1. Use an existing room URL from DAILY_ROOM_URL environment variable (standard mode only)
    2. Create a new temporary room automatically if no URL is provided

    Args:
        aiohttp_session: HTTP session for making API requests.
        api_key: Daily API key.
        room_exp_duration: Room expiration time in hours.
        token_exp_duration: Token expiration time in hours.
        sip_caller_phone: Phone number or identifier for SIP display name.
            When provided, enables SIP functionality and returns SipRoomConfig.
        sip_enable_video: Whether video is enabled for SIP.
        sip_num_endpoints: Number of allowed SIP endpoints.
        sip_codecs: Codecs to support for audio and video. If None, uses Daily defaults.
            Example: {"audio": ["OPUS"], "video": ["H264"]}
        room_properties: Optional DailyRoomProperties to use instead of building from
            individual parameters. When provided, this overrides room_exp_duration and
            SIP-related parameters. If not provided, properties are built from the
            individual parameters as before.
        token_properties: Optional DailyMeetingTokenProperties to customize the meeting
            token. When provided, these properties are passed to the token creation API.
            Note that room_name, exp, and is_owner will be set automatically.

    Returns:
        DailyRoomConfig: Object with room_url, token, and optional sip_endpoint.
        Supports tuple unpacking for backward compatibility: room_url, token = await configure(session)

    Raises:
        Exception: If DAILY_API_KEY is not provided in environment variables.

    Examples::

        # Standard room
        room_url, token = await configure(session)

        # SIP-enabled room
        sip_config = await configure(session, sip_caller_phone="+15551234567")
        print(f"SIP endpoint: {sip_config.sip_endpoint}")

        # Custom room properties with recording enabled
        custom_props = DailyRoomProperties(
            enable_recording="cloud",
            max_participants=2,
        )
        config = await configure(session, room_properties=custom_props)
    DAILY_API_KEYzkDAILY_API_KEY environment variable is required. Get your API key from https://dashboard.daily.co/developersNr    Fr!   zBoth room_properties and individual parameters (room_exp_duration, token_exp_duration, sip_*) were provided. The room_properties will be used and individual parameters will be ignored.TDAILY_API_URLzhttps://api.daily.co/v1)daily_api_keydaily_api_urlr+   DAILY_ROOM_URLzUsing existing Daily room: <   )
properties)paramsr   zpipecat-sippipecat-   zCreating new Daily room: )expeject_at_room_expzdial-in)display_namevideosip_modenum_endpointscodecs)namer4   zCreated Daily room: zSIP endpoint: )r   r   r   zError creating Daily room: )osgetenv	Exceptionanyr   warningsipr
   infor   	get_tokenr   uuiduuid4hextimer   r   enable_dialoutstart_video_offr   create_roomurlconfigr   error)r+   r"   r#   r$   r%   r&   r'   r(   r)   r*   individual_params_providedsip_enableddaily_rest_helperexisting_room_urlr   expiry_timetoken_paramsr   room_prefix	room_nameexpiration_time
sip_paramsroom_paramsroom_responsetoken_expiry_secondsr   e	error_msgs                               r   	configurerb   N   s    | 3?3GJ
 	
 "%(!S("c) , -!Q&$&	&
" &NN# #$.K ?..'ii1JK' 		"2312C1DEF$ 0"4r92>NOL'11(KP\1]]>> $/-IK-q!1!1"1!5 67I
KK+I;78 ))+):R)?")DE ."
 +-&"/!J #-O-1O*2B.BO+ "y_MK/;;KHH $$*8*56  2B6;2>NOL'11*< 2 
 
 (//<<LKK.78"!)  #HEBB{ ^H I
$  1!5	Ysi   C8J!:I.;B6J!2I5 I1AI5 I3AI5  J!!I5 -J!1I5 3I5 5	J>JJJ!c                    K   ddl }|j                         5  |j                  d       |j                  dt        d       ddd       t        |        d{   \  }}||dfS # 1 sw Y   $xY w7 w)a  Configure Daily room with command-line argument parsing.

    .. deprecated:: 0.0.78
        This function is deprecated. Use configure() instead which uses
        environment variables only.

    Args:
        aiohttp_session: HTTP session for making API requests.
        parser: Ignored. Kept for backwards compatibility.

    Returns:
        Tuple containing room URL, authentication token, and None (for args).
    r   Nalwaysz;configure_with_args is deprecated. Use configure() instead.   )
stacklevel)warningscatch_warningssimplefilterwarnDeprecationWarningrb   )r+   parserrg   r   r   s        r   configure_with_argsrm     sy      		 	 	" 
h'I 	 	

 &o66OHeeT""
 
 7s(   A2*A$A2A0A2$A-)A2)N)r   rA   rL   rI   typingr   r   r   aiohttplogurur   pydanticr   pipecat.transports.daily.utilsr   r	   r
   r   r   r   r   ClientSessionr   floatboolintrb   rm   r   r   r   <module>rw      s#  < 
   ' '    i 2 "),*-&*','(1559@Ds**s c]s  	s
 !s sms tns  }s c49n-.s 12s <=s sn#w/D/D #r   