fix(streaming): skip empty partial_json in trigger chunk delta

Only emit the trigger chunk's input_json_delta when partial_json is
non-empty.  OpenAI-style providers send arguments="" in the first
tool chunk, which was producing a spurious empty content_block_delta
event and breaking existing test expectations.
This commit is contained in:
Kiyeon Jeon 2026-04-13 05:02:34 +09:00
parent 0dc0919d39
commit 47a8d4b080

View file

@ -144,9 +144,12 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper):
)
# Also emit the trigger chunk's delta so that providers like
# Ollama that send the complete tool call in a single chunk
# do not lose their arguments.
# do not lose their tool arguments. Skip empty deltas
# (e.g. OpenAI sends arguments="" in the first tool chunk).
if processed_chunk.get("type") == "content_block_delta":
self.chunk_queue.append(processed_chunk)
delta = processed_chunk.get("delta", {})
if delta.get("partial_json"):
self.chunk_queue.append(processed_chunk)
self.sent_content_block_finish = False
return self.chunk_queue.popleft()
@ -328,9 +331,13 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper):
# Also emit the trigger chunk's delta so that providers
# like Ollama that send the complete tool call in a
# single chunk do not lose their arguments.
# single chunk do not lose their tool arguments. Skip
# empty deltas (e.g. OpenAI sends arguments="" in the
# first tool chunk).
if processed_chunk.get("type") == "content_block_delta":
self.chunk_queue.append(processed_chunk)
delta = processed_chunk.get("delta", {})
if delta.get("partial_json"):
self.chunk_queue.append(processed_chunk)
# Reset state for new block
self.sent_content_block_finish = False