mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'dev' of https://github.com/SillyLossy/TavernAI into dev
This commit is contained in:
@ -1336,6 +1336,10 @@
|
||||
<div id="options_button">
|
||||
<div id="options">
|
||||
<div class="options-content">
|
||||
<a id="option_back_to_main">
|
||||
<img class="svg_icon" alt="" src="img/left-long-solid.svg">
|
||||
<span>Back to main chat</span>
|
||||
</a>
|
||||
<a id="option_new_bookmark">
|
||||
<img class="svg_icon" alt="" src="img/bookmark-solid.svg">
|
||||
<span>Save bookmark</span>
|
||||
|
@ -68,6 +68,8 @@ import {
|
||||
nai_settings,
|
||||
} from "./scripts/nai-settings.js";
|
||||
|
||||
import { showBookmarksButtons } from "./scripts/bookmarks.js";
|
||||
|
||||
import { debounce, delay } from "./scripts/utils.js";
|
||||
|
||||
//exporting functions and vars for mods
|
||||
@ -95,6 +97,8 @@ export {
|
||||
setSendButtonState,
|
||||
selectRightMenuWithAnimation,
|
||||
setRightTabSelectedClass,
|
||||
openCharacterChat,
|
||||
saveChat,
|
||||
messageFormating,
|
||||
chat,
|
||||
this_chid,
|
||||
@ -115,7 +119,6 @@ export {
|
||||
system_message_types,
|
||||
talkativeness_default,
|
||||
default_ch_mes,
|
||||
saveChat,
|
||||
}
|
||||
|
||||
// API OBJECT FOR EXTERNAL WIRING
|
||||
@ -154,6 +157,9 @@ const system_avatar = "img/five.png";
|
||||
let is_colab = false;
|
||||
let is_checked_colab = false;
|
||||
let is_mes_reload_avatar = false;
|
||||
let optionsPopper = Popper.createPopper(document.getElementById('options_button'), document.getElementById('options'), {
|
||||
placement: 'top-start',
|
||||
});
|
||||
|
||||
const durationSaveEdit = 200;
|
||||
const saveSettingsDebounced = debounce(() => saveSettings(), durationSaveEdit);
|
||||
@ -1887,6 +1893,17 @@ function getChatResult() {
|
||||
select_selected_character(this_chid);
|
||||
}
|
||||
|
||||
async function openCharacterChat(file_name) {
|
||||
characters[this_chid]["chat"] = file_name;
|
||||
clearChat();
|
||||
chat.length = 0;
|
||||
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");
|
||||
}
|
||||
|
||||
/* function openNavToggle() {
|
||||
if (!$("#nav-toggle").prop("checked")) {
|
||||
$("#nav-toggle").trigger("click");
|
||||
@ -3593,12 +3610,13 @@ $(document).ready(function () {
|
||||
$("#options").css("display") === "none" &&
|
||||
$("#options").css("opacity") == 0.0
|
||||
) {
|
||||
showBookmarksButtons();
|
||||
$("#options").css("display", "block");
|
||||
$("#options").transition({
|
||||
opacity: 1.0, // the manual setting of CSS via JS is what allows the click-away feature to work
|
||||
duration: 100,
|
||||
easing: animation_rm_easing,
|
||||
complete: function () { },
|
||||
complete: function () { optionsPopper.update(); },
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -4110,27 +4128,8 @@ $(document).ready(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;
|
||||
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);
|
||||
}
|
||||
}*/
|
||||
openCharacterChat(file_name);
|
||||
});
|
||||
|
||||
$('.drawer-toggle').click(function () {
|
||||
|
@ -2,11 +2,11 @@ import {
|
||||
characters,
|
||||
saveChat,
|
||||
sendSystemMessage,
|
||||
deleteLastMessage,
|
||||
token,
|
||||
system_messages,
|
||||
system_message_types,
|
||||
this_chid,
|
||||
openCharacterChat,
|
||||
} from "../script.js";
|
||||
import { selected_group } from "./group-chats.js";
|
||||
|
||||
@ -14,6 +14,12 @@ import {
|
||||
stringFormat,
|
||||
} from "./utils.js";
|
||||
|
||||
export {
|
||||
showBookmarksButtons,
|
||||
}
|
||||
|
||||
const bookmarkNameToken = 'Bookmark #';
|
||||
|
||||
async function getExistingChatNames() {
|
||||
const response = await fetch("/getallchatsofcharacter", {
|
||||
method: 'POST',
|
||||
@ -21,7 +27,7 @@ async function getExistingChatNames() {
|
||||
'Content-Type': 'application/json',
|
||||
"X-CSRF-Token": token,
|
||||
},
|
||||
body: JSON.stringify({ avatar_url: characters[this_chid].avatar})
|
||||
body: JSON.stringify({ avatar_url: characters[this_chid].avatar })
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
@ -31,18 +37,14 @@ async function getExistingChatNames() {
|
||||
}
|
||||
|
||||
async function getBookmarkName(currentChat) {
|
||||
const nameToken = 'Bookmark #';
|
||||
if (currentChat.includes(nameToken)) {
|
||||
currentChat = currentChat.substring(0, currentChat.lastIndexOf(nameToken)).trim();
|
||||
}
|
||||
|
||||
const chatNames = await getExistingChatNames();
|
||||
let mainChat = getMainChatName(currentChat);
|
||||
let newChat = Date.now();
|
||||
let friendlyName = '';
|
||||
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
friendlyName = `${nameToken}${i}`;
|
||||
newChat = `${currentChat} ${friendlyName}`;
|
||||
friendlyName = `${bookmarkNameToken}${i}`;
|
||||
newChat = `${mainChat} ${friendlyName}`;
|
||||
if (!chatNames.includes(newChat)) {
|
||||
break;
|
||||
}
|
||||
@ -50,11 +52,37 @@ async function getBookmarkName(currentChat) {
|
||||
return { newChat, friendlyName };
|
||||
}
|
||||
|
||||
function getMainChatName(currentChat) {
|
||||
if (currentChat.includes(bookmarkNameToken)) {
|
||||
currentChat = currentChat.substring(0, currentChat.lastIndexOf(bookmarkNameToken)).trim();
|
||||
}
|
||||
return currentChat;
|
||||
}
|
||||
|
||||
function showBookmarksButtons() {
|
||||
// In groups
|
||||
if (selected_group) {
|
||||
$("#option_back_to_main").hide();
|
||||
$("#option_new_bookmark").hide();
|
||||
}
|
||||
// In main chat
|
||||
else if (!characters[this_chid].chat.includes(bookmarkNameToken)) {
|
||||
$("#option_back_to_main").hide();
|
||||
$("#option_new_bookmark").show();
|
||||
|
||||
}
|
||||
// In bookmark chat
|
||||
else {
|
||||
$("#option_back_to_main").show();
|
||||
$("#option_new_bookmark").show();
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
$('#option_new_bookmark').on('click', async function () {
|
||||
if (selected_group) {
|
||||
alert('Unsupported for groups');
|
||||
throw new Error('not yet implemented');
|
||||
alert('Chat bookmarks unsupported for groups');
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
let { newChat, friendlyName } = await getBookmarkName(characters[this_chid].chat);
|
||||
@ -64,5 +92,13 @@ $(document).ready(function () {
|
||||
sendSystemMessage(system_message_types.BOOKMARK_CREATED, mainMessage);
|
||||
saveChat();
|
||||
});
|
||||
});
|
||||
|
||||
$('#option_back_to_main').on('click', async function() {
|
||||
const mainChatName = getMainChatName(characters[this_chid].chat);
|
||||
const allChats = await getExistingChatNames();
|
||||
|
||||
if (allChats.includes(mainChatName)) {
|
||||
openCharacterChat(mainChatName);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -309,6 +309,7 @@ margin-top:5px;
|
||||
text-shadow: 0 0 3px black;
|
||||
min-width: 200px;
|
||||
z-index: 2000;
|
||||
margin-bottom: 13px;
|
||||
}
|
||||
|
||||
.options-content hr {
|
||||
@ -1983,7 +1984,7 @@ right: -30px;
|
||||
|
||||
.select_chat_block_wrapper{
|
||||
display: grid;
|
||||
grid-template-columns: auto auto;
|
||||
grid-template-columns: auto min-content;
|
||||
align-items: center;
|
||||
grid-gap: 10px;
|
||||
}
|
||||
|
Reference in New Issue
Block a user