@brighterly/lib-assessment
v1.1.0
Published
Brighterly assessment player: engine, player state machine and renderers, host-agnostic
Keywords
Readme
@brighterly/lib-assessment
The Brighterly assessment player: the engine (schema, graders, [[token]] templates), the
player state machine and the question renderers, as one Vue 3 package.
It knows nothing about the app that mounts it: no auth, no kid, no routing, no analytics SDK. Everything it waits on comes from a host object; everything it reports goes out as events. Used by app-student (the standalone player) and cs-app (the classroom), and, in readonly mode, by the tutor's live view and the screen recorder.
Install
pnpm add @brighterly/[email protected] # pin exactly — no ^Peer dependencies: vue ^3.5, @vueuse/core ^14, katex ^0.17, @brighterly/lib-core-types >=0.57.1.
The host loads three stylesheets once, globally:
import '@brighterly/lib-lumee-ui/dist/client.css' // the --btly-* tokens the player uses
import 'katex/dist/katex.min.css'
import '@brighterly/lib-assessment/style.css'Live mode
<script setup lang="ts">
import { AssessmentPlayer, createStudentApi, type AssessmentHost } from '@brighterly/lib-assessment'
const host: AssessmentHost = {
api: createStudentApi({
request: (path, init) => myStudentApiFetch(path, init), // your base URL + bearer
kidId: () => activeKidId(),
}),
uploads: {
audio: (scope, blob, mimeType) => uploadAudio(scope, blob, mimeType), // → stored object path
photo: (scope, photo) => uploadPhoto(scope, photo), // → stored object path
remove: (scope, kind) => removeUpload(scope, kind),
},
// The package stops this track when a take ends. In a call, hand it a clone of the
// call's mic track, so stopping it keeps the call's mic.
audioSource: async () => (await navigator.mediaDevices.getUserMedia({ audio: true })).getAudioTracks()[0]!,
mediaUrl: path => `${MEDIA_BASE}/${path}`,
track: ({ name, props }) => amplitude.track(WIRE_NAMES[name], { ...props, kid_id, booking_id }),
}
</script>
<template>
<AssessmentPlayer
:assessment-id="id"
:kid-name="kidName"
:host="host"
@change="state => broadcast(state)"
@status="status => …"
@finish="goHome"
@error="message => …"
/>
</template>| Prop | Type | |
|---|---|---|
| assessmentId | string | the assessment instance id |
| kidName | string | fills [[kid_name]] |
| mode | 'live' \| 'readonly' | default live |
| host | AssessmentHost | required in live mode |
| state | AssessmentState | readonly only: the state to draw |
| Event | Payload | When |
|---|---|---|
| change | AssessmentState | every answer, navigation, load and submit |
| status | PlayerStatus | every status change |
| finish | — | the kid pressed "Continue learning" on the last screen |
| error | string | the status became error; the message is kid-safe |
Readonly mode
<AssessmentPlayer assessment-id="3" kid-name="Mia" mode="readonly" :state="stateFromTheKid" />It makes no requests (other than the media files it shows), plays no sound and takes no
input: the screen is inert. AssessmentState is plain JSON — a format version, the
assignment, the stored definition, the answers (audio answers without their in-memory
blob), the screen index, the signed media map and the player's size.
Layout
The player sizes itself by its container, not the window (container-name: assessment):
give it a box with a width and a height, a page or a classroom stage.
Analytics
The package calls host.track({ name, props }) with domain names and assessment facts
only. The host maps the names to its own wire names and adds the kid, discipline and
booking. The names are provisional until analytics signs them off.
| Name | When | Extra props |
|---|---|---|
| assessment_opened | the load resolved | |
| assessment_started | the start resolved | |
| assessment_answered | 600 ms after the last edit of an answer | question_number, interaction, response_kind |
| assessment_submitted | the submit resolved | answered_count |
| assessment_failed | the status became error | error |
Every event carries assessment_id, status, discipline, grade_label, screen_idx,
total_screens. Readonly mode tracks nothing.
Development
pnpm install # also points git at _tools/git: the pre-commit hook runs codestyle precommit
pnpm invariants # codestyle check (@brighterly/lib-fe-codestyle rules)
pnpm validate # codestyle validate: invariants, lint, typecheck, test, build
pnpm playground # http://localhost:5199 — a live player beside a readonly copy, fake hostCI is .github/workflows/publish.yml, the @brighterly/lib-fe-codestyle pattern: pnpm validate
on every PR and push to main; on main, when npm does not have the package.json version
yet, the validated dist/ is published (needs the NPM_TOKEN secret). Release = a version
bump merged to main.
