mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-04-29 12:10:57 +00:00
refactor: consolidate module loading utilities and add plugin lifecycle improvements
- Move load_classes_from_file and load_classes_from_folder from extract_tools to new modules helper - Update all imports across api, extension, files, and plugins to use helpers.modules - Add namespace purging to refresh_plugin_modules for selective plugin reload on Python changes - Implement embed trimming in history based on model config max_embeds and vision support - Add pre_update hook documentation to plugin
This commit is contained in:
parent
723225957e
commit
89d4b8913f
25 changed files with 417 additions and 178 deletions
|
|
@ -134,7 +134,11 @@ def install_from_zip(zip_path: str, original_filename: str | None = None) -> dic
|
|||
files.delete_dir(dest)
|
||||
raise
|
||||
|
||||
after_plugin_change([plugin_name])
|
||||
|
||||
# does it have python files?
|
||||
python_change = bool(files.find_existing_paths_by_pattern(dest+"/**/*.py"))
|
||||
|
||||
after_plugin_change([plugin_name], python_change=python_change)
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
|
|
@ -209,7 +213,10 @@ def install_from_git(url: str, token: str | None = None, plugin_name: str = "",
|
|||
files.delete_dir(final_dir)
|
||||
raise
|
||||
|
||||
after_plugin_change([plugin_name])
|
||||
# does it have python files?
|
||||
python_change = bool(files.find_existing_paths_by_pattern(final_dir+"/**/*.py"))
|
||||
|
||||
after_plugin_change([plugin_name],python_change=python_change)
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
|
|
@ -232,6 +239,14 @@ def update_from_git(plugin_name: str) -> dict:
|
|||
if not files.is_in_dir(plugin_dir, custom_plugins_dir):
|
||||
raise ValueError("Only custom plugins can be updated")
|
||||
|
||||
try:
|
||||
run_pre_update_hook(plugin_name)
|
||||
except Exception as e:
|
||||
print_style.PrintStyle.error(
|
||||
f"Failed to run pre-update hook for {plugin_name}: {e}"
|
||||
)
|
||||
raise
|
||||
|
||||
try:
|
||||
repo = git.update_repo(plugin_dir)
|
||||
meta = plugins.get_plugin_meta(plugin_name)
|
||||
|
|
@ -268,6 +283,8 @@ def update_from_git(plugin_name: str) -> dict:
|
|||
def run_install_hook(plugin_name: str):
|
||||
return plugins.call_plugin_hook(plugin_name, "install")
|
||||
|
||||
def run_pre_update_hook(plugin_name: str):
|
||||
return plugins.call_plugin_hook(plugin_name, "pre_update")
|
||||
|
||||
def get_plugin_hub_index() -> dict[str, Any]:
|
||||
"""Return the plugin index plus installed Plugin Hub keys."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue