Refactor /classify-expressions, deprecating... - Update /classify-expressions, deprecating the old "format" - Fix some oversights

7a1b43eb8943b48747bd3efa139e81186346f964

Wolfsblvt <wolfsblvt@gmail.com>

4 files changed, +34 -8Showing whitespace changes
public/scripts/extensions/expressions/index.js+31 -5
@@ -12,6 +12,8 @@ import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from '
12import { isFunctionCallingSupported } from '../../openai.js';12import { isFunctionCallingSupported } from '../../openai.js';
13import { SlashCommandEnumValue, enumTypes } from '../../slash-commands/SlashCommandEnumValue.js';13import { SlashCommandEnumValue, enumTypes } from '../../slash-commands/SlashCommandEnumValue.js';
14import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';14import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js';
15import { slashCommandReturnHelper } from '../../slash-commands/SlashCommandReturnHelper.js';
16import { SlashCommandClosure } from '../../slash-commands/SlashCommandClosure.js';
15export { MODULE_NAME };17export { MODULE_NAME };
1618
17const MODULE_NAME = 'expressions';19const MODULE_NAME = 'expressions';
@@ -2128,18 +2130,42 @@ function migrateSettings() {
2128 name: 'classify-expressions',2130 name: 'classify-expressions',
2129 aliases: ['expressions'],2131 aliases: ['expressions'],
2130 callback: async (args) => {2132 callback: async (args) => {
2131 const list = await getExpressionsList();2133 /** @type {import('../../slash-commands/SlashCommandReturnHelper.js').SlashCommandReturnType} */
2132 switch (String(args.format).toLowerCase()) {2134 // @ts-ignore
2135 let returnType = args.return;
2136
2137 // Old legacy return type handling
2138 if (args.format) {
2139 toastr.warning(`Legacy argument 'format' with value '${args.format}' is deprecated. Please use 'return' instead. Routing to the correct return type...`, 'Deprecation warning');
2140 const type = String(args?.format).toLowerCase().trim();
2141 switch (type) {
2133 case 'json':2142 case 'json':
2134 return JSON.stringify(list);2143 returnType = 'object';
2144 break;
2135 default:2145 default:
2136 return list.join(', ');2146 returnType = 'pipe';
2147 break;
2148 }
2137 }2149 }
2150
2151 // Now the actual new return type handling
2152 const list = await getExpressionsList();
2153
2154 return await slashCommandReturnHelper.doReturn(returnType ?? 'pipe', list, { objectToStringFunc: list => list.join(', ') });
2138 },2155 },
2139 namedArgumentList: [2156 namedArgumentList: [
2140 SlashCommandNamedArgument.fromProps({2157 SlashCommandNamedArgument.fromProps({
2158 name: 'return',
2159 description: 'The way how you want the return value to be provided',
2160 typeList: [ARGUMENT_TYPE.STRING],
2161 defaultValue: 'pipe',
2162 enumList: slashCommandReturnHelper.enumList({ allowObject: true }),
2163 forceEnum: true,
2164 }),
2165 // TODO remove some day
2166 SlashCommandNamedArgument.fromProps({
2141 name: 'format',2167 name: 'format',
2142 description: 'The format to return the list in: comma-separated plain text or JSON array. Default is plain text.',2168 description: '!!! DEPRECATED - use "return" instead !!! The format to return the list in: comma-separated plain text or JSON array. Default is plain text.',
2143 typeList: [ARGUMENT_TYPE.STRING],2169 typeList: [ARGUMENT_TYPE.STRING],
2144 enumList: [2170 enumList: [
2145 new SlashCommandEnumValue('plain', null, enumTypes.enum, ', '),2171 new SlashCommandEnumValue('plain', null, enumTypes.enum, ', '),
public/scripts/slash-commands.js+1 -1
@@ -1538,7 +1538,7 @@ export function initDefaultSlashCommands() {
1538 // TODO remove some day1538 // TODO remove some day
1539 SlashCommandNamedArgument.fromProps({1539 SlashCommandNamedArgument.fromProps({
1540 name: 'format',1540 name: 'format',
1541 description: '!!! DEPRECATED - use "return" instead !!! output format)',1541 description: '!!! DEPRECATED - use "return" instead !!! output format',
1542 typeList: [ARGUMENT_TYPE.STRING],1542 typeList: [ARGUMENT_TYPE.STRING],
1543 isRequired: true,1543 isRequired: true,
1544 forceEnum: true,1544 forceEnum: true,
public/scripts/slash-commands/SlashCommandReturnHelper.js+1 -1
@@ -23,7 +23,7 @@ export const slashCommandReturnHelper = {
23 */23 */
24 enumList: ({ allowPipe = true, allowObject = false, allowChat = false, allowPopup = false, allowTextVersion = true } = {}) => [24 enumList: ({ allowPipe = true, allowObject = false, allowChat = false, allowPopup = false, allowTextVersion = true } = {}) => [
25 allowPipe && new SlashCommandEnumValue('pipe', 'Return to the pipe for the next command', enumTypes.name, '|'),25 allowPipe && new SlashCommandEnumValue('pipe', 'Return to the pipe for the next command', enumTypes.name, '|'),
26 allowObject && new SlashCommandEnumValue('object', 'Return as an object to the pipe for the next command', enumTypes.variable, enumIcons.dictionary),26 allowObject && new SlashCommandEnumValue('object', 'Return as an object (or array) to the pipe for the next command', enumTypes.variable, enumIcons.dictionary),
27 allowChat && new SlashCommandEnumValue('chat-html', 'Sending a chat message with the return value - Can display HTML', enumTypes.command, enumIcons.message),27 allowChat && new SlashCommandEnumValue('chat-html', 'Sending a chat message with the return value - Can display HTML', enumTypes.command, enumIcons.message),
28 allowChat && allowTextVersion && new SlashCommandEnumValue('chat-text', 'Sending a chat message with the return value - Will only display as text', enumTypes.qr, enumIcons.message),28 allowChat && allowTextVersion && new SlashCommandEnumValue('chat-text', 'Sending a chat message with the return value - Will only display as text', enumTypes.qr, enumIcons.message),
29 allowPopup && new SlashCommandEnumValue('popup-html', 'Showing as a popup with the return value - Can display HTML', enumTypes.command, enumIcons.popup),29 allowPopup && new SlashCommandEnumValue('popup-html', 'Showing as a popup with the return value - Can display HTML', enumTypes.command, enumIcons.popup),
public/scripts/variables.js+1 -1
@@ -951,7 +951,7 @@ export function registerVariableCommands() {
951 // TODO remove some day951 // TODO remove some day
952 SlashCommandNamedArgument.fromProps({952 SlashCommandNamedArgument.fromProps({
953 name: 'format',953 name: 'format',
954 description: '!!! DEPRECATED - use "return" instead !!! output format)',954 description: '!!! DEPRECATED - use "return" instead !!! output format',
955 typeList: [ARGUMENT_TYPE.STRING],955 typeList: [ARGUMENT_TYPE.STRING],
956 isRequired: true,956 isRequired: true,
957 forceEnum: true,957 forceEnum: true,