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 | import { isFunctionCallingSupported } from '../../openai.js'; | 12 | import { isFunctionCallingSupported } from '../../openai.js'; |
| 13 | import { SlashCommandEnumValue, enumTypes } from '../../slash-commands/SlashCommandEnumValue.js'; | 13 | import { SlashCommandEnumValue, enumTypes } from '../../slash-commands/SlashCommandEnumValue.js'; |
| 14 | import { commonEnumProviders } from '../../slash-commands/SlashCommandCommonEnumsProvider.js'; | 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 | export { MODULE_NAME }; | 17 | export { MODULE_NAME }; |
| 16 | 18 | ||
| 17 | const MODULE_NAME = 'expressions'; | 19 | const 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 |
| 2133 | case 'json': | 2135 | let returnType = args.return; |
| 2134 | return JSON.stringify(list); | 2136 | |
| 2135 | default: | 2137 | // Old legacy return type handling |
| 2136 | return list.join(', '); | 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) { | ||
| 2142 | case 'json': | ||
| 2143 | returnType = 'object'; | ||
| 2144 | break; | ||
| 2145 | default: | ||
| 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, ', '), |
| @@ -1538,7 +1538,7 @@ export function initDefaultSlashCommands() { | |||
| 1538 | // TODO remove some day | 1538 | // 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, |
| @@ -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), |
| @@ -951,7 +951,7 @@ export function registerVariableCommands() { | |||
| 951 | // TODO remove some day | 951 | // 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, |