diff --git a/html/kidsai/script-new.js b/html/kidsai/script-new.js index 5440f5c..a7ad501 100644 --- a/html/kidsai/script-new.js +++ b/html/kidsai/script-new.js @@ -657,6 +657,19 @@ 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 + const conversationHistory = Array.from(this.conversationContainer.querySelectorAll('.user-message .message-content p')) + .map(p => p.textContent.toLowerCase().trim()) + .slice(-3); // Last 3 user responses + + const recentDontKnowCount = conversationHistory.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') + ).length; + + // If child has said "don't know" multiple times recently, they need help + const needsExplanationDueToRepeatedDontKnow = recentDontKnowCount >= 2; + // Check if child is asking for a definition or explanation const isAskingForDefinition = answerLower.startsWith('was ist') || answerLower.startsWith('what is') || answerLower.includes('was bedeutet') || answerLower.includes('what does') || @@ -670,9 +683,11 @@ class KidsAIExplorer { let response; - if (isExpressingConfusion || isAskingForHelp) { - // Child is expressing confusion or asking for help - provide a simple explanation - console.log('đŸ“€ Sending explanation request for confused child or help request'); + if (isExpressingConfusion || isAskingForHelp || needsExplanationDueToRepeatedDontKnow) { + // Child is expressing confusion, asking for help, or repeatedly saying "don't know" - provide explanation + console.log('đŸ“€ Sending explanation request for confused child, help request, or repeated dont know'); + + const contextReason = needsExplanationDueToRepeatedDontKnow ? 'repeated_dont_know' : 'confusion_explanation'; response = await fetch('/api/respond-to-answer', { method: 'POST', @@ -684,11 +699,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: needsExplanationDueToRepeatedDontKnow + ? (this.currentLanguage === 'de' + ? 'Das Kind braucht jetzt eine einfache, klare ErklĂ€rung. Es hat bereits mehrmals "weiß nicht" gesagt oder ist verwirrt. 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 or are confused. 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 Worte und lade zum Experimentieren ein. Keine weiteren Fragen - 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 (isAskingForDefinition) {