Apply regex to parsed reasoning

4b2575f3017b71995516c8948873fb81351753b5

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

1 files changed, +16 -4Ignore whitespace
public/scripts/reasoning.js+16 -4
@@ -8,7 +8,7 @@ import { SlashCommand } from './slash-commands/SlashCommand.js';
88import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';
99import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js';
1010import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
1111import { copyText, escapeRegex, isFalseBoolean } from './utils.js';
1212
1313/**
1414 * Gets a message from a jQuery element.
@@ -172,13 +172,22 @@ function registerReasoningSlashCommands() {
172172 name: 'reasoning-parse',
173173 returns: 'reasoning string',
174174 helpString: t`Extracts the reasoning block from a string using the Reasoning Formatting settings.`,
175+ namedArgumentList: [
176+ SlashCommandNamedArgument.fromProps({
177+ name: 'regex',
178+ description: 'Whether to apply regex scripts to the reasoning content.',
179+ typeList: ARGUMENT_TYPE.BOOLEAN,
180+ defaultValue: 'true',
181+ isRequired: false,
182+ }),
183+ ],
175184 unnamedArgumentList: [
176185 SlashCommandArgument.fromProps({
177186 description: 'input string',
178187 typeList: ARGUMENT_TYPE.STRING,
179188 }),
180189 ],
181190 callback: (_args, value) => {
182191 if (!value) {
183192 return '';
184193 }
@@ -194,7 +203,10 @@ function registerReasoningSlashCommands() {
194203 return '';
195204 }
196205
197- return getRegexedString(parsedReasoning.reasoning, regex_placement.REASONING);
206+ const applyRegex = !isFalseBoolean(args.regex.toString());
207+ return applyRegex
208+ ? getRegexedString(parsedReasoning.reasoning, regex_placement.REASONING)
209+ : parsedReasoning.reasoning;
198210 },
199211 }));
200212}
@@ -398,7 +410,7 @@ function registerReasoningAppEvents() {
398410
399411 // If reasoning was found, add it to the message
400412 if (parsedReasoning.reasoning) {
401413 message.extra.reasoning = getRegexedString(parsedReasoning.reasoning, regex_placement.REASONING);
402414 }
403415
404416 // Update the message text if it was changed