Commit 3121a7b
fix: handle streaming usage chunk and soft-deleted provider filtering (#76)
* fix(adapters): handle separate usage chunk in OpenAI streaming responses
Some OpenAI-compatible providers send token usage in a separate chunk
(with choices=[]) after the finish_reason chunk, rather than bundling
them together. Previously, this usage-only chunk was silently skipped
because data.choices[0] was undefined, causing token counts to always
be recorded as -1 for streaming requests. This broke TPM rate limiting
and usage tracking.
Now both patterns are supported:
- Usage bundled with finish_reason in the same chunk
- Usage in a separate subsequent chunk (choices=[])
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(db): filter soft-deleted providers in listUniqueSystemNames
listUniqueSystemNames() only filtered NOT models.deleted but did not
join the providers table or check NOT providers.deleted. When a provider
was soft-deleted, its models (still deleted=false) would appear in the
global model registry, but getModelsWithProviderBySystemName() correctly
filtered them out, causing the UI to show models with no providers.
Add innerJoin on ProvidersTable and NOT providers.deleted filter to
match the behavior of getModelsWithProviderBySystemName().
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(adapters): omit messageDelta in usage-only chunk to avoid overwriting stopReason
Remove explicit stopReason: null from the usage-only message_delta
yield to prevent overwriting a previously set stopReason. This aligns
with the pattern used in openai-responses.ts for usage-only events.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 3d4016f commit 3121a7b
2 files changed
Lines changed: 27 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
| 14 | + | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
| |||
387 | 386 | | |
388 | 387 | | |
389 | 388 | | |
390 | | - | |
| 389 | + | |
391 | 390 | | |
392 | 391 | | |
393 | 392 | | |
| |||
510 | 509 | | |
511 | 510 | | |
512 | 511 | | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
513 | 523 | | |
514 | 524 | | |
515 | 525 | | |
| |||
581 | 591 | | |
582 | 592 | | |
583 | 593 | | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
590 | 597 | | |
591 | 598 | | |
592 | 599 | | |
593 | 600 | | |
594 | 601 | | |
595 | | - | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
596 | 608 | | |
597 | 609 | | |
598 | 610 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
955 | 955 | | |
956 | 956 | | |
957 | 957 | | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
958 | 962 | | |
959 | 963 | | |
960 | 964 | | |
| 965 | + | |
961 | 966 | | |
962 | 967 | | |
963 | 968 | | |
| |||
0 commit comments