feat(UI-Overhaul-Phase2): AI Assistent in Kommunikation integriert
Check Cross-Plugin Imports / check (push) Has been cancelled

Migration 0137: Drop AI chat tables (ai_chat_sessions, ai_chat_messages, ai_chat_attachments, ai_conversations, ai_messages)

Backend:
- Remove AIChatSession, AIChatMessage, AIChatAttachment models from ai_assistant/models.py
- Remove AIConversation, AIMessage from app/models/__init__.py
- Remove session/message/stream/attachment routes from ai_assistant/routes.py
- Add new streaming route POST /ai/conversations/{conversation_id}/stream using comm tables
- Add new messages route GET /ai/conversations/{conversation_id}/messages using comm tables
- Add stream_chat_comm, get_comm_messages, save_comm_message to services.py
- Update external_api.py to use CommConversation/CommMessage instead of AIChatSession/AIChatMessage
- Update unified_search ai_chat_provider to search comm_messages with conversation_type=ai
- Remove ai_copilot router from main.py and routes/__init__.py
- Remove ai_conversation from entity_permissions.py and owner_transfer_service.py
- Update ai_assistant/plugin.py get_entity_models to remove AIChatSession
- Guard ai_copilot_service.py imports with try/except

Frontend:
- Remove AIAssistant.tsx, AIAssistantStandalone.tsx, SessionList.tsx, ChatWindow.tsx
- Remove AI Assistant routes from routes/index.tsx
- Update api/ai.ts: streamChat uses /ai/conversations/{id}/stream, fetchMessages uses /ai/conversations/{id}/messages
- Update Communication.tsx: use convId for AI streaming, remove aiSessionId, use fetchAiMessages for AI conversations
- Update AiChatPanel.tsx: create comm conversation instead of AI session, use new fetchMessages
- Update AISidebar.tsx: remove ChatWindow import, show placeholder

tsc clean, build successful, backend import OK
This commit is contained in:
Agent Zero
2026-08-21 13:34:54 +02:00
parent 94c7c8fff5
commit 7f61dfb25b
22 changed files with 361 additions and 1472 deletions
@@ -1,4 +1,4 @@
"""AI chat search provider — FTS search on ai_chat_messages table."""
"""AI chat search provider — FTS search on comm_messages for AI conversations."""
from __future__ import annotations
@@ -15,7 +15,7 @@ logger = logging.getLogger(__name__)
class AIChatSearchProvider(BaseSearchProvider):
"""Search provider for AI chat messages."""
"""Search provider for AI chat messages in comm_messages."""
entity_type = "ai_chat"
supports_fts = True
@@ -29,18 +29,18 @@ class AIChatSearchProvider(BaseSearchProvider):
limit: int,
visible_ids: set[uuid.UUID] | None,
) -> list[dict[str, Any]]:
"""Full-text search on ai_chat_messages.content, joined with sessions for title."""
"""Full-text search on comm_messages.content for AI conversations."""
if visible_ids is not None:
sql = text(
"""
SELECT m.id, m.tenant_id, m.session_id, m.role, m.content,
m.model_used, m.tokens,
s.title AS session_title,
SELECT m.id, m.tenant_id, m.conversation_id, m.sender_type AS role, m.content,
c.title AS session_title,
ts_rank(to_tsvector('pg_catalog.german', m.content),
to_tsquery('pg_catalog.german', :q)) AS rank
FROM ai_chat_messages m
JOIN ai_chat_sessions s ON s.id = m.session_id
FROM comm_messages m
JOIN comm_conversations c ON c.id = m.conversation_id
WHERE m.tenant_id = :tid
AND c.metadata->>'conversation_type' = 'ai'
AND to_tsvector('pg_catalog.german', m.content) @@ to_tsquery('pg_catalog.german', :q)
AND m.id = ANY(:visible_ids)
ORDER BY rank DESC
@@ -59,14 +59,14 @@ class AIChatSearchProvider(BaseSearchProvider):
else:
sql = text(
"""
SELECT m.id, m.tenant_id, m.session_id, m.role, m.content,
m.model_used, m.tokens,
s.title AS session_title,
SELECT m.id, m.tenant_id, m.conversation_id, m.sender_type AS role, m.content,
c.title AS session_title,
ts_rank(to_tsvector('pg_catalog.german', m.content),
to_tsquery('pg_catalog.german', :q)) AS rank
FROM ai_chat_messages m
JOIN ai_chat_sessions s ON s.id = m.session_id
FROM comm_messages m
JOIN comm_conversations c ON c.id = m.conversation_id
WHERE m.tenant_id = :tid
AND c.metadata->>'conversation_type' = 'ai'
AND to_tsvector('pg_catalog.german', m.content) @@ to_tsquery('pg_catalog.german', :q)
ORDER BY rank DESC
LIMIT :lim
@@ -97,7 +97,7 @@ class AIChatSearchProvider(BaseSearchProvider):
sql = text(
"""
SELECT content
FROM ai_chat_messages
FROM comm_messages
WHERE id = :eid AND tenant_id = :tid
"""
)
@@ -114,14 +114,14 @@ class AIChatSearchProvider(BaseSearchProvider):
content = entity.get("content", "")
role = entity.get("role", "")
session_title = entity.get("session_title", "")
session_id = str(entity.get("session_id", ""))
conversation_id = str(entity.get("conversation_id", ""))
score = entity.get("rank", 0.0)
else:
entity_id = str(getattr(entity, "id", ""))
content = getattr(entity, "content", "")
role = getattr(entity, "role", "")
session_title = getattr(entity, "session_title", "")
session_id = str(getattr(entity, "session_id", ""))
conversation_id = str(getattr(entity, "conversation_id", ""))
score = getattr(entity, "rank", 0.0)
return {
"entity_type": self.entity_type,
@@ -131,7 +131,7 @@ class AIChatSearchProvider(BaseSearchProvider):
"score": float(score) if score else 0.0,
"data": {
"role": role,
"session_id": session_id,
"conversation_id": conversation_id,
"session_title": session_title,
},
}