o
    ¯ŠTj	  ã                   @  st   d Z ddlmZ ddlZddlmZ ddlmZ ddlZee	ƒ 
¡ jd Zed d ZG d	d
„ d
ƒZdddd„ZdS )zËLoad and access config/config.yaml.

Every script and runtime module reads the same YAML file so behavior is configured in one place.
Access nested keys with dotted paths: cfg.get("retrieval.top_k", 4).
é    )ÚannotationsN)ÚPath)ÚAnyé   Zconfigzconfig.yamlc                   @  s@   e Zd ZdZddd„Zdddd„Zdddd„Zeddd„ƒZdS )ÚConfigzNThin wrapper over the parsed YAML with dotted-path access and path resolution.Údataúdict[str, Any]Úpathr   c                 C  s   || _ || _d S ©N)Ú_datar	   )Úselfr   r	   © r   úsrc/agent/settings.pyÚ__init__   s   
zConfig.__init__NÚ
dotted_keyÚstrÚdefaultr   Úreturnc                 C  s<   | j }| d¡D ]}t|tƒr||vr|  S || }q|S )NÚ.)r   ÚsplitÚ
isinstanceÚdict)r   r   r   ZnodeÚpartr   r   r   Úget   s   
z
Config.getú
str | Nonec                 C  s>   |   ||¡}|du rtd|› �ƒ‚t|ƒ}| ¡ r|S t| S )zDResolve a config value that is a path, relative to the project root.NzMissing path config key: )r   ÚKeyErrorr   Úis_absoluteÚPROJECT_ROOT)r   r   r   ÚvalueÚpr   r   r   Úresolve"   s
   zConfig.resolvec                 C  s   | j S r
   )r   )r   r   r   r   r   *   s   zConfig.data)r   r   r	   r   r
   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r    Úpropertyr   r   r   r   r   r      s    
r   r	   ústr | os.PathLike | Noner   c                 C  sf   | rt | ƒnt}| ¡ st| }t|ddd��}t |¡pi }W d   ƒ n1 s)w   Y  t||ƒS )NÚrzutf-8)Úencoding)r   ÚDEFAULT_CONFIGr   r   ÚopenÚyamlZ	safe_loadr   )r	   Zcfg_pathÚfr   r   r   r   Úload_config/   s   ÿ
r-   r
   )r	   r&   r   r   )r$   Z
__future__r   ÚosZpathlibr   Útypingr   r+   Ú__file__r    Úparentsr   r)   r   r-   r   r   r   r   Ú<module>   s    