Add /reasoning-parse command

4e7326b61bbc01c34246252aceaf9348baf013f7

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

1 files changed, +30 -0Showing whitespace changes
public/scripts/reasoning.js+30 -0
@@ -167,6 +167,36 @@ function registerReasoningSlashCommands() {
167167 return message.extra.reasoning;
168168 },
169169 }));
170+
171+ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
172+ name: 'reasoning-parse',
173+ returns: 'reasoning string',
174+ helpString: t`Extracts the reasoning block from a string using the Reasoning Formatting settings.`,
175+ unnamedArgumentList: [
176+ SlashCommandArgument.fromProps({
177+ description: 'input string',
178+ typeList: ARGUMENT_TYPE.STRING,
179+ }),
180+ ],
181+ callback: (_, value) => {
182+ if (!value) {
183+ return '';
184+ }
185+
186+ if (!power_user.reasoning.prefix || !power_user.reasoning.suffix) {
187+ toastr.warning(t`Both prefix and suffix must be set in the Reasoning Formatting settings.`);
188+ return value.toString();
189+ }
190+
191+ const parsedReasoning = parseReasoningFromString(value.toString());
192+
193+ if (!parsedReasoning) {
194+ return '';
195+ }
196+
197+ return getRegexedString(parsedReasoning.reasoning, regex_placement.REASONING);
198+ },
199+ }));
170200}
171201
172202function registerReasoningMacros() {