abbe7a18fc
- P0: hooks.py 3-tuple fix, trigger_dispatcher Contract, contacts/plugin unregister_actions_by_owner - P0: 5 test files — check_permission mocks removed, hardcoded DB credential → env var - P1: attachment_service DmsFile via Contract helper, restore_registry/history_hooks dedup - P1: mail/plugin restore unregister, mcp_client datetime.now(UTC), saved_views/filters patterns - P1: ProtectedRoute fail-closed, 13 test assertion fixes (bcrypt, DB-URLs, SECRET_KEYs) - P2: deprecated notifications → post_system_message (3 files), forgejo Base, report_generator lazy import - P2: webhooks permissions, deps.py/roles.py plugin perms removed, import_export default - P2: address/tags/entity_links patterns removed, worker.py Contract-Umgehungen fixed - P2: 28 frontend TODOs (hardcoded constants, deprecated notification API) - P3: dead code, duplicates, deprecated imports, private attr, __import__ inline - P3: 8 frontend TODOs (LucideIcons, inline styles, XSS, i18n) - ruff: 838 → 0 (612 auto-fix + 246 manual + 27 F821 regression fix) - F821: 30 → 0 (AutomationDefinition, DmsFile, user_id, Path, Any, String) - Contract-Umgehungen: 2 neue gefunden (worker.py:169, worker.py:280) und gefixt
93 lines
2.9 KiB
Python
93 lines
2.9 KiB
Python
"""Mini-App registry for plugin-provided interactive chat components."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from typing import Any
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class MiniAppDef(BaseModel):
|
|
"""Definition of a mini-app that plugins can register."""
|
|
|
|
app_id: str = Field(..., description="Unique app identifier")
|
|
name: str = Field(..., description="Display name")
|
|
icon: str = Field(default="app", description="Icon name")
|
|
description: str = Field(default="", description="App description")
|
|
plugin_name: str = Field(..., description="Plugin that registered this app")
|
|
render_schema: dict[str, Any] = Field(
|
|
default_factory=dict, description="JSON schema for frontend rendering"
|
|
)
|
|
|
|
|
|
class MiniAppRegistry:
|
|
"""Registry for mini-apps that plugins provide for chat embedding."""
|
|
|
|
def __init__(self) -> None:
|
|
self._apps: dict[str, MiniAppDef] = {}
|
|
|
|
def register(
|
|
self,
|
|
app_id: str,
|
|
name: str,
|
|
icon: str,
|
|
description: str,
|
|
plugin_name: str,
|
|
render_schema: dict[str, Any] | None = None,
|
|
) -> None:
|
|
"""Register a mini-app."""
|
|
app = MiniAppDef(
|
|
app_id=app_id,
|
|
name=name,
|
|
icon=icon,
|
|
description=description,
|
|
plugin_name=plugin_name,
|
|
render_schema=render_schema or {},
|
|
)
|
|
self._apps[app_id] = app
|
|
logger.info(f"Mini-app registered: {app_id} by {plugin_name}")
|
|
|
|
def unregister(self, app_id: str) -> None:
|
|
"""Unregister a mini-app."""
|
|
app = self._apps.pop(app_id, None)
|
|
if app:
|
|
logger.info(f"Mini-app unregistered: {app_id}")
|
|
|
|
def unregister_plugin(self, plugin_name: str) -> None:
|
|
"""Unregister all mini-apps from a specific plugin."""
|
|
to_remove = [app_id for app_id, app in self._apps.items() if app.plugin_name == plugin_name]
|
|
for app_id in to_remove:
|
|
self._apps.pop(app_id, None)
|
|
if to_remove:
|
|
logger.info(f"Unregistered {len(to_remove)} mini-apps from plugin {plugin_name}")
|
|
|
|
def list_apps(self) -> list[dict[str, Any]]:
|
|
"""List all available mini-apps for frontend."""
|
|
return [app.model_dump() for app in self._apps.values()]
|
|
|
|
def get_app(self, app_id: str) -> MiniAppDef | None:
|
|
"""Get a specific mini-app definition."""
|
|
return self._apps.get(app_id)
|
|
|
|
|
|
# ─── Singleton helpers ───
|
|
|
|
_registry: MiniAppRegistry | None = None
|
|
|
|
|
|
def get_miniapp_registry() -> MiniAppRegistry:
|
|
"""Return the shared singleton MiniAppRegistry instance."""
|
|
global _registry
|
|
if _registry is None:
|
|
_registry = MiniAppRegistry()
|
|
return _registry
|
|
|
|
|
|
def reset_miniapp_registry() -> None:
|
|
"""Reset the singleton instance (useful for tests)."""
|
|
global _registry
|
|
_registry = None
|