@@ -656,9 +687,14 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
callback: deleteSwipeCallback,
aliases: ['swipedel'],
unnamedArgumentList: [
- new SlashCommandArgument(
- '1-based swipe id', [ARGUMENT_TYPE.NUMBER],
- ),
+ SlashCommandArgument.fromProps({
+ description: '1-based swipe id',
+ typeList: [ARGUMENT_TYPE.NUMBER],
+ isRequired: true,
+ enumProvider: () => Array.isArray(chat[chat.length - 1]?.swipes) ?
+ chat[chat.length - 1].swipes.map((/** @type {string} */ swipe, /** @type {number} */ i) => new SlashCommandEnumValue(String(i + 1), swipe, enumTypes.enum, enumIcons.message))
+ : [],
+ }),
],
helpString: `
@@ -687,9 +723,18 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
new SlashCommandNamedArgument(
'title', 'title of the toast message', [ARGUMENT_TYPE.STRING], false,
),
- new SlashCommandNamedArgument(
- 'severity', 'severity level of the toast message', [ARGUMENT_TYPE.STRING], false, false, null, ['info', 'warning', 'error', 'success'],
- ),
+ SlashCommandNamedArgument.fromProps({
+ name: 'severity',
+ description: 'severity level of the toast message',
+ typeList: [ARGUMENT_TYPE.STRING],
+ defaultValue: 'info',
+ enumProvider: () => [
+ new SlashCommandEnumValue('info', 'info', enumTypes.macro, 'âšī¸'),
+ new SlashCommandEnumValue('warning', 'warning', enumTypes.enum, 'â ī¸'),
+ new SlashCommandEnumValue('error', 'error', enumTypes.enum, 'â'),
+ new SlashCommandEnumValue('success', 'success', enumTypes.enum, 'â
'),
+ ],
+ }),
],
unnamedArgumentList: [
new SlashCommandArgument(
@@ -716,17 +761,28 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
returns: 'generated text',
namedArgumentList: [
new SlashCommandNamedArgument(
- 'lock', 'lock user input during generation', [ARGUMENT_TYPE.BOOLEAN], false, false, null, ['on', 'off'],
- ),
- new SlashCommandNamedArgument(
- 'name', 'in-prompt name for instruct mode', [ARGUMENT_TYPE.STRING], false, false, 'System',
+ 'lock', 'lock user input during generation', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(),
),
+ SlashCommandNamedArgument.fromProps({
+ name: 'name',
+ description: 'in-prompt name for instruct mode',
+ typeList: [ARGUMENT_TYPE.STRING],
+ defaultValue: 'System',
+ enumProvider: () => [...commonEnumProviders.characters('character')(), new SlashCommandEnumValue('System', null, enumTypes.enum, enumIcons.assistant)],
+ forceEnum: false,
+ }),
new SlashCommandNamedArgument(
'length', 'API response length in tokens', [ARGUMENT_TYPE.NUMBER], false,
),
- new SlashCommandNamedArgument(
- 'as', 'role of the output prompt', [ARGUMENT_TYPE.STRING], false, false, 'system', ['system', 'char'],
- ),
+ SlashCommandNamedArgument.fromProps({
+ name: 'as',
+ description: 'role of the output prompt',
+ typeList: [ARGUMENT_TYPE.STRING],
+ enumList: [
+ new SlashCommandEnumValue('system', null, enumTypes.enum, enumIcons.assistant),
+ new SlashCommandEnumValue('char', null, enumTypes.enum, enumIcons.character),
+ ],
+ }),
],
unnamedArgumentList: [
new SlashCommandArgument(
@@ -748,17 +804,23 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
returns: 'generated text',
namedArgumentList: [
new SlashCommandNamedArgument(
- 'lock', 'lock user input during generation', [ARGUMENT_TYPE.BOOLEAN], false, false, null, ['on', 'off'],
+ 'lock', 'lock user input during generation', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(),
),
new SlashCommandNamedArgument(
- 'instruct', 'use instruct mode', [ARGUMENT_TYPE.BOOLEAN], false, false, 'on', ['on', 'off'],
+ 'instruct', 'use instruct mode', [ARGUMENT_TYPE.BOOLEAN], false, false, 'on', commonEnumProviders.boolean('onOff')(),
),
new SlashCommandNamedArgument(
'stop', 'one-time custom stop strings', [ARGUMENT_TYPE.LIST], false,
),
- new SlashCommandNamedArgument(
- 'as', 'role of the output prompt', [ARGUMENT_TYPE.STRING], false, false, 'system', ['system', 'char'],
- ),
+ SlashCommandNamedArgument.fromProps({
+ name: 'as',
+ description: 'role of the output prompt',
+ typeList: [ARGUMENT_TYPE.STRING],
+ enumList: [
+ new SlashCommandEnumValue('system', null, enumTypes.enum, enumIcons.assistant),
+ new SlashCommandEnumValue('char', null, enumTypes.enum, enumIcons.character),
+ ],
+ }),
new SlashCommandNamedArgument(
'system', 'system prompt at the start', [ARGUMENT_TYPE.STRING], false,
),
@@ -861,7 +923,12 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
}));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'pass',
- callback: (_, arg) => arg,
+ callback: (_, arg) => {
+ // We do not support arrays of closures. Arrays of strings will be send as JSON
+ if (Array.isArray(arg) && arg.some(x => x instanceof SlashCommandClosure)) throw new Error('Command /pass does not support multiple closures');
+ if (Array.isArray(arg)) return JSON.stringify(arg);
+ return arg;
+ },
returns: 'the provided value',
unnamedArgumentList: [
new SlashCommandArgument(
@@ -914,10 +981,10 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
'default', 'default value of the input field', [ARGUMENT_TYPE.STRING], false, false, '"string"',
),
new SlashCommandNamedArgument(
- 'large', 'show large input field', [ARGUMENT_TYPE.BOOLEAN], false, false, 'off', ['on', 'off'],
+ 'large', 'show large input field', [ARGUMENT_TYPE.BOOLEAN], false, false, 'off', commonEnumProviders.boolean('onOff')(),
),
new SlashCommandNamedArgument(
- 'wide', 'show wide input field', [ARGUMENT_TYPE.BOOLEAN], false, false, 'off', ['on', 'off'],
+ 'wide', 'show wide input field', [ARGUMENT_TYPE.BOOLEAN], false, false, 'off', commonEnumProviders.boolean('onOff')(),
),
new SlashCommandNamedArgument(
'okButton', 'text for the ok button', [ARGUMENT_TYPE.STRING], false,
@@ -949,9 +1016,15 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
),
],
unnamedArgumentList: [
- new SlashCommandArgument(
- 'scoped variable or qr label', [ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.STRING], true,
- ),
+ SlashCommandArgument.fromProps({
+ description: 'scoped variable or qr label',
+ typeList: [ARGUMENT_TYPE.VARIABLE_NAME, ARGUMENT_TYPE.STRING],
+ isRequired: true,
+ enumProvider: () => [
+ ...commonEnumProviders.variables('scope')(),
+ ...(typeof window['qrEnumProviderExecutables'] === 'function') ? window['qrEnumProviderExecutables']() : [],
+ ],
+ }),
],
helpString: `
@@ -966,19 +1039,29 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
aliases: ['message'],
namedArgumentList: [
new SlashCommandNamedArgument(
- 'names', 'show message author names', [ARGUMENT_TYPE.BOOLEAN], false, false, 'off', ['off', 'on'],
+ 'names', 'show message author names', [ARGUMENT_TYPE.BOOLEAN], false, false, 'off', commonEnumProviders.boolean('onOff')(),
),
new SlashCommandNamedArgument(
- 'hidden', 'include hidden messages', [ARGUMENT_TYPE.BOOLEAN], false, false, 'on', ['off', 'on'],
- ),
- new SlashCommandNamedArgument(
- 'role', 'filter messages by role', [ARGUMENT_TYPE.STRING], false, false, null, ['system', 'assistant', 'user'],
+ 'hidden', 'include hidden messages', [ARGUMENT_TYPE.BOOLEAN], false, false, 'on', commonEnumProviders.boolean('onOff')(),
),
+ SlashCommandNamedArgument.fromProps({
+ name: 'role',
+ description: 'filter messages by role',
+ typeList: [ARGUMENT_TYPE.STRING],
+ enumList: [
+ new SlashCommandEnumValue('system', null, enumTypes.enum, enumIcons.system),
+ new SlashCommandEnumValue('assistant', null, enumTypes.enum, enumIcons.assistant),
+ new SlashCommandEnumValue('user', null, enumTypes.enum, enumIcons.user),
+ ],
+ }),
],
unnamedArgumentList: [
- new SlashCommandArgument(
- 'message index or range', [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.RANGE], false, true,
- ),
+ SlashCommandArgument.fromProps({
+ description: 'message index or range',
+ typeList: [ARGUMENT_TYPE.NUMBER, ARGUMENT_TYPE.RANGE],
+ isRequired: true,
+ enumProvider: commonEnumProviders.messages(),
+ }),
],
returns: 'the specified message or range of messages as a string',
helpString: `
@@ -1034,10 +1117,10 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
returns: 'popup text',
namedArgumentList: [
new SlashCommandNamedArgument(
- 'large', 'show large popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, ['on', 'off'],
+ 'large', 'show large popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(),
),
new SlashCommandNamedArgument(
- 'wide', 'show wide popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, ['on', 'off'],
+ 'wide', 'show wide popup', [ARGUMENT_TYPE.BOOLEAN], false, false, null, commonEnumProviders.boolean('onOff')(),
),
new SlashCommandNamedArgument(
'okButton', 'text for the OK button', [ARGUMENT_TYPE.STRING], false,
@@ -1100,9 +1183,16 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
new SlashCommandNamedArgument(
'limit', 'number of tokens to keep', [ARGUMENT_TYPE.NUMBER], true,
),
- new SlashCommandNamedArgument(
- 'direction', 'trim direction', [ARGUMENT_TYPE.STRING], true, false, null, ['start', 'end'],
- ),
+ SlashCommandNamedArgument.fromProps({
+ name: 'direction',
+ description: 'trim direction',
+ typeList: [ARGUMENT_TYPE.STRING],
+ isRequired: true,
+ enumList: [
+ new SlashCommandEnumValue('start', null, enumTypes.enum, 'âŦ
ī¸'),
+ new SlashCommandEnumValue('end', null, enumTypes.enum, 'âĄī¸'),
+ ],
+ }),
],
unnamedArgumentList: [
new SlashCommandArgument(
@@ -1173,11 +1263,19 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
new SlashCommandNamedArgument(
'scan', 'include injection content into World Info scans', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false',
),
+ SlashCommandNamedArgument.fromProps({
+ name: 'role',
+ description: 'role for in-chat injections',
+ typeList: [ARGUMENT_TYPE.STRING],
+ isRequired: false,
+ enumList: [
+ new SlashCommandEnumValue('system', null, enumTypes.enum, enumIcons.system),
+ new SlashCommandEnumValue('assistant', null, enumTypes.enum, enumIcons.assistant),
+ new SlashCommandEnumValue('user', null, enumTypes.enum, enumIcons.user),
+ ],
+ }),
new SlashCommandNamedArgument(
- 'role', 'role for in-chat injections', [ARGUMENT_TYPE.STRING], false, false, 'system', ['system', 'user', 'assistant'],
- ),
- new SlashCommandNamedArgument(
- 'ephemeral', 'remove injection after generation', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false', ['true', 'false'],
+ 'ephemeral', 'remove injection after generation', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false',
),
],
unnamedArgumentList: [
@@ -1196,16 +1294,25 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'flushinject',
aliases: ['flushinjects'],
unnamedArgumentList: [
- new SlashCommandArgument(
- 'injection ID or a variable name pointing to ID', [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.VARIABLE_NAME], false, false, '',
- ),
+ SlashCommandArgument.fromProps({
+ description: 'injection ID or a variable name pointing to ID',
+ typeList: [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.VARIABLE_NAME],
+ defaultValue: '',
+ enumProvider: () => [
+ ...commonEnumProviders.injects(),
+ ...commonEnumProviders.variables('all')().map(x => { x.description = 'Variable'; return x; }),
+ ],
+ })
],
callback: flushInjectsCallback,
helpString: 'Removes a script injection for the current chat. If no ID is provided, removes all script injections.',
}));
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
name: 'tokens',
- callback: (_, text) => getTokenCountAsync(text),
+ callback: (_, text) => {
+ if (text instanceof SlashCommandClosure || Array.isArray(text)) throw new Error('Unnamed argument cannot be a closure for command /tokens')
+ return getTokenCountAsync(text).then(count => String(count));
+ },
returns: 'number of tokens',
unnamedArgumentList: [
new SlashCommandArgument(
@@ -1230,12 +1337,28 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
aliases: ['setpromptentries'],
callback: setPromptEntryCallback,
namedArgumentList: [
- new SlashCommandNamedArgument(
- 'identifier', 'Prompt entry identifier(s) to target', [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.LIST], false, true,
- ),
- new SlashCommandNamedArgument(
- 'name', 'Prompt entry name(s) to target', [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.LIST], false, true,
- ),
+ SlashCommandNamedArgument.fromProps({
+ name: 'identifier',
+ description: 'Prompt entry identifier(s) to target',
+ typeList: [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.LIST],
+ acceptsMultiple: true,
+ enumProvider: () => {
+ const promptManager = setupChatCompletionPromptManager(oai_settings);
+ const prompts = promptManager.serviceSettings.prompts;
+ return prompts.map(prompt => new SlashCommandEnumValue(prompt.identifier, prompt.name, enumTypes.enum));
+ },
+ }),
+ SlashCommandNamedArgument.fromProps({
+ name: 'name',
+ description: 'Prompt entry name(s) to target',
+ typeList: [ARGUMENT_TYPE.STRING, ARGUMENT_TYPE.LIST],
+ acceptsMultiple: true,
+ enumProvider: () => {
+ const promptManager = setupChatCompletionPromptManager(oai_settings);
+ const prompts = promptManager.serviceSettings.prompts;
+ return prompts.map(prompt => new SlashCommandEnumValue(prompt.name, prompt.identifier, enumTypes.enum));
+ }
+ }),
],
unnamedArgumentList: [
SlashCommandArgument.fromProps({
@@ -1244,7 +1367,7 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
isRequired: true,
acceptsMultiple: false,
defaultValue: 'toggle', // unnamed arguments don't support default values yet
- enumList: ['on', 'off', 'toggle'],
+ enumList: commonEnumProviders.boolean('onOffToggle')(),
}),
],
helpString: 'Sets the specified prompt manager entry/entries on or off.',
@@ -1521,7 +1644,7 @@ async function popupCallback(args, value) {
await delay(1);
await callGenericPopup(safeValue, POPUP_TYPE.TEXT, '', popupOptions);
await delay(1);
- return value;
+ return String(value);
}
function getMessagesCallback(args, value) {
@@ -1625,12 +1748,11 @@ async function runCallback(args, name) {
/**
*
- * @param {object} param0
- * @param {SlashCommandAbortController} param0._abortController
- * @param {string} [param0.quiet]
+ * @param {import('./slash-commands/SlashCommand.js').NamedArguments} param0
* @param {string} [reason]
*/
function abortCallback({ _abortController, quiet }, reason) {
+ if (quiet instanceof SlashCommandClosure) throw new Error('argument \'quiet\' cannot be a closure for command /abort');
_abortController.abort((reason ?? '').toString().length == 0 ? '/abort command executed' : reason, !isFalseBoolean(quiet ?? 'true'));
return '';
}
@@ -1661,9 +1783,9 @@ async function inputCallback(args, prompt) {
};
// Do not remove this delay, otherwise the prompt will not show up
await delay(1);
- const result = await callPopup(safeValue, 'input', defaultInput, popupOptions);
+ const result = await callGenericPopup(safeValue, POPUP_TYPE.INPUT, defaultInput, popupOptions);
await delay(1);
- return result || '';
+ return String(result);
}
/**
diff --git a/public/scripts/slash-commands/SlashCommandCommonEnumsProvider.js b/public/scripts/slash-commands/SlashCommandCommonEnumsProvider.js
index 6026f82e1..22f25a281 100644
--- a/public/scripts/slash-commands/SlashCommandCommonEnumsProvider.js
+++ b/public/scripts/slash-commands/SlashCommandCommonEnumsProvider.js
@@ -1,6 +1,7 @@
-import { chat_metadata, characters, substituteParams, chat, extension_prompt_roles } from "../../script.js";
+import { chat_metadata, characters, substituteParams, chat, extension_prompt_roles, extension_prompt_types } from "../../script.js";
import { extension_settings } from "../extensions.js";
-import { groups } from "../group-chats.js";
+import { getGroupMembers, groups, selected_group } from "../group-chats.js";
+import { power_user } from "../power-user.js";
import { searchCharByName, getTagsList, tags } from "../tags.js";
import { SlashCommandClosure } from "./SlashCommandClosure.js";
import { SlashCommandEnumValue, enumTypes } from "./SlashCommandEnumValue.js";
@@ -21,11 +22,13 @@ export const enumIcons = {
// Common types
character: 'đ¤',
group: 'đ§âđ¤âđ§',
- qr: 'đ¤',
+ persona: 'đ§ââī¸',
+ qr: 'QR',
tag: 'đˇī¸',
world: 'đ',
preset: 'âī¸',
file: 'đ',
+ message: 'đŦ',
true: 'âī¸',
false: 'â',
@@ -50,6 +53,16 @@ export const enumIcons = {
disabled: 'â',
vectorized: 'đ',
+ /**
+ * Returns the appropriate state icon based on a boolean
+ *
+ * @param {boolean} state - The state to determine the icon for
+ * @returns {string} The corresponding state icon
+ */
+ getStateIcon: (state) => {
+ return state ? enumIcons.true : enumIcons.false;
+ },
+
/**
* Returns the appropriate WI icon based on the entry
*
@@ -77,6 +90,18 @@ export const enumIcons = {
default: return enumIcons.default;
}
},
+
+ /**
+ * A function to get the data type icon
+ *
+ * @param {string} type - The type of the data
+ * @returns {string} The corresponding data type icon
+ */
+ getDataTypeIcon: (type) => {
+ // Remove possible nullable types definition to match type icon
+ type = type.replace(/\?$/, '');
+ return enumIcons[type] ?? enumIcons.default;
+ }
}
/**
@@ -88,6 +113,7 @@ export const commonEnumProviders = {
/**
* Enum values for booleans. Either using true/false or on/off
* Optionally supports "toggle".
+ *
* @param {('onOff'|'onOffToggle'|'trueFalse')?} [mode='trueFalse'] - The mode to use. Default is 'trueFalse'.
* @returns {() => SlashCommandEnumValue[]}
*/
@@ -112,9 +138,9 @@ export const commonEnumProviders = {
const types = type.flat();
const isAll = types.includes('all');
return [
- ...isAll || types.includes('global') ? Object.keys(extension_settings.variables.global ?? []).map(x => new SlashCommandEnumValue(x, null, enumTypes.macro, enumIcons.globalVariable)) : [],
- ...isAll || types.includes('local') ? Object.keys(chat_metadata.variables ?? []).map(x => new SlashCommandEnumValue(x, null, enumTypes.name, enumIcons.localVariable)) : [],
- ...isAll || types.includes('scope') ? [].map(x => new SlashCommandEnumValue(x, null, enumTypes.variable, enumIcons.scopeVariable)) : [], // TODO: Add scoped variables here, Lenny
+ ...isAll || types.includes('global') ? Object.keys(extension_settings.variables.global ?? []).map(name => new SlashCommandEnumValue(name, null, enumTypes.macro, enumIcons.globalVariable)) : [],
+ ...isAll || types.includes('local') ? Object.keys(chat_metadata.variables ?? []).map(name => new SlashCommandEnumValue(name, null, enumTypes.name, enumIcons.localVariable)) : [],
+ ...isAll || types.includes('scope') ? [].map(name => new SlashCommandEnumValue(name, null, enumTypes.variable, enumIcons.scopeVariable)) : [], // TODO: Add scoped variables here, Lenny
]
},
@@ -124,13 +150,28 @@ export const commonEnumProviders = {
* @param {('all' | 'character' | 'group')?} [mode='all'] - Which type to return
* @returns {() => SlashCommandEnumValue[]}
*/
- charName: (mode = 'all') => () => {
+ characters: (mode = 'all') => () => {
return [
- ...['all', 'character'].includes(mode) ? characters.map(it => new SlashCommandEnumValue(it.name, null, enumTypes.name, enumIcons.character)) : [],
- ...['all', 'group'].includes(mode) ? groups.map(it => new SlashCommandEnumValue(it.name, null, enumTypes.qr, enumIcons.group)) : [],
+ ...['all', 'character'].includes(mode) ? characters.map(char => new SlashCommandEnumValue(char.name, null, enumTypes.name, enumIcons.character)) : [],
+ ...['all', 'group'].includes(mode) ? groups.map(group => new SlashCommandEnumValue(group.name, null, enumTypes.qr, enumIcons.group)) : [],
];
},
+ /**
+ * All group members of the given group, or default the current active one
+ *
+ * @param {string?} groupId - The id of the group - pass in `undefined` to use the current active group
+ * @returns {() =>SlashCommandEnumValue[]}
+ */
+ groupMembers: (groupId = undefined) => () => getGroupMembers(groupId).map((character, index) => new SlashCommandEnumValue(String(index), character.name, enumTypes.enum, enumIcons.character)),
+
+ /**
+ * All possible personas
+ *
+ * @returns {SlashCommandEnumValue[]}
+ */
+ personas: () => Object.values(power_user.personas).map(persona => new SlashCommandEnumValue(persona, null, enumTypes.name, enumIcons.persona)),
+
/**
* All possible tags for a given char/group entity
*
@@ -144,14 +185,26 @@ export const commonEnumProviders = {
const key = searchCharByName(substituteParams(charName), { suppressLogging: true });
const assigned = key ? getTagsList(key) : [];
return tags.filter(it => !key || mode === 'all' || mode === 'existing' && assigned.includes(it) || mode === 'not-existing' && !assigned.includes(it))
- .map(it => new SlashCommandEnumValue(it.name, null, enumTypes.command, enumIcons.tag));
+ .map(tag => new SlashCommandEnumValue(tag.name, null, enumTypes.command, enumIcons.tag));
},
/**
* All messages in the current chat, returning the message id
- * @returns {SlashCommandEnumValue[]}
+ *
+ * Optionally supports variable names, and/or a placeholder for the last/new message id
+ *
+ * @param {object} [options={}] - Optional arguments
+ * @param {boolean} [options.allowIdAfter=false] - Whether to add an enum option for the new message id after the last message
+ * @param {boolean} [options.allowVars=false] - Whether to add enum option for variable names
+ * @returns {() => SlashCommandEnumValue[]}
*/
- messages: () => chat.map((mes, i) => new SlashCommandEnumValue(String(i), `${mes.name}: ${mes.mes}`, enumTypes.number, mes.is_user ? enumIcons.user : mes.is_system ? enumIcons.system : enumIcons.assistant)),
+ messages: ({ allowIdAfter = false, allowVars = false } = {}) => () => {
+ return [
+ ...chat.map((message, index) => new SlashCommandEnumValue(String(index), `${message.name}: ${message.mes}`, enumTypes.number, message.is_user ? enumIcons.user : message.is_system ? enumIcons.system : enumIcons.assistant)),
+ ...allowIdAfter ? [new SlashCommandEnumValue(String(chat.length), '>> After Last Message >>', enumTypes.enum, 'â')] : [],
+ ...allowVars ? commonEnumProviders.variables('all')() : [],
+ ];
+ },
/**
* All existing worlds / lorebooks
@@ -159,18 +212,19 @@ export const commonEnumProviders = {
* @returns {SlashCommandEnumValue[]}
*/
worlds: () => $('#world_info').children().toArray().map(x => new SlashCommandEnumValue(x.textContent, null, enumTypes.name, enumIcons.world)),
-};
-/**
- * Get the unicode icon for the given enum value type
- *
- * Can also confert nullable data types to their non-nullable counterparts
- *
- * @param {string} type The type of the enum value
- * @returns {string} the unicode icon
- */
-export function getEnumIcon(type) {
- // Remove possible nullable types definition to match type icon
- type = type.replace(/\?$/, '');
- return enumIcons[type] ?? enumIcons.default;
-}
+ /**
+ * All existing injects for the current chat
+ *
+ * @returns {SlashCommandEnumValue[]}
+ */
+ injects: () => {
+ if (!chat_metadata.script_injects || !Object.keys(chat_metadata.script_injects).length) return [];
+ return Object.entries(chat_metadata.script_injects)
+ .map(([id, inject]) => {
+ const positionName = (Object.entries(extension_prompt_types)).find(([_, value]) => value === inject.position)?.[0] ?? 'unknown';
+ return new SlashCommandEnumValue(id, `${enumIcons.getRoleIcon(inject.role ?? extension_prompt_roles.SYSTEM)}[Inject](${positionName}, depth: ${inject.depth}, scan: ${inject.scan ?? false}) ${inject.value}`,
+ enumTypes.enum, 'đ');
+ });
+ },
+};
diff --git a/public/scripts/tags.js b/public/scripts/tags.js
index c8185d8d5..d8aae0617 100644
--- a/public/scripts/tags.js
+++ b/public/scripts/tags.js
@@ -1825,7 +1825,7 @@ function registerTagsSlashCommands() {
description: 'Character name',
typeList: [ARGUMENT_TYPE.STRING],
defaultValue: '{{char}}',
- enumProvider: commonEnumProviders.charName(),
+ enumProvider: commonEnumProviders.characters(),
}),
],
unnamedArgumentList: [
@@ -1870,7 +1870,7 @@ function registerTagsSlashCommands() {
description: 'Character name',
typeList: [ARGUMENT_TYPE.STRING],
defaultValue: '{{char}}',
- enumProvider: commonEnumProviders.charName(),
+ enumProvider: commonEnumProviders.characters(),
}),
],
unnamedArgumentList: [
@@ -1913,7 +1913,7 @@ function registerTagsSlashCommands() {
description: 'Character name',
typeList: [ARGUMENT_TYPE.STRING],
defaultValue: '{{char}}',
- enumProvider: commonEnumProviders.charName(),
+ enumProvider: commonEnumProviders.characters(),
}),
],
unnamedArgumentList: [
@@ -1956,7 +1956,7 @@ function registerTagsSlashCommands() {
description: 'Character name',
typeList: [ARGUMENT_TYPE.STRING],
defaultValue: '{{char}}',
- enumProvider: commonEnumProviders.charName(),
+ enumProvider: commonEnumProviders.characters(),
}),
],
helpString: `
diff --git a/public/scripts/variables.js b/public/scripts/variables.js
index 49537568b..2a869fc6f 100644
--- a/public/scripts/variables.js
+++ b/public/scripts/variables.js
@@ -372,6 +372,7 @@ async function whileCallback(args, value) {
* @returns
*/
async function timesCallback(args, value) {
+ if (args.guard instanceof SlashCommandClosure) throw new Error('argument \'guard\' cannot be a closure for command /while');
let repeats;
let command;
if (Array.isArray(value)) {
diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js
index 16343ccbd..4cb7bc6ca 100644
--- a/public/scripts/world-info.js
+++ b/public/scripts/world-info.js
@@ -14,7 +14,7 @@ import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
import { SlashCommand } from './slash-commands/SlashCommand.js';
import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';
import { SlashCommandEnumValue, enumTypes } from './slash-commands/SlashCommandEnumValue.js';
-import { commonEnumProviders, enumIcons, getEnumIcon } from './slash-commands/SlashCommandCommonEnumsProvider.js';
+import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';
import { SlashCommandExecutor } from './slash-commands/SlashCommandExecutor.js';
import { SlashCommandClosure } from './slash-commands/SlashCommandClosure.js';
@@ -707,7 +707,7 @@ function registerWorldInfoSlashCommands() {
/** All possible fields that can be set in a WI entry */
wiEntryFields: () => Object.entries(newEntryDefinition).map(([key, value]) =>
new SlashCommandEnumValue(key, `[${value.type}] default: ${(typeof value.default === 'string' ? `'${value.default}'` : value.default)}`,
- enumTypes.enum, getEnumIcon(value.type))),
+ enumTypes.enum, enumIcons.getDataTypeIcon(value.type))),
/** All existing UIDs based on the file argument as world name */
wiUids: (/** @type {SlashCommandExecutor} */ executor) => {