feat: Generation Page AI workflows + AI/Vector modules + exam session fixes

Generation Page (complete rebuild):
- Full production-parity exam generation wizard with 4 IELTS modules
- Reading: AI passage gen, 5 exercise types (MCQ, Fill, Write, T/F, Match)
- Listening: 4 section types, AI context gen, TTS audio gen (ElevenLabs)
- Writing: Task 1/2, AI instruction gen, word limits, marks
- Speaking: 3 parts, AI script gen, avatar video gen (7 avatars)
- Per-module config: timer, CEFR difficulty, access, approval, rubrics
- Exam submission workflow (draft/published)

Exam Structures:
- New encoach.exam.structure model + CRUD controller
- ExamStructuresPage wired to real API

AI Module (encoach_ai):
- OpenAI service, ElevenLabs TTS, AWS Polly, ELAI avatars
- AI settings model with Odoo config parameters
- 7 generation endpoints (passage, exercises, instructions, scripts, context)

Vector Module (encoach_vector):
- pgvector integration for RAG-based content search
- Embedding service with sentence-transformers

Exam Session Fixes:
- Fixed ExamSession.tsx field mapping (question_type→type, exam_title→title)
- Fixed submit payload to include attempt_id and answers
- Fixed normalizeType to handle null/undefined

Tested: 12/12 API tests passed, browser-verified with real OpenAI calls
Made-with: Cursor
This commit is contained in:
Yamen Ahmad
2026-04-11 14:27:03 +04:00
parent 140ca7408d
commit b02ee8b6b7
64 changed files with 2639 additions and 264 deletions

View File

@@ -141,7 +141,7 @@ export default function AiEnglishCourse() {
.filter(Boolean)
: course?.learning_style ?? ["visual"];
createEnglish.mutate(
{ current_level: course?.current_level ?? "B1", target_level: tgt, learning_style: styles },
{ cefr_level: tgt || course?.current_level || "B1" },
{
onSuccess: () => {
qc.invalidateQueries({ queryKey: queryKeys.aiCourse.course(courseId) });

View File

@@ -166,9 +166,8 @@ export default function AiIeltsCourse() {
const band = Number(targetBand || course?.target_level || 7);
createIelts.mutate(
{
exam_type: course?.exam_type ?? "academic",
skill: skillsRanked[0]?.skill ?? "writing",
target_band: Number.isFinite(band) ? band : 7,
skills: skillsRanked.map((s) => s.skill),
},
{
onSuccess: () => {

View File

@@ -22,8 +22,8 @@ import { ScrollArea } from "@/components/ui/scroll-area";
import { Flag, ChevronLeft, ChevronRight, Pause, Play } from "lucide-react";
import { cn } from "@/lib/utils";
function normalizeType(t: string) {
return t.toLowerCase().replace(/\s+/g, "_");
function normalizeType(t: string | null | undefined) {
return (t ?? "").toLowerCase().replace(/\s+/g, "_");
}
function countWords(s: string) {
@@ -49,10 +49,26 @@ export default function ExamSession() {
const { examId: examIdParam } = useParams();
const examId = Number(examIdParam);
const navigate = useNavigate();
const { data: session, isLoading, isError } = useExamSession(examId);
const { data: rawSession, isLoading, isError } = useExamSession(examId);
const autoSave = useExamAutoSave();
const submitMut = useExamSubmit();
const session = useMemo(() => {
if (!rawSession) return rawSession;
const raw = rawSession as any;
return {
...raw,
title: raw.title || raw.exam_title || "",
sections: (raw.sections || []).map((s: any) => ({
...s,
questions: (s.questions || []).map((q: any) => ({
...q,
type: q.type || q.question_type || q.skill || "",
})),
})),
} as typeof rawSession;
}, [rawSession]);
const [sectionIdx, setSectionIdx] = useState(0);
const [questionIdx, setQuestionIdx] = useState(0);
const [answers, setAnswers] = useState<Map<number, ExamAnswer>>(new Map());
@@ -121,10 +137,11 @@ export default function ExamSession() {
useEffect(() => {
if (!session || !section) return;
const attemptId = (session as any)?.attempt_id;
const id = window.setInterval(() => {
autoSave.mutate({
examId,
payload: { section_id: section.id, answers: currentSectionAnswers() },
payload: { attempt_id: attemptId, section_id: section.id, answers: currentSectionAnswers() },
});
}, 10000);
return () => window.clearInterval(id);
@@ -439,12 +456,20 @@ export default function ExamSession() {
<Button
type="button"
onClick={() => {
submitMut.mutate(examId, {
onSuccess: () => {
setReviewOpen(false);
navigate(`/student/exam/${examId}/status`);
const attemptId = (session as any)?.attempt_id;
const allAnswers = Array.from(answers.entries()).map(([qId, a]) => ({
question_id: qId,
answer: a.answer ?? "",
}));
submitMut.mutate(
{ examId, attempt_id: attemptId, answers: allAnswers },
{
onSuccess: () => {
setReviewOpen(false);
navigate(`/student/exam/${examId}/status`);
},
},
});
);
}}
disabled={submitMut.isPending}
>

View File

@@ -29,7 +29,7 @@ export default function StudentGrades() {
<p className="text-muted-foreground">Track your academic performance.</p>
</div>
<AiReportNarrative narrative={`Your average grade is ${avgGrade}%. Your strongest area is essay writing with consistent scores above 80%. Focus on improving speaking scores — your last mock test scored 72%, which is below your average. AI recommends practicing with the IELTS Speaking Masterclass materials.`} />
<AiReportNarrative report_type="grades" data={{ avgGrade, highest, count: gradeRecords.length }} />
<div className="grid grid-cols-1 sm:grid-cols-3 gap-4">
<Card><CardContent className="pt-6 text-center"><p className="text-sm text-muted-foreground">Average</p><p className="text-3xl font-bold text-primary">{avgGrade}%</p></CardContent></Card>