
    /j	                        S SK Jr  S SKJrJr  S SKJr  SSKJrJ	r	  \      S
S j5       r
\      SS j5       r
      SS jr
g	)    )annotations)AsyncGeneratorAsyncIterable)overload   )_basic_word	tokenizerc                    g N textreplacementss     N/app/agent/.venv/lib/python3.13/site-packages/livekit/agents/tokenize/utils.pyreplace_wordsr   	   s    
     c                    g r   r   r   s     r   r   r      s    
 r   c                  ^ ^^ TR                  5        VVs0 s H  u  p#UR                  5       U_M     snnmSU4S jjm[        T [        5      (       a#  [        R
                  " T SS9nT" T U5      u  m nT $ SUU 4S jjnU" 5       $ s  snnf )z
Replace words in the given (async) text. The replacements are case-insensitive and the
replacement will keep the case of the original word.
Args:
    text: text to replace words in
    words: dictionary of words to replace
c                l  > SnSnU H  u  pEnUR                  SR                  [        R                  5      5      n[	        U5      [	        U5      -
  nT
R                  UR                  5       5      n	U	(       a2  U S XR-    U	-   XU-   U-
  S  -   n U[	        U	5      [	        U5      -
  U-   -  nXb-   nM     X4$ )Nr    )rstripjoinr	   PUNCTUATIONSlengetlower)r   wordsoffsetprocessed_indexwordstart_index	end_indexno_punctuationpunctuation_offreplacementr   s             r   _process_words%replace_words.<locals>._process_words(   s    ,1(Dy![[1G1G)HIN!$i#n*==O&**>+?+?+ABK/;/0!"v-?ABC 
 #k*SY6HH'0O -2 $$r   Fignore_punctuationc                  >#    Sn T  S h  vN nX-  n [         R                  " U SS9n[        U5      S::  a  M3  T" XS S 5      u  pU S U 7v   XS  n MN   NI
 U (       a%  [         R                  " U SS9nT" X5      u  pU 7v   g g 7f)Nr   Fr(   r   )r   split_wordsr   )bufferchunkr   procesed_index_r&   r   s        r   _replace_words%replace_words.<locals>._replace_wordsA   s     F# 	1e#//5Qu:?)7cr
)K&_n--0	1t #//5Q*69	 s&   BAAAABA.B)r   strr   zlist[tuple[str, int, int]]returnztuple[str, int])r4   zAsyncGenerator[str, None])itemsr   
isinstancer3   r   r,   )r   r   kvr   r0   r1   r&   s   ``     @r   r   r      s     .:-?-?-AB-ATQAGGIqL-ABL%& $''G u-a	 	$ [ Cs   BN)r   r3   r   dict[str, str]r4   r3   )r   AsyncIterable[str]r   r9   r4   r:   )r   str | AsyncIterable[str]r   r9   r4   r;   )
__future__r   collections.abcr   r   typingr   r   r   r	   r   r   r   r   <module>r?      s    " 9  $ 

 ! 		 
 

 ! 	 
: 
":  !:  	: r   