Add group member defs peeking

This commit is contained in:
SillyLossy
2023-05-01 19:39:18 +03:00
parent 5144ae2220
commit 6f47b07063
9 changed files with 148 additions and 130 deletions

View File

@ -1986,7 +1986,7 @@
<div class="avatar"> <div class="avatar">
<img alt="Avatar" src="" /> <img alt="Avatar" src="" />
</div> </div>
<div class="ch_name"></div> <a href="javascript:void(0);" class="ch_name"></a>
<div class="group_member_icon"> <div class="group_member_icon">
<div title="Move up" data-action="up" class="right_menu_button fa-solid fa-xl fa-chevron-up"></div> <div title="Move up" data-action="up" class="right_menu_button fa-solid fa-xl fa-chevron-up"></div>
<div title="Move down" data-action="down" class="right_menu_button fa-solid fa-xl fa-chevron-down"></div> <div title="Move down" data-action="down" class="right_menu_button fa-solid fa-xl fa-chevron-down"></div>

View File

@ -152,6 +152,7 @@ export {
chat, chat,
this_chid, this_chid,
selected_button, selected_button,
menu_type,
settings, settings,
characters, characters,
online_status, online_status,
@ -208,7 +209,6 @@ let mesStr = "";
let generatedPromtCache = ""; let generatedPromtCache = "";
let characters = []; let characters = [];
let this_chid; let this_chid;
let active_character;
let backgrounds = []; let backgrounds = [];
const default_avatar = "img/ai4.png"; const default_avatar = "img/ai4.png";
const system_avatar = "img/five.png"; const system_avatar = "img/five.png";
@ -2459,8 +2459,6 @@ function deactivateSendButtons() {
} }
function resetChatState() { 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) //unsets expected chid before reloading (related to getCharacters/printCharacters from using old arrays)
this_chid = "invalid-safety-id"; this_chid = "invalid-safety-id";
// replaces deleted charcter name with system user since it will be displayed next. // replaces deleted charcter name with system user since it will be displayed next.
@ -2473,6 +2471,10 @@ function resetChatState() {
characters.length = 0; characters.length = 0;
} }
export function setMenuType(value) {
menu_type = value;
}
function setCharacterId(value) { function setCharacterId(value) {
this_chid = value; this_chid = value;
} }
@ -3039,13 +3041,6 @@ async function getSettings(type) {
loadExtensionSettings(settings); 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 = api_server_textgenerationwebui =
settings.api_server_textgenerationwebui; settings.api_server_textgenerationwebui;
$("#textgenerationwebui_api_url_text").val( $("#textgenerationwebui_api_url_text").val(
@ -3090,7 +3085,6 @@ async function saveSettings(type) {
world_info: world_info, world_info: world_info,
world_info_depth: world_info_depth, world_info_depth: world_info_depth,
world_info_budget: world_info_budget, world_info_budget: world_info_budget,
active_character: active_character,
textgenerationwebui_settings: textgenerationwebui_settings, textgenerationwebui_settings: textgenerationwebui_settings,
swipes: swipes, swipes: swipes,
horde_settings: horde_settings, horde_settings: horde_settings,
@ -3104,7 +3098,6 @@ async function saveSettings(type) {
...oai_settings, ...oai_settings,
}, null, 4), }, null, 4),
beforeSend: function () { beforeSend: function () {
//console.log('saveSettings() -- active_character -- '+active_character);
if (type == "change_name") { if (type == "change_name") {
name1 = $("#your_name").val(); name1 = $("#your_name").val();
// console.log('beforeSend name1 = '+name1); // 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 //character select
//console.log('select_selected_character() -- starting with input of -- '+chid+' (name:'+characters[chid].name+')'); //console.log('select_selected_character() -- starting with input of -- '+chid+' (name:'+characters[chid].name+')');
select_rm_create(); 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").attr("value", "Save"); // what is the use case for this?
$("#create_button_label").css("display", "none"); $("#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(""); $("#add_avatar_button").val("");
$("#character_popup_text_h3").text(characters[chid].name); $("#character_popup_text_h3").text(characters[chid].name);
@ -3350,17 +3347,14 @@ function select_selected_character(chid) {
$("#personality_textarea").val(characters[chid].personality); $("#personality_textarea").val(characters[chid].personality);
$("#firstmessage_textarea").val(characters[chid].first_mes); $("#firstmessage_textarea").val(characters[chid].first_mes);
$("#scenario_pole").val(characters[chid].scenario); $("#scenario_pole").val(characters[chid].scenario);
$("#talkativeness_slider").val( $("#talkativeness_slider").val(characters[chid].talkativeness ?? talkativeness_default);
characters[chid].talkativeness ?? talkativeness_default
);
$("#mes_example_textarea").val(characters[chid].mes_example); $("#mes_example_textarea").val(characters[chid].mes_example);
$("#selected_chat_pole").val(characters[chid].chat); $("#selected_chat_pole").val(characters[chid].chat);
$("#create_date_pole").val(characters[chid].create_date); $("#create_date_pole").val(characters[chid].create_date);
$("#avatar_url_pole").val(characters[chid].avatar); $("#avatar_url_pole").val(characters[chid].avatar);
$("#chat_import_avatar_url").val(characters[chid].avatar); $("#chat_import_avatar_url").val(characters[chid].avatar);
$("#chat_import_character_name").val(characters[chid].name); $("#chat_import_character_name").val(characters[chid].name);
//$("#avatar_div").css("display", "none"); let this_avatar = default_avatar;
var this_avatar = default_avatar;
if (characters[chid].avatar != "none") { if (characters[chid].avatar != "none") {
this_avatar = getThumbnailUrl('avatar', characters[chid].avatar); this_avatar = getThumbnailUrl('avatar', characters[chid].avatar);
} }
@ -3373,7 +3367,6 @@ function select_selected_character(chid) {
$("#renameCharButton").css("display", ""); $("#renameCharButton").css("display", "");
$("#form_create").attr("actiontype", "editcharacter"); $("#form_create").attr("actiontype", "editcharacter");
active_character = chid;
saveSettingsDebounced(); saveSettingsDebounced();
} }
@ -4072,7 +4065,6 @@ $(document).ready(function () {
this_edit_mes_id = undefined; this_edit_mes_id = undefined;
selected_button = "character_edit"; selected_button = "character_edit";
this_chid = $(this).attr("chid"); this_chid = $(this).attr("chid");
active_character = this_chid;
clearChat(); clearChat();
chat.length = 0; chat.length = 0;
chat_metadata = {}; chat_metadata = {};
@ -4451,11 +4443,12 @@ $(document).ready(function () {
contentType: false, contentType: false,
processData: false, processData: false,
success: function (html) { 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. //currently this updates the displayed H2 name regardless of soft errors, doesn't detect actual errors.
let h2text = $("#character_name_pole").val(); let h2text = $("#character_name_pole").val();
console.log('about to change name! in h2'); console.log('about to change name! in h2');
$("#rm_button_selected_ch").children("h2").text(h2text); $("#rm_button_selected_ch").children("h2").text(h2text);
*/
$(".mes").each(function () { $(".mes").each(function () {
if ($(this).attr("is_system") == 'true') { if ($(this).attr("is_system") == 'true') {
@ -5294,13 +5287,6 @@ $(document).ready(function () {
select_rm_characters(); 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 () { $(document).on("click", ".select_chat_block, .bookmark_link", async function () {
let file_name = $(this).attr("file_name").replace(".jsonl", ""); let file_name = $(this).attr("file_name").replace(".jsonl", "");
openCharacterChat(file_name); openCharacterChat(file_name);

View File

@ -11,7 +11,7 @@ import {
api_server_textgenerationwebui, api_server_textgenerationwebui,
is_send_press, is_send_press,
getTokenCount, getTokenCount,
selected_button, menu_type,
} from "../script.js"; } 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 //when any input is made to the advanced editing popup textareas
$("#character_popup").on("input", function () { RA_CountCharTokens(); }); $("#character_popup").on("input", function () { RA_CountCharTokens(); });
//function: //function:
function RA_CountCharTokens() { export function RA_CountCharTokens() {
$("#result_info").html(""); $("#result_info").html("");
//console.log('RA_TC -- starting with this_chid = ' + this_chid); //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() { function saveFormVariables() {
create_save_name = $("#character_name_pole").val(); create_save_name = $("#character_name_pole").val();
create_save_description = $("#description_textarea").val(); create_save_description = $("#description_textarea").val();

View File

@ -80,7 +80,7 @@ async function moduleWorker() {
const context = getContext(); const context = getContext();
// non-characters not supported // non-characters not supported
if (!context.groupId && !context.characterId) { if (!context.groupId && context.characterId === undefined) {
removeExpression(); removeExpression();
return; return;
} }

View File

@ -66,7 +66,7 @@ function loadSettings() {
async function moduleWorker() { async function moduleWorker() {
const context = getContext(); const context = getContext();
if (!context.groupId && !context.characterId) { if (!context.groupId && context.characterId === undefined) {
return; return;
} }

View File

@ -133,7 +133,7 @@ async function moduleWorker() {
const chat = context.chat; const chat = context.chat;
// no characters or group selected // no characters or group selected
if (!context.groupId && !context.characterId) { if (!context.groupId && context.characterId === undefined) {
return; return;
} }

View File

@ -37,7 +37,7 @@ async function moduleWorker() {
updateUiAudioPlayState() updateUiAudioPlayState()
// no characters or group selected // no characters or group selected
if (!context.groupId && !context.characterId) { if (!context.groupId && context.characterId === undefined) {
return return
} }

View File

@ -4,7 +4,7 @@ import {
debounce, debounce,
delay, delay,
} from './utils.js'; } from './utils.js';
import { humanizedDateTime } from "./RossAscends-mods.js"; import { RA_CountCharTokens, humanizedDateTime } from "./RossAscends-mods.js";
import { sortCharactersList } from './power-user.js'; import { sortCharactersList } from './power-user.js';
import { import {
@ -42,15 +42,17 @@ import {
getThumbnailUrl, getThumbnailUrl,
streamingProcessor, streamingProcessor,
getRequestHeaders, getRequestHeaders,
setMenuType,
menu_type,
select_selected_character,
} from "../script.js"; } from "../script.js";
import { appendTagToList, createTagMapFromList, getTagsList } from './tags.js'; import { appendTagToList, createTagMapFromList, getTagsList, applyTagsOnCharacterSelect } from './tags.js';
export { export {
selected_group, selected_group,
is_group_automode_enabled, is_group_automode_enabled,
is_group_generating, is_group_generating,
group_generation_id, group_generation_id,
group_rm_panel_mode,
groups, groups,
saveGroupChat, saveGroupChat,
generateGroupWrapper, generateGroupWrapper,
@ -69,7 +71,6 @@ let groups = [];
let selected_group = null; let selected_group = null;
let group_generation_id = null; let group_generation_id = null;
let fav_grp_checked = false; let fav_grp_checked = false;
let group_rm_panel_mode;
export const group_activation_strategy = { export const group_activation_strategy = {
NATURAL: 0, NATURAL: 0,
@ -377,6 +378,12 @@ async function generateGroupWrapper(by_auto_mode, type = null) {
return; return;
} }
// Auto-navigate back to group menu
if (menu_type !== "group_edit") {
select_group_chats(selected_group);
await delay(1);
}
if (is_group_generating) { if (is_group_generating) {
return false; return false;
} }
@ -798,7 +805,7 @@ async function reorderGroupMember(chat_id, groupMember, direction) {
function select_group_chats(groupId, skipAnimation) { function select_group_chats(groupId, skipAnimation) {
const group = groupId && groups.find((x) => x.id == groupId); const group = groupId && groups.find((x) => x.id == groupId);
const groupName = group?.name ?? ""; 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").val(groupName);
$("#rm_group_chat_name").off(); $("#rm_group_chat_name").off();
$("#rm_group_chat_name").on("input", async function () { $("#rm_group_chat_name").on("input", async function () {
@ -940,94 +947,119 @@ function updateFavButtonState(state) {
$("#group_favorite_button").toggleClass('fav_off', !fav_grp_checked); $("#group_favorite_button").toggleClass('fav_off', !fav_grp_checked);
} }
$(document).ready(() => { async function selectGroup() {
$(document).on("click", ".group_select", async function () { const groupId = $(this).data("id");
const groupId = $(this).data("id");
if (!is_send_press && !is_group_generating) { if (!is_send_press && !is_group_generating) {
if (selected_group !== groupId) { if (selected_group !== groupId) {
selected_group = groupId; selected_group = groupId;
setCharacterId(undefined); setCharacterId(undefined);
setCharacterName(''); setCharacterName('');
setEditedMessageId(undefined); setEditedMessageId(undefined);
clearChat(); clearChat();
updateChatMetadata({}, true); updateChatMetadata({}, true);
chat.length = 0; chat.length = 0;
await getGroupChat(groupId); await getGroupChat(groupId);
//to avoid the filter being lit up yellow and left at true while the list of character and group reseted. //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"); $("#filter_by_fav").removeClass("fav_on");
filterByFav = false; 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}`;
} }
// placeholder select_group_chats(groupId);
const avatar_url = 'img/five.png'; }
}
const chatName = humanizedDateTime(); function openCharacterDefinition() {
const chats = [chatName]; if (is_group_generating) {
console.warn("Can't peek a character def while group reply is being generated");
return;
}
const createGroupResponse = await fetch("/creategroup", { const characterSelect = $(this).closest('.group_member');
method: "POST", const chid = characterSelect.attr('chid');
headers: getRequestHeaders(),
body: JSON.stringify({ if (chid === null || chid === undefined) {
name: name, return;
members: members, }
avatar_url: avatar_url,
allow_self_responses: allow_self_responses, setCharacterId(chid);
activation_strategy: activation_strategy, select_selected_character(chid, true);
chat_metadata: {}, // Gentle nudge to recalculate tokens
fav: fav_grp_checked, RA_CountCharTokens();
chat_id: chatName, // Do a little tomfoolery to spoof the tag selector
chats: chats, 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) { async function createGroup() {
const data = await createGroupResponse.json(); let name = $("#rm_group_chat_name").val();
createTagMapFromList("#groupTagList", data.id); 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(); const memberNames = characters.filter(x => members.includes(x.avatar)).map(x => x.name).join(", ");
$("#rm_info_avatar").html("");
const avatar = $("#avatar_div_div").clone(); if (!name) {
avatar.find("img").attr("src", avatar_url); name = `Chat with ${memberNames}`;
$("#rm_info_avatar").append(avatar); }
$("#rm_info_block").transition({ opacity: 0, duration: 0 });
select_rm_info("Group chat created"); // placeholder
$("#rm_info_block").transition({ opacity: 1.0, duration: 2000 }); 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 () { $("#rm_group_automode").on("input", function () {
const value = $(this).prop("checked"); const value = $(this).prop("checked");
is_group_automode_enabled = value; is_group_automode_enabled = value;

View File

@ -1,5 +1,5 @@
import { characters, saveSettingsDebounced, this_chid, selected_button, callPopup } from "../script.js"; import { characters, saveSettingsDebounced, this_chid, callPopup, menu_type } from "../script.js";
import { group_rm_panel_mode, selected_group } from "./group-chats.js"; import { selected_group } from "./group-chats.js";
export { export {
tags, tags,
@ -58,11 +58,11 @@ function getTagsList(key) {
} }
function getInlineListSelector() { function getInlineListSelector() {
if (selected_group && group_rm_panel_mode !== "create") { if (selected_group && menu_type === "group_edit") {
return `.group_select[grid="${selected_group}"] .tags`; 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`; return `.character_select[chid="${this_chid}"] .tags`;
} }
@ -70,11 +70,11 @@ function getInlineListSelector() {
} }
function getTagKey() { function getTagKey() {
if (selected_group && group_rm_panel_mode !== "create") { if (selected_group && menu_type === "group_edit") {
return selected_group; return selected_group;
} }
if (this_chid && selected_button !== "create") { if (this_chid && menu_type === "character_edit") {
return characters[this_chid].avatar; return characters[this_chid].avatar;
} }
@ -251,7 +251,7 @@ function onGroupCreateClick() {
$("#groupTagList").empty(); $("#groupTagList").empty();
} }
function onCharacterSelectClick() { export function applyTagsOnCharacterSelect() {
clearTagsFilter(); clearTagsFilter();
const chid = Number($(this).attr('chid')); const chid = Number($(this).attr('chid'));
const key = characters[chid].avatar; const key = characters[chid].avatar;
@ -264,7 +264,7 @@ function onCharacterSelectClick() {
} }
} }
function onGroupSelectClick() { function applyTagsOnGroupSelect() {
clearTagsFilter(); clearTagsFilter();
const key = $(this).attr('grid'); const key = $(this).attr('grid');
const tags = getTagsList(key); const tags = getTagsList(key);
@ -332,8 +332,8 @@ $(document).ready(() => {
$(document).on("click", "#rm_button_create", onCharacterCreateClick); $(document).on("click", "#rm_button_create", onCharacterCreateClick);
$(document).on("click", "#rm_button_group_chats", onGroupCreateClick); $(document).on("click", "#rm_button_group_chats", onGroupCreateClick);
$(document).on("click", ".character_select", onCharacterSelectClick); $(document).on("click", ".character_select", applyTagsOnCharacterSelect);
$(document).on("click", ".group_select", onGroupSelectClick); $(document).on("click", ".group_select", applyTagsOnGroupSelect);
$(document).on("click", ".tag_remove", onTagRemoveClick); $(document).on("click", ".tag_remove", onTagRemoveClick);
$(document).on("input", ".tag_input", onTagInput); $(document).on("input", ".tag_input", onTagInput);
$(document).on("click", ".tags_view", onViewTagsListClick); $(document).on("click", ".tags_view", onViewTagsListClick);