@pie-qti/assessment-player 0.1.6 → 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 +22 -4
- package/dist/core/AssessmentPlayer.d.ts.map +1 -1
- package/dist/core/AssessmentPlayer.js +170 -13
- package/dist/integration/ReferenceBackendAdapter.d.ts.map +1 -1
- package/dist/integration/ReferenceBackendAdapter.js +114 -19
- package/dist/integration/api-contract.d.ts +30 -11
- package/dist/integration/api-contract.d.ts.map +1 -1
- package/dist/integration/assessment-item-scorer.d.ts +3 -1
- package/dist/integration/assessment-item-scorer.d.ts.map +1 -1
- package/dist/integration/assessment-item-scorer.js +5 -2
- package/dist/integration/index.d.ts +1 -1
- package/dist/integration/index.d.ts.map +1 -1
- 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/AssessmentShell.svelte +9 -31
- package/src/components/ItemRenderer.svelte +7 -1
- package/src/core/AssessmentPlayer.ts +201 -14
- package/src/integration/ReferenceBackendAdapter.ts +127 -19
- package/src/integration/api-contract.ts +32 -11
- package/src/integration/assessment-item-scorer.ts +7 -2
- package/src/integration/index.ts +2 -0
- package/src/types/index.ts +3 -0
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
* - Submit responses to BackendAdapter
|
|
8
8
|
* - Apply backend navigation decisions + session state
|
|
9
9
|
*/
|
|
10
|
-
import type { QTIRole, PnpProfile } from '@pie-qti/item-player';
|
|
11
|
-
import type { AssessmentRubricBlock, AssessmentSessionState, BackendAdapter, InitSessionRequest } from '../integration/api-contract.js';
|
|
12
|
-
import type { AssessmentResults, ItemResult, NavigationState } from '../types/index.js';
|
|
10
|
+
import type { QTIRole, PnpProfile, SerializedItemSessionState } from '@pie-qti/item-player';
|
|
11
|
+
import type { AssessmentRubricBlock, AssessmentSessionState, BackendAdapter, InitSessionRequest, SecureItemRef } from '../integration/api-contract.js';
|
|
12
|
+
import type { AssessmentResults, ItemResult, NavigationState, TimeLimits } from '../types/index.js';
|
|
13
13
|
export interface BackendAssessmentPlayerConfig {
|
|
14
14
|
backend: BackendAdapter;
|
|
15
15
|
initSession: InitSessionRequest;
|
|
@@ -31,6 +31,12 @@ export interface BackendAssessmentPlayerConfig {
|
|
|
31
31
|
* If provided, this will be passed to all item players in the assessment.
|
|
32
32
|
*/
|
|
33
33
|
security?: any;
|
|
34
|
+
/**
|
|
35
|
+
* Demo/reference-only escape hatch. When false (default), rich item-session
|
|
36
|
+
* variables stay client-local and are not submitted because template variables
|
|
37
|
+
* can contain answer keys. Production backends should own this state server-side.
|
|
38
|
+
*/
|
|
39
|
+
sendItemSessionToBackend?: boolean;
|
|
34
40
|
showSections?: boolean;
|
|
35
41
|
allowSectionNavigation?: boolean;
|
|
36
42
|
showProgress?: boolean;
|
|
@@ -52,7 +58,12 @@ type CurrentItemView = {
|
|
|
52
58
|
title?: string;
|
|
53
59
|
required?: boolean;
|
|
54
60
|
itemXml: string;
|
|
61
|
+
deliveryContext?: SecureItemRef['deliveryContext'];
|
|
55
62
|
};
|
|
63
|
+
export interface EffectiveItemTimeLimits {
|
|
64
|
+
timeLimits?: TimeLimits;
|
|
65
|
+
source?: 'item' | 'section' | 'testPart' | 'assessment';
|
|
66
|
+
}
|
|
56
67
|
export declare class AssessmentPlayer {
|
|
57
68
|
private config;
|
|
58
69
|
static create(config: BackendAssessmentPlayerConfig): Promise<AssessmentPlayer>;
|
|
@@ -84,6 +95,9 @@ export declare class AssessmentPlayer {
|
|
|
84
95
|
* Section-level values override testPart-level when present.
|
|
85
96
|
*/
|
|
86
97
|
private getEffectiveItemSessionControl;
|
|
98
|
+
private getEffectiveItemTimeLimits;
|
|
99
|
+
getCurrentEffectiveTimeLimits(): EffectiveItemTimeLimits;
|
|
100
|
+
private getSubmitTimingEvidence;
|
|
87
101
|
private hasAnyResponse;
|
|
88
102
|
private restoreItemSessionsFromState;
|
|
89
103
|
private getItemSessionStateSnapshot;
|
|
@@ -115,11 +129,15 @@ export declare class AssessmentPlayer {
|
|
|
115
129
|
* (Useful for host integrations / web components.)
|
|
116
130
|
*/
|
|
117
131
|
getResponses(): Record<string, unknown>;
|
|
132
|
+
saveCurrentItemSession(): SerializedItemSessionState | null;
|
|
133
|
+
private endItemSessionForSubmit;
|
|
118
134
|
/**
|
|
119
135
|
* Get the current session state snapshot (client-side view).
|
|
120
136
|
* Note: backend remains authoritative; this is intended for simple save/resume.
|
|
121
137
|
*/
|
|
122
|
-
getState(
|
|
138
|
+
getState(options?: {
|
|
139
|
+
includeItemSessions?: boolean;
|
|
140
|
+
}): AssessmentSessionState;
|
|
123
141
|
/**
|
|
124
142
|
* Restore a previously saved session state.
|
|
125
143
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssessmentPlayer.d.ts","sourceRoot":"","sources":["../../src/core/AssessmentPlayer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"AssessmentPlayer.d.ts","sourceRoot":"","sources":["../../src/core/AssessmentPlayer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAE5F,OAAO,KAAK,EACX,qBAAqB,EACrB,sBAAsB,EAEtB,cAAc,EAEd,kBAAkB,EAGlB,aAAa,EAIb,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EACX,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,UAAU,EACV,MAAM,mBAAmB,CAAC;AAK3B,MAAM,WAAW,6BAA6B;IAC7C,OAAO,EAAE,cAAc,CAAC;IACxB,WAAW,EAAE,kBAAkB,CAAC;IAChC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,+FAA+F;IAC/F,GAAG,C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@ -44,6 +44,7 @@ export class AssessmentPlayer {
|
|
|
44
44
|
visitedItems: [],
|
|
45
45
|
itemResponses: {},
|
|
46
46
|
itemScores: {},
|
|
47
|
+
itemSessions: {},
|
|
47
48
|
timing: { startedAt: Date.now(), itemTimes: {}, totalTime: 0 },
|
|
48
49
|
};
|
|
49
50
|
this.items = this.flattenItems(this.assessment);
|
|
@@ -58,23 +59,23 @@ export class AssessmentPlayer {
|
|
|
58
59
|
this.sessionController.initializeItem(q.identifier);
|
|
59
60
|
}
|
|
60
61
|
this.restoreItemSessionsFromState(this.state);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
onTick: (remainingSeconds, elapsedSeconds) => this.notifyTimeTick(remainingSeconds, elapsedSeconds),
|
|
70
|
-
});
|
|
71
|
-
}
|
|
62
|
+
this.timeManager = new TimeManager({
|
|
63
|
+
assessmentTimeLimits: this.assessment.timeLimits,
|
|
64
|
+
warningThreshold: config.timeWarningThreshold || 60,
|
|
65
|
+
extendedTime: config.pnp?.content?.extendedTime,
|
|
66
|
+
onWarning: (remainingSeconds) => this.notifyTimeWarning(remainingSeconds),
|
|
67
|
+
onExpired: () => this.notifyTimeExpired(),
|
|
68
|
+
onTick: (remainingSeconds, elapsedSeconds) => this.notifyTimeTick(remainingSeconds, elapsedSeconds),
|
|
69
|
+
});
|
|
72
70
|
// Restore to backend-provided current item if present
|
|
73
71
|
const startId = this.state.currentItemIdentifier;
|
|
74
72
|
const idx = startId ? this.items.findIndex((q) => q.identifier === startId) : -1;
|
|
75
73
|
if (idx >= 0) {
|
|
76
74
|
this.navigateTo(idx, { restoring: true }).catch(() => { });
|
|
77
75
|
}
|
|
76
|
+
else if (this.items.length > 0) {
|
|
77
|
+
this.navigateTo(0, { restoring: true }).catch(() => { });
|
|
78
|
+
}
|
|
78
79
|
}
|
|
79
80
|
/**
|
|
80
81
|
* Compute effective itemSessionControl for a given item using three-level fallback:
|
|
@@ -98,6 +99,69 @@ export class AssessmentPlayer {
|
|
|
98
99
|
validateResponses: sectionControl.validateResponses ?? testPartControl.validateResponses,
|
|
99
100
|
};
|
|
100
101
|
}
|
|
102
|
+
getEffectiveItemTimeLimits(flat) {
|
|
103
|
+
const scopes = [
|
|
104
|
+
{ source: 'assessment', limits: this.assessment.timeLimits },
|
|
105
|
+
{ source: 'testPart', limits: flat.testPart.timeLimits },
|
|
106
|
+
{ source: 'section', limits: flat.section.timeLimits },
|
|
107
|
+
{ source: 'item', limits: flat.item.timeLimits },
|
|
108
|
+
];
|
|
109
|
+
let source;
|
|
110
|
+
let minTime;
|
|
111
|
+
let maxTime;
|
|
112
|
+
let allowLateSubmission;
|
|
113
|
+
for (const scope of scopes) {
|
|
114
|
+
if (!scope.limits)
|
|
115
|
+
continue;
|
|
116
|
+
if (scope.limits.minTime !== undefined) {
|
|
117
|
+
minTime = minTime === undefined ? scope.limits.minTime : Math.max(minTime, scope.limits.minTime);
|
|
118
|
+
}
|
|
119
|
+
if (scope.limits.maxTime !== undefined) {
|
|
120
|
+
const extended = this.config.pnp?.content?.extendedTime;
|
|
121
|
+
const scopedMaxTime = extended?.active
|
|
122
|
+
? extended.multiplier === Infinity
|
|
123
|
+
? undefined
|
|
124
|
+
: scope.limits.maxTime * extended.multiplier
|
|
125
|
+
: scope.limits.maxTime;
|
|
126
|
+
if (scopedMaxTime !== undefined && (maxTime === undefined || scopedMaxTime < maxTime)) {
|
|
127
|
+
maxTime = scopedMaxTime;
|
|
128
|
+
source = scope.source;
|
|
129
|
+
allowLateSubmission = scope.limits.allowLateSubmission;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else if (scope.limits.allowLateSubmission !== undefined && maxTime === undefined) {
|
|
133
|
+
allowLateSubmission = scope.limits.allowLateSubmission;
|
|
134
|
+
source = scope.source;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (maxTime === undefined && minTime === undefined && allowLateSubmission === undefined) {
|
|
138
|
+
return {};
|
|
139
|
+
}
|
|
140
|
+
return { source, timeLimits: { minTime, maxTime, allowLateSubmission } };
|
|
141
|
+
}
|
|
142
|
+
getCurrentEffectiveTimeLimits() {
|
|
143
|
+
const q = this.items[this.currentItemIndex];
|
|
144
|
+
return q ? this.getEffectiveItemTimeLimits(q) : {};
|
|
145
|
+
}
|
|
146
|
+
getSubmitTimingEvidence(q, elapsedMs) {
|
|
147
|
+
const effective = this.getEffectiveItemTimeLimits(q);
|
|
148
|
+
const limitSeconds = effective.timeLimits?.maxTime;
|
|
149
|
+
if (!effective.source || limitSeconds === undefined)
|
|
150
|
+
return undefined;
|
|
151
|
+
if (effective.source !== 'item' && effective.source !== 'assessment') {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
const scopedElapsedMs = effective.source === 'assessment'
|
|
155
|
+
? (this.timeManager?.getElapsedSeconds() ?? 0) * 1000
|
|
156
|
+
: elapsedMs;
|
|
157
|
+
return {
|
|
158
|
+
scope: effective.source,
|
|
159
|
+
elapsedMs: scopedElapsedMs,
|
|
160
|
+
limitSeconds,
|
|
161
|
+
expired: scopedElapsedMs >= limitSeconds * 1000,
|
|
162
|
+
allowLateSubmission: effective.timeLimits?.allowLateSubmission,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
101
165
|
hasAnyResponse(responses) {
|
|
102
166
|
for (const v of Object.values(responses)) {
|
|
103
167
|
if (v == null)
|
|
@@ -221,6 +285,7 @@ export class AssessmentPlayer {
|
|
|
221
285
|
title: q.section.title,
|
|
222
286
|
required: q.item.required,
|
|
223
287
|
itemXml: q.item.itemXml,
|
|
288
|
+
deliveryContext: q.item.deliveryContext,
|
|
224
289
|
};
|
|
225
290
|
}
|
|
226
291
|
getCurrentRubricBlocks() {
|
|
@@ -267,17 +332,48 @@ export class AssessmentPlayer {
|
|
|
267
332
|
getResponses() {
|
|
268
333
|
return { ...this.responses };
|
|
269
334
|
}
|
|
335
|
+
saveCurrentItemSession() {
|
|
336
|
+
const q = this.items[this.currentItemIndex];
|
|
337
|
+
if (!q || !this.currentItemPlayer)
|
|
338
|
+
return null;
|
|
339
|
+
this.currentItemPlayer.setResponses(this.responses);
|
|
340
|
+
const result = this.currentItemPlayer.suspendAttempt();
|
|
341
|
+
this.state.itemSessions = {
|
|
342
|
+
...(this.state.itemSessions ?? {}),
|
|
343
|
+
[q.identifier]: result.sessionState,
|
|
344
|
+
};
|
|
345
|
+
this.state.itemResponses[q.identifier] = this.responses;
|
|
346
|
+
this.state.timing.itemTimes[q.identifier] = result.duration;
|
|
347
|
+
this.sessionController.markAnswered(q.identifier, this.hasAnyResponse(this.responses));
|
|
348
|
+
return result.sessionState;
|
|
349
|
+
}
|
|
350
|
+
endItemSessionForSubmit(q, responses, itemSession) {
|
|
351
|
+
const player = new Player({
|
|
352
|
+
itemXml: q.item.itemXml,
|
|
353
|
+
role: q.item.role,
|
|
354
|
+
i18nProvider: this.i18nProvider,
|
|
355
|
+
pnp: this.config.pnp,
|
|
356
|
+
security: this.config.security,
|
|
357
|
+
deliveryContext: q.item.deliveryContext,
|
|
358
|
+
});
|
|
359
|
+
if (itemSession) {
|
|
360
|
+
player.restoreItemSession(itemSession);
|
|
361
|
+
}
|
|
362
|
+
player.setResponses(responses);
|
|
363
|
+
return player.endAttempt().sessionState;
|
|
364
|
+
}
|
|
270
365
|
/**
|
|
271
366
|
* Get the current session state snapshot (client-side view).
|
|
272
367
|
* Note: backend remains authoritative; this is intended for simple save/resume.
|
|
273
368
|
*/
|
|
274
|
-
getState() {
|
|
369
|
+
getState(options = {}) {
|
|
275
370
|
// Shallow clone to avoid accidental external mutation.
|
|
276
371
|
return {
|
|
277
372
|
...this.state,
|
|
278
373
|
visitedItems: [...this.state.visitedItems],
|
|
279
374
|
itemResponses: { ...this.state.itemResponses },
|
|
280
375
|
itemScores: this.state.itemScores ? { ...this.state.itemScores } : undefined,
|
|
376
|
+
itemSessions: options.includeItemSessions && this.state.itemSessions ? { ...this.state.itemSessions } : undefined,
|
|
281
377
|
itemSessionStates: this.getItemSessionStateSnapshot(),
|
|
282
378
|
timing: {
|
|
283
379
|
...this.state.timing,
|
|
@@ -331,9 +427,22 @@ export class AssessmentPlayer {
|
|
|
331
427
|
if (!options.restoring && target && !this.sessionController.canReview(target.identifier)) {
|
|
332
428
|
throw new Error('You cannot go back to previous questions in this assessment.');
|
|
333
429
|
}
|
|
430
|
+
const currentItem = this.items[this.currentItemIndex];
|
|
431
|
+
const currentSessionStatus = currentItem ? this.state.itemSessions?.[currentItem.identifier]?.lifecycleStatus : undefined;
|
|
432
|
+
if (!options.restoring &&
|
|
433
|
+
this.currentItemIndex >= 0 &&
|
|
434
|
+
this.currentItemIndex !== index &&
|
|
435
|
+
currentSessionStatus !== 'closed') {
|
|
436
|
+
this.saveCurrentItemSession();
|
|
437
|
+
}
|
|
438
|
+
if (currentItem && this.currentItemIndex !== index) {
|
|
439
|
+
this.timeManager?.endItem(currentItem.identifier);
|
|
440
|
+
}
|
|
334
441
|
this.currentItemIndex = index;
|
|
335
442
|
const q = this.items[index];
|
|
336
443
|
this.state.currentItemIdentifier = q.identifier;
|
|
444
|
+
this.timeManager?.startSection(q.section.identifier);
|
|
445
|
+
this.timeManager?.startItem(q.identifier);
|
|
337
446
|
// Apply three-level itemSessionControl fallback for this item's section (S1).
|
|
338
447
|
const effectiveControl = this.getEffectiveItemSessionControl(q);
|
|
339
448
|
if (effectiveControl) {
|
|
@@ -342,12 +451,22 @@ export class AssessmentPlayer {
|
|
|
342
451
|
// Restore responses
|
|
343
452
|
this.responses = { ...(this.state.itemResponses[q.identifier] || {}) };
|
|
344
453
|
// Create item player
|
|
454
|
+
this.currentItemPlayer?.destroy();
|
|
345
455
|
this.currentItemPlayer = new Player({
|
|
346
456
|
itemXml: q.item.itemXml,
|
|
347
457
|
role: q.item.role,
|
|
348
458
|
i18nProvider: this.i18nProvider,
|
|
459
|
+
pnp: this.config.pnp,
|
|
460
|
+
security: this.config.security,
|
|
461
|
+
deliveryContext: q.item.deliveryContext,
|
|
349
462
|
});
|
|
350
|
-
this.
|
|
463
|
+
const restoredItemSession = this.state.itemSessions?.[q.identifier];
|
|
464
|
+
if (restoredItemSession) {
|
|
465
|
+
this.currentItemPlayer.restoreItemSession(restoredItemSession);
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
this.currentItemPlayer.setResponses(this.responses);
|
|
469
|
+
}
|
|
351
470
|
this.notifyItemChange();
|
|
352
471
|
this.notifySectionChange();
|
|
353
472
|
}
|
|
@@ -391,17 +510,39 @@ export class AssessmentPlayer {
|
|
|
391
510
|
if (!q)
|
|
392
511
|
throw new Error('No current item');
|
|
393
512
|
const submittedAt = Date.now();
|
|
513
|
+
let itemSession;
|
|
514
|
+
if (this.currentItemPlayer) {
|
|
515
|
+
this.currentItemPlayer.setResponses(this.responses);
|
|
516
|
+
const attempt = this.currentItemPlayer.endAttempt({
|
|
517
|
+
validateResponses: this.sessionController.mustValidateResponses(),
|
|
518
|
+
});
|
|
519
|
+
if (attempt.validation && !attempt.validation.valid) {
|
|
520
|
+
throw new Error(attempt.validation.issues[0]?.message || 'Submit failed: invalid response');
|
|
521
|
+
}
|
|
522
|
+
itemSession = attempt.sessionState;
|
|
523
|
+
this.state.itemSessions = {
|
|
524
|
+
...(this.state.itemSessions ?? {}),
|
|
525
|
+
[q.identifier]: itemSession,
|
|
526
|
+
};
|
|
527
|
+
}
|
|
394
528
|
const res = await this.backend.submitResponses({
|
|
395
529
|
sessionId: this.sessionId,
|
|
396
530
|
itemIdentifier: q.identifier,
|
|
397
531
|
responses: this.responses,
|
|
398
532
|
submittedAt,
|
|
533
|
+
timeSpent: itemSession?.duration,
|
|
534
|
+
timing: this.getSubmitTimingEvidence(q, itemSession?.duration ?? 0),
|
|
535
|
+
itemSession: this.config.sendItemSessionToBackend ? itemSession : undefined,
|
|
399
536
|
});
|
|
400
537
|
if (!res.success || !res.result) {
|
|
401
538
|
throw new Error(res.error || 'Submit failed');
|
|
402
539
|
}
|
|
403
540
|
if (res.updatedState) {
|
|
541
|
+
const localItemSessions = this.state.itemSessions;
|
|
404
542
|
this.state = res.updatedState;
|
|
543
|
+
if (localItemSessions) {
|
|
544
|
+
this.state.itemSessions = { ...(this.state.itemSessions ?? {}), ...localItemSessions };
|
|
545
|
+
}
|
|
405
546
|
}
|
|
406
547
|
else {
|
|
407
548
|
// Minimal state update when backend doesn't return full state.
|
|
@@ -410,6 +551,9 @@ export class AssessmentPlayer {
|
|
|
410
551
|
if (!this.state.visitedItems.includes(q.identifier))
|
|
411
552
|
this.state.visitedItems.push(q.identifier);
|
|
412
553
|
this.state.itemResponses[q.identifier] = this.responses;
|
|
554
|
+
if (itemSession) {
|
|
555
|
+
this.state.itemSessions = { ...(this.state.itemSessions ?? {}), [q.identifier]: itemSession };
|
|
556
|
+
}
|
|
413
557
|
}
|
|
414
558
|
const itemResult = {
|
|
415
559
|
itemIdentifier: q.identifier,
|
|
@@ -490,21 +634,28 @@ export class AssessmentPlayer {
|
|
|
490
634
|
// For simultaneous submission, ensure all items are submitted before finalize so
|
|
491
635
|
// the backend can compute a complete test score.
|
|
492
636
|
if (this.assessment.submissionMode === 'simultaneous') {
|
|
637
|
+
this.saveCurrentItemSession();
|
|
493
638
|
// Preserve client-collected responses across backend state updates.
|
|
494
639
|
// Some backend adapters return an updatedState snapshot that may only include
|
|
495
640
|
// responses for items that have been submitted so far, which would otherwise
|
|
496
641
|
// wipe out responses for later items during this loop.
|
|
497
642
|
const allItemResponses = { ...(this.state.itemResponses || {}) };
|
|
643
|
+
const allItemSessions = { ...(this.state.itemSessions || {}) };
|
|
498
644
|
for (const q of this.items) {
|
|
499
645
|
if (this.itemResults.has(q.identifier))
|
|
500
646
|
continue;
|
|
501
647
|
const submittedAt = Date.now();
|
|
502
648
|
const responsesForItem = (allItemResponses?.[q.identifier] || {});
|
|
649
|
+
const itemSession = this.endItemSessionForSubmit(q, responsesForItem, allItemSessions[q.identifier]);
|
|
650
|
+
allItemSessions[q.identifier] = itemSession;
|
|
503
651
|
const res = await this.backend.submitResponses({
|
|
504
652
|
sessionId: this.sessionId,
|
|
505
653
|
itemIdentifier: q.identifier,
|
|
506
654
|
responses: responsesForItem,
|
|
507
655
|
submittedAt,
|
|
656
|
+
timeSpent: itemSession?.duration,
|
|
657
|
+
timing: this.getSubmitTimingEvidence(q, itemSession?.duration ?? 0),
|
|
658
|
+
itemSession: this.config.sendItemSessionToBackend ? itemSession : undefined,
|
|
508
659
|
});
|
|
509
660
|
if (!res.success || !res.result) {
|
|
510
661
|
throw new Error(res.error || `Submit failed for item ${q.identifier}`);
|
|
@@ -513,6 +664,7 @@ export class AssessmentPlayer {
|
|
|
513
664
|
this.state = res.updatedState;
|
|
514
665
|
// Restore full response map captured on the client.
|
|
515
666
|
this.state.itemResponses = allItemResponses;
|
|
667
|
+
this.state.itemSessions = allItemSessions;
|
|
516
668
|
}
|
|
517
669
|
else {
|
|
518
670
|
this.state.itemScores = this.state.itemScores || {};
|
|
@@ -520,6 +672,9 @@ export class AssessmentPlayer {
|
|
|
520
672
|
if (!this.state.visitedItems.includes(q.identifier))
|
|
521
673
|
this.state.visitedItems.push(q.identifier);
|
|
522
674
|
this.state.itemResponses[q.identifier] = responsesForItem;
|
|
675
|
+
if (itemSession) {
|
|
676
|
+
this.state.itemSessions = { ...(this.state.itemSessions ?? {}), [q.identifier]: itemSession };
|
|
677
|
+
}
|
|
523
678
|
}
|
|
524
679
|
this.itemResults.set(q.identifier, {
|
|
525
680
|
itemIdentifier: q.identifier,
|
|
@@ -645,6 +800,8 @@ export class AssessmentPlayer {
|
|
|
645
800
|
return () => this.timeTickListeners.delete(listener);
|
|
646
801
|
}
|
|
647
802
|
destroy() {
|
|
803
|
+
this.timeManager?.destroy();
|
|
804
|
+
this.currentItemPlayer?.destroy();
|
|
648
805
|
this.itemChangeListeners.clear();
|
|
649
806
|
this.sectionChangeListeners.clear();
|
|
650
807
|
this.responseChangeListeners.clear();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReferenceBackendAdapter.d.ts","sourceRoot":"","sources":["../../src/integration/ReferenceBackendAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;
|
|
1
|
+
{"version":3,"file":"ReferenceBackendAdapter.d.ts","sourceRoot":"","sources":["../../src/integration/ReferenceBackendAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAsBH,OAAO,KAAK,EAGX,cAAc,EACd,yBAAyB,EACzB,0BAA0B,EAC1B,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,0BAA0B,EAC1B,2BAA2B,EAC3B,gBAAgB,EAChB,aAAa,EAGb,SAAS,EACT,sBAAsB,EACtB,uBAAuB,EACvB,MAAM,mBAAmB,CAAC;AAmD3B;;;;;;;;;;;GAWG;AACH,qBAAa,uBAAwB,YAAW,cAAc;IAC7D,OAAO,CAAC,qBAAqB,CAA4C;IAEzE;;;;;;OAMG;IACI,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,gBAAgB;IAI5E,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,cAAc;IAgBtB;;OAEG;IACG,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAuD5E;;OAEG;IACG,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IA+HxF;;OAEG;IACG,SAAS,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAmB1F;;OAEG;IACG,kBAAkB,CACvB,OAAO,EAAE,yBAAyB,GAChC,OAAO,CAAC,0BAA0B,CAAC;IAkCtC;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAoF5B;;OAEG;IACG,aAAa,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAQvE;;;;;;;;;;OAUG;IACG,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAuClF,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,WAAW;IAanB,OAAO,CAAC,WAAW;IAanB;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IAuH5B;;;;;;;;;;;;;OAaG;WACU,sBAAsB,CAClC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;QACR,IAAI,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;QAC7B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACpC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;QACjD,OAAO,CAAC,EAAE,MAAM,CAAC;KACZ,GACJ,OAAO,CAAC,gBAAgB,CAAC;IAmV5B,OAAO,CAAC,oBAAoB;IA4B5B,OAAO,CAAC,YAAY;IAgBpB;;OAEG;IACH,OAAO,CAAC,eAAe;IAWvB;;OAEG;IACH,OAAO,CAAC,aAAa;IAqBrB;;OAEG;IACH,OAAO,CAAC,aAAa;IAQrB;;;;;OAKG;YACW,kBAAkB;IAkLhC;;OAEG;IACH,OAAO,CAAC,KAAK;CAGb"}
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
* - Filters sensitive data based on role
|
|
28
28
|
*/
|
|
29
29
|
import { buildExpression, buildOutcomeProcessingAst, DeclarationContext, evalExpr, execProgram, OperatorRegistry, parseXml, serializeXml, qtiNull, qtiValue, } from '@pie-qti/qti-processing';
|
|
30
|
+
import { createResolvedItemDeliveryContext, extractAssessmentStimulusRefs, resolveRelativePath as resolveQtiRelativePath, } from '@pie-qti/ims-cp-core';
|
|
30
31
|
import { scoreAssessmentItem } from './assessment-item-scorer.js';
|
|
31
32
|
/**
|
|
32
33
|
* Storage key prefix for localStorage
|
|
@@ -122,6 +123,7 @@ export class ReferenceBackendAdapter {
|
|
|
122
123
|
visitedItems: [],
|
|
123
124
|
itemResponses: {},
|
|
124
125
|
itemScores: {},
|
|
126
|
+
itemSessions: {},
|
|
125
127
|
timing: {
|
|
126
128
|
startedAt: Date.now(),
|
|
127
129
|
itemTimes: {},
|
|
@@ -160,6 +162,28 @@ export class ReferenceBackendAdapter {
|
|
|
160
162
|
error: 'Session already finalized',
|
|
161
163
|
};
|
|
162
164
|
}
|
|
165
|
+
const receivedAt = Date.now();
|
|
166
|
+
const assessmentLimit = session.assessment.timeLimits;
|
|
167
|
+
const effectiveAssessmentLimitSeconds = request.timing?.scope === 'assessment' && request.timing.limitSeconds !== undefined
|
|
168
|
+
? request.timing.limitSeconds
|
|
169
|
+
: assessmentLimit?.maxTime;
|
|
170
|
+
const assessmentAllowsLate = assessmentLimit?.allowLateSubmission ?? request.timing?.allowLateSubmission;
|
|
171
|
+
if (effectiveAssessmentLimitSeconds !== undefined &&
|
|
172
|
+
assessmentAllowsLate !== true &&
|
|
173
|
+
receivedAt - session.createdAt > effectiveAssessmentLimitSeconds * 1000) {
|
|
174
|
+
return {
|
|
175
|
+
success: false,
|
|
176
|
+
error: 'Assessment time limit expired',
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const evidenceExpired = request.timing?.limitSeconds !== undefined &&
|
|
180
|
+
request.timing.elapsedMs >= request.timing.limitSeconds * 1000;
|
|
181
|
+
if (evidenceExpired && request.timing?.allowLateSubmission !== true) {
|
|
182
|
+
return {
|
|
183
|
+
success: false,
|
|
184
|
+
error: 'Time limit expired',
|
|
185
|
+
};
|
|
186
|
+
}
|
|
163
187
|
// Find the item XML
|
|
164
188
|
const itemXml = this.findItemXml(session.assessment, request.itemIdentifier);
|
|
165
189
|
if (!itemXml) {
|
|
@@ -170,13 +194,19 @@ export class ReferenceBackendAdapter {
|
|
|
170
194
|
}
|
|
171
195
|
// **SECURITY WARNING**: Client-side scoring is INSECURE
|
|
172
196
|
// In production, this MUST be done server-side
|
|
173
|
-
const result = scoreAssessmentItem({ itemXml, responses: request.responses });
|
|
197
|
+
const result = scoreAssessmentItem({ itemXml, responses: request.responses, itemSession: request.itemSession });
|
|
174
198
|
// Store responses and result
|
|
175
199
|
session.state.itemResponses[request.itemIdentifier] = request.responses;
|
|
176
200
|
if (!session.state.itemScores) {
|
|
177
201
|
session.state.itemScores = {};
|
|
178
202
|
}
|
|
179
203
|
session.state.itemScores[request.itemIdentifier] = result;
|
|
204
|
+
if (request.itemSession) {
|
|
205
|
+
session.state.itemSessions = {
|
|
206
|
+
...(session.state.itemSessions ?? {}),
|
|
207
|
+
[request.itemIdentifier]: request.itemSession,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
180
210
|
const previousItemSession = session.state.itemSessionStates?.[request.itemIdentifier];
|
|
181
211
|
session.state.itemSessionStates = {
|
|
182
212
|
...(session.state.itemSessionStates ?? {}),
|
|
@@ -631,13 +661,79 @@ export class ReferenceBackendAdapter {
|
|
|
631
661
|
validateResponses: boolAttr('validateResponses') ?? boolAttr('validate-responses'),
|
|
632
662
|
};
|
|
633
663
|
};
|
|
664
|
+
const parseTimeLimits = (el) => {
|
|
665
|
+
const limitsEl = childrenByTag(el, 'timeLimit')[0] ?? childrenByTag(el, 'timeLimits')[0];
|
|
666
|
+
if (!limitsEl)
|
|
667
|
+
return undefined;
|
|
668
|
+
const numberAttr = (name) => {
|
|
669
|
+
const value = getAttr(limitsEl, name);
|
|
670
|
+
if (value === undefined)
|
|
671
|
+
return undefined;
|
|
672
|
+
const parsed = Number(value);
|
|
673
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
674
|
+
};
|
|
675
|
+
const boolAttr = (name) => {
|
|
676
|
+
const value = getAttr(limitsEl, name);
|
|
677
|
+
return value === undefined ? undefined : value === 'true';
|
|
678
|
+
};
|
|
679
|
+
return {
|
|
680
|
+
minTime: numberAttr('minTime'),
|
|
681
|
+
maxTime: numberAttr('maxTime'),
|
|
682
|
+
allowLateSubmission: boolAttr('allowLateSubmission'),
|
|
683
|
+
};
|
|
684
|
+
};
|
|
685
|
+
const resolveAgainstBase = (href) => {
|
|
686
|
+
if (!href)
|
|
687
|
+
return undefined;
|
|
688
|
+
return baseUrl ? resolveQtiRelativePath(baseUrl, href) : href;
|
|
689
|
+
};
|
|
690
|
+
const loadText = async (href) => {
|
|
691
|
+
if (!href)
|
|
692
|
+
return undefined;
|
|
693
|
+
const candidates = [href, resolveAgainstBase(href)].filter((value, index, all) => Boolean(value) && all.indexOf(value) === index);
|
|
694
|
+
for (const candidate of candidates) {
|
|
695
|
+
if (itemXmlMap[candidate] !== undefined) {
|
|
696
|
+
return itemXmlMap[candidate];
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
if (!fileResolver)
|
|
700
|
+
return undefined;
|
|
701
|
+
for (const candidate of candidates) {
|
|
702
|
+
try {
|
|
703
|
+
return await fileResolver(candidate);
|
|
704
|
+
}
|
|
705
|
+
catch {
|
|
706
|
+
// Try the next candidate before giving up.
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
return undefined;
|
|
710
|
+
};
|
|
711
|
+
const buildDeliveryContext = async (itemXml, itemHref) => {
|
|
712
|
+
if (!itemHref || extractAssessmentStimulusRefs(itemXml).length === 0) {
|
|
713
|
+
return undefined;
|
|
714
|
+
}
|
|
715
|
+
const stimulusXmlByPath = {};
|
|
716
|
+
for (const ref of extractAssessmentStimulusRefs(itemXml)) {
|
|
717
|
+
const stimulusPath = resolveQtiRelativePath(itemHref, ref.href);
|
|
718
|
+
const stimulusXml = await loadText(stimulusPath);
|
|
719
|
+
if (stimulusXml) {
|
|
720
|
+
stimulusXmlByPath[stimulusPath] = stimulusXml;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return createResolvedItemDeliveryContext({
|
|
724
|
+
itemXml,
|
|
725
|
+
itemHref,
|
|
726
|
+
readText: (path) => stimulusXmlByPath[path] ?? itemXmlMap[path],
|
|
727
|
+
});
|
|
728
|
+
};
|
|
634
729
|
// Parse a single assessmentSection element
|
|
635
|
-
const parseSection = (sectionEl) => {
|
|
730
|
+
const parseSection = async (sectionEl) => {
|
|
636
731
|
const identifier = getAttr(sectionEl, 'identifier') ?? 'section';
|
|
637
732
|
const title = getAttr(sectionEl, 'title');
|
|
638
733
|
const visibleRaw = getAttr(sectionEl, 'visible');
|
|
639
734
|
const visible = visibleRaw === undefined ? true : visibleRaw !== 'false';
|
|
640
735
|
const itemSessionControl = parseItemSessionControl(sectionEl);
|
|
736
|
+
const timeLimits = parseTimeLimits(sectionEl);
|
|
641
737
|
// rubricBlocks
|
|
642
738
|
const rubricBlockEls = childrenByTag(sectionEl, 'rubricBlock');
|
|
643
739
|
const rubricBlocks = rubricBlockEls.length > 0
|
|
@@ -650,20 +746,24 @@ export class ReferenceBackendAdapter {
|
|
|
650
746
|
: undefined;
|
|
651
747
|
// assessmentItemRefs
|
|
652
748
|
const itemRefEls = childrenByTag(sectionEl, 'assessmentItemRef');
|
|
653
|
-
const assessmentItemRefs =
|
|
749
|
+
const assessmentItemRefs = [];
|
|
750
|
+
for (const ref of itemRefEls) {
|
|
654
751
|
const itemId = getAttr(ref, 'identifier') ?? 'item';
|
|
655
752
|
const href = getAttr(ref, 'href');
|
|
753
|
+
const itemHref = resolveAgainstBase(href) ?? href;
|
|
656
754
|
// Look up pre-loaded XML by identifier or href
|
|
657
|
-
const resolvedXml = itemXmlMap[itemId] ?? (href ? itemXmlMap[href] : undefined) ?? '';
|
|
755
|
+
const resolvedXml = itemXmlMap[itemId] ?? (href ? itemXmlMap[href] : undefined) ?? (itemHref ? itemXmlMap[itemHref] : undefined) ?? (await loadText(href)) ?? '';
|
|
658
756
|
const requiredRaw = getAttr(ref, 'required');
|
|
659
757
|
const required = requiredRaw === undefined ? undefined : requiredRaw !== 'false';
|
|
660
|
-
|
|
758
|
+
assessmentItemRefs.push({
|
|
661
759
|
identifier: itemId,
|
|
662
760
|
itemXml: resolvedXml,
|
|
663
761
|
role,
|
|
664
762
|
required,
|
|
665
|
-
|
|
666
|
-
|
|
763
|
+
timeLimits: parseTimeLimits(ref),
|
|
764
|
+
deliveryContext: await buildDeliveryContext(resolvedXml, itemHref),
|
|
765
|
+
});
|
|
766
|
+
}
|
|
667
767
|
return {
|
|
668
768
|
identifier,
|
|
669
769
|
title,
|
|
@@ -671,6 +771,7 @@ export class ReferenceBackendAdapter {
|
|
|
671
771
|
assessmentItemRefs,
|
|
672
772
|
rubricBlocks,
|
|
673
773
|
itemSessionControl,
|
|
774
|
+
timeLimits,
|
|
674
775
|
};
|
|
675
776
|
};
|
|
676
777
|
// Resolve assessmentSectionRef: load and parse referenced section file
|
|
@@ -704,7 +805,7 @@ export class ReferenceBackendAdapter {
|
|
|
704
805
|
const sections = [];
|
|
705
806
|
for (const child of childElements(testPartEl)) {
|
|
706
807
|
if (toCanonicalQtiName(child.localName) === 'assessmentSection') {
|
|
707
|
-
sections.push(parseSection(child));
|
|
808
|
+
sections.push(await parseSection(child));
|
|
708
809
|
}
|
|
709
810
|
else if (toCanonicalQtiName(child.localName) === 'assessmentSectionRef') {
|
|
710
811
|
const resolved = await resolveSectionRef(child);
|
|
@@ -764,16 +865,8 @@ export class ReferenceBackendAdapter {
|
|
|
764
865
|
const outcomeProcessingXml = outcomeProcessingEl
|
|
765
866
|
? serializeXml(outcomeProcessingEl)
|
|
766
867
|
: undefined;
|
|
767
|
-
// Extract timeLimits
|
|
768
|
-
const
|
|
769
|
-
const timeLimits = timeLimitsEl
|
|
770
|
-
? {
|
|
771
|
-
maxTime: getAttr(timeLimitsEl, 'maxTime')
|
|
772
|
-
? Number(getAttr(timeLimitsEl, 'maxTime'))
|
|
773
|
-
: undefined,
|
|
774
|
-
allowLateSubmission: getAttr(timeLimitsEl, 'allowLateSubmission') === 'true',
|
|
775
|
-
}
|
|
776
|
-
: undefined;
|
|
868
|
+
// Extract assessment-level timeLimits.
|
|
869
|
+
const timeLimits = parseTimeLimits(root);
|
|
777
870
|
// Parse testParts
|
|
778
871
|
const testPartEls = childrenByTag(root, 'testPart');
|
|
779
872
|
const firstTestPart = testPartEls[0];
|
|
@@ -784,6 +877,7 @@ export class ReferenceBackendAdapter {
|
|
|
784
877
|
for (const tp of testPartEls) {
|
|
785
878
|
const tpIdentifier = getAttr(tp, 'identifier') ?? 'part-1';
|
|
786
879
|
const tpItemSessionControl = parseTestPartItemSessionControl(tp);
|
|
880
|
+
const tpTimeLimits = parseTimeLimits(tp);
|
|
787
881
|
const tpRubricBlockEls = childrenByTag(tp, 'rubricBlock');
|
|
788
882
|
const tpRubricBlocks = tpRubricBlockEls.length > 0
|
|
789
883
|
? tpRubricBlockEls.map((b, idx) => ({
|
|
@@ -799,6 +893,7 @@ export class ReferenceBackendAdapter {
|
|
|
799
893
|
sections,
|
|
800
894
|
rubricBlocks: tpRubricBlocks,
|
|
801
895
|
itemSessionControl: tpItemSessionControl,
|
|
896
|
+
timeLimits: tpTimeLimits,
|
|
802
897
|
});
|
|
803
898
|
}
|
|
804
899
|
// If no testParts, try top-level sections
|
|
@@ -806,7 +901,7 @@ export class ReferenceBackendAdapter {
|
|
|
806
901
|
const topSections = [];
|
|
807
902
|
for (const child of childElements(root)) {
|
|
808
903
|
if (toCanonicalQtiName(child.localName) === 'assessmentSection') {
|
|
809
|
-
topSections.push(parseSection(child));
|
|
904
|
+
topSections.push(await parseSection(child));
|
|
810
905
|
}
|
|
811
906
|
else if (toCanonicalQtiName(child.localName) === 'assessmentSectionRef') {
|
|
812
907
|
const resolved = await resolveSectionRef(child);
|