74 lines
2.0 KiB
Python
74 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
from __future__ import annotations
|
|
|
|
import importlib.util
|
|
import json
|
|
import sys
|
|
import types
|
|
from pathlib import Path
|
|
|
|
|
|
class FakeHermesContext:
|
|
def __init__(self) -> None:
|
|
self.registered_tools = []
|
|
self.registered_hooks = []
|
|
|
|
def register_tool(self, name, toolset, schema, handler, **kwargs):
|
|
self.registered_tools.append(
|
|
{
|
|
"name": name,
|
|
"toolset": toolset,
|
|
"schema": schema,
|
|
"handler_callable": callable(handler),
|
|
"kwargs": kwargs,
|
|
}
|
|
)
|
|
|
|
def register_hook(self, hook_name, callback):
|
|
self.registered_hooks.append({"name": hook_name, "handler_callable": callable(callback)})
|
|
|
|
|
|
def load_plugin_module():
|
|
plugin_dir = Path(__file__).resolve().parents[1]
|
|
init_file = plugin_dir / "__init__.py"
|
|
module_name = "hermes_plugins.memory_gateway_agent_smoke"
|
|
if "hermes_plugins" not in sys.modules:
|
|
parent = types.ModuleType("hermes_plugins")
|
|
parent.__path__ = []
|
|
sys.modules["hermes_plugins"] = parent
|
|
spec = importlib.util.spec_from_file_location(
|
|
module_name,
|
|
init_file,
|
|
submodule_search_locations=[str(plugin_dir)],
|
|
)
|
|
if spec is None or spec.loader is None:
|
|
raise RuntimeError("Cannot create plugin module spec")
|
|
module = importlib.util.module_from_spec(spec)
|
|
module.__package__ = module_name
|
|
module.__path__ = [str(plugin_dir)]
|
|
sys.modules[module_name] = module
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
def main() -> None:
|
|
module = load_plugin_module()
|
|
ctx = FakeHermesContext()
|
|
module.register(ctx)
|
|
print(
|
|
json.dumps(
|
|
{
|
|
"ok": True,
|
|
"has_register": callable(getattr(module, "register", None)),
|
|
"registered_tools": ctx.registered_tools,
|
|
"registered_hooks": ctx.registered_hooks,
|
|
},
|
|
ensure_ascii=False,
|
|
indent=2,
|
|
)
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|