+
    ~jz)                        ^ RI Ht ^ RIt^ RIt^ RIHtHtHt ^ RIH	t	 ^ RI
HtHt ^ RIHt ^RIHtHt ^RIHt R	t]	 ! R
 R4      4       t]! RR7      t ! R R4      tR# )    )annotationsN)Callable	GeneratorSequence)	dataclass)AnyLiteral)context)llmutils)loggerg      @c                  "    ] tR t^t$ R]R&   RtR# )InputDetailszLiteral['text', 'audio']modality N)__name__
__module____qualname____firstlineno____annotations____static_attributes__r       w/Users/mitch_tango/dev/rabbit-r1-livekit/agent/.venv/lib/python3.14/site-packages/livekit/agents/voice/speech_handle.pyr   r      s    &&r   r   audio)r   c                  2   ] tR t^t^ t ^t ^
t R R lt]R]	3R R ll4       t
]R R l4       t]R R	 l4       t]R
 R l4       t]R R l4       t]R R l4       t]R R l4       t]R R l4       t]R R l4       t]P(                  R R l4       t]R R l4       tR R ltRR/R R lltR  R! ltR" R# ltR$ R% ltR& R' ltR( R) ltR* R+ ltR, R- ltR. R/ ltR0 R1 lt R2 R3 lt!R4 R5 lt"R6 R7 lt#RDR8 R9 llt$R: R; lt%R< R= lt&R> R? lt'R@ RA lt(RBt)RC# )ESpeechHandlec               (    V ^8  d   QhRRRRRRRR/# )	   	speech_idstrallow_interruptionsboolinput_detailsr   returnNoner   )formats   "r   __annotate__SpeechHandle.__annotate__!   s,     !1 !1!16:!1KW!1	!1r   c               	  a  VS n         VS n        VS n        \        P                  R ,          ! 4       S n        \        P                  R ,          ! 4       S n        \        P                  R ,          ! 4       S n        \        P                  ! 4       S n	        . S n
        . S n        . S n        ^S n        R S n        R S n        \!        4       S n        \!        4       S n        R V 3R llpS P                  P'                  V4       R S n        R # )Nc                    V ^8  d   QhRRRR/# )r   _zasyncio.Future[None]r$   r%   r   )r&   s   "r   r'   +SpeechHandle.__init__.<locals>.__annotate__:   s     	P 	P, 	P 	Pr   c                   < \        SP                  4       F  p V! S4       K  	  R#   \         d'   p\        P                  ! R T 2TR7        Rp?K>  Rp?ii ; i)zerror in done_callback: exc_infoN)list_done_callbacks	Exceptionr   warning)r+   cbeselfs   &  r   _on_done'SpeechHandle.__init__.<locals>._on_done:   sR    4//0PtH 1 ! PNN%=bT#BQOOPs   )AAA)_id_allow_interruptions_input_detailsasyncioFuture_interrupt_fut	_done_fut_scheduled_futEvent_authorize_event_generations_tasks_chat_items
_num_steps_agent_turn_context_interrupt_timeout_handleset_item_added_callbacksr1   add_done_callback_maybe_run_final_output)r6   r   r!   r#   r7   s   f$$$ r   __init__SpeechHandle.__init__!   s     $7!+%nnT24 -/%nnT24 '8: +-/1@D EI&JM%"DGE	P 	P 	((2,0$r   Tc               $    V ^8  d   QhRRRRRR/# )r   r!   r"   r#   r   r$   r   r   )r&   s   "r   r'   r(   E   s&     
 
!
#
 

r   c                	F    \        \        P                  ! R 4      V VR7      # )speech_)r   r!   r#   )r   r   	shortuuid)r!   r#   s   &&r   createSpeechHandle.createD   s#    
 ooi0 3'
 	
r   c                   V ^8  d   QhRR/# )r   r$   intr   )r&   s   "r   r'   r(   P   s      3 r   c                	    V P                   # N)rF   r6   s   &r   	num_stepsSpeechHandle.num_stepsO   s    r   c                   V ^8  d   QhRR/# r   r$   r    r   )r&   s   "r   r'   r(   T   s      C r   c                	    V P                   # rX   )r9   rY   s   &r   idSpeechHandle.idS   s    xxr   c                   V ^8  d   QhRR/# )r   r$   r   r   )r&   s   "r   r'   r(   X   s     # #| #r   c                	    V P                   # rX   )r;   rY   s   &r   r#   SpeechHandle.input_detailsW   s    """r   c                   V ^8  d   QhRR/# r]   r   )r&   s   "r   r'   r(   \   s     / / /r   c                	8    V P                    R V P                   2# )r+   )r9   rF   rY   s   &r   _generation_idSpeechHandle._generation_id[   s    ((1T__-..r   c                   V ^8  d   QhRR/# )r   r$   z
str | Noner   )r&   s   "r   r'   r(   `   s     3 3z 3r   c                	l    V P                   ^8:  d   R# V P                   RV P                   ^,
           2# )   Nr+   )rF   r9   rY   s   &r   _parent_generation_id"SpeechHandle._parent_generation_id_   s0    ??a((1T__q0122r   c                   V ^8  d   QhRR/# r   r$   r"   r   )r&   s   "r   r'   r(   f   s     * *4 *r   c                	6    V P                   P                  4       # rX   )r@   donerY   s   &r   	scheduledSpeechHandle.schedulede       ""''))r   c                   V ^8  d   QhRR/# rn   r   )r&   s   "r   r'   r(   j   s     * *T *r   c                	6    V P                   P                  4       # rX   )r>   rp   rY   s   &r   interruptedSpeechHandle.interruptedi   rs   r   c                   V ^8  d   QhRR/# rn   r   )r&   s   "r   r'   r(   n   s     ) )T )r   c                	    V P                   # rX   )r:   rY   s   &r   r!    SpeechHandle.allow_interruptionsm   s    (((r   c                    V ^8  d   QhRRRR/# )r   valuer"   r$   r%   r   )r&   s   "r   r'   r(   r   s     * * *$ *r   c                \    V P                   '       d   V'       g   \        R4      hWn        R# )a  Allow or disallow interruptions on this SpeechHandle.

When set to False, the SpeechHandle will no longer accept any incoming
interruption requests until re-enabled. If the handle is already
interrupted, clearing interruptions is not allowed.

Args:
    value (bool): True to allow interruptions, False to disallow.

Raises:
    RuntimeError: If attempting to disable interruptions when already interrupted.
zPCannot set allow_interruptions to False, the SpeechHandle is already interruptedN)rv   RuntimeErrorr:   )r6   r|   s   &&r   r!   rz   q   s*     Eb  %*!r   c                   V ^8  d   QhRR/# )r   r$   zlist[llm.ChatItem]r   )r&   s   "r   r'   r(      s        .  r   c                	    V P                   # rX   )rE   rY   s   &r   
chat_itemsSpeechHandle.chat_items   s    r   c                   V ^8  d   QhRR/# rn   r   )r&   s   "r   r'   r(      s     % %d %r   c                	6    V P                   P                  4       # rX   )r?   rp   rY   s   &r   rp   SpeechHandle.done   s    ~~""$$r   forceFc                    V ^8  d   QhRRRR/# )r   r   r"   r$   r   r   )r&   s   "r   r'   r(      s      $ < r   c               p    V'       g   V P                   '       g   \        R4      hV P                  4        V # )zInterrupt the current speech generation.

Raises:
    RuntimeError: If this speech handle does not allow interruptions.

Returns:
    SpeechHandle: The same speech handle that was interrupted.
z3This generation handle does not allow interruptions)r:   r~   _cancel)r6   r   s   &$r   	interruptSpeechHandle.interrupt   s,     T666TUUr   c                   V ^8  d   QhRR/# r   r$   r%   r   )r&   s   "r   r'   r(      s     - - -r   c                  "   ^RI Hp \        P                  ! 4       ;p'       d   V! V4      pV'       ds   VP                  '       da   VP
                  V 8X  dP   VP                  P                  P                  RR4      '       g$   \        RVP                  P                   R24      h\        P                  ! V P                  4      G Rj  xL
  R#  L5i)aS  Waits for the entire assistant turn to complete playback.

This method waits until the assistant has fully finished speaking,
including any finalization steps beyond initial response generation.
This is appropriate to call when you want to ensure the speech output
has entirely played out, including any tool calls and response follow-ups.)_get_activity_task_info__livekit_agents_tool_pendingFzMcannot call `SpeechHandle.wait_for_playout()` from inside the function tool `u<  ` that owns this SpeechHandle. This creates a circular wait: the speech handle is waiting for the function tool to complete, while the function tool is simultaneously waiting for the speech handle.
To wait for the assistant’s spoken response prior to running this tool, use `RunContext.wait_for_playout()` instead.N)agentr   r<   current_taskfunction_callspeech_handleextragetr~   nameshieldr?   )r6   r   taskinfos   &   r   wait_for_playoutSpeechHandle.wait_for_playout   s      	3''))4)*40D&&&&&$.**00445TV[\\"cdhdvdvd{d{c| }M M  nnT^^,,,s#   3CC<CACCCc                   V ^8  d   QhRR/# )r   r$   z#Generator[None, None, SpeechHandle]r   )r&   s   "r   r'   r(      s     ) )> )r   c                	@   a  R  V 3R llpV! 4       P                  4       # )c                   V ^8  d   QhRR/# r   r$   r   r   )r&   s   "r   r'   ,SpeechHandle.__await__.<locals>.__annotate__   s     	 	< 	r   c                 D   <"   S P                  4       G R j  xL
  S #  L5irX   )r   rY   s   r   _await_impl+SpeechHandle.__await__.<locals>._await_impl   s"     '')))K *s     )	__await__)r6   r   s   f r   r   SpeechHandle.__await__   s     	 	 }&&((r   c                    V ^8  d   QhRRRR/# r   callbackzCallable[[SpeechHandle], None]r$   r%   r   )r&   s   "r   r'   r(      s     + +*H +T +r   c                	    V P                  4       '       d'   \        P                  ! 4       P                  W4       R # V P                  P                  V4       R # rX   )rp   r<   get_running_loop	call_soonr1   addr6   r   s   &&r   rK   SpeechHandle.add_done_callback   s;    99;;$$&00@  *r   c                    V ^8  d   QhRRRR/# r   r   )r&   s   "r   r'   r(      s     / /-K /PT /r   c                	<    V P                   P                  V4       R # rX   )r1   discardr   s   &&r   remove_done_callback!SpeechHandle.remove_done_callback   s    $$X.r   c                    V ^8  d   QhRRRR/# )r   awz!list[asyncio.futures.Future[Any]]r$   r%   r   )r&   s   "r   r'   r(      s     ! !0Q !VZ !r   c                	  "   \         P                  ! V Uu. uF  p\         P                  ! V4      NK  	  upR R/ pW0P                  0p\         P                  ! V\         P
                  R7      G Rj  xL
 w  rVW69   dR   \        P                  ! \         P                  4      ;_uu_ 4        VP                  4        VG Rj  xL
  RRR4       R# R# u upi  Ld L  + '       g   i     R# ; i5i)return_exceptionsT)return_whenN)
r<   gatherr   r>   waitFIRST_COMPLETED
contextlibsuppressCancelledErrorcancel)r6   r   fut
gather_futfsr+   pendings   &&     r   wait_if_not_interrupted$SpeechHandle.wait_if_not_interrupted   s     ^^R%HRcgnnS&9R%Ha\`a
(24G4G'H"<<8O8OPP
 $$W%;%;<<!!#    =< ! &IP ! =<<sE   C0C=C03C48C0,CCCC0CC-	'	C0c                   V ^8  d   QhRR/# r   r   )r&   s   "r   r'   r(      s       r   c                	  a  S P                  4       '       d   S # S P                  P                  4       '       gS   S P                  P                  R 4       R V 3R llp\        P                  ! 4       P                  \        V4      S n        S # )Nc                   V ^8  d   QhRR/# r   r   )r&   s   "r   r'   *SpeechHandle._cancel.<locals>.__annotate__   s     " " "r   c                    < \         P                  ! R RSP                  R\        /R7       SP                   F  p V P                  4        K  	  SP                  4        R# )zNspeech not done in time after interruption, cancelling the speech arbitrarily.r   timeout)r   N)r   errorr9   INTERRUPTION_TIMEOUTrD   r   
_mark_done)r   r6   s    r   _on_timeout)SpeechHandle._cancel.<locals>._on_timeout   sF    d&)=QR !KKDKKM (!r   )rp   r>   
set_resultr<   get_event_loop
call_laterr   rH   )r6   r   s   f r   r   SpeechHandle._cancel   sp    99;;K""''))**40" " .5-C-C-E-P-P$k.D* r   c                    V ^8  d   QhRRRR/# r   r   zCallable[[llm.ChatItem], Any]r$   r%   r   )r&   s   "r   r'   r(      s     1 11N 1SW 1r   c                	<    V P                   P                  V4       R # rX   )rJ   r   r   s   &&r   _add_item_added_callback%SpeechHandle._add_item_added_callback   s    ""&&x0r   c                    V ^8  d   QhRRRR/# r   r   )r&   s   "r   r'   r(      s     5 54Q 5VZ 5r   c                	<    V P                   P                  V4       R # rX   )rJ   r   r   s   &&r   _remove_item_added_callback(SpeechHandle._remove_item_added_callback   s    ""**84r   c                    V ^8  d   QhRRRR/# )r   itemszSequence[llm.ChatItem]r$   r%   r   )r&   s   "r   r'   r(      s     * *!7 *D *r   c                	    V FC  p\        V P                  4       F  p V! V4       K  	  V P
                  P                  V4       KE  	  R#   \         d'   p\        P                  ! R T 2TR7        Rp?K]  Rp?ii ; i)zerror in item_added_callback: r.   N)r0   rJ   r2   r   r3   rE   append)r6   r   itemr4   r5   s   &&   r   _item_addedSpeechHandle._item_added   sr    D4556VtH 7 ##D)  ! VNN%CB4#HSTUUVs   AA=A88A=c                   V ^8  d   QhRR/# r   r   )r&   s   "r   r'   r(      s     $ $t $r   c                	    \         P                  R ,          ! 4       pV P                  P                  V4       V P                  P                  4        R # rX   )r<   r=   rC   r   rB   rI   )r6   r   s   & r   _authorize_generation"SpeechHandle._authorize_generation   s9    nnT"$  %!!#r   c                   V ^8  d   QhRR/# r   r   )r&   s   "r   r'   r(      s     & &d &r   c                	:    V P                   P                  4        R # rX   )rB   clearrY   s   &r   _clear_authorization!SpeechHandle._clear_authorization   s    ##%r   c                   V ^8  d   QhRR/# r   r   )r&   s   "r   r'   r(     s     + +t +r   c                	V   "   V P                   P                  4       G R j  xL
  R #  L5irX   )rB   r   rY   s   &r   _wait_for_authorization$SpeechHandle._wait_for_authorization  s     ##((***s   )')c                    V ^8  d   QhRRRR/# )r   step_idxrV   r$   r%   r   )r&   s   "r   r'   r(     s     : :3 : :r   c                	   "   V P                   '       g   \        R 4      h\        P                  ! V P                   V,          4      G Rj  xL
  R#  L5i)z@cannot use wait_for_generation: no active generation is running.N)rC   r~   r<   r   )r6   r   s   &&r   _wait_for_generation!SpeechHandle._wait_for_generation  s:        abbnnT..x8999s   AA
AAc                   V ^8  d   QhRR/# r   r   )r&   s   "r   r'   r(   
  s     2 24 2r   c                	b   "   \         P                  ! V P                  4      G R j  xL
  R #  L5irX   )r<   r   r@   rY   s   &r   _wait_for_scheduled SpeechHandle._wait_for_scheduled
  s     nnT00111s   $/-/c                   V ^8  d   QhRR/# r   r   )r&   s   "r   r'   r(     s     3 3t 3r   c                	   V P                   '       g   \        R 4      h\        P                  ! \        P
                  4      ;_uu_ 4        V P                   R,          P                  R4       RRR4       R#   + '       g   i     R# ; i)zAcannot use mark_generation_done: no active generation is running.N)rC   r~   r   r   r<   InvalidStateErrorr   rY   s   &r   _mark_generation_done"SpeechHandle._mark_generation_done  sY       bcc  !:!:;;b!,,T2 <;;;s   
#A77B	c                   V ^8  d   QhRR/# r   r   )r&   s   "r   r'   r(     s     2 2D 2r   c                	r   \         P                  ! \        P                  4      ;_uu_ 4        V P                  P                  R 4       R R R 4       V P                  '       d   V P                  4        V P                  e$   V P                  P                  4        R V n        R # R #   + '       g   i     Le; irX   )
r   r   r<   r   r?   r   rC   r   rH   r   rY   s   &r   r   SpeechHandle._mark_done  s~      !:!:;;NN%%d+ < &&())5**113-1D* 6 <;s   B&&B6	c                   V ^8  d   QhRR/# r   r   )r&   s   "r   r'   r(   "  s     1 1 1r   c                	    \         P                  ! \        P                  4      ;_uu_ 4        V P                  P                  R 4       R R R 4       R #   + '       g   i     R # ; irX   )r   r   r<   r   r@   r   rY   s   &r   _mark_scheduledSpeechHandle._mark_scheduled"  s<      !:!:;;**40 <;;;s   AA$	)rG   r:   rB   rE   r1   r?   rC   r9   r;   r>   rH   rJ   rL   rF   r@   rD   N)r   )*r   r   r   r   SPEECH_PRIORITY_LOWSPEECH_PRIORITY_NORMALSPEECH_PRIORITY_HIGHrM   staticmethodDEFAULT_INPUT_DETAILSrS   propertyrZ   r_   r#   rf   rk   rq   rv   r!   setterr   rp   r   r   r   rK   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r      sv   [MN!1F $(&;
 
     # # / / 3 3
 * * * * ) ) *  *(    % -8)+/!,15*$
&+:2321 1r   r   )
__future__r   r<   r   collections.abcr   r   r   dataclassesr   typingr   r	   opentelemetryr
   otel_context r   r   logr   r   r   r  r   r   r   r   <module>r     s[    "   9 9 !  1    ' ' ' %g6 K1 K1r   