diff --git a/public/scripts/PromptManager.js b/public/scripts/PromptManager.js index 5685d911a..e08a526e9 100644 --- a/public/scripts/PromptManager.js +++ b/public/scripts/PromptManager.js @@ -64,6 +64,7 @@ function PromptManagerModule() { containerIdentifier: '', listIdentifier: '', listItemTemplateIdentifier: '', + toggleDisabled: [], draggable: true }; @@ -367,6 +368,24 @@ PromptManagerModule.prototype.isPromptDeletionAllowed = function (prompt) { return false === prompt.system_prompt; } +/** + * Check whether a prompt can be edited. + * @param {object} prompt - The prompt to check. + * @returns {boolean} True if the prompt can be deleted, false otherwise. + */ +PromptManagerModule.prototype.isPromptEditAllowed = function (prompt) { + return true; +} + +/** + * Check whether a prompt can be toggled on or off. + * @param {object} prompt - The prompt to check. + * @returns {boolean} True if the prompt can be deleted, false otherwise. + */ +PromptManagerModule.prototype.isPromptToggleAllowed = function (prompt) { + return !this.configuration.toggleDisabled.includes(prompt.identifier); +} + /** * Handle the deletion of a character by removing their prompt list and nullifying the active character if it was the one deleted. * @param {object} event - The event object containing the character's ID. @@ -706,7 +725,21 @@ PromptManagerModule.prototype.renderPromptManagerListItems = function () { let detachSpanHtml = ''; if (this.isPromptDeletionAllowed(prompt)) { detachSpanHtml = ` - + + `; + } + + let editSpanHtml = ''; + if (this.isPromptEditAllowed(prompt)) { + editSpanHtml = ` + + `; + } + + let toggleSpanHtml = ''; + if (this.isPromptToggleAllowed(prompt)) { + toggleSpanHtml = ` + `; } @@ -720,8 +753,8 @@ PromptManagerModule.prototype.renderPromptManagerListItems = function () { ${detachSpanHtml} - - + ${editSpanHtml} + ${toggleSpanHtml} `} @@ -733,15 +766,15 @@ PromptManagerModule.prototype.renderPromptManagerListItems = function () { promptManagerList.insertAdjacentHTML('beforeend', listItemHtml); // Now that the new elements are in the DOM, you can add the event listeners. - Array.from(promptManagerList.getElementsByClassName('fa-x')).forEach(el => { + Array.from(promptManagerList.getElementsByClassName('prompt-manager-detach-action')).forEach(el => { el.addEventListener('click', this.handleDetach); }); - Array.from(promptManagerList.getElementsByClassName('fa-pencil')).forEach(el => { + Array.from(promptManagerList.getElementsByClassName('prompt-manager-edit-action')).forEach(el => { el.addEventListener('click', this.handleEdit); }); - Array.from(promptManagerList.querySelectorAll('.prompt_manager_prompt_controls span:last-child')).forEach(el => { + Array.from(promptManagerList.querySelectorAll('.prompt-manager-toggle-action')).forEach(el => { el.addEventListener('click', this.handleToggle); }); }; diff --git a/public/scripts/openai.js b/public/scripts/openai.js index beab66ba1..a6ffd9c82 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -277,6 +277,7 @@ function setupOpenAIPromptManager(openAiSettings) { prefix: 'openai_', containerIdentifier: 'openai_prompt_manager', listIdentifier: 'openai_prompt_manager_list', + toggleDisabled: ['main'], draggable: true }; @@ -580,11 +581,12 @@ async function prepareOpenAIMessages({ try { populateChatCompletion(prompts, chatCompletion, {bias, quietPrompt, type}); } catch (error) { - toastr.error('An error occurred while counting tokens.') if (error instanceof TokenBudgetExceededError) { + toastr.error('An error occurred while counting tokens: Token budget exceeded.') chatCompletion.log('Token budget exceeded.'); promptManager.error = 'Not enough free tokens for mandatory prompts. Raise your token Limit or disable custom prompts.'; } else { + toastr.error('An unknown error occurred while counting tokens. Further info available in console.') chatCompletion.log('Unexpected error:'); chatCompletion.log(error); }