@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.
@@ -0,0 +1,608 @@
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;
22
+
23
+ /** H5P-aligned interaction kinds for assessment telemetry and xAPI. */
24
+ type AssessmentInteractionType = "mcq" | "trueFalse" | "fillInBlanks" | "markTheWords" | "dragTheWords" | "dragAndDrop" | "assessmentSequence" | "findHotspot" | "findMultipleHotspots" | "summary" | "imagePairing" | "imageSequencing" | "essay" | "arithmeticQuiz" | "memoryGame";
25
+ /** Serializable resume blob for a single assessment block. */
26
+ type AssessmentResumeState = Record<string, unknown>;
27
+ /** Behaviour flags aligned with H5P question types. */
28
+ type AssessmentBehaviour = {
29
+ enableRetry?: boolean;
30
+ enableSolutionsButton?: boolean;
31
+ autoCheck?: boolean;
32
+ };
33
+ /** Payload for xAPI mapping from assessment components. */
34
+ type AssessmentXAPIData = {
35
+ checkId: CheckId;
36
+ interactionType: AssessmentInteractionType;
37
+ response?: string | string[] | boolean | Record<string, unknown>;
38
+ correct?: boolean;
39
+ score?: number;
40
+ maxScore?: number;
41
+ };
42
+ /**
43
+ * Imperative handle for scored blocks (H5P question-type contract analogue).
44
+ * Parent containers (`AssessmentSequence`, future compounds) may call these methods.
45
+ */
46
+ type AssessmentHandle = {
47
+ getScore: () => number;
48
+ getMaxScore: () => number;
49
+ getAnswerGiven: () => boolean;
50
+ resetTask: () => void;
51
+ showSolutions: () => void;
52
+ getXAPIData: () => AssessmentXAPIData;
53
+ getCurrentState?: () => AssessmentResumeState;
54
+ resume?: (state: AssessmentResumeState) => void;
55
+ };
56
+ type AssessmentBaseProps = AssessmentBehaviour & {
57
+ checkId: CheckId;
58
+ passingScore?: number;
59
+ };
60
+ /** MCQ assessment props shared by React components and LMS packaging descriptors. */
61
+ type McqAssessmentProps = AssessmentBaseProps & {
62
+ kind?: "mcq";
63
+ question: string;
64
+ choices: string[];
65
+ answer: string;
66
+ };
67
+
68
+ 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" | "video_cue_reached" | "video_segment_completed" | "memory_card_flipped" | "information_wall_search" | "parallax_slide_viewed" | "questionnaire_submitted" | "branch_node_viewed" | "branch_selected";
69
+ type TelemetryUser = {
70
+ id?: string;
71
+ email?: string;
72
+ name?: string;
73
+ [key: string]: unknown;
74
+ };
75
+ type TelemetryEventBase = {
76
+ timestamp: string;
77
+ courseId: CourseId;
78
+ /** Optional stable id for sink deduplication (e.g. deliver retry). */
79
+ id?: string;
80
+ sessionId?: string;
81
+ attemptId?: string;
82
+ user?: TelemetryUser;
83
+ };
84
+ type LessonLifecycleData = {
85
+ lessonId: LessonId;
86
+ durationMs?: number;
87
+ success?: boolean;
88
+ score?: number;
89
+ maxScore?: number;
90
+ };
91
+ type QuizAnsweredData = {
92
+ checkId: CheckId;
93
+ question: string;
94
+ choice: string;
95
+ correct: boolean;
96
+ };
97
+ type QuizCompletedData = {
98
+ checkId: CheckId;
99
+ score?: number;
100
+ maxScore?: number;
101
+ passingScore?: number;
102
+ };
103
+ type AssessmentAnsweredData = {
104
+ checkId: CheckId;
105
+ interactionType: AssessmentInteractionType;
106
+ question?: string;
107
+ response?: string | string[] | boolean | Record<string, unknown>;
108
+ correct?: boolean;
109
+ };
110
+ type AssessmentCompletedData = {
111
+ checkId: CheckId;
112
+ interactionType: AssessmentInteractionType;
113
+ score?: number;
114
+ maxScore?: number;
115
+ passingScore?: number;
116
+ };
117
+ type InteractionData = {
118
+ kind?: string;
119
+ blockId?: BlockId;
120
+ payload?: Record<string, unknown>;
121
+ [key: string]: unknown;
122
+ };
123
+ type BookPageViewedData = {
124
+ blockId: BlockId;
125
+ pageIndex: number;
126
+ pageTitle?: string;
127
+ };
128
+ type SlideViewedData = {
129
+ blockId: BlockId;
130
+ slideIndex: number;
131
+ slideTitle?: string;
132
+ };
133
+ type CompoundPageViewedData = {
134
+ blockId: BlockId;
135
+ pageIndex: number;
136
+ parentType?: string;
137
+ };
138
+ type HotspotOpenedData = {
139
+ blockId: BlockId;
140
+ hotspotId: string;
141
+ };
142
+ type AccordionSectionToggledData = {
143
+ blockId: BlockId;
144
+ sectionId: string;
145
+ expanded: boolean;
146
+ };
147
+ type FlashcardFlippedData = {
148
+ blockId: BlockId;
149
+ cardIndex: number;
150
+ face: "front" | "back";
151
+ };
152
+ type ImageSliderChangedData = {
153
+ blockId: BlockId;
154
+ slideIndex: number;
155
+ };
156
+ type VideoCueReachedData = {
157
+ blockId: BlockId;
158
+ cueIndex: number;
159
+ atSeconds: number;
160
+ cueLabel?: string;
161
+ };
162
+ type VideoSegmentCompletedData = {
163
+ blockId: BlockId;
164
+ segmentIndex: number;
165
+ atSeconds: number;
166
+ segmentLabel?: string;
167
+ };
168
+ type MemoryCardFlippedData = {
169
+ blockId: BlockId;
170
+ cardIndex: number;
171
+ face: "front" | "back";
172
+ };
173
+ type InformationWallSearchData = {
174
+ blockId: BlockId;
175
+ query: string;
176
+ resultCount: number;
177
+ };
178
+ type ParallaxSlideViewedData = {
179
+ blockId: BlockId;
180
+ slideIndex: number;
181
+ };
182
+ type QuestionnaireSubmittedData = {
183
+ blockId: BlockId;
184
+ fieldCount: number;
185
+ };
186
+ type BranchNodeViewedData = {
187
+ blockId: BlockId;
188
+ nodeId: string;
189
+ nodeIndex: number;
190
+ nodeTitle?: string;
191
+ };
192
+ type BranchSelectedData = {
193
+ blockId: BlockId;
194
+ fromNodeId: string;
195
+ toNodeId: string;
196
+ label: string;
197
+ scoreWeight?: number;
198
+ };
199
+ type TelemetryEvent = (TelemetryEventBase & {
200
+ name: "course_started";
201
+ lessonId?: LessonId;
202
+ data?: undefined;
203
+ }) | (TelemetryEventBase & {
204
+ name: "course_completed";
205
+ lessonId?: LessonId;
206
+ data?: undefined;
207
+ }) | (TelemetryEventBase & {
208
+ name: "lesson_started";
209
+ lessonId: LessonId;
210
+ data: LessonLifecycleData;
211
+ }) | (TelemetryEventBase & {
212
+ name: "lesson_completed";
213
+ lessonId: LessonId;
214
+ data: LessonLifecycleData;
215
+ }) | (TelemetryEventBase & {
216
+ name: "lesson_time_on_task";
217
+ lessonId: LessonId;
218
+ data: LessonLifecycleData;
219
+ }) | (TelemetryEventBase & {
220
+ name: "quiz_answered";
221
+ lessonId: LessonId;
222
+ data: QuizAnsweredData;
223
+ }) | (TelemetryEventBase & {
224
+ name: "quiz_completed";
225
+ lessonId: LessonId;
226
+ data: QuizCompletedData;
227
+ }) | (TelemetryEventBase & {
228
+ name: "assessment_answered";
229
+ lessonId: LessonId;
230
+ data: AssessmentAnsweredData;
231
+ }) | (TelemetryEventBase & {
232
+ name: "assessment_completed";
233
+ lessonId: LessonId;
234
+ data: AssessmentCompletedData;
235
+ }) | (TelemetryEventBase & {
236
+ name: "interaction";
237
+ lessonId?: LessonId;
238
+ data?: InteractionData;
239
+ }) | (TelemetryEventBase & {
240
+ name: "book_page_viewed";
241
+ lessonId: LessonId;
242
+ data: BookPageViewedData;
243
+ }) | (TelemetryEventBase & {
244
+ name: "slide_viewed";
245
+ lessonId: LessonId;
246
+ data: SlideViewedData;
247
+ }) | (TelemetryEventBase & {
248
+ name: "compound_page_viewed";
249
+ lessonId: LessonId;
250
+ data: CompoundPageViewedData;
251
+ }) | (TelemetryEventBase & {
252
+ name: "hotspot_opened";
253
+ lessonId?: LessonId;
254
+ data: HotspotOpenedData;
255
+ }) | (TelemetryEventBase & {
256
+ name: "accordion_section_toggled";
257
+ lessonId?: LessonId;
258
+ data: AccordionSectionToggledData;
259
+ }) | (TelemetryEventBase & {
260
+ name: "flashcard_flipped";
261
+ lessonId?: LessonId;
262
+ data: FlashcardFlippedData;
263
+ }) | (TelemetryEventBase & {
264
+ name: "image_slider_changed";
265
+ lessonId?: LessonId;
266
+ data: ImageSliderChangedData;
267
+ }) | (TelemetryEventBase & {
268
+ name: "video_cue_reached";
269
+ lessonId: LessonId;
270
+ data: VideoCueReachedData;
271
+ }) | (TelemetryEventBase & {
272
+ name: "video_segment_completed";
273
+ lessonId: LessonId;
274
+ data: VideoSegmentCompletedData;
275
+ }) | (TelemetryEventBase & {
276
+ name: "memory_card_flipped";
277
+ lessonId?: LessonId;
278
+ data: MemoryCardFlippedData;
279
+ }) | (TelemetryEventBase & {
280
+ name: "information_wall_search";
281
+ lessonId?: LessonId;
282
+ data: InformationWallSearchData;
283
+ }) | (TelemetryEventBase & {
284
+ name: "parallax_slide_viewed";
285
+ lessonId?: LessonId;
286
+ data: ParallaxSlideViewedData;
287
+ }) | (TelemetryEventBase & {
288
+ name: "questionnaire_submitted";
289
+ lessonId: LessonId;
290
+ data: QuestionnaireSubmittedData;
291
+ }) | (TelemetryEventBase & {
292
+ name: "branch_node_viewed";
293
+ lessonId: LessonId;
294
+ data: BranchNodeViewedData;
295
+ }) | (TelemetryEventBase & {
296
+ name: "branch_selected";
297
+ lessonId: LessonId;
298
+ data: BranchSelectedData;
299
+ });
300
+ /** Payload shape for a telemetry event name. */
301
+ type TelemetryDataFor<N extends TelemetryEventName> = Extract<TelemetryEvent, {
302
+ name: N;
303
+ }> extends {
304
+ data?: infer D;
305
+ } ? D : never;
306
+ type TelemetrySink = (event: TelemetryEvent) => void | Promise<void>;
307
+ type TelemetryBatchSink = (events: TelemetryEvent[]) => void | Promise<void>;
308
+ type TrackingClient = {
309
+ /** Returns false when the event was dropped (e.g. buffer cap or after dispose). */
310
+ track: (event: TelemetryEvent) => boolean;
311
+ /** Delivers one event and resolves to true only when the sink accepted it (batch: includes flush). */
312
+ deliver?: (event: TelemetryEvent) => Promise<boolean>;
313
+ /** Resolves to true when all buffered events were delivered; false when a sink failure re-queued events. */
314
+ flush?: () => void | Promise<boolean>;
315
+ /** Best-effort synchronous flush for pagehide (keepalive batch sink when configured). */
316
+ flushOnExit?: () => void;
317
+ dispose?: () => void | Promise<void>;
318
+ };
319
+
320
+ type StoragePort = {
321
+ getItem: (key: string) => string | null;
322
+ /** Returns false when the value could not be durably persisted (e.g. sessionStorage quota). */
323
+ setItem: (key: string, value: string) => boolean;
324
+ removeItem?: (key: string) => void;
325
+ /** @internal Test helper to clear in-memory fallback state. */
326
+ resetForTests?: () => void;
327
+ };
328
+ type ClockPort = {
329
+ nowMs: () => number;
330
+ nowIso: () => string;
331
+ };
332
+ type TimerPort = {
333
+ setInterval: (fn: () => void, ms: number) => ReturnType<typeof globalThis.setInterval>;
334
+ clearInterval: (id: ReturnType<typeof globalThis.setInterval>) => void;
335
+ };
336
+ declare function createDefaultClock(): ClockPort;
337
+ declare function createNoopStorage(): StoragePort;
338
+ declare function resetStoragePortForTests(storage: StoragePort): void;
339
+ declare function createSessionStoragePort(): StoragePort;
340
+ declare function createGlobalTimer(): TimerPort;
341
+
342
+ type BuildTelemetryEventContext = {
343
+ courseId: CourseId;
344
+ sessionId?: string;
345
+ attemptId?: string;
346
+ user?: TelemetryUser;
347
+ timestamp?: string;
348
+ };
349
+ type BuildTelemetryEventInput = (BuildTelemetryEventContext & {
350
+ name: "course_started";
351
+ lessonId?: LessonId;
352
+ data?: undefined;
353
+ }) | (BuildTelemetryEventContext & {
354
+ name: "course_completed";
355
+ lessonId?: LessonId;
356
+ data?: undefined;
357
+ }) | (BuildTelemetryEventContext & {
358
+ name: "lesson_started";
359
+ lessonId?: LessonId;
360
+ data?: LessonLifecycleData;
361
+ }) | (BuildTelemetryEventContext & {
362
+ name: "lesson_completed";
363
+ lessonId?: LessonId;
364
+ data?: LessonLifecycleData;
365
+ }) | (BuildTelemetryEventContext & {
366
+ name: "lesson_time_on_task";
367
+ lessonId?: LessonId;
368
+ data?: LessonLifecycleData;
369
+ }) | (BuildTelemetryEventContext & {
370
+ name: "quiz_answered";
371
+ lessonId?: LessonId;
372
+ data: QuizAnsweredData;
373
+ }) | (BuildTelemetryEventContext & {
374
+ name: "quiz_completed";
375
+ lessonId?: LessonId;
376
+ data: QuizCompletedData;
377
+ }) | (BuildTelemetryEventContext & {
378
+ name: "assessment_answered";
379
+ lessonId?: LessonId;
380
+ data: AssessmentAnsweredData;
381
+ }) | (BuildTelemetryEventContext & {
382
+ name: "assessment_completed";
383
+ lessonId?: LessonId;
384
+ data: AssessmentCompletedData;
385
+ }) | (BuildTelemetryEventContext & {
386
+ name: "interaction";
387
+ lessonId?: LessonId;
388
+ data?: InteractionData;
389
+ }) | (BuildTelemetryEventContext & {
390
+ name: "book_page_viewed";
391
+ lessonId?: LessonId;
392
+ data: BookPageViewedData;
393
+ }) | (BuildTelemetryEventContext & {
394
+ name: "slide_viewed";
395
+ lessonId?: LessonId;
396
+ data: SlideViewedData;
397
+ }) | (BuildTelemetryEventContext & {
398
+ name: "compound_page_viewed";
399
+ lessonId?: LessonId;
400
+ data: CompoundPageViewedData;
401
+ }) | (BuildTelemetryEventContext & {
402
+ name: "hotspot_opened";
403
+ lessonId?: LessonId;
404
+ data: HotspotOpenedData;
405
+ }) | (BuildTelemetryEventContext & {
406
+ name: "accordion_section_toggled";
407
+ lessonId?: LessonId;
408
+ data: AccordionSectionToggledData;
409
+ }) | (BuildTelemetryEventContext & {
410
+ name: "flashcard_flipped";
411
+ lessonId?: LessonId;
412
+ data: FlashcardFlippedData;
413
+ }) | (BuildTelemetryEventContext & {
414
+ name: "image_slider_changed";
415
+ lessonId?: LessonId;
416
+ data: ImageSliderChangedData;
417
+ }) | (BuildTelemetryEventContext & {
418
+ name: "video_cue_reached";
419
+ lessonId?: LessonId;
420
+ data: VideoCueReachedData;
421
+ }) | (BuildTelemetryEventContext & {
422
+ name: "video_segment_completed";
423
+ lessonId?: LessonId;
424
+ data: VideoSegmentCompletedData;
425
+ }) | (BuildTelemetryEventContext & {
426
+ name: "memory_card_flipped";
427
+ lessonId?: LessonId;
428
+ data: MemoryCardFlippedData;
429
+ }) | (BuildTelemetryEventContext & {
430
+ name: "information_wall_search";
431
+ lessonId?: LessonId;
432
+ data: InformationWallSearchData;
433
+ }) | (BuildTelemetryEventContext & {
434
+ name: "parallax_slide_viewed";
435
+ lessonId?: LessonId;
436
+ data: ParallaxSlideViewedData;
437
+ }) | (BuildTelemetryEventContext & {
438
+ name: "questionnaire_submitted";
439
+ lessonId?: LessonId;
440
+ data: QuestionnaireSubmittedData;
441
+ }) | (BuildTelemetryEventContext & {
442
+ name: "branch_node_viewed";
443
+ lessonId?: LessonId;
444
+ data: BranchNodeViewedData;
445
+ }) | (BuildTelemetryEventContext & {
446
+ name: "branch_selected";
447
+ lessonId?: LessonId;
448
+ data: BranchSelectedData;
449
+ });
450
+
451
+ /** Reset dev-warning state (tests only). */
452
+ declare function resetTelemetryBuilderWarningsForTests(): void;
453
+ /**
454
+ * Build a typed telemetry event from a catalog event name and context.
455
+ * Validates lesson-scoped events require `lessonId`.
456
+ */
457
+ declare function buildTelemetryEvent(opts: BuildTelemetryEventInput): TelemetryEvent;
458
+ /**
459
+ * Like `buildTelemetryEvent`, but returns null when lesson-scoped events lack `lessonId`
460
+ * (with dev warnings for quiz/assessment events).
461
+ */
462
+ declare function tryBuildTelemetryEvent(opts: BuildTelemetryEventInput): TelemetryEvent | null;
463
+
464
+ type ProgressState = {
465
+ activeLessonId?: LessonId;
466
+ completedLessonIds: ReadonlySet<LessonId>;
467
+ courseCompleted: boolean;
468
+ };
469
+ type ProgressController = {
470
+ getState: () => ProgressState;
471
+ setActiveLesson: (lessonId: LessonId, startedAtMs: number) => {
472
+ previousLessonId?: LessonId;
473
+ };
474
+ completeLesson: (lessonId: LessonId, completedAtMs: number) => {
475
+ durationMs?: number;
476
+ didComplete: boolean;
477
+ };
478
+ completeCourse: () => {
479
+ didComplete: boolean;
480
+ };
481
+ };
482
+ declare function createProgressController(): ProgressController;
483
+
484
+ declare const SESSION_STORAGE_KEY = "lessonkit:sessionId";
485
+ declare function getTabSessionId(storage: StoragePort): string | null;
486
+ declare function resolveSessionId(storage: StoragePort, provided?: string): string;
487
+ declare function hasCourseStarted(storage: StoragePort, sessionId: string, courseId?: CourseId): boolean;
488
+ declare function markCourseStarted(storage: StoragePort, sessionId: string, courseId?: CourseId): boolean;
489
+ declare function hasCourseStartedEmittedToTracking(storage: StoragePort, sessionId: string, courseId?: CourseId): boolean;
490
+ declare function markCourseStartedEmittedToTracking(storage: StoragePort, sessionId: string, courseId?: CourseId): boolean;
491
+ declare function hasCourseStartedPipelineDelivered(storage: StoragePort, sessionId: string, courseId?: CourseId): boolean;
492
+ declare function markCourseStartedPipelineDelivered(storage: StoragePort, sessionId: string, courseId?: CourseId): boolean;
493
+ declare function hasCourseStartedXapiSent(storage: StoragePort, sessionId: string, courseId?: CourseId): boolean;
494
+ declare function markCourseStartedXapiSent(storage: StoragePort, sessionId: string, courseId?: CourseId): boolean;
495
+ /** @internal Reset volatile session ids between tests. */
496
+ declare function resetSharedVolatileSessionIdForTests(): void;
497
+ declare function migrateCourseStartedMark(storage: StoragePort, fromSessionId: string, toSessionId: string, courseId?: CourseId): void;
498
+
499
+ /** Plugin category — aligns with roadmap extension areas. */
500
+ type LessonkitPluginKind = "analytics" | "lms" | "assessment" | "interaction" | "ai";
501
+ type LessonkitPluginContext = {
502
+ courseId: CourseId;
503
+ sessionId?: string;
504
+ attemptId?: string;
505
+ user?: TelemetryUser;
506
+ };
507
+ type AssessmentScoreInput = {
508
+ checkId: CheckId;
509
+ lessonId?: LessonId;
510
+ response: unknown;
511
+ };
512
+ type AssessmentScoreResult = {
513
+ score: number;
514
+ maxScore?: number;
515
+ passed?: boolean;
516
+ feedback?: string;
517
+ };
518
+ /** Metadata for custom interaction blocks (renderer wiring stays in app code until 1.0). */
519
+ type InteractionBlockRegistration = {
520
+ blockType: string;
521
+ catalogVersion?: string;
522
+ description?: string;
523
+ };
524
+ type PluginIdentity = {
525
+ id: string;
526
+ version: string;
527
+ kind: LessonkitPluginKind;
528
+ name?: string;
529
+ };
530
+ /** Narrow telemetry plugin contract (ISP). */
531
+ type TelemetryPlugin = PluginIdentity & {
532
+ onTelemetry?: (event: TelemetryEvent, ctx: LessonkitPluginContext) => TelemetryEvent | null;
533
+ onTelemetryBatch?: (events: TelemetryEvent[], ctx: LessonkitPluginContext) => void;
534
+ wrapTrackingSink?: (sink: TelemetrySink, ctx: LessonkitPluginContext) => TelemetrySink;
535
+ };
536
+ /** Narrow lifecycle plugin contract (ISP). */
537
+ type LifecyclePlugin = PluginIdentity & {
538
+ setup?: (ctx: LessonkitPluginContext) => void;
539
+ dispose?: () => void;
540
+ };
541
+ /** Narrow assessment plugin contract (ISP). */
542
+ type AssessmentPlugin = PluginIdentity & {
543
+ kind: "assessment";
544
+ scoreAssessment?: (input: AssessmentScoreInput, ctx: LessonkitPluginContext) => AssessmentScoreResult | null;
545
+ };
546
+ /**
547
+ * Narrow interaction metadata plugin (ISP).
548
+ * @experimental Not wired into PluginHost; reserved for a future release.
549
+ */
550
+ type InteractionPlugin = PluginIdentity & {
551
+ interactionBlocks?: InteractionBlockRegistration[];
552
+ };
553
+ /**
554
+ * Combined plugin contract (v1). Prefer segregated types for new plugins.
555
+ * @deprecated Prefer `TelemetryPlugin`, `AssessmentPlugin`, or `LifecyclePlugin` via `define*Plugin`.
556
+ */
557
+ type LessonkitPlugin = PluginIdentity & Partial<Pick<TelemetryPlugin, "onTelemetry" | "onTelemetryBatch" | "wrapTrackingSink"> & Pick<LifecyclePlugin, "setup" | "dispose"> & Pick<AssessmentPlugin, "scoreAssessment"> & Pick<InteractionPlugin, "interactionBlocks">>;
558
+ type PluginHost = {
559
+ readonly plugins: readonly LessonkitPlugin[];
560
+ setupAll: (ctx: LessonkitPluginContext) => void;
561
+ disposeAll: () => void;
562
+ runTelemetry: (event: TelemetryEvent, ctx: LessonkitPluginContext) => TelemetryEvent | null;
563
+ runTelemetryBatch: (events: TelemetryEvent[], ctx: LessonkitPluginContext) => TelemetryEvent[];
564
+ deliverTelemetryBatch: (events: TelemetryEvent[], ctx: LessonkitPluginContext) => TelemetryEvent[];
565
+ composeTrackingSink: (sink: TelemetrySink | undefined, ctx: LessonkitPluginContext | (() => LessonkitPluginContext)) => TelemetrySink | undefined;
566
+ scoreAssessment: (input: AssessmentScoreInput, ctx: LessonkitPluginContext) => AssessmentScoreResult | null;
567
+ };
568
+ /** Segregated plugin registry (ISP + SRP). */
569
+ type PluginRegistry = PluginHost;
570
+
571
+ /** @internal Reset in-flight course_started guard between tests. */
572
+ declare function resetCourseStartedEmitFlightForTests(): void;
573
+ type CourseLifecycleContext = {
574
+ courseId: CourseId;
575
+ sessionId: string;
576
+ attemptId?: string;
577
+ user?: TelemetryUser;
578
+ storage: StoragePort;
579
+ pluginHost: PluginRegistry | null;
580
+ lxpackBridge: "auto" | "off";
581
+ };
582
+ type CourseLifecycleDeps = {
583
+ emitCourseStartedEvent: (ctx: CourseLifecycleContext) => boolean;
584
+ };
585
+ /**
586
+ * Emit `course_started` once per tab session when tracking/xAPI are active.
587
+ * Coalesces concurrent calls via an in-flight guard.
588
+ */
589
+ declare function tryEmitCourseStarted(ctx: CourseLifecycleContext, deps: CourseLifecycleDeps, alreadyEmittedToSink: boolean): Promise<{
590
+ emitted: boolean;
591
+ marked: boolean;
592
+ }>;
593
+ declare function buildCourseStartedTelemetryEvent(ctx: CourseLifecycleContext): TelemetryEvent;
594
+ type LessonCompletionEmitter = (lessonId: LessonId, durationMs?: number) => void;
595
+ declare function completeLessonWithTelemetry(opts: {
596
+ progress: ProgressController;
597
+ lessonId: LessonId;
598
+ nowMs: number;
599
+ emitLessonCompleted: LessonCompletionEmitter;
600
+ }): boolean;
601
+ declare function completeCourseWithTelemetry(opts: {
602
+ progress: ProgressController;
603
+ nowMs: number;
604
+ emitLessonCompleted: LessonCompletionEmitter;
605
+ emitCourseCompleted: () => void;
606
+ }): boolean;
607
+
608
+ export { type LessonCompletionEmitter as $, type AssessmentResumeState as A, type BlockId as B, type CourseId as C, type AssessmentInteractionType as D, type AssessmentXAPIData as E, type BookPageViewedData as F, type BranchNodeViewedData as G, type BranchSelectedData as H, type IdentityIdPath as I, type BuildTelemetryEventInput as J, type CompoundPageViewedData as K, type LessonId as L, type CourseLifecycleContext as M, type CourseLifecycleDeps as N, type FlashcardFlippedData as O, type PluginRegistry as P, type HotspotOpenedData as Q, ID_MAX_LENGTH as R, type StoragePort as S, type TelemetryEventName as T, ID_PATTERN as U, type IdentityValidationIssue as V, type ImageSliderChangedData as W, type InformationWallSearchData as X, type InteractionBlockRegistration as Y, type InteractionData as Z, type InteractionPlugin as _, type CheckId as a, type LessonLifecycleData as a0, type LessonkitPluginKind as a1, type McqAssessmentProps as a2, type MemoryCardFlippedData as a3, type ParallaxSlideViewedData as a4, type PluginIdentity as a5, type QuestionnaireSubmittedData as a6, type QuizAnsweredData as a7, type QuizCompletedData as a8, SESSION_STORAGE_KEY as a9, resetTelemetryBuilderWarningsForTests as aA, resolveSessionId as aB, tryBuildTelemetryEvent as aC, tryEmitCourseStarted as aD, resetCourseStartedEmitFlightForTests as aE, type SlideViewedData as aa, type TelemetryEventBase as ab, type TimerPort as ac, type VideoCueReachedData as ad, type VideoSegmentCompletedData as ae, buildCourseStartedTelemetryEvent as af, buildTelemetryEvent as ag, completeCourseWithTelemetry as ah, completeLessonWithTelemetry as ai, createDefaultClock as aj, createGlobalTimer as ak, createNoopStorage as al, createProgressController as am, createSessionStoragePort as an, getTabSessionId as ao, hasCourseStarted as ap, hasCourseStartedEmittedToTracking as aq, hasCourseStartedPipelineDelivered as ar, hasCourseStartedXapiSent as as, markCourseStarted as at, markCourseStartedEmittedToTracking as au, markCourseStartedPipelineDelivered as av, markCourseStartedXapiSent as aw, migrateCourseStartedMark as ax, resetSharedVolatileSessionIdForTests as ay, resetStoragePortForTests as az, type IdentityValidationResult as b, type LessonkitUrn as c, type TelemetrySink as d, type TelemetryBatchSink as e, type TrackingClient as f, type TelemetryEvent as g, type TelemetryUser as h, type LessonkitPlugin as i, type ProgressController as j, type PluginHost as k, type ProgressState as l, type TelemetryDataFor as m, type AssessmentScoreInput as n, type AssessmentScoreResult as o, type ClockPort as p, type AssessmentPlugin as q, type LifecyclePlugin as r, type TelemetryPlugin as s, type LessonkitPluginContext as t, type AccordionSectionToggledData as u, type AssessmentAnsweredData as v, type AssessmentBaseProps as w, type AssessmentBehaviour as x, type AssessmentCompletedData as y, type AssessmentHandle as z };