
    il
                     \    d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ  G d	 d
ee         Z	y)z=KeywordEdgeManager implements declarative keyword conditions.    N)KeywordEdgeConditionConfig   )ConditionFactoryContext)EdgeConditionManager   )ExecutionContextc                   L     e Zd Zdedededdf fdZdedefdZ		 	 d
d	Z
 xZS )KeywordEdgeConditionManagerconfigctxexecution_contextreturnNc                    t         |   |||       t        |j                        | _        t        |j                        | _        t        |j
                        | _        t        |j                        | _        t        |j                        | _	        | j                  rdnt        j                  }| j                  r#| j                  | _        | j                  | _        nZ| j                  D cg c]  }|j                          c}| _        | j                  D cg c]  }|j                          c}| _        | j
                  D cg c]  }t        j                  ||       c}| _        dt#        | j                         dt#        | j                         dt#        | j
                         d| _        | j                  | j                  | j
                  | j                  | j                  d| _        y c c}w c c}w c c}w )Nr   zkeyword(any=z, none=z, regex=))anynoneregexcase_sensitivedefault)super__init__listany_keywordsnone_keywordsregex_patternsboolr   r   default_valuere
IGNORECASEprocessed_anyprocessed_nonelowercompilecompiled_regexlenlabelmetadata)selfr   r   r   lowered_regex_flagskwpattern	__class__s          T/Users/bowang/.openclaw/workspace/ChatDev/runtime/edge/conditions/keyword_manager.pyr   z$KeywordEdgeConditionManager.__init__   s   &78 !4!45!&"6"67"6#8#89"6#8#89!&..1#'#6#6aBMM!%!2!2D"&"4"4D7;7H7H!I7H"((*7H!ID8<8J8J"K8J"288:8J"KDW[WjWjkWjGrzz'3FGWjk#C(9(9$:#;73tGYGYCZB[[cdghlh{h{d|c}}~
$$&&(("11))
	 "J"Kks   0G9G>
Hdatac                 "   | j                   r|n|j                         }| j                  D ]  }|s||v s y | j                  D ]  }|s||v s y | j                  D ]  }|j                  |      s y | j                  s| j                  ryy)NFT)r   r"   r!   r    r$   searchr   r   )r(   r.   haystackkeywordr+   s        r-   	_evaluatez%KeywordEdgeConditionManager._evaluate$   s    ..4DJJL**G7h. + ))G7h. * **G~~d# +  3 3    c           	      p    | j                  | j                  | j                  | j                  ||||       y )N)r&   r'   	edge_linksource_result	from_nodelog_manager)_process_with_conditionr3   r&   r'   )r(   r6   r7   r8   r9   s        r-   processz#KeywordEdgeConditionManager.process3   s8     	$$NN**]]'# 	% 	
r4   )r   N)__name__
__module____qualname__r   r   r   r   strr   r3   r;   __classcell__)r,   s   @r-   r
   r
      sN    
9 
@W 
l| 
  BF 
0c d 
 

r4   r
   )
__doc__r   "entity.configs.edge.edge_conditionr   baser   r   node.executorr   r
    r4   r-   <module>rF      s*    C 	 I ) & -7
"67Q"R 7
r4   