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_button">
|
||||||
<div id="options">
|
<div id="options">
|
||||||
<div class="options-content">
|
<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">
|
<a id="option_new_bookmark">
|
||||||
<img class="svg_icon" alt="" src="img/bookmark-solid.svg">
|
<img class="svg_icon" alt="" src="img/bookmark-solid.svg">
|
||||||
<span>Save bookmark</span>
|
<span>Save bookmark</span>
|
||||||
|
@ -68,6 +68,8 @@ import {
|
|||||||
nai_settings,
|
nai_settings,
|
||||||
} from "./scripts/nai-settings.js";
|
} from "./scripts/nai-settings.js";
|
||||||
|
|
||||||
|
import { showBookmarksButtons } from "./scripts/bookmarks.js";
|
||||||
|
|
||||||
import { debounce, delay } from "./scripts/utils.js";
|
import { debounce, delay } from "./scripts/utils.js";
|
||||||
|
|
||||||
//exporting functions and vars for mods
|
//exporting functions and vars for mods
|
||||||
@ -95,6 +97,8 @@ export {
|
|||||||
setSendButtonState,
|
setSendButtonState,
|
||||||
selectRightMenuWithAnimation,
|
selectRightMenuWithAnimation,
|
||||||
setRightTabSelectedClass,
|
setRightTabSelectedClass,
|
||||||
|
openCharacterChat,
|
||||||
|
saveChat,
|
||||||
messageFormating,
|
messageFormating,
|
||||||
chat,
|
chat,
|
||||||
this_chid,
|
this_chid,
|
||||||
@ -115,7 +119,6 @@ export {
|
|||||||
system_message_types,
|
system_message_types,
|
||||||
talkativeness_default,
|
talkativeness_default,
|
||||||
default_ch_mes,
|
default_ch_mes,
|
||||||
saveChat,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// API OBJECT FOR EXTERNAL WIRING
|
// API OBJECT FOR EXTERNAL WIRING
|
||||||
@ -154,6 +157,9 @@ const system_avatar = "img/five.png";
|
|||||||
let is_colab = false;
|
let is_colab = false;
|
||||||
let is_checked_colab = false;
|
let is_checked_colab = false;
|
||||||
let is_mes_reload_avatar = 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 durationSaveEdit = 200;
|
||||||
const saveSettingsDebounced = debounce(() => saveSettings(), durationSaveEdit);
|
const saveSettingsDebounced = debounce(() => saveSettings(), durationSaveEdit);
|
||||||
@ -1887,6 +1893,17 @@ function getChatResult() {
|
|||||||
select_selected_character(this_chid);
|
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() {
|
/* function openNavToggle() {
|
||||||
if (!$("#nav-toggle").prop("checked")) {
|
if (!$("#nav-toggle").prop("checked")) {
|
||||||
$("#nav-toggle").trigger("click");
|
$("#nav-toggle").trigger("click");
|
||||||
@ -3593,12 +3610,13 @@ $(document).ready(function () {
|
|||||||
$("#options").css("display") === "none" &&
|
$("#options").css("display") === "none" &&
|
||||||
$("#options").css("opacity") == 0.0
|
$("#options").css("opacity") == 0.0
|
||||||
) {
|
) {
|
||||||
|
showBookmarksButtons();
|
||||||
$("#options").css("display", "block");
|
$("#options").css("display", "block");
|
||||||
$("#options").transition({
|
$("#options").transition({
|
||||||
opacity: 1.0, // the manual setting of CSS via JS is what allows the click-away feature to work
|
opacity: 1.0, // the manual setting of CSS via JS is what allows the click-away feature to work
|
||||||
duration: 100,
|
duration: 100,
|
||||||
easing: animation_rm_easing,
|
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 () {
|
$(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", "");
|
let file_name = $(this).attr("file_name").replace(".jsonl", "");
|
||||||
//console.log(characters[this_chid]['chat']);
|
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");
|
|
||||||
|
|
||||||
// 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 () {
|
$('.drawer-toggle').click(function () {
|
||||||
|
@ -2,11 +2,11 @@ import {
|
|||||||
characters,
|
characters,
|
||||||
saveChat,
|
saveChat,
|
||||||
sendSystemMessage,
|
sendSystemMessage,
|
||||||
deleteLastMessage,
|
|
||||||
token,
|
token,
|
||||||
system_messages,
|
system_messages,
|
||||||
system_message_types,
|
system_message_types,
|
||||||
this_chid,
|
this_chid,
|
||||||
|
openCharacterChat,
|
||||||
} from "../script.js";
|
} from "../script.js";
|
||||||
import { selected_group } from "./group-chats.js";
|
import { selected_group } from "./group-chats.js";
|
||||||
|
|
||||||
@ -14,6 +14,12 @@ import {
|
|||||||
stringFormat,
|
stringFormat,
|
||||||
} from "./utils.js";
|
} from "./utils.js";
|
||||||
|
|
||||||
|
export {
|
||||||
|
showBookmarksButtons,
|
||||||
|
}
|
||||||
|
|
||||||
|
const bookmarkNameToken = 'Bookmark #';
|
||||||
|
|
||||||
async function getExistingChatNames() {
|
async function getExistingChatNames() {
|
||||||
const response = await fetch("/getallchatsofcharacter", {
|
const response = await fetch("/getallchatsofcharacter", {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -31,18 +37,14 @@ async function getExistingChatNames() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getBookmarkName(currentChat) {
|
async function getBookmarkName(currentChat) {
|
||||||
const nameToken = 'Bookmark #';
|
|
||||||
if (currentChat.includes(nameToken)) {
|
|
||||||
currentChat = currentChat.substring(0, currentChat.lastIndexOf(nameToken)).trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
const chatNames = await getExistingChatNames();
|
const chatNames = await getExistingChatNames();
|
||||||
|
let mainChat = getMainChatName(currentChat);
|
||||||
let newChat = Date.now();
|
let newChat = Date.now();
|
||||||
let friendlyName = '';
|
let friendlyName = '';
|
||||||
|
|
||||||
for (let i = 0; i < 1000; i++) {
|
for (let i = 0; i < 1000; i++) {
|
||||||
friendlyName = `${nameToken}${i}`;
|
friendlyName = `${bookmarkNameToken}${i}`;
|
||||||
newChat = `${currentChat} ${friendlyName}`;
|
newChat = `${mainChat} ${friendlyName}`;
|
||||||
if (!chatNames.includes(newChat)) {
|
if (!chatNames.includes(newChat)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -50,11 +52,37 @@ async function getBookmarkName(currentChat) {
|
|||||||
return { newChat, friendlyName };
|
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 () {
|
$(document).ready(function () {
|
||||||
$('#option_new_bookmark').on('click', async function () {
|
$('#option_new_bookmark').on('click', async function () {
|
||||||
if (selected_group) {
|
if (selected_group) {
|
||||||
alert('Unsupported for groups');
|
alert('Chat bookmarks unsupported for groups');
|
||||||
throw new Error('not yet implemented');
|
throw new Error();
|
||||||
}
|
}
|
||||||
|
|
||||||
let { newChat, friendlyName } = await getBookmarkName(characters[this_chid].chat);
|
let { newChat, friendlyName } = await getBookmarkName(characters[this_chid].chat);
|
||||||
@ -64,5 +92,13 @@ $(document).ready(function () {
|
|||||||
sendSystemMessage(system_message_types.BOOKMARK_CREATED, mainMessage);
|
sendSystemMessage(system_message_types.BOOKMARK_CREATED, mainMessage);
|
||||||
saveChat();
|
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;
|
text-shadow: 0 0 3px black;
|
||||||
min-width: 200px;
|
min-width: 200px;
|
||||||
z-index: 2000;
|
z-index: 2000;
|
||||||
|
margin-bottom: 13px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.options-content hr {
|
.options-content hr {
|
||||||
@ -1983,7 +1984,7 @@ right: -30px;
|
|||||||
|
|
||||||
.select_chat_block_wrapper{
|
.select_chat_block_wrapper{
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: auto auto;
|
grid-template-columns: auto min-content;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
grid-gap: 10px;
|
grid-gap: 10px;
|
||||||
}
|
}
|
||||||
|
@ -104,3 +104,4 @@ Contact us on Discord: Cohee#1207 or RossAscends#1779
|
|||||||
* SillyLossy's TAI mod: Public domain
|
* SillyLossy's TAI mod: Public domain
|
||||||
* RossAscends' additions: Public domain
|
* RossAscends' additions: Public domain
|
||||||
* Portions of CncAnon's TavernAITurbo mod: Unknown license
|
* Portions of CncAnon's TavernAITurbo mod: Unknown license
|
||||||
|
* Thanks oobabooga for compiling presets for TextGen
|
||||||
|
Reference in New Issue
Block a user