
    /j4                        S SK Jr  S SKrS SKJr  SSKJr  SS.     SS jjrSSS.       SS	 jjrSSS.       SS
 jjr	g)    )annotationsN)rtc   )ATTRIBUTE_AGENT_NAME)
agent_namec                 ^^^#    U R                  5       (       d  [        S5      e[        R                  " 5       mS
U4S jjmSUU4S jjnSUU4S jjnSU4S jjnU R	                  SU5        U R	                  SU5        U R	                  SU5         U R
                  R                  5        HJ  nT" U5      (       d  M  Us  U R                  SU5        U R                  SU5        U R                  SU5        $    TI S	h  vN U R                  SU5        U R                  SU5        U R                  SU5        $  N:! U R                  SU5        U R                  SU5        U R                  SU5        f = f7f)a]  
Wait for an agent participant to join the room.

Args:
    room: The room to wait for the agent in.
    agent_name: If provided, waits for an agent with matching lk.agent.name attribute.
               If None, returns the first agent participant found.

Returns:
    The agent participant.

Raises:
    RuntimeError: If the room is not connected.
room is not connectedc                   > U R                   [        R                  R                  :w  a  gTc  gU R                  R                  [        5      T:H  $ )NFT)kindr   ParticipantKindPARTICIPANT_KIND_AGENT
attributesgetr   )pr   s    Q/app/agent/.venv/lib/python3.13/site-packages/livekit/agents/utils/participant.pymatches_agent%wait_for_agent.<locals>.matches_agent"   sB    66S((???|| 45CC    c                p   > T" U 5      (       a(  TR                  5       (       d  TR                  U 5        g g g N)done
set_result)r   futr   s    r   on_participant_connected0wait_for_agent.<locals>.on_participant_connected)   s,    CHHJJNN1 %/r   c                   > [        U[        R                  5      (       a6  T" U5      (       a(  TR                  5       (       d  TR	                  U5        g g g g r   )
isinstancer   RemoteParticipantr   r   )changedr   r   r   s     r   on_attributes_changed-wait_for_agent.<locals>.on_attributes_changed-   sC    a..//M!4D4DSXXZZNN1 NX4D/r   c                   > U [         R                  R                  :X  a1  TR                  5       (       d  TR	                  [        S5      5        g g g )Nz5room disconnected while waiting for agent participantr   ConnectionStateCONN_DISCONNECTEDr   set_exceptionRuntimeErrorstater   s    r   on_connection_state_changed3wait_for_agent.<locals>.on_connection_state_changed1   ?    C''999#((**l+bcd CM9r   participant_connectedparticipant_attributes_changedconnection_state_changedNr   rtc.RemoteParticipantreturnboolr   r1   r2   None)r   z	list[str]r   zrtc.Participantr2   r5   r)   intr2   r5   )isconnectedr'   asyncioFutureonremote_participantsvaluesoff)roomr   r   r    r*   r   r   r   s    `    @@r   wait_for_agentr@   
   sO    & 233181ACD  e 	GG#%=>GG,.CDGG&(CD
J))002AQ 	(*BC13HI+-HI 3 y(*BC13HI+-HI	 (*BC13HI+-HIsB   BE9(D>  D> 7E9:D> D<D> 7E9<D> >8E66E9)identityr   c                 ^^^^#    U R                  5       (       d  [        S5      e[        R                  [        R
                     " 5       mSU4S jjmS	UUU4S jjnS
U4S jjnU R                  SU5        U R                  SU5         U R                  R                  5        HJ  nUR                  [        R                  R                  :X  a  U" U5        TR                  5       (       d  MJ    O   TI Sh  vN U R                  SU5        U R                  SU5        $  N(! U R                  SU5        U R                  SU5        f = f7f)z
Returns a participant that matches the given identity. If identity is None, the first
participant that joins the room will be returned.
If the participant has already joined, the function will return immediately.
r	   c                r   > Tc  g[        T[        5      (       a  U R                  T;   $ U R                  T:H  $ NT)r   listr   )r   r   s    r   
kind_match(wait_for_participant.<locals>.kind_matchV   s4    <dD!!66T>!vv~r   c                   > Tb  U R                   T:X  a6  T" U 5      (       a(  TR                  5       (       d  TR                  U 5        g g g g r   )rA   r   r   )r   r   rA   rF   s    r   _on_participant_active4wait_for_participant.<locals>._on_participant_active_   sA    

h 6JqMM88::q!  =J 6r   c                   > U [         R                  R                  :X  a1  TR                  5       (       d  TR	                  [        S5      5        g g g )Nz/room disconnected while waiting for participantr#   r(   s    r   _on_connection_state_changed:wait_for_participant.<locals>._on_connection_state_changedd   s?    C''999#((**l+\]^ CM9r   participant_activer/   Nr0   r4   r6   )r8   r'   r9   r:   r   r   r;   r<   r=   r)   ParticipantStatePARTICIPANT_STATE_ACTIVEr   r>   )r?   rA   r   rI   rL   r   r   rF   s    ``   @@r   wait_for_participantrQ   F   s     233
....
/
1C" "
_ 	GG "89GG&(DE
K))002Aww#..GGG&q)xxzz	 3 y%'=>+-IJ %'=>+-IJs7   BEA D$ 0	D$ 9D":D$ =%E"D$ $&E

Ec                 ^^^^#    U R                  5       (       d  [        S5      e[        R                  [        R
                     " 5       mSU4S jjm      S	UUU4S jjnS
U4S jjnU R                  SU5        U R                  SU5         U R                  R                  5        HD  nUR                  R                  5        H#  nU" Xe5        TR                  5       (       d  M"    MB     MF     TI Sh  vN U R                  SU5        U R                  SU5        $  N(! U R                  SU5        U R                  SU5        f = f7f)zReturns a remote track matching the given identity and kind.
If identity is None, the first track matching the kind will be returned.
If the track has already been published, the function will return immediately.
r	   c                J   > Tc  g[        T[        5      (       a  U T;   $ U T:H  $ rD   )r   rE   )kr   s    r   rF   .wait_for_track_publication.<locals>.kind_match   s,    <dD!!9Dyr   c                   > TR                  5       (       a  g Tb  UR                  T:X  a*  T" U R                  5      (       a  TR                  U 5        g g g r   )r   rA   r   r   )publicationparticipantr   rA   rF   s     r   _on_track_published7wait_for_track_publication.<locals>._on_track_published   sM     88:: 4 4 @jQ\QaQaFbFbNN;' Gc @r   c                   > U [         R                  R                  :X  a1  TR                  5       (       d  TR	                  [        S5      5        g g g )Nz5room disconnected while waiting for track publicationr#   r(   s    r   rL   @wait_for_track_publication.<locals>._on_connection_state_changed   r,   r   track_publishedr/   N)rT   zrtc.TrackKind.ValueTyper2   r3   )rW   rtc.RemoteTrackPublicationrX   r1   r2   r5   r6   )r8   r'   r9   r:   r   RemoteTrackPublicationr;   r<   r=   track_publicationsr   r>   )	r?   rA   r   rY   rL   r   rW   r   rF   s	    ``    @@r   wait_for_track_publicationra   x   s$     233
..33
4
6C(/(>S(	( (e
 	GG23GG&(DE
K))002A 33::<#K388::  = 3 y"$78+-IJ "$78+-IJs7   BEAD$ +D$ 9D":D$ =%E"D$ $&E

E)r?   rtc.Roomr   
str | Noner2   r1   )r?   rb   rA   rc   r   zJlist[rtc.ParticipantKind.ValueType] | rtc.ParticipantKind.ValueType | Noner2   r1   )r?   rb   rA   rc   r   z>list[rtc.TrackKind.ValueType] | rtc.TrackKind.ValueType | Noner2   r^   )

__future__r   r9   livekitr   typesr   r@   rQ   ra    r   r   <module>rh      s    "   ( "9J
9J 9J 	9J~  W[	/K
/K /K U	/K
 /Kj  KO	3K
3K 3K I	3K
  3Kr   