(
message: SdkPartialAssistantMessage,
)
| 357 | } |
| 358 | |
| 359 | function* handleStreamEvent( |
| 360 | message: SdkPartialAssistantMessage, |
| 361 | ): Generator<StreamChunk> { |
| 362 | const event = message.event |
| 363 | if (event.type === 'message_start') { |
| 364 | partialMessageId = event.message.id ?? genId() |
| 365 | streamedMessageIds.add(partialMessageId) |
| 366 | } else if (event.type === 'content_block_start') { |
| 367 | partialBlockType = event.content_block.type |
| 368 | if (partialBlockType === 'text') { |
| 369 | partialTextMessageId = partialMessageId ?? genId() |
| 370 | partialTextContent = '' |
| 371 | if (!partialTextStarted) { |
| 372 | partialTextStarted = true |
| 373 | yield { |
| 374 | type: EventType.TEXT_MESSAGE_START, |
| 375 | messageId: partialTextMessageId, |
| 376 | model, |
| 377 | timestamp: now(), |
| 378 | role: 'assistant', |
| 379 | } |
| 380 | } |
| 381 | } else if (partialBlockType === 'thinking') { |
| 382 | partialReasoningId = genId() |
| 383 | yield { |
| 384 | type: EventType.REASONING_START, |
| 385 | messageId: partialReasoningId, |
| 386 | model, |
| 387 | timestamp: now(), |
| 388 | } |
| 389 | yield { |
| 390 | type: EventType.REASONING_MESSAGE_START, |
| 391 | messageId: partialReasoningId, |
| 392 | role: 'reasoning' as const, |
| 393 | model, |
| 394 | timestamp: now(), |
| 395 | } |
| 396 | } |
| 397 | } else if (event.type === 'content_block_delta') { |
| 398 | if ( |
| 399 | event.delta.type === 'text_delta' && |
| 400 | partialTextStarted && |
| 401 | partialTextMessageId && |
| 402 | typeof event.delta.text === 'string' |
| 403 | ) { |
| 404 | partialTextContent += event.delta.text |
| 405 | yield { |
| 406 | type: EventType.TEXT_MESSAGE_CONTENT, |
| 407 | messageId: partialTextMessageId, |
| 408 | model, |
| 409 | timestamp: now(), |
| 410 | delta: event.delta.text, |
| 411 | content: partialTextContent, |
| 412 | } |
| 413 | } else if ( |
| 414 | event.delta.type === 'thinking_delta' && |
| 415 | partialReasoningId && |
| 416 | typeof event.delta.thinking === 'string' |
no test coverage detected