Flashcards & Quizzes
Relevant source files
The following files were used as context for generating this wiki page:
Flashcards and Quizzes represent the core interactive learning modules within the ThinkEx workspace. These features allow users to transform static information into persistent, structured knowledge through AI-driven content generation and interactive UI components. Flashcards provide a traditional two-sided review system, while Quizzes offer structured assessments including multiple-choice and true/false formats with immediate feedback and session tracking.
Sources: README.md, src/lib/ai/tools/quiz-tools.ts:1-10, src/lib/ai/tools/flashcard-tools.ts:1-7
Interactive Quizzes
The Quiz system enables the creation of assessment items with various question types and session state persistence. Quizzes are stored as items within a workspace, containing arrays of questions and optional session data to track user progress.
Quiz Architecture and Data Flow
Quizzes are generated via AI tools or the autogen route and rendered through the QuizContent component. The system supports real-time updates where the AI can append new questions to an existing quiz deck.
The diagram shows the flow when a user or AI appends questions to an existing quiz deck.
Sources: src/lib/ai/workers/workspace-worker.ts:517-576, src/components/workspace-canvas/QuizContent.tsx:132-154
Data Models and Validation
Quizzes rely on a strict schema to ensure compatibility between AI generation and UI rendering.
| Field | Type | Description |
|---|---|---|
type | multiple_choice | true_false | The format of the question. |
questionText | string | The actual text of the question (supports Markdown). |
options | string[] | 4 strings for MC, 2 (['True', 'False']) for T/F. |
correctIndex | number | 0-based index of the correct answer in the options array. |
hint | string (optional) | Optional text to assist the user. |
explanation | string | Reasoning for the correct answer. |
Sources: src/lib/ai/tools/quiz-tools.ts:18-32, src/lib/ai/workers/workspace-worker.ts:795-817
Quiz Session Management
The QuizContent component manages the local and persisted state of a quiz attempt. Session data includes the current question index, the list of answered questions (with correctness), and completion timestamps.
- State Persistence: The session is persisted to the workspace state via
onUpdateData, ensuring progress is saved across reloads. - Result Calculation: Upon completion, the UI calculates a percentage score and displays a summary with the option to restart or request more questions from the AI.
Sources: src/components/workspace-canvas/QuizContent.tsx:28-60, src/components/workspace-canvas/QuizContent.tsx:112-127
Flashcard Decks
Flashcards allow for bipartite information storage (Front/Back) and are optimized for quick reviews.
Generation and API
Flashcards can be created through a dedicated API endpoint (/api/flashcards/create) or via AI tool calls. The AI identifies relevant terms and definitions from workspace context to populate the deck.
The flow describes the lifecycle of a flashcard deck from initial AI tool execution to database persistence.
Sources: src/lib/ai/tools/flashcard-tools.ts:12-61, src/app/api/flashcards/create/route.ts:21-48
Components and Display
The FlashcardContent and WorkspaceCardContent components handle the rendering of decks.
- Preview Mode: Individual cards are rendered using
react-quizlet-flashcard, supporting markdown content on both sides. - Full View: Displays a scrollable list of all cards in the deck, indexed by number.
Sources: src/components/workspace-canvas/WorkspaceCardContent.tsx:162-215, src/components/workspace-canvas/FlashcardContent.tsx:47-83
AI Integration and Tools
The system uses specialized tools that allow the AI to interact with these learning modules.
| Tool Name | Purpose | Key Parameters |
|---|---|---|
createQuiz | Generates a new quiz item | title, questions[] (Max 50) |
createFlashcards | Generates a new flashcard deck | title, cards[] (Front/Back) |
editItem | Modifies existing quiz/flashcard content | itemId, oldString, newString, replaceAll |
Sources: src/lib/ai/tools/quiz-tools.ts:34-40, src/lib/ai/tools/flashcard-tools.ts:9-19, src/lib/ai/workers/workspace-worker.ts:713-731
AI Tool Sanitization
To prevent leaking internal implementation details (like database IDs or raw event logs) back to the LLM, ThinkEx employs a sanitization wrapper. This ensures the AI only sees the functional outcome of its tool call, such as success messages or the number of cards added.
// Example of field stripping for model output
const result = toModelOutput({
output: {
success: true,
itemId: "abc-123", // Stripped
event: { ... }, // Stripped
message: "Created quiz successfully" // Preserved
}
});
Sources: src/lib/ai/tools/tests/tool-utils-sanitize.test.ts:40-75
Conclusion
The Flashcards & Quizzes system in ThinkEx serves as a bridge between passive information consumption and active learning. By leveraging AI for content generation and providing robust React components for interaction, the platform ensures that knowledge captured in the workspace is actionable and persistent. Progress is tracked through a versioned event system, allowing for collaborative and multi-device learning sessions.