diff --git a/public/index.html b/public/index.html
index f34ee5537..c7a3cc968 100644
--- a/public/index.html
+++ b/public/index.html
@@ -262,6 +262,10 @@
diff --git a/public/script.js b/public/script.js
index a1dbf9112..cd2f4986a 100644
--- a/public/script.js
+++ b/public/script.js
@@ -67,7 +67,7 @@ import {
nai_settings,
} from "./scripts/nai-settings.js";
-import { debounce, delay } from "./scripts/utils.js";
+import { debounce, delay, stringFormat } from "./scripts/utils.js";
//exporting functions and vars for mods
export {
@@ -232,7 +232,7 @@ const system_messages = {
is_user: false,
is_system: true,
is_name: true,
- mes: `Bookmark created! Click here to open the bookmark chat:
{0}`,
+ mes: `Bookmark created! Click here to open the bookmark chat:
{1}`,
},
bookmark_back: {
name: systemUserName,
@@ -240,7 +240,7 @@ const system_messages = {
is_user: false,
is_system: true,
is_name: true,
- mes: `Click here to return to the original chat:
{0}`,
+ mes: `Click here to return to the previous chat:
Return`,
},
};
@@ -706,6 +706,10 @@ function deleteLastMessage() {
}
function messageFormating(mes, ch_name, isSystem, forceAvatar) {
+ if (!mes) {
+ mes = '';
+ }
+
if (this_chid != undefined && !isSystem)
mes = mes.replaceAll("<", "<").replaceAll(">", ">"); //for welcome message
if (this_chid === undefined) {
@@ -868,6 +872,12 @@ function sendSystemMessage(type, text) {
newMessage.mes = text;
}
+ if (!newMessage.extras) {
+ newMessage.extras = {};
+ }
+
+ newMessage.extras.type = type;
+
chat.push(newMessage);
addOneMessage(newMessage);
is_send_press = false;
@@ -4061,17 +4071,28 @@ $(document).ready(function () {
selectRightMenuWithAnimation('rm_extensions_block');
});
- $(document).on("click", ".select_chat_block, .bookmark_link", function () {
+ $(document).on("click", ".select_chat_block, .bookmark_link", async function () {
+ let originalChat = characters[this_chid]["chat"];
let file_name = $(this).attr("file_name").replace(".jsonl", "");
//console.log(characters[this_chid]['chat']);
characters[this_chid]["chat"] = file_name;
clearChat();
chat.length = 0;
- getChat();
+ await getChat();
$("#selected_chat_pole").val(file_name);
$("#create_button").click();
$("#shadow_select_chat_popup").css("display", "none");
$("#load_select_chat_div").css("display", "block");
+
+ // create "return back" message
+ /*if ($(this).hasClass('bookmark_link')) {
+ const existingMessageIndex = chat.findIndex(x => x.extras?.type === system_message_types.BOOKMARK_BACK);
+
+ if (existingMessageIndex === -1) {
+ const messageText = stringFormat(system_messages[system_message_types.BOOKMARK_BACK].mes, originalChat);
+ sendSystemMessage(system_message_types.BOOKMARK_BACK, messageText);
+ }
+ }*/
});
$('.drawer-toggle').click(function () {
diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js
index 9ea56c585..55017cc33 100644
--- a/public/scripts/bookmarks.js
+++ b/public/scripts/bookmarks.js
@@ -30,17 +30,24 @@ async function getExistingChatNames() {
}
}
-async function getBookmarkName() {
+async function getBookmarkName(currentChat) {
+ const nameToken = 'Bookmark #';
+ if (currentChat.includes(nameToken)) {
+ currentChat = currentChat.substring(0, currentChat.lastIndexOf(nameToken)).trim();
+ }
+
const chatNames = await getExistingChatNames();
let newChat = Date.now();
+ let friendlyName = '';
for (let i = 0; i < 1000; i++) {
- newChat = `Bookmark - ${i}`;
+ friendlyName = `${nameToken}${i}`;
+ newChat = `${currentChat} ${friendlyName}`;
if (!chatNames.includes(newChat)) {
break;
}
}
- return newChat;
+ return { newChat, friendlyName };
}
$(document).ready(function () {
@@ -50,10 +57,10 @@ $(document).ready(function () {
throw new Error('not yet implemented');
}
- let newChat = await getBookmarkName();
+ let { newChat, friendlyName } = await getBookmarkName(characters[this_chid].chat);
saveChat(newChat);
- let mainMessage = stringFormat(system_messages[system_message_types.BOOKMARK_CREATED].mes, newChat);
+ let mainMessage = stringFormat(system_messages[system_message_types.BOOKMARK_CREATED].mes, newChat, friendlyName);
sendSystemMessage(system_message_types.BOOKMARK_CREATED, mainMessage);
saveChat();
});