SimpleChatTC:ChatMessageEx:While at it also ns_delete

these common helpers avoid needing ignore tagging to ts-check, in
places where valid constructs have been used which go beyond strict
structured js handling that is tried to be achieved using it, but
are still valid and legal.
This commit is contained in:
hanishkvc 2025-10-15 03:35:55 +05:30
parent cc65a2f7a3
commit 152deb5d5a
1 changed files with 10 additions and 2 deletions

View File

@ -115,6 +115,15 @@ class ChatMessageEx {
this.ns[key] = value this.ns[key] = value
} }
/**
* Remove specified key and its value from ns object
* @param {string | number} key
*/
ns_delete(key) {
// @ts-ignore
delete(this.ns[key])
}
/** /**
* Update based on the drip by drip data got from network in streaming mode. * Update based on the drip by drip data got from network in streaming mode.
* Tries to support both Chat and Completion endpoints * Tries to support both Chat and Completion endpoints
@ -329,8 +338,7 @@ class SimpleChat {
for (const msg of xchat) { for (const msg of xchat) {
let tmsg = ChatMessageEx.newFrom(msg); let tmsg = ChatMessageEx.newFrom(msg);
if (!tmsg.has_toolcall()) { if (!tmsg.has_toolcall()) {
// @ts-ignore tmsg.ns_delete("tool_calls")
delete(tmsg.ns.tool_calls)
} }
if (tmsg.ns.role == Roles.Tool) { if (tmsg.ns.role == Roles.Tool) {
let res = ChatMessageEx.extractToolCallResultAllInOne(tmsg.ns.content) let res = ChatMessageEx.extractToolCallResultAllInOne(tmsg.ns.content)