Refactor /classify-expressions, deprecating... - Update /classify-expressions, deprecating the old "format" - Fix some oversights
| @@ -12,6 +12,8 @@ import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from ' | ||
| 12 | 12 | import { isFunctionCallingSupported } from '../../openai.js'; |
| 13 | 13 | import { SlashCommandEnumValue, enumTypes } from '../../slash-commands/SlashCommandEnumValue.js'; |
| 14 | 14 | import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js'; |
| 15 | +import { slashCommandReturnHelper } from '../../slash-commands/SlashCommandReturnHelper.js'; | |
| 16 | +import { SlashCommandClosure } from '../../slash-commands/SlashCommandClosure.js'; | |
| 15 | 17 | export { MODULE_NAME }; |
| 16 | 18 | |
| 17 | 19 | const MODULE_NAME = 'expressions'; |
| @@ -2128,18 +2130,42 @@ function migrateSettings() { | ||
| 2128 | 2130 | name: 'classify-expressions', |
| 2129 | 2131 | aliases: ['expressions'], |
| 2130 | 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 | 2142 | case 'json': |
| 2134 | - return JSON.stringify(list); | |
| 2143 | + returnType = 'object'; | |
| 2144 | + break; | |
| 2135 | 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 | 2156 | namedArgumentList: [ |
| 2140 | 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 | 2167 | name: 'format', |
| 2142 | 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 | 2169 | typeList: [ARGUMENT_TYPE.STRING], |
| 2144 | 2170 | enumList: [ |
| 2145 | 2171 | new SlashCommandEnumValue('plain', null, enumTypes.enum, ', '), |
| @@ -1538,7 +1538,7 @@ export function initDefaultSlashCommands() { | ||
| 1538 | 1538 | // TODO remove some day |
| 1539 | 1539 | SlashCommandNamedArgument.fromProps({ |
| 1540 | 1540 | name: 'format', |
| 1541 | 1541 | description: '!!! DEPRECATED - use "return" instead !!! output format)', |
| 1542 | 1542 | typeList: [ARGUMENT_TYPE.STRING], |
| 1543 | 1543 | isRequired: true, |
| 1544 | 1544 | forceEnum: true, |
| @@ -23,7 +23,7 @@ export const slashCommandReturnHelper = { | ||
| 23 | 23 | */ |
| 24 | 24 | enumList: ({ allowPipe = true, allowObject = false, allowChat = false, allowPopup = false, allowTextVersion = true } = {}) => [ |
| 25 | 25 | allowPipe && new SlashCommandEnumValue('pipe', 'Return to the pipe for the next command', enumTypes.name, '|'), |
| 26 | 26 | allowObject && new SlashCommandEnumValue('object', 'Return as an object (or array) to the pipe for the next command', enumTypes.variable, enumIcons.dictionary), |
| 27 | 27 | allowChat && new SlashCommandEnumValue('chat-html', 'Sending a chat message with the return value - Can display HTML', enumTypes.command, enumIcons.message), |
| 28 | 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 | 29 | allowPopup && new SlashCommandEnumValue('popup-html', 'Showing as a popup with the return value - Can display HTML', enumTypes.command, enumIcons.popup), |
| @@ -951,7 +951,7 @@ export function registerVariableCommands() { | ||
| 951 | 951 | // TODO remove some day |
| 952 | 952 | SlashCommandNamedArgument.fromProps({ |
| 953 | 953 | name: 'format', |
| 954 | 954 | description: '!!! DEPRECATED - use "return" instead !!! output format)', |
| 955 | 955 | typeList: [ARGUMENT_TYPE.STRING], |
| 956 | 956 | isRequired: true, |
| 957 | 957 | forceEnum: true, |