mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add group member defs peeking
This commit is contained in:
@@ -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();
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -66,7 +66,7 @@ function loadSettings() {
|
||||
async function moduleWorker() {
|
||||
const context = getContext();
|
||||
|
||||
if (!context.groupId && !context.characterId) {
|
||||
if (!context.groupId && context.characterId === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user