Add branching as distinct from bookmarking

This commit is contained in:
city-unit
2023-09-20 22:48:05 -04:00
parent e3f760a9dd
commit e0b5df97c4
3 changed files with 51 additions and 2 deletions

View File

@@ -133,6 +133,39 @@ async function saveBookmarkMenu() {
return createNewBookmark(chat.length - 1);
}
export async function createBranch(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];
const mainChat = selected_group ? groups?.find(x => x.id == selected_group)?.chat_id : characters[this_chid].chat;
const newMetadata = { main_chat: mainChat };
let name = `Branch #${mesId} - ${humanizedDateTime()}`
if (selected_group) {
await saveGroupBookmarkChat(selected_group, name, newMetadata, mesId);
} else {
await saveChat(name, newMetadata, mesId);
}
// append to branches list if it exists
// otherwise create it
if (typeof lastMes.extra !== 'object') {
lastMes.extra = {};
}
if (typeof lastMes.extra['branches'] !== 'object') {
lastMes.extra['branches'] = [];
}
lastMes.extra['branches'].push(name);
return name;
}
async function createNewBookmark(mesId) {
if (!chat.length) {
toastr.warning('The chat is empty.', 'Bookmark creation failed');