Merge branch 'staging' into parser-followup-2

This commit is contained in:
LenAnderson
2024-07-28 08:32:25 -04:00
36 changed files with 490 additions and 265 deletions

View File

@@ -1387,7 +1387,8 @@ async function getExpressionsList() {
}
// If there was no specific list, or an error, just return the default expressions
return DEFAULT_EXPRESSIONS;
expressionsList = DEFAULT_EXPRESSIONS.filter(e => e !== 'talkinghead').slice();
return expressionsList;
}
const result = await resolveExpressionsList();
@@ -1618,11 +1619,13 @@ async function onClickExpressionRemoveCustom() {
moduleWorker();
}
function onExperesionApiChanged() {
function onExpressionApiChanged() {
const tempApi = this.value;
if (tempApi) {
extension_settings.expressions.api = Number(tempApi);
$('.expression_llm_prompt_block').toggle(extension_settings.expressions.api === EXPRESSION_API.llm);
expressionsList = null;
spriteCache = {};
moduleWorker();
saveSettingsDebounced();
}
@@ -1972,7 +1975,7 @@ function migrateSettings() {
$('#expression_custom_add').on('click', onClickExpressionAddCustom);
$('#expression_custom_remove').on('click', onClickExpressionRemoveCustom);
$('#expression_fallback').on('change', onExpressionFallbackChanged);
$('#expression_api').on('change', onExperesionApiChanged);
$('#expression_api').on('change', onExpressionApiChanged);
}
// Pause Talkinghead to save resources when the ST tab is not visible or the window is minimized.

View File

@@ -3,6 +3,7 @@ import {
this_chid,
characters,
getRequestHeaders,
event_types,
} from '../../../script.js';
import { groups, selected_group } from '../../group-chats.js';
import { loadFileToDocument, delay } from '../../utils.js';
@@ -25,6 +26,27 @@ let paginationVisiblePages = 10;
let paginationMaxLinesPerPage = 2;
let galleryMaxRows = 3;
$('body').on('click', '.dragClose', function () {
const relatedId = $(this).data('related-id'); // Get the ID of the related draggable
$(`body > .draggable[id="${relatedId}"]`).remove(); // Remove the associated draggable
});
const CUSTOM_GALLERY_REMOVED_EVENT = 'galleryRemoved';
const mutationObserver = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
mutation.removedNodes.forEach((node) => {
if (node instanceof HTMLElement && node.tagName === 'DIV' && node.id === 'gallery') {
eventSource.emit(CUSTOM_GALLERY_REMOVED_EVENT);
}
});
});
});
mutationObserver.observe(document.body, {
childList: true,
subtree: false,
});
/**
* Retrieves a list of gallery items based on a given URL. This function calls an API endpoint
@@ -59,7 +81,9 @@ async function getGalleryItems(url) {
* @returns {Promise<void>} - Promise representing the completion of the gallery initialization.
*/
async function initGallery(items, url) {
const nonce = `nonce-${Math.random().toString(36).substring(2, 15)}`;
const gallery = $('#dragGallery');
gallery.addClass(nonce);
gallery.nanogallery2({
'items': items,
thumbnailWidth: 'auto',
@@ -82,16 +106,26 @@ async function initGallery(items, url) {
fnThumbnailOpen: viewWithDragbox,
});
eventSource.on('resizeUI', function (elmntName) {
gallery.nanogallery2('resize');
});
const dragDropHandler = new DragAndDropHandler('#dragGallery', async (files, event) => {
const dragDropHandler = new DragAndDropHandler(`#dragGallery.${nonce}`, async (files, event) => {
let file = files[0];
uploadFile(file, url); // Added url parameter to know where to upload
});
const resizeHandler = function () {
gallery.nanogallery2('resize');
};
eventSource.on('resizeUI', resizeHandler);
eventSource.once(event_types.CHAT_CHANGED, function () {
gallery.closest('#gallery').remove();
});
eventSource.once(CUSTOM_GALLERY_REMOVED_EVENT, function () {
gallery.nanogallery2('destroy');
dragDropHandler.destroy();
eventSource.removeListener('resizeUI', resizeHandler);
});
// Set dropzone height to be the same as the parent
gallery.css('height', gallery.parent().css('height'));
@@ -140,16 +174,10 @@ async function showCharGallery() {
const items = await getGalleryItems(url);
// if there already is a gallery, destroy it and place this one in its place
if ($('#dragGallery').length) {
$('#dragGallery').nanogallery2('destroy');
initGallery(items, url);
} else {
makeMovable();
setTimeout(async () => {
await initGallery(items, url);
}, 100);
}
$('#dragGallery').closest('#gallery').remove();
makeMovable();
await delay(100);
await initGallery(items, url);
} catch (err) {
console.trace();
console.error(err);
@@ -202,11 +230,11 @@ async function uploadFile(file, url) {
toastr.success('File uploaded successfully. Saved at: ' + result.path);
// Refresh the gallery
$('#dragGallery').nanogallery2('destroy'); // Destroy old gallery
const newItems = await getGalleryItems(url); // Fetch the latest items
initGallery(newItems, url); // Reinitialize the gallery with new items and pass 'url'
$('#dragGallery').closest('#gallery').remove(); // Destroy old gallery
makeMovable();
await delay(100);
await initGallery(newItems, url); // Reinitialize the gallery with new items and pass 'url'
} catch (error) {
console.error('There was an issue uploading the file:', error);
@@ -273,11 +301,6 @@ function makeMovable(id = 'gallery') {
e.preventDefault();
return false;
});
$('body').on('click', '.dragClose', function () {
const relatedId = $(this).data('related-id'); // Get the ID of the related draggable
$(`#${relatedId}`).remove(); // Remove the associated draggable
});
}
/**
@@ -358,11 +381,6 @@ function makeDragImg(id, url) {
} else {
console.error('Failed to append the template content or retrieve the appended content.');
}
$('body').on('click', '.dragClose', function () {
const relatedId = $(this).data('related-id'); // Get the ID of the related draggable
$(`#${relatedId}`).remove(); // Remove the associated draggable
});
}
/**
@@ -401,7 +419,8 @@ function viewWithDragbox(items) {
// Registers a simple command for opening the char gallery.
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'show-gallery',
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'show-gallery',
aliases: ['sg'],
callback: () => {
showCharGallery();
@@ -409,7 +428,8 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'show-gallery
},
helpString: 'Shows the gallery.',
}));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'list-gallery',
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'list-gallery',
aliases: ['lg'],
callback: listGalleryCommand,
returns: 'list of images',
@@ -432,14 +452,14 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'list-gallery
async function listGalleryCommand(args) {
try {
let url = args.char ?? (args.group ? groups.find(it=>it.name == args.group)?.id : null) ?? (selected_group || this_chid);
let url = args.char ?? (args.group ? groups.find(it => it.name == args.group)?.id : null) ?? (selected_group || this_chid);
if (!args.char && !args.group && !selected_group && this_chid) {
const char = characters[this_chid];
url = char.avatar.replace('.png', '');
}
const items = await getGalleryItems(url);
return JSON.stringify(items.map(it=>it.src));
return JSON.stringify(items.map(it => it.src));
} catch (err) {
console.trace();

View File

@@ -5,7 +5,7 @@
"optional": [
],
"js": "index.js",
"css": "",
"css": "style.css",
"author": "City-Unit",
"version": "1.5.0",
"homePage": "https://github.com/SillyTavern/SillyTavern"

View File

@@ -0,0 +1,5 @@
.nGY2 .nGY2GalleryBottom {
display: flex;
align-items: center;
justify-content: center;
}

View File

@@ -14,6 +14,7 @@ import {
substituteParamsExtended,
generateRaw,
getMaxContextSize,
setExtensionPrompt,
} from '../../../script.js';
import { is_group_generating, selected_group } from '../../group-chats.js';
import { loadMovingUIState } from '../../power-user.js';
@@ -73,6 +74,7 @@ const defaultSettings = {
template: defaultTemplate,
position: extension_prompt_types.IN_PROMPT,
role: extension_prompt_roles.SYSTEM,
scan: false,
depth: 2,
promptWords: 200,
promptMinWords: 25,
@@ -122,6 +124,7 @@ function loadSettings() {
$(`input[name="memory_prompt_builder"][value="${extension_settings.memory.prompt_builder}"]`).prop('checked', true).trigger('input');
$('#memory_override_response_length').val(extension_settings.memory.overrideResponseLength).trigger('input');
$('#memory_max_messages_per_request').val(extension_settings.memory.maxMessagesPerRequest).trigger('input');
$('#memory_include_wi_scan').prop('checked', extension_settings.memory.scan).trigger('input');
switchSourceControls(extension_settings.memory.source);
}
@@ -279,6 +282,13 @@ function onMemoryPositionChange(e) {
saveSettingsDebounced();
}
function onMemoryIncludeWIScanInput() {
const value = !!$(this).prop('checked');
extension_settings.memory.scan = value;
reinsertMemory();
saveSettingsDebounced();
}
function onMemoryPromptWordsForceInput() {
const value = $(this).val();
extension_settings.memory.promptForceWords = Number(value);
@@ -800,8 +810,7 @@ function reinsertMemory() {
* @param {number|null} index Index of the chat message to save the summary to. If null, the pre-last message is used.
*/
function setMemoryContext(value, saveToMessage, index = null) {
const context = getContext();
context.setExtensionPrompt(MODULE_NAME, formatMemoryValue(value), extension_settings.memory.position, extension_settings.memory.depth, false, extension_settings.memory.role);
setExtensionPrompt(MODULE_NAME, formatMemoryValue(value), extension_settings.memory.position, extension_settings.memory.depth, extension_settings.memory.scan, extension_settings.memory.role);
$('#memory_contents').val(value);
const summaryLog = value
@@ -809,6 +818,7 @@ function setMemoryContext(value, saveToMessage, index = null) {
: 'Summary has no content';
console.debug(summaryLog);
const context = getContext();
if (saveToMessage && context.chat.length) {
const idx = index ?? context.chat.length - 2;
const mes = context.chat[idx < 0 ? 0 : idx];
@@ -894,6 +904,7 @@ function setupListeners() {
$('#memory_prompt_words_auto').off('click').on('click', onPromptForceWordsAutoClick);
$('#memory_override_response_length').off('click').on('input', onOverrideResponseLengthInput);
$('#memory_max_messages_per_request').off('click').on('input', onMaxMessagesPerRequestInput);
$('#memory_include_wi_scan').off('input').on('input', onMemoryIncludeWIScanInput);
$('#summarySettingsBlockToggle').off('click').on('click', function () {
console.log('saw settings button click');
$('#summarySettingsBlock').slideToggle(200, 'swing'); //toggleClass("hidden");

View File

@@ -109,7 +109,16 @@
<textarea id="memory_template" class="text_pole textarea_compact" rows="2" data-i18n="[placeholder]ext_sum_memory_template_placeholder" placeholder="&lcub;&lcub;summary&rcub;&rcub; will resolve to the current summary contents."></textarea>
</div>
<label for="memory_position" data-i18n="ext_sum_injection_position">Injection Position</label>
<label class="checkbox_label" for="memory_include_wi_scan" data-i18n="[title]ext_sum_include_wi_scan_desc" title="Include the latest summary in the WI scan.">
<input id="memory_include_wi_scan" type="checkbox" />
<span data-i18n="ext_sum_include_wi_scan">Include in World Info Scanning</span>
</label>
<div class="radio_group">
<label>
<input type="radio" name="memory_position" value="-1" />
<span data-i18n="None (not injected)">None (not injected)</span>
<i class="fa-solid fa-info-circle" title="The summary will not be injected into the prompt. You can still access it via the &lcub;&lcub;summary&rcub;&rcub; macro." data-i18n="[title]ext_sum_injection_position_none"></i>
</label>
<label>
<input type="radio" name="memory_position" value="2" />
<span data-i18n="Before Main Prompt / Story String">Before Main Prompt / Story String</span>

View File

@@ -335,8 +335,8 @@
flex-direction: column;
}
body .popup:has(#qr--modalEditor) .popup-content > #qr--modalEditor > #qr--main > .qr--modal-messageContainer > #qr--modal-messageHolder {
min-height: 50svh;
height: 50svh;
min-height: 50dvh;
height: 50dvh;
}
}
.popup:has(#qr--modalEditor) {

View File

@@ -395,8 +395,8 @@
}
>#qr--main>.qr--modal-messageContainer>#qr--modal-messageHolder {
min-height: 50svh;
height: 50svh;
min-height: 50dvh;
height: 50dvh;
}
}
}