mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Confirm custom PM prompt deletion
This commit is contained in:
@ -1,12 +1,13 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import { callPopup, event_types, eventSource, is_send_press, main_api, substituteParams } from '../script.js';
|
import { event_types, eventSource, is_send_press, main_api, substituteParams } from '../script.js';
|
||||||
import { is_group_generating } from './group-chats.js';
|
import { is_group_generating } from './group-chats.js';
|
||||||
import { Message, TokenHandler } from './openai.js';
|
import { Message, TokenHandler } from './openai.js';
|
||||||
import { power_user } from './power-user.js';
|
import { power_user } from './power-user.js';
|
||||||
import { debounce, waitUntilCondition, escapeHtml } from './utils.js';
|
import { debounce, waitUntilCondition, escapeHtml } from './utils.js';
|
||||||
import { debounce_timeout } from './constants.js';
|
import { debounce_timeout } from './constants.js';
|
||||||
import { renderTemplateAsync } from './templates.js';
|
import { renderTemplateAsync } from './templates.js';
|
||||||
|
import { Popup } from './popup.js';
|
||||||
|
|
||||||
function debouncePromise(func, delay) {
|
function debouncePromise(func, delay) {
|
||||||
let timeoutId;
|
let timeoutId;
|
||||||
@ -453,21 +454,24 @@ class PromptManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Delete selected prompt from list form and close edit form
|
// Delete selected prompt from list form and close edit form
|
||||||
this.handleDeletePrompt = (event) => {
|
this.handleDeletePrompt = async (event) => {
|
||||||
const promptID = document.getElementById(this.configuration.prefix + 'prompt_manager_footer_append_prompt').value;
|
Popup.show.confirm('Are you sure you want to delete this prompt?', null).then((userChoice) => {
|
||||||
const prompt = this.getPromptById(promptID);
|
if (!userChoice) return;
|
||||||
|
const promptID = document.getElementById(this.configuration.prefix + 'prompt_manager_footer_append_prompt').value;
|
||||||
|
const prompt = this.getPromptById(promptID);
|
||||||
|
|
||||||
if (prompt && true === this.isPromptDeletionAllowed(prompt)) {
|
if (prompt && true === this.isPromptDeletionAllowed(prompt)) {
|
||||||
const promptIndex = this.getPromptIndexById(promptID);
|
const promptIndex = this.getPromptIndexById(promptID);
|
||||||
this.serviceSettings.prompts.splice(Number(promptIndex), 1);
|
this.serviceSettings.prompts.splice(Number(promptIndex), 1);
|
||||||
|
|
||||||
this.log('Deleted prompt: ' + prompt.identifier);
|
this.log('Deleted prompt: ' + prompt.identifier);
|
||||||
|
|
||||||
this.hidePopup();
|
this.hidePopup();
|
||||||
this.clearEditForm();
|
this.clearEditForm();
|
||||||
this.render();
|
this.render();
|
||||||
this.saveServiceSettings();
|
this.saveServiceSettings();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create new prompt, then save it to settings and close form.
|
// Create new prompt, then save it to settings and close form.
|
||||||
@ -527,9 +531,9 @@ class PromptManager {
|
|||||||
|
|
||||||
// Import prompts for the selected character
|
// Import prompts for the selected character
|
||||||
this.handleImport = () => {
|
this.handleImport = () => {
|
||||||
callPopup('Existing prompts with the same ID will be overridden. Do you want to proceed?', 'confirm')
|
Popup.show.confirm('Existing prompts with the same ID will be overridden. Do you want to proceed?', null)
|
||||||
.then(userChoice => {
|
.then(userChoice => {
|
||||||
if (false === userChoice) return;
|
if (!userChoice) return;
|
||||||
|
|
||||||
const fileOpener = document.createElement('input');
|
const fileOpener = document.createElement('input');
|
||||||
fileOpener.type = 'file';
|
fileOpener.type = 'file';
|
||||||
@ -563,9 +567,9 @@ class PromptManager {
|
|||||||
|
|
||||||
// Restore default state of a characters prompt order
|
// Restore default state of a characters prompt order
|
||||||
this.handleCharacterReset = () => {
|
this.handleCharacterReset = () => {
|
||||||
callPopup('This will reset the prompt order for this character. You will not lose any prompts.', 'confirm')
|
Popup.show.confirm('This will reset the prompt order for this character. You will not lose any prompts.', null)
|
||||||
.then(userChoice => {
|
.then(userChoice => {
|
||||||
if (false === userChoice) return;
|
if (!userChoice) return;
|
||||||
|
|
||||||
this.removePromptOrderForCharacter(this.activeCharacter);
|
this.removePromptOrderForCharacter(this.activeCharacter);
|
||||||
this.addPromptOrderForCharacter(this.activeCharacter, promptManagerDefaultPromptOrder);
|
this.addPromptOrderForCharacter(this.activeCharacter, promptManagerDefaultPromptOrder);
|
||||||
@ -1538,7 +1542,7 @@ class PromptManager {
|
|||||||
const encodedName = escapeHtml(prompt.name);
|
const encodedName = escapeHtml(prompt.name);
|
||||||
const isMarkerPrompt = prompt.marker && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE;
|
const isMarkerPrompt = prompt.marker && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE;
|
||||||
const isSystemPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && !prompt.forbid_overrides;
|
const isSystemPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && !prompt.forbid_overrides;
|
||||||
const isImportantPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && prompt.forbid_overrides;
|
const isImportantPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && prompt.forbid_overrides;
|
||||||
const isUserPrompt = !prompt.marker && !prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE;
|
const isUserPrompt = !prompt.marker && !prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE;
|
||||||
const isInjectionPrompt = prompt.injection_position === INJECTION_POSITION.ABSOLUTE;
|
const isInjectionPrompt = prompt.injection_position === INJECTION_POSITION.ABSOLUTE;
|
||||||
const isOverriddenPrompt = Array.isArray(this.overriddenPrompts) && this.overriddenPrompts.includes(prompt.identifier);
|
const isOverriddenPrompt = Array.isArray(this.overriddenPrompts) && this.overriddenPrompts.includes(prompt.identifier);
|
||||||
|
Reference in New Issue
Block a user