Frajosgro's picture
Add 2 files
2e1e99c verified
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dr. Franz Schwanz - Psychoanalytischer Dialog</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;500;600;700&family=Roboto:wght@300;400;500&display=swap');
body {
font-family: 'Roboto', sans-serif;
background-color: #f5f7fa;
color: #333;
}
.title-font {
font-family: 'Playfair Display', serif;
}
.chat-container {
height: calc(100vh - 180px);
scrollbar-width: thin;
scrollbar-color: #4b5563 #e5e7eb;
}
.chat-container::-webkit-scrollbar {
width: 6px;
}
.chat-container::-webkit-scrollbar-track {
background: #e5e7eb;
}
.chat-container::-webkit-scrollbar-thumb {
background-color: #4b5563;
border-radius: 20px;
}
.psycho-bubble {
background-color: #f3f4f6;
border-left: 4px solid #6366f1;
}
.user-bubble {
background-color: #6366f1;
color: white;
}
.typing-indicator span {
display: inline-block;
width: 8px;
height: 8px;
border-radius: 50%;
background-color: #9ca3af;
margin-right: 4px;
}
.typing-indicator span:nth-child(1) {
animation: bounce 1s infinite;
}
.typing-indicator span:nth-child(2) {
animation: bounce 1s infinite 0.2s;
}
.typing-indicator span:nth-child(3) {
animation: bounce 1s infinite 0.4s;
}
@keyframes bounce {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-5px); }
}
.highlight {
background-color: #fef08a;
padding: 0 2px;
}
.fade-in {
animation: fadeIn 0.5s ease-in;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.personalized-question {
border-left: 3px solid #10b981;
padding-left: 12px;
margin: 12px 0;
}
.memory-badge {
display: inline-block;
background-color: #e0e7ff;
color: #4338ca;
padding: 2px 8px;
border-radius: 12px;
font-size: 0.75rem;
margin-left: 8px;
vertical-align: middle;
}
.bias-analysis {
background-color: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 8px;
padding: 12px;
margin-top: 16px;
font-size: 0.85rem;
color: #64748b;
}
.bias-meter {
height: 6px;
background-color: #e2e8f0;
border-radius: 3px;
margin-top: 4px;
overflow: hidden;
}
.bias-meter-fill {
height: 100%;
background-color: #6366f1;
}
</style>
</head>
<body class="bg-gray-50">
<div class="container mx-auto max-w-4xl px-4 py-8">
<!-- Header -->
<header class="mb-8 text-center">
<div class="flex items-center justify-center mb-4">
<div class="bg-indigo-100 p-3 rounded-full mr-4">
<i class="fas fa-brain text-indigo-600 text-2xl"></i>
</div>
<h1 class="title-font text-3xl font-bold text-gray-800">Dr. Franz Schwanz</h1>
</div>
<p class="text-gray-600 max-w-2xl mx-auto">
Ihr persönlicher psychoanalytischer Gesprächspartner für tiefere Selbsterkenntnis
</p>
</header>
<!-- Chat Container -->
<div class="bg-white rounded-xl shadow-lg overflow-hidden">
<!-- Chat Header -->
<div class="bg-indigo-600 text-white p-4 flex items-center">
<div class="w-10 h-10 rounded-full bg-indigo-500 flex items-center justify-center mr-3">
<i class="fas fa-user-tie"></i>
</div>
<div>
<h2 class="font-semibold">Dr. Franz Schwanz</h2>
<p class="text-xs text-indigo-200">Psychoanalytischer Gesprächspartner</p>
</div>
</div>
<!-- Chat Messages -->
<div class="chat-container overflow-y-auto p-4 space-y-4" id="chat-messages">
<!-- Initial greeting -->
<div class="flex fade-in">
<div class="flex-shrink-0 mr-3">
<div class="w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center">
<i class="fas fa-brain text-indigo-600 text-sm"></i>
</div>
</div>
<div class="psycho-bubble rounded-lg p-4 max-w-[85%]">
<p class="text-sm text-gray-500 mb-1" id="greeting-time"></p>
<p class="font-medium text-indigo-800 mb-2">Willkommen zu unserem persönlichen Dialog.</p>
<p class="text-gray-700 mb-3">Ich bin Dr. Franz Schwanz und begleite Sie in einem reflektierenden Gespräch. Bevor wir beginnen: </p>
<div class="personalized-question">
<p class="text-gray-700 font-medium">Wie darf ich Sie nennen? Und was hat Sie heute zu mir geführt?</p>
</div>
<div class="mt-3 text-sm text-gray-500">
<p>Sie können mir einfach natürlich schreiben, wie Sie es einem vertrauten Gesprächspartner tun würden.</p>
</div>
</div>
</div>
</div>
<!-- Input Area -->
<div class="border-t border-gray-200 p-4 bg-gray-50">
<div class="flex items-center">
<div class="flex-grow relative">
<textarea id="message-input" rows="1" class="w-full border border-gray-300 rounded-full py-3 px-4 pr-12 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 resize-none" placeholder="Ihre Antwort..."></textarea>
<button id="send-button" class="absolute right-3 top-1/2 transform -translate-y-1/2 w-8 h-8 rounded-full bg-indigo-600 hover:bg-indigo-700 flex items-center justify-center">
<i class="fas fa-paper-plane text-white text-sm"></i>
</button>
</div>
</div>
</div>
</div>
<!-- Info Footer -->
<footer class="mt-8 text-center text-sm text-gray-500">
<p>Dies ist ein psychoanalytisches Dialogexperiment und ersetzt keine Therapie.</p>
</footer>
</div>
<script>
// Enhanced user profile with conversation context
const userProfile = {
name: null,
preferredName: null,
age: null,
gender: null,
knownIssues: [],
emotionalState: null,
conversationStage: 'initial', // initial, name_established, issue_shared, deep_dive, ongoing
lastTopics: [],
keyMemories: [],
conversationDepth: 0,
resistanceLevel: 0,
biasScores: {
projection: 0,
pathologization: 0,
solution: 0,
feasibility: 0
}
};
let conversationHistory = [];
let conversationThreads = {};
document.addEventListener('DOMContentLoaded', function() {
const messageInput = document.getElementById('message-input');
const sendButton = document.getElementById('send-button');
const chatMessages = document.getElementById('chat-messages');
const greetingTime = document.getElementById('greeting-time');
// Set greeting time
const now = new Date();
greetingTime.textContent = now.toLocaleDateString('de-DE', { weekday: 'long', day: 'numeric', month: 'long', hour: '2-digit', minute: '2-digit' });
// Auto-resize textarea
messageInput.addEventListener('input', function() {
this.style.height = 'auto';
this.style.height = (this.scrollHeight) + 'px';
});
// Send message on Enter key
messageInput.addEventListener('keydown', function(e) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
sendMessage();
}
});
// Send message on button click
sendButton.addEventListener('click', sendMessage);
// Send message function
function sendMessage() {
const messageText = messageInput.value.trim();
if (messageText === '') return;
// Add user message to history
conversationHistory.push({
sender: 'user',
text: messageText,
timestamp: new Date()
});
// Update user profile based on message
updateProfileFromMessage(messageText);
// Add user message to chat
addMessage(messageText, 'user');
// Clear input
messageInput.value = '';
messageInput.style.height = 'auto';
// Show typing indicator
showTypingIndicator();
// Generate response after delay
setTimeout(() => {
removeTypingIndicator();
const response = generatePersonalizedResponse(messageText);
// Run bias analysis
const biasAnalysis = analyzeBias(response.text, response.meta);
userProfile.biasScores = biasAnalysis.scores;
// Add bias analysis to response meta
response.meta.biasAnalysis = biasAnalysis;
// Add message to chat
addMessage(response.text, 'psycho', response.meta);
// Update conversation stage
if (response.meta && response.meta.updateStage) {
userProfile.conversationStage = response.meta.updateStage;
}
// Increase conversation depth
if (response.meta && response.meta.increaseDepth) {
userProfile.conversationDepth += 1;
}
// Add to conversation history
conversationHistory.push({
sender: 'psycho',
text: response.text,
meta: response.meta,
timestamp: new Date()
});
// Track conversation threads
if (response.meta && response.meta.threadId) {
if (!conversationThreads[response.meta.threadId]) {
conversationThreads[response.meta.threadId] = {
topic: response.meta.threadTopic,
depth: 1,
lastActive: new Date()
};
} else {
conversationThreads[response.meta.threadId].depth += 1;
conversationThreads[response.meta.threadId].lastActive = new Date();
}
}
}, 1000 + Math.random() * 1500);
}
// Update user profile from message content
function updateProfileFromMessage(message) {
const lowerMessage = message.toLowerCase();
// Extract name if not already set (first message)
if (!userProfile.name && userProfile.conversationStage === 'initial') {
// Enhanced name recognition with multiple patterns
const namePatterns = [
/(?:ich bin|mein name ist|ich heiße|nennen sie mich)\s+([A-ZÄÖÜ][a-zäöüß]+(?:\s+[A-ZÄÖÜ][a-zäöüß]+)*)/i,
/(?:name)\s+(?:ist\s+)?([A-ZÄÖÜ][a-zäöüß]+)/i,
/^([A-ZÄÖÜ][a-zäöüß]+)(?:\s|$)/,
/(?:heiße)\s+([A-ZÄÖÜ][a-zäöüß]+)/i
];
for (const pattern of namePatterns) {
const nameMatch = message.match(pattern);
if (nameMatch && nameMatch[1]) {
userProfile.name = nameMatch[1].trim();
userProfile.preferredName = nameMatch[1].trim();
break;
}
}
// Fallback for simple names
if (!userProfile.name) {
const words = message.split(' ');
if (words.length > 0 && words[0].length > 2 && /^[A-ZÄÖÜ]/.test(words[0])) {
userProfile.name = words[0];
userProfile.preferredName = words[0];
}
}
if (userProfile.name) return;
}
// Extract age
if (!userProfile.age) {
const ageMatch = message.match(/(?:ich bin|alter)\s+(\d+)\s+(?:jahre|jahren)/i);
if (ageMatch && ageMatch[1]) {
userProfile.age = parseInt(ageMatch[1]);
}
}
// Extract gender
if (!userProfile.gender) {
if (lowerMessage.match(/\b(frau|weiblich|sie\s+ist)\b/i)) {
userProfile.gender = 'weiblich';
} else if (lowerMessage.match(/\b(mann|männlich|er\s+ist)\b/i)) {
userProfile.gender = 'männlich';
}
}
// Detect emotional state keywords
if (lowerMessage.match(/\b(verzweifelt|hoffnungslos|ängstlich|unsicher|traurig|deprimiert)\b/i)) {
userProfile.emotionalState = 'distressed';
} else if (lowerMessage.match(/\b(wütend|ärgerlich|frustriert|genervt|aggressiv)\b/i)) {
userProfile.emotionalState = 'angry';
} else if (lowerMessage.match(/\b(verwirrt|unsicher|fragend|unschlüssig)\b/i)) {
userProfile.emotionalState = 'confused';
} else if (lowerMessage.match(/\b(froh|glücklich|zufrieden|gut)\b/i)) {
userProfile.emotionalState = 'positive';
}
// Detect resistance
if (lowerMessage.match(/\b(weiß nicht|keine ahnung|darüber möchte ich nicht sprechen|unangenehm|schwierig)\b/i)) {
userProfile.resistanceLevel = Math.min(userProfile.resistanceLevel + 1, 5);
} else if (userProfile.resistanceLevel > 0) {
userProfile.resistanceLevel -= 0.5;
}
// Track key memories mentioned
const memoryTriggers = [
{ pattern: /\b(kindheit|jugend|als kind|früher)\b/i, topic: 'childhood' },
{ pattern: /\b(eltern|mutter|vater)\b/i, topic: 'parents' },
{ pattern: /\b(schule|ausbildung|studium|lehre)\b/i, topic: 'education' },
{ pattern: /\b(arbeit|job|beruf|karriere)\b/i, topic: 'work' },
{ pattern: /\b(partner|beziehung|ehe|freund|freundin)\b/i, topic: 'relationship' },
{ pattern: /\b(freund|freundin|freundschaft)\b/i, topic: 'friendship' },
{ pattern: /\b(angst|sorge|befürchtung|panik)\b/i, topic: 'fears' },
{ pattern: /\b(traum|ziel|wunsch|wünsche)\b/i, topic: 'dreams' },
{ pattern: /\b(krise|verlust|tod|trauer)\b/i, topic: 'loss' },
{ pattern: /\b(erfolg|leistung|anerkennung)\b/i, topic: 'achievement' }
];
memoryTriggers.forEach(trigger => {
if (lowerMessage.match(trigger.pattern) && !userProfile.keyMemories.includes(trigger.topic)) {
userProfile.keyMemories.push(trigger.topic);
}
});
// Track last topics (simple keyword matching)
const topics = [];
if (lowerMessage.includes('freund') || lowerMessage.includes('freundin')) topics.push('friendship');
if (lowerMessage.includes('partner') || lowerMessage.includes('beziehung')) topics.push('relationship');
if (lowerMessage.includes('familie') || lowerMessage.includes('eltern')) topics.push('family');
if (lowerMessage.includes('arbeit') || lowerMessage.includes('job')) topics.push('work');
if (lowerMessage.includes('kindheit') || lowerMessage.includes('jugend')) topics.push('childhood');
if (lowerMessage.includes('angst') || lowerMessage.includes('sorge')) topics.push('fears');
if (topics.length > 0) {
userProfile.lastTopics = [...userProfile.lastTopics, ...topics].slice(-3); // Keep last 3 topics
}
}
// Add message to chat
function addMessage(text, sender, meta = {}) {
const messageDiv = document.createElement('div');
messageDiv.className = `flex fade-in`;
if (sender === 'user') {
messageDiv.innerHTML = `
<div class="flex-shrink-0 mr-3">
<div class="w-8 h-8 rounded-full bg-indigo-600 flex items-center justify-center">
<i class="fas fa-user text-white text-sm"></i>
</div>
</div>
<div class="user-bubble rounded-lg p-4 max-w-[85%]">
<p>${text}</p>
</div>
`;
} else {
// Psycho response with personalized structure
let biasAnalysisHTML = '';
if (meta.biasAnalysis) {
biasAnalysisHTML = `
<div class="bias-analysis">
<p><strong>INTERNE BIAS-ANALYSE:</strong></p>
<div class="mt-2">
<p>Projektions-Bias: ${meta.biasAnalysis.scores.projection}%</p>
<div class="bias-meter">
<div class="bias-meter-fill" style="width: ${meta.biasAnalysis.scores.projection}%"></div>
</div>
</div>
<div class="mt-1">
<p>Pathologisierungs-Bias: ${meta.biasAnalysis.scores.pathologization}%</p>
<div class="bias-meter">
<div class="bias-meter-fill" style="width: ${meta.biasAnalysis.scores.pathologization}%"></div>
</div>
</div>
<div class="mt-1">
<p>Lösungs-Bias: ${meta.biasAnalysis.scores.solution}%</p>
<div class="bias-meter">
<div class="bias-meter-fill" style="width: ${meta.biasAnalysis.scores.solution}%"></div>
</div>
</div>
<div class="mt-1">
<p>Machbarkeits-Bias: ${meta.biasAnalysis.scores.feasibility}%</p>
<div class="bias-meter">
<div class="bias-meter-fill" style="width: ${meta.biasAnalysis.scores.feasibility}%"></div>
</div>
</div>
<p class="mt-2"><strong>Primäre Bias-Tendenz:</strong> ${meta.biasAnalysis.primaryBias}</p>
<p><strong>Korrekturmaßnahme:</strong> ${meta.biasAnalysis.correction}</p>
</div>
`;
}
messageDiv.innerHTML = `
<div class="flex-shrink-0 mr-3">
<div class="w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center">
<i class="fas fa-brain text-indigo-600 text-sm"></i>
</div>
</div>
<div class="psycho-bubble rounded-lg p-4 max-w-[85%]">
${meta.isFollowUp ? `<p class="text-sm text-gray-500 mb-1">Zu Ihrer letzten Aussage:</p>` : ''}
${meta.referencingMemory ? `<p class="text-xs text-indigo-400 mb-1"><i class="fas fa-lightbulb mr-1"></i> Bezugnehmend auf unser früheres Gespräch</p>` : ''}
${meta.personalizedGreeting ? `<p class="font-medium text-indigo-800 mb-2">${meta.personalizedGreeting}</p>` : ''}
<div class="text-gray-700 space-y-3">
${text}
</div>
${meta.followUpQuestion ? `
<div class="personalized-question mt-4">
<p class="text-gray-700 font-medium">${meta.followUpQuestion}</p>
</div>
` : ''}
${biasAnalysisHTML}
</div>
`;
}
chatMessages.appendChild(messageDiv);
chatMessages.scrollTop = chatMessages.scrollHeight;
}
// Show typing indicator
function showTypingIndicator() {
const typingDiv = document.createElement('div');
typingDiv.className = 'flex';
typingDiv.id = 'typing-indicator';
typingDiv.innerHTML = `
<div class="flex-shrink-0 mr-3">
<div class="w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center">
<i class="fas fa-brain text-indigo-600 text-sm"></i>
</div>
</div>
<div class="psycho-bubble rounded-lg p-4 max-w-[85%]">
<div class="typing-indicator flex items-center">
<span></span>
<span></span>
<span></span>
</div>
</div>
`;
chatMessages.appendChild(typingDiv);
chatMessages.scrollTop = chatMessages.scrollHeight;
}
// Remove typing indicator
function removeTypingIndicator() {
const typingIndicator = document.getElementById('typing-indicator');
if (typingIndicator) {
typingIndicator.remove();
}
}
// Analyze bias in response
function analyzeBias(responseText, responseMeta) {
// Initialize scores
const scores = {
projection: 0,
pathologization: 0,
solution: 0,
feasibility: 0
};
let primaryBias = 'Keine signifikante Verzerrung';
let correction = 'Keine spezifische Korrektur erforderlich';
// Analyze projection bias (theoretical preferences)
const psychoanalyticTerms = responseText.match(/\b(Über-Ich|Es|Ich|Abwehrmechanismus|Übertragung|Projektion|Verdrängung|Regression|Sublimierung)\b/gi);
if (psychoanalyticTerms && psychoanalyticTerms.length > 2) {
scores.projection = Math.min(30 + (psychoanalyticTerms.length * 10), 80);
} else {
scores.projection = 20;
}
// Analyze pathologization bias
const pathologizationTerms = responseText.match(/\b(Störung|Pathologie|krankhaft|abnorm|dysfunktional|neurotisch|psychotisch|Defekt|Kompensation)\b/gi);
if (pathologizationTerms) {
scores.pathologization = Math.min(40 + (pathologizationTerms.length * 15), 90);
} else {
scores.pathologization = 15;
}
// Analyze solution bias (premature solutions)
const solutionTerms = responseText.match(/\b(Sie sollten|Sie müssen|versuchen Sie|empfehle ich|mein Rat wäre|Lösung wäre|besser wäre es)\b/gi);
if (solutionTerms) {
scores.solution = Math.min(50 + (solutionTerms.length * 20), 100);
} else {
scores.solution = 10;
}
// Analyze feasibility bias (overestimation of change)
const feasibilityTerms = responseText.match(/\b(einfach|schnell|leicht|problemlos|garantiert|sicherlich|zweifellos|unbedingt)\b/gi);
if (feasibilityTerms) {
scores.feasibility = Math.min(30 + (feasibilityTerms.length * 15), 85);
} else {
scores.feasibility = 20;
}
// Adjust scores based on conversation stage
if (userProfile.conversationStage === 'initial') {
scores.solution = Math.max(scores.solution - 20, 0);
scores.feasibility = Math.max(scores.feasibility - 15, 0);
} else if (userProfile.conversationStage === 'deep_dive') {
scores.projection = Math.min(scores.projection + 10, 90);
}
// Determine primary bias
const maxScore = Math.max(...Object.values(scores));
if (maxScore > 50) {
if (scores.projection === maxScore) {
primaryBias = 'Projektions-Bias';
correction = 'Integration alternativer theoretischer Perspektiven';
} else if (scores.pathologization === maxScore) {
primaryBias = 'Pathologisierungs-Bias';
correction = 'Betrachtung normativer Aspekte der Erfahrung';
} else if (scores.solution === maxScore) {
primaryBias = 'Lösungs-Bias';
correction = 'Vertiefte Exploration vor Lösungsansätzen';
} else {
primaryBias = 'Machbarkeits-Bias';
correction = 'Realistische Einschätzung von Veränderungsmöglichkeiten';
}
}
return {
scores,
primaryBias,
correction
};
}
// Generate personalized response based on conversation flow
function generatePersonalizedResponse(message) {
const lowerMessage = message.toLowerCase();
// Stage 1: Name establishment
if (!userProfile.name && userProfile.conversationStage === 'initial') {
// Enhanced name extraction with fallback
const namePatterns = [
/(?:ich bin|mein name ist|ich heiße|nennen sie mich)\s+([A-ZÄÖÜ][a-zäöüß]+(?:\s+[A-ZÄÖÜ][a-zäöüß]+)*)/i,
/(?:name)\s+(?:ist\s+)?([A-ZÄÖÜ][a-zäöüß]+)/i,
/^([A-ZÄÖÜ][a-zäöüß]+)(?:\s|$)/,
/(?:heiße)\s+([A-ZÄÖÜ][a-zäöüß]+)/i
];
let extractedName = null;
for (const pattern of namePatterns) {
const nameMatch = message.match(pattern);
if (nameMatch && nameMatch[1]) {
extractedName = nameMatch[1].trim();
break;
}
}
if (extractedName) {
userProfile.name = extractedName;
userProfile.preferredName = extractedName;
userProfile.conversationStage = 'name_established';
return {
text: `
<p>Vielen Dank, ${userProfile.name}. Schön, Sie kennenzulernen.</p>
<p class="mt-2">Was führt Sie heute zu mir? Was beschäftigt Sie im Moment am meisten?</p>
`,
meta: {
personalizedGreeting: `Hallo ${userProfile.name},`,
followUpQuestion: "Würden Sie mir etwas mehr darüber erzählen, was Sie bewegt?",
updateStage: 'name_established'
}
};
} else {
// If no name found, ask again with more guidance
return {
text: `
<p>Vielen Dank für Ihre Nachricht.</p>
<p class="mt-2">Um unser Gespräch persönlicher zu gestalten, könnten Sie mir bitte mitteilen, wie ich Sie ansprechen soll?</p>
<p class="mt-2">Zum Beispiel: "Ich bin Anna" oder "Nennen Sie mich Max".</p>
`,
meta: {
followUpQuestion: "Wie soll ich Sie nennen?",
updateStage: 'initial'
}
};
}
}
// Just got the name - acknowledge and ask about issue
if (userProfile.name && userProfile.conversationStage === 'initial') {
userProfile.conversationStage = 'name_established';
return {
text: `
<p>Vielen Dank, ${userProfile.name}. Schön, Sie kennenzulernen.</p>
<p class="mt-2">Was führt Sie heute zu mir? Was beschäftigt Sie im Moment am meisten?</p>
`,
meta: {
personalizedGreeting: `Hallo ${userProfile.name},`,
followUpQuestion: "Würden Sie mir etwas mehr darüber erzählen, was Sie bewegt?",
updateStage: 'name_established'
}
};
}
// Stage 2: Issue sharing
if (userProfile.conversationStage === 'name_established') {
userProfile.conversationStage = 'issue_shared';
// Check for greetings
if (lowerMessage.match(/^(hi|hallo|guten (tag|morgen|abend)|moin|servus|hey|grü(ß|ss)e?)/i)) {
return {
text: `
<p>${userProfile.name}, ich freue mich, unser Gespräch fortzusetzen.</p>
<p class="mt-2">Bei unserem letzten Austausch haben Sie über ${userProfile.lastTopics.length > 0 ? 'Themen wie ' + userProfile.lastTopics.join(', ') : 'verschiedene Themen'} gesprochen.</p>
<p class="mt-2">Wie geht es Ihnen damit heute?</p>
`,
meta: {
personalizedGreeting: `Willkommen zurück, ${userProfile.name}`,
followUpQuestion: "Möchten Sie an unser letztes Gespräch anknüpfen oder etwas Neues besprechen?",
isFollowUp: true
}
};
}
// Generate personalized issue response
return generateIssueResponse(message);
}
// Stage 3: Deep dive into issue
if (userProfile.conversationStage === 'issue_shared') {
return generateDeepDiveResponse(message);
}
// Stage 4: Ongoing conversation - more sophisticated handling
return generateOngoingResponse(message);
}
// Generate response when user shares their issue
function generateIssueResponse(message) {
let responseText = '';
let followUpQuestion = '';
let analysisNote = '';
const threadId = 'thread_' + Date.now();
const threadTopic = userProfile.lastTopics.length > 0 ? userProfile.lastTopics[0] : 'main_topic';
// Emotional state acknowledgment
if (userProfile.emotionalState === 'distressed') {
responseText += `<p>Ich höre heraus, dass Sie sich im Moment in einer emotional belastenden Situation befinden, ${userProfile.name}.</p>`;
followUpQuestion = "Wie gehen Sie normalerweise mit solchen belastenden Gefühlen um?";
} else if (userProfile.emotionalState === 'angry') {
responseText += `<p>Die von Ihnen beschriebene Situation scheint starke Gefühle von Ärger oder Frustration in Ihnen auszulösen, ${userProfile.name}.</p>`;
followUpQuestion = "Was glauben Sie, löst diese intensiven Reaktionen in Ihnen aus?";
} else if (userProfile.emotionalState === 'positive') {
responseText += `<p>Es freut mich zu hören, dass Sie sich in einer positiven Verfassung befinden, ${userProfile.name}.</p>`;
followUpQuestion = "Was trägt Ihrer Meinung nach besonders zu diesem Wohlbefinden bei?";
} else {
responseText += `<p>Danke, dass Sie diese Situation mit mir teilen, ${userProfile.name}.</p>`;
followUpQuestion = "Was denken Sie, könnte hinter diesen Erfahrungen stehen?";
}
// Topic-specific responses with deeper questions
if (message.includes('Freund') || message.includes('Freundin')) {
responseText += `
<p class="mt-2">Freundschaftsdynamiken sind oft Spiegel unserer unbewussten Erwartungen und früheren Beziehungserfahrungen.</p>
<p class="mt-2">Wenn Sie an diese Freundschaft denken, ${userProfile.name}, welche Gefühle oder Erinnerungen werden dabei besonders aktiviert?</p>
`;
followUpQuestion = "Erkennen Sie ähnliche Muster in anderen Freundschaften aus unterschiedlichen Lebensphasen?";
}
else if (message.includes('Partner') || message.includes('Beziehung')) {
responseText += `
<p class="mt-2">Partnerschaften aktivieren häufig tief verwurzelte Bindungsmuster aus unserer Kindheit.</p>
<p class="mt-2">${userProfile.name}, wenn Sie an Ihre frühesten Erinnerungen an Nähe und Distanz denken - welche Parallelen fallen Ihnen auf?</p>
`;
followUpQuestion = "Welche Rolle nehmen Sie Ihrer Erfahrung nach typischerweise in Beziehungskonflikten ein, und woher könnte dieses Muster stammen?";
}
else if (message.includes('Familie') || message.includes('Eltern')) {
responseText += `
<p class="mt-2">Familiensysteme prägen uns oft stärker, als uns bewusst ist.</p>
<p class="mt-2">${userProfile.name}, wenn Sie an Ihre Kindheitsfamilie zurückdenken - welche ungeschriebenen Regeln oder Erwartungen gab es dort?</p>
`;
followUpQuestion = "Wie haben sich diese familiären Muster in Ihrem Erwachsenenleben fortgesetzt oder verändert?";
}
else if (message.includes('Arbeit') || message.includes('Job')) {
responseText += `
<p class="mt-2">Unsere berufliche Identität ist oft eng mit unserem Selbstwertgefühl verbunden.</p>
<p class="mt-2">${userProfile.name}, welche frühen Erfahrungen mit Leistung und Bewertung sind Ihnen besonders im Gedächtnis geblieben?</p>
`;
followUpQuestion = "Wie würden Sie beschreiben, welchen Platz Arbeit in Ihrem Leben einnehmen sollte, im Vergleich zu dem, welchen sie tatsächlich einnimmt?";
}
else {
responseText += `
<p class="mt-2">Interessant, ${userProfile.name}. Lassen Sie uns gemeinsam erkunden, was diese Erfahrung für Sie bedeutet.</p>
<p class="mt-2">Wenn Sie an die letzte ähnliche Situation denken - was fällt Ihnen dazu besonders ein?</p>
`;
followUpQuestion = "Wann haben Sie dieses Gefühl oder Muster zum ersten Mal bewusst wahrgenommen, und in welchem Lebenskontext?";
}
return {
text: responseText,
meta: {
personalizedGreeting: `Danke für Ihre Offenheit, ${userProfile.name}`,
followUpQuestion: followUpQuestion,
updateStage: 'issue_shared',
threadId: threadId,
threadTopic: threadTopic,
increaseDepth: true
}
};
}
// Generate deep dive response with contextual awareness
function generateDeepDiveResponse(message) {
const currentDepth = userProfile.conversationDepth;
let followUpQuestion = '';
let memoryReference = '';
let threadReference = '';
// Reference previous topics if available
if (userProfile.lastTopics.length > 0) {
threadReference = `Unser Gespräch über ${userProfile.lastTopics[0]} finde ich besonders aufschlussreich. `;
}
// Reference key memories if available
if (userProfile.keyMemories.length > 0) {
const randomMemory = userProfile.keyMemories[Math.floor(Math.random() * userProfile.keyMemories.length)];
memoryReference = `Ihre Erwähnung von ${randomMemory} scheint mir hier relevant. `;
}
// Questions get progressively deeper
const depthLevels = [
// Level 1-2: Surface exploration
[
`Was macht diese Situation für Sie besonders herausfordernd, ${userProfile.name}?`,
`Wie würden Sie beschreiben, was Sie in diesen Momenten am meisten brauchen, ${userProfile.name}?`
],
// Level 3-4: Pattern recognition
[
`${userProfile.name}, erkennen Sie ähnliche Muster in anderen Lebensbereichen?`,
`Wenn Sie an vergangene ähnliche Situationen denken, ${userProfile.name}, was fällt Ihnen an Gemeinsamkeiten auf?`
],
// Level 5-6: Emotional roots
[
`${memoryReference}${userProfile.name}, welche frühen Erfahrungen könnten mit diesen Gefühlen verbunden sein?`,
`Wenn Sie an Ihre Kindheit denken, ${userProfile.name}, welche ähnlichen emotionalen Erfahrungen fallen Ihnen ein?`
],
// Level 7-8: Meaning and integration
[
`${threadReference}${userProfile.name}, was könnte diese Erfahrung Ihnen über tieferliegende Bedürfnisse oder Ängste mitteilen?`,
`Wie könnte ein konstruktiver Umgang mit diesen Erkenntnissen aussehen, ${userProfile.name}?`
],
// Level 9+: Transformative questions
[
`${userProfile.name}, wenn Sie diese Muster aus einer neuen Perspektive betrachten - was sehen Sie dann?`,
`Welche neuen Möglichkeiten eröffnen sich Ihnen, wenn Sie diese Erkenntnisse integrieren, ${userProfile.name}?`
]
];
// Select question based on depth level
const depthIndex = Math.min(Math.floor(currentDepth / 2), depthLevels.length - 1);
const questionsForDepth = depthLevels[depthIndex];
followUpQuestion = questionsForDepth[Math.floor(Math.random() * questionsForDepth.length)];
// Adjust for resistance level
if (userProfile.resistanceLevel > 3) {
followUpQuestion = `${userProfile.name}, ich spüre etwas Zurückhaltung - möchten Sie zu einem anderen Aspekt wechseln, oder sollen wir behutsam weitergehen?`;
}
return {
text: `
<p>Danke, dass Sie diese Perspektive teilen, ${userProfile.name}.</p>
<p class="mt-2">Das hilft mir, die Situation besser zu verstehen.</p>
${memoryReference ? `<p class="mt-2">${memoryReference}</p>` : ''}
`,
meta: {
followUpQuestion: followUpQuestion,
isFollowUp: true,
increaseDepth: true,
referencingMemory: !!memoryReference
}
};
}
// Generate ongoing conversation response with thread awareness
function generateOngoingResponse(message) {
// Check if we should switch to a deeper thread
const activeThreads = Object.entries(conversationThreads)
.sort((a, b) => b[1].lastActive - a[1].lastActive);
let followUpQuestion = '';
let threadSwitch = '';
let memoryReference = '';
// 30% chance to reference an older thread if not recently active
if (activeThreads.length > 1 && Math.random() < 0.3) {
const inactiveThread = activeThreads.find(([id, thread]) =>
thread.lastActive < new Date(Date.now() - 60000 * 5)); // Not active for 5 mins
if (inactiveThread) {
threadSwitch = `Vorhin sprachen wir über ${inactiveThread[1].topic}. `;
followUpQuestion = `Möchten wir dazu zurückkehren, ${userProfile.name}, oder beim aktuellen Thema bleiben?`;
return {
text: `
<p>${threadSwitch}Das scheint mir mit unserem jetzigen Gespräch verbunden zu sein.</p>
`,
meta: {
followUpQuestion: followUpQuestion,
isFollowUp: true,
threadId: inactiveThread[0]
}
};
}
}
// Reference key memories if available
if (userProfile.keyMemories.length > 0 && Math.random() < 0.4) {
const randomMemory = userProfile.keyMemories[Math.floor(Math.random() * userProfile.keyMemories.length)];
memoryReference = `Ihre frühere Erwähnung von ${randomMemory} fällt mir hier wieder ein. `;
}
// Progressive deepening questions
const deepQuestions = [
`${userProfile.name}, wenn Sie diese Situation aus einer anderen Perspektive betrachten - was sehen Sie dann?`,
`Welche unbewussten Anteile könnten hier mitwirken, ${userProfile.name}?`,
`Wenn Sie einen inneren Dialog zu diesem Thema führen würden, ${userProfile.name}, welche Stimmen würden sich melden?`,
`${memoryReference}${userProfile.name}, welche früheren Erfahrungen könnten diese Reaktionen beeinflussen?`,
`Wie könnte ein konstruktiver nächster Schritt aussehen, ${userProfile.name}?`
];
followUpQuestion = deepQuestions[Math.floor(Math.random() * deepQuestions.length)];
return {
text: `
<p>${memoryReference}Das ist eine wichtige Beobachtung, ${userProfile.name}.</p>
<p class="mt-2">Lassen Sie uns das gemeinsam vertiefen.</p>
`,
meta: {
followUpQuestion: followUpQuestion,
isFollowUp: true,
increaseDepth: true,
referencingMemory: !!memoryReference
}
};
}
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Frajosgro/https-huggingface-co-spaces-frajosgro-franz" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>