@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
package/dist/impl/couch/index.js
CHANGED
|
@@ -106,9 +106,9 @@ var import_pouchdb, import_pouchdb_find, import_pouchdb_authentication, pouchdb_
|
|
|
106
106
|
var init_pouchdb_setup = __esm({
|
|
107
107
|
"src/impl/couch/pouchdb-setup.ts"() {
|
|
108
108
|
"use strict";
|
|
109
|
-
import_pouchdb = __toESM(require("pouchdb"));
|
|
110
|
-
import_pouchdb_find = __toESM(require("pouchdb-find"));
|
|
111
|
-
import_pouchdb_authentication = __toESM(require("@nilock2/pouchdb-authentication"));
|
|
109
|
+
import_pouchdb = __toESM(require("pouchdb"), 1);
|
|
110
|
+
import_pouchdb_find = __toESM(require("pouchdb-find"), 1);
|
|
111
|
+
import_pouchdb_authentication = __toESM(require("@nilock2/pouchdb-authentication"), 1);
|
|
112
112
|
import_pouchdb.default.plugin(import_pouchdb_find.default);
|
|
113
113
|
import_pouchdb.default.plugin(import_pouchdb_authentication.default);
|
|
114
114
|
import_pouchdb.default.defaults({
|
|
@@ -280,7 +280,8 @@ var init_types_legacy = __esm({
|
|
|
280
280
|
["QUESTION" /* QUESTIONTYPE */]: "QUESTION",
|
|
281
281
|
["VIEW" /* VIEW */]: "VIEW",
|
|
282
282
|
["PEDAGOGY" /* PEDAGOGY */]: "PEDAGOGY",
|
|
283
|
-
["NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */]: "NAVIGATION_STRATEGY"
|
|
283
|
+
["NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */]: "NAVIGATION_STRATEGY",
|
|
284
|
+
["STRATEGY_STATE" /* STRATEGY_STATE */]: "STRATEGY_STATE"
|
|
284
285
|
};
|
|
285
286
|
}
|
|
286
287
|
});
|
|
@@ -621,23 +622,518 @@ var init_courseLookupDB = __esm({
|
|
|
621
622
|
}
|
|
622
623
|
});
|
|
623
624
|
|
|
625
|
+
// src/core/navigators/CompositeGenerator.ts
|
|
626
|
+
var CompositeGenerator_exports = {};
|
|
627
|
+
__export(CompositeGenerator_exports, {
|
|
628
|
+
AggregationMode: () => AggregationMode,
|
|
629
|
+
default: () => CompositeGenerator
|
|
630
|
+
});
|
|
631
|
+
var AggregationMode, DEFAULT_AGGREGATION_MODE, FREQUENCY_BOOST_FACTOR, CompositeGenerator;
|
|
632
|
+
var init_CompositeGenerator = __esm({
|
|
633
|
+
"src/core/navigators/CompositeGenerator.ts"() {
|
|
634
|
+
"use strict";
|
|
635
|
+
init_navigators();
|
|
636
|
+
init_logger();
|
|
637
|
+
AggregationMode = /* @__PURE__ */ ((AggregationMode2) => {
|
|
638
|
+
AggregationMode2["MAX"] = "max";
|
|
639
|
+
AggregationMode2["AVERAGE"] = "average";
|
|
640
|
+
AggregationMode2["FREQUENCY_BOOST"] = "frequencyBoost";
|
|
641
|
+
return AggregationMode2;
|
|
642
|
+
})(AggregationMode || {});
|
|
643
|
+
DEFAULT_AGGREGATION_MODE = "frequencyBoost" /* FREQUENCY_BOOST */;
|
|
644
|
+
FREQUENCY_BOOST_FACTOR = 0.1;
|
|
645
|
+
CompositeGenerator = class _CompositeGenerator extends ContentNavigator {
|
|
646
|
+
/** Human-readable name for CardGenerator interface */
|
|
647
|
+
name = "Composite Generator";
|
|
648
|
+
generators;
|
|
649
|
+
aggregationMode;
|
|
650
|
+
constructor(generators, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
651
|
+
super();
|
|
652
|
+
this.generators = generators;
|
|
653
|
+
this.aggregationMode = aggregationMode;
|
|
654
|
+
if (generators.length === 0) {
|
|
655
|
+
throw new Error("CompositeGenerator requires at least one generator");
|
|
656
|
+
}
|
|
657
|
+
logger.debug(
|
|
658
|
+
`[CompositeGenerator] Created with ${generators.length} generators, mode: ${aggregationMode}`
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Creates a CompositeGenerator from strategy data.
|
|
663
|
+
*
|
|
664
|
+
* This is a convenience factory for use by PipelineAssembler.
|
|
665
|
+
*/
|
|
666
|
+
static async fromStrategies(user, course, strategies, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
667
|
+
const generators = await Promise.all(
|
|
668
|
+
strategies.map((s) => ContentNavigator.create(user, course, s))
|
|
669
|
+
);
|
|
670
|
+
return new _CompositeGenerator(generators, aggregationMode);
|
|
671
|
+
}
|
|
672
|
+
/**
|
|
673
|
+
* Get weighted cards from all generators, merge and deduplicate.
|
|
674
|
+
*
|
|
675
|
+
* Cards appearing in multiple generators receive a score boost.
|
|
676
|
+
* Provenance tracks which generators produced each card and how scores were aggregated.
|
|
677
|
+
*
|
|
678
|
+
* This method supports both the legacy signature (limit only) and the
|
|
679
|
+
* CardGenerator interface signature (limit, context).
|
|
680
|
+
*
|
|
681
|
+
* @param limit - Maximum number of cards to return
|
|
682
|
+
* @param context - Optional GeneratorContext passed to child generators
|
|
683
|
+
*/
|
|
684
|
+
async getWeightedCards(limit, context) {
|
|
685
|
+
const results = await Promise.all(
|
|
686
|
+
this.generators.map((g) => g.getWeightedCards(limit, context))
|
|
687
|
+
);
|
|
688
|
+
const byCardId = /* @__PURE__ */ new Map();
|
|
689
|
+
for (const cards of results) {
|
|
690
|
+
for (const card of cards) {
|
|
691
|
+
const existing = byCardId.get(card.cardId) || [];
|
|
692
|
+
existing.push(card);
|
|
693
|
+
byCardId.set(card.cardId, existing);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
const merged = [];
|
|
697
|
+
for (const [, cards] of byCardId) {
|
|
698
|
+
const aggregatedScore = this.aggregateScores(cards);
|
|
699
|
+
const finalScore = Math.min(1, aggregatedScore);
|
|
700
|
+
const mergedProvenance = cards.flatMap((c) => c.provenance);
|
|
701
|
+
const initialScore = cards[0].score;
|
|
702
|
+
const action = finalScore > initialScore ? "boosted" : finalScore < initialScore ? "penalized" : "passed";
|
|
703
|
+
const reason = this.buildAggregationReason(cards, finalScore);
|
|
704
|
+
merged.push({
|
|
705
|
+
...cards[0],
|
|
706
|
+
score: finalScore,
|
|
707
|
+
provenance: [
|
|
708
|
+
...mergedProvenance,
|
|
709
|
+
{
|
|
710
|
+
strategy: "composite",
|
|
711
|
+
strategyName: "Composite Generator",
|
|
712
|
+
strategyId: "COMPOSITE_GENERATOR",
|
|
713
|
+
action,
|
|
714
|
+
score: finalScore,
|
|
715
|
+
reason
|
|
716
|
+
}
|
|
717
|
+
]
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
return merged.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Build human-readable reason for score aggregation.
|
|
724
|
+
*/
|
|
725
|
+
buildAggregationReason(cards, finalScore) {
|
|
726
|
+
const count = cards.length;
|
|
727
|
+
const scores = cards.map((c) => c.score.toFixed(2)).join(", ");
|
|
728
|
+
if (count === 1) {
|
|
729
|
+
return `Single generator, score ${finalScore.toFixed(2)}`;
|
|
730
|
+
}
|
|
731
|
+
const strategies = cards.map((c) => c.provenance[0]?.strategy || "unknown").join(", ");
|
|
732
|
+
switch (this.aggregationMode) {
|
|
733
|
+
case "max" /* MAX */:
|
|
734
|
+
return `Max of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
735
|
+
case "average" /* AVERAGE */:
|
|
736
|
+
return `Average of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
737
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
738
|
+
const avg = cards.reduce((sum, c) => sum + c.score, 0) / count;
|
|
739
|
+
const boost = 1 + FREQUENCY_BOOST_FACTOR * (count - 1);
|
|
740
|
+
return `Frequency boost from ${count} generators (${strategies}): avg ${avg.toFixed(2)} \xD7 ${boost.toFixed(2)} \u2192 ${finalScore.toFixed(2)}`;
|
|
741
|
+
}
|
|
742
|
+
default:
|
|
743
|
+
return `Aggregated from ${count} generators: ${finalScore.toFixed(2)}`;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Aggregate scores from multiple generators for the same card.
|
|
748
|
+
*/
|
|
749
|
+
aggregateScores(cards) {
|
|
750
|
+
const scores = cards.map((c) => c.score);
|
|
751
|
+
switch (this.aggregationMode) {
|
|
752
|
+
case "max" /* MAX */:
|
|
753
|
+
return Math.max(...scores);
|
|
754
|
+
case "average" /* AVERAGE */:
|
|
755
|
+
return scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
756
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
757
|
+
const avg = scores.reduce((sum, s) => sum + s, 0) / scores.length;
|
|
758
|
+
const frequencyBoost = 1 + FREQUENCY_BOOST_FACTOR * (cards.length - 1);
|
|
759
|
+
return avg * frequencyBoost;
|
|
760
|
+
}
|
|
761
|
+
default:
|
|
762
|
+
return scores[0];
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Get new cards from all generators, merged and deduplicated.
|
|
767
|
+
*/
|
|
768
|
+
async getNewCards(n) {
|
|
769
|
+
const legacyGenerators = this.generators.filter(
|
|
770
|
+
(g) => g instanceof ContentNavigator
|
|
771
|
+
);
|
|
772
|
+
const results = await Promise.all(legacyGenerators.map((g) => g.getNewCards(n)));
|
|
773
|
+
const seen = /* @__PURE__ */ new Set();
|
|
774
|
+
const merged = [];
|
|
775
|
+
for (const cards of results) {
|
|
776
|
+
for (const card of cards) {
|
|
777
|
+
if (!seen.has(card.cardID)) {
|
|
778
|
+
seen.add(card.cardID);
|
|
779
|
+
merged.push(card);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
return n ? merged.slice(0, n) : merged;
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Get pending reviews from all generators, merged and deduplicated.
|
|
787
|
+
*/
|
|
788
|
+
async getPendingReviews() {
|
|
789
|
+
const legacyGenerators = this.generators.filter(
|
|
790
|
+
(g) => g instanceof ContentNavigator
|
|
791
|
+
);
|
|
792
|
+
const results = await Promise.all(legacyGenerators.map((g) => g.getPendingReviews()));
|
|
793
|
+
const seen = /* @__PURE__ */ new Set();
|
|
794
|
+
const merged = [];
|
|
795
|
+
for (const reviews of results) {
|
|
796
|
+
for (const review of reviews) {
|
|
797
|
+
if (!seen.has(review.cardID)) {
|
|
798
|
+
seen.add(review.cardID);
|
|
799
|
+
merged.push(review);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
return merged;
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
// src/core/navigators/Pipeline.ts
|
|
810
|
+
var Pipeline_exports = {};
|
|
811
|
+
__export(Pipeline_exports, {
|
|
812
|
+
Pipeline: () => Pipeline
|
|
813
|
+
});
|
|
814
|
+
function logPipelineConfig(generator, filters) {
|
|
815
|
+
const filterList = filters.length > 0 ? "\n - " + filters.map((f) => f.name).join("\n - ") : " none";
|
|
816
|
+
logger.info(
|
|
817
|
+
`[Pipeline] Configuration:
|
|
818
|
+
Generator: ${generator.name}
|
|
819
|
+
Filters:${filterList}`
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
function logTagHydration(cards, tagsByCard) {
|
|
823
|
+
const totalTags = Array.from(tagsByCard.values()).reduce((sum, tags) => sum + tags.length, 0);
|
|
824
|
+
const cardsWithTags = Array.from(tagsByCard.values()).filter((tags) => tags.length > 0).length;
|
|
825
|
+
logger.debug(
|
|
826
|
+
`[Pipeline] Tag hydration: ${cards.length} cards, ${cardsWithTags} have tags (${totalTags} total tags) - single batch query`
|
|
827
|
+
);
|
|
828
|
+
}
|
|
829
|
+
function logExecutionSummary(generatorName, generatedCount, filterCount, finalCount, topScores) {
|
|
830
|
+
const scoreDisplay = topScores.length > 0 ? topScores.map((s) => s.toFixed(2)).join(", ") : "none";
|
|
831
|
+
logger.info(
|
|
832
|
+
`[Pipeline] Execution: ${generatorName} produced ${generatedCount} \u2192 ${filterCount} filters \u2192 ${finalCount} results (top scores: ${scoreDisplay})`
|
|
833
|
+
);
|
|
834
|
+
}
|
|
835
|
+
function logCardProvenance(cards, maxCards = 3) {
|
|
836
|
+
const cardsToLog = cards.slice(0, maxCards);
|
|
837
|
+
logger.debug(`[Pipeline] Provenance for top ${cardsToLog.length} cards:`);
|
|
838
|
+
for (const card of cardsToLog) {
|
|
839
|
+
logger.debug(`[Pipeline] ${card.cardId} (final score: ${card.score.toFixed(3)}):`);
|
|
840
|
+
for (const entry of card.provenance) {
|
|
841
|
+
const scoreChange = entry.score.toFixed(3);
|
|
842
|
+
const action = entry.action.padEnd(9);
|
|
843
|
+
logger.debug(
|
|
844
|
+
`[Pipeline] ${action} ${scoreChange} - ${entry.strategyName}: ${entry.reason}`
|
|
845
|
+
);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
var import_common5, Pipeline;
|
|
850
|
+
var init_Pipeline = __esm({
|
|
851
|
+
"src/core/navigators/Pipeline.ts"() {
|
|
852
|
+
"use strict";
|
|
853
|
+
import_common5 = require("@vue-skuilder/common");
|
|
854
|
+
init_navigators();
|
|
855
|
+
init_logger();
|
|
856
|
+
Pipeline = class extends ContentNavigator {
|
|
857
|
+
generator;
|
|
858
|
+
filters;
|
|
859
|
+
/**
|
|
860
|
+
* Create a new pipeline.
|
|
861
|
+
*
|
|
862
|
+
* @param generator - The generator (or CompositeGenerator) that produces candidates
|
|
863
|
+
* @param filters - Filters to apply sequentially (order doesn't matter for multipliers)
|
|
864
|
+
* @param user - User database interface
|
|
865
|
+
* @param course - Course database interface
|
|
866
|
+
*/
|
|
867
|
+
constructor(generator, filters, user, course) {
|
|
868
|
+
super();
|
|
869
|
+
this.generator = generator;
|
|
870
|
+
this.filters = filters;
|
|
871
|
+
this.user = user;
|
|
872
|
+
this.course = course;
|
|
873
|
+
logPipelineConfig(generator, filters);
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Get weighted cards by running generator and applying filters.
|
|
877
|
+
*
|
|
878
|
+
* 1. Build shared context (user ELO, etc.)
|
|
879
|
+
* 2. Get candidates from generator (passing context)
|
|
880
|
+
* 3. Batch hydrate tags for all candidates
|
|
881
|
+
* 4. Apply each filter sequentially
|
|
882
|
+
* 5. Remove zero-score cards
|
|
883
|
+
* 6. Sort by score descending
|
|
884
|
+
* 7. Return top N
|
|
885
|
+
*
|
|
886
|
+
* @param limit - Maximum number of cards to return
|
|
887
|
+
* @returns Cards sorted by score descending
|
|
888
|
+
*/
|
|
889
|
+
async getWeightedCards(limit) {
|
|
890
|
+
const context = await this.buildContext();
|
|
891
|
+
const overFetchMultiplier = 2 + this.filters.length * 0.5;
|
|
892
|
+
const fetchLimit = Math.ceil(limit * overFetchMultiplier);
|
|
893
|
+
logger.debug(
|
|
894
|
+
`[Pipeline] Fetching ${fetchLimit} candidates from generator '${this.generator.name}'`
|
|
895
|
+
);
|
|
896
|
+
let cards = await this.generator.getWeightedCards(fetchLimit, context);
|
|
897
|
+
const generatedCount = cards.length;
|
|
898
|
+
logger.debug(`[Pipeline] Generator returned ${generatedCount} candidates`);
|
|
899
|
+
cards = await this.hydrateTags(cards);
|
|
900
|
+
for (const filter of this.filters) {
|
|
901
|
+
const beforeCount = cards.length;
|
|
902
|
+
cards = await filter.transform(cards, context);
|
|
903
|
+
logger.debug(`[Pipeline] Filter '${filter.name}': ${beforeCount} \u2192 ${cards.length} cards`);
|
|
904
|
+
}
|
|
905
|
+
cards = cards.filter((c) => c.score > 0);
|
|
906
|
+
cards.sort((a, b) => b.score - a.score);
|
|
907
|
+
const result = cards.slice(0, limit);
|
|
908
|
+
const topScores = result.slice(0, 3).map((c) => c.score);
|
|
909
|
+
logExecutionSummary(this.generator.name, generatedCount, this.filters.length, result.length, topScores);
|
|
910
|
+
logCardProvenance(result, 3);
|
|
911
|
+
return result;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Batch hydrate tags for all cards.
|
|
915
|
+
*
|
|
916
|
+
* Fetches tags for all cards in a single database query and attaches them
|
|
917
|
+
* to the WeightedCard objects. Filters can then use card.tags instead of
|
|
918
|
+
* making individual getAppliedTags() calls.
|
|
919
|
+
*
|
|
920
|
+
* @param cards - Cards to hydrate
|
|
921
|
+
* @returns Cards with tags populated
|
|
922
|
+
*/
|
|
923
|
+
async hydrateTags(cards) {
|
|
924
|
+
if (cards.length === 0) {
|
|
925
|
+
return cards;
|
|
926
|
+
}
|
|
927
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
928
|
+
const tagsByCard = await this.course.getAppliedTagsBatch(cardIds);
|
|
929
|
+
logTagHydration(cards, tagsByCard);
|
|
930
|
+
return cards.map((card) => ({
|
|
931
|
+
...card,
|
|
932
|
+
tags: tagsByCard.get(card.cardId) ?? []
|
|
933
|
+
}));
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Build shared context for generator and filters.
|
|
937
|
+
*
|
|
938
|
+
* Called once per getWeightedCards() invocation.
|
|
939
|
+
* Contains data that the generator and multiple filters might need.
|
|
940
|
+
*
|
|
941
|
+
* The context satisfies both GeneratorContext and FilterContext interfaces.
|
|
942
|
+
*/
|
|
943
|
+
async buildContext() {
|
|
944
|
+
let userElo = 1e3;
|
|
945
|
+
try {
|
|
946
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
947
|
+
const courseElo = (0, import_common5.toCourseElo)(courseReg.elo);
|
|
948
|
+
userElo = courseElo.global.score;
|
|
949
|
+
} catch (e) {
|
|
950
|
+
logger.debug(`[Pipeline] Could not get user ELO, using default: ${e}`);
|
|
951
|
+
}
|
|
952
|
+
return {
|
|
953
|
+
user: this.user,
|
|
954
|
+
course: this.course,
|
|
955
|
+
userElo
|
|
956
|
+
};
|
|
957
|
+
}
|
|
958
|
+
// ===========================================================================
|
|
959
|
+
// Legacy StudyContentSource methods
|
|
960
|
+
// ===========================================================================
|
|
961
|
+
//
|
|
962
|
+
// These delegate to the generator for backward compatibility.
|
|
963
|
+
// Eventually SessionController will use getWeightedCards() exclusively.
|
|
964
|
+
//
|
|
965
|
+
/**
|
|
966
|
+
* Get new cards via legacy API.
|
|
967
|
+
* Delegates to the generator if it supports the legacy interface.
|
|
968
|
+
*/
|
|
969
|
+
async getNewCards(n) {
|
|
970
|
+
if ("getNewCards" in this.generator && typeof this.generator.getNewCards === "function") {
|
|
971
|
+
return this.generator.getNewCards(n);
|
|
972
|
+
}
|
|
973
|
+
return [];
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* Get pending reviews via legacy API.
|
|
977
|
+
* Delegates to the generator if it supports the legacy interface.
|
|
978
|
+
*/
|
|
979
|
+
async getPendingReviews() {
|
|
980
|
+
if ("getPendingReviews" in this.generator && typeof this.generator.getPendingReviews === "function") {
|
|
981
|
+
return this.generator.getPendingReviews();
|
|
982
|
+
}
|
|
983
|
+
return [];
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Get the course ID for this pipeline.
|
|
987
|
+
*/
|
|
988
|
+
getCourseID() {
|
|
989
|
+
return this.course.getCourseID();
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
});
|
|
994
|
+
|
|
995
|
+
// src/core/navigators/PipelineAssembler.ts
|
|
996
|
+
var PipelineAssembler_exports = {};
|
|
997
|
+
__export(PipelineAssembler_exports, {
|
|
998
|
+
PipelineAssembler: () => PipelineAssembler
|
|
999
|
+
});
|
|
1000
|
+
var PipelineAssembler;
|
|
1001
|
+
var init_PipelineAssembler = __esm({
|
|
1002
|
+
"src/core/navigators/PipelineAssembler.ts"() {
|
|
1003
|
+
"use strict";
|
|
1004
|
+
init_navigators();
|
|
1005
|
+
init_Pipeline();
|
|
1006
|
+
init_types_legacy();
|
|
1007
|
+
init_logger();
|
|
1008
|
+
init_CompositeGenerator();
|
|
1009
|
+
PipelineAssembler = class {
|
|
1010
|
+
/**
|
|
1011
|
+
* Assembles a navigation pipeline from strategy documents.
|
|
1012
|
+
*
|
|
1013
|
+
* 1. Separates into generators and filters by role
|
|
1014
|
+
* 2. Validates at least one generator exists (or creates default ELO)
|
|
1015
|
+
* 3. Instantiates generators - wraps multiple in CompositeGenerator
|
|
1016
|
+
* 4. Instantiates filters
|
|
1017
|
+
* 5. Returns Pipeline(generator, filters)
|
|
1018
|
+
*
|
|
1019
|
+
* @param input - Strategy documents plus user/course interfaces
|
|
1020
|
+
* @returns Assembled pipeline and any warnings
|
|
1021
|
+
*/
|
|
1022
|
+
async assemble(input) {
|
|
1023
|
+
const { strategies, user, course } = input;
|
|
1024
|
+
const warnings = [];
|
|
1025
|
+
if (strategies.length === 0) {
|
|
1026
|
+
return {
|
|
1027
|
+
pipeline: null,
|
|
1028
|
+
generatorStrategies: [],
|
|
1029
|
+
filterStrategies: [],
|
|
1030
|
+
warnings
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1033
|
+
const generatorStrategies = [];
|
|
1034
|
+
const filterStrategies = [];
|
|
1035
|
+
for (const s of strategies) {
|
|
1036
|
+
if (isGenerator(s.implementingClass)) {
|
|
1037
|
+
generatorStrategies.push(s);
|
|
1038
|
+
} else if (isFilter(s.implementingClass)) {
|
|
1039
|
+
filterStrategies.push(s);
|
|
1040
|
+
} else {
|
|
1041
|
+
warnings.push(`Unknown strategy type '${s.implementingClass}', skipping: ${s.name}`);
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
if (generatorStrategies.length === 0) {
|
|
1045
|
+
if (filterStrategies.length > 0) {
|
|
1046
|
+
logger.debug(
|
|
1047
|
+
"[PipelineAssembler] No generator found, using default ELO with configured filters"
|
|
1048
|
+
);
|
|
1049
|
+
generatorStrategies.push(this.makeDefaultEloStrategy(course.getCourseID()));
|
|
1050
|
+
} else {
|
|
1051
|
+
warnings.push("No generator strategy found");
|
|
1052
|
+
return {
|
|
1053
|
+
pipeline: null,
|
|
1054
|
+
generatorStrategies: [],
|
|
1055
|
+
filterStrategies: [],
|
|
1056
|
+
warnings
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
let generator;
|
|
1061
|
+
if (generatorStrategies.length === 1) {
|
|
1062
|
+
const nav = await ContentNavigator.create(user, course, generatorStrategies[0]);
|
|
1063
|
+
generator = nav;
|
|
1064
|
+
logger.debug(`[PipelineAssembler] Using single generator: ${generatorStrategies[0].name}`);
|
|
1065
|
+
} else {
|
|
1066
|
+
logger.debug(
|
|
1067
|
+
`[PipelineAssembler] Using CompositeGenerator for ${generatorStrategies.length} generators: ${generatorStrategies.map((g) => g.name).join(", ")}`
|
|
1068
|
+
);
|
|
1069
|
+
generator = await CompositeGenerator.fromStrategies(user, course, generatorStrategies);
|
|
1070
|
+
}
|
|
1071
|
+
const filters = [];
|
|
1072
|
+
const sortedFilterStrategies = [...filterStrategies].sort(
|
|
1073
|
+
(a, b) => a.name.localeCompare(b.name)
|
|
1074
|
+
);
|
|
1075
|
+
for (const filterStrategy of sortedFilterStrategies) {
|
|
1076
|
+
try {
|
|
1077
|
+
const nav = await ContentNavigator.create(user, course, filterStrategy);
|
|
1078
|
+
if ("transform" in nav && typeof nav.transform === "function") {
|
|
1079
|
+
filters.push(nav);
|
|
1080
|
+
logger.debug(`[PipelineAssembler] Added filter: ${filterStrategy.name}`);
|
|
1081
|
+
} else {
|
|
1082
|
+
warnings.push(
|
|
1083
|
+
`Filter '${filterStrategy.name}' does not implement CardFilter.transform(), skipping`
|
|
1084
|
+
);
|
|
1085
|
+
}
|
|
1086
|
+
} catch (e) {
|
|
1087
|
+
warnings.push(`Failed to instantiate filter '${filterStrategy.name}': ${e}`);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
const pipeline = new Pipeline(generator, filters, user, course);
|
|
1091
|
+
logger.debug(
|
|
1092
|
+
`[PipelineAssembler] Assembled pipeline with ${generatorStrategies.length} generator(s) and ${filters.length} filter(s)`
|
|
1093
|
+
);
|
|
1094
|
+
return {
|
|
1095
|
+
pipeline,
|
|
1096
|
+
generatorStrategies,
|
|
1097
|
+
filterStrategies: sortedFilterStrategies,
|
|
1098
|
+
warnings
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Creates a default ELO generator strategy.
|
|
1103
|
+
* Used when filters are configured but no generator is specified.
|
|
1104
|
+
*/
|
|
1105
|
+
makeDefaultEloStrategy(courseId) {
|
|
1106
|
+
return {
|
|
1107
|
+
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
1108
|
+
course: courseId,
|
|
1109
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1110
|
+
name: "ELO (default)",
|
|
1111
|
+
description: "Default ELO-based generator",
|
|
1112
|
+
implementingClass: "elo" /* ELO */,
|
|
1113
|
+
serializedData: ""
|
|
1114
|
+
};
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
1119
|
+
|
|
624
1120
|
// src/core/navigators/elo.ts
|
|
625
1121
|
var elo_exports = {};
|
|
626
1122
|
__export(elo_exports, {
|
|
627
1123
|
default: () => ELONavigator
|
|
628
1124
|
});
|
|
629
|
-
var ELONavigator;
|
|
1125
|
+
var import_common6, ELONavigator;
|
|
630
1126
|
var init_elo = __esm({
|
|
631
1127
|
"src/core/navigators/elo.ts"() {
|
|
632
1128
|
"use strict";
|
|
633
1129
|
init_navigators();
|
|
1130
|
+
import_common6 = require("@vue-skuilder/common");
|
|
634
1131
|
ELONavigator = class extends ContentNavigator {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
constructor(user, course) {
|
|
638
|
-
super();
|
|
639
|
-
this.
|
|
640
|
-
this.course = course;
|
|
1132
|
+
/** Human-readable name for CardGenerator interface */
|
|
1133
|
+
name;
|
|
1134
|
+
constructor(user, course, strategyData) {
|
|
1135
|
+
super(user, course, strategyData);
|
|
1136
|
+
this.name = strategyData?.name || "ELO";
|
|
641
1137
|
}
|
|
642
1138
|
async getPendingReviews() {
|
|
643
1139
|
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
@@ -683,10 +1179,283 @@ var init_elo = __esm({
|
|
|
683
1179
|
};
|
|
684
1180
|
});
|
|
685
1181
|
}
|
|
1182
|
+
/**
|
|
1183
|
+
* Get new cards with suitability scores based on ELO distance.
|
|
1184
|
+
*
|
|
1185
|
+
* Cards closer to user's ELO get higher scores.
|
|
1186
|
+
* Score formula: max(0, 1 - distance / 500)
|
|
1187
|
+
*
|
|
1188
|
+
* NOTE: This generator only handles NEW cards. Reviews are handled by
|
|
1189
|
+
* SRSNavigator. Use CompositeGenerator to combine both.
|
|
1190
|
+
*
|
|
1191
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1192
|
+
* CardGenerator interface signature (limit, context).
|
|
1193
|
+
*
|
|
1194
|
+
* @param limit - Maximum number of cards to return
|
|
1195
|
+
* @param context - Optional GeneratorContext (used when called via Pipeline)
|
|
1196
|
+
*/
|
|
1197
|
+
async getWeightedCards(limit, context) {
|
|
1198
|
+
let userGlobalElo;
|
|
1199
|
+
if (context?.userElo !== void 0) {
|
|
1200
|
+
userGlobalElo = context.userElo;
|
|
1201
|
+
} else {
|
|
1202
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
1203
|
+
const userElo = (0, import_common6.toCourseElo)(courseReg.elo);
|
|
1204
|
+
userGlobalElo = userElo.global.score;
|
|
1205
|
+
}
|
|
1206
|
+
const newCards = await this.getNewCards(limit);
|
|
1207
|
+
const cardIds = newCards.map((c) => c.cardID);
|
|
1208
|
+
const cardEloData = await this.course.getCardEloData(cardIds);
|
|
1209
|
+
const scored = newCards.map((c, i) => {
|
|
1210
|
+
const cardElo = cardEloData[i]?.global?.score ?? 1e3;
|
|
1211
|
+
const distance = Math.abs(cardElo - userGlobalElo);
|
|
1212
|
+
const score = Math.max(0, 1 - distance / 500);
|
|
1213
|
+
return {
|
|
1214
|
+
cardId: c.cardID,
|
|
1215
|
+
courseId: c.courseID,
|
|
1216
|
+
score,
|
|
1217
|
+
provenance: [
|
|
1218
|
+
{
|
|
1219
|
+
strategy: "elo",
|
|
1220
|
+
strategyName: this.strategyName || this.name,
|
|
1221
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-ELO-default",
|
|
1222
|
+
action: "generated",
|
|
1223
|
+
score,
|
|
1224
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userGlobalElo)}), new card`
|
|
1225
|
+
}
|
|
1226
|
+
]
|
|
1227
|
+
};
|
|
1228
|
+
});
|
|
1229
|
+
scored.sort((a, b) => b.score - a.score);
|
|
1230
|
+
return scored.slice(0, limit);
|
|
1231
|
+
}
|
|
686
1232
|
};
|
|
687
1233
|
}
|
|
688
1234
|
});
|
|
689
1235
|
|
|
1236
|
+
// src/core/navigators/filters/eloDistance.ts
|
|
1237
|
+
var eloDistance_exports = {};
|
|
1238
|
+
__export(eloDistance_exports, {
|
|
1239
|
+
DEFAULT_HALF_LIFE: () => DEFAULT_HALF_LIFE,
|
|
1240
|
+
DEFAULT_MAX_MULTIPLIER: () => DEFAULT_MAX_MULTIPLIER,
|
|
1241
|
+
DEFAULT_MIN_MULTIPLIER: () => DEFAULT_MIN_MULTIPLIER,
|
|
1242
|
+
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1243
|
+
});
|
|
1244
|
+
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
1245
|
+
const normalizedDistance = distance / halfLife;
|
|
1246
|
+
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
1247
|
+
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
1248
|
+
}
|
|
1249
|
+
function createEloDistanceFilter(config) {
|
|
1250
|
+
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
1251
|
+
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
1252
|
+
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
1253
|
+
return {
|
|
1254
|
+
name: "ELO Distance Filter",
|
|
1255
|
+
async transform(cards, context) {
|
|
1256
|
+
const { course, userElo } = context;
|
|
1257
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
1258
|
+
const cardElos = await course.getCardEloData(cardIds);
|
|
1259
|
+
return cards.map((card, i) => {
|
|
1260
|
+
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
1261
|
+
const distance = Math.abs(cardElo - userElo);
|
|
1262
|
+
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
1263
|
+
const newScore = card.score * multiplier;
|
|
1264
|
+
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
1265
|
+
return {
|
|
1266
|
+
...card,
|
|
1267
|
+
score: newScore,
|
|
1268
|
+
provenance: [
|
|
1269
|
+
...card.provenance,
|
|
1270
|
+
{
|
|
1271
|
+
strategy: "eloDistance",
|
|
1272
|
+
strategyName: "ELO Distance Filter",
|
|
1273
|
+
strategyId: "ELO_DISTANCE_FILTER",
|
|
1274
|
+
action,
|
|
1275
|
+
score: newScore,
|
|
1276
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
1277
|
+
}
|
|
1278
|
+
]
|
|
1279
|
+
};
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
};
|
|
1283
|
+
}
|
|
1284
|
+
var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
|
|
1285
|
+
var init_eloDistance = __esm({
|
|
1286
|
+
"src/core/navigators/filters/eloDistance.ts"() {
|
|
1287
|
+
"use strict";
|
|
1288
|
+
DEFAULT_HALF_LIFE = 200;
|
|
1289
|
+
DEFAULT_MIN_MULTIPLIER = 0.3;
|
|
1290
|
+
DEFAULT_MAX_MULTIPLIER = 1;
|
|
1291
|
+
}
|
|
1292
|
+
});
|
|
1293
|
+
|
|
1294
|
+
// src/core/navigators/filters/userTagPreference.ts
|
|
1295
|
+
var userTagPreference_exports = {};
|
|
1296
|
+
__export(userTagPreference_exports, {
|
|
1297
|
+
default: () => UserTagPreferenceFilter
|
|
1298
|
+
});
|
|
1299
|
+
var UserTagPreferenceFilter;
|
|
1300
|
+
var init_userTagPreference = __esm({
|
|
1301
|
+
"src/core/navigators/filters/userTagPreference.ts"() {
|
|
1302
|
+
"use strict";
|
|
1303
|
+
init_navigators();
|
|
1304
|
+
UserTagPreferenceFilter = class extends ContentNavigator {
|
|
1305
|
+
_strategyData;
|
|
1306
|
+
/** Human-readable name for CardFilter interface */
|
|
1307
|
+
name;
|
|
1308
|
+
constructor(user, course, strategyData) {
|
|
1309
|
+
super(user, course, strategyData);
|
|
1310
|
+
this._strategyData = strategyData;
|
|
1311
|
+
this.name = strategyData.name || "User Tag Preferences";
|
|
1312
|
+
}
|
|
1313
|
+
/**
|
|
1314
|
+
* Compute multiplier for a card based on its tags and user preferences.
|
|
1315
|
+
* Returns the maximum multiplier among all matching tags, or 1.0 if no matches.
|
|
1316
|
+
*/
|
|
1317
|
+
computeMultiplier(cardTags, boostMap) {
|
|
1318
|
+
const multipliers = cardTags.map((tag) => boostMap[tag]).filter((val) => val !== void 0);
|
|
1319
|
+
if (multipliers.length === 0) {
|
|
1320
|
+
return 1;
|
|
1321
|
+
}
|
|
1322
|
+
return Math.max(...multipliers);
|
|
1323
|
+
}
|
|
1324
|
+
/**
|
|
1325
|
+
* Build human-readable reason for the filter's decision.
|
|
1326
|
+
*/
|
|
1327
|
+
buildReason(cardTags, boostMap, multiplier) {
|
|
1328
|
+
const matchingTags = cardTags.filter((tag) => boostMap[tag] === multiplier);
|
|
1329
|
+
if (multiplier === 0) {
|
|
1330
|
+
return `Excluded by user preference: ${matchingTags.join(", ")} (${multiplier}x)`;
|
|
1331
|
+
}
|
|
1332
|
+
if (multiplier < 1) {
|
|
1333
|
+
return `Penalized by user preference: ${matchingTags.join(", ")} (${multiplier.toFixed(2)}x)`;
|
|
1334
|
+
}
|
|
1335
|
+
if (multiplier > 1) {
|
|
1336
|
+
return `Boosted by user preference: ${matchingTags.join(", ")} (${multiplier.toFixed(2)}x)`;
|
|
1337
|
+
}
|
|
1338
|
+
return "No matching user preferences";
|
|
1339
|
+
}
|
|
1340
|
+
/**
|
|
1341
|
+
* CardFilter.transform implementation.
|
|
1342
|
+
*
|
|
1343
|
+
* Apply user tag preferences:
|
|
1344
|
+
* 1. Read preferences from strategy state
|
|
1345
|
+
* 2. If no preferences, pass through unchanged
|
|
1346
|
+
* 3. For each card:
|
|
1347
|
+
* - Look up tag in boost record
|
|
1348
|
+
* - If tag found: apply multiplier (0 = exclude, 1 = neutral, >1 = boost)
|
|
1349
|
+
* - If multiple tags match: use max multiplier
|
|
1350
|
+
* - Append provenance with clear reason
|
|
1351
|
+
*/
|
|
1352
|
+
async transform(cards, _context) {
|
|
1353
|
+
const prefs = await this.getStrategyState();
|
|
1354
|
+
if (!prefs || Object.keys(prefs.boost).length === 0) {
|
|
1355
|
+
return cards.map((card) => ({
|
|
1356
|
+
...card,
|
|
1357
|
+
provenance: [
|
|
1358
|
+
...card.provenance,
|
|
1359
|
+
{
|
|
1360
|
+
strategy: "userTagPreference",
|
|
1361
|
+
strategyName: this.strategyName || this.name,
|
|
1362
|
+
strategyId: this.strategyId || this._strategyData._id,
|
|
1363
|
+
action: "passed",
|
|
1364
|
+
score: card.score,
|
|
1365
|
+
reason: "No user tag preferences configured"
|
|
1366
|
+
}
|
|
1367
|
+
]
|
|
1368
|
+
}));
|
|
1369
|
+
}
|
|
1370
|
+
const adjusted = await Promise.all(
|
|
1371
|
+
cards.map(async (card) => {
|
|
1372
|
+
const cardTags = card.tags ?? [];
|
|
1373
|
+
const multiplier = this.computeMultiplier(cardTags, prefs.boost);
|
|
1374
|
+
const finalScore = Math.min(1, card.score * multiplier);
|
|
1375
|
+
let action;
|
|
1376
|
+
if (multiplier === 0 || multiplier < 1) {
|
|
1377
|
+
action = "penalized";
|
|
1378
|
+
} else if (multiplier > 1) {
|
|
1379
|
+
action = "boosted";
|
|
1380
|
+
} else {
|
|
1381
|
+
action = "passed";
|
|
1382
|
+
}
|
|
1383
|
+
return {
|
|
1384
|
+
...card,
|
|
1385
|
+
score: finalScore,
|
|
1386
|
+
provenance: [
|
|
1387
|
+
...card.provenance,
|
|
1388
|
+
{
|
|
1389
|
+
strategy: "userTagPreference",
|
|
1390
|
+
strategyName: this.strategyName || this.name,
|
|
1391
|
+
strategyId: this.strategyId || this._strategyData._id,
|
|
1392
|
+
action,
|
|
1393
|
+
score: finalScore,
|
|
1394
|
+
reason: this.buildReason(cardTags, prefs.boost, multiplier)
|
|
1395
|
+
}
|
|
1396
|
+
]
|
|
1397
|
+
};
|
|
1398
|
+
})
|
|
1399
|
+
);
|
|
1400
|
+
return adjusted;
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Legacy getWeightedCards - throws as filters should not be used as generators.
|
|
1404
|
+
*/
|
|
1405
|
+
async getWeightedCards(_limit) {
|
|
1406
|
+
throw new Error(
|
|
1407
|
+
"UserTagPreferenceFilter is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1408
|
+
);
|
|
1409
|
+
}
|
|
1410
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1411
|
+
async getNewCards(_n) {
|
|
1412
|
+
return [];
|
|
1413
|
+
}
|
|
1414
|
+
async getPendingReviews() {
|
|
1415
|
+
return [];
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
}
|
|
1419
|
+
});
|
|
1420
|
+
|
|
1421
|
+
// src/core/navigators/filters/index.ts
|
|
1422
|
+
var filters_exports = {};
|
|
1423
|
+
__export(filters_exports, {
|
|
1424
|
+
UserTagPreferenceFilter: () => UserTagPreferenceFilter,
|
|
1425
|
+
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1426
|
+
});
|
|
1427
|
+
var init_filters = __esm({
|
|
1428
|
+
"src/core/navigators/filters/index.ts"() {
|
|
1429
|
+
"use strict";
|
|
1430
|
+
init_eloDistance();
|
|
1431
|
+
init_userTagPreference();
|
|
1432
|
+
}
|
|
1433
|
+
});
|
|
1434
|
+
|
|
1435
|
+
// src/core/navigators/filters/types.ts
|
|
1436
|
+
var types_exports = {};
|
|
1437
|
+
var init_types = __esm({
|
|
1438
|
+
"src/core/navigators/filters/types.ts"() {
|
|
1439
|
+
"use strict";
|
|
1440
|
+
}
|
|
1441
|
+
});
|
|
1442
|
+
|
|
1443
|
+
// src/core/navigators/generators/index.ts
|
|
1444
|
+
var generators_exports = {};
|
|
1445
|
+
var init_generators = __esm({
|
|
1446
|
+
"src/core/navigators/generators/index.ts"() {
|
|
1447
|
+
"use strict";
|
|
1448
|
+
}
|
|
1449
|
+
});
|
|
1450
|
+
|
|
1451
|
+
// src/core/navigators/generators/types.ts
|
|
1452
|
+
var types_exports2 = {};
|
|
1453
|
+
var init_types2 = __esm({
|
|
1454
|
+
"src/core/navigators/generators/types.ts"() {
|
|
1455
|
+
"use strict";
|
|
1456
|
+
}
|
|
1457
|
+
});
|
|
1458
|
+
|
|
690
1459
|
// src/core/navigators/hardcodedOrder.ts
|
|
691
1460
|
var hardcodedOrder_exports = {};
|
|
692
1461
|
__export(hardcodedOrder_exports, {
|
|
@@ -699,13 +1468,12 @@ var init_hardcodedOrder = __esm({
|
|
|
699
1468
|
init_navigators();
|
|
700
1469
|
init_logger();
|
|
701
1470
|
HardcodedOrderNavigator = class extends ContentNavigator {
|
|
1471
|
+
/** Human-readable name for CardGenerator interface */
|
|
1472
|
+
name;
|
|
702
1473
|
orderedCardIds = [];
|
|
703
|
-
user;
|
|
704
|
-
course;
|
|
705
1474
|
constructor(user, course, strategyData) {
|
|
706
|
-
super();
|
|
707
|
-
this.
|
|
708
|
-
this.course = course;
|
|
1475
|
+
super(user, course, strategyData);
|
|
1476
|
+
this.name = strategyData.name || "Hardcoded Order";
|
|
709
1477
|
if (strategyData.serializedData) {
|
|
710
1478
|
try {
|
|
711
1479
|
this.orderedCardIds = JSON.parse(strategyData.serializedData);
|
|
@@ -730,32 +1498,806 @@ var init_hardcodedOrder = __esm({
|
|
|
730
1498
|
}
|
|
731
1499
|
async getNewCards(limit = 99) {
|
|
732
1500
|
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
733
|
-
const newCardIds = this.orderedCardIds.filter(
|
|
734
|
-
(cardId) => !activeCardIds.includes(cardId)
|
|
735
|
-
);
|
|
1501
|
+
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
736
1502
|
const cardsToReturn = newCardIds.slice(0, limit);
|
|
737
1503
|
return cardsToReturn.map((cardId) => {
|
|
738
1504
|
return {
|
|
739
|
-
cardID: cardId,
|
|
740
|
-
courseID: this.course.getCourseID(),
|
|
741
|
-
contentSourceType: "course",
|
|
742
|
-
contentSourceID: this.course.getCourseID(),
|
|
743
|
-
status: "new"
|
|
1505
|
+
cardID: cardId,
|
|
1506
|
+
courseID: this.course.getCourseID(),
|
|
1507
|
+
contentSourceType: "course",
|
|
1508
|
+
contentSourceID: this.course.getCourseID(),
|
|
1509
|
+
status: "new"
|
|
1510
|
+
};
|
|
1511
|
+
});
|
|
1512
|
+
}
|
|
1513
|
+
/**
|
|
1514
|
+
* Get cards in hardcoded order with scores based on position.
|
|
1515
|
+
*
|
|
1516
|
+
* Earlier cards in the sequence get higher scores.
|
|
1517
|
+
* Score formula: 1.0 - (position / totalCards) * 0.5
|
|
1518
|
+
* This ensures scores range from 1.0 (first card) to 0.5+ (last card).
|
|
1519
|
+
*
|
|
1520
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1521
|
+
* CardGenerator interface signature (limit, context).
|
|
1522
|
+
*
|
|
1523
|
+
* @param limit - Maximum number of cards to return
|
|
1524
|
+
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1525
|
+
*/
|
|
1526
|
+
async getWeightedCards(limit, _context) {
|
|
1527
|
+
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1528
|
+
const reviews = await this.getPendingReviews();
|
|
1529
|
+
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1530
|
+
const totalCards = newCardIds.length;
|
|
1531
|
+
const scoredNew = newCardIds.slice(0, limit).map((cardId, index) => {
|
|
1532
|
+
const position = index + 1;
|
|
1533
|
+
const score = Math.max(0.5, 1 - index / totalCards * 0.5);
|
|
1534
|
+
return {
|
|
1535
|
+
cardId,
|
|
1536
|
+
courseId: this.course.getCourseID(),
|
|
1537
|
+
score,
|
|
1538
|
+
provenance: [
|
|
1539
|
+
{
|
|
1540
|
+
strategy: "hardcodedOrder",
|
|
1541
|
+
strategyName: this.strategyName || this.name,
|
|
1542
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1543
|
+
action: "generated",
|
|
1544
|
+
score,
|
|
1545
|
+
reason: `Position ${position} of ${totalCards} in fixed sequence, new card`
|
|
1546
|
+
}
|
|
1547
|
+
]
|
|
1548
|
+
};
|
|
1549
|
+
});
|
|
1550
|
+
const scoredReviews = reviews.map((r) => ({
|
|
1551
|
+
cardId: r.cardID,
|
|
1552
|
+
courseId: r.courseID,
|
|
1553
|
+
score: 1,
|
|
1554
|
+
provenance: [
|
|
1555
|
+
{
|
|
1556
|
+
strategy: "hardcodedOrder",
|
|
1557
|
+
strategyName: this.strategyName || this.name,
|
|
1558
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1559
|
+
action: "generated",
|
|
1560
|
+
score: 1,
|
|
1561
|
+
reason: "Scheduled review, highest priority"
|
|
1562
|
+
}
|
|
1563
|
+
]
|
|
1564
|
+
}));
|
|
1565
|
+
const all = [...scoredReviews, ...scoredNew];
|
|
1566
|
+
all.sort((a, b) => b.score - a.score);
|
|
1567
|
+
return all.slice(0, limit);
|
|
1568
|
+
}
|
|
1569
|
+
};
|
|
1570
|
+
}
|
|
1571
|
+
});
|
|
1572
|
+
|
|
1573
|
+
// src/core/navigators/hierarchyDefinition.ts
|
|
1574
|
+
var hierarchyDefinition_exports = {};
|
|
1575
|
+
__export(hierarchyDefinition_exports, {
|
|
1576
|
+
default: () => HierarchyDefinitionNavigator
|
|
1577
|
+
});
|
|
1578
|
+
var import_common7, DEFAULT_MIN_COUNT, HierarchyDefinitionNavigator;
|
|
1579
|
+
var init_hierarchyDefinition = __esm({
|
|
1580
|
+
"src/core/navigators/hierarchyDefinition.ts"() {
|
|
1581
|
+
"use strict";
|
|
1582
|
+
init_navigators();
|
|
1583
|
+
import_common7 = require("@vue-skuilder/common");
|
|
1584
|
+
DEFAULT_MIN_COUNT = 3;
|
|
1585
|
+
HierarchyDefinitionNavigator = class extends ContentNavigator {
|
|
1586
|
+
config;
|
|
1587
|
+
_strategyData;
|
|
1588
|
+
/** Human-readable name for CardFilter interface */
|
|
1589
|
+
name;
|
|
1590
|
+
constructor(user, course, _strategyData) {
|
|
1591
|
+
super(user, course, _strategyData);
|
|
1592
|
+
this._strategyData = _strategyData;
|
|
1593
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1594
|
+
this.name = _strategyData.name || "Hierarchy Definition";
|
|
1595
|
+
}
|
|
1596
|
+
parseConfig(serializedData) {
|
|
1597
|
+
try {
|
|
1598
|
+
const parsed = JSON.parse(serializedData);
|
|
1599
|
+
return {
|
|
1600
|
+
prerequisites: parsed.prerequisites || {}
|
|
1601
|
+
};
|
|
1602
|
+
} catch {
|
|
1603
|
+
return {
|
|
1604
|
+
prerequisites: {}
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
/**
|
|
1609
|
+
* Check if a specific prerequisite is satisfied
|
|
1610
|
+
*/
|
|
1611
|
+
isPrerequisiteMet(prereq, userTagElo, userGlobalElo) {
|
|
1612
|
+
if (!userTagElo) return false;
|
|
1613
|
+
const minCount = prereq.masteryThreshold?.minCount ?? DEFAULT_MIN_COUNT;
|
|
1614
|
+
if (userTagElo.count < minCount) return false;
|
|
1615
|
+
if (prereq.masteryThreshold?.minElo !== void 0) {
|
|
1616
|
+
return userTagElo.score >= prereq.masteryThreshold.minElo;
|
|
1617
|
+
} else {
|
|
1618
|
+
return userTagElo.score >= userGlobalElo;
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
/**
|
|
1622
|
+
* Get the set of tags the user has mastered.
|
|
1623
|
+
* A tag is "mastered" if it appears as a prerequisite somewhere and meets its threshold.
|
|
1624
|
+
*/
|
|
1625
|
+
async getMasteredTags(context) {
|
|
1626
|
+
const mastered = /* @__PURE__ */ new Set();
|
|
1627
|
+
try {
|
|
1628
|
+
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1629
|
+
const userElo = (0, import_common7.toCourseElo)(courseReg.elo);
|
|
1630
|
+
for (const prereqs of Object.values(this.config.prerequisites)) {
|
|
1631
|
+
for (const prereq of prereqs) {
|
|
1632
|
+
const tagElo = userElo.tags[prereq.tag];
|
|
1633
|
+
if (this.isPrerequisiteMet(prereq, tagElo, userElo.global.score)) {
|
|
1634
|
+
mastered.add(prereq.tag);
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
} catch {
|
|
1639
|
+
}
|
|
1640
|
+
return mastered;
|
|
1641
|
+
}
|
|
1642
|
+
/**
|
|
1643
|
+
* Get the set of tags that are unlocked (prerequisites met)
|
|
1644
|
+
*/
|
|
1645
|
+
getUnlockedTags(masteredTags) {
|
|
1646
|
+
const unlocked = /* @__PURE__ */ new Set();
|
|
1647
|
+
for (const [tagId, prereqs] of Object.entries(this.config.prerequisites)) {
|
|
1648
|
+
const allPrereqsMet = prereqs.every((prereq) => masteredTags.has(prereq.tag));
|
|
1649
|
+
if (allPrereqsMet) {
|
|
1650
|
+
unlocked.add(tagId);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
return unlocked;
|
|
1654
|
+
}
|
|
1655
|
+
/**
|
|
1656
|
+
* Check if a tag has prerequisites defined in config
|
|
1657
|
+
*/
|
|
1658
|
+
hasPrerequisites(tagId) {
|
|
1659
|
+
return tagId in this.config.prerequisites;
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1662
|
+
* Check if a card is unlocked and generate reason.
|
|
1663
|
+
*/
|
|
1664
|
+
async checkCardUnlock(card, course, unlockedTags, masteredTags) {
|
|
1665
|
+
try {
|
|
1666
|
+
const cardTags = card.tags ?? [];
|
|
1667
|
+
const lockedTags = cardTags.filter(
|
|
1668
|
+
(tag) => this.hasPrerequisites(tag) && !unlockedTags.has(tag)
|
|
1669
|
+
);
|
|
1670
|
+
if (lockedTags.length === 0) {
|
|
1671
|
+
const tagList = cardTags.length > 0 ? cardTags.join(", ") : "none";
|
|
1672
|
+
return {
|
|
1673
|
+
isUnlocked: true,
|
|
1674
|
+
reason: `Prerequisites met, tags: ${tagList}`
|
|
1675
|
+
};
|
|
1676
|
+
}
|
|
1677
|
+
const missingPrereqs = lockedTags.flatMap((tag) => {
|
|
1678
|
+
const prereqs = this.config.prerequisites[tag] || [];
|
|
1679
|
+
return prereqs.filter((p) => !masteredTags.has(p.tag)).map((p) => p.tag);
|
|
1680
|
+
});
|
|
1681
|
+
return {
|
|
1682
|
+
isUnlocked: false,
|
|
1683
|
+
reason: `Blocked: missing prerequisites ${missingPrereqs.join(", ")} for tags ${lockedTags.join(", ")}`
|
|
1684
|
+
};
|
|
1685
|
+
} catch {
|
|
1686
|
+
return {
|
|
1687
|
+
isUnlocked: true,
|
|
1688
|
+
reason: "Prerequisites check skipped (tag lookup failed)"
|
|
1689
|
+
};
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
/**
|
|
1693
|
+
* CardFilter.transform implementation.
|
|
1694
|
+
*
|
|
1695
|
+
* Apply prerequisite gating to cards. Cards with locked tags receive score: 0.
|
|
1696
|
+
*/
|
|
1697
|
+
async transform(cards, context) {
|
|
1698
|
+
const masteredTags = await this.getMasteredTags(context);
|
|
1699
|
+
const unlockedTags = this.getUnlockedTags(masteredTags);
|
|
1700
|
+
const gated = [];
|
|
1701
|
+
for (const card of cards) {
|
|
1702
|
+
const { isUnlocked, reason } = await this.checkCardUnlock(
|
|
1703
|
+
card,
|
|
1704
|
+
context.course,
|
|
1705
|
+
unlockedTags,
|
|
1706
|
+
masteredTags
|
|
1707
|
+
);
|
|
1708
|
+
const finalScore = isUnlocked ? card.score : 0;
|
|
1709
|
+
const action = isUnlocked ? "passed" : "penalized";
|
|
1710
|
+
gated.push({
|
|
1711
|
+
...card,
|
|
1712
|
+
score: finalScore,
|
|
1713
|
+
provenance: [
|
|
1714
|
+
...card.provenance,
|
|
1715
|
+
{
|
|
1716
|
+
strategy: "hierarchyDefinition",
|
|
1717
|
+
strategyName: this.strategyName || this.name,
|
|
1718
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hierarchy",
|
|
1719
|
+
action,
|
|
1720
|
+
score: finalScore,
|
|
1721
|
+
reason
|
|
1722
|
+
}
|
|
1723
|
+
]
|
|
1724
|
+
});
|
|
1725
|
+
}
|
|
1726
|
+
return gated;
|
|
1727
|
+
}
|
|
1728
|
+
/**
|
|
1729
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1730
|
+
*
|
|
1731
|
+
* Use transform() via Pipeline instead.
|
|
1732
|
+
*/
|
|
1733
|
+
async getWeightedCards(_limit) {
|
|
1734
|
+
throw new Error(
|
|
1735
|
+
"HierarchyDefinitionNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1736
|
+
);
|
|
1737
|
+
}
|
|
1738
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1739
|
+
async getNewCards(_n) {
|
|
1740
|
+
return [];
|
|
1741
|
+
}
|
|
1742
|
+
async getPendingReviews() {
|
|
1743
|
+
return [];
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1746
|
+
}
|
|
1747
|
+
});
|
|
1748
|
+
|
|
1749
|
+
// src/core/navigators/inferredPreference.ts
|
|
1750
|
+
var inferredPreference_exports = {};
|
|
1751
|
+
__export(inferredPreference_exports, {
|
|
1752
|
+
INFERRED_PREFERENCE_NAVIGATOR_STUB: () => INFERRED_PREFERENCE_NAVIGATOR_STUB
|
|
1753
|
+
});
|
|
1754
|
+
var INFERRED_PREFERENCE_NAVIGATOR_STUB;
|
|
1755
|
+
var init_inferredPreference = __esm({
|
|
1756
|
+
"src/core/navigators/inferredPreference.ts"() {
|
|
1757
|
+
"use strict";
|
|
1758
|
+
INFERRED_PREFERENCE_NAVIGATOR_STUB = true;
|
|
1759
|
+
}
|
|
1760
|
+
});
|
|
1761
|
+
|
|
1762
|
+
// src/core/navigators/interferenceMitigator.ts
|
|
1763
|
+
var interferenceMitigator_exports = {};
|
|
1764
|
+
__export(interferenceMitigator_exports, {
|
|
1765
|
+
default: () => InterferenceMitigatorNavigator
|
|
1766
|
+
});
|
|
1767
|
+
var import_common8, DEFAULT_MIN_COUNT2, DEFAULT_MIN_ELAPSED_DAYS, DEFAULT_INTERFERENCE_DECAY, InterferenceMitigatorNavigator;
|
|
1768
|
+
var init_interferenceMitigator = __esm({
|
|
1769
|
+
"src/core/navigators/interferenceMitigator.ts"() {
|
|
1770
|
+
"use strict";
|
|
1771
|
+
init_navigators();
|
|
1772
|
+
import_common8 = require("@vue-skuilder/common");
|
|
1773
|
+
DEFAULT_MIN_COUNT2 = 10;
|
|
1774
|
+
DEFAULT_MIN_ELAPSED_DAYS = 3;
|
|
1775
|
+
DEFAULT_INTERFERENCE_DECAY = 0.8;
|
|
1776
|
+
InterferenceMitigatorNavigator = class extends ContentNavigator {
|
|
1777
|
+
config;
|
|
1778
|
+
_strategyData;
|
|
1779
|
+
/** Human-readable name for CardFilter interface */
|
|
1780
|
+
name;
|
|
1781
|
+
/** Precomputed map: tag -> set of { partner, decay } it interferes with */
|
|
1782
|
+
interferenceMap;
|
|
1783
|
+
constructor(user, course, _strategyData) {
|
|
1784
|
+
super(user, course, _strategyData);
|
|
1785
|
+
this._strategyData = _strategyData;
|
|
1786
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1787
|
+
this.interferenceMap = this.buildInterferenceMap();
|
|
1788
|
+
this.name = _strategyData.name || "Interference Mitigator";
|
|
1789
|
+
}
|
|
1790
|
+
parseConfig(serializedData) {
|
|
1791
|
+
try {
|
|
1792
|
+
const parsed = JSON.parse(serializedData);
|
|
1793
|
+
let sets = parsed.interferenceSets || [];
|
|
1794
|
+
if (sets.length > 0 && Array.isArray(sets[0])) {
|
|
1795
|
+
sets = sets.map((tags) => ({ tags }));
|
|
1796
|
+
}
|
|
1797
|
+
return {
|
|
1798
|
+
interferenceSets: sets,
|
|
1799
|
+
maturityThreshold: {
|
|
1800
|
+
minCount: parsed.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2,
|
|
1801
|
+
minElo: parsed.maturityThreshold?.minElo,
|
|
1802
|
+
minElapsedDays: parsed.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS
|
|
1803
|
+
},
|
|
1804
|
+
defaultDecay: parsed.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY
|
|
1805
|
+
};
|
|
1806
|
+
} catch {
|
|
1807
|
+
return {
|
|
1808
|
+
interferenceSets: [],
|
|
1809
|
+
maturityThreshold: {
|
|
1810
|
+
minCount: DEFAULT_MIN_COUNT2,
|
|
1811
|
+
minElapsedDays: DEFAULT_MIN_ELAPSED_DAYS
|
|
1812
|
+
},
|
|
1813
|
+
defaultDecay: DEFAULT_INTERFERENCE_DECAY
|
|
1814
|
+
};
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
/**
|
|
1818
|
+
* Build a map from each tag to its interference partners with decay coefficients.
|
|
1819
|
+
* If tags A, B, C are in an interference group with decay 0.8, then:
|
|
1820
|
+
* - A interferes with B (decay 0.8) and C (decay 0.8)
|
|
1821
|
+
* - B interferes with A (decay 0.8) and C (decay 0.8)
|
|
1822
|
+
* - etc.
|
|
1823
|
+
*/
|
|
1824
|
+
buildInterferenceMap() {
|
|
1825
|
+
const map = /* @__PURE__ */ new Map();
|
|
1826
|
+
for (const group of this.config.interferenceSets) {
|
|
1827
|
+
const decay = group.decay ?? this.config.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY;
|
|
1828
|
+
for (const tag of group.tags) {
|
|
1829
|
+
if (!map.has(tag)) {
|
|
1830
|
+
map.set(tag, []);
|
|
1831
|
+
}
|
|
1832
|
+
const partners = map.get(tag);
|
|
1833
|
+
for (const other of group.tags) {
|
|
1834
|
+
if (other !== tag) {
|
|
1835
|
+
const existing = partners.find((p) => p.partner === other);
|
|
1836
|
+
if (existing) {
|
|
1837
|
+
existing.decay = Math.max(existing.decay, decay);
|
|
1838
|
+
} else {
|
|
1839
|
+
partners.push({ partner: other, decay });
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
return map;
|
|
1846
|
+
}
|
|
1847
|
+
/**
|
|
1848
|
+
* Get the set of tags that are currently immature for this user.
|
|
1849
|
+
* A tag is immature if the user has interacted with it but hasn't
|
|
1850
|
+
* reached the maturity threshold.
|
|
1851
|
+
*/
|
|
1852
|
+
async getImmatureTags(context) {
|
|
1853
|
+
const immature = /* @__PURE__ */ new Set();
|
|
1854
|
+
try {
|
|
1855
|
+
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1856
|
+
const userElo = (0, import_common8.toCourseElo)(courseReg.elo);
|
|
1857
|
+
const minCount = this.config.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2;
|
|
1858
|
+
const minElo = this.config.maturityThreshold?.minElo;
|
|
1859
|
+
const minElapsedDays = this.config.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS;
|
|
1860
|
+
const minCountForElapsed = minElapsedDays * 2;
|
|
1861
|
+
for (const [tagId, tagElo] of Object.entries(userElo.tags)) {
|
|
1862
|
+
if (tagElo.count === 0) continue;
|
|
1863
|
+
const belowCount = tagElo.count < minCount;
|
|
1864
|
+
const belowElo = minElo !== void 0 && tagElo.score < minElo;
|
|
1865
|
+
const belowElapsed = tagElo.count < minCountForElapsed;
|
|
1866
|
+
if (belowCount || belowElo || belowElapsed) {
|
|
1867
|
+
immature.add(tagId);
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
} catch {
|
|
1871
|
+
}
|
|
1872
|
+
return immature;
|
|
1873
|
+
}
|
|
1874
|
+
/**
|
|
1875
|
+
* Get all tags that interfere with any immature tag, along with their decay coefficients.
|
|
1876
|
+
* These are the tags we want to avoid introducing.
|
|
1877
|
+
*/
|
|
1878
|
+
getTagsToAvoid(immatureTags) {
|
|
1879
|
+
const avoid = /* @__PURE__ */ new Map();
|
|
1880
|
+
for (const immatureTag of immatureTags) {
|
|
1881
|
+
const partners = this.interferenceMap.get(immatureTag);
|
|
1882
|
+
if (partners) {
|
|
1883
|
+
for (const { partner, decay } of partners) {
|
|
1884
|
+
if (!immatureTags.has(partner)) {
|
|
1885
|
+
const existing = avoid.get(partner) ?? 0;
|
|
1886
|
+
avoid.set(partner, Math.max(existing, decay));
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
return avoid;
|
|
1892
|
+
}
|
|
1893
|
+
/**
|
|
1894
|
+
* Compute interference score reduction for a card.
|
|
1895
|
+
* Returns: { multiplier, interfering tags, reason }
|
|
1896
|
+
*/
|
|
1897
|
+
computeInterferenceEffect(cardTags, tagsToAvoid, immatureTags) {
|
|
1898
|
+
if (tagsToAvoid.size === 0) {
|
|
1899
|
+
return {
|
|
1900
|
+
multiplier: 1,
|
|
1901
|
+
interferingTags: [],
|
|
1902
|
+
reason: "No interference detected"
|
|
1903
|
+
};
|
|
1904
|
+
}
|
|
1905
|
+
let multiplier = 1;
|
|
1906
|
+
const interferingTags = [];
|
|
1907
|
+
for (const tag of cardTags) {
|
|
1908
|
+
const decay = tagsToAvoid.get(tag);
|
|
1909
|
+
if (decay !== void 0) {
|
|
1910
|
+
interferingTags.push(tag);
|
|
1911
|
+
multiplier *= 1 - decay;
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
if (interferingTags.length === 0) {
|
|
1915
|
+
return {
|
|
1916
|
+
multiplier: 1,
|
|
1917
|
+
interferingTags: [],
|
|
1918
|
+
reason: "No interference detected"
|
|
1919
|
+
};
|
|
1920
|
+
}
|
|
1921
|
+
const causingTags = /* @__PURE__ */ new Set();
|
|
1922
|
+
for (const tag of interferingTags) {
|
|
1923
|
+
for (const immatureTag of immatureTags) {
|
|
1924
|
+
const partners = this.interferenceMap.get(immatureTag);
|
|
1925
|
+
if (partners?.some((p) => p.partner === tag)) {
|
|
1926
|
+
causingTags.add(immatureTag);
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
const reason = `Interferes with immature tags ${Array.from(causingTags).join(", ")} (tags: ${interferingTags.join(", ")}, multiplier: ${multiplier.toFixed(2)})`;
|
|
1931
|
+
return { multiplier, interferingTags, reason };
|
|
1932
|
+
}
|
|
1933
|
+
/**
|
|
1934
|
+
* CardFilter.transform implementation.
|
|
1935
|
+
*
|
|
1936
|
+
* Apply interference-aware scoring. Cards with tags that interfere with
|
|
1937
|
+
* immature learnings get reduced scores.
|
|
1938
|
+
*/
|
|
1939
|
+
async transform(cards, context) {
|
|
1940
|
+
const immatureTags = await this.getImmatureTags(context);
|
|
1941
|
+
const tagsToAvoid = this.getTagsToAvoid(immatureTags);
|
|
1942
|
+
const adjusted = [];
|
|
1943
|
+
for (const card of cards) {
|
|
1944
|
+
const cardTags = card.tags ?? [];
|
|
1945
|
+
const { multiplier, reason } = this.computeInterferenceEffect(
|
|
1946
|
+
cardTags,
|
|
1947
|
+
tagsToAvoid,
|
|
1948
|
+
immatureTags
|
|
1949
|
+
);
|
|
1950
|
+
const finalScore = card.score * multiplier;
|
|
1951
|
+
const action = multiplier < 1 ? "penalized" : multiplier > 1 ? "boosted" : "passed";
|
|
1952
|
+
adjusted.push({
|
|
1953
|
+
...card,
|
|
1954
|
+
score: finalScore,
|
|
1955
|
+
provenance: [
|
|
1956
|
+
...card.provenance,
|
|
1957
|
+
{
|
|
1958
|
+
strategy: "interferenceMitigator",
|
|
1959
|
+
strategyName: this.strategyName || this.name,
|
|
1960
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-interference",
|
|
1961
|
+
action,
|
|
1962
|
+
score: finalScore,
|
|
1963
|
+
reason
|
|
1964
|
+
}
|
|
1965
|
+
]
|
|
1966
|
+
});
|
|
1967
|
+
}
|
|
1968
|
+
return adjusted;
|
|
1969
|
+
}
|
|
1970
|
+
/**
|
|
1971
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1972
|
+
*
|
|
1973
|
+
* Use transform() via Pipeline instead.
|
|
1974
|
+
*/
|
|
1975
|
+
async getWeightedCards(_limit) {
|
|
1976
|
+
throw new Error(
|
|
1977
|
+
"InterferenceMitigatorNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1978
|
+
);
|
|
1979
|
+
}
|
|
1980
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
1981
|
+
async getNewCards(_n) {
|
|
1982
|
+
return [];
|
|
1983
|
+
}
|
|
1984
|
+
async getPendingReviews() {
|
|
1985
|
+
return [];
|
|
1986
|
+
}
|
|
1987
|
+
};
|
|
1988
|
+
}
|
|
1989
|
+
});
|
|
1990
|
+
|
|
1991
|
+
// src/core/navigators/relativePriority.ts
|
|
1992
|
+
var relativePriority_exports = {};
|
|
1993
|
+
__export(relativePriority_exports, {
|
|
1994
|
+
default: () => RelativePriorityNavigator
|
|
1995
|
+
});
|
|
1996
|
+
var DEFAULT_PRIORITY, DEFAULT_PRIORITY_INFLUENCE, DEFAULT_COMBINE_MODE, RelativePriorityNavigator;
|
|
1997
|
+
var init_relativePriority = __esm({
|
|
1998
|
+
"src/core/navigators/relativePriority.ts"() {
|
|
1999
|
+
"use strict";
|
|
2000
|
+
init_navigators();
|
|
2001
|
+
DEFAULT_PRIORITY = 0.5;
|
|
2002
|
+
DEFAULT_PRIORITY_INFLUENCE = 0.5;
|
|
2003
|
+
DEFAULT_COMBINE_MODE = "max";
|
|
2004
|
+
RelativePriorityNavigator = class extends ContentNavigator {
|
|
2005
|
+
config;
|
|
2006
|
+
_strategyData;
|
|
2007
|
+
/** Human-readable name for CardFilter interface */
|
|
2008
|
+
name;
|
|
2009
|
+
constructor(user, course, _strategyData) {
|
|
2010
|
+
super(user, course, _strategyData);
|
|
2011
|
+
this._strategyData = _strategyData;
|
|
2012
|
+
this.config = this.parseConfig(_strategyData.serializedData);
|
|
2013
|
+
this.name = _strategyData.name || "Relative Priority";
|
|
2014
|
+
}
|
|
2015
|
+
parseConfig(serializedData) {
|
|
2016
|
+
try {
|
|
2017
|
+
const parsed = JSON.parse(serializedData);
|
|
2018
|
+
return {
|
|
2019
|
+
tagPriorities: parsed.tagPriorities || {},
|
|
2020
|
+
defaultPriority: parsed.defaultPriority ?? DEFAULT_PRIORITY,
|
|
2021
|
+
combineMode: parsed.combineMode ?? DEFAULT_COMBINE_MODE,
|
|
2022
|
+
priorityInfluence: parsed.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE
|
|
2023
|
+
};
|
|
2024
|
+
} catch {
|
|
2025
|
+
return {
|
|
2026
|
+
tagPriorities: {},
|
|
2027
|
+
defaultPriority: DEFAULT_PRIORITY,
|
|
2028
|
+
combineMode: DEFAULT_COMBINE_MODE,
|
|
2029
|
+
priorityInfluence: DEFAULT_PRIORITY_INFLUENCE
|
|
2030
|
+
};
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
/**
|
|
2034
|
+
* Look up the priority for a tag.
|
|
2035
|
+
*/
|
|
2036
|
+
getTagPriority(tagId) {
|
|
2037
|
+
return this.config.tagPriorities[tagId] ?? this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
2038
|
+
}
|
|
2039
|
+
/**
|
|
2040
|
+
* Compute combined priority for a card based on its tags.
|
|
2041
|
+
*/
|
|
2042
|
+
computeCardPriority(cardTags) {
|
|
2043
|
+
if (cardTags.length === 0) {
|
|
2044
|
+
return this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
2045
|
+
}
|
|
2046
|
+
const priorities = cardTags.map((tag) => this.getTagPriority(tag));
|
|
2047
|
+
switch (this.config.combineMode) {
|
|
2048
|
+
case "max":
|
|
2049
|
+
return Math.max(...priorities);
|
|
2050
|
+
case "min":
|
|
2051
|
+
return Math.min(...priorities);
|
|
2052
|
+
case "average":
|
|
2053
|
+
return priorities.reduce((sum, p) => sum + p, 0) / priorities.length;
|
|
2054
|
+
default:
|
|
2055
|
+
return Math.max(...priorities);
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
/**
|
|
2059
|
+
* Compute boost factor based on priority.
|
|
2060
|
+
*
|
|
2061
|
+
* The formula: 1 + (priority - 0.5) * priorityInfluence
|
|
2062
|
+
*
|
|
2063
|
+
* This creates a multiplier centered around 1.0:
|
|
2064
|
+
* - Priority 1.0 with influence 0.5 → 1.25 (25% boost)
|
|
2065
|
+
* - Priority 0.5 with any influence → 1.00 (neutral)
|
|
2066
|
+
* - Priority 0.0 with influence 0.5 → 0.75 (25% reduction)
|
|
2067
|
+
*/
|
|
2068
|
+
computeBoostFactor(priority) {
|
|
2069
|
+
const influence = this.config.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE;
|
|
2070
|
+
return 1 + (priority - 0.5) * influence;
|
|
2071
|
+
}
|
|
2072
|
+
/**
|
|
2073
|
+
* Build human-readable reason for priority adjustment.
|
|
2074
|
+
*/
|
|
2075
|
+
buildPriorityReason(cardTags, priority, boostFactor, finalScore) {
|
|
2076
|
+
if (cardTags.length === 0) {
|
|
2077
|
+
return `No tags, neutral priority (${priority.toFixed(2)})`;
|
|
2078
|
+
}
|
|
2079
|
+
const tagList = cardTags.slice(0, 3).join(", ");
|
|
2080
|
+
const more = cardTags.length > 3 ? ` (+${cardTags.length - 3} more)` : "";
|
|
2081
|
+
if (boostFactor === 1) {
|
|
2082
|
+
return `Neutral priority (${priority.toFixed(2)}) for tags: ${tagList}${more}`;
|
|
2083
|
+
} else if (boostFactor > 1) {
|
|
2084
|
+
return `High-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 boost ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
2085
|
+
} else {
|
|
2086
|
+
return `Low-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 reduce ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
/**
|
|
2090
|
+
* CardFilter.transform implementation.
|
|
2091
|
+
*
|
|
2092
|
+
* Apply priority-adjusted scoring. Cards with high-priority tags get boosted,
|
|
2093
|
+
* cards with low-priority tags get reduced scores.
|
|
2094
|
+
*/
|
|
2095
|
+
async transform(cards, _context) {
|
|
2096
|
+
const adjusted = await Promise.all(
|
|
2097
|
+
cards.map(async (card) => {
|
|
2098
|
+
const cardTags = card.tags ?? [];
|
|
2099
|
+
const priority = this.computeCardPriority(cardTags);
|
|
2100
|
+
const boostFactor = this.computeBoostFactor(priority);
|
|
2101
|
+
const finalScore = Math.max(0, Math.min(1, card.score * boostFactor));
|
|
2102
|
+
const action = boostFactor > 1 ? "boosted" : boostFactor < 1 ? "penalized" : "passed";
|
|
2103
|
+
const reason = this.buildPriorityReason(cardTags, priority, boostFactor, finalScore);
|
|
2104
|
+
return {
|
|
2105
|
+
...card,
|
|
2106
|
+
score: finalScore,
|
|
2107
|
+
provenance: [
|
|
2108
|
+
...card.provenance,
|
|
2109
|
+
{
|
|
2110
|
+
strategy: "relativePriority",
|
|
2111
|
+
strategyName: this.strategyName || this.name,
|
|
2112
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-priority",
|
|
2113
|
+
action,
|
|
2114
|
+
score: finalScore,
|
|
2115
|
+
reason
|
|
2116
|
+
}
|
|
2117
|
+
]
|
|
2118
|
+
};
|
|
2119
|
+
})
|
|
2120
|
+
);
|
|
2121
|
+
return adjusted;
|
|
2122
|
+
}
|
|
2123
|
+
/**
|
|
2124
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
2125
|
+
*
|
|
2126
|
+
* Use transform() via Pipeline instead.
|
|
2127
|
+
*/
|
|
2128
|
+
async getWeightedCards(_limit) {
|
|
2129
|
+
throw new Error(
|
|
2130
|
+
"RelativePriorityNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
2131
|
+
);
|
|
2132
|
+
}
|
|
2133
|
+
// Legacy methods - stub implementations since filters don't generate cards
|
|
2134
|
+
async getNewCards(_n) {
|
|
2135
|
+
return [];
|
|
2136
|
+
}
|
|
2137
|
+
async getPendingReviews() {
|
|
2138
|
+
return [];
|
|
2139
|
+
}
|
|
2140
|
+
};
|
|
2141
|
+
}
|
|
2142
|
+
});
|
|
2143
|
+
|
|
2144
|
+
// src/core/navigators/srs.ts
|
|
2145
|
+
var srs_exports = {};
|
|
2146
|
+
__export(srs_exports, {
|
|
2147
|
+
default: () => SRSNavigator
|
|
2148
|
+
});
|
|
2149
|
+
var import_moment, SRSNavigator;
|
|
2150
|
+
var init_srs = __esm({
|
|
2151
|
+
"src/core/navigators/srs.ts"() {
|
|
2152
|
+
"use strict";
|
|
2153
|
+
import_moment = __toESM(require("moment"), 1);
|
|
2154
|
+
init_navigators();
|
|
2155
|
+
SRSNavigator = class extends ContentNavigator {
|
|
2156
|
+
/** Human-readable name for CardGenerator interface */
|
|
2157
|
+
name;
|
|
2158
|
+
constructor(user, course, strategyData) {
|
|
2159
|
+
super(user, course, strategyData);
|
|
2160
|
+
this.name = strategyData?.name || "SRS";
|
|
2161
|
+
}
|
|
2162
|
+
/**
|
|
2163
|
+
* Get review cards scored by urgency.
|
|
2164
|
+
*
|
|
2165
|
+
* Score formula combines:
|
|
2166
|
+
* - Relative overdueness: hoursOverdue / intervalHours
|
|
2167
|
+
* - Interval recency: exponential decay favoring shorter intervals
|
|
2168
|
+
*
|
|
2169
|
+
* Cards not yet due are excluded (not scored as 0).
|
|
2170
|
+
*
|
|
2171
|
+
* This method supports both the legacy signature (limit only) and the
|
|
2172
|
+
* CardGenerator interface signature (limit, context).
|
|
2173
|
+
*
|
|
2174
|
+
* @param limit - Maximum number of cards to return
|
|
2175
|
+
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
2176
|
+
*/
|
|
2177
|
+
async getWeightedCards(limit, _context) {
|
|
2178
|
+
if (!this.user || !this.course) {
|
|
2179
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
2180
|
+
}
|
|
2181
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
2182
|
+
const now = import_moment.default.utc();
|
|
2183
|
+
const dueReviews = reviews.filter((r) => now.isAfter(import_moment.default.utc(r.reviewTime)));
|
|
2184
|
+
const scored = dueReviews.map((review) => {
|
|
2185
|
+
const { score, reason } = this.computeUrgencyScore(review, now);
|
|
2186
|
+
return {
|
|
2187
|
+
cardId: review.cardId,
|
|
2188
|
+
courseId: review.courseId,
|
|
2189
|
+
score,
|
|
2190
|
+
provenance: [
|
|
2191
|
+
{
|
|
2192
|
+
strategy: "srs",
|
|
2193
|
+
strategyName: this.strategyName || this.name,
|
|
2194
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-SRS-default",
|
|
2195
|
+
action: "generated",
|
|
2196
|
+
score,
|
|
2197
|
+
reason
|
|
2198
|
+
}
|
|
2199
|
+
]
|
|
744
2200
|
};
|
|
745
2201
|
});
|
|
2202
|
+
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
2203
|
+
}
|
|
2204
|
+
/**
|
|
2205
|
+
* Compute urgency score for a review card.
|
|
2206
|
+
*
|
|
2207
|
+
* Two factors:
|
|
2208
|
+
* 1. Relative overdueness = hoursOverdue / intervalHours
|
|
2209
|
+
* - 2 days overdue on 3-day interval = 0.67 (urgent)
|
|
2210
|
+
* - 2 days overdue on 180-day interval = 0.01 (not urgent)
|
|
2211
|
+
*
|
|
2212
|
+
* 2. Interval recency factor = 0.3 + 0.7 * exp(-intervalHours / 720)
|
|
2213
|
+
* - 24h interval → ~1.0 (very recent learning)
|
|
2214
|
+
* - 30 days (720h) → ~0.56
|
|
2215
|
+
* - 180 days → ~0.30
|
|
2216
|
+
*
|
|
2217
|
+
* Combined: base 0.5 + weighted average of factors * 0.45
|
|
2218
|
+
* Result range: approximately 0.5 to 0.95
|
|
2219
|
+
*/
|
|
2220
|
+
computeUrgencyScore(review, now) {
|
|
2221
|
+
const scheduledAt = import_moment.default.utc(review.scheduledAt);
|
|
2222
|
+
const due = import_moment.default.utc(review.reviewTime);
|
|
2223
|
+
const intervalHours = Math.max(1, due.diff(scheduledAt, "hours"));
|
|
2224
|
+
const hoursOverdue = now.diff(due, "hours");
|
|
2225
|
+
const relativeOverdue = hoursOverdue / intervalHours;
|
|
2226
|
+
const recencyFactor = 0.3 + 0.7 * Math.exp(-intervalHours / 720);
|
|
2227
|
+
const overdueContribution = Math.min(1, Math.max(0, relativeOverdue));
|
|
2228
|
+
const urgency = overdueContribution * 0.5 + recencyFactor * 0.5;
|
|
2229
|
+
const score = Math.min(0.95, 0.5 + urgency * 0.45);
|
|
2230
|
+
const reason = `${Math.round(hoursOverdue)}h overdue (interval: ${Math.round(intervalHours)}h, relative: ${relativeOverdue.toFixed(2)}), recency: ${recencyFactor.toFixed(2)}, review`;
|
|
2231
|
+
return { score, reason };
|
|
2232
|
+
}
|
|
2233
|
+
/**
|
|
2234
|
+
* Get pending reviews in legacy format.
|
|
2235
|
+
*
|
|
2236
|
+
* Returns all pending reviews for the course, enriched with session item fields.
|
|
2237
|
+
*/
|
|
2238
|
+
async getPendingReviews() {
|
|
2239
|
+
if (!this.user || !this.course) {
|
|
2240
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
2241
|
+
}
|
|
2242
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
2243
|
+
return reviews.map((r) => ({
|
|
2244
|
+
...r,
|
|
2245
|
+
contentSourceType: "course",
|
|
2246
|
+
contentSourceID: this.course.getCourseID(),
|
|
2247
|
+
cardID: r.cardId,
|
|
2248
|
+
courseID: r.courseId,
|
|
2249
|
+
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
2250
|
+
reviewID: r._id,
|
|
2251
|
+
status: "review"
|
|
2252
|
+
}));
|
|
2253
|
+
}
|
|
2254
|
+
/**
|
|
2255
|
+
* SRS does not generate new cards.
|
|
2256
|
+
* Use ELONavigator or another generator for new cards.
|
|
2257
|
+
*/
|
|
2258
|
+
async getNewCards(_n) {
|
|
2259
|
+
return [];
|
|
746
2260
|
}
|
|
747
2261
|
};
|
|
748
2262
|
}
|
|
749
2263
|
});
|
|
750
2264
|
|
|
2265
|
+
// src/core/navigators/userGoal.ts
|
|
2266
|
+
var userGoal_exports = {};
|
|
2267
|
+
__export(userGoal_exports, {
|
|
2268
|
+
USER_GOAL_NAVIGATOR_STUB: () => USER_GOAL_NAVIGATOR_STUB
|
|
2269
|
+
});
|
|
2270
|
+
var USER_GOAL_NAVIGATOR_STUB;
|
|
2271
|
+
var init_userGoal = __esm({
|
|
2272
|
+
"src/core/navigators/userGoal.ts"() {
|
|
2273
|
+
"use strict";
|
|
2274
|
+
USER_GOAL_NAVIGATOR_STUB = true;
|
|
2275
|
+
}
|
|
2276
|
+
});
|
|
2277
|
+
|
|
751
2278
|
// import("./**/*") in src/core/navigators/index.ts
|
|
752
2279
|
var globImport;
|
|
753
2280
|
var init_ = __esm({
|
|
754
2281
|
'import("./**/*") in src/core/navigators/index.ts'() {
|
|
755
2282
|
globImport = __glob({
|
|
2283
|
+
"./CompositeGenerator.ts": () => Promise.resolve().then(() => (init_CompositeGenerator(), CompositeGenerator_exports)),
|
|
2284
|
+
"./Pipeline.ts": () => Promise.resolve().then(() => (init_Pipeline(), Pipeline_exports)),
|
|
2285
|
+
"./PipelineAssembler.ts": () => Promise.resolve().then(() => (init_PipelineAssembler(), PipelineAssembler_exports)),
|
|
756
2286
|
"./elo.ts": () => Promise.resolve().then(() => (init_elo(), elo_exports)),
|
|
2287
|
+
"./filters/eloDistance.ts": () => Promise.resolve().then(() => (init_eloDistance(), eloDistance_exports)),
|
|
2288
|
+
"./filters/index.ts": () => Promise.resolve().then(() => (init_filters(), filters_exports)),
|
|
2289
|
+
"./filters/types.ts": () => Promise.resolve().then(() => (init_types(), types_exports)),
|
|
2290
|
+
"./filters/userTagPreference.ts": () => Promise.resolve().then(() => (init_userTagPreference(), userTagPreference_exports)),
|
|
2291
|
+
"./generators/index.ts": () => Promise.resolve().then(() => (init_generators(), generators_exports)),
|
|
2292
|
+
"./generators/types.ts": () => Promise.resolve().then(() => (init_types2(), types_exports2)),
|
|
757
2293
|
"./hardcodedOrder.ts": () => Promise.resolve().then(() => (init_hardcodedOrder(), hardcodedOrder_exports)),
|
|
758
|
-
"./
|
|
2294
|
+
"./hierarchyDefinition.ts": () => Promise.resolve().then(() => (init_hierarchyDefinition(), hierarchyDefinition_exports)),
|
|
2295
|
+
"./index.ts": () => Promise.resolve().then(() => (init_navigators(), navigators_exports)),
|
|
2296
|
+
"./inferredPreference.ts": () => Promise.resolve().then(() => (init_inferredPreference(), inferredPreference_exports)),
|
|
2297
|
+
"./interferenceMitigator.ts": () => Promise.resolve().then(() => (init_interferenceMitigator(), interferenceMitigator_exports)),
|
|
2298
|
+
"./relativePriority.ts": () => Promise.resolve().then(() => (init_relativePriority(), relativePriority_exports)),
|
|
2299
|
+
"./srs.ts": () => Promise.resolve().then(() => (init_srs(), srs_exports)),
|
|
2300
|
+
"./userGoal.ts": () => Promise.resolve().then(() => (init_userGoal(), userGoal_exports))
|
|
759
2301
|
});
|
|
760
2302
|
}
|
|
761
2303
|
});
|
|
@@ -764,9 +2306,34 @@ var init_ = __esm({
|
|
|
764
2306
|
var navigators_exports = {};
|
|
765
2307
|
__export(navigators_exports, {
|
|
766
2308
|
ContentNavigator: () => ContentNavigator,
|
|
767
|
-
|
|
2309
|
+
NavigatorRole: () => NavigatorRole,
|
|
2310
|
+
NavigatorRoles: () => NavigatorRoles,
|
|
2311
|
+
Navigators: () => Navigators,
|
|
2312
|
+
getCardOrigin: () => getCardOrigin,
|
|
2313
|
+
isFilter: () => isFilter,
|
|
2314
|
+
isGenerator: () => isGenerator
|
|
768
2315
|
});
|
|
769
|
-
|
|
2316
|
+
function getCardOrigin(card) {
|
|
2317
|
+
if (card.provenance.length === 0) {
|
|
2318
|
+
throw new Error("Card has no provenance - cannot determine origin");
|
|
2319
|
+
}
|
|
2320
|
+
const firstEntry = card.provenance[0];
|
|
2321
|
+
const reason = firstEntry.reason.toLowerCase();
|
|
2322
|
+
if (reason.includes("failed")) {
|
|
2323
|
+
return "failed";
|
|
2324
|
+
}
|
|
2325
|
+
if (reason.includes("review")) {
|
|
2326
|
+
return "review";
|
|
2327
|
+
}
|
|
2328
|
+
return "new";
|
|
2329
|
+
}
|
|
2330
|
+
function isGenerator(impl) {
|
|
2331
|
+
return NavigatorRoles[impl] === "generator" /* GENERATOR */;
|
|
2332
|
+
}
|
|
2333
|
+
function isFilter(impl) {
|
|
2334
|
+
return NavigatorRoles[impl] === "filter" /* FILTER */;
|
|
2335
|
+
}
|
|
2336
|
+
var Navigators, NavigatorRole, NavigatorRoles, ContentNavigator;
|
|
770
2337
|
var init_navigators = __esm({
|
|
771
2338
|
"src/core/navigators/index.ts"() {
|
|
772
2339
|
"use strict";
|
|
@@ -774,14 +2341,103 @@ var init_navigators = __esm({
|
|
|
774
2341
|
init_();
|
|
775
2342
|
Navigators = /* @__PURE__ */ ((Navigators2) => {
|
|
776
2343
|
Navigators2["ELO"] = "elo";
|
|
2344
|
+
Navigators2["SRS"] = "srs";
|
|
777
2345
|
Navigators2["HARDCODED"] = "hardcodedOrder";
|
|
2346
|
+
Navigators2["HIERARCHY"] = "hierarchyDefinition";
|
|
2347
|
+
Navigators2["INTERFERENCE"] = "interferenceMitigator";
|
|
2348
|
+
Navigators2["RELATIVE_PRIORITY"] = "relativePriority";
|
|
2349
|
+
Navigators2["USER_TAG_PREFERENCE"] = "userTagPreference";
|
|
778
2350
|
return Navigators2;
|
|
779
2351
|
})(Navigators || {});
|
|
2352
|
+
NavigatorRole = /* @__PURE__ */ ((NavigatorRole2) => {
|
|
2353
|
+
NavigatorRole2["GENERATOR"] = "generator";
|
|
2354
|
+
NavigatorRole2["FILTER"] = "filter";
|
|
2355
|
+
return NavigatorRole2;
|
|
2356
|
+
})(NavigatorRole || {});
|
|
2357
|
+
NavigatorRoles = {
|
|
2358
|
+
["elo" /* ELO */]: "generator" /* GENERATOR */,
|
|
2359
|
+
["srs" /* SRS */]: "generator" /* GENERATOR */,
|
|
2360
|
+
["hardcodedOrder" /* HARDCODED */]: "generator" /* GENERATOR */,
|
|
2361
|
+
["hierarchyDefinition" /* HIERARCHY */]: "filter" /* FILTER */,
|
|
2362
|
+
["interferenceMitigator" /* INTERFERENCE */]: "filter" /* FILTER */,
|
|
2363
|
+
["relativePriority" /* RELATIVE_PRIORITY */]: "filter" /* FILTER */,
|
|
2364
|
+
["userTagPreference" /* USER_TAG_PREFERENCE */]: "filter" /* FILTER */
|
|
2365
|
+
};
|
|
780
2366
|
ContentNavigator = class {
|
|
2367
|
+
/** User interface for this navigation session */
|
|
2368
|
+
user;
|
|
2369
|
+
/** Course interface for this navigation session */
|
|
2370
|
+
course;
|
|
2371
|
+
/** Human-readable name for this strategy instance (from ContentNavigationStrategyData.name) */
|
|
2372
|
+
strategyName;
|
|
2373
|
+
/** Unique document ID for this strategy instance (from ContentNavigationStrategyData._id) */
|
|
2374
|
+
strategyId;
|
|
2375
|
+
/**
|
|
2376
|
+
* Constructor for standard navigators.
|
|
2377
|
+
* Call this from subclass constructors to initialize common fields.
|
|
2378
|
+
*
|
|
2379
|
+
* Note: CompositeGenerator doesn't use this pattern and should call super() without args.
|
|
2380
|
+
*/
|
|
2381
|
+
constructor(user, course, strategyData) {
|
|
2382
|
+
if (user && course && strategyData) {
|
|
2383
|
+
this.user = user;
|
|
2384
|
+
this.course = course;
|
|
2385
|
+
this.strategyName = strategyData.name;
|
|
2386
|
+
this.strategyId = strategyData._id;
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
// ============================================================================
|
|
2390
|
+
// STRATEGY STATE HELPERS
|
|
2391
|
+
// ============================================================================
|
|
2392
|
+
//
|
|
2393
|
+
// These methods allow strategies to persist their own state (user preferences,
|
|
2394
|
+
// learned patterns, temporal tracking) in the user database.
|
|
2395
|
+
//
|
|
2396
|
+
// ============================================================================
|
|
2397
|
+
/**
|
|
2398
|
+
* Unique key identifying this strategy for state storage.
|
|
2399
|
+
*
|
|
2400
|
+
* Defaults to the constructor name (e.g., "UserTagPreferenceFilter").
|
|
2401
|
+
* Override in subclasses if multiple instances of the same strategy type
|
|
2402
|
+
* need separate state storage.
|
|
2403
|
+
*/
|
|
2404
|
+
get strategyKey() {
|
|
2405
|
+
return this.constructor.name;
|
|
2406
|
+
}
|
|
2407
|
+
/**
|
|
2408
|
+
* Get this strategy's persisted state for the current course.
|
|
2409
|
+
*
|
|
2410
|
+
* @returns The strategy's data payload, or null if no state exists
|
|
2411
|
+
* @throws Error if user or course is not initialized
|
|
2412
|
+
*/
|
|
2413
|
+
async getStrategyState() {
|
|
2414
|
+
if (!this.user || !this.course) {
|
|
2415
|
+
throw new Error(
|
|
2416
|
+
`Cannot get strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
2417
|
+
);
|
|
2418
|
+
}
|
|
2419
|
+
return this.user.getStrategyState(this.course.getCourseID(), this.strategyKey);
|
|
2420
|
+
}
|
|
2421
|
+
/**
|
|
2422
|
+
* Persist this strategy's state for the current course.
|
|
2423
|
+
*
|
|
2424
|
+
* @param data - The strategy's data payload to store
|
|
2425
|
+
* @throws Error if user or course is not initialized
|
|
2426
|
+
*/
|
|
2427
|
+
async putStrategyState(data) {
|
|
2428
|
+
if (!this.user || !this.course) {
|
|
2429
|
+
throw new Error(
|
|
2430
|
+
`Cannot put strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
2431
|
+
);
|
|
2432
|
+
}
|
|
2433
|
+
return this.user.putStrategyState(this.course.getCourseID(), this.strategyKey, data);
|
|
2434
|
+
}
|
|
781
2435
|
/**
|
|
2436
|
+
* Factory method to create navigator instances dynamically.
|
|
782
2437
|
*
|
|
783
|
-
* @param user
|
|
784
|
-
* @param
|
|
2438
|
+
* @param user - User interface
|
|
2439
|
+
* @param course - Course interface
|
|
2440
|
+
* @param strategyData - Strategy configuration document
|
|
785
2441
|
* @returns the runtime object used to steer a study session.
|
|
786
2442
|
*/
|
|
787
2443
|
static async create(user, course, strategyData) {
|
|
@@ -802,6 +2458,70 @@ var init_navigators = __esm({
|
|
|
802
2458
|
}
|
|
803
2459
|
return new NavigatorImpl(user, course, strategyData);
|
|
804
2460
|
}
|
|
2461
|
+
/**
|
|
2462
|
+
* Get cards with suitability scores and provenance trails.
|
|
2463
|
+
*
|
|
2464
|
+
* **This is the PRIMARY API for navigation strategies.**
|
|
2465
|
+
*
|
|
2466
|
+
* Returns cards ranked by suitability score (0-1). Higher scores indicate
|
|
2467
|
+
* better candidates for presentation. Each card includes a provenance trail
|
|
2468
|
+
* documenting how strategies contributed to the final score.
|
|
2469
|
+
*
|
|
2470
|
+
* ## For Generators
|
|
2471
|
+
* Override this method to generate candidates and compute scores based on
|
|
2472
|
+
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
2473
|
+
* initial provenance entry with action='generated'.
|
|
2474
|
+
*
|
|
2475
|
+
* ## Default Implementation
|
|
2476
|
+
* The base class provides a backward-compatible default that:
|
|
2477
|
+
* 1. Calls legacy getNewCards() and getPendingReviews()
|
|
2478
|
+
* 2. Assigns score=1.0 to all cards
|
|
2479
|
+
* 3. Creates minimal provenance from legacy methods
|
|
2480
|
+
* 4. Returns combined results up to limit
|
|
2481
|
+
*
|
|
2482
|
+
* This allows existing strategies to work without modification while
|
|
2483
|
+
* new strategies can override with proper scoring and provenance.
|
|
2484
|
+
*
|
|
2485
|
+
* @param limit - Maximum cards to return
|
|
2486
|
+
* @returns Cards sorted by score descending, with provenance trails
|
|
2487
|
+
*/
|
|
2488
|
+
async getWeightedCards(limit) {
|
|
2489
|
+
const newCards = await this.getNewCards(limit);
|
|
2490
|
+
const reviews = await this.getPendingReviews();
|
|
2491
|
+
const weighted = [
|
|
2492
|
+
...newCards.map((c) => ({
|
|
2493
|
+
cardId: c.cardID,
|
|
2494
|
+
courseId: c.courseID,
|
|
2495
|
+
score: 1,
|
|
2496
|
+
provenance: [
|
|
2497
|
+
{
|
|
2498
|
+
strategy: "legacy",
|
|
2499
|
+
strategyName: this.strategyName || "Legacy API",
|
|
2500
|
+
strategyId: this.strategyId || "legacy-fallback",
|
|
2501
|
+
action: "generated",
|
|
2502
|
+
score: 1,
|
|
2503
|
+
reason: "Generated via legacy getNewCards(), new card"
|
|
2504
|
+
}
|
|
2505
|
+
]
|
|
2506
|
+
})),
|
|
2507
|
+
...reviews.map((r) => ({
|
|
2508
|
+
cardId: r.cardID,
|
|
2509
|
+
courseId: r.courseID,
|
|
2510
|
+
score: 1,
|
|
2511
|
+
provenance: [
|
|
2512
|
+
{
|
|
2513
|
+
strategy: "legacy",
|
|
2514
|
+
strategyName: this.strategyName || "Legacy API",
|
|
2515
|
+
strategyId: this.strategyId || "legacy-fallback",
|
|
2516
|
+
action: "generated",
|
|
2517
|
+
score: 1,
|
|
2518
|
+
reason: "Generated via legacy getPendingReviews(), review"
|
|
2519
|
+
}
|
|
2520
|
+
]
|
|
2521
|
+
}))
|
|
2522
|
+
];
|
|
2523
|
+
return weighted.slice(0, limit);
|
|
2524
|
+
}
|
|
805
2525
|
};
|
|
806
2526
|
}
|
|
807
2527
|
});
|
|
@@ -924,11 +2644,11 @@ ${JSON.stringify(config)}
|
|
|
924
2644
|
function isSuccessRow(row) {
|
|
925
2645
|
return "doc" in row && row.doc !== null && row.doc !== void 0;
|
|
926
2646
|
}
|
|
927
|
-
var
|
|
2647
|
+
var import_common9, CoursesDB, CourseDB;
|
|
928
2648
|
var init_courseDB = __esm({
|
|
929
2649
|
"src/impl/couch/courseDB.ts"() {
|
|
930
2650
|
"use strict";
|
|
931
|
-
|
|
2651
|
+
import_common9 = require("@vue-skuilder/common");
|
|
932
2652
|
init_couch();
|
|
933
2653
|
init_updateQueue();
|
|
934
2654
|
init_types_legacy();
|
|
@@ -937,6 +2657,12 @@ var init_courseDB = __esm({
|
|
|
937
2657
|
init_courseAPI();
|
|
938
2658
|
init_courseLookupDB();
|
|
939
2659
|
init_navigators();
|
|
2660
|
+
init_Pipeline();
|
|
2661
|
+
init_PipelineAssembler();
|
|
2662
|
+
init_CompositeGenerator();
|
|
2663
|
+
init_elo();
|
|
2664
|
+
init_srs();
|
|
2665
|
+
init_eloDistance();
|
|
940
2666
|
CoursesDB = class {
|
|
941
2667
|
_courseIDs;
|
|
942
2668
|
constructor(courseIDs) {
|
|
@@ -1048,14 +2774,14 @@ var init_courseDB = __esm({
|
|
|
1048
2774
|
docs.rows.forEach((r) => {
|
|
1049
2775
|
if (isSuccessRow(r)) {
|
|
1050
2776
|
if (r.doc && r.doc.elo) {
|
|
1051
|
-
ret.push((0,
|
|
2777
|
+
ret.push((0, import_common9.toCourseElo)(r.doc.elo));
|
|
1052
2778
|
} else {
|
|
1053
2779
|
logger.warn("no elo data for card: " + r.id);
|
|
1054
|
-
ret.push((0,
|
|
2780
|
+
ret.push((0, import_common9.blankCourseElo)());
|
|
1055
2781
|
}
|
|
1056
2782
|
} else {
|
|
1057
2783
|
logger.warn("no elo data for card: " + JSON.stringify(r));
|
|
1058
|
-
ret.push((0,
|
|
2784
|
+
ret.push((0, import_common9.blankCourseElo)());
|
|
1059
2785
|
}
|
|
1060
2786
|
});
|
|
1061
2787
|
return ret;
|
|
@@ -1117,15 +2843,6 @@ var init_courseDB = __esm({
|
|
|
1117
2843
|
ret[r.id] = r.doc.id_displayable_data;
|
|
1118
2844
|
}
|
|
1119
2845
|
});
|
|
1120
|
-
await Promise.all(
|
|
1121
|
-
cards.rows.map((r) => {
|
|
1122
|
-
return async () => {
|
|
1123
|
-
if (isSuccessRow(r)) {
|
|
1124
|
-
ret[r.id] = r.doc.id_displayable_data;
|
|
1125
|
-
}
|
|
1126
|
-
};
|
|
1127
|
-
})
|
|
1128
|
-
);
|
|
1129
2846
|
return ret;
|
|
1130
2847
|
}
|
|
1131
2848
|
async getCardsByELO(elo, cardLimit) {
|
|
@@ -1210,6 +2927,28 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1210
2927
|
throw new Error(`Failed to find tags for card ${this.id}-${cardId}`);
|
|
1211
2928
|
}
|
|
1212
2929
|
}
|
|
2930
|
+
async getAppliedTagsBatch(cardIds) {
|
|
2931
|
+
if (cardIds.length === 0) {
|
|
2932
|
+
return /* @__PURE__ */ new Map();
|
|
2933
|
+
}
|
|
2934
|
+
const db = getCourseDB2(this.id);
|
|
2935
|
+
const result = await db.query("getTags", {
|
|
2936
|
+
keys: cardIds,
|
|
2937
|
+
include_docs: false
|
|
2938
|
+
});
|
|
2939
|
+
const tagsByCard = /* @__PURE__ */ new Map();
|
|
2940
|
+
for (const cardId of cardIds) {
|
|
2941
|
+
tagsByCard.set(cardId, []);
|
|
2942
|
+
}
|
|
2943
|
+
for (const row of result.rows) {
|
|
2944
|
+
const cardId = row.key;
|
|
2945
|
+
const tagName = row.value?.name;
|
|
2946
|
+
if (tagName && tagsByCard.has(cardId)) {
|
|
2947
|
+
tagsByCard.get(cardId).push(tagName);
|
|
2948
|
+
}
|
|
2949
|
+
}
|
|
2950
|
+
return tagsByCard;
|
|
2951
|
+
}
|
|
1213
2952
|
async addTagToCard(cardId, tagId, updateELO) {
|
|
1214
2953
|
return await addTagToCard(
|
|
1215
2954
|
this.id,
|
|
@@ -1237,7 +2976,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1237
2976
|
async getCourseTagStubs() {
|
|
1238
2977
|
return getCourseTagStubs(this.id);
|
|
1239
2978
|
}
|
|
1240
|
-
async addNote(codeCourse, shape, data, author, tags, uploads, elo = (0,
|
|
2979
|
+
async addNote(codeCourse, shape, data, author, tags, uploads, elo = (0, import_common9.blankCourseElo)()) {
|
|
1241
2980
|
try {
|
|
1242
2981
|
const resp = await addNote55(this.id, codeCourse, shape, data, author, tags, uploads, elo);
|
|
1243
2982
|
if (resp.ok) {
|
|
@@ -1246,19 +2985,19 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1246
2985
|
`[courseDB.addNote] Note added but card creation failed: ${resp.cardCreationError}`
|
|
1247
2986
|
);
|
|
1248
2987
|
return {
|
|
1249
|
-
status:
|
|
2988
|
+
status: import_common9.Status.error,
|
|
1250
2989
|
message: `Note was added but no cards were created: ${resp.cardCreationError}`,
|
|
1251
2990
|
id: resp.id
|
|
1252
2991
|
};
|
|
1253
2992
|
}
|
|
1254
2993
|
return {
|
|
1255
|
-
status:
|
|
2994
|
+
status: import_common9.Status.ok,
|
|
1256
2995
|
message: "",
|
|
1257
2996
|
id: resp.id
|
|
1258
2997
|
};
|
|
1259
2998
|
} else {
|
|
1260
2999
|
return {
|
|
1261
|
-
status:
|
|
3000
|
+
status: import_common9.Status.error,
|
|
1262
3001
|
message: "Unexpected error adding note"
|
|
1263
3002
|
};
|
|
1264
3003
|
}
|
|
@@ -1270,7 +3009,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1270
3009
|
message: ${err.message}`
|
|
1271
3010
|
);
|
|
1272
3011
|
return {
|
|
1273
|
-
status:
|
|
3012
|
+
status: import_common9.Status.error,
|
|
1274
3013
|
message: `Error adding note to course. ${e.reason || err.message}`
|
|
1275
3014
|
};
|
|
1276
3015
|
}
|
|
@@ -1321,42 +3060,82 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1321
3060
|
logger.debug(JSON.stringify(data));
|
|
1322
3061
|
return Promise.resolve();
|
|
1323
3062
|
}
|
|
1324
|
-
|
|
3063
|
+
/**
|
|
3064
|
+
* Creates an instantiated navigator for this course.
|
|
3065
|
+
*
|
|
3066
|
+
* Handles multiple generators by wrapping them in CompositeGenerator.
|
|
3067
|
+
* This is the preferred method for getting a ready-to-use navigator.
|
|
3068
|
+
*
|
|
3069
|
+
* @param user - User database interface
|
|
3070
|
+
* @returns Instantiated ContentNavigator ready for use
|
|
3071
|
+
*/
|
|
3072
|
+
async createNavigator(user) {
|
|
1325
3073
|
try {
|
|
1326
|
-
const
|
|
1327
|
-
if (
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
return strategy;
|
|
1333
|
-
}
|
|
1334
|
-
} catch (e) {
|
|
1335
|
-
logger.warn(
|
|
1336
|
-
// @ts-expect-error tmp: defaultNavigationStrategyId property does not yet exist
|
|
1337
|
-
`Failed to load strategy '${config.defaultNavigationStrategyId}' specified in course config. Falling back to ELO.`,
|
|
1338
|
-
e
|
|
1339
|
-
);
|
|
1340
|
-
}
|
|
3074
|
+
const allStrategies = await this.getAllNavigationStrategies();
|
|
3075
|
+
if (allStrategies.length === 0) {
|
|
3076
|
+
logger.debug(
|
|
3077
|
+
"[courseDB] No strategy documents found, using default Pipeline(Composite(ELO, SRS), [eloDistanceFilter])"
|
|
3078
|
+
);
|
|
3079
|
+
return this.createDefaultPipeline(user);
|
|
1341
3080
|
}
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
3081
|
+
const assembler = new PipelineAssembler();
|
|
3082
|
+
const { pipeline, generatorStrategies, filterStrategies, warnings } = await assembler.assemble({
|
|
3083
|
+
strategies: allStrategies,
|
|
3084
|
+
user,
|
|
3085
|
+
course: this
|
|
3086
|
+
});
|
|
3087
|
+
for (const warning of warnings) {
|
|
3088
|
+
logger.warn(`[PipelineAssembler] ${warning}`);
|
|
3089
|
+
}
|
|
3090
|
+
if (!pipeline) {
|
|
3091
|
+
logger.debug("[courseDB] Pipeline assembly failed, using default pipeline");
|
|
3092
|
+
return this.createDefaultPipeline(user);
|
|
3093
|
+
}
|
|
3094
|
+
logger.debug(
|
|
3095
|
+
`[courseDB] Using assembled pipeline with ${generatorStrategies.length} generator(s) and ${filterStrategies.length} filter(s)`
|
|
1346
3096
|
);
|
|
3097
|
+
return pipeline;
|
|
3098
|
+
} catch (e) {
|
|
3099
|
+
logger.error(`[courseDB] Error creating navigator: ${e}`);
|
|
3100
|
+
throw e;
|
|
1347
3101
|
}
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
3102
|
+
}
|
|
3103
|
+
makeDefaultEloStrategy() {
|
|
3104
|
+
return {
|
|
3105
|
+
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
1351
3106
|
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1352
|
-
name: "ELO",
|
|
1353
|
-
description: "ELO-based navigation strategy",
|
|
3107
|
+
name: "ELO (default)",
|
|
3108
|
+
description: "Default ELO-based navigation strategy for new cards",
|
|
1354
3109
|
implementingClass: "elo" /* ELO */,
|
|
1355
3110
|
course: this.id,
|
|
1356
3111
|
serializedData: ""
|
|
1357
|
-
// serde is a noop for ELO navigator.
|
|
1358
3112
|
};
|
|
1359
|
-
|
|
3113
|
+
}
|
|
3114
|
+
makeDefaultSrsStrategy() {
|
|
3115
|
+
return {
|
|
3116
|
+
_id: "NAVIGATION_STRATEGY-SRS-default",
|
|
3117
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
3118
|
+
name: "SRS (default)",
|
|
3119
|
+
description: "Default SRS-based navigation strategy for reviews",
|
|
3120
|
+
implementingClass: "srs" /* SRS */,
|
|
3121
|
+
course: this.id,
|
|
3122
|
+
serializedData: ""
|
|
3123
|
+
};
|
|
3124
|
+
}
|
|
3125
|
+
/**
|
|
3126
|
+
* Creates the default navigation pipeline for courses with no configured strategies.
|
|
3127
|
+
*
|
|
3128
|
+
* Default: Pipeline(Composite(ELO, SRS), [eloDistanceFilter])
|
|
3129
|
+
* - ELO generator: scores new cards by skill proximity
|
|
3130
|
+
* - SRS generator: scores reviews by overdueness and interval recency
|
|
3131
|
+
* - ELO distance filter: penalizes cards far from user's current level
|
|
3132
|
+
*/
|
|
3133
|
+
createDefaultPipeline(user) {
|
|
3134
|
+
const eloNavigator = new ELONavigator(user, this, this.makeDefaultEloStrategy());
|
|
3135
|
+
const srsNavigator = new SRSNavigator(user, this, this.makeDefaultSrsStrategy());
|
|
3136
|
+
const compositeGenerator = new CompositeGenerator([eloNavigator, srsNavigator]);
|
|
3137
|
+
const eloDistanceFilter = createEloDistanceFilter();
|
|
3138
|
+
return new Pipeline(compositeGenerator, [eloDistanceFilter], user, this);
|
|
1360
3139
|
}
|
|
1361
3140
|
////////////////////////////////////
|
|
1362
3141
|
// END NavigationStrategyManager implementation
|
|
@@ -1367,22 +3146,39 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1367
3146
|
async getNewCards(limit = 99) {
|
|
1368
3147
|
const u = await this._getCurrentUser();
|
|
1369
3148
|
try {
|
|
1370
|
-
const
|
|
1371
|
-
const navigator = await ContentNavigator.create(u, this, strategy);
|
|
3149
|
+
const navigator = await this.createNavigator(u);
|
|
1372
3150
|
return navigator.getNewCards(limit);
|
|
1373
3151
|
} catch (e) {
|
|
1374
|
-
logger.error(`[courseDB] Error
|
|
3152
|
+
logger.error(`[courseDB] Error in getNewCards: ${e}`);
|
|
1375
3153
|
throw e;
|
|
1376
3154
|
}
|
|
1377
3155
|
}
|
|
1378
3156
|
async getPendingReviews() {
|
|
1379
3157
|
const u = await this._getCurrentUser();
|
|
1380
3158
|
try {
|
|
1381
|
-
const
|
|
1382
|
-
const navigator = await ContentNavigator.create(u, this, strategy);
|
|
3159
|
+
const navigator = await this.createNavigator(u);
|
|
1383
3160
|
return navigator.getPendingReviews();
|
|
1384
3161
|
} catch (e) {
|
|
1385
|
-
logger.error(`[courseDB] Error
|
|
3162
|
+
logger.error(`[courseDB] Error in getPendingReviews: ${e}`);
|
|
3163
|
+
throw e;
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
3166
|
+
/**
|
|
3167
|
+
* Get cards with suitability scores for presentation.
|
|
3168
|
+
*
|
|
3169
|
+
* This is the PRIMARY API for content sources going forward. Delegates to the
|
|
3170
|
+
* course's configured NavigationStrategy to get scored candidates.
|
|
3171
|
+
*
|
|
3172
|
+
* @param limit - Maximum number of cards to return
|
|
3173
|
+
* @returns Cards sorted by score descending
|
|
3174
|
+
*/
|
|
3175
|
+
async getWeightedCards(limit) {
|
|
3176
|
+
const u = await this._getCurrentUser();
|
|
3177
|
+
try {
|
|
3178
|
+
const navigator = await this.createNavigator(u);
|
|
3179
|
+
return navigator.getWeightedCards(limit);
|
|
3180
|
+
} catch (e) {
|
|
3181
|
+
logger.error(`[courseDB] Error getting weighted cards: ${e}`);
|
|
1386
3182
|
throw e;
|
|
1387
3183
|
}
|
|
1388
3184
|
}
|
|
@@ -1398,7 +3194,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1398
3194
|
const courseDoc = (await u.getCourseRegistrationsDoc()).courses.find((c) => {
|
|
1399
3195
|
return c.courseID === this.id;
|
|
1400
3196
|
});
|
|
1401
|
-
targetElo = (0,
|
|
3197
|
+
targetElo = (0, import_common9.EloToNumber)(courseDoc.elo);
|
|
1402
3198
|
} catch {
|
|
1403
3199
|
targetElo = 1e3;
|
|
1404
3200
|
}
|
|
@@ -1533,13 +3329,13 @@ function getClassroomDB(classID, version) {
|
|
|
1533
3329
|
async function getClassroomConfig(classID) {
|
|
1534
3330
|
return await getClassroomDB(classID, "student").get(CLASSROOM_CONFIG);
|
|
1535
3331
|
}
|
|
1536
|
-
var
|
|
3332
|
+
var import_moment2, classroomLookupDBTitle, CLASSROOM_CONFIG, ClassroomDBBase, StudentClassroomDB, TeacherClassroomDB, ClassroomLookupDB;
|
|
1537
3333
|
var init_classroomDB2 = __esm({
|
|
1538
3334
|
"src/impl/couch/classroomDB.ts"() {
|
|
1539
3335
|
"use strict";
|
|
1540
3336
|
init_factory();
|
|
1541
3337
|
init_logger();
|
|
1542
|
-
|
|
3338
|
+
import_moment2 = __toESM(require("moment"), 1);
|
|
1543
3339
|
init_pouchdb_setup();
|
|
1544
3340
|
init_couch();
|
|
1545
3341
|
init_courseDB();
|
|
@@ -1634,9 +3430,9 @@ var init_classroomDB2 = __esm({
|
|
|
1634
3430
|
}
|
|
1635
3431
|
async getNewCards() {
|
|
1636
3432
|
const activeCards = await this._user.getActiveCards();
|
|
1637
|
-
const now =
|
|
3433
|
+
const now = import_moment2.default.utc();
|
|
1638
3434
|
const assigned = await this.getAssignedContent();
|
|
1639
|
-
const due = assigned.filter((c) => now.isAfter(
|
|
3435
|
+
const due = assigned.filter((c) => now.isAfter(import_moment2.default.utc(c.activeOn, REVIEW_TIME_FORMAT)));
|
|
1640
3436
|
logger.info(`Due content: ${JSON.stringify(due)}`);
|
|
1641
3437
|
let ret = [];
|
|
1642
3438
|
for (let i = 0; i < due.length; i++) {
|
|
@@ -1673,6 +3469,52 @@ var init_classroomDB2 = __esm({
|
|
|
1673
3469
|
}
|
|
1674
3470
|
});
|
|
1675
3471
|
}
|
|
3472
|
+
/**
|
|
3473
|
+
* Get cards with suitability scores for presentation.
|
|
3474
|
+
*
|
|
3475
|
+
* This implementation wraps the legacy getNewCards/getPendingReviews methods,
|
|
3476
|
+
* assigning score=1.0 to all cards. StudentClassroomDB does not currently
|
|
3477
|
+
* support pluggable navigation strategies.
|
|
3478
|
+
*
|
|
3479
|
+
* @param limit - Maximum number of cards to return
|
|
3480
|
+
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
3481
|
+
*/
|
|
3482
|
+
async getWeightedCards(limit) {
|
|
3483
|
+
const [newCards, reviews] = await Promise.all([this.getNewCards(), this.getPendingReviews()]);
|
|
3484
|
+
const weighted = [
|
|
3485
|
+
...newCards.map((c) => ({
|
|
3486
|
+
cardId: c.cardID,
|
|
3487
|
+
courseId: c.courseID,
|
|
3488
|
+
score: 1,
|
|
3489
|
+
provenance: [
|
|
3490
|
+
{
|
|
3491
|
+
strategy: "classroom",
|
|
3492
|
+
strategyName: "Classroom",
|
|
3493
|
+
strategyId: "CLASSROOM",
|
|
3494
|
+
action: "generated",
|
|
3495
|
+
score: 1,
|
|
3496
|
+
reason: "Classroom legacy getNewCards(), new card"
|
|
3497
|
+
}
|
|
3498
|
+
]
|
|
3499
|
+
})),
|
|
3500
|
+
...reviews.map((r) => ({
|
|
3501
|
+
cardId: r.cardID,
|
|
3502
|
+
courseId: r.courseID,
|
|
3503
|
+
score: 1,
|
|
3504
|
+
provenance: [
|
|
3505
|
+
{
|
|
3506
|
+
strategy: "classroom",
|
|
3507
|
+
strategyName: "Classroom",
|
|
3508
|
+
strategyId: "CLASSROOM",
|
|
3509
|
+
action: "generated",
|
|
3510
|
+
score: 1,
|
|
3511
|
+
reason: "Classroom legacy getPendingReviews(), review"
|
|
3512
|
+
}
|
|
3513
|
+
]
|
|
3514
|
+
}))
|
|
3515
|
+
];
|
|
3516
|
+
return weighted.slice(0, limit);
|
|
3517
|
+
}
|
|
1676
3518
|
};
|
|
1677
3519
|
TeacherClassroomDB = class _TeacherClassroomDB extends ClassroomDBBase {
|
|
1678
3520
|
_stuDb;
|
|
@@ -1729,8 +3571,8 @@ var init_classroomDB2 = __esm({
|
|
|
1729
3571
|
type: "tag",
|
|
1730
3572
|
_id: id,
|
|
1731
3573
|
assignedBy: content.assignedBy,
|
|
1732
|
-
assignedOn:
|
|
1733
|
-
activeOn: content.activeOn ||
|
|
3574
|
+
assignedOn: import_moment2.default.utc(),
|
|
3575
|
+
activeOn: content.activeOn || import_moment2.default.utc()
|
|
1734
3576
|
});
|
|
1735
3577
|
} else {
|
|
1736
3578
|
put = await this._db.put({
|
|
@@ -1738,8 +3580,8 @@ var init_classroomDB2 = __esm({
|
|
|
1738
3580
|
type: "course",
|
|
1739
3581
|
_id: id,
|
|
1740
3582
|
assignedBy: content.assignedBy,
|
|
1741
|
-
assignedOn:
|
|
1742
|
-
activeOn: content.activeOn ||
|
|
3583
|
+
assignedOn: import_moment2.default.utc(),
|
|
3584
|
+
activeOn: content.activeOn || import_moment2.default.utc()
|
|
1743
3585
|
});
|
|
1744
3586
|
}
|
|
1745
3587
|
if (put.ok) {
|
|
@@ -1758,6 +3600,213 @@ var init_classroomDB2 = __esm({
|
|
|
1758
3600
|
}
|
|
1759
3601
|
});
|
|
1760
3602
|
|
|
3603
|
+
// src/study/TagFilteredContentSource.ts
|
|
3604
|
+
var import_common10, TagFilteredContentSource;
|
|
3605
|
+
var init_TagFilteredContentSource = __esm({
|
|
3606
|
+
"src/study/TagFilteredContentSource.ts"() {
|
|
3607
|
+
"use strict";
|
|
3608
|
+
import_common10 = require("@vue-skuilder/common");
|
|
3609
|
+
init_courseDB();
|
|
3610
|
+
init_logger();
|
|
3611
|
+
TagFilteredContentSource = class {
|
|
3612
|
+
courseId;
|
|
3613
|
+
filter;
|
|
3614
|
+
user;
|
|
3615
|
+
// Cache resolved card IDs to avoid repeated lookups within a session
|
|
3616
|
+
resolvedCardIds = null;
|
|
3617
|
+
constructor(courseId, filter, user) {
|
|
3618
|
+
this.courseId = courseId;
|
|
3619
|
+
this.filter = filter;
|
|
3620
|
+
this.user = user;
|
|
3621
|
+
logger.info(
|
|
3622
|
+
`[TagFilteredContentSource] Created for course "${courseId}" with filter:`,
|
|
3623
|
+
JSON.stringify(filter)
|
|
3624
|
+
);
|
|
3625
|
+
}
|
|
3626
|
+
/**
|
|
3627
|
+
* Resolves the TagFilter to a set of eligible card IDs.
|
|
3628
|
+
*
|
|
3629
|
+
* - Cards in `include` tags are OR'd together (card needs at least one)
|
|
3630
|
+
* - Cards in `exclude` tags are removed from the result
|
|
3631
|
+
*/
|
|
3632
|
+
async resolveFilteredCardIds() {
|
|
3633
|
+
if (this.resolvedCardIds !== null) {
|
|
3634
|
+
return this.resolvedCardIds;
|
|
3635
|
+
}
|
|
3636
|
+
const includedCardIds = /* @__PURE__ */ new Set();
|
|
3637
|
+
if (this.filter.include.length > 0) {
|
|
3638
|
+
for (const tagName of this.filter.include) {
|
|
3639
|
+
try {
|
|
3640
|
+
const tagDoc = await getTag(this.courseId, tagName);
|
|
3641
|
+
tagDoc.taggedCards.forEach((cardId) => includedCardIds.add(cardId));
|
|
3642
|
+
} catch (error) {
|
|
3643
|
+
logger.warn(
|
|
3644
|
+
`[TagFilteredContentSource] Could not resolve tag "${tagName}" for inclusion:`,
|
|
3645
|
+
error
|
|
3646
|
+
);
|
|
3647
|
+
}
|
|
3648
|
+
}
|
|
3649
|
+
}
|
|
3650
|
+
if (includedCardIds.size === 0 && this.filter.include.length > 0) {
|
|
3651
|
+
logger.warn(
|
|
3652
|
+
`[TagFilteredContentSource] No cards found for include tags: ${this.filter.include.join(", ")}`
|
|
3653
|
+
);
|
|
3654
|
+
this.resolvedCardIds = /* @__PURE__ */ new Set();
|
|
3655
|
+
return this.resolvedCardIds;
|
|
3656
|
+
}
|
|
3657
|
+
const excludedCardIds = /* @__PURE__ */ new Set();
|
|
3658
|
+
if (this.filter.exclude.length > 0) {
|
|
3659
|
+
for (const tagName of this.filter.exclude) {
|
|
3660
|
+
try {
|
|
3661
|
+
const tagDoc = await getTag(this.courseId, tagName);
|
|
3662
|
+
tagDoc.taggedCards.forEach((cardId) => excludedCardIds.add(cardId));
|
|
3663
|
+
} catch (error) {
|
|
3664
|
+
logger.warn(
|
|
3665
|
+
`[TagFilteredContentSource] Could not resolve tag "${tagName}" for exclusion:`,
|
|
3666
|
+
error
|
|
3667
|
+
);
|
|
3668
|
+
}
|
|
3669
|
+
}
|
|
3670
|
+
}
|
|
3671
|
+
const finalCardIds = /* @__PURE__ */ new Set();
|
|
3672
|
+
for (const cardId of includedCardIds) {
|
|
3673
|
+
if (!excludedCardIds.has(cardId)) {
|
|
3674
|
+
finalCardIds.add(cardId);
|
|
3675
|
+
}
|
|
3676
|
+
}
|
|
3677
|
+
logger.info(
|
|
3678
|
+
`[TagFilteredContentSource] Resolved ${finalCardIds.size} cards (included: ${includedCardIds.size}, excluded: ${excludedCardIds.size})`
|
|
3679
|
+
);
|
|
3680
|
+
this.resolvedCardIds = finalCardIds;
|
|
3681
|
+
return finalCardIds;
|
|
3682
|
+
}
|
|
3683
|
+
/**
|
|
3684
|
+
* Gets new cards that match the tag filter and are not already active for the user.
|
|
3685
|
+
*/
|
|
3686
|
+
async getNewCards(limit) {
|
|
3687
|
+
if (!(0, import_common10.hasActiveFilter)(this.filter)) {
|
|
3688
|
+
logger.warn("[TagFilteredContentSource] getNewCards called with no active filter");
|
|
3689
|
+
return [];
|
|
3690
|
+
}
|
|
3691
|
+
const eligibleCardIds = await this.resolveFilteredCardIds();
|
|
3692
|
+
const activeCards = await this.user.getActiveCards();
|
|
3693
|
+
const activeCardIds = new Set(activeCards.map((c) => c.cardID));
|
|
3694
|
+
const newItems = [];
|
|
3695
|
+
for (const cardId of eligibleCardIds) {
|
|
3696
|
+
if (!activeCardIds.has(cardId)) {
|
|
3697
|
+
newItems.push({
|
|
3698
|
+
courseID: this.courseId,
|
|
3699
|
+
cardID: cardId,
|
|
3700
|
+
contentSourceType: "course",
|
|
3701
|
+
contentSourceID: this.courseId,
|
|
3702
|
+
status: "new"
|
|
3703
|
+
});
|
|
3704
|
+
}
|
|
3705
|
+
if (limit !== void 0 && newItems.length >= limit) {
|
|
3706
|
+
break;
|
|
3707
|
+
}
|
|
3708
|
+
}
|
|
3709
|
+
logger.info(`[TagFilteredContentSource] Found ${newItems.length} new cards matching filter`);
|
|
3710
|
+
return newItems;
|
|
3711
|
+
}
|
|
3712
|
+
/**
|
|
3713
|
+
* Gets pending reviews, filtered to only include cards that match the tag filter.
|
|
3714
|
+
*/
|
|
3715
|
+
async getPendingReviews() {
|
|
3716
|
+
if (!(0, import_common10.hasActiveFilter)(this.filter)) {
|
|
3717
|
+
logger.warn("[TagFilteredContentSource] getPendingReviews called with no active filter");
|
|
3718
|
+
return [];
|
|
3719
|
+
}
|
|
3720
|
+
const eligibleCardIds = await this.resolveFilteredCardIds();
|
|
3721
|
+
const allReviews = await this.user.getPendingReviews(this.courseId);
|
|
3722
|
+
const filteredReviews = allReviews.filter((review) => {
|
|
3723
|
+
return eligibleCardIds.has(review.cardId);
|
|
3724
|
+
});
|
|
3725
|
+
logger.info(
|
|
3726
|
+
`[TagFilteredContentSource] Found ${filteredReviews.length} pending reviews matching filter (of ${allReviews.length} total)`
|
|
3727
|
+
);
|
|
3728
|
+
return filteredReviews.map((r) => ({
|
|
3729
|
+
...r,
|
|
3730
|
+
courseID: r.courseId,
|
|
3731
|
+
cardID: r.cardId,
|
|
3732
|
+
contentSourceType: "course",
|
|
3733
|
+
contentSourceID: this.courseId,
|
|
3734
|
+
reviewID: r._id,
|
|
3735
|
+
status: "review"
|
|
3736
|
+
}));
|
|
3737
|
+
}
|
|
3738
|
+
/**
|
|
3739
|
+
* Get cards with suitability scores for presentation.
|
|
3740
|
+
*
|
|
3741
|
+
* This implementation wraps the legacy getNewCards/getPendingReviews methods,
|
|
3742
|
+
* assigning score=1.0 to all cards. TagFilteredContentSource does not currently
|
|
3743
|
+
* support pluggable navigation strategies - it returns flat-scored candidates.
|
|
3744
|
+
*
|
|
3745
|
+
* @param limit - Maximum number of cards to return
|
|
3746
|
+
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
3747
|
+
*/
|
|
3748
|
+
async getWeightedCards(limit) {
|
|
3749
|
+
const [newCards, reviews] = await Promise.all([
|
|
3750
|
+
this.getNewCards(limit),
|
|
3751
|
+
this.getPendingReviews()
|
|
3752
|
+
]);
|
|
3753
|
+
const weighted = [
|
|
3754
|
+
...reviews.map((r) => ({
|
|
3755
|
+
cardId: r.cardID,
|
|
3756
|
+
courseId: r.courseID,
|
|
3757
|
+
score: 1,
|
|
3758
|
+
provenance: [
|
|
3759
|
+
{
|
|
3760
|
+
strategy: "tagFilter",
|
|
3761
|
+
strategyName: "Tag Filter",
|
|
3762
|
+
strategyId: "TAG_FILTER",
|
|
3763
|
+
action: "generated",
|
|
3764
|
+
score: 1,
|
|
3765
|
+
reason: `Tag-filtered review (tags: ${this.filter.include.join(", ")})`
|
|
3766
|
+
}
|
|
3767
|
+
]
|
|
3768
|
+
})),
|
|
3769
|
+
...newCards.map((c) => ({
|
|
3770
|
+
cardId: c.cardID,
|
|
3771
|
+
courseId: c.courseID,
|
|
3772
|
+
score: 1,
|
|
3773
|
+
provenance: [
|
|
3774
|
+
{
|
|
3775
|
+
strategy: "tagFilter",
|
|
3776
|
+
strategyName: "Tag Filter",
|
|
3777
|
+
strategyId: "TAG_FILTER",
|
|
3778
|
+
action: "generated",
|
|
3779
|
+
score: 1,
|
|
3780
|
+
reason: `Tag-filtered new card (tags: ${this.filter.include.join(", ")})`
|
|
3781
|
+
}
|
|
3782
|
+
]
|
|
3783
|
+
}))
|
|
3784
|
+
];
|
|
3785
|
+
return weighted.slice(0, limit);
|
|
3786
|
+
}
|
|
3787
|
+
/**
|
|
3788
|
+
* Clears the cached resolved card IDs.
|
|
3789
|
+
* Call this if the underlying tag data may have changed during a session.
|
|
3790
|
+
*/
|
|
3791
|
+
clearCache() {
|
|
3792
|
+
this.resolvedCardIds = null;
|
|
3793
|
+
}
|
|
3794
|
+
/**
|
|
3795
|
+
* Returns the course ID this source is filtering.
|
|
3796
|
+
*/
|
|
3797
|
+
getCourseId() {
|
|
3798
|
+
return this.courseId;
|
|
3799
|
+
}
|
|
3800
|
+
/**
|
|
3801
|
+
* Returns the active tag filter.
|
|
3802
|
+
*/
|
|
3803
|
+
getFilter() {
|
|
3804
|
+
return this.filter;
|
|
3805
|
+
}
|
|
3806
|
+
};
|
|
3807
|
+
}
|
|
3808
|
+
});
|
|
3809
|
+
|
|
1761
3810
|
// src/core/interfaces/contentSource.ts
|
|
1762
3811
|
function isReview(item) {
|
|
1763
3812
|
const ret = item.status === "review" || item.status === "failed-review" || "reviewID" in item;
|
|
@@ -1767,14 +3816,20 @@ async function getStudySource(source, user) {
|
|
|
1767
3816
|
if (source.type === "classroom") {
|
|
1768
3817
|
return await StudentClassroomDB.factory(source.id, user);
|
|
1769
3818
|
} else {
|
|
3819
|
+
if ((0, import_common11.hasActiveFilter)(source.tagFilter)) {
|
|
3820
|
+
return new TagFilteredContentSource(source.id, source.tagFilter, user);
|
|
3821
|
+
}
|
|
1770
3822
|
return getDataLayer().getCourseDB(source.id);
|
|
1771
3823
|
}
|
|
1772
3824
|
}
|
|
3825
|
+
var import_common11;
|
|
1773
3826
|
var init_contentSource = __esm({
|
|
1774
3827
|
"src/core/interfaces/contentSource.ts"() {
|
|
1775
3828
|
"use strict";
|
|
1776
3829
|
init_factory();
|
|
1777
3830
|
init_classroomDB2();
|
|
3831
|
+
import_common11 = require("@vue-skuilder/common");
|
|
3832
|
+
init_TagFilteredContentSource();
|
|
1778
3833
|
}
|
|
1779
3834
|
});
|
|
1780
3835
|
|
|
@@ -1819,6 +3874,16 @@ var init_user = __esm({
|
|
|
1819
3874
|
}
|
|
1820
3875
|
});
|
|
1821
3876
|
|
|
3877
|
+
// src/core/types/strategyState.ts
|
|
3878
|
+
function buildStrategyStateId(courseId, strategyKey) {
|
|
3879
|
+
return `STRATEGY_STATE::${courseId}::${strategyKey}`;
|
|
3880
|
+
}
|
|
3881
|
+
var init_strategyState = __esm({
|
|
3882
|
+
"src/core/types/strategyState.ts"() {
|
|
3883
|
+
"use strict";
|
|
3884
|
+
}
|
|
3885
|
+
});
|
|
3886
|
+
|
|
1822
3887
|
// src/core/util/index.ts
|
|
1823
3888
|
function getCardHistoryID(courseID, cardID) {
|
|
1824
3889
|
return `${DocTypePrefixes["CARDRECORD" /* CARDRECORD */]}-${courseID}-${cardID}`;
|
|
@@ -1831,17 +3896,17 @@ var init_util = __esm({
|
|
|
1831
3896
|
});
|
|
1832
3897
|
|
|
1833
3898
|
// src/core/bulkImport/cardProcessor.ts
|
|
1834
|
-
var
|
|
3899
|
+
var import_common12;
|
|
1835
3900
|
var init_cardProcessor = __esm({
|
|
1836
3901
|
"src/core/bulkImport/cardProcessor.ts"() {
|
|
1837
3902
|
"use strict";
|
|
1838
|
-
|
|
3903
|
+
import_common12 = require("@vue-skuilder/common");
|
|
1839
3904
|
init_logger();
|
|
1840
3905
|
}
|
|
1841
3906
|
});
|
|
1842
3907
|
|
|
1843
3908
|
// src/core/bulkImport/types.ts
|
|
1844
|
-
var
|
|
3909
|
+
var init_types3 = __esm({
|
|
1845
3910
|
"src/core/bulkImport/types.ts"() {
|
|
1846
3911
|
"use strict";
|
|
1847
3912
|
}
|
|
@@ -1852,7 +3917,7 @@ var init_bulkImport = __esm({
|
|
|
1852
3917
|
"src/core/bulkImport/index.ts"() {
|
|
1853
3918
|
"use strict";
|
|
1854
3919
|
init_cardProcessor();
|
|
1855
|
-
|
|
3920
|
+
init_types3();
|
|
1856
3921
|
}
|
|
1857
3922
|
});
|
|
1858
3923
|
|
|
@@ -1863,6 +3928,7 @@ var init_core = __esm({
|
|
|
1863
3928
|
init_interfaces();
|
|
1864
3929
|
init_types_legacy();
|
|
1865
3930
|
init_user();
|
|
3931
|
+
init_strategyState();
|
|
1866
3932
|
init_Loggable();
|
|
1867
3933
|
init_util();
|
|
1868
3934
|
init_navigators();
|
|
@@ -1893,8 +3959,8 @@ var path, os;
|
|
|
1893
3959
|
var init_dataDirectory = __esm({
|
|
1894
3960
|
"src/util/dataDirectory.ts"() {
|
|
1895
3961
|
"use strict";
|
|
1896
|
-
path = __toESM(require("path"));
|
|
1897
|
-
os = __toESM(require("os"));
|
|
3962
|
+
path = __toESM(require("path"), 1);
|
|
3963
|
+
os = __toESM(require("os"), 1);
|
|
1898
3964
|
init_tuiLogger();
|
|
1899
3965
|
init_factory();
|
|
1900
3966
|
}
|
|
@@ -1928,7 +3994,7 @@ function getStartAndEndKeys2(key) {
|
|
|
1928
3994
|
};
|
|
1929
3995
|
}
|
|
1930
3996
|
function updateGuestAccountExpirationDate(guestDB) {
|
|
1931
|
-
const currentTime =
|
|
3997
|
+
const currentTime = import_moment3.default.utc();
|
|
1932
3998
|
const expirationDate = currentTime.add(2, "months").toISOString();
|
|
1933
3999
|
const expiryDocID2 = "GuestAccountExpirationDate";
|
|
1934
4000
|
void guestDB.get(expiryDocID2).then((doc) => {
|
|
@@ -1953,7 +4019,7 @@ function getLocalUserDB(username) {
|
|
|
1953
4019
|
}
|
|
1954
4020
|
}
|
|
1955
4021
|
function scheduleCardReviewLocal(userDB, review) {
|
|
1956
|
-
const now =
|
|
4022
|
+
const now = import_moment3.default.utc();
|
|
1957
4023
|
logger.info(`Scheduling for review in: ${review.time.diff(now, "h") / 24} days`);
|
|
1958
4024
|
void userDB.put({
|
|
1959
4025
|
_id: DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */] + review.time.format(REVIEW_TIME_FORMAT2),
|
|
@@ -1976,11 +4042,11 @@ async function removeScheduledCardReviewLocal(userDB, reviewDocID) {
|
|
|
1976
4042
|
${JSON.stringify(err)}`);
|
|
1977
4043
|
});
|
|
1978
4044
|
}
|
|
1979
|
-
var
|
|
4045
|
+
var import_moment3, REVIEW_TIME_FORMAT2, log2;
|
|
1980
4046
|
var init_userDBHelpers = __esm({
|
|
1981
4047
|
"src/impl/common/userDBHelpers.ts"() {
|
|
1982
4048
|
"use strict";
|
|
1983
|
-
|
|
4049
|
+
import_moment3 = __toESM(require("moment"), 1);
|
|
1984
4050
|
init_core();
|
|
1985
4051
|
init_logger();
|
|
1986
4052
|
init_pouchdb_setup();
|
|
@@ -1993,11 +4059,11 @@ var init_userDBHelpers = __esm({
|
|
|
1993
4059
|
});
|
|
1994
4060
|
|
|
1995
4061
|
// src/impl/couch/user-course-relDB.ts
|
|
1996
|
-
var
|
|
4062
|
+
var import_moment4, UsrCrsData;
|
|
1997
4063
|
var init_user_course_relDB = __esm({
|
|
1998
4064
|
"src/impl/couch/user-course-relDB.ts"() {
|
|
1999
4065
|
"use strict";
|
|
2000
|
-
|
|
4066
|
+
import_moment4 = __toESM(require("moment"), 1);
|
|
2001
4067
|
init_logger();
|
|
2002
4068
|
UsrCrsData = class {
|
|
2003
4069
|
user;
|
|
@@ -2007,11 +4073,11 @@ var init_user_course_relDB = __esm({
|
|
|
2007
4073
|
this._courseId = courseId;
|
|
2008
4074
|
}
|
|
2009
4075
|
async getReviewsForcast(daysCount) {
|
|
2010
|
-
const time =
|
|
4076
|
+
const time = import_moment4.default.utc().add(daysCount, "days");
|
|
2011
4077
|
return this.getReviewstoDate(time);
|
|
2012
4078
|
}
|
|
2013
4079
|
async getPendingReviews() {
|
|
2014
|
-
const now =
|
|
4080
|
+
const now = import_moment4.default.utc();
|
|
2015
4081
|
return this.getReviewstoDate(now);
|
|
2016
4082
|
}
|
|
2017
4083
|
async getScheduledReviewCount() {
|
|
@@ -2038,7 +4104,7 @@ var init_user_course_relDB = __esm({
|
|
|
2038
4104
|
`Fetching ${this.user.getUsername()}'s scheduled reviews for course ${this._courseId}.`
|
|
2039
4105
|
);
|
|
2040
4106
|
return allReviews.filter((review) => {
|
|
2041
|
-
const reviewTime =
|
|
4107
|
+
const reviewTime = import_moment4.default.utc(review.reviewTime);
|
|
2042
4108
|
return targetDate.isAfter(reviewTime);
|
|
2043
4109
|
});
|
|
2044
4110
|
}
|
|
@@ -2050,7 +4116,9 @@ var init_user_course_relDB = __esm({
|
|
|
2050
4116
|
function accomodateGuest() {
|
|
2051
4117
|
logger.log("[funnel] accomodateGuest() called");
|
|
2052
4118
|
if (typeof localStorage === "undefined") {
|
|
2053
|
-
logger.log(
|
|
4119
|
+
logger.log(
|
|
4120
|
+
"[funnel] localStorage not available (Node.js environment), returning default guest"
|
|
4121
|
+
);
|
|
2054
4122
|
return {
|
|
2055
4123
|
username: GuestUsername + "nodejs-test",
|
|
2056
4124
|
firstVisit: true
|
|
@@ -2218,14 +4286,14 @@ async function dropUserFromClassroom(user, classID) {
|
|
|
2218
4286
|
async function getUserClassrooms(user) {
|
|
2219
4287
|
return getOrCreateClassroomRegistrationsDoc(user);
|
|
2220
4288
|
}
|
|
2221
|
-
var
|
|
4289
|
+
var import_common13, import_moment5, log3, BaseUser, userCoursesDoc, userClassroomsDoc;
|
|
2222
4290
|
var init_BaseUserDB = __esm({
|
|
2223
4291
|
"src/impl/common/BaseUserDB.ts"() {
|
|
2224
4292
|
"use strict";
|
|
2225
4293
|
init_core();
|
|
2226
4294
|
init_util();
|
|
2227
|
-
|
|
2228
|
-
|
|
4295
|
+
import_common13 = require("@vue-skuilder/common");
|
|
4296
|
+
import_moment5 = __toESM(require("moment"), 1);
|
|
2229
4297
|
init_types_legacy();
|
|
2230
4298
|
init_logger();
|
|
2231
4299
|
init_userDBHelpers();
|
|
@@ -2274,7 +4342,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2274
4342
|
);
|
|
2275
4343
|
}
|
|
2276
4344
|
const result = await this.syncStrategy.createAccount(username, password);
|
|
2277
|
-
if (result.status ===
|
|
4345
|
+
if (result.status === import_common13.Status.ok) {
|
|
2278
4346
|
log3(`Account created successfully, updating username to ${username}`);
|
|
2279
4347
|
this._username = username;
|
|
2280
4348
|
try {
|
|
@@ -2316,7 +4384,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2316
4384
|
async resetUserData() {
|
|
2317
4385
|
if (this.syncStrategy.canAuthenticate()) {
|
|
2318
4386
|
return {
|
|
2319
|
-
status:
|
|
4387
|
+
status: import_common13.Status.error,
|
|
2320
4388
|
error: "Reset user data is only available for local-only mode. Use logout instead for remote sync."
|
|
2321
4389
|
};
|
|
2322
4390
|
}
|
|
@@ -2335,11 +4403,11 @@ Currently logged-in as ${this._username}.`
|
|
|
2335
4403
|
await localDB.bulkDocs(docsToDelete);
|
|
2336
4404
|
}
|
|
2337
4405
|
await this.init();
|
|
2338
|
-
return { status:
|
|
4406
|
+
return { status: import_common13.Status.ok };
|
|
2339
4407
|
} catch (error) {
|
|
2340
4408
|
logger.error("Failed to reset user data:", error);
|
|
2341
4409
|
return {
|
|
2342
|
-
status:
|
|
4410
|
+
status: import_common13.Status.error,
|
|
2343
4411
|
error: error instanceof Error ? error.message : "Unknown error during reset"
|
|
2344
4412
|
};
|
|
2345
4413
|
}
|
|
@@ -2486,7 +4554,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2486
4554
|
);
|
|
2487
4555
|
return reviews.rows.filter((r) => {
|
|
2488
4556
|
if (r.id.startsWith(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */])) {
|
|
2489
|
-
const date =
|
|
4557
|
+
const date = import_moment5.default.utc(
|
|
2490
4558
|
r.id.substr(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */].length),
|
|
2491
4559
|
REVIEW_TIME_FORMAT2
|
|
2492
4560
|
);
|
|
@@ -2499,11 +4567,11 @@ Currently logged-in as ${this._username}.`
|
|
|
2499
4567
|
}).map((r) => r.doc);
|
|
2500
4568
|
}
|
|
2501
4569
|
async getReviewsForcast(daysCount) {
|
|
2502
|
-
const time =
|
|
4570
|
+
const time = import_moment5.default.utc().add(daysCount, "days");
|
|
2503
4571
|
return this.getReviewstoDate(time);
|
|
2504
4572
|
}
|
|
2505
4573
|
async getPendingReviews(course_id) {
|
|
2506
|
-
const now =
|
|
4574
|
+
const now = import_moment5.default.utc();
|
|
2507
4575
|
return this.getReviewstoDate(now, course_id);
|
|
2508
4576
|
}
|
|
2509
4577
|
async getScheduledReviewCount(course_id) {
|
|
@@ -2790,7 +4858,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2790
4858
|
*/
|
|
2791
4859
|
async putCardRecord(record) {
|
|
2792
4860
|
const cardHistoryID = getCardHistoryID(record.courseID, record.cardID);
|
|
2793
|
-
record.timeStamp =
|
|
4861
|
+
record.timeStamp = import_moment5.default.utc(record.timeStamp).toString();
|
|
2794
4862
|
try {
|
|
2795
4863
|
const cardHistory = await this.update(
|
|
2796
4864
|
cardHistoryID,
|
|
@@ -2806,7 +4874,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2806
4874
|
const ret = {
|
|
2807
4875
|
...record2
|
|
2808
4876
|
};
|
|
2809
|
-
ret.timeStamp =
|
|
4877
|
+
ret.timeStamp = import_moment5.default.utc(record2.timeStamp);
|
|
2810
4878
|
return ret;
|
|
2811
4879
|
});
|
|
2812
4880
|
return cardHistory;
|
|
@@ -3030,6 +5098,55 @@ Currently logged-in as ${this._username}.`
|
|
|
3030
5098
|
async updateUserElo(courseId, elo) {
|
|
3031
5099
|
return updateUserElo(this._username, courseId, elo);
|
|
3032
5100
|
}
|
|
5101
|
+
async getStrategyState(courseId, strategyKey) {
|
|
5102
|
+
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
5103
|
+
try {
|
|
5104
|
+
const doc = await this.localDB.get(docId);
|
|
5105
|
+
return doc.data;
|
|
5106
|
+
} catch (e) {
|
|
5107
|
+
const err = e;
|
|
5108
|
+
if (err.status === 404) {
|
|
5109
|
+
return null;
|
|
5110
|
+
}
|
|
5111
|
+
throw e;
|
|
5112
|
+
}
|
|
5113
|
+
}
|
|
5114
|
+
async putStrategyState(courseId, strategyKey, data) {
|
|
5115
|
+
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
5116
|
+
let existingRev;
|
|
5117
|
+
try {
|
|
5118
|
+
const existing = await this.localDB.get(docId);
|
|
5119
|
+
existingRev = existing._rev;
|
|
5120
|
+
} catch (e) {
|
|
5121
|
+
const err = e;
|
|
5122
|
+
if (err.status !== 404) {
|
|
5123
|
+
throw e;
|
|
5124
|
+
}
|
|
5125
|
+
}
|
|
5126
|
+
const doc = {
|
|
5127
|
+
_id: docId,
|
|
5128
|
+
_rev: existingRev,
|
|
5129
|
+
docType: "STRATEGY_STATE" /* STRATEGY_STATE */,
|
|
5130
|
+
courseId,
|
|
5131
|
+
strategyKey,
|
|
5132
|
+
data,
|
|
5133
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5134
|
+
};
|
|
5135
|
+
await this.localDB.put(doc);
|
|
5136
|
+
}
|
|
5137
|
+
async deleteStrategyState(courseId, strategyKey) {
|
|
5138
|
+
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
5139
|
+
try {
|
|
5140
|
+
const doc = await this.localDB.get(docId);
|
|
5141
|
+
await this.localDB.remove(doc);
|
|
5142
|
+
} catch (e) {
|
|
5143
|
+
const err = e;
|
|
5144
|
+
if (err.status === 404) {
|
|
5145
|
+
return;
|
|
5146
|
+
}
|
|
5147
|
+
throw e;
|
|
5148
|
+
}
|
|
5149
|
+
}
|
|
3033
5150
|
};
|
|
3034
5151
|
userCoursesDoc = "CourseRegistrations";
|
|
3035
5152
|
userClassroomsDoc = "ClassroomRegistrations";
|
|
@@ -3130,8 +5247,7 @@ var init_adminDB2 = __esm({
|
|
|
3130
5247
|
}
|
|
3131
5248
|
}
|
|
3132
5249
|
}
|
|
3133
|
-
|
|
3134
|
-
return dbs.map((db) => {
|
|
5250
|
+
return promisedCRDbs.map((db) => {
|
|
3135
5251
|
return {
|
|
3136
5252
|
...db.getConfig(),
|
|
3137
5253
|
_id: db._id
|
|
@@ -3180,19 +5296,19 @@ var init_auth = __esm({
|
|
|
3180
5296
|
"use strict";
|
|
3181
5297
|
init_factory();
|
|
3182
5298
|
init_logger();
|
|
3183
|
-
import_cross_fetch = __toESM(require("cross-fetch"));
|
|
5299
|
+
import_cross_fetch = __toESM(require("cross-fetch"), 1);
|
|
3184
5300
|
}
|
|
3185
5301
|
});
|
|
3186
5302
|
|
|
3187
5303
|
// src/impl/couch/CouchDBSyncStrategy.ts
|
|
3188
|
-
var
|
|
5304
|
+
var import_common15, log4, CouchDBSyncStrategy;
|
|
3189
5305
|
var init_CouchDBSyncStrategy = __esm({
|
|
3190
5306
|
"src/impl/couch/CouchDBSyncStrategy.ts"() {
|
|
3191
5307
|
"use strict";
|
|
3192
5308
|
init_factory();
|
|
3193
5309
|
init_types_legacy();
|
|
3194
5310
|
init_logger();
|
|
3195
|
-
|
|
5311
|
+
import_common15 = require("@vue-skuilder/common");
|
|
3196
5312
|
init_common();
|
|
3197
5313
|
init_pouchdb_setup();
|
|
3198
5314
|
init_couch();
|
|
@@ -3263,32 +5379,32 @@ var init_CouchDBSyncStrategy = __esm({
|
|
|
3263
5379
|
}
|
|
3264
5380
|
}
|
|
3265
5381
|
return {
|
|
3266
|
-
status:
|
|
5382
|
+
status: import_common15.Status.ok,
|
|
3267
5383
|
error: void 0
|
|
3268
5384
|
};
|
|
3269
5385
|
} else {
|
|
3270
5386
|
return {
|
|
3271
|
-
status:
|
|
5387
|
+
status: import_common15.Status.error,
|
|
3272
5388
|
error: "Failed to log in after account creation"
|
|
3273
5389
|
};
|
|
3274
5390
|
}
|
|
3275
5391
|
} else {
|
|
3276
5392
|
logger.warn(`Signup not OK: ${JSON.stringify(signupRequest)}`);
|
|
3277
5393
|
return {
|
|
3278
|
-
status:
|
|
5394
|
+
status: import_common15.Status.error,
|
|
3279
5395
|
error: "Account creation failed"
|
|
3280
5396
|
};
|
|
3281
5397
|
}
|
|
3282
5398
|
} catch (e) {
|
|
3283
5399
|
if (e.reason === "Document update conflict.") {
|
|
3284
5400
|
return {
|
|
3285
|
-
status:
|
|
5401
|
+
status: import_common15.Status.error,
|
|
3286
5402
|
error: "This username is taken!"
|
|
3287
5403
|
};
|
|
3288
5404
|
}
|
|
3289
5405
|
logger.error(`Error on signup: ${JSON.stringify(e)}`);
|
|
3290
5406
|
return {
|
|
3291
|
-
status:
|
|
5407
|
+
status: import_common15.Status.error,
|
|
3292
5408
|
error: e.message || "Unknown error during account creation"
|
|
3293
5409
|
};
|
|
3294
5410
|
}
|
|
@@ -3527,7 +5643,7 @@ async function usernameIsAvailable(username) {
|
|
|
3527
5643
|
}
|
|
3528
5644
|
}
|
|
3529
5645
|
function updateGuestAccountExpirationDate2(guestDB) {
|
|
3530
|
-
const currentTime =
|
|
5646
|
+
const currentTime = import_moment6.default.utc();
|
|
3531
5647
|
const expirationDate = currentTime.add(2, "months").toISOString();
|
|
3532
5648
|
void guestDB.get(expiryDocID).then((doc) => {
|
|
3533
5649
|
return guestDB.put({
|
|
@@ -3590,7 +5706,7 @@ function getCouchUserDB(username) {
|
|
|
3590
5706
|
return ret;
|
|
3591
5707
|
}
|
|
3592
5708
|
function scheduleCardReview(review) {
|
|
3593
|
-
const now =
|
|
5709
|
+
const now = import_moment6.default.utc();
|
|
3594
5710
|
logger.info(`Scheduling for review in: ${review.time.diff(now, "h") / 24} days`);
|
|
3595
5711
|
void getCouchUserDB(review.user).put({
|
|
3596
5712
|
_id: DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */] + review.time.format(REVIEW_TIME_FORMAT),
|
|
@@ -3619,16 +5735,16 @@ function getStartAndEndKeys(key) {
|
|
|
3619
5735
|
endkey: key + "\uFFF0"
|
|
3620
5736
|
};
|
|
3621
5737
|
}
|
|
3622
|
-
var import_cross_fetch2,
|
|
5738
|
+
var import_cross_fetch2, import_moment6, import_process, isBrowser, expiryDocID, GUEST_LOCAL_DB, localUserDB, pouchDBincludeCredentialsConfig, REVIEW_TIME_FORMAT;
|
|
3623
5739
|
var init_couch = __esm({
|
|
3624
5740
|
"src/impl/couch/index.ts"() {
|
|
3625
5741
|
init_factory();
|
|
3626
5742
|
init_types_legacy();
|
|
3627
|
-
import_cross_fetch2 = __toESM(require("cross-fetch"));
|
|
3628
|
-
|
|
5743
|
+
import_cross_fetch2 = __toESM(require("cross-fetch"), 1);
|
|
5744
|
+
import_moment6 = __toESM(require("moment"), 1);
|
|
3629
5745
|
init_logger();
|
|
3630
5746
|
init_pouchdb_setup();
|
|
3631
|
-
import_process = __toESM(require("process"));
|
|
5747
|
+
import_process = __toESM(require("process"), 1);
|
|
3632
5748
|
init_contentSource();
|
|
3633
5749
|
init_adminDB2();
|
|
3634
5750
|
init_classroomDB2();
|