Adjust reasoning template migration procedure

b1346910a451cebf70257f6fb7bbd230f876d354

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

2 files changed, +29 -4Ignore whitespace
public/scripts/power-user.js+2 -2
@@ -55,7 +55,7 @@ import { POPUP_TYPE, callGenericPopup } from './popup.js';
55import { loadSystemPrompts } from './sysprompt.js';55import { loadSystemPrompts } from './sysprompt.js';
56import { fuzzySearchCategories } from './filters.js';56import { fuzzySearchCategories } from './filters.js';
57import { accountStorage } from './util/AccountStorage.js';57import { accountStorage } from './util/AccountStorage.js';
58import { loadReasoningTemplates } from './reasoning.js';58import { DEFAULT_REASONING_TEMPLATE, loadReasoningTemplates } from './reasoning.js';
5959
60export {60export {
61 loadPowerUserSettings,61 loadPowerUserSettings,
@@ -258,7 +258,7 @@ let power_user = {
258 },258 },
259259
260 reasoning: {260 reasoning: {
261 name: 'DeepSeek',261 name: DEFAULT_REASONING_TEMPLATE,
262 auto_parse: false,262 auto_parse: false,
263 add_to_prompts: false,263 add_to_prompts: false,
264 auto_expand: false,264 auto_expand: false,
public/scripts/reasoning.js+27 -2
@@ -8,6 +8,7 @@ import { MacrosParser } from './macros.js';
8import { chat_completion_sources, getChatCompletionModel, oai_settings } from './openai.js';8import { chat_completion_sources, getChatCompletionModel, oai_settings } from './openai.js';
9import { Popup } from './popup.js';9import { Popup } from './popup.js';
10import { performFuzzySearch, power_user } from './power-user.js';10import { performFuzzySearch, power_user } from './power-user.js';
11import { getPresetManager } from './preset-manager.js';
11import { SlashCommand } from './slash-commands/SlashCommand.js';12import { SlashCommand } from './slash-commands/SlashCommand.js';
12import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';13import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js';
13import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';14import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';
@@ -29,6 +30,8 @@ import { copyText, escapeRegex, isFalseBoolean, isTrueBoolean, setDatasetPropert
29 */30 */
30export const reasoning_templates = [];31export const reasoning_templates = [];
3132
33export const DEFAULT_REASONING_TEMPLATE = 'DeepSeek';
34
32/**35/**
33 * @type {Record<string, JQuery<HTMLElement>>} List of UI elements for reasoning settings36 * @type {Record<string, JQuery<HTMLElement>>} List of UI elements for reasoning settings
34 * @readonly37 * @readonly
@@ -1337,8 +1340,30 @@ export async function loadReasoningTemplates(data) {
1337 $('<option>').val(template.name).text(template.name).appendTo(UI.$select);1340 $('<option>').val(template.name).text(template.name).appendTo(UI.$select);
1338 }1341 }
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();
1342 }1367 }
13431368
1344 UI.$select.val(power_user.reasoning.name);1369 UI.$select.val(power_user.reasoning.name);