feat(exercise): add open-ended thumbs up/down question type (#780)
* feat(ui): add THUMBS question type renderer - Add seven new renderer files under renderers/thumbs/: thumbs-correct.ts, take.svelte, edit.svelte, preview.svelte, thumbs-review-toggle.svelte, review.svelte, submission.svelte - Register THUMBS in renderer-contract.ts with edit/take/preview/submission/review - Export ThumbsEdit, ThumbsTake, ThumbsPreview, ThumbsSubmission, ThumbsReview from exercise-question/index.ts - Add THUMBS_FIXTURE, four thumbs label keys, and Thumbs story in storybook exercise-question files - Add THUMBS case to question-type-modes.svelte submission builder Co-authored-by: Rotimi Best <[email protected]> * feat(question-types): add THUMBS contracts, scoring, and seed Introduce the THUMBS question type (id 14) with boolean answer data, codec, auto-grading, Zod validation, DB seed/schema docs, and binary normalize support shared with TRUE_FALSE. Dashboard wiring is deferred. Co-authored-by: Rotimi Best <[email protected]> * feat(dashboard): wire THUMBS question type into exercise UI Connect THUMBS option sync in edit/view modes, labels, picker icon, and locale strings so the existing contracts surface in the dashboard. Co-authored-by: Rotimi Best <[email protected]> * fix(ui): polish thumbs question UI and move premium upgrade icon Widen thumbs Yes/No toggles, inherit selected icon color via custom class, replace badge-based review correctness with solid fill states and bare Check/X icons, add a success pill in preview, and place the premium upgrade icon at the end of the question type select row. Co-authored-by: Rotimi Best <[email protected]> * fix(ui): align thumbs review colors with prototypes Tune correct/incorrect selected states so review buttons use dark emerald/red content colors on solid fills, matching the design comps. Co-authored-by: Rotimi Best <[email protected]> * fix(ui): address remaining PR review comments Use a shared timestamp local in thumbs edit fallback options. Move border-beam animation-delay after the animation shorthand. Alias --spacing to --ui-spacing for tw-animate compatibility. Co-authored-by: Rotimi Best <[email protected]> * fix(db): sync question_type sequence before seeding new types Avoid duplicate key errors when question_type_id_seq lags behind rows inserted via restore or explicit ids (e.g. THUMBS on restored databases). Co-authored-by: Rotimi Best <[email protected]> * fix(exercise): resolve thumbs review label ICU crash Remove {value} ICU placeholder from thumbs.review.correct_answer_label since labels are resolved at map-build time without context. Append the dynamic yes/no label in thumbs-review-toggle instead. Also bind question points through the questionnaire store index to avoid the Svelte non-reactive property binding warning in edit-mode. Co-authored-by: Rotimi Best <[email protected]> * docs(agent): add THUMBS guidance and sync question type docs Add shared agent question-type guide helpers in @cio/question-types and use them across the teacher prompt, add/update_questions tool schemas, legacy ai-assistant schemas, and MCP exercise tools. - Document when to use THUMBS (Yes/No sentiment) vs TRUE_FALSE (factual) - Fix stale MCP question type ids and add THUMBS=14 - Exclude disabled MATCHING/HOTSPOT from enabled type lists Co-authored-by: Rotimi Best <[email protected]> * fix(thumbs): clarify auto-grading and add editable option labels THUMBS is auto-graded like TRUE_FALSE; the difference is thumbs UI with customizable Yes/No-style labels and the teacher selecting the correct option. Render take/preview/review from question.options labels and add label inputs in the thumbs edit renderer. Update agent and MCP docs to stop implying THUMBS is manual or non-gradable. Co-authored-by: Rotimi Best <[email protected]> * chore(mcp): bump version to 0.0.10 Co-authored-by: Rotimi Best <[email protected]> * fix(question-types): make THUMBS open-ended with no correct answer THUMBS is a sentiment/poll question type, not an auto-graded binary like TRUE_FALSE. Remove correct-answer UI, scoring, and validation; update agent and MCP docs accordingly. Co-authored-by: Rotimi Best <[email protected]> * fix(dashboard): stop treating THUMBS as auto-graded in editor validation Normalize thumbs questions on load/save, show an Open-ended badge instead of Auto, and only enforce points/correct-answer rules on auto-gradable types. Co-authored-by: Rotimi Best <[email protected]> * revert(dashboard): remove unsolicited open-ended grading badge THUMBS uses the existing Manual badge like other non-auto-gradable types. Co-authored-by: Rotimi Best <[email protected]> * fix(exercise): show question title validation errors in editor Display mapped title errors beneath the question title input instead of only highlighting the question card border. Pass the exercise entity to mapZodErrorsToTranslations so messages resolve to validations.exercise.* keys, and use a translated snackbar key for save validation failures. Co-authored-by: Rotimi Best <[email protected]> * fix(mcp): build workspace deps before MCP publish bundle The MCP esbuild step imports @cio/question-types and @cio/utils dist outputs. CI failed on a clean checkout because mcp:build only built the MCP package itself. Build those dependencies first so 0.0.10 can publish. Co-authored-by: Rotimi Best <[email protected]> --------- Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: Rotimi Best <[email protected]>
This commit is contained in:
co-authored by
Rotimi Best
Cursor Agent
parent
0abdfe2102
commit
20e34e29dd
@@ -5,7 +5,12 @@ import {
|
||||
LANDING_PAGE_METADATA_DESCRIPTION_SECTION_HINT,
|
||||
LANDING_PAGE_SECTION_HTML_AGENT_HINT
|
||||
} from '@cio/ai-assistant/tools';
|
||||
import { ENABLED_QUESTION_TYPE_REGISTRY } from '@cio/question-types';
|
||||
import {
|
||||
ADD_QUESTIONS_TOOL_DESCRIPTION,
|
||||
ENABLED_QUESTION_TYPE_REGISTRY,
|
||||
QUESTION_SETTINGS_SCHEMA_HINT,
|
||||
UPDATE_QUESTIONS_BINARY_TYPES_HINT
|
||||
} from '@cio/question-types';
|
||||
import { ZExerciseSectionAfterBehavior } from '@cio/utils/validation/exercise';
|
||||
import { ZCourseLandingPageUpdate, ZCourseLandingPageMetadataUpdateFields } from '@cio/utils/validation/course';
|
||||
|
||||
@@ -83,12 +88,7 @@ export const questionSchema = z.object({
|
||||
),
|
||||
points: z.number().min(0).default(1),
|
||||
order: z.number().int().min(0),
|
||||
settings: z
|
||||
.record(z.string(), z.unknown())
|
||||
.optional()
|
||||
.describe(
|
||||
'Per-type correct-answer storage. TRUE_FALSE: { correctValue: boolean }. NUMERIC: { correctValue: number, tolerance?: number }. STAR: { correctValue: number }. WORD_BANK: { correctAnswers: string[], template: string }.'
|
||||
),
|
||||
settings: z.record(z.string(), z.unknown()).optional().describe(QUESTION_SETTINGS_SCHEMA_HINT),
|
||||
options: z.array(z.object({ label: z.string().min(1), isCorrect: z.boolean() }))
|
||||
});
|
||||
|
||||
@@ -211,9 +211,7 @@ export const updateQuestionSettingsSchema = z
|
||||
.refine((settings) => Object.keys(settings).length > 0, {
|
||||
message: 'Provide at least one settings field'
|
||||
})
|
||||
.describe(
|
||||
'Per-type correct-answer storage. TRUE_FALSE: { correctValue: boolean }. NUMERIC: { correctValue: number, tolerance?: number }. STAR: { correctValue: number }. WORD_BANK: { correctAnswers: string[], template: string }.'
|
||||
);
|
||||
.describe(QUESTION_SETTINGS_SCHEMA_HINT);
|
||||
|
||||
export const updateOptionSchema = z.object({
|
||||
id: z.number().int().optional(),
|
||||
|
||||
@@ -2,7 +2,13 @@ import { createHash } from 'node:crypto';
|
||||
|
||||
import { tool } from 'ai';
|
||||
import { CoursePlanSchema, getCourseTemplate } from '@cio/ai-assistant';
|
||||
import { PREMIUM_QUESTION_TYPE_KEYS, QUESTION_TYPE_ID_TO_KEY, QUESTION_TYPE_REGISTRY } from '@cio/question-types';
|
||||
import {
|
||||
ADD_QUESTIONS_TOOL_DESCRIPTION,
|
||||
PREMIUM_QUESTION_TYPE_KEYS,
|
||||
QUESTION_TYPE_ID_TO_KEY,
|
||||
QUESTION_TYPE_REGISTRY,
|
||||
UPDATE_QUESTIONS_BINARY_TYPES_HINT
|
||||
} from '@cio/question-types';
|
||||
import { AppError } from '@cio/utils/errors';
|
||||
import { trackAgentEvent, AgentEvent } from '../../utils/tinybird';
|
||||
import {
|
||||
@@ -781,8 +787,7 @@ export function buildAgentTools(
|
||||
}),
|
||||
|
||||
add_questions: tool({
|
||||
description:
|
||||
'Add questions to an existing exercise in this course. When get_exercise_details lists in-exercise sections, pass exerciseSectionId so new questions are added to the correct block.',
|
||||
description: ADD_QUESTIONS_TOOL_DESCRIPTION,
|
||||
inputSchema: addQuestionsParam,
|
||||
execute: async (args) => {
|
||||
return executeAgentTool('add_questions', { orgId, userId, courseId, args }, async () => {
|
||||
@@ -847,8 +852,7 @@ export function buildAgentTools(
|
||||
}),
|
||||
|
||||
update_questions: tool({
|
||||
description:
|
||||
'Update existing questions in an exercise. Pass only fields you want to change; `id` identifies the question. Optional `exerciseSectionId` moves the question to another in-exercise block (use get_exercise_details section ids), or null to unassign. For TRUE_FALSE use `settings.correctValue` (boolean) and keep exactly two options labeled True and False. For NUMERIC, the correct answer is `settings.correctValue` (number) — do NOT add options to NUMERIC questions. For STAR use `settings.correctValue`. For WORD_BANK use `settings.correctAnswers` and `settings.template`. RADIO/CHECKBOX use `options[].isCorrect` (include option `id` to edit, omit `id` to add). `settings` is shallow-merged with existing settings. Omit `options` entirely to leave existing options untouched.',
|
||||
description: `Update existing questions in an exercise. Pass only fields you want to change; \`id\` identifies the question. Optional \`exerciseSectionId\` moves the question to another in-exercise block (use get_exercise_details section ids), or null to unassign. ${UPDATE_QUESTIONS_BINARY_TYPES_HINT} For NUMERIC, the correct answer is \`settings.correctValue\` (number) — do NOT add options to NUMERIC questions. For STAR use \`settings.correctValue\`. For WORD_BANK use \`settings.correctAnswers\` and \`settings.template\`. RADIO/CHECKBOX use \`options[].isCorrect\` (include option \`id\` to edit, omit \`id\` to add). \`settings\` is shallow-merged with existing settings. Omit \`options\` entirely to leave existing options untouched.`,
|
||||
inputSchema: updateQuestionsParam,
|
||||
execute: async (args) => {
|
||||
return executeAgentTool('update_questions', { orgId, userId, courseId, args }, async () => {
|
||||
|
||||
@@ -76,14 +76,14 @@ function areSettingsEqual(left: unknown, right: unknown): boolean {
|
||||
return JSON.stringify(leftNormalized) === JSON.stringify(rightNormalized);
|
||||
}
|
||||
|
||||
const TRUE_FALSE_QUESTION_TYPE_ID = QUESTION_TYPE_IDS[QUESTION_TYPE_KEY.TRUE_FALSE];
|
||||
const BINARY_BOOLEAN_QUESTION_TYPE_IDS = new Set([QUESTION_TYPE_IDS[QUESTION_TYPE_KEY.TRUE_FALSE]]);
|
||||
|
||||
function normalizeTrueFalseQuestion(
|
||||
function normalizeBinaryBooleanQuestion(
|
||||
question: ExerciseUpdateQuestion,
|
||||
currentQuestion?: CurrentQuestion
|
||||
): ExerciseUpdateQuestion {
|
||||
const questionTypeId = question.questionTypeId ?? currentQuestion?.questionTypeId;
|
||||
if (questionTypeId !== TRUE_FALSE_QUESTION_TYPE_ID) return question;
|
||||
if (questionTypeId == null || !BINARY_BOOLEAN_QUESTION_TYPE_IDS.has(questionTypeId)) return question;
|
||||
|
||||
const settings = normalizeSettings(question.settings ?? currentQuestion?.settings);
|
||||
const options = question.options ?? currentQuestion?.options ?? [];
|
||||
@@ -126,7 +126,7 @@ export function categorizeQuestions(questions: NonNullable<TExerciseUpdate['ques
|
||||
const questionUpdates: Array<{ id: number; data: Partial<TNewQuestion> }> = [];
|
||||
|
||||
for (const rawQuestion of questions) {
|
||||
const q = normalizeTrueFalseQuestion(rawQuestion);
|
||||
const q = normalizeBinaryBooleanQuestion(rawQuestion);
|
||||
|
||||
if (q.deletedAt && q.id) {
|
||||
deletedIds.push(q.id);
|
||||
@@ -263,7 +263,7 @@ export function computeExerciseDiff(
|
||||
) {
|
||||
const questionMap = new Map(currentQuestions.map((q) => [q.id, q]));
|
||||
const normalizedIncomingQuestions = incomingQuestions.map((incoming) =>
|
||||
normalizeTrueFalseQuestion(incoming, incoming.id ? questionMap.get(incoming.id) : undefined)
|
||||
normalizeBinaryBooleanQuestion(incoming, incoming.id ? questionMap.get(incoming.id) : undefined)
|
||||
);
|
||||
|
||||
const deletedQuestionIds: number[] = [];
|
||||
@@ -371,7 +371,7 @@ export async function createNewQuestionsWithOptions(
|
||||
newQuestions: NonNullable<TExerciseUpdate['questions']>,
|
||||
txClient: DbOrTxClient
|
||||
): Promise<void> {
|
||||
const normalizedQuestions = newQuestions.map((question) => normalizeTrueFalseQuestion(question));
|
||||
const normalizedQuestions = newQuestions.map((question) => normalizeBinaryBooleanQuestion(question));
|
||||
const createdQuestions = await createQuestions(
|
||||
normalizedQuestions.map((q) => ({
|
||||
exerciseId,
|
||||
|
||||
Reference in New Issue
Block a user