mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-04-14 02:42:08 +02:00
Merge branch 'staging' into webpack
This commit is contained in:
commit
f918b146e7
@ -13,7 +13,7 @@ import {
|
|||||||
default as libs,
|
default as libs,
|
||||||
} from './lib.js';
|
} from './lib.js';
|
||||||
|
|
||||||
import { humanizedDateTime, favsToHotswap, getMessageTimeStamp, dragElement, isMobile, initRossMods, shouldSendOnEnter, addSafariPatch } from './scripts/RossAscends-mods.js';
|
import { humanizedDateTime, favsToHotswap, getMessageTimeStamp, dragElement, isMobile, initRossMods, shouldSendOnEnter } from './scripts/RossAscends-mods.js';
|
||||||
import { userStatsHandler, statMesProcess, initStats } from './scripts/stats.js';
|
import { userStatsHandler, statMesProcess, initStats } from './scripts/stats.js';
|
||||||
import {
|
import {
|
||||||
generateKoboldWithStreaming,
|
generateKoboldWithStreaming,
|
||||||
@ -263,6 +263,7 @@ import { initSystemPrompts } from './scripts/sysprompt.js';
|
|||||||
import { registerExtensionSlashCommands as initExtensionSlashCommands } from './scripts/extensions-slashcommands.js';
|
import { registerExtensionSlashCommands as initExtensionSlashCommands } from './scripts/extensions-slashcommands.js';
|
||||||
import { ToolManager } from './scripts/tool-calling.js';
|
import { ToolManager } from './scripts/tool-calling.js';
|
||||||
import { addShowdownPatch } from './scripts/util/showdown-patch.js';
|
import { addShowdownPatch } from './scripts/util/showdown-patch.js';
|
||||||
|
import { applyBrowserFixes } from './scripts/browser-fixes.js';
|
||||||
|
|
||||||
//exporting functions and vars for mods
|
//exporting functions and vars for mods
|
||||||
export {
|
export {
|
||||||
@ -932,7 +933,7 @@ async function firstLoadInit() {
|
|||||||
initLibraryShims();
|
initLibraryShims();
|
||||||
addShowdownPatch(showdown);
|
addShowdownPatch(showdown);
|
||||||
reloadMarkdownProcessor();
|
reloadMarkdownProcessor();
|
||||||
addSafariPatch();
|
applyBrowserFixes();
|
||||||
await getClientVersion();
|
await getClientVersion();
|
||||||
await readSecretState();
|
await readSecretState();
|
||||||
await initLocales();
|
await initLocales();
|
||||||
|
@ -122,7 +122,7 @@ export function humanizeGenTime(total_gen_time) {
|
|||||||
*/
|
*/
|
||||||
var parsedUA = null;
|
var parsedUA = null;
|
||||||
|
|
||||||
function getParsedUA() {
|
export function getParsedUA() {
|
||||||
if (!parsedUA) {
|
if (!parsedUA) {
|
||||||
try {
|
try {
|
||||||
parsedUA = Bowser.parse(navigator.userAgent);
|
parsedUA = Bowser.parse(navigator.userAgent);
|
||||||
@ -718,18 +718,6 @@ export const autoFitSendTextAreaDebounced = debounce(autoFitSendTextArea, deboun
|
|||||||
|
|
||||||
// ---------------------------------------------------
|
// ---------------------------------------------------
|
||||||
|
|
||||||
export function addSafariPatch() {
|
|
||||||
const userAgent = getParsedUA();
|
|
||||||
console.debug('User Agent', userAgent);
|
|
||||||
const isMobileSafari = /iPad|iPhone|iPod/.test(navigator.platform) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
|
|
||||||
const isDesktopSafari = userAgent?.browser?.name === 'Safari' && userAgent?.platform?.type === 'desktop';
|
|
||||||
const isIOS = userAgent?.os?.name === 'iOS';
|
|
||||||
|
|
||||||
if (isIOS || isMobileSafari || isDesktopSafari) {
|
|
||||||
document.body.classList.add('safari');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function initRossMods() {
|
export function initRossMods() {
|
||||||
// initial status check
|
// initial status check
|
||||||
checkStatusDebounced();
|
checkStatusDebounced();
|
||||||
@ -742,16 +730,6 @@ export function initRossMods() {
|
|||||||
RA_autoconnect();
|
RA_autoconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isMobile()) {
|
|
||||||
const fixFunkyPositioning = () => {
|
|
||||||
console.debug('[Mobile] Device viewport change detected.');
|
|
||||||
document.documentElement.style.position = 'fixed';
|
|
||||||
requestAnimationFrame(() => document.documentElement.style.position = '');
|
|
||||||
};
|
|
||||||
window.addEventListener('resize', fixFunkyPositioning);
|
|
||||||
window.addEventListener('orientationchange', fixFunkyPositioning);
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#main_api').change(function () {
|
$('#main_api').change(function () {
|
||||||
var PrevAPI = main_api;
|
var PrevAPI = main_api;
|
||||||
setTimeout(() => RA_autoconnect(PrevAPI), 100);
|
setTimeout(() => RA_autoconnect(PrevAPI), 100);
|
||||||
@ -934,6 +912,12 @@ export function initRossMods() {
|
|||||||
if (!$(e.target).closest('#sheld').length) {
|
if (!$(e.target).closest('#sheld').length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ($('#curEditTextarea').length) {
|
||||||
|
// Don't swipe while in text edit mode
|
||||||
|
// the ios selection gestures get picked up
|
||||||
|
// as swipe gestures
|
||||||
|
return;
|
||||||
|
}
|
||||||
var SwipeButR = $('.swipe_right:last');
|
var SwipeButR = $('.swipe_right:last');
|
||||||
var SwipeTargetMesClassParent = $(e.target).closest('.last_mes');
|
var SwipeTargetMesClassParent = $(e.target).closest('.last_mes');
|
||||||
if (SwipeTargetMesClassParent !== null) {
|
if (SwipeTargetMesClassParent !== null) {
|
||||||
@ -952,6 +936,12 @@ export function initRossMods() {
|
|||||||
if (!$(e.target).closest('#sheld').length) {
|
if (!$(e.target).closest('#sheld').length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ($('#curEditTextarea').length) {
|
||||||
|
// Don't swipe while in text edit mode
|
||||||
|
// the ios selection gestures get picked up
|
||||||
|
// as swipe gestures
|
||||||
|
return;
|
||||||
|
}
|
||||||
var SwipeButL = $('.swipe_left:last');
|
var SwipeButL = $('.swipe_left:last');
|
||||||
var SwipeTargetMesClassParent = $(e.target).closest('.last_mes');
|
var SwipeTargetMesClassParent = $(e.target).closest('.last_mes');
|
||||||
if (SwipeTargetMesClassParent !== null) {
|
if (SwipeTargetMesClassParent !== null) {
|
||||||
|
77
public/scripts/browser-fixes.js
Normal file
77
public/scripts/browser-fixes.js
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
import { getParsedUA, isMobile } from './RossAscends-mods.js';
|
||||||
|
|
||||||
|
const isFirefox = () => /firefox/i.test(navigator.userAgent);
|
||||||
|
|
||||||
|
function sanitizeInlineQuotationOnCopy() {
|
||||||
|
// STRG+C, STRG+V on firefox leads to duplicate double quotes when inline quotation elements are copied.
|
||||||
|
// To work around this, take the selection and transform <q> to <span> before calling toString().
|
||||||
|
document.addEventListener('copy', function (event) {
|
||||||
|
const selection = window.getSelection();
|
||||||
|
if (!selection.anchorNode?.parentElement.closest('.mes_text')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const range = selection.getRangeAt(0).cloneContents();
|
||||||
|
const tempDOM = document.createDocumentFragment();
|
||||||
|
|
||||||
|
function processNode(node) {
|
||||||
|
if (node.nodeType === Node.ELEMENT_NODE && node.tagName.toLowerCase() === 'q') {
|
||||||
|
// Transform <q> to <span>, preserve children
|
||||||
|
const span = document.createElement('span');
|
||||||
|
|
||||||
|
[...node.childNodes].forEach(child => {
|
||||||
|
const processedChild = processNode(child);
|
||||||
|
span.appendChild(processedChild);
|
||||||
|
});
|
||||||
|
|
||||||
|
return span;
|
||||||
|
} else {
|
||||||
|
// Nested structures containing <q> elements are unlikely
|
||||||
|
return node.cloneNode(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[...range.childNodes].forEach(child => {
|
||||||
|
const processedChild = processNode(child);
|
||||||
|
tempDOM.appendChild(processedChild);
|
||||||
|
});
|
||||||
|
|
||||||
|
const newRange = document.createRange();
|
||||||
|
newRange.selectNodeContents(tempDOM);
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
event.clipboardData.setData('text/plain', newRange.toString());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function addSafariPatch() {
|
||||||
|
const userAgent = getParsedUA();
|
||||||
|
console.debug('User Agent', userAgent);
|
||||||
|
const isMobileSafari = /iPad|iPhone|iPod/.test(navigator.platform) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
|
||||||
|
const isDesktopSafari = userAgent?.browser?.name === 'Safari' && userAgent?.platform?.type === 'desktop';
|
||||||
|
const isIOS = userAgent?.os?.name === 'iOS';
|
||||||
|
|
||||||
|
if (isIOS || isMobileSafari || isDesktopSafari) {
|
||||||
|
document.body.classList.add('safari');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyBrowserFixes() {
|
||||||
|
if (isFirefox()) {
|
||||||
|
sanitizeInlineQuotationOnCopy();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMobile()) {
|
||||||
|
const fixFunkyPositioning = () => {
|
||||||
|
console.debug('[Mobile] Device viewport change detected.');
|
||||||
|
document.documentElement.style.position = 'fixed';
|
||||||
|
requestAnimationFrame(() => document.documentElement.style.position = '');
|
||||||
|
};
|
||||||
|
window.addEventListener('resize', fixFunkyPositioning);
|
||||||
|
window.addEventListener('orientationchange', fixFunkyPositioning);
|
||||||
|
}
|
||||||
|
|
||||||
|
addSafariPatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
export { isFirefox, applyBrowserFixes };
|
@ -19,7 +19,7 @@ import {
|
|||||||
} from '../../../script.js';
|
} from '../../../script.js';
|
||||||
import { getApiUrl, getContext, extension_settings, doExtrasFetch, modules, renderExtensionTemplateAsync, writeExtensionField } from '../../extensions.js';
|
import { getApiUrl, getContext, extension_settings, doExtrasFetch, modules, renderExtensionTemplateAsync, writeExtensionField } from '../../extensions.js';
|
||||||
import { selected_group } from '../../group-chats.js';
|
import { selected_group } from '../../group-chats.js';
|
||||||
import { stringFormat, initScrollHeight, resetScrollHeight, getCharaFilename, saveBase64AsFile, getBase64Async, delay, isTrueBoolean, debounce, isFalseBoolean } from '../../utils.js';
|
import { stringFormat, initScrollHeight, resetScrollHeight, getCharaFilename, saveBase64AsFile, getBase64Async, delay, isTrueBoolean, debounce, isFalseBoolean, deepMerge } from '../../utils.js';
|
||||||
import { getMessageTimeStamp, humanizedDateTime } from '../../RossAscends-mods.js';
|
import { getMessageTimeStamp, humanizedDateTime } from '../../RossAscends-mods.js';
|
||||||
import { SECRET_KEYS, secret_state, writeSecret } from '../../secrets.js';
|
import { SECRET_KEYS, secret_state, writeSecret } from '../../secrets.js';
|
||||||
import { getNovelUnlimitedImageGeneration, getNovelAnlas, loadNovelSubscriptionData } from '../../nai-settings.js';
|
import { getNovelUnlimitedImageGeneration, getNovelAnlas, loadNovelSubscriptionData } from '../../nai-settings.js';
|
||||||
@ -220,6 +220,7 @@ const defaultSettings = {
|
|||||||
// Automatic1111/Horde exclusives
|
// Automatic1111/Horde exclusives
|
||||||
restore_faces: false,
|
restore_faces: false,
|
||||||
enable_hr: false,
|
enable_hr: false,
|
||||||
|
adetailer_face: false,
|
||||||
|
|
||||||
// Horde settings
|
// Horde settings
|
||||||
horde: false,
|
horde: false,
|
||||||
@ -436,6 +437,7 @@ async function loadSettings() {
|
|||||||
$('#sd_horde_sanitize').prop('checked', extension_settings.sd.horde_sanitize);
|
$('#sd_horde_sanitize').prop('checked', extension_settings.sd.horde_sanitize);
|
||||||
$('#sd_restore_faces').prop('checked', extension_settings.sd.restore_faces);
|
$('#sd_restore_faces').prop('checked', extension_settings.sd.restore_faces);
|
||||||
$('#sd_enable_hr').prop('checked', extension_settings.sd.enable_hr);
|
$('#sd_enable_hr').prop('checked', extension_settings.sd.enable_hr);
|
||||||
|
$('#sd_adetailer_face').prop('checked', extension_settings.sd.adetailer_face);
|
||||||
$('#sd_refine_mode').prop('checked', extension_settings.sd.refine_mode);
|
$('#sd_refine_mode').prop('checked', extension_settings.sd.refine_mode);
|
||||||
$('#sd_multimodal_captioning').prop('checked', extension_settings.sd.multimodal_captioning);
|
$('#sd_multimodal_captioning').prop('checked', extension_settings.sd.multimodal_captioning);
|
||||||
$('#sd_auto_url').val(extension_settings.sd.auto_url);
|
$('#sd_auto_url').val(extension_settings.sd.auto_url);
|
||||||
@ -854,6 +856,11 @@ function onSamplerChange() {
|
|||||||
saveSettingsDebounced();
|
saveSettingsDebounced();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onADetailerFaceChange() {
|
||||||
|
extension_settings.sd.adetailer_face = !!$('#sd_adetailer_face').prop('checked');
|
||||||
|
saveSettingsDebounced();
|
||||||
|
}
|
||||||
|
|
||||||
const resolutionOptions = {
|
const resolutionOptions = {
|
||||||
sd_res_512x512: { width: 512, height: 512, name: '512x512 (1:1, icons, profile pictures)' },
|
sd_res_512x512: { width: 512, height: 512, name: '512x512 (1:1, icons, profile pictures)' },
|
||||||
sd_res_600x600: { width: 600, height: 600, name: '600x600 (1:1, icons, profile pictures)' },
|
sd_res_600x600: { width: 600, height: 600, name: '600x600 (1:1, icons, profile pictures)' },
|
||||||
@ -2921,11 +2928,7 @@ async function generateHordeImage(prompt, negativePrompt, signal) {
|
|||||||
*/
|
*/
|
||||||
async function generateAutoImage(prompt, negativePrompt, signal) {
|
async function generateAutoImage(prompt, negativePrompt, signal) {
|
||||||
const isValidVae = extension_settings.sd.vae && !['N/A', placeholderVae].includes(extension_settings.sd.vae);
|
const isValidVae = extension_settings.sd.vae && !['N/A', placeholderVae].includes(extension_settings.sd.vae);
|
||||||
const result = await fetch('/api/sd/generate', {
|
let payload = {
|
||||||
method: 'POST',
|
|
||||||
headers: getRequestHeaders(),
|
|
||||||
signal: signal,
|
|
||||||
body: JSON.stringify({
|
|
||||||
...getSdRequestBody(),
|
...getSdRequestBody(),
|
||||||
prompt: prompt,
|
prompt: prompt,
|
||||||
negative_prompt: negativePrompt,
|
negative_prompt: negativePrompt,
|
||||||
@ -2942,20 +2945,41 @@ async function generateAutoImage(prompt, negativePrompt, signal) {
|
|||||||
denoising_strength: extension_settings.sd.denoising_strength,
|
denoising_strength: extension_settings.sd.denoising_strength,
|
||||||
hr_second_pass_steps: extension_settings.sd.hr_second_pass_steps,
|
hr_second_pass_steps: extension_settings.sd.hr_second_pass_steps,
|
||||||
seed: extension_settings.sd.seed >= 0 ? extension_settings.sd.seed : undefined,
|
seed: extension_settings.sd.seed >= 0 ? extension_settings.sd.seed : undefined,
|
||||||
// For AUTO1111
|
|
||||||
override_settings: {
|
override_settings: {
|
||||||
CLIP_stop_at_last_layers: extension_settings.sd.clip_skip,
|
CLIP_stop_at_last_layers: extension_settings.sd.clip_skip,
|
||||||
sd_vae: isValidVae ? extension_settings.sd.vae : undefined,
|
sd_vae: isValidVae ? extension_settings.sd.vae : undefined,
|
||||||
},
|
},
|
||||||
override_settings_restore_afterwards: true,
|
override_settings_restore_afterwards: true,
|
||||||
// For SD.Next
|
clip_skip: extension_settings.sd.clip_skip, // For SD.Next
|
||||||
clip_skip: extension_settings.sd.clip_skip,
|
|
||||||
// Ensure generated img is saved to disk
|
|
||||||
save_images: true,
|
save_images: true,
|
||||||
send_images: true,
|
send_images: true,
|
||||||
do_not_save_grid: false,
|
do_not_save_grid: false,
|
||||||
do_not_save_samples: false,
|
do_not_save_samples: false,
|
||||||
}),
|
};
|
||||||
|
|
||||||
|
// Conditionally add the ADetailer if adetailer_face is enabled
|
||||||
|
if (extension_settings.sd.adetailer_face) {
|
||||||
|
payload = deepMerge(payload, {
|
||||||
|
alwayson_scripts: {
|
||||||
|
ADetailer: {
|
||||||
|
args: [
|
||||||
|
true, // ad_enable
|
||||||
|
true, // skip_img2img
|
||||||
|
{
|
||||||
|
'ad_model': 'face_yolov8n.pt',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make the fetch call with the payload
|
||||||
|
const result = await fetch('/api/sd/generate', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: getRequestHeaders(),
|
||||||
|
signal: signal,
|
||||||
|
body: JSON.stringify(payload),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
@ -4187,6 +4211,7 @@ jQuery(async () => {
|
|||||||
$('#sd_horde_sanitize').on('input', onHordeSanitizeInput);
|
$('#sd_horde_sanitize').on('input', onHordeSanitizeInput);
|
||||||
$('#sd_restore_faces').on('input', onRestoreFacesInput);
|
$('#sd_restore_faces').on('input', onRestoreFacesInput);
|
||||||
$('#sd_enable_hr').on('input', onHighResFixInput);
|
$('#sd_enable_hr').on('input', onHighResFixInput);
|
||||||
|
$('#sd_adetailer_face').on('change', onADetailerFaceChange);
|
||||||
$('#sd_refine_mode').on('input', onRefineModeInput);
|
$('#sd_refine_mode').on('input', onRefineModeInput);
|
||||||
$('#sd_character_prompt').on('input', onCharacterPromptInput);
|
$('#sd_character_prompt').on('input', onCharacterPromptInput);
|
||||||
$('#sd_character_negative_prompt').on('input', onCharacterNegativePromptInput);
|
$('#sd_character_negative_prompt').on('input', onCharacterNegativePromptInput);
|
||||||
|
@ -356,6 +356,16 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="flex-container marginTopBot5" data-sd-source="auto,vlad">
|
||||||
|
<label for="sd_adetailer_face" class="flex1 checkbox_label" data-i18n="[title]sd_adetailer_face" title="Use ADetailer with face model during the generation. The ADetailer extension must be installed on the backend.">
|
||||||
|
<input id="sd_adetailer_face" type="checkbox" />
|
||||||
|
<small data-i18n="Use ADetailer (Face)">Use ADetailer (Face)</small>
|
||||||
|
</label>
|
||||||
|
<div class="flex1">
|
||||||
|
<!-- I will be useful later! -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="flex-container marginTopBot5" data-sd-source="novel">
|
<div class="flex-container marginTopBot5" data-sd-source="novel">
|
||||||
<label class="flex1 checkbox_label" data-i18n="[title]SMEA versions of samplers are modified to perform better at high resolution." title="SMEA versions of samplers are modified to perform better at high resolution.">
|
<label class="flex1 checkbox_label" data-i18n="[title]SMEA versions of samplers are modified to perform better at high resolution." title="SMEA versions of samplers are modified to perform better at high resolution.">
|
||||||
<input id="sd_novel_sm" type="checkbox" />
|
<input id="sd_novel_sm" type="checkbox" />
|
||||||
|
@ -30,6 +30,38 @@ export const navigation_option = {
|
|||||||
previous: -1000,
|
previous: -1000,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if a value is an object.
|
||||||
|
* @param {any} item The item to check.
|
||||||
|
* @returns {boolean} True if the item is an object, false otherwise.
|
||||||
|
*/
|
||||||
|
function isObject(item) {
|
||||||
|
return (item && typeof item === 'object' && !Array.isArray(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merges properties of two objects. If the property is an object, it will be merged recursively.
|
||||||
|
* @param {object} target The target object
|
||||||
|
* @param {object} source The source object
|
||||||
|
* @returns {object} Merged object
|
||||||
|
*/
|
||||||
|
export function deepMerge(target, source) {
|
||||||
|
let output = Object.assign({}, target);
|
||||||
|
if (isObject(target) && isObject(source)) {
|
||||||
|
Object.keys(source).forEach(key => {
|
||||||
|
if (isObject(source[key])) {
|
||||||
|
if (!(key in target))
|
||||||
|
Object.assign(output, { [key]: source[key] });
|
||||||
|
else
|
||||||
|
output[key] = deepMerge(target[key], source[key]);
|
||||||
|
} else {
|
||||||
|
Object.assign(output, { [key]: source[key] });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
export function escapeHtml(str) {
|
export function escapeHtml(str) {
|
||||||
return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user