SimpleChatTCRV:ChatMessage: UniqId, Delete logic, edit popover ui

This commit is contained in:
hanishkvc 2025-11-13 17:34:26 +05:30
parent dc71a9be4c
commit 1d2ef9dddb
4 changed files with 47 additions and 2 deletions

View File

@ -44,6 +44,11 @@
<p> You need to have javascript enabled.</p>
</div>
<div id="popover-edit" popover="auto">
<button id="popover-edit-del"> &#x274C; </button>
<button id="popover-edit-copy"> &#x1F4CB; </button>
</div>
<div id="tool-div">
<hr>
<div class="sameline">

View File

@ -743,13 +743,16 @@ sliding window based drop off or even before they kick in, this can help in many
* add open, transact, put and get. Use for chat session save and load
* getKeys used to show Restore/Load button wrt chat sessions.
* ChatMessage
* assign a globally unique (ie across sessions) id to each chat message instance.
* add support for deleting chat message based on its uniquie id in SimpleChat.
* add a popover div block in html, which contains the edit menu wrt chat messages
#### ToDo
Is the tool call promise land trap deep enough, need to think through and explore around this once later.
Handle multimodal handshaking with ai models [WIP].
Add fetch_rss and may be different document formats processing related tool calling, in turn through
the simpleproxy.py if and where needed.

View File

@ -92,6 +92,15 @@
max-width: 20vmin;
max-height: 20vmin;
}
#popover-edit {
position:absolute;
background-color: transparent;
padding: 0;
border-width: 0;
}
#popover-edit button {
padding: 0;
}
.gridx2 {

View File

@ -257,6 +257,16 @@ class NSChatMessage {
class ChatMessageEx {
static uniqCounter = 0
/**
* Get a globally (ie across chat sessions) unique id wrt chat messages.
*/
static getUniqId() {
this.uniqCounter += 1
return this.uniqCounter
}
/**
* Represent a Message in the Chat.
* @param {NSChatMessage|undefined} nsChatMsg - will create a default NSChatMessage instance, if undefined
@ -268,6 +278,7 @@ class ChatMessageEx {
} else {
this.ns = new NSChatMessage()
}
this.uniqId = ChatMessageEx.getUniqId()
this.trimmedContent = trimmedContent;
}
@ -651,6 +662,22 @@ class SimpleChat {
return true;
}
/**
* Delete a chat message in place using chat message uniqId.
* @param {number} uniqId
*/
delete(uniqId) {
let index = this.xchat.findIndex((msg)=>{
if (msg.uniqId == uniqId) {
return true
}
return false
})
if (index >= 0) {
this.xchat.splice(index, 1)
}
}
/**
* Check if the last message in the chat history is a ToolTemp role based one.
* If so, then
@ -1000,6 +1027,7 @@ class MultiChatUI {
this.elBtnTool = /** @type{HTMLButtonElement} */(document.getElementById("tool-btn"));
this.elInToolName = /** @type{HTMLInputElement} */(document.getElementById("toolname-in"));
this.elInToolArgs = /** @type{HTMLInputElement} */(document.getElementById("toolargs-in"));
this.elPopoverEdit = /** @type{HTMLElement} */(document.getElementById("popover-edit"));
// Save any placeholder set by default like through html, to restore where needed
this.elInUser.dataset.placeholder = this.elInUser.placeholder