@pie-qti/assessment-player 0.1.6 → 0.1.8

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.
@@ -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;
@@ -313,6 +332,8 @@ export interface AssessmentSessionState {
313
332
  itemScores?: Record<string, AssessmentScoringResult>;
314
333
  /** ItemSession lifecycle hints per item, used to restore attempt/review UI state */
315
334
  itemSessionStates?: Record<string, AssessmentItemSessionState>;
335
+ /** Rich QTI item session snapshots, used to restore variables and score saved sessions. */
336
+ itemSessions?: Record<string, SerializedItemSessionState>;
316
337
  /** Time tracking */
317
338
  timing: {
318
339
  /** Session start time */
@@ -1,9 +1,10 @@
1
- import { Player } from '@pie-qti/item-player';
1
+ import { Player, type SerializedItemSessionState } from '@pie-qti/item-player';
2
2
  import type { AssessmentScoringResult, ResponseValue } from './api-contract.js';
3
3
 
4
4
  export interface AssessmentItemScoringInput {
5
5
  itemXml: string;
6
6
  responses: Record<string, ResponseValue>;
7
+ itemSession?: SerializedItemSessionState;
7
8
  }
8
9
 
9
10
  export function getAssessmentItemIdentifier(itemXml: string): string {
@@ -18,6 +19,7 @@ export function getAssessmentItemIdentifier(itemXml: string): string {
18
19
  export function scoreAssessmentItem({
19
20
  itemXml,
20
21
  responses,
22
+ itemSession,
21
23
  }: AssessmentItemScoringInput): AssessmentScoringResult {
22
24
  const itemIdentifier = getAssessmentItemIdentifier(itemXml);
23
25
 
@@ -30,8 +32,11 @@ export function scoreAssessmentItem({
30
32
  role: 'scorer',
31
33
  });
32
34
 
35
+ if (itemSession) {
36
+ player.restoreItemSession(itemSession);
37
+ }
33
38
  player.setResponses(responses);
34
- const result = player.processResponses();
39
+ const result = itemSession ? (player.scoreAttempt().scoring ?? player.processResponses()) : player.processResponses();
35
40
 
36
41
  return {
37
42
  itemIdentifier,
@@ -61,7 +61,9 @@ 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';
@@ -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
  /**