@vue-skuilder/db 0.1.18 → 0.1.21
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/CLAUDE.md +2 -2
- package/dist/{classroomDB-BgfrVb8d.d.ts → contentSource-BP9hznNV.d.ts} +220 -197
- package/dist/{classroomDB-CTOenngH.d.cts → contentSource-DsJadoBU.d.cts} +220 -197
- package/dist/core/index.d.cts +80 -6
- package/dist/core/index.d.ts +80 -6
- package/dist/core/index.js +735 -1560
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +708 -1539
- package/dist/core/index.mjs.map +1 -1
- package/dist/{dataLayerProvider-D6PoCwS6.d.cts → dataLayerProvider-CHYrQ5pB.d.cts} +1 -1
- package/dist/{dataLayerProvider-CZxC9GtB.d.ts → dataLayerProvider-MDTxXq2l.d.ts} +1 -1
- package/dist/impl/couch/index.d.cts +8 -23
- package/dist/impl/couch/index.d.ts +8 -23
- package/dist/impl/couch/index.js +723 -1578
- package/dist/impl/couch/index.js.map +1 -1
- package/dist/impl/couch/index.mjs +692 -1552
- package/dist/impl/couch/index.mjs.map +1 -1
- package/dist/impl/static/index.d.cts +25 -8
- package/dist/impl/static/index.d.ts +25 -8
- package/dist/impl/static/index.js +700 -1400
- package/dist/impl/static/index.js.map +1 -1
- package/dist/impl/static/index.mjs +688 -1393
- package/dist/impl/static/index.mjs.map +1 -1
- package/dist/{index-D-Fa4Smt.d.cts → index-B_j6u5E4.d.cts} +1 -1
- package/dist/{index-CD8BZz2k.d.ts → index-Dj0SEgk3.d.ts} +1 -1
- package/dist/index.d.cts +71 -63
- package/dist/index.d.ts +71 -63
- package/dist/index.js +1162 -1996
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1124 -1955
- package/dist/index.mjs.map +1 -1
- package/dist/pouch/index.js +3 -0
- package/dist/pouch/index.js.map +1 -1
- package/dist/pouch/index.mjs +3 -0
- package/dist/pouch/index.mjs.map +1 -1
- package/dist/{types-CzPDLAK6.d.cts → types-Bn0itutr.d.cts} +1 -1
- package/dist/{types-CewsN87z.d.ts → types-DQaXnuoc.d.ts} +1 -1
- package/dist/{types-legacy-6ettoclI.d.cts → types-legacy-DDY4N-Uq.d.cts} +3 -1
- package/dist/{types-legacy-6ettoclI.d.ts → types-legacy-DDY4N-Uq.d.ts} +3 -1
- package/dist/util/packer/index.d.cts +3 -3
- package/dist/util/packer/index.d.ts +3 -3
- package/docs/navigators-architecture.md +115 -17
- package/package.json +4 -4
- package/src/core/index.ts +1 -0
- package/src/core/interfaces/classroomDB.ts +5 -13
- package/src/core/interfaces/contentSource.ts +6 -66
- package/src/core/interfaces/courseDB.ts +15 -7
- package/src/core/interfaces/userDB.ts +32 -0
- package/src/core/navigators/Pipeline.ts +136 -52
- package/src/core/navigators/PipelineAssembler.ts +1 -1
- package/src/core/navigators/defaults.ts +84 -0
- package/src/core/navigators/{hierarchyDefinition.ts → filters/hierarchyDefinition.ts} +15 -29
- package/src/core/navigators/filters/index.ts +3 -0
- package/src/core/navigators/filters/inferredPreferenceStub.ts +107 -0
- package/src/core/navigators/{interferenceMitigator.ts → filters/interferenceMitigator.ts} +11 -37
- package/src/core/navigators/{relativePriority.ts → filters/relativePriority.ts} +12 -38
- package/src/core/navigators/filters/userGoalStub.ts +136 -0
- package/src/core/navigators/filters/userTagPreference.ts +217 -0
- package/src/core/navigators/{CompositeGenerator.ts → generators/CompositeGenerator.ts} +15 -64
- package/src/core/navigators/{elo.ts → generators/elo.ts} +13 -63
- package/src/core/navigators/{srs.ts → generators/srs.ts} +11 -40
- package/src/core/navigators/generators/types.ts +1 -1
- package/src/core/navigators/index.ts +95 -91
- 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 +100 -103
- package/src/impl/couch/courseDB.ts +35 -91
- package/src/impl/couch/pouchdb-setup.ts +7 -0
- package/src/impl/static/StaticDataUnpacker.ts +50 -1
- package/src/impl/static/courseDB.ts +87 -37
- package/src/study/SessionController.ts +122 -202
- package/src/study/SourceMixer.ts +65 -0
- package/src/study/TagFilteredContentSource.ts +49 -92
- package/src/study/index.ts +1 -0
- package/src/study/services/CardHydrationService.ts +165 -81
- package/src/util/dataDirectory.ts +1 -1
- package/src/util/index.ts +0 -1
- package/tests/core/navigators/CompositeGenerator.test.ts +44 -168
- package/tests/core/navigators/Pipeline.test.ts +6 -72
- package/tests/core/navigators/PipelineAssembler.test.ts +8 -58
- package/tests/core/navigators/navigators.test.ts +118 -151
- package/docs/todo-pipeline-optimization.md +0 -117
- package/docs/todo-strategy-state-storage.md +0 -278
- package/src/core/navigators/hardcodedOrder.ts +0 -163
- package/src/util/tuiLogger.ts +0 -139
package/dist/impl/couch/index.js
CHANGED
|
@@ -5,11 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __glob = (map) => (path2) => {
|
|
9
|
-
var fn = map[path2];
|
|
10
|
-
if (fn) return fn();
|
|
11
|
-
throw new Error("Module not found in bundle: " + path2);
|
|
12
|
-
};
|
|
13
8
|
var __esm = (fn, res) => function __init() {
|
|
14
9
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
15
10
|
};
|
|
@@ -111,6 +106,9 @@ var init_pouchdb_setup = __esm({
|
|
|
111
106
|
import_pouchdb_authentication = __toESM(require("@nilock2/pouchdb-authentication"), 1);
|
|
112
107
|
import_pouchdb.default.plugin(import_pouchdb_find.default);
|
|
113
108
|
import_pouchdb.default.plugin(import_pouchdb_authentication.default);
|
|
109
|
+
if (typeof import_pouchdb.default.debug !== "undefined") {
|
|
110
|
+
import_pouchdb.default.debug.disable();
|
|
111
|
+
}
|
|
114
112
|
import_pouchdb.default.defaults({
|
|
115
113
|
// ajax: {
|
|
116
114
|
// timeout: 60000,
|
|
@@ -280,7 +278,8 @@ var init_types_legacy = __esm({
|
|
|
280
278
|
["QUESTION" /* QUESTIONTYPE */]: "QUESTION",
|
|
281
279
|
["VIEW" /* VIEW */]: "VIEW",
|
|
282
280
|
["PEDAGOGY" /* PEDAGOGY */]: "PEDAGOGY",
|
|
283
|
-
["NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */]: "NAVIGATION_STRATEGY"
|
|
281
|
+
["NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */]: "NAVIGATION_STRATEGY",
|
|
282
|
+
["STRATEGY_STATE" /* STRATEGY_STATE */]: "STRATEGY_STATE"
|
|
284
283
|
};
|
|
285
284
|
}
|
|
286
285
|
});
|
|
@@ -621,24 +620,331 @@ var init_courseLookupDB = __esm({
|
|
|
621
620
|
}
|
|
622
621
|
});
|
|
623
622
|
|
|
624
|
-
// src/core/navigators/
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
623
|
+
// src/core/navigators/index.ts
|
|
624
|
+
function isGenerator(impl) {
|
|
625
|
+
return NavigatorRoles[impl] === "generator" /* GENERATOR */;
|
|
626
|
+
}
|
|
627
|
+
function isFilter(impl) {
|
|
628
|
+
return NavigatorRoles[impl] === "filter" /* FILTER */;
|
|
629
|
+
}
|
|
630
|
+
var NavigatorRoles, ContentNavigator;
|
|
631
|
+
var init_navigators = __esm({
|
|
632
|
+
"src/core/navigators/index.ts"() {
|
|
633
|
+
"use strict";
|
|
634
|
+
init_logger();
|
|
635
|
+
NavigatorRoles = {
|
|
636
|
+
["elo" /* ELO */]: "generator" /* GENERATOR */,
|
|
637
|
+
["srs" /* SRS */]: "generator" /* GENERATOR */,
|
|
638
|
+
["hierarchyDefinition" /* HIERARCHY */]: "filter" /* FILTER */,
|
|
639
|
+
["interferenceMitigator" /* INTERFERENCE */]: "filter" /* FILTER */,
|
|
640
|
+
["relativePriority" /* RELATIVE_PRIORITY */]: "filter" /* FILTER */,
|
|
641
|
+
["userTagPreference" /* USER_TAG_PREFERENCE */]: "filter" /* FILTER */
|
|
642
|
+
};
|
|
643
|
+
ContentNavigator = class {
|
|
644
|
+
/** User interface for this navigation session */
|
|
645
|
+
user;
|
|
646
|
+
/** Course interface for this navigation session */
|
|
647
|
+
course;
|
|
648
|
+
/** Human-readable name for this strategy instance (from ContentNavigationStrategyData.name) */
|
|
649
|
+
strategyName;
|
|
650
|
+
/** Unique document ID for this strategy instance (from ContentNavigationStrategyData._id) */
|
|
651
|
+
strategyId;
|
|
652
|
+
/**
|
|
653
|
+
* Constructor for standard navigators.
|
|
654
|
+
* Call this from subclass constructors to initialize common fields.
|
|
655
|
+
*
|
|
656
|
+
* Note: CompositeGenerator and Pipeline call super() without args, then set
|
|
657
|
+
* user/course fields directly if needed.
|
|
658
|
+
*/
|
|
659
|
+
constructor(user, course, strategyData) {
|
|
660
|
+
this.user = user;
|
|
661
|
+
this.course = course;
|
|
662
|
+
if (strategyData) {
|
|
663
|
+
this.strategyName = strategyData.name;
|
|
664
|
+
this.strategyId = strategyData._id;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
// ============================================================================
|
|
668
|
+
// STRATEGY STATE HELPERS
|
|
669
|
+
// ============================================================================
|
|
670
|
+
//
|
|
671
|
+
// These methods allow strategies to persist their own state (user preferences,
|
|
672
|
+
// learned patterns, temporal tracking) in the user database.
|
|
673
|
+
//
|
|
674
|
+
// ============================================================================
|
|
675
|
+
/**
|
|
676
|
+
* Unique key identifying this strategy for state storage.
|
|
677
|
+
*
|
|
678
|
+
* Defaults to the constructor name (e.g., "UserTagPreferenceFilter").
|
|
679
|
+
* Override in subclasses if multiple instances of the same strategy type
|
|
680
|
+
* need separate state storage.
|
|
681
|
+
*/
|
|
682
|
+
get strategyKey() {
|
|
683
|
+
return this.constructor.name;
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* Get this strategy's persisted state for the current course.
|
|
687
|
+
*
|
|
688
|
+
* @returns The strategy's data payload, or null if no state exists
|
|
689
|
+
* @throws Error if user or course is not initialized
|
|
690
|
+
*/
|
|
691
|
+
async getStrategyState() {
|
|
692
|
+
if (!this.user || !this.course) {
|
|
693
|
+
throw new Error(
|
|
694
|
+
`Cannot get strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
return this.user.getStrategyState(this.course.getCourseID(), this.strategyKey);
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Persist this strategy's state for the current course.
|
|
701
|
+
*
|
|
702
|
+
* @param data - The strategy's data payload to store
|
|
703
|
+
* @throws Error if user or course is not initialized
|
|
704
|
+
*/
|
|
705
|
+
async putStrategyState(data) {
|
|
706
|
+
if (!this.user || !this.course) {
|
|
707
|
+
throw new Error(
|
|
708
|
+
`Cannot put strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
709
|
+
);
|
|
710
|
+
}
|
|
711
|
+
return this.user.putStrategyState(this.course.getCourseID(), this.strategyKey, data);
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Factory method to create navigator instances dynamically.
|
|
715
|
+
*
|
|
716
|
+
* @param user - User interface
|
|
717
|
+
* @param course - Course interface
|
|
718
|
+
* @param strategyData - Strategy configuration document
|
|
719
|
+
* @returns the runtime object used to steer a study session.
|
|
720
|
+
*/
|
|
721
|
+
static async create(user, course, strategyData) {
|
|
722
|
+
const implementingClass = strategyData.implementingClass;
|
|
723
|
+
let NavigatorImpl;
|
|
724
|
+
const variations = [".ts", ".js", ""];
|
|
725
|
+
const dirs = ["filters", "generators"];
|
|
726
|
+
for (const ext of variations) {
|
|
727
|
+
for (const dir of dirs) {
|
|
728
|
+
const loadFrom = `./${dir}/${implementingClass}${ext}`;
|
|
729
|
+
try {
|
|
730
|
+
const module2 = await import(loadFrom);
|
|
731
|
+
NavigatorImpl = module2.default;
|
|
732
|
+
break;
|
|
733
|
+
} catch (e) {
|
|
734
|
+
logger.debug(`Failed to load extension from ${loadFrom}:`, e);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
if (!NavigatorImpl) {
|
|
739
|
+
throw new Error(`Could not load navigator implementation for: ${implementingClass}`);
|
|
740
|
+
}
|
|
741
|
+
return new NavigatorImpl(user, course, strategyData);
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Get cards with suitability scores and provenance trails.
|
|
745
|
+
*
|
|
746
|
+
* **This is the PRIMARY API for navigation strategies.**
|
|
747
|
+
*
|
|
748
|
+
* Returns cards ranked by suitability score (0-1). Higher scores indicate
|
|
749
|
+
* better candidates for presentation. Each card includes a provenance trail
|
|
750
|
+
* documenting how strategies contributed to the final score.
|
|
751
|
+
*
|
|
752
|
+
* ## Implementation Required
|
|
753
|
+
* All navigation strategies MUST override this method. The base class does
|
|
754
|
+
* not provide a default implementation.
|
|
755
|
+
*
|
|
756
|
+
* ## For Generators
|
|
757
|
+
* Override this method to generate candidates and compute scores based on
|
|
758
|
+
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
759
|
+
* initial provenance entry with action='generated'.
|
|
760
|
+
*
|
|
761
|
+
* ## For Filters
|
|
762
|
+
* Filters should implement the CardFilter interface instead and be composed
|
|
763
|
+
* via Pipeline. Filters do not directly implement getWeightedCards().
|
|
764
|
+
*
|
|
765
|
+
* @param limit - Maximum cards to return
|
|
766
|
+
* @returns Cards sorted by score descending, with provenance trails
|
|
767
|
+
*/
|
|
768
|
+
async getWeightedCards(_limit) {
|
|
769
|
+
throw new Error(`${this.constructor.name} must implement getWeightedCards(). `);
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
|
|
775
|
+
// src/core/navigators/Pipeline.ts
|
|
776
|
+
function logPipelineConfig(generator, filters) {
|
|
777
|
+
const filterList = filters.length > 0 ? "\n - " + filters.map((f) => f.name).join("\n - ") : " none";
|
|
778
|
+
logger.info(
|
|
779
|
+
`[Pipeline] Configuration:
|
|
780
|
+
Generator: ${generator.name}
|
|
781
|
+
Filters:${filterList}`
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
function logTagHydration(cards, tagsByCard) {
|
|
785
|
+
const totalTags = Array.from(tagsByCard.values()).reduce((sum, tags) => sum + tags.length, 0);
|
|
786
|
+
const cardsWithTags = Array.from(tagsByCard.values()).filter((tags) => tags.length > 0).length;
|
|
787
|
+
logger.debug(
|
|
788
|
+
`[Pipeline] Tag hydration: ${cards.length} cards, ${cardsWithTags} have tags (${totalTags} total tags) - single batch query`
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
function logExecutionSummary(generatorName, generatedCount, filterCount, finalCount, topScores) {
|
|
792
|
+
const scoreDisplay = topScores.length > 0 ? topScores.map((s) => s.toFixed(2)).join(", ") : "none";
|
|
793
|
+
logger.info(
|
|
794
|
+
`[Pipeline] Execution: ${generatorName} produced ${generatedCount} \u2192 ${filterCount} filters \u2192 ${finalCount} results (top scores: ${scoreDisplay})`
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
function logCardProvenance(cards, maxCards = 3) {
|
|
798
|
+
const cardsToLog = cards.slice(0, maxCards);
|
|
799
|
+
logger.debug(`[Pipeline] Provenance for top ${cardsToLog.length} cards:`);
|
|
800
|
+
for (const card of cardsToLog) {
|
|
801
|
+
logger.debug(`[Pipeline] ${card.cardId} (final score: ${card.score.toFixed(3)}):`);
|
|
802
|
+
for (const entry of card.provenance) {
|
|
803
|
+
const scoreChange = entry.score.toFixed(3);
|
|
804
|
+
const action = entry.action.padEnd(9);
|
|
805
|
+
logger.debug(
|
|
806
|
+
`[Pipeline] ${action} ${scoreChange} - ${entry.strategyName}: ${entry.reason}`
|
|
807
|
+
);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
var import_common5, Pipeline;
|
|
812
|
+
var init_Pipeline = __esm({
|
|
813
|
+
"src/core/navigators/Pipeline.ts"() {
|
|
814
|
+
"use strict";
|
|
815
|
+
import_common5 = require("@vue-skuilder/common");
|
|
816
|
+
init_navigators();
|
|
817
|
+
init_logger();
|
|
818
|
+
Pipeline = class extends ContentNavigator {
|
|
819
|
+
generator;
|
|
820
|
+
filters;
|
|
821
|
+
/**
|
|
822
|
+
* Create a new pipeline.
|
|
823
|
+
*
|
|
824
|
+
* @param generator - The generator (or CompositeGenerator) that produces candidates
|
|
825
|
+
* @param filters - Filters to apply sequentially (order doesn't matter for multipliers)
|
|
826
|
+
* @param user - User database interface
|
|
827
|
+
* @param course - Course database interface
|
|
828
|
+
*/
|
|
829
|
+
constructor(generator, filters, user, course) {
|
|
830
|
+
super();
|
|
831
|
+
this.generator = generator;
|
|
832
|
+
this.filters = filters;
|
|
833
|
+
this.user = user;
|
|
834
|
+
this.course = course;
|
|
835
|
+
course.getCourseConfig().then((cfg) => {
|
|
836
|
+
logger.debug(`[pipeline] Crated pipeline for ${cfg.name}`);
|
|
837
|
+
}).catch((e) => {
|
|
838
|
+
logger.error(`[pipeline] Failed to lookup courseCfg: ${e}`);
|
|
839
|
+
});
|
|
840
|
+
logPipelineConfig(generator, filters);
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Get weighted cards by running generator and applying filters.
|
|
844
|
+
*
|
|
845
|
+
* 1. Build shared context (user ELO, etc.)
|
|
846
|
+
* 2. Get candidates from generator (passing context)
|
|
847
|
+
* 3. Batch hydrate tags for all candidates
|
|
848
|
+
* 4. Apply each filter sequentially
|
|
849
|
+
* 5. Remove zero-score cards
|
|
850
|
+
* 6. Sort by score descending
|
|
851
|
+
* 7. Return top N
|
|
852
|
+
*
|
|
853
|
+
* @param limit - Maximum number of cards to return
|
|
854
|
+
* @returns Cards sorted by score descending
|
|
855
|
+
*/
|
|
856
|
+
async getWeightedCards(limit) {
|
|
857
|
+
const context = await this.buildContext();
|
|
858
|
+
const overFetchMultiplier = 2 + this.filters.length * 0.5;
|
|
859
|
+
const fetchLimit = Math.ceil(limit * overFetchMultiplier);
|
|
860
|
+
logger.debug(
|
|
861
|
+
`[Pipeline] Fetching ${fetchLimit} candidates from generator '${this.generator.name}'`
|
|
862
|
+
);
|
|
863
|
+
let cards = await this.generator.getWeightedCards(fetchLimit, context);
|
|
864
|
+
const generatedCount = cards.length;
|
|
865
|
+
logger.debug(`[Pipeline] Generator returned ${generatedCount} candidates`);
|
|
866
|
+
cards = await this.hydrateTags(cards);
|
|
867
|
+
for (const filter of this.filters) {
|
|
868
|
+
const beforeCount = cards.length;
|
|
869
|
+
cards = await filter.transform(cards, context);
|
|
870
|
+
logger.debug(`[Pipeline] Filter '${filter.name}': ${beforeCount} \u2192 ${cards.length} cards`);
|
|
871
|
+
}
|
|
872
|
+
cards = cards.filter((c) => c.score > 0);
|
|
873
|
+
cards.sort((a, b) => b.score - a.score);
|
|
874
|
+
const result = cards.slice(0, limit);
|
|
875
|
+
const topScores = result.slice(0, 3).map((c) => c.score);
|
|
876
|
+
logExecutionSummary(
|
|
877
|
+
this.generator.name,
|
|
878
|
+
generatedCount,
|
|
879
|
+
this.filters.length,
|
|
880
|
+
result.length,
|
|
881
|
+
topScores
|
|
882
|
+
);
|
|
883
|
+
logCardProvenance(result, 3);
|
|
884
|
+
return result;
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Batch hydrate tags for all cards.
|
|
888
|
+
*
|
|
889
|
+
* Fetches tags for all cards in a single database query and attaches them
|
|
890
|
+
* to the WeightedCard objects. Filters can then use card.tags instead of
|
|
891
|
+
* making individual getAppliedTags() calls.
|
|
892
|
+
*
|
|
893
|
+
* @param cards - Cards to hydrate
|
|
894
|
+
* @returns Cards with tags populated
|
|
895
|
+
*/
|
|
896
|
+
async hydrateTags(cards) {
|
|
897
|
+
if (cards.length === 0) {
|
|
898
|
+
return cards;
|
|
899
|
+
}
|
|
900
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
901
|
+
const tagsByCard = await this.course.getAppliedTagsBatch(cardIds);
|
|
902
|
+
logTagHydration(cards, tagsByCard);
|
|
903
|
+
return cards.map((card) => ({
|
|
904
|
+
...card,
|
|
905
|
+
tags: tagsByCard.get(card.cardId) ?? []
|
|
906
|
+
}));
|
|
907
|
+
}
|
|
908
|
+
/**
|
|
909
|
+
* Build shared context for generator and filters.
|
|
910
|
+
*
|
|
911
|
+
* Called once per getWeightedCards() invocation.
|
|
912
|
+
* Contains data that the generator and multiple filters might need.
|
|
913
|
+
*
|
|
914
|
+
* The context satisfies both GeneratorContext and FilterContext interfaces.
|
|
915
|
+
*/
|
|
916
|
+
async buildContext() {
|
|
917
|
+
let userElo = 1e3;
|
|
918
|
+
try {
|
|
919
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
920
|
+
const courseElo = (0, import_common5.toCourseElo)(courseReg.elo);
|
|
921
|
+
userElo = courseElo.global.score;
|
|
922
|
+
} catch (e) {
|
|
923
|
+
logger.debug(`[Pipeline] Could not get user ELO, using default: ${e}`);
|
|
924
|
+
}
|
|
925
|
+
return {
|
|
926
|
+
user: this.user,
|
|
927
|
+
course: this.course,
|
|
928
|
+
userElo
|
|
929
|
+
};
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Get the course ID for this pipeline.
|
|
933
|
+
*/
|
|
934
|
+
getCourseID() {
|
|
935
|
+
return this.course.getCourseID();
|
|
936
|
+
}
|
|
937
|
+
};
|
|
938
|
+
}
|
|
629
939
|
});
|
|
630
|
-
|
|
940
|
+
|
|
941
|
+
// src/core/navigators/generators/CompositeGenerator.ts
|
|
942
|
+
var DEFAULT_AGGREGATION_MODE, FREQUENCY_BOOST_FACTOR, CompositeGenerator;
|
|
631
943
|
var init_CompositeGenerator = __esm({
|
|
632
|
-
"src/core/navigators/CompositeGenerator.ts"() {
|
|
944
|
+
"src/core/navigators/generators/CompositeGenerator.ts"() {
|
|
633
945
|
"use strict";
|
|
634
946
|
init_navigators();
|
|
635
947
|
init_logger();
|
|
636
|
-
AggregationMode = /* @__PURE__ */ ((AggregationMode2) => {
|
|
637
|
-
AggregationMode2["MAX"] = "max";
|
|
638
|
-
AggregationMode2["AVERAGE"] = "average";
|
|
639
|
-
AggregationMode2["FREQUENCY_BOOST"] = "frequencyBoost";
|
|
640
|
-
return AggregationMode2;
|
|
641
|
-
})(AggregationMode || {});
|
|
642
948
|
DEFAULT_AGGREGATION_MODE = "frequencyBoost" /* FREQUENCY_BOOST */;
|
|
643
949
|
FREQUENCY_BOOST_FACTOR = 0.1;
|
|
644
950
|
CompositeGenerator = class _CompositeGenerator extends ContentNavigator {
|
|
@@ -678,9 +984,14 @@ var init_CompositeGenerator = __esm({
|
|
|
678
984
|
* CardGenerator interface signature (limit, context).
|
|
679
985
|
*
|
|
680
986
|
* @param limit - Maximum number of cards to return
|
|
681
|
-
* @param context -
|
|
987
|
+
* @param context - GeneratorContext passed to child generators (required when called via Pipeline)
|
|
682
988
|
*/
|
|
683
989
|
async getWeightedCards(limit, context) {
|
|
990
|
+
if (!context) {
|
|
991
|
+
throw new Error(
|
|
992
|
+
"CompositeGenerator.getWeightedCards requires a GeneratorContext. It should be called via Pipeline, not directly."
|
|
993
|
+
);
|
|
994
|
+
}
|
|
684
995
|
const results = await Promise.all(
|
|
685
996
|
this.generators.map((g) => g.getWeightedCards(limit, context))
|
|
686
997
|
);
|
|
@@ -761,195 +1072,23 @@ var init_CompositeGenerator = __esm({
|
|
|
761
1072
|
return scores[0];
|
|
762
1073
|
}
|
|
763
1074
|
}
|
|
764
|
-
/**
|
|
765
|
-
* Get new cards from all generators, merged and deduplicated.
|
|
766
|
-
*/
|
|
767
|
-
async getNewCards(n) {
|
|
768
|
-
const legacyGenerators = this.generators.filter(
|
|
769
|
-
(g) => g instanceof ContentNavigator
|
|
770
|
-
);
|
|
771
|
-
const results = await Promise.all(legacyGenerators.map((g) => g.getNewCards(n)));
|
|
772
|
-
const seen = /* @__PURE__ */ new Set();
|
|
773
|
-
const merged = [];
|
|
774
|
-
for (const cards of results) {
|
|
775
|
-
for (const card of cards) {
|
|
776
|
-
if (!seen.has(card.cardID)) {
|
|
777
|
-
seen.add(card.cardID);
|
|
778
|
-
merged.push(card);
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
return n ? merged.slice(0, n) : merged;
|
|
783
|
-
}
|
|
784
|
-
/**
|
|
785
|
-
* Get pending reviews from all generators, merged and deduplicated.
|
|
786
|
-
*/
|
|
787
|
-
async getPendingReviews() {
|
|
788
|
-
const legacyGenerators = this.generators.filter(
|
|
789
|
-
(g) => g instanceof ContentNavigator
|
|
790
|
-
);
|
|
791
|
-
const results = await Promise.all(legacyGenerators.map((g) => g.getPendingReviews()));
|
|
792
|
-
const seen = /* @__PURE__ */ new Set();
|
|
793
|
-
const merged = [];
|
|
794
|
-
for (const reviews of results) {
|
|
795
|
-
for (const review of reviews) {
|
|
796
|
-
if (!seen.has(review.cardID)) {
|
|
797
|
-
seen.add(review.cardID);
|
|
798
|
-
merged.push(review);
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
return merged;
|
|
803
|
-
}
|
|
804
1075
|
};
|
|
805
1076
|
}
|
|
806
1077
|
});
|
|
807
1078
|
|
|
808
|
-
// src/core/navigators/
|
|
809
|
-
var
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
});
|
|
813
|
-
var import_common5, Pipeline;
|
|
814
|
-
var init_Pipeline = __esm({
|
|
815
|
-
"src/core/navigators/Pipeline.ts"() {
|
|
1079
|
+
// src/core/navigators/PipelineAssembler.ts
|
|
1080
|
+
var PipelineAssembler;
|
|
1081
|
+
var init_PipelineAssembler = __esm({
|
|
1082
|
+
"src/core/navigators/PipelineAssembler.ts"() {
|
|
816
1083
|
"use strict";
|
|
817
|
-
import_common5 = require("@vue-skuilder/common");
|
|
818
1084
|
init_navigators();
|
|
1085
|
+
init_Pipeline();
|
|
1086
|
+
init_types_legacy();
|
|
819
1087
|
init_logger();
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
filters;
|
|
1088
|
+
init_CompositeGenerator();
|
|
1089
|
+
PipelineAssembler = class {
|
|
823
1090
|
/**
|
|
824
|
-
*
|
|
825
|
-
*
|
|
826
|
-
* @param generator - The generator (or CompositeGenerator) that produces candidates
|
|
827
|
-
* @param filters - Filters to apply sequentially (order doesn't matter for multipliers)
|
|
828
|
-
* @param user - User database interface
|
|
829
|
-
* @param course - Course database interface
|
|
830
|
-
*/
|
|
831
|
-
constructor(generator, filters, user, course) {
|
|
832
|
-
super();
|
|
833
|
-
this.generator = generator;
|
|
834
|
-
this.filters = filters;
|
|
835
|
-
this.user = user;
|
|
836
|
-
this.course = course;
|
|
837
|
-
logger.debug(
|
|
838
|
-
`[Pipeline] Created with generator '${generator.name}' and ${filters.length} filters: ${filters.map((f) => f.name).join(", ")}`
|
|
839
|
-
);
|
|
840
|
-
}
|
|
841
|
-
/**
|
|
842
|
-
* Get weighted cards by running generator and applying filters.
|
|
843
|
-
*
|
|
844
|
-
* 1. Build shared context (user ELO, etc.)
|
|
845
|
-
* 2. Get candidates from generator (passing context)
|
|
846
|
-
* 3. Apply each filter sequentially
|
|
847
|
-
* 4. Remove zero-score cards
|
|
848
|
-
* 5. Sort by score descending
|
|
849
|
-
* 6. Return top N
|
|
850
|
-
*
|
|
851
|
-
* @param limit - Maximum number of cards to return
|
|
852
|
-
* @returns Cards sorted by score descending
|
|
853
|
-
*/
|
|
854
|
-
async getWeightedCards(limit) {
|
|
855
|
-
const context = await this.buildContext();
|
|
856
|
-
const overFetchMultiplier = 2 + this.filters.length * 0.5;
|
|
857
|
-
const fetchLimit = Math.ceil(limit * overFetchMultiplier);
|
|
858
|
-
logger.debug(
|
|
859
|
-
`[Pipeline] Fetching ${fetchLimit} candidates from generator '${this.generator.name}'`
|
|
860
|
-
);
|
|
861
|
-
let cards = await this.generator.getWeightedCards(fetchLimit, context);
|
|
862
|
-
logger.debug(`[Pipeline] Generator returned ${cards.length} candidates`);
|
|
863
|
-
for (const filter of this.filters) {
|
|
864
|
-
const beforeCount = cards.length;
|
|
865
|
-
cards = await filter.transform(cards, context);
|
|
866
|
-
logger.debug(`[Pipeline] Filter '${filter.name}': ${beforeCount} \u2192 ${cards.length} cards`);
|
|
867
|
-
}
|
|
868
|
-
cards = cards.filter((c) => c.score > 0);
|
|
869
|
-
cards.sort((a, b) => b.score - a.score);
|
|
870
|
-
const result = cards.slice(0, limit);
|
|
871
|
-
logger.debug(
|
|
872
|
-
`[Pipeline] Returning ${result.length} cards (top scores: ${result.slice(0, 3).map((c) => c.score.toFixed(2)).join(", ")}...)`
|
|
873
|
-
);
|
|
874
|
-
return result;
|
|
875
|
-
}
|
|
876
|
-
/**
|
|
877
|
-
* Build shared context for generator and filters.
|
|
878
|
-
*
|
|
879
|
-
* Called once per getWeightedCards() invocation.
|
|
880
|
-
* Contains data that the generator and multiple filters might need.
|
|
881
|
-
*
|
|
882
|
-
* The context satisfies both GeneratorContext and FilterContext interfaces.
|
|
883
|
-
*/
|
|
884
|
-
async buildContext() {
|
|
885
|
-
let userElo = 1e3;
|
|
886
|
-
try {
|
|
887
|
-
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
888
|
-
const courseElo = (0, import_common5.toCourseElo)(courseReg.elo);
|
|
889
|
-
userElo = courseElo.global.score;
|
|
890
|
-
} catch (e) {
|
|
891
|
-
logger.debug(`[Pipeline] Could not get user ELO, using default: ${e}`);
|
|
892
|
-
}
|
|
893
|
-
return {
|
|
894
|
-
user: this.user,
|
|
895
|
-
course: this.course,
|
|
896
|
-
userElo
|
|
897
|
-
};
|
|
898
|
-
}
|
|
899
|
-
// ===========================================================================
|
|
900
|
-
// Legacy StudyContentSource methods
|
|
901
|
-
// ===========================================================================
|
|
902
|
-
//
|
|
903
|
-
// These delegate to the generator for backward compatibility.
|
|
904
|
-
// Eventually SessionController will use getWeightedCards() exclusively.
|
|
905
|
-
//
|
|
906
|
-
/**
|
|
907
|
-
* Get new cards via legacy API.
|
|
908
|
-
* Delegates to the generator if it supports the legacy interface.
|
|
909
|
-
*/
|
|
910
|
-
async getNewCards(n) {
|
|
911
|
-
if ("getNewCards" in this.generator && typeof this.generator.getNewCards === "function") {
|
|
912
|
-
return this.generator.getNewCards(n);
|
|
913
|
-
}
|
|
914
|
-
return [];
|
|
915
|
-
}
|
|
916
|
-
/**
|
|
917
|
-
* Get pending reviews via legacy API.
|
|
918
|
-
* Delegates to the generator if it supports the legacy interface.
|
|
919
|
-
*/
|
|
920
|
-
async getPendingReviews() {
|
|
921
|
-
if ("getPendingReviews" in this.generator && typeof this.generator.getPendingReviews === "function") {
|
|
922
|
-
return this.generator.getPendingReviews();
|
|
923
|
-
}
|
|
924
|
-
return [];
|
|
925
|
-
}
|
|
926
|
-
/**
|
|
927
|
-
* Get the course ID for this pipeline.
|
|
928
|
-
*/
|
|
929
|
-
getCourseID() {
|
|
930
|
-
return this.course.getCourseID();
|
|
931
|
-
}
|
|
932
|
-
};
|
|
933
|
-
}
|
|
934
|
-
});
|
|
935
|
-
|
|
936
|
-
// src/core/navigators/PipelineAssembler.ts
|
|
937
|
-
var PipelineAssembler_exports = {};
|
|
938
|
-
__export(PipelineAssembler_exports, {
|
|
939
|
-
PipelineAssembler: () => PipelineAssembler
|
|
940
|
-
});
|
|
941
|
-
var PipelineAssembler;
|
|
942
|
-
var init_PipelineAssembler = __esm({
|
|
943
|
-
"src/core/navigators/PipelineAssembler.ts"() {
|
|
944
|
-
"use strict";
|
|
945
|
-
init_navigators();
|
|
946
|
-
init_Pipeline();
|
|
947
|
-
init_types_legacy();
|
|
948
|
-
init_logger();
|
|
949
|
-
init_CompositeGenerator();
|
|
950
|
-
PipelineAssembler = class {
|
|
951
|
-
/**
|
|
952
|
-
* Assembles a navigation pipeline from strategy documents.
|
|
1091
|
+
* Assembles a navigation pipeline from strategy documents.
|
|
953
1092
|
*
|
|
954
1093
|
* 1. Separates into generators and filters by role
|
|
955
1094
|
* 2. Validates at least one generator exists (or creates default ELO)
|
|
@@ -1058,14 +1197,10 @@ var init_PipelineAssembler = __esm({
|
|
|
1058
1197
|
}
|
|
1059
1198
|
});
|
|
1060
1199
|
|
|
1061
|
-
// src/core/navigators/elo.ts
|
|
1062
|
-
var elo_exports = {};
|
|
1063
|
-
__export(elo_exports, {
|
|
1064
|
-
default: () => ELONavigator
|
|
1065
|
-
});
|
|
1200
|
+
// src/core/navigators/generators/elo.ts
|
|
1066
1201
|
var import_common6, ELONavigator;
|
|
1067
1202
|
var init_elo = __esm({
|
|
1068
|
-
"src/core/navigators/elo.ts"() {
|
|
1203
|
+
"src/core/navigators/generators/elo.ts"() {
|
|
1069
1204
|
"use strict";
|
|
1070
1205
|
init_navigators();
|
|
1071
1206
|
import_common6 = require("@vue-skuilder/common");
|
|
@@ -1076,50 +1211,6 @@ var init_elo = __esm({
|
|
|
1076
1211
|
super(user, course, strategyData);
|
|
1077
1212
|
this.name = strategyData?.name || "ELO";
|
|
1078
1213
|
}
|
|
1079
|
-
async getPendingReviews() {
|
|
1080
|
-
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1081
|
-
const elo = await this.course.getCardEloData(reviews.map((r) => r.cardId));
|
|
1082
|
-
const ratedReviews = reviews.map((r, i) => {
|
|
1083
|
-
const ratedR = {
|
|
1084
|
-
...r,
|
|
1085
|
-
...elo[i]
|
|
1086
|
-
};
|
|
1087
|
-
return ratedR;
|
|
1088
|
-
});
|
|
1089
|
-
ratedReviews.sort((a, b) => {
|
|
1090
|
-
return a.global.score - b.global.score;
|
|
1091
|
-
});
|
|
1092
|
-
return ratedReviews.map((r) => {
|
|
1093
|
-
return {
|
|
1094
|
-
...r,
|
|
1095
|
-
contentSourceType: "course",
|
|
1096
|
-
contentSourceID: this.course.getCourseID(),
|
|
1097
|
-
cardID: r.cardId,
|
|
1098
|
-
courseID: r.courseId,
|
|
1099
|
-
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
1100
|
-
reviewID: r._id,
|
|
1101
|
-
status: "review"
|
|
1102
|
-
};
|
|
1103
|
-
});
|
|
1104
|
-
}
|
|
1105
|
-
async getNewCards(limit = 99) {
|
|
1106
|
-
const activeCards = await this.user.getActiveCards();
|
|
1107
|
-
return (await this.course.getCardsCenteredAtELO(
|
|
1108
|
-
{ limit, elo: "user" },
|
|
1109
|
-
(c) => {
|
|
1110
|
-
if (activeCards.some((ac) => c.cardID === ac.cardID)) {
|
|
1111
|
-
return false;
|
|
1112
|
-
} else {
|
|
1113
|
-
return true;
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
)).map((c) => {
|
|
1117
|
-
return {
|
|
1118
|
-
...c,
|
|
1119
|
-
status: "new"
|
|
1120
|
-
};
|
|
1121
|
-
});
|
|
1122
|
-
}
|
|
1123
1214
|
/**
|
|
1124
1215
|
* Get new cards with suitability scores based on ELO distance.
|
|
1125
1216
|
*
|
|
@@ -1144,7 +1235,11 @@ var init_elo = __esm({
|
|
|
1144
1235
|
const userElo = (0, import_common6.toCourseElo)(courseReg.elo);
|
|
1145
1236
|
userGlobalElo = userElo.global.score;
|
|
1146
1237
|
}
|
|
1147
|
-
const
|
|
1238
|
+
const activeCards = await this.user.getActiveCards();
|
|
1239
|
+
const newCards = (await this.course.getCardsCenteredAtELO(
|
|
1240
|
+
{ limit, elo: "user" },
|
|
1241
|
+
(c) => !activeCards.some((ac) => c.cardID === ac.cardID)
|
|
1242
|
+
)).map((c) => ({ ...c, status: "new" }));
|
|
1148
1243
|
const cardIds = newCards.map((c) => c.cardID);
|
|
1149
1244
|
const cardEloData = await this.course.getCardEloData(cardIds);
|
|
1150
1245
|
const scored = newCards.map((c, i) => {
|
|
@@ -1174,160 +1269,29 @@ var init_elo = __esm({
|
|
|
1174
1269
|
}
|
|
1175
1270
|
});
|
|
1176
1271
|
|
|
1177
|
-
// src/core/navigators/
|
|
1178
|
-
var
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
DEFAULT_MAX_MULTIPLIER: () => DEFAULT_MAX_MULTIPLIER,
|
|
1182
|
-
DEFAULT_MIN_MULTIPLIER: () => DEFAULT_MIN_MULTIPLIER,
|
|
1183
|
-
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1184
|
-
});
|
|
1185
|
-
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
1186
|
-
const normalizedDistance = distance / halfLife;
|
|
1187
|
-
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
1188
|
-
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
1189
|
-
}
|
|
1190
|
-
function createEloDistanceFilter(config) {
|
|
1191
|
-
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
1192
|
-
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
1193
|
-
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
1194
|
-
return {
|
|
1195
|
-
name: "ELO Distance Filter",
|
|
1196
|
-
async transform(cards, context) {
|
|
1197
|
-
const { course, userElo } = context;
|
|
1198
|
-
const cardIds = cards.map((c) => c.cardId);
|
|
1199
|
-
const cardElos = await course.getCardEloData(cardIds);
|
|
1200
|
-
return cards.map((card, i) => {
|
|
1201
|
-
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
1202
|
-
const distance = Math.abs(cardElo - userElo);
|
|
1203
|
-
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
1204
|
-
const newScore = card.score * multiplier;
|
|
1205
|
-
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
1206
|
-
return {
|
|
1207
|
-
...card,
|
|
1208
|
-
score: newScore,
|
|
1209
|
-
provenance: [
|
|
1210
|
-
...card.provenance,
|
|
1211
|
-
{
|
|
1212
|
-
strategy: "eloDistance",
|
|
1213
|
-
strategyName: "ELO Distance Filter",
|
|
1214
|
-
strategyId: "ELO_DISTANCE_FILTER",
|
|
1215
|
-
action,
|
|
1216
|
-
score: newScore,
|
|
1217
|
-
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
1218
|
-
}
|
|
1219
|
-
]
|
|
1220
|
-
};
|
|
1221
|
-
});
|
|
1222
|
-
}
|
|
1223
|
-
};
|
|
1224
|
-
}
|
|
1225
|
-
var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
|
|
1226
|
-
var init_eloDistance = __esm({
|
|
1227
|
-
"src/core/navigators/filters/eloDistance.ts"() {
|
|
1228
|
-
"use strict";
|
|
1229
|
-
DEFAULT_HALF_LIFE = 200;
|
|
1230
|
-
DEFAULT_MIN_MULTIPLIER = 0.3;
|
|
1231
|
-
DEFAULT_MAX_MULTIPLIER = 1;
|
|
1232
|
-
}
|
|
1233
|
-
});
|
|
1234
|
-
|
|
1235
|
-
// src/core/navigators/filters/index.ts
|
|
1236
|
-
var filters_exports = {};
|
|
1237
|
-
__export(filters_exports, {
|
|
1238
|
-
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1239
|
-
});
|
|
1240
|
-
var init_filters = __esm({
|
|
1241
|
-
"src/core/navigators/filters/index.ts"() {
|
|
1242
|
-
"use strict";
|
|
1243
|
-
init_eloDistance();
|
|
1244
|
-
}
|
|
1245
|
-
});
|
|
1246
|
-
|
|
1247
|
-
// src/core/navigators/filters/types.ts
|
|
1248
|
-
var types_exports = {};
|
|
1249
|
-
var init_types = __esm({
|
|
1250
|
-
"src/core/navigators/filters/types.ts"() {
|
|
1251
|
-
"use strict";
|
|
1252
|
-
}
|
|
1253
|
-
});
|
|
1254
|
-
|
|
1255
|
-
// src/core/navigators/generators/index.ts
|
|
1256
|
-
var generators_exports = {};
|
|
1257
|
-
var init_generators = __esm({
|
|
1258
|
-
"src/core/navigators/generators/index.ts"() {
|
|
1259
|
-
"use strict";
|
|
1260
|
-
}
|
|
1261
|
-
});
|
|
1262
|
-
|
|
1263
|
-
// src/core/navigators/generators/types.ts
|
|
1264
|
-
var types_exports2 = {};
|
|
1265
|
-
var init_types2 = __esm({
|
|
1266
|
-
"src/core/navigators/generators/types.ts"() {
|
|
1267
|
-
"use strict";
|
|
1268
|
-
}
|
|
1269
|
-
});
|
|
1270
|
-
|
|
1271
|
-
// src/core/navigators/hardcodedOrder.ts
|
|
1272
|
-
var hardcodedOrder_exports = {};
|
|
1273
|
-
__export(hardcodedOrder_exports, {
|
|
1274
|
-
default: () => HardcodedOrderNavigator
|
|
1275
|
-
});
|
|
1276
|
-
var HardcodedOrderNavigator;
|
|
1277
|
-
var init_hardcodedOrder = __esm({
|
|
1278
|
-
"src/core/navigators/hardcodedOrder.ts"() {
|
|
1272
|
+
// src/core/navigators/generators/srs.ts
|
|
1273
|
+
var import_moment, SRSNavigator;
|
|
1274
|
+
var init_srs = __esm({
|
|
1275
|
+
"src/core/navigators/generators/srs.ts"() {
|
|
1279
1276
|
"use strict";
|
|
1277
|
+
import_moment = __toESM(require("moment"), 1);
|
|
1280
1278
|
init_navigators();
|
|
1281
1279
|
init_logger();
|
|
1282
|
-
|
|
1280
|
+
SRSNavigator = class extends ContentNavigator {
|
|
1283
1281
|
/** Human-readable name for CardGenerator interface */
|
|
1284
1282
|
name;
|
|
1285
|
-
orderedCardIds = [];
|
|
1286
1283
|
constructor(user, course, strategyData) {
|
|
1287
1284
|
super(user, course, strategyData);
|
|
1288
|
-
this.name = strategyData
|
|
1289
|
-
if (strategyData.serializedData) {
|
|
1290
|
-
try {
|
|
1291
|
-
this.orderedCardIds = JSON.parse(strategyData.serializedData);
|
|
1292
|
-
} catch (e) {
|
|
1293
|
-
logger.error("Failed to parse serializedData for HardcodedOrderNavigator", e);
|
|
1294
|
-
}
|
|
1295
|
-
}
|
|
1296
|
-
}
|
|
1297
|
-
async getPendingReviews() {
|
|
1298
|
-
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1299
|
-
return reviews.map((r) => {
|
|
1300
|
-
return {
|
|
1301
|
-
...r,
|
|
1302
|
-
contentSourceType: "course",
|
|
1303
|
-
contentSourceID: this.course.getCourseID(),
|
|
1304
|
-
cardID: r.cardId,
|
|
1305
|
-
courseID: r.courseId,
|
|
1306
|
-
reviewID: r._id,
|
|
1307
|
-
status: "review"
|
|
1308
|
-
};
|
|
1309
|
-
});
|
|
1310
|
-
}
|
|
1311
|
-
async getNewCards(limit = 99) {
|
|
1312
|
-
const activeCardIds = (await this.user.getActiveCards()).map((c) => c.cardID);
|
|
1313
|
-
const newCardIds = this.orderedCardIds.filter((cardId) => !activeCardIds.includes(cardId));
|
|
1314
|
-
const cardsToReturn = newCardIds.slice(0, limit);
|
|
1315
|
-
return cardsToReturn.map((cardId) => {
|
|
1316
|
-
return {
|
|
1317
|
-
cardID: cardId,
|
|
1318
|
-
courseID: this.course.getCourseID(),
|
|
1319
|
-
contentSourceType: "course",
|
|
1320
|
-
contentSourceID: this.course.getCourseID(),
|
|
1321
|
-
status: "new"
|
|
1322
|
-
};
|
|
1323
|
-
});
|
|
1285
|
+
this.name = strategyData?.name || "SRS";
|
|
1324
1286
|
}
|
|
1325
1287
|
/**
|
|
1326
|
-
* Get cards
|
|
1288
|
+
* Get review cards scored by urgency.
|
|
1289
|
+
*
|
|
1290
|
+
* Score formula combines:
|
|
1291
|
+
* - Relative overdueness: hoursOverdue / intervalHours
|
|
1292
|
+
* - Interval recency: exponential decay favoring shorter intervals
|
|
1327
1293
|
*
|
|
1328
|
-
*
|
|
1329
|
-
* Score formula: 1.0 - (position / totalCards) * 0.5
|
|
1330
|
-
* This ensures scores range from 1.0 (first card) to 0.5+ (last card).
|
|
1294
|
+
* Cards not yet due are excluded (not scored as 0).
|
|
1331
1295
|
*
|
|
1332
1296
|
* This method supports both the legacy signature (limit only) and the
|
|
1333
1297
|
* CardGenerator interface signature (limit, context).
|
|
@@ -1336,692 +1300,33 @@ var init_hardcodedOrder = __esm({
|
|
|
1336
1300
|
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1337
1301
|
*/
|
|
1338
1302
|
async getWeightedCards(limit, _context) {
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
const
|
|
1343
|
-
const
|
|
1344
|
-
|
|
1345
|
-
|
|
1303
|
+
if (!this.user || !this.course) {
|
|
1304
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
1305
|
+
}
|
|
1306
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1307
|
+
const now = import_moment.default.utc();
|
|
1308
|
+
const dueReviews = reviews.filter((r) => now.isAfter(import_moment.default.utc(r.reviewTime)));
|
|
1309
|
+
const scored = dueReviews.map((review) => {
|
|
1310
|
+
const { score, reason } = this.computeUrgencyScore(review, now);
|
|
1346
1311
|
return {
|
|
1347
|
-
cardId,
|
|
1348
|
-
courseId:
|
|
1312
|
+
cardId: review.cardId,
|
|
1313
|
+
courseId: review.courseId,
|
|
1349
1314
|
score,
|
|
1315
|
+
reviewID: review._id,
|
|
1350
1316
|
provenance: [
|
|
1351
1317
|
{
|
|
1352
|
-
strategy: "
|
|
1318
|
+
strategy: "srs",
|
|
1353
1319
|
strategyName: this.strategyName || this.name,
|
|
1354
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-
|
|
1320
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-SRS-default",
|
|
1355
1321
|
action: "generated",
|
|
1356
1322
|
score,
|
|
1357
|
-
reason
|
|
1323
|
+
reason
|
|
1358
1324
|
}
|
|
1359
1325
|
]
|
|
1360
1326
|
};
|
|
1361
1327
|
});
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
courseId: r.courseID,
|
|
1365
|
-
score: 1,
|
|
1366
|
-
provenance: [
|
|
1367
|
-
{
|
|
1368
|
-
strategy: "hardcodedOrder",
|
|
1369
|
-
strategyName: this.strategyName || this.name,
|
|
1370
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hardcoded",
|
|
1371
|
-
action: "generated",
|
|
1372
|
-
score: 1,
|
|
1373
|
-
reason: "Scheduled review, highest priority"
|
|
1374
|
-
}
|
|
1375
|
-
]
|
|
1376
|
-
}));
|
|
1377
|
-
const all = [...scoredReviews, ...scoredNew];
|
|
1378
|
-
all.sort((a, b) => b.score - a.score);
|
|
1379
|
-
return all.slice(0, limit);
|
|
1380
|
-
}
|
|
1381
|
-
};
|
|
1382
|
-
}
|
|
1383
|
-
});
|
|
1384
|
-
|
|
1385
|
-
// src/core/navigators/hierarchyDefinition.ts
|
|
1386
|
-
var hierarchyDefinition_exports = {};
|
|
1387
|
-
__export(hierarchyDefinition_exports, {
|
|
1388
|
-
default: () => HierarchyDefinitionNavigator
|
|
1389
|
-
});
|
|
1390
|
-
var import_common7, DEFAULT_MIN_COUNT, HierarchyDefinitionNavigator;
|
|
1391
|
-
var init_hierarchyDefinition = __esm({
|
|
1392
|
-
"src/core/navigators/hierarchyDefinition.ts"() {
|
|
1393
|
-
"use strict";
|
|
1394
|
-
init_navigators();
|
|
1395
|
-
import_common7 = require("@vue-skuilder/common");
|
|
1396
|
-
DEFAULT_MIN_COUNT = 3;
|
|
1397
|
-
HierarchyDefinitionNavigator = class extends ContentNavigator {
|
|
1398
|
-
config;
|
|
1399
|
-
_strategyData;
|
|
1400
|
-
/** Human-readable name for CardFilter interface */
|
|
1401
|
-
name;
|
|
1402
|
-
constructor(user, course, _strategyData) {
|
|
1403
|
-
super(user, course, _strategyData);
|
|
1404
|
-
this._strategyData = _strategyData;
|
|
1405
|
-
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1406
|
-
this.name = _strategyData.name || "Hierarchy Definition";
|
|
1407
|
-
}
|
|
1408
|
-
parseConfig(serializedData) {
|
|
1409
|
-
try {
|
|
1410
|
-
const parsed = JSON.parse(serializedData);
|
|
1411
|
-
return {
|
|
1412
|
-
prerequisites: parsed.prerequisites || {}
|
|
1413
|
-
};
|
|
1414
|
-
} catch {
|
|
1415
|
-
return {
|
|
1416
|
-
prerequisites: {}
|
|
1417
|
-
};
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
/**
|
|
1421
|
-
* Check if a specific prerequisite is satisfied
|
|
1422
|
-
*/
|
|
1423
|
-
isPrerequisiteMet(prereq, userTagElo, userGlobalElo) {
|
|
1424
|
-
if (!userTagElo) return false;
|
|
1425
|
-
const minCount = prereq.masteryThreshold?.minCount ?? DEFAULT_MIN_COUNT;
|
|
1426
|
-
if (userTagElo.count < minCount) return false;
|
|
1427
|
-
if (prereq.masteryThreshold?.minElo !== void 0) {
|
|
1428
|
-
return userTagElo.score >= prereq.masteryThreshold.minElo;
|
|
1429
|
-
} else {
|
|
1430
|
-
return userTagElo.score >= userGlobalElo;
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
/**
|
|
1434
|
-
* Get the set of tags the user has mastered.
|
|
1435
|
-
* A tag is "mastered" if it appears as a prerequisite somewhere and meets its threshold.
|
|
1436
|
-
*/
|
|
1437
|
-
async getMasteredTags(context) {
|
|
1438
|
-
const mastered = /* @__PURE__ */ new Set();
|
|
1439
|
-
try {
|
|
1440
|
-
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1441
|
-
const userElo = (0, import_common7.toCourseElo)(courseReg.elo);
|
|
1442
|
-
for (const prereqs of Object.values(this.config.prerequisites)) {
|
|
1443
|
-
for (const prereq of prereqs) {
|
|
1444
|
-
const tagElo = userElo.tags[prereq.tag];
|
|
1445
|
-
if (this.isPrerequisiteMet(prereq, tagElo, userElo.global.score)) {
|
|
1446
|
-
mastered.add(prereq.tag);
|
|
1447
|
-
}
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
} catch {
|
|
1451
|
-
}
|
|
1452
|
-
return mastered;
|
|
1453
|
-
}
|
|
1454
|
-
/**
|
|
1455
|
-
* Get the set of tags that are unlocked (prerequisites met)
|
|
1456
|
-
*/
|
|
1457
|
-
getUnlockedTags(masteredTags) {
|
|
1458
|
-
const unlocked = /* @__PURE__ */ new Set();
|
|
1459
|
-
for (const [tagId, prereqs] of Object.entries(this.config.prerequisites)) {
|
|
1460
|
-
const allPrereqsMet = prereqs.every((prereq) => masteredTags.has(prereq.tag));
|
|
1461
|
-
if (allPrereqsMet) {
|
|
1462
|
-
unlocked.add(tagId);
|
|
1463
|
-
}
|
|
1464
|
-
}
|
|
1465
|
-
return unlocked;
|
|
1466
|
-
}
|
|
1467
|
-
/**
|
|
1468
|
-
* Check if a tag has prerequisites defined in config
|
|
1469
|
-
*/
|
|
1470
|
-
hasPrerequisites(tagId) {
|
|
1471
|
-
return tagId in this.config.prerequisites;
|
|
1472
|
-
}
|
|
1473
|
-
/**
|
|
1474
|
-
* Check if a card is unlocked and generate reason.
|
|
1475
|
-
*/
|
|
1476
|
-
async checkCardUnlock(cardId, course, unlockedTags, masteredTags) {
|
|
1477
|
-
try {
|
|
1478
|
-
const tagResponse = await course.getAppliedTags(cardId);
|
|
1479
|
-
const cardTags = tagResponse.rows.map((row) => row.value?.name || row.key);
|
|
1480
|
-
const lockedTags = cardTags.filter(
|
|
1481
|
-
(tag) => this.hasPrerequisites(tag) && !unlockedTags.has(tag)
|
|
1482
|
-
);
|
|
1483
|
-
if (lockedTags.length === 0) {
|
|
1484
|
-
const tagList = cardTags.length > 0 ? cardTags.join(", ") : "none";
|
|
1485
|
-
return {
|
|
1486
|
-
isUnlocked: true,
|
|
1487
|
-
reason: `Prerequisites met, tags: ${tagList}`
|
|
1488
|
-
};
|
|
1489
|
-
}
|
|
1490
|
-
const missingPrereqs = lockedTags.flatMap((tag) => {
|
|
1491
|
-
const prereqs = this.config.prerequisites[tag] || [];
|
|
1492
|
-
return prereqs.filter((p) => !masteredTags.has(p.tag)).map((p) => p.tag);
|
|
1493
|
-
});
|
|
1494
|
-
return {
|
|
1495
|
-
isUnlocked: false,
|
|
1496
|
-
reason: `Blocked: missing prerequisites ${missingPrereqs.join(", ")} for tags ${lockedTags.join(", ")}`
|
|
1497
|
-
};
|
|
1498
|
-
} catch {
|
|
1499
|
-
return {
|
|
1500
|
-
isUnlocked: true,
|
|
1501
|
-
reason: "Prerequisites check skipped (tag lookup failed)"
|
|
1502
|
-
};
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
/**
|
|
1506
|
-
* CardFilter.transform implementation.
|
|
1507
|
-
*
|
|
1508
|
-
* Apply prerequisite gating to cards. Cards with locked tags receive score: 0.
|
|
1509
|
-
*/
|
|
1510
|
-
async transform(cards, context) {
|
|
1511
|
-
const masteredTags = await this.getMasteredTags(context);
|
|
1512
|
-
const unlockedTags = this.getUnlockedTags(masteredTags);
|
|
1513
|
-
const gated = [];
|
|
1514
|
-
for (const card of cards) {
|
|
1515
|
-
const { isUnlocked, reason } = await this.checkCardUnlock(
|
|
1516
|
-
card.cardId,
|
|
1517
|
-
context.course,
|
|
1518
|
-
unlockedTags,
|
|
1519
|
-
masteredTags
|
|
1520
|
-
);
|
|
1521
|
-
const finalScore = isUnlocked ? card.score : 0;
|
|
1522
|
-
const action = isUnlocked ? "passed" : "penalized";
|
|
1523
|
-
gated.push({
|
|
1524
|
-
...card,
|
|
1525
|
-
score: finalScore,
|
|
1526
|
-
provenance: [
|
|
1527
|
-
...card.provenance,
|
|
1528
|
-
{
|
|
1529
|
-
strategy: "hierarchyDefinition",
|
|
1530
|
-
strategyName: this.strategyName || this.name,
|
|
1531
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hierarchy",
|
|
1532
|
-
action,
|
|
1533
|
-
score: finalScore,
|
|
1534
|
-
reason
|
|
1535
|
-
}
|
|
1536
|
-
]
|
|
1537
|
-
});
|
|
1538
|
-
}
|
|
1539
|
-
return gated;
|
|
1540
|
-
}
|
|
1541
|
-
/**
|
|
1542
|
-
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1543
|
-
*
|
|
1544
|
-
* Use transform() via Pipeline instead.
|
|
1545
|
-
*/
|
|
1546
|
-
async getWeightedCards(_limit) {
|
|
1547
|
-
throw new Error(
|
|
1548
|
-
"HierarchyDefinitionNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1549
|
-
);
|
|
1550
|
-
}
|
|
1551
|
-
// Legacy methods - stub implementations since filters don't generate cards
|
|
1552
|
-
async getNewCards(_n) {
|
|
1553
|
-
return [];
|
|
1554
|
-
}
|
|
1555
|
-
async getPendingReviews() {
|
|
1556
|
-
return [];
|
|
1557
|
-
}
|
|
1558
|
-
};
|
|
1559
|
-
}
|
|
1560
|
-
});
|
|
1561
|
-
|
|
1562
|
-
// src/core/navigators/interferenceMitigator.ts
|
|
1563
|
-
var interferenceMitigator_exports = {};
|
|
1564
|
-
__export(interferenceMitigator_exports, {
|
|
1565
|
-
default: () => InterferenceMitigatorNavigator
|
|
1566
|
-
});
|
|
1567
|
-
var import_common8, DEFAULT_MIN_COUNT2, DEFAULT_MIN_ELAPSED_DAYS, DEFAULT_INTERFERENCE_DECAY, InterferenceMitigatorNavigator;
|
|
1568
|
-
var init_interferenceMitigator = __esm({
|
|
1569
|
-
"src/core/navigators/interferenceMitigator.ts"() {
|
|
1570
|
-
"use strict";
|
|
1571
|
-
init_navigators();
|
|
1572
|
-
import_common8 = require("@vue-skuilder/common");
|
|
1573
|
-
DEFAULT_MIN_COUNT2 = 10;
|
|
1574
|
-
DEFAULT_MIN_ELAPSED_DAYS = 3;
|
|
1575
|
-
DEFAULT_INTERFERENCE_DECAY = 0.8;
|
|
1576
|
-
InterferenceMitigatorNavigator = class extends ContentNavigator {
|
|
1577
|
-
config;
|
|
1578
|
-
_strategyData;
|
|
1579
|
-
/** Human-readable name for CardFilter interface */
|
|
1580
|
-
name;
|
|
1581
|
-
/** Precomputed map: tag -> set of { partner, decay } it interferes with */
|
|
1582
|
-
interferenceMap;
|
|
1583
|
-
constructor(user, course, _strategyData) {
|
|
1584
|
-
super(user, course, _strategyData);
|
|
1585
|
-
this._strategyData = _strategyData;
|
|
1586
|
-
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1587
|
-
this.interferenceMap = this.buildInterferenceMap();
|
|
1588
|
-
this.name = _strategyData.name || "Interference Mitigator";
|
|
1589
|
-
}
|
|
1590
|
-
parseConfig(serializedData) {
|
|
1591
|
-
try {
|
|
1592
|
-
const parsed = JSON.parse(serializedData);
|
|
1593
|
-
let sets = parsed.interferenceSets || [];
|
|
1594
|
-
if (sets.length > 0 && Array.isArray(sets[0])) {
|
|
1595
|
-
sets = sets.map((tags) => ({ tags }));
|
|
1596
|
-
}
|
|
1597
|
-
return {
|
|
1598
|
-
interferenceSets: sets,
|
|
1599
|
-
maturityThreshold: {
|
|
1600
|
-
minCount: parsed.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2,
|
|
1601
|
-
minElo: parsed.maturityThreshold?.minElo,
|
|
1602
|
-
minElapsedDays: parsed.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS
|
|
1603
|
-
},
|
|
1604
|
-
defaultDecay: parsed.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY
|
|
1605
|
-
};
|
|
1606
|
-
} catch {
|
|
1607
|
-
return {
|
|
1608
|
-
interferenceSets: [],
|
|
1609
|
-
maturityThreshold: {
|
|
1610
|
-
minCount: DEFAULT_MIN_COUNT2,
|
|
1611
|
-
minElapsedDays: DEFAULT_MIN_ELAPSED_DAYS
|
|
1612
|
-
},
|
|
1613
|
-
defaultDecay: DEFAULT_INTERFERENCE_DECAY
|
|
1614
|
-
};
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
/**
|
|
1618
|
-
* Build a map from each tag to its interference partners with decay coefficients.
|
|
1619
|
-
* If tags A, B, C are in an interference group with decay 0.8, then:
|
|
1620
|
-
* - A interferes with B (decay 0.8) and C (decay 0.8)
|
|
1621
|
-
* - B interferes with A (decay 0.8) and C (decay 0.8)
|
|
1622
|
-
* - etc.
|
|
1623
|
-
*/
|
|
1624
|
-
buildInterferenceMap() {
|
|
1625
|
-
const map = /* @__PURE__ */ new Map();
|
|
1626
|
-
for (const group of this.config.interferenceSets) {
|
|
1627
|
-
const decay = group.decay ?? this.config.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY;
|
|
1628
|
-
for (const tag of group.tags) {
|
|
1629
|
-
if (!map.has(tag)) {
|
|
1630
|
-
map.set(tag, []);
|
|
1631
|
-
}
|
|
1632
|
-
const partners = map.get(tag);
|
|
1633
|
-
for (const other of group.tags) {
|
|
1634
|
-
if (other !== tag) {
|
|
1635
|
-
const existing = partners.find((p) => p.partner === other);
|
|
1636
|
-
if (existing) {
|
|
1637
|
-
existing.decay = Math.max(existing.decay, decay);
|
|
1638
|
-
} else {
|
|
1639
|
-
partners.push({ partner: other, decay });
|
|
1640
|
-
}
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
return map;
|
|
1646
|
-
}
|
|
1647
|
-
/**
|
|
1648
|
-
* Get the set of tags that are currently immature for this user.
|
|
1649
|
-
* A tag is immature if the user has interacted with it but hasn't
|
|
1650
|
-
* reached the maturity threshold.
|
|
1651
|
-
*/
|
|
1652
|
-
async getImmatureTags(context) {
|
|
1653
|
-
const immature = /* @__PURE__ */ new Set();
|
|
1654
|
-
try {
|
|
1655
|
-
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1656
|
-
const userElo = (0, import_common8.toCourseElo)(courseReg.elo);
|
|
1657
|
-
const minCount = this.config.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2;
|
|
1658
|
-
const minElo = this.config.maturityThreshold?.minElo;
|
|
1659
|
-
const minElapsedDays = this.config.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS;
|
|
1660
|
-
const minCountForElapsed = minElapsedDays * 2;
|
|
1661
|
-
for (const [tagId, tagElo] of Object.entries(userElo.tags)) {
|
|
1662
|
-
if (tagElo.count === 0) continue;
|
|
1663
|
-
const belowCount = tagElo.count < minCount;
|
|
1664
|
-
const belowElo = minElo !== void 0 && tagElo.score < minElo;
|
|
1665
|
-
const belowElapsed = tagElo.count < minCountForElapsed;
|
|
1666
|
-
if (belowCount || belowElo || belowElapsed) {
|
|
1667
|
-
immature.add(tagId);
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
} catch {
|
|
1671
|
-
}
|
|
1672
|
-
return immature;
|
|
1673
|
-
}
|
|
1674
|
-
/**
|
|
1675
|
-
* Get all tags that interfere with any immature tag, along with their decay coefficients.
|
|
1676
|
-
* These are the tags we want to avoid introducing.
|
|
1677
|
-
*/
|
|
1678
|
-
getTagsToAvoid(immatureTags) {
|
|
1679
|
-
const avoid = /* @__PURE__ */ new Map();
|
|
1680
|
-
for (const immatureTag of immatureTags) {
|
|
1681
|
-
const partners = this.interferenceMap.get(immatureTag);
|
|
1682
|
-
if (partners) {
|
|
1683
|
-
for (const { partner, decay } of partners) {
|
|
1684
|
-
if (!immatureTags.has(partner)) {
|
|
1685
|
-
const existing = avoid.get(partner) ?? 0;
|
|
1686
|
-
avoid.set(partner, Math.max(existing, decay));
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
}
|
|
1690
|
-
}
|
|
1691
|
-
return avoid;
|
|
1692
|
-
}
|
|
1693
|
-
/**
|
|
1694
|
-
* Get tags for a single card
|
|
1695
|
-
*/
|
|
1696
|
-
async getCardTags(cardId, course) {
|
|
1697
|
-
try {
|
|
1698
|
-
const tagResponse = await course.getAppliedTags(cardId);
|
|
1699
|
-
return tagResponse.rows.map((row) => row.value?.name || row.key).filter(Boolean);
|
|
1700
|
-
} catch {
|
|
1701
|
-
return [];
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
/**
|
|
1705
|
-
* Compute interference score reduction for a card.
|
|
1706
|
-
* Returns: { multiplier, interfering tags, reason }
|
|
1707
|
-
*/
|
|
1708
|
-
computeInterferenceEffect(cardTags, tagsToAvoid, immatureTags) {
|
|
1709
|
-
if (tagsToAvoid.size === 0) {
|
|
1710
|
-
return {
|
|
1711
|
-
multiplier: 1,
|
|
1712
|
-
interferingTags: [],
|
|
1713
|
-
reason: "No interference detected"
|
|
1714
|
-
};
|
|
1715
|
-
}
|
|
1716
|
-
let multiplier = 1;
|
|
1717
|
-
const interferingTags = [];
|
|
1718
|
-
for (const tag of cardTags) {
|
|
1719
|
-
const decay = tagsToAvoid.get(tag);
|
|
1720
|
-
if (decay !== void 0) {
|
|
1721
|
-
interferingTags.push(tag);
|
|
1722
|
-
multiplier *= 1 - decay;
|
|
1723
|
-
}
|
|
1724
|
-
}
|
|
1725
|
-
if (interferingTags.length === 0) {
|
|
1726
|
-
return {
|
|
1727
|
-
multiplier: 1,
|
|
1728
|
-
interferingTags: [],
|
|
1729
|
-
reason: "No interference detected"
|
|
1730
|
-
};
|
|
1731
|
-
}
|
|
1732
|
-
const causingTags = /* @__PURE__ */ new Set();
|
|
1733
|
-
for (const tag of interferingTags) {
|
|
1734
|
-
for (const immatureTag of immatureTags) {
|
|
1735
|
-
const partners = this.interferenceMap.get(immatureTag);
|
|
1736
|
-
if (partners?.some((p) => p.partner === tag)) {
|
|
1737
|
-
causingTags.add(immatureTag);
|
|
1738
|
-
}
|
|
1739
|
-
}
|
|
1740
|
-
}
|
|
1741
|
-
const reason = `Interferes with immature tags ${Array.from(causingTags).join(", ")} (tags: ${interferingTags.join(", ")}, multiplier: ${multiplier.toFixed(2)})`;
|
|
1742
|
-
return { multiplier, interferingTags, reason };
|
|
1743
|
-
}
|
|
1744
|
-
/**
|
|
1745
|
-
* CardFilter.transform implementation.
|
|
1746
|
-
*
|
|
1747
|
-
* Apply interference-aware scoring. Cards with tags that interfere with
|
|
1748
|
-
* immature learnings get reduced scores.
|
|
1749
|
-
*/
|
|
1750
|
-
async transform(cards, context) {
|
|
1751
|
-
const immatureTags = await this.getImmatureTags(context);
|
|
1752
|
-
const tagsToAvoid = this.getTagsToAvoid(immatureTags);
|
|
1753
|
-
const adjusted = [];
|
|
1754
|
-
for (const card of cards) {
|
|
1755
|
-
const cardTags = await this.getCardTags(card.cardId, context.course);
|
|
1756
|
-
const { multiplier, reason } = this.computeInterferenceEffect(
|
|
1757
|
-
cardTags,
|
|
1758
|
-
tagsToAvoid,
|
|
1759
|
-
immatureTags
|
|
1760
|
-
);
|
|
1761
|
-
const finalScore = card.score * multiplier;
|
|
1762
|
-
const action = multiplier < 1 ? "penalized" : multiplier > 1 ? "boosted" : "passed";
|
|
1763
|
-
adjusted.push({
|
|
1764
|
-
...card,
|
|
1765
|
-
score: finalScore,
|
|
1766
|
-
provenance: [
|
|
1767
|
-
...card.provenance,
|
|
1768
|
-
{
|
|
1769
|
-
strategy: "interferenceMitigator",
|
|
1770
|
-
strategyName: this.strategyName || this.name,
|
|
1771
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-interference",
|
|
1772
|
-
action,
|
|
1773
|
-
score: finalScore,
|
|
1774
|
-
reason
|
|
1775
|
-
}
|
|
1776
|
-
]
|
|
1777
|
-
});
|
|
1778
|
-
}
|
|
1779
|
-
return adjusted;
|
|
1780
|
-
}
|
|
1781
|
-
/**
|
|
1782
|
-
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1783
|
-
*
|
|
1784
|
-
* Use transform() via Pipeline instead.
|
|
1785
|
-
*/
|
|
1786
|
-
async getWeightedCards(_limit) {
|
|
1787
|
-
throw new Error(
|
|
1788
|
-
"InterferenceMitigatorNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1789
|
-
);
|
|
1790
|
-
}
|
|
1791
|
-
// Legacy methods - stub implementations since filters don't generate cards
|
|
1792
|
-
async getNewCards(_n) {
|
|
1793
|
-
return [];
|
|
1794
|
-
}
|
|
1795
|
-
async getPendingReviews() {
|
|
1796
|
-
return [];
|
|
1797
|
-
}
|
|
1798
|
-
};
|
|
1799
|
-
}
|
|
1800
|
-
});
|
|
1801
|
-
|
|
1802
|
-
// src/core/navigators/relativePriority.ts
|
|
1803
|
-
var relativePriority_exports = {};
|
|
1804
|
-
__export(relativePriority_exports, {
|
|
1805
|
-
default: () => RelativePriorityNavigator
|
|
1806
|
-
});
|
|
1807
|
-
var DEFAULT_PRIORITY, DEFAULT_PRIORITY_INFLUENCE, DEFAULT_COMBINE_MODE, RelativePriorityNavigator;
|
|
1808
|
-
var init_relativePriority = __esm({
|
|
1809
|
-
"src/core/navigators/relativePriority.ts"() {
|
|
1810
|
-
"use strict";
|
|
1811
|
-
init_navigators();
|
|
1812
|
-
DEFAULT_PRIORITY = 0.5;
|
|
1813
|
-
DEFAULT_PRIORITY_INFLUENCE = 0.5;
|
|
1814
|
-
DEFAULT_COMBINE_MODE = "max";
|
|
1815
|
-
RelativePriorityNavigator = class extends ContentNavigator {
|
|
1816
|
-
config;
|
|
1817
|
-
_strategyData;
|
|
1818
|
-
/** Human-readable name for CardFilter interface */
|
|
1819
|
-
name;
|
|
1820
|
-
constructor(user, course, _strategyData) {
|
|
1821
|
-
super(user, course, _strategyData);
|
|
1822
|
-
this._strategyData = _strategyData;
|
|
1823
|
-
this.config = this.parseConfig(_strategyData.serializedData);
|
|
1824
|
-
this.name = _strategyData.name || "Relative Priority";
|
|
1825
|
-
}
|
|
1826
|
-
parseConfig(serializedData) {
|
|
1827
|
-
try {
|
|
1828
|
-
const parsed = JSON.parse(serializedData);
|
|
1829
|
-
return {
|
|
1830
|
-
tagPriorities: parsed.tagPriorities || {},
|
|
1831
|
-
defaultPriority: parsed.defaultPriority ?? DEFAULT_PRIORITY,
|
|
1832
|
-
combineMode: parsed.combineMode ?? DEFAULT_COMBINE_MODE,
|
|
1833
|
-
priorityInfluence: parsed.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE
|
|
1834
|
-
};
|
|
1835
|
-
} catch {
|
|
1836
|
-
return {
|
|
1837
|
-
tagPriorities: {},
|
|
1838
|
-
defaultPriority: DEFAULT_PRIORITY,
|
|
1839
|
-
combineMode: DEFAULT_COMBINE_MODE,
|
|
1840
|
-
priorityInfluence: DEFAULT_PRIORITY_INFLUENCE
|
|
1841
|
-
};
|
|
1842
|
-
}
|
|
1843
|
-
}
|
|
1844
|
-
/**
|
|
1845
|
-
* Look up the priority for a tag.
|
|
1846
|
-
*/
|
|
1847
|
-
getTagPriority(tagId) {
|
|
1848
|
-
return this.config.tagPriorities[tagId] ?? this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1849
|
-
}
|
|
1850
|
-
/**
|
|
1851
|
-
* Compute combined priority for a card based on its tags.
|
|
1852
|
-
*/
|
|
1853
|
-
computeCardPriority(cardTags) {
|
|
1854
|
-
if (cardTags.length === 0) {
|
|
1855
|
-
return this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1856
|
-
}
|
|
1857
|
-
const priorities = cardTags.map((tag) => this.getTagPriority(tag));
|
|
1858
|
-
switch (this.config.combineMode) {
|
|
1859
|
-
case "max":
|
|
1860
|
-
return Math.max(...priorities);
|
|
1861
|
-
case "min":
|
|
1862
|
-
return Math.min(...priorities);
|
|
1863
|
-
case "average":
|
|
1864
|
-
return priorities.reduce((sum, p) => sum + p, 0) / priorities.length;
|
|
1865
|
-
default:
|
|
1866
|
-
return Math.max(...priorities);
|
|
1867
|
-
}
|
|
1868
|
-
}
|
|
1869
|
-
/**
|
|
1870
|
-
* Compute boost factor based on priority.
|
|
1871
|
-
*
|
|
1872
|
-
* The formula: 1 + (priority - 0.5) * priorityInfluence
|
|
1873
|
-
*
|
|
1874
|
-
* This creates a multiplier centered around 1.0:
|
|
1875
|
-
* - Priority 1.0 with influence 0.5 → 1.25 (25% boost)
|
|
1876
|
-
* - Priority 0.5 with any influence → 1.00 (neutral)
|
|
1877
|
-
* - Priority 0.0 with influence 0.5 → 0.75 (25% reduction)
|
|
1878
|
-
*/
|
|
1879
|
-
computeBoostFactor(priority) {
|
|
1880
|
-
const influence = this.config.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE;
|
|
1881
|
-
return 1 + (priority - 0.5) * influence;
|
|
1882
|
-
}
|
|
1883
|
-
/**
|
|
1884
|
-
* Build human-readable reason for priority adjustment.
|
|
1885
|
-
*/
|
|
1886
|
-
buildPriorityReason(cardTags, priority, boostFactor, finalScore) {
|
|
1887
|
-
if (cardTags.length === 0) {
|
|
1888
|
-
return `No tags, neutral priority (${priority.toFixed(2)})`;
|
|
1889
|
-
}
|
|
1890
|
-
const tagList = cardTags.slice(0, 3).join(", ");
|
|
1891
|
-
const more = cardTags.length > 3 ? ` (+${cardTags.length - 3} more)` : "";
|
|
1892
|
-
if (boostFactor === 1) {
|
|
1893
|
-
return `Neutral priority (${priority.toFixed(2)}) for tags: ${tagList}${more}`;
|
|
1894
|
-
} else if (boostFactor > 1) {
|
|
1895
|
-
return `High-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 boost ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1896
|
-
} else {
|
|
1897
|
-
return `Low-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 reduce ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1898
|
-
}
|
|
1899
|
-
}
|
|
1900
|
-
/**
|
|
1901
|
-
* Get tags for a single card.
|
|
1902
|
-
*/
|
|
1903
|
-
async getCardTags(cardId, course) {
|
|
1904
|
-
try {
|
|
1905
|
-
const tagResponse = await course.getAppliedTags(cardId);
|
|
1906
|
-
return tagResponse.rows.map((r) => r.doc?.name).filter((x) => !!x);
|
|
1907
|
-
} catch {
|
|
1908
|
-
return [];
|
|
1909
|
-
}
|
|
1910
|
-
}
|
|
1911
|
-
/**
|
|
1912
|
-
* CardFilter.transform implementation.
|
|
1913
|
-
*
|
|
1914
|
-
* Apply priority-adjusted scoring. Cards with high-priority tags get boosted,
|
|
1915
|
-
* cards with low-priority tags get reduced scores.
|
|
1916
|
-
*/
|
|
1917
|
-
async transform(cards, context) {
|
|
1918
|
-
const adjusted = await Promise.all(
|
|
1919
|
-
cards.map(async (card) => {
|
|
1920
|
-
const cardTags = await this.getCardTags(card.cardId, context.course);
|
|
1921
|
-
const priority = this.computeCardPriority(cardTags);
|
|
1922
|
-
const boostFactor = this.computeBoostFactor(priority);
|
|
1923
|
-
const finalScore = Math.max(0, Math.min(1, card.score * boostFactor));
|
|
1924
|
-
const action = boostFactor > 1 ? "boosted" : boostFactor < 1 ? "penalized" : "passed";
|
|
1925
|
-
const reason = this.buildPriorityReason(cardTags, priority, boostFactor, finalScore);
|
|
1926
|
-
return {
|
|
1927
|
-
...card,
|
|
1928
|
-
score: finalScore,
|
|
1929
|
-
provenance: [
|
|
1930
|
-
...card.provenance,
|
|
1931
|
-
{
|
|
1932
|
-
strategy: "relativePriority",
|
|
1933
|
-
strategyName: this.strategyName || this.name,
|
|
1934
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-priority",
|
|
1935
|
-
action,
|
|
1936
|
-
score: finalScore,
|
|
1937
|
-
reason
|
|
1938
|
-
}
|
|
1939
|
-
]
|
|
1940
|
-
};
|
|
1941
|
-
})
|
|
1942
|
-
);
|
|
1943
|
-
return adjusted;
|
|
1944
|
-
}
|
|
1945
|
-
/**
|
|
1946
|
-
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1947
|
-
*
|
|
1948
|
-
* Use transform() via Pipeline instead.
|
|
1949
|
-
*/
|
|
1950
|
-
async getWeightedCards(_limit) {
|
|
1951
|
-
throw new Error(
|
|
1952
|
-
"RelativePriorityNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1953
|
-
);
|
|
1954
|
-
}
|
|
1955
|
-
// Legacy methods - stub implementations since filters don't generate cards
|
|
1956
|
-
async getNewCards(_n) {
|
|
1957
|
-
return [];
|
|
1958
|
-
}
|
|
1959
|
-
async getPendingReviews() {
|
|
1960
|
-
return [];
|
|
1961
|
-
}
|
|
1962
|
-
};
|
|
1963
|
-
}
|
|
1964
|
-
});
|
|
1965
|
-
|
|
1966
|
-
// src/core/navigators/srs.ts
|
|
1967
|
-
var srs_exports = {};
|
|
1968
|
-
__export(srs_exports, {
|
|
1969
|
-
default: () => SRSNavigator
|
|
1970
|
-
});
|
|
1971
|
-
var import_moment, SRSNavigator;
|
|
1972
|
-
var init_srs = __esm({
|
|
1973
|
-
"src/core/navigators/srs.ts"() {
|
|
1974
|
-
"use strict";
|
|
1975
|
-
import_moment = __toESM(require("moment"), 1);
|
|
1976
|
-
init_navigators();
|
|
1977
|
-
SRSNavigator = class extends ContentNavigator {
|
|
1978
|
-
/** Human-readable name for CardGenerator interface */
|
|
1979
|
-
name;
|
|
1980
|
-
constructor(user, course, strategyData) {
|
|
1981
|
-
super(user, course, strategyData);
|
|
1982
|
-
this.name = strategyData?.name || "SRS";
|
|
1983
|
-
}
|
|
1984
|
-
/**
|
|
1985
|
-
* Get review cards scored by urgency.
|
|
1986
|
-
*
|
|
1987
|
-
* Score formula combines:
|
|
1988
|
-
* - Relative overdueness: hoursOverdue / intervalHours
|
|
1989
|
-
* - Interval recency: exponential decay favoring shorter intervals
|
|
1990
|
-
*
|
|
1991
|
-
* Cards not yet due are excluded (not scored as 0).
|
|
1992
|
-
*
|
|
1993
|
-
* This method supports both the legacy signature (limit only) and the
|
|
1994
|
-
* CardGenerator interface signature (limit, context).
|
|
1995
|
-
*
|
|
1996
|
-
* @param limit - Maximum number of cards to return
|
|
1997
|
-
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1998
|
-
*/
|
|
1999
|
-
async getWeightedCards(limit, _context) {
|
|
2000
|
-
if (!this.user || !this.course) {
|
|
2001
|
-
throw new Error("SRSNavigator requires user and course to be set");
|
|
2002
|
-
}
|
|
2003
|
-
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
2004
|
-
const now = import_moment.default.utc();
|
|
2005
|
-
const dueReviews = reviews.filter((r) => now.isAfter(import_moment.default.utc(r.reviewTime)));
|
|
2006
|
-
const scored = dueReviews.map((review) => {
|
|
2007
|
-
const { score, reason } = this.computeUrgencyScore(review, now);
|
|
2008
|
-
return {
|
|
2009
|
-
cardId: review.cardId,
|
|
2010
|
-
courseId: review.courseId,
|
|
2011
|
-
score,
|
|
2012
|
-
provenance: [
|
|
2013
|
-
{
|
|
2014
|
-
strategy: "srs",
|
|
2015
|
-
strategyName: this.strategyName || this.name,
|
|
2016
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-SRS-default",
|
|
2017
|
-
action: "generated",
|
|
2018
|
-
score,
|
|
2019
|
-
reason
|
|
2020
|
-
}
|
|
2021
|
-
]
|
|
2022
|
-
};
|
|
2023
|
-
});
|
|
2024
|
-
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
1328
|
+
logger.debug(`[srsNav] got ${scored.length} weighted cards`);
|
|
1329
|
+
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
2025
1330
|
}
|
|
2026
1331
|
/**
|
|
2027
1332
|
* Compute urgency score for a review card.
|
|
@@ -2052,235 +1357,102 @@ var init_srs = __esm({
|
|
|
2052
1357
|
const reason = `${Math.round(hoursOverdue)}h overdue (interval: ${Math.round(intervalHours)}h, relative: ${relativeOverdue.toFixed(2)}), recency: ${recencyFactor.toFixed(2)}, review`;
|
|
2053
1358
|
return { score, reason };
|
|
2054
1359
|
}
|
|
2055
|
-
/**
|
|
2056
|
-
* Get pending reviews in legacy format.
|
|
2057
|
-
*
|
|
2058
|
-
* Returns all pending reviews for the course, enriched with session item fields.
|
|
2059
|
-
*/
|
|
2060
|
-
async getPendingReviews() {
|
|
2061
|
-
if (!this.user || !this.course) {
|
|
2062
|
-
throw new Error("SRSNavigator requires user and course to be set");
|
|
2063
|
-
}
|
|
2064
|
-
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
2065
|
-
return reviews.map((r) => ({
|
|
2066
|
-
...r,
|
|
2067
|
-
contentSourceType: "course",
|
|
2068
|
-
contentSourceID: this.course.getCourseID(),
|
|
2069
|
-
cardID: r.cardId,
|
|
2070
|
-
courseID: r.courseId,
|
|
2071
|
-
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
2072
|
-
reviewID: r._id,
|
|
2073
|
-
status: "review"
|
|
2074
|
-
}));
|
|
2075
|
-
}
|
|
2076
|
-
/**
|
|
2077
|
-
* SRS does not generate new cards.
|
|
2078
|
-
* Use ELONavigator or another generator for new cards.
|
|
2079
|
-
*/
|
|
2080
|
-
async getNewCards(_n) {
|
|
2081
|
-
return [];
|
|
2082
|
-
}
|
|
2083
1360
|
};
|
|
2084
1361
|
}
|
|
2085
1362
|
});
|
|
2086
1363
|
|
|
2087
|
-
//
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
"./CompositeGenerator.ts": () => Promise.resolve().then(() => (init_CompositeGenerator(), CompositeGenerator_exports)),
|
|
2093
|
-
"./Pipeline.ts": () => Promise.resolve().then(() => (init_Pipeline(), Pipeline_exports)),
|
|
2094
|
-
"./PipelineAssembler.ts": () => Promise.resolve().then(() => (init_PipelineAssembler(), PipelineAssembler_exports)),
|
|
2095
|
-
"./elo.ts": () => Promise.resolve().then(() => (init_elo(), elo_exports)),
|
|
2096
|
-
"./filters/eloDistance.ts": () => Promise.resolve().then(() => (init_eloDistance(), eloDistance_exports)),
|
|
2097
|
-
"./filters/index.ts": () => Promise.resolve().then(() => (init_filters(), filters_exports)),
|
|
2098
|
-
"./filters/types.ts": () => Promise.resolve().then(() => (init_types(), types_exports)),
|
|
2099
|
-
"./generators/index.ts": () => Promise.resolve().then(() => (init_generators(), generators_exports)),
|
|
2100
|
-
"./generators/types.ts": () => Promise.resolve().then(() => (init_types2(), types_exports2)),
|
|
2101
|
-
"./hardcodedOrder.ts": () => Promise.resolve().then(() => (init_hardcodedOrder(), hardcodedOrder_exports)),
|
|
2102
|
-
"./hierarchyDefinition.ts": () => Promise.resolve().then(() => (init_hierarchyDefinition(), hierarchyDefinition_exports)),
|
|
2103
|
-
"./index.ts": () => Promise.resolve().then(() => (init_navigators(), navigators_exports)),
|
|
2104
|
-
"./interferenceMitigator.ts": () => Promise.resolve().then(() => (init_interferenceMitigator(), interferenceMitigator_exports)),
|
|
2105
|
-
"./relativePriority.ts": () => Promise.resolve().then(() => (init_relativePriority(), relativePriority_exports)),
|
|
2106
|
-
"./srs.ts": () => Promise.resolve().then(() => (init_srs(), srs_exports))
|
|
2107
|
-
});
|
|
2108
|
-
}
|
|
2109
|
-
});
|
|
2110
|
-
|
|
2111
|
-
// src/core/navigators/index.ts
|
|
2112
|
-
var navigators_exports = {};
|
|
2113
|
-
__export(navigators_exports, {
|
|
2114
|
-
ContentNavigator: () => ContentNavigator,
|
|
2115
|
-
NavigatorRole: () => NavigatorRole,
|
|
2116
|
-
NavigatorRoles: () => NavigatorRoles,
|
|
2117
|
-
Navigators: () => Navigators,
|
|
2118
|
-
getCardOrigin: () => getCardOrigin,
|
|
2119
|
-
isFilter: () => isFilter,
|
|
2120
|
-
isGenerator: () => isGenerator
|
|
2121
|
-
});
|
|
2122
|
-
function getCardOrigin(card) {
|
|
2123
|
-
if (card.provenance.length === 0) {
|
|
2124
|
-
throw new Error("Card has no provenance - cannot determine origin");
|
|
2125
|
-
}
|
|
2126
|
-
const firstEntry = card.provenance[0];
|
|
2127
|
-
const reason = firstEntry.reason.toLowerCase();
|
|
2128
|
-
if (reason.includes("failed")) {
|
|
2129
|
-
return "failed";
|
|
2130
|
-
}
|
|
2131
|
-
if (reason.includes("review")) {
|
|
2132
|
-
return "review";
|
|
2133
|
-
}
|
|
2134
|
-
return "new";
|
|
2135
|
-
}
|
|
2136
|
-
function isGenerator(impl) {
|
|
2137
|
-
return NavigatorRoles[impl] === "generator" /* GENERATOR */;
|
|
2138
|
-
}
|
|
2139
|
-
function isFilter(impl) {
|
|
2140
|
-
return NavigatorRoles[impl] === "filter" /* FILTER */;
|
|
1364
|
+
// src/core/navigators/filters/eloDistance.ts
|
|
1365
|
+
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
1366
|
+
const normalizedDistance = distance / halfLife;
|
|
1367
|
+
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
1368
|
+
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
2141
1369
|
}
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
* ## For Generators
|
|
2229
|
-
* Override this method to generate candidates and compute scores based on
|
|
2230
|
-
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
2231
|
-
* initial provenance entry with action='generated'.
|
|
2232
|
-
*
|
|
2233
|
-
* ## Default Implementation
|
|
2234
|
-
* The base class provides a backward-compatible default that:
|
|
2235
|
-
* 1. Calls legacy getNewCards() and getPendingReviews()
|
|
2236
|
-
* 2. Assigns score=1.0 to all cards
|
|
2237
|
-
* 3. Creates minimal provenance from legacy methods
|
|
2238
|
-
* 4. Returns combined results up to limit
|
|
2239
|
-
*
|
|
2240
|
-
* This allows existing strategies to work without modification while
|
|
2241
|
-
* new strategies can override with proper scoring and provenance.
|
|
2242
|
-
*
|
|
2243
|
-
* @param limit - Maximum cards to return
|
|
2244
|
-
* @returns Cards sorted by score descending, with provenance trails
|
|
2245
|
-
*/
|
|
2246
|
-
async getWeightedCards(limit) {
|
|
2247
|
-
const newCards = await this.getNewCards(limit);
|
|
2248
|
-
const reviews = await this.getPendingReviews();
|
|
2249
|
-
const weighted = [
|
|
2250
|
-
...newCards.map((c) => ({
|
|
2251
|
-
cardId: c.cardID,
|
|
2252
|
-
courseId: c.courseID,
|
|
2253
|
-
score: 1,
|
|
2254
|
-
provenance: [
|
|
2255
|
-
{
|
|
2256
|
-
strategy: "legacy",
|
|
2257
|
-
strategyName: this.strategyName || "Legacy API",
|
|
2258
|
-
strategyId: this.strategyId || "legacy-fallback",
|
|
2259
|
-
action: "generated",
|
|
2260
|
-
score: 1,
|
|
2261
|
-
reason: "Generated via legacy getNewCards(), new card"
|
|
2262
|
-
}
|
|
2263
|
-
]
|
|
2264
|
-
})),
|
|
2265
|
-
...reviews.map((r) => ({
|
|
2266
|
-
cardId: r.cardID,
|
|
2267
|
-
courseId: r.courseID,
|
|
2268
|
-
score: 1,
|
|
2269
|
-
provenance: [
|
|
2270
|
-
{
|
|
2271
|
-
strategy: "legacy",
|
|
2272
|
-
strategyName: this.strategyName || "Legacy API",
|
|
2273
|
-
strategyId: this.strategyId || "legacy-fallback",
|
|
2274
|
-
action: "generated",
|
|
2275
|
-
score: 1,
|
|
2276
|
-
reason: "Generated via legacy getPendingReviews(), review"
|
|
2277
|
-
}
|
|
2278
|
-
]
|
|
2279
|
-
}))
|
|
2280
|
-
];
|
|
2281
|
-
return weighted.slice(0, limit);
|
|
2282
|
-
}
|
|
2283
|
-
};
|
|
1370
|
+
function createEloDistanceFilter(config) {
|
|
1371
|
+
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
1372
|
+
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
1373
|
+
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
1374
|
+
return {
|
|
1375
|
+
name: "ELO Distance Filter",
|
|
1376
|
+
async transform(cards, context) {
|
|
1377
|
+
const { course, userElo } = context;
|
|
1378
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
1379
|
+
const cardElos = await course.getCardEloData(cardIds);
|
|
1380
|
+
return cards.map((card, i) => {
|
|
1381
|
+
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
1382
|
+
const distance = Math.abs(cardElo - userElo);
|
|
1383
|
+
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
1384
|
+
const newScore = card.score * multiplier;
|
|
1385
|
+
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
1386
|
+
return {
|
|
1387
|
+
...card,
|
|
1388
|
+
score: newScore,
|
|
1389
|
+
provenance: [
|
|
1390
|
+
...card.provenance,
|
|
1391
|
+
{
|
|
1392
|
+
strategy: "eloDistance",
|
|
1393
|
+
strategyName: "ELO Distance Filter",
|
|
1394
|
+
strategyId: "ELO_DISTANCE_FILTER",
|
|
1395
|
+
action,
|
|
1396
|
+
score: newScore,
|
|
1397
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
1398
|
+
}
|
|
1399
|
+
]
|
|
1400
|
+
};
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
}
|
|
1405
|
+
var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
|
|
1406
|
+
var init_eloDistance = __esm({
|
|
1407
|
+
"src/core/navigators/filters/eloDistance.ts"() {
|
|
1408
|
+
"use strict";
|
|
1409
|
+
DEFAULT_HALF_LIFE = 200;
|
|
1410
|
+
DEFAULT_MIN_MULTIPLIER = 0.3;
|
|
1411
|
+
DEFAULT_MAX_MULTIPLIER = 1;
|
|
1412
|
+
}
|
|
1413
|
+
});
|
|
1414
|
+
|
|
1415
|
+
// src/core/navigators/defaults.ts
|
|
1416
|
+
function createDefaultEloStrategy(courseId) {
|
|
1417
|
+
return {
|
|
1418
|
+
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
1419
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1420
|
+
name: "ELO (default)",
|
|
1421
|
+
description: "Default ELO-based navigation strategy for new cards",
|
|
1422
|
+
implementingClass: "elo" /* ELO */,
|
|
1423
|
+
course: courseId,
|
|
1424
|
+
serializedData: ""
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
function createDefaultSrsStrategy(courseId) {
|
|
1428
|
+
return {
|
|
1429
|
+
_id: "NAVIGATION_STRATEGY-SRS-default",
|
|
1430
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1431
|
+
name: "SRS (default)",
|
|
1432
|
+
description: "Default SRS-based navigation strategy for reviews",
|
|
1433
|
+
implementingClass: "srs" /* SRS */,
|
|
1434
|
+
course: courseId,
|
|
1435
|
+
serializedData: ""
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
function createDefaultPipeline(user, course) {
|
|
1439
|
+
const courseId = course.getCourseID();
|
|
1440
|
+
const eloNavigator = new ELONavigator(user, course, createDefaultEloStrategy(courseId));
|
|
1441
|
+
const srsNavigator = new SRSNavigator(user, course, createDefaultSrsStrategy(courseId));
|
|
1442
|
+
const compositeGenerator = new CompositeGenerator([eloNavigator, srsNavigator]);
|
|
1443
|
+
const eloDistanceFilter = createEloDistanceFilter();
|
|
1444
|
+
return new Pipeline(compositeGenerator, [eloDistanceFilter], user, course);
|
|
1445
|
+
}
|
|
1446
|
+
var init_defaults = __esm({
|
|
1447
|
+
"src/core/navigators/defaults.ts"() {
|
|
1448
|
+
"use strict";
|
|
1449
|
+
init_navigators();
|
|
1450
|
+
init_Pipeline();
|
|
1451
|
+
init_CompositeGenerator();
|
|
1452
|
+
init_elo();
|
|
1453
|
+
init_srs();
|
|
1454
|
+
init_eloDistance();
|
|
1455
|
+
init_types_legacy();
|
|
2284
1456
|
}
|
|
2285
1457
|
});
|
|
2286
1458
|
|
|
@@ -2402,11 +1574,11 @@ ${JSON.stringify(config)}
|
|
|
2402
1574
|
function isSuccessRow(row) {
|
|
2403
1575
|
return "doc" in row && row.doc !== null && row.doc !== void 0;
|
|
2404
1576
|
}
|
|
2405
|
-
var
|
|
1577
|
+
var import_common7, CoursesDB, CourseDB;
|
|
2406
1578
|
var init_courseDB = __esm({
|
|
2407
1579
|
"src/impl/couch/courseDB.ts"() {
|
|
2408
1580
|
"use strict";
|
|
2409
|
-
|
|
1581
|
+
import_common7 = require("@vue-skuilder/common");
|
|
2410
1582
|
init_couch();
|
|
2411
1583
|
init_updateQueue();
|
|
2412
1584
|
init_types_legacy();
|
|
@@ -2415,12 +1587,8 @@ var init_courseDB = __esm({
|
|
|
2415
1587
|
init_courseAPI();
|
|
2416
1588
|
init_courseLookupDB();
|
|
2417
1589
|
init_navigators();
|
|
2418
|
-
init_Pipeline();
|
|
2419
1590
|
init_PipelineAssembler();
|
|
2420
|
-
|
|
2421
|
-
init_elo();
|
|
2422
|
-
init_srs();
|
|
2423
|
-
init_eloDistance();
|
|
1591
|
+
init_defaults();
|
|
2424
1592
|
CoursesDB = class {
|
|
2425
1593
|
_courseIDs;
|
|
2426
1594
|
constructor(courseIDs) {
|
|
@@ -2532,14 +1700,14 @@ var init_courseDB = __esm({
|
|
|
2532
1700
|
docs.rows.forEach((r) => {
|
|
2533
1701
|
if (isSuccessRow(r)) {
|
|
2534
1702
|
if (r.doc && r.doc.elo) {
|
|
2535
|
-
ret.push((0,
|
|
1703
|
+
ret.push((0, import_common7.toCourseElo)(r.doc.elo));
|
|
2536
1704
|
} else {
|
|
2537
1705
|
logger.warn("no elo data for card: " + r.id);
|
|
2538
|
-
ret.push((0,
|
|
1706
|
+
ret.push((0, import_common7.blankCourseElo)());
|
|
2539
1707
|
}
|
|
2540
1708
|
} else {
|
|
2541
1709
|
logger.warn("no elo data for card: " + JSON.stringify(r));
|
|
2542
|
-
ret.push((0,
|
|
1710
|
+
ret.push((0, import_common7.blankCourseElo)());
|
|
2543
1711
|
}
|
|
2544
1712
|
});
|
|
2545
1713
|
return ret;
|
|
@@ -2601,15 +1769,6 @@ var init_courseDB = __esm({
|
|
|
2601
1769
|
ret[r.id] = r.doc.id_displayable_data;
|
|
2602
1770
|
}
|
|
2603
1771
|
});
|
|
2604
|
-
await Promise.all(
|
|
2605
|
-
cards.rows.map((r) => {
|
|
2606
|
-
return async () => {
|
|
2607
|
-
if (isSuccessRow(r)) {
|
|
2608
|
-
ret[r.id] = r.doc.id_displayable_data;
|
|
2609
|
-
}
|
|
2610
|
-
};
|
|
2611
|
-
})
|
|
2612
|
-
);
|
|
2613
1772
|
return ret;
|
|
2614
1773
|
}
|
|
2615
1774
|
async getCardsByELO(elo, cardLimit) {
|
|
@@ -2694,6 +1853,28 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
2694
1853
|
throw new Error(`Failed to find tags for card ${this.id}-${cardId}`);
|
|
2695
1854
|
}
|
|
2696
1855
|
}
|
|
1856
|
+
async getAppliedTagsBatch(cardIds) {
|
|
1857
|
+
if (cardIds.length === 0) {
|
|
1858
|
+
return /* @__PURE__ */ new Map();
|
|
1859
|
+
}
|
|
1860
|
+
const db = getCourseDB2(this.id);
|
|
1861
|
+
const result = await db.query("getTags", {
|
|
1862
|
+
keys: cardIds,
|
|
1863
|
+
include_docs: false
|
|
1864
|
+
});
|
|
1865
|
+
const tagsByCard = /* @__PURE__ */ new Map();
|
|
1866
|
+
for (const cardId of cardIds) {
|
|
1867
|
+
tagsByCard.set(cardId, []);
|
|
1868
|
+
}
|
|
1869
|
+
for (const row of result.rows) {
|
|
1870
|
+
const cardId = row.key;
|
|
1871
|
+
const tagName = row.value?.name;
|
|
1872
|
+
if (tagName && tagsByCard.has(cardId)) {
|
|
1873
|
+
tagsByCard.get(cardId).push(tagName);
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
return tagsByCard;
|
|
1877
|
+
}
|
|
2697
1878
|
async addTagToCard(cardId, tagId, updateELO) {
|
|
2698
1879
|
return await addTagToCard(
|
|
2699
1880
|
this.id,
|
|
@@ -2721,7 +1902,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
2721
1902
|
async getCourseTagStubs() {
|
|
2722
1903
|
return getCourseTagStubs(this.id);
|
|
2723
1904
|
}
|
|
2724
|
-
async addNote(codeCourse, shape, data, author, tags, uploads, elo = (0,
|
|
1905
|
+
async addNote(codeCourse, shape, data, author, tags, uploads, elo = (0, import_common7.blankCourseElo)()) {
|
|
2725
1906
|
try {
|
|
2726
1907
|
const resp = await addNote55(this.id, codeCourse, shape, data, author, tags, uploads, elo);
|
|
2727
1908
|
if (resp.ok) {
|
|
@@ -2730,19 +1911,19 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
2730
1911
|
`[courseDB.addNote] Note added but card creation failed: ${resp.cardCreationError}`
|
|
2731
1912
|
);
|
|
2732
1913
|
return {
|
|
2733
|
-
status:
|
|
1914
|
+
status: import_common7.Status.error,
|
|
2734
1915
|
message: `Note was added but no cards were created: ${resp.cardCreationError}`,
|
|
2735
1916
|
id: resp.id
|
|
2736
1917
|
};
|
|
2737
1918
|
}
|
|
2738
1919
|
return {
|
|
2739
|
-
status:
|
|
1920
|
+
status: import_common7.Status.ok,
|
|
2740
1921
|
message: "",
|
|
2741
1922
|
id: resp.id
|
|
2742
1923
|
};
|
|
2743
1924
|
} else {
|
|
2744
1925
|
return {
|
|
2745
|
-
status:
|
|
1926
|
+
status: import_common7.Status.error,
|
|
2746
1927
|
message: "Unexpected error adding note"
|
|
2747
1928
|
};
|
|
2748
1929
|
}
|
|
@@ -2754,7 +1935,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
2754
1935
|
message: ${err.message}`
|
|
2755
1936
|
);
|
|
2756
1937
|
return {
|
|
2757
|
-
status:
|
|
1938
|
+
status: import_common7.Status.error,
|
|
2758
1939
|
message: `Error adding note to course. ${e.reason || err.message}`
|
|
2759
1940
|
};
|
|
2760
1941
|
}
|
|
@@ -2821,7 +2002,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
2821
2002
|
logger.debug(
|
|
2822
2003
|
"[courseDB] No strategy documents found, using default Pipeline(Composite(ELO, SRS), [eloDistanceFilter])"
|
|
2823
2004
|
);
|
|
2824
|
-
return
|
|
2005
|
+
return createDefaultPipeline(user, this);
|
|
2825
2006
|
}
|
|
2826
2007
|
const assembler = new PipelineAssembler();
|
|
2827
2008
|
const { pipeline, generatorStrategies, filterStrategies, warnings } = await assembler.assemble({
|
|
@@ -2834,7 +2015,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
2834
2015
|
}
|
|
2835
2016
|
if (!pipeline) {
|
|
2836
2017
|
logger.debug("[courseDB] Pipeline assembly failed, using default pipeline");
|
|
2837
|
-
return
|
|
2018
|
+
return createDefaultPipeline(user, this);
|
|
2838
2019
|
}
|
|
2839
2020
|
logger.debug(
|
|
2840
2021
|
`[courseDB] Using assembled pipeline with ${generatorStrategies.length} generator(s) and ${filterStrategies.length} filter(s)`
|
|
@@ -2845,69 +2026,12 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
2845
2026
|
throw e;
|
|
2846
2027
|
}
|
|
2847
2028
|
}
|
|
2848
|
-
makeDefaultEloStrategy() {
|
|
2849
|
-
return {
|
|
2850
|
-
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
2851
|
-
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
2852
|
-
name: "ELO (default)",
|
|
2853
|
-
description: "Default ELO-based navigation strategy for new cards",
|
|
2854
|
-
implementingClass: "elo" /* ELO */,
|
|
2855
|
-
course: this.id,
|
|
2856
|
-
serializedData: ""
|
|
2857
|
-
};
|
|
2858
|
-
}
|
|
2859
|
-
makeDefaultSrsStrategy() {
|
|
2860
|
-
return {
|
|
2861
|
-
_id: "NAVIGATION_STRATEGY-SRS-default",
|
|
2862
|
-
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
2863
|
-
name: "SRS (default)",
|
|
2864
|
-
description: "Default SRS-based navigation strategy for reviews",
|
|
2865
|
-
implementingClass: "srs" /* SRS */,
|
|
2866
|
-
course: this.id,
|
|
2867
|
-
serializedData: ""
|
|
2868
|
-
};
|
|
2869
|
-
}
|
|
2870
|
-
/**
|
|
2871
|
-
* Creates the default navigation pipeline for courses with no configured strategies.
|
|
2872
|
-
*
|
|
2873
|
-
* Default: Pipeline(Composite(ELO, SRS), [eloDistanceFilter])
|
|
2874
|
-
* - ELO generator: scores new cards by skill proximity
|
|
2875
|
-
* - SRS generator: scores reviews by overdueness and interval recency
|
|
2876
|
-
* - ELO distance filter: penalizes cards far from user's current level
|
|
2877
|
-
*/
|
|
2878
|
-
createDefaultPipeline(user) {
|
|
2879
|
-
const eloNavigator = new ELONavigator(user, this, this.makeDefaultEloStrategy());
|
|
2880
|
-
const srsNavigator = new SRSNavigator(user, this, this.makeDefaultSrsStrategy());
|
|
2881
|
-
const compositeGenerator = new CompositeGenerator([eloNavigator, srsNavigator]);
|
|
2882
|
-
const eloDistanceFilter = createEloDistanceFilter();
|
|
2883
|
-
return new Pipeline(compositeGenerator, [eloDistanceFilter], user, this);
|
|
2884
|
-
}
|
|
2885
2029
|
////////////////////////////////////
|
|
2886
2030
|
// END NavigationStrategyManager implementation
|
|
2887
2031
|
////////////////////////////////////
|
|
2888
2032
|
////////////////////////////////////
|
|
2889
2033
|
// StudyContentSource implementation
|
|
2890
2034
|
////////////////////////////////////
|
|
2891
|
-
async getNewCards(limit = 99) {
|
|
2892
|
-
const u = await this._getCurrentUser();
|
|
2893
|
-
try {
|
|
2894
|
-
const navigator = await this.createNavigator(u);
|
|
2895
|
-
return navigator.getNewCards(limit);
|
|
2896
|
-
} catch (e) {
|
|
2897
|
-
logger.error(`[courseDB] Error in getNewCards: ${e}`);
|
|
2898
|
-
throw e;
|
|
2899
|
-
}
|
|
2900
|
-
}
|
|
2901
|
-
async getPendingReviews() {
|
|
2902
|
-
const u = await this._getCurrentUser();
|
|
2903
|
-
try {
|
|
2904
|
-
const navigator = await this.createNavigator(u);
|
|
2905
|
-
return navigator.getPendingReviews();
|
|
2906
|
-
} catch (e) {
|
|
2907
|
-
logger.error(`[courseDB] Error in getPendingReviews: ${e}`);
|
|
2908
|
-
throw e;
|
|
2909
|
-
}
|
|
2910
|
-
}
|
|
2911
2035
|
/**
|
|
2912
2036
|
* Get cards with suitability scores for presentation.
|
|
2913
2037
|
*
|
|
@@ -2939,7 +2063,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
2939
2063
|
const courseDoc = (await u.getCourseRegistrationsDoc()).courses.find((c) => {
|
|
2940
2064
|
return c.courseID === this.id;
|
|
2941
2065
|
});
|
|
2942
|
-
targetElo = (0,
|
|
2066
|
+
targetElo = (0, import_common7.EloToNumber)(courseDoc.elo);
|
|
2943
2067
|
} catch {
|
|
2944
2068
|
targetElo = 1e3;
|
|
2945
2069
|
}
|
|
@@ -3158,79 +2282,27 @@ var init_classroomDB2 = __esm({
|
|
|
3158
2282
|
setChangeFcn(f) {
|
|
3159
2283
|
void this.userMessages.on("change", f);
|
|
3160
2284
|
}
|
|
3161
|
-
async getPendingReviews() {
|
|
3162
|
-
const u = this._user;
|
|
3163
|
-
return (await u.getPendingReviews()).filter((r) => r.scheduledFor === "classroom" && r.schedulingAgentId === this._id).map((r) => {
|
|
3164
|
-
return {
|
|
3165
|
-
...r,
|
|
3166
|
-
qualifiedID: `${r.courseId}-${r.cardId}`,
|
|
3167
|
-
courseID: r.courseId,
|
|
3168
|
-
cardID: r.cardId,
|
|
3169
|
-
contentSourceType: "classroom",
|
|
3170
|
-
contentSourceID: this._id,
|
|
3171
|
-
reviewID: r._id,
|
|
3172
|
-
status: "review"
|
|
3173
|
-
};
|
|
3174
|
-
});
|
|
3175
|
-
}
|
|
3176
|
-
async getNewCards() {
|
|
3177
|
-
const activeCards = await this._user.getActiveCards();
|
|
3178
|
-
const now = import_moment2.default.utc();
|
|
3179
|
-
const assigned = await this.getAssignedContent();
|
|
3180
|
-
const due = assigned.filter((c) => now.isAfter(import_moment2.default.utc(c.activeOn, REVIEW_TIME_FORMAT)));
|
|
3181
|
-
logger.info(`Due content: ${JSON.stringify(due)}`);
|
|
3182
|
-
let ret = [];
|
|
3183
|
-
for (let i = 0; i < due.length; i++) {
|
|
3184
|
-
const content = due[i];
|
|
3185
|
-
if (content.type === "course") {
|
|
3186
|
-
const db = new CourseDB(content.courseID, async () => this._user);
|
|
3187
|
-
ret = ret.concat(await db.getNewCards());
|
|
3188
|
-
} else if (content.type === "tag") {
|
|
3189
|
-
const tagDoc = await getTag(content.courseID, content.tagID);
|
|
3190
|
-
ret = ret.concat(
|
|
3191
|
-
tagDoc.taggedCards.map((c) => {
|
|
3192
|
-
return {
|
|
3193
|
-
courseID: content.courseID,
|
|
3194
|
-
cardID: c,
|
|
3195
|
-
qualifiedID: `${content.courseID}-${c}`,
|
|
3196
|
-
contentSourceType: "classroom",
|
|
3197
|
-
contentSourceID: this._id,
|
|
3198
|
-
status: "new"
|
|
3199
|
-
};
|
|
3200
|
-
})
|
|
3201
|
-
);
|
|
3202
|
-
} else if (content.type === "card") {
|
|
3203
|
-
ret.push(await getCourseDB2(content.courseID).get(content.cardID));
|
|
3204
|
-
}
|
|
3205
|
-
}
|
|
3206
|
-
logger.info(
|
|
3207
|
-
`New Cards from classroom ${this._cfg.name}: ${ret.map((c) => `${c.courseID}-${c.cardID}`)}`
|
|
3208
|
-
);
|
|
3209
|
-
return ret.filter((c) => {
|
|
3210
|
-
if (activeCards.some((ac) => c.cardID === ac.cardID)) {
|
|
3211
|
-
return false;
|
|
3212
|
-
} else {
|
|
3213
|
-
return true;
|
|
3214
|
-
}
|
|
3215
|
-
});
|
|
3216
|
-
}
|
|
3217
2285
|
/**
|
|
3218
2286
|
* Get cards with suitability scores for presentation.
|
|
3219
2287
|
*
|
|
3220
|
-
*
|
|
3221
|
-
*
|
|
3222
|
-
* support pluggable navigation strategies.
|
|
2288
|
+
* Gathers new cards from assigned content (courses, tags, cards) and
|
|
2289
|
+
* pending reviews scheduled for this classroom. Assigns score=1.0 to all.
|
|
3223
2290
|
*
|
|
3224
2291
|
* @param limit - Maximum number of cards to return
|
|
3225
2292
|
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
3226
2293
|
*/
|
|
3227
2294
|
async getWeightedCards(limit) {
|
|
3228
|
-
const
|
|
3229
|
-
const
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
2295
|
+
const weighted = [];
|
|
2296
|
+
const allUserReviews = await this._user.getPendingReviews();
|
|
2297
|
+
const classroomReviews = allUserReviews.filter(
|
|
2298
|
+
(r) => r.scheduledFor === "classroom" && r.schedulingAgentId === this._id
|
|
2299
|
+
);
|
|
2300
|
+
for (const r of classroomReviews) {
|
|
2301
|
+
weighted.push({
|
|
2302
|
+
cardId: r.cardId,
|
|
2303
|
+
courseId: r.courseId,
|
|
3233
2304
|
score: 1,
|
|
2305
|
+
reviewID: r._id,
|
|
3234
2306
|
provenance: [
|
|
3235
2307
|
{
|
|
3236
2308
|
strategy: "classroom",
|
|
@@ -3238,27 +2310,84 @@ var init_classroomDB2 = __esm({
|
|
|
3238
2310
|
strategyId: "CLASSROOM",
|
|
3239
2311
|
action: "generated",
|
|
3240
2312
|
score: 1,
|
|
3241
|
-
reason: "Classroom
|
|
2313
|
+
reason: "Classroom scheduled review"
|
|
3242
2314
|
}
|
|
3243
2315
|
]
|
|
3244
|
-
})
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
2316
|
+
});
|
|
2317
|
+
}
|
|
2318
|
+
const activeCards = await this._user.getActiveCards();
|
|
2319
|
+
const activeCardIds = new Set(activeCards.map((ac) => ac.cardID));
|
|
2320
|
+
const now = import_moment2.default.utc();
|
|
2321
|
+
const assigned = await this.getAssignedContent();
|
|
2322
|
+
const due = assigned.filter((c) => now.isAfter(import_moment2.default.utc(c.activeOn, REVIEW_TIME_FORMAT)));
|
|
2323
|
+
logger.info(`[StudentClassroomDB] Due content: ${JSON.stringify(due)}`);
|
|
2324
|
+
for (const content of due) {
|
|
2325
|
+
if (content.type === "course") {
|
|
2326
|
+
const db = new CourseDB(content.courseID, async () => this._user);
|
|
2327
|
+
const courseCards = await db.getWeightedCards(limit);
|
|
2328
|
+
for (const card of courseCards) {
|
|
2329
|
+
if (!activeCardIds.has(card.cardId)) {
|
|
2330
|
+
weighted.push({
|
|
2331
|
+
...card,
|
|
2332
|
+
provenance: [
|
|
2333
|
+
...card.provenance,
|
|
2334
|
+
{
|
|
2335
|
+
strategy: "classroom",
|
|
2336
|
+
strategyName: "Classroom",
|
|
2337
|
+
strategyId: "CLASSROOM",
|
|
2338
|
+
action: "passed",
|
|
2339
|
+
score: card.score,
|
|
2340
|
+
reason: `Assigned via classroom from course ${content.courseID}`
|
|
2341
|
+
}
|
|
2342
|
+
]
|
|
2343
|
+
});
|
|
3257
2344
|
}
|
|
3258
|
-
|
|
3259
|
-
})
|
|
3260
|
-
|
|
3261
|
-
|
|
2345
|
+
}
|
|
2346
|
+
} else if (content.type === "tag") {
|
|
2347
|
+
const tagDoc = await getTag(content.courseID, content.tagID);
|
|
2348
|
+
for (const cardId of tagDoc.taggedCards) {
|
|
2349
|
+
if (!activeCardIds.has(cardId)) {
|
|
2350
|
+
weighted.push({
|
|
2351
|
+
cardId,
|
|
2352
|
+
courseId: content.courseID,
|
|
2353
|
+
score: 1,
|
|
2354
|
+
provenance: [
|
|
2355
|
+
{
|
|
2356
|
+
strategy: "classroom",
|
|
2357
|
+
strategyName: "Classroom",
|
|
2358
|
+
strategyId: "CLASSROOM",
|
|
2359
|
+
action: "generated",
|
|
2360
|
+
score: 1,
|
|
2361
|
+
reason: `Classroom assigned tag: ${content.tagID}, new card`
|
|
2362
|
+
}
|
|
2363
|
+
]
|
|
2364
|
+
});
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
} else if (content.type === "card") {
|
|
2368
|
+
if (!activeCardIds.has(content.cardID)) {
|
|
2369
|
+
weighted.push({
|
|
2370
|
+
cardId: content.cardID,
|
|
2371
|
+
courseId: content.courseID,
|
|
2372
|
+
score: 1,
|
|
2373
|
+
provenance: [
|
|
2374
|
+
{
|
|
2375
|
+
strategy: "classroom",
|
|
2376
|
+
strategyName: "Classroom",
|
|
2377
|
+
strategyId: "CLASSROOM",
|
|
2378
|
+
action: "generated",
|
|
2379
|
+
score: 1,
|
|
2380
|
+
reason: "Classroom assigned card, new card"
|
|
2381
|
+
}
|
|
2382
|
+
]
|
|
2383
|
+
});
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
logger.info(
|
|
2388
|
+
`[StudentClassroomDB] New cards from classroom ${this._cfg.name}: ${weighted.length} total (reviews + new)`
|
|
2389
|
+
);
|
|
2390
|
+
return weighted.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
3262
2391
|
}
|
|
3263
2392
|
};
|
|
3264
2393
|
TeacherClassroomDB = class _TeacherClassroomDB extends ClassroomDBBase {
|
|
@@ -3346,11 +2475,11 @@ var init_classroomDB2 = __esm({
|
|
|
3346
2475
|
});
|
|
3347
2476
|
|
|
3348
2477
|
// src/study/TagFilteredContentSource.ts
|
|
3349
|
-
var
|
|
2478
|
+
var import_common8, TagFilteredContentSource;
|
|
3350
2479
|
var init_TagFilteredContentSource = __esm({
|
|
3351
2480
|
"src/study/TagFilteredContentSource.ts"() {
|
|
3352
2481
|
"use strict";
|
|
3353
|
-
|
|
2482
|
+
import_common8 = require("@vue-skuilder/common");
|
|
3354
2483
|
init_courseDB();
|
|
3355
2484
|
init_logger();
|
|
3356
2485
|
TagFilteredContentSource = class {
|
|
@@ -3426,108 +2555,71 @@ var init_TagFilteredContentSource = __esm({
|
|
|
3426
2555
|
return finalCardIds;
|
|
3427
2556
|
}
|
|
3428
2557
|
/**
|
|
3429
|
-
*
|
|
2558
|
+
* Get cards with suitability scores for presentation.
|
|
2559
|
+
*
|
|
2560
|
+
* Filters cards by tag inclusion/exclusion and assigns score=1.0 to all.
|
|
2561
|
+
* TagFilteredContentSource does not currently support pluggable navigation
|
|
2562
|
+
* strategies - it returns flat-scored candidates.
|
|
2563
|
+
*
|
|
2564
|
+
* @param limit - Maximum number of cards to return
|
|
2565
|
+
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
3430
2566
|
*/
|
|
3431
|
-
async
|
|
3432
|
-
if (!(0,
|
|
3433
|
-
logger.warn("[TagFilteredContentSource]
|
|
2567
|
+
async getWeightedCards(limit) {
|
|
2568
|
+
if (!(0, import_common8.hasActiveFilter)(this.filter)) {
|
|
2569
|
+
logger.warn("[TagFilteredContentSource] getWeightedCards called with no active filter");
|
|
3434
2570
|
return [];
|
|
3435
2571
|
}
|
|
3436
2572
|
const eligibleCardIds = await this.resolveFilteredCardIds();
|
|
3437
2573
|
const activeCards = await this.user.getActiveCards();
|
|
3438
2574
|
const activeCardIds = new Set(activeCards.map((c) => c.cardID));
|
|
3439
|
-
const
|
|
2575
|
+
const newCardWeighted = [];
|
|
3440
2576
|
for (const cardId of eligibleCardIds) {
|
|
3441
2577
|
if (!activeCardIds.has(cardId)) {
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
2578
|
+
newCardWeighted.push({
|
|
2579
|
+
cardId,
|
|
2580
|
+
courseId: this.courseId,
|
|
2581
|
+
score: 1,
|
|
2582
|
+
provenance: [
|
|
2583
|
+
{
|
|
2584
|
+
strategy: "tagFilter",
|
|
2585
|
+
strategyName: "Tag Filter",
|
|
2586
|
+
strategyId: "TAG_FILTER",
|
|
2587
|
+
action: "generated",
|
|
2588
|
+
score: 1,
|
|
2589
|
+
reason: `Tag-filtered new card (tags: ${this.filter.include.join(", ")})`
|
|
2590
|
+
}
|
|
2591
|
+
]
|
|
3448
2592
|
});
|
|
3449
2593
|
}
|
|
3450
|
-
if (
|
|
2594
|
+
if (newCardWeighted.length >= limit) {
|
|
3451
2595
|
break;
|
|
3452
2596
|
}
|
|
3453
2597
|
}
|
|
3454
|
-
logger.info(
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
/**
|
|
3458
|
-
* Gets pending reviews, filtered to only include cards that match the tag filter.
|
|
3459
|
-
*/
|
|
3460
|
-
async getPendingReviews() {
|
|
3461
|
-
if (!(0, import_common10.hasActiveFilter)(this.filter)) {
|
|
3462
|
-
logger.warn("[TagFilteredContentSource] getPendingReviews called with no active filter");
|
|
3463
|
-
return [];
|
|
3464
|
-
}
|
|
3465
|
-
const eligibleCardIds = await this.resolveFilteredCardIds();
|
|
2598
|
+
logger.info(
|
|
2599
|
+
`[TagFilteredContentSource] Found ${newCardWeighted.length} new cards matching filter`
|
|
2600
|
+
);
|
|
3466
2601
|
const allReviews = await this.user.getPendingReviews(this.courseId);
|
|
3467
|
-
const filteredReviews = allReviews.filter((review) =>
|
|
3468
|
-
return eligibleCardIds.has(review.cardId);
|
|
3469
|
-
});
|
|
2602
|
+
const filteredReviews = allReviews.filter((review) => eligibleCardIds.has(review.cardId));
|
|
3470
2603
|
logger.info(
|
|
3471
2604
|
`[TagFilteredContentSource] Found ${filteredReviews.length} pending reviews matching filter (of ${allReviews.length} total)`
|
|
3472
2605
|
);
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
contentSourceType: "course",
|
|
3478
|
-
contentSourceID: this.courseId,
|
|
2606
|
+
const reviewWeighted = filteredReviews.map((r) => ({
|
|
2607
|
+
cardId: r.cardId,
|
|
2608
|
+
courseId: r.courseId,
|
|
2609
|
+
score: 1,
|
|
3479
2610
|
reviewID: r._id,
|
|
3480
|
-
|
|
2611
|
+
provenance: [
|
|
2612
|
+
{
|
|
2613
|
+
strategy: "tagFilter",
|
|
2614
|
+
strategyName: "Tag Filter",
|
|
2615
|
+
strategyId: "TAG_FILTER",
|
|
2616
|
+
action: "generated",
|
|
2617
|
+
score: 1,
|
|
2618
|
+
reason: `Tag-filtered review (tags: ${this.filter.include.join(", ")})`
|
|
2619
|
+
}
|
|
2620
|
+
]
|
|
3481
2621
|
}));
|
|
3482
|
-
|
|
3483
|
-
/**
|
|
3484
|
-
* Get cards with suitability scores for presentation.
|
|
3485
|
-
*
|
|
3486
|
-
* This implementation wraps the legacy getNewCards/getPendingReviews methods,
|
|
3487
|
-
* assigning score=1.0 to all cards. TagFilteredContentSource does not currently
|
|
3488
|
-
* support pluggable navigation strategies - it returns flat-scored candidates.
|
|
3489
|
-
*
|
|
3490
|
-
* @param limit - Maximum number of cards to return
|
|
3491
|
-
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
3492
|
-
*/
|
|
3493
|
-
async getWeightedCards(limit) {
|
|
3494
|
-
const [newCards, reviews] = await Promise.all([
|
|
3495
|
-
this.getNewCards(limit),
|
|
3496
|
-
this.getPendingReviews()
|
|
3497
|
-
]);
|
|
3498
|
-
const weighted = [
|
|
3499
|
-
...reviews.map((r) => ({
|
|
3500
|
-
cardId: r.cardID,
|
|
3501
|
-
courseId: r.courseID,
|
|
3502
|
-
score: 1,
|
|
3503
|
-
provenance: [
|
|
3504
|
-
{
|
|
3505
|
-
strategy: "tagFilter",
|
|
3506
|
-
strategyName: "Tag Filter",
|
|
3507
|
-
strategyId: "TAG_FILTER",
|
|
3508
|
-
action: "generated",
|
|
3509
|
-
score: 1,
|
|
3510
|
-
reason: `Tag-filtered review (tags: ${this.filter.include.join(", ")})`
|
|
3511
|
-
}
|
|
3512
|
-
]
|
|
3513
|
-
})),
|
|
3514
|
-
...newCards.map((c) => ({
|
|
3515
|
-
cardId: c.cardID,
|
|
3516
|
-
courseId: c.courseID,
|
|
3517
|
-
score: 1,
|
|
3518
|
-
provenance: [
|
|
3519
|
-
{
|
|
3520
|
-
strategy: "tagFilter",
|
|
3521
|
-
strategyName: "Tag Filter",
|
|
3522
|
-
strategyId: "TAG_FILTER",
|
|
3523
|
-
action: "generated",
|
|
3524
|
-
score: 1,
|
|
3525
|
-
reason: `Tag-filtered new card (tags: ${this.filter.include.join(", ")})`
|
|
3526
|
-
}
|
|
3527
|
-
]
|
|
3528
|
-
}))
|
|
3529
|
-
];
|
|
3530
|
-
return weighted.slice(0, limit);
|
|
2622
|
+
return [...reviewWeighted, ...newCardWeighted].slice(0, limit);
|
|
3531
2623
|
}
|
|
3532
2624
|
/**
|
|
3533
2625
|
* Clears the cached resolved card IDs.
|
|
@@ -3561,19 +2653,19 @@ async function getStudySource(source, user) {
|
|
|
3561
2653
|
if (source.type === "classroom") {
|
|
3562
2654
|
return await StudentClassroomDB.factory(source.id, user);
|
|
3563
2655
|
} else {
|
|
3564
|
-
if ((0,
|
|
2656
|
+
if ((0, import_common9.hasActiveFilter)(source.tagFilter)) {
|
|
3565
2657
|
return new TagFilteredContentSource(source.id, source.tagFilter, user);
|
|
3566
2658
|
}
|
|
3567
2659
|
return getDataLayer().getCourseDB(source.id);
|
|
3568
2660
|
}
|
|
3569
2661
|
}
|
|
3570
|
-
var
|
|
2662
|
+
var import_common9;
|
|
3571
2663
|
var init_contentSource = __esm({
|
|
3572
2664
|
"src/core/interfaces/contentSource.ts"() {
|
|
3573
2665
|
"use strict";
|
|
3574
2666
|
init_factory();
|
|
3575
2667
|
init_classroomDB2();
|
|
3576
|
-
|
|
2668
|
+
import_common9 = require("@vue-skuilder/common");
|
|
3577
2669
|
init_TagFilteredContentSource();
|
|
3578
2670
|
}
|
|
3579
2671
|
});
|
|
@@ -3619,6 +2711,16 @@ var init_user = __esm({
|
|
|
3619
2711
|
}
|
|
3620
2712
|
});
|
|
3621
2713
|
|
|
2714
|
+
// src/core/types/strategyState.ts
|
|
2715
|
+
function buildStrategyStateId(courseId, strategyKey) {
|
|
2716
|
+
return `STRATEGY_STATE::${courseId}::${strategyKey}`;
|
|
2717
|
+
}
|
|
2718
|
+
var init_strategyState = __esm({
|
|
2719
|
+
"src/core/types/strategyState.ts"() {
|
|
2720
|
+
"use strict";
|
|
2721
|
+
}
|
|
2722
|
+
});
|
|
2723
|
+
|
|
3622
2724
|
// src/core/util/index.ts
|
|
3623
2725
|
function getCardHistoryID(courseID, cardID) {
|
|
3624
2726
|
return `${DocTypePrefixes["CARDRECORD" /* CARDRECORD */]}-${courseID}-${cardID}`;
|
|
@@ -3631,17 +2733,17 @@ var init_util = __esm({
|
|
|
3631
2733
|
});
|
|
3632
2734
|
|
|
3633
2735
|
// src/core/bulkImport/cardProcessor.ts
|
|
3634
|
-
var
|
|
2736
|
+
var import_common10;
|
|
3635
2737
|
var init_cardProcessor = __esm({
|
|
3636
2738
|
"src/core/bulkImport/cardProcessor.ts"() {
|
|
3637
2739
|
"use strict";
|
|
3638
|
-
|
|
2740
|
+
import_common10 = require("@vue-skuilder/common");
|
|
3639
2741
|
init_logger();
|
|
3640
2742
|
}
|
|
3641
2743
|
});
|
|
3642
2744
|
|
|
3643
2745
|
// src/core/bulkImport/types.ts
|
|
3644
|
-
var
|
|
2746
|
+
var init_types = __esm({
|
|
3645
2747
|
"src/core/bulkImport/types.ts"() {
|
|
3646
2748
|
"use strict";
|
|
3647
2749
|
}
|
|
@@ -3652,7 +2754,7 @@ var init_bulkImport = __esm({
|
|
|
3652
2754
|
"src/core/bulkImport/index.ts"() {
|
|
3653
2755
|
"use strict";
|
|
3654
2756
|
init_cardProcessor();
|
|
3655
|
-
|
|
2757
|
+
init_types();
|
|
3656
2758
|
}
|
|
3657
2759
|
});
|
|
3658
2760
|
|
|
@@ -3663,6 +2765,7 @@ var init_core = __esm({
|
|
|
3663
2765
|
init_interfaces();
|
|
3664
2766
|
init_types_legacy();
|
|
3665
2767
|
init_user();
|
|
2768
|
+
init_strategyState();
|
|
3666
2769
|
init_Loggable();
|
|
3667
2770
|
init_util();
|
|
3668
2771
|
init_navigators();
|
|
@@ -3670,14 +2773,6 @@ var init_core = __esm({
|
|
|
3670
2773
|
}
|
|
3671
2774
|
});
|
|
3672
2775
|
|
|
3673
|
-
// src/util/tuiLogger.ts
|
|
3674
|
-
var init_tuiLogger = __esm({
|
|
3675
|
-
"src/util/tuiLogger.ts"() {
|
|
3676
|
-
"use strict";
|
|
3677
|
-
init_dataDirectory();
|
|
3678
|
-
}
|
|
3679
|
-
});
|
|
3680
|
-
|
|
3681
2776
|
// src/util/dataDirectory.ts
|
|
3682
2777
|
function getAppDataDirectory() {
|
|
3683
2778
|
if (ENV.LOCAL_STORAGE_PREFIX) {
|
|
@@ -3695,7 +2790,7 @@ var init_dataDirectory = __esm({
|
|
|
3695
2790
|
"use strict";
|
|
3696
2791
|
path = __toESM(require("path"), 1);
|
|
3697
2792
|
os = __toESM(require("os"), 1);
|
|
3698
|
-
|
|
2793
|
+
init_logger();
|
|
3699
2794
|
init_factory();
|
|
3700
2795
|
}
|
|
3701
2796
|
});
|
|
@@ -3850,7 +2945,9 @@ var init_user_course_relDB = __esm({
|
|
|
3850
2945
|
function accomodateGuest() {
|
|
3851
2946
|
logger.log("[funnel] accomodateGuest() called");
|
|
3852
2947
|
if (typeof localStorage === "undefined") {
|
|
3853
|
-
logger.log(
|
|
2948
|
+
logger.log(
|
|
2949
|
+
"[funnel] localStorage not available (Node.js environment), returning default guest"
|
|
2950
|
+
);
|
|
3854
2951
|
return {
|
|
3855
2952
|
username: GuestUsername + "nodejs-test",
|
|
3856
2953
|
firstVisit: true
|
|
@@ -4018,13 +3115,13 @@ async function dropUserFromClassroom(user, classID) {
|
|
|
4018
3115
|
async function getUserClassrooms(user) {
|
|
4019
3116
|
return getOrCreateClassroomRegistrationsDoc(user);
|
|
4020
3117
|
}
|
|
4021
|
-
var
|
|
3118
|
+
var import_common11, import_moment5, log3, BaseUser, userCoursesDoc, userClassroomsDoc;
|
|
4022
3119
|
var init_BaseUserDB = __esm({
|
|
4023
3120
|
"src/impl/common/BaseUserDB.ts"() {
|
|
4024
3121
|
"use strict";
|
|
4025
3122
|
init_core();
|
|
4026
3123
|
init_util();
|
|
4027
|
-
|
|
3124
|
+
import_common11 = require("@vue-skuilder/common");
|
|
4028
3125
|
import_moment5 = __toESM(require("moment"), 1);
|
|
4029
3126
|
init_types_legacy();
|
|
4030
3127
|
init_logger();
|
|
@@ -4074,7 +3171,7 @@ Currently logged-in as ${this._username}.`
|
|
|
4074
3171
|
);
|
|
4075
3172
|
}
|
|
4076
3173
|
const result = await this.syncStrategy.createAccount(username, password);
|
|
4077
|
-
if (result.status ===
|
|
3174
|
+
if (result.status === import_common11.Status.ok) {
|
|
4078
3175
|
log3(`Account created successfully, updating username to ${username}`);
|
|
4079
3176
|
this._username = username;
|
|
4080
3177
|
try {
|
|
@@ -4116,7 +3213,7 @@ Currently logged-in as ${this._username}.`
|
|
|
4116
3213
|
async resetUserData() {
|
|
4117
3214
|
if (this.syncStrategy.canAuthenticate()) {
|
|
4118
3215
|
return {
|
|
4119
|
-
status:
|
|
3216
|
+
status: import_common11.Status.error,
|
|
4120
3217
|
error: "Reset user data is only available for local-only mode. Use logout instead for remote sync."
|
|
4121
3218
|
};
|
|
4122
3219
|
}
|
|
@@ -4135,11 +3232,11 @@ Currently logged-in as ${this._username}.`
|
|
|
4135
3232
|
await localDB.bulkDocs(docsToDelete);
|
|
4136
3233
|
}
|
|
4137
3234
|
await this.init();
|
|
4138
|
-
return { status:
|
|
3235
|
+
return { status: import_common11.Status.ok };
|
|
4139
3236
|
} catch (error) {
|
|
4140
3237
|
logger.error("Failed to reset user data:", error);
|
|
4141
3238
|
return {
|
|
4142
|
-
status:
|
|
3239
|
+
status: import_common11.Status.error,
|
|
4143
3240
|
error: error instanceof Error ? error.message : "Unknown error during reset"
|
|
4144
3241
|
};
|
|
4145
3242
|
}
|
|
@@ -4830,6 +3927,55 @@ Currently logged-in as ${this._username}.`
|
|
|
4830
3927
|
async updateUserElo(courseId, elo) {
|
|
4831
3928
|
return updateUserElo(this._username, courseId, elo);
|
|
4832
3929
|
}
|
|
3930
|
+
async getStrategyState(courseId, strategyKey) {
|
|
3931
|
+
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
3932
|
+
try {
|
|
3933
|
+
const doc = await this.localDB.get(docId);
|
|
3934
|
+
return doc.data;
|
|
3935
|
+
} catch (e) {
|
|
3936
|
+
const err = e;
|
|
3937
|
+
if (err.status === 404) {
|
|
3938
|
+
return null;
|
|
3939
|
+
}
|
|
3940
|
+
throw e;
|
|
3941
|
+
}
|
|
3942
|
+
}
|
|
3943
|
+
async putStrategyState(courseId, strategyKey, data) {
|
|
3944
|
+
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
3945
|
+
let existingRev;
|
|
3946
|
+
try {
|
|
3947
|
+
const existing = await this.localDB.get(docId);
|
|
3948
|
+
existingRev = existing._rev;
|
|
3949
|
+
} catch (e) {
|
|
3950
|
+
const err = e;
|
|
3951
|
+
if (err.status !== 404) {
|
|
3952
|
+
throw e;
|
|
3953
|
+
}
|
|
3954
|
+
}
|
|
3955
|
+
const doc = {
|
|
3956
|
+
_id: docId,
|
|
3957
|
+
_rev: existingRev,
|
|
3958
|
+
docType: "STRATEGY_STATE" /* STRATEGY_STATE */,
|
|
3959
|
+
courseId,
|
|
3960
|
+
strategyKey,
|
|
3961
|
+
data,
|
|
3962
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3963
|
+
};
|
|
3964
|
+
await this.localDB.put(doc);
|
|
3965
|
+
}
|
|
3966
|
+
async deleteStrategyState(courseId, strategyKey) {
|
|
3967
|
+
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
3968
|
+
try {
|
|
3969
|
+
const doc = await this.localDB.get(docId);
|
|
3970
|
+
await this.localDB.remove(doc);
|
|
3971
|
+
} catch (e) {
|
|
3972
|
+
const err = e;
|
|
3973
|
+
if (err.status === 404) {
|
|
3974
|
+
return;
|
|
3975
|
+
}
|
|
3976
|
+
throw e;
|
|
3977
|
+
}
|
|
3978
|
+
}
|
|
4833
3979
|
};
|
|
4834
3980
|
userCoursesDoc = "CourseRegistrations";
|
|
4835
3981
|
userClassroomsDoc = "ClassroomRegistrations";
|
|
@@ -4930,8 +4076,7 @@ var init_adminDB2 = __esm({
|
|
|
4930
4076
|
}
|
|
4931
4077
|
}
|
|
4932
4078
|
}
|
|
4933
|
-
|
|
4934
|
-
return dbs.map((db) => {
|
|
4079
|
+
return promisedCRDbs.map((db) => {
|
|
4935
4080
|
return {
|
|
4936
4081
|
...db.getConfig(),
|
|
4937
4082
|
_id: db._id
|
|
@@ -4985,14 +4130,14 @@ var init_auth = __esm({
|
|
|
4985
4130
|
});
|
|
4986
4131
|
|
|
4987
4132
|
// src/impl/couch/CouchDBSyncStrategy.ts
|
|
4988
|
-
var
|
|
4133
|
+
var import_common13, log4, CouchDBSyncStrategy;
|
|
4989
4134
|
var init_CouchDBSyncStrategy = __esm({
|
|
4990
4135
|
"src/impl/couch/CouchDBSyncStrategy.ts"() {
|
|
4991
4136
|
"use strict";
|
|
4992
4137
|
init_factory();
|
|
4993
4138
|
init_types_legacy();
|
|
4994
4139
|
init_logger();
|
|
4995
|
-
|
|
4140
|
+
import_common13 = require("@vue-skuilder/common");
|
|
4996
4141
|
init_common();
|
|
4997
4142
|
init_pouchdb_setup();
|
|
4998
4143
|
init_couch();
|
|
@@ -5063,32 +4208,32 @@ var init_CouchDBSyncStrategy = __esm({
|
|
|
5063
4208
|
}
|
|
5064
4209
|
}
|
|
5065
4210
|
return {
|
|
5066
|
-
status:
|
|
4211
|
+
status: import_common13.Status.ok,
|
|
5067
4212
|
error: void 0
|
|
5068
4213
|
};
|
|
5069
4214
|
} else {
|
|
5070
4215
|
return {
|
|
5071
|
-
status:
|
|
4216
|
+
status: import_common13.Status.error,
|
|
5072
4217
|
error: "Failed to log in after account creation"
|
|
5073
4218
|
};
|
|
5074
4219
|
}
|
|
5075
4220
|
} else {
|
|
5076
4221
|
logger.warn(`Signup not OK: ${JSON.stringify(signupRequest)}`);
|
|
5077
4222
|
return {
|
|
5078
|
-
status:
|
|
4223
|
+
status: import_common13.Status.error,
|
|
5079
4224
|
error: "Account creation failed"
|
|
5080
4225
|
};
|
|
5081
4226
|
}
|
|
5082
4227
|
} catch (e) {
|
|
5083
4228
|
if (e.reason === "Document update conflict.") {
|
|
5084
4229
|
return {
|
|
5085
|
-
status:
|
|
4230
|
+
status: import_common13.Status.error,
|
|
5086
4231
|
error: "This username is taken!"
|
|
5087
4232
|
};
|
|
5088
4233
|
}
|
|
5089
4234
|
logger.error(`Error on signup: ${JSON.stringify(e)}`);
|
|
5090
4235
|
return {
|
|
5091
|
-
status:
|
|
4236
|
+
status: import_common13.Status.error,
|
|
5092
4237
|
error: e.message || "Unknown error during account creation"
|
|
5093
4238
|
};
|
|
5094
4239
|
}
|