diff --git a/tools/server/public_simplechat/readme.md b/tools/server/public_simplechat/readme.md index 82c5bba121..cf0d7c9f97 100644 --- a/tools/server/public_simplechat/readme.md +++ b/tools/server/public_simplechat/readme.md @@ -885,10 +885,13 @@ Cleanup in general * ensures that the available list of tool calls match the config of the chat session involved. Needed as user could change tools related proxy server url. * next setup the main ui as needed. + * Hide user-input area and tool call validate/trigger area when switching into settings and ensure they + get unhidden when returning back, as needed. + * Save and restore ChatSession config entries, as needed, in localStorage. + * load previously saved config if any, when creating ChatSession + * when ever switching, including into a, ChatSession, Configs of all chat sessions are saved. * TODO - * Need to save and restore ChatSession config entries. * Need to allow any changes to proxyUrl to trigger a new tool manager setup wrt that chat session. - * Need to hide user-input area and tool call validate/trigger area when switching into settings #### ToDo diff --git a/tools/server/public_simplechat/simplechat.js b/tools/server/public_simplechat/simplechat.js index ce4a19dbcc..2bde434f5a 100644 --- a/tools/server/public_simplechat/simplechat.js +++ b/tools/server/public_simplechat/simplechat.js @@ -542,6 +542,7 @@ export class SimpleChat { this.latestResponse = new ChatMessageEx(); this.cfg = Config.clone(cfg); this.toolsMgr = toolsMgr + this.load_cfg() } clear() { @@ -571,6 +572,30 @@ export class SimpleChat { return `SimpleChat-${this.chatId}` } + /** + * Save the config to local storage + */ + save_cfg() { + let tag = `SimpleChat:SaveCfg:${this.chatId}`; + let ods = JSON.stringify(this.cfg) + localStorage.setItem(this.ods_key(), ods) + console.log(`DBUG:${tag}:saved`) + } + + /** + * Load the config from local storage + */ + load_cfg() { + let tag = `SimpleChat:LoadCfg:${this.chatId}`; + let odsStr = localStorage.getItem(this.ods_key()) + if (odsStr) { + this.cfg = Object.assign(this.cfg, JSON.parse(odsStr)) + console.log(`DBUG:${tag}:loaded`) + } else { + console.log(`DBUG:${tag}:nothing to load`) + } + } + /** * Save into indexedDB */ @@ -1926,6 +1951,15 @@ class MultiChatUI { return btn; } + /** + * Save configs wrt all the currently loaded sessions + */ + save_sessions_cfgs() { + for (const cid of Object.keys(this.simpleChats)) { + this.simpleChats[cid].save_cfg() + } + } + /** * Switch ui to the specified chatId and set curChatId to same. * @param {string} chatId @@ -1939,6 +1973,7 @@ class MultiChatUI { console.error(`ERRR:SimpleChat:MCUI:HandleSessionSwitch:${chatId} missing...`); return; } + this.save_sessions_cfgs() this.elDivUserIn.hidden = false this.elInSystem.value = chat.get_system_latest().ns.getContent(); this.curChatId = chatId;