Phase 4: KI-UI-Steuerung — AI agent UI control via WebSocket
- New ai_ui_control plugin: WS endpoint /ws/ai-ui-control, REST API (POST /command, GET /command/{id}/status, GET /online-users)
- UI-Command-Protocol: 6 command types (navigate, filter, open_contact, modal, tab, settings) with Pydantic schemas
- WebSocket manager: per-user connections, command delivery, feedback storage, stale cleanup
- Frontend useAIUIControl hook: WS client with auto-reconnect, command dispatch, feedback sending
- aiUIControlStore: Zustand store for command state, active modal/tab, pending filter/settings
- AIUIControlIndicator: visual KI indication (Bot icon, toast, pulse animation)
- ContactDetail integration: syncs activeTab and personModalOpen from AI control store
- AppShell integration: useAIUIControl hook + AIUIControlIndicator
- i18n keys for DE/EN
- 18 Vitest tests: command protocol, store actions, feedback, visual indication
- TSC: 0 new errors (only 2 pre-existing Dms.tsx errors)
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
"""AI UI Control plugin — WebSocket-based UI control for AI agents.
|
||||
|
||||
Phase 4: KI-UI-Steuerung
|
||||
Enables AI agents to control the frontend UI: navigate, filter, open contacts,
|
||||
manage modals, switch tabs, and change settings. Commands flow:
|
||||
AI agent → REST API → WebSocket → Frontend → executes → WebSocket feedback → REST poll
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from app.plugins.base import BasePlugin
|
||||
from app.plugins.manifest import PluginManifest, PluginRouteDef
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AIUIControlPlugin(BasePlugin):
|
||||
"""AI UI Control plugin: lets AI agents control the frontend UI."""
|
||||
|
||||
manifest = PluginManifest(
|
||||
name="ai_ui_control",
|
||||
version="1.0.0",
|
||||
display_name="KI UI-Steuerung",
|
||||
description=(
|
||||
"Enables AI agents to control the frontend UI via WebSocket. "
|
||||
"Supports navigation, filtering, contact opening, modals, tabs, and settings."
|
||||
),
|
||||
dependencies=["permissions"],
|
||||
routes=[
|
||||
PluginRouteDef(
|
||||
path="/api/v1/ai-ui-control",
|
||||
module="app.plugins.builtins.ai_ui_control.routes",
|
||||
router_attr="router",
|
||||
),
|
||||
],
|
||||
events=[],
|
||||
migrations=[],
|
||||
permissions=[
|
||||
"ai_ui_control:read",
|
||||
"ai_ui_control:write",
|
||||
],
|
||||
is_core=True,
|
||||
)
|
||||
|
||||
async def on_install(self, db, service_container) -> None:
|
||||
"""Register the WebSocket manager in the service container."""
|
||||
from app.plugins.builtins.ai_ui_control.websocket_manager import AIUIControlWSManager
|
||||
|
||||
ws_manager = AIUIControlWSManager()
|
||||
service_container.register("ai_ui_control_ws", ws_manager)
|
||||
logger.info("AI UI Control WebSocket manager registered")
|
||||
|
||||
async def on_uninstall(self, db, service_container) -> None:
|
||||
"""Clean up the WebSocket manager."""
|
||||
if service_container.has("ai_ui_control_ws"):
|
||||
service_container.remove("ai_ui_control_ws")
|
||||
logger.info("AI UI Control WebSocket manager removed")
|
||||
Reference in New Issue
Block a user