@pie-qti/assessment-player 0.1.5 → 0.1.7
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/core/AssessmentPlayer.d.ts +27 -5
- package/dist/core/AssessmentPlayer.d.ts.map +1 -1
- package/dist/core/AssessmentPlayer.js +211 -20
- package/dist/integration/ReferenceBackendAdapter.d.ts +1 -7
- package/dist/integration/ReferenceBackendAdapter.d.ts.map +1 -1
- package/dist/integration/ReferenceBackendAdapter.js +144 -61
- package/dist/integration/api-contract.d.ts +39 -11
- package/dist/integration/api-contract.d.ts.map +1 -1
- package/dist/integration/assessment-item-scorer.d.ts +14 -0
- package/dist/integration/assessment-item-scorer.d.ts.map +1 -0
- package/dist/integration/assessment-item-scorer.js +43 -0
- package/dist/integration/index.d.ts +2 -1
- package/dist/integration/index.d.ts.map +1 -1
- package/dist/integration/index.js +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/components/AccessibilityAnnouncer.svelte +13 -2
- package/src/components/AssessmentShell.svelte +22 -39
- package/src/components/AssessmentTimer.svelte +23 -0
- package/src/components/ItemRenderer.svelte +14 -4
- package/src/components/NavigationBar.svelte +2 -0
- package/src/components/SectionMenu.svelte +72 -5
- package/src/core/AssessmentPlayer.ts +249 -23
- package/src/integration/ReferenceBackendAdapter.ts +155 -65
- package/src/integration/api-contract.ts +42 -11
- package/src/integration/assessment-item-scorer.ts +58 -0
- package/src/integration/index.ts +7 -0
- package/src/types/index.ts +3 -0
|
@@ -41,7 +41,11 @@ import {
|
|
|
41
41
|
qtiNull,
|
|
42
42
|
qtiValue,
|
|
43
43
|
} from '@pie-qti/qti-processing';
|
|
44
|
-
import {
|
|
44
|
+
import {
|
|
45
|
+
createResolvedItemDeliveryContext,
|
|
46
|
+
extractAssessmentStimulusRefs,
|
|
47
|
+
resolveRelativePath as resolveQtiRelativePath,
|
|
48
|
+
} from '@pie-qti/ims-cp-core';
|
|
45
49
|
import { parse } from 'node-html-parser';
|
|
46
50
|
import type {
|
|
47
51
|
AssessmentSessionState,
|
|
@@ -63,6 +67,7 @@ import type {
|
|
|
63
67
|
SubmitResponsesRequest,
|
|
64
68
|
SubmitResponsesResponse,
|
|
65
69
|
} from './api-contract.js';
|
|
70
|
+
import { scoreAssessmentItem } from './assessment-item-scorer.js';
|
|
66
71
|
|
|
67
72
|
/**
|
|
68
73
|
* Storage key prefix for localStorage
|
|
@@ -142,6 +147,22 @@ export class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
142
147
|
return this.registeredAssessments.get(assessmentId) ?? this.createDemoAssessment(assessmentId);
|
|
143
148
|
}
|
|
144
149
|
|
|
150
|
+
private hasAnyResponse(responses: Record<string, unknown>): boolean {
|
|
151
|
+
for (const value of Object.values(responses)) {
|
|
152
|
+
if (value == null) continue;
|
|
153
|
+
if (Array.isArray(value)) {
|
|
154
|
+
if (value.length > 0) return true;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (typeof value === 'string') {
|
|
158
|
+
if (value.trim().length > 0) return true;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
|
|
145
166
|
/**
|
|
146
167
|
* Initialize a new assessment session
|
|
147
168
|
*/
|
|
@@ -174,6 +195,7 @@ export class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
174
195
|
visitedItems: [],
|
|
175
196
|
itemResponses: {},
|
|
176
197
|
itemScores: {},
|
|
198
|
+
itemSessions: {},
|
|
177
199
|
timing: {
|
|
178
200
|
startedAt: Date.now(),
|
|
179
201
|
itemTimes: {},
|
|
@@ -218,6 +240,34 @@ export class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
218
240
|
};
|
|
219
241
|
}
|
|
220
242
|
|
|
243
|
+
const receivedAt = Date.now();
|
|
244
|
+
const assessmentLimit = session.assessment.timeLimits;
|
|
245
|
+
const effectiveAssessmentLimitSeconds =
|
|
246
|
+
request.timing?.scope === 'assessment' && request.timing.limitSeconds !== undefined
|
|
247
|
+
? request.timing.limitSeconds
|
|
248
|
+
: assessmentLimit?.maxTime;
|
|
249
|
+
const assessmentAllowsLate = assessmentLimit?.allowLateSubmission ?? request.timing?.allowLateSubmission;
|
|
250
|
+
if (
|
|
251
|
+
effectiveAssessmentLimitSeconds !== undefined &&
|
|
252
|
+
assessmentAllowsLate !== true &&
|
|
253
|
+
receivedAt - session.createdAt > effectiveAssessmentLimitSeconds * 1000
|
|
254
|
+
) {
|
|
255
|
+
return {
|
|
256
|
+
success: false,
|
|
257
|
+
error: 'Assessment time limit expired',
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const evidenceExpired =
|
|
262
|
+
request.timing?.limitSeconds !== undefined &&
|
|
263
|
+
request.timing.elapsedMs >= request.timing.limitSeconds * 1000;
|
|
264
|
+
if (evidenceExpired && request.timing?.allowLateSubmission !== true) {
|
|
265
|
+
return {
|
|
266
|
+
success: false,
|
|
267
|
+
error: 'Time limit expired',
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
221
271
|
// Find the item XML
|
|
222
272
|
const itemXml = this.findItemXml(session.assessment, request.itemIdentifier);
|
|
223
273
|
if (!itemXml) {
|
|
@@ -229,7 +279,7 @@ export class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
229
279
|
|
|
230
280
|
// **SECURITY WARNING**: Client-side scoring is INSECURE
|
|
231
281
|
// In production, this MUST be done server-side
|
|
232
|
-
const result =
|
|
282
|
+
const result = scoreAssessmentItem({ itemXml, responses: request.responses, itemSession: request.itemSession });
|
|
233
283
|
|
|
234
284
|
// Store responses and result
|
|
235
285
|
session.state.itemResponses[request.itemIdentifier] = request.responses;
|
|
@@ -237,6 +287,23 @@ export class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
237
287
|
session.state.itemScores = {};
|
|
238
288
|
}
|
|
239
289
|
session.state.itemScores[request.itemIdentifier] = result;
|
|
290
|
+
if (request.itemSession) {
|
|
291
|
+
session.state.itemSessions = {
|
|
292
|
+
...(session.state.itemSessions ?? {}),
|
|
293
|
+
[request.itemIdentifier]: request.itemSession,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
const previousItemSession = session.state.itemSessionStates?.[request.itemIdentifier];
|
|
297
|
+
session.state.itemSessionStates = {
|
|
298
|
+
...(session.state.itemSessionStates ?? {}),
|
|
299
|
+
[request.itemIdentifier]: {
|
|
300
|
+
itemIdentifier: request.itemIdentifier,
|
|
301
|
+
attemptCount: (previousItemSession?.attemptCount ?? 0) + 1,
|
|
302
|
+
isAnswered: this.hasAnyResponse(request.responses),
|
|
303
|
+
isSubmitted: true,
|
|
304
|
+
lastSubmissionTime: request.submittedAt,
|
|
305
|
+
},
|
|
306
|
+
};
|
|
240
307
|
|
|
241
308
|
// Update timing
|
|
242
309
|
if (request.timeSpent) {
|
|
@@ -544,51 +611,6 @@ export class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
544
611
|
return null;
|
|
545
612
|
}
|
|
546
613
|
|
|
547
|
-
/**
|
|
548
|
-
* Score an item using the Player
|
|
549
|
-
*
|
|
550
|
-
* **SECURITY WARNING**: This is done CLIENT-SIDE for demo purposes only.
|
|
551
|
-
* Production implementations MUST perform scoring SERVER-SIDE.
|
|
552
|
-
*/
|
|
553
|
-
private scoreItem(itemXml: string, responses: Record<string, any>): AssessmentScoringResult {
|
|
554
|
-
try {
|
|
555
|
-
// Extract identifier from XML using regex (more reliable than DOM parsing)
|
|
556
|
-
const identifierMatch = itemXml.match(/assessmentItem[^>]+identifier=["']([^"']+)["']/);
|
|
557
|
-
const itemIdentifier = identifierMatch?.[1] || 'unknown';
|
|
558
|
-
|
|
559
|
-
// Use a scorer-grade view of the item for accurate scoring.
|
|
560
|
-
// NOTE: This reference adapter is intentionally insecure and runs client-side.
|
|
561
|
-
// In production, scoring must happen server-side with secured item content.
|
|
562
|
-
const player = new Player({
|
|
563
|
-
itemXml,
|
|
564
|
-
role: 'scorer',
|
|
565
|
-
});
|
|
566
|
-
|
|
567
|
-
// Set responses using setResponses (plural)
|
|
568
|
-
player.setResponses(responses);
|
|
569
|
-
|
|
570
|
-
// Process and score
|
|
571
|
-
const result = player.processResponses();
|
|
572
|
-
|
|
573
|
-
return {
|
|
574
|
-
itemIdentifier,
|
|
575
|
-
score: result.score,
|
|
576
|
-
maxScore: result.maxScore,
|
|
577
|
-
completed: result.completed,
|
|
578
|
-
outcomeValues: result.outcomeValues,
|
|
579
|
-
};
|
|
580
|
-
} catch (error) {
|
|
581
|
-
console.error('Scoring error:', error);
|
|
582
|
-
return {
|
|
583
|
-
itemIdentifier: 'unknown',
|
|
584
|
-
score: 0,
|
|
585
|
-
maxScore: 1,
|
|
586
|
-
completed: false,
|
|
587
|
-
outcomeValues: {},
|
|
588
|
-
};
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
|
|
592
614
|
/**
|
|
593
615
|
* Create demo assessment for testing
|
|
594
616
|
*
|
|
@@ -779,14 +801,83 @@ export class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
779
801
|
};
|
|
780
802
|
};
|
|
781
803
|
|
|
804
|
+
const parseTimeLimits = (el: Element): SecureAssessment['timeLimits'] | undefined => {
|
|
805
|
+
const limitsEl = childrenByTag(el, 'timeLimit')[0] ?? childrenByTag(el, 'timeLimits')[0];
|
|
806
|
+
if (!limitsEl) return undefined;
|
|
807
|
+
const numberAttr = (name: string): number | undefined => {
|
|
808
|
+
const value = getAttr(limitsEl, name);
|
|
809
|
+
if (value === undefined) return undefined;
|
|
810
|
+
const parsed = Number(value);
|
|
811
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
812
|
+
};
|
|
813
|
+
const boolAttr = (name: string): boolean | undefined => {
|
|
814
|
+
const value = getAttr(limitsEl, name);
|
|
815
|
+
return value === undefined ? undefined : value === 'true';
|
|
816
|
+
};
|
|
817
|
+
return {
|
|
818
|
+
minTime: numberAttr('minTime'),
|
|
819
|
+
maxTime: numberAttr('maxTime'),
|
|
820
|
+
allowLateSubmission: boolAttr('allowLateSubmission'),
|
|
821
|
+
};
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
const resolveAgainstBase = (href: string | undefined): string | undefined => {
|
|
825
|
+
if (!href) return undefined;
|
|
826
|
+
return baseUrl ? resolveQtiRelativePath(baseUrl, href) : href;
|
|
827
|
+
};
|
|
828
|
+
|
|
829
|
+
const loadText = async (href: string | undefined): Promise<string | undefined> => {
|
|
830
|
+
if (!href) return undefined;
|
|
831
|
+
const candidates = [href, resolveAgainstBase(href)].filter((value, index, all): value is string =>
|
|
832
|
+
Boolean(value) && all.indexOf(value) === index
|
|
833
|
+
);
|
|
834
|
+
for (const candidate of candidates) {
|
|
835
|
+
if (itemXmlMap[candidate] !== undefined) {
|
|
836
|
+
return itemXmlMap[candidate];
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
if (!fileResolver) return undefined;
|
|
840
|
+
for (const candidate of candidates) {
|
|
841
|
+
try {
|
|
842
|
+
return await fileResolver(candidate);
|
|
843
|
+
} catch {
|
|
844
|
+
// Try the next candidate before giving up.
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
return undefined;
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
const buildDeliveryContext = async (
|
|
851
|
+
itemXml: string,
|
|
852
|
+
itemHref: string | undefined
|
|
853
|
+
): Promise<SecureItemRef['deliveryContext'] | undefined> => {
|
|
854
|
+
if (!itemHref || extractAssessmentStimulusRefs(itemXml).length === 0) {
|
|
855
|
+
return undefined;
|
|
856
|
+
}
|
|
857
|
+
const stimulusXmlByPath: Record<string, string> = {};
|
|
858
|
+
for (const ref of extractAssessmentStimulusRefs(itemXml)) {
|
|
859
|
+
const stimulusPath = resolveQtiRelativePath(itemHref, ref.href);
|
|
860
|
+
const stimulusXml = await loadText(stimulusPath);
|
|
861
|
+
if (stimulusXml) {
|
|
862
|
+
stimulusXmlByPath[stimulusPath] = stimulusXml;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
return createResolvedItemDeliveryContext({
|
|
866
|
+
itemXml,
|
|
867
|
+
itemHref,
|
|
868
|
+
readText: (path) => stimulusXmlByPath[path] ?? itemXmlMap[path],
|
|
869
|
+
});
|
|
870
|
+
};
|
|
871
|
+
|
|
782
872
|
// Parse a single assessmentSection element
|
|
783
|
-
const parseSection = (sectionEl: Element): SecureSection => {
|
|
873
|
+
const parseSection = async (sectionEl: Element): Promise<SecureSection> => {
|
|
784
874
|
const identifier = getAttr(sectionEl, 'identifier') ?? 'section';
|
|
785
875
|
const title = getAttr(sectionEl, 'title');
|
|
786
876
|
const visibleRaw = getAttr(sectionEl, 'visible');
|
|
787
877
|
const visible = visibleRaw === undefined ? true : visibleRaw !== 'false';
|
|
788
878
|
|
|
789
879
|
const itemSessionControl = parseItemSessionControl(sectionEl);
|
|
880
|
+
const timeLimits = parseTimeLimits(sectionEl);
|
|
790
881
|
|
|
791
882
|
// rubricBlocks
|
|
792
883
|
const rubricBlockEls = childrenByTag(sectionEl, 'rubricBlock');
|
|
@@ -801,20 +892,24 @@ export class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
801
892
|
|
|
802
893
|
// assessmentItemRefs
|
|
803
894
|
const itemRefEls = childrenByTag(sectionEl, 'assessmentItemRef');
|
|
804
|
-
const assessmentItemRefs: SecureItemRef[] =
|
|
895
|
+
const assessmentItemRefs: SecureItemRef[] = [];
|
|
896
|
+
for (const ref of itemRefEls) {
|
|
805
897
|
const itemId = getAttr(ref, 'identifier') ?? 'item';
|
|
806
898
|
const href = getAttr(ref, 'href');
|
|
899
|
+
const itemHref = resolveAgainstBase(href) ?? href;
|
|
807
900
|
// Look up pre-loaded XML by identifier or href
|
|
808
|
-
const resolvedXml = itemXmlMap[itemId] ?? (href ? itemXmlMap[href] : undefined) ?? '';
|
|
901
|
+
const resolvedXml = itemXmlMap[itemId] ?? (href ? itemXmlMap[href] : undefined) ?? (itemHref ? itemXmlMap[itemHref] : undefined) ?? (await loadText(href)) ?? '';
|
|
809
902
|
const requiredRaw = getAttr(ref, 'required');
|
|
810
903
|
const required = requiredRaw === undefined ? undefined : requiredRaw !== 'false';
|
|
811
|
-
|
|
904
|
+
assessmentItemRefs.push({
|
|
812
905
|
identifier: itemId,
|
|
813
906
|
itemXml: resolvedXml,
|
|
814
907
|
role,
|
|
815
908
|
required,
|
|
816
|
-
|
|
817
|
-
|
|
909
|
+
timeLimits: parseTimeLimits(ref),
|
|
910
|
+
deliveryContext: await buildDeliveryContext(resolvedXml, itemHref),
|
|
911
|
+
});
|
|
912
|
+
}
|
|
818
913
|
|
|
819
914
|
return {
|
|
820
915
|
identifier,
|
|
@@ -823,6 +918,7 @@ export class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
823
918
|
assessmentItemRefs,
|
|
824
919
|
rubricBlocks,
|
|
825
920
|
itemSessionControl,
|
|
921
|
+
timeLimits,
|
|
826
922
|
};
|
|
827
923
|
};
|
|
828
924
|
|
|
@@ -866,7 +962,7 @@ export class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
866
962
|
const sections: SecureSection[] = [];
|
|
867
963
|
for (const child of childElements(testPartEl)) {
|
|
868
964
|
if (toCanonicalQtiName(child.localName) === 'assessmentSection') {
|
|
869
|
-
sections.push(parseSection(child));
|
|
965
|
+
sections.push(await parseSection(child));
|
|
870
966
|
} else if (toCanonicalQtiName(child.localName) === 'assessmentSectionRef') {
|
|
871
967
|
const resolved = await resolveSectionRef(child);
|
|
872
968
|
if (resolved) sections.push(resolved);
|
|
@@ -928,16 +1024,8 @@ export class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
928
1024
|
? serializeXml(outcomeProcessingEl)
|
|
929
1025
|
: undefined;
|
|
930
1026
|
|
|
931
|
-
// Extract timeLimits
|
|
932
|
-
const
|
|
933
|
-
const timeLimits = timeLimitsEl
|
|
934
|
-
? {
|
|
935
|
-
maxTime: getAttr(timeLimitsEl, 'maxTime')
|
|
936
|
-
? Number(getAttr(timeLimitsEl, 'maxTime'))
|
|
937
|
-
: undefined,
|
|
938
|
-
allowLateSubmission: getAttr(timeLimitsEl, 'allowLateSubmission') === 'true',
|
|
939
|
-
}
|
|
940
|
-
: undefined;
|
|
1027
|
+
// Extract assessment-level timeLimits.
|
|
1028
|
+
const timeLimits = parseTimeLimits(root);
|
|
941
1029
|
|
|
942
1030
|
// Parse testParts
|
|
943
1031
|
const testPartEls = childrenByTag(root, 'testPart');
|
|
@@ -955,6 +1043,7 @@ export class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
955
1043
|
for (const tp of testPartEls) {
|
|
956
1044
|
const tpIdentifier = getAttr(tp, 'identifier') ?? 'part-1';
|
|
957
1045
|
const tpItemSessionControl = parseTestPartItemSessionControl(tp);
|
|
1046
|
+
const tpTimeLimits = parseTimeLimits(tp);
|
|
958
1047
|
const tpRubricBlockEls = childrenByTag(tp, 'rubricBlock');
|
|
959
1048
|
const tpRubricBlocks = tpRubricBlockEls.length > 0
|
|
960
1049
|
? tpRubricBlockEls.map((b, idx) => ({
|
|
@@ -971,6 +1060,7 @@ export class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
971
1060
|
sections,
|
|
972
1061
|
rubricBlocks: tpRubricBlocks,
|
|
973
1062
|
itemSessionControl: tpItemSessionControl,
|
|
1063
|
+
timeLimits: tpTimeLimits,
|
|
974
1064
|
});
|
|
975
1065
|
}
|
|
976
1066
|
|
|
@@ -979,7 +1069,7 @@ export class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
979
1069
|
const topSections: SecureSection[] = [];
|
|
980
1070
|
for (const child of childElements(root)) {
|
|
981
1071
|
if (toCanonicalQtiName(child.localName) === 'assessmentSection') {
|
|
982
|
-
topSections.push(parseSection(child));
|
|
1072
|
+
topSections.push(await parseSection(child));
|
|
983
1073
|
} else if (toCanonicalQtiName(child.localName) === 'assessmentSectionRef') {
|
|
984
1074
|
const resolved = await resolveSectionRef(child);
|
|
985
1075
|
if (resolved) topSections.push(resolved);
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* that demonstrates the API contract without requiring a real backend.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
import type { QTIRole } from '@pie-qti/item-player';
|
|
20
|
+
import type { QTIRole, ResolvedItemDeliveryContext, SerializedItemSessionState } from '@pie-qti/item-player';
|
|
21
21
|
|
|
22
22
|
// ============================================================================
|
|
23
23
|
// SESSION MANAGEMENT
|
|
@@ -73,6 +73,12 @@ export interface TestFeedbackItem {
|
|
|
73
73
|
content: string;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
export interface SecureTimeLimits {
|
|
77
|
+
minTime?: number;
|
|
78
|
+
maxTime?: number;
|
|
79
|
+
allowLateSubmission?: boolean;
|
|
80
|
+
}
|
|
81
|
+
|
|
76
82
|
export interface SecureAssessment {
|
|
77
83
|
identifier: string;
|
|
78
84
|
title: string;
|
|
@@ -83,10 +89,7 @@ export interface SecureAssessment {
|
|
|
83
89
|
/** Test parts contain sections */
|
|
84
90
|
testParts: SecureTestPart[];
|
|
85
91
|
/** Overall time limit in seconds (optional) */
|
|
86
|
-
timeLimits?:
|
|
87
|
-
maxTime?: number; // seconds
|
|
88
|
-
allowLateSubmission?: boolean;
|
|
89
|
-
};
|
|
92
|
+
timeLimits?: SecureTimeLimits;
|
|
90
93
|
/** QTI outcomeDeclarations for test-level variables */
|
|
91
94
|
outcomeDeclarations?: Array<{
|
|
92
95
|
identifier: string;
|
|
@@ -106,6 +109,8 @@ export interface SecureTestPart {
|
|
|
106
109
|
identifier: string;
|
|
107
110
|
/** Sections contain items */
|
|
108
111
|
sections: SecureSection[];
|
|
112
|
+
/** TestPart-level time limit. */
|
|
113
|
+
timeLimits?: SecureTimeLimits;
|
|
109
114
|
/** Candidate instructions (safe for display) */
|
|
110
115
|
rubricBlocks?: AssessmentRubricBlock[];
|
|
111
116
|
/**
|
|
@@ -131,9 +136,7 @@ export interface SecureSection {
|
|
|
131
136
|
/** Assessment item references (order reflects selection/ordering already applied server-side) */
|
|
132
137
|
assessmentItemRefs: SecureItemRef[];
|
|
133
138
|
/** Section-level time limit */
|
|
134
|
-
timeLimits?:
|
|
135
|
-
maxTime?: number;
|
|
136
|
-
};
|
|
139
|
+
timeLimits?: SecureTimeLimits;
|
|
137
140
|
/** Candidate instructions (safe for display) */
|
|
138
141
|
rubricBlocks?: AssessmentRubricBlock[];
|
|
139
142
|
/**
|
|
@@ -176,6 +179,10 @@ export interface SecureItemRef {
|
|
|
176
179
|
role: QTIRole;
|
|
177
180
|
/** Required=true means item must be attempted */
|
|
178
181
|
required?: boolean;
|
|
182
|
+
/** Item-ref-level time limit. */
|
|
183
|
+
timeLimits?: SecureTimeLimits;
|
|
184
|
+
/** Optional resolved QTI 3 delivery context. Additive; itemXml remains the compatibility path. */
|
|
185
|
+
deliveryContext?: ResolvedItemDeliveryContext;
|
|
179
186
|
/**
|
|
180
187
|
* QTI branchRule: ordered list of branch rules on this item.
|
|
181
188
|
* The backend evaluates these after scoring and returns nextItemIdentifier in SubmitResponsesResponse.
|
|
@@ -220,6 +227,21 @@ export interface SubmitResponsesRequest {
|
|
|
220
227
|
submittedAt: number;
|
|
221
228
|
/** Time spent on item (ms) for analytics */
|
|
222
229
|
timeSpent?: number;
|
|
230
|
+
/** Optional client timing evidence; production backends remain authoritative. */
|
|
231
|
+
timing?: SubmitTimingEvidence;
|
|
232
|
+
/**
|
|
233
|
+
* Serialized item session used by backends to restore template/context variables while scoring.
|
|
234
|
+
* Production backends should treat this as a client save format and validate against server-owned state.
|
|
235
|
+
*/
|
|
236
|
+
itemSession?: SerializedItemSessionState;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export interface SubmitTimingEvidence {
|
|
240
|
+
scope: 'assessment' | 'testPart' | 'section' | 'item';
|
|
241
|
+
elapsedMs: number;
|
|
242
|
+
limitSeconds?: number;
|
|
243
|
+
expired?: boolean;
|
|
244
|
+
allowLateSubmission?: boolean;
|
|
223
245
|
}
|
|
224
246
|
|
|
225
247
|
/**
|
|
@@ -299,9 +321,6 @@ export interface SaveAssessmentStateResponse {
|
|
|
299
321
|
savedAt: number;
|
|
300
322
|
}
|
|
301
323
|
|
|
302
|
-
/**
|
|
303
|
-
* Session state for persistence
|
|
304
|
-
*/
|
|
305
324
|
export interface AssessmentSessionState {
|
|
306
325
|
/** Current item identifier */
|
|
307
326
|
currentItemIdentifier: string;
|
|
@@ -311,6 +330,10 @@ export interface AssessmentSessionState {
|
|
|
311
330
|
itemResponses: Record<string, Record<string, ResponseValue>>;
|
|
312
331
|
/** Scoring results per item (populated after submission) */
|
|
313
332
|
itemScores?: Record<string, AssessmentScoringResult>;
|
|
333
|
+
/** ItemSession lifecycle hints per item, used to restore attempt/review UI state */
|
|
334
|
+
itemSessionStates?: Record<string, AssessmentItemSessionState>;
|
|
335
|
+
/** Rich QTI item session snapshots, used to restore variables and score saved sessions. */
|
|
336
|
+
itemSessions?: Record<string, SerializedItemSessionState>;
|
|
314
337
|
/** Time tracking */
|
|
315
338
|
timing: {
|
|
316
339
|
/** Session start time */
|
|
@@ -322,6 +345,14 @@ export interface AssessmentSessionState {
|
|
|
322
345
|
};
|
|
323
346
|
}
|
|
324
347
|
|
|
348
|
+
export interface AssessmentItemSessionState {
|
|
349
|
+
itemIdentifier: string;
|
|
350
|
+
attemptCount: number;
|
|
351
|
+
isAnswered: boolean;
|
|
352
|
+
isSubmitted: boolean;
|
|
353
|
+
lastSubmissionTime?: number;
|
|
354
|
+
}
|
|
355
|
+
|
|
325
356
|
// ============================================================================
|
|
326
357
|
// FINALIZE ASSESSMENT
|
|
327
358
|
// ============================================================================
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Player, type SerializedItemSessionState } from '@pie-qti/item-player';
|
|
2
|
+
import type { AssessmentScoringResult, ResponseValue } from './api-contract.js';
|
|
3
|
+
|
|
4
|
+
export interface AssessmentItemScoringInput {
|
|
5
|
+
itemXml: string;
|
|
6
|
+
responses: Record<string, ResponseValue>;
|
|
7
|
+
itemSession?: SerializedItemSessionState;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function getAssessmentItemIdentifier(itemXml: string): string {
|
|
11
|
+
const identifierMatch = itemXml.match(/assessmentItem[^>]+identifier=["']([^"']+)["']/);
|
|
12
|
+
return identifierMatch?.[1] || 'unknown';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Runs QTI ResponseProcessing for one AssessmentItem and normalizes the result
|
|
17
|
+
* to the BackendAdapter scoring shape used by AssessmentPlayer.
|
|
18
|
+
*/
|
|
19
|
+
export function scoreAssessmentItem({
|
|
20
|
+
itemXml,
|
|
21
|
+
responses,
|
|
22
|
+
itemSession,
|
|
23
|
+
}: AssessmentItemScoringInput): AssessmentScoringResult {
|
|
24
|
+
const itemIdentifier = getAssessmentItemIdentifier(itemXml);
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
// Use a scorer-grade view of the item for accurate scoring.
|
|
28
|
+
// NOTE: This reference scorer is intentionally insecure and runs client-side.
|
|
29
|
+
// In production, scoring must happen server-side with secured item content.
|
|
30
|
+
const player = new Player({
|
|
31
|
+
itemXml,
|
|
32
|
+
role: 'scorer',
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (itemSession) {
|
|
36
|
+
player.restoreItemSession(itemSession);
|
|
37
|
+
}
|
|
38
|
+
player.setResponses(responses);
|
|
39
|
+
const result = itemSession ? (player.scoreAttempt().scoring ?? player.processResponses()) : player.processResponses();
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
itemIdentifier,
|
|
43
|
+
score: result.score,
|
|
44
|
+
maxScore: result.maxScore,
|
|
45
|
+
completed: result.completed,
|
|
46
|
+
outcomeValues: result.outcomeValues,
|
|
47
|
+
};
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error('Scoring error:', error);
|
|
50
|
+
return {
|
|
51
|
+
itemIdentifier,
|
|
52
|
+
score: 0,
|
|
53
|
+
maxScore: 1,
|
|
54
|
+
completed: false,
|
|
55
|
+
outcomeValues: {},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/integration/index.ts
CHANGED
|
@@ -61,10 +61,17 @@ export type {
|
|
|
61
61
|
SecureItemRef,
|
|
62
62
|
SecureSection,
|
|
63
63
|
SecureTestPart,
|
|
64
|
+
SecureTimeLimits,
|
|
64
65
|
SessionId,
|
|
66
|
+
SubmitTimingEvidence,
|
|
65
67
|
SubmitResponsesRequest,
|
|
66
68
|
SubmitResponsesResponse,
|
|
67
69
|
} from './api-contract.js';
|
|
68
70
|
|
|
69
71
|
// Export reference implementation (for development/demos)
|
|
70
72
|
export { ReferenceBackendAdapter } from './ReferenceBackendAdapter.js';
|
|
73
|
+
export {
|
|
74
|
+
getAssessmentItemIdentifier,
|
|
75
|
+
scoreAssessmentItem,
|
|
76
|
+
type AssessmentItemScoringInput,
|
|
77
|
+
} from './assessment-item-scorer.js';
|
package/src/types/index.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
export type QTIRole = import('@pie-qti/item-player').QTIRole;
|
|
9
|
+
export type ResolvedItemDeliveryContext = import('@pie-qti/item-player').ResolvedItemDeliveryContext;
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Minimal item reference shape used by the UI renderer.
|
|
@@ -16,6 +17,8 @@ export interface ItemRef {
|
|
|
16
17
|
required?: boolean;
|
|
17
18
|
/** Client-safe item XML (backend filtered by role). */
|
|
18
19
|
itemXml?: string;
|
|
20
|
+
/** Optional resolved QTI 3 delivery context produced by package/assessment layers. */
|
|
21
|
+
deliveryContext?: ResolvedItemDeliveryContext;
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
/**
|