o
    iPN                     @   s  d dl Z d dlmZ d dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZmZmZmZ d dlmZmZ d dlmZ d dl m!Z! d dl"m#Z# d dl$m%Z%m&Z& dZ'dZ(ddede)fddZ*dej+fddZ,dS )    N)Optional)logger)Group)Live)Panel)Table)Text)synchronizer)requires_login)console)DeployConfigParamsKrispVivaConfigScalingParamswith_deploy_config)get_region_codesvalidate_region)PIPECAT_CLI_NAME)API)config)KRISP_VIVA_MODELSRegion      Fparamsforcec              
      s  d}t tjdddddM}tj| j||dI d H \}}|r/|  tdW  d    S |rTd}|sT|  tj	d	| j d
ddsTt
  t W  d    S W d    n1 s^w   Y  t tjddddd}	 | jr|td| j d tj| j||dI d H \}}|rt W  d    S |s|  td| j d| d t W  d    S 	 | jr
|td| j d t j| j||dI d H \}}|r|ddkrd}nt  t W  d    S |s
|  td| j d| d |td|rdnd d| j d tj| |||dI d H \}	}|r;t W  d    S |sU|	sU|  td t W  d    S |  W d    n	1 sdw   Y  	 d }
d}d}td|rxdnd d | j d! d"}tj|d#d}z|tk rDtd$ tj| j|d dI d H \}}td%|  |d&g }|rt|dkr|  |d }d|v rd'|v rt|d( ntd)|  t W W  d    S |r|  td* t W W  d    S |
s|d+r|d+ }
d,|
 d-}|| |d.|d/d}|d0d}|r3|r3d}nttI d H  |d7 }|tk sW n tyc   |  td1 t  Y W  d    S w W d    n	1 sow   Y  |rtd2}d3}|sd4}|d5t d67 }tj d7| j d8t d9| j d:| |rd;nd< d=d> t S td?tt  d@t dA| j dB t S )CNFz4[dim]Checking for existing agent deployment...[/dim]dots)spinnerT)	transient)
agent_nameorglive   zDeployment for agent 'zU' exists. Do you want to update it? Note: this will not interrupt any active sessionsdefaultz[dim]Preparing deployment...z[dim]Verifying secret set z exists...[/dim])
secret_setr   r    zSecret set [bold]'z''[/bold] not found in namespace [bold]'z'[/bold]z![dim]Verifying image pull secret code400z#Image pull secret with name [bold]'z[dim]UpdatingPushingz! agent manifest for[/dim] [cyan]'z'[/cyan])deploy_configupdater   r    z<A problem occured during deployment. Please contact support.r   z[bold cyan]z#[/bold cyan] deployment for agent ''z4[dim]Waiting for deployment to become ready...[/dim]bouncingBarzPolling for deployment statuszDeployment status: errorsmessagezAgent deployment failedz)Deployment failed with an unknown error: z Error checking deployment statusactiveDeploymentIdz<[dim]Waiting for deployment to become ready (deployment ID: z
)...[/dim]	availablereadyactiveDeploymentReadyz]
[yellow]Deployment monitoring interrupted. The deployment may still be in progress.[/yellow]default_public_key z

[yellow]Note: if you have not already created a public API key (required to start a session), you can do so by running:
[/yellow]z[bold yellow]`z) organizations keys create`[/bold yellow]zAgent deployment [bold]'zY'[/bold] is ready

[white]Start a session with your new agent by running:
[/white][bold]`z agent start z`[/bold]Update
Deploymentz	 complete)title_extraz,Deployment did not enter ready state within z" seconds. Please check logs with `z agent logs `)!r   r   statusr   agentr   stoptyperExitconfirmcancelr$   r*   secrets_listerrorimage_credentialsbubble_errorgetprint_errordeployprintMAX_ALIVE_CHECKSr   debuglen	api_errorasynciosleepALIVE_CHECK_SLEEPKeyboardInterruptr   r   success)r   r   r   existing_agentr    datarA   secrets_existcreds_existresultactive_deployment_idis_readychecks_performeddeployment_status_messager9   agent_statusstatus_errorserror_messager0   deployment_readypublic_api_keyextra_message r`   T/home/ubuntu/.local/lib/python3.10/site-packages/pipecatcloud/cli/commands/deploy.py_deploy'   sL  
 ,?

EG





5
7>


rb   appc              %   C   s  | j dddtjtttjd ddtjd dddtjd d	ddtjd d
dddddtjd ddddddtjd dddddddtjd dddddtjd ddd ddtjdd!d"d#ddtjdd$d%ddtjd d&d'd(t	 d)ddtjd d*d+d,ddtjd d-d.d/ddtjdd0d1d2d3dtjdd4d5d6d3dtjd d7d8ddd9tjd d:d;dddd<fd=t
d>t
d?t
d@tdAtdBt
dCt
dDtdEtdFt
dGt
dHtt dItdJtdKtdLtf dMdN}|S )ONrF   zDeploy agent to Pipecat Cloud)namehelpT)hiddenz+Name of the agent to deploy e.g. 'my-agent'F)re   show_defaultz,Docker image location e.g. 'my-image:latest'z--credentialsz-cz'Image pull secret to use for deploymentzDeployment Configuration)re   rich_help_panelrg   z--min-agentsz-minz%Minimum number of agents to keep warmr   )re   rh   minz--max-agentsz-maxz Maximum number of allowed agentsr!   2   )re   rh   ri   maxz	--secretsz-sz Secret set to use for deployment)re   rh   z--organizationz-ozOrganization to deploy toz--enable-krispz-krispz`[DEPRECATED] Enable Krisp integration for this deployment. Use --krisp-viva-audio-filter insteadz--enable-managed-keysz'Enable Managed Keys for this deploymentz--krisp-viva-audio-filterz+Enable Krisp VIVA with audio filter model (z or )z	--profilez-pz#Agent profile to use for deploymentz--regionz-rzRegion for service deploymentz--forcez-fz$Force deployment / skip confirmationzAdditional Optionsz--no-credentialsz-ncz0Deployment will not require an image pull secretz--min-instancesz%[Deprecated] Use --min-agents instead)re   rf   ri   z--max-instancesz%[Deprecated] Use --max-agents instead)re   rf   ri   rk   r   imagecredentials
min_agents
max_agentsr$   organizationkrispmanaged_keyskrisp_viva_audio_filterprofileregionskip_confirmno_credentialsmin_instancesmax_instancesc                    s  |d urt d |}|d urt d |}|rt d |p$td}| p)t }|p.|j|_|p4|j|_|p:|j|_|p@|j|_t	|d urI|n|j
j|d urR|n|j
jd|_
|p]|j|_|	pc|j|_|pi|j|_|po|j}||_|rt|I d H st I d H }td| dd|  td	S |
d urt|
d
|_|jstd t S |jstd t S |s|js|stjdddd t S tddddd}|jddd |jddd |dt|j
j |j
jr|dt|j
j n|dd |jrd|j d}nt|I d H \}}|rt S d|d  d }t d!|j dd"|j dd#| dd$| d%|jsAd&nd'|j d  d(|jsPd&nd|j d  d)|js_d&nd|j d  d*|jsnd+nd, d-|jj!syd+nd.|jj! d/  d0|jsd+nd, d1|g|j
jrt"d2|j
j d3d4dgnt"d5d4dgR  }t#t$|d6d7d8d9 |stj%d:dd;st&  t' S t(|||I d H  d S )<Nz3min_instances is deprecated, use min_agents insteadz3max_instances is deprecated, use max_agents insteadze--enable-krisp is deprecated, use --krisp-viva-audio-filter instead for the latest Krisp VIVA models.r   )ro   rp   zInvalid region 'z'. Valid regions are: z, r!   )audio_filterzAgent name is requiredz"Image / repository URL is requiredzDeployments require an image pull secret [bold](--credentials)[/bold] to securely pull images from private repositories.
Please provide an image pull secret name or use [bold][--no-credentials][/bold] to deploy without one.zJLearn more:https://docs.pipecat.daily.co/agents/secrets#image-pull-secretsz0Attempt to deploy without repository credentials)subtitler7   FdimT)show_headerborder_style	show_edge
show_linesPropertycyan)styleValuegreenz
Min agentsz
Max agentsz"[dim]Use existing or default[/dim]z[green]z[/green]defaultRegionz*[/green] [dim](organization default)[/dim]z,[bold white]Agent name:[/bold white] [green]z'[bold white]Image:[/bold white] [green]z.[bold white]Organization:[/bold white] [green]z![bold white]Region:[/bold white] z%[bold white]Secret set:[/bold white] z[dim]None[/dim]z[green] z,[bold white]Image pull secret:[/bold white] z([bold white]Agent profile:[/bold white] z-[bold white]Krisp (deprecated):[/bold white] z[dim]Disabled[/dim]z[green]Enabled[/green]z%[bold white]Krisp VIVA:[/bold white] z[green]Enabled (z	)[/green]z'[bold white]Managed Keys:[/bold white] z"
[dim]Scaling configuration:[/dim]z!Note: Usage costs will apply for zK reserved agent(s). Please see: https://www.daily.co/pricing/pipecat-cloud/redz?Note: Deploying with 0 minimum agents may result in cold startszReview deploymentleftyellow)titletitle_alignr   z(
Do you want to proceed with deployment?r"   ))r   warningr   rD   r   r   rm   rB   r$   r   scalingro   rp   enable_krispenable_managed_keysagent_profilerv   r   r   r   rA   joinr<   r=   r   
krisp_vivar   
add_columnadd_rowstrr   
propertiesr   r{   r   rG   r   r>   r?   Abortrb   )r)   r   rm   rn   ro   rp   r$   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r   partial_configdeploy_regionvalid_regionstableregion_displaypropsrA   contentr`   r`   ra   rF      s   u







" *
z%create_deploy_command.<locals>.deploy)commandr	   create_blockingr
   r   r<   OptionArgumentr   r   r   intboolr   r   )rc   rF   r`   r`   ra   create_deploy_command   s(  	!(/6<BIPW_g  r   )F)-rL   typingr   r<   logurur   rich.consoler   	rich.liver   
rich.panelr   
rich.tabler   	rich.textr   pipecatcloud._utils.async_utilsr	   pipecatcloud._utils.auth_utilsr
   !pipecatcloud._utils.console_utilsr    pipecatcloud._utils.deploy_utilsr   r   r   r   pipecatcloud._utils.regionsr   r   pipecatcloud.clir   pipecatcloud.cli.apir   pipecatcloud.cli.configr   pipecatcloud.constantsr   r   rH   rN   r   rb   Typerr   r`   r`   r`   ra   <module>   s.    G