o
    i                     @   s   d dl Z d dlZd dlmZmZ d dlZd dlmZmZ d dl	m
Z
 d dlmZmZ d dlmZ ddd	d
ZeG dd dZeG dd dZeG dd dZdee fddZdedefddZdS )    N)CallableOptional)	dataclassfield)logger)KRISP_VIVA_MODELSKrispVivaAudioFilter)ConfigFileErrorz[dim]Waiting[/dim]z[green]Ready[/green]z[yellow]Creating[/yellow])UnknownTrueFalsec                   @   sv   e Zd ZU dZee ed< dZee ed< edddidZ	ee ed< edddidZ
ee ed	< d
d Zdd ZdS )ScalingParamsr   
min_agentsN
max_agents
deprecatedT)defaultmetadatamin_instancesmax_instancesc                 C   s   | j d urtd | j | _| jd urtd | j| _| jd ur*| jdk r*td| jd urG| jdk r8td| jd urI| j| jk rKtdd S d S d S )Nz3min_instances is deprecated, use min_agents insteadz3max_instances is deprecated, use max_agents insteadr   z-min_agents must be greater than or equal to 0   z!max_agents must be greater than 0z6max_agents must be greater than or equal to min_agents)r   r   warningr   r   r   
ValueErrorself r   T/home/ubuntu/.local/lib/python3.10/site-packages/pipecatcloud/_utils/deploy_utils.py__attrs_post_init__"   s    







z!ScalingParams.__attrs_post_init__c                 C   s   | j | jdS )Nr   r   r   r   r   r   r   to_dict8   s   zScalingParams.to_dict)__name__
__module____qualname__r   r   int__annotations__r   r   r   r   r   r   r   r   r   r   r      s   
 r   c                   @   s.   e Zd ZU dZee ed< dd Zdd ZdS )KrispVivaConfigNaudio_filterc                 C   s4   | j d ur| j tvrtdt d| j  dd S d S )Nzaudio_filter must be one of z, got '')r%   r   r   r   r   r   r   r   @   s   

z#KrispVivaConfig.__attrs_post_init__c                 C   s
   d| j iS )Nr%   )r%   r   r   r   r   r   I   s   
zKrispVivaConfig.to_dict)	r   r    r!   r%   r   r   r#   r   r   r   r   r   r   r$   <   s   
 	r$   c                   @   s   e Zd ZU dZee ed< dZee ed< dZee ed< dZ	ee ed< dZ
ee ed< e Zeed< dZeed	< dZeed
< eedZeed< dZee ed< eedZeed< dd Zdd ZdS )DeployConfigParamsN
agent_nameimageimage_credentials
secret_setregionscalingFenable_krispenable_managed_keys)factorydocker_configagent_profile
krisp_vivac                 C   s$   | j d urd| j vrtdd S d S )N:z4Provided image must include tag e.g. my-image:latest)r)   r   r   r   r   r   r   [   s   z&DeployConfigParams.__attrs_post_init__c                 C   sR   | j | j| j| j| j| jr| j nd | j| j| j	| j
| jr%| j dS d dS )N)r(   r)   r*   r+   r,   r-   r.   r/   r1   r2   r3   )r(   r)   r*   r+   r,   r-   r   r.   r/   r1   r2   r3   r   r   r   r   r   _   s   zDeployConfigParams.to_dict)r   r    r!   r(   r   strr#   r)   r*   r+   r,   r   r-   r.   boolr/   r   dictr1   r2   r$   r3   r   r   r   r   r   r   r'   M   s   
 r'   returnc               
   C   s<  ddl m}  td|   tdtj|   zt| d}t	|}W d    n1 s0w   Y  W n
 t
y@   Y d S w zE|di }tdi |}|di }|di }tdi |}tdi ||||d	}h d
}	t| |	 }
|
rtd|
 |W S  t
y } zt| tt|d }~ww )Nr   )deploy_config_pathzDeploy config path: zDeploy config path exists: rr-   dockerr3   )r-   r1   r3   >   r)   r;   r,   r-   r(   r3   r+   r.   r2   r*   r/   z Unexpected keys in config file: r   )pipecatcloud.cli.configr9   r   debugospathexistsopentomlload	Exceptionpopr   r$   r'   setkeysr	   r5   )r9   fconfig_datascaling_datascaling_paramsdocker_datakrisp_viva_datakrisp_viva_configvalidated_configexpected_keysunexpected_keyser   r   r   load_deploy_config_fileo   sD   

rS   funcc                    s   t   fdd}|S )z
    Decorator that loads the deploy config file and injects it into the function.
    If the config file exists, it will be loaded and passed to the function as `deploy_config`.
    c               
      sV   z	t  }||d< W n ty# } ztd|  tt|d }~ww  | i |S )Ndeploy_configzError loading deploy config: )rS   rD   r   errorr	   r5   )argskwargsrU   rR   rT   r   r   wrapper   s   z#with_deploy_config.<locals>.wrapper)	functoolswraps)rT   rZ   r   rY   r   with_deploy_config   s   	r]   )r[   r>   typingr   r   rB   attrr   r   logurur   pipecatcloud.constantsr   r   pipecatcloud.exceptionr	   DEPLOY_STATUS_MAPr   r$   r'   rS   r]   r   r   r   r   <module>   s(   "!9