import { useState, useRef, useEffect } from 'react'; import type { ChatMessage as ChatMsg } from '{{PACKAGE_SCOPE}}/core/shared/types.js'; import { useAppState } from '../context/AppStateContext.js'; import { chatService } from '../services/grpc-client.js'; import { ModelSelector } from './ModelSelector.js'; import { ViewModeToggle } from './ViewModeToggle.js'; import { ChatMessage } from './ChatMessage.js'; export function AgenticChat() { const state = useAppState(); const [input, setInput] = useState(''); const messagesEndRef = useRef(null); const { activeModel, viewMode, messages } = state.chat; const visibleMessages: ChatMsg[] = viewMode === 'focused' ? messages[activeModel] || [] : Object.values(messages).flat().sort((a, b) => a.timestamp.localeCompare(b.timestamp)); useEffect(() => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [visibleMessages.length]); const handleSend = () => { if (!input.trim()) return; chatService.sendMessage(activeModel, input.trim()); setInput(''); }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSend(); } }; return (
chatService.setActiveModel(model)} /> chatService.setViewMode(mode)} />
{visibleMessages.length === 0 && (
Start a conversation...
)} {visibleMessages.map((msg) => ( ))}