2026-07-05 22:07:36 +08:00
|
|
|
"""AstrBot ImageStudio plugin entrypoint helpers.
|
2026-07-04 22:51:52 +08:00
|
|
|
|
2026-07-05 22:07:36 +08:00
|
|
|
The plugin is mounted inside AstrBot. This module exposes pure metadata and
|
|
|
|
|
dispatch helpers for the runtime layer without starting a standalone server.
|
2026-07-04 22:51:52 +08:00
|
|
|
"""
|
2026-07-05 22:07:36 +08:00
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2026-07-06 09:19:54 +08:00
|
|
|
import sys
|
|
|
|
|
from pathlib import Path
|
2026-07-05 22:07:36 +08:00
|
|
|
from typing import Any
|
|
|
|
|
|
2026-07-06 09:19:54 +08:00
|
|
|
|
|
|
|
|
PLUGIN_ROOT = Path(__file__).resolve().parent
|
|
|
|
|
if str(PLUGIN_ROOT) not in sys.path:
|
|
|
|
|
# AstrBot may import the plugin entrypoint without adding the plugin root.
|
|
|
|
|
sys.path.insert(0, str(PLUGIN_ROOT))
|
|
|
|
|
|
2026-07-06 04:00:59 +08:00
|
|
|
from adapters.astrbot_adapter import (
|
|
|
|
|
dispatch_extension_request,
|
|
|
|
|
register_astrbot_runtime,
|
|
|
|
|
runtime_health,
|
|
|
|
|
runtime_registration_manifest,
|
|
|
|
|
runtime_route_table,
|
|
|
|
|
)
|
2026-07-05 22:07:36 +08:00
|
|
|
from adapters.webui_adapter import get_web_mount_manifest
|
|
|
|
|
from backend.services.ui_service import API_BASE
|
|
|
|
|
from core.identity import RequestContext
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PLUGIN_NAME = "astrbot_plugin_imagestudio"
|
2026-07-06 09:26:29 +08:00
|
|
|
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
|
2026-07-05 22:07:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_plugin_manifest() -> dict[str, Any]:
|
|
|
|
|
web_manifest = get_web_mount_manifest()
|
2026-07-06 04:00:59 +08:00
|
|
|
runtime = runtime_registration_manifest()
|
2026-07-05 22:07:36 +08:00
|
|
|
return {
|
|
|
|
|
"plugin_name": PLUGIN_NAME,
|
|
|
|
|
"api_base": API_BASE,
|
2026-07-06 04:21:50 +08:00
|
|
|
"contract_url": f"{API_BASE}/contract",
|
2026-07-05 22:07:36 +08:00
|
|
|
"web": web_manifest,
|
|
|
|
|
"routes": runtime_route_table(),
|
2026-07-06 04:00:59 +08:00
|
|
|
"runtime": runtime,
|
|
|
|
|
"health": runtime["health"],
|
2026-07-05 22:07:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2026-07-06 04:00:59 +08:00
|
|
|
def register_plugin(runtime: Any) -> dict[str, Any]:
|
|
|
|
|
return register_astrbot_runtime(runtime, runtime_registration_manifest())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_runtime_health() -> dict[str, Any]:
|
|
|
|
|
return runtime_health()
|
|
|
|
|
|
|
|
|
|
|
2026-07-05 22:07:36 +08:00
|
|
|
def dispatch_web_request(
|
|
|
|
|
ctx: RequestContext,
|
|
|
|
|
method: str,
|
|
|
|
|
path: str,
|
|
|
|
|
*,
|
|
|
|
|
query: dict[str, Any] | None = None,
|
|
|
|
|
payload: dict[str, Any] | None = None,
|
|
|
|
|
) -> dict[str, Any]:
|
|
|
|
|
return dispatch_extension_request(ctx, method, path, query=query, payload=payload)
|
2026-07-06 09:26:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|