Skip to main content

GenAI

Automates course creation from video content by orchestrating AI server communication via webhooks and SSE streams. The module handles job lifecycle management, user approvals, and real-time progress updates.

🗂️ Folder Structure

genAI/
├── controllers/
│ ├── GenAIController.ts # API endpoints for job management and live updates
│ ├── WebhookController.ts # Receives AI server webhooks and dispatches SSE events
├── services/
│ ├── GenAIService.ts # Core logic for job orchestration and state transitions
│ ├── WebhookService.ts # HTTP client to AI server for task control and aborts
│ └── SseService.ts # Manages Server-Sent Events connections and broadcasts
├── repositories/
│ └── GenAIRepository.ts # Persists job and task data separately for optimized queries
├── classes/
│ ├── validators/ # DTOs for job creation, approvals, edits, and status
│ └── transformers/ # Response schemas and mapper functions
├── abilities/ # CASL policies for job-level permissions
├── types.ts # Inversify DI tokens
└── container.ts # Binds controllers, services, and repositories

🎯 Core Functionality

The GenAI module facilitates end-to-end automation of course generation from video content by coordinating with an external AI server and providing a seamless developer and user experience:

  • Job Orchestration: Validates incoming requests, persists job metadata, and queues tasks for segmentation, transcription, question generation, and content assembly.
  • AI Server Coordination: Utilizes WebhookService to send control messages—such as start, continue, abort, and rerun—to the AI engine and handles its asynchronous responses via webhooks.
  • Task Management: Records individual task states (e.g., segmentation, summarization, question creation) in a dedicated task collection to allow granular progress tracking and error handling.
  • User Approval Workflow: Offers endpoints to approve or modify AI-generated outputs at each stage—segment maps, question data, and transcripts—before proceeding to the next task.
  • Real-Time Feedback: Establishes a Server‑Sent Events (SSE) stream for front‑end clients to receive live updates on job progress, task completions, and actionable prompts.
  • Webhooks Handling: Implements a webhook endpoint to receive AI server callbacks, update job and task records in the database, and broadcast events to connected SSE clients.

🔁 Typical Workflow

  1. Initiation: The front-end invokes the module to create a new GenAI job, providing video or playlist identifiers along with target course/version information. The controller validates and delegates to GenAIService, which persists the job.
  2. Task Execution: GenAIService dispatches tasks to the AI server via WebhookService. Each subtask—such as cutting video segments, generating text transcripts, and crafting quiz questions—is tracked separately in the task repository.
  3. Webhook Reception: As the AI engine completes tasks, it triggers webhooks to our WebhookController. This controller updates both job-level and task-level records and relays status events over the SSE channel.
  4. Live Updates: Front-end clients subscribing to the SSE endpoint receive JSON‑encoded events indicating progress metrics, task results, or error notifications, enabling dynamic UI updates.
  5. User Interactions: At critical points, users can approve AI results (e.g., refining segment boundaries, editing questions, adjusting transcripts) via API calls. Successful approvals automatically enqueue the next task.
  6. Completion: Upon final approval, the module assembles the AI‑generated segments, questions, and metadata into structured course content, ready for review or publication.