Merge branch 'staging' into parser-followup-2

This commit is contained in:
LenAnderson
2024-06-23 18:39:28 -04:00
7 changed files with 51 additions and 23 deletions

View File

@ -2877,11 +2877,12 @@
</div>
<h4 data-i18n="Enter a Model ID">Enter a Model ID</h4>
<div class="flex-container">
<input id="custom_model_id" class="text_pole wide100p" maxlength="500" value="" autocomplete="off" data-i18n="[placeholder]Example: gpt-3.5-turbo" placeholder="Example: gpt-3.5-turbo">
<input list="model_custom_select_fill" id="custom_model_id" class="text_pole wide100p" maxlength="500" value="" autocomplete="off" data-i18n="[placeholder]Example: gpt-3.5-turbo" placeholder="Example: gpt-3.5-turbo">
<datalist id="model_custom_select_fill" class="text_pole model_custom_select"></datalist>
</div>
<h4 data-i18n="Available Models">Available Models</h4>
<div class="flex-container">
<select id="model_custom_select" class="text_pole"></select>
<select id="model_custom_select" class="text_pole model_custom_select"></select>
</div>
<h4 data-i18n="Prompt Post-Processing">Prompt Post-Processing</h4>
<select id="custom_prompt_post_processing" class="text_pole" title="Applies additional processing to the prompt before sending it to the API." data-i18n="[title]Applies additional processing to the prompt before sending it to the API.">
@ -4853,7 +4854,7 @@
<div class="popup-content">
<h3 class="popup-header">text</h3>
</div>
<textarea class="popup-input text_pole result-control" rows="1" data-result="1"></textarea>
<textarea class="popup-input text_pole result-control" rows="1" data-result="1" data-result-event="submit"></textarea>
<div class="popup-controls">
<div class="popup-button-ok menu_button result-control" data-result="1" data-i18n="Delete">Delete</div>
<div class="popup-button-cancel menu_button result-control" data-result="0" data-i18n="Cancel">Cancel</div>

View File

@ -1551,10 +1551,10 @@ function saveModelList(data) {
}
if (oai_settings.chat_completion_source == chat_completion_sources.CUSTOM) {
$('#model_custom_select').empty();
$('#model_custom_select').append('<option value="">None</option>');
$('.model_custom_select').empty();
$('.model_custom_select').append('<option value="">None</option>');
model_list.forEach((model) => {
$('#model_custom_select').append(
$('.model_custom_select').append(
$('<option>', {
value: model.id,
text: model.id,
@ -3164,7 +3164,7 @@ async function getStatusOpen() {
}
if (oai_settings.chat_completion_source === chat_completion_sources.CUSTOM) {
$('#model_custom_select').empty();
$('.model_custom_select').empty();
data.custom_url = oai_settings.custom_url;
data.custom_include_headers = oai_settings.custom_include_headers;
}

View File

@ -69,7 +69,7 @@ const showPopupHelper = {
const value = await popup.show();
return value ? String(value) : null;
},
}
};
export class Popup {
/** @type {POPUP_TYPE} */ type;
@ -188,6 +188,7 @@ export class Popup {
case POPUP_TYPE.DISPLAY: {
this.controls.style.display = 'none';
this.closeButton.style.display = 'block';
break;
}
default: {
console.warn('Unknown popup type.', type);
@ -216,7 +217,7 @@ export class Popup {
this.dlg.addEventListener('focusin', (evt) => { if (evt.target instanceof HTMLElement && evt.target != this.dlg) this.lastFocus = evt.target; });
// Bind event listeners for all result controls to their defined event type
this.dlg.querySelectorAll(`[data-result]`).forEach(resultControl => {
this.dlg.querySelectorAll('[data-result]').forEach(resultControl => {
if (!(resultControl instanceof HTMLElement)) return;
const result = Number(resultControl.dataset.result);
if (isNaN(result)) throw new Error('Invalid result control. Result must be a number. ' + resultControl.dataset.result);
@ -284,7 +285,7 @@ export class Popup {
runAfterAnimation(this.dlg, () => {
this.dlg.removeAttribute('opening');
})
});
this.promise = new Promise((resolve) => {
this.resolver = resolve;
@ -431,7 +432,7 @@ export class Popup {
getTopmostModalLayer() {
return getTopmostModalLayer();
},
}
};
}
class PopupUtils {

View File

@ -76,7 +76,7 @@ export class SlashCommandArgument {
this.forceEnum = forceEnum;
// If no enums were set explictly and the type is one where we know possible enum values, we set them here
if (!this.enumList.length && this.typeList.includes(ARGUMENT_TYPE.BOOLEAN)) this.enumList = commonEnumProviders.boolean()();
if (!this.enumList.length && this.typeList.length === 1 && this.typeList.includes(ARGUMENT_TYPE.BOOLEAN)) this.enumList = commonEnumProviders.boolean()();
}
}

View File

@ -623,6 +623,25 @@ export function isFalseBoolean(arg) {
return ['off', 'false', '0'].includes(arg?.trim()?.toLowerCase());
}
/**
* Parses an array either as a comma-separated string or as a JSON array.
* @param {string} value String to parse
* @returns {string[]} The parsed array.
*/
export function parseStringArray(value) {
if (!value || typeof value !== 'string') return [];
try {
const parsedValue = JSON.parse(value);
if (!Array.isArray(parsedValue)) {
throw new Error('Not an array');
}
return parsedValue.map(x => String(x));
} catch (e) {
return value.split(',').map(x => x.trim()).filter(x => x);
}
}
/**
* Checks if a number is odd.
* @param {number} number The number to check.
@ -1539,8 +1558,8 @@ export function flashHighlight(element, timespan = 2000) {
* @returns {boolean} Whether the control has an animation applied
*/
export function hasAnimation(control) {
const animatioName = getComputedStyle(control, null)["animation-name"];
return animatioName != "none";
const animatioName = getComputedStyle(control, null)['animation-name'];
return animatioName != 'none';
}
/**

View File

@ -1,5 +1,5 @@
import { saveSettings, callPopup, substituteParams, getRequestHeaders, chat_metadata, this_chid, characters, saveCharacterDebounced, menu_type, eventSource, event_types, getExtensionPromptByName, saveMetadata, getCurrentChatId, extension_prompt_roles } from '../script.js';
import { download, debounce, initScrollHeight, resetScrollHeight, parseJsonFile, extractDataFromPng, getFileBuffer, getCharaFilename, getSortableDelay, escapeRegex, PAGINATION_TEMPLATE, navigation_option, waitUntilCondition, isTrueBoolean, setValueByPath, flashHighlight, select2ModifyOptions, getSelect2OptionId, dynamicSelect2DataViaAjax, highlightRegex, select2ChoiceClickSubscribe, isFalseBoolean, equalsIgnoreCaseAndAccents, getSanitizedFilename, checkOverwriteExistingData } from './utils.js';
import { download, debounce, initScrollHeight, resetScrollHeight, parseJsonFile, extractDataFromPng, getFileBuffer, getCharaFilename, getSortableDelay, escapeRegex, PAGINATION_TEMPLATE, navigation_option, waitUntilCondition, isTrueBoolean, setValueByPath, flashHighlight, select2ModifyOptions, getSelect2OptionId, dynamicSelect2DataViaAjax, highlightRegex, select2ChoiceClickSubscribe, isFalseBoolean, equalsIgnoreCaseAndAccents, getSanitizedFilename, checkOverwriteExistingData, parseStringArray } from './utils.js';
import { extension_settings, getContext } from './extensions.js';
import { NOTE_MODULE_NAME, metadata_keys, shouldWIAddPrompt } from './authors-note.js';
import { isMobile } from './RossAscends-mods.js';
@ -7,7 +7,6 @@ import { FILTER_TYPES, FilterHelper } from './filters.js';
import { getTokenCountAsync } from './tokenizers.js';
import { power_user } from './power-user.js';
import { getTagKeyForEntity } from './tags.js';
import { resolveVariable } from './variables.js';
import { debounce_timeout } from './constants.js';
import { getRegexedString, regex_placement } from './extensions/regex/engine.js';
import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
@ -545,7 +544,7 @@ function registerWorldInfoSlashCommands() {
}
async function findBookEntryCallback(args, value) {
const file = resolveVariable(args.file);
const file = args.file;
const field = args.field || 'key';
const entries = await getEntriesFromFile(file);
@ -589,7 +588,7 @@ function registerWorldInfoSlashCommands() {
}
async function getEntryFieldCallback(args, uid) {
const file = resolveVariable(args.file);
const file = args.file;
const field = args.field || 'content';
const entries = await getEntriesFromFile(file);
@ -617,14 +616,14 @@ function registerWorldInfoSlashCommands() {
}
if (Array.isArray(fieldValue)) {
return fieldValue.map(x => substituteParams(x)).join(', ');
return JSON.stringify(fieldValue.map(x => substituteParams(x)));
}
return substituteParams(String(fieldValue));
}
async function createEntryCallback(args, content) {
const file = resolveVariable(args.file);
const file = args.file;
const key = args.key;
const data = await loadWorldInfoData(file);
@ -653,8 +652,8 @@ function registerWorldInfoSlashCommands() {
}
async function setEntryFieldCallback(args, value) {
const file = resolveVariable(args.file);
const uid = resolveVariable(args.uid);
const file = args.file;
const uid = args.uid;
const field = args.field || 'content';
if (value === undefined) {
@ -684,7 +683,7 @@ function registerWorldInfoSlashCommands() {
}
if (Array.isArray(entry[field])) {
entry[field] = value.split(',').map(x => x.trim()).filter(x => x);
entry[field] = parseStringArray(value);
} else if (typeof entry[field] === 'boolean') {
entry[field] = isTrueBoolean(value);
} else if (typeof entry[field] === 'number') {

View File

@ -3149,6 +3149,14 @@ grammarly-extension {
.wider_dialogue_popup {
min-width: 750px;
max-width: 90%;
}
/* If doesn't fit 750px in 90% of the screen, we should re-scale the wider popup */
@media (max-width: calc(750px / 0.9)) {
.wider_dialogue_popup {
min-width: 90%;
}
}
.transparent_dialogue_popup {