Ë
    @hA  ã                   óð   — d dl mZmZmZ d dlmZmZ d dlZd dlm	Z	m
Z
mZmZ d dlmZmZmZmZ d dlmZ  e«       Z G d„ de«      Z G d	„ d
e«      Zej/                  ded¬«       ed«      fdefd„«       Zy)é    )Ú	APIRouterÚHTTPExceptionÚBody)Ú	BaseModelÚFieldN)ÚOptionalÚDictÚAnyÚList)Ú	AgentTypeÚMessageÚcoordinatorÚcontext_protocol)Úprocess_voice_command_aic                   óÄ   — e Zd ZU  eddd¬«      Zeed<    eddd¬	«      Zeed
<    edd¬«      Ze	e   ed<    edd¬«      Z
e	e   ed<    edd¬«      Ze	eeef      ed<   y)ÚVoiceCommandInput.é   z,The transcribed text from the user's speech.)Ú
min_lengthÚdescriptionÚ
transcriptÚenz^(en|hi|mr)$z&Language code (e.g., 'en', 'hi', 'mr'))ÚdefaultÚpatternr   ÚlanguageNz0Optional session ID for continuing conversations)r   Ú
session_idÚBaramatiz(User's location for contextual responsesÚlocationz(Additional context for the voice commandÚcontext_data)Ú__name__Ú
__module__Ú__qualname__r   r   ÚstrÚ__annotations__r   r   r   r   r   r	   r
   © ó    úFC:\Users\aadil\OneDrive\Desktop\404\backend\app\api\endpoints\voice.pyr   r      su   … Ù˜C¨AÐ;iÔj€J�Ójá $°ÐLtÔu€HˆcÓuÙ % dÐ8jÔ k€J�˜‘ÓkÙ# JÐ<fÔg€Hˆh�s‰mÓgÙ-2°4ÐEoÔ-p€L�(˜4  S ™>Ñ*Ôpr%   r   c                   ól   — e Zd ZU eed<   dZee   ed<   eed<   dZee   ed<   dZe	ed<   dZ
ee   ed<   y)	ÚVoiceCommandResponseÚresponse_textNÚ	audio_urlr   Údetected_intentFÚrequires_followupÚfollowup_type)r   r    r!   r"   r#   r*   r   r+   r,   Úboolr-   r$   r%   r&   r(   r(      sB   … ØÓØ#€Iˆx˜‰}Ó#ØƒOØ%)€O�X˜c‘]Ó)Ø#Ð�tÓ#Ø#'€M�8˜C‘=Ô'r%   r(   z/commandéÈ   )Úresponse_modelÚstatus_code.Úcommand_inputc           
   ƒ   ó˜  K  — 	 | j                   xs t        t        j                  «       «      }t	        j
                  || j                  | j                  xs d| j                  dœ| j                  xs i ¥«       t        j                  t        t        j                  t        j                  d| j                  idd|i¬«      «      ƒ d{  –—† }|rd|j                   v r-|r|j                   j#                  dd	«      nd
}t%        d|¬«      ‚|j                   j#                  dd«      }|j                   j#                  dd«      }|j                   j#                  d«      }|r|nd}d}t'        ||||||r|¬«      S d¬«      S 7 Œ¶# t$        $ r}	|	‚d}	~	wt(        $ r,}
t+        d|
› �«       t%        ddt        |
«      › �¬«      ‚d}
~
ww xY w­w)z“
    Receives transcribed text, processes the command using the multi-agent system,
    and returns a text response in the specified language.
    r   )r   r   Úlast_transcriptr   Úprocess_commandr   )ÚsenderÚreceiverÚcontentÚmessage_typeÚcontextNÚerrorz&Unknown error processing voice commandzNo response from voice agenti÷  )r1   ÚdetailÚresponsez'Sorry, I couldn't process that command.Úshould_routeFÚtarget_agentÚgeneral_query)r)   r*   r   r+   r,   r-   z'Unexpected error in /command endpoint: iô  z#An internal server error occurred: )r   r"   ÚuuidÚuuid4r   Úset_contextr   r   r   r   r   Úroute_messager   r   ÚCOORDINATORÚVOICE_ASSISTANTr8   Úgetr   r(   Ú	ExceptionÚprint)r2   r   Úmessager;   r)   r>   r?   r+   r*   Úhttp_excÚes              r&   Úhandle_voice_commandrM      sÙ  è ø€ ð;dà"×-Ñ-ÒB´´T·Z±Z³\Ó1Bˆ
ô 	×$Ñ$ ZØ%×.Ñ.Ø%×.Ñ.Ò<°*Ø,×7Ñ7ñ2
ð ×)Ñ)Ò/¨Rð	2
ô 	ô $×1Ñ1ÜÜ ×,Ñ,Ü"×2Ñ2à  -×":Ñ":ðð /Ø% zÐ2ôó

÷ 

ˆñ ˜' W§_¡_Ñ4Ù^e�G—O‘O×'Ñ'¨Ð1YÔZð  lJˆEÜ¨C¸Ô>Ð>ð  Ÿ™×+Ñ+¨JÐ8aÓbˆð —‘×*Ñ*¨>¸5ÓAˆØ—‘×*Ñ*¨>Ó:ˆÙ*6™,¸Oˆð ˆ	ä#Ø'ØØ!Ø+Ø*Ù-9˜/ô
ð 	
ð @Dô
ð 	
ð?

ùôP ò àˆûÜò däÐ7¸°sÐ;Ô<Ü¨Ð6YÔZ]Ð^_ÓZ`ÐYaÐ4bÔcÐcûðdüsT   ‚G
„CF ÃFÃB.F Å:G
Å;F ÆG
ÆF Æ	GÆFÆGÆ'GÇGÇG
)Úfastapir   r   r   Úpydanticr   r   rA   Útypingr   r	   r
   r   Úapp.core.multi_agentr   r   r   r   Úapp.core.ai_servicesr   Úrouterr   r(   ÚpostrM   r$   r%   r&   Ú<module>rU      s~   ðß 2Ñ 2ß %Û ß ,Ó ,÷ SÓ RÝ 9á	‹€ôq˜	ô qô(˜9ô (ð ‡�ˆZÐ(<È#€ÓNá'+¨C£yñBdØ$òBdó OñBdr%   