feat(UI-Overhaul-Phase2): AI Assistent in Kommunikation integriert
Check Cross-Plugin Imports / check (push) Has been cancelled
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:
@@ -80,26 +80,29 @@ async def run_agent_external(
|
||||
|
||||
# Create or find a session for this external interaction
|
||||
|
||||
from app.plugins.builtins.ai_assistant.models import AIChatMessage, AIChatSession
|
||||
# AIChatSession/AIChatMessage removed — using comm tables
|
||||
|
||||
session = AIChatSession(
|
||||
user_id=uuid.UUID(current_user["user_id"]),
|
||||
agent_id=agent.id,
|
||||
title=f"External: {data.message[:50]}" if data.message else "External Agent Run",
|
||||
is_sidebar=False,
|
||||
# Create a comm conversation for this external interaction
|
||||
from app.plugins.builtins.kommunikation.models import CommConversation
|
||||
session = CommConversation(
|
||||
tenant_id=tenant_id,
|
||||
title=f"External: {data.message[:50]}" if data.message else "External Agent Run",
|
||||
owner_id=uuid.UUID(current_user["user_id"]),
|
||||
created_by=uuid.UUID(current_user["user_id"]),
|
||||
created_by_type="user",
|
||||
metadata_={"conversation_type": "ai", "agent_id": str(agent.id)},
|
||||
)
|
||||
db.add(session)
|
||||
await db.flush()
|
||||
|
||||
# Store the user message
|
||||
user_msg = AIChatMessage(
|
||||
session_id=session.id,
|
||||
role="user",
|
||||
from app.plugins.builtins.kommunikation.models import CommMessage
|
||||
user_msg = CommMessage(
|
||||
conversation_id=session.id,
|
||||
sender_id=uuid.UUID(current_user["user_id"]),
|
||||
sender_type="user",
|
||||
content=data.message,
|
||||
tokens=0,
|
||||
model_used=agent.name or "external",
|
||||
content_format="text",
|
||||
tenant_id=tenant_id,
|
||||
)
|
||||
db.add(user_msg)
|
||||
@@ -117,7 +120,7 @@ async def run_agent_external(
|
||||
}
|
||||
|
||||
# Run the agent via streaming chat (non-streaming mode)
|
||||
from app.plugins.builtins.ai_assistant.services import stream_chat
|
||||
from app.plugins.builtins.ai_assistant.services import stream_chat_comm
|
||||
|
||||
full_response = ""
|
||||
async with get_db() as stream_db:
|
||||
@@ -250,15 +253,16 @@ async def stream_agent_external(
|
||||
raise HTTPException(status_code=400, detail="Agent is not active")
|
||||
|
||||
# Create session
|
||||
from app.plugins.builtins.ai_assistant.models import AIChatSession
|
||||
# AIChatSession removed — using comm tables
|
||||
|
||||
session = AIChatSession(
|
||||
user_id=uuid.UUID(current_user["user_id"]),
|
||||
agent_id=agent.id,
|
||||
title=f"External Stream: {data.message[:50]}" if data.message else "External Agent Stream",
|
||||
is_sidebar=False,
|
||||
from app.plugins.builtins.kommunikation.models import CommConversation
|
||||
session = CommConversation(
|
||||
tenant_id=tenant_id,
|
||||
title=f"External Stream: {data.message[:50]}" if data.message else "External Agent Stream",
|
||||
owner_id=uuid.UUID(current_user["user_id"]),
|
||||
created_by=uuid.UUID(current_user["user_id"]),
|
||||
created_by_type="user",
|
||||
metadata_={"conversation_type": "ai", "agent_id": str(agent.id)},
|
||||
)
|
||||
db.add(session)
|
||||
await db.commit()
|
||||
@@ -274,15 +278,15 @@ async def stream_agent_external(
|
||||
"field_permissions": current_user.get("field_permissions", {}),
|
||||
}
|
||||
|
||||
from app.plugins.builtins.ai_assistant.services import stream_chat
|
||||
from app.plugins.builtins.ai_assistant.services import stream_chat_comm
|
||||
|
||||
async def event_stream():
|
||||
from app.core.db import get_session_factory
|
||||
factory = get_session_factory()
|
||||
async with factory() as stream_db:
|
||||
await set_tenant_context(stream_db, tenant_id)
|
||||
async for chunk in stream_chat(
|
||||
stream_db, session, agent, data.message, user_context, tenant_id
|
||||
async for chunk in stream_chat_comm(
|
||||
stream_db, session.id, agent, data.message, user_context, tenant_id, uuid.UUID(current_user["user_id"])
|
||||
):
|
||||
yield chunk
|
||||
yield "data: [DONE]\n\n"
|
||||
|
||||
Reference in New Issue
Block a user