Exercise Manager
When using Algebrakit’s authoring components—especially in a custom integration—you may need to author or manage a single exercise or interaction block (e.g. a question or instruction). In this case, use the ExerciseManager
interface to create, edit, and retrieve Algebrakit exercises programmatically.
This page explains how to initialize an exercise and interact with its elements and interactions using the ExerciseManager
.
Creating an Exercise
Use one of the following methods depending on whether you are creating a new exercise or loading an existing one:
// Create a new exercise
AlgebraKIT.createExercise(options?: IEditorOptions): Promise<ExerciseManager>
// Load an existing exercise
AlgebraKIT.setExercise(spec: Exercise, options?: IEditorOptions): Promise<ExerciseManager>
ExerciseManager Methods
Once you've created or loaded an exercise, the ExerciseManager
gives you access to the following functionality:
Method | Description |
---|---|
getExercise(): ExerciseDefinition |
Returns the full authored exercise specification. |
getExerciseId(): string |
Returns the unique ID of the exercise. |
setDefaultOptions(options: IEditorOptions) |
Sets default options for this exercise (e.g. audience or mode). |
addElement(elementIndex?: number, type: ElementType = "QUESTION") |
Adds a new block to the exercise. Use "QUESTION" for a scorable block or "CONTENT" for an instruction block. |
addInteraction(elementRef: number | string, name?: string): InteractionSpec |
Adds a new interaction to the specified element (by index or ID). |
removeInteraction(refId: string) |
Removes the interaction with the given ID. |
removeElement(elementRef: number | string) |
Removes the block (question or content) identified by index or ID. |
listInteractions(elementIndex: number): string[] |
Returns the IDs of all interactions in a given question block. |
listElements(): { [elementIndex: number]: string[] } |
Returns all block indices and their associated interaction IDs. |
Editor Options
You can customize the behavior and availability of certain features using the IEditorOptions
object:
interface IEditorOptions {
defaultQuestionMode: QuestionMode
defaultAudience: { id: string } // e.g. "uk_KS5"
availableAudiences: Audience[]
}
Here, an Audience
represents a student profile:
interface Audience {
name: string // e.g. "UK Key Stage 5"
id: string // e.g. "uk_KS5"
}
An element represents a question or instruction block. An instruction block cannot contain scorable interactions.
enum ElementType {
"QUESTION" // Scorable interactions
"CONTENT" // Instructional text or rich content
}
The QuestionMode
controls how questions are presented to the student.
enum QuestionMode {
"ALL_AT_ONCE" // All question elements are visible at once
"ONE_BY_ONE" // Completing a question element shows the next one
}