diff --git a/public/script.js b/public/script.js index f476b438a..ca2765ef8 100644 --- a/public/script.js +++ b/public/script.js @@ -431,7 +431,9 @@ export const event_types = { CHARACTER_MESSAGE_RENDERED: 'character_message_rendered', FORCE_SET_BACKGROUND: 'force_set_background', CHAT_DELETED: 'chat_deleted', + CHAT_CREATED: 'chat_created', GROUP_CHAT_DELETED: 'group_chat_deleted', + GROUP_CHAT_CREATED: 'group_chat_created', GENERATE_BEFORE_COMBINE_PROMPTS: 'generate_before_combine_prompts', GENERATE_AFTER_COMBINE_PROMPTS: 'generate_after_combine_prompts', GROUP_MEMBER_DRAFTED: 'group_member_drafted', @@ -5884,11 +5886,13 @@ export async function getChat() { async function getChatResult() { name2 = characters[this_chid].name; + let freshChat = false; if (chat.length === 0) { const message = getFirstMessage(); if (message.mes) { chat.push(message); await saveChatConditional(); + freshChat = true; } } await loadItemizedPrompts(getCurrentChatId()); @@ -5896,6 +5900,7 @@ async function getChatResult() { select_selected_character(this_chid); await eventSource.emit(event_types.CHAT_CHANGED, (getCurrentChatId())); + if (freshChat) await eventSource.emit(event_types.CHAT_CREATED); if (chat.length === 1) { const chat_id = (chat.length - 1); diff --git a/public/scripts/group-chats.js b/public/scripts/group-chats.js index 152074374..ad6c38905 100644 --- a/public/scripts/group-chats.js +++ b/public/scripts/group-chats.js @@ -183,6 +183,7 @@ export async function getGroupChat(groupId, reload = false) { const group = groups.find((x) => x.id === groupId); const chat_id = group.chat_id; const data = await loadGroupChat(chat_id); + let freshChat = false; await loadItemizedPrompts(getCurrentChatId()); @@ -216,6 +217,7 @@ export async function getGroupChat(groupId, reload = false) { } } await saveGroupChat(groupId, false); + freshChat = true; } if (group) { @@ -228,6 +230,7 @@ export async function getGroupChat(groupId, reload = false) { } await eventSource.emit(event_types.CHAT_CHANGED, getCurrentChatId()); + if (freshChat) await eventSource.emit(event_types.GROUP_CHAT_CREATED); } /** diff --git a/src/endpoints/search.js b/src/endpoints/search.js index 7efd004f7..7f08d89c8 100644 --- a/src/endpoints/search.js +++ b/src/endpoints/search.js @@ -34,6 +34,8 @@ router.post('/serpapi', jsonParser, async (request, response) => { const { query } = request.body; const result = await fetch(`https://serpapi.com/search.json?q=${encodeURIComponent(query)}&api_key=${key}`); + console.log('SerpApi query', query); + if (!result.ok) { const text = await result.text(); console.log('SerpApi request failed', result.statusText, text); @@ -143,6 +145,8 @@ router.post('/searxng', jsonParser, async (request, response) => { return response.sendStatus(400); } + console.log('SearXNG query', baseUrl, query); + const url = new URL(baseUrl); const params = new URLSearchParams(); params.append('q', query); @@ -205,6 +209,8 @@ router.post('/visit', jsonParser, async (request, response) => { return response.sendStatus(400); } + console.log('Visiting web URL', url); + const result = await fetch(url, { headers: visitHeaders }); if (!result.ok) {