import type { CourseView } from '../types'; import React, { useState, useRef, useEffect } from 'react'; import { Send, Loader2 } from 'lucide-react'; import { challengeFollowUp } from '@/lib/provingGround'; import OwliverAvatar from '@/components/krow/OwliverAvatar'; // AI roleplay challenge — scenario prompt, worker responds, KROW follows up, // then the worker submits the transcript for AI evaluation. interface RoleplayChallengeProps { course: CourseView; onSubmit?: (...args: any[]) => void; submitting: boolean; } export default function RoleplayChallenge({ course, onSubmit, submitting }: RoleplayChallengeProps) { const initial = course?.challenge?.prompt || course?.description || 'Demonstrate the skill.'; const [messages, setMessages] = useState([{ role: 'ai', content: initial }]); const [input, setInput] = useState(''); const [busy, setBusy] = useState(false); const scrollRef = useRef(null); useEffect(() => { scrollRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [messages]); const send = async () => { const text = input.trim(); if (!text || busy) return; const next = [...messages, { role: 'user', content: text }]; setMessages(next); setInput(''); setBusy(true); try { const follow = await challengeFollowUp(course, next); setMessages([...next, { role: 'ai', content: follow }]); } catch { setMessages([...next, { role: 'ai', content: 'Thanks. Submit your proof when ready.' }]); } finally { setBusy(false); } }; const transcript = messages.map((m) => `${m.role === 'user' ? 'Worker' : 'Owliver'}: ${m.content}`).join('\n'); const hasResponded = messages.some((m) => m.role === 'user'); return (

Owliver

Your AI skills coach

{messages.map((m, i) => { const isAI = m.role !== 'user'; return (
{isAI && }
{m.content}
); })}
setInput(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && send()} disabled={submitting || busy} placeholder="Type your response…" className="flex-1 h-9 bg-transparent px-1 text-[13px] focus:outline-none placeholder:text-ink-4" />
); }