fix(proxy): keep hook dicts with no type on the base Responses frame

A hook dict with no type is not a Responses event, so it gets no event
name either way. Sending it as JSON only made litellm SDKs that read
type on every event stop the stream. Keep such dicts on the frame the
base sends, so every SDK version reads them as before.
This commit is contained in:
mateo-berri 2026-11-02 13:14:18 -08:00
parent df14d51115
commit f4373d28eb
2 changed files with 11 additions and 2 deletions

View file

@ -141,10 +141,13 @@ def _is_plain_json(chunk: object) -> bool:
return next((not level.values for level in levels if _settles(level)), False)
def _carries_a_type(chunk: object) -> bool:
return _is_dict(chunk) and type(chunk) is dict and "type" in chunk
def responses_chunk_data(chunk: object) -> str | None:
kind: Final = type(chunk)
try:
return json.dumps(chunk, allow_nan=False) if kind is dict and _is_plain_json(chunk) else None
return json.dumps(chunk, allow_nan=False) if _carries_a_type(chunk) and _is_plain_json(chunk) else None
except (ValueError, RecursionError):
return None

View file

@ -335,6 +335,12 @@ def test_responses_sse_chunk_that_json_cannot_show_as_printed_keeps_the_base_fra
assert _format_responses_sse_chunk(chunk=chunk) == _format_streaming_sse_chunk(chunk=chunk)
def test_responses_sse_chunk_without_a_type_keeps_the_base_frame() -> None:
chunk: Final = {"note": "hook output without a type"}
assert _format_responses_sse_chunk(chunk=chunk) == _format_streaming_sse_chunk(chunk=chunk)
def test_responses_error_event_encodes_its_detail_the_way_the_chat_error_frame_does() -> None:
error: Final = {
"message": "blocked",