
    i%              	          d Z ddlmZmZ ddlmZmZmZ ddlm	Z	 ddl
mZmZ ddlmZmZmZmZmZmZmZ ddlmZ ddlmZ dd	lmZmZ  ed
      Zdddedee   dedz  ddfdZdedee   fdZ deeee   f   fdZ!deeeeef   f   fdZ"e G d de             Z#e G d de             Z$e G d de             Z%y)z1Subgraph node configuration and registry helpers.    )	dataclassreplace)AnyDictMapping)LogLevel)enum_options_forenum_options_from_values)
BaseConfigConfigErrorConfigFieldSpecChildKeyrequire_mappingrequire_strextend_path)
EdgeConfig)MemoryStoreConfig)RegistryRegistryErrorsubgraph_sourceN)descriptionname
config_clsr   returnc                D    |rd|ind}t         j                  | ||       y)z/Register a subgraph source configuration class.summaryN)targetmetadata)subgraph_source_registryregister)r   r   r   r   s       I/Users/bowang/.openclaw/workspace/ChatDev/entity/configs/node/subgraph.pyregister_subgraph_sourcer"      s'     ,7	;'DH%%d:%Q    c                     t         j                  |       }|j                         }t        |t              rt        |t              st        d|  d      |S )NzEntry 'z' is not a BaseConfig subclass)r   getload
isinstancetype
issubclassr   r   )r   entryr   s      r!   get_subgraph_source_configr+   %   sK    $((.EJj$'z*j/QgdV+IJKKr#   c                  z    t         j                         D  ci c]  \  } }| |j                          c}} S c c}} w N)r   itemsr&   r   r*   s     r!   "iter_subgraph_source_registrationsr0   -   s4    2J2P2P2RS2R;4D%**,2RSSSs   7c            	          t         j                         D  ci c]  \  } }| t        |j                  xs i       ! c}} S c c}} w r-   )r   r.   dictr   r/   s     r!   iter_subgraph_source_metadatar3   1   s<    @X@^@^@`a@`uD$u~~+,,@`aaas   $A c                   ^    e Zd ZU eed<   edeeef   dedd fd       Zd e	ddddd	
      iZ
y)SubgraphFileConfig	file_pathdatapathr   c                H    t        ||      }t        |d|      } | ||      S )Nr8   )r6   r8   )r   r   )clsr7   r8   mappingr6   s        r!   	from_dictzSubgraphFileConfig.from_dict9   s)    !$-6	YT22r#   zSubgraph File PathstrTz@Subgraph file path (relative to yaml_instance/ or absolute path)r   display_name	type_hintrequiredr   N)__name__
__module____qualname__r=   __annotations__classmethodr   r   r<   r   FIELD_SPECS r#   r!   r5   r5   5   sZ    N3WS#X. 3 3AU 3 3 	-Z
Kr#   r5   c                   &   e Zd ZU eeef   ed<   edeeef   dedd fd       Z	d;dZ
 eddd	d
d       eddd	dd       eddddej                  j                  eD  cg c]  }|j                   c}} d ee             edddddd       edddd
d       edd d!d
d"e#       ed$d%d&dd'e#       ed(d)d*di d+       ed,d-d	dd.       ed/d0d	dd1       ed2d3d4dd5       ed6d7d4dd8      d9Zedeeef   ffd:       ZxZS c c}} w )<SubgraphInlineConfiggraphr7   r8   r   c                @    t        ||      } | t        |      |      S )N)rK   r8   )r   r2   )r:   r7   r8   r;   s       r!   r<   zSubgraphInlineConfig.from_dictN   s    !$-gT22r#   c                     d| j                   vr t        dt        | j                  d            d| j                   vr t        dt        | j                  d            y )Nnodesz!subgraph config must define nodesedgesz!subgraph config must define edges)rK   r   r   r8   selfs    r!   validatezSubgraphInlineConfig.validateS   sS    $**$A;tyyZaCbcc$**$A;tyyZaCbcc %r#   idzSubgraph IDr=   TzSubgraph identifierr>   r   zSubgraph DescriptionFzsDescribe the subgraph's responsibility, trigger conditions, and success criteria so reviewers know when to call it.	log_levelz	Log Levelzenum:LogLevelzSubgraph runtime log level)r   r?   r@   rA   defaultenumr   enum_optionsis_majority_votingzMajority Votingboolz2Whether to perform majority voting on node results)r   r?   r@   rA   rU   r   rN   z	Node Listz
list[Node]z2Subgraph node list, must contain at least one noderO   z	Edge Listzlist[EdgeConfig]zSubgraph edge list)r   r?   r@   rA   r   childmemoryzMemory Storeszlist[MemoryStoreConfig]ztProvide a list of memory stores if this subgraph needs dedicated stores; leave empty to inherit parent graph stores.vars	Variableszdict[str, Any]z"Variables passed to subgraph nodesorganizationOrganizationz%Subgraph organization/team identifierinitial_instructionzInitial Instructionz"Subgraph level initial instructionstartz
Start Nodezstr | list[str]z\Start node ID list (entry list executed at subgraph start; not recommended to edit manually)endzEnd NodezEnd node ID list (used to collect final subgraph output, not part of execution logic). This is an ordered list: earlier nodes are checked first; the first with output becomes the subgraph output, otherwise continue down the list.)rS   r   rT   rX   rN   rO   r[   r\   r^   r`   ra   rb   c                 v    t         |          }|j                  d      }|rddlm} t        ||      |d<   |S )NrN   r   )Node)rZ   )superfield_specsr%   entity.configs.node.noderd   r   )r:   specs
nodes_specrd   	__class__s       r!   rf   z SubgraphInlineConfig.field_specs   s9    #%YYw'
5$Zt<E'Nr#   r   N)rB   rC   rD   r   r=   r   rE   rF   r   r<   rR   r   r   INFOvaluer	   r   r   rG   rf   __classcell__).0lvlrj   s   00@r!   rJ   rJ   J   s   S>3WS#X. 3 3AW 3 3d &-
 '/ N
 %$%MM'''/0x#))x04)(3	
 .%*L
 !$"L
 !$(,
 "(/ O#
  $&<
 ('?
  /&.< 
 !%'v
 #' @
k\K| Do!56  U 1s   !DrJ   c                        e Zd ZU eed<   dZedz  ed<   edeee	f   dedd fd       Z
ddZ edd	d
dd       eddddd      dZedeeee   f   fd       Zedeeef   f fd       Z xZS )SubgraphConfigr(   Nconfigr7   r8   r   c                   t        ||      }t        |d|      }d|v r|d   rt        dt        |d            d|vs|d   t        dt        |d            	 t	        |      }|j                  |d   t        |d            } | |||      S # t
        $ r>}t        dt        t               j                                t        |d            |d }~ww xY w)	Nr(   r\   z6vars is only allowed at root level (DesignConfig.vars)rs   z.subgraph configuration requires 'config' blockzsubgraph.type must be one of )r8   )r(   rs   r8   )
r   r   r   r   r+   r   listr0   keysr<   )r:   r7   r8   r;   source_typer   exc
config_objs           r!   r<   zSubgraphConfig.from_dict   s    !$-!'648WVXcdhjpXqrr7"gh&7&?NP[\`bjPkll	3K@J  ))'(*;+dT\B])^
JTBB  	/5W5Y5^5^5`0a/bcD&) 	s   B 	C9CCc                     | j                   s t        dt        | j                  d            t	        | j                   d      r| j                   j                          y y )Nzsubgraph config missingrs   rR   )rs   r   r   r8   hasattrrR   rP   s    r!   rR   zSubgraphConfig.validate   sF    {{7TYYPX9YZZ4;;
+KK  " ,r#   zSubgraph Source Typer=   TzURegistered subgraph source such as 'config' or 'file' (see subgraph_source_registry).r>   zSubgraph Configurationobjectuv   Payload interpreted by the chosen type—for example inline graph schema for 'config' or file path payload for 'file'.)r(   rs   c                 |    t               j                         D ci c]  \  }}t        d|      | c}}S c c}}w )Nrs   )fieldrm   )r0   r.   r   )r:   r   r   s      r!   child_routeszSubgraphConfig.child_routes   sG     %G$H$N$N$P
$P j 840*<$P
 	
 
s   8c           	      L   t         |          }|j                  d      }|r|t               }t	               }t        |j                               }|D ci c]'  }||j                  |      xs i j                  d      ) }}t        ||t        ||d            |d<   |S c c}w )Nr(   r   T)preserve_label_case)rV   rW   )	re   rf   r%   r0   r3   ru   rv   r   r
   )	r:   rh   	type_specregistrationsr   namesr   descriptionsrj   s	           r!   rf   zSubgraphConfig.field_specs   s    #%IIf%	>@M46H++-.ELQLQDx||D)/R44Y??E   $5e\_cdE&M
 s   ,B!rk   )rB   rC   rD   r=   rE   rs   r   rF   r   r   r<   rR   r   rG   r   r   r(   r   rf   rn   )rj   s   @r!   rr   rr      s    
I $FJ$CWS#X. C CAQ C C(#  /o
 "1 Q
K" 
T(D,<"<= 
 
 Do!56  r#   rr   )&__doc__dataclassesr   r   typingr   r   r   entity.enumsr   entity.enum_optionsr	   r
   entity.configs.baser   r   r   r   r   r   r   entity.configs.edge.edger   entity.configs.node.memoryr   utils.registryr   r   r   r=   r(   r"   r+   r0   r3   r5   rJ   rr   rH   r#   r!   <module>r      s*   7 * % % ! J   0 8 2 $$56  #		R
	R Z 	R t		R
 
	RS T*-= TDd:6F1F,G TbtCc3h,?'@ b   ( t: t tn GZ G Gr#   