@lessonkit/core 1.3.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,24 +1,5 @@
1
- type CourseId = string;
2
- type LessonId = string;
3
- type CheckId = string;
4
- type BlockId = string;
5
- /** Stable URN string returned by {@link buildLessonkitUrn}. */
6
- type LessonkitUrn = string;
7
- type IdentityValidationIssue = {
8
- path: string;
9
- message: string;
10
- };
11
- type IdentityValidationResult = {
12
- ok: true;
13
- id: string;
14
- } | {
15
- ok: false;
16
- issues: IdentityValidationIssue[];
17
- };
18
- type IdentityIdPath = "courseId" | "lessonId" | "checkId" | "blockId" | "id";
19
- /** LessonKit id format: letter first, then alphanumeric, `_`, `-`; length 1–64. */
20
- declare const ID_PATTERN: RegExp;
21
- declare const ID_MAX_LENGTH = 64;
1
+ import { C as CourseId, L as LessonId, a as CheckId, B as BlockId, I as IdentityIdPath, b as IdentityValidationResult, c as LessonkitUrn, A as AssessmentResumeState, S as StoragePort, T as TelemetryEventName, d as TelemetrySink, e as TelemetryBatchSink, f as TrackingClient, g as TelemetryEvent, h as TelemetryUser, i as LessonkitPlugin, P as PluginRegistry, j as ProgressController, k as PluginHost, l as ProgressState, m as TelemetryDataFor, n as AssessmentScoreInput, o as AssessmentScoreResult, p as ClockPort, q as AssessmentPlugin, r as LifecyclePlugin, s as TelemetryPlugin, t as LessonkitPluginContext } from './testing-BFr8oEfw.js';
2
+ export { u as AccordionSectionToggledData, v as AssessmentAnsweredData, w as AssessmentBaseProps, x as AssessmentBehaviour, y as AssessmentCompletedData, z as AssessmentHandle, D as AssessmentInteractionType, E as AssessmentXAPIData, F as BookPageViewedData, G as BranchNodeViewedData, H as BranchSelectedData, J as BuildTelemetryEventInput, K as CompoundPageViewedData, M as CourseLifecycleContext, N as CourseLifecycleDeps, O as FlashcardFlippedData, Q as HotspotOpenedData, R as ID_MAX_LENGTH, U as ID_PATTERN, V as IdentityValidationIssue, W as ImageSliderChangedData, X as InformationWallSearchData, Y as InteractionBlockRegistration, Z as InteractionData, _ as InteractionPlugin, $ as LessonCompletionEmitter, a0 as LessonLifecycleData, a1 as LessonkitPluginKind, a2 as McqAssessmentProps, a3 as MemoryCardFlippedData, a4 as ParallaxSlideViewedData, a5 as PluginIdentity, a6 as QuestionnaireSubmittedData, a7 as QuizAnsweredData, a8 as QuizCompletedData, a9 as SESSION_STORAGE_KEY, aa as SlideViewedData, ab as TelemetryEventBase, ac as TimerPort, ad as VideoCueReachedData, ae as VideoSegmentCompletedData, af as buildCourseStartedTelemetryEvent, ag as buildTelemetryEvent, ah as completeCourseWithTelemetry, ai as completeLessonWithTelemetry, aj as createDefaultClock, ak as createGlobalTimer, al as createNoopStorage, am as createProgressController, an as createSessionStoragePort, ao as getTabSessionId, ap as hasCourseStarted, aq as hasCourseStartedEmittedToTracking, ar as hasCourseStartedPipelineDelivered, as as hasCourseStartedXapiSent, at as markCourseStarted, au as markCourseStartedEmittedToTracking, av as markCourseStartedPipelineDelivered, aw as markCourseStartedXapiSent, ax as migrateCourseStartedMark, ay as resetSharedVolatileSessionIdForTests, az as resetStoragePortForTests, aA as resetTelemetryBuilderWarningsForTests, aB as resolveSessionId, aC as tryBuildTelemetryEvent, aD as tryEmitCourseStarted } from './testing-BFr8oEfw.js';
22
3
 
23
4
  /**
24
5
  * Exhaustiveness helper for switch/default branches.
@@ -47,6 +28,7 @@ type LessonkitUrnParts = {
47
28
  lessonId?: LessonId;
48
29
  checkId?: CheckId;
49
30
  blockId?: BlockId;
31
+ nodeId?: string;
50
32
  };
51
33
  /**
52
34
  * Build a stable LessonKit URN for courses, lessons, checks, and blocks.
@@ -54,215 +36,8 @@ type LessonkitUrnParts = {
54
36
  */
55
37
  declare function buildLessonkitUrn(parts: LessonkitUrnParts): LessonkitUrn;
56
38
 
57
- /** H5P-aligned interaction kinds for assessment telemetry and xAPI. */
58
- type AssessmentInteractionType = "mcq" | "trueFalse" | "fillInBlanks" | "markTheWords" | "dragTheWords" | "dragAndDrop" | "assessmentSequence" | "findHotspot" | "findMultipleHotspots";
59
- /** Serializable resume blob for a single assessment block. */
60
- type AssessmentResumeState = Record<string, unknown>;
61
- /** Behaviour flags aligned with H5P question types. */
62
- type AssessmentBehaviour = {
63
- enableRetry?: boolean;
64
- enableSolutionsButton?: boolean;
65
- autoCheck?: boolean;
66
- };
67
- /** Payload for xAPI mapping from assessment components. */
68
- type AssessmentXAPIData = {
69
- checkId: CheckId;
70
- interactionType: AssessmentInteractionType;
71
- response?: string | string[] | boolean | Record<string, unknown>;
72
- correct?: boolean;
73
- score?: number;
74
- maxScore?: number;
75
- };
76
- /**
77
- * Imperative handle for scored blocks (H5P question-type contract analogue).
78
- * Parent containers (`AssessmentSequence`, future compounds) may call these methods.
79
- */
80
- type AssessmentHandle = {
81
- getScore: () => number;
82
- getMaxScore: () => number;
83
- getAnswerGiven: () => boolean;
84
- resetTask: () => void;
85
- showSolutions: () => void;
86
- getXAPIData: () => AssessmentXAPIData;
87
- getCurrentState?: () => AssessmentResumeState;
88
- resume?: (state: AssessmentResumeState) => void;
89
- };
90
- type AssessmentBaseProps = AssessmentBehaviour & {
91
- checkId: CheckId;
92
- passingScore?: number;
93
- };
94
-
95
- type TelemetryEventName = "course_started" | "course_completed" | "lesson_started" | "lesson_completed" | "lesson_time_on_task" | "quiz_answered" | "quiz_completed" | "assessment_answered" | "assessment_completed" | "interaction" | "book_page_viewed" | "slide_viewed" | "compound_page_viewed" | "hotspot_opened" | "accordion_section_toggled" | "flashcard_flipped" | "image_slider_changed";
96
- type TelemetryUser = {
97
- id?: string;
98
- email?: string;
99
- name?: string;
100
- [key: string]: unknown;
101
- };
102
- type TelemetryEventBase = {
103
- timestamp: string;
104
- courseId: CourseId;
105
- sessionId?: string;
106
- attemptId?: string;
107
- user?: TelemetryUser;
108
- };
109
- type LessonLifecycleData = {
110
- lessonId: LessonId;
111
- durationMs?: number;
112
- success?: boolean;
113
- score?: number;
114
- maxScore?: number;
115
- };
116
- type QuizAnsweredData = {
117
- checkId: CheckId;
118
- question: string;
119
- choice: string;
120
- correct: boolean;
121
- };
122
- type QuizCompletedData = {
123
- checkId: CheckId;
124
- score?: number;
125
- maxScore?: number;
126
- passingScore?: number;
127
- };
128
- type AssessmentAnsweredData = {
129
- checkId: CheckId;
130
- interactionType: AssessmentInteractionType;
131
- question?: string;
132
- response?: string | string[] | boolean | Record<string, unknown>;
133
- correct?: boolean;
134
- };
135
- type AssessmentCompletedData = {
136
- checkId: CheckId;
137
- interactionType: AssessmentInteractionType;
138
- score?: number;
139
- maxScore?: number;
140
- passingScore?: number;
141
- };
142
- type InteractionData = {
143
- kind?: string;
144
- blockId?: BlockId;
145
- payload?: Record<string, unknown>;
146
- [key: string]: unknown;
147
- };
148
- type BookPageViewedData = {
149
- blockId: BlockId;
150
- pageIndex: number;
151
- pageTitle?: string;
152
- };
153
- type SlideViewedData = {
154
- blockId: BlockId;
155
- slideIndex: number;
156
- slideTitle?: string;
157
- };
158
- type CompoundPageViewedData = {
159
- blockId: BlockId;
160
- pageIndex: number;
161
- parentType?: string;
162
- };
163
- type HotspotOpenedData = {
164
- blockId: BlockId;
165
- hotspotId: string;
166
- };
167
- type AccordionSectionToggledData = {
168
- blockId: BlockId;
169
- sectionId: string;
170
- expanded: boolean;
171
- };
172
- type FlashcardFlippedData = {
173
- blockId: BlockId;
174
- cardIndex: number;
175
- face: "front" | "back";
176
- };
177
- type ImageSliderChangedData = {
178
- blockId: BlockId;
179
- slideIndex: number;
180
- };
181
- type TelemetryEvent = (TelemetryEventBase & {
182
- name: "course_started";
183
- lessonId?: LessonId;
184
- data?: undefined;
185
- }) | (TelemetryEventBase & {
186
- name: "course_completed";
187
- lessonId?: LessonId;
188
- data?: undefined;
189
- }) | (TelemetryEventBase & {
190
- name: "lesson_started";
191
- lessonId: LessonId;
192
- data: LessonLifecycleData;
193
- }) | (TelemetryEventBase & {
194
- name: "lesson_completed";
195
- lessonId: LessonId;
196
- data: LessonLifecycleData;
197
- }) | (TelemetryEventBase & {
198
- name: "lesson_time_on_task";
199
- lessonId: LessonId;
200
- data: LessonLifecycleData;
201
- }) | (TelemetryEventBase & {
202
- name: "quiz_answered";
203
- lessonId: LessonId;
204
- data: QuizAnsweredData;
205
- }) | (TelemetryEventBase & {
206
- name: "quiz_completed";
207
- lessonId: LessonId;
208
- data: QuizCompletedData;
209
- }) | (TelemetryEventBase & {
210
- name: "assessment_answered";
211
- lessonId: LessonId;
212
- data: AssessmentAnsweredData;
213
- }) | (TelemetryEventBase & {
214
- name: "assessment_completed";
215
- lessonId: LessonId;
216
- data: AssessmentCompletedData;
217
- }) | (TelemetryEventBase & {
218
- name: "interaction";
219
- lessonId?: LessonId;
220
- data?: InteractionData;
221
- }) | (TelemetryEventBase & {
222
- name: "book_page_viewed";
223
- lessonId: LessonId;
224
- data: BookPageViewedData;
225
- }) | (TelemetryEventBase & {
226
- name: "slide_viewed";
227
- lessonId: LessonId;
228
- data: SlideViewedData;
229
- }) | (TelemetryEventBase & {
230
- name: "compound_page_viewed";
231
- lessonId: LessonId;
232
- data: CompoundPageViewedData;
233
- }) | (TelemetryEventBase & {
234
- name: "hotspot_opened";
235
- lessonId?: LessonId;
236
- data: HotspotOpenedData;
237
- }) | (TelemetryEventBase & {
238
- name: "accordion_section_toggled";
239
- lessonId?: LessonId;
240
- data: AccordionSectionToggledData;
241
- }) | (TelemetryEventBase & {
242
- name: "flashcard_flipped";
243
- lessonId?: LessonId;
244
- data: FlashcardFlippedData;
245
- }) | (TelemetryEventBase & {
246
- name: "image_slider_changed";
247
- lessonId?: LessonId;
248
- data: ImageSliderChangedData;
249
- });
250
- /** Payload shape for a telemetry event name. */
251
- type TelemetryDataFor<N extends TelemetryEventName> = Extract<TelemetryEvent, {
252
- name: N;
253
- }> extends {
254
- data?: infer D;
255
- } ? D : never;
256
- type TelemetrySink = (event: TelemetryEvent) => void | Promise<void>;
257
- type TelemetryBatchSink = (events: TelemetryEvent[]) => void | Promise<void>;
258
- type TrackingClient = {
259
- track: (event: TelemetryEvent) => void;
260
- /** Resolves to true when all buffered events were delivered; false when a sink failure re-queued events. */
261
- flush?: () => void | Promise<boolean>;
262
- /** Best-effort synchronous flush for pagehide (keepalive batch sink when configured). */
263
- flushOnExit?: () => void;
264
- dispose?: () => void | Promise<void>;
265
- };
39
+ /** LMS parent-bridge forwarding mode for packaged course runtimes. */
40
+ type LmsBridgeMode = "auto" | "off";
266
41
 
267
42
  declare const COMPOUND_RESUME_SCHEMA_VERSION: 1;
268
43
  /** Serializable resume blob for a compound container (InteractiveBook, AssessmentSequence, …). */
@@ -281,7 +56,10 @@ type CompoundResumeInput = {
281
56
  declare function createCompoundResumeState(input?: CompoundResumeInput): CompoundResumeState;
282
57
  /** Clamp page index to valid range for a compound with `pageCount` pages. */
283
58
  declare function clampCompoundPageIndex(index: number, pageCount: number): number;
284
- declare function parseCompoundResumeState(raw: unknown): CompoundResumeState | null;
59
+ type ParseCompoundResumeStateOptions = {
60
+ onDroppedChildKeys?: (keys: string[]) => void;
61
+ };
62
+ declare function parseCompoundResumeState(raw: unknown, opts?: ParseCompoundResumeStateOptions): CompoundResumeState | null;
285
63
  /**
286
64
  * Imperative handle for compound containers (H5P compound analogue).
287
65
  * Parents aggregate child AssessmentHandle scores and persist navigation state.
@@ -299,46 +77,52 @@ type CompoundBaseProps = {
299
77
  blockId: BlockId;
300
78
  };
301
79
 
302
- type StoragePort = {
303
- getItem: (key: string) => string | null;
304
- /** Returns false when the value could not be durably persisted (e.g. sessionStorage quota). */
305
- setItem: (key: string, value: string) => boolean;
306
- removeItem?: (key: string) => void;
307
- /** @internal Test helper to clear in-memory fallback state. */
308
- resetForTests?: () => void;
309
- };
310
- type ClockPort = {
311
- nowMs: () => number;
312
- nowIso: () => string;
313
- };
314
- type TimerPort = {
315
- setInterval: (fn: () => void, ms: number) => ReturnType<typeof globalThis.setInterval>;
316
- clearInterval: (id: ReturnType<typeof globalThis.setInterval>) => void;
317
- };
318
- declare function createDefaultClock(): ClockPort;
319
- declare function createNoopStorage(): StoragePort;
320
- declare function resetStoragePortForTests(storage: StoragePort): void;
321
- declare function createSessionStoragePort(): StoragePort;
322
- declare function createGlobalTimer(): TimerPort;
323
-
324
80
  declare function compoundStateStorageKey(courseId: CourseId, compoundId: BlockId): string;
325
- declare function loadCompoundState(storage: StoragePort, courseId: CourseId, compoundId: BlockId): CompoundResumeState | null;
81
+ type LoadCompoundStateOptions = ParseCompoundResumeStateOptions & {
82
+ onCorrupt?: () => void;
83
+ };
84
+ declare function loadCompoundState(storage: StoragePort, courseId: CourseId, compoundId: BlockId, opts?: LoadCompoundStateOptions): CompoundResumeState | null;
326
85
  declare function saveCompoundState(storage: StoragePort, courseId: CourseId, compoundId: BlockId, state: CompoundResumeState): boolean;
327
86
  declare function clearCompoundState(storage: StoragePort, courseId: CourseId, compoundId: BlockId): void;
328
87
 
329
88
  /** Canonical compound child allowlists (H5P sub-content curation). */
330
- declare const PAGE_ALLOWED_CHILD_TYPES: readonly ["Text", "Heading", "Image", "Scenario", "Reflection", "Quiz", "KnowledgeCheck", "TrueFalse", "FillInTheBlanks", "DragAndDrop", "DragTheWords", "MarkTheWords", "Accordion", "DialogCards", "Flashcards", "ImageHotspots", "FindHotspot", "FindMultipleHotspots", "ImageSlider", "ProgressTracker"];
89
+ declare const PAGE_ALLOWED_CHILD_TYPES: readonly ["Text", "Heading", "Image", "Video", "Scenario", "Reflection", "Quiz", "KnowledgeCheck", "TrueFalse", "FillInTheBlanks", "DragAndDrop", "DragTheWords", "MarkTheWords", "Summary", "ImagePairing", "ImageSequencing", "MemoryGame", "InformationWall", "ParallaxSlideshow", "Questionnaire", "Essay", "ArithmeticQuiz", "Accordion", "DialogCards", "Flashcards", "ImageHotspots", "FindHotspot", "FindMultipleHotspots", "ImageSlider", "Embed", "Chart", "ProgressTracker"];
90
+ /** Branch node content (Page-like minus ProgressTracker). */
91
+ declare const BRANCH_NODE_ALLOWED_CHILD_TYPES: readonly ["Text", "Heading", "Image", "Video", "Scenario", "Reflection", "Quiz", "KnowledgeCheck", "TrueFalse", "FillInTheBlanks", "DragAndDrop", "DragTheWords", "MarkTheWords", "Summary", "ImagePairing", "ImageSequencing", "MemoryGame", "InformationWall", "ParallaxSlideshow", "Questionnaire", "Essay", "ArithmeticQuiz", "Accordion", "DialogCards", "Flashcards", "ImageHotspots", "FindHotspot", "FindMultipleHotspots", "ImageSlider", "Embed", "Chart", "BranchChoice"];
92
+ declare const BRANCHING_SCENARIO_ALLOWED_CHILD_TYPES: readonly ["BranchNode"];
331
93
  declare const INTERACTIVE_BOOK_ALLOWED_CHILD_TYPES: readonly ["Page"];
332
94
  /** Per-slide content (H5P Course Presentation slide row). Excludes ProgressTracker. */
333
- declare const SLIDE_ALLOWED_CHILD_TYPES: readonly ["Text", "Heading", "Image", "Scenario", "Reflection", "Quiz", "KnowledgeCheck", "TrueFalse", "FillInTheBlanks", "DragAndDrop", "DragTheWords", "MarkTheWords", "Accordion", "DialogCards", "Flashcards", "ImageHotspots", "FindHotspot", "FindMultipleHotspots", "ImageSlider"];
95
+ declare const SLIDE_ALLOWED_CHILD_TYPES: readonly ["Text", "Heading", "Image", "Video", "Scenario", "Reflection", "Quiz", "KnowledgeCheck", "TrueFalse", "FillInTheBlanks", "DragAndDrop", "DragTheWords", "MarkTheWords", "Summary", "ImagePairing", "ImageSequencing", "MemoryGame", "InformationWall", "ParallaxSlideshow", "Questionnaire", "Essay", "ArithmeticQuiz", "Accordion", "DialogCards", "Flashcards", "ImageHotspots", "FindHotspot", "FindMultipleHotspots", "ImageSlider", "Embed", "Chart"];
334
96
  declare const SLIDE_DECK_ALLOWED_CHILD_TYPES: readonly ["Slide"];
335
- declare const ASSESSMENT_SEQUENCE_ALLOWED_CHILD_TYPES: readonly ["TrueFalse", "FillInTheBlanks", "DragAndDrop", "DragTheWords", "MarkTheWords", "Quiz", "KnowledgeCheck", "FindHotspot", "FindMultipleHotspots"];
336
- type CompoundParentType = "Page" | "InteractiveBook" | "Slide" | "SlideDeck" | "AssessmentSequence";
97
+ declare const TIMED_CUE_ALLOWED_CHILD_TYPES: readonly ["Text", "Heading", "Image", "Quiz", "TrueFalse", "FillInTheBlanks", "Summary", "ImagePairing", "ImageSequencing", "MemoryGame", "Questionnaire", "Essay", "ArithmeticQuiz"];
98
+ declare const INTERACTIVE_VIDEO_ALLOWED_CHILD_TYPES: readonly ["TimedCue"];
99
+ declare const ASSESSMENT_SEQUENCE_ALLOWED_CHILD_TYPES: readonly ["TrueFalse", "FillInTheBlanks", "DragAndDrop", "DragTheWords", "MarkTheWords", "Quiz", "KnowledgeCheck", "FindHotspot", "FindMultipleHotspots", "Summary", "ImagePairing", "ImageSequencing", "ArithmeticQuiz", "Essay"];
100
+ type CompoundParentType = "Page" | "InteractiveBook" | "Slide" | "SlideDeck" | "TimedCue" | "InteractiveVideo" | "AssessmentSequence" | "BranchingScenario" | "BranchNode";
337
101
  declare const COMPOUND_MAX_NESTING_DEPTH: Record<CompoundParentType, number>;
338
102
  declare function getAllowedChildTypes(parent: CompoundParentType): readonly string[];
339
103
  declare function isChildTypeAllowed(parent: CompoundParentType, childType: string): boolean;
340
104
  /** Blocks that must not nest inside Accordion (policy: no accordion-in-accordion). */
341
105
  declare const ACCORDION_FORBIDDEN_CHILD_TYPES: readonly ["Accordion"];
106
+ /** New 1.4 blocks added to Page and Slide allowlists (for docs/tests). */
107
+ declare const BLOCKS_14_PAGE_SLIDE: readonly ["Video", "Summary", "ImagePairing", "ImageSequencing", "MemoryGame", "InformationWall", "ParallaxSlideshow", "Questionnaire", "Essay", "ArithmeticQuiz"];
108
+
109
+ type BranchGraphNodeInput = {
110
+ nodeId: string;
111
+ choices: readonly {
112
+ targetNodeId: string;
113
+ }[];
114
+ };
115
+ type BranchGraphValidationIssue = {
116
+ code: "duplicate_node_id" | "start_not_found" | "start_no_choices" | "unknown_target" | "unreachable_node" | "empty_graph";
117
+ message: string;
118
+ nodeId?: string;
119
+ };
120
+ type BranchGraphValidationResult = {
121
+ ok: boolean;
122
+ issues: BranchGraphValidationIssue[];
123
+ reachableNodeIds: string[];
124
+ };
125
+ declare function validateBranchGraph(startNodeId: string, nodes: readonly BranchGraphNodeInput[]): BranchGraphValidationResult;
342
126
 
343
127
  declare const telemetryCatalogVersion: 1;
344
128
  type TelemetryCatalogEntry = {
@@ -365,7 +149,7 @@ declare const TELEMETRY_EVENT_CATALOG_V2: TelemetryCatalogV2Entry[];
365
149
  declare function buildTelemetryCatalogV2(): TelemetryCatalogV2Entry[];
366
150
 
367
151
  declare const telemetryCatalogV3Version: 3;
368
- type TelemetryCatalogV3EventName = Extract<TelemetryEventName, "book_page_viewed" | "slide_viewed" | "compound_page_viewed" | "hotspot_opened" | "accordion_section_toggled" | "flashcard_flipped" | "image_slider_changed">;
152
+ type TelemetryCatalogV3EventName = Extract<TelemetryEventName, "book_page_viewed" | "slide_viewed" | "compound_page_viewed" | "hotspot_opened" | "accordion_section_toggled" | "flashcard_flipped" | "image_slider_changed" | "video_cue_reached" | "video_segment_completed" | "memory_card_flipped" | "information_wall_search" | "parallax_slide_viewed" | "questionnaire_submitted" | "branch_node_viewed" | "branch_selected">;
369
153
  type TelemetryCatalogV3Entry = {
370
154
  name: TelemetryCatalogV3EventName;
371
155
  description: string;
@@ -377,6 +161,14 @@ type TelemetryCatalogV3Entry = {
377
161
  declare const TELEMETRY_EVENT_CATALOG_V3: TelemetryCatalogV3Entry[];
378
162
  declare function buildTelemetryCatalogV3(): TelemetryCatalogV3Entry[];
379
163
 
164
+ /**
165
+ * Creates a client that buffers telemetry and flushes in batches.
166
+ *
167
+ * **Delivery semantics:** batch mode is at-least-once. A failed flush re-queues the batch for
168
+ * retry; `flushOnExit` and periodic flushes may deliver the same events more than once unless
169
+ * the sink deduplicates. Events currently owned by an in-flight `batchSink` call are not included
170
+ * in `flushOnExit` to avoid duplicate delivery on page unload.
171
+ */
380
172
  declare function createTrackingClient(opts?: {
381
173
  sink?: TelemetrySink;
382
174
  batch?: {
@@ -395,95 +187,6 @@ declare function createSessionId(): string;
395
187
 
396
188
  declare function nowIso(): string;
397
189
 
398
- type BuildTelemetryEventContext = {
399
- courseId: CourseId;
400
- sessionId?: string;
401
- attemptId?: string;
402
- user?: TelemetryUser;
403
- timestamp?: string;
404
- };
405
- type BuildTelemetryEventInput = (BuildTelemetryEventContext & {
406
- name: "course_started";
407
- lessonId?: LessonId;
408
- data?: undefined;
409
- }) | (BuildTelemetryEventContext & {
410
- name: "course_completed";
411
- lessonId?: LessonId;
412
- data?: undefined;
413
- }) | (BuildTelemetryEventContext & {
414
- name: "lesson_started";
415
- lessonId?: LessonId;
416
- data?: LessonLifecycleData;
417
- }) | (BuildTelemetryEventContext & {
418
- name: "lesson_completed";
419
- lessonId?: LessonId;
420
- data?: LessonLifecycleData;
421
- }) | (BuildTelemetryEventContext & {
422
- name: "lesson_time_on_task";
423
- lessonId?: LessonId;
424
- data?: LessonLifecycleData;
425
- }) | (BuildTelemetryEventContext & {
426
- name: "quiz_answered";
427
- lessonId?: LessonId;
428
- data: QuizAnsweredData;
429
- }) | (BuildTelemetryEventContext & {
430
- name: "quiz_completed";
431
- lessonId?: LessonId;
432
- data: QuizCompletedData;
433
- }) | (BuildTelemetryEventContext & {
434
- name: "assessment_answered";
435
- lessonId?: LessonId;
436
- data: AssessmentAnsweredData;
437
- }) | (BuildTelemetryEventContext & {
438
- name: "assessment_completed";
439
- lessonId?: LessonId;
440
- data: AssessmentCompletedData;
441
- }) | (BuildTelemetryEventContext & {
442
- name: "interaction";
443
- lessonId?: LessonId;
444
- data?: InteractionData;
445
- }) | (BuildTelemetryEventContext & {
446
- name: "book_page_viewed";
447
- lessonId?: LessonId;
448
- data: BookPageViewedData;
449
- }) | (BuildTelemetryEventContext & {
450
- name: "slide_viewed";
451
- lessonId?: LessonId;
452
- data: SlideViewedData;
453
- }) | (BuildTelemetryEventContext & {
454
- name: "compound_page_viewed";
455
- lessonId?: LessonId;
456
- data: CompoundPageViewedData;
457
- }) | (BuildTelemetryEventContext & {
458
- name: "hotspot_opened";
459
- lessonId?: LessonId;
460
- data: HotspotOpenedData;
461
- }) | (BuildTelemetryEventContext & {
462
- name: "accordion_section_toggled";
463
- lessonId?: LessonId;
464
- data: AccordionSectionToggledData;
465
- }) | (BuildTelemetryEventContext & {
466
- name: "flashcard_flipped";
467
- lessonId?: LessonId;
468
- data: FlashcardFlippedData;
469
- }) | (BuildTelemetryEventContext & {
470
- name: "image_slider_changed";
471
- lessonId?: LessonId;
472
- data: ImageSliderChangedData;
473
- });
474
-
475
- /** Reset dev-warning state (tests only). */
476
- declare function resetTelemetryBuilderWarningsForTests(): void;
477
- /**
478
- * Build a typed telemetry event from a catalog event name and context.
479
- * Validates lesson-scoped events require `lessonId`.
480
- */
481
- declare function buildTelemetryEvent(opts: BuildTelemetryEventInput): TelemetryEvent;
482
- /**
483
- * Like `buildTelemetryEvent`, but returns null (with a dev warning) when quiz events lack an active lesson.
484
- */
485
- declare function tryBuildTelemetryEvent(opts: BuildTelemetryEventInput): TelemetryEvent | null;
486
-
487
190
  type EmitContext = {
488
191
  courseId: CourseId;
489
192
  sessionId?: string;
@@ -498,145 +201,10 @@ type TelemetryPipeline = {
498
201
  readonly sinks: readonly TelemetryPipelineSink[];
499
202
  emit(event: TelemetryEvent, ctx?: EmitContext): void | Promise<void>;
500
203
  };
204
+ declare function isLifecycleTelemetryEvent(name: TelemetryEventName): boolean;
501
205
  declare function createTelemetryPipeline(sinks: TelemetryPipelineSink[]): TelemetryPipeline;
502
206
  declare function createTrackingPipelineSink(id: string, track: (event: TelemetryEvent) => void): TelemetryPipelineSink;
503
207
 
504
- type ProgressState = {
505
- activeLessonId?: LessonId;
506
- completedLessonIds: ReadonlySet<LessonId>;
507
- courseCompleted: boolean;
508
- };
509
- type ProgressController = {
510
- getState: () => ProgressState;
511
- setActiveLesson: (lessonId: LessonId, startedAtMs: number) => {
512
- previousLessonId?: LessonId;
513
- };
514
- completeLesson: (lessonId: LessonId, completedAtMs: number) => {
515
- durationMs?: number;
516
- didComplete: boolean;
517
- };
518
- completeCourse: () => {
519
- didComplete: boolean;
520
- };
521
- };
522
- declare function createProgressController(): ProgressController;
523
-
524
- declare const SESSION_STORAGE_KEY = "lessonkit:sessionId";
525
- declare function getTabSessionId(storage: StoragePort): string | null;
526
- declare function resolveSessionId(storage: StoragePort, provided?: string): string;
527
- declare function hasCourseStarted(storage: StoragePort, sessionId: string, courseId?: CourseId): boolean;
528
- declare function markCourseStarted(storage: StoragePort, sessionId: string, courseId?: CourseId): boolean;
529
- declare function hasCourseStartedEmittedToTracking(storage: StoragePort, sessionId: string, courseId?: CourseId): boolean;
530
- declare function markCourseStartedEmittedToTracking(storage: StoragePort, sessionId: string, courseId?: CourseId): boolean;
531
- declare function hasCourseStartedPipelineDelivered(storage: StoragePort, sessionId: string, courseId?: CourseId): boolean;
532
- declare function markCourseStartedPipelineDelivered(storage: StoragePort, sessionId: string, courseId?: CourseId): boolean;
533
- /** @internal Reset shared volatile session id between tests. */
534
- declare function resetSharedVolatileSessionIdForTests(): void;
535
- declare function migrateCourseStartedMark(storage: StoragePort, fromSessionId: string, toSessionId: string, courseId?: CourseId): void;
536
-
537
- /** Plugin category — aligns with roadmap extension areas. */
538
- type LessonkitPluginKind = "analytics" | "lms" | "assessment" | "interaction" | "ai";
539
- type LessonkitPluginContext = {
540
- courseId: CourseId;
541
- sessionId?: string;
542
- attemptId?: string;
543
- user?: TelemetryUser;
544
- };
545
- type AssessmentScoreInput = {
546
- checkId: CheckId;
547
- lessonId?: LessonId;
548
- response: unknown;
549
- };
550
- type AssessmentScoreResult = {
551
- score: number;
552
- maxScore?: number;
553
- passed?: boolean;
554
- feedback?: string;
555
- };
556
- /** Metadata for custom interaction blocks (renderer wiring stays in app code until 1.0). */
557
- type InteractionBlockRegistration = {
558
- blockType: string;
559
- catalogVersion?: string;
560
- description?: string;
561
- };
562
- type PluginIdentity = {
563
- id: string;
564
- version: string;
565
- kind: LessonkitPluginKind;
566
- name?: string;
567
- };
568
- /** Narrow telemetry plugin contract (ISP). */
569
- type TelemetryPlugin = PluginIdentity & {
570
- onTelemetry?: (event: TelemetryEvent, ctx: LessonkitPluginContext) => TelemetryEvent | null;
571
- onTelemetryBatch?: (events: TelemetryEvent[], ctx: LessonkitPluginContext) => void;
572
- wrapTrackingSink?: (sink: TelemetrySink, ctx: LessonkitPluginContext) => TelemetrySink;
573
- };
574
- /** Narrow lifecycle plugin contract (ISP). */
575
- type LifecyclePlugin = PluginIdentity & {
576
- setup?: (ctx: LessonkitPluginContext) => void;
577
- dispose?: () => void;
578
- };
579
- /** Narrow assessment plugin contract (ISP). */
580
- type AssessmentPlugin = PluginIdentity & {
581
- kind: "assessment";
582
- scoreAssessment?: (input: AssessmentScoreInput, ctx: LessonkitPluginContext) => AssessmentScoreResult | null;
583
- };
584
- /**
585
- * Narrow interaction metadata plugin (ISP).
586
- * @experimental Not wired into PluginHost; reserved for a future release.
587
- */
588
- type InteractionPlugin = PluginIdentity & {
589
- interactionBlocks?: InteractionBlockRegistration[];
590
- };
591
- /**
592
- * Combined plugin contract (v1). Prefer segregated types for new plugins.
593
- * @deprecated Prefer `TelemetryPlugin`, `AssessmentPlugin`, or `LifecyclePlugin` via `define*Plugin`.
594
- */
595
- type LessonkitPlugin = PluginIdentity & Partial<Pick<TelemetryPlugin, "onTelemetry" | "onTelemetryBatch" | "wrapTrackingSink"> & Pick<LifecyclePlugin, "setup" | "dispose"> & Pick<AssessmentPlugin, "scoreAssessment"> & Pick<InteractionPlugin, "interactionBlocks">>;
596
- type PluginHost = {
597
- readonly plugins: readonly LessonkitPlugin[];
598
- setupAll: (ctx: LessonkitPluginContext) => void;
599
- disposeAll: () => void;
600
- runTelemetry: (event: TelemetryEvent, ctx: LessonkitPluginContext) => TelemetryEvent | null;
601
- runTelemetryBatch: (events: TelemetryEvent[], ctx: LessonkitPluginContext) => TelemetryEvent[];
602
- deliverTelemetryBatch: (events: TelemetryEvent[], ctx: LessonkitPluginContext) => TelemetryEvent[];
603
- composeTrackingSink: (sink: TelemetrySink | undefined, ctx: LessonkitPluginContext | (() => LessonkitPluginContext)) => TelemetrySink | undefined;
604
- scoreAssessment: (input: AssessmentScoreInput, ctx: LessonkitPluginContext) => AssessmentScoreResult | null;
605
- };
606
- /** Segregated plugin registry (ISP + SRP). */
607
- type PluginRegistry = PluginHost;
608
-
609
- type CourseLifecycleContext = {
610
- courseId: CourseId;
611
- sessionId: string;
612
- attemptId?: string;
613
- user?: TelemetryUser;
614
- storage: StoragePort;
615
- pluginHost: PluginRegistry | null;
616
- lxpackBridge: "auto" | "off";
617
- };
618
- type CourseLifecycleDeps = {
619
- emitCourseStartedEvent: (ctx: CourseLifecycleContext) => boolean;
620
- };
621
- declare function tryEmitCourseStarted(ctx: CourseLifecycleContext, deps: CourseLifecycleDeps, alreadyEmittedToSink: boolean): {
622
- emitted: boolean;
623
- marked: boolean;
624
- };
625
- declare function buildCourseStartedTelemetryEvent(ctx: CourseLifecycleContext): TelemetryEvent;
626
- type LessonCompletionEmitter = (lessonId: LessonId, durationMs?: number) => void;
627
- declare function completeLessonWithTelemetry(opts: {
628
- progress: ProgressController;
629
- lessonId: LessonId;
630
- nowMs: number;
631
- emitLessonCompleted: LessonCompletionEmitter;
632
- }): boolean;
633
- declare function completeCourseWithTelemetry(opts: {
634
- progress: ProgressController;
635
- nowMs: number;
636
- emitLessonCompleted: LessonCompletionEmitter;
637
- emitCourseCompleted: () => void;
638
- }): boolean;
639
-
640
208
  type LessonkitRuntimeVersion = "v1" | "v2";
641
209
  type HeadlessLessonkitPlugins = readonly LessonkitPlugin[] | PluginRegistry | null | undefined;
642
210
  type HeadlessLessonkitConfig = {
@@ -647,6 +215,8 @@ type HeadlessLessonkitConfig = {
647
215
  attemptId?: string;
648
216
  user?: TelemetryUser;
649
217
  };
218
+ /** When true (default), switching lessons auto-completes the previous in-progress lesson. */
219
+ autoCompleteOnLessonSwitch?: boolean;
650
220
  /** Plugin list or registry; hooks run on {@link HeadlessLessonkitRuntime.track} and lifecycle emits. */
651
221
  plugins?: HeadlessLessonkitPlugins;
652
222
  /** When true, skip initial {@link PluginHost.setupAll}; host caller runs setup (React v2 provider). */
@@ -656,9 +226,8 @@ type HeadlessRuntimePorts = {
656
226
  storage?: StoragePort;
657
227
  clock?: ClockPort;
658
228
  };
659
- type TelemetryEmitFn = {
660
- <N extends TelemetryEventName>(name: N, data?: TelemetryDataFor<N>, lessonId?: LessonId): void;
661
- };
229
+ /** Delivers a fully-built lifecycle telemetry event (plugins already applied). */
230
+ type TelemetryEmitFn = (event: TelemetryEvent) => void;
662
231
  type HeadlessLessonkitRuntime = {
663
232
  readonly config: HeadlessLessonkitConfig;
664
233
  readonly progress: ProgressController;
@@ -670,6 +239,8 @@ type HeadlessLessonkitRuntime = {
670
239
  user?: TelemetryUser;
671
240
  };
672
241
  updateConfig: (next: Partial<HeadlessLessonkitConfig>) => void;
242
+ /** Move course-started dedupe marks between session ids (e.g. LMS anonymous → authenticated handoff). */
243
+ migrateSessionMarks: (fromSessionId: string, toSessionId: string) => void;
673
244
  setActiveLesson: (lessonId: LessonId, emit: TelemetryEmitFn) => void;
674
245
  completeLesson: (lessonId: LessonId, emit: TelemetryEmitFn) => void;
675
246
  completeCourse: (emit: TelemetryEmitFn) => void;
@@ -678,6 +249,10 @@ type HeadlessLessonkitRuntime = {
678
249
  resetForCourseChange: (courseId: CourseId) => void;
679
250
  dispose: () => void;
680
251
  };
252
+ /**
253
+ * Create a headless LessonKit runtime for non-React tooling and tests.
254
+ * Powers `LessonkitProvider` from `@lessonkit/react` when `runtimeVersion` is `"v2"` (default).
255
+ */
681
256
  declare function createLessonkitRuntime(config: HeadlessLessonkitConfig, ports?: HeadlessRuntimePorts): HeadlessLessonkitRuntime;
682
257
 
683
258
  declare function createPluginRegistry(plugins?: readonly LessonkitPlugin[]): PluginRegistry;
@@ -696,4 +271,4 @@ declare function buildPluginContext(opts: {
696
271
  user?: TelemetryUser;
697
272
  }): LessonkitPluginContext;
698
273
 
699
- export { ACCORDION_FORBIDDEN_CHILD_TYPES, ASSESSMENT_SEQUENCE_ALLOWED_CHILD_TYPES, type AccordionSectionToggledData, type AssessmentAnsweredData, type AssessmentBaseProps, type AssessmentBehaviour, type AssessmentCompletedData, type AssessmentHandle, type AssessmentInteractionType, type AssessmentPlugin, type AssessmentResumeState, type AssessmentScoreInput, type AssessmentScoreResult, type AssessmentXAPIData, type BlockId, type BookPageViewedData, type BuildTelemetryEventInput, COMPOUND_MAX_NESTING_DEPTH, COMPOUND_RESUME_SCHEMA_VERSION, type CheckId, type ClockPort, type CompoundBaseProps, type CompoundHandle, type CompoundPageViewedData, type CompoundParentType, type CompoundResumeInput, type CompoundResumeState, type CourseId, type CourseLifecycleContext, type CourseLifecycleDeps, type EmitContext, type FlashcardFlippedData, type HeadlessLessonkitConfig, type HeadlessLessonkitRuntime, type HeadlessRuntimePorts, type HotspotOpenedData, ID_MAX_LENGTH, ID_PATTERN, INTERACTIVE_BOOK_ALLOWED_CHILD_TYPES, type IdentityIdPath, type IdentityValidationIssue, type IdentityValidationResult, type ImageSliderChangedData, type InteractionBlockRegistration, type InteractionData, type InteractionPlugin, type LessonCompletionEmitter, type LessonId, type LessonLifecycleData, type LessonkitPlugin, type LessonkitPluginContext, type LessonkitPluginKind, type LessonkitRuntimeVersion, type LessonkitUrn, type LessonkitUrnParts, type LifecyclePlugin, PAGE_ALLOWED_CHILD_TYPES, type PluginHost, type PluginIdentity, type PluginRegistry, type ProgressController, type ProgressState, type QuizAnsweredData, type QuizCompletedData, SESSION_STORAGE_KEY, SLIDE_ALLOWED_CHILD_TYPES, SLIDE_DECK_ALLOWED_CHILD_TYPES, type SlideViewedData, type StoragePort, TELEMETRY_EVENT_CATALOG, TELEMETRY_EVENT_CATALOG_V2, TELEMETRY_EVENT_CATALOG_V3, type TelemetryBatchSink, type TelemetryCatalogEntry, type TelemetryCatalogV2Entry, type TelemetryCatalogV3Entry, type TelemetryDataFor, type TelemetryEmitFn, type TelemetryEvent, type TelemetryEventBase, type TelemetryEventName, type TelemetryPipeline, type TelemetryPipelineSink, type TelemetryPlugin, type TelemetrySink, type TelemetryUser, type TimerPort, type TrackingClient, assertNever, assertValidId, buildCourseStartedTelemetryEvent, buildLessonkitUrn, buildPluginContext, buildTelemetryCatalog, buildTelemetryCatalogV2, buildTelemetryCatalogV3, buildTelemetryEvent, clampCompoundPageIndex, clearCompoundState, completeCourseWithTelemetry, completeLessonWithTelemetry, compoundStateStorageKey, createCompoundResumeState, createDefaultClock, createGlobalTimer, createLessonkitRuntime, createNoopStorage, createPluginRegistry, createProgressController, createSessionId, createSessionStoragePort, createTelemetryPipeline, createTrackingClient, createTrackingPipelineSink, defineAssessmentPlugin, defineLifecyclePlugin, defineTelemetryPlugin, deriveId, getAllowedChildTypes, getTabSessionId, hasCourseStarted, hasCourseStartedEmittedToTracking, hasCourseStartedPipelineDelivered, isChildTypeAllowed, loadCompoundState, markCourseStarted, markCourseStartedEmittedToTracking, markCourseStartedPipelineDelivered, migrateCourseStartedMark, nowIso, parseBlockId, parseCheckId, parseCompoundResumeState, parseCourseId, parseLessonId, resetSharedVolatileSessionIdForTests, resetStoragePortForTests, resetTelemetryBuilderWarningsForTests, resolveSessionId, saveCompoundState, slugifyId, telemetryCatalogV2Version, telemetryCatalogV3Version, telemetryCatalogVersion, tryBuildTelemetryEvent, tryEmitCourseStarted, validateId };
274
+ export { ACCORDION_FORBIDDEN_CHILD_TYPES, ASSESSMENT_SEQUENCE_ALLOWED_CHILD_TYPES, AssessmentPlugin, AssessmentResumeState, AssessmentScoreInput, AssessmentScoreResult, BLOCKS_14_PAGE_SLIDE, BRANCHING_SCENARIO_ALLOWED_CHILD_TYPES, BRANCH_NODE_ALLOWED_CHILD_TYPES, BlockId, type BranchGraphNodeInput, type BranchGraphValidationIssue, type BranchGraphValidationResult, COMPOUND_MAX_NESTING_DEPTH, COMPOUND_RESUME_SCHEMA_VERSION, CheckId, ClockPort, type CompoundBaseProps, type CompoundHandle, type CompoundParentType, type CompoundResumeInput, type CompoundResumeState, CourseId, type EmitContext, type HeadlessLessonkitConfig, type HeadlessLessonkitRuntime, type HeadlessRuntimePorts, INTERACTIVE_BOOK_ALLOWED_CHILD_TYPES, INTERACTIVE_VIDEO_ALLOWED_CHILD_TYPES, IdentityIdPath, IdentityValidationResult, LessonId, LessonkitPlugin, LessonkitPluginContext, type LessonkitRuntimeVersion, LessonkitUrn, type LessonkitUrnParts, LifecyclePlugin, type LmsBridgeMode, type LoadCompoundStateOptions, PAGE_ALLOWED_CHILD_TYPES, type ParseCompoundResumeStateOptions, PluginHost, PluginRegistry, ProgressController, ProgressState, SLIDE_ALLOWED_CHILD_TYPES, SLIDE_DECK_ALLOWED_CHILD_TYPES, StoragePort, TELEMETRY_EVENT_CATALOG, TELEMETRY_EVENT_CATALOG_V2, TELEMETRY_EVENT_CATALOG_V3, TIMED_CUE_ALLOWED_CHILD_TYPES, TelemetryBatchSink, type TelemetryCatalogEntry, type TelemetryCatalogV2Entry, type TelemetryCatalogV3Entry, TelemetryDataFor, type TelemetryEmitFn, TelemetryEvent, TelemetryEventName, type TelemetryPipeline, type TelemetryPipelineSink, TelemetryPlugin, TelemetrySink, TelemetryUser, TrackingClient, assertNever, assertValidId, buildLessonkitUrn, buildPluginContext, buildTelemetryCatalog, buildTelemetryCatalogV2, buildTelemetryCatalogV3, clampCompoundPageIndex, clearCompoundState, compoundStateStorageKey, createCompoundResumeState, createLessonkitRuntime, createPluginRegistry, createSessionId, createTelemetryPipeline, createTrackingClient, createTrackingPipelineSink, defineAssessmentPlugin, defineLifecyclePlugin, defineTelemetryPlugin, deriveId, getAllowedChildTypes, isChildTypeAllowed, isLifecycleTelemetryEvent, loadCompoundState, nowIso, parseBlockId, parseCheckId, parseCompoundResumeState, parseCourseId, parseLessonId, saveCompoundState, slugifyId, telemetryCatalogV2Version, telemetryCatalogV3Version, telemetryCatalogVersion, validateBranchGraph, validateId };