
    ir	                     |    d Z ddlmZmZ ddlmZ ddlm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?FunctionEdgeManager centralizes function-based edge conditions.    )CallableOptional)FunctionEdgeConditionConfig)get_server_logger   )ConditionFactoryContext)EdgeConditionManager)FunctionManager   )ExecutionContextc            	            e Zd Zdedededdf fdZdeege	f   fdZ
	 	 ddZd	ed
ed   deeege	f      fdZ xZS )FunctionEdgeConditionManagerconfigctxexecution_contextreturnNc                     t         |   |||       |j                  xs d| _        | j                  xs d| _        d| j                  i| _        | j                         | _        y )Ntruefunction)super__init__name_namelabelmetadata_build_evaluator
_evaluator)selfr   r   r   	__class__s       U/Users/bowang/.openclaw/workspace/ChatDev/runtime/edge/conditions/function_manager.pyr   z%FunctionEdgeConditionManager.__init__   sU    &78[[*F
ZZ)6
#TZZ0//1    c                 X     j                   dk(  rd S  j                   j                    j                  j                        Qt	               }|j                  d j                    d        j                   dd _        dt        dt        f fd	}|S d
t        dt        ffd}|S )Nr   c                      y)NT )_s    r    <lambda>z?FunctionEdgeConditionManager._build_evaluator.<locals>.<lambda>   s    Tr!   zEdge condition function 'z' not found; defaulting to trueT)r   missingr%   r   c                     j                   j                  r3j                   j                  j                  dj                   d       y)NzCondition function 'z' not found, defaulting to trueT)r   log_managerwarningr   )r%   r   s    r    r'   z>FunctionEdgeConditionManager._build_evaluator.<locals>.missing   s>    88''HH((00.tzzl:YZ r!   datac                 &    t         |             S N)bool)r+   function_objs    r    	evaluatorz@FunctionEdgeConditionManager._build_evaluator.<locals>.evaluator(   s    T*++r!   )	r   _resolve_functionr   function_managerr   r*   r   strr.   )r   loggerr'   r0   r/   s   `   @r    r   z-FunctionEdgeConditionManager._build_evaluator   s    ::!!--djj$((:S:ST&(FNN6tzzlBabc)-EDM3 4  N	,C 	,D 	, r!   c           	      p    | j                  | j                  | j                  | j                  ||||       y )N)r   r   	edge_linksource_result	from_noder)   )_process_with_conditionr   r   r   )r   r6   r7   r8   r)   s        r    processz$FunctionEdgeConditionManager.process-   s8     	$$OO**]]'# 	% 	
r!   r   r2   r
   c                 *    |sy |j                  |      S r-   )get_function)r   r   r2   s      r    r1   z.FunctionEdgeConditionManager._resolve_function>   s      ,,T22r!   )r   N)__name__
__module____qualname__r   r   r   r   r   r3   r.   r   r:   r   r1   __classcell__)r   s   @r    r   r      s    2: 2AX 2m} 2  CG 2(C5$;"7 0
 

"33+34E+F3	(C5$;'	(3r!   r   N)__doc__typingr   r   "entity.configs.edge.edge_conditionr   utils.structured_loggerr   baser   r	   utils.function_managerr
   node.executorr   r   r$   r!   r    <module>rH      s0    E % J 5 ) & 2 -63#78S#T 63r!   