diff --git a/html/kidsai/script-new.js b/html/kidsai/script-new.js index 984ac80..e47d15f 100644 --- a/html/kidsai/script-new.js +++ b/html/kidsai/script-new.js @@ -458,11 +458,32 @@ class KidsAIExplorer { // Pure "don't know" without additional thinking const isPureDontKnow = (hasDontKnowPhrase || isOnlyWhyQuestion || answer.trim().length < 5) && !hasSubstantialThinking && !isExpressingConfusion && !isAskingForHelp; + // Check conversation history for repeated "don't know" responses (Chat Mode) + const conversationHistoryChat = Array.from(this.conversationContainer.querySelectorAll('.user-message .message-content')) + .map(el => el.textContent.toLowerCase().trim()) + .slice(-4); // Last 4 user responses + + console.log('🔍 Recent conversation history (Chat):', conversationHistoryChat); + + const recentDontKnowCountChat = conversationHistoryChat.filter(msg => + msg.includes('weiß nicht') || msg.includes('weis nicht') || msg.includes('weiss nicht') || + msg.includes("don't know") || msg.includes('i dont know') || msg.includes('keine ahnung') || + msg.includes('das weiß ich nicht') || msg.includes('das weiss ich nicht') || + msg.includes('das weis ich nicht') || msg.includes('weiß ich auch nicht') + ).length; + + console.log(`🔱 Recent "don't know" count (Chat): ${recentDontKnowCountChat}`); + + // If child has said "don't know" 2 or more times recently, they need help + const needsExplanationDueToRepeatedDontKnowChat = recentDontKnowCountChat >= 2; + let response; - if (isExpressingConfusion) { - // Child is expressing confusion - provide a simple explanation - console.log('đŸ“€ Sending explanation request for confused child'); + if (isExpressingConfusion || needsExplanationDueToRepeatedDontKnowChat) { + // Child is expressing confusion or repeatedly saying "don't know" - provide a simple explanation + console.log('đŸ“€ Sending explanation request for confused child or repeated dont know (Chat mode)'); + + const contextReason = needsExplanationDueToRepeatedDontKnowChat ? 'repeated_dont_know' : 'confusion_explanation'; response = await fetch('/api/respond-to-answer', { method: 'POST', @@ -474,11 +495,15 @@ class KidsAIExplorer { question: currentQuestion, originalTopic: originalQuestion, language: this.currentLanguage, - context: 'confusion_explanation', + context: contextReason, stepIndex: questionIndex, - instructions: this.currentLanguage === 'de' - ? 'Das Kind ist verwirrt und braucht eine einfache ErklĂ€rung. Gib eine klare, konkrete Antwort fĂŒr Kinder. ErklĂ€re das Konzept mit alltĂ€glichen Beispielen. Verwende einfache Wörter und lade zum Ausprobieren ein. Keine weiteren Fragen stellen - erst erklĂ€ren!' - : 'The child is confused and needs a simple explanation. Give a clear, concrete answer for children. Explain the concept with everyday examples. Use simple words and invite experimentation. Don\'t ask more questions - explain first!' + instructions: needsExplanationDueToRepeatedDontKnowChat + ? (this.currentLanguage === 'de' + ? 'Das Kind braucht jetzt eine einfache, klare ErklĂ€rung. Es hat bereits mehrmals "weiß nicht" gesagt. Gib eine vollstĂ€ndige Antwort mit praktischen Beispielen. ErklĂ€re das Konzept Schritt fĂŒr Schritt mit alltĂ€glichen Vergleichen. Keine weiteren Fragen - das Kind braucht Wissen!' + : 'The child needs a simple, clear explanation now. They have said "don\'t know" multiple times. Give a complete answer with practical examples. Explain the concept step by step with everyday comparisons. No more questions - the child needs knowledge!') + : (this.currentLanguage === 'de' + ? 'Das Kind ist verwirrt und braucht eine einfache ErklĂ€rung. Gib eine klare, konkrete Antwort fĂŒr Kinder. ErklĂ€re das Konzept mit alltĂ€glichen Beispielen. Verwende einfache Wörter und lade zum Ausprobieren ein. Keine weiteren Fragen stellen - erst erklĂ€ren!' + : 'The child is confused and needs a simple explanation. Give a clear, concrete answer for children. Explain the concept with everyday examples. Use simple words and invite experimentation. Don\'t ask more questions - explain first!') }) }); } else if (isNegative || isPureDontKnow) { diff --git a/html/kidsai/server.js b/html/kidsai/server.js index e919348..b263884 100755 --- a/html/kidsai/server.js +++ b/html/kidsai/server.js @@ -716,7 +716,8 @@ The child is asking for a definition, explanation, or clarification about locati console.log(`🔍 Answer analysis - isDontKnow: ${isDontKnowResponse}, answer: "${answer}"`); // If this is a "don't know" response and we're in a loop, provide explanation - if (isDontKnowResponse && (context === 'repeated_dont_know' || instructions.includes('mehrmals') || instructions.includes('multiple times'))) { + if (isDontKnowResponse && (context === 'repeated_dont_know' || + (instructions && (instructions.includes('mehrmals') || instructions.includes('multiple times'))))) { console.log('🎯 Detected repeated "don\'t know" - providing explanation instead of more questions'); const explanationPrompt = isGerman ?