+
    im$                        ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHtH	t	H
t
Ht R R ltR R ltR R	 ltR
 R ltR R ltRRRRRRRRRRRR/R R llt]P$                  ! R4      tR R ltRRRRRRRRRRRRRR/R R lltR R ltR# )     NPath)AnyDictListTuplec                2    V ^8  d   QhR\         R,          /# )   returnNstr)formats   ">E:\live-kit-agent\livekit_voicebot\backend\apps\livekit\cli.py__annotate__r   
   s      t     c                  .    \         P                  ! R 4      # )lk)shutilwhich r   r   lk_pathr   
   s    <<r   c                $    V ^8  d   QhR\         /# r
   r   r   )r   s   "r   r   r      s     A A4 Ar   c                  *   \         P                  ! R 4      p V '       dB   \        V 4      P                  4       '       d#   \	        \        V 4      P                  4       4      # \	        \
        4      P                  4       P                  ^,          R,          # )LIVEKIT_AGENT_TEMPLATE_WORKDIRagent_runtime)osgetenvr   stripr   __file__resolveparentsenv_dirs    r   _default_template_workdirr%      sa    ii89G3w<%%''CL&&())>!!#++A.@@r   c                $    V ^8  d   QhR\         /# r   r   )r   s   "r   r   r      s     6 6$ 6r   c                      \         P                  ! R 4      p V '       dB   \        V 4      P                  4       '       d#   \	        \        V 4      P                  4       4      # \        4       R,          # )LIVEKIT_AGENT_DEPLOY_ROOT
.lk_deploy)r   r   r   r   r   r%   r#   s    r   _deploy_root_dirr*      sL    ii34G3w<%%''CL&&())$&55r   c                0    V ^8  d   QhR\         R\         /# )r
   namer   r   )r   s   "r   r   r      s     " "S "S "r   c                     \         P                  ! R RT ;'       g    RP                  4       4      p\         P                  ! RRV4      P                  R4      pV'       d
   VR,          # R# )z[^a-zA-Z0-9._-]+- z-{2,}:N@   Nbot)resubr   )r,   ss   & r   
_safe_slugr5      sR    
"C$**"););)=>A
xa &&s+A1S6!E!r   c                0    V ^8  d   QhR\         R\        /# )r
   bot_namer   )r   r   )r   s   "r   r   r   #   s     J Jc Jd Jr   c                R   \        4       pVP                  4       '       g   \        RV 24      h\        4       pVP	                  RRR7       \        V 4      p\        P                  ! R4      pW# RV 2,          pR R lp\        P                  ! WRVR	7       VR
,          pVP                  RP                  . RO4      RR7       VR,          pVP                  4       '       gC   VR,          p	V	P                  4       '       d$   VP                  V	P                  RR7      RR7       V# )z
Create a per-bot workdir for `lk agent create`.

We copy a template agent directory so each bot can become its own LiveKit Cloud deployment
without clobbering other deployments.
z"Agent template workdir not found: T)r"   exist_okz%Y%m%d-%H%M%Sr.   c                h    V ^8  d   QhR\         R\        \         ,          R\        \         ,          /# )r
   _dirnamesr   )r   r   set)r   s   "r   r   -prepare_workdir_for_bot.<locals>.__annotate__5   s)     	1 	1c 	1$s) 	1C 	1r   c                 H    0 RmpV Uu0 uF  q3V9   g   K  VkK  	  up# u upi ).git>   __pycache__node_modulesr@   .venvr)   .pytest_cacher   )r;   r<   ignorens   &&  r   _ignore(prepare_workdir_for_bot.<locals>._ignore5   s)    
 !05aK5000s   F)dirs_exist_okrE   
Dockerfile
zutf-8)encodingzrequirements.txtzrequirements.in)z# syntax=docker/dockerfile:1zFROM python:3.12-slim-bookwormr/   zENV PYTHONUNBUFFERED=1zENV PYTHONDONTWRITEBYTECODE=1r/   zWORKDIR /appr/   zBRUN apt-get update && apt-get install -y --no-install-recommends \z    build-essential \z    ffmpeg \z   && rm -rf /var/lib/apt/lists/*r/   zS# Install dependencies for the agent runtime (this directory is the build context).z+COPY requirements.txt /app/requirements.txtz1RUN python -m pip install --no-cache-dir -U pip \zA && python -m pip install --no-cache-dir -r /app/requirements.txtr/   zCOPY . /app/agent_runtimezWORKDIR /app/agent_runtimer/   z.RUN python src/agent.py download-files || truer/   z%CMD ["python", "src/agent.py", "dev"]r/   )r%   existsFileNotFoundErrorr*   mkdirr5   timestrftimer   copytree
write_textjoin	read_text)
r7   templaterootslugstamptargetrG   
dockerfilereqalts
   &         r   prepare_workdir_for_botr^   #   s
    )*H??"DXJ OPPDJJtdJ+hDMM/*EfAeW%%F	1 OOHE'J ,&J			
: =  D %
%C::<<((::<<NN3=='=:WNMMr   regionconfigagent_idsecretssecrets_filesilentTc                :   V ^8  d   QhR\         R\        R\         R,          R\         R,          R\         R,          R\        \         \        3,          R,          R\         R,          R	\        R
\
        \        \         ,          \        \         ,          3,          /	# )r
   actionworkdirr_   Nr`   ra   rb   rc   rd   r   )r   r   r   r   boolr   r   )r   s   "r   r   r   p   s     * *** $J	*
 $J* Dj* #s(^d"* ** * 49d3i *r   c                :   R RV .pR RV .p	V'       d   VRV.,          pV	RV.,          p	V'       d   VRV.,          pV	RV.,          p	V'       d   VRV.,          pV	RV.,          p	V'       d   VRV.,          pV	RV.,          p	V'       d@   VP                  4        F+  w  rT
 RVf   RMT 2pVRV.,          pV	RV
 R	2.,          p	K-  	  V'       d   VR
.,          pV	R
.,          p	VP                  \        V4      4       V	P                  \        V4      4       W3# )r   agentz--regionz--configz--idz--secrets-file=r/   z	--secretsz=***z--silent)itemsappendr   )rf   rg   r_   r`   ra   rb   rc   rd   argvredactedkvkvs   &&$$$$$$     r   build_lk_argsrs   p   s7    Wf-D&1HV$$Z((V$$Z((""VX&&!<00%|44MMODA3aaiQ/0B["%%D4j11H $
 ZL KKGOOCL!>r   z\b((?:CA|sb)_[a-zA-Z0-9]+)\bc                J    V ^8  d   QhR\         R\         R\         R,          /# )r
   stdoutstderrr   Nr   )r   s   "r   r   r      s%     
% 
% 
%S 
%S4Z 
%r   c                    RP                  T ;'       g    RT;'       g    R.4      p\        P                  V4      pV'       d   VP                  ^4      # R# )z
Best-effort extraction of a LiveKit Cloud agent deployment id.

LiveKit Cloud agent deployments currently look like:
- CA_... (agent deployment id in the Cloud dashboard)
- sb_... (older/other identifiers in some outputs)
rK   r/   N)rT   _AGENT_DEPLOYMENT_ID_REsearchgroup)ru   rv   txtms   &&  r   extract_agent_deployment_idr}      sH     ))V\\r6<<R0
1C&&s+A1771:$$r   	timeout_si  c                   V ^8  d   QhR\         R\        R\         R,          R\         R,          R\         R,          R\        \         \        3,          R,          R\         R,          R	\        R
\
        R\        \         \        3,          /
# )r
   rf   rg   r_   Nr`   ra   rb   rc   rd   r~   r   )r   r   r   r   rh   int)r   s   "r   r   r      s     I III $J	I
 $JI DjI #s(^d"I *I I I 
#s(^Ir   c                d   V R9  d   \        R4      h\        4       '       g	   RRRRRR/# \        V4      pVP                  4       '       g   RRRRRRV 2/# V R 8w  d&   VR	,          P                  4       '       g	   RRRRRR
/# \	        V VVVVVVVR7      w  rRpV R 8X  d   Rp \
        P                  ! V	\        V4      RRV\        ^
\        \        V4      R4      4      R7      p\        TP                  ;'       g    RTP                  ;'       g    R4      pRTP                   ^ 8H  RTP                   RT
RTP                  ;'       g    RRTP                  ;'       g    RRT/#   \
        P                   d    RRRRRT
RR/u # \         d   pRRRRRT
R\        T4      /u Rp?# Rp?ii ; i)createz#action must be 'create' or 'deploy'okF	exit_codeNmessagez3LiveKit CLI (`lk`) is not installed on this server.zworkdir does not exist: zlivekit.tomlz-workdir must contain livekit.toml for deploy.)r_   r`   ra   rb   rc   rd   zY
Ti  )cwdcapture_outputtextinputtimeoutcommandr   r/   ru   rv   ra   )r   deploy)
ValueErrorr   r   rM   rs   
subprocessrunr   maxminr   TimeoutExpired	Exceptionr}   ru   rv   
returncode)rf   rg   r_   r`   ra   rb   rc   rd   r~   rn   ro   stdinprocedep_ids   &&$$$$$$$      r   run_lk_agentr      s    ))>??99%L
 	
 7mG>>e[$	=UV]U^;_`` 7^#;"C"C"E"E%F
 	
 #!	ND EX~~GCI56
 )):):DKK<M<M2NFdoo"T__8$++##$++##F  $$ [e[$	8YPYZZ Xe[$	8YPSTUPVWWXs+   $AE' 'F/F/F/F*$F/*F/c                :    V ^8  d   QhR\         \        ,          /# r   )listr   )r   s   "r   r   r      s     0 0d3i 0r   c                     \        4       '       g   . # \        P                  ! R4      ;'       g    Rp \        P                  ! R4      ;'       g    Rp\        P                  ! R4      ;'       g    RpV '       d   V'       d	   V'       g   . #  \        P                  ! RRRRV R	VR
V.	RR^R7      pRP                  TP                  ;'       g    RTP                  ;'       g    R.4      p. p\        P                  ! RT4       F#  pTP                  TP                  ^ 4      4       K%  	  \        4       p. pT F-  p	Y9   d   K  TP                  T	4       TP                  T	4       K/  	  T#   \
         d    . u # i ; i)z
Best-effort list of LiveKit Cloud agent deployment IDs (CA_...) using credentials
from environment (LIVEKIT_URL/LIVEKIT_API_KEY/LIVEKIT_API_SECRET).

Returns a list of ids in the order `lk` prints them (typically newest first).
LIVEKIT_URLr/   LIVEKIT_API_KEYLIVEKIT_API_SECRETr   rj   r   z--urlz	--api-keyz--api-secretT)r   r   r   rK   z\bCA_[a-zA-Z0-9]+\b)r   r   r   r   r   r   rT   ru   rv   r2   finditerrm   rz   r=   add)
urlapi_key
api_secretr   r{   idsr|   seenoutxs
             r   list_cloud_agent_deploymentsr      sM    99	
))M
"
(
(bCii)*00bG/066BJG
	~~
  
& ))T[[&&B(9(9r:
;C
C[[/5

1771: 6 5DC9

1	 
 J  	s   #E- -E=<E=)r   r2   r   r   rP   pathlibr   typingr   r   r   r   r   r%   r*   r5   r^   rs   compilerx   r}   r   r   r   r   r   <module>r      s    	 	     ) )A6"JZ* 	*
 *  * &**  $* *Z **%DE 
%I 	I
 I  I &*I  $I I IX0r   