Plugins reference¶
LessonKit plugin architecture (v1)¶
LessonKit plugins extend the runtime without forking @lessonkit/react. They register on
LessonkitProvider via config.plugins and run in a deterministic order.
Plugin kinds¶
Kind |
Purpose |
Typical hooks |
|---|---|---|
|
Forward or transform telemetry |
|
|
LMS-specific session/completion (future) |
|
|
Custom scoring engines |
|
|
Declare custom block types |
|
|
AI-assisted flows (future) |
|
Lifecycle¶
Register — pass
plugins: LessonkitPlugin[]onLessonkitProvider/<Course config={…}>.Setup —
setup(ctx)runs when the provider mounts and whencourseId,session.sessionId,session.attemptId, orsession.userchanges (ctxincludescourseId,sessionId,attemptId).Runtime — telemetry flows through
onTelemetryin registration order (returnnullto drop an event for delivery; downstream plugins’onTelemetryhooks are not called after anull). Register filters before enrichers. Then tracking/xAPI/LXPack bridge.Dispose —
dispose()runs in reverse registration order on unmount.
Constraints (v1)¶
Plugins are bundled with your app (static import). Dynamic loading and a marketplace are post–Studio 1.0.
onTelemetryis synchronous; keep work fast or enqueue to your own service.Custom interaction blocks require you to render React components;
interactionBlocksis metadata for tooling.Plugins must use stable
idstrings (reverse-DNS recommended, e.g.com.example.analytics).onTelemetryBatchruns when you configuretracking.batchSink(the provider wraps your batch sink and applieswrapTrackingSinkper event before yourbatchSink). Batched flushes that only usetracking.sinkdo not invokeonTelemetryBatch.If both
tracking.sinkandtracking.batchSinkare set, flushed batches use onlybatchSink(per-eventsinkis not called for buffered events).
API surface¶
Types and helpers live in @lessonkit/core (re-exported from @lessonkit/react):
LessonkitPlugin,LessonkitPluginKind,LessonkitPluginContextcreatePluginRegistry(),defineTelemetryPlugin(),defineAssessmentPlugin(),defineLifecyclePlugin()useLessonkit().plugins— the activePluginRegistry(ornull)
Example¶
import { defineTelemetryPlugin } from "@lessonkit/react";
const myAnalytics = defineTelemetryPlugin({
id: "com.example.analytics",
version: "1.0.0",
kind: "analytics",
onTelemetry(event) {
if (event.name === "course_completed") {
void fetch("/api/telemetry", {
method: "POST",
body: JSON.stringify(event),
});
}
return event;
},
});
<Course courseId="my-course" config={{ plugins: [myAnalytics] }}>...</Course>
See Plugin cookbook for a full walkthrough.