diff --git a/main.py b/main.py index e4d59b2..a45c178 100644 --- a/main.py +++ b/main.py @@ -29,6 +29,22 @@ from core.identity import RequestContext PLUGIN_NAME = "astrbot_plugin_imagestudio" +PLUGIN_DESC = "AstrBot ImageStudio role asset production and image-generation workspace." +PLUGIN_VERSION = "3.0.0" + +try: + from astrbot.api.star import Star as AstrBotStar + from astrbot.api.star import register as astrbot_star_register +except Exception: # pragma: no cover - AstrBot is only present in runtime. + class AstrBotStar: # type: ignore[no-redef] + def __init__(self, context: Any | None = None, *args: Any, **kwargs: Any) -> None: + self.context = context + + def astrbot_star_register(*args: Any, **kwargs: Any) -> Any: + def decorator(cls: type[Any]) -> type[Any]: + return cls + + return decorator def get_plugin_manifest() -> dict[str, Any]: @@ -62,3 +78,37 @@ def dispatch_web_request( payload: dict[str, Any] | None = None, ) -> dict[str, Any]: return dispatch_extension_request(ctx, method, path, query=query, payload=payload) + + +def _register_star_class(cls: type[Any]) -> type[Any]: + try: + return astrbot_star_register(PLUGIN_NAME, "YokiiroBW", PLUGIN_DESC, PLUGIN_VERSION)(cls) + except Exception: + return cls + + +@_register_star_class +class Main(AstrBotStar): + """Minimal AstrBot plugin class for runtime discovery.""" + + def __init__(self, context: Any | None = None, *args: Any, **kwargs: Any) -> None: + try: + super().__init__(context, *args, **kwargs) + except TypeError: + try: + super().__init__(*args, **kwargs) + except TypeError: + super().__init__() + self.context = context + + async def initialize(self) -> None: + return None + + async def terminate(self) -> None: + return None + + def get_plugin_manifest(self) -> dict[str, Any]: + return get_plugin_manifest() + + def register_plugin(self, runtime: Any) -> dict[str, Any]: + return register_plugin(runtime) diff --git a/tests/test_plugin_entrypoint.py b/tests/test_plugin_entrypoint.py index 7ab0f61..9152dd4 100644 --- a/tests/test_plugin_entrypoint.py +++ b/tests/test_plugin_entrypoint.py @@ -4,7 +4,7 @@ import unittest from backend.route_registry import ROUTES from core.identity import RequestContext -from main import PLUGIN_NAME, dispatch_web_request, get_plugin_manifest, get_runtime_health, register_plugin +from main import Main, PLUGIN_NAME, dispatch_web_request, get_plugin_manifest, get_runtime_health, register_plugin class PluginEntrypointTests(unittest.TestCase): @@ -51,6 +51,14 @@ class PluginEntrypointTests(unittest.TestCase): self.assertEqual(len(runtime.mounts), 1) self.assertTrue(get_runtime_health()["ok"]) + def test_astrbot_main_class_exposes_manifest(self): + plugin = Main(context=object()) + + manifest = plugin.get_plugin_manifest() + + self.assertEqual(manifest["plugin_name"], PLUGIN_NAME) + self.assertTrue(manifest["runtime"]["health"]["ok"]) + if __name__ == "__main__": unittest.main()