Indicate welcome page assistant in the list
| @@ -6383,6 +6383,9 @@ | ||
| 6383 | 6383 | <div class="wide100p character_name_block"> |
| 6384 | 6384 | <span class="ch_name"></span> |
| 6385 | 6385 | <small class="ch_additional_info ch_add_placeholder">+++</small> |
| 6386 | + <small class="ch_assistant" title="This character will be used as a welcome page assistant." data-i18n="[title]This character will be used as a welcome page assistant."> | |
| 6387 | + <i class="fa-solid fa-sm fa-user-graduate"></i> | |
| 6388 | + </small> | |
| 6386 | 6389 | <small class="ch_additional_info character_version"></small> |
| 6387 | 6390 | <small class="ch_additional_info ch_avatar_url"></small> |
| 6388 | 6391 | </div> |
| @@ -282,7 +282,7 @@ import { deriveTemplatesFromChatTemplate } from './scripts/chat-templates.js'; | ||
| 282 | 282 | import { getContext } from './scripts/st-context.js'; |
| 283 | 283 | import { extractReasoningFromData, initReasoning, parseReasoningInSwipes, PromptReasoning, ReasoningHandler, removeReasoningFromString, updateReasoningUI } from './scripts/reasoning.js'; |
| 284 | 284 | import { accountStorage } from './scripts/util/AccountStorage.js'; |
| 285 | 285 | import { initWelcomeScreen, openPermanentAssistantChat, openPermanentAssistantCard, getPermanentAssistantAvatar } from './scripts/welcome-screen.js'; |
| 286 | 286 | |
| 287 | 287 | // API OBJECT FOR EXTERNAL WIRING |
| 288 | 288 | globalThis.SillyTavern = { |
| @@ -1473,6 +1473,11 @@ function getCharacterBlock(item, id) { | ||
| 1473 | 1473 | template.toggleClass('is_fav', item.fav || item.fav == 'true'); |
| 1474 | 1474 | template.find('.ch_fav').val(item.fav); |
| 1475 | 1475 | |
| 1476 | + const isAssistant = item.avatar === getPermanentAssistantAvatar(); | |
| 1477 | + if (!isAssistant) { | |
| 1478 | + template.find('.ch_assistant').remove(); | |
| 1479 | + } | |
| 1480 | + | |
| 1476 | 1481 | const description = item.data?.creator_notes || ''; |
| 1477 | 1482 | if (description) { |
| 1478 | 1483 | template.find('.ch_description').text(description); |
| @@ -19,9 +19,26 @@ import { | ||
| 19 | 19 | import { is_group_generating } from './group-chats.js'; |
| 20 | 20 | import { t } from './i18n.js'; |
| 21 | 21 | import { renderTemplateAsync } from './templates.js'; |
| 22 | +import { accountStorage } from './util/AccountStorage.js'; | |
| 22 | 23 | import { timestampToMoment } from './utils.js'; |
| 23 | 24 | |
| 24 | 25 | const permanentAssistantAvatarassistantAvatarKey = 'default_Assistant.pngassistant'; |
| 26 | +const defaultAssistantAvatar = 'default_Assistant.png'; | |
| 27 | + | |
| 28 | +export function getPermanentAssistantAvatar() { | |
| 29 | + const assistantAvatar = accountStorage.getItem(assistantAvatarKey); | |
| 30 | + if (assistantAvatar === null) { | |
| 31 | + return defaultAssistantAvatar; | |
| 32 | + } | |
| 33 | + | |
| 34 | + const character = characters.find(x => x.avatar === assistantAvatar); | |
| 35 | + if (character === undefined) { | |
| 36 | + accountStorage.removeItem(assistantAvatarKey); | |
| 37 | + return defaultAssistantAvatar; | |
| 38 | + } | |
| 39 | + | |
| 40 | + return assistantAvatar; | |
| 41 | +} | |
| 25 | 42 | |
| 26 | 43 | export async function openWelcomeScreen() { |
| 27 | 44 | const currentChatId = getCurrentChatId(); |
| @@ -121,14 +138,10 @@ async function getRecentChats() { | ||
| 121 | 138 | /** @type {RecentChat[]} */ |
| 122 | 139 | const data = await response.json(); |
| 123 | 140 | |
| 124 | 141 | data.sort((a, b) => b.last_mes - a.last_mes).forEach((chat, index) => { |
| 125 | 142 | const character.map(chat => ({ chat, character: characters.find(x => x.avatar === chat.avatar); })) |
| 126 | - if (!character) { | |
| 143 | + .filter(t => t.character) | |
| 127 | - console.warn(`Character not found for chat: ${chat.file_name}`); | |
| 144 | + .forEach(({ chat, character }) => { | |
| 128 | - data.splice(index, 1); | |
| 129 | - return; | |
| 130 | - } | |
| 131 | - | |
| 132 | 145 | const chatTimestamp = timestampToMoment(chat.last_mes); |
| 133 | 146 | chat.char_name = character.name; |
| 134 | 147 | chat.date_short = chatTimestamp.format('l'); |
| @@ -141,15 +154,16 @@ async function getRecentChats() { | ||
| 141 | 154 | } |
| 142 | 155 | |
| 143 | 156 | export async function openPermanentAssistantChat({ tryCreate = true } = {}) { |
| 144 | - const characterId = characters.findIndex(x => x.avatar === permanentAssistantAvatar); | |
| 157 | + const avatar = getPermanentAssistantAvatar(); | |
| 158 | + const characterId = characters.findIndex(x => x.avatar === avatar); | |
| 145 | 159 | if (characterId === -1) { |
| 146 | 160 | if (!tryCreate) { |
| 147 | 161 | console.error(`Character not found for avatar ID: ${permanentAssistantAvataravatar}. Cannot create.`); |
| 148 | 162 | return; |
| 149 | 163 | } |
| 150 | 164 | |
| 151 | 165 | try { |
| 152 | 166 | console.log(`Character not found for avatar ID: ${permanentAssistantAvataravatar}. Creating new assistant.`); |
| 153 | 167 | await createPermanentAssistant(); |
| 154 | 168 | return openPermanentAssistantChat({ tryCreate: false }); |
| 155 | 169 | } |
| @@ -177,7 +191,7 @@ async function createPermanentAssistant() { | ||
| 177 | 191 | |
| 178 | 192 | const formData = new FormData(); |
| 179 | 193 | formData.append('ch_name', neutralCharacterName); |
| 180 | 194 | formData.append('file_name', permanentAssistantAvatardefaultAssistantAvatar.replace('.png', '')); |
| 181 | 195 | |
| 182 | 196 | const headers = getRequestHeaders(); |
| 183 | 197 | delete headers['Content-Type']; |
| @@ -197,7 +211,8 @@ async function createPermanentAssistant() { | ||
| 197 | 211 | } |
| 198 | 212 | |
| 199 | 213 | export async function openPermanentAssistantCard() { |
| 200 | - const characterId = characters.findIndex(x => x.avatar === permanentAssistantAvatar); | |
| 214 | + const avatar = getPermanentAssistantAvatar(); | |
| 215 | + const characterId = characters.findIndex(x => x.avatar === avatar); | |
| 201 | 216 | if (characterId === -1) { |
| 202 | 217 | toastr.info(t`Assistant not found. Try sending a chat message.`); |
| 203 | 218 | return; |