From d07e16af7448fbb67f432bcc2dba73914e8688a7 Mon Sep 17 00:00:00 2001 From: hanishkvc Date: Sun, 23 Nov 2025 12:21:06 +0530 Subject: [PATCH] SimpleChatTCRV:Config+:WIP:CleanUp: Have sensible chatIds Given that now currently settings relates to only those related to the current chat session, so indicate the name/chatId of the current chat session in the Settings heading. * this inturn makes the id dynamic, so change the css rule wrt settings block from using id to classname, and to help with same also set a class name for the top level settings block. As part of same, as well as to help and ensure sanity in general add a helper to clean up a string to be a form usable as a chatId --- tools/server/public_simplechat/simplechat.css | 4 ++-- tools/server/public_simplechat/simplechat.js | 21 ++++++++++++++++--- tools/server/public_simplechat/ui.mjs | 1 + 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/tools/server/public_simplechat/simplechat.css b/tools/server/public_simplechat/simplechat.css index a949d644ce..4789666a3e 100644 --- a/tools/server/public_simplechat/simplechat.css +++ b/tools/server/public_simplechat/simplechat.css @@ -246,11 +246,11 @@ button { [class^=SectionObjPropsInfoL] { margin-left: 2vmin; } -#ObjPropsEdit-Settings * { +.ObjPropsEdit * { border-radius: 0.2rem; padding-inline: 0.5rem; } -#ObjPropsEdit-Settings button, #ObjPropsEdit-Settings select, #ObjPropsEdit-Settings input { +.ObjPropsEdit button, .ObjPropsEdit select, .ObjPropsEdit input { border-radius: 0.2rem; padding-inline: 0.5rem; min-height: 2vmin; diff --git a/tools/server/public_simplechat/simplechat.js b/tools/server/public_simplechat/simplechat.js index 7c5cc9e7b4..c2ac025304 100644 --- a/tools/server/public_simplechat/simplechat.js +++ b/tools/server/public_simplechat/simplechat.js @@ -546,6 +546,19 @@ export class SimpleChat { this.latestResponse = new ChatMessageEx(); } + /** + * Given a string, gives the equivalent simplified string which could be used as chatId. + * * Converts the very 1st char into upper case. + * * Removes everything other than alphabets and numbers. + * Also converts 1st character following such removed substrings into upper case. + * @param {string} chatId + */ + static ChatIdClean(chatId) { + let sTempId1 = chatId.trim() + let sTempId2 = sTempId1.replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.toUpperCase()); + return `${sTempId2[0].toUpperCase()}${sTempId2.slice(1)}` + } + ods_key() { return `SimpleChat-${this.chatId}` } @@ -1609,7 +1622,7 @@ class MultiChatUI { this.elBtnSettings.addEventListener("click", (ev)=>{ this.elDivChat.replaceChildren(); let chat = this.simpleChats[this.curChatId] - chat.cfg.show_settings(this.elDivChat); + chat.cfg.show_settings(this.elDivChat, chat.chatId); this.me.houseKeeping.clear = true; }); this.elBtnClearChat.addEventListener("click", (ev)=>{ @@ -1860,6 +1873,7 @@ class MultiChatUI { console.error("ERRR:SimpleChat:MCUI:NewChat:Skipping based on user request..."); return; } + chatIdGot = SimpleChat.ChatIdClean(chatIdGot) this.new_chat_session(chatIdGot, true); this.create_session_btn(elDiv, chatIdGot); ui.el_children_config_class(elDiv, chatIdGot, "session-selected", ""); @@ -2042,9 +2056,10 @@ export class Config { /** * Show settings ui for configurable parameters, in the passed Div element. * @param {HTMLDivElement} elDiv + * @param {string} tag */ - show_settings(elDiv) { - ui.ui_show_obj_props_edit(elDiv, "", this, ["baseURL", "headers", "tools", "apiRequestOptions", "chatProps"], "Settings", (prop, elProp)=>{ + show_settings(elDiv, tag) { + ui.ui_show_obj_props_edit(elDiv, "", this, ["baseURL", "headers", "tools", "apiRequestOptions", "chatProps"], `Settings-${tag}`, (prop, elProp)=>{ if (prop == "headers:Authorization") { // @ts-ignore elProp.placeholder = "Bearer OPENAI_API_KEY"; diff --git a/tools/server/public_simplechat/ui.mjs b/tools/server/public_simplechat/ui.mjs index 0bfffb4a47..fac63e489e 100644 --- a/tools/server/public_simplechat/ui.mjs +++ b/tools/server/public_simplechat/ui.mjs @@ -314,6 +314,7 @@ export function ui_show_obj_props_edit(elParent, propsTreeRoot, oObj, lProps, sL let elFS = document.createElement("fieldset"); if (propsTreeRoot == "") { elFS.id = `ObjPropsEdit-${sLegend.replaceAll(' ', '')}` + elFS.classList.add('ObjPropsEdit') } let elLegend = document.createElement("legend"); elLegend.innerText = sLegend;