@vue-skuilder/db 0.2.21 → 0.2.23
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/{contentSource-BMxsujRu.d.cts → contentSource-BvOpKUeU.d.ts} +442 -79
- package/dist/{contentSource-Bazgkf4C.d.ts → contentSource-DT9NaX69.d.cts} +442 -79
- package/dist/core/index.d.cts +84 -342
- package/dist/core/index.d.ts +84 -342
- package/dist/core/index.js +79 -4
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +74 -4
- package/dist/core/index.mjs.map +1 -1
- package/dist/{dataLayerProvider-Bt-D6xas.d.ts → dataLayerProvider-CY2B2lyW.d.ts} +1 -1
- package/dist/{dataLayerProvider-DifVCcIS.d.cts → dataLayerProvider-wY6s_4x9.d.cts} +1 -1
- package/dist/impl/couch/index.d.cts +3 -3
- package/dist/impl/couch/index.d.ts +3 -3
- package/dist/impl/couch/index.js +63 -4
- package/dist/impl/couch/index.js.map +1 -1
- package/dist/impl/couch/index.mjs +63 -4
- package/dist/impl/couch/index.mjs.map +1 -1
- package/dist/impl/static/index.d.cts +4 -4
- package/dist/impl/static/index.d.ts +4 -4
- package/dist/impl/static/index.js +63 -4
- package/dist/impl/static/index.js.map +1 -1
- package/dist/impl/static/index.mjs +63 -4
- package/dist/impl/static/index.mjs.map +1 -1
- package/dist/{index-BLLT5BYE.d.ts → index-BkBJlGDX.d.ts} +1 -1
- package/dist/{index-k9NFHpS1.d.cts → index-D7WdMDAs.d.cts} +1 -1
- package/dist/index.d.cts +51 -14
- package/dist/index.d.ts +51 -14
- package/dist/index.js +240 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +235 -12
- package/dist/index.mjs.map +1 -1
- package/dist/{types-BFUa1pa3.d.cts → types-DjiFOZxJ.d.cts} +1 -1
- package/dist/{types-legacy-4tlwHnXo.d.cts → types-legacy-CrwyZIvI.d.cts} +10 -2
- package/dist/{types-legacy-4tlwHnXo.d.ts → types-legacy-CrwyZIvI.d.ts} +10 -2
- package/dist/{types-CHgpWQAY.d.ts → types-uJ2Xn3_X.d.ts} +1 -1
- package/dist/util/packer/index.d.cts +3 -3
- package/dist/util/packer/index.d.ts +3 -3
- package/package.json +3 -3
- package/src/core/index.ts +1 -0
- package/src/core/interfaces/userDB.ts +7 -0
- package/src/core/navigators/PipelineDebugger.ts +41 -1
- package/src/core/navigators/index.ts +3 -0
- package/src/core/types/studySession.ts +125 -0
- package/src/core/types/types-legacy.ts +8 -0
- package/src/impl/common/BaseUserDB.ts +36 -0
- package/src/study/SessionController.ts +188 -2
- package/src/study/SessionDebugger.ts +4 -3
- package/src/study/SessionOverlay.ts +1 -0
- package/src/study/services/ResponseProcessor.ts +32 -4
package/dist/index.mjs
CHANGED
|
@@ -103,6 +103,7 @@ var init_types_legacy = __esm({
|
|
|
103
103
|
DocType3["STRATEGY_STATE"] = "STRATEGY_STATE";
|
|
104
104
|
DocType3["USER_OUTCOME"] = "USER_OUTCOME";
|
|
105
105
|
DocType3["STRATEGY_LEARNING_STATE"] = "STRATEGY_LEARNING_STATE";
|
|
106
|
+
DocType3["STUDY_SESSION"] = "STUDY_SESSION";
|
|
106
107
|
return DocType3;
|
|
107
108
|
})(DocType || {});
|
|
108
109
|
DocTypePrefixes = {
|
|
@@ -119,7 +120,8 @@ var init_types_legacy = __esm({
|
|
|
119
120
|
["NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */]: "NAVIGATION_STRATEGY",
|
|
120
121
|
["STRATEGY_STATE" /* STRATEGY_STATE */]: "STRATEGY_STATE",
|
|
121
122
|
["USER_OUTCOME" /* USER_OUTCOME */]: "USER_OUTCOME",
|
|
122
|
-
["STRATEGY_LEARNING_STATE" /* STRATEGY_LEARNING_STATE */]: "STRATEGY_LEARNING_STATE"
|
|
123
|
+
["STRATEGY_LEARNING_STATE" /* STRATEGY_LEARNING_STATE */]: "STRATEGY_LEARNING_STATE",
|
|
124
|
+
["STUDY_SESSION" /* STUDY_SESSION */]: "SESSION"
|
|
123
125
|
};
|
|
124
126
|
}
|
|
125
127
|
});
|
|
@@ -947,10 +949,13 @@ __export(PipelineDebugger_exports, {
|
|
|
947
949
|
buildRunReport: () => buildRunReport,
|
|
948
950
|
captureRun: () => captureRun,
|
|
949
951
|
clearRunHistory: () => clearRunHistory,
|
|
952
|
+
drainCapturedRuns: () => drainCapturedRuns,
|
|
950
953
|
getActivePipeline: () => getActivePipeline,
|
|
954
|
+
getRunsForSession: () => getRunsForSession,
|
|
951
955
|
mountPipelineDebugger: () => mountPipelineDebugger,
|
|
952
956
|
pipelineDebugAPI: () => pipelineDebugAPI,
|
|
953
|
-
registerPipelineForDebug: () => registerPipelineForDebug
|
|
957
|
+
registerPipelineForDebug: () => registerPipelineForDebug,
|
|
958
|
+
setDebugSessionId: () => setDebugSessionId
|
|
954
959
|
});
|
|
955
960
|
function registerPipelineForDebug(pipeline) {
|
|
956
961
|
_activePipeline = pipeline;
|
|
@@ -958,8 +963,20 @@ function registerPipelineForDebug(pipeline) {
|
|
|
958
963
|
function getActivePipeline() {
|
|
959
964
|
return _activePipeline;
|
|
960
965
|
}
|
|
966
|
+
function setDebugSessionId(sessionId) {
|
|
967
|
+
_currentSessionId = sessionId;
|
|
968
|
+
}
|
|
969
|
+
function drainCapturedRuns() {
|
|
970
|
+
const drained = _pendingRuns;
|
|
971
|
+
_pendingRuns = [];
|
|
972
|
+
return drained;
|
|
973
|
+
}
|
|
974
|
+
function getRunsForSession(sessionId) {
|
|
975
|
+
return runHistory.filter((r) => r.sessionId === sessionId).reverse();
|
|
976
|
+
}
|
|
961
977
|
function clearRunHistory() {
|
|
962
978
|
runHistory.length = 0;
|
|
979
|
+
_pendingRuns = [];
|
|
963
980
|
}
|
|
964
981
|
function getOrigin(card) {
|
|
965
982
|
const firstEntry = card.provenance[0];
|
|
@@ -974,12 +991,15 @@ function captureRun(report) {
|
|
|
974
991
|
const fullReport = {
|
|
975
992
|
...report,
|
|
976
993
|
runId: `run-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
994
|
+
sessionId: _currentSessionId,
|
|
977
995
|
timestamp: /* @__PURE__ */ new Date()
|
|
978
996
|
};
|
|
979
997
|
runHistory.unshift(fullReport);
|
|
980
998
|
if (runHistory.length > MAX_RUNS) {
|
|
981
999
|
runHistory.pop();
|
|
982
1000
|
}
|
|
1001
|
+
_pendingRuns.push(fullReport);
|
|
1002
|
+
return fullReport;
|
|
983
1003
|
}
|
|
984
1004
|
function parseCardElo(provenance) {
|
|
985
1005
|
const eloEntry = provenance.find((p) => p.strategy === "elo");
|
|
@@ -1307,7 +1327,7 @@ function mountPipelineDebugger() {
|
|
|
1307
1327
|
win.skuilder = win.skuilder || {};
|
|
1308
1328
|
win.skuilder.pipeline = pipelineDebugAPI;
|
|
1309
1329
|
}
|
|
1310
|
-
var _activePipeline, MAX_RUNS, runHistory, DISCARDED_KEEP_TOP, _uiContainer, _selectedRunIndex, _cardSearchQuery, pipelineDebugAPI;
|
|
1330
|
+
var _activePipeline, MAX_RUNS, runHistory, _currentSessionId, _pendingRuns, DISCARDED_KEEP_TOP, _uiContainer, _selectedRunIndex, _cardSearchQuery, pipelineDebugAPI;
|
|
1311
1331
|
var init_PipelineDebugger = __esm({
|
|
1312
1332
|
"src/core/navigators/PipelineDebugger.ts"() {
|
|
1313
1333
|
"use strict";
|
|
@@ -1316,6 +1336,7 @@ var init_PipelineDebugger = __esm({
|
|
|
1316
1336
|
_activePipeline = null;
|
|
1317
1337
|
MAX_RUNS = 10;
|
|
1318
1338
|
runHistory = [];
|
|
1339
|
+
_pendingRuns = [];
|
|
1319
1340
|
DISCARDED_KEEP_TOP = 25;
|
|
1320
1341
|
_uiContainer = null;
|
|
1321
1342
|
_selectedRunIndex = null;
|
|
@@ -5539,11 +5560,13 @@ __export(navigators_exports, {
|
|
|
5539
5560
|
clearSrsBacklogDebug: () => clearSrsBacklogDebug,
|
|
5540
5561
|
clearStrategyPressureDebug: () => clearStrategyPressureDebug,
|
|
5541
5562
|
diversityRerank: () => diversityRerank,
|
|
5563
|
+
drainCapturedRuns: () => drainCapturedRuns,
|
|
5542
5564
|
getActivePipeline: () => getActivePipeline,
|
|
5543
5565
|
getCardOrigin: () => getCardOrigin,
|
|
5544
5566
|
getRegisteredNavigator: () => getRegisteredNavigator,
|
|
5545
5567
|
getRegisteredNavigatorNames: () => getRegisteredNavigatorNames,
|
|
5546
5568
|
getRegisteredNavigatorRole: () => getRegisteredNavigatorRole,
|
|
5569
|
+
getRunsForSession: () => getRunsForSession,
|
|
5547
5570
|
getSrsBacklogDebug: () => getSrsBacklogDebug,
|
|
5548
5571
|
getStrategyPressureDebug: () => getStrategyPressureDebug,
|
|
5549
5572
|
hasRegisteredNavigator: () => hasRegisteredNavigator,
|
|
@@ -5552,7 +5575,8 @@ __export(navigators_exports, {
|
|
|
5552
5575
|
isGenerator: () => isGenerator,
|
|
5553
5576
|
mountPipelineDebugger: () => mountPipelineDebugger,
|
|
5554
5577
|
pipelineDebugAPI: () => pipelineDebugAPI,
|
|
5555
|
-
registerNavigator: () => registerNavigator
|
|
5578
|
+
registerNavigator: () => registerNavigator,
|
|
5579
|
+
setDebugSessionId: () => setDebugSessionId
|
|
5556
5580
|
});
|
|
5557
5581
|
function registerNavigator(implementingClass, constructor, role) {
|
|
5558
5582
|
navigatorRegistry.set(implementingClass, { constructor, role });
|
|
@@ -8895,6 +8919,32 @@ Currently logged-in as ${this._username}.`
|
|
|
8895
8919
|
};
|
|
8896
8920
|
await this.localDB.put(doc);
|
|
8897
8921
|
}
|
|
8922
|
+
/**
|
|
8923
|
+
* Open and close write the same `_id`, so the 409 path is the expected
|
|
8924
|
+
* route for the second write, not an error case.
|
|
8925
|
+
*/
|
|
8926
|
+
async putStudySession(doc) {
|
|
8927
|
+
try {
|
|
8928
|
+
await this.localDB.put(doc);
|
|
8929
|
+
} catch (err) {
|
|
8930
|
+
if (err.status === 409) {
|
|
8931
|
+
const existing = await this.localDB.get(doc._id);
|
|
8932
|
+
await this.localDB.put({ ...doc, _rev: existing._rev });
|
|
8933
|
+
} else {
|
|
8934
|
+
throw err;
|
|
8935
|
+
}
|
|
8936
|
+
}
|
|
8937
|
+
}
|
|
8938
|
+
async getStudySessions(courseId) {
|
|
8939
|
+
const prefix = courseId ? `${DocTypePrefixes["STUDY_SESSION" /* STUDY_SESSION */]}::${courseId}::` : `${DocTypePrefixes["STUDY_SESSION" /* STUDY_SESSION */]}::`;
|
|
8940
|
+
const keys = getStartAndEndKeys(prefix);
|
|
8941
|
+
const res = await this.localDB.allDocs({
|
|
8942
|
+
startkey: keys.startkey,
|
|
8943
|
+
endkey: keys.endkey,
|
|
8944
|
+
include_docs: true
|
|
8945
|
+
});
|
|
8946
|
+
return res.rows.map((r) => r.doc).filter((d) => !!d).sort((a, b) => b.startTime.localeCompare(a.startTime));
|
|
8947
|
+
}
|
|
8898
8948
|
async putUserOutcome(record) {
|
|
8899
8949
|
try {
|
|
8900
8950
|
await this.localDB.put(record);
|
|
@@ -10386,6 +10436,20 @@ var init_userOutcome = __esm({
|
|
|
10386
10436
|
}
|
|
10387
10437
|
});
|
|
10388
10438
|
|
|
10439
|
+
// src/core/types/studySession.ts
|
|
10440
|
+
function makeStudySessionId(courseId, userId, sessionId) {
|
|
10441
|
+
return `${DocTypePrefixes["STUDY_SESSION" /* STUDY_SESSION */]}::${courseId}::${userId}::${sessionId}`;
|
|
10442
|
+
}
|
|
10443
|
+
function newSessionId() {
|
|
10444
|
+
return `session-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
10445
|
+
}
|
|
10446
|
+
var init_studySession = __esm({
|
|
10447
|
+
"src/core/types/studySession.ts"() {
|
|
10448
|
+
"use strict";
|
|
10449
|
+
init_types_legacy();
|
|
10450
|
+
}
|
|
10451
|
+
});
|
|
10452
|
+
|
|
10389
10453
|
// src/core/types/hydration.ts
|
|
10390
10454
|
var HYDRATION_MARKER_ID;
|
|
10391
10455
|
var init_hydration = __esm({
|
|
@@ -10874,6 +10938,7 @@ var init_core = __esm({
|
|
|
10874
10938
|
init_user();
|
|
10875
10939
|
init_strategyState();
|
|
10876
10940
|
init_userOutcome();
|
|
10941
|
+
init_studySession();
|
|
10877
10942
|
init_hydration();
|
|
10878
10943
|
init_Loggable();
|
|
10879
10944
|
init_util();
|
|
@@ -11539,7 +11604,9 @@ var ResponseProcessor = class {
|
|
|
11539
11604
|
courseRegistrationDoc,
|
|
11540
11605
|
currentCard,
|
|
11541
11606
|
courseId,
|
|
11542
|
-
cardId
|
|
11607
|
+
cardId,
|
|
11608
|
+
maxSessionViews,
|
|
11609
|
+
sessionViews
|
|
11543
11610
|
);
|
|
11544
11611
|
} else {
|
|
11545
11612
|
result = this.processIncorrectResponse(
|
|
@@ -11574,7 +11641,7 @@ var ResponseProcessor = class {
|
|
|
11574
11641
|
/**
|
|
11575
11642
|
* Handles processing for correct responses: SRS scheduling and ELO updates.
|
|
11576
11643
|
*/
|
|
11577
|
-
processCorrectResponse(cardRecord, history, studySessionItem, courseRegistrationDoc, currentCard, courseId, cardId) {
|
|
11644
|
+
processCorrectResponse(cardRecord, history, studySessionItem, courseRegistrationDoc, currentCard, courseId, cardId, maxSessionViews, sessionViews) {
|
|
11578
11645
|
if (cardRecord.priorAttemps === 0) {
|
|
11579
11646
|
const skipSrs = currentCard.card.tags.includes("srs:skip");
|
|
11580
11647
|
if (!skipSrs) {
|
|
@@ -11622,12 +11689,16 @@ var ResponseProcessor = class {
|
|
|
11622
11689
|
shouldClearFeedbackShadow: true
|
|
11623
11690
|
};
|
|
11624
11691
|
} else {
|
|
11692
|
+
const budgetSpent = sessionViews >= maxSessionViews;
|
|
11625
11693
|
logger.info(
|
|
11626
|
-
|
|
11694
|
+
`[ResponseProcessor] Processed correct response (retry attempt - no scheduling/ELO); sessionViews=${sessionViews}/${maxSessionViews} -> ${budgetSpent ? "dismiss-success" : "marked-failed"}`
|
|
11627
11695
|
);
|
|
11628
11696
|
const { globalScore } = this.parsePerformance(cardRecord.performance);
|
|
11629
11697
|
return {
|
|
11630
|
-
|
|
11698
|
+
// Budget spent: the learner did get it right, so retire the card as a
|
|
11699
|
+
// success rather than penalising it ('dismiss-failed' would apply an
|
|
11700
|
+
// ELO penalty for an answer that was correct).
|
|
11701
|
+
nextCardAction: budgetSpent ? "dismiss-success" : "marked-failed",
|
|
11631
11702
|
shouldLoadNextCard: true,
|
|
11632
11703
|
isCorrect: true,
|
|
11633
11704
|
performanceScore: globalScore,
|
|
@@ -12004,6 +12075,8 @@ var ItemQueue = class {
|
|
|
12004
12075
|
// src/study/SessionController.ts
|
|
12005
12076
|
init_couch();
|
|
12006
12077
|
init_core();
|
|
12078
|
+
init_types_legacy();
|
|
12079
|
+
init_studySession();
|
|
12007
12080
|
init_recording();
|
|
12008
12081
|
|
|
12009
12082
|
// src/util/index.ts
|
|
@@ -14207,8 +14280,7 @@ function clearStaleSessionDebugState() {
|
|
|
14207
14280
|
clearSrsBacklogDebug();
|
|
14208
14281
|
clearStrategyPressureDebug();
|
|
14209
14282
|
}
|
|
14210
|
-
function startSessionTracking(supplyQLength, failedQLength) {
|
|
14211
|
-
const sessionId = `session-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
14283
|
+
function startSessionTracking(sessionId, supplyQLength, failedQLength) {
|
|
14212
14284
|
activeSession = {
|
|
14213
14285
|
sessionId,
|
|
14214
14286
|
startTime: /* @__PURE__ */ new Date(),
|
|
@@ -14591,6 +14663,24 @@ var SessionController = class _SessionController extends Loggable {
|
|
|
14591
14663
|
* `this`; constructed once so observers can rely on referential identity.
|
|
14592
14664
|
*/
|
|
14593
14665
|
_sessionControls = null;
|
|
14666
|
+
/**
|
|
14667
|
+
* Minted at construction so the bootstrap pipeline run in `prepareSession()`
|
|
14668
|
+
* can carry it. Stamped onto every CardRecord and pipeline run this session.
|
|
14669
|
+
*/
|
|
14670
|
+
sessionId;
|
|
14671
|
+
/** Host-supplied. Without it, no durable session doc is written. */
|
|
14672
|
+
_courseId;
|
|
14673
|
+
_stateSnapshotProvider;
|
|
14674
|
+
_sessionDoc = null;
|
|
14675
|
+
/**
|
|
14676
|
+
* Awaited by the close path — the open write is slow (time-boxed snapshot)
|
|
14677
|
+
* and would otherwise land last, leaving a finished session marked `open`.
|
|
14678
|
+
*/
|
|
14679
|
+
_openDocPromise = null;
|
|
14680
|
+
_runLog = [];
|
|
14681
|
+
static MAX_LOGGED_RUNS = 100;
|
|
14682
|
+
/** Guards `endSession()` against the several termination paths racing it. */
|
|
14683
|
+
_sessionClosed = false;
|
|
14594
14684
|
startTime;
|
|
14595
14685
|
endTime;
|
|
14596
14686
|
_secondsRemaining;
|
|
@@ -14624,6 +14714,8 @@ var SessionController = class _SessionController extends Loggable {
|
|
|
14624
14714
|
*/
|
|
14625
14715
|
constructor(sources, time, dataLayer, getViewComponent, mixer, options) {
|
|
14626
14716
|
super();
|
|
14717
|
+
this.sessionId = newSessionId();
|
|
14718
|
+
setDebugSessionId(this.sessionId);
|
|
14627
14719
|
this.dataLayer = dataLayer;
|
|
14628
14720
|
this.mixer = mixer || new QuotaRoundRobinMixer();
|
|
14629
14721
|
this.srsService = new SrsService(dataLayer.getUserDB());
|
|
@@ -14646,7 +14738,10 @@ var SessionController = class _SessionController extends Loggable {
|
|
|
14646
14738
|
if (options?.outcomeObservers?.length) {
|
|
14647
14739
|
this._outcomeObservers = [...options.outcomeObservers];
|
|
14648
14740
|
}
|
|
14741
|
+
this._courseId = options?.courseId;
|
|
14742
|
+
this._stateSnapshotProvider = options?.stateSnapshotProvider;
|
|
14649
14743
|
this.log(`Session constructed:
|
|
14744
|
+
sessionId: ${this.sessionId}
|
|
14650
14745
|
startTime: ${this.startTime}
|
|
14651
14746
|
endTime: ${this.endTime}
|
|
14652
14747
|
defaultBatchLimit: ${this._defaultBatchLimit}`);
|
|
@@ -14691,6 +14786,7 @@ var SessionController = class _SessionController extends Loggable {
|
|
|
14691
14786
|
}
|
|
14692
14787
|
clearStaleSessionDebugState();
|
|
14693
14788
|
const wellIndicated = await this.getWeightedContent();
|
|
14789
|
+
this._recordRuns("bootstrap");
|
|
14694
14790
|
this._wellIndicatedRemaining = wellIndicated;
|
|
14695
14791
|
if (wellIndicated >= 0 && wellIndicated < _SessionController.MIN_WELL_INDICATED) {
|
|
14696
14792
|
this.log(
|
|
@@ -14698,11 +14794,81 @@ var SessionController = class _SessionController extends Loggable {
|
|
|
14698
14794
|
);
|
|
14699
14795
|
}
|
|
14700
14796
|
await this.hydrationService.ensureHydratedCards();
|
|
14701
|
-
startSessionTracking(this.supplyQ.length, this.failedQ.length);
|
|
14797
|
+
startSessionTracking(this.sessionId, this.supplyQ.length, this.failedQ.length);
|
|
14798
|
+
this._openDocPromise = this._openSessionDoc();
|
|
14702
14799
|
this._intervalHandle = setInterval(() => {
|
|
14703
14800
|
this.tick();
|
|
14704
14801
|
}, 1e3);
|
|
14705
14802
|
}
|
|
14803
|
+
/** Label the runs the last plan produced. The pipeline can't know the why. */
|
|
14804
|
+
_recordRuns(label, mode) {
|
|
14805
|
+
for (const run of drainCapturedRuns()) {
|
|
14806
|
+
if (this._runLog.length >= _SessionController.MAX_LOGGED_RUNS) break;
|
|
14807
|
+
this._runLog.push({
|
|
14808
|
+
runId: run.runId,
|
|
14809
|
+
at: run.timestamp.toISOString(),
|
|
14810
|
+
label,
|
|
14811
|
+
...mode ? { mode } : {},
|
|
14812
|
+
generatedCount: run.generatedCount,
|
|
14813
|
+
finalCount: run.finalCount,
|
|
14814
|
+
reviewsSelected: run.reviewsSelected,
|
|
14815
|
+
newSelected: run.newSelected,
|
|
14816
|
+
// Compact detail projected off the full report so a persisted run is
|
|
14817
|
+
// self-explanatory once the in-memory ring buffer has rolled over.
|
|
14818
|
+
// Per-card provenance (`run.cards`) is intentionally left out — it's
|
|
14819
|
+
// the dominant memory cost and not worth persisting per run.
|
|
14820
|
+
...typeof run.userElo === "number" ? { userElo: run.userElo } : {},
|
|
14821
|
+
...run.generators ? { generators: run.generators } : {},
|
|
14822
|
+
...run.filters ? { filters: run.filters } : {},
|
|
14823
|
+
...run.hints ? { hints: run.hints } : {},
|
|
14824
|
+
...run.discardedTail ? { discardedTail: run.discardedTail } : {}
|
|
14825
|
+
});
|
|
14826
|
+
}
|
|
14827
|
+
}
|
|
14828
|
+
/** Time-boxed and isolated — a bad provider degrades the record, not the session. */
|
|
14829
|
+
async _captureState(phase) {
|
|
14830
|
+
if (!this._stateSnapshotProvider) return void 0;
|
|
14831
|
+
const TIMEOUT_MS = 3e3;
|
|
14832
|
+
try {
|
|
14833
|
+
return await Promise.race([
|
|
14834
|
+
Promise.resolve(this._stateSnapshotProvider(phase)),
|
|
14835
|
+
new Promise((resolve) => setTimeout(() => resolve(void 0), TIMEOUT_MS))
|
|
14836
|
+
]);
|
|
14837
|
+
} catch (e) {
|
|
14838
|
+
this.log(`[Session] state snapshot (${phase}) failed: ${e}`);
|
|
14839
|
+
return void 0;
|
|
14840
|
+
}
|
|
14841
|
+
}
|
|
14842
|
+
/** Writing at open is what makes an unclosed session visible at all. */
|
|
14843
|
+
async _openSessionDoc() {
|
|
14844
|
+
if (!this._courseId) return;
|
|
14845
|
+
try {
|
|
14846
|
+
const user = this.dataLayer.getUserDB();
|
|
14847
|
+
const doc = {
|
|
14848
|
+
_id: makeStudySessionId(this._courseId, user.getUsername(), this.sessionId),
|
|
14849
|
+
docType: "STUDY_SESSION" /* STUDY_SESSION */,
|
|
14850
|
+
sessionId: this.sessionId,
|
|
14851
|
+
courseId: this._courseId,
|
|
14852
|
+
userId: user.getUsername(),
|
|
14853
|
+
startTime: this.startTime.toISOString(),
|
|
14854
|
+
status: "open",
|
|
14855
|
+
plannedSeconds: Math.round((this.endTime.valueOf() - this.startTime.valueOf()) / 1e3),
|
|
14856
|
+
config: {
|
|
14857
|
+
defaultBatchLimit: this._defaultBatchLimit,
|
|
14858
|
+
sourceCount: this.sources.length,
|
|
14859
|
+
initHints: this._sessionHints
|
|
14860
|
+
},
|
|
14861
|
+
initialQueues: { supplyQ: this.supplyQ.length, failedQ: this.failedQ.length },
|
|
14862
|
+
runs: [...this._runLog],
|
|
14863
|
+
stateAtStart: await this._captureState("start")
|
|
14864
|
+
};
|
|
14865
|
+
this._sessionDoc = doc;
|
|
14866
|
+
await user.putStudySession(doc);
|
|
14867
|
+
this.log(`[Session] Opened session record ${doc._id}`);
|
|
14868
|
+
} catch (e) {
|
|
14869
|
+
logger.warn(`[SessionController] Failed to open session record: ${e}`);
|
|
14870
|
+
}
|
|
14871
|
+
}
|
|
14706
14872
|
/**
|
|
14707
14873
|
* Request a mid-session replan. Re-runs the pipeline with current user state
|
|
14708
14874
|
* and atomically replaces (or merges into) the supplyQ contents. Safe to call
|
|
@@ -14883,6 +15049,7 @@ var SessionController = class _SessionController extends Loggable {
|
|
|
14883
15049
|
};
|
|
14884
15050
|
});
|
|
14885
15051
|
return {
|
|
15052
|
+
sessionId: this.sessionId,
|
|
14886
15053
|
secondsRemaining: this.secondsRemaining,
|
|
14887
15054
|
hasCardGuarantee: this.hasCardGuarantee,
|
|
14888
15055
|
minCardsGuarantee: this._minCardsGuarantee,
|
|
@@ -15042,6 +15209,7 @@ var SessionController = class _SessionController extends Loggable {
|
|
|
15042
15209
|
additive: mode === "merge",
|
|
15043
15210
|
limit
|
|
15044
15211
|
});
|
|
15212
|
+
this._recordRuns(opts.label ?? "(auto)", mode);
|
|
15045
15213
|
this._wellIndicatedRemaining = wellIndicated;
|
|
15046
15214
|
if (limit !== void 0 && limit < this._defaultBatchLimit) {
|
|
15047
15215
|
this._suppressQualityReplan = true;
|
|
@@ -15353,6 +15521,7 @@ var SessionController = class _SessionController extends Loggable {
|
|
|
15353
15521
|
if (this._secondsRemaining <= 0 && this.failedQ.length === 0 && this._minCardsGuarantee <= 0) {
|
|
15354
15522
|
this._currentCard = null;
|
|
15355
15523
|
endSessionTracking();
|
|
15524
|
+
void this._terminate();
|
|
15356
15525
|
return null;
|
|
15357
15526
|
}
|
|
15358
15527
|
const WEDGE_MAX_EMPTY_STREAK = 3;
|
|
@@ -15382,6 +15551,7 @@ var SessionController = class _SessionController extends Loggable {
|
|
|
15382
15551
|
if (!nextItem) {
|
|
15383
15552
|
this._currentCard = null;
|
|
15384
15553
|
endSessionTracking();
|
|
15554
|
+
void this._terminate();
|
|
15385
15555
|
return null;
|
|
15386
15556
|
}
|
|
15387
15557
|
let card = this.hydrationService.getHydratedCard(nextItem.cardID);
|
|
@@ -15413,8 +15583,15 @@ var SessionController = class _SessionController extends Loggable {
|
|
|
15413
15583
|
this.log(`Exhausted ${MAX_SKIP} skip attempts finding a hydratable card`);
|
|
15414
15584
|
this._currentCard = null;
|
|
15415
15585
|
endSessionTracking();
|
|
15586
|
+
void this._terminate();
|
|
15416
15587
|
return null;
|
|
15417
15588
|
}
|
|
15589
|
+
/** Not awaited — the host renders the end screen off `nextCard()`'s null. */
|
|
15590
|
+
_terminate() {
|
|
15591
|
+
void this.endSession().catch((e) => {
|
|
15592
|
+
logger.warn(`[SessionController] endSession failed: ${e}`);
|
|
15593
|
+
});
|
|
15594
|
+
}
|
|
15418
15595
|
/**
|
|
15419
15596
|
* Public API for processing user responses to cards.
|
|
15420
15597
|
* @param cardRecord User's response record
|
|
@@ -15524,7 +15701,16 @@ var SessionController = class _SessionController extends Loggable {
|
|
|
15524
15701
|
* This method aggregates all responses from the session and records a
|
|
15525
15702
|
* UserOutcomeRecord if evolutionary orchestration is enabled.
|
|
15526
15703
|
*/
|
|
15527
|
-
|
|
15704
|
+
/**
|
|
15705
|
+
* Idempotent. Called from every `nextCard()` path that returns null; hosts
|
|
15706
|
+
* should also call it with `'abandoned'` when tearing down mid-session.
|
|
15707
|
+
*/
|
|
15708
|
+
async endSession(reason = "closed") {
|
|
15709
|
+
if (this._sessionClosed) return;
|
|
15710
|
+
this._sessionClosed = true;
|
|
15711
|
+
clearInterval(this._intervalHandle);
|
|
15712
|
+
setDebugSessionId(void 0);
|
|
15713
|
+
await this._closeSessionDoc(reason);
|
|
15528
15714
|
if (!this._sessionRecord || this._sessionRecord.length === 0) {
|
|
15529
15715
|
return;
|
|
15530
15716
|
}
|
|
@@ -15561,6 +15747,38 @@ var SessionController = class _SessionController extends Loggable {
|
|
|
15561
15747
|
strategies
|
|
15562
15748
|
);
|
|
15563
15749
|
}
|
|
15750
|
+
async _closeSessionDoc(reason) {
|
|
15751
|
+
if (this._openDocPromise) await this._openDocPromise;
|
|
15752
|
+
const doc = this._sessionDoc;
|
|
15753
|
+
if (!doc) return;
|
|
15754
|
+
const records = this._sessionRecord.flatMap((r) => r.records);
|
|
15755
|
+
const questionRecords = records.filter(isQuestionRecord);
|
|
15756
|
+
try {
|
|
15757
|
+
const closed = {
|
|
15758
|
+
...doc,
|
|
15759
|
+
status: reason,
|
|
15760
|
+
endTime: (/* @__PURE__ */ new Date()).toISOString(),
|
|
15761
|
+
tally: {
|
|
15762
|
+
cardsPresented: this._sessionRecord.length,
|
|
15763
|
+
responses: records.length,
|
|
15764
|
+
correct: questionRecords.filter((r) => r.isCorrect).length,
|
|
15765
|
+
incorrect: questionRecords.filter((r) => !r.isCorrect).length,
|
|
15766
|
+
failedQRemaining: this.failedQ.length,
|
|
15767
|
+
secondsRemaining: Math.max(0, this._secondsRemaining)
|
|
15768
|
+
},
|
|
15769
|
+
runs: [...this._runLog],
|
|
15770
|
+
finalHints: this._sessionHints,
|
|
15771
|
+
stateAtEnd: await this._captureState("end")
|
|
15772
|
+
};
|
|
15773
|
+
this._sessionDoc = closed;
|
|
15774
|
+
await this.dataLayer.getUserDB().putStudySession(closed);
|
|
15775
|
+
this.log(
|
|
15776
|
+
`[Session] Session record ${closed._id} -> ${reason} (${closed.tally.cardsPresented} cards, ${closed.tally.responses} responses, ${this._runLog.length} pipeline runs)`
|
|
15777
|
+
);
|
|
15778
|
+
} catch (e) {
|
|
15779
|
+
logger.warn(`[SessionController] Failed to close session record: ${e}`);
|
|
15780
|
+
}
|
|
15781
|
+
}
|
|
15564
15782
|
};
|
|
15565
15783
|
|
|
15566
15784
|
// src/study/index.ts
|
|
@@ -15608,6 +15826,7 @@ export {
|
|
|
15608
15826
|
createOrchestrationContext,
|
|
15609
15827
|
diversityRerank,
|
|
15610
15828
|
docIsDeleted,
|
|
15829
|
+
drainCapturedRuns,
|
|
15611
15830
|
endSessionTracking,
|
|
15612
15831
|
ensureAppDataDirectory,
|
|
15613
15832
|
getActiveController,
|
|
@@ -15621,6 +15840,7 @@ export {
|
|
|
15621
15840
|
getRegisteredNavigator,
|
|
15622
15841
|
getRegisteredNavigatorNames,
|
|
15623
15842
|
getRegisteredNavigatorRole,
|
|
15843
|
+
getRunsForSession,
|
|
15624
15844
|
getSrsBacklogDebug,
|
|
15625
15845
|
getStrategyPressureDebug,
|
|
15626
15846
|
getStudySource,
|
|
@@ -15638,12 +15858,14 @@ export {
|
|
|
15638
15858
|
isReview,
|
|
15639
15859
|
log,
|
|
15640
15860
|
makeScheduledCardId,
|
|
15861
|
+
makeStudySessionId,
|
|
15641
15862
|
mixerDebugAPI,
|
|
15642
15863
|
mountMixerDebugger,
|
|
15643
15864
|
mountPipelineDebugger,
|
|
15644
15865
|
mountSessionDebugger,
|
|
15645
15866
|
mountUserDBDebugger,
|
|
15646
15867
|
newInterval,
|
|
15868
|
+
newSessionId,
|
|
15647
15869
|
parseCardHistoryID,
|
|
15648
15870
|
pipelineDebugAPI,
|
|
15649
15871
|
processCustomQuestionsData,
|
|
@@ -15662,6 +15884,7 @@ export {
|
|
|
15662
15884
|
runPeriodUpdate,
|
|
15663
15885
|
scoreAccuracyInZone,
|
|
15664
15886
|
sessionDebugAPI,
|
|
15887
|
+
setDebugSessionId,
|
|
15665
15888
|
snapshotQueues,
|
|
15666
15889
|
startSessionTracking,
|
|
15667
15890
|
toggleSessionOverlay,
|