Indicate welcome page assistant in the list

d5c56fa40531e61cca7baaa87e2ccaa4a2890604

Cohee <18619528+Cohee1207@users.noreply.github.com>

3 files changed, +45 -22Ignore whitespace
public/index.html+3 -0
@@ -6383,6 +6383,9 @@
63836383 <div class="wide100p character_name_block">
63846384 <span class="ch_name"></span>
63856385 <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>
63866389 <small class="ch_additional_info character_version"></small>
63876390 <small class="ch_additional_info ch_avatar_url"></small>
63886391 </div>
public/script.js+6 -1
@@ -282,7 +282,7 @@ import { deriveTemplatesFromChatTemplate } from './scripts/chat-templates.js';
282282import { getContext } from './scripts/st-context.js';
283283import { extractReasoningFromData, initReasoning, parseReasoningInSwipes, PromptReasoning, ReasoningHandler, removeReasoningFromString, updateReasoningUI } from './scripts/reasoning.js';
284284import { accountStorage } from './scripts/util/AccountStorage.js';
285285import { initWelcomeScreen, openPermanentAssistantChat, openPermanentAssistantCard, getPermanentAssistantAvatar } from './scripts/welcome-screen.js';
286286
287287// API OBJECT FOR EXTERNAL WIRING
288288globalThis.SillyTavern = {
@@ -1473,6 +1473,11 @@ function getCharacterBlock(item, id) {
14731473 template.toggleClass('is_fav', item.fav || item.fav == 'true');
14741474 template.find('.ch_fav').val(item.fav);
14751475
1476+ const isAssistant = item.avatar === getPermanentAssistantAvatar();
1477+ if (!isAssistant) {
1478+ template.find('.ch_assistant').remove();
1479+ }
1480+
14761481 const description = item.data?.creator_notes || '';
14771482 if (description) {
14781483 template.find('.ch_description').text(description);
public/scripts/welcome-screen.js+36 -21
@@ -19,9 +19,26 @@ import {
1919import { is_group_generating } from './group-chats.js';
2020import { t } from './i18n.js';
2121import { renderTemplateAsync } from './templates.js';
22+import { accountStorage } from './util/AccountStorage.js';
2223import { timestampToMoment } from './utils.js';
2324
2425const 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+}
2542
2643export async function openWelcomeScreen() {
2744 const currentChatId = getCurrentChatId();
@@ -121,35 +138,32 @@ async function getRecentChats() {
121138 /** @type {RecentChat[]} */
122139 const data = await response.json();
123140
124141 data.sort((a, b) => b.last_mes - a.last_mes).forEach((chat, index) => {
125142 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);
145+ const chatTimestamp = timestampToMoment(chat.last_mes);
129- return;
146+ chat.char_name = character.name;
130- }
147+ chat.date_short = chatTimestamp.format('l');
131-
148+ chat.date_long = chatTimestamp.format('LL LT');
132- const chatTimestamp = timestampToMoment(chat.last_mes);
149+ chat.chat_name = chat.file_name.replace('.jsonl', '');
133150 chat.char_namechar_thumbnail = getThumbnailUrl('avatar', character.nameavatar);
134- chat.date_short = chatTimestamp.format('l');
151+ });
135- chat.date_long = chatTimestamp.format('LL LT');
136- chat.chat_name = chat.file_name.replace('.jsonl', '');
137- chat.char_thumbnail = getThumbnailUrl('avatar', character.avatar);
138- });
139152
140153 return data;
141154}
142155
143156export 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);
145159 if (characterId === -1) {
146160 if (!tryCreate) {
147161 console.error(`Character not found for avatar ID: ${permanentAssistantAvataravatar}. Cannot create.`);
148162 return;
149163 }
150164
151165 try {
152166 console.log(`Character not found for avatar ID: ${permanentAssistantAvataravatar}. Creating new assistant.`);
153167 await createPermanentAssistant();
154168 return openPermanentAssistantChat({ tryCreate: false });
155169 }
@@ -177,7 +191,7 @@ async function createPermanentAssistant() {
177191
178192 const formData = new FormData();
179193 formData.append('ch_name', neutralCharacterName);
180194 formData.append('file_name', permanentAssistantAvatardefaultAssistantAvatar.replace('.png', ''));
181195
182196 const headers = getRequestHeaders();
183197 delete headers['Content-Type'];
@@ -197,7 +211,8 @@ async function createPermanentAssistant() {
197211}
198212
199213export 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);
201216 if (characterId === -1) {
202217 toastr.info(t`Assistant not found. Try sending a chat message.`);
203218 return;