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:
@@ -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 }),
|
||||
};
|
||||
|
||||
@@ -1,5 +1,37 @@
|
||||
import { api } from "@/lib/api-client";
|
||||
import type { AiInsight, AiAlert, AiSearchResult, AiBatchOptimization, AiGradingResult } from "@/types";
|
||||
|
||||
export interface AiSearchResponse {
|
||||
answer: string;
|
||||
suggestions: string[];
|
||||
related_actions?: { label: string; action: string }[];
|
||||
}
|
||||
|
||||
export interface AiInsightItem {
|
||||
title: string;
|
||||
description: string;
|
||||
severity: "info" | "warning" | "critical";
|
||||
recommendation: string;
|
||||
}
|
||||
|
||||
export interface AiAlertItem {
|
||||
title: string;
|
||||
description: string;
|
||||
severity: string;
|
||||
recommendation?: string;
|
||||
}
|
||||
|
||||
export interface BatchOptimizeResponse {
|
||||
optimized: unknown[];
|
||||
summary: string;
|
||||
impact: string;
|
||||
}
|
||||
|
||||
export interface AiGradingResult {
|
||||
scores: Record<string, number>;
|
||||
overall_band: number;
|
||||
feedback: string;
|
||||
suggestions: string[];
|
||||
}
|
||||
|
||||
export const analyticsService = {
|
||||
async getStudentAnalytics(params?: Record<string, string | number | boolean | undefined>): Promise<unknown> {
|
||||
@@ -18,27 +50,44 @@ export const analyticsService = {
|
||||
return api.get("/analytics/content-gaps", params as Record<string, string | number | boolean | undefined>);
|
||||
},
|
||||
|
||||
async search(query: string): Promise<AiSearchResult[]> {
|
||||
return api.post<AiSearchResult[]>("/ai/search", { query });
|
||||
async search(query: string): Promise<AiSearchResponse> {
|
||||
return api.post<AiSearchResponse>("/ai/search", { query });
|
||||
},
|
||||
|
||||
async getInsights(data: Record<string, unknown>): Promise<AiInsight[]> {
|
||||
return api.post<AiInsight[]>("/ai/insights", data);
|
||||
async getInsights(data: Record<string, unknown>): Promise<{ insights: AiInsightItem[] }> {
|
||||
return api.post<{ insights: AiInsightItem[] }>("/ai/insights", { data, type: "general" });
|
||||
},
|
||||
|
||||
async getAlerts(): Promise<AiAlert[]> {
|
||||
return api.get<AiAlert[]>("/ai/alerts");
|
||||
async getAlerts(): Promise<{ alerts: AiAlertItem[] }> {
|
||||
return api.get<{ alerts: AiAlertItem[] }>("/ai/alerts");
|
||||
},
|
||||
|
||||
async getReportNarrative(data: { report_type: string; data: Record<string, unknown> }): Promise<{ narrative: string }> {
|
||||
return api.post("/ai/report-narrative", data);
|
||||
},
|
||||
|
||||
async getBatchOptimization(batchId: number): Promise<AiBatchOptimization[]> {
|
||||
return api.post<AiBatchOptimization[]>("/ai/batch-optimize", { batch_id: batchId });
|
||||
async getBatchOptimization(batchId: number, items: unknown[] = [], type = "schedule"): Promise<BatchOptimizeResponse> {
|
||||
return api.post<BatchOptimizeResponse>("/ai/batch-optimize", { items, type });
|
||||
},
|
||||
|
||||
async getGradingSuggestion(data: { submission_id: number; text: string; rubric_id?: number }): Promise<AiGradingResult> {
|
||||
async getGradingSuggestion(data: {
|
||||
submission_text: string;
|
||||
skill?: string;
|
||||
rubric?: string;
|
||||
task?: string;
|
||||
}): Promise<AiGradingResult> {
|
||||
return api.post<AiGradingResult>("/ai/grade-suggest", data);
|
||||
},
|
||||
|
||||
async applyBatchOptimization(batchId: number, optimized: unknown[]): Promise<{ applied: number }> {
|
||||
return api.post("/ai/batch-optimize/apply", { batch_id: batchId, optimized });
|
||||
},
|
||||
|
||||
async vectorSearch(query: string, options?: { content_type?: string; limit?: number }): Promise<{
|
||||
results: { content_type: string; content_id: number; text: string; metadata: Record<string, unknown>; similarity: number }[];
|
||||
query: string;
|
||||
count: number;
|
||||
}> {
|
||||
return api.get("/ai/vector-search", { q: query, ...options } as Record<string, string | number | boolean | undefined>);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,28 +1,55 @@
|
||||
import { api } from "@/lib/api-client";
|
||||
import type { AiChatRequest, AiChatResponse, AiTip } from "@/types";
|
||||
|
||||
interface CoachChatRequest {
|
||||
message: string;
|
||||
history?: { role: string; content: string }[];
|
||||
context?: unknown;
|
||||
}
|
||||
|
||||
interface CoachChatResponse {
|
||||
reply: string;
|
||||
}
|
||||
|
||||
interface CoachTipResponse {
|
||||
tip: string;
|
||||
category: string;
|
||||
}
|
||||
|
||||
interface CoachSuggestResponse {
|
||||
suggestion: string;
|
||||
focus_areas: string[];
|
||||
daily_plan: { activity: string; duration_min: number; skill: string }[];
|
||||
motivation: string;
|
||||
}
|
||||
|
||||
interface CoachWritingResponse {
|
||||
improved_text: string;
|
||||
changes: { original: string; revised: string; reason: string }[];
|
||||
tips: string[];
|
||||
}
|
||||
|
||||
export const coachingService = {
|
||||
async chat(data: AiChatRequest): Promise<AiChatResponse> {
|
||||
return api.post<AiChatResponse>("/coach/chat", data);
|
||||
async chat(data: CoachChatRequest): Promise<CoachChatResponse> {
|
||||
return api.post<CoachChatResponse>("/coach/chat", data);
|
||||
},
|
||||
|
||||
async getHint(data: { topic_id: number; question_id: string }): Promise<{ hint: string }> {
|
||||
async getHint(data: { topic_id: number; question_id: string }): Promise<{ hint: string; strategy: string }> {
|
||||
return api.post("/coach/hint", data);
|
||||
},
|
||||
|
||||
async explain(data: { context: string; scores?: Record<string, number> }): Promise<{ explanation: string }> {
|
||||
async explain(data: { score_data: Record<string, unknown>; student_context?: string }): Promise<{ explanation: string }> {
|
||||
return api.post("/coach/explain", data);
|
||||
},
|
||||
|
||||
async suggest(data?: { subject_id?: number }): Promise<{ suggestions: string[]; study_plan_tips: string[] }> {
|
||||
async suggest(data?: Record<string, unknown>): Promise<CoachSuggestResponse> {
|
||||
return api.post("/coach/suggest", data);
|
||||
},
|
||||
|
||||
async writingHelp(data: { text: string; task_type: string }): Promise<{ feedback: string; improved: string; grammar_notes: string[] }> {
|
||||
async writingHelp(data: { task: string; draft: string; help_type: string }): Promise<CoachWritingResponse> {
|
||||
return api.post("/coach/writing-help", data);
|
||||
},
|
||||
|
||||
async getTip(context: string): Promise<AiTip> {
|
||||
return api.get<AiTip>("/coach/tip", { context });
|
||||
async getTip(context: string): Promise<CoachTipResponse> {
|
||||
return api.get<CoachTipResponse>("/coach/tip", { context });
|
||||
},
|
||||
};
|
||||
|
||||
@@ -9,8 +9,8 @@ export const examSessionService = {
|
||||
autoSave: (examId: number, data: ExamAutoSave) =>
|
||||
api.post<ApiSuccessResponse>(`/exam/${examId}/autosave`, data),
|
||||
|
||||
submit: (examId: number) =>
|
||||
api.post<ExamSubmitResponse>(`/exam/${examId}/submit`),
|
||||
submit: (examId: number, data?: { attempt_id: number; answers: { question_id: number; answer: unknown }[] }) =>
|
||||
api.post<ExamSubmitResponse>(`/exam/${examId}/submit`, data),
|
||||
|
||||
getStatus: (examId: number) =>
|
||||
api.get<{ status: string; scores_available: boolean }>(`/exam/${examId}/status`),
|
||||
|
||||
Reference in New Issue
Block a user