/* AI Tutor — a real working homework helper powered by claude.complete. Kid-friendly: explains and guides rather than just handing over answers. */ const JL_TUTOR_PRIMER = [ { role:'user', content: "You are JewelLink's friendly AI homework tutor for EJ, a 6th-grade student (about 11 years old). " + "Rules: Be warm, encouraging and patient. Explain concepts simply with everyday examples. " + "Guide the student toward the answer with hints and small steps instead of just giving the final answer outright; " + "for factual questions you may answer directly but still explain why. Keep replies short — 2 to 4 short sentences or a few bullet points. " + "Use plain language a middle-schooler understands. Write in plain text only — do not use markdown, asterisks, or bold formatting. " + "If asked something inappropriate or unrelated to schoolwork, gently steer back to learning. " + "Acknowledge you understand and then wait for the first question." }, { role:'assistant', content:"Got it! I'm EJ's homework buddy. I'll keep things friendly and simple, and help EJ figure things out step by step. What are we working on today?" }, ]; const JL_TUTOR_SUGGESTIONS = [ "Explain fractions simply", "Help me start my book report", "Why is the sky blue?", "Quiz me on multiplication", ]; function TutorScreen({ onBack }) { const [msgs, setMsgs] = React.useState([ { role:'assistant', content:"Hi EJ! I'm your AI tutor. Ask me anything about your homework — math, science, reading, you name it. I'll help you understand it, not just give answers." }, ]); const [input, setInput] = React.useState(''); const [busy, setBusy] = React.useState(false); const scrollRef = React.useRef(null); React.useEffect(() => { const el = scrollRef.current; if (el) el.scrollTop = el.scrollHeight; }, [msgs, busy]); const send = async (text) => { const q = (text != null ? text : input).trim(); if (!q || busy) return; setInput(''); const next = [...msgs, { role:'user', content:q }]; setMsgs(next); setBusy(true); try { if (!(window.claude && window.claude.complete)) throw new Error('offline'); const convo = JL_TUTOR_PRIMER.concat(next.map(m => ({ role:m.role, content:m.content }))); const reply = await window.claude.complete({ messages: convo }); setMsgs(m => [...m, { role:'assistant', content: (reply || '').trim() || "Hmm, I didn't catch that — can you ask again?" }]); } catch (e) { setMsgs(m => [...m, { role:'assistant', content:"I can't reach my tutor service right now — check your connection and try again in a moment.", err:true }]); } finally { setBusy(false); } }; return (