@vue-skuilder/db 0.1.22 → 0.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{contentSource-BP9hznNV.d.ts → contentSource-BotbOOfX.d.ts} +227 -3
- package/dist/{contentSource-DsJadoBU.d.cts → contentSource-C90LH-OH.d.cts} +227 -3
- package/dist/core/index.d.cts +220 -6
- package/dist/core/index.d.ts +220 -6
- package/dist/core/index.js +2052 -559
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +2035 -555
- package/dist/core/index.mjs.map +1 -1
- package/dist/{dataLayerProvider-CHYrQ5pB.d.cts → dataLayerProvider-DGKp4zFB.d.cts} +1 -1
- package/dist/{dataLayerProvider-MDTxXq2l.d.ts → dataLayerProvider-SBpz9jQf.d.ts} +1 -1
- package/dist/impl/couch/index.d.cts +11 -3
- package/dist/impl/couch/index.d.ts +11 -3
- package/dist/impl/couch/index.js +1811 -574
- package/dist/impl/couch/index.js.map +1 -1
- package/dist/impl/couch/index.mjs +1792 -550
- package/dist/impl/couch/index.mjs.map +1 -1
- package/dist/impl/static/index.d.cts +4 -4
- package/dist/impl/static/index.d.ts +4 -4
- package/dist/impl/static/index.js +1797 -560
- package/dist/impl/static/index.js.map +1 -1
- package/dist/impl/static/index.mjs +1789 -547
- package/dist/impl/static/index.mjs.map +1 -1
- package/dist/{index-Dj0SEgk3.d.ts → index-BWvO-_rJ.d.ts} +1 -1
- package/dist/{index-B_j6u5E4.d.cts → index-Ba7hYbHj.d.cts} +1 -1
- package/dist/index.d.cts +150 -12
- package/dist/index.d.ts +150 -12
- package/dist/index.js +2658 -791
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2584 -747
- package/dist/index.mjs.map +1 -1
- package/dist/{types-DQaXnuoc.d.ts → types-CJrLM1Ew.d.ts} +1 -1
- package/dist/{types-Bn0itutr.d.cts → types-W8n-B6HG.d.cts} +1 -1
- package/dist/{types-legacy-DDY4N-Uq.d.cts → types-legacy-JXDxinpU.d.cts} +5 -1
- package/dist/{types-legacy-DDY4N-Uq.d.ts → types-legacy-JXDxinpU.d.ts} +5 -1
- package/dist/util/packer/index.d.cts +3 -3
- package/dist/util/packer/index.d.ts +3 -3
- package/docs/brainstorm-navigation-paradigm.md +40 -34
- package/docs/future-orchestration-vision.md +216 -0
- package/docs/navigators-architecture.md +188 -5
- package/docs/todo-strategy-authoring.md +8 -6
- package/package.json +3 -3
- package/src/core/index.ts +2 -0
- package/src/core/interfaces/contentSource.ts +7 -0
- package/src/core/interfaces/userDB.ts +6 -0
- package/src/core/navigators/Pipeline.ts +46 -0
- package/src/core/navigators/PipelineAssembler.ts +14 -1
- package/src/core/navigators/filters/WeightedFilter.ts +141 -0
- package/src/core/navigators/filters/types.ts +4 -0
- package/src/core/navigators/generators/CompositeGenerator.ts +61 -19
- package/src/core/navigators/generators/types.ts +4 -0
- package/src/core/navigators/index.ts +194 -13
- package/src/core/orchestration/gradient.ts +133 -0
- package/src/core/orchestration/index.ts +210 -0
- package/src/core/orchestration/learning.ts +250 -0
- package/src/core/orchestration/recording.ts +92 -0
- package/src/core/orchestration/signal.ts +67 -0
- package/src/core/types/contentNavigationStrategy.ts +38 -0
- package/src/core/types/learningState.ts +77 -0
- package/src/core/types/types-legacy.ts +4 -0
- package/src/core/types/userOutcome.ts +51 -0
- package/src/courseConfigRegistration.ts +546 -0
- package/src/factory.ts +6 -0
- package/src/impl/common/BaseUserDB.ts +16 -0
- package/src/index.ts +2 -0
- package/src/study/SessionController.ts +64 -1
- package/tests/core/navigators/Pipeline.test.ts +2 -0
- package/docs/todo-evolutionary-orchestration.md +0 -310
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CourseConfig, ClassroomConfig, Status, SkuilderCourseData as SkuilderCourseData$1, CourseElo, DataShape, TagFilter } from '@vue-skuilder/common';
|
|
2
2
|
import { Moment } from 'moment';
|
|
3
|
-
import { S as SkuilderCourseData, b as DocTypePrefixes, D as DocType, Q as QualifiedCardID, T as TagStub, a as Tag, C as CardHistory, c as CardRecord } from './types-legacy-
|
|
3
|
+
import { S as SkuilderCourseData, b as DocTypePrefixes, D as DocType, Q as QualifiedCardID, T as TagStub, a as Tag, C as CardHistory, c as CardRecord } from './types-legacy-JXDxinpU.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Admin functionality
|
|
@@ -91,6 +91,24 @@ interface DataLayerResult {
|
|
|
91
91
|
id?: string;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Configuration for an evolutionarily-weighted strategy.
|
|
96
|
+
*
|
|
97
|
+
* This structure tracks the "learned" weight of a strategy, representing the
|
|
98
|
+
* system's confidence in its utility.
|
|
99
|
+
*
|
|
100
|
+
* - weight: The best-known multiplier (peak of the bell curve)
|
|
101
|
+
* - confidence: How certain we are (inverse of variance / spread)
|
|
102
|
+
* - sampleSize: How many data points informed this weight
|
|
103
|
+
*/
|
|
104
|
+
interface LearnableWeight {
|
|
105
|
+
/** The current best estimate of optimal weight (multiplier) */
|
|
106
|
+
weight: number;
|
|
107
|
+
/** Confidence in this weight (0-1). Higher = narrower exploration spread. */
|
|
108
|
+
confidence: number;
|
|
109
|
+
/** Number of outcome observations that contributed to this weight */
|
|
110
|
+
sampleSize: number;
|
|
111
|
+
}
|
|
94
112
|
/**
|
|
95
113
|
*
|
|
96
114
|
*/
|
|
@@ -108,6 +126,17 @@ interface ContentNavigationStrategyData extends SkuilderCourseData {
|
|
|
108
126
|
by the implementing class's constructor at runtime.
|
|
109
127
|
*/
|
|
110
128
|
serializedData: string;
|
|
129
|
+
/**
|
|
130
|
+
* Evolutionary weighting configuration.
|
|
131
|
+
* If present, the strategy's influence is scaled by this weight.
|
|
132
|
+
* If omitted, weight defaults to 1.0.
|
|
133
|
+
*/
|
|
134
|
+
learnable?: LearnableWeight;
|
|
135
|
+
/**
|
|
136
|
+
* If true, the weight is applied exactly as configured, without
|
|
137
|
+
* per-user deviation. Used for manual tuning or A/B testing.
|
|
138
|
+
*/
|
|
139
|
+
staticWeight?: boolean;
|
|
111
140
|
}
|
|
112
141
|
|
|
113
142
|
/**
|
|
@@ -340,6 +369,50 @@ interface ScheduledCard {
|
|
|
340
369
|
schedulingAgentId: string;
|
|
341
370
|
}
|
|
342
371
|
|
|
372
|
+
/**
|
|
373
|
+
* Record of a user's learning outcome over a specific period.
|
|
374
|
+
*
|
|
375
|
+
* Used by the evolutionary orchestration system to correlate strategy
|
|
376
|
+
* deviations with learning success.
|
|
377
|
+
*
|
|
378
|
+
* Stored in the UserDB.
|
|
379
|
+
*/
|
|
380
|
+
interface UserOutcomeRecord {
|
|
381
|
+
/**
|
|
382
|
+
* Unique ID: "USER_OUTCOME::{courseId}::{userId}::{timestamp}"
|
|
383
|
+
* Timestamp corresponds to periodEnd.
|
|
384
|
+
*/
|
|
385
|
+
_id: string;
|
|
386
|
+
docType: DocType.USER_OUTCOME;
|
|
387
|
+
courseId: string;
|
|
388
|
+
userId: string;
|
|
389
|
+
/** Start of the measurement period (ISO timestamp) */
|
|
390
|
+
periodStart: string;
|
|
391
|
+
/** End of the measurement period (ISO timestamp) */
|
|
392
|
+
periodEnd: string;
|
|
393
|
+
/**
|
|
394
|
+
* The computed signal value (e.g., 0.85 for 85% accuracy).
|
|
395
|
+
* This is the 'Y' in the regression analysis.
|
|
396
|
+
*
|
|
397
|
+
* Higher values indicate better learning outcomes.
|
|
398
|
+
*/
|
|
399
|
+
outcomeValue: number;
|
|
400
|
+
/**
|
|
401
|
+
* Snapshot of active deviations during this period.
|
|
402
|
+
* Maps strategyId -> deviation value used [-1.0, 1.0].
|
|
403
|
+
* This provides the 'X' values for regression analysis.
|
|
404
|
+
*/
|
|
405
|
+
deviations: Record<string, number>;
|
|
406
|
+
metadata: {
|
|
407
|
+
sessionsCount: number;
|
|
408
|
+
cardsSeen: number;
|
|
409
|
+
eloStart: number;
|
|
410
|
+
eloEnd: number;
|
|
411
|
+
/** The algorithm used to compute outcomeValue (e.g. "accuracy_in_zone") */
|
|
412
|
+
signalType: string;
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
|
|
343
416
|
type Update<T> = Partial<T> | ((x: T) => T);
|
|
344
417
|
|
|
345
418
|
interface DocumentUpdater {
|
|
@@ -483,6 +556,10 @@ interface UserDBWriter extends DocumentUpdater {
|
|
|
483
556
|
* @param strategyKey - Unique key identifying the strategy (typically class name)
|
|
484
557
|
*/
|
|
485
558
|
deleteStrategyState(courseId: string, strategyKey: string): Promise<void>;
|
|
559
|
+
/**
|
|
560
|
+
* Record a user learning outcome for evolutionary orchestration.
|
|
561
|
+
*/
|
|
562
|
+
putUserOutcome(record: UserOutcomeRecord): Promise<void>;
|
|
486
563
|
}
|
|
487
564
|
/**
|
|
488
565
|
* Authentication and account management operations
|
|
@@ -537,6 +614,127 @@ interface ClassroomRegistrationDoc {
|
|
|
537
614
|
registrations: ClassroomRegistration[];
|
|
538
615
|
}
|
|
539
616
|
|
|
617
|
+
/**
|
|
618
|
+
* Context for orchestration decisions during a session.
|
|
619
|
+
*
|
|
620
|
+
* Provides access to user/course data and helper methods for determining
|
|
621
|
+
* effective strategy weights based on the user's cohort assignment.
|
|
622
|
+
*/
|
|
623
|
+
interface OrchestrationContext {
|
|
624
|
+
user: UserDBInterface;
|
|
625
|
+
course: CourseDBInterface;
|
|
626
|
+
userId: string;
|
|
627
|
+
courseConfig: CourseConfig;
|
|
628
|
+
/**
|
|
629
|
+
* Calculate the effective weight for a strategy for this user.
|
|
630
|
+
*
|
|
631
|
+
* Applies deviation based on the user's cohort assignment (derived from
|
|
632
|
+
* userId, strategyId, and course salt).
|
|
633
|
+
*
|
|
634
|
+
* @param strategyId - Unique ID of the strategy
|
|
635
|
+
* @param learnable - The strategy's learning configuration
|
|
636
|
+
* @returns Effective weight multiplier (typically 0.1 - 3.0)
|
|
637
|
+
*/
|
|
638
|
+
getEffectiveWeight(strategyId: string, learnable: LearnableWeight): number;
|
|
639
|
+
/**
|
|
640
|
+
* Get the deviation factor for this user/strategy.
|
|
641
|
+
* Range [-1.0, 1.0].
|
|
642
|
+
*/
|
|
643
|
+
getDeviation(strategyId: string): number;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Compute a user's deviation for a specific strategy.
|
|
647
|
+
*
|
|
648
|
+
* Returns a value in [-1, 1] that is:
|
|
649
|
+
* 1. Deterministic for the same (user, strategy, salt) tuple
|
|
650
|
+
* 2. Uniformly distributed across users
|
|
651
|
+
* 3. Uncorrelated between different strategies (due to strategyId in hash)
|
|
652
|
+
* 4. Rotatable by changing the salt
|
|
653
|
+
*
|
|
654
|
+
* @param userId - ID of the user
|
|
655
|
+
* @param strategyId - ID of the strategy
|
|
656
|
+
* @param salt - Random seed from course config
|
|
657
|
+
* @returns Deviation factor between -1.0 and 1.0
|
|
658
|
+
*/
|
|
659
|
+
declare function computeDeviation(userId: string, strategyId: string, salt: string): number;
|
|
660
|
+
/**
|
|
661
|
+
* Compute the exploration spread based on confidence.
|
|
662
|
+
*
|
|
663
|
+
* - Low confidence (0.0) -> Max spread (Explore broadly)
|
|
664
|
+
* - High confidence (1.0) -> Min spread (Exploit known good weight)
|
|
665
|
+
*
|
|
666
|
+
* @param confidence - Confidence level 0-1
|
|
667
|
+
* @returns Spread magnitude (half-width of the distribution)
|
|
668
|
+
*/
|
|
669
|
+
declare function computeSpread(confidence: number): number;
|
|
670
|
+
/**
|
|
671
|
+
* Calculate the effective weight for a strategy instance.
|
|
672
|
+
*
|
|
673
|
+
* Combines the learnable weight (peak) with the user's deviation and the
|
|
674
|
+
* allowed spread (based on confidence).
|
|
675
|
+
*
|
|
676
|
+
* @param learnable - Strategy learning config
|
|
677
|
+
* @param userId - User ID
|
|
678
|
+
* @param strategyId - Strategy ID
|
|
679
|
+
* @param salt - Course salt
|
|
680
|
+
* @returns Effective weight multiplier
|
|
681
|
+
*/
|
|
682
|
+
declare function computeEffectiveWeight(learnable: LearnableWeight, userId: string, strategyId: string, salt: string): number;
|
|
683
|
+
/**
|
|
684
|
+
* Create an orchestration context for a study session.
|
|
685
|
+
*
|
|
686
|
+
* Fetches necessary configuration to enable deterministic weight calculation.
|
|
687
|
+
*
|
|
688
|
+
* @param user - User DB interface
|
|
689
|
+
* @param course - Course DB interface
|
|
690
|
+
* @returns Initialized orchestration context
|
|
691
|
+
*/
|
|
692
|
+
declare function createOrchestrationContext(user: UserDBInterface, course: CourseDBInterface): Promise<OrchestrationContext>;
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* Type for navigator constructor functions.
|
|
696
|
+
*/
|
|
697
|
+
type NavigatorConstructor = new (user: UserDBInterface, course: CourseDBInterface, strategyData: ContentNavigationStrategyData) => ContentNavigator;
|
|
698
|
+
/**
|
|
699
|
+
* Register a navigator implementation.
|
|
700
|
+
*
|
|
701
|
+
* Call this to make a navigator available for instantiation by
|
|
702
|
+
* ContentNavigator.create() without relying on dynamic imports.
|
|
703
|
+
*
|
|
704
|
+
* @param implementingClass - The class name (e.g., 'elo', 'hierarchyDefinition')
|
|
705
|
+
* @param constructor - The navigator class constructor
|
|
706
|
+
*/
|
|
707
|
+
declare function registerNavigator(implementingClass: string, constructor: NavigatorConstructor): void;
|
|
708
|
+
/**
|
|
709
|
+
* Get a navigator constructor from the registry.
|
|
710
|
+
*
|
|
711
|
+
* @param implementingClass - The class name to look up
|
|
712
|
+
* @returns The constructor, or undefined if not registered
|
|
713
|
+
*/
|
|
714
|
+
declare function getRegisteredNavigator(implementingClass: string): NavigatorConstructor | undefined;
|
|
715
|
+
/**
|
|
716
|
+
* Check if a navigator is registered.
|
|
717
|
+
*
|
|
718
|
+
* @param implementingClass - The class name to check
|
|
719
|
+
* @returns true if registered, false otherwise
|
|
720
|
+
*/
|
|
721
|
+
declare function hasRegisteredNavigator(implementingClass: string): boolean;
|
|
722
|
+
/**
|
|
723
|
+
* Get all registered navigator names.
|
|
724
|
+
* Useful for debugging and testing.
|
|
725
|
+
*/
|
|
726
|
+
declare function getRegisteredNavigatorNames(): string[];
|
|
727
|
+
/**
|
|
728
|
+
* Initialize the navigator registry with all built-in navigators.
|
|
729
|
+
*
|
|
730
|
+
* This function dynamically imports all standard navigator implementations
|
|
731
|
+
* and registers them. Call this once at application startup to ensure
|
|
732
|
+
* all navigators are available.
|
|
733
|
+
*
|
|
734
|
+
* In test environments, this may need to be called explicitly before
|
|
735
|
+
* using ContentNavigator.create().
|
|
736
|
+
*/
|
|
737
|
+
declare function initializeNavigatorRegistry(): Promise<void>;
|
|
540
738
|
/**
|
|
541
739
|
* Tracks a single strategy's contribution to a card's final score.
|
|
542
740
|
*
|
|
@@ -583,6 +781,17 @@ interface StrategyContribution {
|
|
|
583
781
|
action: 'generated' | 'passed' | 'boosted' | 'penalized';
|
|
584
782
|
/** Score after this strategy's processing */
|
|
585
783
|
score: number;
|
|
784
|
+
/**
|
|
785
|
+
* The effective weight applied for this strategy instance.
|
|
786
|
+
* If using evolutionary orchestration, this includes deviation.
|
|
787
|
+
* If omitted, implies weight 1.0 (legacy behavior).
|
|
788
|
+
*/
|
|
789
|
+
effectiveWeight?: number;
|
|
790
|
+
/**
|
|
791
|
+
* The deviation factor applied to this user's cohort for this strategy.
|
|
792
|
+
* Range [-1.0, 1.0].
|
|
793
|
+
*/
|
|
794
|
+
deviation?: number;
|
|
586
795
|
/**
|
|
587
796
|
* Human-readable explanation of the strategy's decision.
|
|
588
797
|
*
|
|
@@ -698,6 +907,10 @@ declare abstract class ContentNavigator implements StudyContentSource {
|
|
|
698
907
|
protected strategyName?: string;
|
|
699
908
|
/** Unique document ID for this strategy instance (from ContentNavigationStrategyData._id) */
|
|
700
909
|
protected strategyId?: string;
|
|
910
|
+
/** Evolutionary weighting configuration */
|
|
911
|
+
learnable?: LearnableWeight;
|
|
912
|
+
/** Whether to bypass deviation (manual/static weighting) */
|
|
913
|
+
staticWeight?: boolean;
|
|
701
914
|
/**
|
|
702
915
|
* Constructor for standard navigators.
|
|
703
916
|
* Call this from subclass constructors to initialize common fields.
|
|
@@ -729,7 +942,13 @@ declare abstract class ContentNavigator implements StudyContentSource {
|
|
|
729
942
|
*/
|
|
730
943
|
protected putStrategyState<T>(data: T): Promise<void>;
|
|
731
944
|
/**
|
|
732
|
-
* Factory method to create navigator instances
|
|
945
|
+
* Factory method to create navigator instances.
|
|
946
|
+
*
|
|
947
|
+
* First checks the navigator registry for a pre-registered constructor.
|
|
948
|
+
* If not found, falls back to dynamic import (for custom navigators).
|
|
949
|
+
*
|
|
950
|
+
* For reliable operation in test environments, call initializeNavigatorRegistry()
|
|
951
|
+
* before using this method.
|
|
733
952
|
*
|
|
734
953
|
* @param user - User interface
|
|
735
954
|
* @param course - Course interface
|
|
@@ -816,7 +1035,12 @@ interface StudyContentSource {
|
|
|
816
1035
|
* @returns Cards sorted by score descending
|
|
817
1036
|
*/
|
|
818
1037
|
getWeightedCards(limit: number): Promise<WeightedCard[]>;
|
|
1038
|
+
/**
|
|
1039
|
+
* Get the orchestration context for this source.
|
|
1040
|
+
* Used for recording learning outcomes.
|
|
1041
|
+
*/
|
|
1042
|
+
getOrchestrationContext?(): Promise<OrchestrationContext>;
|
|
819
1043
|
}
|
|
820
1044
|
declare function getStudySource(source: ContentSourceID, user: UserDBInterface): Promise<StudyContentSource>;
|
|
821
1045
|
|
|
822
|
-
export { type AdminDBInterface as A, type UsrCrsDataInterface as B, type CourseDBInterface as C, type DataLayerResult as D, type ClassroomRegistrationDesignation as E, type ClassroomRegistration as F, type ClassroomRegistrationDoc as G, type SessionTrackingData as H, type UserConfig as I, type ActivityRecord as J, type CourseRegistration as K, type
|
|
1046
|
+
export { isGenerator as $, type AdminDBInterface as A, type UsrCrsDataInterface as B, type CourseDBInterface as C, type DataLayerResult as D, type ClassroomRegistrationDesignation as E, type ClassroomRegistration as F, type ClassroomRegistrationDoc as G, type SessionTrackingData as H, type UserConfig as I, type ActivityRecord as J, type CourseRegistration as K, type UserOutcomeRecord as L, registerNavigator as M, type NavigatorConstructor as N, getRegisteredNavigator as O, hasRegisteredNavigator as P, getRegisteredNavigatorNames as Q, initializeNavigatorRegistry as R, type StudySessionItem as S, type TeacherClassroomDBInterface as T, type UserDBInterface as U, type StrategyContribution as V, type WeightedCard as W, getCardOrigin as X, Navigators as Y, NavigatorRole as Z, NavigatorRoles as _, type UserDBReader as a, isFilter as a0, type LearnableWeight as a1, type OrchestrationContext as a2, computeDeviation as a3, computeSpread as a4, computeEffectiveWeight as a5, createOrchestrationContext as a6, type DocumentUpdater as a7, newInterval as a8, type CoursesDBInterface as b, type ClassroomDBInterface as c, type CourseInfo as d, type ContentNavigationStrategyData as e, ContentNavigator as f, type AssignedContent as g, type StudyContentSource as h, type StudentClassroomDBInterface as i, type ScheduledCard as j, type StudySessionFailedItem as k, type StudySessionFailedNewItem as l, type StudySessionFailedReviewItem as m, type StudySessionNewItem as n, type StudySessionReviewItem as o, isReview as p, type ContentSourceID as q, getStudySource as r, type CourseRegistrationDoc as s, type AssignedTag as t, type AssignedCourse as u, type AssignedCard as v, type UserDBWriter as w, type UserDBAuthenticator as x, type UserCourseSettings as y, type UserCourseSetting as z };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CourseConfig, ClassroomConfig, Status, SkuilderCourseData as SkuilderCourseData$1, CourseElo, DataShape, TagFilter } from '@vue-skuilder/common';
|
|
2
2
|
import { Moment } from 'moment';
|
|
3
|
-
import { S as SkuilderCourseData, b as DocTypePrefixes, D as DocType, Q as QualifiedCardID, T as TagStub, a as Tag, C as CardHistory, c as CardRecord } from './types-legacy-
|
|
3
|
+
import { S as SkuilderCourseData, b as DocTypePrefixes, D as DocType, Q as QualifiedCardID, T as TagStub, a as Tag, C as CardHistory, c as CardRecord } from './types-legacy-JXDxinpU.cjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Admin functionality
|
|
@@ -91,6 +91,24 @@ interface DataLayerResult {
|
|
|
91
91
|
id?: string;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Configuration for an evolutionarily-weighted strategy.
|
|
96
|
+
*
|
|
97
|
+
* This structure tracks the "learned" weight of a strategy, representing the
|
|
98
|
+
* system's confidence in its utility.
|
|
99
|
+
*
|
|
100
|
+
* - weight: The best-known multiplier (peak of the bell curve)
|
|
101
|
+
* - confidence: How certain we are (inverse of variance / spread)
|
|
102
|
+
* - sampleSize: How many data points informed this weight
|
|
103
|
+
*/
|
|
104
|
+
interface LearnableWeight {
|
|
105
|
+
/** The current best estimate of optimal weight (multiplier) */
|
|
106
|
+
weight: number;
|
|
107
|
+
/** Confidence in this weight (0-1). Higher = narrower exploration spread. */
|
|
108
|
+
confidence: number;
|
|
109
|
+
/** Number of outcome observations that contributed to this weight */
|
|
110
|
+
sampleSize: number;
|
|
111
|
+
}
|
|
94
112
|
/**
|
|
95
113
|
*
|
|
96
114
|
*/
|
|
@@ -108,6 +126,17 @@ interface ContentNavigationStrategyData extends SkuilderCourseData {
|
|
|
108
126
|
by the implementing class's constructor at runtime.
|
|
109
127
|
*/
|
|
110
128
|
serializedData: string;
|
|
129
|
+
/**
|
|
130
|
+
* Evolutionary weighting configuration.
|
|
131
|
+
* If present, the strategy's influence is scaled by this weight.
|
|
132
|
+
* If omitted, weight defaults to 1.0.
|
|
133
|
+
*/
|
|
134
|
+
learnable?: LearnableWeight;
|
|
135
|
+
/**
|
|
136
|
+
* If true, the weight is applied exactly as configured, without
|
|
137
|
+
* per-user deviation. Used for manual tuning or A/B testing.
|
|
138
|
+
*/
|
|
139
|
+
staticWeight?: boolean;
|
|
111
140
|
}
|
|
112
141
|
|
|
113
142
|
/**
|
|
@@ -340,6 +369,50 @@ interface ScheduledCard {
|
|
|
340
369
|
schedulingAgentId: string;
|
|
341
370
|
}
|
|
342
371
|
|
|
372
|
+
/**
|
|
373
|
+
* Record of a user's learning outcome over a specific period.
|
|
374
|
+
*
|
|
375
|
+
* Used by the evolutionary orchestration system to correlate strategy
|
|
376
|
+
* deviations with learning success.
|
|
377
|
+
*
|
|
378
|
+
* Stored in the UserDB.
|
|
379
|
+
*/
|
|
380
|
+
interface UserOutcomeRecord {
|
|
381
|
+
/**
|
|
382
|
+
* Unique ID: "USER_OUTCOME::{courseId}::{userId}::{timestamp}"
|
|
383
|
+
* Timestamp corresponds to periodEnd.
|
|
384
|
+
*/
|
|
385
|
+
_id: string;
|
|
386
|
+
docType: DocType.USER_OUTCOME;
|
|
387
|
+
courseId: string;
|
|
388
|
+
userId: string;
|
|
389
|
+
/** Start of the measurement period (ISO timestamp) */
|
|
390
|
+
periodStart: string;
|
|
391
|
+
/** End of the measurement period (ISO timestamp) */
|
|
392
|
+
periodEnd: string;
|
|
393
|
+
/**
|
|
394
|
+
* The computed signal value (e.g., 0.85 for 85% accuracy).
|
|
395
|
+
* This is the 'Y' in the regression analysis.
|
|
396
|
+
*
|
|
397
|
+
* Higher values indicate better learning outcomes.
|
|
398
|
+
*/
|
|
399
|
+
outcomeValue: number;
|
|
400
|
+
/**
|
|
401
|
+
* Snapshot of active deviations during this period.
|
|
402
|
+
* Maps strategyId -> deviation value used [-1.0, 1.0].
|
|
403
|
+
* This provides the 'X' values for regression analysis.
|
|
404
|
+
*/
|
|
405
|
+
deviations: Record<string, number>;
|
|
406
|
+
metadata: {
|
|
407
|
+
sessionsCount: number;
|
|
408
|
+
cardsSeen: number;
|
|
409
|
+
eloStart: number;
|
|
410
|
+
eloEnd: number;
|
|
411
|
+
/** The algorithm used to compute outcomeValue (e.g. "accuracy_in_zone") */
|
|
412
|
+
signalType: string;
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
|
|
343
416
|
type Update<T> = Partial<T> | ((x: T) => T);
|
|
344
417
|
|
|
345
418
|
interface DocumentUpdater {
|
|
@@ -483,6 +556,10 @@ interface UserDBWriter extends DocumentUpdater {
|
|
|
483
556
|
* @param strategyKey - Unique key identifying the strategy (typically class name)
|
|
484
557
|
*/
|
|
485
558
|
deleteStrategyState(courseId: string, strategyKey: string): Promise<void>;
|
|
559
|
+
/**
|
|
560
|
+
* Record a user learning outcome for evolutionary orchestration.
|
|
561
|
+
*/
|
|
562
|
+
putUserOutcome(record: UserOutcomeRecord): Promise<void>;
|
|
486
563
|
}
|
|
487
564
|
/**
|
|
488
565
|
* Authentication and account management operations
|
|
@@ -537,6 +614,127 @@ interface ClassroomRegistrationDoc {
|
|
|
537
614
|
registrations: ClassroomRegistration[];
|
|
538
615
|
}
|
|
539
616
|
|
|
617
|
+
/**
|
|
618
|
+
* Context for orchestration decisions during a session.
|
|
619
|
+
*
|
|
620
|
+
* Provides access to user/course data and helper methods for determining
|
|
621
|
+
* effective strategy weights based on the user's cohort assignment.
|
|
622
|
+
*/
|
|
623
|
+
interface OrchestrationContext {
|
|
624
|
+
user: UserDBInterface;
|
|
625
|
+
course: CourseDBInterface;
|
|
626
|
+
userId: string;
|
|
627
|
+
courseConfig: CourseConfig;
|
|
628
|
+
/**
|
|
629
|
+
* Calculate the effective weight for a strategy for this user.
|
|
630
|
+
*
|
|
631
|
+
* Applies deviation based on the user's cohort assignment (derived from
|
|
632
|
+
* userId, strategyId, and course salt).
|
|
633
|
+
*
|
|
634
|
+
* @param strategyId - Unique ID of the strategy
|
|
635
|
+
* @param learnable - The strategy's learning configuration
|
|
636
|
+
* @returns Effective weight multiplier (typically 0.1 - 3.0)
|
|
637
|
+
*/
|
|
638
|
+
getEffectiveWeight(strategyId: string, learnable: LearnableWeight): number;
|
|
639
|
+
/**
|
|
640
|
+
* Get the deviation factor for this user/strategy.
|
|
641
|
+
* Range [-1.0, 1.0].
|
|
642
|
+
*/
|
|
643
|
+
getDeviation(strategyId: string): number;
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Compute a user's deviation for a specific strategy.
|
|
647
|
+
*
|
|
648
|
+
* Returns a value in [-1, 1] that is:
|
|
649
|
+
* 1. Deterministic for the same (user, strategy, salt) tuple
|
|
650
|
+
* 2. Uniformly distributed across users
|
|
651
|
+
* 3. Uncorrelated between different strategies (due to strategyId in hash)
|
|
652
|
+
* 4. Rotatable by changing the salt
|
|
653
|
+
*
|
|
654
|
+
* @param userId - ID of the user
|
|
655
|
+
* @param strategyId - ID of the strategy
|
|
656
|
+
* @param salt - Random seed from course config
|
|
657
|
+
* @returns Deviation factor between -1.0 and 1.0
|
|
658
|
+
*/
|
|
659
|
+
declare function computeDeviation(userId: string, strategyId: string, salt: string): number;
|
|
660
|
+
/**
|
|
661
|
+
* Compute the exploration spread based on confidence.
|
|
662
|
+
*
|
|
663
|
+
* - Low confidence (0.0) -> Max spread (Explore broadly)
|
|
664
|
+
* - High confidence (1.0) -> Min spread (Exploit known good weight)
|
|
665
|
+
*
|
|
666
|
+
* @param confidence - Confidence level 0-1
|
|
667
|
+
* @returns Spread magnitude (half-width of the distribution)
|
|
668
|
+
*/
|
|
669
|
+
declare function computeSpread(confidence: number): number;
|
|
670
|
+
/**
|
|
671
|
+
* Calculate the effective weight for a strategy instance.
|
|
672
|
+
*
|
|
673
|
+
* Combines the learnable weight (peak) with the user's deviation and the
|
|
674
|
+
* allowed spread (based on confidence).
|
|
675
|
+
*
|
|
676
|
+
* @param learnable - Strategy learning config
|
|
677
|
+
* @param userId - User ID
|
|
678
|
+
* @param strategyId - Strategy ID
|
|
679
|
+
* @param salt - Course salt
|
|
680
|
+
* @returns Effective weight multiplier
|
|
681
|
+
*/
|
|
682
|
+
declare function computeEffectiveWeight(learnable: LearnableWeight, userId: string, strategyId: string, salt: string): number;
|
|
683
|
+
/**
|
|
684
|
+
* Create an orchestration context for a study session.
|
|
685
|
+
*
|
|
686
|
+
* Fetches necessary configuration to enable deterministic weight calculation.
|
|
687
|
+
*
|
|
688
|
+
* @param user - User DB interface
|
|
689
|
+
* @param course - Course DB interface
|
|
690
|
+
* @returns Initialized orchestration context
|
|
691
|
+
*/
|
|
692
|
+
declare function createOrchestrationContext(user: UserDBInterface, course: CourseDBInterface): Promise<OrchestrationContext>;
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* Type for navigator constructor functions.
|
|
696
|
+
*/
|
|
697
|
+
type NavigatorConstructor = new (user: UserDBInterface, course: CourseDBInterface, strategyData: ContentNavigationStrategyData) => ContentNavigator;
|
|
698
|
+
/**
|
|
699
|
+
* Register a navigator implementation.
|
|
700
|
+
*
|
|
701
|
+
* Call this to make a navigator available for instantiation by
|
|
702
|
+
* ContentNavigator.create() without relying on dynamic imports.
|
|
703
|
+
*
|
|
704
|
+
* @param implementingClass - The class name (e.g., 'elo', 'hierarchyDefinition')
|
|
705
|
+
* @param constructor - The navigator class constructor
|
|
706
|
+
*/
|
|
707
|
+
declare function registerNavigator(implementingClass: string, constructor: NavigatorConstructor): void;
|
|
708
|
+
/**
|
|
709
|
+
* Get a navigator constructor from the registry.
|
|
710
|
+
*
|
|
711
|
+
* @param implementingClass - The class name to look up
|
|
712
|
+
* @returns The constructor, or undefined if not registered
|
|
713
|
+
*/
|
|
714
|
+
declare function getRegisteredNavigator(implementingClass: string): NavigatorConstructor | undefined;
|
|
715
|
+
/**
|
|
716
|
+
* Check if a navigator is registered.
|
|
717
|
+
*
|
|
718
|
+
* @param implementingClass - The class name to check
|
|
719
|
+
* @returns true if registered, false otherwise
|
|
720
|
+
*/
|
|
721
|
+
declare function hasRegisteredNavigator(implementingClass: string): boolean;
|
|
722
|
+
/**
|
|
723
|
+
* Get all registered navigator names.
|
|
724
|
+
* Useful for debugging and testing.
|
|
725
|
+
*/
|
|
726
|
+
declare function getRegisteredNavigatorNames(): string[];
|
|
727
|
+
/**
|
|
728
|
+
* Initialize the navigator registry with all built-in navigators.
|
|
729
|
+
*
|
|
730
|
+
* This function dynamically imports all standard navigator implementations
|
|
731
|
+
* and registers them. Call this once at application startup to ensure
|
|
732
|
+
* all navigators are available.
|
|
733
|
+
*
|
|
734
|
+
* In test environments, this may need to be called explicitly before
|
|
735
|
+
* using ContentNavigator.create().
|
|
736
|
+
*/
|
|
737
|
+
declare function initializeNavigatorRegistry(): Promise<void>;
|
|
540
738
|
/**
|
|
541
739
|
* Tracks a single strategy's contribution to a card's final score.
|
|
542
740
|
*
|
|
@@ -583,6 +781,17 @@ interface StrategyContribution {
|
|
|
583
781
|
action: 'generated' | 'passed' | 'boosted' | 'penalized';
|
|
584
782
|
/** Score after this strategy's processing */
|
|
585
783
|
score: number;
|
|
784
|
+
/**
|
|
785
|
+
* The effective weight applied for this strategy instance.
|
|
786
|
+
* If using evolutionary orchestration, this includes deviation.
|
|
787
|
+
* If omitted, implies weight 1.0 (legacy behavior).
|
|
788
|
+
*/
|
|
789
|
+
effectiveWeight?: number;
|
|
790
|
+
/**
|
|
791
|
+
* The deviation factor applied to this user's cohort for this strategy.
|
|
792
|
+
* Range [-1.0, 1.0].
|
|
793
|
+
*/
|
|
794
|
+
deviation?: number;
|
|
586
795
|
/**
|
|
587
796
|
* Human-readable explanation of the strategy's decision.
|
|
588
797
|
*
|
|
@@ -698,6 +907,10 @@ declare abstract class ContentNavigator implements StudyContentSource {
|
|
|
698
907
|
protected strategyName?: string;
|
|
699
908
|
/** Unique document ID for this strategy instance (from ContentNavigationStrategyData._id) */
|
|
700
909
|
protected strategyId?: string;
|
|
910
|
+
/** Evolutionary weighting configuration */
|
|
911
|
+
learnable?: LearnableWeight;
|
|
912
|
+
/** Whether to bypass deviation (manual/static weighting) */
|
|
913
|
+
staticWeight?: boolean;
|
|
701
914
|
/**
|
|
702
915
|
* Constructor for standard navigators.
|
|
703
916
|
* Call this from subclass constructors to initialize common fields.
|
|
@@ -729,7 +942,13 @@ declare abstract class ContentNavigator implements StudyContentSource {
|
|
|
729
942
|
*/
|
|
730
943
|
protected putStrategyState<T>(data: T): Promise<void>;
|
|
731
944
|
/**
|
|
732
|
-
* Factory method to create navigator instances
|
|
945
|
+
* Factory method to create navigator instances.
|
|
946
|
+
*
|
|
947
|
+
* First checks the navigator registry for a pre-registered constructor.
|
|
948
|
+
* If not found, falls back to dynamic import (for custom navigators).
|
|
949
|
+
*
|
|
950
|
+
* For reliable operation in test environments, call initializeNavigatorRegistry()
|
|
951
|
+
* before using this method.
|
|
733
952
|
*
|
|
734
953
|
* @param user - User interface
|
|
735
954
|
* @param course - Course interface
|
|
@@ -816,7 +1035,12 @@ interface StudyContentSource {
|
|
|
816
1035
|
* @returns Cards sorted by score descending
|
|
817
1036
|
*/
|
|
818
1037
|
getWeightedCards(limit: number): Promise<WeightedCard[]>;
|
|
1038
|
+
/**
|
|
1039
|
+
* Get the orchestration context for this source.
|
|
1040
|
+
* Used for recording learning outcomes.
|
|
1041
|
+
*/
|
|
1042
|
+
getOrchestrationContext?(): Promise<OrchestrationContext>;
|
|
819
1043
|
}
|
|
820
1044
|
declare function getStudySource(source: ContentSourceID, user: UserDBInterface): Promise<StudyContentSource>;
|
|
821
1045
|
|
|
822
|
-
export { type AdminDBInterface as A, type UsrCrsDataInterface as B, type CourseDBInterface as C, type DataLayerResult as D, type ClassroomRegistrationDesignation as E, type ClassroomRegistration as F, type ClassroomRegistrationDoc as G, type SessionTrackingData as H, type UserConfig as I, type ActivityRecord as J, type CourseRegistration as K, type
|
|
1046
|
+
export { isGenerator as $, type AdminDBInterface as A, type UsrCrsDataInterface as B, type CourseDBInterface as C, type DataLayerResult as D, type ClassroomRegistrationDesignation as E, type ClassroomRegistration as F, type ClassroomRegistrationDoc as G, type SessionTrackingData as H, type UserConfig as I, type ActivityRecord as J, type CourseRegistration as K, type UserOutcomeRecord as L, registerNavigator as M, type NavigatorConstructor as N, getRegisteredNavigator as O, hasRegisteredNavigator as P, getRegisteredNavigatorNames as Q, initializeNavigatorRegistry as R, type StudySessionItem as S, type TeacherClassroomDBInterface as T, type UserDBInterface as U, type StrategyContribution as V, type WeightedCard as W, getCardOrigin as X, Navigators as Y, NavigatorRole as Z, NavigatorRoles as _, type UserDBReader as a, isFilter as a0, type LearnableWeight as a1, type OrchestrationContext as a2, computeDeviation as a3, computeSpread as a4, computeEffectiveWeight as a5, createOrchestrationContext as a6, type DocumentUpdater as a7, newInterval as a8, type CoursesDBInterface as b, type ClassroomDBInterface as c, type CourseInfo as d, type ContentNavigationStrategyData as e, ContentNavigator as f, type AssignedContent as g, type StudyContentSource as h, type StudentClassroomDBInterface as i, type ScheduledCard as j, type StudySessionFailedItem as k, type StudySessionFailedNewItem as l, type StudySessionFailedReviewItem as m, type StudySessionNewItem as n, type StudySessionReviewItem as o, isReview as p, type ContentSourceID as q, getStudySource as r, type CourseRegistrationDoc as s, type AssignedTag as t, type AssignedCourse as u, type AssignedCard as v, type UserDBWriter as w, type UserDBAuthenticator as x, type UserCourseSettings as y, type UserCourseSetting as z };
|