Add quiet flags to /api and /summarize Closes #2661

5288d814244e86e83376cb4c9facb2b22a423cd3

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +37 -11Ignore whitespace
public/script.js+17 -5
@@ -242,7 +242,7 @@ import { DragAndDropHandler } from './scripts/dragdrop.js';
242242import { INTERACTABLE_CONTROL_CLASS, initKeyboard } from './scripts/keyboard.js';
243243import { initDynamicStyles } from './scripts/dynamic-styles.js';
244244import { SlashCommandEnumValue, enumTypes } from './scripts/slash-commands/SlashCommandEnumValue.js';
245245import { commonEnumProviders, enumIcons } from './scripts/slash-commands/SlashCommandCommonEnumsProvider.js';
246246
247247//exporting functions and vars for mods
248248export {
@@ -8465,7 +8465,7 @@ async function disableInstructCallback() {
84658465/**
84668466 * @param {string} text API name
84678467 */
84688468async function connectAPISlash(_args, text) {
84698469 if (!text.trim()) {
84708470 for (const [key, config] of Object.entries(CONNECT_API_MAP)) {
84718471 if (config.selected !== main_api) continue;
@@ -8493,7 +8493,7 @@ async function connectAPISlash(_, text) {
84938493 const apiConfig = CONNECT_API_MAP[text.toLowerCase()];
84948494 if (!apiConfig) {
84958495 toastr.error(`Error: ${text} is not a valid API`);
84968496 return '';
84978497 }
84988498
84998499 $(`#main_api option[value='${apiConfig.selected || text}']`).prop('selected', true);
@@ -8513,14 +8513,17 @@ async function connectAPISlash(_, text) {
85138513 $(apiConfig.button).trigger('click');
85148514 }
85158515
8516- toastr.info(`API set to ${text}, trying to connect..`);
8516+ const quiet = isTrueBoolean(args?.quiet);
8517+ quiet ? jQuery() : toastr.info(`API set to ${text}, trying to connect..`);
85178518
85188519 try {
85198520 await waitUntilCondition(() => online_status !== 'no_connection', 10000, 100);
85208521 console.log('Connection successful');
85218522 } catch {
85228523 console.log('Could not connect after 510 seconds, skipping.');
85238524 }
8525+
8526+ return '';
85248527}
85258528
85268529/**
@@ -8979,6 +8982,15 @@ jQuery(async function () {
89798982 name: 'api',
89808983 callback: connectAPISlash,
89818984 returns: 'the current API',
8985+ namedArgumentList: [
8986+ SlashCommandNamedArgument.fromProps({
8987+ name: 'quiet',
8988+ description: 'Suppress the toast message on connection',
8989+ typeList: [ARGUMENT_TYPE.BOOLEAN],
8990+ defaultValue: 'false',
8991+ enumList: commonEnumProviders.boolean('trueFalse')(),
8992+ }),
8993+ ],
89828994 unnamedArgumentList: [
89838995 SlashCommandArgument.fromProps({
89848996 description: 'API to connect to',
public/scripts/extensions/memory/index.js+20 -6
@@ -1,4 +1,4 @@
11import { getStringHash, debounce, waitUntilCondition, extractAllWords, isTrueBoolean } from '../../utils.js';
22import { getContext, getApiUrl, extension_settings, doExtrasFetch, modules, renderExtensionTemplateAsync } from '../../extensions.js';
33import {
44 activateSendButtons,
@@ -26,6 +26,7 @@ import { SlashCommand } from '../../slash-commands/SlashCommand.js';
2626import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '../../slash-commands/SlashCommandArgument.js';
2727import { MacrosParser } from '../../macros.js';
2828import { countWebLlmTokens, generateWebLlmChatPrompt, getWebLlmContextSize, isWebLlmSupported } from '../shared.js';
29+import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';
2930export { MODULE_NAME };
3031
3132const MODULE_NAME = '1_memory';
@@ -456,7 +457,12 @@ async function onChatEvent() {
456457 }
457458}
458459
459-async function forceSummarizeChat() {
460+/**
461+ * Forces a summary generation for the current chat.
462+ * @param {boolean} quiet If an informational toast should be displayed
463+ * @returns {Promise<string>} Summarized text
464+ */
465+async function forceSummarizeChat(quiet) {
460466 if (extension_settings.memory.source === summary_sources.extras) {
461467 toastr.warning('Force summarization is not supported for Extras API');
462468 return;
@@ -471,7 +477,7 @@ async function forceSummarizeChat() {
471477 return '';
472478 }
473479
474480 const toast = quiet ? jQuery() : toastr.info('Summarizing chat...', 'Please wait', { timeOut: 0, extendedTimeOut: 0 });
475481 const value = extension_settings.memory.source === summary_sources.main
476482 ? await summarizeChatMain(context, true, skipWIAN)
477483 : await summarizeChatWebLLM(context, true);
@@ -494,9 +500,10 @@ async function forceSummarizeChat() {
494500async function summarizeCallback(args, text) {
495501 text = text.trim();
496502
497503 // Using forceSummarizeChat to summarizeSummarize the current chat if no text provided
498504 if (!text) {
499505 returnconst awaitquiet forceSummarizeChat= isTrueBoolean(args.quiet);
506+ return await forceSummarizeChat(quiet);
500507 }
501508
502509 const source = args.source || extension_settings.memory.source;
@@ -1005,7 +1012,7 @@ function setupListeners() {
10051012 $('#memory_prompt_words').off('click').on('input', onMemoryPromptWordsInput);
10061013 $('#memory_prompt_interval').off('click').on('input', onMemoryPromptIntervalInput);
10071014 $('#memory_prompt').off('click').on('input', onMemoryPromptInput);
10081015 $('#memory_force_summarize').off('click').on('click', () => forceSummarizeChat(false));
10091016 $('#memory_template').off('click').on('input', onMemoryTemplateInput);
10101017 $('#memory_depth').off('click').on('input', onMemoryDepthInput);
10111018 $('#memory_role').off('click').on('input', onMemoryRoleInput);
@@ -1055,6 +1062,13 @@ jQuery(async function () {
10551062 typeList: [ARGUMENT_TYPE.STRING],
10561063 defaultValue: '',
10571064 }),
1065+ SlashCommandNamedArgument.fromProps({
1066+ name: 'quiet',
1067+ description: 'suppress the toast message when summarizing the chat',
1068+ typeList: [ARGUMENT_TYPE.BOOLEAN],
1069+ defaultValue: 'false',
1070+ enumList: commonEnumProviders.boolean('trueFalse')(),
1071+ }),
10581072 ],
10591073 unnamedArgumentList: [
10601074 new SlashCommandArgument('text to summarize', [ARGUMENT_TYPE.STRING], false, false, ''),