Merge branch 'SillyTavern:staging' into staging

This commit is contained in:
Tony Ribeiro
2023-08-25 00:45:34 +02:00
committed by GitHub
16 changed files with 139 additions and 120 deletions

View File

@@ -98,28 +98,45 @@ export function humanizeGenTime(total_gen_time) {
return time_spent;
}
// Device detection
export const deviceInfo = await getDeviceInfo();
async function getDeviceInfo() {
try {
const deviceInfo = await (await fetch('/deviceinfo')).json();
console.log("Device type: " + deviceInfo?.device?.type);
return deviceInfo;
}
catch {
console.log("Couldn't load device info. Defaulting to desktop");
return { device: { type: 'desktop' } };
}
}
/**
* Checks if the device is a mobile device.
* @returns {boolean} - True if the device is a mobile device, false otherwise.
*/
export function isMobile() {
const mobileTypes = ['smartphone', 'tablet', 'phablet', 'feature phone', 'portable media player'];
const deviceInfo = getDeviceInfo();
return mobileTypes.includes(deviceInfo?.device?.type);
}
/**
* Loads device info from the server. Caches the result in sessionStorage.
* @returns {object} - The device info object.
*/
export function getDeviceInfo() {
let deviceInfo = null;
if (sessionStorage.getItem('deviceInfo')) {
deviceInfo = JSON.parse(sessionStorage.getItem('deviceInfo'));
} else {
$.ajax({
url: '/deviceinfo',
dataType: 'json',
async: false,
cache: true,
success: function (result) {
sessionStorage.setItem('deviceInfo', JSON.stringify(result));
deviceInfo = result;
},
error: function () {
console.log("Couldn't load device info. Defaulting to desktop");
deviceInfo = { device: { type: 'desktop' } };
},
});
}
return deviceInfo;
}
function shouldSendOnEnter() {
if (!power_user) {
return false;
@@ -394,8 +411,8 @@ function isUrlOrAPIKey(string) {
}
function OpenNavPanels() {
if (deviceInfo.device.type === 'desktop') {
const deviceInfo = getDeviceInfo();
if (deviceInfo && deviceInfo.device.type === 'desktop') {
//auto-open R nav if locked and previously open
if (LoadLocalBool("NavLockOn") == true && LoadLocalBool("NavOpened") == true) {
//console.log("RA -- clicking right nav to open");
@@ -669,13 +686,7 @@ export async function initMovingUI() {
// ---------------------------------------------------
jQuery(async function () {
try {
await waitUntilCondition(() => online_status !== undefined, 1000, 10);
} catch {
console.log('Timeout waiting for online_status');
}
export function initRossMods() {
// initial status check
setTimeout(() => {
RA_checkOnlineStatus();
@@ -1070,4 +1081,4 @@ jQuery(async function () {
console.log("Ctrl +" + event.key + " pressed!");
}
}
});
}

View File

@@ -699,10 +699,8 @@ async function runGenerationInterceptors(chat, contextSize) {
}
jQuery(function () {
setTimeout(async function () {
addExtensionsButtonAndMenu();
$("#extensionsMenuButton").css("display", "flex");
}, 100)
addExtensionsButtonAndMenu();
$("#extensionsMenuButton").css("display", "flex");
$("#extensions_connect").on('click', connectClickHandler);
$("#extensions_autoconnect").on('input', autoConnectInputHandler);

View File

@@ -57,7 +57,6 @@ export function getCfgPrompt(guidanceScale, isNegative) {
substituteParams(
chat_metadata[isNegative ? metadataKeys.negative_prompt : metadataKeys.positive_prompt]
)
?.trim()
);
}
@@ -67,7 +66,6 @@ export function getCfgPrompt(guidanceScale, isNegative) {
substituteParams(
isNegative ? charaCfg.negative_prompt : charaCfg.positive_prompt
)
?.trim()
);
}
@@ -76,7 +74,6 @@ export function getCfgPrompt(guidanceScale, isNegative) {
substituteParams(
isNegative ? extension_settings.cfg.global.negative_prompt : extension_settings.cfg.global.positive_prompt
)
?.trim()
);
}

View File

@@ -6,13 +6,13 @@
#expression-wrapper {
display: flex;
height: calc(100vh - 40px);
height: calc(100vh - var(--topBarBlockSize));
width: 100vw;
}
#visual-novel-wrapper {
display: flex;
height: calc(100vh - 40px);
height: calc(100vh - var(--topBarBlockSize));
width: 100vw;
position: relative;
overflow: hidden;
@@ -180,4 +180,4 @@ img.expression.default {
div.expression {
display: none;
}
}
}

View File

@@ -7,8 +7,7 @@ import {
} from "../script.js";
import { SECRET_KEYS, writeSecret } from "./secrets.js";
import { delay } from "./utils.js";
import { deviceInfo } from "./RossAscends-mods.js";
import { power_user } from "./power-user.js";
import { getDeviceInfo } from "./RossAscends-mods.js";
import { autoSelectInstructPreset } from "./instruct-mode.js";
export {
@@ -259,7 +258,8 @@ jQuery(function () {
$("#horde_kudos").on("click", showKudos);
// Not needed on mobile
if (deviceInfo.device.type === 'desktop') {
const deviceInfo = getDeviceInfo();
if (deviceInfo && deviceInfo.device.type === 'desktop') {
$('#horde_model').select2({
width: '100%',
placeholder: 'Select Horde models',

View File

@@ -256,7 +256,12 @@ export function formatInstructModeChat(name, mes, isUser, isNarrator, forceAvata
export function formatInstructModeSystemPrompt(systemPrompt){
if (power_user.instruct.system_sequence) {
const separator = power_user.instruct.wrap ? '\n' : '';
return power_user.instruct.system_sequence + separator + systemPrompt;
if (power_user.instruct.system_sequence.includes("{{sys}}")) {
return power_user.instruct.system_sequence.replace(/{{sys}}/gi, systemPrompt);
} else {
return power_user.instruct.system_sequence + separator + systemPrompt;
}
}
return systemPrompt;

View File

@@ -46,7 +46,7 @@ export {
export const MAX_CONTEXT_DEFAULT = 4096;
const MAX_CONTEXT_UNLOCKED = 65536;
const defaultStoryString = "{{#if system}}{{system}}\n{{/if}}{{#if description}}{{description}}\n{{/if}}{{#if personality}}{{char}}'s personality: {{personality}}\n{{/if}}{{#if scenario}}Scenario: {{scenario}}\n{{/if}}{{#if persona}}{{persona}}\n{{/if}}";
const defaultStoryString = "{{#if system}}{{system}}\n{{/if}}{{#if description}}{{description}}\n{{/if}}{{#if personality}}{{char}}'s personality: {{personality}}\n{{/if}}{{#if scenario}}Scenario: {{scenario}}\n{{/if}}{{#if persona}}{{persona}}\n{{/if}}";
const defaultExampleSeparator = '***';
const defaultChatStart = '***';
@@ -482,9 +482,19 @@ async function applyShadowWidth() {
}
async function applyFontScale() {
async function applyFontScale(type) {
power_user.font_scale = Number(localStorage.getItem(storage_keys.font_scale) ?? 1);
document.documentElement.style.setProperty('--fontScale', power_user.font_scale);
//this is to allow forced setting on page load, theme swap, etc
if (type === 'forced') {
document.documentElement.style.setProperty('--fontScale', power_user.font_scale);
} else {
//this is to prevent the slider from updating page in real time
$("#font_scale").off('mouseup touchend').on('mouseup touchend', () => {
document.documentElement.style.setProperty('--fontScale', power_user.font_scale);
})
}
$("#font_scale_counter").text(power_user.font_scale);
$("#font_scale").val(power_user.font_scale);
}
@@ -522,7 +532,7 @@ async function applyTheme(name) {
key: 'font_scale',
action: async () => {
localStorage.setItem(storage_keys.font_scale, power_user.font_scale);
await applyFontScale();
await applyFontScale('forced');
}
},
{
@@ -641,7 +651,7 @@ async function applyMovingUIPreset(name) {
}
switchUiMode();
applyFontScale();
applyFontScale('forced');
applyThemeColor();
applyChatWidth();
applyAvatarStyle();

View File

@@ -1,5 +1,6 @@
import { getContext } from "./extensions.js";
import { getRequestHeaders } from "../script.js";
import { isMobile } from "./RossAscends-mods.js";
/**
* Pagination status string template.
@@ -38,10 +39,10 @@ export function isDigitsOnly(str) {
/**
* Gets a drag delay for sortable elements. This is to prevent accidental drags when scrolling.
* @returns {number} The delay in milliseconds. 100ms for desktop, 750ms for mobile.
* @returns {number} The delay in milliseconds. 50ms for desktop, 750ms for mobile.
*/
export function getSortableDelay() {
return navigator.maxTouchPoints > 0 ? 750 : 100;
return isMobile() ? 750 : 50;
}
/**

View File

@@ -3,7 +3,7 @@ import { download, debounce, initScrollHeight, resetScrollHeight, parseJsonFile,
import { getContext } from "./extensions.js";
import { NOTE_MODULE_NAME, metadata_keys, shouldWIAddPrompt } from "./authors-note.js";
import { registerSlashCommand } from "./slash-commands.js";
import { deviceInfo } from "./RossAscends-mods.js";
import { getDeviceInfo } from "./RossAscends-mods.js";
import { FILTER_TYPES, FilterHelper } from "./filters.js";
import { getTokenCount } from "./tokenizers.js";
@@ -1621,7 +1621,8 @@ jQuery(() => {
});
// Not needed on mobile
if (deviceInfo.device.type === 'desktop') {
const deviceInfo = getDeviceInfo();
if (deviceInfo && deviceInfo.device.type === 'desktop') {
$('#world_info').select2({
width: '100%',
placeholder: 'No Worlds active. Click here to select.',