mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
lint: Require semicolons
This commit is contained in:
@ -29,7 +29,7 @@ const DEFAULT_DEPTH = 4;
|
||||
export const INJECTION_POSITION = {
|
||||
RELATIVE: 0,
|
||||
ABSOLUTE: 1,
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Register migrations for the prompt manager when settings are loaded or an Open AI preset is loaded.
|
||||
@ -44,17 +44,17 @@ const registerPromptManagerMigration = () => {
|
||||
|
||||
const findPrompt = (identifier) => settings.prompts.find(prompt => identifier === prompt.identifier);
|
||||
if (settings.main_prompt) {
|
||||
findPrompt('main').content = settings.main_prompt
|
||||
findPrompt('main').content = settings.main_prompt;
|
||||
delete settings.main_prompt;
|
||||
}
|
||||
|
||||
if (settings.nsfw_prompt) {
|
||||
findPrompt('nsfw').content = settings.nsfw_prompt
|
||||
findPrompt('nsfw').content = settings.nsfw_prompt;
|
||||
delete settings.nsfw_prompt;
|
||||
}
|
||||
|
||||
if (settings.jailbreak_prompt) {
|
||||
findPrompt('jailbreak').content = settings.jailbreak_prompt
|
||||
findPrompt('jailbreak').content = settings.jailbreak_prompt;
|
||||
delete settings.jailbreak_prompt;
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ const registerPromptManagerMigration = () => {
|
||||
|
||||
eventSource.on(event_types.SETTINGS_LOADED_BEFORE, settings => migrate(settings));
|
||||
eventSource.on(event_types.OAI_PRESET_CHANGED_BEFORE, event => migrate(event.preset, event.savePreset, event.presetName));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents a prompt.
|
||||
@ -322,7 +322,7 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
||||
this.loadPromptIntoEditForm(prompt);
|
||||
|
||||
this.showPopup();
|
||||
}
|
||||
};
|
||||
|
||||
// Open edit form and load selected prompt
|
||||
this.handleInspect = (event) => {
|
||||
@ -337,7 +337,7 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
||||
|
||||
this.showPopup('inspect');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Detach selected prompt from list form and close edit form
|
||||
this.handleDetach = (event) => {
|
||||
@ -373,7 +373,7 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
||||
this.hidePopup();
|
||||
this.clearEditForm();
|
||||
this.saveServiceSettings().then(() => this.render());
|
||||
}
|
||||
};
|
||||
|
||||
// Reset prompt should it be a system prompt
|
||||
this.handleResetPrompt = (event) => {
|
||||
@ -409,7 +409,7 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
||||
if (!this.systemPrompts.includes(promptId)) {
|
||||
document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position').removeAttribute('disabled');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Append prompt to selected character
|
||||
this.handleAppendPrompt = (event) => {
|
||||
@ -420,7 +420,7 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
||||
this.appendPrompt(prompt, this.activeCharacter);
|
||||
this.saveServiceSettings().then(() => this.render());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Delete selected prompt from list form and close edit form
|
||||
this.handleDeletePrompt = (event) => {
|
||||
@ -446,11 +446,11 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
||||
name: '',
|
||||
role: 'system',
|
||||
content: ''
|
||||
}
|
||||
};
|
||||
|
||||
this.loadPromptIntoEditForm(prompt);
|
||||
this.showPopup();
|
||||
}
|
||||
};
|
||||
|
||||
// Export all user prompts
|
||||
this.handleFullExport = () => {
|
||||
@ -465,16 +465,16 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
||||
} else if ('character' === this.configuration.promptOrder.strategy) {
|
||||
promptOrder = [];
|
||||
} else {
|
||||
throw new Error('Prompt order strategy not supported.')
|
||||
throw new Error('Prompt order strategy not supported.');
|
||||
}
|
||||
|
||||
const exportPrompts = {
|
||||
prompts: prompts,
|
||||
prompt_order: promptOrder
|
||||
}
|
||||
};
|
||||
|
||||
this.export(exportPrompts, 'full', 'st-prompts');
|
||||
}
|
||||
};
|
||||
|
||||
// Export user prompts and order for this character
|
||||
this.handleCharacterExport = () => {
|
||||
@ -488,11 +488,11 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
||||
const exportPrompts = {
|
||||
prompts: characterPrompts,
|
||||
prompt_order: characterList
|
||||
}
|
||||
};
|
||||
|
||||
const name = this.activeCharacter.name + '-prompts';
|
||||
this.export(exportPrompts, 'character', name);
|
||||
}
|
||||
};
|
||||
|
||||
// Import prompts for the selected character
|
||||
this.handleImport = () => {
|
||||
@ -517,7 +517,7 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
||||
const data = JSON.parse(fileContent);
|
||||
this.import(data);
|
||||
} catch (err) {
|
||||
toastr.error('An error occurred while importing prompts. More info available in console.')
|
||||
toastr.error('An error occurred while importing prompts. More info available in console.');
|
||||
console.log('An error occurred while importing prompts');
|
||||
console.log(err.toString());
|
||||
}
|
||||
@ -528,7 +528,7 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
||||
|
||||
fileOpener.click();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Restore default state of a characters prompt order
|
||||
this.handleCharacterReset = () => {
|
||||
@ -541,7 +541,7 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
||||
|
||||
this.saveServiceSettings().then(() => this.render());
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Fill quick edit fields for the first time
|
||||
if ('global' === this.configuration.promptOrder.strategy) {
|
||||
@ -587,7 +587,7 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
||||
|
||||
// Re-render when the character changes.
|
||||
eventSource.on('chatLoaded', (event) => {
|
||||
this.handleCharacterSelected(event)
|
||||
this.handleCharacterSelected(event);
|
||||
this.saveServiceSettings().then(() => this.renderDebounced());
|
||||
});
|
||||
|
||||
@ -595,17 +595,17 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
||||
eventSource.on(event_types.CHARACTER_EDITED, (event) => {
|
||||
this.handleCharacterUpdated(event);
|
||||
this.saveServiceSettings().then(() => this.renderDebounced());
|
||||
})
|
||||
});
|
||||
|
||||
// Re-render when the group changes.
|
||||
eventSource.on('groupSelected', (event) => {
|
||||
this.handleGroupSelected(event)
|
||||
this.handleGroupSelected(event);
|
||||
this.saveServiceSettings().then(() => this.renderDebounced());
|
||||
});
|
||||
|
||||
// Sanitize settings after character has been deleted.
|
||||
eventSource.on('characterDeleted', (event) => {
|
||||
this.handleCharacterDeleted(event)
|
||||
this.handleCharacterDeleted(event);
|
||||
this.saveServiceSettings().then(() => this.renderDebounced());
|
||||
});
|
||||
|
||||
@ -653,7 +653,7 @@ PromptManagerModule.prototype.init = function (moduleConfiguration, serviceSetti
|
||||
// Re-render prompt manager on world settings update
|
||||
eventSource.on(event_types.WORLDINFO_SETTINGS_UPDATED, () => this.renderDebounced());
|
||||
|
||||
this.log('Initialized')
|
||||
this.log('Initialized');
|
||||
};
|
||||
|
||||
/**
|
||||
@ -675,7 +675,7 @@ PromptManagerModule.prototype.render = function (afterTryGenerate = true) {
|
||||
this.profileEnd('filling context');
|
||||
this.profileStart('render');
|
||||
this.renderPromptManager();
|
||||
this.renderPromptManagerListItems()
|
||||
this.renderPromptManagerListItems();
|
||||
this.makeDraggable();
|
||||
this.profileEnd('render');
|
||||
});
|
||||
@ -683,14 +683,14 @@ PromptManagerModule.prototype.render = function (afterTryGenerate = true) {
|
||||
// Executed during live communication
|
||||
this.profileStart('render');
|
||||
this.renderPromptManager();
|
||||
this.renderPromptManagerListItems()
|
||||
this.renderPromptManagerListItems();
|
||||
this.makeDraggable();
|
||||
this.profileEnd('render');
|
||||
}
|
||||
}).catch(() => {
|
||||
console.log('Timeout while waiting for send press to be false');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Update a prompt with the values from the HTML form.
|
||||
@ -703,7 +703,7 @@ PromptManagerModule.prototype.updatePromptWithPromptEditForm = function (prompt)
|
||||
prompt.content = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_prompt').value;
|
||||
prompt.injection_position = Number(document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_position').value);
|
||||
prompt.injection_depth = Number(document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_injection_depth').value);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Find a prompt by its identifier and update it with the provided object.
|
||||
@ -714,7 +714,7 @@ PromptManagerModule.prototype.updatePromptWithPromptEditForm = function (prompt)
|
||||
PromptManagerModule.prototype.updatePromptByIdentifier = function (identifier, updatePrompt) {
|
||||
let prompt = this.serviceSettings.prompts.find((item) => identifier === item.identifier);
|
||||
if (prompt) prompt = Object.assign(prompt, updatePrompt);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Iterate over an array of prompts, find each one by its identifier, and update them with the provided data.
|
||||
@ -725,18 +725,18 @@ PromptManagerModule.prototype.updatePrompts = function (prompts) {
|
||||
prompts.forEach((update) => {
|
||||
let prompt = this.getPromptById(update.identifier);
|
||||
if (prompt) Object.assign(prompt, update);
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
PromptManagerModule.prototype.getTokenHandler = function () {
|
||||
return this.tokenHandler;
|
||||
}
|
||||
};
|
||||
|
||||
PromptManagerModule.prototype.isPromptDisabledForActiveCharacter = function (identifier) {
|
||||
const promptOrderEntry = this.getPromptOrderEntry(this.activeCharacter, identifier);
|
||||
if (promptOrderEntry) return !promptOrderEntry.enabled;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Add a prompt to the current character's prompt list.
|
||||
@ -749,7 +749,7 @@ PromptManagerModule.prototype.appendPrompt = function (prompt, character) {
|
||||
const index = promptOrder.findIndex(entry => entry.identifier === prompt.identifier);
|
||||
|
||||
if (-1 === index) promptOrder.push({ identifier: prompt.identifier, enabled: false });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove a prompt from the current character's prompt list.
|
||||
@ -762,8 +762,8 @@ PromptManagerModule.prototype.detachPrompt = function (prompt, character) {
|
||||
const promptOrder = this.getPromptOrderForCharacter(character);
|
||||
const index = promptOrder.findIndex(entry => entry.identifier === prompt.identifier);
|
||||
if (-1 === index) return;
|
||||
promptOrder.splice(index, 1)
|
||||
}
|
||||
promptOrder.splice(index, 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new prompt and add it to the list of prompts.
|
||||
@ -781,10 +781,10 @@ PromptManagerModule.prototype.addPrompt = function (prompt, identifier) {
|
||||
enabled: false,
|
||||
marker: false,
|
||||
...prompt
|
||||
}
|
||||
};
|
||||
|
||||
this.serviceSettings.prompts.push(newPrompt);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sanitize the service settings, ensuring each prompt has a unique identifier.
|
||||
@ -850,7 +850,7 @@ PromptManagerModule.prototype.checkForMissingPrompts = function (prompts) {
|
||||
*/
|
||||
PromptManagerModule.prototype.isPromptInspectionAllowed = function (prompt) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether a prompt can be deleted. System prompts cannot be deleted.
|
||||
@ -859,7 +859,7 @@ PromptManagerModule.prototype.isPromptInspectionAllowed = function (prompt) {
|
||||
*/
|
||||
PromptManagerModule.prototype.isPromptDeletionAllowed = function (prompt) {
|
||||
return false === prompt.system_prompt;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether a prompt can be edited.
|
||||
@ -868,7 +868,7 @@ PromptManagerModule.prototype.isPromptDeletionAllowed = function (prompt) {
|
||||
*/
|
||||
PromptManagerModule.prototype.isPromptEditAllowed = function (prompt) {
|
||||
return !prompt.marker;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Check whether a prompt can be toggled on or off.
|
||||
@ -878,7 +878,7 @@ PromptManagerModule.prototype.isPromptEditAllowed = function (prompt) {
|
||||
PromptManagerModule.prototype.isPromptToggleAllowed = function (prompt) {
|
||||
const forceTogglePrompts = ['charDescription', 'charPersonality', 'scenario', 'personaDescription', 'worldInfoBefore', 'worldInfoAfter'];
|
||||
return prompt.marker && !forceTogglePrompts.includes(prompt.identifier) ? false : !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.
|
||||
@ -889,7 +889,7 @@ PromptManagerModule.prototype.handleCharacterDeleted = function (event) {
|
||||
if ('global' === this.configuration.promptOrder.strategy) return;
|
||||
this.removePromptOrderForCharacter(this.activeCharacter);
|
||||
if (this.activeCharacter.id === event.detail.id) this.activeCharacter = null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle the selection of a character by setting them as the active character and setting up their prompt list if necessary.
|
||||
@ -900,7 +900,7 @@ PromptManagerModule.prototype.handleCharacterSelected = function (event) {
|
||||
if ('global' === this.configuration.promptOrder.strategy) {
|
||||
this.activeCharacter = { id: this.configuration.promptOrder.dummyId };
|
||||
} else if ('character' === this.configuration.promptOrder.strategy) {
|
||||
console.log('FOO')
|
||||
console.log('FOO');
|
||||
this.activeCharacter = { id: event.detail.id, ...event.detail.character };
|
||||
const promptOrder = this.getPromptOrderForCharacter(this.activeCharacter);
|
||||
|
||||
@ -910,7 +910,7 @@ PromptManagerModule.prototype.handleCharacterSelected = function (event) {
|
||||
} else {
|
||||
throw new Error('Unsupported prompt order mode.');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the most recently selected character
|
||||
@ -923,9 +923,9 @@ PromptManagerModule.prototype.handleCharacterUpdated = function (event) {
|
||||
} else if ('character' === this.configuration.promptOrder.strategy) {
|
||||
this.activeCharacter = { id: event.detail.id, ...event.detail.character };
|
||||
} else {
|
||||
throw new Error('Prompt order strategy not supported.')
|
||||
throw new Error('Prompt order strategy not supported.');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the most recently selected character group
|
||||
@ -940,11 +940,11 @@ PromptManagerModule.prototype.handleGroupSelected = function (event) {
|
||||
this.activeCharacter = characterDummy;
|
||||
const promptOrder = this.getPromptOrderForCharacter(characterDummy);
|
||||
|
||||
if (0 === promptOrder.length) this.addPromptOrderForCharacter(characterDummy, promptManagerDefaultPromptOrder)
|
||||
if (0 === promptOrder.length) this.addPromptOrderForCharacter(characterDummy, promptManagerDefaultPromptOrder);
|
||||
} else {
|
||||
throw new Error('Prompt order strategy not supported.')
|
||||
throw new Error('Prompt order strategy not supported.');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a list of group characters, regardless of whether they are active or not.
|
||||
@ -954,7 +954,7 @@ PromptManagerModule.prototype.handleGroupSelected = function (event) {
|
||||
PromptManagerModule.prototype.getActiveGroupCharacters = function () {
|
||||
// ToDo: Ideally, this should return the actual characters.
|
||||
return (this.activeCharacter?.group?.members || []).map(member => member && member.substring(0, member.lastIndexOf('.')));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the prompts for a specific character. Can be filtered to only include enabled prompts.
|
||||
@ -966,7 +966,7 @@ PromptManagerModule.prototype.getPromptsForCharacter = function (character, only
|
||||
return this.getPromptOrderForCharacter(character)
|
||||
.map(item => true === onlyEnabled ? (true === item.enabled ? this.getPromptById(item.identifier) : null) : this.getPromptById(item.identifier))
|
||||
.filter(prompt => null !== prompt);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the order of prompts for a specific character. If no character is specified or the character doesn't have a prompt list, an empty array is returned.
|
||||
@ -975,7 +975,7 @@ PromptManagerModule.prototype.getPromptsForCharacter = function (character, only
|
||||
*/
|
||||
PromptManagerModule.prototype.getPromptOrderForCharacter = function (character) {
|
||||
return !character ? [] : (this.serviceSettings.prompt_order.find(list => String(list.character_id) === String(character.id))?.order ?? []);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the prompts for the manager.
|
||||
@ -984,7 +984,7 @@ PromptManagerModule.prototype.getPromptOrderForCharacter = function (character)
|
||||
*/
|
||||
PromptManagerModule.prototype.setPrompts = function (prompts) {
|
||||
this.serviceSettings.prompts = prompts;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove the prompt list for a specific character.
|
||||
@ -994,7 +994,7 @@ PromptManagerModule.prototype.setPrompts = function (prompts) {
|
||||
PromptManagerModule.prototype.removePromptOrderForCharacter = function (character) {
|
||||
const index = this.serviceSettings.prompt_order.findIndex(list => String(list.character_id) === String(character.id));
|
||||
if (-1 !== index) this.serviceSettings.prompt_order.splice(index, 1);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a new prompt list for a specific character.
|
||||
@ -1006,7 +1006,7 @@ PromptManagerModule.prototype.addPromptOrderForCharacter = function (character,
|
||||
character_id: character.id,
|
||||
order: JSON.parse(JSON.stringify(promptOrder))
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Searches for a prompt list entry for a given character and identifier.
|
||||
@ -1016,7 +1016,7 @@ PromptManagerModule.prototype.addPromptOrderForCharacter = function (character,
|
||||
*/
|
||||
PromptManagerModule.prototype.getPromptOrderEntry = function (character, identifier) {
|
||||
return this.getPromptOrderForCharacter(character).find(entry => entry.identifier === identifier) ?? null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Finds and returns a prompt by its identifier.
|
||||
@ -1025,7 +1025,7 @@ PromptManagerModule.prototype.getPromptOrderEntry = function (character, identif
|
||||
*/
|
||||
PromptManagerModule.prototype.getPromptById = function (identifier) {
|
||||
return this.serviceSettings.prompts.find(item => item && item.identifier === identifier) ?? null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Finds and returns the index of a prompt by its identifier.
|
||||
@ -1034,7 +1034,7 @@ PromptManagerModule.prototype.getPromptById = function (identifier) {
|
||||
*/
|
||||
PromptManagerModule.prototype.getPromptIndexById = function (identifier) {
|
||||
return this.serviceSettings.prompts.findIndex(item => item.identifier === identifier) ?? null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Enriches a generic object, creating a new prompt object in the process
|
||||
@ -1056,7 +1056,7 @@ PromptManagerModule.prototype.preparePrompt = function (prompt, original = null)
|
||||
}
|
||||
|
||||
return preparedPrompt;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Factory function for creating a QuickEdit object associated with a prompt element.
|
||||
@ -1087,7 +1087,7 @@ PromptManagerModule.prototype.createQuickEdit = function (identifier, title) {
|
||||
debouncedSaveServiceSettings().then(() => this.render());
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
PromptManagerModule.prototype.updateQuickEdit = function (identifier, prompt) {
|
||||
const elementId = `${identifier}_prompt_quick_edit_textarea`;
|
||||
@ -1095,7 +1095,7 @@ PromptManagerModule.prototype.updateQuickEdit = function (identifier, prompt) {
|
||||
textarea.value = prompt.content;
|
||||
|
||||
return elementId;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if a given name is accepted by OpenAi API
|
||||
@ -1108,11 +1108,11 @@ PromptManagerModule.prototype.isValidName = function (name) {
|
||||
const regex = /^[a-zA-Z0-9_]{1,64}$/;
|
||||
|
||||
return regex.test(name);
|
||||
}
|
||||
};
|
||||
|
||||
PromptManagerModule.prototype.sanitizeName = function (name) {
|
||||
return name.replace(/[^a-zA-Z0-9_]/g, '_').substring(0, 64);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Loads a given prompt into the edit form fields.
|
||||
@ -1151,7 +1151,7 @@ PromptManagerModule.prototype.loadPromptIntoEditForm = function (prompt) {
|
||||
|
||||
const savePromptButton = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_save');
|
||||
savePromptButton.dataset.pmPrompt = prompt.identifier;
|
||||
}
|
||||
};
|
||||
|
||||
PromptManagerModule.prototype.handleInjectionPositionChange = function (event) {
|
||||
const injectionDepthBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_depth_block');
|
||||
@ -1161,7 +1161,7 @@ PromptManagerModule.prototype.handleInjectionPositionChange = function (event) {
|
||||
} else {
|
||||
injectionDepthBlock.style.visibility = 'hidden';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Loads a given prompt into the inspect form
|
||||
@ -1190,7 +1190,7 @@ PromptManagerModule.prototype.loadMessagesIntoInspectForm = function (messages)
|
||||
let template = document.createElement('template');
|
||||
template.innerHTML = drawerHTML.trim();
|
||||
return template.content.firstChild;
|
||||
}
|
||||
};
|
||||
|
||||
const messageList = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_inspect_list');
|
||||
|
||||
@ -1201,7 +1201,7 @@ PromptManagerModule.prototype.loadMessagesIntoInspectForm = function (messages)
|
||||
messagesCollection.forEach(message => {
|
||||
messageList.append(createInlineDrawer(message));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Clears all input fields in the edit form.
|
||||
@ -1226,14 +1226,14 @@ PromptManagerModule.prototype.clearEditForm = function () {
|
||||
injectionDepthBlock.style.visibility = 'unset';
|
||||
|
||||
roleField.disabled = false;
|
||||
}
|
||||
};
|
||||
|
||||
PromptManagerModule.prototype.clearInspectForm = function () {
|
||||
const inspectArea = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_inspect');
|
||||
inspectArea.style.display = 'none';
|
||||
const messageList = document.getElementById(this.configuration.prefix + 'prompt_manager_popup_entry_form_inspect_list');
|
||||
messageList.innerHTML = '';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a full list of prompts whose content markers have been substituted.
|
||||
@ -1251,7 +1251,7 @@ PromptManagerModule.prototype.getPromptCollection = function () {
|
||||
});
|
||||
|
||||
return promptCollection;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Setter for messages property
|
||||
@ -1272,7 +1272,7 @@ PromptManagerModule.prototype.setChatCompletion = function (chatCompletion) {
|
||||
|
||||
this.setMessages(messages);
|
||||
this.populateTokenCounts(messages);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Populates the token handler
|
||||
@ -1289,7 +1289,7 @@ PromptManagerModule.prototype.populateTokenCounts = function (messages) {
|
||||
this.tokenUsage = this.tokenHandler.getTotal();
|
||||
|
||||
this.log('Updated token usage with ' + this.tokenUsage);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Populates legacy token counts
|
||||
@ -1317,7 +1317,7 @@ PromptManagerModule.prototype.populateLegacyTokenCounts = function (messages) {
|
||||
'conversation': this.tokenHandler.counts.chatHistory ?? 0,
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Empties, then re-assembles the container containing the prompt list.
|
||||
@ -1414,7 +1414,7 @@ PromptManagerModule.prototype.renderPromptManager = function () {
|
||||
else popup.setAttribute('data-show', '');
|
||||
|
||||
exportPopper.update();
|
||||
}
|
||||
};
|
||||
|
||||
footerDiv.querySelector('#prompt-manager-import').addEventListener('click', this.handleImport);
|
||||
footerDiv.querySelector('#prompt-manager-export').addEventListener('click', showExportSelection);
|
||||
@ -1594,7 +1594,7 @@ PromptManagerModule.prototype.import = function (importData) {
|
||||
merged = Array.from(map.values());
|
||||
|
||||
return merged;
|
||||
}
|
||||
};
|
||||
|
||||
const controlObj = {
|
||||
version: 1,
|
||||
@ -1603,7 +1603,7 @@ PromptManagerModule.prototype.import = function (importData) {
|
||||
prompts: [],
|
||||
prompt_order: null
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (false === this.validateObject(controlObj, importData)) {
|
||||
toastr.warning('Could not import prompts. Export failed validation.');
|
||||
@ -1626,7 +1626,7 @@ PromptManagerModule.prototype.import = function (importData) {
|
||||
this.log(`Prompt order import for character ${this.activeCharacter.name} succeeded`);
|
||||
}
|
||||
} else {
|
||||
throw new Error('Prompt order strategy not supported.')
|
||||
throw new Error('Prompt order strategy not supported.');
|
||||
}
|
||||
|
||||
toastr.success('Prompt import complete.');
|
||||
@ -1656,7 +1656,7 @@ PromptManagerModule.prototype.validateObject = function (controlObj, object) {
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get current date as mm/dd/YYYY
|
||||
@ -1673,7 +1673,7 @@ PromptManagerModule.prototype.getFormattedDate = function () {
|
||||
if (day.length < 2) day = '0' + day;
|
||||
|
||||
return `${month}_${day}_${year}`;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes the prompt list draggable and handles swapping of two entries in the list.
|
||||
@ -1712,7 +1712,7 @@ PromptManagerModule.prototype.showPopup = function (area = 'edit') {
|
||||
$('#' + this.configuration.prefix + 'prompt_manager_popup').first()
|
||||
.slideDown(200, 'swing')
|
||||
.addClass('openDrawer');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Slides up the edit form and removes the class 'openDrawer' from the first element of '#openai_prompt_manager_popup'.
|
||||
@ -1722,7 +1722,7 @@ PromptManagerModule.prototype.hidePopup = function () {
|
||||
$('#' + this.configuration.prefix + 'prompt_manager_popup').first()
|
||||
.slideUp(200, 'swing')
|
||||
.removeClass('openDrawer');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Quick uuid4 implementation
|
||||
@ -1734,7 +1734,7 @@ PromptManagerModule.prototype.getUuidv4 = function () {
|
||||
v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Write to console with prefix
|
||||
@ -1743,7 +1743,7 @@ PromptManagerModule.prototype.getUuidv4 = function () {
|
||||
*/
|
||||
PromptManagerModule.prototype.log = function (output) {
|
||||
if (power_user.console_log_prompts) console.log('[PromptManager] ' + output);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Start a profiling task
|
||||
@ -1752,7 +1752,7 @@ PromptManagerModule.prototype.log = function (output) {
|
||||
*/
|
||||
PromptManagerModule.prototype.profileStart = function (identifier) {
|
||||
if (power_user.console_log_prompts) console.time(identifier);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* End a profiling task
|
||||
@ -1764,7 +1764,7 @@ PromptManagerModule.prototype.profileEnd = function (identifier) {
|
||||
this.log('Profiling of "' + identifier + '" finished. Result below.');
|
||||
console.timeEnd(identifier);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const chatCompletionDefaultPrompts = {
|
||||
'prompts': [
|
||||
|
Reference in New Issue
Block a user