+
    ji=                        ^ RI t ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHtHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIHtHtHt ^RIHt ]! R.4      ]! ].4      R 4       4       t]! R.4      ]! ].4      R 4       4       t]! RR.4      ]! ].4      R 4       4       t]! R.4      ]! ].4      R 4       4       t]! R.4      ]! ].4      R 4       4       t R# )    N)settings)JsonResponse)require_http_methods)csrf_exempt)method_decoratorstatus)api_viewpermission_classes)AllowAny)Response)Session)ConversationUserTurnAgentResponse)create_user_tokenPOSTc           
     Z   V P                   P                  R4      ;'       g*    R\        P                  ! 4       P                  R,           2pV P                   P                  R4      pV P                   P                  R4      ;'       g*    R\        P                  ! 4       P                  R,           2pRpV'       d&   \
        P                  P                  VRV/R	7      w  rE\        P                  P                  VV\        P                  P                  R
7      p \        \        P                  \        P                  VVR7      p\#        RTRTR\%        TP*                  4      RT/4      #   \          d1   p\#        R\%        T4      /\&        P(                  R7      u Rp?# Rp?ii ; i)zKCreate conversation and return LiveKit token + room_name + conversation_id.	room_nameroom-N   N
session_ididentityuser-N   NNr   defaultssessionr   r	   api_key
api_secretr   r   errorr   tokenconversation_id)datagetuuiduuid4hexr   objectsget_or_creater   createStatusACTIVEr   r   LIVEKIT_API_KEYLIVEKIT_API_SECRET	Exceptionr   strr	   HTTP_500_INTERNAL_SERVER_ERRORid)	requestr   r   r   session_obj_convr&   es	   &        FE:\live-kit-agent\livekit_voicebot\backend\apps\conversations\views.pystart_sessionr>      sj      -PP59I9I#9N8O1PI!!,/J||
+MMtzz|7G7G7K6L/MHK 66!"J/ 7 

 &&"")) ' DY!,,22	
 Y3tww<H	    Y#a&)&2W2WXXYs   +E/ /F*:%F%F*%F*GETc           
     x   V P                   P                  R4      ;'       g*    R\        P                  ! 4       P                  R,           2pV P                   P                  R4      ;'       g*    R\        P                  ! 4       P                  R,           2pV P                   P                  R4      pRpV'       d.    \
        P                  P                  VR	7      pVP                  pV'       g   \        P                  P                  V P                   P                  R
4      ;'       g     \        P                  ! 4       P                  / R7      w  rV\
        P                  P                  VV\
        P                  P                  R7      p \        \        P                   \        P"                  VVR7      p\'        RTRTR\)        TP.                  4      RT/4      #   \
        P                   d     ELi ; i  \$         d1   p\'        R\)        T4      /\*        P,                  R7      u Rp?# Rp?ii ; i)zEGET /api/token/?room=...&identity=...&conversation_id=... (optional).roomr   r   r   r   r   r'   Nr7   r   r   r    r"   r%   r   r&   r   )query_paramsr)   r*   r+   r,   r   r-   r   DoesNotExistr   r.   r/   r0   r1   r   r   r2   r3   r4   r   r5   r	   r6   r7   )	r8   r   r   r'   r;   r9   r:   r&   r<   s	   &        r=   	get_tokenrE   8   s    $$((0SSeDJJL<L<LS<Q;R4SI##''
3UUtzz|?O?OPR?S>T7UH**../@AOD	''+++?DI  66++//=QQAQAQ 7 
 ##**&&-- + 
Y!,,22	
 Y3tww<H	  1 (( 		*  Y#a&)&2W2WXXYs0   ?,G" +G> "G;:G;>H9	%H4.H94H9c                \    \         P                  P                  VR7      pT P                  R8X  Ed,   TP                  P                  4       p\        P                  P                  TTT P                  P                  RR4      T P                  P                  R4      T P                  P                  R	4      T P                  P                  R
4      R7      pT P                  P                  R4      '       d5   T P                  P                  R4      Tn        TP                  RR.R7       \	        R\        TP                   4      RT/\
        P"                  R7      # TP                  P%                  R4      P'                  R4      p. pT F  pTP)                  R\        TP                   4      RTP*                  RTP,                  RTP                  R	TP.                  RTP0                  P3                  4       R\5        TRR4      '       dS   RTP6                  P8                  RTP6                  P:                  RTP6                  P0                  P3                  4       /MR/4       K  	  \	        T4      #   \         P                   d!    \	        RR/\
        P                  R7      u # i ; i)z/POST: worker creates UserTurn. GET: list turns.rB   r%   Conversation not foundr   r   
transcript detected_languagestt_providerstt_confidence)conversationorder_indextranscribed_textrJ   rK   rL   
updated_at)update_fieldsturn_idrN   agent_responserO   
created_atNresponse_textlanguage_used)r   r-   r)   rD   r   r	   HTTP_404_NOT_FOUNDmethod
user_turnscountr   r/   r(   rJ   saver5   r7   HTTP_201_CREATEDprefetch_relatedorder_byappendrN   rO   rK   rT   	isoformatgetattrrS   rU   rV   )r8   r'   r;   rN   turnturnsr(   ts   &&      r=   turns_list_createre   e   s:   _##''?'; ~~oo++-&&#$\\--lB?%ll../BC )).9"<<++,<= ' 
 <</00%,\\%5%56I%JD"II%8,$GIHCL-MV\VmVmnnOO,,-=>GGVEDs144y1== 2 2!4!4ANN!,,002 ,d33  !1!1!?!?!1!1!?!?a..99CCE :>
 	  D>E $$ _":;FD]D]^^_s    I6 62J+*J+c                |    \         P                  P                  VR7      pVP                  P                  VR7      p\        P                  P                  TRTRT P                  P                  RR4      RT P                  P                  R4      R	T P                  P                  R	4      R
T P                  P                  R
4      RT P                  P                  R4      /R7       \        RR/4      #   \         P                  \
        P                  3 d!    \        RR/\        P                  R7      u # i ; i)z,Worker posts agent response for a user turn.rB   r%   z	Not foundr   rM   rU   rI   llm_providertts_providervoice_idrV   )	user_turnr   r	   ok)r   r-   r)   rY   rD   r   r   r	   rW   r   update_or_creater(   )r8   r'   rR   r;   rb   s   &&&  r=   turn_responserm      s   R##''?';""g". **DW\\--orBGLL,,^<GLL,,^<((4W\\--o>
 + 
 Xt$%% %%x'<'<= R+.v7P7PQQRs   <C6 6AD;:D;c                r    \         P                  P                  VR7      pTP                  P                  R4      P                  R4      p. pT F  pTP                  RRR	TP                  R
TP                  RTP                  P                  4       /4       \        TRR4      '       g   K]  TP                   pTP                  RRR	TP"                  RTP                  P                  4       /4       K  	  \	        T4      #   \         P                   d!    \	        RR/\
        P                  R7      u # i ; i)z?Full transcript: list of { role, text, language?, created_at }.rB   r%   rG   r   rS   rN   roleusertextlanguagerT   Nagent)r   r-   r)   rD   r   r	   rW   rY   r]   r^   r_   rO   rJ   rT   r`   ra   rS   rU   )r8   r'   r;   rc   r(   rd   rs   &&     r=   rH   rH      s   _##''?'; OO,,-=>GGVEDFA&&++!,,002	
 	 1&--  AKKall446   D>' $$ _":;FD]D]^^_s    D 2D65D6)!r*   django.confr   django.httpr   django.views.decorators.httpr   django.views.decorators.csrfr   django.utils.decoratorsr   rest_frameworkr	   rest_framework.decoratorsr
   r   rest_framework.permissionsr   rest_framework.responser   apps.users.modelsr   apps.conversations.modelsr   r   r   livekit_tokensr   r>   rE   re   rm   rH        r=   <module>r      s      $ = 4 4 ! B / , % K K - 
6(XJ"   "J 
5'XJ(   (V 
65/XJ&   &R 
6(XJ&   &, 
5'XJ   r   