Add "unset" value for PM prompt role, refactor icons display

This commit is contained in:
Cohee
2024-12-31 15:14:29 +02:00
parent d58f471cc3
commit 227201a5fc
3 changed files with 18 additions and 32 deletions

View File

@ -1208,7 +1208,7 @@ class PromptManager {
const forbidOverridesBlock = document.getElementById(this.configuration.prefix + 'prompt_manager_forbid_overrides_block');
nameField.value = prompt.name ?? '';
roleField.value = prompt.role ?? 'system';
roleField.value = prompt.role ?? '';
promptField.value = prompt.content ?? '';
promptField.disabled = prompt.marker ?? false;
injectionPositionField.value = prompt.injection_position ?? INJECTION_POSITION.RELATIVE;
@ -1543,6 +1543,7 @@ class PromptManager {
}
const encodedName = escapeHtml(prompt.name);
const isRolePrompt = !!prompt.role;
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 isImportantPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && prompt.forbid_overrides;
@ -1552,36 +1553,16 @@ class PromptManager {
const importantClass = isImportantPrompt ? `${prefix}prompt_manager_important` : '';
//add role icons to the right of prompt name
const hasRole = !!prompt.role;
let roleIcon, roleTitle;
if (hasRole) {
switch (prompt.role) {
case 'system':
roleIcon = 'fa-cog';
roleTitle = 'Prompt will be sent as System';
break;
case 'assistant':
roleIcon = 'fa-robot';
roleTitle = 'Prompt will be sent as Assistant';
break;
case 'user':
roleIcon = 'fa-user';
roleTitle = 'Prompt will be sent as User';
}
// not sure if this makes sense to include as 'markers' should not be sendable except by System, included in case I'm wrong.
// if it shouldn't be changeable, we should remove that dropdown from editor for Marker prompts.
/*
if (isMarkerPrompt && prompt.role !== 'user' && prompt.role !== 'assistant' && prompt.role !== 'system') {
roleIcon = 'fa-cog';
roleTitle = 'ST Global Prompt is sent as System by default (but can be changed in Editor)';
}
*/
}
const promptRoles = {
system: { roleIcon: 'fa-cog', roleTitle: 'Prompt will be sent as System' },
assistant: { roleIcon: 'fa-robot', roleTitle: 'Prompt will be sent as Assistant' },
user: { roleIcon: 'fa-user', roleTitle: 'Prompt will be sent as User' },
};
const roleIcon = isRolePrompt ? promptRoles[prompt.role]?.roleIcon : '';
const roleTitle = isRolePrompt ? promptRoles[prompt.role]?.roleTitle : '';
listItemHtml += `
<li class="${prefix}prompt_manager_prompt ${draggableClass} ${enabledClass} ${markerClass} ${importantClass}" data-pm-identifier="${prompt.identifier}">
<li class="${prefix}prompt_manager_prompt ${draggableClass} ${enabledClass} ${markerClass} ${importantClass}" data-pm-identifier="${escapeHtml(prompt.identifier)}">
<span class="${prefix}prompt_manager_prompt_name" data-pm-name="${encodedName}">
${isMarkerPrompt ? '<span class="fa-fw fa-solid fa-thumb-tack" title="Marker"></span>' : ''}
${isSystemPrompt ? '<span class="fa-fw fa-solid fa-square-poll-horizontal" title="Global Prompt"></span>' : ''}
@ -1589,14 +1570,14 @@ class PromptManager {
${isUserPrompt ? '<span class="fa-fw fa-solid fa-user" title="Preset Prompt"></span>' : ''}
${isInjectionPrompt ? '<span class="fa-fw fa-solid fa-syringe" title="In-Chat Injection"></span>' : ''}
${this.isPromptInspectionAllowed(prompt) ? `<a title="${encodedName}" class="prompt-manager-inspect-action">${encodedName}</a>` : `<span title="${encodedName}">${encodedName}</span>`}
${hasRole ? `<span class='fa-solid ${roleIcon}' title='${roleTitle}'></span>` : ''}
${isInjectionPrompt ? `<small class="prompt-manager-injection-depth">@ ${prompt.injection_depth}</small>` : ''}
${isRolePrompt ? `<span data-role="${escapeHtml(prompt.role)}" class="fa-xs fa-solid ${roleIcon}" title="${roleTitle}"></span>` : ''}
${isInjectionPrompt ? `<small class="prompt-manager-injection-depth">@ ${escapeHtml(prompt.injection_depth)}</small>` : ''}
${isOverriddenPrompt ? '<small class="fa-solid fa-address-card prompt-manager-overridden" title="Pulled from a character card"></small>' : ''}
</span>
<span>
<span class="prompt_manager_prompt_controls">
${detachSpanHtml}
${ editSpanHtml }
${editSpanHtml}
${toggleSpanHtml}
</span>
</span>