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';
8import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';8import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';
9import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js';9import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js';
10import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';10import { SlashCommandParser } from './slash-commands/SlashCommandParser.js';
11import { copyText, escapeRegex } from './utils.js';11import { copyText, escapeRegex, isFalseBoolean } from './utils.js';
1212
13/**13/**
14 * Gets a message from a jQuery element.14 * Gets a message from a jQuery element.
@@ -172,13 +172,22 @@ function registerReasoningSlashCommands() {
172 name: 'reasoning-parse',172 name: 'reasoning-parse',
173 returns: 'reasoning string',173 returns: 'reasoning string',
174 helpString: t`Extracts the reasoning block from a string using the Reasoning Formatting settings.`,174 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 ],
175 unnamedArgumentList: [184 unnamedArgumentList: [
176 SlashCommandArgument.fromProps({185 SlashCommandArgument.fromProps({
177 description: 'input string',186 description: 'input string',
178 typeList: ARGUMENT_TYPE.STRING,187 typeList: ARGUMENT_TYPE.STRING,
179 }),188 }),
180 ],189 ],
181 callback: (_, value) => {190 callback: (args, value) => {
182 if (!value) {191 if (!value) {
183 return '';192 return '';
184 }193 }
@@ -194,7 +203,10 @@ function registerReasoningSlashCommands() {
194 return '';203 return '';
195 }204 }
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;
198 },210 },
199 }));211 }));
200}212}
@@ -398,7 +410,7 @@ function registerReasoningAppEvents() {
398410
399 // If reasoning was found, add it to the message411 // If reasoning was found, add it to the message
400 if (parsedReasoning.reasoning) {412 if (parsedReasoning.reasoning) {
401 message.extra.reasoning = parsedReasoning.reasoning;413 message.extra.reasoning = getRegexedString(parsedReasoning.reasoning, regex_placement.REASONING);
402 }414 }
403415
404 // Update the message text if it was changed416 // Update the message text if it was changed