Confirm custom PM prompt deletion
| @@ -1,12 +1,13 @@ | |||
| 1 | 'use strict'; | 1 | 'use strict'; |
| 2 | 2 | ||
| 3 | import { callPopup, event_types, eventSource, is_send_press, main_api, substituteParams } from '../script.js'; | 3 | import { event_types, eventSource, is_send_press, main_api, substituteParams } from '../script.js'; |
| 4 | import { is_group_generating } from './group-chats.js'; | 4 | import { is_group_generating } from './group-chats.js'; |
| 5 | import { Message, TokenHandler } from './openai.js'; | 5 | import { Message, TokenHandler } from './openai.js'; |
| 6 | import { power_user } from './power-user.js'; | 6 | import { power_user } from './power-user.js'; |
| 7 | import { debounce, waitUntilCondition, escapeHtml } from './utils.js'; | 7 | import { debounce, waitUntilCondition, escapeHtml } from './utils.js'; |
| 8 | import { debounce_timeout } from './constants.js'; | 8 | import { debounce_timeout } from './constants.js'; |
| 9 | import { renderTemplateAsync } from './templates.js'; | 9 | import { renderTemplateAsync } from './templates.js'; |
| 10 | import { Popup } from './popup.js'; | ||
| 10 | 11 | ||
| 11 | function debouncePromise(func, delay) { | 12 | function debouncePromise(func, delay) { |
| 12 | let timeoutId; | 13 | let timeoutId; |
| @@ -453,21 +454,24 @@ class PromptManager { | |||
| 453 | }; | 454 | }; |
| 454 | 455 | ||
| 455 | // Delete selected prompt from list form and close edit form | 456 | // Delete selected prompt from list form and close edit form |
| 456 | this.handleDeletePrompt = (event) => { | 457 | this.handleDeletePrompt = async (event) => { |
| 457 | const promptID = document.getElementById(this.configuration.prefix + 'prompt_manager_footer_append_prompt').value; | 458 | Popup.show.confirm('Are you sure you want to delete this prompt?', null).then((userChoice) => { |
| 458 | const prompt = this.getPromptById(promptID); | 459 | if (!userChoice) return; |
| 460 | const promptID = document.getElementById(this.configuration.prefix + 'prompt_manager_footer_append_prompt').value; | ||
| 461 | const prompt = this.getPromptById(promptID); | ||
| 459 | 462 | ||
| 460 | if (prompt && true === this.isPromptDeletionAllowed(prompt)) { | 463 | if (prompt && true === this.isPromptDeletionAllowed(prompt)) { |
| 461 | const promptIndex = this.getPromptIndexById(promptID); | 464 | const promptIndex = this.getPromptIndexById(promptID); |
| 462 | this.serviceSettings.prompts.splice(Number(promptIndex), 1); | 465 | this.serviceSettings.prompts.splice(Number(promptIndex), 1); |
| 463 | 466 | ||
| 464 | this.log('Deleted prompt: ' + prompt.identifier); | 467 | this.log('Deleted prompt: ' + prompt.identifier); |
| 465 | 468 | ||
| 466 | this.hidePopup(); | 469 | this.hidePopup(); |
| 467 | this.clearEditForm(); | 470 | this.clearEditForm(); |
| 468 | this.render(); | 471 | this.render(); |
| 469 | this.saveServiceSettings(); | 472 | this.saveServiceSettings(); |
| 470 | } | 473 | } |
| 474 | }); | ||
| 471 | }; | 475 | }; |
| 472 | 476 | ||
| 473 | // Create new prompt, then save it to settings and close form. | 477 | // Create new prompt, then save it to settings and close form. |
| @@ -527,9 +531,9 @@ class PromptManager { | |||
| 527 | 531 | ||
| 528 | // Import prompts for the selected character | 532 | // Import prompts for the selected character |
| 529 | this.handleImport = () => { | 533 | this.handleImport = () => { |
| 530 | callPopup('Existing prompts with the same ID will be overridden. Do you want to proceed?', 'confirm') | 534 | Popup.show.confirm('Existing prompts with the same ID will be overridden. Do you want to proceed?', null) |
| 531 | .then(userChoice => { | 535 | .then(userChoice => { |
| 532 | if (false === userChoice) return; | 536 | if (!userChoice) return; |
| 533 | 537 | ||
| 534 | const fileOpener = document.createElement('input'); | 538 | const fileOpener = document.createElement('input'); |
| 535 | fileOpener.type = 'file'; | 539 | fileOpener.type = 'file'; |
| @@ -563,9 +567,9 @@ class PromptManager { | |||
| 563 | 567 | ||
| 564 | // Restore default state of a characters prompt order | 568 | // Restore default state of a characters prompt order |
| 565 | this.handleCharacterReset = () => { | 569 | this.handleCharacterReset = () => { |
| 566 | callPopup('This will reset the prompt order for this character. You will not lose any prompts.', 'confirm') | 570 | Popup.show.confirm('This will reset the prompt order for this character. You will not lose any prompts.', null) |
| 567 | .then(userChoice => { | 571 | .then(userChoice => { |
| 568 | if (false === userChoice) return; | 572 | if (!userChoice) return; |
| 569 | 573 | ||
| 570 | this.removePromptOrderForCharacter(this.activeCharacter); | 574 | this.removePromptOrderForCharacter(this.activeCharacter); |
| 571 | this.addPromptOrderForCharacter(this.activeCharacter, promptManagerDefaultPromptOrder); | 575 | this.addPromptOrderForCharacter(this.activeCharacter, promptManagerDefaultPromptOrder); |
| @@ -1538,7 +1542,7 @@ class PromptManager { | |||
| 1538 | const encodedName = escapeHtml(prompt.name); | 1542 | const encodedName = escapeHtml(prompt.name); |
| 1539 | const isMarkerPrompt = prompt.marker && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE; | 1543 | const isMarkerPrompt = prompt.marker && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE; |
| 1540 | const isSystemPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && !prompt.forbid_overrides; | 1544 | const isSystemPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && !prompt.forbid_overrides; |
| 1541 | const isImportantPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && prompt.forbid_overrides; | 1545 | const isImportantPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && prompt.forbid_overrides; |
| 1542 | const isUserPrompt = !prompt.marker && !prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE; | 1546 | const isUserPrompt = !prompt.marker && !prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE; |
| 1543 | const isInjectionPrompt = prompt.injection_position === INJECTION_POSITION.ABSOLUTE; | 1547 | const isInjectionPrompt = prompt.injection_position === INJECTION_POSITION.ABSOLUTE; |
| 1544 | const isOverriddenPrompt = Array.isArray(this.overriddenPrompts) && this.overriddenPrompts.includes(prompt.identifier); | 1548 | const isOverriddenPrompt = Array.isArray(this.overriddenPrompts) && this.overriddenPrompts.includes(prompt.identifier); |