import { saveSettingsDebounced } from '../script.js'; import { callGenericPopup, POPUP_TYPE } from './popup.js'; import { power_user } from './power-user.js'; import { getPresetManager } from './preset-manager.js'; import { SlashCommand } from './slash-commands/SlashCommand.js'; import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from './slash-commands/SlashCommandArgument.js'; import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js'; import { enumTypes, SlashCommandEnumValue } from './slash-commands/SlashCommandEnumValue.js'; import { SlashCommandParser } from './slash-commands/SlashCommandParser.js'; import { renderTemplateAsync } from './templates.js'; import { isTrueBoolean, resetScrollHeight } from './utils.js'; export let system_prompts = []; const $enabled = $('#sysprompt_enabled'); const $select = $('#sysprompt_select'); const $content = $('#sysprompt_content'); const $contentBlock = $('#SystemPromptBlock'); async function migrateSystemPromptFromInstructMode() { if ('system_prompt' in power_user.instruct) { const prompt = String(power_user.instruct.system_prompt); delete power_user.instruct.system_prompt; power_user.sysprompt.enabled = power_user.instruct.enabled; power_user.sysprompt.content = prompt; const existingPromptName = system_prompts.find(x => x.content === prompt)?.name; if (existingPromptName) { power_user.sysprompt.name = existingPromptName; } else { const data = { name: `[Migrated] ${power_user.instruct.preset}`, content: prompt }; await getPresetManager('sysprompt')?.savePreset(data.name, data); power_user.sysprompt.name = data.name; } saveSettingsDebounced(); toastr.info('System prompt settings have been moved from the Instruct Mode.', 'Migration notice', { timeOut: 5000 }); } } /** * Loads sysprompt settings from the given data object. * @param {object} data Settings data object. */ export async function loadSystemPrompts(data) { if (data.sysprompt !== undefined) { system_prompts = data.sysprompt; } await migrateSystemPromptFromInstructMode(); toggleSystemPromptDisabledControls(); for (const prompt of system_prompts) { $('