
    `gjp                       U d Z ddlmZ ddlZddlZddlmZmZ	  ej                  e      ZdZdZdZdZd	Zd
ZdZdZ ed       G d d             Z ed       G d d             Z ed       G d d             Zi Zded<   ddZy)u  Declarative configuration schema for memory provider plugins.

Each memory provider plugin *declares* its configurable surface in a
``config_schema.py`` next to its ``__init__.py`` — the fields, their types,
which values are secrets, and (for selects) the allowed options. A single
generic renderer in the desktop UI and a single generic ``GET/PUT
/api/memory/providers/{name}/config`` endpoint pair drive the whole
experience, so adding a provider config surface is pure declaration with no
bespoke UI components.

Schema files are loaded by path (like the provider plugins themselves), never
via package import: plugin ``__init__.py`` files pull in the agent runtime,
which must not load into the web server. A ``config_schema.py`` may only
import from this module.

This module is intentionally pure data: it imports nothing from the
config/env layer. ``web_server`` owns the generic read/write logic that
interprets these declarations, dispatching on ``ProviderConfigSchema.storage``
to the matching backend.
    )annotationsN)	dataclassfieldtextselectsecretboolnumberjson	flat_jsonhoncho_host_blockT)frozenc                  4    e Zd ZU dZded<   ded<   dZded<   y)ProviderFieldOptionz'A single choice for a ``select`` field.strvaluelabel descriptionN)__name__
__module____qualname____doc____annotations__r        O/root/.hermes/venv/lib/python3.12/site-packages/plugins/memory/config_schema.pyr   r   +   s    1JJKr   r   c                      e Zd ZU dZded<   ded<   eZded<   dZded<   dZded<   dZ	ded	<   d
Z
ded<   dZded<   d
Zded<   d
Zded<   dZded<   dZded<   dZded<   dZded<   edd       ZddZy)ProviderFieldu  One configurable field on a memory provider.

    A field is stored in exactly one place, decided by ``kind``:

    * non-secret kinds — persisted to the provider's config via its storage
      backend under ``key``.
    * ``secret`` — persisted to the env store under ``env_key`` and never read
      back out over the API (only an ``is_set`` flag is surfaced).

    ``aliases`` and ``env_fallbacks`` let a field read legacy values written by
    earlier CLI/env setup without re-introducing per-provider code. ``inline``
    marks the curated subset shown in the compact panel; the rest surface only
    in the full-config modal. ``group`` buckets fields within that modal.
    r   keyr   kindr   defaultr   placeholderr   ztuple[ProviderFieldOption, ...]optionsNz
str | Noneenv_keyztuple[str, ...]aliasesenv_fallbacksFr	   inlinegroupinfohostscopec                (    | j                   t        k(  S N)r!   KIND_SECRETselfs    r   	is_secretzProviderField.is_secretV   s    yyK''r   c                T    | j                   D ch c]  }|j                   c}S c c}w r.   )r$   r   )r1   opts     r   allowed_valueszProviderField.allowed_valuesZ   s    %)\\2c		222s   %)returnr	   )r6   zset[str])r   r   r   r   r   	KIND_TEXTr!   r"   r   r#   r$   r%   r&   r'   r(   r)   r*   r,   propertyr2   r5   r   r   r   r   r   4   s     
HJD#GSKK/1G,1GZ!G_!%'M?'FDE3OD#NE3( (3r   r   c                  f    e Zd ZU dZded<   ded<   eZded<   dZded<    ee	      Z
d	ed
<   ddZy)ProviderConfigSchemaz,A provider plugin's declared config surface.r   namer   storager   docs_url)default_factorytuple[ProviderField, ...]fieldsc                :    t        d | j                  D              S )Nc              3  :   K   | ]  }|j                   s|  y wr.   )r(   ).0fs     r   	<genexpr>z5ProviderConfigSchema.inline_fields.<locals>.<genexpr>j   s     81qxxQ8s   )tupler@   r0   s    r   inline_fieldsz"ProviderConfigSchema.inline_fieldsi   s    8888r   N)r6   r?   )r   r   r   r   r   STORAGE_FLAT_JSONr<   r=   dataclass_fieldrF   r@   rG   r   r   r   r:   r:   ^   s8    6
IJ$GS$Hc(7(NF%N9r   r:   zdict[str, ProviderConfigSchema]_SCHEMA_CACHEc                   ddl m}  ||       }|r|dz  nd}||j                         syt        |      }|t        v r	t        |   S 	 t
        j                  j                  d|  |      }t
        j                  j                  |      }|j                  j                  |       t        |dd      }|	|t        |<   |S # t        $ r t        j                  d|        Y yw xY w)af  Return the ``CONFIG_SCHEMA`` declared by the provider plugin ``name``.

    Providers without a ``config_schema.py`` (e.g. ``builtin``) return ``None``
    and simply render no config panel. The cache keys on the resolved schema
    file, not the name: user-installed plugins are per-profile, so one
    profile's lookup must never answer for another's.
    r   )find_provider_dirzconfig_schema.pyNz_hermes_memory_config_schema.CONFIG_SCHEMAz3failed to load config schema for memory provider %r)plugins.memoryrL   is_filer   rJ   	importlibutilspec_from_file_locationmodule_from_specloaderexec_modulegetattr	Exception_log	exception)r;   rL   provider_dirpathr    specmoduleschemas           r   get_provider_config_schemar_   p   s     1$T*L0<<,,$D|4<<>
d)C
mS!!~~558UVZU[6\^bc006'$7 #cM  LdSs   A*B? ?C! C!)r;   r   r6   zProviderConfigSchema | None)r   
__future__r   importlib.utilrP   loggingdataclassesr   r   rI   	getLoggerr   rX   r7   KIND_SELECTr/   	KIND_BOOLKIND_NUMBER	KIND_JSONrH   STORAGE_HONCHO_HOST_BLOCKr   r   r:   rJ   r   r_   r   r   r   <module>rj      s   * #   ;w" 			   /  $   $&3 &3 &3R $9 9 9 24. 3 r   