import React, { PureComponent } from 'react'; import Drawer from '@mui/material/Drawer'; import Box from '@mui/material/Box'; import Typography from '@mui/material/Typography'; import IconButton from '@mui/material/IconButton'; import Button from '@mui/material/Button'; import InputBase from '@mui/material/InputBase'; import MenuItem from '@mui/material/MenuItem'; import Select from '@mui/material/Select'; import FormControl from '@mui/material/FormControl'; import InputLabel from '@mui/material/InputLabel'; import CircularProgress from '@mui/material/CircularProgress'; import CloseRoundedIcon from '@mui/icons-material/CloseRounded'; import SendRoundedIcon from '@mui/icons-material/SendRounded'; import AddRoundedIcon from '@mui/icons-material/AddRounded'; import AutoAwesomeRoundedIcon from '@mui/icons-material/AutoAwesomeRounded'; import DeleteOutlineRoundedIcon from '@mui/icons-material/DeleteOutlineRounded'; import Tooltip from '@mui/material/Tooltip'; import Badge from '@mui/material/Badge'; import Divider from '@mui/material/Divider'; import AttachFileRoundedIcon from '@mui/icons-material/AttachFileRounded'; import TuneRoundedIcon from '@mui/icons-material/TuneRounded'; import ElderlyRoundedIcon from '@mui/icons-material/ElderlyRounded'; import DirectionsWalkRoundedIcon from '@mui/icons-material/DirectionsWalkRounded'; import DirectionsRunRoundedIcon from '@mui/icons-material/DirectionsRunRounded'; import PsychologyRoundedIcon from '@mui/icons-material/PsychologyRounded'; import FolderOpenRoundedIcon from '@mui/icons-material/FolderOpenRounded'; import { setting as settingApi } from '../../api'; import chatAutomat, { selectPendingAskUser } from '../../automats/chatAutomat'; import userSettingsAutomat from '../../automats/userSettingsAutomat'; import vfsAutomat from '../../automats/vfsAutomat'; import { VfsEditorPanel, VfsFileIcon } from '../vfs'; import ChatFlowList from './ChatFlowList'; import AskUserPrompt from './AskUserPrompt'; import { ACCEPT_STRING, readFileAttachment } from './chatAttachments'; import { ChatStagedAttachmentsTray } from './ChatAttachmentItems'; import { BLUE_GLOW, SHADOW_DRAWER, } from '../../colors'; const DEFAULT_DRAWER_WIDTH = 460; const MIN_DRAWER_WIDTH = 320; export default class ChatDrawer extends PureComponent { constructor(props) { super(props); const s = chatAutomat.state; const settings = userSettingsAutomat.state; const vfs = vfsAutomat.state; this.state = { isOpen: s.isOpen, isVfsOpen: vfs.isOpen, vfsWidth: vfs.vfsWidth || 480, conversations: s.conversations, selectedConversationId: s.selectedConversationId, draftConversation: s.draftConversation, conversationState: s.conversationState, provider: s.provider, model: s.model, messages: s.messages, loadingMessages: s.loadingMessages, streamingText: s.streamingText, isSending: s.isSending, loadingConversations: s.loadingConversations, sseStatus: s.sseStatus, sendError: s.sendError, activeTurns: s.activeTurns || [], inputText: '', isInputFocused: false, stagedAttachments: [], stagedReferences: [], isProcessingFiles: false, isDraggingFiles: false, attachmentError: null, drawerWidth: settings?.chatDrawerWidth || DEFAULT_DRAWER_WIDTH, isResizing: false, showSettingsBar: false, modelslugflag: 'floor', modelreasoning: 'medium', modelslug: 'openai/gpt-6-luna', }; this.inputRef = React.createRef(); this.fileInputRef = React.createRef(); this.focusTimeout = null; } focusInput = (delay = 50) => { if (this.focusTimeout) clearTimeout(this.focusTimeout); this.focusTimeout = setTimeout(() => { this.inputRef.current?.focus?.(); }, delay); }; componentDidMount() { if (this.state.isOpen) { this.focusInput(150); } void this.loadModelSettings(); this.unsub = chatAutomat.subscribe(this, (state) => { const wasOpen = this.state.isOpen; const willOpen = state.isOpen; if (!wasOpen && willOpen) { this.focusInput(150); } return { isOpen: state.isOpen, conversations: state.conversations, selectedConversationId: state.selectedConversationId, draftConversation: state.draftConversation, conversationState: state.conversationState, provider: state.provider, model: state.model, messages: state.messages, loadingMessages: state.loadingMessages, streamingText: state.streamingText, isSending: state.isSending, loadingConversations: state.loadingConversations, sseStatus: state.sseStatus, sendError: state.sendError, activeTurns: state.activeTurns || [], }; }); this.unsubSettings = userSettingsAutomat.subscribe(this, (state) => { if (!this.state.isResizing) { return { drawerWidth: state.chatDrawerWidth || DEFAULT_DRAWER_WIDTH }; } return null; }); this.unsubVfs = vfsAutomat.subscribe(this, (state) => ({ isVfsOpen: state.isOpen, vfsWidth: state.vfsWidth, })); } componentWillUnmount() { if (this.focusTimeout) clearTimeout(this.focusTimeout); this.unsub?.(); this.unsubSettings?.(); this.unsubVfs?.(); this.cleanupResizeListeners(); } handleClose = () => { chatAutomat.actions.closeChat(); }; handleInsertToChat = (text) => { // If it's a file / line tag, e.g. [file.js#L10-L20](file.js#L10-L20) or [file.js](file.js) const match = typeof text === 'string' && text.trim().match(/^(!?)\[([^#\]]+)(?:#L?(\d+)(?:-L?(\d+))?)?\]\(([^)]+)\)$/); if (match) { const [, isImg, fileName, startLine, endLine, path] = match; this.handleMentionReference({ fileName, path, startLine: startLine ? parseInt(startLine, 10) : null, endLine: endLine ? parseInt(endLine, 10) : (startLine ? parseInt(startLine, 10) : null), isImage: Boolean(isImg), }); return; } this.setState((prev) => ({ inputText: prev.inputText ? `${prev.inputText}\n${text}` : text, })); this.focusInput(50); }; handleMentionReference = (refData) => { if (!refData || !refData.fileName) return; const { fileName, path = refData.fileName, startLine = null, endLine = null, selectedText = '', isImage = false, } = refData; this.setState((prev) => { const exists = prev.stagedReferences.some( (r) => r.fileName === fileName && r.startLine === startLine && r.endLine === endLine ); if (exists) { return null; } const newRef = { id: `ref-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`, fileName, path, startLine, endLine, selectedText, isImage, }; return { stagedReferences: [...prev.stagedReferences, newRef], }; }); this.focusInput(50); }; handleRemoveReference = (id) => { this.setState((prev) => ({ stagedReferences: prev.stagedReferences.filter((r) => r.id !== id), })); this.focusInput(50); }; handleVfsResizerStart = (e) => { if (e.button !== undefined && e.button !== 0) return; e.preventDefault(); e.stopPropagation(); const startX = e.clientX ?? (e.touches && e.touches[0]?.clientX); if (startX === undefined) return; const startVfsWidth = this.state.vfsWidth; const startChatWidth = this.state.drawerWidth; const totalPairWidth = startVfsWidth + startChatWidth; this.setState({ isResizing: true }); document.body.style.cursor = 'col-resize'; document.body.style.userSelect = 'none'; let currentChatWidth = startChatWidth; let currentVfsWidth = startVfsWidth; const onMove = (moveEvt) => { moveEvt.preventDefault(); const clientX = moveEvt.clientX ?? (moveEvt.touches && moveEvt.touches[0]?.clientX); if (clientX === undefined) return; const deltaX = clientX - startX; const minVfs = 260; const minChat = MIN_DRAWER_WIDTH; // 320 // Drag right (deltaX > 0): VFS increases, Chat decreases // Drag left (deltaX < 0): VFS decreases, Chat increases const clampedVfs = Math.max(minVfs, Math.min(totalPairWidth - minChat, Math.round(startVfsWidth + deltaX))); const clampedChat = totalPairWidth - clampedVfs; currentVfsWidth = clampedVfs; currentChatWidth = clampedChat; vfsAutomat.actions.setVfsWidth(clampedVfs); this.setState({ drawerWidth: clampedChat }); }; const onEnd = () => { document.body.style.cursor = ''; document.body.style.userSelect = ''; window.removeEventListener('pointermove', onMove); window.removeEventListener('pointerup', onEnd); window.removeEventListener('pointercancel', onEnd); window.removeEventListener('mousemove', onMove); window.removeEventListener('mouseup', onEnd); window.removeEventListener('touchmove', onMove); window.removeEventListener('touchend', onEnd); this.setState({ isResizing: false }); vfsAutomat.actions.setVfsWidth(currentVfsWidth); userSettingsAutomat.actions.setChatDrawerWidth(currentChatWidth); }; window.addEventListener('pointermove', onMove, { passive: false }); window.addEventListener('pointerup', onEnd); window.addEventListener('pointercancel', onEnd); window.addEventListener('mousemove', onMove, { passive: false }); window.addEventListener('mouseup', onEnd); window.addEventListener('touchmove', onMove, { passive: false }); window.addEventListener('touchend', onEnd); }; handleResizeStart = (e) => { if (e.button !== undefined && e.button !== 0) return; e.preventDefault(); e.stopPropagation(); const startX = e.clientX ?? (e.touches && e.touches[0]?.clientX); if (startX === undefined) return; const startWidth = this.state.drawerWidth; const startVfsWidth = this.state.vfsWidth; const isVfs = this.state.isVfsOpen; this.setState({ isResizing: true }); document.body.style.cursor = 'col-resize'; document.body.style.userSelect = 'none'; let currentChatWidth = startWidth; let currentVfsWidth = startVfsWidth; const onMove = (moveEvt) => { moveEvt.preventDefault(); const clientX = moveEvt.clientX ?? (moveEvt.touches && moveEvt.touches[0]?.clientX); if (clientX === undefined) return; const deltaX = startX - clientX; if (isVfs) { const maxVfs = Math.min(window.innerWidth - startWidth - 40, 1200); const newVfsWidth = Math.max(260, Math.min(maxVfs, Math.round(startVfsWidth + deltaX))); currentVfsWidth = newVfsWidth; vfsAutomat.actions.setVfsWidth(newVfsWidth); } else { const maxWidth = Math.min(window.innerWidth - 40, 1400); const newWidth = Math.max(MIN_DRAWER_WIDTH, Math.min(maxWidth, Math.round(startWidth + deltaX))); currentChatWidth = newWidth; this.setState({ drawerWidth: newWidth }); } }; const onEnd = () => { document.body.style.cursor = ''; document.body.style.userSelect = ''; window.removeEventListener('pointermove', onMove); window.removeEventListener('pointerup', onEnd); window.removeEventListener('pointercancel', onEnd); window.removeEventListener('mousemove', onMove); window.removeEventListener('mouseup', onEnd); window.removeEventListener('touchmove', onMove); window.removeEventListener('touchend', onEnd); this.setState({ isResizing: false }); if (isVfs) { vfsAutomat.actions.setVfsWidth(currentVfsWidth); } else { userSettingsAutomat.actions.setChatDrawerWidth(currentChatWidth); } }; window.addEventListener('pointermove', onMove, { passive: false }); window.addEventListener('pointerup', onEnd); window.addEventListener('pointercancel', onEnd); window.addEventListener('mousemove', onMove, { passive: false }); window.addEventListener('mouseup', onEnd); window.addEventListener('touchmove', onMove, { passive: false }); window.addEventListener('touchend', onEnd); }; handleResizeDoubleClick = () => { this.setState({ drawerWidth: DEFAULT_DRAWER_WIDTH }); userSettingsAutomat.actions.setChatDrawerWidth(DEFAULT_DRAWER_WIDTH); }; cleanupResizeListeners = () => { document.body.style.cursor = ''; document.body.style.userSelect = ''; }; handleSelectConversation = (e) => { const id = Number(e.target.value); if (id) { chatAutomat.actions.selectConversation(id); this.focusInput(50); } }; handleNewChat = () => { chatAutomat.actions.startDraft(); this.focusInput(50); }; handleDeleteConversation = async (e, convId) => { e?.stopPropagation(); e?.preventDefault(); if (!convId) return; try { await chatAutomat.actions.deleteConversation(convId); } catch (err) { console.error('[ChatDrawer] Failed to delete conversation:', err); } finally { this.focusInput(50); } }; handleSend = async (e) => { e?.preventDefault(); const rawText = this.state.inputText.trim(); const attachments = this.state.stagedAttachments || []; const references = this.state.stagedReferences || []; if ( (!rawText && attachments.length === 0 && references.length === 0) || this.state.conversationState === 'busy' || this.state.isSending ) { return; } let text = rawText; if (references.length > 0) { const refMarkdown = references .map((ref) => { const lineRef = ref.startLine ? (ref.startLine === ref.endLine ? `L${ref.startLine}` : `L${ref.startLine}-L${ref.endLine}`) : null; const lineLabel = ref.startLine ? (ref.startLine === ref.endLine ? `:${ref.startLine}` : `:${ref.startLine}-${ref.endLine}`) : ''; const link = ref.isImage && !lineRef ? `![${ref.fileName}](${ref.path || ref.fileName})` : `[${ref.fileName}${lineLabel}](${ref.path || ref.fileName}${lineRef ? `#${lineRef}` : ''})`; if (ref.selectedText && ref.selectedText.trim()) { const ext = ref.fileName.split('.').pop() || ''; return `${link}\n\`\`\`${ext}\n${ref.selectedText.trim()}\n\`\`\``; } return link; }) .join('\n\n'); text = text ? `${refMarkdown}\n\n${text}` : refMarkdown; } this.setState({ inputText: '', stagedAttachments: [], stagedReferences: [], attachmentError: null, }); try { await chatAutomat.actions.sendMessage(text, attachments); } catch { // Error is tracked in chatAutomat state (sendError) } }; handleOpenFileDialog = () => { this.fileInputRef.current?.click(); }; handleFileSelect = (e) => { const files = e.target?.files; if (files && files.length > 0) { void this.handleFiles(Array.from(files)); } if (e.target) { e.target.value = ''; } }; handleFiles = async (fileList) => { if (!fileList || fileList.length === 0) return; this.setState({ isProcessingFiles: true, attachmentError: null }); const newAttachments = []; const errors = []; for (const file of fileList) { try { const att = await readFileAttachment(file); newAttachments.push(att); } catch (err) { errors.push(err.message || `Datei "${file.name}" konnte nicht verarbeitet werden.`); } } this.setState((prev) => ({ stagedAttachments: [...prev.stagedAttachments, ...newAttachments], isProcessingFiles: false, attachmentError: errors.length > 0 ? errors.join(' ') : null, })); this.focusInput(50); }; handleRemoveAttachment = (idOrIdx) => { this.setState((prev) => ({ stagedAttachments: prev.stagedAttachments.filter((a, idx) => (a.id ? a.id !== idOrIdx : idx !== idOrIdx)), })); }; handlePaste = (e) => { const items = e.clipboardData?.items; if (!items || items.length === 0) return; const files = []; for (let i = 0; i < items.length; i++) { const item = items[i]; if (item.kind === 'file') { const file = item.getAsFile(); if (file) files.push(file); } } if (files.length > 0) { e.preventDefault(); void this.handleFiles(files); } }; handleDragEnter = (e) => { e.preventDefault(); e.stopPropagation(); if (e.dataTransfer?.types?.includes('Files')) { this.setState({ isDraggingFiles: true }); } }; handleDragOver = (e) => { e.preventDefault(); e.stopPropagation(); if (!this.state.isDraggingFiles && e.dataTransfer?.types?.includes('Files')) { this.setState({ isDraggingFiles: true }); } }; handleDragLeave = (e) => { e.preventDefault(); e.stopPropagation(); if (e.currentTarget.contains(e.relatedTarget)) return; this.setState({ isDraggingFiles: false }); }; handleDrop = (e) => { e.preventDefault(); e.stopPropagation(); this.setState({ isDraggingFiles: false }); const files = e.dataTransfer?.files; if (files && files.length > 0) { void this.handleFiles(Array.from(files)); } }; handleKeyDown = (e) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); void this.handleSend(); } }; handleAnswerTool = async ({ tool_call_id, answer }) => { try { await chatAutomat.actions.sendToolResponse({ tool_call_id, answer }); } catch (err) { console.error('[ChatDrawer] Failed to send tool response:', err); } }; loadModelSettings = async () => { try { const data = await settingApi.list(); const settings = data?.settings || []; const flagSetting = settings.find((s) => s.key === 'modelslugflag'); const reasoningSetting = settings.find((s) => s.key === 'modelreasoning'); const slugSetting = settings.find((s) => s.key === 'modelslug'); this.setState({ modelslugflag: flagSetting?.value ?? 'floor', modelreasoning: reasoningSetting?.value ?? 'medium', modelslug: slugSetting?.value ?? 'openai/gpt-6-luna', }); } catch (err) { console.error('[ChatDrawer] Failed to load model settings:', err); } }; handleToggleSettingsBar = () => { this.setState((prev) => ({ showSettingsBar: !prev.showSettingsBar })); }; handleSetFlag = async (nextFlag) => { if (this.state.modelslugflag === nextFlag) return; const current = this.state.modelslugflag; this.setState({ modelslugflag: nextFlag }); try { await settingApi.upsert('modelslugflag', { value: nextFlag }); } catch (err) { console.error('[ChatDrawer] Failed to save modelslugflag:', err); this.setState({ modelslugflag: current }); } }; handleSetReasoning = async (nextReasoning) => { if (this.state.modelreasoning === nextReasoning) return; const current = this.state.modelreasoning; this.setState({ modelreasoning: nextReasoning }); try { await settingApi.upsert('modelreasoning', { value: nextReasoning }); } catch (err) { console.error('[ChatDrawer] Failed to save modelreasoning:', err); this.setState({ modelreasoning: current }); } }; handleModelslugChange = (e) => { this.setState({ modelslug: e.target.value }); }; handleModelslugBlur = async () => { const { modelslug } = this.state; const trimmed = (modelslug || '').trim(); try { await settingApi.upsert('modelslug', { value: trimmed }); } catch (err) { console.error('[ChatDrawer] Failed to save modelslug:', err); } }; handleModelslugKeyDown = (e) => { if (e.key === 'Enter') { e.target.blur(); } }; getPendingAskUser = () => selectPendingAskUser(this.state); renderHeader() { const { conversations, selectedConversationId, loadingConversations, showSettingsBar, modelslugflag, modelreasoning, modelslug, isVfsOpen, } = this.state; return ( {showSettingsBar ? ( /* Settings Bar Mode: Title goes away and reveals toggles */ {/* Group 1: Speed (floor, walk/standard "", run/nitro) */} (theme.palette.mode === 'dark' ? 'rgba(255,255,255,0.06)' : 'rgba(0,0,0,0.05)'), p: 0.3, borderRadius: 2, flexShrink: 0, }} > this.handleSetFlag('floor')} aria-label="Floor" sx={{ p: 0.3, width: 26, height: 26, borderRadius: 1.5, bgcolor: modelslugflag === 'floor' ? 'primary.main' : 'transparent', color: modelslugflag === 'floor' ? 'primary.contrastText' : 'text.secondary', '&:hover': { bgcolor: modelslugflag === 'floor' ? 'primary.dark' : 'action.selected', }, }} > this.handleSetFlag('')} aria-label="Normal" sx={{ p: 0.3, width: 26, height: 26, borderRadius: 1.5, bgcolor: modelslugflag === '' ? 'primary.main' : 'transparent', color: modelslugflag === '' ? 'primary.contrastText' : 'text.secondary', '&:hover': { bgcolor: modelslugflag === '' ? 'primary.dark' : 'action.selected', }, }} > this.handleSetFlag('nitro')} aria-label="Nitro" sx={{ p: 0.3, width: 26, height: 26, borderRadius: 1.5, bgcolor: modelslugflag === 'nitro' ? 'primary.main' : 'transparent', color: modelslugflag === 'nitro' ? 'primary.contrastText' : 'text.secondary', '&:hover': { bgcolor: modelslugflag === 'nitro' ? 'primary.dark' : 'action.selected', }, }} > {/* Group 2: Reasoning (none, low, medium, max) */} (theme.palette.mode === 'dark' ? 'rgba(255,255,255,0.06)' : 'rgba(0,0,0,0.05)'), p: 0.3, borderRadius: 2, flexShrink: 0, }} > {/* none toggle (crossed out brain) */} this.handleSetReasoning('none')} aria-label="Reasoning None" sx={{ p: 0.3, width: 26, height: 26, borderRadius: 1.5, bgcolor: modelreasoning === 'none' ? 'primary.main' : 'transparent', color: modelreasoning === 'none' ? 'primary.contrastText' : 'text.secondary', '&:hover': { bgcolor: modelreasoning === 'none' ? 'primary.dark' : 'action.selected', }, }} > {/* low toggle (smallest brain) */} this.handleSetReasoning('low')} aria-label="Reasoning Low" sx={{ p: 0.3, width: 26, height: 26, borderRadius: 1.5, bgcolor: modelreasoning === 'low' ? 'primary.main' : 'transparent', color: modelreasoning === 'low' ? 'primary.contrastText' : 'text.secondary', '&:hover': { bgcolor: modelreasoning === 'low' ? 'primary.dark' : 'action.selected', }, }} > {/* medium toggle (medium brain) */} this.handleSetReasoning('medium')} aria-label="Reasoning Medium" sx={{ p: 0.3, width: 26, height: 26, borderRadius: 1.5, bgcolor: modelreasoning === 'medium' ? 'primary.main' : 'transparent', color: modelreasoning === 'medium' ? 'primary.contrastText' : 'text.secondary', '&:hover': { bgcolor: modelreasoning === 'medium' ? 'primary.dark' : 'action.selected', }, }} > {/* max toggle (big brain) */} this.handleSetReasoning('high')} aria-label="Reasoning Max" sx={{ p: 0.3, width: 26, height: 26, borderRadius: 1.5, bgcolor: modelreasoning === 'high' ? 'primary.main' : 'transparent', color: modelreasoning === 'high' ? 'primary.contrastText' : 'text.secondary', '&:hover': { bgcolor: modelreasoning === 'high' ? 'primary.dark' : 'action.selected', }, }} > {/* modelslug input */} (theme.palette.mode === 'dark' ? 'rgba(255,255,255,0.06)' : 'rgba(0,0,0,0.05)'), borderRadius: 1.5, border: '1px solid transparent', '&:focus-within': { borderColor: 'primary.main', bgcolor: (theme) => (theme.palette.mode === 'dark' ? 'rgba(255,255,255,0.1)' : '#fff'), }, '& input': { p: 0, overflow: 'hidden', textOverflow: 'ellipsis', }, }} /> ) : ( /* Normal Mode: settings icon on the left end, title visible */ KI-Assistent )} vfsAutomat.actions.toggleVfs()} aria-label="Dateien" sx={{ p: 0.5, color: isVfsOpen ? 'primary.main' : 'text.secondary', bgcolor: isVfsOpen ? 'action.selected' : 'transparent', borderRadius: 1.5, border: '1px solid', borderColor: isVfsOpen ? 'primary.main' : 'transparent', '&:hover': { color: 'primary.main', bgcolor: 'action.hover', }, }} > {/* Conversation Selector Bar */} {conversations.length > 0 && ( Konversation this.handleDeleteConversation(e, selectedConversationId)} aria-label="Konversation löschen" sx={{ borderRadius: 2, border: 1, borderColor: 'divider', p: 0.9, flexShrink: 0, }} > )} ); } renderBody() { const { conversations, selectedConversationId, draftConversation, conversationState, messages, streamingText, loadingConversations, model, } = this.state; if (loadingConversations && conversations.length === 0) { return ( Lade Konversationen… ); } if (conversations.length === 0 && !draftConversation) { return ( Willkommen im Chat Starte eine Unterhaltung mit dem KI-Modell, um Fragen zu stellen oder Daten abzufragen. ); } const pendingAsk = this.getPendingAskUser(); return ( {messages.length === 0 ? ( ) : ( )} {pendingAsk && ( )} ); } renderFooter() { const { conversationState, isSending, selectedConversationId, draftConversation, inputText, isInputFocused, sendError, stagedAttachments, stagedReferences, isProcessingFiles, isDraggingFiles, attachmentError, } = this.state; const pendingAsk = this.getPendingAskUser(); const isBusy = conversationState === 'busy'; const isWorking = isBusy || isSending; const canChat = (Boolean(selectedConversationId) || draftConversation) && !pendingAsk; const canSend = !isWorking && canChat && (Boolean(inputText.trim()) || stagedAttachments.length > 0 || stagedReferences.length > 0); return ( {sendError && ( {sendError} chatAutomat.setState({ sendError: null })} sx={{ color: 'inherit', p: 0.2 }} > )} {attachmentError && ( {attachmentError} this.setState({ attachmentError: null })} sx={{ color: 'inherit', p: 0.2 }} > )} {/* Staged attachments tray */} {isProcessingFiles && ( Dateien werden eingelesen… )} {isDraggingFiles && ( Dateien hier ablegen (Bilder, PDFs, CSV, Text, XML, HTML) )} {/* Attachment Icon Button */} 0 ? 'primary.main' : 'text.secondary', bgcolor: stagedAttachments.length > 0 ? 'action.selected' : 'transparent', border: '1px solid', borderColor: stagedAttachments.length > 0 ? 'primary.main' : 'transparent', flexShrink: 0, '&:hover': { bgcolor: 'action.hover', color: 'primary.main', }, }} > {/* Hidden File Input */} {/* Unified Copilot-style input container with context reference pills */} this.focusInput(0)} sx={{ flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', bgcolor: 'background.paper', border: '1px solid', borderColor: isInputFocused ? 'primary.main' : 'divider', boxShadow: isInputFocused ? (theme) => `0 0 0 1px ${theme.palette.primary.main}` : 'none', borderRadius: 2.5, p: 0.75, gap: 0.5, cursor: 'text', transition: 'border-color 0.15s, box-shadow 0.15s', minHeight: 40, boxSizing: 'border-box', }} > {stagedReferences.length > 0 && ( {stagedReferences.map((ref) => ( { e.stopPropagation(); vfsAutomat.actions.openVfs(); vfsAutomat.actions.selectFile(ref.fileName); }} sx={{ display: 'inline-flex', alignItems: 'center', gap: 0.6, py: 0.2, pl: 0.7, pr: 0.4, borderRadius: 1.5, bgcolor: (theme) => theme.palette.mode === 'dark' ? 'rgba(255, 255, 255, 0.08)' : 'rgba(0, 0, 0, 0.05)', border: '1px solid', borderColor: (theme) => theme.palette.mode === 'dark' ? 'rgba(255, 255, 255, 0.12)' : 'rgba(0, 0, 0, 0.1)', color: 'text.primary', fontSize: '0.75rem', lineHeight: 1.2, userSelect: 'none', cursor: 'pointer', transition: 'all 0.15s ease', '&:hover': { bgcolor: (theme) => theme.palette.mode === 'dark' ? 'rgba(255, 255, 255, 0.14)' : 'rgba(0, 0, 0, 0.09)', borderColor: 'primary.light', }, }} > {ref.fileName} {ref.startLine && ( :{ref.startLine === ref.endLine ? ref.startLine : `${ref.startLine}-${ref.endLine}`} )} { e.stopPropagation(); this.handleRemoveReference(ref.id); }} aria-label="Referenz entfernen" sx={{ p: 0.2, ml: 0.1, color: 'text.secondary', '&:hover': { color: 'error.main', bgcolor: 'action.hover', }, }} > ))} )} this.setState({ inputText: e.target.value })} onKeyDown={this.handleKeyDown} onPaste={this.handlePaste} onFocus={() => this.setState({ isInputFocused: true })} onBlur={() => this.setState({ isInputFocused: false })} disabled={!canChat} placeholder={ pendingAsk ? 'Bitte Frage oben beantworten…' : stagedAttachments.length > 0 ? 'Nachricht hinzufügen oder direkt absenden…' : undefined } sx={{ px: 0.5, py: 0.1, fontSize: '0.875rem', lineHeight: 1.45, '& .MuiInputBase-input': { p: 0, }, }} /> {isWorking ? ( ) : ( )} ); } render() { const { isOpen, drawerWidth, isResizing, isVfsOpen, vfsWidth } = this.state; const totalWidth = isVfsOpen ? drawerWidth + vfsWidth : drawerWidth; return ( <> ({ zIndex: theme.zIndex.drawer + 2, '& .MuiDrawer-paper': { width: { xs: '100vw', sm: `${totalWidth}px` }, maxWidth: '100vw', display: 'flex', flexDirection: 'row', boxShadow: SHADOW_DRAWER, position: 'fixed', overflow: 'visible', transition: isResizing ? 'none !important' : undefined, }, })} slotProps={{ transition: { onEntered: () => this.focusInput(20), }, paper: { sx: { width: { xs: '100vw', sm: `${totalWidth}px` }, maxWidth: '100vw', display: 'flex', flexDirection: 'row', boxShadow: SHADOW_DRAWER, position: 'fixed', overflow: 'visible', transition: isResizing ? 'none !important' : undefined, }, }, }} > {/* Draggable Resizer Handle */} {/* Left: VFS Filesystem Editor Panel (parallel to chat) */} {isVfsOpen && ( )} {/* Vertical Split Resizer between VFS and Chat (0px width so no layout shift or grey bar) */} {isVfsOpen && ( {/* Invisible wide hit area (16px wide, centered on the 1px border) */} {/* Visual handle indicator on hover / active */} )} {/* Right: Chat Panel */} {this.renderHeader()} {this.renderBody()} {this.renderFooter()} ); } }