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:
@@ -1,12 +1,8 @@
|
||||
import { asError } from '@/utils/errorTypes';
|
||||
import React, { useState, useRef, useEffect, useCallback } from 'react';
|
||||
import { Sparkles, Send } from 'lucide-react';
|
||||
import {
|
||||
streamChat,
|
||||
createSession,
|
||||
fetchMessages,
|
||||
type ChatMessage,
|
||||
} from '@/api/ai';
|
||||
import { streamChat, fetchMessages } from '@/api/ai';
|
||||
import { apiClient } from '@/api/client';
|
||||
|
||||
interface AiChatPanelProps {
|
||||
windowTitle: string;
|
||||
@@ -30,24 +26,30 @@ export function AiChatPanel({ windowTitle, windowType }: AiChatPanelProps) {
|
||||
const scrollRef = useRef<HTMLDivElement>(null);
|
||||
const msgIdCounter = useRef(0);
|
||||
|
||||
// Create a sidebar session on mount
|
||||
// Create a comm conversation for AI chat on mount
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
setLoadingSession(true);
|
||||
createSession({ title: `KI: ${windowTitle}`, is_sidebar: true })
|
||||
.then((session) => {
|
||||
apiClient.post('/comm/conversations', {
|
||||
title: `KI: ${windowTitle}`,
|
||||
participant_ids: [],
|
||||
is_direct: false,
|
||||
metadata: { conversation_type: 'ai' },
|
||||
})
|
||||
.then((res) => {
|
||||
if (cancelled) return;
|
||||
setSessionId(session.id);
|
||||
return fetchMessages(session.id).then((msgs: ChatMessage[]) => {
|
||||
const convId = res.data.id;
|
||||
setSessionId(convId);
|
||||
return fetchMessages(convId).then((msgs) => {
|
||||
if (cancelled) return;
|
||||
setMessages(
|
||||
msgs.map((m) => ({ id: m.id, role: m.role, content: m.content }))
|
||||
msgs.map((m, i) => ({ id: `msg-${i}`, role: m.role, content: m.content }))
|
||||
);
|
||||
});
|
||||
})
|
||||
.catch((e) => {
|
||||
if (!cancelled) {
|
||||
console.error('AI session creation failed:', e);
|
||||
console.error('AI conversation creation failed:', e);
|
||||
setError('KI Chat ist in diesem Kontext nicht verfügbar');
|
||||
}
|
||||
})
|
||||
@@ -90,7 +92,7 @@ export function AiChatPanel({ windowTitle, windowType }: AiChatPanelProps) {
|
||||
} else if (event.type === 'done') {
|
||||
const msgs = await fetchMessages(sessionId);
|
||||
setMessages(
|
||||
msgs.map((m) => ({ id: m.id, role: m.role, content: m.content }))
|
||||
msgs.map((m, i) => ({ id: `msg-${i}`, role: m.role, content: m.content }))
|
||||
);
|
||||
setStreamingContent('');
|
||||
} else if (event.type === 'error') {
|
||||
|
||||
Reference in New Issue
Block a user