Adjust reasoning template migration procedure

b1346910a451cebf70257f6fb7bbd230f876d354

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

2 files changed, +29 -4Showing whitespace changes
public/scripts/power-user.js+2 -2
@@ -55,7 +55,7 @@ import { POPUP_TYPE, callGenericPopup } from './popup.js';
5555import { loadSystemPrompts } from './sysprompt.js';
5656import { fuzzySearchCategories } from './filters.js';
5757import { accountStorage } from './util/AccountStorage.js';
5858import { DEFAULT_REASONING_TEMPLATE, loadReasoningTemplates } from './reasoning.js';
5959
6060export {
6161 loadPowerUserSettings,
@@ -258,7 +258,7 @@ let power_user = {
258258 },
259259
260260 reasoning: {
261261 name: 'DeepSeek'DEFAULT_REASONING_TEMPLATE,
262262 auto_parse: false,
263263 add_to_prompts: false,
264264 auto_expand: false,
public/scripts/reasoning.js+27 -2
@@ -8,6 +8,7 @@ import { MacrosParser } from './macros.js';
88import { chat_completion_sources, getChatCompletionModel, oai_settings } from './openai.js';
99import { Popup } from './popup.js';
1010import { performFuzzySearch, power_user } from './power-user.js';
11+import { getPresetManager } from './preset-manager.js';
1112import { SlashCommand } from './slash-commands/SlashCommand.js';
1213import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';
1314import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';
@@ -29,6 +30,8 @@ import { copyText, escapeRegex, isFalseBoolean, isTrueBoolean, setDatasetPropert
2930 */
3031export const reasoning_templates = [];
3132
33+export const DEFAULT_REASONING_TEMPLATE = 'DeepSeek';
34+
3235/**
3336 * @type {Record<string, JQuery<HTMLElement>>} List of UI elements for reasoning settings
3437 * @readonly
@@ -1337,8 +1340,30 @@ export async function loadReasoningTemplates(data) {
13371340 $('<option>').val(template.name).text(template.name).appendTo(UI.$select);
13381341 }
13391342
1340- if (!power_user.reasoning.name) {
1343+ // No template name, need to migrate
1341- power_user.reasoning.name = reasoning_templates[0]?.name ?? '';
1344+ if (power_user.reasoning.name === undefined) {
1345+ const defaultTemplate = reasoning_templates.find(p => p.name === DEFAULT_REASONING_TEMPLATE);
1346+ if (defaultTemplate) {
1347+ // If the reasoning settings were modified - migrate them to a custom template
1348+ if (power_user.reasoning.prefix !== defaultTemplate.prefix || power_user.reasoning.suffix !== defaultTemplate.suffix || power_user.reasoning.separator !== defaultTemplate.separator) {
1349+ /** @type {ReasoningTemplate} */
1350+ const data = {
1351+ name: '[Migrated] Custom',
1352+ prefix: power_user.reasoning.prefix,
1353+ suffix: power_user.reasoning.suffix,
1354+ separator: power_user.reasoning.separator,
1355+ };
1356+ await getPresetManager('reasoning')?.savePreset(data.name, data);
1357+ power_user.reasoning.name = data.name;
1358+ } else {
1359+ power_user.reasoning.name = defaultTemplate.name;
1360+ }
1361+ } else {
1362+ // Template not found (deleted or content check skipped - leave blank)
1363+ power_user.reasoning.name = '';
1364+ }
1365+
1366+ saveSettingsDebounced();
13421367 }
13431368
13441369 UI.$select.val(power_user.reasoning.name);