11
22import { reactive , markRaw } from 'vue'
3- import { EventBus , humanize , combinePaths } from "@servicestack/client"
3+ import { EventBus , humanize , combinePaths , pick } from "@servicestack/client"
44import { storageObject , isHtml , sanitizeHtml } from './utils.mjs'
55
66export class ExtensionScope {
@@ -141,6 +141,7 @@ export class AppContext {
141141 cacheBreaker : new Date ( ) . getTime ( ) ,
142142 theme,
143143 styles : theme . styles ,
144+ profile : localStorage . getItem ( 'llms.profile' ) || 'default' ,
144145 } )
145146 this . events = new EventBus ( )
146147 this . modalComponents = { }
@@ -158,7 +159,18 @@ export class AppContext {
158159 this . left = { }
159160 this . leftTop = { }
160161 this . layout = reactive ( storageObject ( `llms.layout` ) )
161- this . prefs = reactive ( storageObject ( ai . prefsKey ) )
162+
163+ const oldPrefsKey = ai . prefsKey
164+ const prefsKey = ai . prefsKey + '.' + this . state . profile
165+ if ( localStorage . getItem ( oldPrefsKey ) ) {
166+ if ( ! localStorage . getItem ( prefsKey ) ) {
167+ const oldPrefs = storageObject ( oldPrefsKey )
168+ storageObject ( prefsKey , oldPrefs )
169+ }
170+ localStorage . removeItem ( oldPrefsKey )
171+ }
172+ this . prefs = reactive ( storageObject ( prefsKey ) )
173+
162174 this . _onRouterBeforeEach = [ ]
163175 this . _onClass = [ ]
164176
@@ -204,9 +216,7 @@ export class AppContext {
204216 let html = document . documentElement
205217 html . classList . toggle ( 'dark' , darkMode )
206218 html . style . setProperty ( 'color-scheme' , darkMode ? 'dark' : null )
207- if ( localStorage . getItem ( 'color-scheme' ) === null ) {
208- localStorage . setItem ( 'color-scheme' , darkMode ? 'dark' : 'light' )
209- }
219+ localStorage . setItem ( 'color-scheme' , darkMode ? 'dark' : 'light' )
210220 }
211221 getUserAvatar ( ) {
212222 const theme = this . getPrefs ( ) . theme || this . getColorScheme ( )
@@ -219,11 +229,30 @@ export class AppContext {
219229 incCacheBreaker ( ) {
220230 this . state . cacheBreaker ++
221231 }
232+ getPrefsKey ( ) {
233+ return this . ai . prefsKey + '.' + this . state . profile
234+ }
235+ changeProfile ( profile ) {
236+ console . log ( 'changeProfile' , JSON . stringify ( profile , null , 2 ) )
237+ this . selectTheme ( profile ?. theme )
238+
239+ const profileId = profile ?. id || 'default'
240+ if ( this . state . profile == profileId ) return
241+ this . state . profile = profileId
242+ if ( profile ) {
243+ const profilePrefs = pick ( profile , [ 'model' , 'tools' , 'skills' ] )
244+ this . setPrefs ( profilePrefs )
245+ if ( profile . model ) {
246+ this . state . selectedModel = model
247+ }
248+ }
249+ this . prefs = reactive ( storageObject ( this . getPrefsKey ( ) ) )
250+ }
222251 getPrefs ( ) {
223252 return this . prefs
224253 }
225254 setPrefs ( o ) {
226- storageObject ( this . ai . prefsKey , Object . assign ( this . prefs , o ) )
255+ storageObject ( this . getPrefsKey ( ) , Object . assign ( this . prefs , o ) )
227256 }
228257 _validateComponents ( componentMap ) {
229258 Object . entries ( componentMap ) . forEach ( ( [ id , def ] ) => {
@@ -546,6 +575,7 @@ export class AppContext {
546575 }
547576
548577 changeTheme ( theme ) {
578+ console . log ( 'changeTheme' , theme )
549579
550580 const fullTheme = this . createTheme ( theme )
551581 Object . assign ( this . state . theme , fullTheme )
0 commit comments