fix: handle empty string delta.content in OpenAI streaming
Some providers send an empty string as the first delta to signal streaming start. The falsy check `if (delta.content)` treated "" as absent, skipping content_block_start. The next delta with actual content was emitted without it, violating the Anthropic protocol. Changed to `delta.content != null` to distinguish between absent field and empty string. Relates to #42 Co-Authored-By: Juan Camilo <juancamilo.auriti@gmail.com>
This commit is contained in:
@@ -345,8 +345,9 @@ async function* openaiStreamToAnthropic(
|
||||
for (const choice of chunk.choices ?? []) {
|
||||
const delta = choice.delta
|
||||
|
||||
// Text content
|
||||
if (delta.content) {
|
||||
// Text content — use != null to distinguish absent field from empty string,
|
||||
// some providers send "" as first delta to signal streaming start
|
||||
if (delta.content != null) {
|
||||
if (!hasEmittedContentStart) {
|
||||
yield {
|
||||
type: 'content_block_start',
|
||||
|
||||
Reference in New Issue
Block a user