diff --git a/public/index.html b/public/index.html index 67b2395db..9da30cda3 100644 --- a/public/index.html +++ b/public/index.html @@ -1986,7 +1986,7 @@
Avatar
-
+
diff --git a/public/script.js b/public/script.js index 5184500f4..0dc5c3c0a 100644 --- a/public/script.js +++ b/public/script.js @@ -152,6 +152,7 @@ export { chat, this_chid, selected_button, + menu_type, settings, characters, online_status, @@ -208,7 +209,6 @@ let mesStr = ""; let generatedPromtCache = ""; let characters = []; let this_chid; -let active_character; let backgrounds = []; const default_avatar = "img/ai4.png"; const system_avatar = "img/five.png"; @@ -2459,8 +2459,6 @@ function deactivateSendButtons() { } function resetChatState() { - //unsets the chid in settings (this prevents AutoLoadChat from trying to load the wrong ChID - active_character = "invalid-safety-id"; //unsets expected chid before reloading (related to getCharacters/printCharacters from using old arrays) this_chid = "invalid-safety-id"; // replaces deleted charcter name with system user since it will be displayed next. @@ -2473,6 +2471,10 @@ function resetChatState() { characters.length = 0; } +export function setMenuType(value) { + menu_type = value; +} + function setCharacterId(value) { this_chid = value; } @@ -3039,13 +3041,6 @@ async function getSettings(type) { loadExtensionSettings(settings); } - //get the character to auto-load - if (settings.active_character !== undefined) { - if (settings.active_character !== "") { - active_character = settings.active_character; - } - } - api_server_textgenerationwebui = settings.api_server_textgenerationwebui; $("#textgenerationwebui_api_url_text").val( @@ -3090,7 +3085,6 @@ async function saveSettings(type) { world_info: world_info, world_info_depth: world_info_depth, world_info_budget: world_info_budget, - active_character: active_character, textgenerationwebui_settings: textgenerationwebui_settings, swipes: swipes, horde_settings: horde_settings, @@ -3104,7 +3098,6 @@ async function saveSettings(type) { ...oai_settings, }, null, 4), beforeSend: function () { - //console.log('saveSettings() -- active_character -- '+active_character); if (type == "change_name") { name1 = $("#your_name").val(); // console.log('beforeSend name1 = '+name1); @@ -3325,7 +3318,7 @@ function select_rm_info(text, charId = null) { } } -function select_selected_character(chid) { +export function select_selected_character(chid) { //character select //console.log('select_selected_character() -- starting with input of -- '+chid+' (name:'+characters[chid].name+')'); select_rm_create(); @@ -3341,7 +3334,11 @@ function select_selected_character(chid) { $("#create_button").attr("value", "Save"); // what is the use case for this? $("#create_button_label").css("display", "none"); - $("#rm_button_selected_ch").children("h2").text(display_name); + // Don't update the navbar name if we're peeking the group member defs + if (!selected_group) { + $("#rm_button_selected_ch").children("h2").text(display_name); + } + $("#add_avatar_button").val(""); $("#character_popup_text_h3").text(characters[chid].name); @@ -3350,17 +3347,14 @@ function select_selected_character(chid) { $("#personality_textarea").val(characters[chid].personality); $("#firstmessage_textarea").val(characters[chid].first_mes); $("#scenario_pole").val(characters[chid].scenario); - $("#talkativeness_slider").val( - characters[chid].talkativeness ?? talkativeness_default - ); + $("#talkativeness_slider").val(characters[chid].talkativeness ?? talkativeness_default); $("#mes_example_textarea").val(characters[chid].mes_example); $("#selected_chat_pole").val(characters[chid].chat); $("#create_date_pole").val(characters[chid].create_date); $("#avatar_url_pole").val(characters[chid].avatar); $("#chat_import_avatar_url").val(characters[chid].avatar); $("#chat_import_character_name").val(characters[chid].name); - //$("#avatar_div").css("display", "none"); - var this_avatar = default_avatar; + let this_avatar = default_avatar; if (characters[chid].avatar != "none") { this_avatar = getThumbnailUrl('avatar', characters[chid].avatar); } @@ -3373,7 +3367,6 @@ function select_selected_character(chid) { $("#renameCharButton").css("display", ""); $("#form_create").attr("actiontype", "editcharacter"); - active_character = chid; saveSettingsDebounced(); } @@ -4072,7 +4065,6 @@ $(document).ready(function () { this_edit_mes_id = undefined; selected_button = "character_edit"; this_chid = $(this).attr("chid"); - active_character = this_chid; clearChat(); chat.length = 0; chat_metadata = {}; @@ -4451,11 +4443,12 @@ $(document).ready(function () { contentType: false, processData: false, success: function (html) { - + /* Cohee: Not needed, since the rename routine forcefully reloads the chat //currently this updates the displayed H2 name regardless of soft errors, doesn't detect actual errors. let h2text = $("#character_name_pole").val(); console.log('about to change name! in h2'); $("#rm_button_selected_ch").children("h2").text(h2text); + */ $(".mes").each(function () { if ($(this).attr("is_system") == 'true') { @@ -5294,13 +5287,6 @@ $(document).ready(function () { select_rm_characters(); }); - $("#rm_button_extensions").click(function () { - menu_type = 'extennsions'; - selected_button = 'extensions'; - setRightTabSelectedClass('rm_button_extensions'); - selectRightMenuWithAnimation('rm_extensions_block'); - }); - $(document).on("click", ".select_chat_block, .bookmark_link", async function () { let file_name = $(this).attr("file_name").replace(".jsonl", ""); openCharacterChat(file_name); diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index d0bdc3774..8ccd359c1 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -11,7 +11,7 @@ import { api_server_textgenerationwebui, is_send_press, getTokenCount, - selected_button, + menu_type, } from "../script.js"; @@ -176,10 +176,10 @@ $("#rm_ch_create_block").on("input", function () { RA_CountCharTokens(); }); //when any input is made to the advanced editing popup textareas $("#character_popup").on("input", function () { RA_CountCharTokens(); }); //function: -function RA_CountCharTokens() { +export function RA_CountCharTokens() { $("#result_info").html(""); //console.log('RA_TC -- starting with this_chid = ' + this_chid); - if (selected_button === "create") { //if new char + if (menu_type === "create") { //if new char function saveFormVariables() { create_save_name = $("#character_name_pole").val(); create_save_description = $("#description_textarea").val(); diff --git a/public/scripts/extensions/expressions/index.js b/public/scripts/extensions/expressions/index.js index 9c21fffe3..bcde51bfb 100644 --- a/public/scripts/extensions/expressions/index.js +++ b/public/scripts/extensions/expressions/index.js @@ -80,7 +80,7 @@ async function moduleWorker() { const context = getContext(); // non-characters not supported - if (!context.groupId && !context.characterId) { + if (!context.groupId && context.characterId === undefined) { removeExpression(); return; } diff --git a/public/scripts/extensions/floating-prompt/index.js b/public/scripts/extensions/floating-prompt/index.js index b61ad3fff..da8563777 100644 --- a/public/scripts/extensions/floating-prompt/index.js +++ b/public/scripts/extensions/floating-prompt/index.js @@ -66,7 +66,7 @@ function loadSettings() { async function moduleWorker() { const context = getContext(); - if (!context.groupId && !context.characterId) { + if (!context.groupId && context.characterId === undefined) { return; } diff --git a/public/scripts/extensions/memory/index.js b/public/scripts/extensions/memory/index.js index 18b1074d5..17c7a68fa 100644 --- a/public/scripts/extensions/memory/index.js +++ b/public/scripts/extensions/memory/index.js @@ -133,7 +133,7 @@ async function moduleWorker() { const chat = context.chat; // no characters or group selected - if (!context.groupId && !context.characterId) { + if (!context.groupId && context.characterId === undefined) { return; } diff --git a/public/scripts/extensions/tts/index.js b/public/scripts/extensions/tts/index.js index b35e0b1ee..a4df5ff51 100644 --- a/public/scripts/extensions/tts/index.js +++ b/public/scripts/extensions/tts/index.js @@ -37,7 +37,7 @@ async function moduleWorker() { updateUiAudioPlayState() // no characters or group selected - if (!context.groupId && !context.characterId) { + if (!context.groupId && context.characterId === undefined) { return } diff --git a/public/scripts/group-chats.js b/public/scripts/group-chats.js index 041b474cb..93e01cdd0 100644 --- a/public/scripts/group-chats.js +++ b/public/scripts/group-chats.js @@ -4,7 +4,7 @@ import { debounce, delay, } from './utils.js'; -import { humanizedDateTime } from "./RossAscends-mods.js"; +import { RA_CountCharTokens, humanizedDateTime } from "./RossAscends-mods.js"; import { sortCharactersList } from './power-user.js'; import { @@ -42,15 +42,17 @@ import { getThumbnailUrl, streamingProcessor, getRequestHeaders, + setMenuType, + menu_type, + select_selected_character, } from "../script.js"; -import { appendTagToList, createTagMapFromList, getTagsList } from './tags.js'; +import { appendTagToList, createTagMapFromList, getTagsList, applyTagsOnCharacterSelect } from './tags.js'; export { selected_group, is_group_automode_enabled, is_group_generating, group_generation_id, - group_rm_panel_mode, groups, saveGroupChat, generateGroupWrapper, @@ -69,7 +71,6 @@ let groups = []; let selected_group = null; let group_generation_id = null; let fav_grp_checked = false; -let group_rm_panel_mode; export const group_activation_strategy = { NATURAL: 0, @@ -377,6 +378,12 @@ async function generateGroupWrapper(by_auto_mode, type = null) { return; } + // Auto-navigate back to group menu + if (menu_type !== "group_edit") { + select_group_chats(selected_group); + await delay(1); + } + if (is_group_generating) { return false; } @@ -798,7 +805,7 @@ async function reorderGroupMember(chat_id, groupMember, direction) { function select_group_chats(groupId, skipAnimation) { const group = groupId && groups.find((x) => x.id == groupId); const groupName = group?.name ?? ""; - group_rm_panel_mode = !!group ? 'edit' : 'create'; + setMenuType(!!group ? 'group_edit' : 'group_create'); $("#rm_group_chat_name").val(groupName); $("#rm_group_chat_name").off(); $("#rm_group_chat_name").on("input", async function () { @@ -940,94 +947,119 @@ function updateFavButtonState(state) { $("#group_favorite_button").toggleClass('fav_off', !fav_grp_checked); } -$(document).ready(() => { - $(document).on("click", ".group_select", async function () { - const groupId = $(this).data("id"); +async function selectGroup() { + const groupId = $(this).data("id"); - if (!is_send_press && !is_group_generating) { - if (selected_group !== groupId) { - selected_group = groupId; - setCharacterId(undefined); - setCharacterName(''); - setEditedMessageId(undefined); - clearChat(); - updateChatMetadata({}, true); - chat.length = 0; - await getGroupChat(groupId); - //to avoid the filter being lit up yellow and left at true while the list of character and group reseted. - $("#filter_by_fav").removeClass("fav_on"); - filterByFav = false; - } - - select_group_chats(groupId); - } - }); - - $("#rm_group_filter").on("input", function () { - const searchValue = $(this).val().trim().toLowerCase(); - - if (!searchValue) { - $("#rm_group_add_members .group_member").show(); - } else { - $("#rm_group_add_members .group_member").each(function () { - $(this).children(".ch_name").text().toLowerCase().includes(searchValue) - ? $(this).show() - : $(this).hide(); - }); - } - }); - - $("#rm_group_submit").click(async function () { - let name = $("#rm_group_chat_name").val(); - let allow_self_responses = !!$("#rm_group_allow_self_responses").prop("checked"); - let activation_strategy = $('input[name="rm_group_activation_strategy"]:checked').val() ?? group_activation_strategy.NATURAL; - const members = $("#rm_group_members .group_member") - .map((_, x) => $(x).data("id")) - .toArray(); - - const memberNames = characters.filter(x => members.includes(x.avatar)).map(x => x.name).join(", "); - - if (!name) { - name = `Chat with ${memberNames}`; + if (!is_send_press && !is_group_generating) { + if (selected_group !== groupId) { + selected_group = groupId; + setCharacterId(undefined); + setCharacterName(''); + setEditedMessageId(undefined); + clearChat(); + updateChatMetadata({}, true); + chat.length = 0; + await getGroupChat(groupId); + //to avoid the filter being lit up yellow and left at true while the list of character and group reseted. + $("#filter_by_fav").removeClass("fav_on"); + filterByFav = false; } - // placeholder - const avatar_url = 'img/five.png'; + select_group_chats(groupId); + } +} - const chatName = humanizedDateTime(); - const chats = [chatName]; +function openCharacterDefinition() { + if (is_group_generating) { + console.warn("Can't peek a character def while group reply is being generated"); + return; + } - const createGroupResponse = await fetch("/creategroup", { - method: "POST", - headers: getRequestHeaders(), - body: JSON.stringify({ - name: name, - members: members, - avatar_url: avatar_url, - allow_self_responses: allow_self_responses, - activation_strategy: activation_strategy, - chat_metadata: {}, - fav: fav_grp_checked, - chat_id: chatName, - chats: chats, - }), + const characterSelect = $(this).closest('.group_member'); + const chid = characterSelect.attr('chid'); + + if (chid === null || chid === undefined) { + return; + } + + setCharacterId(chid); + select_selected_character(chid, true); + // Gentle nudge to recalculate tokens + RA_CountCharTokens(); + // Do a little tomfoolery to spoof the tag selector + applyTagsOnCharacterSelect.call(characterSelect); +} + +function filterGroupMembers() { + const searchValue = $(this).val().trim().toLowerCase(); + + if (!searchValue) { + $("#rm_group_add_members .group_member").show(); + } else { + $("#rm_group_add_members .group_member").each(function () { + $(this).children(".ch_name").text().toLowerCase().includes(searchValue) + ? $(this).show() + : $(this).hide(); }); + } +} - if (createGroupResponse.ok) { - const data = await createGroupResponse.json(); - createTagMapFromList("#groupTagList", data.id); +async function createGroup() { + let name = $("#rm_group_chat_name").val(); + let allow_self_responses = !!$("#rm_group_allow_self_responses").prop("checked"); + let activation_strategy = $('input[name="rm_group_activation_strategy"]:checked').val() ?? group_activation_strategy.NATURAL; + const members = $("#rm_group_members .group_member") + .map((_, x) => $(x).data("id")) + .toArray(); - await getCharacters(); - $("#rm_info_avatar").html(""); - const avatar = $("#avatar_div_div").clone(); - avatar.find("img").attr("src", avatar_url); - $("#rm_info_avatar").append(avatar); - $("#rm_info_block").transition({ opacity: 0, duration: 0 }); - select_rm_info("Group chat created"); - $("#rm_info_block").transition({ opacity: 1.0, duration: 2000 }); - } + const memberNames = characters.filter(x => members.includes(x.avatar)).map(x => x.name).join(", "); + + if (!name) { + name = `Chat with ${memberNames}`; + } + + // placeholder + const avatar_url = 'img/five.png'; + + const chatName = humanizedDateTime(); + const chats = [chatName]; + + const createGroupResponse = await fetch("/creategroup", { + method: "POST", + headers: getRequestHeaders(), + body: JSON.stringify({ + name: name, + members: members, + avatar_url: avatar_url, + allow_self_responses: allow_self_responses, + activation_strategy: activation_strategy, + chat_metadata: {}, + fav: fav_grp_checked, + chat_id: chatName, + chats: chats, + }), }); + if (createGroupResponse.ok) { + const data = await createGroupResponse.json(); + createTagMapFromList("#groupTagList", data.id); + + await getCharacters(); + $("#rm_info_avatar").html(""); + const avatar = $("#avatar_div_div").clone(); + avatar.find("img").attr("src", avatar_url); + $("#rm_info_avatar").append(avatar); + $("#rm_info_block").transition({ opacity: 0, duration: 0 }); + select_rm_info("Group chat created"); + $("#rm_info_block").transition({ opacity: 1.0, duration: 2000 }); + } +} + +$(document).ready(() => { + $(document).on("click", ".group_member .ch_name", openCharacterDefinition); + $(document).on("click", ".group_select", selectGroup); + $("#rm_group_filter").on("input", filterGroupMembers); + $("#rm_group_submit").on("click", createGroup); $("#rm_group_automode").on("input", function () { const value = $(this).prop("checked"); is_group_automode_enabled = value; diff --git a/public/scripts/tags.js b/public/scripts/tags.js index 6f40296ca..bb887418d 100644 --- a/public/scripts/tags.js +++ b/public/scripts/tags.js @@ -1,5 +1,5 @@ -import { characters, saveSettingsDebounced, this_chid, selected_button, callPopup } from "../script.js"; -import { group_rm_panel_mode, selected_group } from "./group-chats.js"; +import { characters, saveSettingsDebounced, this_chid, callPopup, menu_type } from "../script.js"; +import { selected_group } from "./group-chats.js"; export { tags, @@ -58,11 +58,11 @@ function getTagsList(key) { } function getInlineListSelector() { - if (selected_group && group_rm_panel_mode !== "create") { + if (selected_group && menu_type === "group_edit") { return `.group_select[grid="${selected_group}"] .tags`; } - if (this_chid && selected_button !== "create") { + if (this_chid && menu_type === "character_edit") { return `.character_select[chid="${this_chid}"] .tags`; } @@ -70,11 +70,11 @@ function getInlineListSelector() { } function getTagKey() { - if (selected_group && group_rm_panel_mode !== "create") { + if (selected_group && menu_type === "group_edit") { return selected_group; } - if (this_chid && selected_button !== "create") { + if (this_chid && menu_type === "character_edit") { return characters[this_chid].avatar; } @@ -251,7 +251,7 @@ function onGroupCreateClick() { $("#groupTagList").empty(); } -function onCharacterSelectClick() { +export function applyTagsOnCharacterSelect() { clearTagsFilter(); const chid = Number($(this).attr('chid')); const key = characters[chid].avatar; @@ -264,7 +264,7 @@ function onCharacterSelectClick() { } } -function onGroupSelectClick() { +function applyTagsOnGroupSelect() { clearTagsFilter(); const key = $(this).attr('grid'); const tags = getTagsList(key); @@ -332,8 +332,8 @@ $(document).ready(() => { $(document).on("click", "#rm_button_create", onCharacterCreateClick); $(document).on("click", "#rm_button_group_chats", onGroupCreateClick); - $(document).on("click", ".character_select", onCharacterSelectClick); - $(document).on("click", ".group_select", onGroupSelectClick); + $(document).on("click", ".character_select", applyTagsOnCharacterSelect); + $(document).on("click", ".group_select", applyTagsOnGroupSelect); $(document).on("click", ".tag_remove", onTagRemoveClick); $(document).on("input", ".tag_input", onTagInput); $(document).on("click", ".tags_view", onViewTagsListClick);