
    /j[                        S SK Jr  S SKJr  S SKJr  S SKJrJr  SSK	J
r
  \" S5      r\" S5      r " S	 S
\\\4   5      rg)    )annotations)OrderedDict)Callable)AnyTypeVar   )loggerKVc                  j   ^  \ rS rSrSS	U 4S jjjrS
U 4S jjrSS jrSS jr S   SS jjrSr	U =r
$ )BoundedDict   c                   > [         TU ]  5         Xl        U R                  b  U R                  S::  a  [        S5      eg g )Nr   zmaxsize must be greater than 0)super__init__maxsize
ValueError)selfr   	__class__s     R/app/agent/.venv/lib/python3.13/site-packages/livekit/agents/utils/bounded_dict.pyr   BoundedDict.__init__   s<    <<#(9=>> ):#    c                   > [         TU ]  X5        U R                  bS  [        U 5      U R                  :  a9  U R	                  SS9  U R                  b  [        U 5      U R                  :  a  M7  g g g g )NFlast)r   __setitem__r   lenpopitem)r   keyvaluer   s      r   r   BoundedDict.__setitem__   s[    C'll&3t9t||+CLLeL$ ll&3t9t||+C&+C&r   c                   U R                  US5      nUc  U$ UR                  5        HS  u  pEUc  M
  [        X45      (       a  [        X4U5        M(  [        R
                  " SU[        U5      R                  5        MU     U$ )a  Update the value of a key with the given keyword arguments.
Only update the value if the field value is not None and the field exists on the value.

Args:
    key: The key to update.
    kwargs: The keyword arguments to update the value.

Returns:
    The value of the key.
Nz1field %s is not set on value of type %s, skipping)getitemshasattrsetattrr	   warningtype__name__)r   r   kwargsr    
field_namefield_values         r   update_valueBoundedDict.update_value   su     d#=L'-||~#J"u));7GK(( (6 r   c                n    U R                  US5      c	  U" 5       X'   U R                  " U40 UD6nUc   eU$ )a  Set a value for a key if it doesn't exist, or update it if it does.

Args:
    key: The key to set or update.
    factory: The factory function to create a new value if the key doesn't exist.
    kwargs: The keyword arguments to update the value.

Returns:
    The value of the key.
N)r#   r-   )r   r   factoryr*   results        r   set_or_updateBoundedDict.set_or_update5   sD     88C&	DI""31&1!!!r   c                    Uc  [        U 5      S:  a  U R                  SS9$ g[        [        U R	                  5       5      5       H&  u  p#U" U5      (       d  M  X R                  U5      4s  $    g)zPop an item from the dictionary if it satisfies the predicate.

Args:
    predicate: The predicate to check if the value satisfies.

Returns:
    A tuple of the key and value of the popped item.
r   Fr   )NN)r   r   reversedlistr$   pop)r   	predicater   r    s       r   pop_ifBoundedDict.pop_ifF   sf     4y1}|||//"4

#56JCHHSM)) 7 r   )r   )N)r   z
int | None)r   r
   r    r   returnNone)r   r
   r*   r   r;   zV | None)r   r
   r0   zCallable[[], V]r*   r   r;   r   )r8   zCallable[[V], bool] | Noner;   ztuple[K | None, V | None])r)   
__module____qualname____firstlineno__r   r   r-   r2   r9   __static_attributes____classcell__)r   s   @r   r   r      s=    ? ?%6& 15- 
# r   r   N)
__future__r   collectionsr   collections.abcr   typingr   r   logr	   r
   r   r    r   r   <module>rH      s=    " # $  CLCLM+ad# Mr   