Emit event on streaming tick
| @@ -454,7 +454,9 @@ export const event_types = { | |||
| 454 | // TODO: Naming convention is inconsistent with other events | 454 | // TODO: Naming convention is inconsistent with other events |
| 455 | CHARACTER_DELETED: 'characterDeleted', | 455 | CHARACTER_DELETED: 'characterDeleted', |
| 456 | CHARACTER_DUPLICATED: 'character_duplicated', | 456 | 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', | ||
| 458 | FILE_ATTACHMENT_DELETED: 'file_attachment_deleted', | 460 | FILE_ATTACHMENT_DELETED: 'file_attachment_deleted', |
| 459 | WORLDINFO_FORCE_ACTIVATE: 'worldinfo_force_activate', | 461 | WORLDINFO_FORCE_ACTIVATE: 'worldinfo_force_activate', |
| 460 | OPEN_CHARACTER_LIBRARY: 'open_character_library', | 462 | OPEN_CHARACTER_LIBRARY: 'open_character_library', |
| @@ -3122,6 +3124,7 @@ class StreamingProcessor { | |||
| 3122 | if (logprobs) { | 3124 | if (logprobs) { |
| 3123 | this.messageLogprobs.push(...(Array.isArray(logprobs) ? logprobs : [logprobs])); | 3125 | this.messageLogprobs.push(...(Array.isArray(logprobs) ? logprobs : [logprobs])); |
| 3124 | } | 3126 | } |
| 3127 | await eventSource.emit(event_types.STREAM_TOKEN_RECEIVED, text); | ||
| 3125 | await sw.tick(() => this.onProgressStreaming(this.messageId, this.continueMessage + text)); | 3128 | await sw.tick(() => this.onProgressStreaming(this.messageId, this.continueMessage + text)); |
| 3126 | } | 3129 | } |
| 3127 | const seconds = (timestamps[timestamps.length - 1] - timestamps[0]) / 1000; | 3130 | const seconds = (timestamps[timestamps.length - 1] - timestamps[0]) / 1000; |
| @@ -1,4 +1,3 @@ | |||
| 1 | import { eventSource, event_types } from '../script.js'; | ||
| 2 | import { power_user } from './power-user.js'; | 1 | import { power_user } from './power-user.js'; |
| 3 | import { delay } from './utils.js'; | 2 | import { delay } from './utils.js'; |
| 4 | 3 | ||
| @@ -268,7 +267,6 @@ export class SmoothEventSourceStream extends EventSourceStream { | |||
| 268 | hasFocus && await delay(getDelay(lastStr)); | 267 | hasFocus && await delay(getDelay(lastStr)); |
| 269 | controller.enqueue(new MessageEvent(event.type, { data: JSON.stringify(parsed.data) })); | 268 | controller.enqueue(new MessageEvent(event.type, { data: JSON.stringify(parsed.data) })); |
| 270 | lastStr = parsed.chunk; | 269 | lastStr = parsed.chunk; |
| 271 | hasFocus && await eventSource.emit(event_types.SMOOTH_STREAM_TOKEN_RECEIVED, parsed.chunk); | ||
| 272 | } | 270 | } |
| 273 | } catch (error) { | 271 | } catch (error) { |
| 274 | console.debug('Smooth Streaming parsing error', error); | 272 | console.debug('Smooth Streaming parsing error', error); |