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

@@ -1,41 +1,71 @@
import { api } from "@/lib/api-client";
import type {
AICourseConfig,
QualityGateResult,
IELTSValidationResult,
ExaminerReview,
AICourseTrack,
} from "@/types";
import type { ApiSuccessResponse } from "@/types";
export interface AiCourseCreateEnglishRequest {
cefr_level: string;
gap_profile_id?: number;
}
export interface AiCourseCreateIeltsRequest {
skill: "listening" | "reading" | "writing" | "speaking";
target_band: number;
brief?: string;
}
export interface AiCourseCreateResponse {
log_id: number;
status: string;
brief?: Record<string, unknown>;
skill?: string;
}
export interface QualityGateResult {
status: string;
readability_score: number;
cefr_alignment: boolean;
grammar_issues: string[];
attempts: number;
}
export interface IELTSValidationResult {
type: string;
validation_results: Record<string, unknown>;
overall_passed: boolean;
}
export const aiCourseService = {
createEnglish: (data: { current_level: string; target_level: string; learning_style: string[] }) =>
api.post<{ course_id: number }>("/ai-course/english/create", data),
createEnglish: (data: AiCourseCreateEnglishRequest) =>
api.post<AiCourseCreateResponse>("/ai-course/english/create", data),
createIelts: (data: { exam_type: string; target_band: number; skills: string[] }) =>
api.post<{ course_id: number }>("/ai-course/ielts/create", data),
createIelts: (data: AiCourseCreateIeltsRequest) =>
api.post<AiCourseCreateResponse>("/ai-course/ielts/create", data),
getCourse: (courseId: number) =>
api.get<AICourseConfig>(`/ai-course/${courseId}`),
api.get<Record<string, unknown>>(`/ai-course/${courseId}`),
getTracks: (courseId: number) =>
api.get<AICourseTrack[]>(`/ai-course/${courseId}/tracks`),
api.get<unknown[]>(`/ai-course/${courseId}/tracks`),
getQualityGate: (courseId: number) =>
api.get<QualityGateResult>(`/ai-course/${courseId}/quality`),
approveQuality: (courseId: number) =>
api.post<ApiSuccessResponse>(`/ai-course/${courseId}/quality/approve`),
api.post<{ approved: boolean }>(`/ai-course/${courseId}/approve`),
rejectQuality: (courseId: number, notes: string) =>
api.post<ApiSuccessResponse>(`/ai-course/${courseId}/quality/reject`, { notes }),
rejectQuality: (courseId: number, reason: string) =>
api.post<{ rejected: boolean; can_retry: boolean }>(`/ai-course/${courseId}/reject`, { reason }),
getIeltsValidation: (courseId: number) =>
api.get<IELTSValidationResult>(`/ai-course/${courseId}/validation`),
submitExaminerReview: (data: ExaminerReview) =>
api.post<ApiSuccessResponse>(`/ai-course/examiner-review`, data),
submitExaminerReview: (logId: number, data: { action: string; examiner_notes?: string }) =>
api.post<{ status: string; log_id: number }>(`/ai-course/ielts-review/${logId}`, data),
getEnglishTaxonomy: () =>
api.get<Record<string, unknown>>("/ai-course/english/taxonomy"),
getReviewQueue: (page = 1, size = 20) =>
api.get<{ total: number; page: number; size: number; items: unknown[] }>("/ai-course/review-queue", { page, size }),
getIeltsReviewQueue: (page = 1, size = 20) =>
api.get<{ total: number; page: number; size: number; items: unknown[] }>("/ai-course/ielts-review-queue", { page, size }),
};