Merge branch 'staging' into contentEditablew-AF-Panel

c21f59ca7a84e1229a3c34d74f66c9174d5d42a8

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

4 files changed, +41 -16Showing whitespace changes
public/index.html+3 -1
@@ -3441,12 +3441,14 @@
34413441 </div>
34423442 <div id="WorldInfo" class="drawer-content closedDrawer">
34433443 <div id="WorldInfoheader" class="fa-solid fa-grip drag-grabber"></div>
3444- <div id="WI_panel_pin_div" class="flex-container alignitemscenter gap10px" title="Locked = World Editor will stay open" data-i18n="[title]Locked = World Editor will stay open">
3444+ <div class="flex-container alignitemscenter gap10px">
3445+ <div id="WI_panel_pin_div" title="Locked = World Editor will stay open" data-i18n="[title]Locked = World Editor will stay open">
34453446 <input type="checkbox" id="WI_panel_pin">
34463447 <label for="WI_panel_pin">
34473448 <div class="unchecked fa-solid fa-unlock "></div>
34483449 <div class="checked fa-solid fa-lock "></div>
34493450 </label>
3451+ </div>
34503452 <h3 class="margin0">
34513453 <span data-i18n="Worlds/Lorebooks">Worlds/Lorebooks</span>
34523454 <a href="https://docs.sillytavern.app/usage/core-concepts/worldinfo/" class="notes-link" target="_blank">
public/script.js+4 -1
@@ -454,7 +454,9 @@ export const event_types = {
454454 // TODO: Naming convention is inconsistent with other events
455455 CHARACTER_DELETED: 'characterDeleted',
456456 CHARACTER_DUPLICATED: 'character_duplicated',
457- SMOOTH_STREAM_TOKEN_RECEIVED: 'smooth_stream_token_received',
457+ /** @deprecated The event is aliased to STREAM_TOKEN_RECEIVED. */
458+ SMOOTH_STREAM_TOKEN_RECEIVED: 'stream_token_received',
459+ STREAM_TOKEN_RECEIVED: 'stream_token_received',
458460 FILE_ATTACHMENT_DELETED: 'file_attachment_deleted',
459461 WORLDINFO_FORCE_ACTIVATE: 'worldinfo_force_activate',
460462 OPEN_CHARACTER_LIBRARY: 'open_character_library',
@@ -3122,6 +3124,7 @@ class StreamingProcessor {
31223124 if (logprobs) {
31233125 this.messageLogprobs.push(...(Array.isArray(logprobs) ? logprobs : [logprobs]));
31243126 }
3127+ await eventSource.emit(event_types.STREAM_TOKEN_RECEIVED, text);
31253128 await sw.tick(() => this.onProgressStreaming(this.messageId, this.continueMessage + text));
31263129 }
31273130 const seconds = (timestamps[timestamps.length - 1] - timestamps[0]) / 1000;
public/scripts/extensions/memory/index.js+34 -12
@@ -15,6 +15,7 @@ import {
1515 generateRaw,
1616 getMaxContextSize,
1717 setExtensionPrompt,
18+ streamingProcessor,
1819} from '../../../script.js';
1920import { is_group_generating, selected_group } from '../../group-chats.js';
2021import { loadMovingUIState } from '../../power-user.js';
@@ -408,8 +409,8 @@ async function onChatEvent() {
408409 return;
409410 }
410411
411412 // Generation isStreaming in -progress, summary prevented
412413 if (is_send_pressstreamingProcessor && !streamingProcessor.isFinished) {
413414 return;
414415 }
415416
@@ -446,15 +447,9 @@ async function onChatEvent() {
446447 delete chat[chat.length - 1].extra.memory;
447448 }
448449
449- try {
450+ summarizeChat(context)
450- await summarizeChat(context);
451+ .catch(console.error)
451- }
452+ .finally(saveLastValues);
452- catch (error) {
453- console.log(error);
454- }
455- finally {
456- saveLastValues();
457- }
458453}
459454
460455/**
@@ -567,7 +562,7 @@ async function getSummaryPromptForNow(context, force) {
567562 await waitUntilCondition(() => is_group_generating === false, 1000, 10);
568563 }
569564 // Wait for the send button to be released
570565 await waitUntilCondition(() => is_send_press === false, 30000, 100);
571566 } catch {
572567 console.debug('Timeout waiting for is_send_press');
573568 return '';
@@ -650,9 +645,16 @@ async function summarizeChatWebLLM(context, force) {
650645 params.max_tokens = extension_settings.memory.overrideResponseLength;
651646 }
652647
648+ try {
649+ inApiCall = true;
653650 const summary = await generateWebLlmChatPrompt(messages, params);
654651 const newContext = getContext();
655652
653+ if (!summary) {
654+ console.warn('Empty summary received');
655+ return;
656+ }
657+
656658 // something changed during summarization request
657659 if (newContext.groupId !== context.groupId ||
658660 newContext.chatId !== context.chatId ||
@@ -663,6 +665,9 @@ async function summarizeChatWebLLM(context, force) {
663665
664666 setMemoryContext(summary, true, lastUsedIndex);
665667 return summary;
668+ } finally {
669+ inApiCall = false;
670+ }
666671}
667672
668673async function summarizeChatMain(context, force, skipWIAN) {
@@ -677,12 +682,18 @@ async function summarizeChatMain(context, force, skipWIAN) {
677682 let index = null;
678683
679684 if (prompt_builders.DEFAULT === extension_settings.memory.prompt_builder) {
685+ try {
686+ inApiCall = true;
680687 summary = await generateQuietPrompt(prompt, false, skipWIAN, '', '', extension_settings.memory.overrideResponseLength);
688+ } finally {
689+ inApiCall = false;
690+ }
681691 }
682692
683693 if ([prompt_builders.RAW_BLOCKING, prompt_builders.RAW_NON_BLOCKING].includes(extension_settings.memory.prompt_builder)) {
684694 const lock = extension_settings.memory.prompt_builder === prompt_builders.RAW_BLOCKING;
685695 try {
696+ inApiCall = true;
686697 if (lock) {
687698 deactivateSendButtons();
688699 }
@@ -700,12 +711,18 @@ async function summarizeChatMain(context, force, skipWIAN) {
700711 summary = await generateRaw(rawPrompt, '', false, false, prompt, extension_settings.memory.overrideResponseLength);
701712 index = lastUsedIndex;
702713 } finally {
714+ inApiCall = false;
703715 if (lock) {
704716 activateSendButtons();
705717 }
706718 }
707719 }
708720
721+ if (!summary) {
722+ console.warn('Empty summary received');
723+ return;
724+ }
725+
709726 const newContext = getContext();
710727
711728 // something changed during summarization request
@@ -840,6 +857,11 @@ async function summarizeChatExtras(context) {
840857 const summary = await callExtrasSummarizeAPI(resultingString);
841858 const newContext = getContext();
842859
860+ if (!summary) {
861+ console.warn('Empty summary received');
862+ return;
863+ }
864+
843865 // something changed during summarization request
844866 if (newContext.groupId !== context.groupId
845867 || newContext.chatId !== context.chatId
public/scripts/sse-stream.js+0 -2
@@ -1,4 +1,3 @@
1-import { eventSource, event_types } from '../script.js';
21import { power_user } from './power-user.js';
32import { delay } from './utils.js';
43
@@ -268,7 +267,6 @@ export class SmoothEventSourceStream extends EventSourceStream {
268267 hasFocus && await delay(getDelay(lastStr));
269268 controller.enqueue(new MessageEvent(event.type, { data: JSON.stringify(parsed.data) }));
270269 lastStr = parsed.chunk;
271- hasFocus && await eventSource.emit(event_types.SMOOTH_STREAM_TOKEN_RECEIVED, parsed.chunk);
272270 }
273271 } catch (error) {
274272 console.debug('Smooth Streaming parsing error', error);