@vue-skuilder/db 0.1.22 → 0.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{contentSource-BP9hznNV.d.ts → contentSource-BotbOOfX.d.ts} +227 -3
- package/dist/{contentSource-DsJadoBU.d.cts → contentSource-C90LH-OH.d.cts} +227 -3
- package/dist/core/index.d.cts +220 -6
- package/dist/core/index.d.ts +220 -6
- package/dist/core/index.js +2052 -559
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +2035 -555
- package/dist/core/index.mjs.map +1 -1
- package/dist/{dataLayerProvider-CHYrQ5pB.d.cts → dataLayerProvider-DGKp4zFB.d.cts} +1 -1
- package/dist/{dataLayerProvider-MDTxXq2l.d.ts → dataLayerProvider-SBpz9jQf.d.ts} +1 -1
- package/dist/impl/couch/index.d.cts +11 -3
- package/dist/impl/couch/index.d.ts +11 -3
- package/dist/impl/couch/index.js +1811 -574
- package/dist/impl/couch/index.js.map +1 -1
- package/dist/impl/couch/index.mjs +1792 -550
- package/dist/impl/couch/index.mjs.map +1 -1
- package/dist/impl/static/index.d.cts +4 -4
- package/dist/impl/static/index.d.ts +4 -4
- package/dist/impl/static/index.js +1797 -560
- package/dist/impl/static/index.js.map +1 -1
- package/dist/impl/static/index.mjs +1789 -547
- package/dist/impl/static/index.mjs.map +1 -1
- package/dist/{index-Dj0SEgk3.d.ts → index-BWvO-_rJ.d.ts} +1 -1
- package/dist/{index-B_j6u5E4.d.cts → index-Ba7hYbHj.d.cts} +1 -1
- package/dist/index.d.cts +150 -12
- package/dist/index.d.ts +150 -12
- package/dist/index.js +2658 -791
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2584 -747
- package/dist/index.mjs.map +1 -1
- package/dist/{types-DQaXnuoc.d.ts → types-CJrLM1Ew.d.ts} +1 -1
- package/dist/{types-Bn0itutr.d.cts → types-W8n-B6HG.d.cts} +1 -1
- package/dist/{types-legacy-DDY4N-Uq.d.cts → types-legacy-JXDxinpU.d.cts} +5 -1
- package/dist/{types-legacy-DDY4N-Uq.d.ts → types-legacy-JXDxinpU.d.ts} +5 -1
- package/dist/util/packer/index.d.cts +3 -3
- package/dist/util/packer/index.d.ts +3 -3
- package/docs/brainstorm-navigation-paradigm.md +40 -34
- package/docs/future-orchestration-vision.md +216 -0
- package/docs/navigators-architecture.md +188 -5
- package/docs/todo-strategy-authoring.md +8 -6
- package/package.json +3 -3
- package/src/core/index.ts +2 -0
- package/src/core/interfaces/contentSource.ts +7 -0
- package/src/core/interfaces/userDB.ts +6 -0
- package/src/core/navigators/Pipeline.ts +46 -0
- package/src/core/navigators/PipelineAssembler.ts +14 -1
- package/src/core/navigators/filters/WeightedFilter.ts +141 -0
- package/src/core/navigators/filters/types.ts +4 -0
- package/src/core/navigators/generators/CompositeGenerator.ts +61 -19
- package/src/core/navigators/generators/types.ts +4 -0
- package/src/core/navigators/index.ts +194 -13
- package/src/core/orchestration/gradient.ts +133 -0
- package/src/core/orchestration/index.ts +210 -0
- package/src/core/orchestration/learning.ts +250 -0
- package/src/core/orchestration/recording.ts +92 -0
- package/src/core/orchestration/signal.ts +67 -0
- package/src/core/types/contentNavigationStrategy.ts +38 -0
- package/src/core/types/learningState.ts +77 -0
- package/src/core/types/types-legacy.ts +4 -0
- package/src/core/types/userOutcome.ts +51 -0
- package/src/courseConfigRegistration.ts +546 -0
- package/src/factory.ts +6 -0
- package/src/impl/common/BaseUserDB.ts +16 -0
- package/src/index.ts +2 -0
- package/src/study/SessionController.ts +64 -1
- package/tests/core/navigators/Pipeline.test.ts +2 -0
- package/docs/todo-evolutionary-orchestration.md +0 -310
package/dist/core/index.js
CHANGED
|
@@ -5,6 +5,11 @@ 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
|
+
};
|
|
8
13
|
var __esm = (fn, res) => function __init() {
|
|
9
14
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
15
|
};
|
|
@@ -118,6 +123,8 @@ var init_types_legacy = __esm({
|
|
|
118
123
|
DocType2["TAG"] = "TAG";
|
|
119
124
|
DocType2["NAVIGATION_STRATEGY"] = "NAVIGATION_STRATEGY";
|
|
120
125
|
DocType2["STRATEGY_STATE"] = "STRATEGY_STATE";
|
|
126
|
+
DocType2["USER_OUTCOME"] = "USER_OUTCOME";
|
|
127
|
+
DocType2["STRATEGY_LEARNING_STATE"] = "STRATEGY_LEARNING_STATE";
|
|
121
128
|
return DocType2;
|
|
122
129
|
})(DocType || {});
|
|
123
130
|
DocTypePrefixes = {
|
|
@@ -132,7 +139,9 @@ var init_types_legacy = __esm({
|
|
|
132
139
|
["VIEW" /* VIEW */]: "VIEW",
|
|
133
140
|
["PEDAGOGY" /* PEDAGOGY */]: "PEDAGOGY",
|
|
134
141
|
["NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */]: "NAVIGATION_STRATEGY",
|
|
135
|
-
["STRATEGY_STATE" /* STRATEGY_STATE */]: "STRATEGY_STATE"
|
|
142
|
+
["STRATEGY_STATE" /* STRATEGY_STATE */]: "STRATEGY_STATE",
|
|
143
|
+
["USER_OUTCOME" /* USER_OUTCOME */]: "USER_OUTCOME",
|
|
144
|
+
["STRATEGY_LEARNING_STATE" /* STRATEGY_LEARNING_STATE */]: "STRATEGY_LEARNING_STATE"
|
|
136
145
|
};
|
|
137
146
|
}
|
|
138
147
|
});
|
|
@@ -701,187 +710,1614 @@ var init_courseLookupDB = __esm({
|
|
|
701
710
|
}
|
|
702
711
|
});
|
|
703
712
|
|
|
704
|
-
// src/core/navigators/
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
}
|
|
714
|
-
if (reason.includes("review")) {
|
|
715
|
-
return "review";
|
|
716
|
-
}
|
|
717
|
-
return "new";
|
|
718
|
-
}
|
|
719
|
-
function isGenerator(impl) {
|
|
720
|
-
return NavigatorRoles[impl] === "generator" /* GENERATOR */;
|
|
721
|
-
}
|
|
722
|
-
function isFilter(impl) {
|
|
723
|
-
return NavigatorRoles[impl] === "filter" /* FILTER */;
|
|
724
|
-
}
|
|
725
|
-
var Navigators, NavigatorRole, NavigatorRoles, ContentNavigator;
|
|
726
|
-
var init_navigators = __esm({
|
|
727
|
-
"src/core/navigators/index.ts"() {
|
|
713
|
+
// src/core/navigators/generators/CompositeGenerator.ts
|
|
714
|
+
var CompositeGenerator_exports = {};
|
|
715
|
+
__export(CompositeGenerator_exports, {
|
|
716
|
+
AggregationMode: () => AggregationMode,
|
|
717
|
+
default: () => CompositeGenerator
|
|
718
|
+
});
|
|
719
|
+
var AggregationMode, DEFAULT_AGGREGATION_MODE, FREQUENCY_BOOST_FACTOR, CompositeGenerator;
|
|
720
|
+
var init_CompositeGenerator = __esm({
|
|
721
|
+
"src/core/navigators/generators/CompositeGenerator.ts"() {
|
|
728
722
|
"use strict";
|
|
723
|
+
init_navigators();
|
|
729
724
|
init_logger();
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
["relativePriority" /* RELATIVE_PRIORITY */]: "filter" /* FILTER */,
|
|
750
|
-
["userTagPreference" /* USER_TAG_PREFERENCE */]: "filter" /* FILTER */
|
|
751
|
-
};
|
|
752
|
-
ContentNavigator = class {
|
|
753
|
-
/** User interface for this navigation session */
|
|
754
|
-
user;
|
|
755
|
-
/** Course interface for this navigation session */
|
|
756
|
-
course;
|
|
757
|
-
/** Human-readable name for this strategy instance (from ContentNavigationStrategyData.name) */
|
|
758
|
-
strategyName;
|
|
759
|
-
/** Unique document ID for this strategy instance (from ContentNavigationStrategyData._id) */
|
|
760
|
-
strategyId;
|
|
761
|
-
/**
|
|
762
|
-
* Constructor for standard navigators.
|
|
763
|
-
* Call this from subclass constructors to initialize common fields.
|
|
764
|
-
*
|
|
765
|
-
* Note: CompositeGenerator and Pipeline call super() without args, then set
|
|
766
|
-
* user/course fields directly if needed.
|
|
767
|
-
*/
|
|
768
|
-
constructor(user, course, strategyData) {
|
|
769
|
-
this.user = user;
|
|
770
|
-
this.course = course;
|
|
771
|
-
if (strategyData) {
|
|
772
|
-
this.strategyName = strategyData.name;
|
|
773
|
-
this.strategyId = strategyData._id;
|
|
725
|
+
AggregationMode = /* @__PURE__ */ ((AggregationMode2) => {
|
|
726
|
+
AggregationMode2["MAX"] = "max";
|
|
727
|
+
AggregationMode2["AVERAGE"] = "average";
|
|
728
|
+
AggregationMode2["FREQUENCY_BOOST"] = "frequencyBoost";
|
|
729
|
+
return AggregationMode2;
|
|
730
|
+
})(AggregationMode || {});
|
|
731
|
+
DEFAULT_AGGREGATION_MODE = "frequencyBoost" /* FREQUENCY_BOOST */;
|
|
732
|
+
FREQUENCY_BOOST_FACTOR = 0.1;
|
|
733
|
+
CompositeGenerator = class _CompositeGenerator extends ContentNavigator {
|
|
734
|
+
/** Human-readable name for CardGenerator interface */
|
|
735
|
+
name = "Composite Generator";
|
|
736
|
+
generators;
|
|
737
|
+
aggregationMode;
|
|
738
|
+
constructor(generators, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
739
|
+
super();
|
|
740
|
+
this.generators = generators;
|
|
741
|
+
this.aggregationMode = aggregationMode;
|
|
742
|
+
if (generators.length === 0) {
|
|
743
|
+
throw new Error("CompositeGenerator requires at least one generator");
|
|
774
744
|
}
|
|
745
|
+
logger.debug(
|
|
746
|
+
`[CompositeGenerator] Created with ${generators.length} generators, mode: ${aggregationMode}`
|
|
747
|
+
);
|
|
775
748
|
}
|
|
776
|
-
// ============================================================================
|
|
777
|
-
// STRATEGY STATE HELPERS
|
|
778
|
-
// ============================================================================
|
|
779
|
-
//
|
|
780
|
-
// These methods allow strategies to persist their own state (user preferences,
|
|
781
|
-
// learned patterns, temporal tracking) in the user database.
|
|
782
|
-
//
|
|
783
|
-
// ============================================================================
|
|
784
749
|
/**
|
|
785
|
-
*
|
|
750
|
+
* Creates a CompositeGenerator from strategy data.
|
|
786
751
|
*
|
|
787
|
-
*
|
|
788
|
-
* Override in subclasses if multiple instances of the same strategy type
|
|
789
|
-
* need separate state storage.
|
|
752
|
+
* This is a convenience factory for use by PipelineAssembler.
|
|
790
753
|
*/
|
|
791
|
-
|
|
792
|
-
|
|
754
|
+
static async fromStrategies(user, course, strategies, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
755
|
+
const generators = await Promise.all(
|
|
756
|
+
strategies.map((s) => ContentNavigator.create(user, course, s))
|
|
757
|
+
);
|
|
758
|
+
return new _CompositeGenerator(generators, aggregationMode);
|
|
793
759
|
}
|
|
794
760
|
/**
|
|
795
|
-
* Get
|
|
761
|
+
* Get weighted cards from all generators, merge and deduplicate.
|
|
796
762
|
*
|
|
797
|
-
*
|
|
798
|
-
*
|
|
763
|
+
* Cards appearing in multiple generators receive a score boost.
|
|
764
|
+
* Provenance tracks which generators produced each card and how scores were aggregated.
|
|
765
|
+
*
|
|
766
|
+
* This method supports both the legacy signature (limit only) and the
|
|
767
|
+
* CardGenerator interface signature (limit, context).
|
|
768
|
+
*
|
|
769
|
+
* @param limit - Maximum number of cards to return
|
|
770
|
+
* @param context - GeneratorContext passed to child generators (required when called via Pipeline)
|
|
799
771
|
*/
|
|
800
|
-
async
|
|
801
|
-
if (!
|
|
772
|
+
async getWeightedCards(limit, context) {
|
|
773
|
+
if (!context) {
|
|
802
774
|
throw new Error(
|
|
803
|
-
|
|
775
|
+
"CompositeGenerator.getWeightedCards requires a GeneratorContext. It should be called via Pipeline, not directly."
|
|
804
776
|
);
|
|
805
777
|
}
|
|
806
|
-
|
|
778
|
+
const results = await Promise.all(
|
|
779
|
+
this.generators.map((g) => g.getWeightedCards(limit, context))
|
|
780
|
+
);
|
|
781
|
+
const byCardId = /* @__PURE__ */ new Map();
|
|
782
|
+
results.forEach((cards, index) => {
|
|
783
|
+
const gen = this.generators[index];
|
|
784
|
+
let weight = gen.learnable?.weight ?? 1;
|
|
785
|
+
let deviation;
|
|
786
|
+
if (gen.learnable && !gen.staticWeight && context.orchestration) {
|
|
787
|
+
const strategyId = gen.strategyId;
|
|
788
|
+
if (strategyId) {
|
|
789
|
+
weight = context.orchestration.getEffectiveWeight(strategyId, gen.learnable);
|
|
790
|
+
deviation = context.orchestration.getDeviation(strategyId);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
for (const card of cards) {
|
|
794
|
+
if (card.provenance.length > 0) {
|
|
795
|
+
card.provenance[0].effectiveWeight = weight;
|
|
796
|
+
card.provenance[0].deviation = deviation;
|
|
797
|
+
}
|
|
798
|
+
const existing = byCardId.get(card.cardId) || [];
|
|
799
|
+
existing.push({ card, weight });
|
|
800
|
+
byCardId.set(card.cardId, existing);
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
const merged = [];
|
|
804
|
+
for (const [, items] of byCardId) {
|
|
805
|
+
const cards = items.map((i) => i.card);
|
|
806
|
+
const aggregatedScore = this.aggregateScores(items);
|
|
807
|
+
const finalScore = Math.min(1, aggregatedScore);
|
|
808
|
+
const mergedProvenance = cards.flatMap((c) => c.provenance);
|
|
809
|
+
const initialScore = cards[0].score;
|
|
810
|
+
const action = finalScore > initialScore ? "boosted" : finalScore < initialScore ? "penalized" : "passed";
|
|
811
|
+
const reason = this.buildAggregationReason(items, finalScore);
|
|
812
|
+
merged.push({
|
|
813
|
+
...cards[0],
|
|
814
|
+
score: finalScore,
|
|
815
|
+
provenance: [
|
|
816
|
+
...mergedProvenance,
|
|
817
|
+
{
|
|
818
|
+
strategy: "composite",
|
|
819
|
+
strategyName: "Composite Generator",
|
|
820
|
+
strategyId: "COMPOSITE_GENERATOR",
|
|
821
|
+
action,
|
|
822
|
+
score: finalScore,
|
|
823
|
+
reason
|
|
824
|
+
}
|
|
825
|
+
]
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
return merged.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
807
829
|
}
|
|
808
830
|
/**
|
|
809
|
-
*
|
|
810
|
-
*
|
|
811
|
-
* @param data - The strategy's data payload to store
|
|
812
|
-
* @throws Error if user or course is not initialized
|
|
831
|
+
* Build human-readable reason for score aggregation.
|
|
813
832
|
*/
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
833
|
+
buildAggregationReason(items, finalScore) {
|
|
834
|
+
const cards = items.map((i) => i.card);
|
|
835
|
+
const count = cards.length;
|
|
836
|
+
const scores = cards.map((c) => c.score.toFixed(2)).join(", ");
|
|
837
|
+
if (count === 1) {
|
|
838
|
+
const weightMsg = Math.abs(items[0].weight - 1) > 1e-3 ? ` (w=${items[0].weight.toFixed(2)})` : "";
|
|
839
|
+
return `Single generator, score ${finalScore.toFixed(2)}${weightMsg}`;
|
|
840
|
+
}
|
|
841
|
+
const strategies = cards.map((c) => c.provenance[0]?.strategy || "unknown").join(", ");
|
|
842
|
+
switch (this.aggregationMode) {
|
|
843
|
+
case "max" /* MAX */:
|
|
844
|
+
return `Max of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
845
|
+
case "average" /* AVERAGE */:
|
|
846
|
+
return `Weighted Avg of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
847
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
848
|
+
const totalWeight = items.reduce((sum, i) => sum + i.weight, 0);
|
|
849
|
+
const weightedSum = items.reduce((sum, i) => sum + i.card.score * i.weight, 0);
|
|
850
|
+
const avg = totalWeight > 0 ? weightedSum / totalWeight : 0;
|
|
851
|
+
const boost = 1 + FREQUENCY_BOOST_FACTOR * (count - 1);
|
|
852
|
+
return `Frequency boost from ${count} generators (${strategies}): w-avg ${avg.toFixed(2)} \xD7 ${boost.toFixed(2)} \u2192 ${finalScore.toFixed(2)}`;
|
|
853
|
+
}
|
|
854
|
+
default:
|
|
855
|
+
return `Aggregated from ${count} generators: ${finalScore.toFixed(2)}`;
|
|
819
856
|
}
|
|
820
|
-
return this.user.putStrategyState(this.course.getCourseID(), this.strategyKey, data);
|
|
821
857
|
}
|
|
822
858
|
/**
|
|
823
|
-
*
|
|
824
|
-
*
|
|
825
|
-
* @param user - User interface
|
|
826
|
-
* @param course - Course interface
|
|
827
|
-
* @param strategyData - Strategy configuration document
|
|
828
|
-
* @returns the runtime object used to steer a study session.
|
|
859
|
+
* Aggregate scores from multiple generators for the same card.
|
|
829
860
|
*/
|
|
830
|
-
|
|
831
|
-
const
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
NavigatorImpl = module2.default;
|
|
841
|
-
break;
|
|
842
|
-
} catch (e) {
|
|
843
|
-
logger.debug(`Failed to load extension from ${loadFrom}:`, e);
|
|
844
|
-
}
|
|
861
|
+
aggregateScores(items) {
|
|
862
|
+
const scores = items.map((i) => i.card.score);
|
|
863
|
+
switch (this.aggregationMode) {
|
|
864
|
+
case "max" /* MAX */:
|
|
865
|
+
return Math.max(...scores);
|
|
866
|
+
case "average" /* AVERAGE */: {
|
|
867
|
+
const totalWeight = items.reduce((sum, i) => sum + i.weight, 0);
|
|
868
|
+
if (totalWeight === 0) return 0;
|
|
869
|
+
const weightedSum = items.reduce((sum, i) => sum + i.card.score * i.weight, 0);
|
|
870
|
+
return weightedSum / totalWeight;
|
|
845
871
|
}
|
|
872
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
873
|
+
const totalWeight = items.reduce((sum, i) => sum + i.weight, 0);
|
|
874
|
+
const weightedSum = items.reduce((sum, i) => sum + i.card.score * i.weight, 0);
|
|
875
|
+
const avg = totalWeight > 0 ? weightedSum / totalWeight : 0;
|
|
876
|
+
const frequencyBoost = 1 + FREQUENCY_BOOST_FACTOR * (items.length - 1);
|
|
877
|
+
return avg * frequencyBoost;
|
|
878
|
+
}
|
|
879
|
+
default:
|
|
880
|
+
return scores[0];
|
|
846
881
|
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
});
|
|
886
|
+
|
|
887
|
+
// src/core/navigators/generators/elo.ts
|
|
888
|
+
var elo_exports = {};
|
|
889
|
+
__export(elo_exports, {
|
|
890
|
+
default: () => ELONavigator
|
|
891
|
+
});
|
|
892
|
+
var import_common5, ELONavigator;
|
|
893
|
+
var init_elo = __esm({
|
|
894
|
+
"src/core/navigators/generators/elo.ts"() {
|
|
895
|
+
"use strict";
|
|
896
|
+
init_navigators();
|
|
897
|
+
import_common5 = require("@vue-skuilder/common");
|
|
898
|
+
ELONavigator = class extends ContentNavigator {
|
|
899
|
+
/** Human-readable name for CardGenerator interface */
|
|
900
|
+
name;
|
|
901
|
+
constructor(user, course, strategyData) {
|
|
902
|
+
super(user, course, strategyData);
|
|
903
|
+
this.name = strategyData?.name || "ELO";
|
|
851
904
|
}
|
|
852
905
|
/**
|
|
853
|
-
* Get cards with suitability scores
|
|
854
|
-
*
|
|
855
|
-
* **This is the PRIMARY API for navigation strategies.**
|
|
856
|
-
*
|
|
857
|
-
* Returns cards ranked by suitability score (0-1). Higher scores indicate
|
|
858
|
-
* better candidates for presentation. Each card includes a provenance trail
|
|
859
|
-
* documenting how strategies contributed to the final score.
|
|
906
|
+
* Get new cards with suitability scores based on ELO distance.
|
|
860
907
|
*
|
|
861
|
-
*
|
|
862
|
-
*
|
|
863
|
-
* not provide a default implementation.
|
|
908
|
+
* Cards closer to user's ELO get higher scores.
|
|
909
|
+
* Score formula: max(0, 1 - distance / 500)
|
|
864
910
|
*
|
|
865
|
-
*
|
|
866
|
-
*
|
|
867
|
-
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
868
|
-
* initial provenance entry with action='generated'.
|
|
911
|
+
* NOTE: This generator only handles NEW cards. Reviews are handled by
|
|
912
|
+
* SRSNavigator. Use CompositeGenerator to combine both.
|
|
869
913
|
*
|
|
870
|
-
*
|
|
871
|
-
*
|
|
872
|
-
* via Pipeline. Filters do not directly implement getWeightedCards().
|
|
914
|
+
* This method supports both the legacy signature (limit only) and the
|
|
915
|
+
* CardGenerator interface signature (limit, context).
|
|
873
916
|
*
|
|
874
|
-
* @param limit - Maximum cards to return
|
|
875
|
-
* @
|
|
917
|
+
* @param limit - Maximum number of cards to return
|
|
918
|
+
* @param context - Optional GeneratorContext (used when called via Pipeline)
|
|
919
|
+
*/
|
|
920
|
+
async getWeightedCards(limit, context) {
|
|
921
|
+
let userGlobalElo;
|
|
922
|
+
if (context?.userElo !== void 0) {
|
|
923
|
+
userGlobalElo = context.userElo;
|
|
924
|
+
} else {
|
|
925
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
926
|
+
const userElo = (0, import_common5.toCourseElo)(courseReg.elo);
|
|
927
|
+
userGlobalElo = userElo.global.score;
|
|
928
|
+
}
|
|
929
|
+
const activeCards = await this.user.getActiveCards();
|
|
930
|
+
const newCards = (await this.course.getCardsCenteredAtELO(
|
|
931
|
+
{ limit, elo: "user" },
|
|
932
|
+
(c) => !activeCards.some((ac) => c.cardID === ac.cardID)
|
|
933
|
+
)).map((c) => ({ ...c, status: "new" }));
|
|
934
|
+
const cardIds = newCards.map((c) => c.cardID);
|
|
935
|
+
const cardEloData = await this.course.getCardEloData(cardIds);
|
|
936
|
+
const scored = newCards.map((c, i) => {
|
|
937
|
+
const cardElo = cardEloData[i]?.global?.score ?? 1e3;
|
|
938
|
+
const distance = Math.abs(cardElo - userGlobalElo);
|
|
939
|
+
const score = Math.max(0, 1 - distance / 500);
|
|
940
|
+
return {
|
|
941
|
+
cardId: c.cardID,
|
|
942
|
+
courseId: c.courseID,
|
|
943
|
+
score,
|
|
944
|
+
provenance: [
|
|
945
|
+
{
|
|
946
|
+
strategy: "elo",
|
|
947
|
+
strategyName: this.strategyName || this.name,
|
|
948
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-ELO-default",
|
|
949
|
+
action: "generated",
|
|
950
|
+
score,
|
|
951
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userGlobalElo)}), new card`
|
|
952
|
+
}
|
|
953
|
+
]
|
|
954
|
+
};
|
|
955
|
+
});
|
|
956
|
+
scored.sort((a, b) => b.score - a.score);
|
|
957
|
+
return scored.slice(0, limit);
|
|
958
|
+
}
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
});
|
|
962
|
+
|
|
963
|
+
// src/core/navigators/generators/index.ts
|
|
964
|
+
var generators_exports = {};
|
|
965
|
+
var init_generators = __esm({
|
|
966
|
+
"src/core/navigators/generators/index.ts"() {
|
|
967
|
+
"use strict";
|
|
968
|
+
}
|
|
969
|
+
});
|
|
970
|
+
|
|
971
|
+
// src/core/navigators/generators/srs.ts
|
|
972
|
+
var srs_exports = {};
|
|
973
|
+
__export(srs_exports, {
|
|
974
|
+
default: () => SRSNavigator
|
|
975
|
+
});
|
|
976
|
+
var import_moment3, SRSNavigator;
|
|
977
|
+
var init_srs = __esm({
|
|
978
|
+
"src/core/navigators/generators/srs.ts"() {
|
|
979
|
+
"use strict";
|
|
980
|
+
import_moment3 = __toESM(require("moment"), 1);
|
|
981
|
+
init_navigators();
|
|
982
|
+
init_logger();
|
|
983
|
+
SRSNavigator = class extends ContentNavigator {
|
|
984
|
+
/** Human-readable name for CardGenerator interface */
|
|
985
|
+
name;
|
|
986
|
+
constructor(user, course, strategyData) {
|
|
987
|
+
super(user, course, strategyData);
|
|
988
|
+
this.name = strategyData?.name || "SRS";
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* Get review cards scored by urgency.
|
|
992
|
+
*
|
|
993
|
+
* Score formula combines:
|
|
994
|
+
* - Relative overdueness: hoursOverdue / intervalHours
|
|
995
|
+
* - Interval recency: exponential decay favoring shorter intervals
|
|
996
|
+
*
|
|
997
|
+
* Cards not yet due are excluded (not scored as 0).
|
|
998
|
+
*
|
|
999
|
+
* This method supports both the legacy signature (limit only) and the
|
|
1000
|
+
* CardGenerator interface signature (limit, context).
|
|
1001
|
+
*
|
|
1002
|
+
* @param limit - Maximum number of cards to return
|
|
1003
|
+
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1004
|
+
*/
|
|
1005
|
+
async getWeightedCards(limit, _context) {
|
|
1006
|
+
if (!this.user || !this.course) {
|
|
1007
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
1008
|
+
}
|
|
1009
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1010
|
+
const now = import_moment3.default.utc();
|
|
1011
|
+
const dueReviews = reviews.filter((r) => now.isAfter(import_moment3.default.utc(r.reviewTime)));
|
|
1012
|
+
const scored = dueReviews.map((review) => {
|
|
1013
|
+
const { score, reason } = this.computeUrgencyScore(review, now);
|
|
1014
|
+
return {
|
|
1015
|
+
cardId: review.cardId,
|
|
1016
|
+
courseId: review.courseId,
|
|
1017
|
+
score,
|
|
1018
|
+
reviewID: review._id,
|
|
1019
|
+
provenance: [
|
|
1020
|
+
{
|
|
1021
|
+
strategy: "srs",
|
|
1022
|
+
strategyName: this.strategyName || this.name,
|
|
1023
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-SRS-default",
|
|
1024
|
+
action: "generated",
|
|
1025
|
+
score,
|
|
1026
|
+
reason
|
|
1027
|
+
}
|
|
1028
|
+
]
|
|
1029
|
+
};
|
|
1030
|
+
});
|
|
1031
|
+
logger.debug(`[srsNav] got ${scored.length} weighted cards`);
|
|
1032
|
+
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
1033
|
+
}
|
|
1034
|
+
/**
|
|
1035
|
+
* Compute urgency score for a review card.
|
|
1036
|
+
*
|
|
1037
|
+
* Two factors:
|
|
1038
|
+
* 1. Relative overdueness = hoursOverdue / intervalHours
|
|
1039
|
+
* - 2 days overdue on 3-day interval = 0.67 (urgent)
|
|
1040
|
+
* - 2 days overdue on 180-day interval = 0.01 (not urgent)
|
|
1041
|
+
*
|
|
1042
|
+
* 2. Interval recency factor = 0.3 + 0.7 * exp(-intervalHours / 720)
|
|
1043
|
+
* - 24h interval → ~1.0 (very recent learning)
|
|
1044
|
+
* - 30 days (720h) → ~0.56
|
|
1045
|
+
* - 180 days → ~0.30
|
|
1046
|
+
*
|
|
1047
|
+
* Combined: base 0.5 + weighted average of factors * 0.45
|
|
1048
|
+
* Result range: approximately 0.5 to 0.95
|
|
1049
|
+
*/
|
|
1050
|
+
computeUrgencyScore(review, now) {
|
|
1051
|
+
const scheduledAt = import_moment3.default.utc(review.scheduledAt);
|
|
1052
|
+
const due = import_moment3.default.utc(review.reviewTime);
|
|
1053
|
+
const intervalHours = Math.max(1, due.diff(scheduledAt, "hours"));
|
|
1054
|
+
const hoursOverdue = now.diff(due, "hours");
|
|
1055
|
+
const relativeOverdue = hoursOverdue / intervalHours;
|
|
1056
|
+
const recencyFactor = 0.3 + 0.7 * Math.exp(-intervalHours / 720);
|
|
1057
|
+
const overdueContribution = Math.min(1, Math.max(0, relativeOverdue));
|
|
1058
|
+
const urgency = overdueContribution * 0.5 + recencyFactor * 0.5;
|
|
1059
|
+
const score = Math.min(0.95, 0.5 + urgency * 0.45);
|
|
1060
|
+
const reason = `${Math.round(hoursOverdue)}h overdue (interval: ${Math.round(intervalHours)}h, relative: ${relativeOverdue.toFixed(2)}), recency: ${recencyFactor.toFixed(2)}, review`;
|
|
1061
|
+
return { score, reason };
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
});
|
|
1066
|
+
|
|
1067
|
+
// src/core/navigators/generators/types.ts
|
|
1068
|
+
var types_exports = {};
|
|
1069
|
+
var init_types = __esm({
|
|
1070
|
+
"src/core/navigators/generators/types.ts"() {
|
|
1071
|
+
"use strict";
|
|
1072
|
+
}
|
|
1073
|
+
});
|
|
1074
|
+
|
|
1075
|
+
// import("./generators/**/*") in src/core/navigators/index.ts
|
|
1076
|
+
var globImport_generators;
|
|
1077
|
+
var init_ = __esm({
|
|
1078
|
+
'import("./generators/**/*") in src/core/navigators/index.ts'() {
|
|
1079
|
+
globImport_generators = __glob({
|
|
1080
|
+
"./generators/CompositeGenerator.ts": () => Promise.resolve().then(() => (init_CompositeGenerator(), CompositeGenerator_exports)),
|
|
1081
|
+
"./generators/elo.ts": () => Promise.resolve().then(() => (init_elo(), elo_exports)),
|
|
1082
|
+
"./generators/index.ts": () => Promise.resolve().then(() => (init_generators(), generators_exports)),
|
|
1083
|
+
"./generators/srs.ts": () => Promise.resolve().then(() => (init_srs(), srs_exports)),
|
|
1084
|
+
"./generators/types.ts": () => Promise.resolve().then(() => (init_types(), types_exports))
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
|
|
1089
|
+
// src/core/types/contentNavigationStrategy.ts
|
|
1090
|
+
var DEFAULT_LEARNABLE_WEIGHT;
|
|
1091
|
+
var init_contentNavigationStrategy = __esm({
|
|
1092
|
+
"src/core/types/contentNavigationStrategy.ts"() {
|
|
1093
|
+
"use strict";
|
|
1094
|
+
DEFAULT_LEARNABLE_WEIGHT = {
|
|
1095
|
+
weight: 1,
|
|
1096
|
+
confidence: 0.1,
|
|
1097
|
+
// Low confidence initially = wide exploration
|
|
1098
|
+
sampleSize: 0
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
|
|
1103
|
+
// src/core/navigators/filters/WeightedFilter.ts
|
|
1104
|
+
var WeightedFilter_exports = {};
|
|
1105
|
+
__export(WeightedFilter_exports, {
|
|
1106
|
+
WeightedFilter: () => WeightedFilter
|
|
1107
|
+
});
|
|
1108
|
+
var WeightedFilter;
|
|
1109
|
+
var init_WeightedFilter = __esm({
|
|
1110
|
+
"src/core/navigators/filters/WeightedFilter.ts"() {
|
|
1111
|
+
"use strict";
|
|
1112
|
+
init_contentNavigationStrategy();
|
|
1113
|
+
WeightedFilter = class {
|
|
1114
|
+
name;
|
|
1115
|
+
inner;
|
|
1116
|
+
learnable;
|
|
1117
|
+
staticWeight;
|
|
1118
|
+
strategyId;
|
|
1119
|
+
constructor(inner, learnable = DEFAULT_LEARNABLE_WEIGHT, staticWeight = false, strategyId) {
|
|
1120
|
+
this.inner = inner;
|
|
1121
|
+
this.name = inner.name;
|
|
1122
|
+
this.learnable = learnable;
|
|
1123
|
+
this.staticWeight = staticWeight;
|
|
1124
|
+
this.strategyId = strategyId;
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Apply the inner filter, then scale its effect by the configured weight.
|
|
1128
|
+
*/
|
|
1129
|
+
async transform(cards, context) {
|
|
1130
|
+
let effectiveWeight = this.learnable.weight;
|
|
1131
|
+
let deviation;
|
|
1132
|
+
if (!this.staticWeight && context.orchestration) {
|
|
1133
|
+
const strategyId = this.strategyId || this.inner.strategyId || this.name;
|
|
1134
|
+
effectiveWeight = context.orchestration.getEffectiveWeight(strategyId, this.learnable);
|
|
1135
|
+
deviation = context.orchestration.getDeviation(strategyId);
|
|
1136
|
+
}
|
|
1137
|
+
if (Math.abs(effectiveWeight - 1) < 1e-3) {
|
|
1138
|
+
return this.inner.transform(cards, context);
|
|
1139
|
+
}
|
|
1140
|
+
const originalScores = /* @__PURE__ */ new Map();
|
|
1141
|
+
for (const card of cards) {
|
|
1142
|
+
originalScores.set(card.cardId, card.score);
|
|
1143
|
+
}
|
|
1144
|
+
const transformedCards = await this.inner.transform(cards, context);
|
|
1145
|
+
return transformedCards.map((card) => {
|
|
1146
|
+
const originalScore = originalScores.get(card.cardId);
|
|
1147
|
+
if (originalScore === void 0 || originalScore === 0 || card.score === 0) {
|
|
1148
|
+
return card;
|
|
1149
|
+
}
|
|
1150
|
+
const rawEffect = card.score / originalScore;
|
|
1151
|
+
if (Math.abs(rawEffect - 1) < 1e-4) {
|
|
1152
|
+
return card;
|
|
1153
|
+
}
|
|
1154
|
+
const weightedEffect = Math.pow(rawEffect, effectiveWeight);
|
|
1155
|
+
const newScore = originalScore * weightedEffect;
|
|
1156
|
+
const lastProvIndex = card.provenance.length - 1;
|
|
1157
|
+
const lastProv = card.provenance[lastProvIndex];
|
|
1158
|
+
if (lastProv) {
|
|
1159
|
+
const updatedProvenance = [...card.provenance];
|
|
1160
|
+
updatedProvenance[lastProvIndex] = {
|
|
1161
|
+
...lastProv,
|
|
1162
|
+
score: newScore,
|
|
1163
|
+
effectiveWeight,
|
|
1164
|
+
deviation
|
|
1165
|
+
// We can optionally append to the reason, but the structured field is key
|
|
1166
|
+
};
|
|
1167
|
+
return {
|
|
1168
|
+
...card,
|
|
1169
|
+
score: newScore,
|
|
1170
|
+
provenance: updatedProvenance
|
|
1171
|
+
};
|
|
1172
|
+
}
|
|
1173
|
+
return {
|
|
1174
|
+
...card,
|
|
1175
|
+
score: newScore
|
|
1176
|
+
};
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
});
|
|
1182
|
+
|
|
1183
|
+
// src/core/navigators/filters/eloDistance.ts
|
|
1184
|
+
var eloDistance_exports = {};
|
|
1185
|
+
__export(eloDistance_exports, {
|
|
1186
|
+
DEFAULT_HALF_LIFE: () => DEFAULT_HALF_LIFE,
|
|
1187
|
+
DEFAULT_MAX_MULTIPLIER: () => DEFAULT_MAX_MULTIPLIER,
|
|
1188
|
+
DEFAULT_MIN_MULTIPLIER: () => DEFAULT_MIN_MULTIPLIER,
|
|
1189
|
+
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1190
|
+
});
|
|
1191
|
+
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
1192
|
+
const normalizedDistance = distance / halfLife;
|
|
1193
|
+
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
1194
|
+
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
1195
|
+
}
|
|
1196
|
+
function createEloDistanceFilter(config) {
|
|
1197
|
+
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
1198
|
+
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
1199
|
+
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
1200
|
+
return {
|
|
1201
|
+
name: "ELO Distance Filter",
|
|
1202
|
+
async transform(cards, context) {
|
|
1203
|
+
const { course, userElo } = context;
|
|
1204
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
1205
|
+
const cardElos = await course.getCardEloData(cardIds);
|
|
1206
|
+
return cards.map((card, i) => {
|
|
1207
|
+
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
1208
|
+
const distance = Math.abs(cardElo - userElo);
|
|
1209
|
+
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
1210
|
+
const newScore = card.score * multiplier;
|
|
1211
|
+
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
1212
|
+
return {
|
|
1213
|
+
...card,
|
|
1214
|
+
score: newScore,
|
|
1215
|
+
provenance: [
|
|
1216
|
+
...card.provenance,
|
|
1217
|
+
{
|
|
1218
|
+
strategy: "eloDistance",
|
|
1219
|
+
strategyName: "ELO Distance Filter",
|
|
1220
|
+
strategyId: "ELO_DISTANCE_FILTER",
|
|
1221
|
+
action,
|
|
1222
|
+
score: newScore,
|
|
1223
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
1224
|
+
}
|
|
1225
|
+
]
|
|
1226
|
+
};
|
|
1227
|
+
});
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
|
|
1232
|
+
var init_eloDistance = __esm({
|
|
1233
|
+
"src/core/navigators/filters/eloDistance.ts"() {
|
|
1234
|
+
"use strict";
|
|
1235
|
+
DEFAULT_HALF_LIFE = 200;
|
|
1236
|
+
DEFAULT_MIN_MULTIPLIER = 0.3;
|
|
1237
|
+
DEFAULT_MAX_MULTIPLIER = 1;
|
|
1238
|
+
}
|
|
1239
|
+
});
|
|
1240
|
+
|
|
1241
|
+
// src/core/navigators/filters/hierarchyDefinition.ts
|
|
1242
|
+
var hierarchyDefinition_exports = {};
|
|
1243
|
+
__export(hierarchyDefinition_exports, {
|
|
1244
|
+
default: () => HierarchyDefinitionNavigator
|
|
1245
|
+
});
|
|
1246
|
+
var import_common6, DEFAULT_MIN_COUNT, HierarchyDefinitionNavigator;
|
|
1247
|
+
var init_hierarchyDefinition = __esm({
|
|
1248
|
+
"src/core/navigators/filters/hierarchyDefinition.ts"() {
|
|
1249
|
+
"use strict";
|
|
1250
|
+
init_navigators();
|
|
1251
|
+
import_common6 = require("@vue-skuilder/common");
|
|
1252
|
+
DEFAULT_MIN_COUNT = 3;
|
|
1253
|
+
HierarchyDefinitionNavigator = class extends ContentNavigator {
|
|
1254
|
+
config;
|
|
1255
|
+
/** Human-readable name for CardFilter interface */
|
|
1256
|
+
name;
|
|
1257
|
+
constructor(user, course, strategyData) {
|
|
1258
|
+
super(user, course, strategyData);
|
|
1259
|
+
this.config = this.parseConfig(strategyData.serializedData);
|
|
1260
|
+
this.name = strategyData.name || "Hierarchy Definition";
|
|
1261
|
+
}
|
|
1262
|
+
parseConfig(serializedData) {
|
|
1263
|
+
try {
|
|
1264
|
+
const parsed = JSON.parse(serializedData);
|
|
1265
|
+
return {
|
|
1266
|
+
prerequisites: parsed.prerequisites || {}
|
|
1267
|
+
};
|
|
1268
|
+
} catch {
|
|
1269
|
+
return {
|
|
1270
|
+
prerequisites: {}
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
/**
|
|
1275
|
+
* Check if a specific prerequisite is satisfied
|
|
1276
|
+
*/
|
|
1277
|
+
isPrerequisiteMet(prereq, userTagElo, userGlobalElo) {
|
|
1278
|
+
if (!userTagElo) return false;
|
|
1279
|
+
const minCount = prereq.masteryThreshold?.minCount ?? DEFAULT_MIN_COUNT;
|
|
1280
|
+
if (userTagElo.count < minCount) return false;
|
|
1281
|
+
if (prereq.masteryThreshold?.minElo !== void 0) {
|
|
1282
|
+
return userTagElo.score >= prereq.masteryThreshold.minElo;
|
|
1283
|
+
} else {
|
|
1284
|
+
return userTagElo.score >= userGlobalElo;
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Get the set of tags the user has mastered.
|
|
1289
|
+
* A tag is "mastered" if it appears as a prerequisite somewhere and meets its threshold.
|
|
1290
|
+
*/
|
|
1291
|
+
async getMasteredTags(context) {
|
|
1292
|
+
const mastered = /* @__PURE__ */ new Set();
|
|
1293
|
+
try {
|
|
1294
|
+
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1295
|
+
const userElo = (0, import_common6.toCourseElo)(courseReg.elo);
|
|
1296
|
+
for (const prereqs of Object.values(this.config.prerequisites)) {
|
|
1297
|
+
for (const prereq of prereqs) {
|
|
1298
|
+
const tagElo = userElo.tags[prereq.tag];
|
|
1299
|
+
if (this.isPrerequisiteMet(prereq, tagElo, userElo.global.score)) {
|
|
1300
|
+
mastered.add(prereq.tag);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
} catch {
|
|
1305
|
+
}
|
|
1306
|
+
return mastered;
|
|
1307
|
+
}
|
|
1308
|
+
/**
|
|
1309
|
+
* Get the set of tags that are unlocked (prerequisites met)
|
|
1310
|
+
*/
|
|
1311
|
+
getUnlockedTags(masteredTags) {
|
|
1312
|
+
const unlocked = /* @__PURE__ */ new Set();
|
|
1313
|
+
for (const [tagId, prereqs] of Object.entries(this.config.prerequisites)) {
|
|
1314
|
+
const allPrereqsMet = prereqs.every((prereq) => masteredTags.has(prereq.tag));
|
|
1315
|
+
if (allPrereqsMet) {
|
|
1316
|
+
unlocked.add(tagId);
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
return unlocked;
|
|
1320
|
+
}
|
|
1321
|
+
/**
|
|
1322
|
+
* Check if a tag has prerequisites defined in config
|
|
1323
|
+
*/
|
|
1324
|
+
hasPrerequisites(tagId) {
|
|
1325
|
+
return tagId in this.config.prerequisites;
|
|
1326
|
+
}
|
|
1327
|
+
/**
|
|
1328
|
+
* Check if a card is unlocked and generate reason.
|
|
1329
|
+
*/
|
|
1330
|
+
async checkCardUnlock(card, _course, unlockedTags, masteredTags) {
|
|
1331
|
+
try {
|
|
1332
|
+
const cardTags = card.tags ?? [];
|
|
1333
|
+
const lockedTags = cardTags.filter(
|
|
1334
|
+
(tag) => this.hasPrerequisites(tag) && !unlockedTags.has(tag)
|
|
1335
|
+
);
|
|
1336
|
+
if (lockedTags.length === 0) {
|
|
1337
|
+
const tagList = cardTags.length > 0 ? cardTags.join(", ") : "none";
|
|
1338
|
+
return {
|
|
1339
|
+
isUnlocked: true,
|
|
1340
|
+
reason: `Prerequisites met, tags: ${tagList}`
|
|
1341
|
+
};
|
|
1342
|
+
}
|
|
1343
|
+
const missingPrereqs = lockedTags.flatMap((tag) => {
|
|
1344
|
+
const prereqs = this.config.prerequisites[tag] || [];
|
|
1345
|
+
return prereqs.filter((p) => !masteredTags.has(p.tag)).map((p) => p.tag);
|
|
1346
|
+
});
|
|
1347
|
+
return {
|
|
1348
|
+
isUnlocked: false,
|
|
1349
|
+
reason: `Blocked: missing prerequisites ${missingPrereqs.join(", ")} for tags ${lockedTags.join(", ")}`
|
|
1350
|
+
};
|
|
1351
|
+
} catch {
|
|
1352
|
+
return {
|
|
1353
|
+
isUnlocked: true,
|
|
1354
|
+
reason: "Prerequisites check skipped (tag lookup failed)"
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
/**
|
|
1359
|
+
* CardFilter.transform implementation.
|
|
1360
|
+
*
|
|
1361
|
+
* Apply prerequisite gating to cards. Cards with locked tags receive score: 0.
|
|
1362
|
+
*/
|
|
1363
|
+
async transform(cards, context) {
|
|
1364
|
+
const masteredTags = await this.getMasteredTags(context);
|
|
1365
|
+
const unlockedTags = this.getUnlockedTags(masteredTags);
|
|
1366
|
+
const gated = [];
|
|
1367
|
+
for (const card of cards) {
|
|
1368
|
+
const { isUnlocked, reason } = await this.checkCardUnlock(
|
|
1369
|
+
card,
|
|
1370
|
+
context.course,
|
|
1371
|
+
unlockedTags,
|
|
1372
|
+
masteredTags
|
|
1373
|
+
);
|
|
1374
|
+
const finalScore = isUnlocked ? card.score : 0;
|
|
1375
|
+
const action = isUnlocked ? "passed" : "penalized";
|
|
1376
|
+
gated.push({
|
|
1377
|
+
...card,
|
|
1378
|
+
score: finalScore,
|
|
1379
|
+
provenance: [
|
|
1380
|
+
...card.provenance,
|
|
1381
|
+
{
|
|
1382
|
+
strategy: "hierarchyDefinition",
|
|
1383
|
+
strategyName: this.strategyName || this.name,
|
|
1384
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hierarchy",
|
|
1385
|
+
action,
|
|
1386
|
+
score: finalScore,
|
|
1387
|
+
reason
|
|
1388
|
+
}
|
|
1389
|
+
]
|
|
1390
|
+
});
|
|
1391
|
+
}
|
|
1392
|
+
return gated;
|
|
1393
|
+
}
|
|
1394
|
+
/**
|
|
1395
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1396
|
+
*
|
|
1397
|
+
* Use transform() via Pipeline instead.
|
|
1398
|
+
*/
|
|
1399
|
+
async getWeightedCards(_limit) {
|
|
1400
|
+
throw new Error(
|
|
1401
|
+
"HierarchyDefinitionNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1402
|
+
);
|
|
1403
|
+
}
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
});
|
|
1407
|
+
|
|
1408
|
+
// src/core/navigators/filters/userTagPreference.ts
|
|
1409
|
+
var userTagPreference_exports = {};
|
|
1410
|
+
__export(userTagPreference_exports, {
|
|
1411
|
+
default: () => UserTagPreferenceFilter
|
|
1412
|
+
});
|
|
1413
|
+
var UserTagPreferenceFilter;
|
|
1414
|
+
var init_userTagPreference = __esm({
|
|
1415
|
+
"src/core/navigators/filters/userTagPreference.ts"() {
|
|
1416
|
+
"use strict";
|
|
1417
|
+
init_navigators();
|
|
1418
|
+
UserTagPreferenceFilter = class extends ContentNavigator {
|
|
1419
|
+
_strategyData;
|
|
1420
|
+
/** Human-readable name for CardFilter interface */
|
|
1421
|
+
name;
|
|
1422
|
+
constructor(user, course, strategyData) {
|
|
1423
|
+
super(user, course, strategyData);
|
|
1424
|
+
this._strategyData = strategyData;
|
|
1425
|
+
this.name = strategyData.name || "User Tag Preferences";
|
|
1426
|
+
}
|
|
1427
|
+
/**
|
|
1428
|
+
* Compute multiplier for a card based on its tags and user preferences.
|
|
1429
|
+
* Returns the maximum multiplier among all matching tags, or 1.0 if no matches.
|
|
1430
|
+
*/
|
|
1431
|
+
computeMultiplier(cardTags, boostMap) {
|
|
1432
|
+
const multipliers = cardTags.map((tag) => boostMap[tag]).filter((val) => val !== void 0);
|
|
1433
|
+
if (multipliers.length === 0) {
|
|
1434
|
+
return 1;
|
|
1435
|
+
}
|
|
1436
|
+
return Math.max(...multipliers);
|
|
1437
|
+
}
|
|
1438
|
+
/**
|
|
1439
|
+
* Build human-readable reason for the filter's decision.
|
|
1440
|
+
*/
|
|
1441
|
+
buildReason(cardTags, boostMap, multiplier) {
|
|
1442
|
+
const matchingTags = cardTags.filter((tag) => boostMap[tag] === multiplier);
|
|
1443
|
+
if (multiplier === 0) {
|
|
1444
|
+
return `Excluded by user preference: ${matchingTags.join(", ")} (${multiplier}x)`;
|
|
1445
|
+
}
|
|
1446
|
+
if (multiplier < 1) {
|
|
1447
|
+
return `Penalized by user preference: ${matchingTags.join(", ")} (${multiplier.toFixed(2)}x)`;
|
|
1448
|
+
}
|
|
1449
|
+
if (multiplier > 1) {
|
|
1450
|
+
return `Boosted by user preference: ${matchingTags.join(", ")} (${multiplier.toFixed(2)}x)`;
|
|
1451
|
+
}
|
|
1452
|
+
return "No matching user preferences";
|
|
1453
|
+
}
|
|
1454
|
+
/**
|
|
1455
|
+
* CardFilter.transform implementation.
|
|
1456
|
+
*
|
|
1457
|
+
* Apply user tag preferences:
|
|
1458
|
+
* 1. Read preferences from strategy state
|
|
1459
|
+
* 2. If no preferences, pass through unchanged
|
|
1460
|
+
* 3. For each card:
|
|
1461
|
+
* - Look up tag in boost record
|
|
1462
|
+
* - If tag found: apply multiplier (0 = exclude, 1 = neutral, >1 = boost)
|
|
1463
|
+
* - If multiple tags match: use max multiplier
|
|
1464
|
+
* - Append provenance with clear reason
|
|
1465
|
+
*/
|
|
1466
|
+
async transform(cards, _context) {
|
|
1467
|
+
const prefs = await this.getStrategyState();
|
|
1468
|
+
if (!prefs || Object.keys(prefs.boost).length === 0) {
|
|
1469
|
+
return cards.map((card) => ({
|
|
1470
|
+
...card,
|
|
1471
|
+
provenance: [
|
|
1472
|
+
...card.provenance,
|
|
1473
|
+
{
|
|
1474
|
+
strategy: "userTagPreference",
|
|
1475
|
+
strategyName: this.strategyName || this.name,
|
|
1476
|
+
strategyId: this.strategyId || this._strategyData._id,
|
|
1477
|
+
action: "passed",
|
|
1478
|
+
score: card.score,
|
|
1479
|
+
reason: "No user tag preferences configured"
|
|
1480
|
+
}
|
|
1481
|
+
]
|
|
1482
|
+
}));
|
|
1483
|
+
}
|
|
1484
|
+
const adjusted = await Promise.all(
|
|
1485
|
+
cards.map(async (card) => {
|
|
1486
|
+
const cardTags = card.tags ?? [];
|
|
1487
|
+
const multiplier = this.computeMultiplier(cardTags, prefs.boost);
|
|
1488
|
+
const finalScore = Math.min(1, card.score * multiplier);
|
|
1489
|
+
let action;
|
|
1490
|
+
if (multiplier === 0 || multiplier < 1) {
|
|
1491
|
+
action = "penalized";
|
|
1492
|
+
} else if (multiplier > 1) {
|
|
1493
|
+
action = "boosted";
|
|
1494
|
+
} else {
|
|
1495
|
+
action = "passed";
|
|
1496
|
+
}
|
|
1497
|
+
return {
|
|
1498
|
+
...card,
|
|
1499
|
+
score: finalScore,
|
|
1500
|
+
provenance: [
|
|
1501
|
+
...card.provenance,
|
|
1502
|
+
{
|
|
1503
|
+
strategy: "userTagPreference",
|
|
1504
|
+
strategyName: this.strategyName || this.name,
|
|
1505
|
+
strategyId: this.strategyId || this._strategyData._id,
|
|
1506
|
+
action,
|
|
1507
|
+
score: finalScore,
|
|
1508
|
+
reason: this.buildReason(cardTags, prefs.boost, multiplier)
|
|
1509
|
+
}
|
|
1510
|
+
]
|
|
1511
|
+
};
|
|
1512
|
+
})
|
|
1513
|
+
);
|
|
1514
|
+
return adjusted;
|
|
1515
|
+
}
|
|
1516
|
+
/**
|
|
1517
|
+
* Legacy getWeightedCards - throws as filters should not be used as generators.
|
|
1518
|
+
*/
|
|
1519
|
+
async getWeightedCards(_limit) {
|
|
1520
|
+
throw new Error(
|
|
1521
|
+
"UserTagPreferenceFilter is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1522
|
+
);
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
}
|
|
1526
|
+
});
|
|
1527
|
+
|
|
1528
|
+
// src/core/navigators/filters/index.ts
|
|
1529
|
+
var filters_exports = {};
|
|
1530
|
+
__export(filters_exports, {
|
|
1531
|
+
UserTagPreferenceFilter: () => UserTagPreferenceFilter,
|
|
1532
|
+
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1533
|
+
});
|
|
1534
|
+
var init_filters = __esm({
|
|
1535
|
+
"src/core/navigators/filters/index.ts"() {
|
|
1536
|
+
"use strict";
|
|
1537
|
+
init_eloDistance();
|
|
1538
|
+
init_userTagPreference();
|
|
1539
|
+
}
|
|
1540
|
+
});
|
|
1541
|
+
|
|
1542
|
+
// src/core/navigators/filters/inferredPreferenceStub.ts
|
|
1543
|
+
var inferredPreferenceStub_exports = {};
|
|
1544
|
+
__export(inferredPreferenceStub_exports, {
|
|
1545
|
+
INFERRED_PREFERENCE_NAVIGATOR_STUB: () => INFERRED_PREFERENCE_NAVIGATOR_STUB
|
|
1546
|
+
});
|
|
1547
|
+
var INFERRED_PREFERENCE_NAVIGATOR_STUB;
|
|
1548
|
+
var init_inferredPreferenceStub = __esm({
|
|
1549
|
+
"src/core/navigators/filters/inferredPreferenceStub.ts"() {
|
|
1550
|
+
"use strict";
|
|
1551
|
+
INFERRED_PREFERENCE_NAVIGATOR_STUB = true;
|
|
1552
|
+
}
|
|
1553
|
+
});
|
|
1554
|
+
|
|
1555
|
+
// src/core/navigators/filters/interferenceMitigator.ts
|
|
1556
|
+
var interferenceMitigator_exports = {};
|
|
1557
|
+
__export(interferenceMitigator_exports, {
|
|
1558
|
+
default: () => InterferenceMitigatorNavigator
|
|
1559
|
+
});
|
|
1560
|
+
var import_common7, DEFAULT_MIN_COUNT2, DEFAULT_MIN_ELAPSED_DAYS, DEFAULT_INTERFERENCE_DECAY, InterferenceMitigatorNavigator;
|
|
1561
|
+
var init_interferenceMitigator = __esm({
|
|
1562
|
+
"src/core/navigators/filters/interferenceMitigator.ts"() {
|
|
1563
|
+
"use strict";
|
|
1564
|
+
init_navigators();
|
|
1565
|
+
import_common7 = require("@vue-skuilder/common");
|
|
1566
|
+
DEFAULT_MIN_COUNT2 = 10;
|
|
1567
|
+
DEFAULT_MIN_ELAPSED_DAYS = 3;
|
|
1568
|
+
DEFAULT_INTERFERENCE_DECAY = 0.8;
|
|
1569
|
+
InterferenceMitigatorNavigator = class extends ContentNavigator {
|
|
1570
|
+
config;
|
|
1571
|
+
/** Human-readable name for CardFilter interface */
|
|
1572
|
+
name;
|
|
1573
|
+
/** Precomputed map: tag -> set of { partner, decay } it interferes with */
|
|
1574
|
+
interferenceMap;
|
|
1575
|
+
constructor(user, course, strategyData) {
|
|
1576
|
+
super(user, course, strategyData);
|
|
1577
|
+
this.config = this.parseConfig(strategyData.serializedData);
|
|
1578
|
+
this.interferenceMap = this.buildInterferenceMap();
|
|
1579
|
+
this.name = strategyData.name || "Interference Mitigator";
|
|
1580
|
+
}
|
|
1581
|
+
parseConfig(serializedData) {
|
|
1582
|
+
try {
|
|
1583
|
+
const parsed = JSON.parse(serializedData);
|
|
1584
|
+
let sets = parsed.interferenceSets || [];
|
|
1585
|
+
if (sets.length > 0 && Array.isArray(sets[0])) {
|
|
1586
|
+
sets = sets.map((tags) => ({ tags }));
|
|
1587
|
+
}
|
|
1588
|
+
return {
|
|
1589
|
+
interferenceSets: sets,
|
|
1590
|
+
maturityThreshold: {
|
|
1591
|
+
minCount: parsed.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2,
|
|
1592
|
+
minElo: parsed.maturityThreshold?.minElo,
|
|
1593
|
+
minElapsedDays: parsed.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS
|
|
1594
|
+
},
|
|
1595
|
+
defaultDecay: parsed.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY
|
|
1596
|
+
};
|
|
1597
|
+
} catch {
|
|
1598
|
+
return {
|
|
1599
|
+
interferenceSets: [],
|
|
1600
|
+
maturityThreshold: {
|
|
1601
|
+
minCount: DEFAULT_MIN_COUNT2,
|
|
1602
|
+
minElapsedDays: DEFAULT_MIN_ELAPSED_DAYS
|
|
1603
|
+
},
|
|
1604
|
+
defaultDecay: DEFAULT_INTERFERENCE_DECAY
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
/**
|
|
1609
|
+
* Build a map from each tag to its interference partners with decay coefficients.
|
|
1610
|
+
* If tags A, B, C are in an interference group with decay 0.8, then:
|
|
1611
|
+
* - A interferes with B (decay 0.8) and C (decay 0.8)
|
|
1612
|
+
* - B interferes with A (decay 0.8) and C (decay 0.8)
|
|
1613
|
+
* - etc.
|
|
1614
|
+
*/
|
|
1615
|
+
buildInterferenceMap() {
|
|
1616
|
+
const map = /* @__PURE__ */ new Map();
|
|
1617
|
+
for (const group of this.config.interferenceSets) {
|
|
1618
|
+
const decay = group.decay ?? this.config.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY;
|
|
1619
|
+
for (const tag of group.tags) {
|
|
1620
|
+
if (!map.has(tag)) {
|
|
1621
|
+
map.set(tag, []);
|
|
1622
|
+
}
|
|
1623
|
+
const partners = map.get(tag);
|
|
1624
|
+
for (const other of group.tags) {
|
|
1625
|
+
if (other !== tag) {
|
|
1626
|
+
const existing = partners.find((p) => p.partner === other);
|
|
1627
|
+
if (existing) {
|
|
1628
|
+
existing.decay = Math.max(existing.decay, decay);
|
|
1629
|
+
} else {
|
|
1630
|
+
partners.push({ partner: other, decay });
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
return map;
|
|
1637
|
+
}
|
|
1638
|
+
/**
|
|
1639
|
+
* Get the set of tags that are currently immature for this user.
|
|
1640
|
+
* A tag is immature if the user has interacted with it but hasn't
|
|
1641
|
+
* reached the maturity threshold.
|
|
1642
|
+
*/
|
|
1643
|
+
async getImmatureTags(context) {
|
|
1644
|
+
const immature = /* @__PURE__ */ new Set();
|
|
1645
|
+
try {
|
|
1646
|
+
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1647
|
+
const userElo = (0, import_common7.toCourseElo)(courseReg.elo);
|
|
1648
|
+
const minCount = this.config.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2;
|
|
1649
|
+
const minElo = this.config.maturityThreshold?.minElo;
|
|
1650
|
+
const minElapsedDays = this.config.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS;
|
|
1651
|
+
const minCountForElapsed = minElapsedDays * 2;
|
|
1652
|
+
for (const [tagId, tagElo] of Object.entries(userElo.tags)) {
|
|
1653
|
+
if (tagElo.count === 0) continue;
|
|
1654
|
+
const belowCount = tagElo.count < minCount;
|
|
1655
|
+
const belowElo = minElo !== void 0 && tagElo.score < minElo;
|
|
1656
|
+
const belowElapsed = tagElo.count < minCountForElapsed;
|
|
1657
|
+
if (belowCount || belowElo || belowElapsed) {
|
|
1658
|
+
immature.add(tagId);
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
} catch {
|
|
1662
|
+
}
|
|
1663
|
+
return immature;
|
|
1664
|
+
}
|
|
1665
|
+
/**
|
|
1666
|
+
* Get all tags that interfere with any immature tag, along with their decay coefficients.
|
|
1667
|
+
* These are the tags we want to avoid introducing.
|
|
1668
|
+
*/
|
|
1669
|
+
getTagsToAvoid(immatureTags) {
|
|
1670
|
+
const avoid = /* @__PURE__ */ new Map();
|
|
1671
|
+
for (const immatureTag of immatureTags) {
|
|
1672
|
+
const partners = this.interferenceMap.get(immatureTag);
|
|
1673
|
+
if (partners) {
|
|
1674
|
+
for (const { partner, decay } of partners) {
|
|
1675
|
+
if (!immatureTags.has(partner)) {
|
|
1676
|
+
const existing = avoid.get(partner) ?? 0;
|
|
1677
|
+
avoid.set(partner, Math.max(existing, decay));
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
return avoid;
|
|
1683
|
+
}
|
|
1684
|
+
/**
|
|
1685
|
+
* Compute interference score reduction for a card.
|
|
1686
|
+
* Returns: { multiplier, interfering tags, reason }
|
|
1687
|
+
*/
|
|
1688
|
+
computeInterferenceEffect(cardTags, tagsToAvoid, immatureTags) {
|
|
1689
|
+
if (tagsToAvoid.size === 0) {
|
|
1690
|
+
return {
|
|
1691
|
+
multiplier: 1,
|
|
1692
|
+
interferingTags: [],
|
|
1693
|
+
reason: "No interference detected"
|
|
1694
|
+
};
|
|
1695
|
+
}
|
|
1696
|
+
let multiplier = 1;
|
|
1697
|
+
const interferingTags = [];
|
|
1698
|
+
for (const tag of cardTags) {
|
|
1699
|
+
const decay = tagsToAvoid.get(tag);
|
|
1700
|
+
if (decay !== void 0) {
|
|
1701
|
+
interferingTags.push(tag);
|
|
1702
|
+
multiplier *= 1 - decay;
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
if (interferingTags.length === 0) {
|
|
1706
|
+
return {
|
|
1707
|
+
multiplier: 1,
|
|
1708
|
+
interferingTags: [],
|
|
1709
|
+
reason: "No interference detected"
|
|
1710
|
+
};
|
|
1711
|
+
}
|
|
1712
|
+
const causingTags = /* @__PURE__ */ new Set();
|
|
1713
|
+
for (const tag of interferingTags) {
|
|
1714
|
+
for (const immatureTag of immatureTags) {
|
|
1715
|
+
const partners = this.interferenceMap.get(immatureTag);
|
|
1716
|
+
if (partners?.some((p) => p.partner === tag)) {
|
|
1717
|
+
causingTags.add(immatureTag);
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
const reason = `Interferes with immature tags ${Array.from(causingTags).join(", ")} (tags: ${interferingTags.join(", ")}, multiplier: ${multiplier.toFixed(2)})`;
|
|
1722
|
+
return { multiplier, interferingTags, reason };
|
|
1723
|
+
}
|
|
1724
|
+
/**
|
|
1725
|
+
* CardFilter.transform implementation.
|
|
1726
|
+
*
|
|
1727
|
+
* Apply interference-aware scoring. Cards with tags that interfere with
|
|
1728
|
+
* immature learnings get reduced scores.
|
|
1729
|
+
*/
|
|
1730
|
+
async transform(cards, context) {
|
|
1731
|
+
const immatureTags = await this.getImmatureTags(context);
|
|
1732
|
+
const tagsToAvoid = this.getTagsToAvoid(immatureTags);
|
|
1733
|
+
const adjusted = [];
|
|
1734
|
+
for (const card of cards) {
|
|
1735
|
+
const cardTags = card.tags ?? [];
|
|
1736
|
+
const { multiplier, reason } = this.computeInterferenceEffect(
|
|
1737
|
+
cardTags,
|
|
1738
|
+
tagsToAvoid,
|
|
1739
|
+
immatureTags
|
|
1740
|
+
);
|
|
1741
|
+
const finalScore = card.score * multiplier;
|
|
1742
|
+
const action = multiplier < 1 ? "penalized" : multiplier > 1 ? "boosted" : "passed";
|
|
1743
|
+
adjusted.push({
|
|
1744
|
+
...card,
|
|
1745
|
+
score: finalScore,
|
|
1746
|
+
provenance: [
|
|
1747
|
+
...card.provenance,
|
|
1748
|
+
{
|
|
1749
|
+
strategy: "interferenceMitigator",
|
|
1750
|
+
strategyName: this.strategyName || this.name,
|
|
1751
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-interference",
|
|
1752
|
+
action,
|
|
1753
|
+
score: finalScore,
|
|
1754
|
+
reason
|
|
1755
|
+
}
|
|
1756
|
+
]
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
return adjusted;
|
|
1760
|
+
}
|
|
1761
|
+
/**
|
|
1762
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1763
|
+
*
|
|
1764
|
+
* Use transform() via Pipeline instead.
|
|
1765
|
+
*/
|
|
1766
|
+
async getWeightedCards(_limit) {
|
|
1767
|
+
throw new Error(
|
|
1768
|
+
"InterferenceMitigatorNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1769
|
+
);
|
|
1770
|
+
}
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1773
|
+
});
|
|
1774
|
+
|
|
1775
|
+
// src/core/navigators/filters/relativePriority.ts
|
|
1776
|
+
var relativePriority_exports = {};
|
|
1777
|
+
__export(relativePriority_exports, {
|
|
1778
|
+
default: () => RelativePriorityNavigator
|
|
1779
|
+
});
|
|
1780
|
+
var DEFAULT_PRIORITY, DEFAULT_PRIORITY_INFLUENCE, DEFAULT_COMBINE_MODE, RelativePriorityNavigator;
|
|
1781
|
+
var init_relativePriority = __esm({
|
|
1782
|
+
"src/core/navigators/filters/relativePriority.ts"() {
|
|
1783
|
+
"use strict";
|
|
1784
|
+
init_navigators();
|
|
1785
|
+
DEFAULT_PRIORITY = 0.5;
|
|
1786
|
+
DEFAULT_PRIORITY_INFLUENCE = 0.5;
|
|
1787
|
+
DEFAULT_COMBINE_MODE = "max";
|
|
1788
|
+
RelativePriorityNavigator = class extends ContentNavigator {
|
|
1789
|
+
config;
|
|
1790
|
+
/** Human-readable name for CardFilter interface */
|
|
1791
|
+
name;
|
|
1792
|
+
constructor(user, course, strategyData) {
|
|
1793
|
+
super(user, course, strategyData);
|
|
1794
|
+
this.config = this.parseConfig(strategyData.serializedData);
|
|
1795
|
+
this.name = strategyData.name || "Relative Priority";
|
|
1796
|
+
}
|
|
1797
|
+
parseConfig(serializedData) {
|
|
1798
|
+
try {
|
|
1799
|
+
const parsed = JSON.parse(serializedData);
|
|
1800
|
+
return {
|
|
1801
|
+
tagPriorities: parsed.tagPriorities || {},
|
|
1802
|
+
defaultPriority: parsed.defaultPriority ?? DEFAULT_PRIORITY,
|
|
1803
|
+
combineMode: parsed.combineMode ?? DEFAULT_COMBINE_MODE,
|
|
1804
|
+
priorityInfluence: parsed.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE
|
|
1805
|
+
};
|
|
1806
|
+
} catch {
|
|
1807
|
+
return {
|
|
1808
|
+
tagPriorities: {},
|
|
1809
|
+
defaultPriority: DEFAULT_PRIORITY,
|
|
1810
|
+
combineMode: DEFAULT_COMBINE_MODE,
|
|
1811
|
+
priorityInfluence: DEFAULT_PRIORITY_INFLUENCE
|
|
1812
|
+
};
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
/**
|
|
1816
|
+
* Look up the priority for a tag.
|
|
1817
|
+
*/
|
|
1818
|
+
getTagPriority(tagId) {
|
|
1819
|
+
return this.config.tagPriorities[tagId] ?? this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1820
|
+
}
|
|
1821
|
+
/**
|
|
1822
|
+
* Compute combined priority for a card based on its tags.
|
|
1823
|
+
*/
|
|
1824
|
+
computeCardPriority(cardTags) {
|
|
1825
|
+
if (cardTags.length === 0) {
|
|
1826
|
+
return this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1827
|
+
}
|
|
1828
|
+
const priorities = cardTags.map((tag) => this.getTagPriority(tag));
|
|
1829
|
+
switch (this.config.combineMode) {
|
|
1830
|
+
case "max":
|
|
1831
|
+
return Math.max(...priorities);
|
|
1832
|
+
case "min":
|
|
1833
|
+
return Math.min(...priorities);
|
|
1834
|
+
case "average":
|
|
1835
|
+
return priorities.reduce((sum, p) => sum + p, 0) / priorities.length;
|
|
1836
|
+
default:
|
|
1837
|
+
return Math.max(...priorities);
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
/**
|
|
1841
|
+
* Compute boost factor based on priority.
|
|
1842
|
+
*
|
|
1843
|
+
* The formula: 1 + (priority - 0.5) * priorityInfluence
|
|
1844
|
+
*
|
|
1845
|
+
* This creates a multiplier centered around 1.0:
|
|
1846
|
+
* - Priority 1.0 with influence 0.5 → 1.25 (25% boost)
|
|
1847
|
+
* - Priority 0.5 with any influence → 1.00 (neutral)
|
|
1848
|
+
* - Priority 0.0 with influence 0.5 → 0.75 (25% reduction)
|
|
1849
|
+
*/
|
|
1850
|
+
computeBoostFactor(priority) {
|
|
1851
|
+
const influence = this.config.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE;
|
|
1852
|
+
return 1 + (priority - 0.5) * influence;
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* Build human-readable reason for priority adjustment.
|
|
1856
|
+
*/
|
|
1857
|
+
buildPriorityReason(cardTags, priority, boostFactor, finalScore) {
|
|
1858
|
+
if (cardTags.length === 0) {
|
|
1859
|
+
return `No tags, neutral priority (${priority.toFixed(2)})`;
|
|
1860
|
+
}
|
|
1861
|
+
const tagList = cardTags.slice(0, 3).join(", ");
|
|
1862
|
+
const more = cardTags.length > 3 ? ` (+${cardTags.length - 3} more)` : "";
|
|
1863
|
+
if (boostFactor === 1) {
|
|
1864
|
+
return `Neutral priority (${priority.toFixed(2)}) for tags: ${tagList}${more}`;
|
|
1865
|
+
} else if (boostFactor > 1) {
|
|
1866
|
+
return `High-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 boost ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1867
|
+
} else {
|
|
1868
|
+
return `Low-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 reduce ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
/**
|
|
1872
|
+
* CardFilter.transform implementation.
|
|
1873
|
+
*
|
|
1874
|
+
* Apply priority-adjusted scoring. Cards with high-priority tags get boosted,
|
|
1875
|
+
* cards with low-priority tags get reduced scores.
|
|
1876
|
+
*/
|
|
1877
|
+
async transform(cards, _context) {
|
|
1878
|
+
const adjusted = await Promise.all(
|
|
1879
|
+
cards.map(async (card) => {
|
|
1880
|
+
const cardTags = card.tags ?? [];
|
|
1881
|
+
const priority = this.computeCardPriority(cardTags);
|
|
1882
|
+
const boostFactor = this.computeBoostFactor(priority);
|
|
1883
|
+
const finalScore = Math.max(0, Math.min(1, card.score * boostFactor));
|
|
1884
|
+
const action = boostFactor > 1 ? "boosted" : boostFactor < 1 ? "penalized" : "passed";
|
|
1885
|
+
const reason = this.buildPriorityReason(cardTags, priority, boostFactor, finalScore);
|
|
1886
|
+
return {
|
|
1887
|
+
...card,
|
|
1888
|
+
score: finalScore,
|
|
1889
|
+
provenance: [
|
|
1890
|
+
...card.provenance,
|
|
1891
|
+
{
|
|
1892
|
+
strategy: "relativePriority",
|
|
1893
|
+
strategyName: this.strategyName || this.name,
|
|
1894
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-priority",
|
|
1895
|
+
action,
|
|
1896
|
+
score: finalScore,
|
|
1897
|
+
reason
|
|
1898
|
+
}
|
|
1899
|
+
]
|
|
1900
|
+
};
|
|
1901
|
+
})
|
|
1902
|
+
);
|
|
1903
|
+
return adjusted;
|
|
1904
|
+
}
|
|
1905
|
+
/**
|
|
1906
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1907
|
+
*
|
|
1908
|
+
* Use transform() via Pipeline instead.
|
|
876
1909
|
*/
|
|
877
1910
|
async getWeightedCards(_limit) {
|
|
878
|
-
throw new Error(
|
|
1911
|
+
throw new Error(
|
|
1912
|
+
"RelativePriorityNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1913
|
+
);
|
|
879
1914
|
}
|
|
880
1915
|
};
|
|
881
1916
|
}
|
|
882
1917
|
});
|
|
883
1918
|
|
|
1919
|
+
// src/core/navigators/filters/types.ts
|
|
1920
|
+
var types_exports2 = {};
|
|
1921
|
+
var init_types2 = __esm({
|
|
1922
|
+
"src/core/navigators/filters/types.ts"() {
|
|
1923
|
+
"use strict";
|
|
1924
|
+
}
|
|
1925
|
+
});
|
|
1926
|
+
|
|
1927
|
+
// src/core/navigators/filters/userGoalStub.ts
|
|
1928
|
+
var userGoalStub_exports = {};
|
|
1929
|
+
__export(userGoalStub_exports, {
|
|
1930
|
+
USER_GOAL_NAVIGATOR_STUB: () => USER_GOAL_NAVIGATOR_STUB
|
|
1931
|
+
});
|
|
1932
|
+
var USER_GOAL_NAVIGATOR_STUB;
|
|
1933
|
+
var init_userGoalStub = __esm({
|
|
1934
|
+
"src/core/navigators/filters/userGoalStub.ts"() {
|
|
1935
|
+
"use strict";
|
|
1936
|
+
USER_GOAL_NAVIGATOR_STUB = true;
|
|
1937
|
+
}
|
|
1938
|
+
});
|
|
1939
|
+
|
|
1940
|
+
// import("./filters/**/*") in src/core/navigators/index.ts
|
|
1941
|
+
var globImport_filters;
|
|
1942
|
+
var init_2 = __esm({
|
|
1943
|
+
'import("./filters/**/*") in src/core/navigators/index.ts'() {
|
|
1944
|
+
globImport_filters = __glob({
|
|
1945
|
+
"./filters/WeightedFilter.ts": () => Promise.resolve().then(() => (init_WeightedFilter(), WeightedFilter_exports)),
|
|
1946
|
+
"./filters/eloDistance.ts": () => Promise.resolve().then(() => (init_eloDistance(), eloDistance_exports)),
|
|
1947
|
+
"./filters/hierarchyDefinition.ts": () => Promise.resolve().then(() => (init_hierarchyDefinition(), hierarchyDefinition_exports)),
|
|
1948
|
+
"./filters/index.ts": () => Promise.resolve().then(() => (init_filters(), filters_exports)),
|
|
1949
|
+
"./filters/inferredPreferenceStub.ts": () => Promise.resolve().then(() => (init_inferredPreferenceStub(), inferredPreferenceStub_exports)),
|
|
1950
|
+
"./filters/interferenceMitigator.ts": () => Promise.resolve().then(() => (init_interferenceMitigator(), interferenceMitigator_exports)),
|
|
1951
|
+
"./filters/relativePriority.ts": () => Promise.resolve().then(() => (init_relativePriority(), relativePriority_exports)),
|
|
1952
|
+
"./filters/types.ts": () => Promise.resolve().then(() => (init_types2(), types_exports2)),
|
|
1953
|
+
"./filters/userGoalStub.ts": () => Promise.resolve().then(() => (init_userGoalStub(), userGoalStub_exports)),
|
|
1954
|
+
"./filters/userTagPreference.ts": () => Promise.resolve().then(() => (init_userTagPreference(), userTagPreference_exports))
|
|
1955
|
+
});
|
|
1956
|
+
}
|
|
1957
|
+
});
|
|
1958
|
+
|
|
1959
|
+
// src/core/orchestration/gradient.ts
|
|
1960
|
+
function aggregateOutcomesForGradient(outcomes, strategyId) {
|
|
1961
|
+
const observations = [];
|
|
1962
|
+
for (const outcome of outcomes) {
|
|
1963
|
+
const deviation = outcome.deviations[strategyId];
|
|
1964
|
+
if (deviation === void 0) {
|
|
1965
|
+
continue;
|
|
1966
|
+
}
|
|
1967
|
+
observations.push({
|
|
1968
|
+
deviation,
|
|
1969
|
+
outcomeValue: outcome.outcomeValue,
|
|
1970
|
+
weight: 1
|
|
1971
|
+
});
|
|
1972
|
+
}
|
|
1973
|
+
logger.debug(
|
|
1974
|
+
`[Orchestration] Aggregated ${observations.length} observations for strategy ${strategyId}`
|
|
1975
|
+
);
|
|
1976
|
+
return observations;
|
|
1977
|
+
}
|
|
1978
|
+
function computeStrategyGradient(observations) {
|
|
1979
|
+
const n = observations.length;
|
|
1980
|
+
if (n < 3) {
|
|
1981
|
+
logger.debug(`[Orchestration] Insufficient observations for gradient (${n} < 3)`);
|
|
1982
|
+
return null;
|
|
1983
|
+
}
|
|
1984
|
+
let sumX = 0;
|
|
1985
|
+
let sumY = 0;
|
|
1986
|
+
let sumW = 0;
|
|
1987
|
+
for (const obs of observations) {
|
|
1988
|
+
const w = obs.weight ?? 1;
|
|
1989
|
+
sumX += obs.deviation * w;
|
|
1990
|
+
sumY += obs.outcomeValue * w;
|
|
1991
|
+
sumW += w;
|
|
1992
|
+
}
|
|
1993
|
+
const meanX = sumX / sumW;
|
|
1994
|
+
const meanY = sumY / sumW;
|
|
1995
|
+
let numerator = 0;
|
|
1996
|
+
let denominator = 0;
|
|
1997
|
+
let ssTotal = 0;
|
|
1998
|
+
for (const obs of observations) {
|
|
1999
|
+
const w = obs.weight ?? 1;
|
|
2000
|
+
const dx = obs.deviation - meanX;
|
|
2001
|
+
const dy = obs.outcomeValue - meanY;
|
|
2002
|
+
numerator += w * dx * dy;
|
|
2003
|
+
denominator += w * dx * dx;
|
|
2004
|
+
ssTotal += w * dy * dy;
|
|
2005
|
+
}
|
|
2006
|
+
if (denominator < 1e-10) {
|
|
2007
|
+
logger.debug(`[Orchestration] No variance in deviations, cannot compute gradient`);
|
|
2008
|
+
return {
|
|
2009
|
+
gradient: 0,
|
|
2010
|
+
intercept: meanY,
|
|
2011
|
+
rSquared: 0,
|
|
2012
|
+
sampleSize: n
|
|
2013
|
+
};
|
|
2014
|
+
}
|
|
2015
|
+
const gradient = numerator / denominator;
|
|
2016
|
+
const intercept = meanY - gradient * meanX;
|
|
2017
|
+
let ssResidual = 0;
|
|
2018
|
+
for (const obs of observations) {
|
|
2019
|
+
const w = obs.weight ?? 1;
|
|
2020
|
+
const predicted = gradient * obs.deviation + intercept;
|
|
2021
|
+
const residual = obs.outcomeValue - predicted;
|
|
2022
|
+
ssResidual += w * residual * residual;
|
|
2023
|
+
}
|
|
2024
|
+
const rSquared = ssTotal > 1e-10 ? 1 - ssResidual / ssTotal : 0;
|
|
2025
|
+
logger.debug(
|
|
2026
|
+
`[Orchestration] Computed gradient: ${gradient.toFixed(4)}, intercept: ${intercept.toFixed(4)}, R\xB2: ${rSquared.toFixed(4)}, n=${n}`
|
|
2027
|
+
);
|
|
2028
|
+
return {
|
|
2029
|
+
gradient,
|
|
2030
|
+
intercept,
|
|
2031
|
+
rSquared: Math.max(0, Math.min(1, rSquared)),
|
|
2032
|
+
// Clamp to [0,1]
|
|
2033
|
+
sampleSize: n
|
|
2034
|
+
};
|
|
2035
|
+
}
|
|
2036
|
+
var init_gradient = __esm({
|
|
2037
|
+
"src/core/orchestration/gradient.ts"() {
|
|
2038
|
+
"use strict";
|
|
2039
|
+
init_logger();
|
|
2040
|
+
}
|
|
2041
|
+
});
|
|
2042
|
+
|
|
2043
|
+
// src/core/orchestration/learning.ts
|
|
2044
|
+
function updateStrategyWeight(current, gradient) {
|
|
2045
|
+
if (gradient.sampleSize < MIN_OBSERVATIONS_FOR_UPDATE) {
|
|
2046
|
+
logger.debug(
|
|
2047
|
+
`[Orchestration] Insufficient samples (${gradient.sampleSize} < ${MIN_OBSERVATIONS_FOR_UPDATE}), keeping current weight`
|
|
2048
|
+
);
|
|
2049
|
+
return {
|
|
2050
|
+
...current,
|
|
2051
|
+
sampleSize: current.sampleSize + gradient.sampleSize
|
|
2052
|
+
};
|
|
2053
|
+
}
|
|
2054
|
+
const isReliable = gradient.rSquared >= MIN_R_SQUARED_FOR_GRADIENT;
|
|
2055
|
+
const isFlat = Math.abs(gradient.gradient) < FLAT_GRADIENT_THRESHOLD;
|
|
2056
|
+
let newWeight = current.weight;
|
|
2057
|
+
let newConfidence = current.confidence;
|
|
2058
|
+
if (!isReliable || isFlat) {
|
|
2059
|
+
const confidenceGain = 0.05 * (1 - current.confidence);
|
|
2060
|
+
newConfidence = Math.min(1, current.confidence + confidenceGain);
|
|
2061
|
+
logger.debug(
|
|
2062
|
+
`[Orchestration] Flat/unreliable gradient (|g|=${Math.abs(gradient.gradient).toFixed(4)}, R\xB2=${gradient.rSquared.toFixed(4)}). Increasing confidence: ${current.confidence.toFixed(3)} \u2192 ${newConfidence.toFixed(3)}`
|
|
2063
|
+
);
|
|
2064
|
+
} else {
|
|
2065
|
+
let delta = gradient.gradient * LEARNING_RATE;
|
|
2066
|
+
delta = Math.max(-MAX_WEIGHT_DELTA, Math.min(MAX_WEIGHT_DELTA, delta));
|
|
2067
|
+
newWeight = current.weight + delta;
|
|
2068
|
+
newWeight = Math.max(0.1, Math.min(3, newWeight));
|
|
2069
|
+
const confidenceGain = 0.02 * (1 - current.confidence);
|
|
2070
|
+
newConfidence = Math.min(1, current.confidence + confidenceGain);
|
|
2071
|
+
logger.debug(
|
|
2072
|
+
`[Orchestration] Adjusting weight: ${current.weight.toFixed(3)} \u2192 ${newWeight.toFixed(3)} (gradient=${gradient.gradient.toFixed(4)}, delta=${delta.toFixed(4)})`
|
|
2073
|
+
);
|
|
2074
|
+
}
|
|
2075
|
+
return {
|
|
2076
|
+
weight: newWeight,
|
|
2077
|
+
confidence: newConfidence,
|
|
2078
|
+
sampleSize: current.sampleSize + gradient.sampleSize
|
|
2079
|
+
};
|
|
2080
|
+
}
|
|
2081
|
+
function updateLearningState(courseId, strategyId, currentWeight, gradient, existing) {
|
|
2082
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2083
|
+
const id = `STRATEGY_LEARNING_STATE::${courseId}::${strategyId}`;
|
|
2084
|
+
const historyEntry = {
|
|
2085
|
+
timestamp: now,
|
|
2086
|
+
weight: currentWeight.weight,
|
|
2087
|
+
confidence: currentWeight.confidence,
|
|
2088
|
+
gradient: gradient.gradient
|
|
2089
|
+
};
|
|
2090
|
+
let history = existing?.history ?? [];
|
|
2091
|
+
history = [...history, historyEntry];
|
|
2092
|
+
if (history.length > MAX_HISTORY_LENGTH) {
|
|
2093
|
+
history = history.slice(history.length - MAX_HISTORY_LENGTH);
|
|
2094
|
+
}
|
|
2095
|
+
const state = {
|
|
2096
|
+
_id: id,
|
|
2097
|
+
_rev: existing?._rev,
|
|
2098
|
+
docType: "STRATEGY_LEARNING_STATE" /* STRATEGY_LEARNING_STATE */,
|
|
2099
|
+
courseId,
|
|
2100
|
+
strategyId,
|
|
2101
|
+
currentWeight,
|
|
2102
|
+
regression: {
|
|
2103
|
+
gradient: gradient.gradient,
|
|
2104
|
+
intercept: gradient.intercept,
|
|
2105
|
+
rSquared: gradient.rSquared,
|
|
2106
|
+
sampleSize: gradient.sampleSize,
|
|
2107
|
+
computedAt: now
|
|
2108
|
+
},
|
|
2109
|
+
history,
|
|
2110
|
+
updatedAt: now
|
|
2111
|
+
};
|
|
2112
|
+
return state;
|
|
2113
|
+
}
|
|
2114
|
+
function runPeriodUpdate(input) {
|
|
2115
|
+
const { courseId, strategyId, currentWeight, gradient, existingState } = input;
|
|
2116
|
+
logger.info(
|
|
2117
|
+
`[Orchestration] Running period update for strategy ${strategyId} (${gradient.sampleSize} observations)`
|
|
2118
|
+
);
|
|
2119
|
+
const newWeight = updateStrategyWeight(currentWeight, gradient);
|
|
2120
|
+
const updated = newWeight.weight !== currentWeight.weight;
|
|
2121
|
+
const learningState = updateLearningState(
|
|
2122
|
+
courseId,
|
|
2123
|
+
strategyId,
|
|
2124
|
+
newWeight,
|
|
2125
|
+
gradient,
|
|
2126
|
+
existingState
|
|
2127
|
+
);
|
|
2128
|
+
logger.info(
|
|
2129
|
+
`[Orchestration] Period update complete for ${strategyId}: weight ${currentWeight.weight.toFixed(3)} \u2192 ${newWeight.weight.toFixed(3)}, confidence ${currentWeight.confidence.toFixed(3)} \u2192 ${newWeight.confidence.toFixed(3)}`
|
|
2130
|
+
);
|
|
2131
|
+
return {
|
|
2132
|
+
strategyId,
|
|
2133
|
+
previousWeight: currentWeight,
|
|
2134
|
+
newWeight,
|
|
2135
|
+
gradient,
|
|
2136
|
+
learningState,
|
|
2137
|
+
updated
|
|
2138
|
+
};
|
|
2139
|
+
}
|
|
2140
|
+
function getDefaultLearnableWeight() {
|
|
2141
|
+
return { ...DEFAULT_LEARNABLE_WEIGHT };
|
|
2142
|
+
}
|
|
2143
|
+
var MIN_OBSERVATIONS_FOR_UPDATE, LEARNING_RATE, MAX_WEIGHT_DELTA, MIN_R_SQUARED_FOR_GRADIENT, FLAT_GRADIENT_THRESHOLD, MAX_HISTORY_LENGTH;
|
|
2144
|
+
var init_learning = __esm({
|
|
2145
|
+
"src/core/orchestration/learning.ts"() {
|
|
2146
|
+
"use strict";
|
|
2147
|
+
init_contentNavigationStrategy();
|
|
2148
|
+
init_types_legacy();
|
|
2149
|
+
init_logger();
|
|
2150
|
+
MIN_OBSERVATIONS_FOR_UPDATE = 10;
|
|
2151
|
+
LEARNING_RATE = 0.1;
|
|
2152
|
+
MAX_WEIGHT_DELTA = 0.3;
|
|
2153
|
+
MIN_R_SQUARED_FOR_GRADIENT = 0.05;
|
|
2154
|
+
FLAT_GRADIENT_THRESHOLD = 0.02;
|
|
2155
|
+
MAX_HISTORY_LENGTH = 100;
|
|
2156
|
+
}
|
|
2157
|
+
});
|
|
2158
|
+
|
|
2159
|
+
// src/core/orchestration/signal.ts
|
|
2160
|
+
function computeOutcomeSignal(records, config = {}) {
|
|
2161
|
+
if (!records || records.length === 0) {
|
|
2162
|
+
return null;
|
|
2163
|
+
}
|
|
2164
|
+
const target = config.targetAccuracy ?? 0.85;
|
|
2165
|
+
const tolerance = config.tolerance ?? 0.05;
|
|
2166
|
+
let correct = 0;
|
|
2167
|
+
for (const r of records) {
|
|
2168
|
+
if (r.isCorrect) correct++;
|
|
2169
|
+
}
|
|
2170
|
+
const accuracy = correct / records.length;
|
|
2171
|
+
return scoreAccuracyInZone(accuracy, target, tolerance);
|
|
2172
|
+
}
|
|
2173
|
+
function scoreAccuracyInZone(accuracy, target, tolerance) {
|
|
2174
|
+
const dist = Math.abs(accuracy - target);
|
|
2175
|
+
if (dist <= tolerance) {
|
|
2176
|
+
return 1;
|
|
2177
|
+
}
|
|
2178
|
+
const excess = dist - tolerance;
|
|
2179
|
+
const slope = 2.5;
|
|
2180
|
+
return Math.max(0, 1 - excess * slope);
|
|
2181
|
+
}
|
|
2182
|
+
var init_signal = __esm({
|
|
2183
|
+
"src/core/orchestration/signal.ts"() {
|
|
2184
|
+
"use strict";
|
|
2185
|
+
}
|
|
2186
|
+
});
|
|
2187
|
+
|
|
2188
|
+
// src/core/orchestration/recording.ts
|
|
2189
|
+
async function recordUserOutcome(context, periodStart, periodEnd, records, activeStrategyIds, eloStart = 0, eloEnd = 0, config) {
|
|
2190
|
+
const { user, course, userId } = context;
|
|
2191
|
+
const courseId = course.getCourseID();
|
|
2192
|
+
const outcomeValue = computeOutcomeSignal(records, config);
|
|
2193
|
+
if (outcomeValue === null) {
|
|
2194
|
+
logger.debug(
|
|
2195
|
+
`[Orchestration] No outcome signal computed for ${userId} (insufficient data). Skipping record.`
|
|
2196
|
+
);
|
|
2197
|
+
return;
|
|
2198
|
+
}
|
|
2199
|
+
const deviations = {};
|
|
2200
|
+
for (const strategyId of activeStrategyIds) {
|
|
2201
|
+
deviations[strategyId] = context.getDeviation(strategyId);
|
|
2202
|
+
}
|
|
2203
|
+
const id = `USER_OUTCOME::${courseId}::${userId}::${periodEnd}`;
|
|
2204
|
+
const record = {
|
|
2205
|
+
_id: id,
|
|
2206
|
+
docType: "USER_OUTCOME" /* USER_OUTCOME */,
|
|
2207
|
+
courseId,
|
|
2208
|
+
userId,
|
|
2209
|
+
periodStart,
|
|
2210
|
+
periodEnd,
|
|
2211
|
+
outcomeValue,
|
|
2212
|
+
deviations,
|
|
2213
|
+
metadata: {
|
|
2214
|
+
sessionsCount: 1,
|
|
2215
|
+
// Assumes recording is triggered per-session currently
|
|
2216
|
+
cardsSeen: records.length,
|
|
2217
|
+
eloStart,
|
|
2218
|
+
eloEnd,
|
|
2219
|
+
signalType: "accuracy_in_zone"
|
|
2220
|
+
}
|
|
2221
|
+
};
|
|
2222
|
+
try {
|
|
2223
|
+
await user.putUserOutcome(record);
|
|
2224
|
+
logger.debug(
|
|
2225
|
+
`[Orchestration] Recorded outcome ${outcomeValue.toFixed(3)} for ${userId} (doc: ${id})`
|
|
2226
|
+
);
|
|
2227
|
+
} catch (e) {
|
|
2228
|
+
logger.error(`[Orchestration] Failed to record outcome: ${e}`);
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2231
|
+
var init_recording = __esm({
|
|
2232
|
+
"src/core/orchestration/recording.ts"() {
|
|
2233
|
+
"use strict";
|
|
2234
|
+
init_signal();
|
|
2235
|
+
init_types_legacy();
|
|
2236
|
+
init_logger();
|
|
2237
|
+
}
|
|
2238
|
+
});
|
|
2239
|
+
|
|
2240
|
+
// src/core/orchestration/index.ts
|
|
2241
|
+
function fnv1a(str) {
|
|
2242
|
+
let hash = 2166136261;
|
|
2243
|
+
for (let i = 0; i < str.length; i++) {
|
|
2244
|
+
hash ^= str.charCodeAt(i);
|
|
2245
|
+
hash = Math.imul(hash, 16777619);
|
|
2246
|
+
}
|
|
2247
|
+
return hash >>> 0;
|
|
2248
|
+
}
|
|
2249
|
+
function computeDeviation(userId, strategyId, salt) {
|
|
2250
|
+
const input = `${userId}:${strategyId}:${salt}`;
|
|
2251
|
+
const hash = fnv1a(input);
|
|
2252
|
+
const normalized = hash / 4294967296;
|
|
2253
|
+
return normalized * 2 - 1;
|
|
2254
|
+
}
|
|
2255
|
+
function computeSpread(confidence) {
|
|
2256
|
+
const clampedConfidence = Math.max(0, Math.min(1, confidence));
|
|
2257
|
+
return MAX_SPREAD - clampedConfidence * (MAX_SPREAD - MIN_SPREAD);
|
|
2258
|
+
}
|
|
2259
|
+
function computeEffectiveWeight(learnable, userId, strategyId, salt) {
|
|
2260
|
+
const deviation = computeDeviation(userId, strategyId, salt);
|
|
2261
|
+
const spread = computeSpread(learnable.confidence);
|
|
2262
|
+
const adjustment = deviation * spread * learnable.weight;
|
|
2263
|
+
const effective = learnable.weight + adjustment;
|
|
2264
|
+
return Math.max(MIN_WEIGHT, Math.min(MAX_WEIGHT, effective));
|
|
2265
|
+
}
|
|
2266
|
+
async function createOrchestrationContext(user, course) {
|
|
2267
|
+
let courseConfig;
|
|
2268
|
+
try {
|
|
2269
|
+
courseConfig = await course.getCourseConfig();
|
|
2270
|
+
} catch (e) {
|
|
2271
|
+
logger.error(`[Orchestration] Failed to load course config: ${e}`);
|
|
2272
|
+
courseConfig = {
|
|
2273
|
+
name: "Unknown",
|
|
2274
|
+
description: "",
|
|
2275
|
+
public: false,
|
|
2276
|
+
deleted: false,
|
|
2277
|
+
creator: "",
|
|
2278
|
+
admins: [],
|
|
2279
|
+
moderators: [],
|
|
2280
|
+
dataShapes: [],
|
|
2281
|
+
questionTypes: [],
|
|
2282
|
+
orchestration: { salt: "default" }
|
|
2283
|
+
};
|
|
2284
|
+
}
|
|
2285
|
+
const userId = user.getUsername();
|
|
2286
|
+
const salt = courseConfig.orchestration?.salt || "default_salt";
|
|
2287
|
+
return {
|
|
2288
|
+
user,
|
|
2289
|
+
course,
|
|
2290
|
+
userId,
|
|
2291
|
+
courseConfig,
|
|
2292
|
+
getEffectiveWeight(strategyId, learnable) {
|
|
2293
|
+
return computeEffectiveWeight(learnable, userId, strategyId, salt);
|
|
2294
|
+
},
|
|
2295
|
+
getDeviation(strategyId) {
|
|
2296
|
+
return computeDeviation(userId, strategyId, salt);
|
|
2297
|
+
}
|
|
2298
|
+
};
|
|
2299
|
+
}
|
|
2300
|
+
var MIN_SPREAD, MAX_SPREAD, MIN_WEIGHT, MAX_WEIGHT;
|
|
2301
|
+
var init_orchestration = __esm({
|
|
2302
|
+
"src/core/orchestration/index.ts"() {
|
|
2303
|
+
"use strict";
|
|
2304
|
+
init_logger();
|
|
2305
|
+
init_gradient();
|
|
2306
|
+
init_learning();
|
|
2307
|
+
init_signal();
|
|
2308
|
+
init_recording();
|
|
2309
|
+
MIN_SPREAD = 0.1;
|
|
2310
|
+
MAX_SPREAD = 0.5;
|
|
2311
|
+
MIN_WEIGHT = 0.1;
|
|
2312
|
+
MAX_WEIGHT = 3;
|
|
2313
|
+
}
|
|
2314
|
+
});
|
|
2315
|
+
|
|
884
2316
|
// src/core/navigators/Pipeline.ts
|
|
2317
|
+
var Pipeline_exports = {};
|
|
2318
|
+
__export(Pipeline_exports, {
|
|
2319
|
+
Pipeline: () => Pipeline
|
|
2320
|
+
});
|
|
885
2321
|
function logPipelineConfig(generator, filters) {
|
|
886
2322
|
const filterList = filters.length > 0 ? "\n - " + filters.map((f) => f.name).join("\n - ") : " none";
|
|
887
2323
|
logger.info(
|
|
@@ -917,13 +2353,14 @@ function logCardProvenance(cards, maxCards = 3) {
|
|
|
917
2353
|
}
|
|
918
2354
|
}
|
|
919
2355
|
}
|
|
920
|
-
var
|
|
2356
|
+
var import_common8, Pipeline;
|
|
921
2357
|
var init_Pipeline = __esm({
|
|
922
2358
|
"src/core/navigators/Pipeline.ts"() {
|
|
923
2359
|
"use strict";
|
|
924
|
-
|
|
2360
|
+
import_common8 = require("@vue-skuilder/common");
|
|
925
2361
|
init_navigators();
|
|
926
2362
|
init_logger();
|
|
2363
|
+
init_orchestration();
|
|
927
2364
|
Pipeline = class extends ContentNavigator {
|
|
928
2365
|
generator;
|
|
929
2366
|
filters;
|
|
@@ -1017,180 +2454,79 @@ var init_Pipeline = __esm({
|
|
|
1017
2454
|
/**
|
|
1018
2455
|
* Build shared context for generator and filters.
|
|
1019
2456
|
*
|
|
1020
|
-
* Called once per getWeightedCards() invocation.
|
|
1021
|
-
* Contains data that the generator and multiple filters might need.
|
|
1022
|
-
*
|
|
1023
|
-
* The context satisfies both GeneratorContext and FilterContext interfaces.
|
|
1024
|
-
*/
|
|
1025
|
-
async buildContext() {
|
|
1026
|
-
let userElo = 1e3;
|
|
1027
|
-
try {
|
|
1028
|
-
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
1029
|
-
const courseElo = (0,
|
|
1030
|
-
userElo = courseElo.global.score;
|
|
1031
|
-
} catch (e) {
|
|
1032
|
-
logger.debug(`[Pipeline] Could not get user ELO, using default: ${e}`);
|
|
1033
|
-
}
|
|
1034
|
-
return {
|
|
1035
|
-
user: this.user,
|
|
1036
|
-
course: this.course,
|
|
1037
|
-
userElo
|
|
1038
|
-
};
|
|
1039
|
-
}
|
|
1040
|
-
/**
|
|
1041
|
-
* Get the course ID for this pipeline.
|
|
1042
|
-
*/
|
|
1043
|
-
getCourseID() {
|
|
1044
|
-
return this.course.getCourseID();
|
|
1045
|
-
}
|
|
1046
|
-
};
|
|
1047
|
-
}
|
|
1048
|
-
});
|
|
1049
|
-
|
|
1050
|
-
// src/core/navigators/generators/CompositeGenerator.ts
|
|
1051
|
-
var DEFAULT_AGGREGATION_MODE, FREQUENCY_BOOST_FACTOR, CompositeGenerator;
|
|
1052
|
-
var init_CompositeGenerator = __esm({
|
|
1053
|
-
"src/core/navigators/generators/CompositeGenerator.ts"() {
|
|
1054
|
-
"use strict";
|
|
1055
|
-
init_navigators();
|
|
1056
|
-
init_logger();
|
|
1057
|
-
DEFAULT_AGGREGATION_MODE = "frequencyBoost" /* FREQUENCY_BOOST */;
|
|
1058
|
-
FREQUENCY_BOOST_FACTOR = 0.1;
|
|
1059
|
-
CompositeGenerator = class _CompositeGenerator extends ContentNavigator {
|
|
1060
|
-
/** Human-readable name for CardGenerator interface */
|
|
1061
|
-
name = "Composite Generator";
|
|
1062
|
-
generators;
|
|
1063
|
-
aggregationMode;
|
|
1064
|
-
constructor(generators, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
1065
|
-
super();
|
|
1066
|
-
this.generators = generators;
|
|
1067
|
-
this.aggregationMode = aggregationMode;
|
|
1068
|
-
if (generators.length === 0) {
|
|
1069
|
-
throw new Error("CompositeGenerator requires at least one generator");
|
|
1070
|
-
}
|
|
1071
|
-
logger.debug(
|
|
1072
|
-
`[CompositeGenerator] Created with ${generators.length} generators, mode: ${aggregationMode}`
|
|
1073
|
-
);
|
|
1074
|
-
}
|
|
1075
|
-
/**
|
|
1076
|
-
* Creates a CompositeGenerator from strategy data.
|
|
1077
|
-
*
|
|
1078
|
-
* This is a convenience factory for use by PipelineAssembler.
|
|
1079
|
-
*/
|
|
1080
|
-
static async fromStrategies(user, course, strategies, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
1081
|
-
const generators = await Promise.all(
|
|
1082
|
-
strategies.map((s) => ContentNavigator.create(user, course, s))
|
|
1083
|
-
);
|
|
1084
|
-
return new _CompositeGenerator(generators, aggregationMode);
|
|
1085
|
-
}
|
|
1086
|
-
/**
|
|
1087
|
-
* Get weighted cards from all generators, merge and deduplicate.
|
|
1088
|
-
*
|
|
1089
|
-
* Cards appearing in multiple generators receive a score boost.
|
|
1090
|
-
* Provenance tracks which generators produced each card and how scores were aggregated.
|
|
1091
|
-
*
|
|
1092
|
-
* This method supports both the legacy signature (limit only) and the
|
|
1093
|
-
* CardGenerator interface signature (limit, context).
|
|
1094
|
-
*
|
|
1095
|
-
* @param limit - Maximum number of cards to return
|
|
1096
|
-
* @param context - GeneratorContext passed to child generators (required when called via Pipeline)
|
|
1097
|
-
*/
|
|
1098
|
-
async getWeightedCards(limit, context) {
|
|
1099
|
-
if (!context) {
|
|
1100
|
-
throw new Error(
|
|
1101
|
-
"CompositeGenerator.getWeightedCards requires a GeneratorContext. It should be called via Pipeline, not directly."
|
|
1102
|
-
);
|
|
1103
|
-
}
|
|
1104
|
-
const results = await Promise.all(
|
|
1105
|
-
this.generators.map((g) => g.getWeightedCards(limit, context))
|
|
1106
|
-
);
|
|
1107
|
-
const byCardId = /* @__PURE__ */ new Map();
|
|
1108
|
-
for (const cards of results) {
|
|
1109
|
-
for (const card of cards) {
|
|
1110
|
-
const existing = byCardId.get(card.cardId) || [];
|
|
1111
|
-
existing.push(card);
|
|
1112
|
-
byCardId.set(card.cardId, existing);
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
const merged = [];
|
|
1116
|
-
for (const [, cards] of byCardId) {
|
|
1117
|
-
const aggregatedScore = this.aggregateScores(cards);
|
|
1118
|
-
const finalScore = Math.min(1, aggregatedScore);
|
|
1119
|
-
const mergedProvenance = cards.flatMap((c) => c.provenance);
|
|
1120
|
-
const initialScore = cards[0].score;
|
|
1121
|
-
const action = finalScore > initialScore ? "boosted" : finalScore < initialScore ? "penalized" : "passed";
|
|
1122
|
-
const reason = this.buildAggregationReason(cards, finalScore);
|
|
1123
|
-
merged.push({
|
|
1124
|
-
...cards[0],
|
|
1125
|
-
score: finalScore,
|
|
1126
|
-
provenance: [
|
|
1127
|
-
...mergedProvenance,
|
|
1128
|
-
{
|
|
1129
|
-
strategy: "composite",
|
|
1130
|
-
strategyName: "Composite Generator",
|
|
1131
|
-
strategyId: "COMPOSITE_GENERATOR",
|
|
1132
|
-
action,
|
|
1133
|
-
score: finalScore,
|
|
1134
|
-
reason
|
|
1135
|
-
}
|
|
1136
|
-
]
|
|
1137
|
-
});
|
|
2457
|
+
* Called once per getWeightedCards() invocation.
|
|
2458
|
+
* Contains data that the generator and multiple filters might need.
|
|
2459
|
+
*
|
|
2460
|
+
* The context satisfies both GeneratorContext and FilterContext interfaces.
|
|
2461
|
+
*/
|
|
2462
|
+
async buildContext() {
|
|
2463
|
+
let userElo = 1e3;
|
|
2464
|
+
try {
|
|
2465
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
2466
|
+
const courseElo = (0, import_common8.toCourseElo)(courseReg.elo);
|
|
2467
|
+
userElo = courseElo.global.score;
|
|
2468
|
+
} catch (e) {
|
|
2469
|
+
logger.debug(`[Pipeline] Could not get user ELO, using default: ${e}`);
|
|
1138
2470
|
}
|
|
1139
|
-
|
|
2471
|
+
const orchestration = await createOrchestrationContext(this.user, this.course);
|
|
2472
|
+
return {
|
|
2473
|
+
user: this.user,
|
|
2474
|
+
course: this.course,
|
|
2475
|
+
userElo,
|
|
2476
|
+
orchestration
|
|
2477
|
+
};
|
|
1140
2478
|
}
|
|
1141
2479
|
/**
|
|
1142
|
-
*
|
|
2480
|
+
* Get the course ID for this pipeline.
|
|
1143
2481
|
*/
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
const scores = cards.map((c) => c.score.toFixed(2)).join(", ");
|
|
1147
|
-
if (count === 1) {
|
|
1148
|
-
return `Single generator, score ${finalScore.toFixed(2)}`;
|
|
1149
|
-
}
|
|
1150
|
-
const strategies = cards.map((c) => c.provenance[0]?.strategy || "unknown").join(", ");
|
|
1151
|
-
switch (this.aggregationMode) {
|
|
1152
|
-
case "max" /* MAX */:
|
|
1153
|
-
return `Max of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
1154
|
-
case "average" /* AVERAGE */:
|
|
1155
|
-
return `Average of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
1156
|
-
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
1157
|
-
const avg = cards.reduce((sum, c) => sum + c.score, 0) / count;
|
|
1158
|
-
const boost = 1 + FREQUENCY_BOOST_FACTOR * (count - 1);
|
|
1159
|
-
return `Frequency boost from ${count} generators (${strategies}): avg ${avg.toFixed(2)} \xD7 ${boost.toFixed(2)} \u2192 ${finalScore.toFixed(2)}`;
|
|
1160
|
-
}
|
|
1161
|
-
default:
|
|
1162
|
-
return `Aggregated from ${count} generators: ${finalScore.toFixed(2)}`;
|
|
1163
|
-
}
|
|
2482
|
+
getCourseID() {
|
|
2483
|
+
return this.course.getCourseID();
|
|
1164
2484
|
}
|
|
1165
2485
|
/**
|
|
1166
|
-
*
|
|
2486
|
+
* Get orchestration context for outcome recording.
|
|
1167
2487
|
*/
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
2488
|
+
async getOrchestrationContext() {
|
|
2489
|
+
return createOrchestrationContext(this.user, this.course);
|
|
2490
|
+
}
|
|
2491
|
+
/**
|
|
2492
|
+
* Get IDs of all strategies in this pipeline.
|
|
2493
|
+
* Used to record which strategies contributed to an outcome.
|
|
2494
|
+
*/
|
|
2495
|
+
getStrategyIds() {
|
|
2496
|
+
const ids = [];
|
|
2497
|
+
const extractId = (obj) => {
|
|
2498
|
+
if (obj.strategyId) return obj.strategyId;
|
|
2499
|
+
return null;
|
|
2500
|
+
};
|
|
2501
|
+
const genId = extractId(this.generator);
|
|
2502
|
+
if (genId) ids.push(genId);
|
|
2503
|
+
if (this.generator.generators && Array.isArray(this.generator.generators)) {
|
|
2504
|
+
this.generator.generators.forEach((g) => {
|
|
2505
|
+
const subId = extractId(g);
|
|
2506
|
+
if (subId) ids.push(subId);
|
|
2507
|
+
});
|
|
2508
|
+
}
|
|
2509
|
+
for (const filter of this.filters) {
|
|
2510
|
+
const fId = extractId(filter);
|
|
2511
|
+
if (fId) ids.push(fId);
|
|
1182
2512
|
}
|
|
2513
|
+
return [...new Set(ids)];
|
|
1183
2514
|
}
|
|
1184
2515
|
};
|
|
1185
2516
|
}
|
|
1186
2517
|
});
|
|
1187
2518
|
|
|
1188
2519
|
// src/core/navigators/PipelineAssembler.ts
|
|
2520
|
+
var PipelineAssembler_exports = {};
|
|
2521
|
+
__export(PipelineAssembler_exports, {
|
|
2522
|
+
PipelineAssembler: () => PipelineAssembler
|
|
2523
|
+
});
|
|
1189
2524
|
var PipelineAssembler;
|
|
1190
2525
|
var init_PipelineAssembler = __esm({
|
|
1191
2526
|
"src/core/navigators/PipelineAssembler.ts"() {
|
|
1192
2527
|
"use strict";
|
|
1193
2528
|
init_navigators();
|
|
2529
|
+
init_WeightedFilter();
|
|
1194
2530
|
init_Pipeline();
|
|
1195
2531
|
init_types_legacy();
|
|
1196
2532
|
init_logger();
|
|
@@ -1265,7 +2601,16 @@ var init_PipelineAssembler = __esm({
|
|
|
1265
2601
|
try {
|
|
1266
2602
|
const nav = await ContentNavigator.create(user, course, filterStrategy);
|
|
1267
2603
|
if ("transform" in nav && typeof nav.transform === "function") {
|
|
1268
|
-
|
|
2604
|
+
let filter = nav;
|
|
2605
|
+
if (filterStrategy.learnable) {
|
|
2606
|
+
filter = new WeightedFilter(
|
|
2607
|
+
filter,
|
|
2608
|
+
filterStrategy.learnable,
|
|
2609
|
+
filterStrategy.staticWeight,
|
|
2610
|
+
filterStrategy._id
|
|
2611
|
+
);
|
|
2612
|
+
}
|
|
2613
|
+
filters.push(filter);
|
|
1269
2614
|
logger.debug(`[PipelineAssembler] Added filter: ${filterStrategy.name}`);
|
|
1270
2615
|
} else {
|
|
1271
2616
|
warnings.push(
|
|
@@ -1290,238 +2635,29 @@ var init_PipelineAssembler = __esm({
|
|
|
1290
2635
|
/**
|
|
1291
2636
|
* Creates a default ELO generator strategy.
|
|
1292
2637
|
* Used when filters are configured but no generator is specified.
|
|
1293
|
-
*/
|
|
1294
|
-
makeDefaultEloStrategy(courseId) {
|
|
1295
|
-
return {
|
|
1296
|
-
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
1297
|
-
course: courseId,
|
|
1298
|
-
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1299
|
-
name: "ELO (default)",
|
|
1300
|
-
description: "Default ELO-based generator",
|
|
1301
|
-
implementingClass: "elo" /* ELO */,
|
|
1302
|
-
serializedData: ""
|
|
1303
|
-
};
|
|
1304
|
-
}
|
|
1305
|
-
};
|
|
1306
|
-
}
|
|
1307
|
-
});
|
|
1308
|
-
|
|
1309
|
-
// src/core/navigators/generators/elo.ts
|
|
1310
|
-
var import_common6, ELONavigator;
|
|
1311
|
-
var init_elo = __esm({
|
|
1312
|
-
"src/core/navigators/generators/elo.ts"() {
|
|
1313
|
-
"use strict";
|
|
1314
|
-
init_navigators();
|
|
1315
|
-
import_common6 = require("@vue-skuilder/common");
|
|
1316
|
-
ELONavigator = class extends ContentNavigator {
|
|
1317
|
-
/** Human-readable name for CardGenerator interface */
|
|
1318
|
-
name;
|
|
1319
|
-
constructor(user, course, strategyData) {
|
|
1320
|
-
super(user, course, strategyData);
|
|
1321
|
-
this.name = strategyData?.name || "ELO";
|
|
1322
|
-
}
|
|
1323
|
-
/**
|
|
1324
|
-
* Get new cards with suitability scores based on ELO distance.
|
|
1325
|
-
*
|
|
1326
|
-
* Cards closer to user's ELO get higher scores.
|
|
1327
|
-
* Score formula: max(0, 1 - distance / 500)
|
|
1328
|
-
*
|
|
1329
|
-
* NOTE: This generator only handles NEW cards. Reviews are handled by
|
|
1330
|
-
* SRSNavigator. Use CompositeGenerator to combine both.
|
|
1331
|
-
*
|
|
1332
|
-
* This method supports both the legacy signature (limit only) and the
|
|
1333
|
-
* CardGenerator interface signature (limit, context).
|
|
1334
|
-
*
|
|
1335
|
-
* @param limit - Maximum number of cards to return
|
|
1336
|
-
* @param context - Optional GeneratorContext (used when called via Pipeline)
|
|
1337
|
-
*/
|
|
1338
|
-
async getWeightedCards(limit, context) {
|
|
1339
|
-
let userGlobalElo;
|
|
1340
|
-
if (context?.userElo !== void 0) {
|
|
1341
|
-
userGlobalElo = context.userElo;
|
|
1342
|
-
} else {
|
|
1343
|
-
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
1344
|
-
const userElo = (0, import_common6.toCourseElo)(courseReg.elo);
|
|
1345
|
-
userGlobalElo = userElo.global.score;
|
|
1346
|
-
}
|
|
1347
|
-
const activeCards = await this.user.getActiveCards();
|
|
1348
|
-
const newCards = (await this.course.getCardsCenteredAtELO(
|
|
1349
|
-
{ limit, elo: "user" },
|
|
1350
|
-
(c) => !activeCards.some((ac) => c.cardID === ac.cardID)
|
|
1351
|
-
)).map((c) => ({ ...c, status: "new" }));
|
|
1352
|
-
const cardIds = newCards.map((c) => c.cardID);
|
|
1353
|
-
const cardEloData = await this.course.getCardEloData(cardIds);
|
|
1354
|
-
const scored = newCards.map((c, i) => {
|
|
1355
|
-
const cardElo = cardEloData[i]?.global?.score ?? 1e3;
|
|
1356
|
-
const distance = Math.abs(cardElo - userGlobalElo);
|
|
1357
|
-
const score = Math.max(0, 1 - distance / 500);
|
|
1358
|
-
return {
|
|
1359
|
-
cardId: c.cardID,
|
|
1360
|
-
courseId: c.courseID,
|
|
1361
|
-
score,
|
|
1362
|
-
provenance: [
|
|
1363
|
-
{
|
|
1364
|
-
strategy: "elo",
|
|
1365
|
-
strategyName: this.strategyName || this.name,
|
|
1366
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-ELO-default",
|
|
1367
|
-
action: "generated",
|
|
1368
|
-
score,
|
|
1369
|
-
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userGlobalElo)}), new card`
|
|
1370
|
-
}
|
|
1371
|
-
]
|
|
1372
|
-
};
|
|
1373
|
-
});
|
|
1374
|
-
scored.sort((a, b) => b.score - a.score);
|
|
1375
|
-
return scored.slice(0, limit);
|
|
1376
|
-
}
|
|
1377
|
-
};
|
|
1378
|
-
}
|
|
1379
|
-
});
|
|
1380
|
-
|
|
1381
|
-
// src/core/navigators/generators/srs.ts
|
|
1382
|
-
var import_moment3, SRSNavigator;
|
|
1383
|
-
var init_srs = __esm({
|
|
1384
|
-
"src/core/navigators/generators/srs.ts"() {
|
|
1385
|
-
"use strict";
|
|
1386
|
-
import_moment3 = __toESM(require("moment"), 1);
|
|
1387
|
-
init_navigators();
|
|
1388
|
-
init_logger();
|
|
1389
|
-
SRSNavigator = class extends ContentNavigator {
|
|
1390
|
-
/** Human-readable name for CardGenerator interface */
|
|
1391
|
-
name;
|
|
1392
|
-
constructor(user, course, strategyData) {
|
|
1393
|
-
super(user, course, strategyData);
|
|
1394
|
-
this.name = strategyData?.name || "SRS";
|
|
1395
|
-
}
|
|
1396
|
-
/**
|
|
1397
|
-
* Get review cards scored by urgency.
|
|
1398
|
-
*
|
|
1399
|
-
* Score formula combines:
|
|
1400
|
-
* - Relative overdueness: hoursOverdue / intervalHours
|
|
1401
|
-
* - Interval recency: exponential decay favoring shorter intervals
|
|
1402
|
-
*
|
|
1403
|
-
* Cards not yet due are excluded (not scored as 0).
|
|
1404
|
-
*
|
|
1405
|
-
* This method supports both the legacy signature (limit only) and the
|
|
1406
|
-
* CardGenerator interface signature (limit, context).
|
|
1407
|
-
*
|
|
1408
|
-
* @param limit - Maximum number of cards to return
|
|
1409
|
-
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1410
|
-
*/
|
|
1411
|
-
async getWeightedCards(limit, _context) {
|
|
1412
|
-
if (!this.user || !this.course) {
|
|
1413
|
-
throw new Error("SRSNavigator requires user and course to be set");
|
|
1414
|
-
}
|
|
1415
|
-
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1416
|
-
const now = import_moment3.default.utc();
|
|
1417
|
-
const dueReviews = reviews.filter((r) => now.isAfter(import_moment3.default.utc(r.reviewTime)));
|
|
1418
|
-
const scored = dueReviews.map((review) => {
|
|
1419
|
-
const { score, reason } = this.computeUrgencyScore(review, now);
|
|
1420
|
-
return {
|
|
1421
|
-
cardId: review.cardId,
|
|
1422
|
-
courseId: review.courseId,
|
|
1423
|
-
score,
|
|
1424
|
-
reviewID: review._id,
|
|
1425
|
-
provenance: [
|
|
1426
|
-
{
|
|
1427
|
-
strategy: "srs",
|
|
1428
|
-
strategyName: this.strategyName || this.name,
|
|
1429
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-SRS-default",
|
|
1430
|
-
action: "generated",
|
|
1431
|
-
score,
|
|
1432
|
-
reason
|
|
1433
|
-
}
|
|
1434
|
-
]
|
|
1435
|
-
};
|
|
1436
|
-
});
|
|
1437
|
-
logger.debug(`[srsNav] got ${scored.length} weighted cards`);
|
|
1438
|
-
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
1439
|
-
}
|
|
1440
|
-
/**
|
|
1441
|
-
* Compute urgency score for a review card.
|
|
1442
|
-
*
|
|
1443
|
-
* Two factors:
|
|
1444
|
-
* 1. Relative overdueness = hoursOverdue / intervalHours
|
|
1445
|
-
* - 2 days overdue on 3-day interval = 0.67 (urgent)
|
|
1446
|
-
* - 2 days overdue on 180-day interval = 0.01 (not urgent)
|
|
1447
|
-
*
|
|
1448
|
-
* 2. Interval recency factor = 0.3 + 0.7 * exp(-intervalHours / 720)
|
|
1449
|
-
* - 24h interval → ~1.0 (very recent learning)
|
|
1450
|
-
* - 30 days (720h) → ~0.56
|
|
1451
|
-
* - 180 days → ~0.30
|
|
1452
|
-
*
|
|
1453
|
-
* Combined: base 0.5 + weighted average of factors * 0.45
|
|
1454
|
-
* Result range: approximately 0.5 to 0.95
|
|
1455
|
-
*/
|
|
1456
|
-
computeUrgencyScore(review, now) {
|
|
1457
|
-
const scheduledAt = import_moment3.default.utc(review.scheduledAt);
|
|
1458
|
-
const due = import_moment3.default.utc(review.reviewTime);
|
|
1459
|
-
const intervalHours = Math.max(1, due.diff(scheduledAt, "hours"));
|
|
1460
|
-
const hoursOverdue = now.diff(due, "hours");
|
|
1461
|
-
const relativeOverdue = hoursOverdue / intervalHours;
|
|
1462
|
-
const recencyFactor = 0.3 + 0.7 * Math.exp(-intervalHours / 720);
|
|
1463
|
-
const overdueContribution = Math.min(1, Math.max(0, relativeOverdue));
|
|
1464
|
-
const urgency = overdueContribution * 0.5 + recencyFactor * 0.5;
|
|
1465
|
-
const score = Math.min(0.95, 0.5 + urgency * 0.45);
|
|
1466
|
-
const reason = `${Math.round(hoursOverdue)}h overdue (interval: ${Math.round(intervalHours)}h, relative: ${relativeOverdue.toFixed(2)}), recency: ${recencyFactor.toFixed(2)}, review`;
|
|
1467
|
-
return { score, reason };
|
|
1468
|
-
}
|
|
1469
|
-
};
|
|
1470
|
-
}
|
|
1471
|
-
});
|
|
1472
|
-
|
|
1473
|
-
// src/core/navigators/filters/eloDistance.ts
|
|
1474
|
-
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
1475
|
-
const normalizedDistance = distance / halfLife;
|
|
1476
|
-
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
1477
|
-
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
1478
|
-
}
|
|
1479
|
-
function createEloDistanceFilter(config) {
|
|
1480
|
-
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
1481
|
-
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
1482
|
-
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
1483
|
-
return {
|
|
1484
|
-
name: "ELO Distance Filter",
|
|
1485
|
-
async transform(cards, context) {
|
|
1486
|
-
const { course, userElo } = context;
|
|
1487
|
-
const cardIds = cards.map((c) => c.cardId);
|
|
1488
|
-
const cardElos = await course.getCardEloData(cardIds);
|
|
1489
|
-
return cards.map((card, i) => {
|
|
1490
|
-
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
1491
|
-
const distance = Math.abs(cardElo - userElo);
|
|
1492
|
-
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
1493
|
-
const newScore = card.score * multiplier;
|
|
1494
|
-
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
2638
|
+
*/
|
|
2639
|
+
makeDefaultEloStrategy(courseId) {
|
|
1495
2640
|
return {
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
strategyId: "ELO_DISTANCE_FILTER",
|
|
1504
|
-
action,
|
|
1505
|
-
score: newScore,
|
|
1506
|
-
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
1507
|
-
}
|
|
1508
|
-
]
|
|
2641
|
+
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
2642
|
+
course: courseId,
|
|
2643
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
2644
|
+
name: "ELO (default)",
|
|
2645
|
+
description: "Default ELO-based generator",
|
|
2646
|
+
implementingClass: "elo" /* ELO */,
|
|
2647
|
+
serializedData: ""
|
|
1509
2648
|
};
|
|
1510
|
-
}
|
|
1511
|
-
}
|
|
1512
|
-
};
|
|
1513
|
-
}
|
|
1514
|
-
var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
|
|
1515
|
-
var init_eloDistance = __esm({
|
|
1516
|
-
"src/core/navigators/filters/eloDistance.ts"() {
|
|
1517
|
-
"use strict";
|
|
1518
|
-
DEFAULT_HALF_LIFE = 200;
|
|
1519
|
-
DEFAULT_MIN_MULTIPLIER = 0.3;
|
|
1520
|
-
DEFAULT_MAX_MULTIPLIER = 1;
|
|
2649
|
+
}
|
|
2650
|
+
};
|
|
1521
2651
|
}
|
|
1522
2652
|
});
|
|
1523
2653
|
|
|
1524
2654
|
// src/core/navigators/defaults.ts
|
|
2655
|
+
var defaults_exports = {};
|
|
2656
|
+
__export(defaults_exports, {
|
|
2657
|
+
createDefaultEloStrategy: () => createDefaultEloStrategy,
|
|
2658
|
+
createDefaultPipeline: () => createDefaultPipeline,
|
|
2659
|
+
createDefaultSrsStrategy: () => createDefaultSrsStrategy
|
|
2660
|
+
});
|
|
1525
2661
|
function createDefaultEloStrategy(courseId) {
|
|
1526
2662
|
return {
|
|
1527
2663
|
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
@@ -1565,6 +2701,304 @@ var init_defaults = __esm({
|
|
|
1565
2701
|
}
|
|
1566
2702
|
});
|
|
1567
2703
|
|
|
2704
|
+
// import("./**/*") in src/core/navigators/index.ts
|
|
2705
|
+
var globImport;
|
|
2706
|
+
var init_3 = __esm({
|
|
2707
|
+
'import("./**/*") in src/core/navigators/index.ts'() {
|
|
2708
|
+
globImport = __glob({
|
|
2709
|
+
"./Pipeline.ts": () => Promise.resolve().then(() => (init_Pipeline(), Pipeline_exports)),
|
|
2710
|
+
"./PipelineAssembler.ts": () => Promise.resolve().then(() => (init_PipelineAssembler(), PipelineAssembler_exports)),
|
|
2711
|
+
"./defaults.ts": () => Promise.resolve().then(() => (init_defaults(), defaults_exports)),
|
|
2712
|
+
"./filters/WeightedFilter.ts": () => Promise.resolve().then(() => (init_WeightedFilter(), WeightedFilter_exports)),
|
|
2713
|
+
"./filters/eloDistance.ts": () => Promise.resolve().then(() => (init_eloDistance(), eloDistance_exports)),
|
|
2714
|
+
"./filters/hierarchyDefinition.ts": () => Promise.resolve().then(() => (init_hierarchyDefinition(), hierarchyDefinition_exports)),
|
|
2715
|
+
"./filters/index.ts": () => Promise.resolve().then(() => (init_filters(), filters_exports)),
|
|
2716
|
+
"./filters/inferredPreferenceStub.ts": () => Promise.resolve().then(() => (init_inferredPreferenceStub(), inferredPreferenceStub_exports)),
|
|
2717
|
+
"./filters/interferenceMitigator.ts": () => Promise.resolve().then(() => (init_interferenceMitigator(), interferenceMitigator_exports)),
|
|
2718
|
+
"./filters/relativePriority.ts": () => Promise.resolve().then(() => (init_relativePriority(), relativePriority_exports)),
|
|
2719
|
+
"./filters/types.ts": () => Promise.resolve().then(() => (init_types2(), types_exports2)),
|
|
2720
|
+
"./filters/userGoalStub.ts": () => Promise.resolve().then(() => (init_userGoalStub(), userGoalStub_exports)),
|
|
2721
|
+
"./filters/userTagPreference.ts": () => Promise.resolve().then(() => (init_userTagPreference(), userTagPreference_exports)),
|
|
2722
|
+
"./generators/CompositeGenerator.ts": () => Promise.resolve().then(() => (init_CompositeGenerator(), CompositeGenerator_exports)),
|
|
2723
|
+
"./generators/elo.ts": () => Promise.resolve().then(() => (init_elo(), elo_exports)),
|
|
2724
|
+
"./generators/index.ts": () => Promise.resolve().then(() => (init_generators(), generators_exports)),
|
|
2725
|
+
"./generators/srs.ts": () => Promise.resolve().then(() => (init_srs(), srs_exports)),
|
|
2726
|
+
"./generators/types.ts": () => Promise.resolve().then(() => (init_types(), types_exports)),
|
|
2727
|
+
"./index.ts": () => Promise.resolve().then(() => (init_navigators(), navigators_exports))
|
|
2728
|
+
});
|
|
2729
|
+
}
|
|
2730
|
+
});
|
|
2731
|
+
|
|
2732
|
+
// src/core/navigators/index.ts
|
|
2733
|
+
var navigators_exports = {};
|
|
2734
|
+
__export(navigators_exports, {
|
|
2735
|
+
ContentNavigator: () => ContentNavigator,
|
|
2736
|
+
NavigatorRole: () => NavigatorRole,
|
|
2737
|
+
NavigatorRoles: () => NavigatorRoles,
|
|
2738
|
+
Navigators: () => Navigators,
|
|
2739
|
+
getCardOrigin: () => getCardOrigin,
|
|
2740
|
+
getRegisteredNavigator: () => getRegisteredNavigator,
|
|
2741
|
+
getRegisteredNavigatorNames: () => getRegisteredNavigatorNames,
|
|
2742
|
+
hasRegisteredNavigator: () => hasRegisteredNavigator,
|
|
2743
|
+
initializeNavigatorRegistry: () => initializeNavigatorRegistry,
|
|
2744
|
+
isFilter: () => isFilter,
|
|
2745
|
+
isGenerator: () => isGenerator,
|
|
2746
|
+
registerNavigator: () => registerNavigator
|
|
2747
|
+
});
|
|
2748
|
+
function registerNavigator(implementingClass, constructor) {
|
|
2749
|
+
navigatorRegistry.set(implementingClass, constructor);
|
|
2750
|
+
logger.debug(`[NavigatorRegistry] Registered: ${implementingClass}`);
|
|
2751
|
+
}
|
|
2752
|
+
function getRegisteredNavigator(implementingClass) {
|
|
2753
|
+
return navigatorRegistry.get(implementingClass);
|
|
2754
|
+
}
|
|
2755
|
+
function hasRegisteredNavigator(implementingClass) {
|
|
2756
|
+
return navigatorRegistry.has(implementingClass);
|
|
2757
|
+
}
|
|
2758
|
+
function getRegisteredNavigatorNames() {
|
|
2759
|
+
return Array.from(navigatorRegistry.keys());
|
|
2760
|
+
}
|
|
2761
|
+
async function initializeNavigatorRegistry() {
|
|
2762
|
+
logger.debug("[NavigatorRegistry] Initializing built-in navigators...");
|
|
2763
|
+
const [eloModule, srsModule] = await Promise.all([
|
|
2764
|
+
Promise.resolve().then(() => (init_elo(), elo_exports)),
|
|
2765
|
+
Promise.resolve().then(() => (init_srs(), srs_exports))
|
|
2766
|
+
]);
|
|
2767
|
+
registerNavigator("elo", eloModule.default);
|
|
2768
|
+
registerNavigator("srs", srsModule.default);
|
|
2769
|
+
const [
|
|
2770
|
+
hierarchyModule,
|
|
2771
|
+
interferenceModule,
|
|
2772
|
+
relativePriorityModule,
|
|
2773
|
+
userTagPreferenceModule
|
|
2774
|
+
] = await Promise.all([
|
|
2775
|
+
Promise.resolve().then(() => (init_hierarchyDefinition(), hierarchyDefinition_exports)),
|
|
2776
|
+
Promise.resolve().then(() => (init_interferenceMitigator(), interferenceMitigator_exports)),
|
|
2777
|
+
Promise.resolve().then(() => (init_relativePriority(), relativePriority_exports)),
|
|
2778
|
+
Promise.resolve().then(() => (init_userTagPreference(), userTagPreference_exports))
|
|
2779
|
+
]);
|
|
2780
|
+
registerNavigator("hierarchyDefinition", hierarchyModule.default);
|
|
2781
|
+
registerNavigator("interferenceMitigator", interferenceModule.default);
|
|
2782
|
+
registerNavigator("relativePriority", relativePriorityModule.default);
|
|
2783
|
+
registerNavigator("userTagPreference", userTagPreferenceModule.default);
|
|
2784
|
+
logger.debug(
|
|
2785
|
+
`[NavigatorRegistry] Initialized ${navigatorRegistry.size} navigators: ${getRegisteredNavigatorNames().join(", ")}`
|
|
2786
|
+
);
|
|
2787
|
+
}
|
|
2788
|
+
function getCardOrigin(card) {
|
|
2789
|
+
if (card.provenance.length === 0) {
|
|
2790
|
+
throw new Error("Card has no provenance - cannot determine origin");
|
|
2791
|
+
}
|
|
2792
|
+
const firstEntry = card.provenance[0];
|
|
2793
|
+
const reason = firstEntry.reason.toLowerCase();
|
|
2794
|
+
if (reason.includes("failed")) {
|
|
2795
|
+
return "failed";
|
|
2796
|
+
}
|
|
2797
|
+
if (reason.includes("review")) {
|
|
2798
|
+
return "review";
|
|
2799
|
+
}
|
|
2800
|
+
return "new";
|
|
2801
|
+
}
|
|
2802
|
+
function isGenerator(impl) {
|
|
2803
|
+
return NavigatorRoles[impl] === "generator" /* GENERATOR */;
|
|
2804
|
+
}
|
|
2805
|
+
function isFilter(impl) {
|
|
2806
|
+
return NavigatorRoles[impl] === "filter" /* FILTER */;
|
|
2807
|
+
}
|
|
2808
|
+
var navigatorRegistry, Navigators, NavigatorRole, NavigatorRoles, ContentNavigator;
|
|
2809
|
+
var init_navigators = __esm({
|
|
2810
|
+
"src/core/navigators/index.ts"() {
|
|
2811
|
+
"use strict";
|
|
2812
|
+
init_logger();
|
|
2813
|
+
init_();
|
|
2814
|
+
init_2();
|
|
2815
|
+
init_3();
|
|
2816
|
+
navigatorRegistry = /* @__PURE__ */ new Map();
|
|
2817
|
+
Navigators = /* @__PURE__ */ ((Navigators2) => {
|
|
2818
|
+
Navigators2["ELO"] = "elo";
|
|
2819
|
+
Navigators2["SRS"] = "srs";
|
|
2820
|
+
Navigators2["HIERARCHY"] = "hierarchyDefinition";
|
|
2821
|
+
Navigators2["INTERFERENCE"] = "interferenceMitigator";
|
|
2822
|
+
Navigators2["RELATIVE_PRIORITY"] = "relativePriority";
|
|
2823
|
+
Navigators2["USER_TAG_PREFERENCE"] = "userTagPreference";
|
|
2824
|
+
return Navigators2;
|
|
2825
|
+
})(Navigators || {});
|
|
2826
|
+
NavigatorRole = /* @__PURE__ */ ((NavigatorRole2) => {
|
|
2827
|
+
NavigatorRole2["GENERATOR"] = "generator";
|
|
2828
|
+
NavigatorRole2["FILTER"] = "filter";
|
|
2829
|
+
return NavigatorRole2;
|
|
2830
|
+
})(NavigatorRole || {});
|
|
2831
|
+
NavigatorRoles = {
|
|
2832
|
+
["elo" /* ELO */]: "generator" /* GENERATOR */,
|
|
2833
|
+
["srs" /* SRS */]: "generator" /* GENERATOR */,
|
|
2834
|
+
["hierarchyDefinition" /* HIERARCHY */]: "filter" /* FILTER */,
|
|
2835
|
+
["interferenceMitigator" /* INTERFERENCE */]: "filter" /* FILTER */,
|
|
2836
|
+
["relativePriority" /* RELATIVE_PRIORITY */]: "filter" /* FILTER */,
|
|
2837
|
+
["userTagPreference" /* USER_TAG_PREFERENCE */]: "filter" /* FILTER */
|
|
2838
|
+
};
|
|
2839
|
+
ContentNavigator = class {
|
|
2840
|
+
/** User interface for this navigation session */
|
|
2841
|
+
user;
|
|
2842
|
+
/** Course interface for this navigation session */
|
|
2843
|
+
course;
|
|
2844
|
+
/** Human-readable name for this strategy instance (from ContentNavigationStrategyData.name) */
|
|
2845
|
+
strategyName;
|
|
2846
|
+
/** Unique document ID for this strategy instance (from ContentNavigationStrategyData._id) */
|
|
2847
|
+
strategyId;
|
|
2848
|
+
/** Evolutionary weighting configuration */
|
|
2849
|
+
learnable;
|
|
2850
|
+
/** Whether to bypass deviation (manual/static weighting) */
|
|
2851
|
+
staticWeight;
|
|
2852
|
+
/**
|
|
2853
|
+
* Constructor for standard navigators.
|
|
2854
|
+
* Call this from subclass constructors to initialize common fields.
|
|
2855
|
+
*
|
|
2856
|
+
* Note: CompositeGenerator and Pipeline call super() without args, then set
|
|
2857
|
+
* user/course fields directly if needed.
|
|
2858
|
+
*/
|
|
2859
|
+
constructor(user, course, strategyData) {
|
|
2860
|
+
this.user = user;
|
|
2861
|
+
this.course = course;
|
|
2862
|
+
if (strategyData) {
|
|
2863
|
+
this.strategyName = strategyData.name;
|
|
2864
|
+
this.strategyId = strategyData._id;
|
|
2865
|
+
this.learnable = strategyData.learnable;
|
|
2866
|
+
this.staticWeight = strategyData.staticWeight;
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2869
|
+
// ============================================================================
|
|
2870
|
+
// STRATEGY STATE HELPERS
|
|
2871
|
+
// ============================================================================
|
|
2872
|
+
//
|
|
2873
|
+
// These methods allow strategies to persist their own state (user preferences,
|
|
2874
|
+
// learned patterns, temporal tracking) in the user database.
|
|
2875
|
+
//
|
|
2876
|
+
// ============================================================================
|
|
2877
|
+
/**
|
|
2878
|
+
* Unique key identifying this strategy for state storage.
|
|
2879
|
+
*
|
|
2880
|
+
* Defaults to the constructor name (e.g., "UserTagPreferenceFilter").
|
|
2881
|
+
* Override in subclasses if multiple instances of the same strategy type
|
|
2882
|
+
* need separate state storage.
|
|
2883
|
+
*/
|
|
2884
|
+
get strategyKey() {
|
|
2885
|
+
return this.constructor.name;
|
|
2886
|
+
}
|
|
2887
|
+
/**
|
|
2888
|
+
* Get this strategy's persisted state for the current course.
|
|
2889
|
+
*
|
|
2890
|
+
* @returns The strategy's data payload, or null if no state exists
|
|
2891
|
+
* @throws Error if user or course is not initialized
|
|
2892
|
+
*/
|
|
2893
|
+
async getStrategyState() {
|
|
2894
|
+
if (!this.user || !this.course) {
|
|
2895
|
+
throw new Error(
|
|
2896
|
+
`Cannot get strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
2897
|
+
);
|
|
2898
|
+
}
|
|
2899
|
+
return this.user.getStrategyState(this.course.getCourseID(), this.strategyKey);
|
|
2900
|
+
}
|
|
2901
|
+
/**
|
|
2902
|
+
* Persist this strategy's state for the current course.
|
|
2903
|
+
*
|
|
2904
|
+
* @param data - The strategy's data payload to store
|
|
2905
|
+
* @throws Error if user or course is not initialized
|
|
2906
|
+
*/
|
|
2907
|
+
async putStrategyState(data) {
|
|
2908
|
+
if (!this.user || !this.course) {
|
|
2909
|
+
throw new Error(
|
|
2910
|
+
`Cannot put strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
2911
|
+
);
|
|
2912
|
+
}
|
|
2913
|
+
return this.user.putStrategyState(this.course.getCourseID(), this.strategyKey, data);
|
|
2914
|
+
}
|
|
2915
|
+
/**
|
|
2916
|
+
* Factory method to create navigator instances.
|
|
2917
|
+
*
|
|
2918
|
+
* First checks the navigator registry for a pre-registered constructor.
|
|
2919
|
+
* If not found, falls back to dynamic import (for custom navigators).
|
|
2920
|
+
*
|
|
2921
|
+
* For reliable operation in test environments, call initializeNavigatorRegistry()
|
|
2922
|
+
* before using this method.
|
|
2923
|
+
*
|
|
2924
|
+
* @param user - User interface
|
|
2925
|
+
* @param course - Course interface
|
|
2926
|
+
* @param strategyData - Strategy configuration document
|
|
2927
|
+
* @returns the runtime object used to steer a study session.
|
|
2928
|
+
*/
|
|
2929
|
+
static async create(user, course, strategyData) {
|
|
2930
|
+
const implementingClass = strategyData.implementingClass;
|
|
2931
|
+
const RegisteredImpl = getRegisteredNavigator(implementingClass);
|
|
2932
|
+
if (RegisteredImpl) {
|
|
2933
|
+
logger.debug(`[ContentNavigator.create] Using registered navigator: ${implementingClass}`);
|
|
2934
|
+
return new RegisteredImpl(user, course, strategyData);
|
|
2935
|
+
}
|
|
2936
|
+
logger.debug(
|
|
2937
|
+
`[ContentNavigator.create] Navigator not in registry, attempting dynamic import: ${implementingClass}`
|
|
2938
|
+
);
|
|
2939
|
+
let NavigatorImpl;
|
|
2940
|
+
const variations = [".ts", ".js", ""];
|
|
2941
|
+
for (const ext of variations) {
|
|
2942
|
+
try {
|
|
2943
|
+
const module2 = await globImport_generators(`./generators/${implementingClass}${ext}`);
|
|
2944
|
+
NavigatorImpl = module2.default;
|
|
2945
|
+
if (NavigatorImpl) break;
|
|
2946
|
+
} catch (e) {
|
|
2947
|
+
logger.debug(`Failed to load generator ${implementingClass}${ext}:`, e);
|
|
2948
|
+
}
|
|
2949
|
+
try {
|
|
2950
|
+
const module2 = await globImport_filters(`./filters/${implementingClass}${ext}`);
|
|
2951
|
+
NavigatorImpl = module2.default;
|
|
2952
|
+
if (NavigatorImpl) break;
|
|
2953
|
+
} catch (e) {
|
|
2954
|
+
logger.debug(`Failed to load filter ${implementingClass}${ext}:`, e);
|
|
2955
|
+
}
|
|
2956
|
+
try {
|
|
2957
|
+
const module2 = await globImport(`./${implementingClass}${ext}`);
|
|
2958
|
+
NavigatorImpl = module2.default;
|
|
2959
|
+
if (NavigatorImpl) break;
|
|
2960
|
+
} catch (e) {
|
|
2961
|
+
logger.debug(`Failed to load legacy ${implementingClass}${ext}:`, e);
|
|
2962
|
+
}
|
|
2963
|
+
if (NavigatorImpl) break;
|
|
2964
|
+
}
|
|
2965
|
+
if (!NavigatorImpl) {
|
|
2966
|
+
throw new Error(`Could not load navigator implementation for: ${implementingClass}`);
|
|
2967
|
+
}
|
|
2968
|
+
return new NavigatorImpl(user, course, strategyData);
|
|
2969
|
+
}
|
|
2970
|
+
/**
|
|
2971
|
+
* Get cards with suitability scores and provenance trails.
|
|
2972
|
+
*
|
|
2973
|
+
* **This is the PRIMARY API for navigation strategies.**
|
|
2974
|
+
*
|
|
2975
|
+
* Returns cards ranked by suitability score (0-1). Higher scores indicate
|
|
2976
|
+
* better candidates for presentation. Each card includes a provenance trail
|
|
2977
|
+
* documenting how strategies contributed to the final score.
|
|
2978
|
+
*
|
|
2979
|
+
* ## Implementation Required
|
|
2980
|
+
* All navigation strategies MUST override this method. The base class does
|
|
2981
|
+
* not provide a default implementation.
|
|
2982
|
+
*
|
|
2983
|
+
* ## For Generators
|
|
2984
|
+
* Override this method to generate candidates and compute scores based on
|
|
2985
|
+
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
2986
|
+
* initial provenance entry with action='generated'.
|
|
2987
|
+
*
|
|
2988
|
+
* ## For Filters
|
|
2989
|
+
* Filters should implement the CardFilter interface instead and be composed
|
|
2990
|
+
* via Pipeline. Filters do not directly implement getWeightedCards().
|
|
2991
|
+
*
|
|
2992
|
+
* @param limit - Maximum cards to return
|
|
2993
|
+
* @returns Cards sorted by score descending, with provenance trails
|
|
2994
|
+
*/
|
|
2995
|
+
async getWeightedCards(_limit) {
|
|
2996
|
+
throw new Error(`${this.constructor.name} must implement getWeightedCards(). `);
|
|
2997
|
+
}
|
|
2998
|
+
};
|
|
2999
|
+
}
|
|
3000
|
+
});
|
|
3001
|
+
|
|
1568
3002
|
// src/impl/couch/courseDB.ts
|
|
1569
3003
|
function randIntWeightedTowardZero(n) {
|
|
1570
3004
|
return Math.floor(Math.random() * Math.random() * Math.random() * n);
|
|
@@ -1641,11 +3075,11 @@ ${JSON.stringify(config)}
|
|
|
1641
3075
|
function isSuccessRow(row) {
|
|
1642
3076
|
return "doc" in row && row.doc !== null && row.doc !== void 0;
|
|
1643
3077
|
}
|
|
1644
|
-
var
|
|
3078
|
+
var import_common9, CourseDB;
|
|
1645
3079
|
var init_courseDB = __esm({
|
|
1646
3080
|
"src/impl/couch/courseDB.ts"() {
|
|
1647
3081
|
"use strict";
|
|
1648
|
-
|
|
3082
|
+
import_common9 = require("@vue-skuilder/common");
|
|
1649
3083
|
init_couch();
|
|
1650
3084
|
init_updateQueue();
|
|
1651
3085
|
init_types_legacy();
|
|
@@ -1722,14 +3156,14 @@ var init_courseDB = __esm({
|
|
|
1722
3156
|
docs.rows.forEach((r) => {
|
|
1723
3157
|
if (isSuccessRow(r)) {
|
|
1724
3158
|
if (r.doc && r.doc.elo) {
|
|
1725
|
-
ret.push((0,
|
|
3159
|
+
ret.push((0, import_common9.toCourseElo)(r.doc.elo));
|
|
1726
3160
|
} else {
|
|
1727
3161
|
logger.warn("no elo data for card: " + r.id);
|
|
1728
|
-
ret.push((0,
|
|
3162
|
+
ret.push((0, import_common9.blankCourseElo)());
|
|
1729
3163
|
}
|
|
1730
3164
|
} else {
|
|
1731
3165
|
logger.warn("no elo data for card: " + JSON.stringify(r));
|
|
1732
|
-
ret.push((0,
|
|
3166
|
+
ret.push((0, import_common9.blankCourseElo)());
|
|
1733
3167
|
}
|
|
1734
3168
|
});
|
|
1735
3169
|
return ret;
|
|
@@ -1924,7 +3358,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1924
3358
|
async getCourseTagStubs() {
|
|
1925
3359
|
return getCourseTagStubs(this.id);
|
|
1926
3360
|
}
|
|
1927
|
-
async addNote(codeCourse, shape, data, author, tags, uploads, elo = (0,
|
|
3361
|
+
async addNote(codeCourse, shape, data, author, tags, uploads, elo = (0, import_common9.blankCourseElo)()) {
|
|
1928
3362
|
try {
|
|
1929
3363
|
const resp = await addNote55(this.id, codeCourse, shape, data, author, tags, uploads, elo);
|
|
1930
3364
|
if (resp.ok) {
|
|
@@ -1933,19 +3367,19 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1933
3367
|
`[courseDB.addNote] Note added but card creation failed: ${resp.cardCreationError}`
|
|
1934
3368
|
);
|
|
1935
3369
|
return {
|
|
1936
|
-
status:
|
|
3370
|
+
status: import_common9.Status.error,
|
|
1937
3371
|
message: `Note was added but no cards were created: ${resp.cardCreationError}`,
|
|
1938
3372
|
id: resp.id
|
|
1939
3373
|
};
|
|
1940
3374
|
}
|
|
1941
3375
|
return {
|
|
1942
|
-
status:
|
|
3376
|
+
status: import_common9.Status.ok,
|
|
1943
3377
|
message: "",
|
|
1944
3378
|
id: resp.id
|
|
1945
3379
|
};
|
|
1946
3380
|
} else {
|
|
1947
3381
|
return {
|
|
1948
|
-
status:
|
|
3382
|
+
status: import_common9.Status.error,
|
|
1949
3383
|
message: "Unexpected error adding note"
|
|
1950
3384
|
};
|
|
1951
3385
|
}
|
|
@@ -1957,7 +3391,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
1957
3391
|
message: ${err.message}`
|
|
1958
3392
|
);
|
|
1959
3393
|
return {
|
|
1960
|
-
status:
|
|
3394
|
+
status: import_common9.Status.error,
|
|
1961
3395
|
message: `Error adding note to course. ${e.reason || err.message}`
|
|
1962
3396
|
};
|
|
1963
3397
|
}
|
|
@@ -2085,7 +3519,7 @@ ${above.rows.map((r) => ` ${r.id}-${r.key}
|
|
|
2085
3519
|
const courseDoc = (await u.getCourseRegistrationsDoc()).courses.find((c) => {
|
|
2086
3520
|
return c.courseID === this.id;
|
|
2087
3521
|
});
|
|
2088
|
-
targetElo = (0,
|
|
3522
|
+
targetElo = (0, import_common9.EloToNumber)(courseDoc.elo);
|
|
2089
3523
|
} catch {
|
|
2090
3524
|
targetElo = 1e3;
|
|
2091
3525
|
}
|
|
@@ -2428,14 +3862,14 @@ var init_auth = __esm({
|
|
|
2428
3862
|
});
|
|
2429
3863
|
|
|
2430
3864
|
// src/impl/couch/CouchDBSyncStrategy.ts
|
|
2431
|
-
var
|
|
3865
|
+
var import_common10;
|
|
2432
3866
|
var init_CouchDBSyncStrategy = __esm({
|
|
2433
3867
|
"src/impl/couch/CouchDBSyncStrategy.ts"() {
|
|
2434
3868
|
"use strict";
|
|
2435
3869
|
init_factory();
|
|
2436
3870
|
init_types_legacy();
|
|
2437
3871
|
init_logger();
|
|
2438
|
-
|
|
3872
|
+
import_common10 = require("@vue-skuilder/common");
|
|
2439
3873
|
init_common();
|
|
2440
3874
|
init_pouchdb_setup();
|
|
2441
3875
|
init_couch();
|
|
@@ -2621,13 +4055,13 @@ async function dropUserFromClassroom(user, classID) {
|
|
|
2621
4055
|
async function getUserClassrooms(user) {
|
|
2622
4056
|
return getOrCreateClassroomRegistrationsDoc(user);
|
|
2623
4057
|
}
|
|
2624
|
-
var
|
|
4058
|
+
var import_common12, import_moment6, log3, BaseUser, userCoursesDoc, userClassroomsDoc;
|
|
2625
4059
|
var init_BaseUserDB = __esm({
|
|
2626
4060
|
"src/impl/common/BaseUserDB.ts"() {
|
|
2627
4061
|
"use strict";
|
|
2628
4062
|
init_core();
|
|
2629
4063
|
init_util();
|
|
2630
|
-
|
|
4064
|
+
import_common12 = require("@vue-skuilder/common");
|
|
2631
4065
|
import_moment6 = __toESM(require("moment"), 1);
|
|
2632
4066
|
init_types_legacy();
|
|
2633
4067
|
init_logger();
|
|
@@ -2677,7 +4111,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2677
4111
|
);
|
|
2678
4112
|
}
|
|
2679
4113
|
const result = await this.syncStrategy.createAccount(username, password);
|
|
2680
|
-
if (result.status ===
|
|
4114
|
+
if (result.status === import_common12.Status.ok) {
|
|
2681
4115
|
log3(`Account created successfully, updating username to ${username}`);
|
|
2682
4116
|
this._username = username;
|
|
2683
4117
|
try {
|
|
@@ -2719,7 +4153,7 @@ Currently logged-in as ${this._username}.`
|
|
|
2719
4153
|
async resetUserData() {
|
|
2720
4154
|
if (this.syncStrategy.canAuthenticate()) {
|
|
2721
4155
|
return {
|
|
2722
|
-
status:
|
|
4156
|
+
status: import_common12.Status.error,
|
|
2723
4157
|
error: "Reset user data is only available for local-only mode. Use logout instead for remote sync."
|
|
2724
4158
|
};
|
|
2725
4159
|
}
|
|
@@ -2738,11 +4172,11 @@ Currently logged-in as ${this._username}.`
|
|
|
2738
4172
|
await localDB.bulkDocs(docsToDelete);
|
|
2739
4173
|
}
|
|
2740
4174
|
await this.init();
|
|
2741
|
-
return { status:
|
|
4175
|
+
return { status: import_common12.Status.ok };
|
|
2742
4176
|
} catch (error) {
|
|
2743
4177
|
logger.error("Failed to reset user data:", error);
|
|
2744
4178
|
return {
|
|
2745
|
-
status:
|
|
4179
|
+
status: import_common12.Status.error,
|
|
2746
4180
|
error: error instanceof Error ? error.message : "Unknown error during reset"
|
|
2747
4181
|
};
|
|
2748
4182
|
}
|
|
@@ -3469,6 +4903,19 @@ Currently logged-in as ${this._username}.`
|
|
|
3469
4903
|
};
|
|
3470
4904
|
await this.localDB.put(doc);
|
|
3471
4905
|
}
|
|
4906
|
+
async putUserOutcome(record) {
|
|
4907
|
+
try {
|
|
4908
|
+
await this.localDB.put(record);
|
|
4909
|
+
} catch (err) {
|
|
4910
|
+
if (err.status === 409) {
|
|
4911
|
+
const existing = await this.localDB.get(record._id);
|
|
4912
|
+
record._rev = existing._rev;
|
|
4913
|
+
await this.localDB.put(record);
|
|
4914
|
+
} else {
|
|
4915
|
+
throw err;
|
|
4916
|
+
}
|
|
4917
|
+
}
|
|
4918
|
+
}
|
|
3472
4919
|
async deleteStrategyState(courseId, strategyKey) {
|
|
3473
4920
|
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
3474
4921
|
try {
|
|
@@ -3511,6 +4958,7 @@ var init_factory = __esm({
|
|
|
3511
4958
|
"use strict";
|
|
3512
4959
|
init_common();
|
|
3513
4960
|
init_logger();
|
|
4961
|
+
init_navigators();
|
|
3514
4962
|
NOT_SET = "NOT_SET";
|
|
3515
4963
|
ENV = {
|
|
3516
4964
|
COUCHDB_SERVER_PROTOCOL: NOT_SET,
|
|
@@ -3522,11 +4970,11 @@ var init_factory = __esm({
|
|
|
3522
4970
|
});
|
|
3523
4971
|
|
|
3524
4972
|
// src/study/TagFilteredContentSource.ts
|
|
3525
|
-
var
|
|
4973
|
+
var import_common14, TagFilteredContentSource;
|
|
3526
4974
|
var init_TagFilteredContentSource = __esm({
|
|
3527
4975
|
"src/study/TagFilteredContentSource.ts"() {
|
|
3528
4976
|
"use strict";
|
|
3529
|
-
|
|
4977
|
+
import_common14 = require("@vue-skuilder/common");
|
|
3530
4978
|
init_courseDB();
|
|
3531
4979
|
init_logger();
|
|
3532
4980
|
TagFilteredContentSource = class {
|
|
@@ -3612,7 +5060,7 @@ var init_TagFilteredContentSource = __esm({
|
|
|
3612
5060
|
* @returns Cards sorted by score descending (all scores = 1.0)
|
|
3613
5061
|
*/
|
|
3614
5062
|
async getWeightedCards(limit) {
|
|
3615
|
-
if (!(0,
|
|
5063
|
+
if (!(0, import_common14.hasActiveFilter)(this.filter)) {
|
|
3616
5064
|
logger.warn("[TagFilteredContentSource] getWeightedCards called with no active filter");
|
|
3617
5065
|
return [];
|
|
3618
5066
|
}
|
|
@@ -3700,19 +5148,19 @@ async function getStudySource(source, user) {
|
|
|
3700
5148
|
if (source.type === "classroom") {
|
|
3701
5149
|
return await StudentClassroomDB.factory(source.id, user);
|
|
3702
5150
|
} else {
|
|
3703
|
-
if ((0,
|
|
5151
|
+
if ((0, import_common15.hasActiveFilter)(source.tagFilter)) {
|
|
3704
5152
|
return new TagFilteredContentSource(source.id, source.tagFilter, user);
|
|
3705
5153
|
}
|
|
3706
5154
|
return getDataLayer().getCourseDB(source.id);
|
|
3707
5155
|
}
|
|
3708
5156
|
}
|
|
3709
|
-
var
|
|
5157
|
+
var import_common15;
|
|
3710
5158
|
var init_contentSource = __esm({
|
|
3711
5159
|
"src/core/interfaces/contentSource.ts"() {
|
|
3712
5160
|
"use strict";
|
|
3713
5161
|
init_factory();
|
|
3714
5162
|
init_classroomDB2();
|
|
3715
|
-
|
|
5163
|
+
import_common15 = require("@vue-skuilder/common");
|
|
3716
5164
|
init_TagFilteredContentSource();
|
|
3717
5165
|
}
|
|
3718
5166
|
});
|
|
@@ -3768,6 +5216,13 @@ var init_strategyState = __esm({
|
|
|
3768
5216
|
}
|
|
3769
5217
|
});
|
|
3770
5218
|
|
|
5219
|
+
// src/core/types/userOutcome.ts
|
|
5220
|
+
var init_userOutcome = __esm({
|
|
5221
|
+
"src/core/types/userOutcome.ts"() {
|
|
5222
|
+
"use strict";
|
|
5223
|
+
}
|
|
5224
|
+
});
|
|
5225
|
+
|
|
3771
5226
|
// src/core/bulkImport/cardProcessor.ts
|
|
3772
5227
|
async function importParsedCards(parsedCards, courseDB, config) {
|
|
3773
5228
|
const results = [];
|
|
@@ -3836,7 +5291,7 @@ elo: ${elo}`;
|
|
|
3836
5291
|
misc: {}
|
|
3837
5292
|
} : void 0
|
|
3838
5293
|
);
|
|
3839
|
-
if (result.status ===
|
|
5294
|
+
if (result.status === import_common16.Status.ok) {
|
|
3840
5295
|
return {
|
|
3841
5296
|
originalText,
|
|
3842
5297
|
status: "success",
|
|
@@ -3880,17 +5335,17 @@ function validateProcessorConfig(config) {
|
|
|
3880
5335
|
}
|
|
3881
5336
|
return { isValid: true };
|
|
3882
5337
|
}
|
|
3883
|
-
var
|
|
5338
|
+
var import_common16;
|
|
3884
5339
|
var init_cardProcessor = __esm({
|
|
3885
5340
|
"src/core/bulkImport/cardProcessor.ts"() {
|
|
3886
5341
|
"use strict";
|
|
3887
|
-
|
|
5342
|
+
import_common16 = require("@vue-skuilder/common");
|
|
3888
5343
|
init_logger();
|
|
3889
5344
|
}
|
|
3890
5345
|
});
|
|
3891
5346
|
|
|
3892
5347
|
// src/core/bulkImport/types.ts
|
|
3893
|
-
var
|
|
5348
|
+
var init_types3 = __esm({
|
|
3894
5349
|
"src/core/bulkImport/types.ts"() {
|
|
3895
5350
|
"use strict";
|
|
3896
5351
|
}
|
|
@@ -3901,7 +5356,7 @@ var init_bulkImport = __esm({
|
|
|
3901
5356
|
"src/core/bulkImport/index.ts"() {
|
|
3902
5357
|
"use strict";
|
|
3903
5358
|
init_cardProcessor();
|
|
3904
|
-
|
|
5359
|
+
init_types3();
|
|
3905
5360
|
}
|
|
3906
5361
|
});
|
|
3907
5362
|
|
|
@@ -3916,19 +5371,37 @@ __export(core_exports, {
|
|
|
3916
5371
|
NavigatorRole: () => NavigatorRole,
|
|
3917
5372
|
NavigatorRoles: () => NavigatorRoles,
|
|
3918
5373
|
Navigators: () => Navigators,
|
|
5374
|
+
aggregateOutcomesForGradient: () => aggregateOutcomesForGradient,
|
|
3919
5375
|
areQuestionRecords: () => areQuestionRecords,
|
|
3920
5376
|
buildStrategyStateId: () => buildStrategyStateId,
|
|
5377
|
+
computeDeviation: () => computeDeviation,
|
|
5378
|
+
computeEffectiveWeight: () => computeEffectiveWeight,
|
|
5379
|
+
computeOutcomeSignal: () => computeOutcomeSignal,
|
|
5380
|
+
computeSpread: () => computeSpread,
|
|
5381
|
+
computeStrategyGradient: () => computeStrategyGradient,
|
|
5382
|
+
createOrchestrationContext: () => createOrchestrationContext,
|
|
3921
5383
|
docIsDeleted: () => docIsDeleted,
|
|
3922
5384
|
getCardHistoryID: () => getCardHistoryID,
|
|
3923
5385
|
getCardOrigin: () => getCardOrigin,
|
|
5386
|
+
getDefaultLearnableWeight: () => getDefaultLearnableWeight,
|
|
5387
|
+
getRegisteredNavigator: () => getRegisteredNavigator,
|
|
5388
|
+
getRegisteredNavigatorNames: () => getRegisteredNavigatorNames,
|
|
3924
5389
|
getStudySource: () => getStudySource,
|
|
5390
|
+
hasRegisteredNavigator: () => hasRegisteredNavigator,
|
|
3925
5391
|
importParsedCards: () => importParsedCards,
|
|
5392
|
+
initializeNavigatorRegistry: () => initializeNavigatorRegistry,
|
|
3926
5393
|
isFilter: () => isFilter,
|
|
3927
5394
|
isGenerator: () => isGenerator,
|
|
3928
5395
|
isQuestionRecord: () => isQuestionRecord,
|
|
3929
5396
|
isReview: () => isReview,
|
|
3930
5397
|
log: () => log,
|
|
3931
5398
|
parseCardHistoryID: () => parseCardHistoryID,
|
|
5399
|
+
recordUserOutcome: () => recordUserOutcome,
|
|
5400
|
+
registerNavigator: () => registerNavigator,
|
|
5401
|
+
runPeriodUpdate: () => runPeriodUpdate,
|
|
5402
|
+
scoreAccuracyInZone: () => scoreAccuracyInZone,
|
|
5403
|
+
updateLearningState: () => updateLearningState,
|
|
5404
|
+
updateStrategyWeight: () => updateStrategyWeight,
|
|
3932
5405
|
validateProcessorConfig: () => validateProcessorConfig
|
|
3933
5406
|
});
|
|
3934
5407
|
module.exports = __toCommonJS(core_exports);
|
|
@@ -3938,10 +5411,12 @@ var init_core = __esm({
|
|
|
3938
5411
|
init_types_legacy();
|
|
3939
5412
|
init_user();
|
|
3940
5413
|
init_strategyState();
|
|
5414
|
+
init_userOutcome();
|
|
3941
5415
|
init_Loggable();
|
|
3942
5416
|
init_util();
|
|
3943
5417
|
init_navigators();
|
|
3944
5418
|
init_bulkImport();
|
|
5419
|
+
init_orchestration();
|
|
3945
5420
|
}
|
|
3946
5421
|
});
|
|
3947
5422
|
init_core();
|
|
@@ -3955,19 +5430,37 @@ init_core();
|
|
|
3955
5430
|
NavigatorRole,
|
|
3956
5431
|
NavigatorRoles,
|
|
3957
5432
|
Navigators,
|
|
5433
|
+
aggregateOutcomesForGradient,
|
|
3958
5434
|
areQuestionRecords,
|
|
3959
5435
|
buildStrategyStateId,
|
|
5436
|
+
computeDeviation,
|
|
5437
|
+
computeEffectiveWeight,
|
|
5438
|
+
computeOutcomeSignal,
|
|
5439
|
+
computeSpread,
|
|
5440
|
+
computeStrategyGradient,
|
|
5441
|
+
createOrchestrationContext,
|
|
3960
5442
|
docIsDeleted,
|
|
3961
5443
|
getCardHistoryID,
|
|
3962
5444
|
getCardOrigin,
|
|
5445
|
+
getDefaultLearnableWeight,
|
|
5446
|
+
getRegisteredNavigator,
|
|
5447
|
+
getRegisteredNavigatorNames,
|
|
3963
5448
|
getStudySource,
|
|
5449
|
+
hasRegisteredNavigator,
|
|
3964
5450
|
importParsedCards,
|
|
5451
|
+
initializeNavigatorRegistry,
|
|
3965
5452
|
isFilter,
|
|
3966
5453
|
isGenerator,
|
|
3967
5454
|
isQuestionRecord,
|
|
3968
5455
|
isReview,
|
|
3969
5456
|
log,
|
|
3970
5457
|
parseCardHistoryID,
|
|
5458
|
+
recordUserOutcome,
|
|
5459
|
+
registerNavigator,
|
|
5460
|
+
runPeriodUpdate,
|
|
5461
|
+
scoreAccuracyInZone,
|
|
5462
|
+
updateLearningState,
|
|
5463
|
+
updateStrategyWeight,
|
|
3971
5464
|
validateProcessorConfig
|
|
3972
5465
|
});
|
|
3973
5466
|
//# sourceMappingURL=index.js.map
|