Merge branch 'staging' into erew123/release

This commit is contained in:
Cohee 2024-01-18 02:35:26 +02:00
commit 05d292e055
5 changed files with 57 additions and 31 deletions

View File

@ -1302,7 +1302,7 @@
<input class="neo-range-input" type="number" min="0" max="5" step="1" data-for="prompt_log_probs_aphrodite" id="prompt_log_probs_aphrodite_counter_textgenerationwebui"> <input class="neo-range-input" type="number" min="0" max="5" step="1" data-for="prompt_log_probs_aphrodite" id="prompt_log_probs_aphrodite_counter_textgenerationwebui">
</div> </div>
--> -->
<div data-newbie-hidden name="dynaTempBlock" class="wide100p"> <div data-newbie-hidden data-tg-type="ooba, koboldcpp" name="dynaTempBlock" class="wide100p">
<h4 class="wide100p textAlignCenter" data-i18n="DynaTemp"> <h4 class="wide100p textAlignCenter" data-i18n="DynaTemp">
<div class="flex-container alignitemscenter" style="justify-content: center;"> <div class="flex-container alignitemscenter" style="justify-content: center;">
<div class="checkbox_label" for="dynatemp_textgenerationwebui"> <div class="checkbox_label" for="dynatemp_textgenerationwebui">

View File

@ -248,9 +248,9 @@ export class QuickReplyApi {
if (!qr) { if (!qr) {
throw new Error(`No quick reply with label "${label}" in set "${setName}" found.`); throw new Error(`No quick reply with label "${label}" in set "${setName}" found.`);
} }
qr.label = newLabel ?? qr.label; qr.updateLabel(newLabel ?? qr.label);
qr.message = message ?? qr.message; qr.updateMessage(message ?? qr.message);
qr.title = title ?? qr.title; qr.updateTitle(title ?? qr.title);
qr.isHidden = isHidden ?? qr.isHidden; qr.isHidden = isHidden ?? qr.isHidden;
qr.executeOnStartup = executeOnStartup ?? qr.executeOnStartup; qr.executeOnStartup = executeOnStartup ?? qr.executeOnStartup;
qr.executeOnUser = executeOnUser ?? qr.executeOnUser; qr.executeOnUser = executeOnUser ?? qr.executeOnUser;

View File

@ -58,6 +58,10 @@ const defaultSettings = {
}; };
/** @type {Boolean}*/
let isReady = false;
/** @type {Function[]}*/
let executeQueue = [];
/** @type {QuickReplySettings}*/ /** @type {QuickReplySettings}*/
let settings; let settings;
/** @type {SettingsUi} */ /** @type {SettingsUi} */
@ -144,6 +148,16 @@ const loadSettings = async () => {
} }
}; };
const executeIfReadyElseQueue = async (functionToCall, args) => {
if (isReady) {
log('calling', { functionToCall, args });
await functionToCall(...args);
} else {
log('queueing', { functionToCall, args });
executeQueue.push(async()=>await functionToCall(...args));
}
};
@ -183,9 +197,20 @@ const init = async () => {
slash.init(); slash.init();
autoExec = new AutoExecuteHandler(settings); autoExec = new AutoExecuteHandler(settings);
log('executing startup');
await autoExec.handleStartup(); await autoExec.handleStartup();
log('/executing startup');
log(`executing queue (${executeQueue.length} items)`);
while (executeQueue.length > 0) {
const func = executeQueue.shift();
await func();
}
log('/executing queue');
isReady = true;
log('READY');
}; };
eventSource.on(event_types.APP_READY, init); init();
const onChatChanged = async (chatIdx) => { const onChatChanged = async (chatIdx) => {
log('CHAT_CHANGED', chatIdx); log('CHAT_CHANGED', chatIdx);
@ -199,14 +224,14 @@ const onChatChanged = async (chatIdx) => {
await autoExec.handleChatChanged(); await autoExec.handleChatChanged();
}; };
eventSource.on(event_types.CHAT_CHANGED, onChatChanged); eventSource.on(event_types.CHAT_CHANGED, (...args)=>executeIfReadyElseQueue(onChatChanged, args));
const onUserMessage = async () => { const onUserMessage = async () => {
await autoExec.handleUser(); await autoExec.handleUser();
}; };
eventSource.on(event_types.USER_MESSAGE_RENDERED, onUserMessage); eventSource.on(event_types.USER_MESSAGE_RENDERED, (...args)=>executeIfReadyElseQueue(onUserMessage, args));
const onAiMessage = async () => { const onAiMessage = async () => {
await autoExec.handleAi(); await autoExec.handleAi();
}; };
eventSource.on(event_types.CHARACTER_MESSAGE_RENDERED, onAiMessage); eventSource.on(event_types.CHARACTER_MESSAGE_RENDERED, (...args)=>executeIfReadyElseQueue(onAiMessage, args));

View File

@ -1,4 +1,5 @@
import { registerSlashCommand } from '../../../slash-commands.js'; import { registerSlashCommand } from '../../../slash-commands.js';
import { isTrueBoolean } from '../../../utils.js';
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
import { QuickReplyApi } from '../api/QuickReplyApi.js'; import { QuickReplyApi } from '../api/QuickReplyApi.js';
@ -35,7 +36,7 @@ export class SlashCommandHandler {
user - bool - auto execute on user message, e.g., user=true user - bool - auto execute on user message, e.g., user=true
bot - bool - auto execute on AI message, e.g., bot=true bot - bool - auto execute on AI message, e.g., bot=true
load - bool - auto execute on chat load, e.g., load=true load - bool - auto execute on chat load, e.g., load=true
title - bool - title / tooltip to be shown on button, e.g., title="My Fancy Button" title - string - title / tooltip to be shown on button, e.g., title="My Fancy Button"
`.trim(); `.trim();
const qrUpdateArgs = ` const qrUpdateArgs = `
newlabel - string - new text for the button, e.g. newlabel=MyRenamedButton newlabel - string - new text for the button, e.g. newlabel=MyRenamedButton
@ -90,14 +91,14 @@ export class SlashCommandHandler {
toggleGlobalSet(name, args = {}) { toggleGlobalSet(name, args = {}) {
try { try {
this.api.toggleGlobalSet(name, JSON.parse(args.visible ?? 'true') === true); this.api.toggleGlobalSet(name, isTrueBoolean(args.visible ?? 'true'));
} catch (ex) { } catch (ex) {
toastr.error(ex.message); toastr.error(ex.message);
} }
} }
addGlobalSet(name, args = {}) { addGlobalSet(name, args = {}) {
try { try {
this.api.addGlobalSet(name, JSON.parse(args.visible ?? 'true') === true); this.api.addGlobalSet(name, isTrueBoolean(args.visible ?? 'true'));
} catch (ex) { } catch (ex) {
toastr.error(ex.message); toastr.error(ex.message);
} }
@ -113,14 +114,14 @@ export class SlashCommandHandler {
toggleChatSet(name, args = {}) { toggleChatSet(name, args = {}) {
try { try {
this.api.toggleChatSet(name, JSON.parse(args.visible ?? 'true') === true); this.api.toggleChatSet(name, isTrueBoolean(args.visible ?? 'true'));
} catch (ex) { } catch (ex) {
toastr.error(ex.message); toastr.error(ex.message);
} }
} }
addChatSet(name, args = {}) { addChatSet(name, args = {}) {
try { try {
this.api.addChatSet(name, JSON.parse(args.visible ?? 'true') === true); this.api.addChatSet(name, isTrueBoolean(args.visible ?? 'true'));
} catch (ex) { } catch (ex) {
toastr.error(ex.message); toastr.error(ex.message);
} }
@ -142,11 +143,11 @@ export class SlashCommandHandler {
{ {
message: message ?? '', message: message ?? '',
title: args.title, title: args.title,
isHidden: JSON.parse(args.hidden ?? 'false') === true, isHidden: isTrueBoolean(args.hidden),
executeOnStartup: JSON.parse(args.startup ?? 'false') === true, executeOnStartup: isTrueBoolean(args.startup),
executeOnUser: JSON.parse(args.user ?? 'false') === true, executeOnUser: isTrueBoolean(args.user),
executeOnAi: JSON.parse(args.bot ?? 'false') === true, executeOnAi: isTrueBoolean(args.bot),
executeOnChatChange: JSON.parse(args.load ?? 'false') === true, executeOnChatChange: isTrueBoolean(args.load),
}, },
); );
} catch (ex) { } catch (ex) {
@ -162,11 +163,11 @@ export class SlashCommandHandler {
newLabel: args.newlabel, newLabel: args.newlabel,
message: (message ?? '').trim().length > 0 ? message : undefined, message: (message ?? '').trim().length > 0 ? message : undefined,
title: args.title, title: args.title,
isHidden: args.hidden, isHidden: args.hidden === undefined ? undefined : isTrueBoolean(args.hidden),
executeOnStartup: args.startup, executeOnStartup: args.startup === undefined ? undefined : isTrueBoolean(args.startup),
executeOnUser: args.user, executeOnUser: args.user === undefined ? undefined : isTrueBoolean(args.user),
executeOnAi: args.bot, executeOnAi: args.bot === undefined ? undefined : isTrueBoolean(args.bot),
executeOnChatChange: args.load, executeOnChatChange: args.load === undefined ? undefined : isTrueBoolean(args.load),
}, },
); );
} catch (ex) { } catch (ex) {
@ -188,7 +189,7 @@ export class SlashCommandHandler {
args.set, args.set,
args.label, args.label,
name, name,
JSON.parse(args.chain ?? 'false') === true, isTrueBoolean(args.chain),
); );
} catch (ex) { } catch (ex) {
toastr.error(ex.message); toastr.error(ex.message);
@ -215,9 +216,9 @@ export class SlashCommandHandler {
this.api.createSet( this.api.createSet(
args.name ?? name ?? '', args.name ?? name ?? '',
{ {
disableSend: JSON.parse(args.nosend ?? 'false') === true, disableSend: isTrueBoolean(args.nosend),
placeBeforeInput: JSON.parse(args.before ?? 'false') === true, placeBeforeInput: isTrueBoolean(args.before),
injectInput: JSON.parse(args.inject ?? 'false') === true, injectInput: isTrueBoolean(args.inject),
}, },
); );
} catch (ex) { } catch (ex) {
@ -229,9 +230,9 @@ export class SlashCommandHandler {
this.api.updateSet( this.api.updateSet(
args.name ?? name ?? '', args.name ?? name ?? '',
{ {
disableSend: args.nosend !== undefined ? JSON.parse(args.nosend ?? 'false') === true : undefined, disableSend: args.nosend !== undefined ? isTrueBoolean(args.nosend) : undefined,
placeBeforeInput: args.before !== undefined ? JSON.parse(args.before ?? 'false') === true : undefined, placeBeforeInput: args.before !== undefined ? isTrueBoolean(args.before) : undefined,
injectInput: args.inject !== undefined ? JSON.parse(args.inject ?? 'false') === true : undefined, injectInput: args.inject !== undefined ? isTrueBoolean(args.inject) : undefined,
}, },
); );
} catch (ex) { } catch (ex) {

View File

@ -116,7 +116,7 @@ function addLocalVariable(name, value) {
const parsedValue = JSON.parse(currentValue); const parsedValue = JSON.parse(currentValue);
if (Array.isArray(parsedValue)) { if (Array.isArray(parsedValue)) {
parsedValue.push(value); parsedValue.push(value);
setGlobalVariable(name, JSON.stringify(parsedValue)); setLocalVariable(name, JSON.stringify(parsedValue));
return parsedValue; return parsedValue;
} }
} catch { } catch {