o
    i&                  1   @   s  d Z ddlZddlm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 e Zd	efd
dZejdddddejdddeddejdddddejdddddejdddddejdddd dejdd!d"dejdd#d$dejdd%d&dejdd'd(dejdd)d*dejdd+d,dejdd-d.dejdd/d0dejdd1d2dejdd3d4dejdd5d6dejdd7d8dejdd9d:dejdd;d<dejdd=d>dejdd?d@dejddAdBdCdejddDdEdfdFee dGedHee dIee dJeee  dKee dLee dMee dNee dOee dPee dQee dRee dSee dTee dUedVedWedXedYedZed[ed\ee d]ef0d^d_ZdS )`z>Init command implementation for creating new Pipecat projects.    N)Path)Optional)Console)ProjectGenerator)ask_project_questions)ServiceRegistryvaluec                 C   st   | sdS dd }ddg|t j|t jd|t j|t j|t j|t j|t jd}tt	j
|dd	 td
)z)Print available options as JSON and exit.Nc                 S   s   dd | D S )Nc                 S   s   g | ]}|j qS  )r   ).0sr	   r	   M/home/ubuntu/.local/lib/python3.10/site-packages/pipecat_cli/commands/init.py
<listcomp>   s    z:_list_options_callback.<locals>.values.<locals>.<listcomp>r	   )defsr	   r	   r   values   s   z&_list_options_callback.<locals>.valuesweb	telephony)r   r   )bot_type
transportssttllmttsrealtimevideo   )indentr   )r   WEBRTC_TRANSPORTSTELEPHONY_TRANSPORTSSTT_SERVICESLLM_SERVICESTTS_SERVICESREALTIME_SERVICESVIDEO_SERVICESprintjsondumpstyperExit)r   r   optionsr	   r	   r   _list_options_callback   s   
r(   z--outputz-oz0Output directory (defaults to current directory))helpFz--list-optionsz0Print available service options as JSON and exitT)r)   callbackis_eagerz--namez-nz,Project name (triggers non-interactive mode)z
--bot-typez-bzBot type: 'web' or 'telephony'z--transportz-tz4Transport (repeatable, e.g. -t daily -t smallwebrtc)z--modez-mz&Pipeline mode: 'cascade' or 'realtime'z--sttzSTT service (cascade mode)z--llmzLLM service (cascade mode)z--ttszTTS service (cascade mode)z
--realtimez Realtime service (realtime mode)z--videozVideo avatar servicez--client-frameworkz/Client framework: 'react', 'vanilla', or 'none'z--client-serverz%Client dev server: 'vite' or 'nextjs'z--daily-pstn-modez(Daily PSTN mode: 'dial-in' or 'dial-out'z--twilio-daily-sip-modez.Twilio+Daily SIP mode: 'dial-in' or 'dial-out'z--recording/--no-recordingzEnable recordingz"--transcription/--no-transcriptionzEnable transcriptionz--video-input/--no-video-inputzEnable video inputz --video-output/--no-video-outputzEnable video outputz&--deploy-to-cloud/--no-deploy-to-cloudzGenerate cloud deployment filesz --enable-krisp/--no-enable-krispzEnable Krisp noise cancellationz"--observability/--no-observabilityzEnable observabilityz--configz-cz0JSON config file (triggers non-interactive mode)z	--dry-runz6Print resolved config as JSON without generating files
output_dirlist_optionsnamer   	transportmoder   r   r   r   r   client_frameworkclient_serverdaily_pstn_modetwilio_daily_sip_mode	recordingtranscriptionvideo_inputvideo_outputdeploy_to_cloudenable_krispobservabilityconfigdry_runc           #   
   C   s|  zm|dup	|du}|r[ddl m}m}m}m} |dur||}|p,|dp,|d}|p3|d}|p?|dp?|d}|pF|d	}|pR|d
pR|d}|p^|dp^|d}|pj|dpj|d}|	pv|dpv|d}	|
p|dp|d}
|p|d}|p|d}|p|d}|p|d}|p|dd}|p|dd}|p|dd}|p|dd}d|v r|d }|p|dd}|p|d|d d}zC|d)i d|d|d|d	|d
|d|d|d|	d|
d|d|d|d|d|d|d|d|d|d|d|}W n |y9 } ztd!| d" t	d#d}~ww |rHt|| t	dt
|} | j| d$d%}!| |! W dS t }"t
|"} | | }!| |! W dS  ty   td& t	d# tj	y     ty } ztd'| d" t	d#d}~w ty } ztd(| d" t	d#d}~ww )*a(  
    Initialize a new Pipecat project.

    Creates a complete project structure with bot.py, dependencies, and configuration files.

    In interactive mode (default), uses a wizard to guide you through setup.
    In non-interactive mode (when --name or --config is provided), all configuration
    is taken from flags or a config file.

    Examples:
        pc init                                          # Interactive wizard
        pc init --name my-bot --bot-type web \
          --transport daily --mode cascade \
          --stt deepgram_stt --llm openai_llm \
          --tts cartesia_tts                             # Non-interactive
        pc init --config project-config.json             # From config file
        pc init --name my-bot ... --dry-run              # Preview config as JSON
    Nr   )ConfigValidationErrorconfig_to_jsonload_config_from_filevalidate_and_build_configr.   project_namer   r   r/   r0   r   stt_servicer   llm_servicer   tts_servicer   realtime_servicer   video_servicer1   r2   r3   r4   r5   Fr6   r7   r8   r9   r:   r;   enable_observabilityz
[red]z[/red]   T)non_interactivez-
[yellow]Project creation cancelled.[/yellow]z
[red]Error: z
[red]Error creating project: r	   )pipecat_cli.config_validatorr>   r?   r@   rA   getconsoler"   r%   r&   r   generateprint_next_stepsr   KeyboardInterruptFileExistsError	Exception)#r,   r-   r.   r   r/   r0   r   r   r   r   r   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   rJ   r>   r?   r@   rA   	file_dataproject_confige	generatorproject_pathconfig_resultr	   r	   r   init_command/   s   W	







rY   )__doc__r#   pathlibr   typingr   r%   rich.consoler   pipecat_cli.generatorsr   pipecat_cli.promptsr   %pipecat_cli.registry.service_metadatar   rM   boolr(   OptionstrlistrY   r	   r	   r	   r   <module>   s   
"%(+,/258;>A