From 7d6971a7372e1f4a010fe4c8678eb5eec059692d Mon Sep 17 00:00:00 2001 From: hanishkvc Date: Sun, 23 Nov 2025 15:35:39 +0530 Subject: [PATCH] SimpleChatTCRV:Config++: ValidatedToolCall UI updated Given that ValidatedToolCallTrigger UI setup has to also setup the auto trigger logic, which inturn is dependent on the autosecs value in the Config associated with the Chat session involved, so pass chatId to ShowMessage and inturn ValidatedToolCallTriggerUI setup logic Rename the function name to better match the semantic. --- tools/server/public_simplechat/readme.md | 28 +++++++++++++------- tools/server/public_simplechat/simplechat.js | 27 ++++++++++--------- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/tools/server/public_simplechat/readme.md b/tools/server/public_simplechat/readme.md index caee6014f8..82c5bba121 100644 --- a/tools/server/public_simplechat/readme.md +++ b/tools/server/public_simplechat/readme.md @@ -867,15 +867,28 @@ Cleanup in general end user can see the streamed response from that chat session as it is occuring. * Cleanup the tool call descriptions and verbose messages returned a bit. * Move towards Chat Session specific settings + * Needed so that one could + * setup a different ai model / engine as the external ai backend. + * interact with different independent ai models / engines / parallel instances in general * Move needed configs from Me into a seperate Config class. * also move ShowSettings, ShowInfo etal into Config class * SimpleChat maintains an instance of Config class instead of Me. - * Update starting flow to create the default set of chat sessions, setup ui etal after toolsMgr init - * TODO: Rather temporarily for now, to ensure tools name etal get populated. - * TODO: May need to have seperate partial tools manager per chat session, if we allow the proxyUrl - to be decided at a per chat session basis. - * TODO: Rather current flow expects any changed proxyUrl to reflect what ever was supported by - default proxyUrl + * ToolsManager and the different tool call modules have been updated to + * have seperate init and setup calls. + * init is called at the begining + * setup will be called when ever a chat session is being created + and or in future when ever any config of interest changes. + * pick needed config etal from the specified chatId's config and not any global config. + * Starting flow updated to chain the different logical blocks of code + * first allow tools manager to be initd + * next create the needed default set of sessions, while parallely calling tool manager setup as needed. + * 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. + * 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 @@ -894,9 +907,6 @@ the simpleproxy.py if and where needed. Save used config entries along with the auto saved chat sessions and inturn give option to reload the same when saved chat is loaded. -MAYBE make the settings in general chat session specific, rather than the current global config flow. -Rather for now having a global settings seems to make more sense, so dont change for now. - Have a seperate helper to show the user input area, based on set state. And have support for multiple images if the models support same. It should also take care of some aspects of the tool call response edit / submit, potentially. diff --git a/tools/server/public_simplechat/simplechat.js b/tools/server/public_simplechat/simplechat.js index 51f3642733..a79603e550 100644 --- a/tools/server/public_simplechat/simplechat.js +++ b/tools/server/public_simplechat/simplechat.js @@ -1238,21 +1238,23 @@ class MultiChatUI { } /** - * Reset/Setup Tool Call UI parts as needed + * Setup/Reset Validated Tool Call UI parts as needed * @param {ChatMessageEx} ar + * @param {string} chatId * @param {boolean} bAuto - allows caller to explicitly control whether auto triggering should be setup. */ - ui_reset_toolcall_as_needed(ar, bAuto = false) { + ui_toolcallvalidated_as_needed(ar, chatId = "", bAuto = false) { if (ar.ns.has_toolcalls()) { this.elDivTool.hidden = false this.elInToolName.value = ar.ns.getFuncName(0) this.elInToolName.dataset.tool_call_id = ar.ns.getFunc(0)?.id this.elInToolArgs.value = `${ar.ns.getFunc(0)?.function.arguments}` this.elBtnTool.disabled = false - if ((this.me.tools.autoSecs > 0) && (bAuto)) { + let chat = this.simpleChats[chatId] + if ((chat) && (chat.cfg.tools.autoSecs > 0) && (bAuto)) { this.timers.toolcallTriggerClick = setTimeout(()=>{ this.elBtnTool.click() - }, this.me.tools.autoSecs*this.TimePeriods.ToolCallAutoSecsTimeUnit) + }, chat.cfg.tools.autoSecs*this.TimePeriods.ToolCallAutoSecsTimeUnit) } } else { this.elDivTool.hidden = true @@ -1363,11 +1365,12 @@ class MultiChatUI { * * if it is the last message OR * * if it is the last but one message and there is a ToolTemp message next * @param {HTMLElement | undefined} elParent + * @param {string} chatId * @param {ChatMessageEx} msg * @param {number} iFromLast * @param {ChatMessageEx | undefined} nextMsg */ - show_message(elParent, msg, iFromLast, nextMsg) { + show_message(elParent, chatId, msg, iFromLast, nextMsg) { // Handle ToolTemp if (iFromLast == 0) { if (msg.ns.role === Roles.ToolTemp) { @@ -1457,7 +1460,7 @@ class MultiChatUI { } } if (bTC) { - this.ui_reset_toolcall_as_needed(msg, bAuto); + this.ui_toolcallvalidated_as_needed(msg, chatId, bAuto); } } // Handle tool call message show @@ -1495,7 +1498,7 @@ class MultiChatUI { this.ui_userinput_reset() this.elDivStreams[chatId]?.clear() } - this.ui_reset_toolcall_as_needed(new ChatMessageEx()); + this.ui_toolcallvalidated_as_needed(new ChatMessageEx()); this.elLastChatMessage = null let chatToShow = chat.recent_chat(chat.cfg.chatProps.iRecentUserMsgCnt); for(const [i, x] of chatToShow.entries()) { @@ -1504,7 +1507,7 @@ class MultiChatUI { if (iFromLast == 1) { nextMsg = chatToShow[i+1] } - this.show_message(this.elDivChat, x, iFromLast, nextMsg) + this.show_message(this.elDivChat, chat.chatId, x, iFromLast, nextMsg) } this.elDivChat.appendChild(this.elDivStreams[chatId].div) this.elDivChat.appendChild(this.elDivStreams[AI_TC_SESSIONNAME].div) @@ -1557,13 +1560,13 @@ class MultiChatUI { return this.chat_show(chatId, true, true) } this.ui_userinput_reset(false) - this.ui_reset_toolcall_as_needed(new ChatMessageEx()); + this.ui_toolcallvalidated_as_needed(new ChatMessageEx()); for(let i=lastN; i > 0; i-=1) { let msg = chat.xchat[chat.xchat.length-i] let nextMsg = chat.xchat[chat.xchat.length-(i-1)] if (msg) { this.chatmsg_ui_remove(msg.uniqId) - this.show_message(this.elDivChat, msg, (i-1), nextMsg) + this.show_message(this.elDivChat, chat.chatId, msg, (i-1), nextMsg) } } if (!this.elDivChat.contains(this.elDivStreams[chatId].div)) { @@ -1625,7 +1628,7 @@ class MultiChatUI { this.handle_session_switch(this.curChatId); } - this.ui_reset_toolcall_as_needed(new ChatMessageEx()); + this.ui_toolcallvalidated_as_needed(new ChatMessageEx()); this.elBtnSettings.addEventListener("click", (ev)=>{ this.elDivChat.replaceChildren(); @@ -1776,7 +1779,7 @@ class MultiChatUI { chat.clear(); } - this.ui_reset_toolcall_as_needed(new ChatMessageEx()); + this.ui_toolcallvalidated_as_needed(new ChatMessageEx()); chat.add_system_anytime(this.elInSystem.value, chatId);