SimpleChatTCRV:MCUI:ChatMsgAddShow, Use4 toolresp nonhappy paths
Make the toolresp non happy path use a direct insert chat msg wrt ui, rather than recreating the full chat session ui fresh.
This commit is contained in:
parent
926b5cd8f3
commit
1b4e1aa682
|
|
@ -762,10 +762,15 @@ sliding window based drop off or even before they kick in, this can help in many
|
||||||
|
|
||||||
* MultiChatUI
|
* MultiChatUI
|
||||||
* chat_show takes care of showing or clearing tool call edit / trigger as well as tool response
|
* chat_show takes care of showing or clearing tool call edit / trigger as well as tool response
|
||||||
edit / submit. Also show the currently active tool call and its response before it is submit
|
edit / submit. Also show the currently active tool call and its response before it is submitted
|
||||||
was previously only shown in the edit / trigger and edit / submit ui elements, now instead it
|
was previously only shown in the edit / trigger and edit / submit ui elements, now instead it
|
||||||
also shows as part of the chat session message blocks, so that user can delete or copy these
|
also shows as part of the chat session message blocks, so that user can delete or copy these
|
||||||
if needed using the same mechanism as other messages in the chat session.
|
if needed using the same mechanism as other messages in the chat session.
|
||||||
|
* use a delete msg helper, which takes care of deleting the msg from chat session as well as
|
||||||
|
efficiently update ui to any extent by removing the corresponding element directly from existing
|
||||||
|
chat session ui without recreating the full chat session ui.
|
||||||
|
* a helper to add a message into specified chat session, as well as show/update in the chat session
|
||||||
|
ui by appending the chat message, instead of recreating the full chat session ui.
|
||||||
|
|
||||||
|
|
||||||
#### ToDo
|
#### ToDo
|
||||||
|
|
|
||||||
|
|
@ -1347,14 +1347,36 @@ class MultiChatUI {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a chatmsg to specified chat session,
|
||||||
|
* and update the chat session ui.
|
||||||
|
*
|
||||||
|
* @param {string} chatId
|
||||||
|
* @param {ChatMessageEx} msg
|
||||||
|
*/
|
||||||
|
chatmsg_add_show(chatId, msg) {
|
||||||
|
let chat = this.simpleChats[chatId];
|
||||||
|
if (!chat) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let lastMsg = chat.xchat[chat.xchat.length-1]
|
||||||
|
chat.add(msg)
|
||||||
|
if (lastMsg) {
|
||||||
|
this.ui_chatmessage_delete(chatId, lastMsg.uniqId, false)
|
||||||
|
this.show_message(this.elDivChat, lastMsg, 1, msg)
|
||||||
|
}
|
||||||
|
this.show_message(this.elDivChat, msg, 0, undefined)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the specified ChatMessage block in ui, without needing to show full chat session again.
|
* Remove the specified ChatMessage block in ui, without needing to show full chat session again.
|
||||||
* @param {string} curChatId
|
* @param {string} curChatId
|
||||||
* @param {number} uniqIdChatMsg
|
* @param {number} uniqIdChatMsg
|
||||||
|
* @param {boolean} bUpdateUI
|
||||||
*/
|
*/
|
||||||
ui_chatmessage_delete(curChatId, uniqIdChatMsg) {
|
ui_chatmessage_delete(curChatId, uniqIdChatMsg, bUpdateUI=true) {
|
||||||
let index = this.simpleChats[curChatId].delete(uniqIdChatMsg)
|
let index = this.simpleChats[curChatId].delete(uniqIdChatMsg)
|
||||||
if ((index >= 0) && (curChatId == this.curChatId)) {
|
if ((index >= 0) && (curChatId == this.curChatId) && bUpdateUI) {
|
||||||
let el = document.querySelector(`[CMUniqId="${uniqIdChatMsg}"]`)
|
let el = document.querySelector(`[CMUniqId="${uniqIdChatMsg}"]`)
|
||||||
el?.remove()
|
el?.remove()
|
||||||
if (index >= (this.simpleChats[curChatId].xchat.length-1)) {
|
if (index >= (this.simpleChats[curChatId].xchat.length-1)) {
|
||||||
|
|
@ -1587,14 +1609,12 @@ class MultiChatUI {
|
||||||
}
|
}
|
||||||
let toolResult = await chat.handle_toolcall(toolCallId, toolname, this.elInToolArgs.value)
|
let toolResult = await chat.handle_toolcall(toolCallId, toolname, this.elInToolArgs.value)
|
||||||
if (toolResult !== undefined) {
|
if (toolResult !== undefined) {
|
||||||
chat.add(new ChatMessageEx(NSChatMessage.new_tool_response(Roles.ToolTemp, toolCallId, toolname, toolResult)))
|
this.chatmsg_add_show(chat.chatId, new ChatMessageEx(NSChatMessage.new_tool_response(Roles.ToolTemp, toolCallId, toolname, toolResult)))
|
||||||
this.chat_show(chat.chatId)
|
|
||||||
this.ui_reset_userinput(false)
|
this.ui_reset_userinput(false)
|
||||||
} else {
|
} else {
|
||||||
this.timers.toolcallResponseTimeout = setTimeout(() => {
|
this.timers.toolcallResponseTimeout = setTimeout(() => {
|
||||||
this.me.toolsMgr.toolcallpending_found_cleared(chat.chatId, toolCallId, 'MCUI:HandleToolRun:TimeOut')
|
this.me.toolsMgr.toolcallpending_found_cleared(chat.chatId, toolCallId, 'MCUI:HandleToolRun:TimeOut')
|
||||||
chat.add(new ChatMessageEx(NSChatMessage.new_tool_response(Roles.ToolTemp, toolCallId, toolname, `Tool/Function call ${toolname} taking too much time, aborting...`)))
|
this.chatmsg_add_show(chat.chatId, new ChatMessageEx(NSChatMessage.new_tool_response(Roles.ToolTemp, toolCallId, toolname, `Tool/Function call ${toolname} taking too much time, aborting...`)))
|
||||||
this.chat_show(chat.chatId)
|
|
||||||
this.ui_reset_userinput(false)
|
this.ui_reset_userinput(false)
|
||||||
}, this.me.tools.toolCallResponseTimeoutMS)
|
}, this.me.tools.toolCallResponseTimeoutMS)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue