update and cleanup repo

This commit is contained in:
2026-05-26 15:32:01 -07:00
parent 5041d9fbb9
commit 0db899d0c3
72 changed files with 788 additions and 1884 deletions
+51 -51
View File
@@ -14,6 +14,36 @@ logger = logging.getLogger(__name__)
ConfigField = Dict[str, Any]
def _import_plugin_support_module(plugin_name: str) -> Optional[Any]:
normalized = str(plugin_name or "").strip()
if not normalized:
return None
try:
return importlib.import_module(f"plugins.{normalized}")
except Exception:
return None
def _iter_plugin_module_names() -> List[str]:
names: List[str] = []
try:
import plugins as plugin_package
except Exception:
logger.exception("Failed to import plugins package for config discovery")
return names
package_path = getattr(plugin_package, "__path__", None)
if not package_path:
return names
for module_info in pkgutil.iter_modules(package_path):
name = str(module_info.name or "").strip()
if not name or name.startswith("_"):
continue
names.append(name)
return names
def _normalize_schema(fields: Optional[Iterable[Any]]) -> List[ConfigField]:
normalized: List[ConfigField] = []
seen: set[str] = set()
@@ -55,48 +85,38 @@ def _call_schema(owner: Any, label: str) -> List[ConfigField]:
def get_store_schema(store_type: str) -> List[ConfigField]:
"""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.
Store types are now 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)
return get_plugin_schema(str(store_type or "").strip())
def get_plugin_schema(plugin_name: str) -> List[ConfigField]:
plugin_class = get_plugin_class(str(plugin_name or "").strip())
if plugin_class is None:
normalized_name = str(plugin_name or "").strip()
if not normalized_name:
return []
return _call_schema(plugin_class, f"plugin '{plugin_name}'")
plugin_class = get_plugin_class(normalized_name)
if plugin_class is not None:
schema = _call_schema(plugin_class, f"plugin '{normalized_name}'")
if schema:
return schema
def get_tool_schema(tool_name: str) -> List[ConfigField]:
tool_name = str(tool_name or "").strip()
if not tool_name:
module = _import_plugin_support_module(normalized_name)
if module is None:
return []
try:
module = importlib.import_module(f"tool.{tool_name}")
except Exception:
logger.exception("Failed to import tool module 'tool.%s'", tool_name)
return []
return _call_schema(module, f"tool '{tool_name}'")
return _call_schema(module, f"plugin support '{normalized_name}'")
def get_item_schema(item_type: str, item_name: str) -> List[ConfigField]:
normalized_type = str(item_type or "").strip()
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"}:
if normalized_type == "plugin":
return get_plugin_schema(normalized_name)
if normalized_type == "tool":
return get_tool_schema(normalized_name)
return []
@@ -143,13 +163,6 @@ def build_default_plugin_config(plugin_name: str) -> Dict[str, Any]:
return config
def build_default_tool_config(tool_name: str) -> Dict[str, Any]:
config: Dict[str, Any] = {}
for field in get_tool_schema(tool_name):
config[field["key"]] = field.get("default", "")
return config
def get_required_config_keys(item_type: str, item_name: str) -> List[str]:
normalized_type = str(item_type or "").strip()
normalized_name = str(item_name or "").strip()
@@ -170,9 +183,9 @@ 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("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)
if normalized_type.startswith("plugin-"):
# Multi-instance plugin (plugin-{ptype}): look up by plugin name.
ptype = normalized_type.replace("plugin-", "", 1)
plugin_class = get_plugin_class(ptype)
if plugin_class is not None:
try:
@@ -180,7 +193,7 @@ def get_required_config_keys(item_type: str, item_name: str) -> List[str]:
_add_key(required_key)
except Exception:
logger.exception("Failed to load required config keys for plugin '%s'", ptype)
elif normalized_type in {"provider", "plugin"}:
elif normalized_type == "plugin":
plugin_class = get_plugin_class(normalized_name)
if plugin_class is not None:
try:
@@ -211,20 +224,7 @@ def get_configurable_plugin_types() -> List[str]:
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))
def get_configurable_tool_types() -> List[str]:
options: List[str] = []
try:
import tool as tool_package
for module_info in pkgutil.iter_modules(tool_package.__path__):
tool_name = str(module_info.name or "").strip()
if not tool_name:
continue
if get_tool_schema(tool_name):
options.append(tool_name)
except Exception:
logger.exception("Failed to discover configurable tool modules")
for module_name in _iter_plugin_module_names():
if get_plugin_schema(module_name):
options.append(module_name)
return sorted(set(options))