
    i	
                     h    d Z ddlmZ ddlmZmZmZ ddlmZm	Z	m
Z
mZmZmZ e G d de             Zy)z+Configuration for loop counter guard nodes.    )	dataclass)MappingAnyOptional)
BaseConfigConfigErrorConfigFieldSpecrequire_mappingextend_pathoptional_strc            
           e Zd ZU dZdZeed<   dZeed<   dZ	e
e   ed<   edeeef   dz  d	ed
d fd       ZddZ edddddd       eddddddd       edddddd      dZy)LoopCounterConfigz4Configuration schema for the loop counter node type.
   max_iterationsTreset_on_emitNmessagedatapathreturnc                X   t        |xs i |      }|j                  dd      }	 t        |      }|dk  rt        dt        |d            t        |j                  dd            }t        |d|      } | ||||	      S # t        t        f$ r}t        dt        |d            |d }~ww xY w)
Nr   r   z!max_iterations must be an integer   max_iterations must be >= 1r   Tr   )r   r   r   r   )	r
   getint	TypeError
ValueErrorr   r   boolr   )	clsr   r   mappingmax_iterations_rawr   excr   r   s	            M/Users/bowang/.openclaw/workspace/ChatDev/entity/configs/node/loop_counter.py	from_dictzLoopCounterConfig.from_dict   s    !$*"d3$[[)92>	 !34N A;[O_=`aaW[[$?@w	48)'	
 	
 :& 	3D"23 	s   A> >B)B$$B)c                 b    | j                   dk  r t        dt        | j                  d            y )Nr   r   r   )r   r   r   r   )selfs    r"   validatezLoopCounterConfig.validate1   s/    ";[Td=eff #    zMaximum Iterationsr   zAHow many times the loop can run before this node emits an output.)namedisplay_name	type_hintrequireddefaultdescriptionzReset After Emitr   Fz?Whether to reset the internal counter after reaching the limit.)r(   r)   r*   r+   r,   r-   advancezRelease Messagetextz@Optional text sent downstream once the iteration cap is reached.)r(   r)   r*   r+   r-   r.   )r   r   r   )r   N)__name__
__module____qualname____doc__r   r   __annotations__r   r   r   r   strclassmethodr   r   r#   r&   r	   FIELD_SPECS r'   r"   r   r      s    >NCM4!GXc]!
WS#X.5 
 
H[ 
 
0g
 *!-[
 ) +Y
 #*Z
%Kr'   r   N)r3   dataclassesr   typingr   r   r   entity.configs.baser   r   r	   r
   r   r   r   r8   r'   r"   <module>r<      s6    1 ! ) )  >
 > >r'   