import { useEffect, useRef } from 'react' import { useChatStore } from '../../store/chatStore' import { useWebSocket } from '../../hooks/useWebSocket' import MessageList from './MessageList' import ChatInput from './ChatInput' function moodEmoji(mood: string): string { const map: Record = { 开心: '😊', 平静: '😌', 难过: '😢', 害羞: '☺️', 感动: '🥹' } return map[mood] || '😌' } export default function ChatContainer() { const { send } = useWebSocket() const { messages, isStreaming, currentSessionId, inputText, mood, setInput, addMessage, setStreaming } = useChatStore() const bottomRef = useRef(null) useEffect(() => { bottomRef.current?.scrollIntoView({ behavior: 'smooth' }) }, [messages]) const handleSend = () => { if (!inputText.trim() || !currentSessionId) return const userMsg = { id: crypto.randomUUID(), session_id: currentSessionId, role: 'user' as const, content: inputText, created_at: new Date().toISOString(), } addMessage(userMsg) setStreaming(true) // Placeholder for assistant addMessage({ id: crypto.randomUUID(), session_id: currentSessionId, role: 'assistant' as const, content: '', created_at: new Date().toISOString(), }) send({ type: 'message', content: inputText, session_id: currentSessionId, timestamp: Date.now() }) setInput('') } return (
{/* Mood badge */} {mood && (
{moodEmoji(mood.mood)} {mood.mood}
)} {/* Chat area */}
{messages.length === 0 ? (
Cyrene

开始新对话吧~

) : ( )}
{/* Input bar */}
) }