@vue-skuilder/db 0.1.23 → 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 +36 -11
- package/dist/index.d.ts +36 -11
- package/dist/index.js +2410 -806
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2112 -529
- 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 +107 -0
- package/src/factory.ts +6 -0
- package/src/impl/common/BaseUserDB.ts +16 -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
|
@@ -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
|
};
|
|
@@ -115,7 +120,9 @@ var init_types_legacy = __esm({
|
|
|
115
120
|
["VIEW" /* VIEW */]: "VIEW",
|
|
116
121
|
["PEDAGOGY" /* PEDAGOGY */]: "PEDAGOGY",
|
|
117
122
|
["NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */]: "NAVIGATION_STRATEGY",
|
|
118
|
-
["STRATEGY_STATE" /* STRATEGY_STATE */]: "STRATEGY_STATE"
|
|
123
|
+
["STRATEGY_STATE" /* STRATEGY_STATE */]: "STRATEGY_STATE",
|
|
124
|
+
["USER_OUTCOME" /* USER_OUTCOME */]: "USER_OUTCOME",
|
|
125
|
+
["STRATEGY_LEARNING_STATE" /* STRATEGY_LEARNING_STATE */]: "STRATEGY_LEARNING_STATE"
|
|
119
126
|
};
|
|
120
127
|
}
|
|
121
128
|
});
|
|
@@ -490,175 +497,1384 @@ var init_courseLookupDB = __esm({
|
|
|
490
497
|
}
|
|
491
498
|
});
|
|
492
499
|
|
|
493
|
-
// src/core/navigators/
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
var
|
|
501
|
-
|
|
502
|
-
"src/core/navigators/index.ts"() {
|
|
500
|
+
// src/core/navigators/generators/CompositeGenerator.ts
|
|
501
|
+
var CompositeGenerator_exports = {};
|
|
502
|
+
__export(CompositeGenerator_exports, {
|
|
503
|
+
AggregationMode: () => AggregationMode,
|
|
504
|
+
default: () => CompositeGenerator
|
|
505
|
+
});
|
|
506
|
+
var AggregationMode, DEFAULT_AGGREGATION_MODE, FREQUENCY_BOOST_FACTOR, CompositeGenerator;
|
|
507
|
+
var init_CompositeGenerator = __esm({
|
|
508
|
+
"src/core/navigators/generators/CompositeGenerator.ts"() {
|
|
503
509
|
"use strict";
|
|
510
|
+
init_navigators();
|
|
504
511
|
init_logger();
|
|
505
|
-
|
|
506
|
-
["
|
|
507
|
-
["
|
|
508
|
-
["
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
* Call this from subclass constructors to initialize common fields.
|
|
525
|
-
*
|
|
526
|
-
* Note: CompositeGenerator and Pipeline call super() without args, then set
|
|
527
|
-
* user/course fields directly if needed.
|
|
528
|
-
*/
|
|
529
|
-
constructor(user, course, strategyData) {
|
|
530
|
-
this.user = user;
|
|
531
|
-
this.course = course;
|
|
532
|
-
if (strategyData) {
|
|
533
|
-
this.strategyName = strategyData.name;
|
|
534
|
-
this.strategyId = strategyData._id;
|
|
512
|
+
AggregationMode = /* @__PURE__ */ ((AggregationMode2) => {
|
|
513
|
+
AggregationMode2["MAX"] = "max";
|
|
514
|
+
AggregationMode2["AVERAGE"] = "average";
|
|
515
|
+
AggregationMode2["FREQUENCY_BOOST"] = "frequencyBoost";
|
|
516
|
+
return AggregationMode2;
|
|
517
|
+
})(AggregationMode || {});
|
|
518
|
+
DEFAULT_AGGREGATION_MODE = "frequencyBoost" /* FREQUENCY_BOOST */;
|
|
519
|
+
FREQUENCY_BOOST_FACTOR = 0.1;
|
|
520
|
+
CompositeGenerator = class _CompositeGenerator extends ContentNavigator {
|
|
521
|
+
/** Human-readable name for CardGenerator interface */
|
|
522
|
+
name = "Composite Generator";
|
|
523
|
+
generators;
|
|
524
|
+
aggregationMode;
|
|
525
|
+
constructor(generators, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
526
|
+
super();
|
|
527
|
+
this.generators = generators;
|
|
528
|
+
this.aggregationMode = aggregationMode;
|
|
529
|
+
if (generators.length === 0) {
|
|
530
|
+
throw new Error("CompositeGenerator requires at least one generator");
|
|
535
531
|
}
|
|
532
|
+
logger.debug(
|
|
533
|
+
`[CompositeGenerator] Created with ${generators.length} generators, mode: ${aggregationMode}`
|
|
534
|
+
);
|
|
536
535
|
}
|
|
537
|
-
// ============================================================================
|
|
538
|
-
// STRATEGY STATE HELPERS
|
|
539
|
-
// ============================================================================
|
|
540
|
-
//
|
|
541
|
-
// These methods allow strategies to persist their own state (user preferences,
|
|
542
|
-
// learned patterns, temporal tracking) in the user database.
|
|
543
|
-
//
|
|
544
|
-
// ============================================================================
|
|
545
536
|
/**
|
|
546
|
-
*
|
|
537
|
+
* Creates a CompositeGenerator from strategy data.
|
|
547
538
|
*
|
|
548
|
-
*
|
|
549
|
-
* Override in subclasses if multiple instances of the same strategy type
|
|
550
|
-
* need separate state storage.
|
|
539
|
+
* This is a convenience factory for use by PipelineAssembler.
|
|
551
540
|
*/
|
|
552
|
-
|
|
553
|
-
|
|
541
|
+
static async fromStrategies(user, course, strategies, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
542
|
+
const generators = await Promise.all(
|
|
543
|
+
strategies.map((s) => ContentNavigator.create(user, course, s))
|
|
544
|
+
);
|
|
545
|
+
return new _CompositeGenerator(generators, aggregationMode);
|
|
554
546
|
}
|
|
555
547
|
/**
|
|
556
|
-
* Get
|
|
548
|
+
* Get weighted cards from all generators, merge and deduplicate.
|
|
557
549
|
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
550
|
+
* Cards appearing in multiple generators receive a score boost.
|
|
551
|
+
* Provenance tracks which generators produced each card and how scores were aggregated.
|
|
552
|
+
*
|
|
553
|
+
* This method supports both the legacy signature (limit only) and the
|
|
554
|
+
* CardGenerator interface signature (limit, context).
|
|
555
|
+
*
|
|
556
|
+
* @param limit - Maximum number of cards to return
|
|
557
|
+
* @param context - GeneratorContext passed to child generators (required when called via Pipeline)
|
|
560
558
|
*/
|
|
561
|
-
async
|
|
562
|
-
if (!
|
|
559
|
+
async getWeightedCards(limit, context) {
|
|
560
|
+
if (!context) {
|
|
563
561
|
throw new Error(
|
|
564
|
-
|
|
562
|
+
"CompositeGenerator.getWeightedCards requires a GeneratorContext. It should be called via Pipeline, not directly."
|
|
565
563
|
);
|
|
566
564
|
}
|
|
567
|
-
|
|
565
|
+
const results = await Promise.all(
|
|
566
|
+
this.generators.map((g) => g.getWeightedCards(limit, context))
|
|
567
|
+
);
|
|
568
|
+
const byCardId = /* @__PURE__ */ new Map();
|
|
569
|
+
results.forEach((cards, index) => {
|
|
570
|
+
const gen = this.generators[index];
|
|
571
|
+
let weight = gen.learnable?.weight ?? 1;
|
|
572
|
+
let deviation;
|
|
573
|
+
if (gen.learnable && !gen.staticWeight && context.orchestration) {
|
|
574
|
+
const strategyId = gen.strategyId;
|
|
575
|
+
if (strategyId) {
|
|
576
|
+
weight = context.orchestration.getEffectiveWeight(strategyId, gen.learnable);
|
|
577
|
+
deviation = context.orchestration.getDeviation(strategyId);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
for (const card of cards) {
|
|
581
|
+
if (card.provenance.length > 0) {
|
|
582
|
+
card.provenance[0].effectiveWeight = weight;
|
|
583
|
+
card.provenance[0].deviation = deviation;
|
|
584
|
+
}
|
|
585
|
+
const existing = byCardId.get(card.cardId) || [];
|
|
586
|
+
existing.push({ card, weight });
|
|
587
|
+
byCardId.set(card.cardId, existing);
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
const merged = [];
|
|
591
|
+
for (const [, items] of byCardId) {
|
|
592
|
+
const cards = items.map((i) => i.card);
|
|
593
|
+
const aggregatedScore = this.aggregateScores(items);
|
|
594
|
+
const finalScore = Math.min(1, aggregatedScore);
|
|
595
|
+
const mergedProvenance = cards.flatMap((c) => c.provenance);
|
|
596
|
+
const initialScore = cards[0].score;
|
|
597
|
+
const action = finalScore > initialScore ? "boosted" : finalScore < initialScore ? "penalized" : "passed";
|
|
598
|
+
const reason = this.buildAggregationReason(items, finalScore);
|
|
599
|
+
merged.push({
|
|
600
|
+
...cards[0],
|
|
601
|
+
score: finalScore,
|
|
602
|
+
provenance: [
|
|
603
|
+
...mergedProvenance,
|
|
604
|
+
{
|
|
605
|
+
strategy: "composite",
|
|
606
|
+
strategyName: "Composite Generator",
|
|
607
|
+
strategyId: "COMPOSITE_GENERATOR",
|
|
608
|
+
action,
|
|
609
|
+
score: finalScore,
|
|
610
|
+
reason
|
|
611
|
+
}
|
|
612
|
+
]
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
return merged.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
568
616
|
}
|
|
569
617
|
/**
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
* @param data - The strategy's data payload to store
|
|
573
|
-
* @throws Error if user or course is not initialized
|
|
618
|
+
* Build human-readable reason for score aggregation.
|
|
574
619
|
*/
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
620
|
+
buildAggregationReason(items, finalScore) {
|
|
621
|
+
const cards = items.map((i) => i.card);
|
|
622
|
+
const count = cards.length;
|
|
623
|
+
const scores = cards.map((c) => c.score.toFixed(2)).join(", ");
|
|
624
|
+
if (count === 1) {
|
|
625
|
+
const weightMsg = Math.abs(items[0].weight - 1) > 1e-3 ? ` (w=${items[0].weight.toFixed(2)})` : "";
|
|
626
|
+
return `Single generator, score ${finalScore.toFixed(2)}${weightMsg}`;
|
|
627
|
+
}
|
|
628
|
+
const strategies = cards.map((c) => c.provenance[0]?.strategy || "unknown").join(", ");
|
|
629
|
+
switch (this.aggregationMode) {
|
|
630
|
+
case "max" /* MAX */:
|
|
631
|
+
return `Max of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
632
|
+
case "average" /* AVERAGE */:
|
|
633
|
+
return `Weighted Avg of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
634
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
635
|
+
const totalWeight = items.reduce((sum, i) => sum + i.weight, 0);
|
|
636
|
+
const weightedSum = items.reduce((sum, i) => sum + i.card.score * i.weight, 0);
|
|
637
|
+
const avg = totalWeight > 0 ? weightedSum / totalWeight : 0;
|
|
638
|
+
const boost = 1 + FREQUENCY_BOOST_FACTOR * (count - 1);
|
|
639
|
+
return `Frequency boost from ${count} generators (${strategies}): w-avg ${avg.toFixed(2)} \xD7 ${boost.toFixed(2)} \u2192 ${finalScore.toFixed(2)}`;
|
|
640
|
+
}
|
|
641
|
+
default:
|
|
642
|
+
return `Aggregated from ${count} generators: ${finalScore.toFixed(2)}`;
|
|
580
643
|
}
|
|
581
|
-
return this.user.putStrategyState(this.course.getCourseID(), this.strategyKey, data);
|
|
582
644
|
}
|
|
583
645
|
/**
|
|
584
|
-
*
|
|
585
|
-
*
|
|
586
|
-
* @param user - User interface
|
|
587
|
-
* @param course - Course interface
|
|
588
|
-
* @param strategyData - Strategy configuration document
|
|
589
|
-
* @returns the runtime object used to steer a study session.
|
|
646
|
+
* Aggregate scores from multiple generators for the same card.
|
|
590
647
|
*/
|
|
591
|
-
|
|
592
|
-
const
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
NavigatorImpl = module2.default;
|
|
602
|
-
break;
|
|
603
|
-
} catch (e) {
|
|
604
|
-
logger.debug(`Failed to load extension from ${loadFrom}:`, e);
|
|
605
|
-
}
|
|
648
|
+
aggregateScores(items) {
|
|
649
|
+
const scores = items.map((i) => i.card.score);
|
|
650
|
+
switch (this.aggregationMode) {
|
|
651
|
+
case "max" /* MAX */:
|
|
652
|
+
return Math.max(...scores);
|
|
653
|
+
case "average" /* AVERAGE */: {
|
|
654
|
+
const totalWeight = items.reduce((sum, i) => sum + i.weight, 0);
|
|
655
|
+
if (totalWeight === 0) return 0;
|
|
656
|
+
const weightedSum = items.reduce((sum, i) => sum + i.card.score * i.weight, 0);
|
|
657
|
+
return weightedSum / totalWeight;
|
|
606
658
|
}
|
|
659
|
+
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
660
|
+
const totalWeight = items.reduce((sum, i) => sum + i.weight, 0);
|
|
661
|
+
const weightedSum = items.reduce((sum, i) => sum + i.card.score * i.weight, 0);
|
|
662
|
+
const avg = totalWeight > 0 ? weightedSum / totalWeight : 0;
|
|
663
|
+
const frequencyBoost = 1 + FREQUENCY_BOOST_FACTOR * (items.length - 1);
|
|
664
|
+
return avg * frequencyBoost;
|
|
665
|
+
}
|
|
666
|
+
default:
|
|
667
|
+
return scores[0];
|
|
607
668
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
|
|
674
|
+
// src/core/navigators/generators/elo.ts
|
|
675
|
+
var elo_exports = {};
|
|
676
|
+
__export(elo_exports, {
|
|
677
|
+
default: () => ELONavigator
|
|
678
|
+
});
|
|
679
|
+
var import_common5, ELONavigator;
|
|
680
|
+
var init_elo = __esm({
|
|
681
|
+
"src/core/navigators/generators/elo.ts"() {
|
|
682
|
+
"use strict";
|
|
683
|
+
init_navigators();
|
|
684
|
+
import_common5 = require("@vue-skuilder/common");
|
|
685
|
+
ELONavigator = class extends ContentNavigator {
|
|
686
|
+
/** Human-readable name for CardGenerator interface */
|
|
687
|
+
name;
|
|
688
|
+
constructor(user, course, strategyData) {
|
|
689
|
+
super(user, course, strategyData);
|
|
690
|
+
this.name = strategyData?.name || "ELO";
|
|
612
691
|
}
|
|
613
692
|
/**
|
|
614
|
-
* Get cards with suitability scores
|
|
615
|
-
*
|
|
616
|
-
* **This is the PRIMARY API for navigation strategies.**
|
|
617
|
-
*
|
|
618
|
-
* Returns cards ranked by suitability score (0-1). Higher scores indicate
|
|
619
|
-
* better candidates for presentation. Each card includes a provenance trail
|
|
620
|
-
* documenting how strategies contributed to the final score.
|
|
693
|
+
* Get new cards with suitability scores based on ELO distance.
|
|
621
694
|
*
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
* not provide a default implementation.
|
|
695
|
+
* Cards closer to user's ELO get higher scores.
|
|
696
|
+
* Score formula: max(0, 1 - distance / 500)
|
|
625
697
|
*
|
|
626
|
-
*
|
|
627
|
-
*
|
|
628
|
-
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
629
|
-
* initial provenance entry with action='generated'.
|
|
698
|
+
* NOTE: This generator only handles NEW cards. Reviews are handled by
|
|
699
|
+
* SRSNavigator. Use CompositeGenerator to combine both.
|
|
630
700
|
*
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
* via Pipeline. Filters do not directly implement getWeightedCards().
|
|
701
|
+
* This method supports both the legacy signature (limit only) and the
|
|
702
|
+
* CardGenerator interface signature (limit, context).
|
|
634
703
|
*
|
|
635
|
-
* @param limit - Maximum cards to return
|
|
636
|
-
* @
|
|
704
|
+
* @param limit - Maximum number of cards to return
|
|
705
|
+
* @param context - Optional GeneratorContext (used when called via Pipeline)
|
|
637
706
|
*/
|
|
638
|
-
async getWeightedCards(
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
707
|
+
async getWeightedCards(limit, context) {
|
|
708
|
+
let userGlobalElo;
|
|
709
|
+
if (context?.userElo !== void 0) {
|
|
710
|
+
userGlobalElo = context.userElo;
|
|
711
|
+
} else {
|
|
712
|
+
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
713
|
+
const userElo = (0, import_common5.toCourseElo)(courseReg.elo);
|
|
714
|
+
userGlobalElo = userElo.global.score;
|
|
715
|
+
}
|
|
716
|
+
const activeCards = await this.user.getActiveCards();
|
|
717
|
+
const newCards = (await this.course.getCardsCenteredAtELO(
|
|
718
|
+
{ limit, elo: "user" },
|
|
719
|
+
(c) => !activeCards.some((ac) => c.cardID === ac.cardID)
|
|
720
|
+
)).map((c) => ({ ...c, status: "new" }));
|
|
721
|
+
const cardIds = newCards.map((c) => c.cardID);
|
|
722
|
+
const cardEloData = await this.course.getCardEloData(cardIds);
|
|
723
|
+
const scored = newCards.map((c, i) => {
|
|
724
|
+
const cardElo = cardEloData[i]?.global?.score ?? 1e3;
|
|
725
|
+
const distance = Math.abs(cardElo - userGlobalElo);
|
|
726
|
+
const score = Math.max(0, 1 - distance / 500);
|
|
727
|
+
return {
|
|
728
|
+
cardId: c.cardID,
|
|
729
|
+
courseId: c.courseID,
|
|
730
|
+
score,
|
|
731
|
+
provenance: [
|
|
732
|
+
{
|
|
733
|
+
strategy: "elo",
|
|
734
|
+
strategyName: this.strategyName || this.name,
|
|
735
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-ELO-default",
|
|
736
|
+
action: "generated",
|
|
737
|
+
score,
|
|
738
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userGlobalElo)}), new card`
|
|
739
|
+
}
|
|
740
|
+
]
|
|
741
|
+
};
|
|
742
|
+
});
|
|
743
|
+
scored.sort((a, b) => b.score - a.score);
|
|
744
|
+
return scored.slice(0, limit);
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
});
|
|
749
|
+
|
|
750
|
+
// src/core/navigators/generators/index.ts
|
|
751
|
+
var generators_exports = {};
|
|
752
|
+
var init_generators = __esm({
|
|
753
|
+
"src/core/navigators/generators/index.ts"() {
|
|
754
|
+
"use strict";
|
|
755
|
+
}
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
// src/core/navigators/generators/srs.ts
|
|
759
|
+
var srs_exports = {};
|
|
760
|
+
__export(srs_exports, {
|
|
761
|
+
default: () => SRSNavigator
|
|
762
|
+
});
|
|
763
|
+
var import_moment3, SRSNavigator;
|
|
764
|
+
var init_srs = __esm({
|
|
765
|
+
"src/core/navigators/generators/srs.ts"() {
|
|
766
|
+
"use strict";
|
|
767
|
+
import_moment3 = __toESM(require("moment"), 1);
|
|
768
|
+
init_navigators();
|
|
769
|
+
init_logger();
|
|
770
|
+
SRSNavigator = class extends ContentNavigator {
|
|
771
|
+
/** Human-readable name for CardGenerator interface */
|
|
772
|
+
name;
|
|
773
|
+
constructor(user, course, strategyData) {
|
|
774
|
+
super(user, course, strategyData);
|
|
775
|
+
this.name = strategyData?.name || "SRS";
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Get review cards scored by urgency.
|
|
779
|
+
*
|
|
780
|
+
* Score formula combines:
|
|
781
|
+
* - Relative overdueness: hoursOverdue / intervalHours
|
|
782
|
+
* - Interval recency: exponential decay favoring shorter intervals
|
|
783
|
+
*
|
|
784
|
+
* Cards not yet due are excluded (not scored as 0).
|
|
785
|
+
*
|
|
786
|
+
* This method supports both the legacy signature (limit only) and the
|
|
787
|
+
* CardGenerator interface signature (limit, context).
|
|
788
|
+
*
|
|
789
|
+
* @param limit - Maximum number of cards to return
|
|
790
|
+
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
791
|
+
*/
|
|
792
|
+
async getWeightedCards(limit, _context) {
|
|
793
|
+
if (!this.user || !this.course) {
|
|
794
|
+
throw new Error("SRSNavigator requires user and course to be set");
|
|
795
|
+
}
|
|
796
|
+
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
797
|
+
const now = import_moment3.default.utc();
|
|
798
|
+
const dueReviews = reviews.filter((r) => now.isAfter(import_moment3.default.utc(r.reviewTime)));
|
|
799
|
+
const scored = dueReviews.map((review) => {
|
|
800
|
+
const { score, reason } = this.computeUrgencyScore(review, now);
|
|
801
|
+
return {
|
|
802
|
+
cardId: review.cardId,
|
|
803
|
+
courseId: review.courseId,
|
|
804
|
+
score,
|
|
805
|
+
reviewID: review._id,
|
|
806
|
+
provenance: [
|
|
807
|
+
{
|
|
808
|
+
strategy: "srs",
|
|
809
|
+
strategyName: this.strategyName || this.name,
|
|
810
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-SRS-default",
|
|
811
|
+
action: "generated",
|
|
812
|
+
score,
|
|
813
|
+
reason
|
|
814
|
+
}
|
|
815
|
+
]
|
|
816
|
+
};
|
|
817
|
+
});
|
|
818
|
+
logger.debug(`[srsNav] got ${scored.length} weighted cards`);
|
|
819
|
+
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* Compute urgency score for a review card.
|
|
823
|
+
*
|
|
824
|
+
* Two factors:
|
|
825
|
+
* 1. Relative overdueness = hoursOverdue / intervalHours
|
|
826
|
+
* - 2 days overdue on 3-day interval = 0.67 (urgent)
|
|
827
|
+
* - 2 days overdue on 180-day interval = 0.01 (not urgent)
|
|
828
|
+
*
|
|
829
|
+
* 2. Interval recency factor = 0.3 + 0.7 * exp(-intervalHours / 720)
|
|
830
|
+
* - 24h interval → ~1.0 (very recent learning)
|
|
831
|
+
* - 30 days (720h) → ~0.56
|
|
832
|
+
* - 180 days → ~0.30
|
|
833
|
+
*
|
|
834
|
+
* Combined: base 0.5 + weighted average of factors * 0.45
|
|
835
|
+
* Result range: approximately 0.5 to 0.95
|
|
836
|
+
*/
|
|
837
|
+
computeUrgencyScore(review, now) {
|
|
838
|
+
const scheduledAt = import_moment3.default.utc(review.scheduledAt);
|
|
839
|
+
const due = import_moment3.default.utc(review.reviewTime);
|
|
840
|
+
const intervalHours = Math.max(1, due.diff(scheduledAt, "hours"));
|
|
841
|
+
const hoursOverdue = now.diff(due, "hours");
|
|
842
|
+
const relativeOverdue = hoursOverdue / intervalHours;
|
|
843
|
+
const recencyFactor = 0.3 + 0.7 * Math.exp(-intervalHours / 720);
|
|
844
|
+
const overdueContribution = Math.min(1, Math.max(0, relativeOverdue));
|
|
845
|
+
const urgency = overdueContribution * 0.5 + recencyFactor * 0.5;
|
|
846
|
+
const score = Math.min(0.95, 0.5 + urgency * 0.45);
|
|
847
|
+
const reason = `${Math.round(hoursOverdue)}h overdue (interval: ${Math.round(intervalHours)}h, relative: ${relativeOverdue.toFixed(2)}), recency: ${recencyFactor.toFixed(2)}, review`;
|
|
848
|
+
return { score, reason };
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
});
|
|
853
|
+
|
|
854
|
+
// src/core/navigators/generators/types.ts
|
|
855
|
+
var types_exports = {};
|
|
856
|
+
var init_types = __esm({
|
|
857
|
+
"src/core/navigators/generators/types.ts"() {
|
|
858
|
+
"use strict";
|
|
859
|
+
}
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
// import("./generators/**/*") in src/core/navigators/index.ts
|
|
863
|
+
var globImport_generators;
|
|
864
|
+
var init_ = __esm({
|
|
865
|
+
'import("./generators/**/*") in src/core/navigators/index.ts'() {
|
|
866
|
+
globImport_generators = __glob({
|
|
867
|
+
"./generators/CompositeGenerator.ts": () => Promise.resolve().then(() => (init_CompositeGenerator(), CompositeGenerator_exports)),
|
|
868
|
+
"./generators/elo.ts": () => Promise.resolve().then(() => (init_elo(), elo_exports)),
|
|
869
|
+
"./generators/index.ts": () => Promise.resolve().then(() => (init_generators(), generators_exports)),
|
|
870
|
+
"./generators/srs.ts": () => Promise.resolve().then(() => (init_srs(), srs_exports)),
|
|
871
|
+
"./generators/types.ts": () => Promise.resolve().then(() => (init_types(), types_exports))
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
|
|
876
|
+
// src/core/types/contentNavigationStrategy.ts
|
|
877
|
+
var DEFAULT_LEARNABLE_WEIGHT;
|
|
878
|
+
var init_contentNavigationStrategy = __esm({
|
|
879
|
+
"src/core/types/contentNavigationStrategy.ts"() {
|
|
880
|
+
"use strict";
|
|
881
|
+
DEFAULT_LEARNABLE_WEIGHT = {
|
|
882
|
+
weight: 1,
|
|
883
|
+
confidence: 0.1,
|
|
884
|
+
// Low confidence initially = wide exploration
|
|
885
|
+
sampleSize: 0
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
|
|
890
|
+
// src/core/navigators/filters/WeightedFilter.ts
|
|
891
|
+
var WeightedFilter_exports = {};
|
|
892
|
+
__export(WeightedFilter_exports, {
|
|
893
|
+
WeightedFilter: () => WeightedFilter
|
|
894
|
+
});
|
|
895
|
+
var WeightedFilter;
|
|
896
|
+
var init_WeightedFilter = __esm({
|
|
897
|
+
"src/core/navigators/filters/WeightedFilter.ts"() {
|
|
898
|
+
"use strict";
|
|
899
|
+
init_contentNavigationStrategy();
|
|
900
|
+
WeightedFilter = class {
|
|
901
|
+
name;
|
|
902
|
+
inner;
|
|
903
|
+
learnable;
|
|
904
|
+
staticWeight;
|
|
905
|
+
strategyId;
|
|
906
|
+
constructor(inner, learnable = DEFAULT_LEARNABLE_WEIGHT, staticWeight = false, strategyId) {
|
|
907
|
+
this.inner = inner;
|
|
908
|
+
this.name = inner.name;
|
|
909
|
+
this.learnable = learnable;
|
|
910
|
+
this.staticWeight = staticWeight;
|
|
911
|
+
this.strategyId = strategyId;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Apply the inner filter, then scale its effect by the configured weight.
|
|
915
|
+
*/
|
|
916
|
+
async transform(cards, context) {
|
|
917
|
+
let effectiveWeight = this.learnable.weight;
|
|
918
|
+
let deviation;
|
|
919
|
+
if (!this.staticWeight && context.orchestration) {
|
|
920
|
+
const strategyId = this.strategyId || this.inner.strategyId || this.name;
|
|
921
|
+
effectiveWeight = context.orchestration.getEffectiveWeight(strategyId, this.learnable);
|
|
922
|
+
deviation = context.orchestration.getDeviation(strategyId);
|
|
923
|
+
}
|
|
924
|
+
if (Math.abs(effectiveWeight - 1) < 1e-3) {
|
|
925
|
+
return this.inner.transform(cards, context);
|
|
926
|
+
}
|
|
927
|
+
const originalScores = /* @__PURE__ */ new Map();
|
|
928
|
+
for (const card of cards) {
|
|
929
|
+
originalScores.set(card.cardId, card.score);
|
|
930
|
+
}
|
|
931
|
+
const transformedCards = await this.inner.transform(cards, context);
|
|
932
|
+
return transformedCards.map((card) => {
|
|
933
|
+
const originalScore = originalScores.get(card.cardId);
|
|
934
|
+
if (originalScore === void 0 || originalScore === 0 || card.score === 0) {
|
|
935
|
+
return card;
|
|
936
|
+
}
|
|
937
|
+
const rawEffect = card.score / originalScore;
|
|
938
|
+
if (Math.abs(rawEffect - 1) < 1e-4) {
|
|
939
|
+
return card;
|
|
940
|
+
}
|
|
941
|
+
const weightedEffect = Math.pow(rawEffect, effectiveWeight);
|
|
942
|
+
const newScore = originalScore * weightedEffect;
|
|
943
|
+
const lastProvIndex = card.provenance.length - 1;
|
|
944
|
+
const lastProv = card.provenance[lastProvIndex];
|
|
945
|
+
if (lastProv) {
|
|
946
|
+
const updatedProvenance = [...card.provenance];
|
|
947
|
+
updatedProvenance[lastProvIndex] = {
|
|
948
|
+
...lastProv,
|
|
949
|
+
score: newScore,
|
|
950
|
+
effectiveWeight,
|
|
951
|
+
deviation
|
|
952
|
+
// We can optionally append to the reason, but the structured field is key
|
|
953
|
+
};
|
|
954
|
+
return {
|
|
955
|
+
...card,
|
|
956
|
+
score: newScore,
|
|
957
|
+
provenance: updatedProvenance
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
return {
|
|
961
|
+
...card,
|
|
962
|
+
score: newScore
|
|
963
|
+
};
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
});
|
|
969
|
+
|
|
970
|
+
// src/core/navigators/filters/eloDistance.ts
|
|
971
|
+
var eloDistance_exports = {};
|
|
972
|
+
__export(eloDistance_exports, {
|
|
973
|
+
DEFAULT_HALF_LIFE: () => DEFAULT_HALF_LIFE,
|
|
974
|
+
DEFAULT_MAX_MULTIPLIER: () => DEFAULT_MAX_MULTIPLIER,
|
|
975
|
+
DEFAULT_MIN_MULTIPLIER: () => DEFAULT_MIN_MULTIPLIER,
|
|
976
|
+
createEloDistanceFilter: () => createEloDistanceFilter
|
|
977
|
+
});
|
|
978
|
+
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
979
|
+
const normalizedDistance = distance / halfLife;
|
|
980
|
+
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
981
|
+
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
982
|
+
}
|
|
983
|
+
function createEloDistanceFilter(config) {
|
|
984
|
+
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
985
|
+
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
986
|
+
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
987
|
+
return {
|
|
988
|
+
name: "ELO Distance Filter",
|
|
989
|
+
async transform(cards, context) {
|
|
990
|
+
const { course, userElo } = context;
|
|
991
|
+
const cardIds = cards.map((c) => c.cardId);
|
|
992
|
+
const cardElos = await course.getCardEloData(cardIds);
|
|
993
|
+
return cards.map((card, i) => {
|
|
994
|
+
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
995
|
+
const distance = Math.abs(cardElo - userElo);
|
|
996
|
+
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
997
|
+
const newScore = card.score * multiplier;
|
|
998
|
+
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
999
|
+
return {
|
|
1000
|
+
...card,
|
|
1001
|
+
score: newScore,
|
|
1002
|
+
provenance: [
|
|
1003
|
+
...card.provenance,
|
|
1004
|
+
{
|
|
1005
|
+
strategy: "eloDistance",
|
|
1006
|
+
strategyName: "ELO Distance Filter",
|
|
1007
|
+
strategyId: "ELO_DISTANCE_FILTER",
|
|
1008
|
+
action,
|
|
1009
|
+
score: newScore,
|
|
1010
|
+
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
1011
|
+
}
|
|
1012
|
+
]
|
|
1013
|
+
};
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
var DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER;
|
|
1019
|
+
var init_eloDistance = __esm({
|
|
1020
|
+
"src/core/navigators/filters/eloDistance.ts"() {
|
|
1021
|
+
"use strict";
|
|
1022
|
+
DEFAULT_HALF_LIFE = 200;
|
|
1023
|
+
DEFAULT_MIN_MULTIPLIER = 0.3;
|
|
1024
|
+
DEFAULT_MAX_MULTIPLIER = 1;
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
|
|
1028
|
+
// src/core/navigators/filters/hierarchyDefinition.ts
|
|
1029
|
+
var hierarchyDefinition_exports = {};
|
|
1030
|
+
__export(hierarchyDefinition_exports, {
|
|
1031
|
+
default: () => HierarchyDefinitionNavigator
|
|
1032
|
+
});
|
|
1033
|
+
var import_common6, DEFAULT_MIN_COUNT, HierarchyDefinitionNavigator;
|
|
1034
|
+
var init_hierarchyDefinition = __esm({
|
|
1035
|
+
"src/core/navigators/filters/hierarchyDefinition.ts"() {
|
|
1036
|
+
"use strict";
|
|
1037
|
+
init_navigators();
|
|
1038
|
+
import_common6 = require("@vue-skuilder/common");
|
|
1039
|
+
DEFAULT_MIN_COUNT = 3;
|
|
1040
|
+
HierarchyDefinitionNavigator = class extends ContentNavigator {
|
|
1041
|
+
config;
|
|
1042
|
+
/** Human-readable name for CardFilter interface */
|
|
1043
|
+
name;
|
|
1044
|
+
constructor(user, course, strategyData) {
|
|
1045
|
+
super(user, course, strategyData);
|
|
1046
|
+
this.config = this.parseConfig(strategyData.serializedData);
|
|
1047
|
+
this.name = strategyData.name || "Hierarchy Definition";
|
|
1048
|
+
}
|
|
1049
|
+
parseConfig(serializedData) {
|
|
1050
|
+
try {
|
|
1051
|
+
const parsed = JSON.parse(serializedData);
|
|
1052
|
+
return {
|
|
1053
|
+
prerequisites: parsed.prerequisites || {}
|
|
1054
|
+
};
|
|
1055
|
+
} catch {
|
|
1056
|
+
return {
|
|
1057
|
+
prerequisites: {}
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
/**
|
|
1062
|
+
* Check if a specific prerequisite is satisfied
|
|
1063
|
+
*/
|
|
1064
|
+
isPrerequisiteMet(prereq, userTagElo, userGlobalElo) {
|
|
1065
|
+
if (!userTagElo) return false;
|
|
1066
|
+
const minCount = prereq.masteryThreshold?.minCount ?? DEFAULT_MIN_COUNT;
|
|
1067
|
+
if (userTagElo.count < minCount) return false;
|
|
1068
|
+
if (prereq.masteryThreshold?.minElo !== void 0) {
|
|
1069
|
+
return userTagElo.score >= prereq.masteryThreshold.minElo;
|
|
1070
|
+
} else {
|
|
1071
|
+
return userTagElo.score >= userGlobalElo;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Get the set of tags the user has mastered.
|
|
1076
|
+
* A tag is "mastered" if it appears as a prerequisite somewhere and meets its threshold.
|
|
1077
|
+
*/
|
|
1078
|
+
async getMasteredTags(context) {
|
|
1079
|
+
const mastered = /* @__PURE__ */ new Set();
|
|
1080
|
+
try {
|
|
1081
|
+
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1082
|
+
const userElo = (0, import_common6.toCourseElo)(courseReg.elo);
|
|
1083
|
+
for (const prereqs of Object.values(this.config.prerequisites)) {
|
|
1084
|
+
for (const prereq of prereqs) {
|
|
1085
|
+
const tagElo = userElo.tags[prereq.tag];
|
|
1086
|
+
if (this.isPrerequisiteMet(prereq, tagElo, userElo.global.score)) {
|
|
1087
|
+
mastered.add(prereq.tag);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
} catch {
|
|
1092
|
+
}
|
|
1093
|
+
return mastered;
|
|
1094
|
+
}
|
|
1095
|
+
/**
|
|
1096
|
+
* Get the set of tags that are unlocked (prerequisites met)
|
|
1097
|
+
*/
|
|
1098
|
+
getUnlockedTags(masteredTags) {
|
|
1099
|
+
const unlocked = /* @__PURE__ */ new Set();
|
|
1100
|
+
for (const [tagId, prereqs] of Object.entries(this.config.prerequisites)) {
|
|
1101
|
+
const allPrereqsMet = prereqs.every((prereq) => masteredTags.has(prereq.tag));
|
|
1102
|
+
if (allPrereqsMet) {
|
|
1103
|
+
unlocked.add(tagId);
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
return unlocked;
|
|
1107
|
+
}
|
|
1108
|
+
/**
|
|
1109
|
+
* Check if a tag has prerequisites defined in config
|
|
1110
|
+
*/
|
|
1111
|
+
hasPrerequisites(tagId) {
|
|
1112
|
+
return tagId in this.config.prerequisites;
|
|
1113
|
+
}
|
|
1114
|
+
/**
|
|
1115
|
+
* Check if a card is unlocked and generate reason.
|
|
1116
|
+
*/
|
|
1117
|
+
async checkCardUnlock(card, _course, unlockedTags, masteredTags) {
|
|
1118
|
+
try {
|
|
1119
|
+
const cardTags = card.tags ?? [];
|
|
1120
|
+
const lockedTags = cardTags.filter(
|
|
1121
|
+
(tag) => this.hasPrerequisites(tag) && !unlockedTags.has(tag)
|
|
1122
|
+
);
|
|
1123
|
+
if (lockedTags.length === 0) {
|
|
1124
|
+
const tagList = cardTags.length > 0 ? cardTags.join(", ") : "none";
|
|
1125
|
+
return {
|
|
1126
|
+
isUnlocked: true,
|
|
1127
|
+
reason: `Prerequisites met, tags: ${tagList}`
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
const missingPrereqs = lockedTags.flatMap((tag) => {
|
|
1131
|
+
const prereqs = this.config.prerequisites[tag] || [];
|
|
1132
|
+
return prereqs.filter((p) => !masteredTags.has(p.tag)).map((p) => p.tag);
|
|
1133
|
+
});
|
|
1134
|
+
return {
|
|
1135
|
+
isUnlocked: false,
|
|
1136
|
+
reason: `Blocked: missing prerequisites ${missingPrereqs.join(", ")} for tags ${lockedTags.join(", ")}`
|
|
1137
|
+
};
|
|
1138
|
+
} catch {
|
|
1139
|
+
return {
|
|
1140
|
+
isUnlocked: true,
|
|
1141
|
+
reason: "Prerequisites check skipped (tag lookup failed)"
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
/**
|
|
1146
|
+
* CardFilter.transform implementation.
|
|
1147
|
+
*
|
|
1148
|
+
* Apply prerequisite gating to cards. Cards with locked tags receive score: 0.
|
|
1149
|
+
*/
|
|
1150
|
+
async transform(cards, context) {
|
|
1151
|
+
const masteredTags = await this.getMasteredTags(context);
|
|
1152
|
+
const unlockedTags = this.getUnlockedTags(masteredTags);
|
|
1153
|
+
const gated = [];
|
|
1154
|
+
for (const card of cards) {
|
|
1155
|
+
const { isUnlocked, reason } = await this.checkCardUnlock(
|
|
1156
|
+
card,
|
|
1157
|
+
context.course,
|
|
1158
|
+
unlockedTags,
|
|
1159
|
+
masteredTags
|
|
1160
|
+
);
|
|
1161
|
+
const finalScore = isUnlocked ? card.score : 0;
|
|
1162
|
+
const action = isUnlocked ? "passed" : "penalized";
|
|
1163
|
+
gated.push({
|
|
1164
|
+
...card,
|
|
1165
|
+
score: finalScore,
|
|
1166
|
+
provenance: [
|
|
1167
|
+
...card.provenance,
|
|
1168
|
+
{
|
|
1169
|
+
strategy: "hierarchyDefinition",
|
|
1170
|
+
strategyName: this.strategyName || this.name,
|
|
1171
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-hierarchy",
|
|
1172
|
+
action,
|
|
1173
|
+
score: finalScore,
|
|
1174
|
+
reason
|
|
1175
|
+
}
|
|
1176
|
+
]
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
return gated;
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1183
|
+
*
|
|
1184
|
+
* Use transform() via Pipeline instead.
|
|
1185
|
+
*/
|
|
1186
|
+
async getWeightedCards(_limit) {
|
|
1187
|
+
throw new Error(
|
|
1188
|
+
"HierarchyDefinitionNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1189
|
+
);
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
}
|
|
1193
|
+
});
|
|
1194
|
+
|
|
1195
|
+
// src/core/navigators/filters/userTagPreference.ts
|
|
1196
|
+
var userTagPreference_exports = {};
|
|
1197
|
+
__export(userTagPreference_exports, {
|
|
1198
|
+
default: () => UserTagPreferenceFilter
|
|
1199
|
+
});
|
|
1200
|
+
var UserTagPreferenceFilter;
|
|
1201
|
+
var init_userTagPreference = __esm({
|
|
1202
|
+
"src/core/navigators/filters/userTagPreference.ts"() {
|
|
1203
|
+
"use strict";
|
|
1204
|
+
init_navigators();
|
|
1205
|
+
UserTagPreferenceFilter = class extends ContentNavigator {
|
|
1206
|
+
_strategyData;
|
|
1207
|
+
/** Human-readable name for CardFilter interface */
|
|
1208
|
+
name;
|
|
1209
|
+
constructor(user, course, strategyData) {
|
|
1210
|
+
super(user, course, strategyData);
|
|
1211
|
+
this._strategyData = strategyData;
|
|
1212
|
+
this.name = strategyData.name || "User Tag Preferences";
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1215
|
+
* Compute multiplier for a card based on its tags and user preferences.
|
|
1216
|
+
* Returns the maximum multiplier among all matching tags, or 1.0 if no matches.
|
|
1217
|
+
*/
|
|
1218
|
+
computeMultiplier(cardTags, boostMap) {
|
|
1219
|
+
const multipliers = cardTags.map((tag) => boostMap[tag]).filter((val) => val !== void 0);
|
|
1220
|
+
if (multipliers.length === 0) {
|
|
1221
|
+
return 1;
|
|
1222
|
+
}
|
|
1223
|
+
return Math.max(...multipliers);
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* Build human-readable reason for the filter's decision.
|
|
1227
|
+
*/
|
|
1228
|
+
buildReason(cardTags, boostMap, multiplier) {
|
|
1229
|
+
const matchingTags = cardTags.filter((tag) => boostMap[tag] === multiplier);
|
|
1230
|
+
if (multiplier === 0) {
|
|
1231
|
+
return `Excluded by user preference: ${matchingTags.join(", ")} (${multiplier}x)`;
|
|
1232
|
+
}
|
|
1233
|
+
if (multiplier < 1) {
|
|
1234
|
+
return `Penalized by user preference: ${matchingTags.join(", ")} (${multiplier.toFixed(2)}x)`;
|
|
1235
|
+
}
|
|
1236
|
+
if (multiplier > 1) {
|
|
1237
|
+
return `Boosted by user preference: ${matchingTags.join(", ")} (${multiplier.toFixed(2)}x)`;
|
|
1238
|
+
}
|
|
1239
|
+
return "No matching user preferences";
|
|
1240
|
+
}
|
|
1241
|
+
/**
|
|
1242
|
+
* CardFilter.transform implementation.
|
|
1243
|
+
*
|
|
1244
|
+
* Apply user tag preferences:
|
|
1245
|
+
* 1. Read preferences from strategy state
|
|
1246
|
+
* 2. If no preferences, pass through unchanged
|
|
1247
|
+
* 3. For each card:
|
|
1248
|
+
* - Look up tag in boost record
|
|
1249
|
+
* - If tag found: apply multiplier (0 = exclude, 1 = neutral, >1 = boost)
|
|
1250
|
+
* - If multiple tags match: use max multiplier
|
|
1251
|
+
* - Append provenance with clear reason
|
|
1252
|
+
*/
|
|
1253
|
+
async transform(cards, _context) {
|
|
1254
|
+
const prefs = await this.getStrategyState();
|
|
1255
|
+
if (!prefs || Object.keys(prefs.boost).length === 0) {
|
|
1256
|
+
return cards.map((card) => ({
|
|
1257
|
+
...card,
|
|
1258
|
+
provenance: [
|
|
1259
|
+
...card.provenance,
|
|
1260
|
+
{
|
|
1261
|
+
strategy: "userTagPreference",
|
|
1262
|
+
strategyName: this.strategyName || this.name,
|
|
1263
|
+
strategyId: this.strategyId || this._strategyData._id,
|
|
1264
|
+
action: "passed",
|
|
1265
|
+
score: card.score,
|
|
1266
|
+
reason: "No user tag preferences configured"
|
|
1267
|
+
}
|
|
1268
|
+
]
|
|
1269
|
+
}));
|
|
1270
|
+
}
|
|
1271
|
+
const adjusted = await Promise.all(
|
|
1272
|
+
cards.map(async (card) => {
|
|
1273
|
+
const cardTags = card.tags ?? [];
|
|
1274
|
+
const multiplier = this.computeMultiplier(cardTags, prefs.boost);
|
|
1275
|
+
const finalScore = Math.min(1, card.score * multiplier);
|
|
1276
|
+
let action;
|
|
1277
|
+
if (multiplier === 0 || multiplier < 1) {
|
|
1278
|
+
action = "penalized";
|
|
1279
|
+
} else if (multiplier > 1) {
|
|
1280
|
+
action = "boosted";
|
|
1281
|
+
} else {
|
|
1282
|
+
action = "passed";
|
|
1283
|
+
}
|
|
1284
|
+
return {
|
|
1285
|
+
...card,
|
|
1286
|
+
score: finalScore,
|
|
1287
|
+
provenance: [
|
|
1288
|
+
...card.provenance,
|
|
1289
|
+
{
|
|
1290
|
+
strategy: "userTagPreference",
|
|
1291
|
+
strategyName: this.strategyName || this.name,
|
|
1292
|
+
strategyId: this.strategyId || this._strategyData._id,
|
|
1293
|
+
action,
|
|
1294
|
+
score: finalScore,
|
|
1295
|
+
reason: this.buildReason(cardTags, prefs.boost, multiplier)
|
|
1296
|
+
}
|
|
1297
|
+
]
|
|
1298
|
+
};
|
|
1299
|
+
})
|
|
1300
|
+
);
|
|
1301
|
+
return adjusted;
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
* Legacy getWeightedCards - throws as filters should not be used as generators.
|
|
1305
|
+
*/
|
|
1306
|
+
async getWeightedCards(_limit) {
|
|
1307
|
+
throw new Error(
|
|
1308
|
+
"UserTagPreferenceFilter is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1309
|
+
);
|
|
1310
|
+
}
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
});
|
|
1314
|
+
|
|
1315
|
+
// src/core/navigators/filters/index.ts
|
|
1316
|
+
var filters_exports = {};
|
|
1317
|
+
__export(filters_exports, {
|
|
1318
|
+
UserTagPreferenceFilter: () => UserTagPreferenceFilter,
|
|
1319
|
+
createEloDistanceFilter: () => createEloDistanceFilter
|
|
1320
|
+
});
|
|
1321
|
+
var init_filters = __esm({
|
|
1322
|
+
"src/core/navigators/filters/index.ts"() {
|
|
1323
|
+
"use strict";
|
|
1324
|
+
init_eloDistance();
|
|
1325
|
+
init_userTagPreference();
|
|
1326
|
+
}
|
|
1327
|
+
});
|
|
1328
|
+
|
|
1329
|
+
// src/core/navigators/filters/inferredPreferenceStub.ts
|
|
1330
|
+
var inferredPreferenceStub_exports = {};
|
|
1331
|
+
__export(inferredPreferenceStub_exports, {
|
|
1332
|
+
INFERRED_PREFERENCE_NAVIGATOR_STUB: () => INFERRED_PREFERENCE_NAVIGATOR_STUB
|
|
1333
|
+
});
|
|
1334
|
+
var INFERRED_PREFERENCE_NAVIGATOR_STUB;
|
|
1335
|
+
var init_inferredPreferenceStub = __esm({
|
|
1336
|
+
"src/core/navigators/filters/inferredPreferenceStub.ts"() {
|
|
1337
|
+
"use strict";
|
|
1338
|
+
INFERRED_PREFERENCE_NAVIGATOR_STUB = true;
|
|
1339
|
+
}
|
|
1340
|
+
});
|
|
1341
|
+
|
|
1342
|
+
// src/core/navigators/filters/interferenceMitigator.ts
|
|
1343
|
+
var interferenceMitigator_exports = {};
|
|
1344
|
+
__export(interferenceMitigator_exports, {
|
|
1345
|
+
default: () => InterferenceMitigatorNavigator
|
|
1346
|
+
});
|
|
1347
|
+
var import_common7, DEFAULT_MIN_COUNT2, DEFAULT_MIN_ELAPSED_DAYS, DEFAULT_INTERFERENCE_DECAY, InterferenceMitigatorNavigator;
|
|
1348
|
+
var init_interferenceMitigator = __esm({
|
|
1349
|
+
"src/core/navigators/filters/interferenceMitigator.ts"() {
|
|
1350
|
+
"use strict";
|
|
1351
|
+
init_navigators();
|
|
1352
|
+
import_common7 = require("@vue-skuilder/common");
|
|
1353
|
+
DEFAULT_MIN_COUNT2 = 10;
|
|
1354
|
+
DEFAULT_MIN_ELAPSED_DAYS = 3;
|
|
1355
|
+
DEFAULT_INTERFERENCE_DECAY = 0.8;
|
|
1356
|
+
InterferenceMitigatorNavigator = class extends ContentNavigator {
|
|
1357
|
+
config;
|
|
1358
|
+
/** Human-readable name for CardFilter interface */
|
|
1359
|
+
name;
|
|
1360
|
+
/** Precomputed map: tag -> set of { partner, decay } it interferes with */
|
|
1361
|
+
interferenceMap;
|
|
1362
|
+
constructor(user, course, strategyData) {
|
|
1363
|
+
super(user, course, strategyData);
|
|
1364
|
+
this.config = this.parseConfig(strategyData.serializedData);
|
|
1365
|
+
this.interferenceMap = this.buildInterferenceMap();
|
|
1366
|
+
this.name = strategyData.name || "Interference Mitigator";
|
|
1367
|
+
}
|
|
1368
|
+
parseConfig(serializedData) {
|
|
1369
|
+
try {
|
|
1370
|
+
const parsed = JSON.parse(serializedData);
|
|
1371
|
+
let sets = parsed.interferenceSets || [];
|
|
1372
|
+
if (sets.length > 0 && Array.isArray(sets[0])) {
|
|
1373
|
+
sets = sets.map((tags) => ({ tags }));
|
|
1374
|
+
}
|
|
1375
|
+
return {
|
|
1376
|
+
interferenceSets: sets,
|
|
1377
|
+
maturityThreshold: {
|
|
1378
|
+
minCount: parsed.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2,
|
|
1379
|
+
minElo: parsed.maturityThreshold?.minElo,
|
|
1380
|
+
minElapsedDays: parsed.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS
|
|
1381
|
+
},
|
|
1382
|
+
defaultDecay: parsed.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY
|
|
1383
|
+
};
|
|
1384
|
+
} catch {
|
|
1385
|
+
return {
|
|
1386
|
+
interferenceSets: [],
|
|
1387
|
+
maturityThreshold: {
|
|
1388
|
+
minCount: DEFAULT_MIN_COUNT2,
|
|
1389
|
+
minElapsedDays: DEFAULT_MIN_ELAPSED_DAYS
|
|
1390
|
+
},
|
|
1391
|
+
defaultDecay: DEFAULT_INTERFERENCE_DECAY
|
|
1392
|
+
};
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
/**
|
|
1396
|
+
* Build a map from each tag to its interference partners with decay coefficients.
|
|
1397
|
+
* If tags A, B, C are in an interference group with decay 0.8, then:
|
|
1398
|
+
* - A interferes with B (decay 0.8) and C (decay 0.8)
|
|
1399
|
+
* - B interferes with A (decay 0.8) and C (decay 0.8)
|
|
1400
|
+
* - etc.
|
|
1401
|
+
*/
|
|
1402
|
+
buildInterferenceMap() {
|
|
1403
|
+
const map = /* @__PURE__ */ new Map();
|
|
1404
|
+
for (const group of this.config.interferenceSets) {
|
|
1405
|
+
const decay = group.decay ?? this.config.defaultDecay ?? DEFAULT_INTERFERENCE_DECAY;
|
|
1406
|
+
for (const tag of group.tags) {
|
|
1407
|
+
if (!map.has(tag)) {
|
|
1408
|
+
map.set(tag, []);
|
|
1409
|
+
}
|
|
1410
|
+
const partners = map.get(tag);
|
|
1411
|
+
for (const other of group.tags) {
|
|
1412
|
+
if (other !== tag) {
|
|
1413
|
+
const existing = partners.find((p) => p.partner === other);
|
|
1414
|
+
if (existing) {
|
|
1415
|
+
existing.decay = Math.max(existing.decay, decay);
|
|
1416
|
+
} else {
|
|
1417
|
+
partners.push({ partner: other, decay });
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
return map;
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* Get the set of tags that are currently immature for this user.
|
|
1427
|
+
* A tag is immature if the user has interacted with it but hasn't
|
|
1428
|
+
* reached the maturity threshold.
|
|
1429
|
+
*/
|
|
1430
|
+
async getImmatureTags(context) {
|
|
1431
|
+
const immature = /* @__PURE__ */ new Set();
|
|
1432
|
+
try {
|
|
1433
|
+
const courseReg = await context.user.getCourseRegDoc(context.course.getCourseID());
|
|
1434
|
+
const userElo = (0, import_common7.toCourseElo)(courseReg.elo);
|
|
1435
|
+
const minCount = this.config.maturityThreshold?.minCount ?? DEFAULT_MIN_COUNT2;
|
|
1436
|
+
const minElo = this.config.maturityThreshold?.minElo;
|
|
1437
|
+
const minElapsedDays = this.config.maturityThreshold?.minElapsedDays ?? DEFAULT_MIN_ELAPSED_DAYS;
|
|
1438
|
+
const minCountForElapsed = minElapsedDays * 2;
|
|
1439
|
+
for (const [tagId, tagElo] of Object.entries(userElo.tags)) {
|
|
1440
|
+
if (tagElo.count === 0) continue;
|
|
1441
|
+
const belowCount = tagElo.count < minCount;
|
|
1442
|
+
const belowElo = minElo !== void 0 && tagElo.score < minElo;
|
|
1443
|
+
const belowElapsed = tagElo.count < minCountForElapsed;
|
|
1444
|
+
if (belowCount || belowElo || belowElapsed) {
|
|
1445
|
+
immature.add(tagId);
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
} catch {
|
|
1449
|
+
}
|
|
1450
|
+
return immature;
|
|
1451
|
+
}
|
|
1452
|
+
/**
|
|
1453
|
+
* Get all tags that interfere with any immature tag, along with their decay coefficients.
|
|
1454
|
+
* These are the tags we want to avoid introducing.
|
|
1455
|
+
*/
|
|
1456
|
+
getTagsToAvoid(immatureTags) {
|
|
1457
|
+
const avoid = /* @__PURE__ */ new Map();
|
|
1458
|
+
for (const immatureTag of immatureTags) {
|
|
1459
|
+
const partners = this.interferenceMap.get(immatureTag);
|
|
1460
|
+
if (partners) {
|
|
1461
|
+
for (const { partner, decay } of partners) {
|
|
1462
|
+
if (!immatureTags.has(partner)) {
|
|
1463
|
+
const existing = avoid.get(partner) ?? 0;
|
|
1464
|
+
avoid.set(partner, Math.max(existing, decay));
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
return avoid;
|
|
1470
|
+
}
|
|
1471
|
+
/**
|
|
1472
|
+
* Compute interference score reduction for a card.
|
|
1473
|
+
* Returns: { multiplier, interfering tags, reason }
|
|
1474
|
+
*/
|
|
1475
|
+
computeInterferenceEffect(cardTags, tagsToAvoid, immatureTags) {
|
|
1476
|
+
if (tagsToAvoid.size === 0) {
|
|
1477
|
+
return {
|
|
1478
|
+
multiplier: 1,
|
|
1479
|
+
interferingTags: [],
|
|
1480
|
+
reason: "No interference detected"
|
|
1481
|
+
};
|
|
1482
|
+
}
|
|
1483
|
+
let multiplier = 1;
|
|
1484
|
+
const interferingTags = [];
|
|
1485
|
+
for (const tag of cardTags) {
|
|
1486
|
+
const decay = tagsToAvoid.get(tag);
|
|
1487
|
+
if (decay !== void 0) {
|
|
1488
|
+
interferingTags.push(tag);
|
|
1489
|
+
multiplier *= 1 - decay;
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
if (interferingTags.length === 0) {
|
|
1493
|
+
return {
|
|
1494
|
+
multiplier: 1,
|
|
1495
|
+
interferingTags: [],
|
|
1496
|
+
reason: "No interference detected"
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1499
|
+
const causingTags = /* @__PURE__ */ new Set();
|
|
1500
|
+
for (const tag of interferingTags) {
|
|
1501
|
+
for (const immatureTag of immatureTags) {
|
|
1502
|
+
const partners = this.interferenceMap.get(immatureTag);
|
|
1503
|
+
if (partners?.some((p) => p.partner === tag)) {
|
|
1504
|
+
causingTags.add(immatureTag);
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
const reason = `Interferes with immature tags ${Array.from(causingTags).join(", ")} (tags: ${interferingTags.join(", ")}, multiplier: ${multiplier.toFixed(2)})`;
|
|
1509
|
+
return { multiplier, interferingTags, reason };
|
|
1510
|
+
}
|
|
1511
|
+
/**
|
|
1512
|
+
* CardFilter.transform implementation.
|
|
1513
|
+
*
|
|
1514
|
+
* Apply interference-aware scoring. Cards with tags that interfere with
|
|
1515
|
+
* immature learnings get reduced scores.
|
|
1516
|
+
*/
|
|
1517
|
+
async transform(cards, context) {
|
|
1518
|
+
const immatureTags = await this.getImmatureTags(context);
|
|
1519
|
+
const tagsToAvoid = this.getTagsToAvoid(immatureTags);
|
|
1520
|
+
const adjusted = [];
|
|
1521
|
+
for (const card of cards) {
|
|
1522
|
+
const cardTags = card.tags ?? [];
|
|
1523
|
+
const { multiplier, reason } = this.computeInterferenceEffect(
|
|
1524
|
+
cardTags,
|
|
1525
|
+
tagsToAvoid,
|
|
1526
|
+
immatureTags
|
|
1527
|
+
);
|
|
1528
|
+
const finalScore = card.score * multiplier;
|
|
1529
|
+
const action = multiplier < 1 ? "penalized" : multiplier > 1 ? "boosted" : "passed";
|
|
1530
|
+
adjusted.push({
|
|
1531
|
+
...card,
|
|
1532
|
+
score: finalScore,
|
|
1533
|
+
provenance: [
|
|
1534
|
+
...card.provenance,
|
|
1535
|
+
{
|
|
1536
|
+
strategy: "interferenceMitigator",
|
|
1537
|
+
strategyName: this.strategyName || this.name,
|
|
1538
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-interference",
|
|
1539
|
+
action,
|
|
1540
|
+
score: finalScore,
|
|
1541
|
+
reason
|
|
1542
|
+
}
|
|
1543
|
+
]
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
return adjusted;
|
|
1547
|
+
}
|
|
1548
|
+
/**
|
|
1549
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1550
|
+
*
|
|
1551
|
+
* Use transform() via Pipeline instead.
|
|
1552
|
+
*/
|
|
1553
|
+
async getWeightedCards(_limit) {
|
|
1554
|
+
throw new Error(
|
|
1555
|
+
"InterferenceMitigatorNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1556
|
+
);
|
|
1557
|
+
}
|
|
1558
|
+
};
|
|
1559
|
+
}
|
|
1560
|
+
});
|
|
1561
|
+
|
|
1562
|
+
// src/core/navigators/filters/relativePriority.ts
|
|
1563
|
+
var relativePriority_exports = {};
|
|
1564
|
+
__export(relativePriority_exports, {
|
|
1565
|
+
default: () => RelativePriorityNavigator
|
|
1566
|
+
});
|
|
1567
|
+
var DEFAULT_PRIORITY, DEFAULT_PRIORITY_INFLUENCE, DEFAULT_COMBINE_MODE, RelativePriorityNavigator;
|
|
1568
|
+
var init_relativePriority = __esm({
|
|
1569
|
+
"src/core/navigators/filters/relativePriority.ts"() {
|
|
1570
|
+
"use strict";
|
|
1571
|
+
init_navigators();
|
|
1572
|
+
DEFAULT_PRIORITY = 0.5;
|
|
1573
|
+
DEFAULT_PRIORITY_INFLUENCE = 0.5;
|
|
1574
|
+
DEFAULT_COMBINE_MODE = "max";
|
|
1575
|
+
RelativePriorityNavigator = class extends ContentNavigator {
|
|
1576
|
+
config;
|
|
1577
|
+
/** Human-readable name for CardFilter interface */
|
|
1578
|
+
name;
|
|
1579
|
+
constructor(user, course, strategyData) {
|
|
1580
|
+
super(user, course, strategyData);
|
|
1581
|
+
this.config = this.parseConfig(strategyData.serializedData);
|
|
1582
|
+
this.name = strategyData.name || "Relative Priority";
|
|
1583
|
+
}
|
|
1584
|
+
parseConfig(serializedData) {
|
|
1585
|
+
try {
|
|
1586
|
+
const parsed = JSON.parse(serializedData);
|
|
1587
|
+
return {
|
|
1588
|
+
tagPriorities: parsed.tagPriorities || {},
|
|
1589
|
+
defaultPriority: parsed.defaultPriority ?? DEFAULT_PRIORITY,
|
|
1590
|
+
combineMode: parsed.combineMode ?? DEFAULT_COMBINE_MODE,
|
|
1591
|
+
priorityInfluence: parsed.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE
|
|
1592
|
+
};
|
|
1593
|
+
} catch {
|
|
1594
|
+
return {
|
|
1595
|
+
tagPriorities: {},
|
|
1596
|
+
defaultPriority: DEFAULT_PRIORITY,
|
|
1597
|
+
combineMode: DEFAULT_COMBINE_MODE,
|
|
1598
|
+
priorityInfluence: DEFAULT_PRIORITY_INFLUENCE
|
|
1599
|
+
};
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
/**
|
|
1603
|
+
* Look up the priority for a tag.
|
|
1604
|
+
*/
|
|
1605
|
+
getTagPriority(tagId) {
|
|
1606
|
+
return this.config.tagPriorities[tagId] ?? this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1607
|
+
}
|
|
1608
|
+
/**
|
|
1609
|
+
* Compute combined priority for a card based on its tags.
|
|
1610
|
+
*/
|
|
1611
|
+
computeCardPriority(cardTags) {
|
|
1612
|
+
if (cardTags.length === 0) {
|
|
1613
|
+
return this.config.defaultPriority ?? DEFAULT_PRIORITY;
|
|
1614
|
+
}
|
|
1615
|
+
const priorities = cardTags.map((tag) => this.getTagPriority(tag));
|
|
1616
|
+
switch (this.config.combineMode) {
|
|
1617
|
+
case "max":
|
|
1618
|
+
return Math.max(...priorities);
|
|
1619
|
+
case "min":
|
|
1620
|
+
return Math.min(...priorities);
|
|
1621
|
+
case "average":
|
|
1622
|
+
return priorities.reduce((sum, p) => sum + p, 0) / priorities.length;
|
|
1623
|
+
default:
|
|
1624
|
+
return Math.max(...priorities);
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
/**
|
|
1628
|
+
* Compute boost factor based on priority.
|
|
1629
|
+
*
|
|
1630
|
+
* The formula: 1 + (priority - 0.5) * priorityInfluence
|
|
1631
|
+
*
|
|
1632
|
+
* This creates a multiplier centered around 1.0:
|
|
1633
|
+
* - Priority 1.0 with influence 0.5 → 1.25 (25% boost)
|
|
1634
|
+
* - Priority 0.5 with any influence → 1.00 (neutral)
|
|
1635
|
+
* - Priority 0.0 with influence 0.5 → 0.75 (25% reduction)
|
|
1636
|
+
*/
|
|
1637
|
+
computeBoostFactor(priority) {
|
|
1638
|
+
const influence = this.config.priorityInfluence ?? DEFAULT_PRIORITY_INFLUENCE;
|
|
1639
|
+
return 1 + (priority - 0.5) * influence;
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Build human-readable reason for priority adjustment.
|
|
1643
|
+
*/
|
|
1644
|
+
buildPriorityReason(cardTags, priority, boostFactor, finalScore) {
|
|
1645
|
+
if (cardTags.length === 0) {
|
|
1646
|
+
return `No tags, neutral priority (${priority.toFixed(2)})`;
|
|
1647
|
+
}
|
|
1648
|
+
const tagList = cardTags.slice(0, 3).join(", ");
|
|
1649
|
+
const more = cardTags.length > 3 ? ` (+${cardTags.length - 3} more)` : "";
|
|
1650
|
+
if (boostFactor === 1) {
|
|
1651
|
+
return `Neutral priority (${priority.toFixed(2)}) for tags: ${tagList}${more}`;
|
|
1652
|
+
} else if (boostFactor > 1) {
|
|
1653
|
+
return `High-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 boost ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1654
|
+
} else {
|
|
1655
|
+
return `Low-priority tags: ${tagList}${more} (priority ${priority.toFixed(2)} \u2192 reduce ${boostFactor.toFixed(2)}x \u2192 ${finalScore.toFixed(2)})`;
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
/**
|
|
1659
|
+
* CardFilter.transform implementation.
|
|
1660
|
+
*
|
|
1661
|
+
* Apply priority-adjusted scoring. Cards with high-priority tags get boosted,
|
|
1662
|
+
* cards with low-priority tags get reduced scores.
|
|
1663
|
+
*/
|
|
1664
|
+
async transform(cards, _context) {
|
|
1665
|
+
const adjusted = await Promise.all(
|
|
1666
|
+
cards.map(async (card) => {
|
|
1667
|
+
const cardTags = card.tags ?? [];
|
|
1668
|
+
const priority = this.computeCardPriority(cardTags);
|
|
1669
|
+
const boostFactor = this.computeBoostFactor(priority);
|
|
1670
|
+
const finalScore = Math.max(0, Math.min(1, card.score * boostFactor));
|
|
1671
|
+
const action = boostFactor > 1 ? "boosted" : boostFactor < 1 ? "penalized" : "passed";
|
|
1672
|
+
const reason = this.buildPriorityReason(cardTags, priority, boostFactor, finalScore);
|
|
1673
|
+
return {
|
|
1674
|
+
...card,
|
|
1675
|
+
score: finalScore,
|
|
1676
|
+
provenance: [
|
|
1677
|
+
...card.provenance,
|
|
1678
|
+
{
|
|
1679
|
+
strategy: "relativePriority",
|
|
1680
|
+
strategyName: this.strategyName || this.name,
|
|
1681
|
+
strategyId: this.strategyId || "NAVIGATION_STRATEGY-priority",
|
|
1682
|
+
action,
|
|
1683
|
+
score: finalScore,
|
|
1684
|
+
reason
|
|
1685
|
+
}
|
|
1686
|
+
]
|
|
1687
|
+
};
|
|
1688
|
+
})
|
|
1689
|
+
);
|
|
1690
|
+
return adjusted;
|
|
1691
|
+
}
|
|
1692
|
+
/**
|
|
1693
|
+
* Legacy getWeightedCards - now throws as filters should not be used as generators.
|
|
1694
|
+
*
|
|
1695
|
+
* Use transform() via Pipeline instead.
|
|
1696
|
+
*/
|
|
1697
|
+
async getWeightedCards(_limit) {
|
|
1698
|
+
throw new Error(
|
|
1699
|
+
"RelativePriorityNavigator is a filter and should not be used as a generator. Use Pipeline with a generator and this filter via transform()."
|
|
1700
|
+
);
|
|
1701
|
+
}
|
|
1702
|
+
};
|
|
1703
|
+
}
|
|
1704
|
+
});
|
|
1705
|
+
|
|
1706
|
+
// src/core/navigators/filters/types.ts
|
|
1707
|
+
var types_exports2 = {};
|
|
1708
|
+
var init_types2 = __esm({
|
|
1709
|
+
"src/core/navigators/filters/types.ts"() {
|
|
1710
|
+
"use strict";
|
|
1711
|
+
}
|
|
1712
|
+
});
|
|
1713
|
+
|
|
1714
|
+
// src/core/navigators/filters/userGoalStub.ts
|
|
1715
|
+
var userGoalStub_exports = {};
|
|
1716
|
+
__export(userGoalStub_exports, {
|
|
1717
|
+
USER_GOAL_NAVIGATOR_STUB: () => USER_GOAL_NAVIGATOR_STUB
|
|
1718
|
+
});
|
|
1719
|
+
var USER_GOAL_NAVIGATOR_STUB;
|
|
1720
|
+
var init_userGoalStub = __esm({
|
|
1721
|
+
"src/core/navigators/filters/userGoalStub.ts"() {
|
|
1722
|
+
"use strict";
|
|
1723
|
+
USER_GOAL_NAVIGATOR_STUB = true;
|
|
1724
|
+
}
|
|
1725
|
+
});
|
|
1726
|
+
|
|
1727
|
+
// import("./filters/**/*") in src/core/navigators/index.ts
|
|
1728
|
+
var globImport_filters;
|
|
1729
|
+
var init_2 = __esm({
|
|
1730
|
+
'import("./filters/**/*") in src/core/navigators/index.ts'() {
|
|
1731
|
+
globImport_filters = __glob({
|
|
1732
|
+
"./filters/WeightedFilter.ts": () => Promise.resolve().then(() => (init_WeightedFilter(), WeightedFilter_exports)),
|
|
1733
|
+
"./filters/eloDistance.ts": () => Promise.resolve().then(() => (init_eloDistance(), eloDistance_exports)),
|
|
1734
|
+
"./filters/hierarchyDefinition.ts": () => Promise.resolve().then(() => (init_hierarchyDefinition(), hierarchyDefinition_exports)),
|
|
1735
|
+
"./filters/index.ts": () => Promise.resolve().then(() => (init_filters(), filters_exports)),
|
|
1736
|
+
"./filters/inferredPreferenceStub.ts": () => Promise.resolve().then(() => (init_inferredPreferenceStub(), inferredPreferenceStub_exports)),
|
|
1737
|
+
"./filters/interferenceMitigator.ts": () => Promise.resolve().then(() => (init_interferenceMitigator(), interferenceMitigator_exports)),
|
|
1738
|
+
"./filters/relativePriority.ts": () => Promise.resolve().then(() => (init_relativePriority(), relativePriority_exports)),
|
|
1739
|
+
"./filters/types.ts": () => Promise.resolve().then(() => (init_types2(), types_exports2)),
|
|
1740
|
+
"./filters/userGoalStub.ts": () => Promise.resolve().then(() => (init_userGoalStub(), userGoalStub_exports)),
|
|
1741
|
+
"./filters/userTagPreference.ts": () => Promise.resolve().then(() => (init_userTagPreference(), userTagPreference_exports))
|
|
1742
|
+
});
|
|
1743
|
+
}
|
|
1744
|
+
});
|
|
1745
|
+
|
|
1746
|
+
// src/core/orchestration/gradient.ts
|
|
1747
|
+
var init_gradient = __esm({
|
|
1748
|
+
"src/core/orchestration/gradient.ts"() {
|
|
1749
|
+
"use strict";
|
|
1750
|
+
init_logger();
|
|
1751
|
+
}
|
|
1752
|
+
});
|
|
1753
|
+
|
|
1754
|
+
// src/core/orchestration/learning.ts
|
|
1755
|
+
var init_learning = __esm({
|
|
1756
|
+
"src/core/orchestration/learning.ts"() {
|
|
1757
|
+
"use strict";
|
|
1758
|
+
init_contentNavigationStrategy();
|
|
1759
|
+
init_types_legacy();
|
|
1760
|
+
init_logger();
|
|
1761
|
+
}
|
|
1762
|
+
});
|
|
1763
|
+
|
|
1764
|
+
// src/core/orchestration/signal.ts
|
|
1765
|
+
var init_signal = __esm({
|
|
1766
|
+
"src/core/orchestration/signal.ts"() {
|
|
1767
|
+
"use strict";
|
|
1768
|
+
}
|
|
1769
|
+
});
|
|
1770
|
+
|
|
1771
|
+
// src/core/orchestration/recording.ts
|
|
1772
|
+
var init_recording = __esm({
|
|
1773
|
+
"src/core/orchestration/recording.ts"() {
|
|
1774
|
+
"use strict";
|
|
1775
|
+
init_signal();
|
|
1776
|
+
init_types_legacy();
|
|
1777
|
+
init_logger();
|
|
1778
|
+
}
|
|
1779
|
+
});
|
|
1780
|
+
|
|
1781
|
+
// src/core/orchestration/index.ts
|
|
1782
|
+
function fnv1a(str) {
|
|
1783
|
+
let hash = 2166136261;
|
|
1784
|
+
for (let i = 0; i < str.length; i++) {
|
|
1785
|
+
hash ^= str.charCodeAt(i);
|
|
1786
|
+
hash = Math.imul(hash, 16777619);
|
|
1787
|
+
}
|
|
1788
|
+
return hash >>> 0;
|
|
1789
|
+
}
|
|
1790
|
+
function computeDeviation(userId, strategyId, salt) {
|
|
1791
|
+
const input = `${userId}:${strategyId}:${salt}`;
|
|
1792
|
+
const hash = fnv1a(input);
|
|
1793
|
+
const normalized = hash / 4294967296;
|
|
1794
|
+
return normalized * 2 - 1;
|
|
1795
|
+
}
|
|
1796
|
+
function computeSpread(confidence) {
|
|
1797
|
+
const clampedConfidence = Math.max(0, Math.min(1, confidence));
|
|
1798
|
+
return MAX_SPREAD - clampedConfidence * (MAX_SPREAD - MIN_SPREAD);
|
|
1799
|
+
}
|
|
1800
|
+
function computeEffectiveWeight(learnable, userId, strategyId, salt) {
|
|
1801
|
+
const deviation = computeDeviation(userId, strategyId, salt);
|
|
1802
|
+
const spread = computeSpread(learnable.confidence);
|
|
1803
|
+
const adjustment = deviation * spread * learnable.weight;
|
|
1804
|
+
const effective = learnable.weight + adjustment;
|
|
1805
|
+
return Math.max(MIN_WEIGHT, Math.min(MAX_WEIGHT, effective));
|
|
1806
|
+
}
|
|
1807
|
+
async function createOrchestrationContext(user, course) {
|
|
1808
|
+
let courseConfig;
|
|
1809
|
+
try {
|
|
1810
|
+
courseConfig = await course.getCourseConfig();
|
|
1811
|
+
} catch (e) {
|
|
1812
|
+
logger.error(`[Orchestration] Failed to load course config: ${e}`);
|
|
1813
|
+
courseConfig = {
|
|
1814
|
+
name: "Unknown",
|
|
1815
|
+
description: "",
|
|
1816
|
+
public: false,
|
|
1817
|
+
deleted: false,
|
|
1818
|
+
creator: "",
|
|
1819
|
+
admins: [],
|
|
1820
|
+
moderators: [],
|
|
1821
|
+
dataShapes: [],
|
|
1822
|
+
questionTypes: [],
|
|
1823
|
+
orchestration: { salt: "default" }
|
|
1824
|
+
};
|
|
1825
|
+
}
|
|
1826
|
+
const userId = user.getUsername();
|
|
1827
|
+
const salt = courseConfig.orchestration?.salt || "default_salt";
|
|
1828
|
+
return {
|
|
1829
|
+
user,
|
|
1830
|
+
course,
|
|
1831
|
+
userId,
|
|
1832
|
+
courseConfig,
|
|
1833
|
+
getEffectiveWeight(strategyId, learnable) {
|
|
1834
|
+
return computeEffectiveWeight(learnable, userId, strategyId, salt);
|
|
1835
|
+
},
|
|
1836
|
+
getDeviation(strategyId) {
|
|
1837
|
+
return computeDeviation(userId, strategyId, salt);
|
|
1838
|
+
}
|
|
1839
|
+
};
|
|
1840
|
+
}
|
|
1841
|
+
var MIN_SPREAD, MAX_SPREAD, MIN_WEIGHT, MAX_WEIGHT;
|
|
1842
|
+
var init_orchestration = __esm({
|
|
1843
|
+
"src/core/orchestration/index.ts"() {
|
|
1844
|
+
"use strict";
|
|
1845
|
+
init_logger();
|
|
1846
|
+
init_gradient();
|
|
1847
|
+
init_learning();
|
|
1848
|
+
init_signal();
|
|
1849
|
+
init_recording();
|
|
1850
|
+
MIN_SPREAD = 0.1;
|
|
1851
|
+
MAX_SPREAD = 0.5;
|
|
1852
|
+
MIN_WEIGHT = 0.1;
|
|
1853
|
+
MAX_WEIGHT = 3;
|
|
1854
|
+
}
|
|
1855
|
+
});
|
|
1856
|
+
|
|
1857
|
+
// src/core/navigators/Pipeline.ts
|
|
1858
|
+
var Pipeline_exports = {};
|
|
1859
|
+
__export(Pipeline_exports, {
|
|
1860
|
+
Pipeline: () => Pipeline
|
|
1861
|
+
});
|
|
1862
|
+
function logPipelineConfig(generator, filters) {
|
|
1863
|
+
const filterList = filters.length > 0 ? "\n - " + filters.map((f) => f.name).join("\n - ") : " none";
|
|
1864
|
+
logger.info(
|
|
1865
|
+
`[Pipeline] Configuration:
|
|
1866
|
+
Generator: ${generator.name}
|
|
1867
|
+
Filters:${filterList}`
|
|
1868
|
+
);
|
|
1869
|
+
}
|
|
1870
|
+
function logTagHydration(cards, tagsByCard) {
|
|
1871
|
+
const totalTags = Array.from(tagsByCard.values()).reduce((sum, tags) => sum + tags.length, 0);
|
|
1872
|
+
const cardsWithTags = Array.from(tagsByCard.values()).filter((tags) => tags.length > 0).length;
|
|
1873
|
+
logger.debug(
|
|
1874
|
+
`[Pipeline] Tag hydration: ${cards.length} cards, ${cardsWithTags} have tags (${totalTags} total tags) - single batch query`
|
|
1875
|
+
);
|
|
1876
|
+
}
|
|
1877
|
+
function logExecutionSummary(generatorName, generatedCount, filterCount, finalCount, topScores) {
|
|
662
1878
|
const scoreDisplay = topScores.length > 0 ? topScores.map((s) => s.toFixed(2)).join(", ") : "none";
|
|
663
1879
|
logger.info(
|
|
664
1880
|
`[Pipeline] Execution: ${generatorName} produced ${generatedCount} \u2192 ${filterCount} filters \u2192 ${finalCount} results (top scores: ${scoreDisplay})`
|
|
@@ -678,13 +1894,14 @@ function logCardProvenance(cards, maxCards = 3) {
|
|
|
678
1894
|
}
|
|
679
1895
|
}
|
|
680
1896
|
}
|
|
681
|
-
var
|
|
1897
|
+
var import_common8, Pipeline;
|
|
682
1898
|
var init_Pipeline = __esm({
|
|
683
1899
|
"src/core/navigators/Pipeline.ts"() {
|
|
684
1900
|
"use strict";
|
|
685
|
-
|
|
1901
|
+
import_common8 = require("@vue-skuilder/common");
|
|
686
1902
|
init_navigators();
|
|
687
1903
|
init_logger();
|
|
1904
|
+
init_orchestration();
|
|
688
1905
|
Pipeline = class extends ContentNavigator {
|
|
689
1906
|
generator;
|
|
690
1907
|
filters;
|
|
@@ -787,15 +2004,17 @@ var init_Pipeline = __esm({
|
|
|
787
2004
|
let userElo = 1e3;
|
|
788
2005
|
try {
|
|
789
2006
|
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
790
|
-
const courseElo = (0,
|
|
2007
|
+
const courseElo = (0, import_common8.toCourseElo)(courseReg.elo);
|
|
791
2008
|
userElo = courseElo.global.score;
|
|
792
2009
|
} catch (e) {
|
|
793
2010
|
logger.debug(`[Pipeline] Could not get user ELO, using default: ${e}`);
|
|
794
2011
|
}
|
|
2012
|
+
const orchestration = await createOrchestrationContext(this.user, this.course);
|
|
795
2013
|
return {
|
|
796
2014
|
user: this.user,
|
|
797
2015
|
course: this.course,
|
|
798
|
-
userElo
|
|
2016
|
+
userElo,
|
|
2017
|
+
orchestration
|
|
799
2018
|
};
|
|
800
2019
|
}
|
|
801
2020
|
/**
|
|
@@ -804,154 +2023,51 @@ var init_Pipeline = __esm({
|
|
|
804
2023
|
getCourseID() {
|
|
805
2024
|
return this.course.getCourseID();
|
|
806
2025
|
}
|
|
807
|
-
};
|
|
808
|
-
}
|
|
809
|
-
});
|
|
810
|
-
|
|
811
|
-
// src/core/navigators/generators/CompositeGenerator.ts
|
|
812
|
-
var DEFAULT_AGGREGATION_MODE, FREQUENCY_BOOST_FACTOR, CompositeGenerator;
|
|
813
|
-
var init_CompositeGenerator = __esm({
|
|
814
|
-
"src/core/navigators/generators/CompositeGenerator.ts"() {
|
|
815
|
-
"use strict";
|
|
816
|
-
init_navigators();
|
|
817
|
-
init_logger();
|
|
818
|
-
DEFAULT_AGGREGATION_MODE = "frequencyBoost" /* FREQUENCY_BOOST */;
|
|
819
|
-
FREQUENCY_BOOST_FACTOR = 0.1;
|
|
820
|
-
CompositeGenerator = class _CompositeGenerator extends ContentNavigator {
|
|
821
|
-
/** Human-readable name for CardGenerator interface */
|
|
822
|
-
name = "Composite Generator";
|
|
823
|
-
generators;
|
|
824
|
-
aggregationMode;
|
|
825
|
-
constructor(generators, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
826
|
-
super();
|
|
827
|
-
this.generators = generators;
|
|
828
|
-
this.aggregationMode = aggregationMode;
|
|
829
|
-
if (generators.length === 0) {
|
|
830
|
-
throw new Error("CompositeGenerator requires at least one generator");
|
|
831
|
-
}
|
|
832
|
-
logger.debug(
|
|
833
|
-
`[CompositeGenerator] Created with ${generators.length} generators, mode: ${aggregationMode}`
|
|
834
|
-
);
|
|
835
|
-
}
|
|
836
|
-
/**
|
|
837
|
-
* Creates a CompositeGenerator from strategy data.
|
|
838
|
-
*
|
|
839
|
-
* This is a convenience factory for use by PipelineAssembler.
|
|
840
|
-
*/
|
|
841
|
-
static async fromStrategies(user, course, strategies, aggregationMode = DEFAULT_AGGREGATION_MODE) {
|
|
842
|
-
const generators = await Promise.all(
|
|
843
|
-
strategies.map((s) => ContentNavigator.create(user, course, s))
|
|
844
|
-
);
|
|
845
|
-
return new _CompositeGenerator(generators, aggregationMode);
|
|
846
|
-
}
|
|
847
|
-
/**
|
|
848
|
-
* Get weighted cards from all generators, merge and deduplicate.
|
|
849
|
-
*
|
|
850
|
-
* Cards appearing in multiple generators receive a score boost.
|
|
851
|
-
* Provenance tracks which generators produced each card and how scores were aggregated.
|
|
852
|
-
*
|
|
853
|
-
* This method supports both the legacy signature (limit only) and the
|
|
854
|
-
* CardGenerator interface signature (limit, context).
|
|
855
|
-
*
|
|
856
|
-
* @param limit - Maximum number of cards to return
|
|
857
|
-
* @param context - GeneratorContext passed to child generators (required when called via Pipeline)
|
|
858
|
-
*/
|
|
859
|
-
async getWeightedCards(limit, context) {
|
|
860
|
-
if (!context) {
|
|
861
|
-
throw new Error(
|
|
862
|
-
"CompositeGenerator.getWeightedCards requires a GeneratorContext. It should be called via Pipeline, not directly."
|
|
863
|
-
);
|
|
864
|
-
}
|
|
865
|
-
const results = await Promise.all(
|
|
866
|
-
this.generators.map((g) => g.getWeightedCards(limit, context))
|
|
867
|
-
);
|
|
868
|
-
const byCardId = /* @__PURE__ */ new Map();
|
|
869
|
-
for (const cards of results) {
|
|
870
|
-
for (const card of cards) {
|
|
871
|
-
const existing = byCardId.get(card.cardId) || [];
|
|
872
|
-
existing.push(card);
|
|
873
|
-
byCardId.set(card.cardId, existing);
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
const merged = [];
|
|
877
|
-
for (const [, cards] of byCardId) {
|
|
878
|
-
const aggregatedScore = this.aggregateScores(cards);
|
|
879
|
-
const finalScore = Math.min(1, aggregatedScore);
|
|
880
|
-
const mergedProvenance = cards.flatMap((c) => c.provenance);
|
|
881
|
-
const initialScore = cards[0].score;
|
|
882
|
-
const action = finalScore > initialScore ? "boosted" : finalScore < initialScore ? "penalized" : "passed";
|
|
883
|
-
const reason = this.buildAggregationReason(cards, finalScore);
|
|
884
|
-
merged.push({
|
|
885
|
-
...cards[0],
|
|
886
|
-
score: finalScore,
|
|
887
|
-
provenance: [
|
|
888
|
-
...mergedProvenance,
|
|
889
|
-
{
|
|
890
|
-
strategy: "composite",
|
|
891
|
-
strategyName: "Composite Generator",
|
|
892
|
-
strategyId: "COMPOSITE_GENERATOR",
|
|
893
|
-
action,
|
|
894
|
-
score: finalScore,
|
|
895
|
-
reason
|
|
896
|
-
}
|
|
897
|
-
]
|
|
898
|
-
});
|
|
899
|
-
}
|
|
900
|
-
return merged.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
901
|
-
}
|
|
902
2026
|
/**
|
|
903
|
-
*
|
|
2027
|
+
* Get orchestration context for outcome recording.
|
|
904
2028
|
*/
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
const scores = cards.map((c) => c.score.toFixed(2)).join(", ");
|
|
908
|
-
if (count === 1) {
|
|
909
|
-
return `Single generator, score ${finalScore.toFixed(2)}`;
|
|
910
|
-
}
|
|
911
|
-
const strategies = cards.map((c) => c.provenance[0]?.strategy || "unknown").join(", ");
|
|
912
|
-
switch (this.aggregationMode) {
|
|
913
|
-
case "max" /* MAX */:
|
|
914
|
-
return `Max of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
915
|
-
case "average" /* AVERAGE */:
|
|
916
|
-
return `Average of ${count} generators (${strategies}): scores [${scores}] \u2192 ${finalScore.toFixed(2)}`;
|
|
917
|
-
case "frequencyBoost" /* FREQUENCY_BOOST */: {
|
|
918
|
-
const avg = cards.reduce((sum, c) => sum + c.score, 0) / count;
|
|
919
|
-
const boost = 1 + FREQUENCY_BOOST_FACTOR * (count - 1);
|
|
920
|
-
return `Frequency boost from ${count} generators (${strategies}): avg ${avg.toFixed(2)} \xD7 ${boost.toFixed(2)} \u2192 ${finalScore.toFixed(2)}`;
|
|
921
|
-
}
|
|
922
|
-
default:
|
|
923
|
-
return `Aggregated from ${count} generators: ${finalScore.toFixed(2)}`;
|
|
924
|
-
}
|
|
2029
|
+
async getOrchestrationContext() {
|
|
2030
|
+
return createOrchestrationContext(this.user, this.course);
|
|
925
2031
|
}
|
|
926
2032
|
/**
|
|
927
|
-
*
|
|
2033
|
+
* Get IDs of all strategies in this pipeline.
|
|
2034
|
+
* Used to record which strategies contributed to an outcome.
|
|
928
2035
|
*/
|
|
929
|
-
|
|
930
|
-
const
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
2036
|
+
getStrategyIds() {
|
|
2037
|
+
const ids = [];
|
|
2038
|
+
const extractId = (obj) => {
|
|
2039
|
+
if (obj.strategyId) return obj.strategyId;
|
|
2040
|
+
return null;
|
|
2041
|
+
};
|
|
2042
|
+
const genId = extractId(this.generator);
|
|
2043
|
+
if (genId) ids.push(genId);
|
|
2044
|
+
if (this.generator.generators && Array.isArray(this.generator.generators)) {
|
|
2045
|
+
this.generator.generators.forEach((g) => {
|
|
2046
|
+
const subId = extractId(g);
|
|
2047
|
+
if (subId) ids.push(subId);
|
|
2048
|
+
});
|
|
2049
|
+
}
|
|
2050
|
+
for (const filter of this.filters) {
|
|
2051
|
+
const fId = extractId(filter);
|
|
2052
|
+
if (fId) ids.push(fId);
|
|
943
2053
|
}
|
|
2054
|
+
return [...new Set(ids)];
|
|
944
2055
|
}
|
|
945
2056
|
};
|
|
946
2057
|
}
|
|
947
2058
|
});
|
|
948
2059
|
|
|
949
2060
|
// src/core/navigators/PipelineAssembler.ts
|
|
2061
|
+
var PipelineAssembler_exports = {};
|
|
2062
|
+
__export(PipelineAssembler_exports, {
|
|
2063
|
+
PipelineAssembler: () => PipelineAssembler
|
|
2064
|
+
});
|
|
950
2065
|
var PipelineAssembler;
|
|
951
2066
|
var init_PipelineAssembler = __esm({
|
|
952
2067
|
"src/core/navigators/PipelineAssembler.ts"() {
|
|
953
2068
|
"use strict";
|
|
954
2069
|
init_navigators();
|
|
2070
|
+
init_WeightedFilter();
|
|
955
2071
|
init_Pipeline();
|
|
956
2072
|
init_types_legacy();
|
|
957
2073
|
init_logger();
|
|
@@ -1013,276 +2129,76 @@ var init_PipelineAssembler = __esm({
|
|
|
1013
2129
|
generator = nav;
|
|
1014
2130
|
logger.debug(`[PipelineAssembler] Using single generator: ${generatorStrategies[0].name}`);
|
|
1015
2131
|
} else {
|
|
1016
|
-
logger.debug(
|
|
1017
|
-
`[PipelineAssembler] Using CompositeGenerator for ${generatorStrategies.length} generators: ${generatorStrategies.map((g) => g.name).join(", ")}`
|
|
1018
|
-
);
|
|
1019
|
-
generator = await CompositeGenerator.fromStrategies(user, course, generatorStrategies);
|
|
1020
|
-
}
|
|
1021
|
-
const filters = [];
|
|
1022
|
-
const sortedFilterStrategies = [...filterStrategies].sort(
|
|
1023
|
-
(a, b) => a.name.localeCompare(b.name)
|
|
1024
|
-
);
|
|
1025
|
-
for (const filterStrategy of sortedFilterStrategies) {
|
|
1026
|
-
try {
|
|
1027
|
-
const nav = await ContentNavigator.create(user, course, filterStrategy);
|
|
1028
|
-
if ("transform" in nav && typeof nav.transform === "function") {
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
return {
|
|
1045
|
-
pipeline,
|
|
1046
|
-
generatorStrategies,
|
|
1047
|
-
filterStrategies: sortedFilterStrategies,
|
|
1048
|
-
warnings
|
|
1049
|
-
};
|
|
1050
|
-
}
|
|
1051
|
-
/**
|
|
1052
|
-
* Creates a default ELO generator strategy.
|
|
1053
|
-
* Used when filters are configured but no generator is specified.
|
|
1054
|
-
*/
|
|
1055
|
-
makeDefaultEloStrategy(courseId) {
|
|
1056
|
-
return {
|
|
1057
|
-
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
1058
|
-
course: courseId,
|
|
1059
|
-
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
1060
|
-
name: "ELO (default)",
|
|
1061
|
-
description: "Default ELO-based generator",
|
|
1062
|
-
implementingClass: "elo" /* ELO */,
|
|
1063
|
-
serializedData: ""
|
|
1064
|
-
};
|
|
1065
|
-
}
|
|
1066
|
-
};
|
|
1067
|
-
}
|
|
1068
|
-
});
|
|
1069
|
-
|
|
1070
|
-
// src/core/navigators/generators/elo.ts
|
|
1071
|
-
var import_common6, ELONavigator;
|
|
1072
|
-
var init_elo = __esm({
|
|
1073
|
-
"src/core/navigators/generators/elo.ts"() {
|
|
1074
|
-
"use strict";
|
|
1075
|
-
init_navigators();
|
|
1076
|
-
import_common6 = require("@vue-skuilder/common");
|
|
1077
|
-
ELONavigator = class extends ContentNavigator {
|
|
1078
|
-
/** Human-readable name for CardGenerator interface */
|
|
1079
|
-
name;
|
|
1080
|
-
constructor(user, course, strategyData) {
|
|
1081
|
-
super(user, course, strategyData);
|
|
1082
|
-
this.name = strategyData?.name || "ELO";
|
|
1083
|
-
}
|
|
1084
|
-
/**
|
|
1085
|
-
* Get new cards with suitability scores based on ELO distance.
|
|
1086
|
-
*
|
|
1087
|
-
* Cards closer to user's ELO get higher scores.
|
|
1088
|
-
* Score formula: max(0, 1 - distance / 500)
|
|
1089
|
-
*
|
|
1090
|
-
* NOTE: This generator only handles NEW cards. Reviews are handled by
|
|
1091
|
-
* SRSNavigator. Use CompositeGenerator to combine both.
|
|
1092
|
-
*
|
|
1093
|
-
* This method supports both the legacy signature (limit only) and the
|
|
1094
|
-
* CardGenerator interface signature (limit, context).
|
|
1095
|
-
*
|
|
1096
|
-
* @param limit - Maximum number of cards to return
|
|
1097
|
-
* @param context - Optional GeneratorContext (used when called via Pipeline)
|
|
1098
|
-
*/
|
|
1099
|
-
async getWeightedCards(limit, context) {
|
|
1100
|
-
let userGlobalElo;
|
|
1101
|
-
if (context?.userElo !== void 0) {
|
|
1102
|
-
userGlobalElo = context.userElo;
|
|
1103
|
-
} else {
|
|
1104
|
-
const courseReg = await this.user.getCourseRegDoc(this.course.getCourseID());
|
|
1105
|
-
const userElo = (0, import_common6.toCourseElo)(courseReg.elo);
|
|
1106
|
-
userGlobalElo = userElo.global.score;
|
|
1107
|
-
}
|
|
1108
|
-
const activeCards = await this.user.getActiveCards();
|
|
1109
|
-
const newCards = (await this.course.getCardsCenteredAtELO(
|
|
1110
|
-
{ limit, elo: "user" },
|
|
1111
|
-
(c) => !activeCards.some((ac) => c.cardID === ac.cardID)
|
|
1112
|
-
)).map((c) => ({ ...c, status: "new" }));
|
|
1113
|
-
const cardIds = newCards.map((c) => c.cardID);
|
|
1114
|
-
const cardEloData = await this.course.getCardEloData(cardIds);
|
|
1115
|
-
const scored = newCards.map((c, i) => {
|
|
1116
|
-
const cardElo = cardEloData[i]?.global?.score ?? 1e3;
|
|
1117
|
-
const distance = Math.abs(cardElo - userGlobalElo);
|
|
1118
|
-
const score = Math.max(0, 1 - distance / 500);
|
|
1119
|
-
return {
|
|
1120
|
-
cardId: c.cardID,
|
|
1121
|
-
courseId: c.courseID,
|
|
1122
|
-
score,
|
|
1123
|
-
provenance: [
|
|
1124
|
-
{
|
|
1125
|
-
strategy: "elo",
|
|
1126
|
-
strategyName: this.strategyName || this.name,
|
|
1127
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-ELO-default",
|
|
1128
|
-
action: "generated",
|
|
1129
|
-
score,
|
|
1130
|
-
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userGlobalElo)}), new card`
|
|
1131
|
-
}
|
|
1132
|
-
]
|
|
1133
|
-
};
|
|
1134
|
-
});
|
|
1135
|
-
scored.sort((a, b) => b.score - a.score);
|
|
1136
|
-
return scored.slice(0, limit);
|
|
1137
|
-
}
|
|
1138
|
-
};
|
|
1139
|
-
}
|
|
1140
|
-
});
|
|
1141
|
-
|
|
1142
|
-
// src/core/navigators/generators/srs.ts
|
|
1143
|
-
var import_moment3, SRSNavigator;
|
|
1144
|
-
var init_srs = __esm({
|
|
1145
|
-
"src/core/navigators/generators/srs.ts"() {
|
|
1146
|
-
"use strict";
|
|
1147
|
-
import_moment3 = __toESM(require("moment"), 1);
|
|
1148
|
-
init_navigators();
|
|
1149
|
-
init_logger();
|
|
1150
|
-
SRSNavigator = class extends ContentNavigator {
|
|
1151
|
-
/** Human-readable name for CardGenerator interface */
|
|
1152
|
-
name;
|
|
1153
|
-
constructor(user, course, strategyData) {
|
|
1154
|
-
super(user, course, strategyData);
|
|
1155
|
-
this.name = strategyData?.name || "SRS";
|
|
1156
|
-
}
|
|
1157
|
-
/**
|
|
1158
|
-
* Get review cards scored by urgency.
|
|
1159
|
-
*
|
|
1160
|
-
* Score formula combines:
|
|
1161
|
-
* - Relative overdueness: hoursOverdue / intervalHours
|
|
1162
|
-
* - Interval recency: exponential decay favoring shorter intervals
|
|
1163
|
-
*
|
|
1164
|
-
* Cards not yet due are excluded (not scored as 0).
|
|
1165
|
-
*
|
|
1166
|
-
* This method supports both the legacy signature (limit only) and the
|
|
1167
|
-
* CardGenerator interface signature (limit, context).
|
|
1168
|
-
*
|
|
1169
|
-
* @param limit - Maximum number of cards to return
|
|
1170
|
-
* @param _context - Optional GeneratorContext (currently unused, but required for interface)
|
|
1171
|
-
*/
|
|
1172
|
-
async getWeightedCards(limit, _context) {
|
|
1173
|
-
if (!this.user || !this.course) {
|
|
1174
|
-
throw new Error("SRSNavigator requires user and course to be set");
|
|
1175
|
-
}
|
|
1176
|
-
const reviews = await this.user.getPendingReviews(this.course.getCourseID());
|
|
1177
|
-
const now = import_moment3.default.utc();
|
|
1178
|
-
const dueReviews = reviews.filter((r) => now.isAfter(import_moment3.default.utc(r.reviewTime)));
|
|
1179
|
-
const scored = dueReviews.map((review) => {
|
|
1180
|
-
const { score, reason } = this.computeUrgencyScore(review, now);
|
|
1181
|
-
return {
|
|
1182
|
-
cardId: review.cardId,
|
|
1183
|
-
courseId: review.courseId,
|
|
1184
|
-
score,
|
|
1185
|
-
reviewID: review._id,
|
|
1186
|
-
provenance: [
|
|
1187
|
-
{
|
|
1188
|
-
strategy: "srs",
|
|
1189
|
-
strategyName: this.strategyName || this.name,
|
|
1190
|
-
strategyId: this.strategyId || "NAVIGATION_STRATEGY-SRS-default",
|
|
1191
|
-
action: "generated",
|
|
1192
|
-
score,
|
|
1193
|
-
reason
|
|
1194
|
-
}
|
|
1195
|
-
]
|
|
1196
|
-
};
|
|
1197
|
-
});
|
|
1198
|
-
logger.debug(`[srsNav] got ${scored.length} weighted cards`);
|
|
1199
|
-
return scored.sort((a, b) => b.score - a.score).slice(0, limit);
|
|
1200
|
-
}
|
|
1201
|
-
/**
|
|
1202
|
-
* Compute urgency score for a review card.
|
|
1203
|
-
*
|
|
1204
|
-
* Two factors:
|
|
1205
|
-
* 1. Relative overdueness = hoursOverdue / intervalHours
|
|
1206
|
-
* - 2 days overdue on 3-day interval = 0.67 (urgent)
|
|
1207
|
-
* - 2 days overdue on 180-day interval = 0.01 (not urgent)
|
|
1208
|
-
*
|
|
1209
|
-
* 2. Interval recency factor = 0.3 + 0.7 * exp(-intervalHours / 720)
|
|
1210
|
-
* - 24h interval → ~1.0 (very recent learning)
|
|
1211
|
-
* - 30 days (720h) → ~0.56
|
|
1212
|
-
* - 180 days → ~0.30
|
|
1213
|
-
*
|
|
1214
|
-
* Combined: base 0.5 + weighted average of factors * 0.45
|
|
1215
|
-
* Result range: approximately 0.5 to 0.95
|
|
1216
|
-
*/
|
|
1217
|
-
computeUrgencyScore(review, now) {
|
|
1218
|
-
const scheduledAt = import_moment3.default.utc(review.scheduledAt);
|
|
1219
|
-
const due = import_moment3.default.utc(review.reviewTime);
|
|
1220
|
-
const intervalHours = Math.max(1, due.diff(scheduledAt, "hours"));
|
|
1221
|
-
const hoursOverdue = now.diff(due, "hours");
|
|
1222
|
-
const relativeOverdue = hoursOverdue / intervalHours;
|
|
1223
|
-
const recencyFactor = 0.3 + 0.7 * Math.exp(-intervalHours / 720);
|
|
1224
|
-
const overdueContribution = Math.min(1, Math.max(0, relativeOverdue));
|
|
1225
|
-
const urgency = overdueContribution * 0.5 + recencyFactor * 0.5;
|
|
1226
|
-
const score = Math.min(0.95, 0.5 + urgency * 0.45);
|
|
1227
|
-
const reason = `${Math.round(hoursOverdue)}h overdue (interval: ${Math.round(intervalHours)}h, relative: ${relativeOverdue.toFixed(2)}), recency: ${recencyFactor.toFixed(2)}, review`;
|
|
1228
|
-
return { score, reason };
|
|
1229
|
-
}
|
|
1230
|
-
};
|
|
1231
|
-
}
|
|
1232
|
-
});
|
|
1233
|
-
|
|
1234
|
-
// src/core/navigators/filters/eloDistance.ts
|
|
1235
|
-
function computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier) {
|
|
1236
|
-
const normalizedDistance = distance / halfLife;
|
|
1237
|
-
const decay = Math.exp(-(normalizedDistance * normalizedDistance));
|
|
1238
|
-
return minMultiplier + (maxMultiplier - minMultiplier) * decay;
|
|
1239
|
-
}
|
|
1240
|
-
function createEloDistanceFilter(config) {
|
|
1241
|
-
const halfLife = config?.halfLife ?? DEFAULT_HALF_LIFE;
|
|
1242
|
-
const minMultiplier = config?.minMultiplier ?? DEFAULT_MIN_MULTIPLIER;
|
|
1243
|
-
const maxMultiplier = config?.maxMultiplier ?? DEFAULT_MAX_MULTIPLIER;
|
|
1244
|
-
return {
|
|
1245
|
-
name: "ELO Distance Filter",
|
|
1246
|
-
async transform(cards, context) {
|
|
1247
|
-
const { course, userElo } = context;
|
|
1248
|
-
const cardIds = cards.map((c) => c.cardId);
|
|
1249
|
-
const cardElos = await course.getCardEloData(cardIds);
|
|
1250
|
-
return cards.map((card, i) => {
|
|
1251
|
-
const cardElo = cardElos[i]?.global?.score ?? 1e3;
|
|
1252
|
-
const distance = Math.abs(cardElo - userElo);
|
|
1253
|
-
const multiplier = computeMultiplier(distance, halfLife, minMultiplier, maxMultiplier);
|
|
1254
|
-
const newScore = card.score * multiplier;
|
|
1255
|
-
const action = multiplier < maxMultiplier - 0.01 ? "penalized" : "passed";
|
|
1256
|
-
return {
|
|
1257
|
-
...card,
|
|
1258
|
-
score: newScore,
|
|
1259
|
-
provenance: [
|
|
1260
|
-
...card.provenance,
|
|
1261
|
-
{
|
|
1262
|
-
strategy: "eloDistance",
|
|
1263
|
-
strategyName: "ELO Distance Filter",
|
|
1264
|
-
strategyId: "ELO_DISTANCE_FILTER",
|
|
1265
|
-
action,
|
|
1266
|
-
score: newScore,
|
|
1267
|
-
reason: `ELO distance ${Math.round(distance)} (card: ${Math.round(cardElo)}, user: ${Math.round(userElo)}) \u2192 ${multiplier.toFixed(2)}x`
|
|
2132
|
+
logger.debug(
|
|
2133
|
+
`[PipelineAssembler] Using CompositeGenerator for ${generatorStrategies.length} generators: ${generatorStrategies.map((g) => g.name).join(", ")}`
|
|
2134
|
+
);
|
|
2135
|
+
generator = await CompositeGenerator.fromStrategies(user, course, generatorStrategies);
|
|
2136
|
+
}
|
|
2137
|
+
const filters = [];
|
|
2138
|
+
const sortedFilterStrategies = [...filterStrategies].sort(
|
|
2139
|
+
(a, b) => a.name.localeCompare(b.name)
|
|
2140
|
+
);
|
|
2141
|
+
for (const filterStrategy of sortedFilterStrategies) {
|
|
2142
|
+
try {
|
|
2143
|
+
const nav = await ContentNavigator.create(user, course, filterStrategy);
|
|
2144
|
+
if ("transform" in nav && typeof nav.transform === "function") {
|
|
2145
|
+
let filter = nav;
|
|
2146
|
+
if (filterStrategy.learnable) {
|
|
2147
|
+
filter = new WeightedFilter(
|
|
2148
|
+
filter,
|
|
2149
|
+
filterStrategy.learnable,
|
|
2150
|
+
filterStrategy.staticWeight,
|
|
2151
|
+
filterStrategy._id
|
|
2152
|
+
);
|
|
2153
|
+
}
|
|
2154
|
+
filters.push(filter);
|
|
2155
|
+
logger.debug(`[PipelineAssembler] Added filter: ${filterStrategy.name}`);
|
|
2156
|
+
} else {
|
|
2157
|
+
warnings.push(
|
|
2158
|
+
`Filter '${filterStrategy.name}' does not implement CardFilter.transform(), skipping`
|
|
2159
|
+
);
|
|
1268
2160
|
}
|
|
1269
|
-
|
|
2161
|
+
} catch (e) {
|
|
2162
|
+
warnings.push(`Failed to instantiate filter '${filterStrategy.name}': ${e}`);
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
const pipeline = new Pipeline(generator, filters, user, course);
|
|
2166
|
+
logger.debug(
|
|
2167
|
+
`[PipelineAssembler] Assembled pipeline with ${generatorStrategies.length} generator(s) and ${filters.length} filter(s)`
|
|
2168
|
+
);
|
|
2169
|
+
return {
|
|
2170
|
+
pipeline,
|
|
2171
|
+
generatorStrategies,
|
|
2172
|
+
filterStrategies: sortedFilterStrategies,
|
|
2173
|
+
warnings
|
|
1270
2174
|
};
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
2175
|
+
}
|
|
2176
|
+
/**
|
|
2177
|
+
* Creates a default ELO generator strategy.
|
|
2178
|
+
* Used when filters are configured but no generator is specified.
|
|
2179
|
+
*/
|
|
2180
|
+
makeDefaultEloStrategy(courseId) {
|
|
2181
|
+
return {
|
|
2182
|
+
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
2183
|
+
course: courseId,
|
|
2184
|
+
docType: "NAVIGATION_STRATEGY" /* NAVIGATION_STRATEGY */,
|
|
2185
|
+
name: "ELO (default)",
|
|
2186
|
+
description: "Default ELO-based generator",
|
|
2187
|
+
implementingClass: "elo" /* ELO */,
|
|
2188
|
+
serializedData: ""
|
|
2189
|
+
};
|
|
2190
|
+
}
|
|
2191
|
+
};
|
|
1282
2192
|
}
|
|
1283
2193
|
});
|
|
1284
2194
|
|
|
1285
2195
|
// src/core/navigators/defaults.ts
|
|
2196
|
+
var defaults_exports = {};
|
|
2197
|
+
__export(defaults_exports, {
|
|
2198
|
+
createDefaultEloStrategy: () => createDefaultEloStrategy,
|
|
2199
|
+
createDefaultPipeline: () => createDefaultPipeline,
|
|
2200
|
+
createDefaultSrsStrategy: () => createDefaultSrsStrategy
|
|
2201
|
+
});
|
|
1286
2202
|
function createDefaultEloStrategy(courseId) {
|
|
1287
2203
|
return {
|
|
1288
2204
|
_id: "NAVIGATION_STRATEGY-ELO-default",
|
|
@@ -1326,12 +2242,310 @@ var init_defaults = __esm({
|
|
|
1326
2242
|
}
|
|
1327
2243
|
});
|
|
1328
2244
|
|
|
2245
|
+
// import("./**/*") in src/core/navigators/index.ts
|
|
2246
|
+
var globImport;
|
|
2247
|
+
var init_3 = __esm({
|
|
2248
|
+
'import("./**/*") in src/core/navigators/index.ts'() {
|
|
2249
|
+
globImport = __glob({
|
|
2250
|
+
"./Pipeline.ts": () => Promise.resolve().then(() => (init_Pipeline(), Pipeline_exports)),
|
|
2251
|
+
"./PipelineAssembler.ts": () => Promise.resolve().then(() => (init_PipelineAssembler(), PipelineAssembler_exports)),
|
|
2252
|
+
"./defaults.ts": () => Promise.resolve().then(() => (init_defaults(), defaults_exports)),
|
|
2253
|
+
"./filters/WeightedFilter.ts": () => Promise.resolve().then(() => (init_WeightedFilter(), WeightedFilter_exports)),
|
|
2254
|
+
"./filters/eloDistance.ts": () => Promise.resolve().then(() => (init_eloDistance(), eloDistance_exports)),
|
|
2255
|
+
"./filters/hierarchyDefinition.ts": () => Promise.resolve().then(() => (init_hierarchyDefinition(), hierarchyDefinition_exports)),
|
|
2256
|
+
"./filters/index.ts": () => Promise.resolve().then(() => (init_filters(), filters_exports)),
|
|
2257
|
+
"./filters/inferredPreferenceStub.ts": () => Promise.resolve().then(() => (init_inferredPreferenceStub(), inferredPreferenceStub_exports)),
|
|
2258
|
+
"./filters/interferenceMitigator.ts": () => Promise.resolve().then(() => (init_interferenceMitigator(), interferenceMitigator_exports)),
|
|
2259
|
+
"./filters/relativePriority.ts": () => Promise.resolve().then(() => (init_relativePriority(), relativePriority_exports)),
|
|
2260
|
+
"./filters/types.ts": () => Promise.resolve().then(() => (init_types2(), types_exports2)),
|
|
2261
|
+
"./filters/userGoalStub.ts": () => Promise.resolve().then(() => (init_userGoalStub(), userGoalStub_exports)),
|
|
2262
|
+
"./filters/userTagPreference.ts": () => Promise.resolve().then(() => (init_userTagPreference(), userTagPreference_exports)),
|
|
2263
|
+
"./generators/CompositeGenerator.ts": () => Promise.resolve().then(() => (init_CompositeGenerator(), CompositeGenerator_exports)),
|
|
2264
|
+
"./generators/elo.ts": () => Promise.resolve().then(() => (init_elo(), elo_exports)),
|
|
2265
|
+
"./generators/index.ts": () => Promise.resolve().then(() => (init_generators(), generators_exports)),
|
|
2266
|
+
"./generators/srs.ts": () => Promise.resolve().then(() => (init_srs(), srs_exports)),
|
|
2267
|
+
"./generators/types.ts": () => Promise.resolve().then(() => (init_types(), types_exports)),
|
|
2268
|
+
"./index.ts": () => Promise.resolve().then(() => (init_navigators(), navigators_exports))
|
|
2269
|
+
});
|
|
2270
|
+
}
|
|
2271
|
+
});
|
|
2272
|
+
|
|
2273
|
+
// src/core/navigators/index.ts
|
|
2274
|
+
var navigators_exports = {};
|
|
2275
|
+
__export(navigators_exports, {
|
|
2276
|
+
ContentNavigator: () => ContentNavigator,
|
|
2277
|
+
NavigatorRole: () => NavigatorRole,
|
|
2278
|
+
NavigatorRoles: () => NavigatorRoles,
|
|
2279
|
+
Navigators: () => Navigators,
|
|
2280
|
+
getCardOrigin: () => getCardOrigin,
|
|
2281
|
+
getRegisteredNavigator: () => getRegisteredNavigator,
|
|
2282
|
+
getRegisteredNavigatorNames: () => getRegisteredNavigatorNames,
|
|
2283
|
+
hasRegisteredNavigator: () => hasRegisteredNavigator,
|
|
2284
|
+
initializeNavigatorRegistry: () => initializeNavigatorRegistry,
|
|
2285
|
+
isFilter: () => isFilter,
|
|
2286
|
+
isGenerator: () => isGenerator,
|
|
2287
|
+
registerNavigator: () => registerNavigator
|
|
2288
|
+
});
|
|
2289
|
+
function registerNavigator(implementingClass, constructor) {
|
|
2290
|
+
navigatorRegistry.set(implementingClass, constructor);
|
|
2291
|
+
logger.debug(`[NavigatorRegistry] Registered: ${implementingClass}`);
|
|
2292
|
+
}
|
|
2293
|
+
function getRegisteredNavigator(implementingClass) {
|
|
2294
|
+
return navigatorRegistry.get(implementingClass);
|
|
2295
|
+
}
|
|
2296
|
+
function hasRegisteredNavigator(implementingClass) {
|
|
2297
|
+
return navigatorRegistry.has(implementingClass);
|
|
2298
|
+
}
|
|
2299
|
+
function getRegisteredNavigatorNames() {
|
|
2300
|
+
return Array.from(navigatorRegistry.keys());
|
|
2301
|
+
}
|
|
2302
|
+
async function initializeNavigatorRegistry() {
|
|
2303
|
+
logger.debug("[NavigatorRegistry] Initializing built-in navigators...");
|
|
2304
|
+
const [eloModule, srsModule] = await Promise.all([
|
|
2305
|
+
Promise.resolve().then(() => (init_elo(), elo_exports)),
|
|
2306
|
+
Promise.resolve().then(() => (init_srs(), srs_exports))
|
|
2307
|
+
]);
|
|
2308
|
+
registerNavigator("elo", eloModule.default);
|
|
2309
|
+
registerNavigator("srs", srsModule.default);
|
|
2310
|
+
const [
|
|
2311
|
+
hierarchyModule,
|
|
2312
|
+
interferenceModule,
|
|
2313
|
+
relativePriorityModule,
|
|
2314
|
+
userTagPreferenceModule
|
|
2315
|
+
] = await Promise.all([
|
|
2316
|
+
Promise.resolve().then(() => (init_hierarchyDefinition(), hierarchyDefinition_exports)),
|
|
2317
|
+
Promise.resolve().then(() => (init_interferenceMitigator(), interferenceMitigator_exports)),
|
|
2318
|
+
Promise.resolve().then(() => (init_relativePriority(), relativePriority_exports)),
|
|
2319
|
+
Promise.resolve().then(() => (init_userTagPreference(), userTagPreference_exports))
|
|
2320
|
+
]);
|
|
2321
|
+
registerNavigator("hierarchyDefinition", hierarchyModule.default);
|
|
2322
|
+
registerNavigator("interferenceMitigator", interferenceModule.default);
|
|
2323
|
+
registerNavigator("relativePriority", relativePriorityModule.default);
|
|
2324
|
+
registerNavigator("userTagPreference", userTagPreferenceModule.default);
|
|
2325
|
+
logger.debug(
|
|
2326
|
+
`[NavigatorRegistry] Initialized ${navigatorRegistry.size} navigators: ${getRegisteredNavigatorNames().join(", ")}`
|
|
2327
|
+
);
|
|
2328
|
+
}
|
|
2329
|
+
function getCardOrigin(card) {
|
|
2330
|
+
if (card.provenance.length === 0) {
|
|
2331
|
+
throw new Error("Card has no provenance - cannot determine origin");
|
|
2332
|
+
}
|
|
2333
|
+
const firstEntry = card.provenance[0];
|
|
2334
|
+
const reason = firstEntry.reason.toLowerCase();
|
|
2335
|
+
if (reason.includes("failed")) {
|
|
2336
|
+
return "failed";
|
|
2337
|
+
}
|
|
2338
|
+
if (reason.includes("review")) {
|
|
2339
|
+
return "review";
|
|
2340
|
+
}
|
|
2341
|
+
return "new";
|
|
2342
|
+
}
|
|
2343
|
+
function isGenerator(impl) {
|
|
2344
|
+
return NavigatorRoles[impl] === "generator" /* GENERATOR */;
|
|
2345
|
+
}
|
|
2346
|
+
function isFilter(impl) {
|
|
2347
|
+
return NavigatorRoles[impl] === "filter" /* FILTER */;
|
|
2348
|
+
}
|
|
2349
|
+
var navigatorRegistry, Navigators, NavigatorRole, NavigatorRoles, ContentNavigator;
|
|
2350
|
+
var init_navigators = __esm({
|
|
2351
|
+
"src/core/navigators/index.ts"() {
|
|
2352
|
+
"use strict";
|
|
2353
|
+
init_logger();
|
|
2354
|
+
init_();
|
|
2355
|
+
init_2();
|
|
2356
|
+
init_3();
|
|
2357
|
+
navigatorRegistry = /* @__PURE__ */ new Map();
|
|
2358
|
+
Navigators = /* @__PURE__ */ ((Navigators2) => {
|
|
2359
|
+
Navigators2["ELO"] = "elo";
|
|
2360
|
+
Navigators2["SRS"] = "srs";
|
|
2361
|
+
Navigators2["HIERARCHY"] = "hierarchyDefinition";
|
|
2362
|
+
Navigators2["INTERFERENCE"] = "interferenceMitigator";
|
|
2363
|
+
Navigators2["RELATIVE_PRIORITY"] = "relativePriority";
|
|
2364
|
+
Navigators2["USER_TAG_PREFERENCE"] = "userTagPreference";
|
|
2365
|
+
return Navigators2;
|
|
2366
|
+
})(Navigators || {});
|
|
2367
|
+
NavigatorRole = /* @__PURE__ */ ((NavigatorRole2) => {
|
|
2368
|
+
NavigatorRole2["GENERATOR"] = "generator";
|
|
2369
|
+
NavigatorRole2["FILTER"] = "filter";
|
|
2370
|
+
return NavigatorRole2;
|
|
2371
|
+
})(NavigatorRole || {});
|
|
2372
|
+
NavigatorRoles = {
|
|
2373
|
+
["elo" /* ELO */]: "generator" /* GENERATOR */,
|
|
2374
|
+
["srs" /* SRS */]: "generator" /* GENERATOR */,
|
|
2375
|
+
["hierarchyDefinition" /* HIERARCHY */]: "filter" /* FILTER */,
|
|
2376
|
+
["interferenceMitigator" /* INTERFERENCE */]: "filter" /* FILTER */,
|
|
2377
|
+
["relativePriority" /* RELATIVE_PRIORITY */]: "filter" /* FILTER */,
|
|
2378
|
+
["userTagPreference" /* USER_TAG_PREFERENCE */]: "filter" /* FILTER */
|
|
2379
|
+
};
|
|
2380
|
+
ContentNavigator = class {
|
|
2381
|
+
/** User interface for this navigation session */
|
|
2382
|
+
user;
|
|
2383
|
+
/** Course interface for this navigation session */
|
|
2384
|
+
course;
|
|
2385
|
+
/** Human-readable name for this strategy instance (from ContentNavigationStrategyData.name) */
|
|
2386
|
+
strategyName;
|
|
2387
|
+
/** Unique document ID for this strategy instance (from ContentNavigationStrategyData._id) */
|
|
2388
|
+
strategyId;
|
|
2389
|
+
/** Evolutionary weighting configuration */
|
|
2390
|
+
learnable;
|
|
2391
|
+
/** Whether to bypass deviation (manual/static weighting) */
|
|
2392
|
+
staticWeight;
|
|
2393
|
+
/**
|
|
2394
|
+
* Constructor for standard navigators.
|
|
2395
|
+
* Call this from subclass constructors to initialize common fields.
|
|
2396
|
+
*
|
|
2397
|
+
* Note: CompositeGenerator and Pipeline call super() without args, then set
|
|
2398
|
+
* user/course fields directly if needed.
|
|
2399
|
+
*/
|
|
2400
|
+
constructor(user, course, strategyData) {
|
|
2401
|
+
this.user = user;
|
|
2402
|
+
this.course = course;
|
|
2403
|
+
if (strategyData) {
|
|
2404
|
+
this.strategyName = strategyData.name;
|
|
2405
|
+
this.strategyId = strategyData._id;
|
|
2406
|
+
this.learnable = strategyData.learnable;
|
|
2407
|
+
this.staticWeight = strategyData.staticWeight;
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
// ============================================================================
|
|
2411
|
+
// STRATEGY STATE HELPERS
|
|
2412
|
+
// ============================================================================
|
|
2413
|
+
//
|
|
2414
|
+
// These methods allow strategies to persist their own state (user preferences,
|
|
2415
|
+
// learned patterns, temporal tracking) in the user database.
|
|
2416
|
+
//
|
|
2417
|
+
// ============================================================================
|
|
2418
|
+
/**
|
|
2419
|
+
* Unique key identifying this strategy for state storage.
|
|
2420
|
+
*
|
|
2421
|
+
* Defaults to the constructor name (e.g., "UserTagPreferenceFilter").
|
|
2422
|
+
* Override in subclasses if multiple instances of the same strategy type
|
|
2423
|
+
* need separate state storage.
|
|
2424
|
+
*/
|
|
2425
|
+
get strategyKey() {
|
|
2426
|
+
return this.constructor.name;
|
|
2427
|
+
}
|
|
2428
|
+
/**
|
|
2429
|
+
* Get this strategy's persisted state for the current course.
|
|
2430
|
+
*
|
|
2431
|
+
* @returns The strategy's data payload, or null if no state exists
|
|
2432
|
+
* @throws Error if user or course is not initialized
|
|
2433
|
+
*/
|
|
2434
|
+
async getStrategyState() {
|
|
2435
|
+
if (!this.user || !this.course) {
|
|
2436
|
+
throw new Error(
|
|
2437
|
+
`Cannot get strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
2438
|
+
);
|
|
2439
|
+
}
|
|
2440
|
+
return this.user.getStrategyState(this.course.getCourseID(), this.strategyKey);
|
|
2441
|
+
}
|
|
2442
|
+
/**
|
|
2443
|
+
* Persist this strategy's state for the current course.
|
|
2444
|
+
*
|
|
2445
|
+
* @param data - The strategy's data payload to store
|
|
2446
|
+
* @throws Error if user or course is not initialized
|
|
2447
|
+
*/
|
|
2448
|
+
async putStrategyState(data) {
|
|
2449
|
+
if (!this.user || !this.course) {
|
|
2450
|
+
throw new Error(
|
|
2451
|
+
`Cannot put strategy state: navigator not properly initialized. Ensure user and course are provided to constructor.`
|
|
2452
|
+
);
|
|
2453
|
+
}
|
|
2454
|
+
return this.user.putStrategyState(this.course.getCourseID(), this.strategyKey, data);
|
|
2455
|
+
}
|
|
2456
|
+
/**
|
|
2457
|
+
* Factory method to create navigator instances.
|
|
2458
|
+
*
|
|
2459
|
+
* First checks the navigator registry for a pre-registered constructor.
|
|
2460
|
+
* If not found, falls back to dynamic import (for custom navigators).
|
|
2461
|
+
*
|
|
2462
|
+
* For reliable operation in test environments, call initializeNavigatorRegistry()
|
|
2463
|
+
* before using this method.
|
|
2464
|
+
*
|
|
2465
|
+
* @param user - User interface
|
|
2466
|
+
* @param course - Course interface
|
|
2467
|
+
* @param strategyData - Strategy configuration document
|
|
2468
|
+
* @returns the runtime object used to steer a study session.
|
|
2469
|
+
*/
|
|
2470
|
+
static async create(user, course, strategyData) {
|
|
2471
|
+
const implementingClass = strategyData.implementingClass;
|
|
2472
|
+
const RegisteredImpl = getRegisteredNavigator(implementingClass);
|
|
2473
|
+
if (RegisteredImpl) {
|
|
2474
|
+
logger.debug(`[ContentNavigator.create] Using registered navigator: ${implementingClass}`);
|
|
2475
|
+
return new RegisteredImpl(user, course, strategyData);
|
|
2476
|
+
}
|
|
2477
|
+
logger.debug(
|
|
2478
|
+
`[ContentNavigator.create] Navigator not in registry, attempting dynamic import: ${implementingClass}`
|
|
2479
|
+
);
|
|
2480
|
+
let NavigatorImpl;
|
|
2481
|
+
const variations = [".ts", ".js", ""];
|
|
2482
|
+
for (const ext of variations) {
|
|
2483
|
+
try {
|
|
2484
|
+
const module2 = await globImport_generators(`./generators/${implementingClass}${ext}`);
|
|
2485
|
+
NavigatorImpl = module2.default;
|
|
2486
|
+
if (NavigatorImpl) break;
|
|
2487
|
+
} catch (e) {
|
|
2488
|
+
logger.debug(`Failed to load generator ${implementingClass}${ext}:`, e);
|
|
2489
|
+
}
|
|
2490
|
+
try {
|
|
2491
|
+
const module2 = await globImport_filters(`./filters/${implementingClass}${ext}`);
|
|
2492
|
+
NavigatorImpl = module2.default;
|
|
2493
|
+
if (NavigatorImpl) break;
|
|
2494
|
+
} catch (e) {
|
|
2495
|
+
logger.debug(`Failed to load filter ${implementingClass}${ext}:`, e);
|
|
2496
|
+
}
|
|
2497
|
+
try {
|
|
2498
|
+
const module2 = await globImport(`./${implementingClass}${ext}`);
|
|
2499
|
+
NavigatorImpl = module2.default;
|
|
2500
|
+
if (NavigatorImpl) break;
|
|
2501
|
+
} catch (e) {
|
|
2502
|
+
logger.debug(`Failed to load legacy ${implementingClass}${ext}:`, e);
|
|
2503
|
+
}
|
|
2504
|
+
if (NavigatorImpl) break;
|
|
2505
|
+
}
|
|
2506
|
+
if (!NavigatorImpl) {
|
|
2507
|
+
throw new Error(`Could not load navigator implementation for: ${implementingClass}`);
|
|
2508
|
+
}
|
|
2509
|
+
return new NavigatorImpl(user, course, strategyData);
|
|
2510
|
+
}
|
|
2511
|
+
/**
|
|
2512
|
+
* Get cards with suitability scores and provenance trails.
|
|
2513
|
+
*
|
|
2514
|
+
* **This is the PRIMARY API for navigation strategies.**
|
|
2515
|
+
*
|
|
2516
|
+
* Returns cards ranked by suitability score (0-1). Higher scores indicate
|
|
2517
|
+
* better candidates for presentation. Each card includes a provenance trail
|
|
2518
|
+
* documenting how strategies contributed to the final score.
|
|
2519
|
+
*
|
|
2520
|
+
* ## Implementation Required
|
|
2521
|
+
* All navigation strategies MUST override this method. The base class does
|
|
2522
|
+
* not provide a default implementation.
|
|
2523
|
+
*
|
|
2524
|
+
* ## For Generators
|
|
2525
|
+
* Override this method to generate candidates and compute scores based on
|
|
2526
|
+
* your strategy's logic (e.g., ELO proximity, review urgency). Create the
|
|
2527
|
+
* initial provenance entry with action='generated'.
|
|
2528
|
+
*
|
|
2529
|
+
* ## For Filters
|
|
2530
|
+
* Filters should implement the CardFilter interface instead and be composed
|
|
2531
|
+
* via Pipeline. Filters do not directly implement getWeightedCards().
|
|
2532
|
+
*
|
|
2533
|
+
* @param limit - Maximum cards to return
|
|
2534
|
+
* @returns Cards sorted by score descending, with provenance trails
|
|
2535
|
+
*/
|
|
2536
|
+
async getWeightedCards(_limit) {
|
|
2537
|
+
throw new Error(`${this.constructor.name} must implement getWeightedCards(). `);
|
|
2538
|
+
}
|
|
2539
|
+
};
|
|
2540
|
+
}
|
|
2541
|
+
});
|
|
2542
|
+
|
|
1329
2543
|
// src/impl/couch/courseDB.ts
|
|
1330
|
-
var
|
|
2544
|
+
var import_common9;
|
|
1331
2545
|
var init_courseDB = __esm({
|
|
1332
2546
|
"src/impl/couch/courseDB.ts"() {
|
|
1333
2547
|
"use strict";
|
|
1334
|
-
|
|
2548
|
+
import_common9 = require("@vue-skuilder/common");
|
|
1335
2549
|
init_couch();
|
|
1336
2550
|
init_updateQueue();
|
|
1337
2551
|
init_types_legacy();
|
|
@@ -1384,14 +2598,14 @@ var init_auth = __esm({
|
|
|
1384
2598
|
});
|
|
1385
2599
|
|
|
1386
2600
|
// src/impl/couch/CouchDBSyncStrategy.ts
|
|
1387
|
-
var
|
|
2601
|
+
var import_common10;
|
|
1388
2602
|
var init_CouchDBSyncStrategy = __esm({
|
|
1389
2603
|
"src/impl/couch/CouchDBSyncStrategy.ts"() {
|
|
1390
2604
|
"use strict";
|
|
1391
2605
|
init_factory();
|
|
1392
2606
|
init_types_legacy();
|
|
1393
2607
|
init_logger();
|
|
1394
|
-
|
|
2608
|
+
import_common10 = require("@vue-skuilder/common");
|
|
1395
2609
|
init_common();
|
|
1396
2610
|
init_pouchdb_setup();
|
|
1397
2611
|
init_couch();
|
|
@@ -1625,13 +2839,13 @@ async function dropUserFromClassroom(user, classID) {
|
|
|
1625
2839
|
async function getUserClassrooms(user) {
|
|
1626
2840
|
return getOrCreateClassroomRegistrationsDoc(user);
|
|
1627
2841
|
}
|
|
1628
|
-
var
|
|
2842
|
+
var import_common12, import_moment6, log3, BaseUser, userCoursesDoc, userClassroomsDoc;
|
|
1629
2843
|
var init_BaseUserDB = __esm({
|
|
1630
2844
|
"src/impl/common/BaseUserDB.ts"() {
|
|
1631
2845
|
"use strict";
|
|
1632
2846
|
init_core();
|
|
1633
2847
|
init_util();
|
|
1634
|
-
|
|
2848
|
+
import_common12 = require("@vue-skuilder/common");
|
|
1635
2849
|
import_moment6 = __toESM(require("moment"), 1);
|
|
1636
2850
|
init_types_legacy();
|
|
1637
2851
|
init_logger();
|
|
@@ -1681,7 +2895,7 @@ Currently logged-in as ${this._username}.`
|
|
|
1681
2895
|
);
|
|
1682
2896
|
}
|
|
1683
2897
|
const result = await this.syncStrategy.createAccount(username, password);
|
|
1684
|
-
if (result.status ===
|
|
2898
|
+
if (result.status === import_common12.Status.ok) {
|
|
1685
2899
|
log3(`Account created successfully, updating username to ${username}`);
|
|
1686
2900
|
this._username = username;
|
|
1687
2901
|
try {
|
|
@@ -1723,7 +2937,7 @@ Currently logged-in as ${this._username}.`
|
|
|
1723
2937
|
async resetUserData() {
|
|
1724
2938
|
if (this.syncStrategy.canAuthenticate()) {
|
|
1725
2939
|
return {
|
|
1726
|
-
status:
|
|
2940
|
+
status: import_common12.Status.error,
|
|
1727
2941
|
error: "Reset user data is only available for local-only mode. Use logout instead for remote sync."
|
|
1728
2942
|
};
|
|
1729
2943
|
}
|
|
@@ -1742,11 +2956,11 @@ Currently logged-in as ${this._username}.`
|
|
|
1742
2956
|
await localDB.bulkDocs(docsToDelete);
|
|
1743
2957
|
}
|
|
1744
2958
|
await this.init();
|
|
1745
|
-
return { status:
|
|
2959
|
+
return { status: import_common12.Status.ok };
|
|
1746
2960
|
} catch (error) {
|
|
1747
2961
|
logger.error("Failed to reset user data:", error);
|
|
1748
2962
|
return {
|
|
1749
|
-
status:
|
|
2963
|
+
status: import_common12.Status.error,
|
|
1750
2964
|
error: error instanceof Error ? error.message : "Unknown error during reset"
|
|
1751
2965
|
};
|
|
1752
2966
|
}
|
|
@@ -2473,6 +3687,19 @@ Currently logged-in as ${this._username}.`
|
|
|
2473
3687
|
};
|
|
2474
3688
|
await this.localDB.put(doc);
|
|
2475
3689
|
}
|
|
3690
|
+
async putUserOutcome(record) {
|
|
3691
|
+
try {
|
|
3692
|
+
await this.localDB.put(record);
|
|
3693
|
+
} catch (err) {
|
|
3694
|
+
if (err.status === 409) {
|
|
3695
|
+
const existing = await this.localDB.get(record._id);
|
|
3696
|
+
record._rev = existing._rev;
|
|
3697
|
+
await this.localDB.put(record);
|
|
3698
|
+
} else {
|
|
3699
|
+
throw err;
|
|
3700
|
+
}
|
|
3701
|
+
}
|
|
3702
|
+
}
|
|
2476
3703
|
async deleteStrategyState(courseId, strategyKey) {
|
|
2477
3704
|
const docId = buildStrategyStateId(courseId, strategyKey);
|
|
2478
3705
|
try {
|
|
@@ -2509,6 +3736,7 @@ var init_factory = __esm({
|
|
|
2509
3736
|
"use strict";
|
|
2510
3737
|
init_common();
|
|
2511
3738
|
init_logger();
|
|
3739
|
+
init_navigators();
|
|
2512
3740
|
NOT_SET = "NOT_SET";
|
|
2513
3741
|
ENV = {
|
|
2514
3742
|
COUCHDB_SERVER_PROTOCOL: NOT_SET,
|
|
@@ -2519,24 +3747,24 @@ var init_factory = __esm({
|
|
|
2519
3747
|
});
|
|
2520
3748
|
|
|
2521
3749
|
// src/study/TagFilteredContentSource.ts
|
|
2522
|
-
var
|
|
3750
|
+
var import_common14;
|
|
2523
3751
|
var init_TagFilteredContentSource = __esm({
|
|
2524
3752
|
"src/study/TagFilteredContentSource.ts"() {
|
|
2525
3753
|
"use strict";
|
|
2526
|
-
|
|
3754
|
+
import_common14 = require("@vue-skuilder/common");
|
|
2527
3755
|
init_courseDB();
|
|
2528
3756
|
init_logger();
|
|
2529
3757
|
}
|
|
2530
3758
|
});
|
|
2531
3759
|
|
|
2532
3760
|
// src/core/interfaces/contentSource.ts
|
|
2533
|
-
var
|
|
3761
|
+
var import_common15;
|
|
2534
3762
|
var init_contentSource = __esm({
|
|
2535
3763
|
"src/core/interfaces/contentSource.ts"() {
|
|
2536
3764
|
"use strict";
|
|
2537
3765
|
init_factory();
|
|
2538
3766
|
init_classroomDB2();
|
|
2539
|
-
|
|
3767
|
+
import_common15 = require("@vue-skuilder/common");
|
|
2540
3768
|
init_TagFilteredContentSource();
|
|
2541
3769
|
}
|
|
2542
3770
|
});
|
|
@@ -2592,18 +3820,25 @@ var init_strategyState = __esm({
|
|
|
2592
3820
|
}
|
|
2593
3821
|
});
|
|
2594
3822
|
|
|
3823
|
+
// src/core/types/userOutcome.ts
|
|
3824
|
+
var init_userOutcome = __esm({
|
|
3825
|
+
"src/core/types/userOutcome.ts"() {
|
|
3826
|
+
"use strict";
|
|
3827
|
+
}
|
|
3828
|
+
});
|
|
3829
|
+
|
|
2595
3830
|
// src/core/bulkImport/cardProcessor.ts
|
|
2596
|
-
var
|
|
3831
|
+
var import_common16;
|
|
2597
3832
|
var init_cardProcessor = __esm({
|
|
2598
3833
|
"src/core/bulkImport/cardProcessor.ts"() {
|
|
2599
3834
|
"use strict";
|
|
2600
|
-
|
|
3835
|
+
import_common16 = require("@vue-skuilder/common");
|
|
2601
3836
|
init_logger();
|
|
2602
3837
|
}
|
|
2603
3838
|
});
|
|
2604
3839
|
|
|
2605
3840
|
// src/core/bulkImport/types.ts
|
|
2606
|
-
var
|
|
3841
|
+
var init_types3 = __esm({
|
|
2607
3842
|
"src/core/bulkImport/types.ts"() {
|
|
2608
3843
|
"use strict";
|
|
2609
3844
|
}
|
|
@@ -2614,7 +3849,7 @@ var init_bulkImport = __esm({
|
|
|
2614
3849
|
"src/core/bulkImport/index.ts"() {
|
|
2615
3850
|
"use strict";
|
|
2616
3851
|
init_cardProcessor();
|
|
2617
|
-
|
|
3852
|
+
init_types3();
|
|
2618
3853
|
}
|
|
2619
3854
|
});
|
|
2620
3855
|
|
|
@@ -2626,10 +3861,12 @@ var init_core = __esm({
|
|
|
2626
3861
|
init_types_legacy();
|
|
2627
3862
|
init_user();
|
|
2628
3863
|
init_strategyState();
|
|
3864
|
+
init_userOutcome();
|
|
2629
3865
|
init_Loggable();
|
|
2630
3866
|
init_util();
|
|
2631
3867
|
init_navigators();
|
|
2632
3868
|
init_bulkImport();
|
|
3869
|
+
init_orchestration();
|
|
2633
3870
|
}
|
|
2634
3871
|
});
|
|
2635
3872
|
|
|
@@ -3050,11 +4287,11 @@ var init_StaticDataUnpacker = __esm({
|
|
|
3050
4287
|
});
|
|
3051
4288
|
|
|
3052
4289
|
// src/impl/static/courseDB.ts
|
|
3053
|
-
var
|
|
4290
|
+
var import_common17, StaticCourseDB;
|
|
3054
4291
|
var init_courseDB3 = __esm({
|
|
3055
4292
|
"src/impl/static/courseDB.ts"() {
|
|
3056
4293
|
"use strict";
|
|
3057
|
-
|
|
4294
|
+
import_common17 = require("@vue-skuilder/common");
|
|
3058
4295
|
init_types_legacy();
|
|
3059
4296
|
init_logger();
|
|
3060
4297
|
init_defaults();
|
|
@@ -3311,7 +4548,7 @@ var init_courseDB3 = __esm({
|
|
|
3311
4548
|
}
|
|
3312
4549
|
async addNote(_codeCourse, _shape, _data, _author, _tags, _uploads, _elo) {
|
|
3313
4550
|
return {
|
|
3314
|
-
status:
|
|
4551
|
+
status: import_common17.Status.error,
|
|
3315
4552
|
message: "Cannot add notes in static mode"
|
|
3316
4553
|
};
|
|
3317
4554
|
}
|