| 454 | |
| 455 | describe('finishReason propagation', () => { |
| 456 | function streamWithFinish( |
| 457 | parts: StreamedMessagePart[], |
| 458 | finishReason: |
| 459 | | 'completed' |
| 460 | | 'truncated' |
| 461 | | 'tool_calls' |
| 462 | | 'filtered' |
| 463 | | 'paused' |
| 464 | | 'other' |
| 465 | | null, |
| 466 | rawFinishReason: string | null, |
| 467 | ): StreamedMessage { |
| 468 | return { |
| 469 | id: 'mock', |
| 470 | usage: null, |
| 471 | finishReason, |
| 472 | rawFinishReason, |
| 473 | async *[Symbol.asyncIterator](): AsyncIterator<StreamedMessagePart> { |
| 474 | for (const part of parts) { |
| 475 | yield part; |
| 476 | } |
| 477 | }, |
| 478 | }; |
| 479 | } |
| 480 | |
| 481 | it('copies stream.finishReason onto the StepResult', async () => { |
| 482 | const stream = streamWithFinish([{ type: 'text', text: 'hi' }], 'truncated', 'length'); |