diff --git a/public/index.html b/public/index.html
index 06878afbd..243634606 100644
--- a/public/index.html
+++ b/public/index.html
@@ -3307,6 +3307,7 @@
+
diff --git a/public/script.js b/public/script.js
index f22757020..8421296be 100644
--- a/public/script.js
+++ b/public/script.js
@@ -101,7 +101,10 @@ import {
nai_settings,
} from "./scripts/nai-settings.js";
-import { showBookmarksButtons } from "./scripts/bookmarks.js";
+import {
+ createNewBookmark,
+ showBookmarksButtons
+} from "./scripts/bookmarks.js";
import {
horde_settings,
@@ -3816,7 +3819,7 @@ async function renamePastChats(newAvatar, newValue) {
}
}
-async function saveChat(chat_name, withMetadata) {
+async function saveChat(chat_name, withMetadata, mesId) {
const metadata = { ...chat_metadata, ...(withMetadata || {}) };
let file_name = chat_name ?? characters[this_chid].chat;
characters[this_chid]['date_last_chat'] = Date.now();
@@ -3837,6 +3840,11 @@ async function saveChat(chat_name, withMetadata) {
}
*/
});
+
+ const trimmed_chat = (mesId !== undefined && mesId >= 0 && mesId < chat.length)
+ ? chat.slice(0, parseInt(mesId) + 1)
+ : chat;
+
var save_chat = [
{
user_name: name1,
@@ -3844,7 +3852,7 @@ async function saveChat(chat_name, withMetadata) {
create_date: chat_create_date,
chat_metadata: metadata,
},
- ...chat,
+ ...trimmed_chat,
];
return jQuery.ajax({
type: "POST",
@@ -7884,6 +7892,13 @@ $(document).ready(function () {
$("#load_select_chat_div").css("display", "block");
});
+ $(document).on("click", ".mes_create_bookmark", async function () {
+ var selected_mes_id = $(this).closest(".mes").attr("mesid");
+ if (selected_mes_id !== undefined) {
+ createNewBookmark(selected_mes_id);
+ }
+ });
+
$(document).on("click", ".mes_stop", function () {
if (streamingProcessor) {
streamingProcessor.abortController.abort();
diff --git a/public/scripts/bookmarks.js b/public/scripts/bookmarks.js
index b69dbc1ff..ba77eda84 100644
--- a/public/scripts/bookmarks.js
+++ b/public/scripts/bookmarks.js
@@ -32,6 +32,7 @@ import {
} from "./utils.js";
export {
+ createNewBookmark,
showBookmarksButtons,
}
@@ -123,13 +124,26 @@ function showBookmarksButtons() {
}
}
-async function createNewBookmark() {
+async function saveBookmarkMenu() {
if (!chat.length) {
toastr.warning('The chat is empty.', 'Bookmark creation failed');
return;
}
- const mesId = chat.length - 1;
+ return createNewBookmark(chat.length - 1);
+}
+
+async function createNewBookmark(mesId) {
+ if (!chat.length) {
+ toastr.warning('The chat is empty.', 'Bookmark creation failed');
+ return;
+ }
+
+ if (mesId < 0 || mesId >= chat.length) {
+ toastr.warning('Invalid message ID.', 'Bookmark creation failed');
+ return;
+ }
+
const lastMes = chat[mesId];
if (typeof lastMes.extra !== 'object') {
@@ -155,9 +169,9 @@ async function createNewBookmark() {
const newMetadata = { main_chat: mainChat };
if (selected_group) {
- await saveGroupBookmarkChat(selected_group, name, newMetadata);
+ await saveGroupBookmarkChat(selected_group, name, newMetadata, mesId);
} else {
- await saveChat(name, newMetadata);
+ await saveChat(name, newMetadata, mesId);
}
lastMes.extra['bookmark_link'] = name;
@@ -294,7 +308,7 @@ async function convertSoloToGroupChat() {
}
$(document).ready(function () {
- $('#option_new_bookmark').on('click', createNewBookmark);
+ $('#option_new_bookmark').on('click', saveBookmarkMenu);
$('#option_back_to_main').on('click', backToMainChat);
$('#option_convert_to_group').on('click', convertSoloToGroupChat);
});
diff --git a/public/scripts/group-chats.js b/public/scripts/group-chats.js
index f6a9e08fd..821b4b212 100644
--- a/public/scripts/group-chats.js
+++ b/public/scripts/group-chats.js
@@ -1440,7 +1440,7 @@ export async function importGroupChat(formData) {
});
}
-export async function saveGroupBookmarkChat(groupId, name, metadata) {
+export async function saveGroupBookmarkChat(groupId, name, metadata, mesId) {
const group = groups.find(x => x.id === groupId);
if (!group) {
@@ -1450,12 +1450,16 @@ export async function saveGroupBookmarkChat(groupId, name, metadata) {
group.past_metadata[name] = { ...chat_metadata, ...(metadata || {}) };
group.chats.push(name);
+ const trimmed_chat = (mesId !== undefined && mesId >= 0 && mesId < chat.length)
+ ? chat.slice(0, parseInt(mesId) + 1)
+ : chat;
+
await editGroup(groupId, true);
await fetch("/savegroupchat", {
method: "POST",
headers: getRequestHeaders(),
- body: JSON.stringify({ id: name, chat: [...chat] }),
+ body: JSON.stringify({ id: name, chat: [...trimmed_chat] }),
});
}
diff --git a/public/style.css b/public/style.css
index ae87fefe2..d7e3739a4 100644
--- a/public/style.css
+++ b/public/style.css
@@ -2470,6 +2470,7 @@ input[type="range"]::-webkit-slider-thumb {
.mes_buttons .mes_edit,
.mes_buttons .mes_bookmark,
+.mes_buttons .mes_create_bookmark,
.extraMesButtonsHint,
.tagListHint,
.extraMesButtons div {
@@ -2481,6 +2482,7 @@ input[type="range"]::-webkit-slider-thumb {
.mes_buttons .mes_edit:hover,
.mes_buttons .mes_bookmark:hover,
+.mes_buttons .mes_create_bookmark:hover,
.extraMesButtonsHint:hover,
.tagListHint:hover,
.extraMesButtons div:hover {