Indicate welcome page assistant in the list

This commit is contained in:
Cohee
2025-05-12 19:52:14 +03:00
parent 7b9f5b3fb8
commit d5c56fa405
3 changed files with 45 additions and 22 deletions

View File

@@ -6383,6 +6383,9 @@
<div class="wide100p character_name_block"> <div class="wide100p character_name_block">
<span class="ch_name"></span> <span class="ch_name"></span>
<small class="ch_additional_info ch_add_placeholder">+++</small> <small class="ch_additional_info ch_add_placeholder">+++</small>
<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.">
<i class="fa-solid fa-sm fa-user-graduate"></i>
</small>
<small class="ch_additional_info character_version"></small> <small class="ch_additional_info character_version"></small>
<small class="ch_additional_info ch_avatar_url"></small> <small class="ch_additional_info ch_avatar_url"></small>
</div> </div>

View File

@@ -282,7 +282,7 @@ import { deriveTemplatesFromChatTemplate } from './scripts/chat-templates.js';
import { getContext } from './scripts/st-context.js'; import { getContext } from './scripts/st-context.js';
import { extractReasoningFromData, initReasoning, parseReasoningInSwipes, PromptReasoning, ReasoningHandler, removeReasoningFromString, updateReasoningUI } from './scripts/reasoning.js'; import { extractReasoningFromData, initReasoning, parseReasoningInSwipes, PromptReasoning, ReasoningHandler, removeReasoningFromString, updateReasoningUI } from './scripts/reasoning.js';
import { accountStorage } from './scripts/util/AccountStorage.js'; import { accountStorage } from './scripts/util/AccountStorage.js';
import { initWelcomeScreen, openPermanentAssistantChat, openPermanentAssistantCard } from './scripts/welcome-screen.js'; import { initWelcomeScreen, openPermanentAssistantChat, openPermanentAssistantCard, getPermanentAssistantAvatar } from './scripts/welcome-screen.js';
// API OBJECT FOR EXTERNAL WIRING // API OBJECT FOR EXTERNAL WIRING
globalThis.SillyTavern = { globalThis.SillyTavern = {
@@ -1473,6 +1473,11 @@ function getCharacterBlock(item, id) {
template.toggleClass('is_fav', item.fav || item.fav == 'true'); template.toggleClass('is_fav', item.fav || item.fav == 'true');
template.find('.ch_fav').val(item.fav); template.find('.ch_fav').val(item.fav);
const isAssistant = item.avatar === getPermanentAssistantAvatar();
if (!isAssistant) {
template.find('.ch_assistant').remove();
}
const description = item.data?.creator_notes || ''; const description = item.data?.creator_notes || '';
if (description) { if (description) {
template.find('.ch_description').text(description); template.find('.ch_description').text(description);

View File

@@ -19,9 +19,26 @@ import {
import { is_group_generating } from './group-chats.js'; import { is_group_generating } from './group-chats.js';
import { t } from './i18n.js'; import { t } from './i18n.js';
import { renderTemplateAsync } from './templates.js'; import { renderTemplateAsync } from './templates.js';
import { accountStorage } from './util/AccountStorage.js';
import { timestampToMoment } from './utils.js'; import { timestampToMoment } from './utils.js';
const permanentAssistantAvatar = 'default_Assistant.png'; const assistantAvatarKey = 'assistant';
const defaultAssistantAvatar = 'default_Assistant.png';
export function getPermanentAssistantAvatar() {
const assistantAvatar = accountStorage.getItem(assistantAvatarKey);
if (assistantAvatar === null) {
return defaultAssistantAvatar;
}
const character = characters.find(x => x.avatar === assistantAvatar);
if (character === undefined) {
accountStorage.removeItem(assistantAvatarKey);
return defaultAssistantAvatar;
}
return assistantAvatar;
}
export async function openWelcomeScreen() { export async function openWelcomeScreen() {
const currentChatId = getCurrentChatId(); const currentChatId = getCurrentChatId();
@@ -121,35 +138,32 @@ async function getRecentChats() {
/** @type {RecentChat[]} */ /** @type {RecentChat[]} */
const data = await response.json(); const data = await response.json();
data.sort((a, b) => b.last_mes - a.last_mes).forEach((chat, index) => { data.sort((a, b) => b.last_mes - a.last_mes)
const character = characters.find(x => x.avatar === chat.avatar); .map(chat => ({ chat, character: characters.find(x => x.avatar === chat.avatar) }))
if (!character) { .filter(t => t.character)
console.warn(`Character not found for chat: ${chat.file_name}`); .forEach(({ chat, character }) => {
data.splice(index, 1); const chatTimestamp = timestampToMoment(chat.last_mes);
return; chat.char_name = character.name;
} chat.date_short = chatTimestamp.format('l');
chat.date_long = chatTimestamp.format('LL LT');
const chatTimestamp = timestampToMoment(chat.last_mes); chat.chat_name = chat.file_name.replace('.jsonl', '');
chat.char_name = character.name; chat.char_thumbnail = getThumbnailUrl('avatar', character.avatar);
chat.date_short = chatTimestamp.format('l'); });
chat.date_long = chatTimestamp.format('LL LT');
chat.chat_name = chat.file_name.replace('.jsonl', '');
chat.char_thumbnail = getThumbnailUrl('avatar', character.avatar);
});
return data; return data;
} }
export async function openPermanentAssistantChat({ tryCreate = true } = {}) { export async function openPermanentAssistantChat({ tryCreate = true } = {}) {
const characterId = characters.findIndex(x => x.avatar === permanentAssistantAvatar); const avatar = getPermanentAssistantAvatar();
const characterId = characters.findIndex(x => x.avatar === avatar);
if (characterId === -1) { if (characterId === -1) {
if (!tryCreate) { if (!tryCreate) {
console.error(`Character not found for avatar ID: ${permanentAssistantAvatar}. Cannot create.`); console.error(`Character not found for avatar ID: ${avatar}. Cannot create.`);
return; return;
} }
try { try {
console.log(`Character not found for avatar ID: ${permanentAssistantAvatar}. Creating new assistant.`); console.log(`Character not found for avatar ID: ${avatar}. Creating new assistant.`);
await createPermanentAssistant(); await createPermanentAssistant();
return openPermanentAssistantChat({ tryCreate: false }); return openPermanentAssistantChat({ tryCreate: false });
} }
@@ -177,7 +191,7 @@ async function createPermanentAssistant() {
const formData = new FormData(); const formData = new FormData();
formData.append('ch_name', neutralCharacterName); formData.append('ch_name', neutralCharacterName);
formData.append('file_name', permanentAssistantAvatar.replace('.png', '')); formData.append('file_name', defaultAssistantAvatar.replace('.png', ''));
const headers = getRequestHeaders(); const headers = getRequestHeaders();
delete headers['Content-Type']; delete headers['Content-Type'];
@@ -197,7 +211,8 @@ async function createPermanentAssistant() {
} }
export async function openPermanentAssistantCard() { export async function openPermanentAssistantCard() {
const characterId = characters.findIndex(x => x.avatar === permanentAssistantAvatar); const avatar = getPermanentAssistantAvatar();
const characterId = characters.findIndex(x => x.avatar === avatar);
if (characterId === -1) { if (characterId === -1) {
toastr.info(t`Assistant not found. Try sending a chat message.`); toastr.info(t`Assistant not found. Try sending a chat message.`);
return; return;