Files
leocrm/app/plugins/builtins/ai_ui_control/schemas.py
T
Agent Zero abbe7a18fc fix(audit): P0-P3 audit fixes — 838 ruff errors → 0, 30 F821 bugs fixed, 118 files changed
- 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
2026-08-16 01:17:18 +02:00

109 lines
4.0 KiB
Python

"""Pydantic schemas for AI UI Control commands and feedback."""
from __future__ import annotations
from enum import StrEnum
from typing import Any
from pydantic import BaseModel, Field
class UICommandType(StrEnum):
"""Supported UI command types."""
navigate = "navigate"
filter = "filter"
open_contact = "open_contact"
modal = "modal"
tab = "tab"
settings = "settings"
class UICommandStatus(StrEnum):
"""Status of a UI command execution."""
pending = "pending"
delivered = "delivered"
success = "success"
failed = "failed"
timeout = "timeout"
class UICommand(BaseModel):
"""A UI command sent by an AI agent to control the frontend.
Task 4.1: UI-Command-Protokoll
JSON protocol for UI commands with action types:
- navigate: {action: 'navigate', path: '/contacts/123'}
- filter: {action: 'filter', entity: 'contacts', filter: {type: 'company'}}
- open_contact: {action: 'open_contact', id: '...'}
- modal: {action: 'modal', modal: 'edit', contactId: '...'}
- tab: {action: 'tab', tab: 'emails', contactId: '...'}
- settings: {action: 'settings', section: 'ai', key: 'model', value: 'gpt-4'}
"""
command_id: str = Field(..., description="Unique command ID")
action: UICommandType = Field(..., description="Command type")
# navigate
path: str | None = Field(None, description="Target path for navigate command")
# filter
entity: str | None = Field(None, description="Entity type for filter command")
filter: dict[str, Any] | None = Field(None, description="Filter criteria")
# open_contact
contact_id: str | None = Field(None, description="Contact ID for open_contact command")
# modal
modal: str | None = Field(None, description="Modal type: 'edit', 'create', 'delete', 'close'")
# tab
tab: str | None = Field(None, description="Tab name: 'emails', 'files', 'calendar', etc.")
# settings
section: str | None = Field(None, description="Settings section")
key: str | None = Field(None, description="Setting key")
value: Any | None = Field(None, description="Setting value")
# metadata
timestamp: str | None = Field(None, description="Command timestamp ISO format")
description: str | None = Field(None, description="Human-readable description of the command")
class UICommandCreate(BaseModel):
"""Request body for creating a UI command (sent by AI agent)."""
action: UICommandType = Field(..., description="Command type")
path: str | None = None
entity: str | None = None
filter: dict[str, Any] | None = None
contact_id: str | None = None
modal: str | None = None
tab: str | None = None
section: str | None = None
key: str | None = None
value: Any | None = None
description: str | None = None
class UICommandFeedback(BaseModel):
"""Feedback from frontend after executing a command.
Task 4.10: UI-Action-Feedback an KI
Frontend sends confirmation back: {action: 'navigate', status: 'success', current_path: '/contacts/123'}
"""
command_id: str = Field(..., description="ID of the command being acknowledged")
status: UICommandStatus = Field(..., description="Execution status")
action: UICommandType | None = None
current_path: str | None = Field(None, description="Current URL path after command")
current_tab: str | None = Field(None, description="Current active tab")
message: str | None = Field(None, description="Optional message")
error: str | None = Field(None, description="Error message if failed")
data: dict[str, Any] | None = Field(None, description="Additional response data")
class UICommandResponse(BaseModel):
"""Response after creating a command."""
command_id: str
status: UICommandStatus
action: UICommandType
message: str | None = None
class UICommandStatusResponse(BaseModel):
"""Status response for polling command execution result."""
command_id: str
status: UICommandStatus
action: UICommandType | None = None
feedback: UICommandFeedback | None = None