1+ // Configuration flags for enabling/disabling features
12export interface FeatureFlags {
23 dragDropUpload : boolean ;
34 clientSideRAG : boolean ;
@@ -6,6 +7,7 @@ export interface FeatureFlags {
67 ragContextDisplay : boolean ;
78}
89
10+ // Default feature flag values
911export const DEFAULT_FEATURES : FeatureFlags = {
1012 dragDropUpload : true ,
1113 clientSideRAG : true ,
@@ -14,15 +16,18 @@ export const DEFAULT_FEATURES: FeatureFlags = {
1416 ragContextDisplay : true
1517} ;
1618
19+ // LocalStorage key for feature flags
1720export const FEATURE_FLAG_STORAGE_KEY = 'webllm_feature_flags' ;
1821
22+ // Manages feature flags with localStorage persistence
1923export class FeatureManager {
2024 private flags : FeatureFlags ;
2125
2226 constructor ( ) {
2327 this . flags = this . loadFlags ( ) ;
2428 }
2529
30+ // Loads feature flags from localStorage
2631 private loadFlags ( ) : FeatureFlags {
2732 try {
2833 const stored = localStorage . getItem ( FEATURE_FLAG_STORAGE_KEY ) ;
@@ -35,6 +40,7 @@ export class FeatureManager {
3540 return { ...DEFAULT_FEATURES } ;
3641 }
3742
43+ // Persists feature flags to localStorage
3844 private saveFlags ( ) : void {
3945 try {
4046 localStorage . setItem ( FEATURE_FLAG_STORAGE_KEY , JSON . stringify ( this . flags ) ) ;
@@ -43,60 +49,72 @@ export class FeatureManager {
4349 }
4450 }
4551
52+ // Checks if a feature is enabled
4653 isEnabled ( feature : keyof FeatureFlags ) : boolean {
4754 return this . flags [ feature ] ;
4855 }
4956
57+ // Enables a specific feature
5058 enable ( feature : keyof FeatureFlags ) : void {
5159 this . flags [ feature ] = true ;
5260 this . saveFlags ( ) ;
5361 }
5462
63+ // Disables a specific feature
5564 disable ( feature : keyof FeatureFlags ) : void {
5665 this . flags [ feature ] = false ;
5766 this . saveFlags ( ) ;
5867 }
5968
69+ // Toggles a feature and returns new state
6070 toggle ( feature : keyof FeatureFlags ) : boolean {
6171 this . flags [ feature ] = ! this . flags [ feature ] ;
6272 this . saveFlags ( ) ;
6373 return this . flags [ feature ] ;
6474 }
6575
76+ // Returns all current feature flags
6677 getAll ( ) : FeatureFlags {
6778 return { ...this . flags } ;
6879 }
6980
81+ // Updates multiple feature flags at once
7082 setAll ( flags : Partial < FeatureFlags > ) : void {
7183 this . flags = { ...this . flags , ...flags } ;
7284 this . saveFlags ( ) ;
7385 }
7486}
7587
88+ // Singleton instance of feature manager
7689export const featureManager = new FeatureManager ( ) ;
7790
7891// RAG Settings
92+ // Configuration settings for RAG functionality
7993export interface RAGSettings {
8094 chunkSize : number ;
8195 overlapSize : number ;
8296 searchAccuracy : number ;
8397}
8498
99+ // Default RAG configuration values
85100export const DEFAULT_RAG_SETTINGS : RAGSettings = {
86101 chunkSize : 300 ,
87102 overlapSize : 20 , // Reduced from 50 to minimize repetition
88103 searchAccuracy : 50 // 0-100 scale, 50 is balanced
89104} ;
90105
106+ // LocalStorage key for RAG settings
91107export const RAG_SETTINGS_STORAGE_KEY = 'webllm_rag_settings' ;
92108
109+ // Manages RAG settings with localStorage persistence
93110export class RAGSettingsManager {
94111 private settings : RAGSettings ;
95112
96113 constructor ( ) {
97114 this . settings = this . loadSettings ( ) ;
98115 }
99116
117+ // Loads RAG settings from localStorage
100118 private loadSettings ( ) : RAGSettings {
101119 try {
102120 const stored = localStorage . getItem ( RAG_SETTINGS_STORAGE_KEY ) ;
@@ -109,6 +127,7 @@ export class RAGSettingsManager {
109127 return { ...DEFAULT_RAG_SETTINGS } ;
110128 }
111129
130+ // Persists RAG settings to localStorage
112131 private saveSettings ( ) : void {
113132 try {
114133 localStorage . setItem ( RAG_SETTINGS_STORAGE_KEY , JSON . stringify ( this . settings ) ) ;
@@ -117,36 +136,44 @@ export class RAGSettingsManager {
117136 }
118137 }
119138
139+ // Gets current chunk size setting
120140 getChunkSize ( ) : number {
121141 return this . settings . chunkSize ;
122142 }
123143
144+ // Sets chunk size with bounds validation
124145 setChunkSize ( size : number ) : void {
125146 this . settings . chunkSize = Math . max ( 50 , Math . min ( 1000 , size ) ) ;
126147 this . saveSettings ( ) ;
127148 }
128149
150+ // Gets current overlap size setting
129151 getOverlapSize ( ) : number {
130152 return this . settings . overlapSize ;
131153 }
132154
155+ // Sets overlap size with bounds validation
133156 setOverlapSize ( size : number ) : void {
134157 this . settings . overlapSize = Math . max ( 0 , Math . min ( 200 , size ) ) ;
135158 this . saveSettings ( ) ;
136159 }
137160
161+ // Returns all current RAG settings
138162 getAll ( ) : RAGSettings {
139163 return { ...this . settings } ;
140164 }
141165
166+ // Gets current search accuracy setting
142167 getSearchAccuracy ( ) : number {
143168 return this . settings . searchAccuracy ;
144169 }
145170
171+ // Sets search accuracy with bounds validation
146172 setSearchAccuracy ( accuracy : number ) : void {
147173 this . settings . searchAccuracy = Math . max ( 0 , Math . min ( 100 , accuracy ) ) ;
148174 this . saveSettings ( ) ;
149175 }
150176}
151177
178+ // Singleton instance of RAG settings manager
152179export const ragSettingsManager = new RAGSettingsManager ( ) ;
0 commit comments