Spaces:
Running
Running
feat: Update Quiz App with Passkey and add read_file tool
Browse files- app/components/QuizApp.tsx +159 -98
- mcp-server.js +81 -1
app/components/QuizApp.tsx
CHANGED
|
@@ -10,14 +10,20 @@ import {
|
|
| 10 |
Brain,
|
| 11 |
Spinner,
|
| 12 |
Trophy,
|
| 13 |
-
ArrowClockwise
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
} from '@phosphor-icons/react'
|
| 15 |
import Window from './Window'
|
| 16 |
|
| 17 |
interface QuizQuestion {
|
| 18 |
-
id: number
|
| 19 |
question: string
|
| 20 |
options: string[]
|
|
|
|
|
|
|
| 21 |
}
|
| 22 |
|
| 23 |
interface QuizAppProps {
|
|
@@ -27,22 +33,45 @@ interface QuizAppProps {
|
|
| 27 |
}
|
| 28 |
|
| 29 |
export function QuizApp({ onClose, onMinimize, zIndex }: QuizAppProps) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
const [questions, setQuestions] = useState<QuizQuestion[]>([])
|
| 31 |
-
const [loading, setLoading] = useState(
|
| 32 |
const [error, setError] = useState<string | null>(null)
|
| 33 |
const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0)
|
| 34 |
-
const [answers, setAnswers] = useState<Record<
|
| 35 |
const [completed, setCompleted] = useState(false)
|
| 36 |
const [saving, setSaving] = useState(false)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
setLoading(true)
|
| 40 |
setError(null)
|
| 41 |
try {
|
| 42 |
-
//
|
| 43 |
-
const response = await fetch(
|
| 44 |
const data = await response.json()
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
const quizFile = data.files?.find((f: any) => f.name === 'quiz.json')
|
| 47 |
|
| 48 |
if (!quizFile) {
|
|
@@ -51,26 +80,23 @@ export function QuizApp({ onClose, onMinimize, zIndex }: QuizAppProps) {
|
|
| 51 |
return
|
| 52 |
}
|
| 53 |
|
| 54 |
-
//
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
// Let's assume for this demo that Claude writes to 'public/quiz.json' and it's available at root.
|
| 70 |
-
throw new Error('Could not load quiz.json')
|
| 71 |
}
|
| 72 |
|
| 73 |
-
const quizData = await quizResponse.json()
|
| 74 |
if (Array.isArray(quizData)) {
|
| 75 |
setQuestions(quizData)
|
| 76 |
} else if (quizData.questions) {
|
|
@@ -78,27 +104,19 @@ export function QuizApp({ onClose, onMinimize, zIndex }: QuizAppProps) {
|
|
| 78 |
} else {
|
| 79 |
throw new Error('Invalid quiz format')
|
| 80 |
}
|
| 81 |
-
} catch (err) {
|
| 82 |
console.error('Error loading quiz:', err)
|
| 83 |
-
|
| 84 |
-
// setError('Could not load quiz.json. Please ask Claude to generate one.')
|
| 85 |
-
|
| 86 |
-
// For testing/demo, let's provide a mock if fetch fails, or just show the error.
|
| 87 |
-
// The user specifically wants the flow with Claude, so showing the error is better to prompt the user.
|
| 88 |
-
setError('Waiting for Claude to generate a quiz... (File public/quiz.json not found)')
|
| 89 |
} finally {
|
| 90 |
setLoading(false)
|
| 91 |
}
|
| 92 |
}
|
| 93 |
|
| 94 |
-
useEffect(() => {
|
| 95 |
-
loadQuiz()
|
| 96 |
-
}, [])
|
| 97 |
-
|
| 98 |
const handleOptionSelect = (option: string) => {
|
|
|
|
| 99 |
setAnswers(prev => ({
|
| 100 |
...prev,
|
| 101 |
-
[
|
| 102 |
}))
|
| 103 |
}
|
| 104 |
|
|
@@ -119,38 +137,54 @@ export function QuizApp({ onClose, onMinimize, zIndex }: QuizAppProps) {
|
|
| 119 |
const finishQuiz = async () => {
|
| 120 |
setSaving(true)
|
| 121 |
try {
|
| 122 |
-
// Save answers to
|
| 123 |
-
// We use the upload API to save the file
|
| 124 |
const answersJson = JSON.stringify(
|
| 125 |
Object.entries(answers).map(([id, answer]) => ({
|
| 126 |
-
questionId:
|
| 127 |
answer
|
| 128 |
})),
|
| 129 |
null,
|
| 130 |
2
|
| 131 |
)
|
| 132 |
|
| 133 |
-
|
| 134 |
-
const file = new File([blob], 'quiz_answers.json', { type: 'application/json' })
|
| 135 |
-
|
| 136 |
-
const formData = new FormData()
|
| 137 |
-
formData.append('file', file)
|
| 138 |
-
formData.append('folder', '') // Root of public
|
| 139 |
-
|
| 140 |
-
await fetch('/api/public', {
|
| 141 |
method: 'POST',
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
})
|
| 144 |
|
| 145 |
setCompleted(true)
|
| 146 |
} catch (err) {
|
| 147 |
console.error('Error saving answers:', err)
|
| 148 |
-
alert('Failed to save answers
|
|
|
|
| 149 |
} finally {
|
| 150 |
setSaving(false)
|
| 151 |
}
|
| 152 |
}
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
return (
|
| 155 |
<Window
|
| 156 |
id="quiz-app"
|
|
@@ -161,10 +195,10 @@ export function QuizApp({ onClose, onMinimize, zIndex }: QuizAppProps) {
|
|
| 161 |
zIndex={zIndex}
|
| 162 |
width={800}
|
| 163 |
height={600}
|
| 164 |
-
className="bg-[#F5F5F7] font-
|
| 165 |
>
|
| 166 |
<div className="h-full flex flex-col">
|
| 167 |
-
{/*
|
| 168 |
<div className="bg-[#F5F5F7]/80 backdrop-blur-xl border-b border-[#000000]/10 p-4 flex items-center justify-between sticky top-0 z-10">
|
| 169 |
<div className="flex items-center gap-3">
|
| 170 |
<div className="w-10 h-10 bg-gradient-to-br from-teal-400 to-emerald-500 rounded-lg shadow-sm flex items-center justify-center border border-white/10">
|
|
@@ -176,7 +210,7 @@ export function QuizApp({ onClose, onMinimize, zIndex }: QuizAppProps) {
|
|
| 176 |
</div>
|
| 177 |
</div>
|
| 178 |
|
| 179 |
-
{!loading && !error && !completed && (
|
| 180 |
<div className="flex items-center gap-2 bg-white/50 px-3 py-1 rounded-md border border-black/5">
|
| 181 |
<span className="text-xs font-medium text-gray-500">Question {currentQuestionIndex + 1} of {questions.length}</span>
|
| 182 |
</div>
|
|
@@ -184,35 +218,54 @@ export function QuizApp({ onClose, onMinimize, zIndex }: QuizAppProps) {
|
|
| 184 |
</div>
|
| 185 |
|
| 186 |
{/* Content */}
|
| 187 |
-
<div className="flex-1 p-8 overflow-y-auto flex flex-col items-center">
|
| 188 |
-
{
|
| 189 |
-
<div className="flex flex-col items-center
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
<Spinner size={32} className="animate-spin text-gray-400" />
|
| 191 |
<p className="text-sm font-medium">Loading quiz...</p>
|
| 192 |
</div>
|
| 193 |
) : error ? (
|
| 194 |
<div className="flex flex-col items-center justify-center h-full max-w-md text-center">
|
| 195 |
-
<div className="w-16 h-16 bg-
|
| 196 |
-
<
|
| 197 |
</div>
|
| 198 |
-
<h3 className="text-lg font-semibold text-gray-900 mb-2">
|
| 199 |
<p className="text-sm text-gray-500 mb-6 leading-relaxed">{error}</p>
|
| 200 |
-
|
| 201 |
-
<div className="bg-white p-4 rounded-xl border border-gray-200 shadow-sm w-full text-left mb-6">
|
| 202 |
-
<p className="text-xs font-semibold text-gray-500 uppercase tracking-wider mb-3">How to start</p>
|
| 203 |
-
<ol className="text-sm text-gray-600 space-y-2 list-decimal pl-4">
|
| 204 |
-
<li>Open <span className="font-semibold text-gray-900">Claude Desktop</span></li>
|
| 205 |
-
<li>Ask: "Create a quiz about [Topic]"</li>
|
| 206 |
-
<li>Wait for the file to be generated</li>
|
| 207 |
-
</ol>
|
| 208 |
-
</div>
|
| 209 |
-
|
| 210 |
<button
|
| 211 |
-
onClick={
|
| 212 |
-
className="px-4 py-2 bg-white border border-gray-300 rounded-lg shadow-sm text-sm font-medium text-gray-700 hover:bg-gray-50
|
| 213 |
>
|
| 214 |
-
|
| 215 |
-
Check Again
|
| 216 |
</button>
|
| 217 |
</div>
|
| 218 |
) : completed ? (
|
|
@@ -220,27 +273,34 @@ export function QuizApp({ onClose, onMinimize, zIndex }: QuizAppProps) {
|
|
| 220 |
<div className="w-20 h-20 bg-gradient-to-br from-green-400 to-emerald-500 rounded-full flex items-center justify-center mb-6 shadow-lg shadow-green-500/20">
|
| 221 |
<Trophy size={40} weight="fill" className="text-white" />
|
| 222 |
</div>
|
| 223 |
-
<h2 className="text-2xl font-bold text-gray-900 mb-2">Quiz Completed
|
| 224 |
-
<p className="text-gray-500 mb-8">
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
</div>
|
| 232 |
-
|
| 233 |
-
<button
|
| 234 |
-
onClick={onClose}
|
| 235 |
-
className="px-6 py-2 bg-[#007AFF] text-white rounded-lg shadow-sm hover:bg-[#0062CC] active:bg-[#0051A8] transition-colors text-sm font-medium"
|
| 236 |
-
>
|
| 237 |
-
Done
|
| 238 |
-
</button>
|
| 239 |
</div>
|
| 240 |
) : questions.length > 0 ? (
|
| 241 |
<div className="w-full max-w-2xl flex flex-col h-full justify-center">
|
| 242 |
{/* Question Card */}
|
| 243 |
-
<div className="bg-white rounded-xl shadow-
|
| 244 |
<div className="p-8 border-b border-gray-100">
|
| 245 |
<h3 className="text-xl font-semibold text-gray-900 leading-relaxed">
|
| 246 |
{questions[currentQuestionIndex].question}
|
|
@@ -249,14 +309,15 @@ export function QuizApp({ onClose, onMinimize, zIndex }: QuizAppProps) {
|
|
| 249 |
|
| 250 |
<div className="p-4 bg-gray-50/50 space-y-2">
|
| 251 |
{questions[currentQuestionIndex].options.map((option, idx) => {
|
| 252 |
-
const
|
|
|
|
| 253 |
return (
|
| 254 |
<button
|
| 255 |
key={idx}
|
| 256 |
onClick={() => handleOptionSelect(option)}
|
| 257 |
className={`w-full text-left px-4 py-3.5 rounded-lg border transition-all duration-200 flex items-center gap-3 text-[15px] ${isSelected
|
| 258 |
-
|
| 259 |
-
|
| 260 |
}`}
|
| 261 |
>
|
| 262 |
<div className={`w-5 h-5 rounded-full border flex items-center justify-center flex-shrink-0 ${isSelected ? 'border-white bg-white/20' : 'border-gray-300'
|
|
@@ -283,8 +344,8 @@ export function QuizApp({ onClose, onMinimize, zIndex }: QuizAppProps) {
|
|
| 283 |
onClick={handleNext}
|
| 284 |
disabled={!answers[questions[currentQuestionIndex].id]}
|
| 285 |
className={`flex items-center gap-2 px-5 py-2 rounded-lg text-sm font-medium shadow-sm transition-all ${!answers[questions[currentQuestionIndex].id]
|
| 286 |
-
|
| 287 |
-
|
| 288 |
}`}
|
| 289 |
>
|
| 290 |
{currentQuestionIndex === questions.length - 1 ? 'Finish' : 'Next'}
|
|
@@ -299,10 +360,10 @@ export function QuizApp({ onClose, onMinimize, zIndex }: QuizAppProps) {
|
|
| 299 |
<div
|
| 300 |
key={idx}
|
| 301 |
className={`h-1.5 rounded-full transition-all duration-300 ${idx === currentQuestionIndex
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
}`}
|
| 307 |
/>
|
| 308 |
))}
|
|
|
|
| 10 |
Brain,
|
| 11 |
Spinner,
|
| 12 |
Trophy,
|
| 13 |
+
ArrowClockwise,
|
| 14 |
+
Lock,
|
| 15 |
+
Key,
|
| 16 |
+
Copy,
|
| 17 |
+
ClipboardText
|
| 18 |
} from '@phosphor-icons/react'
|
| 19 |
import Window from './Window'
|
| 20 |
|
| 21 |
interface QuizQuestion {
|
| 22 |
+
id: number | string
|
| 23 |
question: string
|
| 24 |
options: string[]
|
| 25 |
+
correctAnswer?: string | number | boolean
|
| 26 |
+
explanation?: string
|
| 27 |
}
|
| 28 |
|
| 29 |
interface QuizAppProps {
|
|
|
|
| 33 |
}
|
| 34 |
|
| 35 |
export function QuizApp({ onClose, onMinimize, zIndex }: QuizAppProps) {
|
| 36 |
+
const [passkey, setPasskey] = useState('')
|
| 37 |
+
const [tempPasskey, setTempPasskey] = useState('')
|
| 38 |
+
const [isLocked, setIsLocked] = useState(true)
|
| 39 |
+
|
| 40 |
const [questions, setQuestions] = useState<QuizQuestion[]>([])
|
| 41 |
+
const [loading, setLoading] = useState(false)
|
| 42 |
const [error, setError] = useState<string | null>(null)
|
| 43 |
const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0)
|
| 44 |
+
const [answers, setAnswers] = useState<Record<string, string>>({})
|
| 45 |
const [completed, setCompleted] = useState(false)
|
| 46 |
const [saving, setSaving] = useState(false)
|
| 47 |
+
const [copySuccess, setCopySuccess] = useState(false)
|
| 48 |
+
|
| 49 |
+
// Check if quiz has answers embedded (for immediate feedback)
|
| 50 |
+
const hasEmbeddedAnswers = questions.some(q => q.correctAnswer !== undefined)
|
| 51 |
|
| 52 |
+
const handlePasskeySubmit = () => {
|
| 53 |
+
if (tempPasskey.trim().length >= 4) {
|
| 54 |
+
setPasskey(tempPasskey.trim())
|
| 55 |
+
setIsLocked(false)
|
| 56 |
+
loadQuiz(tempPasskey.trim())
|
| 57 |
+
} else {
|
| 58 |
+
alert('Passkey must be at least 4 characters')
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
const loadQuiz = async (key: string) => {
|
| 63 |
setLoading(true)
|
| 64 |
setError(null)
|
| 65 |
try {
|
| 66 |
+
// Fetch from secure data using passkey
|
| 67 |
+
const response = await fetch(`/api/data?key=${encodeURIComponent(key)}&folder=`)
|
| 68 |
const data = await response.json()
|
| 69 |
|
| 70 |
+
if (data.error) {
|
| 71 |
+
throw new Error(data.error)
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
// Look for quiz.json
|
| 75 |
const quizFile = data.files?.find((f: any) => f.name === 'quiz.json')
|
| 76 |
|
| 77 |
if (!quizFile) {
|
|
|
|
| 80 |
return
|
| 81 |
}
|
| 82 |
|
| 83 |
+
// Parse content
|
| 84 |
+
let quizData
|
| 85 |
+
if (typeof quizFile.content === 'string') {
|
| 86 |
+
try {
|
| 87 |
+
quizData = JSON.parse(quizFile.content)
|
| 88 |
+
} catch (e) {
|
| 89 |
+
// Maybe it's double encoded or raw text
|
| 90 |
+
quizData = quizFile.content
|
| 91 |
+
}
|
| 92 |
+
} else {
|
| 93 |
+
quizData = quizFile.content
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
if (!quizData) {
|
| 97 |
+
throw new Error('Quiz file is empty')
|
|
|
|
|
|
|
| 98 |
}
|
| 99 |
|
|
|
|
| 100 |
if (Array.isArray(quizData)) {
|
| 101 |
setQuestions(quizData)
|
| 102 |
} else if (quizData.questions) {
|
|
|
|
| 104 |
} else {
|
| 105 |
throw new Error('Invalid quiz format')
|
| 106 |
}
|
| 107 |
+
} catch (err: any) {
|
| 108 |
console.error('Error loading quiz:', err)
|
| 109 |
+
setError(err.message || 'Could not load quiz.json')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
} finally {
|
| 111 |
setLoading(false)
|
| 112 |
}
|
| 113 |
}
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
const handleOptionSelect = (option: string) => {
|
| 116 |
+
const currentQ = questions[currentQuestionIndex]
|
| 117 |
setAnswers(prev => ({
|
| 118 |
...prev,
|
| 119 |
+
[currentQ.id]: option
|
| 120 |
}))
|
| 121 |
}
|
| 122 |
|
|
|
|
| 137 |
const finishQuiz = async () => {
|
| 138 |
setSaving(true)
|
| 139 |
try {
|
| 140 |
+
// Save answers to secure storage
|
|
|
|
| 141 |
const answersJson = JSON.stringify(
|
| 142 |
Object.entries(answers).map(([id, answer]) => ({
|
| 143 |
+
questionId: id,
|
| 144 |
answer
|
| 145 |
})),
|
| 146 |
null,
|
| 147 |
2
|
| 148 |
)
|
| 149 |
|
| 150 |
+
await fetch('/api/data', {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
method: 'POST',
|
| 152 |
+
headers: { 'Content-Type': 'application/json' },
|
| 153 |
+
body: JSON.stringify({
|
| 154 |
+
passkey,
|
| 155 |
+
action: 'save_file',
|
| 156 |
+
fileName: 'quiz_answers.json',
|
| 157 |
+
content: answersJson
|
| 158 |
+
})
|
| 159 |
})
|
| 160 |
|
| 161 |
setCompleted(true)
|
| 162 |
} catch (err) {
|
| 163 |
console.error('Error saving answers:', err)
|
| 164 |
+
alert('Failed to save answers locally.')
|
| 165 |
+
setCompleted(true) // Still show completion screen
|
| 166 |
} finally {
|
| 167 |
setSaving(false)
|
| 168 |
}
|
| 169 |
}
|
| 170 |
|
| 171 |
+
const handleCopyAnswers = async () => {
|
| 172 |
+
const summary = questions.map((q, idx) => {
|
| 173 |
+
const answer = answers[q.id]
|
| 174 |
+
return `Q${idx + 1}: ${answer}`
|
| 175 |
+
}).join('\n')
|
| 176 |
+
|
| 177 |
+
const textToCopy = `Here are my quiz answers:\n\n${summary}\n\nPlease grade my quiz!`
|
| 178 |
+
|
| 179 |
+
try {
|
| 180 |
+
await navigator.clipboard.writeText(textToCopy)
|
| 181 |
+
setCopySuccess(true)
|
| 182 |
+
setTimeout(() => setCopySuccess(false), 2000)
|
| 183 |
+
} catch (err) {
|
| 184 |
+
console.error('Failed to copy:', err)
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
return (
|
| 189 |
<Window
|
| 190 |
id="quiz-app"
|
|
|
|
| 195 |
zIndex={zIndex}
|
| 196 |
width={800}
|
| 197 |
height={600}
|
| 198 |
+
className="bg-[#F5F5F7] font-sans"
|
| 199 |
>
|
| 200 |
<div className="h-full flex flex-col">
|
| 201 |
+
{/* Header */}
|
| 202 |
<div className="bg-[#F5F5F7]/80 backdrop-blur-xl border-b border-[#000000]/10 p-4 flex items-center justify-between sticky top-0 z-10">
|
| 203 |
<div className="flex items-center gap-3">
|
| 204 |
<div className="w-10 h-10 bg-gradient-to-br from-teal-400 to-emerald-500 rounded-lg shadow-sm flex items-center justify-center border border-white/10">
|
|
|
|
| 210 |
</div>
|
| 211 |
</div>
|
| 212 |
|
| 213 |
+
{!isLocked && !loading && !error && !completed && (
|
| 214 |
<div className="flex items-center gap-2 bg-white/50 px-3 py-1 rounded-md border border-black/5">
|
| 215 |
<span className="text-xs font-medium text-gray-500">Question {currentQuestionIndex + 1} of {questions.length}</span>
|
| 216 |
</div>
|
|
|
|
| 218 |
</div>
|
| 219 |
|
| 220 |
{/* Content */}
|
| 221 |
+
<div className="flex-1 p-8 overflow-y-auto flex flex-col items-center justify-center">
|
| 222 |
+
{isLocked ? (
|
| 223 |
+
<div className="flex flex-col items-center gap-6 max-w-md w-full bg-white p-8 rounded-2xl shadow-sm border border-gray-200">
|
| 224 |
+
<div className="w-16 h-16 bg-blue-50 rounded-full flex items-center justify-center">
|
| 225 |
+
<Lock size={32} weight="duotone" className="text-blue-500" />
|
| 226 |
+
</div>
|
| 227 |
+
<div className="text-center">
|
| 228 |
+
<h2 className="text-xl font-bold text-gray-900 mb-2">Enter Passkey</h2>
|
| 229 |
+
<p className="text-gray-500 text-sm">Enter your passkey to load your secure quiz.</p>
|
| 230 |
+
</div>
|
| 231 |
+
<div className="w-full space-y-4">
|
| 232 |
+
<div className="relative">
|
| 233 |
+
<Key size={20} className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-400" />
|
| 234 |
+
<input
|
| 235 |
+
type="password"
|
| 236 |
+
value={tempPasskey}
|
| 237 |
+
onChange={(e) => setTempPasskey(e.target.value)}
|
| 238 |
+
onKeyPress={(e) => e.key === 'Enter' && handlePasskeySubmit()}
|
| 239 |
+
placeholder="Your Passkey"
|
| 240 |
+
className="w-full pl-10 pr-4 py-3 bg-gray-50 border border-gray-200 rounded-xl focus:outline-none focus:ring-2 focus:ring-blue-500 focus:bg-white transition-all"
|
| 241 |
+
autoFocus
|
| 242 |
+
/>
|
| 243 |
+
</div>
|
| 244 |
+
<button
|
| 245 |
+
onClick={handlePasskeySubmit}
|
| 246 |
+
className="w-full py-3 bg-blue-600 hover:bg-blue-700 text-white rounded-xl font-medium transition-colors shadow-lg shadow-blue-500/20"
|
| 247 |
+
>
|
| 248 |
+
Unlock Quiz
|
| 249 |
+
</button>
|
| 250 |
+
</div>
|
| 251 |
+
</div>
|
| 252 |
+
) : loading ? (
|
| 253 |
+
<div className="flex flex-col items-center gap-4 text-gray-500">
|
| 254 |
<Spinner size={32} className="animate-spin text-gray-400" />
|
| 255 |
<p className="text-sm font-medium">Loading quiz...</p>
|
| 256 |
</div>
|
| 257 |
) : error ? (
|
| 258 |
<div className="flex flex-col items-center justify-center h-full max-w-md text-center">
|
| 259 |
+
<div className="w-16 h-16 bg-red-50 rounded-full flex items-center justify-center mb-4">
|
| 260 |
+
<XCircle size={32} weight="duotone" className="text-red-500" />
|
| 261 |
</div>
|
| 262 |
+
<h3 className="text-lg font-semibold text-gray-900 mb-2">Quiz Load Error</h3>
|
| 263 |
<p className="text-sm text-gray-500 mb-6 leading-relaxed">{error}</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
<button
|
| 265 |
+
onClick={() => setIsLocked(true)}
|
| 266 |
+
className="px-4 py-2 bg-white border border-gray-300 rounded-lg shadow-sm text-sm font-medium text-gray-700 hover:bg-gray-50 transition-colors"
|
| 267 |
>
|
| 268 |
+
Try Different Passkey
|
|
|
|
| 269 |
</button>
|
| 270 |
</div>
|
| 271 |
) : completed ? (
|
|
|
|
| 273 |
<div className="w-20 h-20 bg-gradient-to-br from-green-400 to-emerald-500 rounded-full flex items-center justify-center mb-6 shadow-lg shadow-green-500/20">
|
| 274 |
<Trophy size={40} weight="fill" className="text-white" />
|
| 275 |
</div>
|
| 276 |
+
<h2 className="text-2xl font-bold text-gray-900 mb-2">Quiz Completed!</h2>
|
| 277 |
+
<p className="text-gray-500 mb-8">
|
| 278 |
+
{hasEmbeddedAnswers
|
| 279 |
+
? "You've finished the quiz."
|
| 280 |
+
: "Answers saved. Copy them below to get your grade from Claude."}
|
| 281 |
+
</p>
|
| 282 |
+
|
| 283 |
+
<div className="w-full space-y-3">
|
| 284 |
+
<button
|
| 285 |
+
onClick={handleCopyAnswers}
|
| 286 |
+
className="w-full py-3 bg-blue-600 hover:bg-blue-700 text-white rounded-xl font-medium transition-colors shadow-lg shadow-blue-500/20 flex items-center justify-center gap-2"
|
| 287 |
+
>
|
| 288 |
+
{copySuccess ? <CheckCircle size={20} weight="fill" /> : <Copy size={20} weight="bold" />}
|
| 289 |
+
{copySuccess ? 'Copied to Clipboard!' : 'Copy Answers for Claude'}
|
| 290 |
+
</button>
|
| 291 |
+
|
| 292 |
+
<button
|
| 293 |
+
onClick={onClose}
|
| 294 |
+
className="w-full py-3 bg-white border border-gray-200 text-gray-700 hover:bg-gray-50 rounded-xl font-medium transition-colors"
|
| 295 |
+
>
|
| 296 |
+
Close Quiz
|
| 297 |
+
</button>
|
| 298 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
</div>
|
| 300 |
) : questions.length > 0 ? (
|
| 301 |
<div className="w-full max-w-2xl flex flex-col h-full justify-center">
|
| 302 |
{/* Question Card */}
|
| 303 |
+
<div className="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
|
| 304 |
<div className="p-8 border-b border-gray-100">
|
| 305 |
<h3 className="text-xl font-semibold text-gray-900 leading-relaxed">
|
| 306 |
{questions[currentQuestionIndex].question}
|
|
|
|
| 309 |
|
| 310 |
<div className="p-4 bg-gray-50/50 space-y-2">
|
| 311 |
{questions[currentQuestionIndex].options.map((option, idx) => {
|
| 312 |
+
const currentQId = questions[currentQuestionIndex].id
|
| 313 |
+
const isSelected = answers[currentQId] === option
|
| 314 |
return (
|
| 315 |
<button
|
| 316 |
key={idx}
|
| 317 |
onClick={() => handleOptionSelect(option)}
|
| 318 |
className={`w-full text-left px-4 py-3.5 rounded-lg border transition-all duration-200 flex items-center gap-3 text-[15px] ${isSelected
|
| 319 |
+
? 'bg-blue-600 border-blue-600 text-white shadow-md shadow-blue-500/20'
|
| 320 |
+
: 'bg-white border-gray-200 hover:border-gray-300 hover:bg-gray-50 text-gray-700'
|
| 321 |
}`}
|
| 322 |
>
|
| 323 |
<div className={`w-5 h-5 rounded-full border flex items-center justify-center flex-shrink-0 ${isSelected ? 'border-white bg-white/20' : 'border-gray-300'
|
|
|
|
| 344 |
onClick={handleNext}
|
| 345 |
disabled={!answers[questions[currentQuestionIndex].id]}
|
| 346 |
className={`flex items-center gap-2 px-5 py-2 rounded-lg text-sm font-medium shadow-sm transition-all ${!answers[questions[currentQuestionIndex].id]
|
| 347 |
+
? 'bg-gray-100 text-gray-400 cursor-not-allowed'
|
| 348 |
+
: 'bg-blue-600 text-white hover:bg-blue-700 active:bg-blue-800'
|
| 349 |
}`}
|
| 350 |
>
|
| 351 |
{currentQuestionIndex === questions.length - 1 ? 'Finish' : 'Next'}
|
|
|
|
| 360 |
<div
|
| 361 |
key={idx}
|
| 362 |
className={`h-1.5 rounded-full transition-all duration-300 ${idx === currentQuestionIndex
|
| 363 |
+
? 'w-8 bg-blue-600'
|
| 364 |
+
: idx < currentQuestionIndex
|
| 365 |
+
? 'w-1.5 bg-gray-300'
|
| 366 |
+
: 'w-1.5 bg-gray-200'
|
| 367 |
}`}
|
| 368 |
/>
|
| 369 |
))}
|
mcp-server.js
CHANGED
|
@@ -147,7 +147,7 @@ class ReubenOSMCPServer {
|
|
| 147 |
explanation: { type: 'string' },
|
| 148 |
points: { type: 'number' },
|
| 149 |
},
|
| 150 |
-
required: ['id', 'question', 'type'
|
| 151 |
},
|
| 152 |
},
|
| 153 |
},
|
|
@@ -157,6 +157,28 @@ class ReubenOSMCPServer {
|
|
| 157 |
required: ['quizData'],
|
| 158 |
},
|
| 159 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
],
|
| 161 |
}));
|
| 162 |
|
|
@@ -173,6 +195,8 @@ class ReubenOSMCPServer {
|
|
| 173 |
return await this.deleteFile(args);
|
| 174 |
case 'deploy_quiz':
|
| 175 |
return await this.deployQuiz(args);
|
|
|
|
|
|
|
| 176 |
default:
|
| 177 |
throw new Error(`Unknown tool: ${name}`);
|
| 178 |
}
|
|
@@ -189,6 +213,62 @@ class ReubenOSMCPServer {
|
|
| 189 |
});
|
| 190 |
}
|
| 191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
async saveFile(args) {
|
| 193 |
try {
|
| 194 |
const { fileName, content, passkey, isPublic = false } = args;
|
|
|
|
| 147 |
explanation: { type: 'string' },
|
| 148 |
points: { type: 'number' },
|
| 149 |
},
|
| 150 |
+
required: ['id', 'question', 'type'],
|
| 151 |
},
|
| 152 |
},
|
| 153 |
},
|
|
|
|
| 157 |
required: ['quizData'],
|
| 158 |
},
|
| 159 |
},
|
| 160 |
+
{
|
| 161 |
+
name: 'read_file',
|
| 162 |
+
description: 'Read the content of a file from secure storage or public folder. Useful for evaluating quiz answers.',
|
| 163 |
+
inputSchema: {
|
| 164 |
+
type: 'object',
|
| 165 |
+
properties: {
|
| 166 |
+
fileName: {
|
| 167 |
+
type: 'string',
|
| 168 |
+
description: 'Name of the file to read (e.g., quiz_answers.json)',
|
| 169 |
+
},
|
| 170 |
+
passkey: {
|
| 171 |
+
type: 'string',
|
| 172 |
+
description: 'Your passkey (required for secure files)',
|
| 173 |
+
},
|
| 174 |
+
isPublic: {
|
| 175 |
+
type: 'boolean',
|
| 176 |
+
description: 'Set to true if reading from public folder. Default: false',
|
| 177 |
+
},
|
| 178 |
+
},
|
| 179 |
+
required: ['fileName'],
|
| 180 |
+
},
|
| 181 |
+
},
|
| 182 |
],
|
| 183 |
}));
|
| 184 |
|
|
|
|
| 195 |
return await this.deleteFile(args);
|
| 196 |
case 'deploy_quiz':
|
| 197 |
return await this.deployQuiz(args);
|
| 198 |
+
case 'read_file':
|
| 199 |
+
return await this.readFile(args);
|
| 200 |
default:
|
| 201 |
throw new Error(`Unknown tool: ${name}`);
|
| 202 |
}
|
|
|
|
| 213 |
});
|
| 214 |
}
|
| 215 |
|
| 216 |
+
async readFile(args) {
|
| 217 |
+
try {
|
| 218 |
+
const { fileName, passkey, isPublic = false } = args;
|
| 219 |
+
|
| 220 |
+
if (!fileName) {
|
| 221 |
+
return {
|
| 222 |
+
content: [{ type: 'text', text: 'β fileName is required' }],
|
| 223 |
+
};
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
if (!isPublic && !passkey) {
|
| 227 |
+
return {
|
| 228 |
+
content: [{ type: 'text', text: 'β Passkey is required (or set isPublic=true)' }],
|
| 229 |
+
};
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
const url = new URL(API_ENDPOINT);
|
| 233 |
+
if (passkey) url.searchParams.set('passkey', passkey);
|
| 234 |
+
if (isPublic) url.searchParams.set('isPublic', 'true');
|
| 235 |
+
|
| 236 |
+
const response = await fetch(url, {
|
| 237 |
+
method: 'GET',
|
| 238 |
+
headers: { 'Content-Type': 'application/json' },
|
| 239 |
+
});
|
| 240 |
+
|
| 241 |
+
const data = await response.json();
|
| 242 |
+
|
| 243 |
+
if (response.ok && data.success) {
|
| 244 |
+
const file = data.files.find(f => f.name === fileName);
|
| 245 |
+
|
| 246 |
+
if (!file) {
|
| 247 |
+
return {
|
| 248 |
+
content: [{ type: 'text', text: `β File '${fileName}' not found in ${data.location}` }],
|
| 249 |
+
};
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
return {
|
| 253 |
+
content: [
|
| 254 |
+
{
|
| 255 |
+
type: 'text',
|
| 256 |
+
text: `π Content of ${fileName}:\n\n${file.content || '(Empty file)'}`,
|
| 257 |
+
},
|
| 258 |
+
],
|
| 259 |
+
};
|
| 260 |
+
} else {
|
| 261 |
+
return {
|
| 262 |
+
content: [{ type: 'text', text: `β Failed: ${data.error || 'Unknown error'}` }],
|
| 263 |
+
};
|
| 264 |
+
}
|
| 265 |
+
} catch (error) {
|
| 266 |
+
return {
|
| 267 |
+
content: [{ type: 'text', text: `β Error: ${error.message}` }],
|
| 268 |
+
};
|
| 269 |
+
}
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
async saveFile(args) {
|
| 273 |
try {
|
| 274 |
const { fileName, content, passkey, isPublic = false } = args;
|