@vue-skuilder/db 0.1.17 → 0.1.20
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/{userDB-BqwxtJ_7.d.mts → classroomDB-CZdMBiTU.d.ts} +427 -104
- package/dist/{userDB-DNa0XPtn.d.ts → classroomDB-PxDZTky3.d.cts} +427 -104
- package/dist/core/index.d.cts +304 -0
- package/dist/core/index.d.ts +237 -25
- package/dist/core/index.js +2246 -118
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +2235 -114
- package/dist/core/index.mjs.map +1 -1
- package/dist/{dataLayerProvider-VlngD19_.d.mts → dataLayerProvider-D0MoZMjH.d.cts} +1 -1
- package/dist/{dataLayerProvider-BV5iZqt_.d.ts → dataLayerProvider-D8o6ZnKW.d.ts} +1 -1
- package/dist/impl/couch/{index.d.mts → index.d.cts} +47 -5
- package/dist/impl/couch/index.d.ts +46 -4
- package/dist/impl/couch/index.js +2250 -134
- package/dist/impl/couch/index.js.map +1 -1
- package/dist/impl/couch/index.mjs +2212 -97
- package/dist/impl/couch/index.mjs.map +1 -1
- package/dist/impl/static/{index.d.mts → index.d.cts} +6 -6
- package/dist/impl/static/index.d.ts +5 -5
- package/dist/impl/static/index.js +1950 -143
- package/dist/impl/static/index.js.map +1 -1
- package/dist/impl/static/index.mjs +1922 -117
- package/dist/impl/static/index.mjs.map +1 -1
- package/dist/{index-Bmll7Xse.d.mts → index-B_j6u5E4.d.cts} +1 -1
- package/dist/{index-CD8BZz2k.d.ts → index-Dj0SEgk3.d.ts} +1 -1
- package/dist/{index.d.mts → index.d.cts} +97 -13
- package/dist/index.d.ts +96 -12
- package/dist/index.js +2439 -180
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2386 -135
- package/dist/index.mjs.map +1 -1
- package/dist/pouch/index.js +3 -3
- package/dist/{types-Dbp5DaRR.d.mts → types-Bn0itutr.d.cts} +1 -1
- package/dist/{types-CewsN87z.d.ts → types-DQaXnuoc.d.ts} +1 -1
- package/dist/{types-legacy-6ettoclI.d.ts → types-legacy-DDY4N-Uq.d.cts} +3 -1
- package/dist/{types-legacy-6ettoclI.d.mts → types-legacy-DDY4N-Uq.d.ts} +3 -1
- package/dist/util/packer/{index.d.mts → index.d.cts} +3 -3
- package/dist/util/packer/index.d.ts +3 -3
- package/dist/util/packer/index.js.map +1 -1
- package/dist/util/packer/index.mjs.map +1 -1
- package/docs/brainstorm-navigation-paradigm.md +369 -0
- package/docs/navigators-architecture.md +370 -0
- package/docs/todo-evolutionary-orchestration.md +310 -0
- package/docs/todo-nominal-tag-types.md +121 -0
- package/docs/todo-strategy-authoring.md +401 -0
- package/eslint.config.mjs +1 -1
- package/package.json +9 -4
- package/src/core/index.ts +1 -0
- package/src/core/interfaces/contentSource.ts +88 -4
- package/src/core/interfaces/courseDB.ts +13 -0
- package/src/core/interfaces/navigationStrategyManager.ts +0 -5
- package/src/core/interfaces/userDB.ts +32 -0
- package/src/core/navigators/CompositeGenerator.ts +268 -0
- package/src/core/navigators/Pipeline.ts +318 -0
- package/src/core/navigators/PipelineAssembler.ts +194 -0
- package/src/core/navigators/elo.ts +104 -15
- package/src/core/navigators/filters/eloDistance.ts +132 -0
- package/src/core/navigators/filters/index.ts +9 -0
- package/src/core/navigators/filters/types.ts +115 -0
- package/src/core/navigators/filters/userTagPreference.ts +232 -0
- package/src/core/navigators/generators/index.ts +2 -0
- package/src/core/navigators/generators/types.ts +107 -0
- package/src/core/navigators/hardcodedOrder.ts +111 -12
- package/src/core/navigators/hierarchyDefinition.ts +266 -0
- package/src/core/navigators/index.ts +404 -3
- package/src/core/navigators/inferredPreference.ts +107 -0
- package/src/core/navigators/interferenceMitigator.ts +355 -0
- package/src/core/navigators/relativePriority.ts +255 -0
- package/src/core/navigators/srs.ts +195 -0
- package/src/core/navigators/userGoal.ts +136 -0
- package/src/core/types/strategyState.ts +84 -0
- package/src/core/types/types-legacy.ts +2 -0
- package/src/impl/common/BaseUserDB.ts +74 -7
- package/src/impl/couch/adminDB.ts +1 -2
- package/src/impl/couch/classroomDB.ts +51 -0
- package/src/impl/couch/courseDB.ts +147 -49
- package/src/impl/static/courseDB.ts +11 -4
- package/src/study/SessionController.ts +149 -1
- package/src/study/TagFilteredContentSource.ts +255 -0
- package/src/study/index.ts +1 -0
- package/src/util/dataDirectory.test.ts +51 -22
- package/src/util/logger.ts +0 -1
- package/tests/core/navigators/CompositeGenerator.test.ts +455 -0
- package/tests/core/navigators/Pipeline.test.ts +406 -0
- package/tests/core/navigators/PipelineAssembler.test.ts +351 -0
- package/tests/core/navigators/SRSNavigator.test.ts +344 -0
- package/tests/core/navigators/eloDistanceFilter.test.ts +192 -0
- package/tests/core/navigators/navigators.test.ts +710 -0
- package/tsconfig.json +1 -1
- package/vitest.config.ts +29 -0
- package/dist/core/index.d.mts +0 -92
- /package/dist/{SyncStrategy-CyATpyLQ.d.mts → SyncStrategy-CyATpyLQ.d.cts} +0 -0
- /package/dist/pouch/{index.d.mts → index.d.cts} +0 -0
|
@@ -119,7 +119,8 @@ var init_types_legacy = __esm({
|
|
|
119
119
|
["QUESTION" /* QUESTIONTYPE */]: "QUESTION",
|
|
120
120
|
["VIEW" /* VIEW */]: "VIEW",
|
|
121
121
|
["PEDAGOGY" /* PEDAGOGY */]: "PEDAGOGY",
|
|
122
|
-
["NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */]: "NAVIGATION_STRATEGY"
|
|
122
|
+
["NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */]: "NAVIGATION_STRATEGY",
|
|
123
|
+
["STRATEGY_STATE" /* STRATEGY_STATE */]: "STRATEGY_STATE"
|
|
123
124
|
};
|
|
124
125
|
}
|
|
125
126
|
});
|
|
@@ -140,9 +141,9 @@ var import_pouchdb, import_pouchdb_find, import_pouchdb_authentication, pouchdb_
|
|
|
140
141
|
var init_pouchdb_setup = __esm({
|
|
141
142
|
"src/impl/couch/pouchdb-setup.ts"() {
|
|
142
143
|
"use strict";
|
|
143
|
-
import_pouchdb = __toESM(require("pouchdb"));
|
|
144
|
-
import_pouchdb_find = __toESM(require("pouchdb-find"));
|
|
145
|
-
import_pouchdb_authentication = __toESM(require("@nilock2/pouchdb-authentication"));
|
|
144
|
+
import_pouchdb = __toESM(require("pouchdb"), 1);
|
|
145
|
+
import_pouchdb_find = __toESM(require("pouchdb-find"), 1);
|
|
146
|
+
import_pouchdb_authentication = __toESM(require("@nilock2/pouchdb-authentication"), 1);
|
|
146
147
|
import_pouchdb.default.plugin(import_pouchdb_find.default);
|
|
147
148
|
import_pouchdb.default.plugin(import_pouchdb_authentication.default);
|
|
148
149
|
import_pouchdb.default.defaults({
|
|
@@ -177,8 +178,8 @@ var path, os;
|
|
|
177
178
|
var init_dataDirectory = __esm({
|
|
178
179
|
"src/util/dataDirectory.ts"() {
|
|
179
180
|
"use strict";
|
|
180
|
-
path = __toESM(require("path"));
|
|
181
|
-
os = __toESM(require("os"));
|
|
181
|
+
path = __toESM(require("path"), 1);
|
|
182
|
+
os = __toESM(require("os"), 1);
|
|
182
183
|
init_tuiLogger();
|
|
183
184
|
init_factory();
|
|
184
185
|
}
|
|
@@ -238,7 +239,7 @@ var import_moment, REVIEW_TIME_FORMAT, log;
|
|
|
238
239
|
var init_userDBHelpers = __esm({
|
|
239
240
|
"src/impl/common/userDBHelpers.ts"() {
|
|
240
241
|
"use strict";
|
|
241
|
-
import_moment = __toESM(require("moment"));
|
|
242
|
+
import_moment = __toESM(require("moment"), 1);
|
|
242
243
|
init_core();
|
|
243
244
|
init_logger();
|
|
244
245
|
init_pouchdb_setup();
|
|
@@ -394,7 +395,7 @@ var import_moment2, UsrCrsData;
|
|
|
394
395
|
var init_user_course_relDB = __esm({
|
|
395
396
|
"src/impl/couch/user-course-relDB.ts"() {
|
|
396
397
|
"use strict";
|
|
397
|
-
import_moment2 = __toESM(require("moment"));
|
|
398
|
+
import_moment2 = __toESM(require("moment"), 1);
|
|
398
399
|
init_logger();
|
|
399
400
|
UsrCrsData = class {
|
|
400
401
|
user;
|
|
@@ -499,141 +500,1682 @@ var init_courseLookupDB = __esm({
|
|
|
499
500
|
}
|
|
500
501
|
});
|
|
501
502
|
|
|
503
|
+
// src/core/navigators/CompositeGenerator.ts
|
|
504
|
+
var CompositeGenerator_exports = {};
|
|
505
|
+
__export(CompositeGenerator_exports, {
|
|
506
|
+
AggregationMode: () => AggregationMode,
|
|
507
|
+
default: () => CompositeGenerator
|
|
508
|
+
});
|
|
509
|
+
var AggregationMode, DEFAULT_AGGREGATION_MODE, FREQUENCY_BOOST_FACTOR, CompositeGenerator;
|
|
510
|
+
var init_CompositeGenerator = __esm({
|
|
511
|
+
"src/core/navigators/CompositeGenerator.ts"() {
|
|
512
|
+
"use strict";
|
|
513
|
+
init_navigators();
|
|
514
|
+
init_logger();
|
|
515
|
+
AggregationMode = /* @__PURE__ */ ((AggregationMode2) => {
|
|
516
|
+
AggregationMode2["MAX"] = "max";
|
|
517
|
+
AggregationMode2["AVERAGE"] = "average";
|
|
518
|
+
AggregationMode2["FREQUENCY_BOOST"] = "frequencyBoost";
|
|
519
|
+
return AggregationMode2;
|
|
520
|
+
})(AggregationMode || {});
|
|
521
|
+
DEFAULT_AGGREGATION_MODE = "frequencyBoost" /* FREQUENCY_BOOST */;
|
|
522
|
+
FREQUENCY_BOOST_FACTOR = 0.1;
|
|
523
|
+
CompositeGenerator = class _CompositeGenerator extends ContentNavigator {
|
|
524
|
+
/** Human-readable name for CardGenerator interface */
|
|
525
|
+
name = "Composite Generator";
|
|
526
|
+
generators;
|
|
527
|
+
aggregationMode;
|
|
528
|
+
constructor(generators, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
529
|
+
super();
|
|
530
|
+
this.generators = generators;
|
|
531
|
+
this.aggregationMode = aggregationMode;
|
|
532
|
+
if (generators.length === 0) {
|
|
533
|
+
throw new Error("CompositeGenerator requires at least one generator");
|
|
534
|
+
}
|
|
535
|
+
logger.debug(
|
|
536
|
+
`[CompositeGenerator] Created with ${generators.length} generators, mode: ${aggregationMode}`
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Creates a CompositeGenerator from strategy data.
|
|
541
|
+
*
|
|
542
|
+
* This is a convenience factory for use by PipelineAssembler.
|
|
543
|
+
*/
|
|
544
|
+
static async fromStrategies(user, course, strategies, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
545
|
+
const generators = await Promise.all(
|
|
546
|
+
strategies.map((s) => ContentNavigator.create(user, course, s))
|
|
547
|
+
);
|
|
548
|
+
return new _CompositeGenerator(generators, aggregationMode);
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Get weighted cards from all generators, merge and deduplicate.
|
|
552
|
+
*
|
|
553
|
+
* Cards appearing in multiple generators receive a score boost.
|
|
554
|
+
* Provenance tracks which generators produced each card and how scores were aggregated.
|
|
555
|
+
*
|
|
556
|
+
* This method supports both the legacy signature (limit only) and the
|
|
557
|
+
* CardGenerator interface signature (limit, context).
|
|
558
|
+
*
|
|
559
|
+
* @param limit - Maximum number of cards to return
|
|
560
|
+
* @param context - Optional GeneratorContext passed to child generators
|
|
561
|
+
*/
|
|
562
|
+
async getWeightedCards(limit, context) {
|
|
563
|
+
const results = await Promise.all(
|
|
564
|
+
this.generators.map((g) => g.getWeightedCards(limit, context))
|
|
565
|
+
);
|
|
566
|
+
const byCardId = /* @__PURE__ */ new Map();
|
|
567
|
+
for (const cards of results) {
|
|
568
|
+
for (const card of cards) {
|
|
569
|
+
const existing = byCardId.get(card.cardId) || [];
|
|
570
|
+
existing.push(card);
|
|
571
|
+
byCardId.set(card.cardId, existing);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
const merged = [];
|
|
575
|
+
for (const [, cards] of byCardId) {
|
|
576
|
+
const aggregatedScore = this.aggregateScores(cards);
|
|
577
|
+
const finalScore = Math.min(1, aggregatedScore);
|
|
578
|
+
const mergedProvenance = cards.flatMap((c) => c.provenance);
|
|
579
|
+
const initialScore = cards[0].score;
|
|
580
|
+
const action = finalScore > initialScore ? "boosted" : finalScore < initialScore ? "penalized" : "passed";
|
|
581
|
+
const reason = this.buildAggregationReason(cards, finalScore);
|
|
582
|
+
merged.push({
|
|
583
|
+
...cards[0],
|
|
584
|
+
score: finalScore,
|
|
585
|
+
provenance: [
|
|
586
|
+
...mergedProvenance,
|
|
587
|
+
{
|
|
588
|
+
strategy: "composite",
|
|
589
|
+
strategyName: "Composite Generator",
|
|
590
|
+
strategyId: "COMPOSITE_GENERATOR",
|
|
591
|
+
action,
|
|
592
|
+
score: finalScore,
|
|
593
|
+
reason
|
|
594
|
+
}
|
|
595
|
+
]
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
return merged.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Build human-readable reason for score aggregation.
|
|
602
|
+
*/
|
|
603
|
+
buildAggregationReason(cards, finalScore) {
|
|
604
|
+
const count = cards.length;
|
|
605
|
+
const scores = cards.map((c) => c.score.toFixed(2)).join(", ");
|
|
606
|
+
if (count === 1) {
|
|
607
|
+
return `Single generator, score ${finalScore.toFixed(2)}`;
|
|
608
|
+
}
|
|
609
|
+
const strategies = cards.map((c) => c.provenance[0]?.strategy || "unknown").join(", ");
|
|
610
|
+
switch (this.aggregationMode) {
|
|
611
|
+
case "max" /* MAX */:
|
|
612
|
+
return `Max of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
613
|
+
case "average" /* AVERAGE */:
|
|
614
|
+
return `Average of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
615
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
616
|
+
const avg = cards.reduce((sum, c) => sum + c.score, 0) / count;
|
|
617
|
+
const boost = 1 + FREQUENCY_BOOST_FACTOR * (count - 1);
|
|
618
|
+
return `Frequency boost from ${count} generators (${strategies}): avg ${avg.toFixed(2)} \xD7 ${boost.toFixed(2)} \u2192 ${finalScore.toFixed(2)}`;
|
|
619
|
+
}
|
|
620
|
+
default:
|
|
621
|
+
return `Aggregated from ${count} generators: ${finalScore.toFixed(2)}`;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Aggregate scores from multiple generators for the same card.
|
|
626
|
+
*/
|
|
627
|
+
aggregateScores(cards) {
|
|
628
|
+
const scores = cards.map((c) => c.score);
|
|
629
|
+
switch (this.aggregationMode) {
|
|
630
|
+
case "max" /* MAX */:
|
|
631
|
+
return Math.max(...scores);
|
|
632
|
+
case "average" /* AVERAGE */:
|
|
633
|
+
return scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
634
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
635
|
+
const avg = scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
636
|
+
const frequencyBoost = 1 + FREQUENCY_BOOST_FACTOR * (cards.length - 1);
|
|
637
|
+
return avg * frequencyBoost;
|
|
638
|
+
}
|
|
639
|
+
default:
|
|
640
|
+
return scores[0];
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
/**
|
|
644
|
+
* Get new cards from all generators, merged and deduplicated.
|
|
645
|
+
*/
|
|
646
|
+
async getNewCards(n) {
|
|
647
|
+
const legacyGenerators = this.generators.filter(
|
|
648
|
+
(g) => g instanceof ContentNavigator
|
|
649
|
+
);
|
|
650
|
+
const results = await Promise.all(legacyGenerators.map((g) => g.getNewCards(n)));
|
|
651
|
+
const seen = /* @__PURE__ */ new Set();
|
|
652
|
+
const merged = [];
|
|
653
|
+
for (const cards of results) {
|
|
654
|
+
for (const card of cards) {
|
|
655
|
+
if (!seen.has(card.cardID)) {
|
|
656
|
+
seen.add(card.cardID);
|
|
657
|
+
merged.push(card);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
return n ? merged.slice(0, n) : merged;
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Get pending reviews from all generators, merged and deduplicated.
|
|
665
|
+
*/
|
|
666
|
+
async getPendingReviews() {
|
|
667
|
+
const legacyGenerators = this.generators.filter(
|
|
668
|
+
(g) => g instanceof ContentNavigator
|
|
669
|
+
);
|
|
670
|
+
const results = await Promise.all(legacyGenerators.map((g) => g.getPendingReviews()));
|
|
671
|
+
const seen = /* @__PURE__ */ new Set();
|
|
672
|
+
const merged = [];
|
|
673
|
+
for (const reviews of results) {
|
|
674
|
+
for (const review of reviews) {
|
|
675
|
+
if (!seen.has(review.cardID)) {
|
|
676
|
+
seen.add(review.cardID);
|
|
677
|
+
merged.push(review);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
return merged;
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
// src/core/navigators/Pipeline.ts
|
|
688
|
+
var Pipeline_exports = {};
|
|
689
|
+
__export(Pipeline_exports, {
|
|
690
|
+
Pipeline: () => Pipeline
|
|
691
|
+
});
|
|
692
|
+
function logPipelineConfig(generator, filters) {
|
|
693
|
+
const filterList = filters.length > 0 ? "\n - " + filters.map((f) => f.name).join("\n - ") : " none";
|
|
694
|
+
logger.info(
|
|
695
|
+
`[Pipeline] Configuration:
|
|
696
|
+
Generator: ${generator.name}
|
|
697
|
+
Filters:${filterList}`
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
function logTagHydration(cards, tagsByCard) {
|
|
701
|
+
const totalTags = Array.from(tagsByCard.values()).reduce((sum, tags) => sum + tags.length, 0);
|
|
702
|
+
const cardsWithTags = Array.from(tagsByCard.values()).filter((tags) => tags.length > 0).length;
|
|
703
|
+
logger.debug(
|
|
704
|
+
`[Pipeline] Tag hydration: ${cards.length} cards, ${cardsWithTags} have tags (${totalTags} total tags) - single batch query`
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
function logExecutionSummary(generatorName, generatedCount, filterCount, finalCount, topScores) {
|
|
708
|
+
const scoreDisplay = topScores.length > 0 ? topScores.map((s) => s.toFixed(2)).join(", ") : "none";
|
|
709
|
+
logger.info(
|
|
710
|
+
`[Pipeline] Execution: ${generatorName} produced ${generatedCount} \u2192 ${filterCount} filters \u2192 ${finalCount} results (top scores: ${scoreDisplay})`
|
|
711
|
+
);
|
|
712
|
+
}
|
|
713
|
+
function logCardProvenance(cards, maxCards = 3) {
|
|
714
|
+
const cardsToLog = cards.slice(0, maxCards);
|
|
715
|
+
logger.debug(`[Pipeline] Provenance for top ${cardsToLog.length} cards:`);
|
|
716
|
+
for (const card of cardsToLog) {
|
|
717
|
+
logger.debug(`[Pipeline] ${card.cardId} (final score: ${card.score.toFixed(3)}):`);
|
|
718
|
+
for (const entry of card.provenance) {
|
|
719
|
+
const scoreChange = entry.score.toFixed(3);
|
|
720
|
+
const action = entry.action.padEnd(9);
|
|
721
|
+
logger.debug(
|
|
722
|
+
`[Pipeline] ${action} ${scoreChange} - ${entry.strategyName}: ${entry.reason}`
|
|
723
|
+
);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
var import_common5, Pipeline;
|
|
728
|
+
var init_Pipeline = __esm({
|
|
729
|
+
"src/core/navigators/Pipeline.ts"() {
|
|
730
|
+
"use strict";
|
|
731
|
+
import_common5 = require("@vue-skuilder/common");
|
|
732
|
+
init_navigators();
|
|
733
|
+
init_logger();
|
|
734
|
+
Pipeline = class extends ContentNavigator {
|
|
735
|
+
generator;
|
|
736
|
+
filters;
|
|
737
|
+
/**
|
|
738
|
+
* Create a new pipeline.
|
|
739
|
+
*
|
|
740
|
+
* @param generator - The generator (or CompositeGenerator) that produces candidates
|
|
741
|
+
* @param filters - Filters to apply sequentially (order doesn't matter for multipliers)
|
|
742
|
+
* @param user - User database interface
|
|
743
|
+
* @param course - Course database interface
|
|
744
|
+
*/
|
|
745
|
+
constructor(generator, filters, user, course) {
|
|
746
|
+
super();
|
|
747
|
+
this.generator = generator;
|
|
748
|
+
this.filters = filters;
|
|
749
|
+
this.user = user;
|
|
750
|
+
this.course = course;
|
|
751
|
+
logPipelineConfig(generator, filters);
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Get weighted cards by running generator and applying filters.
|
|
755
|
+
*
|
|
756
|
+
* 1. Build shared context (user ELO, etc.)
|
|
757
|
+
* 2. Get candidates from generator (passing context)
|
|
758
|
+
* 3. Batch hydrate tags for all candidates
|
|
759
|
+
* 4. Apply each filter sequentially
|
|
760
|
+
* 5. Remove zero-score cards
|
|
761
|
+
* 6. Sort by score descending
|
|
762
|
+
* 7. Return top N
|
|
763
|
+
*
|
|
764
|
+
* @param limit - Maximum number of cards to return
|
|
765
|
+
* @returns Cards sorted by score descending
|
|
766
|
+
*/
|
|
767
|
+
async getWeightedCards(limit) {
|
|
768
|
+
const context = await this.buildContext();
|
|
769
|
+
const overFetchMultiplier = 2 + this.filters.length * 0.5;
|
|
770
|
+
const fetchLimit = Math.ceil(limit * overFetchMultiplier);
|
|
771
|
+
logger.debug(
|
|
772
|
+
`[Pipeline] Fetching ${fetchLimit} candidates from generator '${this.generator.name}'`
|
|
773
|
+
);
|
|
774
|
+
let cards = await this.generator.getWeightedCards(fetchLimit, context);
|
|
775
|
+
const generatedCount = cards.length;
|
|
776
|
+
logger.debug(`[Pipeline] Generator returned ${generatedCount} candidates`);
|
|
777
|
+
cards = await this.hydrateTags(cards);
|
|
778
|
+
for (const filter of this.filters) {
|
|
779
|
+
const beforeCount = cards.length;
|
|
780
|
+
cards = await filter.transform(cards, context);
|
|
781
|
+
logger.debug(`[Pipeline] Filter '${filter.name}': ${beforeCount} \u2192 ${cards.length} cards`);
|
|
782
|
+
}
|
|
783
|
+
cards = cards.filter((c) => c.score > 0);
|
|
784
|
+
cards.sort((a, b) => b.score - a.score);
|
|
785
|
+
const result = cards.slice(0, limit);
|
|
786
|
+
const topScores = result.slice(0, 3).map((c) => c.score);
|
|
787
|
+
logExecutionSummary(this.generator.name, generatedCount, this.filters.length, result.length, topScores);
|
|
788
|
+
logCardProvenance(result, 3);
|
|
789
|
+
return result;
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Batch hydrate tags for all cards.
|
|
793
|
+
*
|
|
794
|
+
* Fetches tags for all cards in a single database query and attaches them
|
|
795
|
+
* to the WeightedCard objects. Filters can then use card.tags instead of
|
|
796
|
+
* making individual getAppliedTags() calls.
|
|
797
|
+
*
|
|
798
|
+
* @param cards - Cards to hydrate
|
|
799
|
+
* @returns Cards with tags populated
|
|
800
|
+
*/
|
|
801
|
+
async hydrateTags(cards) {
|
|
802
|
+
if (cards.length === 0) {
|
|
803
|
+
return cards;
|
|
804
|
+
}
|
|
805
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
806
|
+
const tagsByCard = await this.course.getAppliedTagsBatch(cardIds);
|
|
807
|
+
logTagHydration(cards, tagsByCard);
|
|
808
|
+
return cards.map((card) => ({
|
|
809
|
+
...card,
|
|
810
|
+
tags: tagsByCard.get(card.cardId) ?? []
|
|
811
|
+
}));
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Build shared context for generator and filters.
|
|
815
|
+
*
|
|
816
|
+
* Called once per getWeightedCards() invocation.
|
|
817
|
+
* Contains data that the generator and multiple filters might need.
|
|
818
|
+
*
|
|
819
|
+
* The context satisfies both GeneratorContext and FilterContext interfaces.
|
|
820
|
+
*/
|
|
821
|
+
async buildContext() {
|
|
822
|
+
let userElo = 1e3;
|
|
823
|
+
try {
|
|
824
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
825
|
+
const courseElo = (0, import_common5.toCourseElo)(courseReg.elo);
|
|
826
|
+
userElo = courseElo.global.score;
|
|
827
|
+
} catch (e) {
|
|
828
|
+
logger.debug(`[Pipeline] Could not get user ELO, using default: ${e}`);
|
|
829
|
+
}
|
|
830
|
+
return {
|
|
831
|
+
user: this.user,
|
|
832
|
+
course: this.course,
|
|
833
|
+
userElo
|
|
834
|
+
};
|
|
835
|
+
}
|
|
836
|
+
// ===========================================================================
|
|
837
|
+
// Legacy StudyContentSource methods
|
|
838
|
+
// ===========================================================================
|
|
839
|
+
//
|
|
840
|
+
// These delegate to the generator for backward compatibility.
|
|
841
|
+
// Eventually SessionController will use getWeightedCards() exclusively.
|
|
842
|
+
//
|
|
843
|
+
/**
|
|
844
|
+
* Get new cards via legacy API.
|
|
845
|
+
* Delegates to the generator if it supports the legacy interface.
|
|
846
|
+
*/
|
|
847
|
+
async getNewCards(n) {
|
|
848
|
+
if ("getNewCards" in this.generator && typeof this.generator.getNewCards === "function") {
|
|
849
|
+
return this.generator.getNewCards(n);
|
|
850
|
+
}
|
|
851
|
+
return [];
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Get pending reviews via legacy API.
|
|
855
|
+
* Delegates to the generator if it supports the legacy interface.
|
|
856
|
+
*/
|
|
857
|
+
async getPendingReviews() {
|
|
858
|
+
if ("getPendingReviews" in this.generator && typeof this.generator.getPendingReviews === "function") {
|
|
859
|
+
return this.generator.getPendingReviews();
|
|
860
|
+
}
|
|
861
|
+
return [];
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Get the course ID for this pipeline.
|
|
865
|
+
*/
|
|
866
|
+
getCourseID() {
|
|
867
|
+
return this.course.getCourseID();
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
});
|
|
872
|
+
|
|
873
|
+
// src/core/navigators/PipelineAssembler.ts
|
|
874
|
+
var PipelineAssembler_exports = {};
|
|
875
|
+
__export(PipelineAssembler_exports, {
|
|
876
|
+
PipelineAssembler: () => PipelineAssembler
|
|
877
|
+
});
|
|
878
|
+
var PipelineAssembler;
|
|
879
|
+
var init_PipelineAssembler = __esm({
|
|
880
|
+
"src/core/navigators/PipelineAssembler.ts"() {
|
|
881
|
+
"use strict";
|
|
882
|
+
init_navigators();
|
|
883
|
+
init_Pipeline();
|
|
884
|
+
init_types_legacy();
|
|
885
|
+
init_logger();
|
|
886
|
+
init_CompositeGenerator();
|
|
887
|
+
PipelineAssembler = class {
|
|
888
|
+
/**
|
|
889
|
+
* Assembles a navigation pipeline from strategy documents.
|
|
890
|
+
*
|
|
891
|
+
* 1. Separates into generators and filters by role
|
|
892
|
+
* 2. Validates at least one generator exists (or creates default ELO)
|
|
893
|
+
* 3. Instantiates generators - wraps multiple in CompositeGenerator
|
|
894
|
+
* 4. Instantiates filters
|
|
895
|
+
* 5. Returns Pipeline(generator, filters)
|
|
896
|
+
*
|
|
897
|
+
* @param input - Strategy documents plus user/course interfaces
|
|
898
|
+
* @returns Assembled pipeline and any warnings
|
|
899
|
+
*/
|
|
900
|
+
async assemble(input) {
|
|
901
|
+
const { strategies, user, course } = input;
|
|
902
|
+
const warnings = [];
|
|
903
|
+
if (strategies.length === 0) {
|
|
904
|
+
return {
|
|
905
|
+
pipeline: null,
|
|
906
|
+
generatorStrategies: [],
|
|
907
|
+
filterStrategies: [],
|
|
908
|
+
warnings
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
const generatorStrategies = [];
|
|
912
|
+
const filterStrategies = [];
|
|
913
|
+
for (const s of strategies) {
|
|
914
|
+
if (isGenerator(s.implementingClass)) {
|
|
915
|
+
generatorStrategies.push(s);
|
|
916
|
+
} else if (isFilter(s.implementingClass)) {
|
|
917
|
+
filterStrategies.push(s);
|
|
918
|
+
} else {
|
|
919
|
+
warnings.push(`Unknown strategy type '${s.implementingClass}', skipping: ${s.name}`);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
if (generatorStrategies.length === 0) {
|
|
923
|
+
if (filterStrategies.length > 0) {
|
|
924
|
+
logger.debug(
|
|
925
|
+
"[PipelineAssembler] No generator found, using default ELO with configured filters"
|
|
926
|
+
);
|
|
927
|
+
generatorStrategies.push(this.makeDefaultEloStrategy(course.getCourseID()));
|
|
928
|
+
} else {
|
|
929
|
+
warnings.push("No generator strategy found");
|
|
930
|
+
return {
|
|
931
|
+
pipeline: null,
|
|
932
|
+
generatorStrategies: [],
|
|
933
|
+
filterStrategies: [],
|
|
934
|
+
warnings
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
let generator;
|
|
939
|
+
if (generatorStrategies.length === 1) {
|
|
940
|
+
const nav = await ContentNavigator.create(user, course, generatorStrategies[0]);
|
|
941
|
+
generator = nav;
|
|
942
|
+
logger.debug(`[PipelineAssembler] Using single generator: ${generatorStrategies[0].name}`);
|
|
943
|
+
} else {
|
|
944
|
+
logger.debug(
|
|
945
|
+
`[PipelineAssembler] Using CompositeGenerator for ${generatorStrategies.length} generators: ${generatorStrategies.map((g) => g.name).join(", ")}`
|
|
946
|
+
);
|
|
947
|
+
generator = await CompositeGenerator.fromStrategies(user, course, generatorStrategies);
|
|
948
|
+
}
|
|
949
|
+
const filters = [];
|
|
950
|
+
const sortedFilterStrategies = [...filterStrategies].sort(
|
|
951
|
+
(a, b) => a.name.localeCompare(b.name)
|
|
952
|
+
);
|
|
953
|
+
for (const filterStrategy of sortedFilterStrategies) {
|
|
954
|
+
try {
|
|
955
|
+
const nav = await ContentNavigator.create(user, course, filterStrategy);
|
|
956
|
+
if ("transform" in nav && typeof nav.transform === "function") {
|
|
957
|
+
filters.push(nav);
|
|
958
|
+
logger.debug(`[PipelineAssembler] Added filter: ${filterStrategy.name}`);
|
|
959
|
+
} else {
|
|
960
|
+
warnings.push(
|
|
961
|
+
`Filter '${filterStrategy.name}' does not implement CardFilter.transform(), skipping`
|
|
962
|
+
);
|
|
963
|
+
}
|
|
964
|
+
} catch (e) {
|
|
965
|
+
warnings.push(`Failed to instantiate filter '${filterStrategy.name}': ${e}`);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
const pipeline = new Pipeline(generator, filters, user, course);
|
|
969
|
+
logger.debug(
|
|
970
|
+
`[PipelineAssembler] Assembled pipeline with ${generatorStrategies.length} generator(s) and ${filters.length} filter(s)`
|
|
971
|
+
);
|
|
972
|
+
return {
|
|
973
|
+
pipeline,
|
|
974
|
+
generatorStrategies,
|
|
975
|
+
filterStrategies: sortedFilterStrategies,
|
|
976
|
+
warnings
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* Creates a default ELO generator strategy.
|
|
981
|
+
* Used when filters are configured but no generator is specified.
|
|
982
|
+
*/
|
|
983
|
+
makeDefaultEloStrategy(courseId) {
|
|
984
|
+
return {
|
|
985
|
+
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
986
|
+
course: courseId,
|
|
987
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
988
|
+
name: "ELO (default)",
|
|
989
|
+
description: "Default ELO-based generator",
|
|
990
|
+
implementingClass: "elo" /* ELO */,
|
|
991
|
+
serializedData: ""
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
});
|
|
997
|
+
|
|
502
998
|
// src/core/navigators/elo.ts
|
|
503
999
|
var elo_exports = {};
|
|
504
1000
|
__export(elo_exports, {
|
|
505
1001
|
default: () => ELONavigator
|
|
506
1002
|
});
|
|
507
|
-
var ELONavigator;
|
|
508
|
-
var init_elo = __esm({
|
|
509
|
-
"src/core/navigators/elo.ts"() {
|
|
1003
|
+
var import_common6, ELONavigator;
|
|
1004
|
+
var init_elo = __esm({
|
|
1005
|
+
"src/core/navigators/elo.ts"() {
|
|
1006
|
+
"use strict";
|
|
1007
|
+
init_navigators();
|
|
1008
|
+
import_common6 = require("@vue-skuilder/common");
|
|
1009
|
+
ELONavigator = class extends ContentNavigator {
|
|
1010
|
+
/** Human-readable name for CardGenerator interface */
|
|
1011
|
+
name;
|
|
1012
|
+
constructor(user, course, strategyData) {
|
|
1013
|
+
super(user, course, strategyData);
|
|
1014
|
+
this.name = strategyData?.name || "ELO";
|
|
1015
|
+
}
|
|
1016
|
+
async getPendingReviews() {
|
|
1017
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1018
|
+
const elo = await this.course.getCardEloData(reviews.map((r) => r.cardId));
|
|
1019
|
+
const ratedReviews = reviews.map((r, i) => {
|
|
1020
|
+
const ratedR = {
|
|
1021
|
+
...r,
|
|
1022
|
+
...elo[i]
|
|
1023
|
+
};
|
|
1024
|
+
return ratedR;
|
|
1025
|
+
});
|
|
1026
|
+
ratedReviews.sort((a, b) => {
|
|
1027
|
+
return a.global.score - b.global.score;
|
|
1028
|
+
});
|
|
1029
|
+
return ratedReviews.map((r) => {
|
|
1030
|
+
return {
|
|
1031
|
+
...r,
|
|
1032
|
+
contentSourceType: "course",
|
|
1033
|
+
contentSourceID: this.course.getCourseID(),
|
|
1034
|
+
cardID: r.cardId,
|
|
1035
|
+
courseID: r.courseId,
|
|
1036
|
+
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
1037
|
+
reviewID: r._id,
|
|
1038
|
+
status: "review"
|
|
1039
|
+
};
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
async getNewCards(limit = 99) {
|
|
1043
|
+
const activeCards = await this.user.getActiveCards();
|
|
1044
|
+
return (await this.course.getCardsCenteredAtELO(
|
|
1045
|
+
{ limit, elo: "user" },
|
|
1046
|
+
(c) => {
|
|
1047
|
+
if (activeCards.some((ac) => c.cardID === ac.cardID)) {
|
|
1048
|
+
return false;
|
|
1049
|
+
} else {
|
|
1050
|
+
return true;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
)).map((c) => {
|
|
1054
|
+
return {
|
|
1055
|
+
...c,
|
|
1056
|
+
status: "new"
|
|
1057
|
+
};
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Get new cards with suitability scores based on ELO distance.
|
|
1062
|
+
*
|
|
1063
|
+
* Cards closer to user's ELO get higher scores.
|
|
1064
|
+
* Score formula: max(0, 1 - distance / 500)
|
|
1065
|
+
*
|
|
1066
|
+
* NOTE: This generator only handles NEW cards. Reviews are handled by
|
|
1067
|
+
* SRSNavigator. Use CompositeGenerator to combine both.
|
|
1068
|
+
*
|
|
1069
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1070
|
+
* CardGenerator interface signature (limit, context).
|
|
1071
|
+
*
|
|
1072
|
+
* @param limit - Maximum number of cards to return
|
|
1073
|
+
* @param context - Optional GeneratorContext (used when called via Pipeline)
|
|
1074
|
+
*/
|
|
1075
|
+
async getWeightedCards(limit, context) {
|
|
1076
|
+
let userGlobalElo;
|
|
1077
|
+
if (context?.userElo !== void 0) {
|
|
1078
|
+
userGlobalElo = context.userElo;
|
|
1079
|
+
} else {
|
|
1080
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
1081
|
+
const userElo = (0, import_common6.toCourseElo)(courseReg.elo);
|
|
1082
|
+
userGlobalElo = userElo.global.score;
|
|
1083
|
+
}
|
|
1084
|
+
const newCards = await this.getNewCards(limit);
|
|
1085
|
+
const cardIds = newCards.map((c) => c.cardID);
|
|
1086
|
+
const cardEloData = await this.course.getCardEloData(cardIds);
|
|
1087
|
+
const scored = newCards.map((c, i) => {
|
|
1088
|
+
const cardElo = cardEloData[i]?.global?.score ?? 1e3;
|
|
1089
|
+
const distance = Math.abs(cardElo - userGlobalElo);
|
|
1090
|
+
const score = Math.max(0, 1 - distance / 500);
|
|
1091
|
+
return {
|
|
1092
|
+
cardId: c.cardID,
|
|
1093
|
+
courseId: c.courseID,
|
|
1094
|
+
score,
|
|
1095
|
+
provenance: [
|
|
1096
|
+
{
|
|
1097
|
+
strategy: "elo",
|
|
1098
|
+
strategyName: this.strategyName || this.name,
|
|
1099
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-ELO-default",
|
|
1100
|
+
action: "generated",
|
|
1101
|
+
score,
|
|
1102
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userGlobalElo)}), new card`
|
|
1103
|
+
}
|
|
1104
|
+
]
|
|
1105
|
+
};
|
|
1106
|
+
});
|
|
1107
|
+
scored.sort((a, b) => b.score - a.score);
|
|
1108
|
+
return scored.slice(0, limit);
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
}
|
|
1112
|
+
});
|
|
1113
|
+
|
|
1114
|
+
// src/core/navigators/filters/eloDistance.ts
|
|
1115
|
+
var eloDistance_exports = {};
|
|
1116
|
+
__export(eloDistance_exports, {
|
|
1117
|
+
DEFAULT_HALF_LIFE: () => DEFAULT_HALF_LIFE,
|
|
1118
|
+
DEFAULT_MAX_MULTIPLIER: () => DEFAULT_MAX_MULTIPLIER,
|
|
1119
|
+
DEFAULT_MIN_MULTIPLIER: () => DEFAULT_MIN_MULTIPLIER,
|
|
1120
|
+
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1121
|
+
});
|
|
1122
|
+
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
1123
|
+
const normalizedDistance = distance / halfLife;
|
|
1124
|
+
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
1125
|
+
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
1126
|
+
}
|
|
1127
|
+
function createEloDistanceFilter(config) {
|
|
1128
|
+
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
1129
|
+
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
1130
|
+
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
1131
|
+
return {
|
|
1132
|
+
name: "ELO Distance Filter",
|
|
1133
|
+
async transform(cards, context) {
|
|
1134
|
+
const { course, userElo } = context;
|
|
1135
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
1136
|
+
const cardElos = await course.getCardEloData(cardIds);
|
|
1137
|
+
return cards.map((card, i) => {
|
|
1138
|
+
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
1139
|
+
const distance = Math.abs(cardElo - userElo);
|
|
1140
|
+
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
1141
|
+
const newScore = card.score * multiplier;
|
|
1142
|
+
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
1143
|
+
return {
|
|
1144
|
+
...card,
|
|
1145
|
+
score: newScore,
|
|
1146
|
+
provenance: [
|
|
1147
|
+
...card.provenance,
|
|
1148
|
+
{
|
|
1149
|
+
strategy: "eloDistance",
|
|
1150
|
+
strategyName: "ELO Distance Filter",
|
|
1151
|
+
strategyId: "ELO_DISTANCE_FILTER",
|
|
1152
|
+
action,
|
|
1153
|
+
score: newScore,
|
|
1154
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
1155
|
+
}
|
|
1156
|
+
]
|
|
1157
|
+
};
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
|
|
1163
|
+
var init_eloDistance = __esm({
|
|
1164
|
+
"src/core/navigators/filters/eloDistance.ts"() {
|
|
1165
|
+
"use strict";
|
|
1166
|
+
DEFAULT_HALF_LIFE = 200;
|
|
1167
|
+
DEFAULT_MIN_MULTIPLIER = 0.3;
|
|
1168
|
+
DEFAULT_MAX_MULTIPLIER = 1;
|
|
1169
|
+
}
|
|
1170
|
+
});
|
|
1171
|
+
|
|
1172
|
+
// src/core/navigators/filters/userTagPreference.ts
|
|
1173
|
+
var userTagPreference_exports = {};
|
|
1174
|
+
__export(userTagPreference_exports, {
|
|
1175
|
+
default: () => UserTagPreferenceFilter
|
|
1176
|
+
});
|
|
1177
|
+
var UserTagPreferenceFilter;
|
|
1178
|
+
var init_userTagPreference = __esm({
|
|
1179
|
+
"src/core/navigators/filters/userTagPreference.ts"() {
|
|
1180
|
+
"use strict";
|
|
1181
|
+
init_navigators();
|
|
1182
|
+
UserTagPreferenceFilter = class extends ContentNavigator {
|
|
1183
|
+
_strategyData;
|
|
1184
|
+
/** Human-readable name for CardFilter interface */
|
|
1185
|
+
name;
|
|
1186
|
+
constructor(user, course, strategyData) {
|
|
1187
|
+
super(user, course, strategyData);
|
|
1188
|
+
this._strategyData = strategyData;
|
|
1189
|
+
this.name = strategyData.name || "User Tag Preferences";
|
|
1190
|
+
}
|
|
1191
|
+
/**
|
|
1192
|
+
* Compute multiplier for a card based on its tags and user preferences.
|
|
1193
|
+
* Returns the maximum multiplier among all matching tags, or 1.0 if no matches.
|
|
1194
|
+
*/
|
|
1195
|
+
computeMultiplier(cardTags, boostMap) {
|
|
1196
|
+
const multipliers = cardTags.map((tag) => boostMap[tag]).filter((val) => val !== void 0);
|
|
1197
|
+
if (multipliers.length === 0) {
|
|
1198
|
+
return 1;
|
|
1199
|
+
}
|
|
1200
|
+
return Math.max(...multipliers);
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Build human-readable reason for the filter's decision.
|
|
1204
|
+
*/
|
|
1205
|
+
buildReason(cardTags, boostMap, multiplier) {
|
|
1206
|
+
const matchingTags = cardTags.filter((tag) => boostMap[tag] === multiplier);
|
|
1207
|
+
if (multiplier === 0) {
|
|
1208
|
+
return `Excluded by user preference: ${matchingTags.join(", ")} (${multiplier}x)`;
|
|
1209
|
+
}
|
|
1210
|
+
if (multiplier < 1) {
|
|
1211
|
+
return `Penalized by user preference: ${matchingTags.join(", ")} (${multiplier.toFixed(2)}x)`;
|
|
1212
|
+
}
|
|
1213
|
+
if (multiplier > 1) {
|
|
1214
|
+
return `Boosted by user preference: ${matchingTags.join(", ")} (${multiplier.toFixed(2)}x)`;
|
|
1215
|
+
}
|
|
1216
|
+
return "No matching user preferences";
|
|
1217
|
+
}
|
|
1218
|
+
/**
|
|
1219
|
+
* CardFilter.transform implementation.
|
|
1220
|
+
*
|
|
1221
|
+
* Apply user tag preferences:
|
|
1222
|
+
* 1. Read preferences from strategy state
|
|
1223
|
+
* 2. If no preferences, pass through unchanged
|
|
1224
|
+
* 3. For each card:
|
|
1225
|
+
* - Look up tag in boost record
|
|
1226
|
+
* - If tag found: apply multiplier (0 = exclude, 1 = neutral, >1 = boost)
|
|
1227
|
+
* - If multiple tags match: use max multiplier
|
|
1228
|
+
* - Append provenance with clear reason
|
|
1229
|
+
*/
|
|
1230
|
+
async transform(cards, _context) {
|
|
1231
|
+
const prefs = await this.getStrategyState();
|
|
1232
|
+
if (!prefs || Object.keys(prefs.boost).length === 0) {
|
|
1233
|
+
return cards.map((card) => ({
|
|
1234
|
+
...card,
|
|
1235
|
+
provenance: [
|
|
1236
|
+
...card.provenance,
|
|
1237
|
+
{
|
|
1238
|
+
strategy: "userTagPreference",
|
|
1239
|
+
strategyName: this.strategyName || this.name,
|
|
1240
|
+
strategyId: this.strategyId || this._strategyData._id,
|
|
1241
|
+
action: "passed",
|
|
1242
|
+
score: card.score,
|
|
1243
|
+
reason: "No user tag preferences configured"
|
|
1244
|
+
}
|
|
1245
|
+
]
|
|
1246
|
+
}));
|
|
1247
|
+
}
|
|
1248
|
+
const adjusted = await Promise.all(
|
|
1249
|
+
cards.map(async (card) => {
|
|
1250
|
+
const cardTags = card.tags ?? [];
|
|
1251
|
+
const multiplier = this.computeMultiplier(cardTags, prefs.boost);
|
|
1252
|
+
const finalScore = Math.min(1, card.score * multiplier);
|
|
1253
|
+
let action;
|
|
1254
|
+
if (multiplier === 0 || multiplier < 1) {
|
|
1255
|
+
action = "penalized";
|
|
1256
|
+
} else if (multiplier > 1) {
|
|
1257
|
+
action = "boosted";
|
|
1258
|
+
} else {
|
|
1259
|
+
action = "passed";
|
|
1260
|
+
}
|
|
1261
|
+
return {
|
|
1262
|
+
...card,
|
|
1263
|
+
score: finalScore,
|
|
1264
|
+
provenance: [
|
|
1265
|
+
...card.provenance,
|
|
1266
|
+
{
|
|
1267
|
+
strategy: "userTagPreference",
|
|
1268
|
+
strategyName: this.strategyName || this.name,
|
|
1269
|
+
strategyId: this.strategyId || this._strategyData._id,
|
|
1270
|
+
action,
|
|
1271
|
+
score: finalScore,
|
|
1272
|
+
reason: this.buildReason(cardTags, prefs.boost, multiplier)
|
|
1273
|
+
}
|
|
1274
|
+
]
|
|
1275
|
+
};
|
|
1276
|
+
})
|
|
1277
|
+
);
|
|
1278
|
+
return adjusted;
|
|
1279
|
+
}
|
|
1280
|
+
/**
|
|
1281
|
+
* Legacy getWeightedCards - throws as filters should not be used as generators.
|
|
1282
|
+
*/
|
|
1283
|
+
async getWeightedCards(_limit) {
|
|
1284
|
+
throw new Error(
|
|
1285
|
+
"UserTagPreferenceFilter is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1286
|
+
);
|
|
1287
|
+
}
|
|
1288
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1289
|
+
async getNewCards(_n) {
|
|
1290
|
+
return [];
|
|
1291
|
+
}
|
|
1292
|
+
async getPendingReviews() {
|
|
1293
|
+
return [];
|
|
1294
|
+
}
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
});
|
|
1298
|
+
|
|
1299
|
+
// src/core/navigators/filters/index.ts
|
|
1300
|
+
var filters_exports = {};
|
|
1301
|
+
__export(filters_exports, {
|
|
1302
|
+
UserTagPreferenceFilter: () => UserTagPreferenceFilter,
|
|
1303
|
+
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1304
|
+
});
|
|
1305
|
+
var init_filters = __esm({
|
|
1306
|
+
"src/core/navigators/filters/index.ts"() {
|
|
1307
|
+
"use strict";
|
|
1308
|
+
init_eloDistance();
|
|
1309
|
+
init_userTagPreference();
|
|
1310
|
+
}
|
|
1311
|
+
});
|
|
1312
|
+
|
|
1313
|
+
// src/core/navigators/filters/types.ts
|
|
1314
|
+
var types_exports = {};
|
|
1315
|
+
var init_types = __esm({
|
|
1316
|
+
"src/core/navigators/filters/types.ts"() {
|
|
1317
|
+
"use strict";
|
|
1318
|
+
}
|
|
1319
|
+
});
|
|
1320
|
+
|
|
1321
|
+
// src/core/navigators/generators/index.ts
|
|
1322
|
+
var generators_exports = {};
|
|
1323
|
+
var init_generators = __esm({
|
|
1324
|
+
"src/core/navigators/generators/index.ts"() {
|
|
1325
|
+
"use strict";
|
|
1326
|
+
}
|
|
1327
|
+
});
|
|
1328
|
+
|
|
1329
|
+
// src/core/navigators/generators/types.ts
|
|
1330
|
+
var types_exports2 = {};
|
|
1331
|
+
var init_types2 = __esm({
|
|
1332
|
+
"src/core/navigators/generators/types.ts"() {
|
|
1333
|
+
"use strict";
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
|
|
1337
|
+
// src/core/navigators/hardcodedOrder.ts
|
|
1338
|
+
var hardcodedOrder_exports = {};
|
|
1339
|
+
__export(hardcodedOrder_exports, {
|
|
1340
|
+
default: () => HardcodedOrderNavigator
|
|
1341
|
+
});
|
|
1342
|
+
var HardcodedOrderNavigator;
|
|
1343
|
+
var init_hardcodedOrder = __esm({
|
|
1344
|
+
"src/core/navigators/hardcodedOrder.ts"() {
|
|
1345
|
+
"use strict";
|
|
1346
|
+
init_navigators();
|
|
1347
|
+
init_logger();
|
|
1348
|
+
HardcodedOrderNavigator = class extends ContentNavigator {
|
|
1349
|
+
/** Human-readable name for CardGenerator interface */
|
|
1350
|
+
name;
|
|
1351
|
+
orderedCardIds = [];
|
|
1352
|
+
constructor(user, course, strategyData) {
|
|
1353
|
+
super(user, course, strategyData);
|
|
1354
|
+
this.name = strategyData.name || "Hardcoded Order";
|
|
1355
|
+
if (strategyData.serializedData) {
|
|
1356
|
+
try {
|
|
1357
|
+
this.orderedCardIds = JSON.parse(strategyData.serializedData);
|
|
1358
|
+
} catch (e) {
|
|
1359
|
+
logger.error("Failed to parse serializedData for HardcodedOrderNavigator", e);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
async getPendingReviews() {
|
|
1364
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1365
|
+
return reviews.map((r) => {
|
|
1366
|
+
return {
|
|
1367
|
+
...r,
|
|
1368
|
+
contentSourceType: "course",
|
|
1369
|
+
contentSourceID: this.course.getCourseID(),
|
|
1370
|
+
cardID: r.cardId,
|
|
1371
|
+
courseID: r.courseId,
|
|
1372
|
+
reviewID: r._id,
|
|
1373
|
+
status: "review"
|
|
1374
|
+
};
|
|
1375
|
+
});
|
|
1376
|
+
}
|
|
1377
|
+
async getNewCards(limit = 99) {
|
|
1378
|
+
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1379
|
+
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1380
|
+
const cardsToReturn = newCardIds.slice(0, limit);
|
|
1381
|
+
return cardsToReturn.map((cardId) => {
|
|
1382
|
+
return {
|
|
1383
|
+
cardID: cardId,
|
|
1384
|
+
courseID: this.course.getCourseID(),
|
|
1385
|
+
contentSourceType: "course",
|
|
1386
|
+
contentSourceID: this.course.getCourseID(),
|
|
1387
|
+
status: "new"
|
|
1388
|
+
};
|
|
1389
|
+
});
|
|
1390
|
+
}
|
|
1391
|
+
/**
|
|
1392
|
+
* Get cards in hardcoded order with scores based on position.
|
|
1393
|
+
*
|
|
1394
|
+
* Earlier cards in the sequence get higher scores.
|
|
1395
|
+
* Score formula: 1.0 - (position / totalCards) * 0.5
|
|
1396
|
+
* This ensures scores range from 1.0 (first card) to 0.5+ (last card).
|
|
1397
|
+
*
|
|
1398
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1399
|
+
* CardGenerator interface signature (limit, context).
|
|
1400
|
+
*
|
|
1401
|
+
* @param limit - Maximum number of cards to return
|
|
1402
|
+
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1403
|
+
*/
|
|
1404
|
+
async getWeightedCards(limit, _context) {
|
|
1405
|
+
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1406
|
+
const reviews = await this.getPendingReviews();
|
|
1407
|
+
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1408
|
+
const totalCards = newCardIds.length;
|
|
1409
|
+
const scoredNew = newCardIds.slice(0, limit).map((cardId, index) => {
|
|
1410
|
+
const position = index + 1;
|
|
1411
|
+
const score = Math.max(0.5, 1 - index / totalCards * 0.5);
|
|
1412
|
+
return {
|
|
1413
|
+
cardId,
|
|
1414
|
+
courseId: this.course.getCourseID(),
|
|
1415
|
+
score,
|
|
1416
|
+
provenance: [
|
|
1417
|
+
{
|
|
1418
|
+
strategy: "hardcodedOrder",
|
|
1419
|
+
strategyName: this.strategyName || this.name,
|
|
1420
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1421
|
+
action: "generated",
|
|
1422
|
+
score,
|
|
1423
|
+
reason: `Position ${position} of ${totalCards} in fixed sequence, new card`
|
|
1424
|
+
}
|
|
1425
|
+
]
|
|
1426
|
+
};
|
|
1427
|
+
});
|
|
1428
|
+
const scoredReviews = reviews.map((r) => ({
|
|
1429
|
+
cardId: r.cardID,
|
|
1430
|
+
courseId: r.courseID,
|
|
1431
|
+
score: 1,
|
|
1432
|
+
provenance: [
|
|
1433
|
+
{
|
|
1434
|
+
strategy: "hardcodedOrder",
|
|
1435
|
+
strategyName: this.strategyName || this.name,
|
|
1436
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1437
|
+
action: "generated",
|
|
1438
|
+
score: 1,
|
|
1439
|
+
reason: "Scheduled review, highest priority"
|
|
1440
|
+
}
|
|
1441
|
+
]
|
|
1442
|
+
}));
|
|
1443
|
+
const all = [...scoredReviews, ...scoredNew];
|
|
1444
|
+
all.sort((a, b) => b.score - a.score);
|
|
1445
|
+
return all.slice(0, limit);
|
|
1446
|
+
}
|
|
1447
|
+
};
|
|
1448
|
+
}
|
|
1449
|
+
});
|
|
1450
|
+
|
|
1451
|
+
// src/core/navigators/hierarchyDefinition.ts
|
|
1452
|
+
var hierarchyDefinition_exports = {};
|
|
1453
|
+
__export(hierarchyDefinition_exports, {
|
|
1454
|
+
default: () => HierarchyDefinitionNavigator
|
|
1455
|
+
});
|
|
1456
|
+
var import_common7, DEFAULT_MIN_COUNT, HierarchyDefinitionNavigator;
|
|
1457
|
+
var init_hierarchyDefinition = __esm({
|
|
1458
|
+
"src/core/navigators/hierarchyDefinition.ts"() {
|
|
1459
|
+
"use strict";
|
|
1460
|
+
init_navigators();
|
|
1461
|
+
import_common7 = require("@vue-skuilder/common");
|
|
1462
|
+
DEFAULT_MIN_COUNT = 3;
|
|
1463
|
+
HierarchyDefinitionNavigator = class extends ContentNavigator {
|
|
1464
|
+
config;
|
|
1465
|
+
_strategyData;
|
|
1466
|
+
/** Human-readable name for CardFilter interface */
|
|
1467
|
+
name;
|
|
1468
|
+
constructor(user, course, _strategyData) {
|
|
1469
|
+
super(user, course, _strategyData);
|
|
1470
|
+
this._strategyData = _strategyData;
|
|
1471
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1472
|
+
this.name = _strategyData.name || "Hierarchy Definition";
|
|
1473
|
+
}
|
|
1474
|
+
parseConfig(serializedData) {
|
|
1475
|
+
try {
|
|
1476
|
+
const parsed = JSON.parse(serializedData);
|
|
1477
|
+
return {
|
|
1478
|
+
prerequisites: parsed.prerequisites || {}
|
|
1479
|
+
};
|
|
1480
|
+
} catch {
|
|
1481
|
+
return {
|
|
1482
|
+
prerequisites: {}
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
/**
|
|
1487
|
+
* Check if a specific prerequisite is satisfied
|
|
1488
|
+
*/
|
|
1489
|
+
isPrerequisiteMet(prereq, userTagElo, userGlobalElo) {
|
|
1490
|
+
if (!userTagElo) return false;
|
|
1491
|
+
const minCount = prereq.masteryThreshold?.minCount ?? DEFAULT_MIN_COUNT;
|
|
1492
|
+
if (userTagElo.count < minCount) return false;
|
|
1493
|
+
if (prereq.masteryThreshold?.minElo !== void 0) {
|
|
1494
|
+
return userTagElo.score >= prereq.masteryThreshold.minElo;
|
|
1495
|
+
} else {
|
|
1496
|
+
return userTagElo.score >= userGlobalElo;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
/**
|
|
1500
|
+
* Get the set of tags the user has mastered.
|
|
1501
|
+
* A tag is "mastered" if it appears as a prerequisite somewhere and meets its threshold.
|
|
1502
|
+
*/
|
|
1503
|
+
async getMasteredTags(context) {
|
|
1504
|
+
const mastered = /* @__PURE__ */ new Set();
|
|
1505
|
+
try {
|
|
1506
|
+
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1507
|
+
const userElo = (0, import_common7.toCourseElo)(courseReg.elo);
|
|
1508
|
+
for (const prereqs of Object.values(this.config.prerequisites)) {
|
|
1509
|
+
for (const prereq of prereqs) {
|
|
1510
|
+
const tagElo = userElo.tags[prereq.tag];
|
|
1511
|
+
if (this.isPrerequisiteMet(prereq, tagElo, userElo.global.score)) {
|
|
1512
|
+
mastered.add(prereq.tag);
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
} catch {
|
|
1517
|
+
}
|
|
1518
|
+
return mastered;
|
|
1519
|
+
}
|
|
1520
|
+
/**
|
|
1521
|
+
* Get the set of tags that are unlocked (prerequisites met)
|
|
1522
|
+
*/
|
|
1523
|
+
getUnlockedTags(masteredTags) {
|
|
1524
|
+
const unlocked = /* @__PURE__ */ new Set();
|
|
1525
|
+
for (const [tagId, prereqs] of Object.entries(this.config.prerequisites)) {
|
|
1526
|
+
const allPrereqsMet = prereqs.every((prereq) => masteredTags.has(prereq.tag));
|
|
1527
|
+
if (allPrereqsMet) {
|
|
1528
|
+
unlocked.add(tagId);
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
return unlocked;
|
|
1532
|
+
}
|
|
1533
|
+
/**
|
|
1534
|
+
* Check if a tag has prerequisites defined in config
|
|
1535
|
+
*/
|
|
1536
|
+
hasPrerequisites(tagId) {
|
|
1537
|
+
return tagId in this.config.prerequisites;
|
|
1538
|
+
}
|
|
1539
|
+
/**
|
|
1540
|
+
* Check if a card is unlocked and generate reason.
|
|
1541
|
+
*/
|
|
1542
|
+
async checkCardUnlock(card, course, unlockedTags, masteredTags) {
|
|
1543
|
+
try {
|
|
1544
|
+
const cardTags = card.tags ?? [];
|
|
1545
|
+
const lockedTags = cardTags.filter(
|
|
1546
|
+
(tag) => this.hasPrerequisites(tag) && !unlockedTags.has(tag)
|
|
1547
|
+
);
|
|
1548
|
+
if (lockedTags.length === 0) {
|
|
1549
|
+
const tagList = cardTags.length > 0 ? cardTags.join(", ") : "none";
|
|
1550
|
+
return {
|
|
1551
|
+
isUnlocked: true,
|
|
1552
|
+
reason: `Prerequisites met, tags: ${tagList}`
|
|
1553
|
+
};
|
|
1554
|
+
}
|
|
1555
|
+
const missingPrereqs = lockedTags.flatMap((tag) => {
|
|
1556
|
+
const prereqs = this.config.prerequisites[tag] || [];
|
|
1557
|
+
return prereqs.filter((p) => !masteredTags.has(p.tag)).map((p) => p.tag);
|
|
1558
|
+
});
|
|
1559
|
+
return {
|
|
1560
|
+
isUnlocked: false,
|
|
1561
|
+
reason: `Blocked: missing prerequisites ${missingPrereqs.join(", ")} for tags ${lockedTags.join(", ")}`
|
|
1562
|
+
};
|
|
1563
|
+
} catch {
|
|
1564
|
+
return {
|
|
1565
|
+
isUnlocked: true,
|
|
1566
|
+
reason: "Prerequisites check skipped (tag lookup failed)"
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
/**
|
|
1571
|
+
* CardFilter.transform implementation.
|
|
1572
|
+
*
|
|
1573
|
+
* Apply prerequisite gating to cards. Cards with locked tags receive score: 0.
|
|
1574
|
+
*/
|
|
1575
|
+
async transform(cards, context) {
|
|
1576
|
+
const masteredTags = await this.getMasteredTags(context);
|
|
1577
|
+
const unlockedTags = this.getUnlockedTags(masteredTags);
|
|
1578
|
+
const gated = [];
|
|
1579
|
+
for (const card of cards) {
|
|
1580
|
+
const { isUnlocked, reason } = await this.checkCardUnlock(
|
|
1581
|
+
card,
|
|
1582
|
+
context.course,
|
|
1583
|
+
unlockedTags,
|
|
1584
|
+
masteredTags
|
|
1585
|
+
);
|
|
1586
|
+
const finalScore = isUnlocked ? card.score : 0;
|
|
1587
|
+
const action = isUnlocked ? "passed" : "penalized";
|
|
1588
|
+
gated.push({
|
|
1589
|
+
...card,
|
|
1590
|
+
score: finalScore,
|
|
1591
|
+
provenance: [
|
|
1592
|
+
...card.provenance,
|
|
1593
|
+
{
|
|
1594
|
+
strategy: "hierarchyDefinition",
|
|
1595
|
+
strategyName: this.strategyName || this.name,
|
|
1596
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hierarchy",
|
|
1597
|
+
action,
|
|
1598
|
+
score: finalScore,
|
|
1599
|
+
reason
|
|
1600
|
+
}
|
|
1601
|
+
]
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
return gated;
|
|
1605
|
+
}
|
|
1606
|
+
/**
|
|
1607
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1608
|
+
*
|
|
1609
|
+
* Use transform() via Pipeline instead.
|
|
1610
|
+
*/
|
|
1611
|
+
async getWeightedCards(_limit) {
|
|
1612
|
+
throw new Error(
|
|
1613
|
+
"HierarchyDefinitionNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1614
|
+
);
|
|
1615
|
+
}
|
|
1616
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1617
|
+
async getNewCards(_n) {
|
|
1618
|
+
return [];
|
|
1619
|
+
}
|
|
1620
|
+
async getPendingReviews() {
|
|
1621
|
+
return [];
|
|
1622
|
+
}
|
|
1623
|
+
};
|
|
1624
|
+
}
|
|
1625
|
+
});
|
|
1626
|
+
|
|
1627
|
+
// src/core/navigators/inferredPreference.ts
|
|
1628
|
+
var inferredPreference_exports = {};
|
|
1629
|
+
__export(inferredPreference_exports, {
|
|
1630
|
+
INFERRED_PREFERENCE_NAVIGATOR_STUB: () => INFERRED_PREFERENCE_NAVIGATOR_STUB
|
|
1631
|
+
});
|
|
1632
|
+
var INFERRED_PREFERENCE_NAVIGATOR_STUB;
|
|
1633
|
+
var init_inferredPreference = __esm({
|
|
1634
|
+
"src/core/navigators/inferredPreference.ts"() {
|
|
1635
|
+
"use strict";
|
|
1636
|
+
INFERRED_PREFERENCE_NAVIGATOR_STUB = true;
|
|
1637
|
+
}
|
|
1638
|
+
});
|
|
1639
|
+
|
|
1640
|
+
// src/core/navigators/interferenceMitigator.ts
|
|
1641
|
+
var interferenceMitigator_exports = {};
|
|
1642
|
+
__export(interferenceMitigator_exports, {
|
|
1643
|
+
default: () => InterferenceMitigatorNavigator
|
|
1644
|
+
});
|
|
1645
|
+
var import_common8, DEFAULT_MIN_COUNT2, DEFAULT_MIN_ELAPSED_DAYS, DEFAULT_INTERFERENCE_DECAY, InterferenceMitigatorNavigator;
|
|
1646
|
+
var init_interferenceMitigator = __esm({
|
|
1647
|
+
"src/core/navigators/interferenceMitigator.ts"() {
|
|
1648
|
+
"use strict";
|
|
1649
|
+
init_navigators();
|
|
1650
|
+
import_common8 = require("@vue-skuilder/common");
|
|
1651
|
+
DEFAULT_MIN_COUNT2 = 10;
|
|
1652
|
+
DEFAULT_MIN_ELAPSED_DAYS = 3;
|
|
1653
|
+
DEFAULT_INTERFERENCE_DECAY = 0.8;
|
|
1654
|
+
InterferenceMitigatorNavigator = class extends ContentNavigator {
|
|
1655
|
+
config;
|
|
1656
|
+
_strategyData;
|
|
1657
|
+
/** Human-readable name for CardFilter interface */
|
|
1658
|
+
name;
|
|
1659
|
+
/** Precomputed map: tag -> set of { partner, decay } it interferes with */
|
|
1660
|
+
interferenceMap;
|
|
1661
|
+
constructor(user, course, _strategyData) {
|
|
1662
|
+
super(user, course, _strategyData);
|
|
1663
|
+
this._strategyData = _strategyData;
|
|
1664
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1665
|
+
this.interferenceMap = this.buildInterferenceMap();
|
|
1666
|
+
this.name = _strategyData.name || "Interference Mitigator";
|
|
1667
|
+
}
|
|
1668
|
+
parseConfig(serializedData) {
|
|
1669
|
+
try {
|
|
1670
|
+
const parsed = JSON.parse(serializedData);
|
|
1671
|
+
let sets = parsed.interferenceSets || [];
|
|
1672
|
+
if (sets.length > 0 && Array.isArray(sets[0])) {
|
|
1673
|
+
sets = sets.map((tags) => ({ tags }));
|
|
1674
|
+
}
|
|
1675
|
+
return {
|
|
1676
|
+
interferenceSets: sets,
|
|
1677
|
+
maturityThreshold: {
|
|
1678
|
+
minCount: parsed.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2,
|
|
1679
|
+
minElo: parsed.maturityThreshold?.minElo,
|
|
1680
|
+
minElapsedDays: parsed.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS
|
|
1681
|
+
},
|
|
1682
|
+
defaultDecay: parsed.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY
|
|
1683
|
+
};
|
|
1684
|
+
} catch {
|
|
1685
|
+
return {
|
|
1686
|
+
interferenceSets: [],
|
|
1687
|
+
maturityThreshold: {
|
|
1688
|
+
minCount: DEFAULT_MIN_COUNT2,
|
|
1689
|
+
minElapsedDays: DEFAULT_MIN_ELAPSED_DAYS
|
|
1690
|
+
},
|
|
1691
|
+
defaultDecay: DEFAULT_INTERFERENCE_DECAY
|
|
1692
|
+
};
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
/**
|
|
1696
|
+
* Build a map from each tag to its interference partners with decay coefficients.
|
|
1697
|
+
* If tags A, B, C are in an interference group with decay 0.8, then:
|
|
1698
|
+
* - A interferes with B (decay 0.8) and C (decay 0.8)
|
|
1699
|
+
* - B interferes with A (decay 0.8) and C (decay 0.8)
|
|
1700
|
+
* - etc.
|
|
1701
|
+
*/
|
|
1702
|
+
buildInterferenceMap() {
|
|
1703
|
+
const map = /* @__PURE__ */ new Map();
|
|
1704
|
+
for (const group of this.config.interferenceSets) {
|
|
1705
|
+
const decay = group.decay ?? this.config.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY;
|
|
1706
|
+
for (const tag of group.tags) {
|
|
1707
|
+
if (!map.has(tag)) {
|
|
1708
|
+
map.set(tag, []);
|
|
1709
|
+
}
|
|
1710
|
+
const partners = map.get(tag);
|
|
1711
|
+
for (const other of group.tags) {
|
|
1712
|
+
if (other !== tag) {
|
|
1713
|
+
const existing = partners.find((p) => p.partner === other);
|
|
1714
|
+
if (existing) {
|
|
1715
|
+
existing.decay = Math.max(existing.decay, decay);
|
|
1716
|
+
} else {
|
|
1717
|
+
partners.push({ partner: other, decay });
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
}
|
|
1723
|
+
return map;
|
|
1724
|
+
}
|
|
1725
|
+
/**
|
|
1726
|
+
* Get the set of tags that are currently immature for this user.
|
|
1727
|
+
* A tag is immature if the user has interacted with it but hasn't
|
|
1728
|
+
* reached the maturity threshold.
|
|
1729
|
+
*/
|
|
1730
|
+
async getImmatureTags(context) {
|
|
1731
|
+
const immature = /* @__PURE__ */ new Set();
|
|
1732
|
+
try {
|
|
1733
|
+
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1734
|
+
const userElo = (0, import_common8.toCourseElo)(courseReg.elo);
|
|
1735
|
+
const minCount = this.config.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2;
|
|
1736
|
+
const minElo = this.config.maturityThreshold?.minElo;
|
|
1737
|
+
const minElapsedDays = this.config.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS;
|
|
1738
|
+
const minCountForElapsed = minElapsedDays * 2;
|
|
1739
|
+
for (const [tagId, tagElo] of Object.entries(userElo.tags)) {
|
|
1740
|
+
if (tagElo.count === 0) continue;
|
|
1741
|
+
const belowCount = tagElo.count < minCount;
|
|
1742
|
+
const belowElo = minElo !== void 0 && tagElo.score < minElo;
|
|
1743
|
+
const belowElapsed = tagElo.count < minCountForElapsed;
|
|
1744
|
+
if (belowCount || belowElo || belowElapsed) {
|
|
1745
|
+
immature.add(tagId);
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
} catch {
|
|
1749
|
+
}
|
|
1750
|
+
return immature;
|
|
1751
|
+
}
|
|
1752
|
+
/**
|
|
1753
|
+
* Get all tags that interfere with any immature tag, along with their decay coefficients.
|
|
1754
|
+
* These are the tags we want to avoid introducing.
|
|
1755
|
+
*/
|
|
1756
|
+
getTagsToAvoid(immatureTags) {
|
|
1757
|
+
const avoid = /* @__PURE__ */ new Map();
|
|
1758
|
+
for (const immatureTag of immatureTags) {
|
|
1759
|
+
const partners = this.interferenceMap.get(immatureTag);
|
|
1760
|
+
if (partners) {
|
|
1761
|
+
for (const { partner, decay } of partners) {
|
|
1762
|
+
if (!immatureTags.has(partner)) {
|
|
1763
|
+
const existing = avoid.get(partner) ?? 0;
|
|
1764
|
+
avoid.set(partner, Math.max(existing, decay));
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
return avoid;
|
|
1770
|
+
}
|
|
1771
|
+
/**
|
|
1772
|
+
* Compute interference score reduction for a card.
|
|
1773
|
+
* Returns: { multiplier, interfering tags, reason }
|
|
1774
|
+
*/
|
|
1775
|
+
computeInterferenceEffect(cardTags, tagsToAvoid, immatureTags) {
|
|
1776
|
+
if (tagsToAvoid.size === 0) {
|
|
1777
|
+
return {
|
|
1778
|
+
multiplier: 1,
|
|
1779
|
+
interferingTags: [],
|
|
1780
|
+
reason: "No interference detected"
|
|
1781
|
+
};
|
|
1782
|
+
}
|
|
1783
|
+
let multiplier = 1;
|
|
1784
|
+
const interferingTags = [];
|
|
1785
|
+
for (const tag of cardTags) {
|
|
1786
|
+
const decay = tagsToAvoid.get(tag);
|
|
1787
|
+
if (decay !== void 0) {
|
|
1788
|
+
interferingTags.push(tag);
|
|
1789
|
+
multiplier *= 1 - decay;
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
if (interferingTags.length === 0) {
|
|
1793
|
+
return {
|
|
1794
|
+
multiplier: 1,
|
|
1795
|
+
interferingTags: [],
|
|
1796
|
+
reason: "No interference detected"
|
|
1797
|
+
};
|
|
1798
|
+
}
|
|
1799
|
+
const causingTags = /* @__PURE__ */ new Set();
|
|
1800
|
+
for (const tag of interferingTags) {
|
|
1801
|
+
for (const immatureTag of immatureTags) {
|
|
1802
|
+
const partners = this.interferenceMap.get(immatureTag);
|
|
1803
|
+
if (partners?.some((p) => p.partner === tag)) {
|
|
1804
|
+
causingTags.add(immatureTag);
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
const reason = `Interferes with immature tags ${Array.from(causingTags).join(", ")} (tags: ${interferingTags.join(", ")}, multiplier: ${multiplier.toFixed(2)})`;
|
|
1809
|
+
return { multiplier, interferingTags, reason };
|
|
1810
|
+
}
|
|
1811
|
+
/**
|
|
1812
|
+
* CardFilter.transform implementation.
|
|
1813
|
+
*
|
|
1814
|
+
* Apply interference-aware scoring. Cards with tags that interfere with
|
|
1815
|
+
* immature learnings get reduced scores.
|
|
1816
|
+
*/
|
|
1817
|
+
async transform(cards, context) {
|
|
1818
|
+
const immatureTags = await this.getImmatureTags(context);
|
|
1819
|
+
const tagsToAvoid = this.getTagsToAvoid(immatureTags);
|
|
1820
|
+
const adjusted = [];
|
|
1821
|
+
for (const card of cards) {
|
|
1822
|
+
const cardTags = card.tags ?? [];
|
|
1823
|
+
const { multiplier, reason } = this.computeInterferenceEffect(
|
|
1824
|
+
cardTags,
|
|
1825
|
+
tagsToAvoid,
|
|
1826
|
+
immatureTags
|
|
1827
|
+
);
|
|
1828
|
+
const finalScore = card.score * multiplier;
|
|
1829
|
+
const action = multiplier < 1 ? "penalized" : multiplier > 1 ? "boosted" : "passed";
|
|
1830
|
+
adjusted.push({
|
|
1831
|
+
...card,
|
|
1832
|
+
score: finalScore,
|
|
1833
|
+
provenance: [
|
|
1834
|
+
...card.provenance,
|
|
1835
|
+
{
|
|
1836
|
+
strategy: "interferenceMitigator",
|
|
1837
|
+
strategyName: this.strategyName || this.name,
|
|
1838
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-interference",
|
|
1839
|
+
action,
|
|
1840
|
+
score: finalScore,
|
|
1841
|
+
reason
|
|
1842
|
+
}
|
|
1843
|
+
]
|
|
1844
|
+
});
|
|
1845
|
+
}
|
|
1846
|
+
return adjusted;
|
|
1847
|
+
}
|
|
1848
|
+
/**
|
|
1849
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1850
|
+
*
|
|
1851
|
+
* Use transform() via Pipeline instead.
|
|
1852
|
+
*/
|
|
1853
|
+
async getWeightedCards(_limit) {
|
|
1854
|
+
throw new Error(
|
|
1855
|
+
"InterferenceMitigatorNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1856
|
+
);
|
|
1857
|
+
}
|
|
1858
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1859
|
+
async getNewCards(_n) {
|
|
1860
|
+
return [];
|
|
1861
|
+
}
|
|
1862
|
+
async getPendingReviews() {
|
|
1863
|
+
return [];
|
|
1864
|
+
}
|
|
1865
|
+
};
|
|
1866
|
+
}
|
|
1867
|
+
});
|
|
1868
|
+
|
|
1869
|
+
// src/core/navigators/relativePriority.ts
|
|
1870
|
+
var relativePriority_exports = {};
|
|
1871
|
+
__export(relativePriority_exports, {
|
|
1872
|
+
default: () => RelativePriorityNavigator
|
|
1873
|
+
});
|
|
1874
|
+
var DEFAULT_PRIORITY, DEFAULT_PRIORITY_INFLUENCE, DEFAULT_COMBINE_MODE, RelativePriorityNavigator;
|
|
1875
|
+
var init_relativePriority = __esm({
|
|
1876
|
+
"src/core/navigators/relativePriority.ts"() {
|
|
510
1877
|
"use strict";
|
|
511
1878
|
init_navigators();
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
});
|
|
530
|
-
ratedReviews.sort((a, b) => {
|
|
531
|
-
return a.global.score - b.global.score;
|
|
532
|
-
});
|
|
533
|
-
return ratedReviews.map((r) => {
|
|
1879
|
+
DEFAULT_PRIORITY = 0.5;
|
|
1880
|
+
DEFAULT_PRIORITY_INFLUENCE = 0.5;
|
|
1881
|
+
DEFAULT_COMBINE_MODE = "max";
|
|
1882
|
+
RelativePriorityNavigator = class extends ContentNavigator {
|
|
1883
|
+
config;
|
|
1884
|
+
_strategyData;
|
|
1885
|
+
/** Human-readable name for CardFilter interface */
|
|
1886
|
+
name;
|
|
1887
|
+
constructor(user, course, _strategyData) {
|
|
1888
|
+
super(user, course, _strategyData);
|
|
1889
|
+
this._strategyData = _strategyData;
|
|
1890
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1891
|
+
this.name = _strategyData.name || "Relative Priority";
|
|
1892
|
+
}
|
|
1893
|
+
parseConfig(serializedData) {
|
|
1894
|
+
try {
|
|
1895
|
+
const parsed = JSON.parse(serializedData);
|
|
534
1896
|
return {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
courseID: r.courseId,
|
|
540
|
-
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
541
|
-
reviewID: r._id,
|
|
542
|
-
status: "review"
|
|
1897
|
+
tagPriorities: parsed.tagPriorities || {},
|
|
1898
|
+
defaultPriority: parsed.defaultPriority ?? DEFAULT_PRIORITY,
|
|
1899
|
+
combineMode: parsed.combineMode ?? DEFAULT_COMBINE_MODE,
|
|
1900
|
+
priorityInfluence: parsed.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE
|
|
543
1901
|
};
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
async getNewCards(limit = 99) {
|
|
547
|
-
const activeCards = await this.user.getActiveCards();
|
|
548
|
-
return (await this.course.getCardsCenteredAtELO(
|
|
549
|
-
{ limit, elo: "user" },
|
|
550
|
-
(c) => {
|
|
551
|
-
if (activeCards.some((ac) => c.cardID === ac.cardID)) {
|
|
552
|
-
return false;
|
|
553
|
-
} else {
|
|
554
|
-
return true;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
)).map((c) => {
|
|
1902
|
+
} catch {
|
|
558
1903
|
return {
|
|
559
|
-
|
|
560
|
-
|
|
1904
|
+
tagPriorities: {},
|
|
1905
|
+
defaultPriority: DEFAULT_PRIORITY,
|
|
1906
|
+
combineMode: DEFAULT_COMBINE_MODE,
|
|
1907
|
+
priorityInfluence: DEFAULT_PRIORITY_INFLUENCE
|
|
561
1908
|
};
|
|
562
|
-
}
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
/**
|
|
1912
|
+
* Look up the priority for a tag.
|
|
1913
|
+
*/
|
|
1914
|
+
getTagPriority(tagId) {
|
|
1915
|
+
return this.config.tagPriorities[tagId] ?? this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1916
|
+
}
|
|
1917
|
+
/**
|
|
1918
|
+
* Compute combined priority for a card based on its tags.
|
|
1919
|
+
*/
|
|
1920
|
+
computeCardPriority(cardTags) {
|
|
1921
|
+
if (cardTags.length === 0) {
|
|
1922
|
+
return this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1923
|
+
}
|
|
1924
|
+
const priorities = cardTags.map((tag) => this.getTagPriority(tag));
|
|
1925
|
+
switch (this.config.combineMode) {
|
|
1926
|
+
case "max":
|
|
1927
|
+
return Math.max(...priorities);
|
|
1928
|
+
case "min":
|
|
1929
|
+
return Math.min(...priorities);
|
|
1930
|
+
case "average":
|
|
1931
|
+
return priorities.reduce((sum, p) => sum + p, 0) / priorities.length;
|
|
1932
|
+
default:
|
|
1933
|
+
return Math.max(...priorities);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
/**
|
|
1937
|
+
* Compute boost factor based on priority.
|
|
1938
|
+
*
|
|
1939
|
+
* The formula: 1 + (priority - 0.5) * priorityInfluence
|
|
1940
|
+
*
|
|
1941
|
+
* This creates a multiplier centered around 1.0:
|
|
1942
|
+
* - Priority 1.0 with influence 0.5 → 1.25 (25% boost)
|
|
1943
|
+
* - Priority 0.5 with any influence → 1.00 (neutral)
|
|
1944
|
+
* - Priority 0.0 with influence 0.5 → 0.75 (25% reduction)
|
|
1945
|
+
*/
|
|
1946
|
+
computeBoostFactor(priority) {
|
|
1947
|
+
const influence = this.config.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE;
|
|
1948
|
+
return 1 + (priority - 0.5) * influence;
|
|
1949
|
+
}
|
|
1950
|
+
/**
|
|
1951
|
+
* Build human-readable reason for priority adjustment.
|
|
1952
|
+
*/
|
|
1953
|
+
buildPriorityReason(cardTags, priority, boostFactor, finalScore) {
|
|
1954
|
+
if (cardTags.length === 0) {
|
|
1955
|
+
return `No tags, neutral priority (${priority.toFixed(2)})`;
|
|
1956
|
+
}
|
|
1957
|
+
const tagList = cardTags.slice(0, 3).join(", ");
|
|
1958
|
+
const more = cardTags.length > 3 ? ` (+${cardTags.length - 3} more)` : "";
|
|
1959
|
+
if (boostFactor === 1) {
|
|
1960
|
+
return `Neutral priority (${priority.toFixed(2)}) for tags: ${tagList}${more}`;
|
|
1961
|
+
} else if (boostFactor > 1) {
|
|
1962
|
+
return `High-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 boost ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1963
|
+
} else {
|
|
1964
|
+
return `Low-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 reduce ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
/**
|
|
1968
|
+
* CardFilter.transform implementation.
|
|
1969
|
+
*
|
|
1970
|
+
* Apply priority-adjusted scoring. Cards with high-priority tags get boosted,
|
|
1971
|
+
* cards with low-priority tags get reduced scores.
|
|
1972
|
+
*/
|
|
1973
|
+
async transform(cards, _context) {
|
|
1974
|
+
const adjusted = await Promise.all(
|
|
1975
|
+
cards.map(async (card) => {
|
|
1976
|
+
const cardTags = card.tags ?? [];
|
|
1977
|
+
const priority = this.computeCardPriority(cardTags);
|
|
1978
|
+
const boostFactor = this.computeBoostFactor(priority);
|
|
1979
|
+
const finalScore = Math.max(0, Math.min(1, card.score * boostFactor));
|
|
1980
|
+
const action = boostFactor > 1 ? "boosted" : boostFactor < 1 ? "penalized" : "passed";
|
|
1981
|
+
const reason = this.buildPriorityReason(cardTags, priority, boostFactor, finalScore);
|
|
1982
|
+
return {
|
|
1983
|
+
...card,
|
|
1984
|
+
score: finalScore,
|
|
1985
|
+
provenance: [
|
|
1986
|
+
...card.provenance,
|
|
1987
|
+
{
|
|
1988
|
+
strategy: "relativePriority",
|
|
1989
|
+
strategyName: this.strategyName || this.name,
|
|
1990
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-priority",
|
|
1991
|
+
action,
|
|
1992
|
+
score: finalScore,
|
|
1993
|
+
reason
|
|
1994
|
+
}
|
|
1995
|
+
]
|
|
1996
|
+
};
|
|
1997
|
+
})
|
|
1998
|
+
);
|
|
1999
|
+
return adjusted;
|
|
2000
|
+
}
|
|
2001
|
+
/**
|
|
2002
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
2003
|
+
*
|
|
2004
|
+
* Use transform() via Pipeline instead.
|
|
2005
|
+
*/
|
|
2006
|
+
async getWeightedCards(_limit) {
|
|
2007
|
+
throw new Error(
|
|
2008
|
+
"RelativePriorityNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
2009
|
+
);
|
|
2010
|
+
}
|
|
2011
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
2012
|
+
async getNewCards(_n) {
|
|
2013
|
+
return [];
|
|
2014
|
+
}
|
|
2015
|
+
async getPendingReviews() {
|
|
2016
|
+
return [];
|
|
563
2017
|
}
|
|
564
2018
|
};
|
|
565
2019
|
}
|
|
566
2020
|
});
|
|
567
2021
|
|
|
568
|
-
// src/core/navigators/
|
|
569
|
-
var
|
|
570
|
-
__export(
|
|
571
|
-
default: () =>
|
|
2022
|
+
// src/core/navigators/srs.ts
|
|
2023
|
+
var srs_exports = {};
|
|
2024
|
+
__export(srs_exports, {
|
|
2025
|
+
default: () => SRSNavigator
|
|
572
2026
|
});
|
|
573
|
-
var
|
|
574
|
-
var
|
|
575
|
-
"src/core/navigators/
|
|
2027
|
+
var import_moment3, SRSNavigator;
|
|
2028
|
+
var init_srs = __esm({
|
|
2029
|
+
"src/core/navigators/srs.ts"() {
|
|
576
2030
|
"use strict";
|
|
2031
|
+
import_moment3 = __toESM(require("moment"), 1);
|
|
577
2032
|
init_navigators();
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
user;
|
|
582
|
-
course;
|
|
2033
|
+
SRSNavigator = class extends ContentNavigator {
|
|
2034
|
+
/** Human-readable name for CardGenerator interface */
|
|
2035
|
+
name;
|
|
583
2036
|
constructor(user, course, strategyData) {
|
|
584
|
-
super();
|
|
585
|
-
this.
|
|
586
|
-
this.course = course;
|
|
587
|
-
if (strategyData.serializedData) {
|
|
588
|
-
try {
|
|
589
|
-
this.orderedCardIds = JSON.parse(strategyData.serializedData);
|
|
590
|
-
} catch (e) {
|
|
591
|
-
logger.error("Failed to parse serializedData for HardcodedOrderNavigator", e);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
2037
|
+
super(user, course, strategyData);
|
|
2038
|
+
this.name = strategyData?.name || "SRS";
|
|
594
2039
|
}
|
|
595
|
-
|
|
2040
|
+
/**
|
|
2041
|
+
* Get review cards scored by urgency.
|
|
2042
|
+
*
|
|
2043
|
+
* Score formula combines:
|
|
2044
|
+
* - Relative overdueness: hoursOverdue / intervalHours
|
|
2045
|
+
* - Interval recency: exponential decay favoring shorter intervals
|
|
2046
|
+
*
|
|
2047
|
+
* Cards not yet due are excluded (not scored as 0).
|
|
2048
|
+
*
|
|
2049
|
+
* This method supports both the legacy signature (limit only) and the
|
|
2050
|
+
* CardGenerator interface signature (limit, context).
|
|
2051
|
+
*
|
|
2052
|
+
* @param limit - Maximum number of cards to return
|
|
2053
|
+
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
2054
|
+
*/
|
|
2055
|
+
async getWeightedCards(limit, _context) {
|
|
2056
|
+
if (!this.user || !this.course) {
|
|
2057
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
2058
|
+
}
|
|
596
2059
|
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
597
|
-
|
|
2060
|
+
const now = import_moment3.default.utc();
|
|
2061
|
+
const dueReviews = reviews.filter((r) => now.isAfter(import_moment3.default.utc(r.reviewTime)));
|
|
2062
|
+
const scored = dueReviews.map((review) => {
|
|
2063
|
+
const { score, reason } = this.computeUrgencyScore(review, now);
|
|
598
2064
|
return {
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
2065
|
+
cardId: review.cardId,
|
|
2066
|
+
courseId: review.courseId,
|
|
2067
|
+
score,
|
|
2068
|
+
provenance: [
|
|
2069
|
+
{
|
|
2070
|
+
strategy: "srs",
|
|
2071
|
+
strategyName: this.strategyName || this.name,
|
|
2072
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-SRS-default",
|
|
2073
|
+
action: "generated",
|
|
2074
|
+
score,
|
|
2075
|
+
reason
|
|
2076
|
+
}
|
|
2077
|
+
]
|
|
606
2078
|
};
|
|
607
2079
|
});
|
|
2080
|
+
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
608
2081
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
2082
|
+
/**
|
|
2083
|
+
* Compute urgency score for a review card.
|
|
2084
|
+
*
|
|
2085
|
+
* Two factors:
|
|
2086
|
+
* 1. Relative overdueness = hoursOverdue / intervalHours
|
|
2087
|
+
* - 2 days overdue on 3-day interval = 0.67 (urgent)
|
|
2088
|
+
* - 2 days overdue on 180-day interval = 0.01 (not urgent)
|
|
2089
|
+
*
|
|
2090
|
+
* 2. Interval recency factor = 0.3 + 0.7 * exp(-intervalHours / 720)
|
|
2091
|
+
* - 24h interval → ~1.0 (very recent learning)
|
|
2092
|
+
* - 30 days (720h) → ~0.56
|
|
2093
|
+
* - 180 days → ~0.30
|
|
2094
|
+
*
|
|
2095
|
+
* Combined: base 0.5 + weighted average of factors * 0.45
|
|
2096
|
+
* Result range: approximately 0.5 to 0.95
|
|
2097
|
+
*/
|
|
2098
|
+
computeUrgencyScore(review, now) {
|
|
2099
|
+
const scheduledAt = import_moment3.default.utc(review.scheduledAt);
|
|
2100
|
+
const due = import_moment3.default.utc(review.reviewTime);
|
|
2101
|
+
const intervalHours = Math.max(1, due.diff(scheduledAt, "hours"));
|
|
2102
|
+
const hoursOverdue = now.diff(due, "hours");
|
|
2103
|
+
const relativeOverdue = hoursOverdue / intervalHours;
|
|
2104
|
+
const recencyFactor = 0.3 + 0.7 * Math.exp(-intervalHours / 720);
|
|
2105
|
+
const overdueContribution = Math.min(1, Math.max(0, relativeOverdue));
|
|
2106
|
+
const urgency = overdueContribution * 0.5 + recencyFactor * 0.5;
|
|
2107
|
+
const score = Math.min(0.95, 0.5 + urgency * 0.45);
|
|
2108
|
+
const reason = `${Math.round(hoursOverdue)}h overdue (interval: ${Math.round(intervalHours)}h, relative: ${relativeOverdue.toFixed(2)}), recency: ${recencyFactor.toFixed(2)}, review`;
|
|
2109
|
+
return { score, reason };
|
|
2110
|
+
}
|
|
2111
|
+
/**
|
|
2112
|
+
* Get pending reviews in legacy format.
|
|
2113
|
+
*
|
|
2114
|
+
* Returns all pending reviews for the course, enriched with session item fields.
|
|
2115
|
+
*/
|
|
2116
|
+
async getPendingReviews() {
|
|
2117
|
+
if (!this.user || !this.course) {
|
|
2118
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
2119
|
+
}
|
|
2120
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
2121
|
+
return reviews.map((r) => ({
|
|
2122
|
+
...r,
|
|
2123
|
+
contentSourceType: "course",
|
|
2124
|
+
contentSourceID: this.course.getCourseID(),
|
|
2125
|
+
cardID: r.cardId,
|
|
2126
|
+
courseID: r.courseId,
|
|
2127
|
+
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
2128
|
+
reviewID: r._id,
|
|
2129
|
+
status: "review"
|
|
2130
|
+
}));
|
|
2131
|
+
}
|
|
2132
|
+
/**
|
|
2133
|
+
* SRS does not generate new cards.
|
|
2134
|
+
* Use ELONavigator or another generator for new cards.
|
|
2135
|
+
*/
|
|
2136
|
+
async getNewCards(_n) {
|
|
2137
|
+
return [];
|
|
624
2138
|
}
|
|
625
2139
|
};
|
|
626
2140
|
}
|
|
627
2141
|
});
|
|
628
2142
|
|
|
2143
|
+
// src/core/navigators/userGoal.ts
|
|
2144
|
+
var userGoal_exports = {};
|
|
2145
|
+
__export(userGoal_exports, {
|
|
2146
|
+
USER_GOAL_NAVIGATOR_STUB: () => USER_GOAL_NAVIGATOR_STUB
|
|
2147
|
+
});
|
|
2148
|
+
var USER_GOAL_NAVIGATOR_STUB;
|
|
2149
|
+
var init_userGoal = __esm({
|
|
2150
|
+
"src/core/navigators/userGoal.ts"() {
|
|
2151
|
+
"use strict";
|
|
2152
|
+
USER_GOAL_NAVIGATOR_STUB = true;
|
|
2153
|
+
}
|
|
2154
|
+
});
|
|
2155
|
+
|
|
629
2156
|
// import("./**/*") in src/core/navigators/index.ts
|
|
630
2157
|
var globImport;
|
|
631
2158
|
var init_ = __esm({
|
|
632
2159
|
'import("./**/*") in src/core/navigators/index.ts'() {
|
|
633
2160
|
globImport = __glob({
|
|
2161
|
+
"./CompositeGenerator.ts": () => Promise.resolve().then(() => (init_CompositeGenerator(), CompositeGenerator_exports)),
|
|
2162
|
+
"./Pipeline.ts": () => Promise.resolve().then(() => (init_Pipeline(), Pipeline_exports)),
|
|
2163
|
+
"./PipelineAssembler.ts": () => Promise.resolve().then(() => (init_PipelineAssembler(), PipelineAssembler_exports)),
|
|
634
2164
|
"./elo.ts": () => Promise.resolve().then(() => (init_elo(), elo_exports)),
|
|
2165
|
+
"./filters/eloDistance.ts": () => Promise.resolve().then(() => (init_eloDistance(), eloDistance_exports)),
|
|
2166
|
+
"./filters/index.ts": () => Promise.resolve().then(() => (init_filters(), filters_exports)),
|
|
2167
|
+
"./filters/types.ts": () => Promise.resolve().then(() => (init_types(), types_exports)),
|
|
2168
|
+
"./filters/userTagPreference.ts": () => Promise.resolve().then(() => (init_userTagPreference(), userTagPreference_exports)),
|
|
2169
|
+
"./generators/index.ts": () => Promise.resolve().then(() => (init_generators(), generators_exports)),
|
|
2170
|
+
"./generators/types.ts": () => Promise.resolve().then(() => (init_types2(), types_exports2)),
|
|
635
2171
|
"./hardcodedOrder.ts": () => Promise.resolve().then(() => (init_hardcodedOrder(), hardcodedOrder_exports)),
|
|
636
|
-
"./
|
|
2172
|
+
"./hierarchyDefinition.ts": () => Promise.resolve().then(() => (init_hierarchyDefinition(), hierarchyDefinition_exports)),
|
|
2173
|
+
"./index.ts": () => Promise.resolve().then(() => (init_navigators(), navigators_exports)),
|
|
2174
|
+
"./inferredPreference.ts": () => Promise.resolve().then(() => (init_inferredPreference(), inferredPreference_exports)),
|
|
2175
|
+
"./interferenceMitigator.ts": () => Promise.resolve().then(() => (init_interferenceMitigator(), interferenceMitigator_exports)),
|
|
2176
|
+
"./relativePriority.ts": () => Promise.resolve().then(() => (init_relativePriority(), relativePriority_exports)),
|
|
2177
|
+
"./srs.ts": () => Promise.resolve().then(() => (init_srs(), srs_exports)),
|
|
2178
|
+
"./userGoal.ts": () => Promise.resolve().then(() => (init_userGoal(), userGoal_exports))
|
|
637
2179
|
});
|
|
638
2180
|
}
|
|
639
2181
|
});
|
|
@@ -642,9 +2184,34 @@ var init_ = __esm({
|
|
|
642
2184
|
var navigators_exports = {};
|
|
643
2185
|
__export(navigators_exports, {
|
|
644
2186
|
ContentNavigator: () => ContentNavigator,
|
|
645
|
-
|
|
2187
|
+
NavigatorRole: () => NavigatorRole,
|
|
2188
|
+
NavigatorRoles: () => NavigatorRoles,
|
|
2189
|
+
Navigators: () => Navigators,
|
|
2190
|
+
getCardOrigin: () => getCardOrigin,
|
|
2191
|
+
isFilter: () => isFilter,
|
|
2192
|
+
isGenerator: () => isGenerator
|
|
646
2193
|
});
|
|
647
|
-
|
|
2194
|
+
function getCardOrigin(card) {
|
|
2195
|
+
if (card.provenance.length === 0) {
|
|
2196
|
+
throw new Error("Card has no provenance - cannot determine origin");
|
|
2197
|
+
}
|
|
2198
|
+
const firstEntry = card.provenance[0];
|
|
2199
|
+
const reason = firstEntry.reason.toLowerCase();
|
|
2200
|
+
if (reason.includes("failed")) {
|
|
2201
|
+
return "failed";
|
|
2202
|
+
}
|
|
2203
|
+
if (reason.includes("review")) {
|
|
2204
|
+
return "review";
|
|
2205
|
+
}
|
|
2206
|
+
return "new";
|
|
2207
|
+
}
|
|
2208
|
+
function isGenerator(impl) {
|
|
2209
|
+
return NavigatorRoles[impl] === "generator" /* GENERATOR */;
|
|
2210
|
+
}
|
|
2211
|
+
function isFilter(impl) {
|
|
2212
|
+
return NavigatorRoles[impl] === "filter" /* FILTER */;
|
|
2213
|
+
}
|
|
2214
|
+
var Navigators, NavigatorRole, NavigatorRoles, ContentNavigator;
|
|
648
2215
|
var init_navigators = __esm({
|
|
649
2216
|
"src/core/navigators/index.ts"() {
|
|
650
2217
|
"use strict";
|
|
@@ -652,14 +2219,103 @@ var init_navigators = __esm({
|
|
|
652
2219
|
init_();
|
|
653
2220
|
Navigators = /* @__PURE__ */ ((Navigators2) => {
|
|
654
2221
|
Navigators2["ELO"] = "elo";
|
|
2222
|
+
Navigators2["SRS"] = "srs";
|
|
655
2223
|
Navigators2["HARDCODED"] = "hardcodedOrder";
|
|
2224
|
+
Navigators2["HIERARCHY"] = "hierarchyDefinition";
|
|
2225
|
+
Navigators2["INTERFERENCE"] = "interferenceMitigator";
|
|
2226
|
+
Navigators2["RELATIVE_PRIORITY"] = "relativePriority";
|
|
2227
|
+
Navigators2["USER_TAG_PREFERENCE"] = "userTagPreference";
|
|
656
2228
|
return Navigators2;
|
|
657
2229
|
})(Navigators || {});
|
|
2230
|
+
NavigatorRole = /* @__PURE__ */ ((NavigatorRole2) => {
|
|
2231
|
+
NavigatorRole2["GENERATOR"] = "generator";
|
|
2232
|
+
NavigatorRole2["FILTER"] = "filter";
|
|
2233
|
+
return NavigatorRole2;
|
|
2234
|
+
})(NavigatorRole || {});
|
|
2235
|
+
NavigatorRoles = {
|
|
2236
|
+
["elo" /* ELO */]: "generator" /* GENERATOR */,
|
|
2237
|
+
["srs" /* SRS */]: "generator" /* GENERATOR */,
|
|
2238
|
+
["hardcodedOrder" /* HARDCODED */]: "generator" /* GENERATOR */,
|
|
2239
|
+
["hierarchyDefinition" /* HIERARCHY */]: "filter" /* FILTER */,
|
|
2240
|
+
["interferenceMitigator" /* INTERFERENCE */]: "filter" /* FILTER */,
|
|
2241
|
+
["relativePriority" /* RELATIVE_PRIORITY */]: "filter" /* FILTER */,
|
|
2242
|
+
["userTagPreference" /* USER_TAG_PREFERENCE */]: "filter" /* FILTER */
|
|
2243
|
+
};
|
|
658
2244
|
ContentNavigator = class {
|
|
2245
|
+
/** User interface for this navigation session */
|
|
2246
|
+
user;
|
|
2247
|
+
/** Course interface for this navigation session */
|
|
2248
|
+
course;
|
|
2249
|
+
/** Human-readable name for this strategy instance (from ContentNavigationStrategyData.name) */
|
|
2250
|
+
strategyName;
|
|
2251
|
+
/** Unique document ID for this strategy instance (from ContentNavigationStrategyData._id) */
|
|
2252
|
+
strategyId;
|
|
2253
|
+
/**
|
|
2254
|
+
* Constructor for standard navigators.
|
|
2255
|
+
* Call this from subclass constructors to initialize common fields.
|
|
2256
|
+
*
|
|
2257
|
+
* Note: CompositeGenerator doesn't use this pattern and should call super() without args.
|
|
2258
|
+
*/
|
|
2259
|
+
constructor(user, course, strategyData) {
|
|
2260
|
+
if (user && course && strategyData) {
|
|
2261
|
+
this.user = user;
|
|
2262
|
+
this.course = course;
|
|
2263
|
+
this.strategyName = strategyData.name;
|
|
2264
|
+
this.strategyId = strategyData._id;
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
// ============================================================================
|
|
2268
|
+
// STRATEGY STATE HELPERS
|
|
2269
|
+
// ============================================================================
|
|
2270
|
+
//
|
|
2271
|
+
// These methods allow strategies to persist their own state (user preferences,
|
|
2272
|
+
// learned patterns, temporal tracking) in the user database.
|
|
2273
|
+
//
|
|
2274
|
+
// ============================================================================
|
|
2275
|
+
/**
|
|
2276
|
+
* Unique key identifying this strategy for state storage.
|
|
2277
|
+
*
|
|
2278
|
+
* Defaults to the constructor name (e.g., "UserTagPreferenceFilter").
|
|
2279
|
+
* Override in subclasses if multiple instances of the same strategy type
|
|
2280
|
+
* need separate state storage.
|
|
2281
|
+
*/
|
|
2282
|
+
get strategyKey() {
|
|
2283
|
+
return this.constructor.name;
|
|
2284
|
+
}
|
|
2285
|
+
/**
|
|
2286
|
+
* Get this strategy's persisted state for the current course.
|
|
2287
|
+
*
|
|
2288
|
+
* @returns The strategy's data payload, or null if no state exists
|
|
2289
|
+
* @throws Error if user or course is not initialized
|
|
2290
|
+
*/
|
|
2291
|
+
async getStrategyState() {
|
|
2292
|
+
if (!this.user || !this.course) {
|
|
2293
|
+
throw new Error(
|
|
2294
|
+
`Cannot get strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
2295
|
+
);
|
|
2296
|
+
}
|
|
2297
|
+
return this.user.getStrategyState(this.course.getCourseID(), this.strategyKey);
|
|
2298
|
+
}
|
|
2299
|
+
/**
|
|
2300
|
+
* Persist this strategy's state for the current course.
|
|
2301
|
+
*
|
|
2302
|
+
* @param data - The strategy's data payload to store
|
|
2303
|
+
* @throws Error if user or course is not initialized
|
|
2304
|
+
*/
|
|
2305
|
+
async putStrategyState(data) {
|
|
2306
|
+
if (!this.user || !this.course) {
|
|
2307
|
+
throw new Error(
|
|
2308
|
+
`Cannot put strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
2309
|
+
);
|
|
2310
|
+
}
|
|
2311
|
+
return this.user.putStrategyState(this.course.getCourseID(), this.strategyKey, data);
|
|
2312
|
+
}
|
|
659
2313
|
/**
|
|
2314
|
+
* Factory method to create navigator instances dynamically.
|
|
660
2315
|
*
|
|
661
|
-
* @param user
|
|
662
|
-
* @param
|
|
2316
|
+
* @param user - User interface
|
|
2317
|
+
* @param course - Course interface
|
|
2318
|
+
* @param strategyData - Strategy configuration document
|
|
663
2319
|
* @returns the runtime object used to steer a study session.
|
|
664
2320
|
*/
|
|
665
2321
|
static async create(user, course, strategyData) {
|
|
@@ -680,16 +2336,80 @@ var init_navigators = __esm({
|
|
|
680
2336
|
}
|
|
681
2337
|
return new NavigatorImpl(user, course, strategyData);
|
|
682
2338
|
}
|
|
2339
|
+
/**
|
|
2340
|
+
* Get cards with suitability scores and provenance trails.
|
|
2341
|
+
*
|
|
2342
|
+
* **This is the PRIMARY API for navigation strategies.**
|
|
2343
|
+
*
|
|
2344
|
+
* Returns cards ranked by suitability score (0-1). Higher scores indicate
|
|
2345
|
+
* better candidates for presentation. Each card includes a provenance trail
|
|
2346
|
+
* documenting how strategies contributed to the final score.
|
|
2347
|
+
*
|
|
2348
|
+
* ## For Generators
|
|
2349
|
+
* Override this method to generate candidates and compute scores based on
|
|
2350
|
+
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
2351
|
+
* initial provenance entry with action='generated'.
|
|
2352
|
+
*
|
|
2353
|
+
* ## Default Implementation
|
|
2354
|
+
* The base class provides a backward-compatible default that:
|
|
2355
|
+
* 1. Calls legacy getNewCards() and getPendingReviews()
|
|
2356
|
+
* 2. Assigns score=1.0 to all cards
|
|
2357
|
+
* 3. Creates minimal provenance from legacy methods
|
|
2358
|
+
* 4. Returns combined results up to limit
|
|
2359
|
+
*
|
|
2360
|
+
* This allows existing strategies to work without modification while
|
|
2361
|
+
* new strategies can override with proper scoring and provenance.
|
|
2362
|
+
*
|
|
2363
|
+
* @param limit - Maximum cards to return
|
|
2364
|
+
* @returns Cards sorted by score descending, with provenance trails
|
|
2365
|
+
*/
|
|
2366
|
+
async getWeightedCards(limit) {
|
|
2367
|
+
const newCards = await this.getNewCards(limit);
|
|
2368
|
+
const reviews = await this.getPendingReviews();
|
|
2369
|
+
const weighted = [
|
|
2370
|
+
...newCards.map((c) => ({
|
|
2371
|
+
cardId: c.cardID,
|
|
2372
|
+
courseId: c.courseID,
|
|
2373
|
+
score: 1,
|
|
2374
|
+
provenance: [
|
|
2375
|
+
{
|
|
2376
|
+
strategy: "legacy",
|
|
2377
|
+
strategyName: this.strategyName || "Legacy API",
|
|
2378
|
+
strategyId: this.strategyId || "legacy-fallback",
|
|
2379
|
+
action: "generated",
|
|
2380
|
+
score: 1,
|
|
2381
|
+
reason: "Generated via legacy getNewCards(), new card"
|
|
2382
|
+
}
|
|
2383
|
+
]
|
|
2384
|
+
})),
|
|
2385
|
+
...reviews.map((r) => ({
|
|
2386
|
+
cardId: r.cardID,
|
|
2387
|
+
courseId: r.courseID,
|
|
2388
|
+
score: 1,
|
|
2389
|
+
provenance: [
|
|
2390
|
+
{
|
|
2391
|
+
strategy: "legacy",
|
|
2392
|
+
strategyName: this.strategyName || "Legacy API",
|
|
2393
|
+
strategyId: this.strategyId || "legacy-fallback",
|
|
2394
|
+
action: "generated",
|
|
2395
|
+
score: 1,
|
|
2396
|
+
reason: "Generated via legacy getPendingReviews(), review"
|
|
2397
|
+
}
|
|
2398
|
+
]
|
|
2399
|
+
}))
|
|
2400
|
+
];
|
|
2401
|
+
return weighted.slice(0, limit);
|
|
2402
|
+
}
|
|
683
2403
|
};
|
|
684
2404
|
}
|
|
685
2405
|
});
|
|
686
2406
|
|
|
687
2407
|
// src/impl/couch/courseDB.ts
|
|
688
|
-
var
|
|
2408
|
+
var import_common9;
|
|
689
2409
|
var init_courseDB = __esm({
|
|
690
2410
|
"src/impl/couch/courseDB.ts"() {
|
|
691
2411
|
"use strict";
|
|
692
|
-
|
|
2412
|
+
import_common9 = require("@vue-skuilder/common");
|
|
693
2413
|
init_couch();
|
|
694
2414
|
init_updateQueue();
|
|
695
2415
|
init_types_legacy();
|
|
@@ -698,17 +2418,23 @@ var init_courseDB = __esm({
|
|
|
698
2418
|
init_courseAPI();
|
|
699
2419
|
init_courseLookupDB();
|
|
700
2420
|
init_navigators();
|
|
2421
|
+
init_Pipeline();
|
|
2422
|
+
init_PipelineAssembler();
|
|
2423
|
+
init_CompositeGenerator();
|
|
2424
|
+
init_elo();
|
|
2425
|
+
init_srs();
|
|
2426
|
+
init_eloDistance();
|
|
701
2427
|
}
|
|
702
2428
|
});
|
|
703
2429
|
|
|
704
2430
|
// src/impl/couch/classroomDB.ts
|
|
705
|
-
var
|
|
2431
|
+
var import_moment4;
|
|
706
2432
|
var init_classroomDB2 = __esm({
|
|
707
2433
|
"src/impl/couch/classroomDB.ts"() {
|
|
708
2434
|
"use strict";
|
|
709
2435
|
init_factory();
|
|
710
2436
|
init_logger();
|
|
711
|
-
|
|
2437
|
+
import_moment4 = __toESM(require("moment"), 1);
|
|
712
2438
|
init_pouchdb_setup();
|
|
713
2439
|
init_couch();
|
|
714
2440
|
init_courseDB();
|
|
@@ -735,19 +2461,19 @@ var init_auth = __esm({
|
|
|
735
2461
|
"use strict";
|
|
736
2462
|
init_factory();
|
|
737
2463
|
init_logger();
|
|
738
|
-
import_cross_fetch = __toESM(require("cross-fetch"));
|
|
2464
|
+
import_cross_fetch = __toESM(require("cross-fetch"), 1);
|
|
739
2465
|
}
|
|
740
2466
|
});
|
|
741
2467
|
|
|
742
2468
|
// src/impl/couch/CouchDBSyncStrategy.ts
|
|
743
|
-
var
|
|
2469
|
+
var import_common10;
|
|
744
2470
|
var init_CouchDBSyncStrategy = __esm({
|
|
745
2471
|
"src/impl/couch/CouchDBSyncStrategy.ts"() {
|
|
746
2472
|
"use strict";
|
|
747
2473
|
init_factory();
|
|
748
2474
|
init_types_legacy();
|
|
749
2475
|
init_logger();
|
|
750
|
-
|
|
2476
|
+
import_common10 = require("@vue-skuilder/common");
|
|
751
2477
|
init_common();
|
|
752
2478
|
init_pouchdb_setup();
|
|
753
2479
|
init_couch();
|
|
@@ -775,17 +2501,17 @@ function createPouchDBConfig() {
|
|
|
775
2501
|
}
|
|
776
2502
|
return pouchDBincludeCredentialsConfig;
|
|
777
2503
|
}
|
|
778
|
-
var import_cross_fetch2,
|
|
2504
|
+
var import_cross_fetch2, import_moment5, import_process, isBrowser, GUEST_LOCAL_DB, localUserDB, pouchDBincludeCredentialsConfig;
|
|
779
2505
|
var init_couch = __esm({
|
|
780
2506
|
"src/impl/couch/index.ts"() {
|
|
781
2507
|
"use strict";
|
|
782
2508
|
init_factory();
|
|
783
2509
|
init_types_legacy();
|
|
784
|
-
import_cross_fetch2 = __toESM(require("cross-fetch"));
|
|
785
|
-
|
|
2510
|
+
import_cross_fetch2 = __toESM(require("cross-fetch"), 1);
|
|
2511
|
+
import_moment5 = __toESM(require("moment"), 1);
|
|
786
2512
|
init_logger();
|
|
787
2513
|
init_pouchdb_setup();
|
|
788
|
-
import_process = __toESM(require("process"));
|
|
2514
|
+
import_process = __toESM(require("process"), 1);
|
|
789
2515
|
init_contentSource();
|
|
790
2516
|
init_adminDB2();
|
|
791
2517
|
init_classroomDB2();
|
|
@@ -811,7 +2537,9 @@ var init_couch = __esm({
|
|
|
811
2537
|
function accomodateGuest() {
|
|
812
2538
|
logger.log("[funnel] accomodateGuest() called");
|
|
813
2539
|
if (typeof localStorage === "undefined") {
|
|
814
|
-
logger.log(
|
|
2540
|
+
logger.log(
|
|
2541
|
+
"[funnel] localStorage not available (Node.js environment), returning default guest"
|
|
2542
|
+
);
|
|
815
2543
|
return {
|
|
816
2544
|
username: GuestUsername + "nodejs-test",
|
|
817
2545
|
firstVisit: true
|
|
@@ -979,14 +2707,14 @@ async function dropUserFromClassroom(user, classID) {
|
|
|
979
2707
|
async function getUserClassrooms(user) {
|
|
980
2708
|
return getOrCreateClassroomRegistrationsDoc(user);
|
|
981
2709
|
}
|
|
982
|
-
var
|
|
2710
|
+
var import_common12, import_moment6, log3, BaseUser, userCoursesDoc, userClassroomsDoc;
|
|
983
2711
|
var init_BaseUserDB = __esm({
|
|
984
2712
|
"src/impl/common/BaseUserDB.ts"() {
|
|
985
2713
|
"use strict";
|
|
986
2714
|
init_core();
|
|
987
2715
|
init_util();
|
|
988
|
-
|
|
989
|
-
|
|
2716
|
+
import_common12 = require("@vue-skuilder/common");
|
|
2717
|
+
import_moment6 = __toESM(require("moment"), 1);
|
|
990
2718
|
init_types_legacy();
|
|
991
2719
|
init_logger();
|
|
992
2720
|
init_userDBHelpers();
|
|
@@ -1035,7 +2763,7 @@ Currently logged-in as ${this._username}.`
|
|
|
1035
2763
|
);
|
|
1036
2764
|
}
|
|
1037
2765
|
const result = await this.syncStrategy.createAccount(username, password);
|
|
1038
|
-
if (result.status ===
|
|
2766
|
+
if (result.status === import_common12.Status.ok) {
|
|
1039
2767
|
log3(`Account created successfully, updating username to ${username}`);
|
|
1040
2768
|
this._username = username;
|
|
1041
2769
|
try {
|
|
@@ -1077,7 +2805,7 @@ Currently logged-in as ${this._username}.`
|
|
|
1077
2805
|
async resetUserData() {
|
|
1078
2806
|
if (this.syncStrategy.canAuthenticate()) {
|
|
1079
2807
|
return {
|
|
1080
|
-
status:
|
|
2808
|
+
status: import_common12.Status.error,
|
|
1081
2809
|
error: "Reset user data is only available for local-only mode. Use logout instead for remote sync."
|
|
1082
2810
|
};
|
|
1083
2811
|
}
|
|
@@ -1096,11 +2824,11 @@ Currently logged-in as ${this._username}.`
|
|
|
1096
2824
|
await localDB.bulkDocs(docsToDelete);
|
|
1097
2825
|
}
|
|
1098
2826
|
await this.init();
|
|
1099
|
-
return { status:
|
|
2827
|
+
return { status: import_common12.Status.ok };
|
|
1100
2828
|
} catch (error) {
|
|
1101
2829
|
logger.error("Failed to reset user data:", error);
|
|
1102
2830
|
return {
|
|
1103
|
-
status:
|
|
2831
|
+
status: import_common12.Status.error,
|
|
1104
2832
|
error: error instanceof Error ? error.message : "Unknown error during reset"
|
|
1105
2833
|
};
|
|
1106
2834
|
}
|
|
@@ -1247,7 +2975,7 @@ Currently logged-in as ${this._username}.`
|
|
|
1247
2975
|
);
|
|
1248
2976
|
return reviews.rows.filter((r) => {
|
|
1249
2977
|
if (r.id.startsWith(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */])) {
|
|
1250
|
-
const date =
|
|
2978
|
+
const date = import_moment6.default.utc(
|
|
1251
2979
|
r.id.substr(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */].length),
|
|
1252
2980
|
REVIEW_TIME_FORMAT
|
|
1253
2981
|
);
|
|
@@ -1260,11 +2988,11 @@ Currently logged-in as ${this._username}.`
|
|
|
1260
2988
|
}).map((r) => r.doc);
|
|
1261
2989
|
}
|
|
1262
2990
|
async getReviewsForcast(daysCount) {
|
|
1263
|
-
const time =
|
|
2991
|
+
const time = import_moment6.default.utc().add(daysCount, "days");
|
|
1264
2992
|
return this.getReviewstoDate(time);
|
|
1265
2993
|
}
|
|
1266
2994
|
async getPendingReviews(course_id) {
|
|
1267
|
-
const now =
|
|
2995
|
+
const now = import_moment6.default.utc();
|
|
1268
2996
|
return this.getReviewstoDate(now, course_id);
|
|
1269
2997
|
}
|
|
1270
2998
|
async getScheduledReviewCount(course_id) {
|
|
@@ -1551,7 +3279,7 @@ Currently logged-in as ${this._username}.`
|
|
|
1551
3279
|
*/
|
|
1552
3280
|
async putCardRecord(record) {
|
|
1553
3281
|
const cardHistoryID = getCardHistoryID(record.courseID, record.cardID);
|
|
1554
|
-
record.timeStamp =
|
|
3282
|
+
record.timeStamp = import_moment6.default.utc(record.timeStamp).toString();
|
|
1555
3283
|
try {
|
|
1556
3284
|
const cardHistory = await this.update(
|
|
1557
3285
|
cardHistoryID,
|
|
@@ -1567,7 +3295,7 @@ Currently logged-in as ${this._username}.`
|
|
|
1567
3295
|
const ret = {
|
|
1568
3296
|
...record2
|
|
1569
3297
|
};
|
|
1570
|
-
ret.timeStamp =
|
|
3298
|
+
ret.timeStamp = import_moment6.default.utc(record2.timeStamp);
|
|
1571
3299
|
return ret;
|
|
1572
3300
|
});
|
|
1573
3301
|
return cardHistory;
|
|
@@ -1791,6 +3519,55 @@ Currently logged-in as ${this._username}.`
|
|
|
1791
3519
|
async updateUserElo(courseId, elo) {
|
|
1792
3520
|
return updateUserElo(this._username, courseId, elo);
|
|
1793
3521
|
}
|
|
3522
|
+
async getStrategyState(courseId, strategyKey) {
|
|
3523
|
+
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
3524
|
+
try {
|
|
3525
|
+
const doc = await this.localDB.get(docId);
|
|
3526
|
+
return doc.data;
|
|
3527
|
+
} catch (e) {
|
|
3528
|
+
const err = e;
|
|
3529
|
+
if (err.status === 404) {
|
|
3530
|
+
return null;
|
|
3531
|
+
}
|
|
3532
|
+
throw e;
|
|
3533
|
+
}
|
|
3534
|
+
}
|
|
3535
|
+
async putStrategyState(courseId, strategyKey, data) {
|
|
3536
|
+
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
3537
|
+
let existingRev;
|
|
3538
|
+
try {
|
|
3539
|
+
const existing = await this.localDB.get(docId);
|
|
3540
|
+
existingRev = existing._rev;
|
|
3541
|
+
} catch (e) {
|
|
3542
|
+
const err = e;
|
|
3543
|
+
if (err.status !== 404) {
|
|
3544
|
+
throw e;
|
|
3545
|
+
}
|
|
3546
|
+
}
|
|
3547
|
+
const doc = {
|
|
3548
|
+
_id: docId,
|
|
3549
|
+
_rev: existingRev,
|
|
3550
|
+
docType: "STRATEGY_STATE" /* STRATEGY_STATE */,
|
|
3551
|
+
courseId,
|
|
3552
|
+
strategyKey,
|
|
3553
|
+
data,
|
|
3554
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3555
|
+
};
|
|
3556
|
+
await this.localDB.put(doc);
|
|
3557
|
+
}
|
|
3558
|
+
async deleteStrategyState(courseId, strategyKey) {
|
|
3559
|
+
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
3560
|
+
try {
|
|
3561
|
+
const doc = await this.localDB.get(docId);
|
|
3562
|
+
await this.localDB.remove(doc);
|
|
3563
|
+
} catch (e) {
|
|
3564
|
+
const err = e;
|
|
3565
|
+
if (err.status === 404) {
|
|
3566
|
+
return;
|
|
3567
|
+
}
|
|
3568
|
+
throw e;
|
|
3569
|
+
}
|
|
3570
|
+
}
|
|
1794
3571
|
};
|
|
1795
3572
|
userCoursesDoc = "CourseRegistrations";
|
|
1796
3573
|
userClassroomsDoc = "ClassroomRegistrations";
|
|
@@ -1823,12 +3600,26 @@ var init_factory = __esm({
|
|
|
1823
3600
|
}
|
|
1824
3601
|
});
|
|
1825
3602
|
|
|
3603
|
+
// src/study/TagFilteredContentSource.ts
|
|
3604
|
+
var import_common14;
|
|
3605
|
+
var init_TagFilteredContentSource = __esm({
|
|
3606
|
+
"src/study/TagFilteredContentSource.ts"() {
|
|
3607
|
+
"use strict";
|
|
3608
|
+
import_common14 = require("@vue-skuilder/common");
|
|
3609
|
+
init_courseDB();
|
|
3610
|
+
init_logger();
|
|
3611
|
+
}
|
|
3612
|
+
});
|
|
3613
|
+
|
|
1826
3614
|
// src/core/interfaces/contentSource.ts
|
|
3615
|
+
var import_common15;
|
|
1827
3616
|
var init_contentSource = __esm({
|
|
1828
3617
|
"src/core/interfaces/contentSource.ts"() {
|
|
1829
3618
|
"use strict";
|
|
1830
3619
|
init_factory();
|
|
1831
3620
|
init_classroomDB2();
|
|
3621
|
+
import_common15 = require("@vue-skuilder/common");
|
|
3622
|
+
init_TagFilteredContentSource();
|
|
1832
3623
|
}
|
|
1833
3624
|
});
|
|
1834
3625
|
|
|
@@ -1873,18 +3664,28 @@ var init_user = __esm({
|
|
|
1873
3664
|
}
|
|
1874
3665
|
});
|
|
1875
3666
|
|
|
3667
|
+
// src/core/types/strategyState.ts
|
|
3668
|
+
function buildStrategyStateId(courseId, strategyKey) {
|
|
3669
|
+
return `STRATEGY_STATE::${courseId}::${strategyKey}`;
|
|
3670
|
+
}
|
|
3671
|
+
var init_strategyState = __esm({
|
|
3672
|
+
"src/core/types/strategyState.ts"() {
|
|
3673
|
+
"use strict";
|
|
3674
|
+
}
|
|
3675
|
+
});
|
|
3676
|
+
|
|
1876
3677
|
// src/core/bulkImport/cardProcessor.ts
|
|
1877
|
-
var
|
|
3678
|
+
var import_common16;
|
|
1878
3679
|
var init_cardProcessor = __esm({
|
|
1879
3680
|
"src/core/bulkImport/cardProcessor.ts"() {
|
|
1880
3681
|
"use strict";
|
|
1881
|
-
|
|
3682
|
+
import_common16 = require("@vue-skuilder/common");
|
|
1882
3683
|
init_logger();
|
|
1883
3684
|
}
|
|
1884
3685
|
});
|
|
1885
3686
|
|
|
1886
3687
|
// src/core/bulkImport/types.ts
|
|
1887
|
-
var
|
|
3688
|
+
var init_types3 = __esm({
|
|
1888
3689
|
"src/core/bulkImport/types.ts"() {
|
|
1889
3690
|
"use strict";
|
|
1890
3691
|
}
|
|
@@ -1895,7 +3696,7 @@ var init_bulkImport = __esm({
|
|
|
1895
3696
|
"src/core/bulkImport/index.ts"() {
|
|
1896
3697
|
"use strict";
|
|
1897
3698
|
init_cardProcessor();
|
|
1898
|
-
|
|
3699
|
+
init_types3();
|
|
1899
3700
|
}
|
|
1900
3701
|
});
|
|
1901
3702
|
|
|
@@ -1906,6 +3707,7 @@ var init_core = __esm({
|
|
|
1906
3707
|
init_interfaces();
|
|
1907
3708
|
init_types_legacy();
|
|
1908
3709
|
init_user();
|
|
3710
|
+
init_strategyState();
|
|
1909
3711
|
init_Loggable();
|
|
1910
3712
|
init_util();
|
|
1911
3713
|
init_navigators();
|
|
@@ -2293,11 +4095,11 @@ var init_StaticDataUnpacker = __esm({
|
|
|
2293
4095
|
});
|
|
2294
4096
|
|
|
2295
4097
|
// src/impl/static/courseDB.ts
|
|
2296
|
-
var
|
|
4098
|
+
var import_common17, StaticCourseDB;
|
|
2297
4099
|
var init_courseDB3 = __esm({
|
|
2298
4100
|
"src/impl/static/courseDB.ts"() {
|
|
2299
4101
|
"use strict";
|
|
2300
|
-
|
|
4102
|
+
import_common17 = require("@vue-skuilder/common");
|
|
2301
4103
|
init_types_legacy();
|
|
2302
4104
|
init_navigators();
|
|
2303
4105
|
init_logger();
|
|
@@ -2478,6 +4280,14 @@ var init_courseDB3 = __esm({
|
|
|
2478
4280
|
};
|
|
2479
4281
|
}
|
|
2480
4282
|
}
|
|
4283
|
+
async getAppliedTagsBatch(cardIds) {
|
|
4284
|
+
const tagsIndex = await this.unpacker.getTagsIndex();
|
|
4285
|
+
const tagsByCard = /* @__PURE__ */ new Map();
|
|
4286
|
+
for (const cardId of cardIds) {
|
|
4287
|
+
tagsByCard.set(cardId, tagsIndex.byCard[cardId] || []);
|
|
4288
|
+
}
|
|
4289
|
+
return tagsByCard;
|
|
4290
|
+
}
|
|
2481
4291
|
async addTagToCard(_cardId, _tagId) {
|
|
2482
4292
|
throw new Error("Cannot modify tags in static mode");
|
|
2483
4293
|
}
|
|
@@ -2560,7 +4370,7 @@ var init_courseDB3 = __esm({
|
|
|
2560
4370
|
}
|
|
2561
4371
|
async addNote(_codeCourse, _shape, _data, _author, _tags, _uploads, _elo) {
|
|
2562
4372
|
return {
|
|
2563
|
-
status:
|
|
4373
|
+
status: import_common17.Status.error,
|
|
2564
4374
|
message: "Cannot add notes in static mode"
|
|
2565
4375
|
};
|
|
2566
4376
|
}
|
|
@@ -2591,9 +4401,6 @@ var init_courseDB3 = __esm({
|
|
|
2591
4401
|
async updateNavigationStrategy(_id, _data) {
|
|
2592
4402
|
throw new Error("Cannot update navigation strategies in static mode");
|
|
2593
4403
|
}
|
|
2594
|
-
async surfaceNavigationStrategy() {
|
|
2595
|
-
return this.getNavigationStrategy("ELO");
|
|
2596
|
-
}
|
|
2597
4404
|
// Study Content Source implementation
|
|
2598
4405
|
async getPendingReviews() {
|
|
2599
4406
|
return [];
|