o
    i                     @   sL   d Z ddlmZmZmZmZ ddlmZmZ ddl	m
Z
 G dd deZdS )zText sentence aggregation processor for Pipecat.

This module provides a frame processor that accumulates text frames into
complete sentences, only outputting when a sentence-ending pattern is detected.
    )EndFrameFrameInterimTranscriptionFrame	TextFrame)FrameDirectionFrameProcessor)match_endofsentencec                       s6   e Zd ZdZ fddZdedef fddZ  ZS )SentenceAggregatora  Aggregates text frames into complete sentences.

    This processor accumulates incoming text frames until a sentence-ending
    pattern is detected, then outputs the complete sentence as a single frame.
    Useful for ensuring downstream processors receive coherent, complete sentences
    rather than fragmented text.

    Frame input/output::

        TextFrame("Hello,") -> None
        TextFrame(" world.") -> TextFrame("Hello, world.")
    c                    s   t    d| _dS )zInitialize the sentence aggregator.

        Sets up internal state for accumulating text frames into complete sentences.
         N)super__init___aggregation)self	__class__ [/home/ubuntu/.local/lib/python3.10/site-packages/pipecat/processors/aggregators/sentence.pyr       s   

zSentenceAggregator.__init__frame	directionc                    s   t  ||I dH  t|trdS t|tr6|  j|j7  _t| jr4| t| jI dH  d| _dS dS t|t	rS| jrI| t| jI dH  | |I dH  dS | ||I dH  dS )zProcess incoming frames and aggregate text into complete sentences.

        Args:
            frame: The incoming frame to process.
            direction: The direction of frame flow in the pipeline.
        Nr
   )
r   process_frame
isinstancer   r   r   textr   
push_framer   )r   r   r   r   r   r   r   (   s   




z SentenceAggregator.process_frame)	__name__
__module____qualname____doc__r   r   r   r   __classcell__r   r   r   r   r	      s    r	   N)r   pipecat.frames.framesr   r   r   r   "pipecat.processors.frame_processorr   r   pipecat.utils.stringr   r	   r   r   r   r   <module>   s
   