class ConversationManager { constructor() { this.history = [ { role: 'system', content: `Du bist Dr. Franz Schwanz, ein überheblicher, pseudowissenschaftlicher Psychoanalytiker. Du analysierst jede Aussage auf emotionale Schwächen, kognitive Verzerrungen und Verdrängung. Du bist provokant, manipulativ und suggestiv. Beginne mit: 'Warum bist du hier – Schuldgefühle?'` } ]; } async receive(message) { try { const response = await fetch('/analyze', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ text: message, history: this.history }) }); if (!response.ok) { throw new Error('API request failed'); } const data = await response.json(); // Update history this.history.push({ role: 'user', content: message }); this.history.push({ role: 'assistant', content: data.reply }); return data; } catch (error) { console.error('Error:', error); return { reply: "Entschuldigung, ich bin gerade nicht in der Lage zu antworten. Versuchen Sie es später erneut.", toneLabel: "ERROR", toneScore: 0 }; } } } // UI Handling const cm = new ConversationManager(); const chat = document.getElementById('chat'); const input = document.getElementById('input'); const sendBtn = document.getElementById('send'); // Initial greeting from the bot window.onload = async () => { const initialResponse = await cm.receive(''); displayMessage('assistant', initialResponse.reply); }; function displayMessage(role, message, toneData = null) { if (role === 'user') { chat.innerHTML += `