@pie-qti/assessment-player 1.0.0-beta.3 → 1.0.0-beta.5

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.
Files changed (134) hide show
  1. package/README.md +28 -7
  2. package/dist/components/createPlayerConnection.svelte.d.ts +90 -0
  3. package/dist/components/createPlayerConnection.svelte.js +151 -0
  4. package/dist/components/createPlayerConnection.svelte.js.map +1 -0
  5. package/dist/components/displaySettings.svelte.d.ts +23 -0
  6. package/dist/components/displaySettings.svelte.js +40 -0
  7. package/dist/components/displaySettings.svelte.js.map +1 -0
  8. package/dist/components/srOnly.d.ts +29 -0
  9. package/dist/components/srOnly.js +55 -0
  10. package/dist/components/srOnly.js.map +1 -0
  11. package/dist/components/submitDialogAction.d.ts +25 -0
  12. package/dist/components/submitDialogAction.js +89 -0
  13. package/dist/components/submitDialogAction.js.map +1 -0
  14. package/dist/core/AssessmentPlayer.d.ts +1102 -53
  15. package/dist/core/AssessmentPlayer.js +2836 -457
  16. package/dist/core/AssessmentPlayer.js.map +1 -1
  17. package/dist/core/AssessmentSessionCoordinator.d.ts +76 -7
  18. package/dist/core/AssessmentSessionCoordinator.js +185 -10
  19. package/dist/core/AssessmentSessionCoordinator.js.map +1 -1
  20. package/dist/core/AutosaveManager.d.ts +104 -0
  21. package/dist/core/AutosaveManager.js +181 -0
  22. package/dist/core/AutosaveManager.js.map +1 -0
  23. package/dist/core/ItemSessionController.d.ts +17 -26
  24. package/dist/core/ItemSessionController.js +33 -73
  25. package/dist/core/ItemSessionController.js.map +1 -1
  26. package/dist/core/NavigationManager.d.ts +18 -50
  27. package/dist/core/NavigationManager.js +21 -83
  28. package/dist/core/NavigationManager.js.map +1 -1
  29. package/dist/core/TimeManager.d.ts +62 -16
  30. package/dist/core/TimeManager.js +148 -57
  31. package/dist/core/TimeManager.js.map +1 -1
  32. package/dist/core/autosave.d.ts +44 -0
  33. package/dist/core/autosave.js +46 -0
  34. package/dist/core/autosave.js.map +1 -0
  35. package/dist/core/deliveryStructure.d.ts +54 -0
  36. package/dist/core/deliveryStructure.js +72 -0
  37. package/dist/core/deliveryStructure.js.map +1 -0
  38. package/dist/core/errors.d.ts +116 -0
  39. package/dist/core/errors.js +77 -0
  40. package/dist/core/errors.js.map +1 -0
  41. package/dist/core/exitBoundaries.d.ts +64 -0
  42. package/dist/core/exitBoundaries.js +98 -0
  43. package/dist/core/exitBoundaries.js.map +1 -0
  44. package/dist/core/feedback.d.ts +46 -0
  45. package/dist/core/feedback.js +47 -0
  46. package/dist/core/feedback.js.map +1 -0
  47. package/dist/core/formatTime.d.ts +8 -0
  48. package/dist/core/formatTime.js +20 -0
  49. package/dist/core/formatTime.js.map +1 -0
  50. package/dist/core/index.d.ts +7 -4
  51. package/dist/core/index.js +4 -1
  52. package/dist/core/index.js.map +1 -1
  53. package/dist/core/navigationPolicy.d.ts +46 -0
  54. package/dist/core/navigationPolicy.js +66 -0
  55. package/dist/core/navigationPolicy.js.map +1 -0
  56. package/dist/core/pause.d.ts +58 -0
  57. package/dist/core/pause.js +101 -0
  58. package/dist/core/pause.js.map +1 -0
  59. package/dist/core/playerEvents.d.ts +51 -0
  60. package/dist/core/playerEvents.js +66 -0
  61. package/dist/core/playerEvents.js.map +1 -0
  62. package/dist/core/reviewState.d.ts +81 -0
  63. package/dist/core/reviewState.js +113 -0
  64. package/dist/core/reviewState.js.map +1 -0
  65. package/dist/core/reviewViews.d.ts +43 -0
  66. package/dist/core/reviewViews.js +88 -0
  67. package/dist/core/reviewViews.js.map +1 -0
  68. package/dist/core/scopeLocks.d.ts +36 -0
  69. package/dist/core/scopeLocks.js +78 -0
  70. package/dist/core/scopeLocks.js.map +1 -0
  71. package/dist/core/sessionRecords.d.ts +31 -0
  72. package/dist/core/sessionRecords.js +74 -0
  73. package/dist/core/sessionRecords.js.map +1 -0
  74. package/dist/core/submissionPolicy.d.ts +65 -0
  75. package/dist/core/submissionPolicy.js +71 -0
  76. package/dist/core/submissionPolicy.js.map +1 -0
  77. package/dist/core/templateDefaults.d.ts +26 -0
  78. package/dist/core/templateDefaults.js +54 -0
  79. package/dist/core/templateDefaults.js.map +1 -0
  80. package/dist/core/testStructure.d.ts +118 -3
  81. package/dist/core/testStructure.js +255 -6
  82. package/dist/core/testStructure.js.map +1 -1
  83. package/dist/core/timePolicy.d.ts +40 -0
  84. package/dist/core/timePolicy.js +106 -0
  85. package/dist/core/timePolicy.js.map +1 -0
  86. package/dist/index.d.ts +7 -4
  87. package/dist/index.js +5 -1
  88. package/dist/index.js.map +1 -1
  89. package/dist/integration/ReferenceBackendAdapter.d.ts +64 -101
  90. package/dist/integration/ReferenceBackendAdapter.js +214 -1033
  91. package/dist/integration/ReferenceBackendAdapter.js.map +1 -1
  92. package/dist/integration/api-contract.d.ts +175 -10
  93. package/dist/integration/api-contract.js.map +1 -1
  94. package/dist/integration/assessment-item-scorer.d.ts +56 -5
  95. package/dist/integration/assessment-item-scorer.js +116 -13
  96. package/dist/integration/assessment-item-scorer.js.map +1 -1
  97. package/dist/integration/index.d.ts +2 -2
  98. package/dist/integration/index.js +1 -1
  99. package/dist/integration/index.js.map +1 -1
  100. package/dist/integration/qti-test-parser.d.ts +44 -0
  101. package/dist/integration/qti-test-parser.js +558 -0
  102. package/dist/integration/qti-test-parser.js.map +1 -0
  103. package/dist/integration/session-store.d.ts +54 -0
  104. package/dist/integration/session-store.js +75 -0
  105. package/dist/integration/session-store.js.map +1 -0
  106. package/dist/integration/test-navigation.d.ts +23 -0
  107. package/dist/integration/test-navigation.js +32 -0
  108. package/dist/integration/test-navigation.js.map +1 -0
  109. package/dist/integration/toSectionComposition.js +8 -1
  110. package/dist/integration/toSectionComposition.js.map +1 -1
  111. package/dist/reporting/index.d.ts +3 -0
  112. package/dist/reporting/index.js +3 -0
  113. package/dist/reporting/index.js.map +1 -0
  114. package/dist/reporting/inferBaseType.d.ts +13 -0
  115. package/dist/reporting/inferBaseType.js +26 -0
  116. package/dist/reporting/inferBaseType.js.map +1 -0
  117. package/dist/reporting/serializeAssessmentResult.d.ts +27 -0
  118. package/dist/reporting/serializeAssessmentResult.js +377 -0
  119. package/dist/reporting/serializeAssessmentResult.js.map +1 -0
  120. package/dist/reporting/toAssessmentResultXml.d.ts +39 -0
  121. package/dist/reporting/toAssessmentResultXml.js +304 -0
  122. package/dist/reporting/toAssessmentResultXml.js.map +1 -0
  123. package/dist/reporting/types.d.ts +85 -0
  124. package/dist/reporting/types.js +8 -0
  125. package/dist/reporting/types.js.map +1 -0
  126. package/dist/types/index.d.ts +96 -9
  127. package/dist/types/index.js.map +1 -1
  128. package/package.json +18 -14
  129. package/dist/core/StatePersistenceManager.d.ts +0 -125
  130. package/dist/core/StatePersistenceManager.js +0 -268
  131. package/dist/core/StatePersistenceManager.js.map +0 -1
  132. package/dist/utils/PerformanceMonitor.d.ts +0 -114
  133. package/dist/utils/PerformanceMonitor.js +0 -172
  134. package/dist/utils/PerformanceMonitor.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import type { SerializedItemSessionState } from '@pie-qti/item-player';
2
- import type { AssessmentSessionState } from '../integration/api-contract.js';
2
+ import type { AssessmentScoringResult, AssessmentSessionState } from '../integration/api-contract.js';
3
3
  import type { ItemResult } from '../types/index.js';
4
4
  import { type ItemSessionControlSettings } from './ItemSessionController.js';
5
5
  export interface AssessmentSessionCoordinatorOptions {
@@ -38,22 +38,91 @@ export declare class AssessmentSessionCoordinator {
38
38
  mergeItemSessions(itemSessions: AssessmentSessionState['itemSessions']): void;
39
39
  replaceStatePreservingItemSessions(updatedState: AssessmentSessionState): void;
40
40
  replaceStatePreservingResponsesAndSessions(updatedState: AssessmentSessionState, itemResponses: AssessmentSessionState['itemResponses'], itemSessions: AssessmentSessionState['itemSessions']): void;
41
+ /** Where delivery stands (navigation owns the pointer; the snapshot carries it). */
42
+ setCurrentItem(itemIdentifier: string): void;
43
+ /** The backend decision kept for the item (`state.branchDecisions`), if any. */
44
+ getBranchDecision(itemIdentifier: string): string | undefined;
45
+ /** Keep `target` as the one decision delivery may still follow — the item's freshest. */
46
+ keepBranchDecision(itemIdentifier: string, target: string): void;
47
+ /** Every kept decision is void: a counted submission moved the outcomes they decided on. */
48
+ clearBranchDecisions(): void;
49
+ /** The test-level outcomes the backend last returned (`state.testOutcomes`), if any. */
50
+ getTestOutcomes(): AssessmentSessionState['testOutcomes'];
51
+ /** Store the test-level outcomes the backend returned for its last outcome processing. */
52
+ setTestOutcomes(outcomes: AssessmentSessionState['testOutcomes']): void;
53
+ /**
54
+ * The live item session's responses mirrored into the persisted record: an
55
+ * equality-checked write (identical responses are not re-written or re-notified)
56
+ * plus the answered mark. Returns whether the record changed.
57
+ */
58
+ mirrorResponses(itemIdentifier: string, responses: Readonly<Record<string, unknown>>): boolean;
59
+ /**
60
+ * A counted individual submission the backend accepted WITH its `updatedState`:
61
+ * replace the session state with the backend's, keeping the client-owned position
62
+ * and the client-collected responses and sessions (the snapshot may only include
63
+ * the items submitted so far, which would otherwise wipe later answers).
64
+ */
65
+ recordSubmittedItemInUpdatedState(itemIdentifier: string, responses: Record<string, unknown>, updatedState: AssessmentSessionState): void;
66
+ /**
67
+ * A counted individual submission the backend accepted WITHOUT a state update:
68
+ * the minimal local commit — score, visited mark, responses, session snapshot.
69
+ */
70
+ recordIndividualSubmission(itemIdentifier: string, responses: Record<string, unknown>, itemSession: SerializedItemSessionState | undefined, scoring: AssessmentScoringResult): void;
71
+ /**
72
+ * A counted simultaneous-flush submission the backend accepted WITHOUT a state
73
+ * update: the minimal local commit plus the attempt record and the accepted
74
+ * result (its responses read back from the persisted record, as the flush loop did).
75
+ */
76
+ recordSimultaneousSubmission(itemIdentifier: string, responses: Record<string, unknown>, itemSession: SerializedItemSessionState, scoring: AssessmentScoringResult): void;
77
+ /**
78
+ * Record an attempt locally only when the backend has not counted it already: a
79
+ * backend `updatedState` carries its own authoritative count (`itemSessionStates`),
80
+ * which must not be counted twice.
81
+ */
82
+ recordAttemptIfUncounted(itemIdentifier: string, attemptsBefore: number): void;
83
+ /** The test ended: every delivered item session in the persisted record is closed. */
84
+ closeAllItemSessions(): void;
85
+ /** Whether the candidate hid the countdown (a persisted shell preference). */
86
+ setTimerHidden(hidden: boolean): void;
41
87
  markVisited(itemIdentifier: string): void;
42
88
  markAnswered(itemIdentifier: string, responses: Record<string, unknown>): void;
43
- canReview(itemIdentifier: string): boolean;
44
- canNavigateAway(itemIdentifier: string, responses: Record<string, unknown>): {
45
- allowed: boolean;
46
- reason?: string;
47
- };
89
+ /**
90
+ * Whether the candidate may return to the item: always before its first submission, and
91
+ * while attempts remain (an adaptive item: until it `completed`); after that QTI
92
+ * `allowReview` decides.
93
+ */
94
+ canReview(itemIdentifier: string, options?: {
95
+ completed?: boolean;
96
+ }): boolean;
48
97
  updateItemSessionControl(settings: ItemSessionControlSettings): void;
49
98
  mustValidateResponses(itemIdentifier?: string): boolean;
50
99
  canSubmit(itemIdentifier: string): boolean;
51
100
  getItemSettings(itemIdentifier: string): ItemSessionControlSettings;
52
- /** Records the candidate's comment on an item; throws unless its allowComment is on. */
101
+ /** Records the candidate's comment on an item; throws a coded error unless its allowComment is on. */
53
102
  setItemComment(itemIdentifier: string, comment: string): void;
54
103
  getItemComment(itemIdentifier: string): string | undefined;
104
+ /** Sets (or clears) the candidate's flag-for-review on an item. */
105
+ setItemFlag(itemIdentifier: string, flagged: boolean): void;
106
+ isItemFlagged(itemIdentifier: string): boolean;
107
+ getFlaggedItemIdentifiers(): string[];
55
108
  recordAttempt(itemIdentifier: string): void;
56
109
  setItemResult(itemResult: ItemResult): void;
57
110
  hasItemResult(itemIdentifier: string): boolean;
58
111
  getItemSessionInfo(itemIdentifier: string): ItemSessionInfo;
59
112
  }
113
+ /**
114
+ * True when any response value in the record carries learner input. Shared with the
115
+ * reference backend adapter so "answered" is decided identically on both sides.
116
+ */
117
+ export declare function hasAnyResponse(responses: Record<string, unknown>): boolean;
118
+ /** A response variable's declared default, with the cardinality that decides how it compares. */
119
+ export interface ResponseDefault {
120
+ value: unknown;
121
+ cardinality?: string;
122
+ }
123
+ /**
124
+ * QTI's skipped item (itemSessionControl `allowSkipping`): every response is NULL, empty, or
125
+ * still equal to its declared default — the same test `numberResponded` applies (a response
126
+ * that differs from its default). A `multiple` response compares as an unordered container.
127
+ */
128
+ export declare function isSkippedResponseSet(responses: Record<string, unknown>, defaults?: Readonly<Record<string, ResponseDefault>>): boolean;
@@ -10,7 +10,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
12
  var _AssessmentSessionCoordinator_instances, _AssessmentSessionCoordinator_state, _AssessmentSessionCoordinator_sessionController, _AssessmentSessionCoordinator_itemResults, _AssessmentSessionCoordinator_itemIdentifiers, _AssessmentSessionCoordinator_initializeItemSessions, _AssessmentSessionCoordinator_restoreItemSessionsFromState, _AssessmentSessionCoordinator_restoreItemResultsFromScores, _AssessmentSessionCoordinator_itemSessionStateSnapshot;
13
+ import { AssessmentPlayerError } from './errors.js';
13
14
  import { ItemSessionController, } from './ItemSessionController.js';
15
+ import { asResponseValues, cloneData, cloneResponseRecord, closedItemSession, responseValuesEqual, } from './sessionRecords.js';
14
16
  export class AssessmentSessionCoordinator {
15
17
  constructor({ state, itemIdentifiers, itemSessionControl, itemSessionControlByItem }) {
16
18
  _AssessmentSessionCoordinator_instances.add(this);
@@ -47,6 +49,9 @@ export class AssessmentSessionCoordinator {
47
49
  : undefined,
48
50
  itemSessionStates: __classPrivateFieldGet(this, _AssessmentSessionCoordinator_instances, "m", _AssessmentSessionCoordinator_itemSessionStateSnapshot).call(this),
49
51
  itemComments: __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemComments ? { ...__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemComments } : undefined,
52
+ itemFlags: __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemFlags ? { ...__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemFlags } : undefined,
53
+ branchDecisions: __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").branchDecisions ? { ...__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").branchDecisions } : undefined,
54
+ testOutcomes: __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").testOutcomes ? { ...__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").testOutcomes } : undefined,
50
55
  timing: {
51
56
  ...__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").timing,
52
57
  itemTimes: { ...__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").timing.itemTimes },
@@ -80,7 +85,7 @@ export class AssessmentSessionCoordinator {
80
85
  ...(__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemResponses?.[itemIdentifier] || {}),
81
86
  [responseId]: value,
82
87
  };
83
- __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemResponses[itemIdentifier] = next;
88
+ __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemResponses[itemIdentifier] = asResponseValues(next);
84
89
  this.markAnswered(itemIdentifier, next);
85
90
  return next;
86
91
  }
@@ -89,7 +94,7 @@ export class AssessmentSessionCoordinator {
89
94
  ...(__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemSessions ?? {}),
90
95
  [itemIdentifier]: sessionState,
91
96
  };
92
- __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemResponses[itemIdentifier] = responses;
97
+ __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemResponses[itemIdentifier] = asResponseValues(responses);
93
98
  __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").timing.itemTimes[itemIdentifier] = duration;
94
99
  this.markAnswered(itemIdentifier, responses);
95
100
  }
@@ -113,12 +118,136 @@ export class AssessmentSessionCoordinator {
113
118
  this.mergeItemSessions(localItemSessions);
114
119
  }
115
120
  replaceStatePreservingResponsesAndSessions(updatedState, itemResponses, itemSessions) {
121
+ // Where the candidate stands is the client's: delivery moves through navigation (a
122
+ // branch decision is `nextItemIdentifier`), never through a backend state update,
123
+ // whose position may be stale — or already overtaken by a scope expiry's move.
124
+ const currentItemIdentifier = __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").currentItemIdentifier;
125
+ // The test outcomes the client already mirrored into its state survive a backend
126
+ // snapshot that does not carry the field; a snapshot that does wins (its values are
127
+ // the fresher outcome processing's).
128
+ const testOutcomes = updatedState.testOutcomes ?? __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").testOutcomes;
116
129
  this.restoreState(updatedState);
130
+ __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").currentItemIdentifier = currentItemIdentifier;
117
131
  // Own the accepted snapshots rather than retaining the submit loop's mutable
118
132
  // working maps. Later provisional items must not appear committed until their
119
133
  // backend request succeeds.
120
134
  __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemResponses = { ...itemResponses };
121
135
  __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemSessions = itemSessions ? { ...itemSessions } : undefined;
136
+ __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").testOutcomes = testOutcomes ? { ...testOutcomes } : undefined;
137
+ }
138
+ // ---------------------------------------------------------------------------
139
+ // Submission commits — the only writers of session state.
140
+ //
141
+ // One method per submit-path combination (individual / simultaneous × backend
142
+ // returns / omits `updatedState`), reproducing exactly the state writes the
143
+ // player's submit loops used to make inline.
144
+ // ---------------------------------------------------------------------------
145
+ /** Where delivery stands (navigation owns the pointer; the snapshot carries it). */
146
+ setCurrentItem(itemIdentifier) {
147
+ __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").currentItemIdentifier = itemIdentifier;
148
+ }
149
+ /** The backend decision kept for the item (`state.branchDecisions`), if any. */
150
+ getBranchDecision(itemIdentifier) {
151
+ return __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").branchDecisions?.[itemIdentifier];
152
+ }
153
+ /** Keep `target` as the one decision delivery may still follow — the item's freshest. */
154
+ keepBranchDecision(itemIdentifier, target) {
155
+ __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").branchDecisions = { [itemIdentifier]: target };
156
+ }
157
+ /** Every kept decision is void: a counted submission moved the outcomes they decided on. */
158
+ clearBranchDecisions() {
159
+ delete __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").branchDecisions;
160
+ }
161
+ /** The test-level outcomes the backend last returned (`state.testOutcomes`), if any. */
162
+ getTestOutcomes() {
163
+ return __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").testOutcomes;
164
+ }
165
+ /** Store the test-level outcomes the backend returned for its last outcome processing. */
166
+ setTestOutcomes(outcomes) {
167
+ __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").testOutcomes = outcomes ? { ...outcomes } : undefined;
168
+ }
169
+ /**
170
+ * The live item session's responses mirrored into the persisted record: an
171
+ * equality-checked write (identical responses are not re-written or re-notified)
172
+ * plus the answered mark. Returns whether the record changed.
173
+ */
174
+ mirrorResponses(itemIdentifier, responses) {
175
+ const current = this.getResponses(itemIdentifier);
176
+ if (responseValuesEqual(current, responses))
177
+ return false;
178
+ const snapshot = cloneResponseRecord(responses);
179
+ __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemResponses[itemIdentifier] = asResponseValues(snapshot);
180
+ this.markAnswered(itemIdentifier, snapshot);
181
+ return true;
182
+ }
183
+ /**
184
+ * A counted individual submission the backend accepted WITH its `updatedState`:
185
+ * replace the session state with the backend's, keeping the client-owned position
186
+ * and the client-collected responses and sessions (the snapshot may only include
187
+ * the items submitted so far, which would otherwise wipe later answers).
188
+ */
189
+ recordSubmittedItemInUpdatedState(itemIdentifier, responses, updatedState) {
190
+ const localResponses = cloneData(__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemResponses || {});
191
+ localResponses[itemIdentifier] = asResponseValues(cloneResponseRecord(responses));
192
+ this.replaceStatePreservingResponsesAndSessions(updatedState, localResponses, cloneData(__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemSessions || {}));
193
+ }
194
+ /**
195
+ * A counted individual submission the backend accepted WITHOUT a state update:
196
+ * the minimal local commit — score, visited mark, responses, session snapshot.
197
+ */
198
+ recordIndividualSubmission(itemIdentifier, responses, itemSession, scoring) {
199
+ __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemScores = __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemScores || {};
200
+ __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemScores[itemIdentifier] = scoring;
201
+ this.markVisited(itemIdentifier);
202
+ __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemResponses[itemIdentifier] = asResponseValues(responses);
203
+ if (itemSession) {
204
+ this.setItemSession(itemIdentifier, itemSession);
205
+ }
206
+ }
207
+ /**
208
+ * A counted simultaneous-flush submission the backend accepted WITHOUT a state
209
+ * update: the minimal local commit plus the attempt record and the accepted
210
+ * result (its responses read back from the persisted record, as the flush loop did).
211
+ */
212
+ recordSimultaneousSubmission(itemIdentifier, responses, itemSession, scoring) {
213
+ __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemScores = __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemScores || {};
214
+ __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemScores[itemIdentifier] = scoring;
215
+ this.markVisited(itemIdentifier);
216
+ __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemResponses[itemIdentifier] = asResponseValues(responses);
217
+ this.setItemSession(itemIdentifier, itemSession);
218
+ this.recordAttempt(itemIdentifier);
219
+ this.setItemResult({
220
+ itemIdentifier,
221
+ score: scoring.score,
222
+ maxScore: scoring.maxScore,
223
+ responses: __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemResponses[itemIdentifier] || {},
224
+ });
225
+ }
226
+ /**
227
+ * Record an attempt locally only when the backend has not counted it already: a
228
+ * backend `updatedState` carries its own authoritative count (`itemSessionStates`),
229
+ * which must not be counted twice.
230
+ */
231
+ recordAttemptIfUncounted(itemIdentifier, attemptsBefore) {
232
+ try {
233
+ if (this.getItemSessionInfo(itemIdentifier).attemptCount <= attemptsBefore) {
234
+ this.recordAttempt(itemIdentifier);
235
+ }
236
+ }
237
+ catch {
238
+ // ignore
239
+ }
240
+ }
241
+ /** The test ended: every delivered item session in the persisted record is closed. */
242
+ closeAllItemSessions() {
243
+ const sessions = __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemSessions;
244
+ if (sessions) {
245
+ __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemSessions = Object.fromEntries(Object.entries(sessions).map(([identifier, session]) => [identifier, closedItemSession(session)]));
246
+ }
247
+ }
248
+ /** Whether the candidate hid the countdown (a persisted shell preference). */
249
+ setTimerHidden(hidden) {
250
+ __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").timerHidden = hidden;
122
251
  }
123
252
  markVisited(itemIdentifier) {
124
253
  if (!__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").visitedItems.includes(itemIdentifier)) {
@@ -128,11 +257,13 @@ export class AssessmentSessionCoordinator {
128
257
  markAnswered(itemIdentifier, responses) {
129
258
  __classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").markAnswered(itemIdentifier, hasAnyResponse(responses));
130
259
  }
131
- canReview(itemIdentifier) {
132
- return __classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").canReview(itemIdentifier);
133
- }
134
- canNavigateAway(itemIdentifier, responses) {
135
- return __classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").canNavigateAway(itemIdentifier, hasAnyResponse(responses));
260
+ /**
261
+ * Whether the candidate may return to the item: always before its first submission, and
262
+ * while attempts remain (an adaptive item: until it `completed`); after that QTI
263
+ * `allowReview` decides.
264
+ */
265
+ canReview(itemIdentifier, options = {}) {
266
+ return __classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").canReview(itemIdentifier, options);
136
267
  }
137
268
  updateItemSessionControl(settings) {
138
269
  __classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").updateSettings(settings);
@@ -146,16 +277,31 @@ export class AssessmentSessionCoordinator {
146
277
  getItemSettings(itemIdentifier) {
147
278
  return __classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").getItemSettings(itemIdentifier);
148
279
  }
149
- /** Records the candidate's comment on an item; throws unless its allowComment is on. */
280
+ /** Records the candidate's comment on an item; throws a coded error unless its allowComment is on. */
150
281
  setItemComment(itemIdentifier, comment) {
151
282
  if (!__classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").canComment(itemIdentifier)) {
152
- throw new Error(`Comments are not allowed for item "${itemIdentifier}".`);
283
+ throw new AssessmentPlayerError('commentsNotAllowed', `Comments are not allowed for item "${itemIdentifier}".`);
153
284
  }
154
285
  __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemComments = { ...(__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemComments ?? {}), [itemIdentifier]: comment };
155
286
  }
156
287
  getItemComment(itemIdentifier) {
157
288
  return __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemComments?.[itemIdentifier];
158
289
  }
290
+ /** Sets (or clears) the candidate's flag-for-review on an item. */
291
+ setItemFlag(itemIdentifier, flagged) {
292
+ const flags = { ...(__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemFlags ?? {}) };
293
+ if (flagged)
294
+ flags[itemIdentifier] = true;
295
+ else
296
+ delete flags[itemIdentifier];
297
+ __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemFlags = flags;
298
+ }
299
+ isItemFlagged(itemIdentifier) {
300
+ return __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemFlags?.[itemIdentifier] === true;
301
+ }
302
+ getFlaggedItemIdentifiers() {
303
+ return Object.keys(__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemFlags ?? {}).filter((id) => __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemFlags?.[id] === true);
304
+ }
159
305
  recordAttempt(itemIdentifier) {
160
306
  __classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").recordAttempt(itemIdentifier);
161
307
  }
@@ -228,7 +374,11 @@ _AssessmentSessionCoordinator_state = new WeakMap(), _AssessmentSessionCoordinat
228
374
  { ...state },
229
375
  ]));
230
376
  };
231
- function hasAnyResponse(responses) {
377
+ /**
378
+ * True when any response value in the record carries learner input. Shared with the
379
+ * reference backend adapter so "answered" is decided identically on both sides.
380
+ */
381
+ export function hasAnyResponse(responses) {
232
382
  for (const value of Object.values(responses)) {
233
383
  if (value == null)
234
384
  continue;
@@ -246,4 +396,29 @@ function hasAnyResponse(responses) {
246
396
  }
247
397
  return false;
248
398
  }
399
+ /**
400
+ * QTI's skipped item (itemSessionControl `allowSkipping`): every response is NULL, empty, or
401
+ * still equal to its declared default — the same test `numberResponded` applies (a response
402
+ * that differs from its default). A `multiple` response compares as an unordered container.
403
+ */
404
+ export function isSkippedResponseSet(responses, defaults = {}) {
405
+ for (const [identifier, value] of Object.entries(responses)) {
406
+ if (!hasAnyResponse({ [identifier]: value }))
407
+ continue;
408
+ const declared = defaults[identifier];
409
+ if (declared && declared.value != null && responseEqualsDefault(value, declared))
410
+ continue;
411
+ return false;
412
+ }
413
+ return true;
414
+ }
415
+ function responseEqualsDefault(value, declared) {
416
+ if (declared.cardinality === 'multiple' && Array.isArray(value) && Array.isArray(declared.value)) {
417
+ const canonical = (entries) => entries.map((entry) => JSON.stringify(entry)).sort();
418
+ const left = canonical(value);
419
+ const right = canonical(declared.value);
420
+ return left.length === right.length && left.every((entry, index) => entry === right[index]);
421
+ }
422
+ return JSON.stringify(value) === JSON.stringify(declared.value);
423
+ }
249
424
  //# sourceMappingURL=AssessmentSessionCoordinator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AssessmentSessionCoordinator.js","sourceRoot":"","sources":["../../src/core/AssessmentSessionCoordinator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,OAAO,EACN,qBAAqB,GAGrB,MAAM,4BAA4B,CAAC;AAqBpC,MAAM,OAAO,4BAA4B;IAMxC,YAAY,EAAE,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,wBAAwB,EAAuC;;QALzH,sDAA+B;QAC/B,kEAA0C;QAC1C,oDAAe,IAAI,GAAG,EAAsB,EAAC;QAC7C,gEAA2B;QAG1B,uBAAA,IAAI,uCAAU,KAAK,MAAA,CAAC;QACpB,uBAAA,IAAI,iDAAoB,eAAe,MAAA,CAAC;QACxC,uBAAA,IAAI,mDAAsB,IAAI,qBAAqB,CAAC,kBAAkB,CAAC,MAAA,CAAC;QACxE,KAAK,MAAM,CAAC,cAAc,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,wBAAwB,IAAI,EAAE,CAAC,EAAE,CAAC;YACzF,uBAAA,IAAI,uDAAmB,CAAC,eAAe,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;QACnE,CAAC;QACD,uBAAA,IAAI,qGAAwB,MAA5B,IAAI,CAA0B,CAAC;QAC/B,uBAAA,IAAI,2GAA8B,MAAlC,IAAI,EAA+B,KAAK,CAAC,CAAC;QAC1C,uBAAA,IAAI,2GAA8B,MAAlC,IAAI,EAA+B,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,IAAI,KAAK;QACR,OAAO,uBAAA,IAAI,2CAAO,CAAC;IACpB,CAAC;IAED,YAAY,CAAC,KAA6B;QACzC,uBAAA,IAAI,uCAAU,KAAK,MAAA,CAAC;QACpB,uBAAA,IAAI,2GAA8B,MAAlC,IAAI,EAA+B,KAAK,CAAC,CAAC;QAC1C,uBAAA,IAAI,2GAA8B,MAAlC,IAAI,EAA+B,KAAK,CAAC,C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AC;YAC1B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;gBAAE,OAAO,IAAI,CAAC;YAClC,SAAS;QACV,CAAC;QACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC/B,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;gBAAE,OAAO,IAAI,CAAC;YACzC,SAAS;QACV,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC","sourcesContent":["import type { SerializedItemSessionState } from '@pie-qti/item-player';\nimport type { AssessmentSessionState } from '../integration/api-contract.js';\nimport type { ItemResult } from '../types/index.js';\nimport {\n\tItemSessionController,\n\ttype ItemSessionControlSettings,\n\ttype ItemSessionState,\n} from './ItemSessionController.js';\n\nexport interface AssessmentSessionCoordinatorOptions {\n\tstate: AssessmentSessionState;\n\titemIdentifiers: string[];\n\titemSessionControl?: ItemSessionControlSettings;\n\t/** Effective itemSessionControl per item, overriding `itemSessionControl` for those items. */\n\titemSessionControlByItem?: Record<string, ItemSessionControlSettings>;\n}\n\nexport interface ItemSessionInfo {\n\tcanSubmit: boolean;\n\tremainingAttempts: number | null;\n\tattemptCount: number;\n\tshowFeedback: boolean;\n\tshowSolution: boolean;\n\tcanReview: boolean;\n\tcanSkip: boolean;\n\tcanComment: boolean;\n}\n\nexport class AssessmentSessionCoordinator {\n\t#state: AssessmentSessionState;\n\t#sessionController: ItemSessionController;\n\t#itemResults = new Map<string, ItemResult>();\n\t#itemIdentifiers: string[];\n\n\tconstructor({ state, itemIdentifiers, itemSessionControl, itemSessionControlByItem }: AssessmentSessionCoordinatorOptions) {\n\t\tthis.#state = state;\n\t\tthis.#itemIdentifiers = itemIdentifiers;\n\t\tthis.#sessionController = new ItemSessionController(itemSessionControl);\n\t\tfor (const [itemIdentifier, settings] of Object.entries(itemSessionControlByItem ?? {})) {\n\t\t\tthis.#sessionController.setItemSettings(itemIdentifier, settings);\n\t\t}\n\t\tthis.#initializeItemSessions();\n\t\tthis.#restoreItemSessionsFromState(state);\n\t\tthis.#restoreItemResultsFromScores(state);\n\t}\n\n\tget state() {\n\t\treturn this.#state;\n\t}\n\n\trestoreState(state: AssessmentSessionState): void {\n\t\tthis.#state = state;\n\t\tthis.#restoreItemSessionsFromState(state);\n\t\tthis.#restoreItemResultsFromScores(state);\n\t}\n\n\tsnapshot(options: { includeItemSessions?: boolean } = {}): AssessmentSessionState {\n\t\treturn {\n\t\t\t...this.#state,\n\t\t\tvisitedItems: [...this.#state.visitedItems],\n\t\t\titemResponses: { ...this.#state.itemResponses },\n\t\t\titemScores: this.#state.itemScores ? { ...this.#state.itemScores } : undefined,\n\t\t\titemSessions:\n\t\t\t\toptions.includeItemSessions && this.#state.itemSessions\n\t\t\t\t\t? { ...this.#state.itemSessions }\n\t\t\t\t\t: undefined,\n\t\t\titemSessionStates: this.#itemSessionStateSnapshot(),\n\t\t\titemComments: this.#state.itemComments ? { ...this.#state.itemComments } : undefined,\n\t\t\ttiming: {\n\t\t\t\t...this.#state.timing,\n\t\t\t\titemTimes: { ...this.#state.timing.itemTimes },\n\t\t\t\tsectionTimes: this.#state.timing.sectionTimes\n\t\t\t\t\t? { ...this.#state.timing.sectionTimes }\n\t\t\t\t\t: undefined,\n\t\t\t\ttestPartTimes: this.#state.timing.testPartTimes\n\t\t\t\t\t? { ...this.#state.timing.testPartTimes }\n\t\t\t\t\t: undefined,\n\t\t\t},\n\t\t};\n\t}\n\n\tactivateItem(itemIdentifier: string): Record<string, unknown> {\n\t\tthis.#state.currentItemIdentifier = itemIdentifier;\n\t\treturn this.getResponses(itemIdentifier);\n\t}\n\n\tgetActiveResponses(): Record<string, unknown> {\n\t\treturn this.getResponses(this.#state.currentItemIdentifier);\n\t}\n\n\tgetResponses(itemIdentifier: string): Record<string, unknown> {\n\t\treturn { ...((this.#state.itemResponses?.[itemIdentifier] || {}) as Record<string, unknown>) };\n\t}\n\n\tgetPersistedItemSession(itemIdentifier: string): SerializedItemSessionState | undefined {\n\t\treturn this.#state.itemSessions?.[itemIdentifier];\n\t}\n\n\tupdateActiveResponse(responseId: string, value: unknown): Record<string, unknown> {\n\t\treturn this.updateResponseForItem(this.#state.currentItemIdentifier, responseId, value);\n\t}\n\n\tupdateResponseForItem(\n\t\titemIdentifier: string,\n\t\tresponseId: string,\n\t\tvalue: unknown\n\t): Record<string, unknown> {\n\t\tconst next = {\n\t\t\t...((this.#state.itemResponses?.[itemIdentifier] || {}) as Record<string, unknown>),\n\t\t\t[responseId]: value,\n\t\t};\n\t\tthis.#state.itemResponses[itemIdentifier] = next as any;\n\t\tthis.markAnswered(itemIdentifier, next);\n\t\treturn next;\n\t}\n\n\tsaveItemSession(\n\t\titemIdentifier: string,\n\t\tresponses: Record<string, unknown>,\n\t\tsessionState: SerializedItemSessionState,\n\t\tduration: number\n\t): void {\n\t\tthis.#state.itemSessions = {\n\t\t\t...(this.#state.itemSessions ?? {}),\n\t\t\t[itemIdentifier]: sessionState,\n\t\t};\n\t\tthis.#state.itemResponses[itemIdentifier] = responses as any;\n\t\tthis.#state.timing.itemTimes[itemIdentifier] = duration;\n\t\tthis.markAnswered(itemIdentifier, responses);\n\t}\n\n\tsetItemSession(itemIdentifier: string, sessionState: SerializedItemSessionState): void {\n\t\tthis.#state.itemSessions = {\n\t\t\t...(this.#state.itemSessions ?? {}),\n\t\t\t[itemIdentifier]: sessionState,\n\t\t};\n\t}\n\n\tmergeItemSessions(itemSessions: AssessmentSessionState['itemSessions']): void {\n\t\tif (!itemSessions) return;\n\t\tthis.#state.itemSessions = {\n\t\t\t...(this.#state.itemSessions ?? {}),\n\t\t\t...itemSessions,\n\t\t};\n\t}\n\n\treplaceStatePreservingItemSessions(updatedState: AssessmentSessionState): void {\n\t\tconst localItemSessions = this.#state.itemSessions;\n\t\tthis.restoreState(updatedState);\n\t\tthis.mergeItemSessions(localItemSessions);\n\t}\n\n\treplaceStatePreservingResponsesAndSessions(\n\t\tupdatedState: AssessmentSessionState,\n\t\titemResponses: AssessmentSessionState['itemResponses'],\n\t\titemSessions: AssessmentSessionState['itemSessions']\n\t): void {\n\t\tthis.restoreState(updatedState);\n\t\t// Own the accepted snapshots rather than retaining the submit loop's mutable\n\t\t// working maps. Later provisional items must not appear committed until their\n\t\t// backend request succeeds.\n\t\tthis.#state.itemResponses = { ...itemResponses };\n\t\tthis.#state.itemSessions = itemSessions ? { ...itemSessions } : undefined;\n\t}\n\n\tmarkVisited(itemIdentifier: string): void {\n\t\tif (!this.#state.visitedItems.includes(itemIdentifier)) {\n\t\t\tthis.#state.visitedItems.push(itemIdentifier);\n\t\t}\n\t}\n\n\tmarkAnswered(itemIdentifier: string, responses: Record<string, unknown>): void {\n\t\tthis.#sessionController.markAnswered(itemIdentifier, hasAnyResponse(responses));\n\t}\n\n\tcanReview(itemIdentifier: string): boolean {\n\t\treturn this.#sessionController.canReview(itemIdentifier);\n\t}\n\n\tcanNavigateAway(\n\t\titemIdentifier: string,\n\t\tresponses: Record<string, unknown>\n\t): { allowed: boolean; reason?: string } {\n\t\treturn this.#sessionController.canNavigateAway(itemIdentifier, hasAnyResponse(responses));\n\t}\n\n\tupdateItemSessionControl(settings: ItemSessionControlSettings): void {\n\t\tthis.#sessionController.updateSettings(settings);\n\t}\n\n\tmustValidateResponses(itemIdentifier?: string): boolean {\n\t\treturn this.#sessionController.mustValidateResponses(itemIdentifier);\n\t}\n\n\tcanSubmit(itemIdentifier: string): boolean {\n\t\treturn this.#sessionController.canSubmit(itemIdentifier);\n\t}\n\n\tgetItemSettings(itemIdentifier: string): ItemSessionControlSettings {\n\t\treturn this.#sessionController.getItemSettings(itemIdentifier);\n\t}\n\n\t/** Records the candidate's comment on an item; throws unless its allowComment is on. */\n\tsetItemComment(itemIdentifier: string, comment: string): void {\n\t\tif (!this.#sessionController.canComment(itemIdentifier)) {\n\t\t\tthrow new Error(`Comments are not allowed for item \"${itemIdentifier}\".`);\n\t\t}\n\t\tthis.#state.itemComments = { ...(this.#state.itemComments ?? {}), [itemIdentifier]: comment };\n\t}\n\n\tgetItemComment(itemIdentifier: string): string | undefined {\n\t\treturn this.#state.itemComments?.[itemIdentifier];\n\t}\n\n\trecordAttempt(itemIdentifier: string): void {\n\t\tthis.#sessionController.recordAttempt(itemIdentifier);\n\t}\n\n\tsetItemResult(itemResult: ItemResult): void {\n\t\tthis.#itemResults.set(itemResult.itemIdentifier, itemResult);\n\t}\n\n\thasItemResult(itemIdentifier: string): boolean {\n\t\treturn this.#itemResults.has(itemIdentifier);\n\t}\n\n\tgetItemSessionInfo(itemIdentifier: string): ItemSessionInfo {\n\t\tif (!this.#sessionController.getItemState(itemIdentifier)) {\n\t\t\tthis.#sessionController.initializeItem(itemIdentifier);\n\t\t}\n\t\tconst state = this.#sessionController.getItemState(itemIdentifier);\n\t\treturn {\n\t\t\tcanSubmit: this.#sessionController.canSubmit(itemIdentifier),\n\t\t\tremainingAttempts: this.#sessionController.getRemainingAttempts(itemIdentifier),\n\t\t\tattemptCount: state?.attemptCount ?? 0,\n\t\t\tshowFeedback: this.#sessionController.shouldShowFeedback(itemIdentifier),\n\t\t\tshowSolution: this.#sessionController.shouldShowSolution(itemIdentifier),\n\t\t\tcanReview: this.#sessionController.canReview(itemIdentifier),\n\t\t\tcanSkip: this.#sessionController.canSkip(itemIdentifier),\n\t\t\tcanComment: this.#sessionController.canComment(itemIdentifier),\n\t\t};\n\t}\n\n\t#initializeItemSessions(): void {\n\t\tfor (const itemIdentifier of this.#itemIdentifiers) {\n\t\t\tthis.#sessionController.initializeItem(itemIdentifier);\n\t\t}\n\t}\n\n\t#restoreItemSessionsFromState(state: AssessmentSessionState): void {\n\t\tconst restoredStates = new Map<string, ItemSessionState>();\n\t\tfor (const itemIdentifier of this.#itemIdentifiers) {\n\t\t\tconst persisted = state.itemSessionStates?.[itemIdentifier];\n\t\t\tif (persisted) {\n\t\t\t\trestoredStates.set(itemIdentifier, {\n\t\t\t\t\titemIdentifier,\n\t\t\t\t\tattemptCount: Math.max(0, persisted.attemptCount),\n\t\t\t\t\tisAnswered: persisted.isAnswered,\n\t\t\t\t\tisSubmitted: persisted.isSubmitted,\n\t\t\t\t\tlastSubmissionTime: persisted.lastSubmissionTime,\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst responses = state.itemResponses?.[itemIdentifier] ?? {};\n\t\t\tconst isSubmitted = Boolean(state.itemScores?.[itemIdentifier]);\n\t\t\trestoredStates.set(itemIdentifier, {\n\t\t\t\titemIdentifier,\n\t\t\t\tattemptCount: isSubmitted ? 1 : 0,\n\t\t\t\tisAnswered: hasAnyResponse(responses),\n\t\t\t\tisSubmitted,\n\t\t\t});\n\t\t}\n\t\tthis.#sessionController.restoreStates(restoredStates);\n\t}\n\n\t#restoreItemResultsFromScores(state: AssessmentSessionState): void {\n\t\tthis.#itemResults.clear();\n\t\tif (!state.itemScores) return;\n\t\tfor (const [itemIdentifier, scoring] of Object.entries(state.itemScores)) {\n\t\t\tthis.#itemResults.set(itemIdentifier, {\n\t\t\t\titemIdentifier,\n\t\t\t\tscore: scoring.score,\n\t\t\t\tmaxScore: scoring.maxScore,\n\t\t\t\tresponses: state.itemResponses?.[itemIdentifier] || {},\n\t\t\t});\n\t\t}\n\t}\n\n\t#itemSessionStateSnapshot(): Record<string, ItemSessionState> {\n\t\treturn Object.fromEntries(\n\t\t\t[...this.#sessionController.getAllStates().entries()].map(([itemIdentifier, state]) => [\n\t\t\t\titemIdentifier,\n\t\t\t\t{ ...state },\n\t\t\t])\n\t\t);\n\t}\n}\n\nfunction hasAnyResponse(responses: Record<string, unknown>): boolean {\n\tfor (const value of Object.values(responses)) {\n\t\tif (value == null) continue;\n\t\tif (Array.isArray(value)) {\n\t\t\tif (value.length > 0) return true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof value === 'string') {\n\t\t\tif (value.trim().length > 0) return true;\n\t\t\tcontinue;\n\t\t}\n\t\treturn true;\n\t}\n\treturn false;\n}\n"]}
1
+ {"version":3,"file":"Assessm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AC;AAED,SAAS,qBAAqB,CAAC,KAAc,EAAE,QAAyB;IACvE,IAAI,QAAQ,CAAC,WAAW,KAAK,UAAU,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAClG,MAAM,SAAS,GAAG,CAAC,OAAkB,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC/F,MAAM,IAAI,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAC9B,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACxC,OAAO,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7F,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import type { SerializedItemSessionState } from '@pie-qti/item-player';\nimport type { AssessmentScoringResult, AssessmentSessionState } from '../integration/api-contract.js';\nimport type { ItemResult } from '../types/index.js';\nimport { AssessmentPlayerError } from './errors.js';\nimport {\n\tItemSessionController,\n\ttype ItemSessionControlSettings,\n\ttype ItemSessionState,\n} from './ItemSessionController.js';\nimport {\n\tasResponseValues,\n\tcloneData,\n\tcloneResponseRecord,\n\tclosedItemSession,\n\tresponseValuesEqual,\n} from './sessionRecords.js';\n\nexport interface AssessmentSessionCoordinatorOptions {\n\tstate: AssessmentSessionState;\n\titemIdentifiers: string[];\n\titemSessionControl?: ItemSessionControlSettings;\n\t/** Effective itemSessionControl per item, overriding `itemSessionControl` for those items. */\n\titemSessionControlByItem?: Record<string, ItemSessionControlSettings>;\n}\n\nexport interface ItemSessionInfo {\n\tcanSubmit: boolean;\n\tremainingAttempts: number | null;\n\tattemptCount: number;\n\tshowFeedback: boolean;\n\tshowSolution: boolean;\n\tcanReview: boolean;\n\tcanSkip: boolean;\n\tcanComment: boolean;\n}\n\nexport class AssessmentSessionCoordinator {\n\t#state: AssessmentSessionState;\n\t#sessionController: ItemSessionController;\n\t#itemResults = new Map<string, ItemResult>();\n\t#itemIdentifiers: string[];\n\n\tconstructor({ state, itemIdentifiers, itemSessionControl, itemSessionControlByItem }: AssessmentSessionCoordinatorOptions) {\n\t\tthis.#state = state;\n\t\tthis.#itemIdentifiers = itemIdentifiers;\n\t\tthis.#sessionController = new ItemSessionController(itemSessionControl);\n\t\tfor (const [itemIdentifier, settings] of Object.entries(itemSessionControlByItem ?? {})) {\n\t\t\tthis.#sessionController.setItemSettings(itemIdentifier, settings);\n\t\t}\n\t\tthis.#initializeItemSessions();\n\t\tthis.#restoreItemSessionsFromState(state);\n\t\tthis.#restoreItemResultsFromScores(state);\n\t}\n\n\tget state() {\n\t\treturn this.#state;\n\t}\n\n\trestoreState(state: AssessmentSessionState): void {\n\t\tthis.#state = state;\n\t\tthis.#restoreItemSessionsFromState(state);\n\t\tthis.#restoreItemResultsFromScores(state);\n\t}\n\n\tsnapshot(options: { includeItemSessions?: boolean } = {}): AssessmentSessionState {\n\t\treturn {\n\t\t\t...this.#state,\n\t\t\tvisitedItems: [...this.#state.visitedItems],\n\t\t\titemResponses: { ...this.#state.itemResponses },\n\t\t\titemScores: this.#state.itemScores ? { ...this.#state.itemScores } : undefined,\n\t\t\titemSessions:\n\t\t\t\toptions.includeItemSessions && this.#state.itemSessions\n\t\t\t\t\t? { ...this.#state.itemSessions }\n\t\t\t\t\t: undefined,\n\t\t\titemSessionStates: this.#itemSessionStateSnapshot(),\n\t\t\titemComments: this.#state.itemComments ? { ...this.#state.itemComments } : undefined,\n\t\t\titemFlags: this.#state.itemFlags ? { ...this.#state.itemFlags } : undefined,\n\t\t\tbranchDecisions: this.#state.branchDecisions ? { ...this.#state.branchDecisions } : undefined,\n\t\t\ttestOutcomes: this.#state.testOutcomes ? { ...this.#state.testOutcomes } : undefined,\n\t\t\ttiming: {\n\t\t\t\t...this.#state.timing,\n\t\t\t\titemTimes: { ...this.#state.timing.itemTimes },\n\t\t\t\tsectionTimes: this.#state.timing.sectionTimes\n\t\t\t\t\t? { ...this.#state.timing.sectionTimes }\n\t\t\t\t\t: undefined,\n\t\t\t\ttestPartTimes: this.#state.timing.testPartTimes\n\t\t\t\t\t? { ...this.#state.timing.testPartTimes }\n\t\t\t\t\t: undefined,\n\t\t\t},\n\t\t};\n\t}\n\n\tactivateItem(itemIdentifier: string): Record<string, unknown> {\n\t\tthis.#state.currentItemIdentifier = itemIdentifier;\n\t\treturn this.getResponses(itemIdentifier);\n\t}\n\n\tgetActiveResponses(): Record<string, unknown> {\n\t\treturn this.getResponses(this.#state.currentItemIdentifier);\n\t}\n\n\tgetResponses(itemIdentifier: string): Record<string, unknown> {\n\t\treturn { ...((this.#state.itemResponses?.[itemIdentifier] || {}) as Record<string, unknown>) };\n\t}\n\n\tgetPersistedItemSession(itemIdentifier: string): SerializedItemSessionState | undefined {\n\t\treturn this.#state.itemSessions?.[itemIdentifier];\n\t}\n\n\tupdateActiveResponse(responseId: string, value: unknown): Record<string, unknown> {\n\t\treturn this.updateResponseForItem(this.#state.currentItemIdentifier, responseId, value);\n\t}\n\n\tupdateResponseForItem(\n\t\titemIdentifier: string,\n\t\tresponseId: string,\n\t\tvalue: unknown\n\t): Record<string, unknown> {\n\t\tconst next = {\n\t\t\t...((this.#state.itemResponses?.[itemIdentifier] || {}) as Record<string, unknown>),\n\t\t\t[responseId]: value,\n\t\t};\n\t\tthis.#state.itemResponses[itemIdentifier] = asResponseValues(next);\n\t\tthis.markAnswered(itemIdentifier, next);\n\t\treturn next;\n\t}\n\n\tsaveItemSession(\n\t\titemIdentifier: string,\n\t\tresponses: Record<string, unknown>,\n\t\tsessionState: SerializedItemSessionState,\n\t\tduration: number\n\t): void {\n\t\tthis.#state.itemSessions = {\n\t\t\t...(this.#state.itemSessions ?? {}),\n\t\t\t[itemIdentifier]: sessionState,\n\t\t};\n\t\tthis.#state.itemResponses[itemIdentifier] = asResponseValues(responses);\n\t\tthis.#state.timing.itemTimes[itemIdentifier] = duration;\n\t\tthis.markAnswered(itemIdentifier, responses);\n\t}\n\n\tsetItemSession(itemIdentifier: string, sessionState: SerializedItemSessionState): void {\n\t\tthis.#state.itemSessions = {\n\t\t\t...(this.#state.itemSessions ?? {}),\n\t\t\t[itemIdentifier]: sessionState,\n\t\t};\n\t}\n\n\tmergeItemSessions(itemSessions: AssessmentSessionState['itemSessions']): void {\n\t\tif (!itemSessions) return;\n\t\tthis.#state.itemSessions = {\n\t\t\t...(this.#state.itemSessions ?? {}),\n\t\t\t...itemSessions,\n\t\t};\n\t}\n\n\treplaceStatePreservingItemSessions(updatedState: AssessmentSessionState): void {\n\t\tconst localItemSessions = this.#state.itemSessions;\n\t\tthis.restoreState(updatedState);\n\t\tthis.mergeItemSessions(localItemSessions);\n\t}\n\n\treplaceStatePreservingResponsesAndSessions(\n\t\tupdatedState: AssessmentSessionState,\n\t\titemResponses: AssessmentSessionState['itemResponses'],\n\t\titemSessions: AssessmentSessionState['itemSessions']\n\t): void {\n\t\t// Where the candidate stands is the client's: delivery moves through navigation (a\n\t\t// branch decision is `nextItemIdentifier`), never through a backend state update,\n\t\t// whose position may be stale — or already overtaken by a scope expiry's move.\n\t\tconst currentItemIdentifier = this.#state.currentItemIdentifier;\n\t\t// The test outcomes the client already mirrored into its state survive a backend\n\t\t// snapshot that does not carry the field; a snapshot that does wins (its values are\n\t\t// the fresher outcome processing's).\n\t\tconst testOutcomes = updatedState.testOutcomes ?? this.#state.testOutcomes;\n\t\tthis.restoreState(updatedState);\n\t\tthis.#state.currentItemIdentifier = currentItemIdentifier;\n\t\t// Own the accepted snapshots rather than retaining the submit loop's mutable\n\t\t// working maps. Later provisional items must not appear committed until their\n\t\t// backend request succeeds.\n\t\tthis.#state.itemResponses = { ...itemResponses };\n\t\tthis.#state.itemSessions = itemSessions ? { ...itemSessions } : undefined;\n\t\tthis.#state.testOutcomes = testOutcomes ? { ...testOutcomes } : undefined;\n\t}\n\n\t// ---------------------------------------------------------------------------\n\t// Submission commits — the only writers of session state.\n\t//\n\t// One method per submit-path combination (individual / simultaneous × backend\n\t// returns / omits `updatedState`), reproducing exactly the state writes the\n\t// player's submit loops used to make inline.\n\t// ---------------------------------------------------------------------------\n\n\t/** Where delivery stands (navigation owns the pointer; the snapshot carries it). */\n\tsetCurrentItem(itemIdentifier: string): void {\n\t\tthis.#state.currentItemIdentifier = itemIdentifier;\n\t}\n\n\t/** The backend decision kept for the item (`state.branchDecisions`), if any. */\n\tgetBranchDecision(itemIdentifier: string): string | undefined {\n\t\treturn this.#state.branchDecisions?.[itemIdentifier];\n\t}\n\n\t/** Keep `target` as the one decision delivery may still follow — the item's freshest. */\n\tkeepBranchDecision(itemIdentifier: string, target: string): void {\n\t\tthis.#state.branchDecisions = { [itemIdentifier]: target };\n\t}\n\n\t/** Every kept decision is void: a counted submission moved the outcomes they decided on. */\n\tclearBranchDecisions(): void {\n\t\tdelete this.#state.branchDecisions;\n\t}\n\n\t/** The test-level outcomes the backend last returned (`state.testOutcomes`), if any. */\n\tgetTestOutcomes(): AssessmentSessionState['testOutcomes'] {\n\t\treturn this.#state.testOutcomes;\n\t}\n\n\t/** Store the test-level outcomes the backend returned for its last outcome processing. */\n\tsetTestOutcomes(outcomes: AssessmentSessionState['testOutcomes']): void {\n\t\tthis.#state.testOutcomes = outcomes ? { ...outcomes } : undefined;\n\t}\n\n\t/**\n\t * The live item session's responses mirrored into the persisted record: an\n\t * equality-checked write (identical responses are not re-written or re-notified)\n\t * plus the answered mark. Returns whether the record changed.\n\t */\n\tmirrorResponses(itemIdentifier: string, responses: Readonly<Record<string, unknown>>): boolean {\n\t\tconst current = this.getResponses(itemIdentifier);\n\t\tif (responseValuesEqual(current, responses)) return false;\n\n\t\tconst snapshot = cloneResponseRecord(responses);\n\t\tthis.#state.itemResponses[itemIdentifier] = asResponseValues(snapshot);\n\t\tthis.markAnswered(itemIdentifier, snapshot);\n\t\treturn true;\n\t}\n\n\t/**\n\t * A counted individual submission the backend accepted WITH its `updatedState`:\n\t * replace the session state with the backend's, keeping the client-owned position\n\t * and the client-collected responses and sessions (the snapshot may only include\n\t * the items submitted so far, which would otherwise wipe later answers).\n\t */\n\trecordSubmittedItemInUpdatedState(\n\t\titemIdentifier: string,\n\t\tresponses: Record<string, unknown>,\n\t\tupdatedState: AssessmentSessionState,\n\t): void {\n\t\tconst localResponses = cloneData(this.#state.itemResponses || {})!;\n\t\tlocalResponses[itemIdentifier] = asResponseValues(cloneResponseRecord(responses));\n\t\tthis.replaceStatePreservingResponsesAndSessions(\n\t\t\tupdatedState,\n\t\t\tlocalResponses,\n\t\t\tcloneData(this.#state.itemSessions || {})!,\n\t\t);\n\t}\n\n\t/**\n\t * A counted individual submission the backend accepted WITHOUT a state update:\n\t * the minimal local commit — score, visited mark, responses, session snapshot.\n\t */\n\trecordIndividualSubmission(\n\t\titemIdentifier: string,\n\t\tresponses: Record<string, unknown>,\n\t\titemSession: SerializedItemSessionState | undefined,\n\t\tscoring: AssessmentScoringResult,\n\t): void {\n\t\tthis.#state.itemScores = this.#state.itemScores || {};\n\t\tthis.#state.itemScores[itemIdentifier] = scoring;\n\t\tthis.markVisited(itemIdentifier);\n\t\tthis.#state.itemResponses[itemIdentifier] = asResponseValues(responses);\n\t\tif (itemSession) {\n\t\t\tthis.setItemSession(itemIdentifier, itemSession);\n\t\t}\n\t}\n\n\t/**\n\t * A counted simultaneous-flush submission the backend accepted WITHOUT a state\n\t * update: the minimal local commit plus the attempt record and the accepted\n\t * result (its responses read back from the persisted record, as the flush loop did).\n\t */\n\trecordSimultaneousSubmission(\n\t\titemIdentifier: string,\n\t\tresponses: Record<string, unknown>,\n\t\titemSession: SerializedItemSessionState,\n\t\tscoring: AssessmentScoringResult,\n\t): void {\n\t\tthis.#state.itemScores = this.#state.itemScores || {};\n\t\tthis.#state.itemScores[itemIdentifier] = scoring;\n\t\tthis.markVisited(itemIdentifier);\n\t\tthis.#state.itemResponses[itemIdentifier] = asResponseValues(responses);\n\t\tthis.setItemSession(itemIdentifier, itemSession);\n\t\tthis.recordAttempt(itemIdentifier);\n\t\tthis.setItemResult({\n\t\t\titemIdentifier,\n\t\t\tscore: scoring.score,\n\t\t\tmaxScore: scoring.maxScore,\n\t\t\tresponses: this.#state.itemResponses[itemIdentifier] || {},\n\t\t});\n\t}\n\n\t/**\n\t * Record an attempt locally only when the backend has not counted it already: a\n\t * backend `updatedState` carries its own authoritative count (`itemSessionStates`),\n\t * which must not be counted twice.\n\t */\n\trecordAttemptIfUncounted(itemIdentifier: string, attemptsBefore: number): void {\n\t\ttry {\n\t\t\tif (this.getItemSessionInfo(itemIdentifier).attemptCount <= attemptsBefore) {\n\t\t\t\tthis.recordAttempt(itemIdentifier);\n\t\t\t}\n\t\t} catch {\n\t\t\t// ignore\n\t\t}\n\t}\n\n\t/** The test ended: every delivered item session in the persisted record is closed. */\n\tcloseAllItemSessions(): void {\n\t\tconst sessions = this.#state.itemSessions;\n\t\tif (sessions) {\n\t\t\tthis.#state.itemSessions = Object.fromEntries(\n\t\t\t\tObject.entries(sessions).map(([identifier, session]) => [identifier, closedItemSession(session)]),\n\t\t\t);\n\t\t}\n\t}\n\n\t/** Whether the candidate hid the countdown (a persisted shell preference). */\n\tsetTimerHidden(hidden: boolean): void {\n\t\tthis.#state.timerHidden = hidden;\n\t}\n\n\tmarkVisited(itemIdentifier: string): void {\n\t\tif (!this.#state.visitedItems.includes(itemIdentifier)) {\n\t\t\tthis.#state.visitedItems.push(itemIdentifier);\n\t\t}\n\t}\n\n\tmarkAnswered(itemIdentifier: string, responses: Record<string, unknown>): void {\n\t\tthis.#sessionController.markAnswered(itemIdentifier, hasAnyResponse(responses));\n\t}\n\n\t/**\n\t * Whether the candidate may return to the item: always before its first submission, and\n\t * while attempts remain (an adaptive item: until it `completed`); after that QTI\n\t * `allowReview` decides.\n\t */\n\tcanReview(itemIdentifier: string, options: { completed?: boolean } = {}): boolean {\n\t\treturn this.#sessionController.canReview(itemIdentifier, options);\n\t}\n\n\tupdateItemSessionControl(settings: ItemSessionControlSettings): void {\n\t\tthis.#sessionController.updateSettings(settings);\n\t}\n\n\tmustValidateResponses(itemIdentifier?: string): boolean {\n\t\treturn this.#sessionController.mustValidateResponses(itemIdentifier);\n\t}\n\n\tcanSubmit(itemIdentifier: string): boolean {\n\t\treturn this.#sessionController.canSubmit(itemIdentifier);\n\t}\n\n\tgetItemSettings(itemIdentifier: string): ItemSessionControlSettings {\n\t\treturn this.#sessionController.getItemSettings(itemIdentifier);\n\t}\n\n\t/** Records the candidate's comment on an item; throws a coded error unless its allowComment is on. */\n\tsetItemComment(itemIdentifier: string, comment: string): void {\n\t\tif (!this.#sessionController.canComment(itemIdentifier)) {\n\t\t\tthrow new AssessmentPlayerError(\n\t\t\t\t'commentsNotAllowed',\n\t\t\t\t`Comments are not allowed for item \"${itemIdentifier}\".`,\n\t\t\t);\n\t\t}\n\t\tthis.#state.itemComments = { ...(this.#state.itemComments ?? {}), [itemIdentifier]: comment };\n\t}\n\n\tgetItemComment(itemIdentifier: string): string | undefined {\n\t\treturn this.#state.itemComments?.[itemIdentifier];\n\t}\n\n\t/** Sets (or clears) the candidate's flag-for-review on an item. */\n\tsetItemFlag(itemIdentifier: string, flagged: boolean): void {\n\t\tconst flags = { ...(this.#state.itemFlags ?? {}) };\n\t\tif (flagged) flags[itemIdentifier] = true;\n\t\telse delete flags[itemIdentifier];\n\t\tthis.#state.itemFlags = flags;\n\t}\n\n\tisItemFlagged(itemIdentifier: string): boolean {\n\t\treturn this.#state.itemFlags?.[itemIdentifier] === true;\n\t}\n\n\tgetFlaggedItemIdentifiers(): string[] {\n\t\treturn Object.keys(this.#state.itemFlags ?? {}).filter((id) => this.#state.itemFlags?.[id] === true);\n\t}\n\n\trecordAttempt(itemIdentifier: string): void {\n\t\tthis.#sessionController.recordAttempt(itemIdentifier);\n\t}\n\n\tsetItemResult(itemResult: ItemResult): void {\n\t\tthis.#itemResults.set(itemResult.itemIdentifier, itemResult);\n\t}\n\n\thasItemResult(itemIdentifier: string): boolean {\n\t\treturn this.#itemResults.has(itemIdentifier);\n\t}\n\n\tgetItemSessionInfo(itemIdentifier: string): ItemSessionInfo {\n\t\tif (!this.#sessionController.getItemState(itemIdentifier)) {\n\t\t\tthis.#sessionController.initializeItem(itemIdentifier);\n\t\t}\n\t\tconst state = this.#sessionController.getItemState(itemIdentifier);\n\t\treturn {\n\t\t\tcanSubmit: this.#sessionController.canSubmit(itemIdentifier),\n\t\t\tremainingAttempts: this.#sessionController.getRemainingAttempts(itemIdentifier),\n\t\t\tattemptCount: state?.attemptCount ?? 0,\n\t\t\tshowFeedback: this.#sessionController.shouldShowFeedback(itemIdentifier),\n\t\t\tshowSolution: this.#sessionController.shouldShowSolution(itemIdentifier),\n\t\t\tcanReview: this.#sessionController.canReview(itemIdentifier),\n\t\t\tcanSkip: this.#sessionController.canSkip(itemIdentifier),\n\t\t\tcanComment: this.#sessionController.canComment(itemIdentifier),\n\t\t};\n\t}\n\n\t#initializeItemSessions(): void {\n\t\tfor (const itemIdentifier of this.#itemIdentifiers) {\n\t\t\tthis.#sessionController.initializeItem(itemIdentifier);\n\t\t}\n\t}\n\n\t#restoreItemSessionsFromState(state: AssessmentSessionState): void {\n\t\tconst restoredStates = new Map<string, ItemSessionState>();\n\t\tfor (const itemIdentifier of this.#itemIdentifiers) {\n\t\t\tconst persisted = state.itemSessionStates?.[itemIdentifier];\n\t\t\tif (persisted) {\n\t\t\t\trestoredStates.set(itemIdentifier, {\n\t\t\t\t\titemIdentifier,\n\t\t\t\t\tattemptCount: Math.max(0, persisted.attemptCount),\n\t\t\t\t\tisAnswered: persisted.isAnswered,\n\t\t\t\t\tisSubmitted: persisted.isSubmitted,\n\t\t\t\t\tlastSubmissionTime: persisted.lastSubmissionTime,\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst responses = state.itemResponses?.[itemIdentifier] ?? {};\n\t\t\tconst isSubmitted = Boolean(state.itemScores?.[itemIdentifier]);\n\t\t\trestoredStates.set(itemIdentifier, {\n\t\t\t\titemIdentifier,\n\t\t\t\tattemptCount: isSubmitted ? 1 : 0,\n\t\t\t\tisAnswered: hasAnyResponse(responses),\n\t\t\t\tisSubmitted,\n\t\t\t});\n\t\t}\n\t\tthis.#sessionController.restoreStates(restoredStates);\n\t}\n\n\t#restoreItemResultsFromScores(state: AssessmentSessionState): void {\n\t\tthis.#itemResults.clear();\n\t\tif (!state.itemScores) return;\n\t\tfor (const [itemIdentifier, scoring] of Object.entries(state.itemScores)) {\n\t\t\tthis.#itemResults.set(itemIdentifier, {\n\t\t\t\titemIdentifier,\n\t\t\t\tscore: scoring.score,\n\t\t\t\tmaxScore: scoring.maxScore,\n\t\t\t\tresponses: state.itemResponses?.[itemIdentifier] || {},\n\t\t\t});\n\t\t}\n\t}\n\n\t#itemSessionStateSnapshot(): Record<string, ItemSessionState> {\n\t\treturn Object.fromEntries(\n\t\t\t[...this.#sessionController.getAllStates().entries()].map(([itemIdentifier, state]) => [\n\t\t\t\titemIdentifier,\n\t\t\t\t{ ...state },\n\t\t\t])\n\t\t);\n\t}\n}\n\n/**\n * True when any response value in the record carries learner input. Shared with the\n * reference backend adapter so \"answered\" is decided identically on both sides.\n */\nexport function hasAnyResponse(responses: Record<string, unknown>): boolean {\n\tfor (const value of Object.values(responses)) {\n\t\tif (value == null) continue;\n\t\tif (Array.isArray(value)) {\n\t\t\tif (value.length > 0) return true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof value === 'string') {\n\t\t\tif (value.trim().length > 0) return true;\n\t\t\tcontinue;\n\t\t}\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n/** A response variable's declared default, with the cardinality that decides how it compares. */\nexport interface ResponseDefault {\n\tvalue: unknown;\n\tcardinality?: string;\n}\n\n/**\n * QTI's skipped item (itemSessionControl `allowSkipping`): every response is NULL, empty, or\n * still equal to its declared default — the same test `numberResponded` applies (a response\n * that differs from its default). A `multiple` response compares as an unordered container.\n */\nexport function isSkippedResponseSet(\n\tresponses: Record<string, unknown>,\n\tdefaults: Readonly<Record<string, ResponseDefault>> = {},\n): boolean {\n\tfor (const [identifier, value] of Object.entries(responses)) {\n\t\tif (!hasAnyResponse({ [identifier]: value })) continue;\n\t\tconst declared = defaults[identifier];\n\t\tif (declared && declared.value != null && responseEqualsDefault(value, declared)) continue;\n\t\treturn false;\n\t}\n\treturn true;\n}\n\nfunction responseEqualsDefault(value: unknown, declared: ResponseDefault): boolean {\n\tif (declared.cardinality === 'multiple' && Array.isArray(value) && Array.isArray(declared.value)) {\n\t\tconst canonical = (entries: unknown[]) => entries.map((entry) => JSON.stringify(entry)).sort();\n\t\tconst left = canonical(value);\n\t\tconst right = canonical(declared.value);\n\t\treturn left.length === right.length && left.every((entry, index) => entry === right[index]);\n\t}\n\treturn JSON.stringify(value) === JSON.stringify(declared.value);\n}\n"]}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Debounced autosave for the assessment core.
3
+ *
4
+ * Collects a session snapshot after candidate activity settles (response edits,
5
+ * navigation, flags, timer visibility, pause) and persists it through the backend's
6
+ * `saveState`. The backend is the store: no offline queue, no client-side storage.
7
+ *
8
+ * Guarantees:
9
+ * - **Non-fatal, with bounded backoff.** A failed save logs to the console, reports
10
+ * `failed` through `onStateChange` (plus `onError` for the raw detail) and retries
11
+ * with a bounded backoff (2s, 8s, 30s — then it waits for the next change or
12
+ * flush); delivery is never interrupted. A success or `stop()` resets the backoff.
13
+ * - **Busy-aware.** While a navigation or submission transition is in flight a
14
+ * due save is deferred and retried once the transition settles, so the snapshot
15
+ * is not taken mid-transition.
16
+ * - **Terminal-safe.** Once `stop()` runs (finalization, destroy) nothing is saved.
17
+ */
18
+ export type AutosaveStatus = 'idle' | 'pending' | 'saving' | 'saved' | 'failed';
19
+ /** What the save indicator (and host callbacks) see. */
20
+ export interface AutosaveState {
21
+ status: AutosaveStatus;
22
+ /** Client clock (ms) of the last successful save; undefined until one lands. */
23
+ lastSavedAt?: number;
24
+ }
25
+ export interface AutosaveManagerOptions {
26
+ /** Whether the backend accepts saves at all (capability + config). */
27
+ enabled: boolean;
28
+ /** Debounce window in ms after the last activity. Default 1500. */
29
+ intervalMs: number;
30
+ /** Build the snapshot to persist. */
31
+ collect: () => {
32
+ sessionId: string;
33
+ state: unknown;
34
+ };
35
+ /** Persist one snapshot. */
36
+ save: (request: {
37
+ sessionId: string;
38
+ state: unknown;
39
+ }) => Promise<{
40
+ success: boolean;
41
+ }>;
42
+ /** True while a navigation or submission transition is in flight. */
43
+ isBlocked: () => boolean;
44
+ /** Whether delivery has ended (finalized, destroyed, stopped). */
45
+ isStopped: () => boolean;
46
+ /** Indicator/host state changes. */
47
+ onStateChange: (state: AutosaveState) => void;
48
+ /** Raw failure detail for logs and host callbacks. */
49
+ onError: (error: Error) => void;
50
+ /**
51
+ * Backoff delays (ms) for the automatic retries of a failed save. Default
52
+ * 2s → 8s → 30s; after the last attempt the manager waits for the next candidate
53
+ * change or flush. Tests pass shorter delays.
54
+ */
55
+ retryDelaysMs?: number[];
56
+ }
57
+ export declare class AutosaveManager {
58
+ private readonly options;
59
+ private state;
60
+ private timer;
61
+ private flushing;
62
+ private stopped;
63
+ private readonly intervalMs;
64
+ private readonly retryDelays;
65
+ /** How many of the bounded backoff retries the current failure has spent. */
66
+ private retryAttempt;
67
+ constructor(options: AutosaveManagerOptions);
68
+ /** The current indicator state. */
69
+ getState(): AutosaveState;
70
+ /**
71
+ * Candidate activity happened (response edit, navigation, flag, timer visibility,
72
+ * pause). Restarts the debounce window; a due-but-blocked save is re-queued until
73
+ * the transition settles.
74
+ */
75
+ notify(): void;
76
+ /**
77
+ * Save immediately (best-effort): `visibilitychange`/`pagehide`, or any host that
78
+ * wants a durable draft now. While a transition is in flight the save is re-queued
79
+ * on the debounce window instead of racing it. Safe to call concurrently; the
80
+ * in-flight save is shared.
81
+ */
82
+ flush(): Promise<void>;
83
+ /**
84
+ * Save the current snapshot immediately even while a transition is in flight: the
85
+ * terminal transition (finalization) itself calls this so the backend finalizes
86
+ * against the final clocks and responses, not the last debounced draft. A save
87
+ * already in flight captured an older snapshot, so it is awaited first and the
88
+ * current one is saved after it — the end-of-test snapshot always lands. Must run
89
+ * inside that transition's exclusive lock; failures stay non-fatal.
90
+ */
91
+ flushImmediate(): Promise<void>;
92
+ /** Stop autosaving for good: nothing runs afterwards, pending timers cleared. */
93
+ stop(): void;
94
+ private scheduleRetry;
95
+ /**
96
+ * A failed save retries with bounded backoff (2s, 8s, 30s): a transient outage
97
+ * recovers without waiting for the candidate's next keystroke. After the last
98
+ * attempt the state stays `failed` until the next change or flush.
99
+ */
100
+ private scheduleBackoffRetry;
101
+ private saveNow;
102
+ private persist;
103
+ private setState;
104
+ }