Commit 7d3fa6d
fix(openai-adapters): Add defensive type checks for stream.usage Promise
Added type validation for stream.usage values to prevent NaN:
- Check if promptTokens is a number before using
- Check if completionTokens is a number before using
- Calculate totalTokens from components if not provided
- Default to 0 for any undefined/invalid values
This prevents NaN errors when stream.usage Promise resolves with
unexpected/undefined values in the fallback path.
Co-authored-by: nate <[email protected]>
Generated with [Continue](https://continue.dev)1 parent bbeec4b commit 7d3fa6d
2 files changed
+32
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
680 | 680 | | |
681 | 681 | | |
682 | 682 | | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
683 | 696 | | |
684 | 697 | | |
685 | 698 | | |
686 | | - | |
687 | | - | |
688 | | - | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
689 | 702 | | |
690 | 703 | | |
691 | 704 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
351 | 364 | | |
352 | 365 | | |
353 | 366 | | |
354 | | - | |
355 | | - | |
356 | | - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
357 | 370 | | |
358 | 371 | | |
359 | 372 | | |
| |||
0 commit comments