
    i                     l    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mZ e G d de             Zy)z)Configuration for loop timer guard nodes.    )	dataclass)MappingAnyOptional)
BaseConfigConfigErrorConfigFieldSpec
EnumOptionrequire_mappingextend_pathoptional_strc                   d   e Zd ZU dZdZeed<   dZeed<   dZ	e
ed<   dZee   ed	<   d
Z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g d eddd       eddd       edd d!      g"       edd#d$d
dd%d&       ed	d'd(d
d)d*       edd+d$d
d
d,d&      d-Zy)/LoopTimerConfigz2Configuration schema for the loop timer node type.      N@max_durationsecondsduration_unitTreset_on_emitNmessageFpassthroughdatapathreturnc                (   t        |xs i |      }|j                  dd      }	 t        |      }|dk  rt        dt        |d            t        |j                  dd            }g d}||vr(t        d	d
j                  |       t        |d            t        |j                  dd            }	t        |d|      }
t        |j                  dd            } | |||	|
||      S # t        t        f$ r}t        dt        |d            |d }~ww xY w)Nr   r   zmax_duration must be a numberr   max_duration must be > 0r   r   r   minuteshoursduration_unit must be one of: , r   Tr   r   F)r   r   r   r   r   r   )r   getfloat	TypeError
ValueErrorr   r   strjoinboolr   )clsr   r   mappingmax_duration_rawr   excr   valid_unitsr   r   r   s               K/Users/bowang/.openclaw/workspace/ChatDev/entity/configs/node/loop_timer.py	from_dictzLoopTimerConfig.from_dict   s6    "$*"d3";;~t<	 !12L 1*Kn,M  GKKCD5+0;1G0HID/2 
 W[[$?@w	487;;}e<=%''#
 	
/ :& 	/D.1 	s   C& &D5DDc                     | j                   dk  r t        dt        | j                  d            g d}| j                  |vr2t        ddj                  |       t        | j                  d            y )Nr   r   r   r   r   r    r   )r   r   r   r   r   r&   )selfr,   s     r-   validatezLoopTimerConfig.validateC   sv    !*K		>,R  6[00;1G0HIDII7  1    zMaximum Durationr"   z;How long the loop can run before this node emits an output.)namedisplay_name	type_hintrequireddefaultdescriptionzDuration Unitr%   z@Unit of time for max_duration: 'seconds', 'minutes', or 'hours'.r   SecondszTime in seconds)valuelabelr8   r   MinuteszTime in minutesr   HourszTime in hours)r3   r4   r5   r6   r7   r8   enumenum_optionszReset After Emitr'   z=Whether to reset the internal timer after reaching the limit.)r3   r4   r5   r6   r7   r8   advancezRelease Messagetextz=Optional text sent downstream once the time limit is reached.)r3   r4   r5   r6   r8   r@   zPassthrough ModezXIf true, after emitting the limit message, all subsequent inputs pass through unchanged.)r   r   r   r   r   )r   N)__name__
__module____qualname____doc__r   r"   __annotations__r   r%   r   r'   r   r   r   classmethodr   r   r.   r1   r	   r
   FIELD_SPECS r2   r-   r   r      sK   <L%"M3"M4!GXc]!K%
38$t+%
69%
	%
 %
N (+U
 ) (Z0#9BS #9BS _U
$ ) +W
 #*W
 '+r
Y5Kr2   r   N)rE   dataclassesr   typingr   r   r   entity.configs.baser   r   r	   r
   r   r   r   r   rI   r2   r-   <module>rM      s>    / ! ) )   sj s sr2   