
    Ng                        d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
 erd dlmZ d dlmZ  G d de          Z G d d	e	          Z G d
 d          ZdS )    )annotations)Enum)TYPE_CHECKINGAnyDictList
NamedTupleOptional)DeltaGenerator)SupportsStrc                      e Zd ZdZdZdZdS )	ChildTypezEnumerator of the child type.MARKDOWN	EXCEPTIONN)__name__
__module____qualname____doc__r   r        t/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/callbacks/streamlit/mutable_expander.pyr   r      s        ''HIIIr   r   c                  2    e Zd ZU dZded<   ded<   ded<   dS )	ChildRecordzChild record as a NamedTuple.r   typeDict[str, Any]kwargsr   dgN)r   r   r   r   __annotations__r   r   r   r   r      s9         ''OOOr   r   c                      e Zd ZdZd.dZed/d
            Zed0d            Zd1dZd2dZ	dddd3dZ
	 d4dddd5d Zdd!d6d$Zd7d)Zd8d,Zd9d-ZdS ):MutableExpanderzJStreamlit expander that can be renamed and dynamically expanded/collapsed.parent_containerr   labelstrexpandedboolc                    || _         || _        |                                | _        | j                            ||          | _        g | _        dS )a;  Create a new MutableExpander.

        Parameters
        ----------
        parent_container
            The `st.container` that the expander will be created inside.

            The expander transparently deletes and recreates its underlying
            `st.expander` instance when its label changes, and it uses
            `parent_container` to ensure it recreates this underlying expander in the
            same location onscreen.
        label
            The expander's initial label.
        expanded
            The expander's initial `expanded` value.
        N)_label	_expandedempty_parent_cursorexpander
_container_child_records)selfr!   r"   r$   s       r   __init__zMutableExpander.__init__   sN    " !.4466-66uhGG13r   returnc                    | j         S )zExpander's label string.)r'   r.   s    r   r"   zMutableExpander.label4   s     {r   c                    | j         S )z6True if the expander was created with `expanded=True`.)r(   r2   s    r   r$   zMutableExpander.expanded9   s     ~r   Nonec                t    | j                                         | _        | j                                         dS )zeRemove the container and its contents entirely. A cleared container can't
        be reused.
        N)r*   r)   r,   r-   clearr2   s    r   r6   zMutableExpander.clear>   s5     -3355!!#####r   otherc                    |j                                         }|D ]"}|                     |j        |j                   #dS )z]Append a copy of another MutableExpander's children to this
        MutableExpander.
        N)r-   copy_create_childr   r   )r.   r7   other_recordsrecords       r   append_copyzMutableExpander.append_copyE   sN     ,1133# 	; 	;Fv{FM::::	; 	;r   N)	new_labelnew_expandedr>   Optional[str]r?   Optional[bool]c                  || j         }|| j        }| j         |k    r| j        |k    rdS || _         || _        | j                            ||          | _        | j        }g | _        |D ]"}|                     |j        |j                   #dS )z.Change the expander's label and expanded stateN)	r'   r(   r*   r+   r,   r-   r:   r   r   )r.   r>   r?   prev_recordsr<   s        r   updatezMutableExpander.updateM   s     I>L;)##,(F(FF%-66y,OO*  # 	; 	;Fv{FM::::	; 	;r   F)helpindexbodyr   unsafe_allow_htmlrE   rF   Optional[int]intc                   |||d} |                      |          j        di |}t          t          j        ||          }|                     ||          S )z=Add a Markdown element to the container and return its index.)rG   rH   rE   r   )_get_dgmarkdownr   r   r   _add_record)r.   rG   rH   rE   rF   r   new_dgr<   s           r   rM   zMutableExpander.markdowne   sc     5FPTUU-e$$-7777Y/@@...r   )rF   	exceptionBaseExceptionc                   d|i} |                      |          j        di |}t          t          j        ||          }|                     ||          S )z?Add an Exception element to the container and return its index.rP   r   )rL   rP   r   r   r   rN   )r.   rP   rF   r   rO   r<   s         r   rP   zMutableExpander.exceptions   s\     y).e$$.8888Y0&&AA...r   r   r   r   r   c                    |t           j        k    r | j        di | dS |t           j        k    r | j        di | dS t          d|           )z(Create a new child with the given paramszUnexpected child type Nr   )r   r   rM   r   rP   RuntimeError)r.   r   r   s      r   r:   zMutableExpander._create_child|   sq    9%%%DM##F#####Y(((DN$$V$$$$$>>>???r   r<   r   c                    ||| j         |<   |S | j                             |           t          | j                   dz
  S )zAdd a ChildRecord to self._children. If `index` is specified, replace
        the existing record at that index. Otherwise, append the record to the
        end of the list.

        Return the index of the added record.
        N   )r-   appendlen)r.   r<   rF   s      r   rN   zMutableExpander._add_record   sK     )/D&L 	""6***4&''!++r   c                    |@d|cxk    rt          | j                  k     sn J d|             | j        |         j        S | j        S )Nr   zBad index: )rX   r-   r   r,   )r.   rF   s     r   rL   zMutableExpander._get_dg   sd    8888D$7 8 888888:O:O:O888&u-00 r   )r!   r   r"   r#   r$   r%   )r0   r#   )r0   r%   )r0   r4   )r7   r    r0   r4   )r>   r@   r?   rA   r0   r4   )F)
rG   r   rH   r%   rE   r@   rF   rI   r0   rJ   )rP   rQ   rF   rI   r0   rJ   )r   r   r   r   r0   r4   )r<   r   rF   rI   r0   rJ   )rF   rI   r0   r   )r   r   r   r   r/   propertyr"   r$   r6   r=   rD   rM   rP   r:   rN   rL   r   r   r   r    r       sQ       TT4 4 4 4.    X    X$ $ $ $; ; ; ; -1QU; ; ; ; ; ;6 #(/
 ##/ / / / / / CG/ / / / / /@ @ @ @, , , ,      r   r    N)
__future__r   enumr   typingr   r   r   r   r	   r
   streamlit.delta_generatorr   streamlit.type_utilr   r   r   r    r   r   r   <module>r`      s   " " " " " "       G G G G G G G G G G G G G G G G 0888888//////           *   B B B B B B B B B Br   