Fix empty chat if creating new assistant

21252cf2dda79bd94ed06c9b37b34308c7073f4f

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

1 files changed, +5 -3Ignore whitespace
public/scripts/welcome-screen.js+5 -3
@@ -281,7 +281,7 @@ async function getRecentChats() {
281 return data;281 return data;
282}282}
283283
284export async function openPermanentAssistantChat({ tryCreate = true } = {}) {284export async function openPermanentAssistantChat({ tryCreate = true, created = false } = {}) {
285 const avatar = getPermanentAssistantAvatar();285 const avatar = getPermanentAssistantAvatar();
286 const characterId = characters.findIndex(x => x.avatar === avatar);286 const characterId = characters.findIndex(x => x.avatar === avatar);
287 if (characterId === -1) {287 if (characterId === -1) {
@@ -293,7 +293,7 @@ export async function openPermanentAssistantChat({ tryCreate = true } = {}) {
293 try {293 try {
294 console.log(`Character not found for avatar ID: ${avatar}. Creating new assistant.`);294 console.log(`Character not found for avatar ID: ${avatar}. Creating new assistant.`);
295 await createPermanentAssistant();295 await createPermanentAssistant();
296 return openPermanentAssistantChat({ tryCreate: false });296 return openPermanentAssistantChat({ tryCreate: false, created: true });
297 }297 }
298 catch (error) {298 catch (error) {
299 console.error('Error creating permanent assistant:', error);299 console.error('Error creating permanent assistant:', error);
@@ -304,7 +304,9 @@ export async function openPermanentAssistantChat({ tryCreate = true } = {}) {
304304
305 try {305 try {
306 await selectCharacterById(characterId);306 await selectCharacterById(characterId);
307 await doNewChat({ deleteCurrentChat: false });307 if (!created) {
308 await doNewChat({ deleteCurrentChat: false });
309 }
308 console.log(`Opened permanent assistant chat for ${neutralCharacterName}.`, getCurrentChatId());310 console.log(`Opened permanent assistant chat for ${neutralCharacterName}.`, getCurrentChatId());
309 } catch (error) {311 } catch (error) {
310 console.error('Error opening permanent assistant chat:', error);312 console.error('Error opening permanent assistant chat:', error);