(state: EventHandlerState)
| 491 | |
| 492 | export const createStreamChunkHandler = |
| 493 | (state: EventHandlerState) => (event: StreamChunkEvent) => { |
| 494 | const destination = destinationFromChunkEvent(event) |
| 495 | let text: string | undefined |
| 496 | if (typeof event === 'string') { |
| 497 | text = event |
| 498 | } else { |
| 499 | text = event.chunk |
| 500 | } |
| 501 | |
| 502 | if (!destination) { |
| 503 | state.logger.warn({ event }, 'Unhandled stream chunk event') |
| 504 | return |
| 505 | } |
| 506 | |
| 507 | if (!text) { |
| 508 | return |
| 509 | } |
| 510 | |
| 511 | ensureStreaming(state) |
| 512 | |
| 513 | if (destination.type === 'root') { |
| 514 | if (destination.textType === 'text') { |
| 515 | state.streaming.streamRefs.setters.appendRootStreamBuffer(text) |
| 516 | } |
| 517 | state.streaming.streamRefs.setters.setRootStreamSeen(true) |
| 518 | appendRootChunk(state, { type: destination.textType, text }) |
| 519 | return |
| 520 | } |
| 521 | |
| 522 | state.message.updater.updateAiMessageBlocks((blocks) => |
| 523 | processTextChunk(blocks, destination, text), |
| 524 | ) |
| 525 | } |
| 526 | |
| 527 | export const createEventHandler = |
| 528 | (state: EventHandlerState) => (event: SDKEvent) => { |
no test coverage detected