refactor: move plugin setting to db

This commit is contained in:
Junyan Qin
2025-04-12 20:21:43 +08:00
parent 11342e75de
commit ebd091a9e0
10 changed files with 130 additions and 127 deletions

View File

@@ -133,7 +133,10 @@ class PluginLoader(loader.PluginLoader):
"""注册事件处理器"""
self.ap.logger.debug(f'注册事件处理器 {event.__name__}')
def wrapper(func: typing.Callable) -> typing.Callable:
if self._current_container is None: # None indicates this plugin is registered through manifest, so ignore it here
return func
self._current_container.event_handlers[event] = func
return func
@@ -148,6 +151,9 @@ class PluginLoader(loader.PluginLoader):
self.ap.logger.debug(f'注册内容函数 {name}')
def wrapper(func: typing.Callable) -> typing.Callable:
if self._current_container is None: # None indicates this plugin is registered through manifest, so ignore it here
return func
function_schema = funcschema.get_func_schema(func)
function_name = self._current_container.plugin_name + '-' + (func.__name__ if name is None else name)

View File

@@ -68,6 +68,8 @@ class PluginManifestLoader(loader.PluginLoader):
for plugin_manifest in plugin_manifests:
try:
config_schema = plugin_manifest.spec['config'] if 'config' in plugin_manifest.spec else []
current_plugin_container = context.RuntimeContainer(
plugin_name=plugin_manifest.metadata.name,
plugin_label=plugin_manifest.metadata.label,
@@ -77,6 +79,7 @@ class PluginManifestLoader(loader.PluginLoader):
plugin_repository=plugin_manifest.metadata.repository,
main_file=os.path.join(plugin_manifest.rel_dir, plugin_manifest.execution.python.path),
pkg_path=plugin_manifest.rel_dir,
config_schema=config_schema,
event_handlers={},
tools=[],
)