mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add retroactive bookmarking
This commit is contained in:
@@ -3302,6 +3302,7 @@
|
||||
<div title="Copy" class="mes_copy fa-solid fa-copy "></div>
|
||||
</div>
|
||||
<div title="Open bookmark chat" class="mes_bookmark fa-solid fa-bookmark"></div>
|
||||
<div title="Create bookmark" class="mes_create_bookmark fa-regular fa-code-branch"></div>
|
||||
<div title="Edit" class="mes_edit fa-solid fa-pencil "></div>
|
||||
</div>
|
||||
<div class="mes_edit_buttons">
|
||||
|
@@ -100,7 +100,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,
|
||||
@@ -3815,7 +3818,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();
|
||||
@@ -3836,6 +3839,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,
|
||||
@@ -3843,7 +3851,7 @@ async function saveChat(chat_name, withMetadata) {
|
||||
create_date: chat_create_date,
|
||||
chat_metadata: metadata,
|
||||
},
|
||||
...chat,
|
||||
...trimmed_chat,
|
||||
];
|
||||
return jQuery.ajax({
|
||||
type: "POST",
|
||||
@@ -7883,6 +7891,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();
|
||||
|
@@ -32,6 +32,7 @@ import {
|
||||
} from "./utils.js";
|
||||
|
||||
export {
|
||||
createNewBookmark,
|
||||
showBookmarksButtons,
|
||||
}
|
||||
|
||||
@@ -123,13 +124,14 @@ function showBookmarksButtons() {
|
||||
}
|
||||
}
|
||||
|
||||
async function createNewBookmark() {
|
||||
async function createNewBookmark(mesId) {
|
||||
if (!chat.length) {
|
||||
toastr.warning('The chat is empty.', 'Bookmark creation failed');
|
||||
return;
|
||||
}
|
||||
|
||||
const mesId = chat.length - 1;
|
||||
// Default to last message in chat if no mesId given.
|
||||
mesId = mesId || chat.length - 1;
|
||||
const lastMes = chat[mesId];
|
||||
|
||||
if (typeof lastMes.extra !== 'object') {
|
||||
@@ -155,9 +157,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;
|
||||
|
@@ -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] }),
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user