mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Merge remote-tracking branch 'upstream/staging' into staging
This commit is contained in:
@@ -36,6 +36,7 @@ import { chat_completion_sources, oai_settings } from './openai.js';
|
||||
import { getTokenCount } from './tokenizers.js';
|
||||
import { textgen_types, textgenerationwebui_settings as textgen_settings } from './textgen-settings.js';
|
||||
|
||||
import Bowser from '../lib/bowser.min.js';
|
||||
|
||||
var RPanelPin = document.getElementById('rm_button_panel_pin');
|
||||
var LPanelPin = document.getElementById('lm_button_panel_pin');
|
||||
@@ -98,43 +99,22 @@ export function humanizeGenTime(total_gen_time) {
|
||||
return time_spent;
|
||||
}
|
||||
|
||||
let parsedUA = null;
|
||||
try {
|
||||
parsedUA = Bowser.parse(navigator.userAgent);
|
||||
} catch {
|
||||
// In case the user agent is an empty string or Bowser can't parse it for some other reason
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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();
|
||||
const mobileTypes = ['mobile', 'tablet'];
|
||||
|
||||
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;
|
||||
return mobileTypes.includes(parsedUA?.platform?.type);
|
||||
}
|
||||
|
||||
function shouldSendOnEnter() {
|
||||
@@ -431,8 +411,7 @@ function RA_autoconnect(PrevApi) {
|
||||
}
|
||||
|
||||
function OpenNavPanels() {
|
||||
const deviceInfo = getDeviceInfo();
|
||||
if (deviceInfo && deviceInfo.device.type === 'desktop') {
|
||||
if (!isMobile()) {
|
||||
//auto-open R nav if locked and previously open
|
||||
if (LoadLocalBool('NavLockOn') == true && LoadLocalBool('NavOpened') == true) {
|
||||
//console.log("RA -- clicking right nav to open");
|
||||
@@ -508,7 +487,7 @@ export function dragElement(elmnt) {
|
||||
|| Number((String(target.height).replace('px', ''))) < 50
|
||||
|| Number((String(target.width).replace('px', ''))) < 50
|
||||
|| power_user.movingUI === false
|
||||
|| isMobile() === true
|
||||
|| isMobile()
|
||||
) {
|
||||
console.debug('aborting mutator');
|
||||
return;
|
||||
@@ -716,7 +695,7 @@ export function dragElement(elmnt) {
|
||||
}
|
||||
|
||||
export async function initMovingUI() {
|
||||
if (isMobile() === false && power_user.movingUI === true) {
|
||||
if (!isMobile() && power_user.movingUI === true) {
|
||||
console.debug('START MOVING UI');
|
||||
dragElement($('#sheld'));
|
||||
dragElement($('#left-nav-panel'));
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { callPopup, chat_metadata, eventSource, event_types, generateQuietPrompt, getCurrentChatId, getRequestHeaders, getThumbnailUrl } from '../script.js';
|
||||
import { callPopup, chat_metadata, eventSource, event_types, generateQuietPrompt, getCurrentChatId, getRequestHeaders, getThumbnailUrl, saveSettingsDebounced } from '../script.js';
|
||||
import { saveMetadataDebounced } from './extensions.js';
|
||||
import { registerSlashCommand } from './slash-commands.js';
|
||||
import { stringFormat } from './utils.js';
|
||||
@@ -6,6 +6,19 @@ import { stringFormat } from './utils.js';
|
||||
const BG_METADATA_KEY = 'custom_background';
|
||||
const LIST_METADATA_KEY = 'chat_backgrounds';
|
||||
|
||||
export let background_settings = {
|
||||
name: '__transparent.png',
|
||||
url: generateUrlParameter('__transparent.png', false),
|
||||
};
|
||||
|
||||
export function loadBackgroundSettings(settings) {
|
||||
let backgroundSettings = settings.background;
|
||||
if (!backgroundSettings || !backgroundSettings.name || !backgroundSettings.url) {
|
||||
backgroundSettings = background_settings;
|
||||
}
|
||||
setBackground(backgroundSettings.name, backgroundSettings.url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the background for the current chat and adds it to the list of custom backgrounds.
|
||||
* @param {{url: string, path:string}} backgroundInfo
|
||||
@@ -141,9 +154,8 @@ function onSelectBackgroundClick() {
|
||||
saveBackgroundMetadata(relativeBgImage);
|
||||
setCustomBackground();
|
||||
highlightLockedBackground();
|
||||
} else {
|
||||
highlightLockedBackground();
|
||||
}
|
||||
highlightLockedBackground();
|
||||
|
||||
const customBg = window.getComputedStyle(document.getElementById('bg_custom')).backgroundImage;
|
||||
|
||||
@@ -157,8 +169,7 @@ function onSelectBackgroundClick() {
|
||||
|
||||
// Fetching to browser memory to reduce flicker
|
||||
fetch(backgroundUrl).then(() => {
|
||||
$('#bg1').css('background-image', relativeBgImage);
|
||||
setBackground(bgFile);
|
||||
setBackground(bgFile, relativeBgImage);
|
||||
}).catch(() => {
|
||||
console.log('Background could not be set: ' + backgroundUrl);
|
||||
});
|
||||
@@ -333,7 +344,7 @@ export async function getBackgrounds() {
|
||||
'': '',
|
||||
}),
|
||||
});
|
||||
if (response.ok === true) {
|
||||
if (response.ok) {
|
||||
const getData = await response.json();
|
||||
//background = getData;
|
||||
//console.log(getData.length);
|
||||
@@ -346,7 +357,7 @@ export async function getBackgrounds() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URL of the background
|
||||
* Gets the CSS URL of the background
|
||||
* @param {Element} block
|
||||
* @returns {string} URL of the background
|
||||
*/
|
||||
@@ -354,6 +365,10 @@ function getUrlParameter(block) {
|
||||
return $(block).closest('.bg_example').data('url');
|
||||
}
|
||||
|
||||
function generateUrlParameter(bg, isCustom) {
|
||||
return isCustom ? `url("${encodeURI(bg)}")` : `url("${getBackgroundPath(bg)}")`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a background template
|
||||
* @param {string} bg Path to background
|
||||
@@ -363,7 +378,7 @@ function getUrlParameter(block) {
|
||||
function getBackgroundFromTemplate(bg, isCustom) {
|
||||
const template = $('#background_template .bg_example').clone();
|
||||
const thumbPath = isCustom ? bg : getThumbnailUrl('bg', bg);
|
||||
const url = isCustom ? `url("${encodeURI(bg)}")` : `url("${getBackgroundPath(bg)}")`;
|
||||
const url = generateUrlParameter(bg, isCustom);
|
||||
const title = isCustom ? bg.split('/').pop() : bg;
|
||||
const friendlyTitle = title.slice(0, title.lastIndexOf('.'));
|
||||
template.attr('title', title);
|
||||
@@ -375,26 +390,11 @@ function getBackgroundFromTemplate(bg, isCustom) {
|
||||
return template;
|
||||
}
|
||||
|
||||
async function setBackground(bg) {
|
||||
jQuery.ajax({
|
||||
type: 'POST', //
|
||||
url: '/api/backgrounds/set', //
|
||||
data: JSON.stringify({
|
||||
bg: bg,
|
||||
}),
|
||||
beforeSend: function () {
|
||||
|
||||
},
|
||||
cache: false,
|
||||
dataType: 'json',
|
||||
contentType: 'application/json',
|
||||
//processData: false,
|
||||
success: function (html) { },
|
||||
error: function (jqXHR, exception) {
|
||||
console.log(exception);
|
||||
console.log(jqXHR);
|
||||
},
|
||||
});
|
||||
async function setBackground(bg, url) {
|
||||
$('#bg1').css('background-image', url);
|
||||
background_settings.name = bg;
|
||||
background_settings.url = url;
|
||||
saveSettingsDebounced();
|
||||
}
|
||||
|
||||
async function delBackground(bg) {
|
||||
@@ -435,8 +435,7 @@ function uploadBackground(formData) {
|
||||
contentType: false,
|
||||
processData: false,
|
||||
success: async function (bg) {
|
||||
setBackground(bg);
|
||||
$('#bg1').css('background-image', `url("${getBackgroundPath(bg)}"`);
|
||||
setBackground(bg, generateUrlParameter(bg, false));
|
||||
await getBackgrounds();
|
||||
highlightNewBackground(bg);
|
||||
},
|
||||
|
@@ -9,7 +9,7 @@ import {
|
||||
} from '../script.js';
|
||||
import { SECRET_KEYS, writeSecret } from './secrets.js';
|
||||
import { delay } from './utils.js';
|
||||
import { getDeviceInfo } from './RossAscends-mods.js';
|
||||
import { isMobile } from './RossAscends-mods.js';
|
||||
import { autoSelectInstructPreset } from './instruct-mode.js';
|
||||
|
||||
export {
|
||||
@@ -41,7 +41,7 @@ const getRequestArgs = () => ({
|
||||
},
|
||||
});
|
||||
|
||||
async function getWorkers() {
|
||||
async function getWorkers(workerType) {
|
||||
const response = await fetch('https://horde.koboldai.net/api/v2/workers?type=text', getRequestArgs());
|
||||
const data = await response.json();
|
||||
return data;
|
||||
@@ -303,8 +303,7 @@ jQuery(function () {
|
||||
$('#horde_kudos').on('click', showKudos);
|
||||
|
||||
// Not needed on mobile
|
||||
const deviceInfo = getDeviceInfo();
|
||||
if (deviceInfo && deviceInfo.device.type === 'desktop') {
|
||||
if (!isMobile()) {
|
||||
$('#horde_model').select2({
|
||||
width: '100%',
|
||||
placeholder: 'Select Horde models',
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { setGenerationParamsFromPreset } from '../script.js';
|
||||
import { getDeviceInfo } from './RossAscends-mods.js';
|
||||
import { isMobile } from './RossAscends-mods.js';
|
||||
import { textgenerationwebui_settings as textgen_settings } from './textgen-settings.js';
|
||||
|
||||
let models = [];
|
||||
@@ -52,8 +52,7 @@ function getMancerModelTemplate(option) {
|
||||
jQuery(function () {
|
||||
$('#mancer_model').on('change', onMancerModelSelect);
|
||||
|
||||
const deviceInfo = getDeviceInfo();
|
||||
if (deviceInfo && deviceInfo.device.type === 'desktop') {
|
||||
if (!isMobile()) {
|
||||
$('#mancer_model').select2({
|
||||
placeholder: 'Select a model',
|
||||
searchInputPlaceholder: 'Search models...',
|
||||
|
@@ -57,7 +57,7 @@ const MAX_CONTEXT_UNLOCKED = 200 * 1024;
|
||||
const MAX_RESPONSE_UNLOCKED = 16 * 1024;
|
||||
const unlockedMaxContextStep = 512;
|
||||
const maxContextMin = 512;
|
||||
const maxContextStep = 256;
|
||||
const maxContextStep = 64;
|
||||
|
||||
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 = '***';
|
||||
@@ -1530,7 +1530,7 @@ async function loadCharListState() {
|
||||
}
|
||||
|
||||
function loadMovingUIState() {
|
||||
if (isMobile() === false
|
||||
if (!isMobile()
|
||||
&& power_user.movingUIState
|
||||
&& power_user.movingUI === true) {
|
||||
console.debug('loading movingUI state');
|
||||
|
@@ -637,9 +637,19 @@ function lenValuesCallback(value) {
|
||||
return parsedValue.length;
|
||||
}
|
||||
|
||||
function randValuesCallback(from, to) {
|
||||
function randValuesCallback(from, to, args) {
|
||||
const range = to - from;
|
||||
return from + Math.random() * range;
|
||||
const value = from + Math.random() * range;
|
||||
if (args.round == 'round') {
|
||||
return Math.round(value);
|
||||
}
|
||||
if (args.round == 'ceil') {
|
||||
return Math.ceil(value);
|
||||
}
|
||||
if (args.round == 'floor') {
|
||||
return Math.floor(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export function registerVariableCommands() {
|
||||
@@ -673,5 +683,5 @@ export function registerVariableCommands() {
|
||||
registerSlashCommand('sqrt', (_, value) => sqrtValuesCallback(value), [], '<span class="monospace">(a)</span> – performs a square root operation of a value and passes the result down the pipe, can use variable names, e.g. <tt>/sqrt i</tt>', true, true);
|
||||
registerSlashCommand('round', (_, value) => roundValuesCallback(value), [], '<span class="monospace">(a)</span> – rounds a value and passes the result down the pipe, can use variable names, e.g. <tt>/round i</tt>', true, true);
|
||||
registerSlashCommand('len', (_, value) => lenValuesCallback(value), [], '<span class="monospace">(a)</span> – gets the length of a value and passes the result down the pipe, can use variable names, e.g. <tt>/len i</tt>', true, true);
|
||||
registerSlashCommand('rand', (args, value) => randValuesCallback(Number(args.from ?? 0), Number(args.to ?? (value.length ? value : 1))), [], '<span class="monospace">(from=number=0 to=number=1)</span> – returns a random number between from and to, e.g. <tt>/rand</tt> or <tt>/rand 10</tt> or <tt>/rand from=5 to=10</tt>', true, true);
|
||||
registerSlashCommand('rand', (args, value) => randValuesCallback(Number(args.from ?? 0), Number(args.to ?? (value.length ? value : 1)), args), [], '<span class="monospace">(from=number=0 to=number=1 round=round|ceil|floor)</span> – returns a random number between from and to, e.g. <tt>/rand</tt> or <tt>/rand 10</tt> or <tt>/rand from=5 to=10</tt>', true, true);
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ import { download, debounce, initScrollHeight, resetScrollHeight, parseJsonFile,
|
||||
import { extension_settings, getContext } from './extensions.js';
|
||||
import { NOTE_MODULE_NAME, metadata_keys, shouldWIAddPrompt } from './authors-note.js';
|
||||
import { registerSlashCommand } from './slash-commands.js';
|
||||
import { getDeviceInfo } from './RossAscends-mods.js';
|
||||
import { isMobile } from './RossAscends-mods.js';
|
||||
import { FILTER_TYPES, FilterHelper } from './filters.js';
|
||||
import { getTokenCount } from './tokenizers.js';
|
||||
import { power_user } from './power-user.js';
|
||||
@@ -896,8 +896,8 @@ function getWorldEntry(name, data, entry) {
|
||||
|
||||
const characterFilter = template.find('select[name="characterFilter"]');
|
||||
characterFilter.data('uid', entry.uid);
|
||||
const deviceInfo = getDeviceInfo();
|
||||
if (deviceInfo && deviceInfo.device.type === 'desktop') {
|
||||
|
||||
if (!isMobile()) {
|
||||
$(characterFilter).select2({
|
||||
width: '100%',
|
||||
placeholder: 'All characters will pull from this entry.',
|
||||
@@ -2551,8 +2551,7 @@ jQuery(() => {
|
||||
$(document).on('click', '.chat_lorebook_button', assignLorebookToChat);
|
||||
|
||||
// Not needed on mobile
|
||||
const deviceInfo = getDeviceInfo();
|
||||
if (deviceInfo && deviceInfo.device.type === 'desktop') {
|
||||
if (!isMobile()) {
|
||||
$('#world_info').select2({
|
||||
width: '100%',
|
||||
placeholder: 'No Worlds active. Click here to select.',
|
||||
|
Reference in New Issue
Block a user