mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge branch 'staging' into persona-improvements
This commit is contained in:
@@ -78,6 +78,7 @@ import { FILTER_TYPES, FilterHelper } from './filters.js';
|
||||
import { isExternalMediaAllowed } from './chats.js';
|
||||
import { POPUP_TYPE, Popup, callGenericPopup } from './popup.js';
|
||||
import { t } from './i18n.js';
|
||||
import { accountStorage } from './util/AccountStorage.js';
|
||||
|
||||
export {
|
||||
selected_group,
|
||||
@@ -292,10 +293,11 @@ export function getGroupNames() {
|
||||
|
||||
/**
|
||||
* Finds the character ID for a group member.
|
||||
* @param {string} arg 0-based member index or character name
|
||||
* @returns {number} 0-based character ID
|
||||
* @param {number|string} arg 0-based member index or character name
|
||||
* @param {Boolean} full Whether to return a key-value object containing extra data
|
||||
* @returns {number|Object} 0-based character ID or key-value object if full is true
|
||||
*/
|
||||
export function findGroupMemberId(arg) {
|
||||
export function findGroupMemberId(arg, full = false) {
|
||||
arg = arg?.trim();
|
||||
|
||||
if (!arg) {
|
||||
@@ -311,15 +313,19 @@ export function findGroupMemberId(arg) {
|
||||
}
|
||||
|
||||
const index = parseInt(arg);
|
||||
const searchByName = isNaN(index);
|
||||
const searchByString = isNaN(index);
|
||||
|
||||
if (searchByName) {
|
||||
const memberNames = group.members.map(x => ({ name: characters.find(y => y.avatar === x)?.name, index: characters.findIndex(y => y.avatar === x) }));
|
||||
const fuse = new Fuse(memberNames, { keys: ['name'] });
|
||||
if (searchByString) {
|
||||
const memberNames = group.members.map(x => ({
|
||||
avatar: x,
|
||||
name: characters.find(y => y.avatar === x)?.name,
|
||||
index: characters.findIndex(y => y.avatar === x),
|
||||
}));
|
||||
const fuse = new Fuse(memberNames, { keys: ['avatar', 'name'] });
|
||||
const result = fuse.search(arg);
|
||||
|
||||
if (!result.length) {
|
||||
console.warn(`WARN: No group member found with name ${arg}`);
|
||||
console.warn(`WARN: No group member found using string ${arg}`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -330,9 +336,11 @@ export function findGroupMemberId(arg) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Triggering group member ${chid} (${arg}) from search result`, result[0]);
|
||||
return chid;
|
||||
} else {
|
||||
console.log(`Targeting group member ${chid} (${arg}) from search result`, result[0]);
|
||||
|
||||
return !full ? chid : { ...{ id: chid }, ...result[0].item };
|
||||
}
|
||||
else {
|
||||
const memberAvatar = group.members[index];
|
||||
|
||||
if (memberAvatar === undefined) {
|
||||
@@ -347,8 +355,14 @@ export function findGroupMemberId(arg) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Triggering group member ${memberAvatar} at index ${index}`);
|
||||
return chid;
|
||||
console.log(`Targeting group member ${memberAvatar} at index ${index}`);
|
||||
|
||||
return !full ? chid : {
|
||||
id: chid,
|
||||
avatar: memberAvatar,
|
||||
name: characters.find(y => y.avatar === memberAvatar)?.name,
|
||||
index: index,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -805,7 +819,6 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) {
|
||||
|
||||
/** @type {any} Caution: JS war crimes ahead */
|
||||
let textResult = '';
|
||||
let typingIndicator = $('#chat .typing_indicator');
|
||||
const group = groups.find((x) => x.id === selected_group);
|
||||
|
||||
if (!group || !Array.isArray(group.members) || !group.members.length) {
|
||||
@@ -821,14 +834,6 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) {
|
||||
setCharacterId(undefined);
|
||||
const userInput = String($('#send_textarea').val());
|
||||
|
||||
if (typingIndicator.length === 0 && !isStreamingEnabled()) {
|
||||
typingIndicator = $(
|
||||
'#typing_indicator_template .typing_indicator',
|
||||
).clone();
|
||||
typingIndicator.hide();
|
||||
$('#chat').append(typingIndicator);
|
||||
}
|
||||
|
||||
// id of this specific batch for regeneration purposes
|
||||
group_generation_id = Date.now();
|
||||
const lastMessage = chat[chat.length - 1];
|
||||
@@ -906,14 +911,6 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) {
|
||||
}
|
||||
await eventSource.emit(event_types.GROUP_MEMBER_DRAFTED, chId);
|
||||
|
||||
if (type !== 'swipe' && type !== 'impersonate' && !isStreamingEnabled()) {
|
||||
// update indicator and scroll down
|
||||
typingIndicator
|
||||
.find('.typing_indicator_name')
|
||||
.text(characters[chId].name);
|
||||
typingIndicator.show();
|
||||
}
|
||||
|
||||
// Wait for generation to finish
|
||||
textResult = await Generate(generateType, { automatic_trigger: by_auto_mode, ...(params || {}) });
|
||||
let messageChunk = textResult?.messageChunk;
|
||||
@@ -930,8 +927,6 @@ async function generateGroupWrapper(by_auto_mode, type = null, params = {}) {
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
typingIndicator.hide();
|
||||
|
||||
is_group_generating = false;
|
||||
setSendButtonState(false);
|
||||
setCharacterId(undefined);
|
||||
@@ -1315,10 +1310,10 @@ function printGroupCandidates() {
|
||||
formatNavigator: PAGINATION_TEMPLATE,
|
||||
showNavigator: true,
|
||||
showSizeChanger: true,
|
||||
pageSize: Number(localStorage.getItem(storageKey)) || 5,
|
||||
pageSize: Number(accountStorage.getItem(storageKey)) || 5,
|
||||
sizeChangerOptions: [5, 10, 25, 50, 100, 200, 500, 1000],
|
||||
afterSizeSelectorChange: function (e) {
|
||||
localStorage.setItem(storageKey, e.target.value);
|
||||
accountStorage.setItem(storageKey, e.target.value);
|
||||
},
|
||||
callback: function (data) {
|
||||
$('#rm_group_add_members').empty();
|
||||
@@ -1342,10 +1337,10 @@ function printGroupMembers() {
|
||||
formatNavigator: PAGINATION_TEMPLATE,
|
||||
showNavigator: true,
|
||||
showSizeChanger: true,
|
||||
pageSize: Number(localStorage.getItem(storageKey)) || 5,
|
||||
pageSize: Number(accountStorage.getItem(storageKey)) || 5,
|
||||
sizeChangerOptions: [5, 10, 25, 50, 100, 200, 500, 1000],
|
||||
afterSizeSelectorChange: function (e) {
|
||||
localStorage.setItem(storageKey, e.target.value);
|
||||
accountStorage.setItem(storageKey, e.target.value);
|
||||
},
|
||||
callback: function (data) {
|
||||
$('.rm_group_members').empty();
|
||||
@@ -1669,12 +1664,12 @@ function updateFavButtonState(state) {
|
||||
export async function openGroupById(groupId) {
|
||||
if (isChatSaving) {
|
||||
toastr.info(t`Please wait until the chat is saved before switching characters.`, t`Your chat is still saving...`);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!groups.find(x => x.id === groupId)) {
|
||||
console.log('Group not found', groupId);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_send_press && !is_group_generating) {
|
||||
@@ -1691,8 +1686,11 @@ export async function openGroupById(groupId) {
|
||||
updateChatMetadata({}, true);
|
||||
chat.length = 0;
|
||||
await getGroupChat(groupId);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function openCharacterDefinition(characterSelect) {
|
||||
|
Reference in New Issue
Block a user