continuing refactor

This commit is contained in:
2026-05-03 21:20:05 -07:00
parent 77cab1bd27
commit 5534812426
50 changed files with 1004 additions and 428 deletions
+41 -31
View File
@@ -7,7 +7,6 @@ from typing import Any, Dict, Iterable, List, Optional
from SYS.config import global_config
from ProviderCore.registry import get_plugin_class, list_plugins
from Store.registry import _discover_store_classes, _required_keys_for, _resolve_store_class
logger = logging.getLogger(__name__)
@@ -54,10 +53,16 @@ def _call_schema(owner: Any, label: str) -> List[ConfigField]:
def get_store_schema(store_type: str) -> List[ConfigField]:
cls = _resolve_store_class(str(store_type or "").strip())
if cls is None:
return []
return _call_schema(cls, f"store '{store_type}'")
"""Return config schema for a store type.
After the store→plugin migration, store types are plugins. We look up the
plugin schema by name; if not found we return an empty list.
"""
normalized = str(store_type or "").strip()
# Strip a legacy "store-" prefix so callers using the old type name still work
if normalized.startswith("store-"):
normalized = normalized[len("store-"):]
return get_plugin_schema(normalized)
def get_plugin_schema(plugin_name: str) -> List[ConfigField]:
@@ -84,6 +89,10 @@ def get_item_schema(item_type: str, item_name: str) -> List[ConfigField]:
normalized_name = str(item_name or "").strip()
if normalized_type.startswith("store-"):
return get_store_schema(normalized_type.replace("store-", "", 1))
if normalized_type.startswith("plugin-"):
# Multi-instance plugin: plugin-{ptype}; item_name is the instance name
ptype = normalized_type[len("plugin-"):]
return get_plugin_schema(ptype)
if normalized_type in {"provider", "plugin"}:
return get_plugin_schema(normalized_name)
if normalized_type == "tool":
@@ -104,23 +113,14 @@ def get_global_schema_map() -> Dict[str, ConfigField]:
def build_default_store_config(store_type: str, instance_name: str) -> Dict[str, Any]:
"""Build a default config dict for a new store/multi-instance plugin entry."""
config: Dict[str, Any] = {"NAME": instance_name}
schema = get_store_schema(store_type)
if schema:
for field in schema:
key = field["key"]
if key.upper() == "NAME":
continue
config[key] = field.get("default", "")
return config
cls = _resolve_store_class(str(store_type or "").strip())
if cls is None:
return config
for required_key in _required_keys_for(cls):
if required_key.upper() == "NAME":
for field in schema:
key = field["key"]
if key.upper() == "NAME":
continue
config[required_key] = ""
config[key] = field.get("default", "")
return config
@@ -170,12 +170,16 @@ def get_required_config_keys(item_type: str, item_name: str) -> List[str]:
if field.get("required"):
_add_key(field.get("key"))
if normalized_type.startswith("store-"):
store_type = normalized_type.replace("store-", "", 1)
cls = _resolve_store_class(store_type)
if cls is not None:
for required_key in _required_keys_for(cls):
_add_key(required_key)
if normalized_type.startswith("plugin-") or normalized_type.startswith("store-"):
# Multi-instance plugin (plugin-{ptype}) or legacy store-{type}: look up by plugin name
ptype = normalized_type.replace("plugin-", "", 1).replace("store-", "", 1)
plugin_class = get_plugin_class(ptype)
if plugin_class is not None:
try:
for required_key in plugin_class.required_config_keys():
_add_key(required_key)
except Exception:
logger.exception("Failed to load required config keys for plugin '%s'", ptype)
elif normalized_type in {"provider", "plugin"}:
plugin_class = get_plugin_class(normalized_name)
if plugin_class is not None:
@@ -189,18 +193,24 @@ def get_required_config_keys(item_type: str, item_name: str) -> List[str]:
def get_configurable_store_types() -> List[str]:
"""Return configurable multi-instance plugin types (formerly 'store types')."""
from ProviderCore.registry import REGISTRY
options: List[str] = []
for store_type in _discover_store_classes().keys():
if get_store_schema(store_type):
options.append(str(store_type))
for info in REGISTRY.iter_plugins():
plugin_cls = info.plugin_class
if getattr(plugin_cls, 'MULTI_INSTANCE', False) and get_plugin_schema(info.canonical_name):
options.append(info.canonical_name)
return sorted(set(options))
def get_configurable_plugin_types() -> List[str]:
"""Return all plugin types that can be configured: those with a schema or MULTI_INSTANCE flag."""
from ProviderCore.registry import REGISTRY
options: List[str] = []
for plugin_name in list_plugins().keys():
if get_plugin_schema(plugin_name):
options.append(str(plugin_name))
for info in REGISTRY.iter_plugins():
plugin_cls = info.plugin_class
if get_plugin_schema(info.canonical_name) or getattr(plugin_cls, 'MULTI_INSTANCE', False):
options.append(info.canonical_name)
return sorted(set(options))