From 72f62eed0f13078c289c9a3d89489dd70c529244 Mon Sep 17 00:00:00 2001 From: hanishkvc Date: Sun, 9 Nov 2025 23:48:50 +0530 Subject: [PATCH] SimpleChatTC:Vision: take care of image_url wrt newFrom & load --- tools/server/public_simplechat/simplechat.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tools/server/public_simplechat/simplechat.js b/tools/server/public_simplechat/simplechat.js index 5a4eeb7474..d313bf33ff 100644 --- a/tools/server/public_simplechat/simplechat.js +++ b/tools/server/public_simplechat/simplechat.js @@ -54,6 +54,10 @@ class ApiEP { } +/** + * @typedef {Array>>} NSMixedContent + */ + /** * @typedef {{id: string, type: string, function: {name: string, arguments: string}}} NSToolCall */ @@ -62,7 +66,7 @@ class NSChatMessage { /** * Represents a Message as seen in the http server Chat handshake * @param {string} role - * @param {string|undefined} content + * @param {string|undefined} content - used to store text content directly * @param {string|undefined} reasoning_content * @param {Array|undefined} tool_calls * @param {string|undefined} tool_call_id - toolcall response - the tool / function call id @@ -89,6 +93,9 @@ class NSChatMessage { return new NSChatMessage(role, content, undefined, undefined, tool_call_id, name) } + /** + * Return the direct text content, or else empty string. + */ getContent() { if (this.content) { return this.content @@ -262,7 +269,7 @@ class ChatMessageEx { * @param {ChatMessageEx} old */ static newFrom(old) { - return new ChatMessageEx(new NSChatMessage(old.ns.role, old.ns.content, old.ns.reasoning_content, old.ns.tool_calls, old.ns.tool_call_id, old.ns.name), old.trimmedContent) + return new ChatMessageEx(new NSChatMessage(old.ns.role, old.ns.content, old.ns.reasoning_content, old.ns.tool_calls, old.ns.tool_call_id, old.ns.name, old.ns.image_url), old.trimmedContent) } clear() { @@ -458,12 +465,18 @@ class SimpleChat { return `SimpleChat-${this.chatId}` } + /** + * Save into localStorage + */ save() { /** @type {SimpleChatODS} */ let ods = {iLastSys: this.iLastSys, xchat: this.xchat}; localStorage.setItem(this.ods_key(), JSON.stringify(ods)); } + /** + * Load from localStorage + */ load() { let sods = localStorage.getItem(this.ods_key()); if (sods == null) { @@ -474,7 +487,7 @@ class SimpleChat { this.iLastSys = ods.iLastSys; this.xchat = []; for (const cur of ods.xchat) { - this.xchat.push(new ChatMessageEx(new NSChatMessage(cur.ns.role, cur.ns.content, cur.ns.reasoning_content, cur.ns.tool_calls, cur.ns.tool_call_id, cur.ns.name), cur.trimmedContent)) + this.xchat.push(new ChatMessageEx(new NSChatMessage(cur.ns.role, cur.ns.content, cur.ns.reasoning_content, cur.ns.tool_calls, cur.ns.tool_call_id, cur.ns.name, cur.ns.image_url), cur.trimmedContent)) } }