diff --git a/html/kidsai/script-new.js b/html/kidsai/script-new.js index df3583d..0b3f58a 100644 --- a/html/kidsai/script-new.js +++ b/html/kidsai/script-new.js @@ -415,21 +415,48 @@ class KidsAIExplorer { ? this.currentSteps[stepIndex].text : 'the current question'; - console.log('📤 Sending request to /api/respond-to-answer:', { answer, currentQuestion }); + // Analyze the answer to determine the appropriate response type + const answerLower = answer.toLowerCase().trim(); + const isNegative = answerLower === 'no' || answerLower === 'nein' || answerLower === 'nope' || answerLower === 'nei'; + const isDontKnow = answerLower.includes("don't know") || answerLower.includes('weiß nicht') || answerLower.includes('keine ahnung') || answer.trim().length < 3; - // Call server API for contextual response - const response = await fetch('/api/respond-to-answer', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - answer: answer, - question: currentQuestion, - language: this.currentLanguage, - stepIndex: stepIndex - }) - }); + let response; + + if (isNegative || isDontKnow) { + // For "no" or "don't know" answers, get Socratic guidance questions + console.log('📤 Sending guidance request to /api/ask for Socratic questioning'); + + const guidancePrompt = this.currentLanguage === 'de' + ? `Ein Kind hat "${answer}" geantwortet auf die Frage "${currentQuestion}". Führe es durch Socratic Fragen zur Entdeckung, ohne direkte Antworten zu geben.` + : `A child answered "${answer}" to the question "${currentQuestion}". Guide them through Socratic questions to discovery without giving direct answers.`; + + response = await fetch('/api/ask', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + question: guidancePrompt, + language: this.currentLanguage + }) + }); + } else { + // For substantial answers, acknowledge and validate + console.log('📤 Sending validation request to /api/respond-to-answer'); + + response = await fetch('/api/respond-to-answer', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + answer: answer, + question: currentQuestion, + language: this.currentLanguage, + stepIndex: stepIndex + }) + }); + } console.log('📥 Server response status:', response.status); @@ -440,7 +467,25 @@ class KidsAIExplorer { const data = await response.json(); console.log('✅ Server response data:', data); - if (data.success && data.response) { + let responseContent = ''; + + if (data.success) { + if (data.guidance && data.guidance.steps) { + // Response from /api/ask with Socratic guidance steps + const steps = data.guidance.steps.slice(0, 3); // Limit to 3 steps + responseContent = steps.map((step, index) => + `
${index + 1}. ${step.text}
` + ).join(''); + } else if (data.response) { + // Simple response from /api/respond-to-answer + responseContent = `${data.response}
`; + } else { + // Fallback + responseContent = this.currentLanguage === 'de' + ? '🤔 Das ist eine interessante Frage! Lass uns zusammen darüber nachdenken...
' + : '🤔 That\'s an interesting question! Let\'s think about it together...
'; + } + responseDiv.innerHTML = `${index + 1}. ${step.text}
` + ).join(''); + } else if (data.response) { + // Simple response from /api/respond-to-answer + responseContent = `${data.response}
`; + } else { + // Fallback + responseContent = this.currentLanguage === 'de' + ? '🤔 Das ist eine interessante Frage! Lass uns zusammen darüber nachdenken...
' + : '🤔 That\'s an interesting question! Let\'s think about it together...
'; + } + // Add AI response bubble const responseBubble = document.createElement('div'); responseBubble.className = 'chat-message ai-message'; @@ -549,7 +635,7 @@ class KidsAIExplorer { ${this.getTranslation('ai-teacher')} `;