Emit event on streaming tick

9a6a82b400ad094b9dadd0d95fb63054d8752c02

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

2 files changed, +4 -3Showing whitespace changes
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/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);