
    i6                     T   d Z ddlmZmZmZ ddlmZ ddlmZm	Z	m
Z
mZ ddlZddlmZmZmZmZmZmZmZ  ee      j-                         j.                  d   Zedz  d	z  j-                         Zd
e
eeef      fdZded
eeef   fdZe G d de             Ze G d de             Z y)z!Agent skill configuration models.    )	dataclassfieldreplace)Path)AnyDictListMappingN)
BaseConfigConfigErrorConfigFieldSpec
EnumOptionoptional_boolextend_pathrequire_mapping   z.agentsskillsreturnc                  L   t         j                         rt         j                         sg S g } t        t         j	                               D ]  }|j                         s|dz  }|j                         s*	 t        |      }|j                  d      }|j                  d      }t        |t              r|j                         syt        |t              r|j                         s| j                  |j                         |j                         f        | S # t        $ r Y w xY w)NzSKILL.mdnamedescription)DEFAULT_SKILLS_ROOTexistsis_dirsortediterdiris_file_parse_frontmatter	Exceptionget
isinstancestrstripappend)
discovered	candidate
skill_filefrontmatterraw_nameraw_descriptions         G/Users/bowang/.openclaw/workspace/ChatDev/entity/configs/node/skills.py_discover_default_skillsr,      s    %%'/B/I/I/K	(*J/779:	!+
!!#	,Z8K ??6*%//-8(C(0@/3/7L7L7N8>>+_-B-B-DEF! ;"   		s   5D	D#"D#r'   c                    | j                  d      }|j                  d      st        d      |j                         }d }t	        dt        |            D ]  }||   j                         dk(  s|} n |t        d      dj                  |d|       }t        j                  |      xs i }t        |t              st        d      |S )	Nzutf-8)encodingz---zmissing frontmatter   zmissing closing delimiter
zfrontmatter must be a mapping)	read_text
startswith
ValueError
splitlinesrangelenr#   joinyaml	safe_loadr!   r
   )r'   textlinesend_idxidxpayloaddatas          r+   r   r   /   s    1D??5!.//OOEGQE
#:&G $ 455iia()G>>'"(bDdG$899K    c                        e Zd ZU eed<   d eddddd      iZedeee	f   ded	d fd
       Z
ed	eeef   f fd       Z xZS )AgentSkillSelectionConfigr   z
Skill Namer"   TzCDiscovered skill name from the default repo-level skills directory.)r   display_name	type_hintrequiredr   r?   pathr   c                    t        ||      }|j                  d      }t        |t              r|j	                         st        dt        |d             | |j	                         |      S )Nr   zskill name is required)r   rF   )r   r    r!   r"   r#   r   r   )clsr?   rF   mappingr   s        r+   	from_dictz#AgentSkillSelectionConfig.from_dictP   sV    !$-{{6"$$DJJL6D&8QRR

400r@   c           	      p   t         	|          }|j                  d      }||S t               }|D cg c]  \  }}|	 c}}xs d }|D cg c]  \  }}t	        |||       c}}xs d }|j
                  xs d}|s| dt         d}n| dt         d}t        ||||      |d<   |S c c}}w c c}}w )	Nr   )valuelabelr   z
Skill namez (no skills found in )z Picker options come from .)enumenum_optionsr   )superfield_specsr    r,   r   r   r   r   )
rH   specs	name_specr%   r   _enum_valuesr   rQ   	__class__s
            r+   rS   z%AgentSkillSelectionConfig.field_specsX   s    #%IIf%	L-/
+56:at:6>$ &0
%/!k T;G%/
   	  ++;|-45H4IK 
 -9:M9NaP   %#	
f ) 7
s   B,B2)__name__
__module____qualname__r"   __annotations__r   FIELD_SPECSclassmethodr
   r   rJ   r   rS   __classcell__)rX   s   @r+   rB   rB   B   s    
I 	%]
K 1WS#X. 1 1A\ 1 1 Do!56  r@   rB   c            
           e Zd ZU dZeed<    ee      Ze	e
   ed<    eddddddd	       edd
ddded      dZedee
ef   de
dd fd       Zedede
de	e
   fd       Zy)AgentSkillsConfigFenabled)default_factoryallowzEnable SkillsboolzJEnable Agent Skills discovery and the built-in skill tools for this agent.T)r   rC   rD   rE   defaultr   advancezAllowed Skillszlist[AgentSkillSelectionConfig]z[Optional allowlist of discovered skill names. Leave empty to expose every discovered skill.)r   rC   rD   rE   r   childrg   )rb   rd   r?   rF   r   c                    t        ||      }t        |d|d      }|d}| j                  |j                  d      t	        |d            } | |||      S )Nrb   F)rf   rd   )
field_path)rb   rd   rF   )r   r   _coerce_allow_entriesr    r   )rH   r?   rF   rI   rb   rd   s         r+   rJ   zAgentSkillsConfig.from_dict   s^    !$-D%H?G))'++g*>;W[]dKe)f7%d;;r@   rL   rj   c                   | g S t        | t              st        d|      g }t        |       D ]  \  }}| d| d}t        |t              r$|j                         }|r|j                  |       Bt        |t              r3t        j                  ||      }|j                  |j                         t        d|       |S )Nzexpected list of skill entries[])rF   z&expected skill entry mapping or string)r!   listr   	enumerater"   r#   r$   r
   rB   rJ   r   )rL   rj   resultr=   item	item_path
normalizedentrys           r+   rk   z'AgentSkillsConfig._coerce_allow_entries   s    =I%&>
KK"5)IC%,auA.I$$!ZZ\
MM*-$(1;;Dy;Qejj)F	RR * r@   N)rY   rZ   r[   rb   re   r\   r   ro   rd   r	   r"   r   rB   r]   r^   r
   r   rJ   staticmethodrk    r@   r+   ra   ra   w   s    GTT2E492 #(d
 !)7u+
K* <WS#X. < <AT < < S  c  r@   ra   )!__doc__dataclassesr   r   r   pathlibr   typingr   r   r	   r
   r8   entity.configs.baser   r   r   r   r   r   r   __file__resolveparents	REPO_ROOTr   tupler"   r,   objectr   rB   ra   rw   r@   r+   <module>r      s    ' 1 1  + +    N""$,,Q/	 9,x7@@B $uS#X"7 24 GCK,@ & 1
 1 1h 8
 8 8r@   