fix(anthropic): aux stream reader tolerates non-iterable get_final_message shims

_stream_final_message now iterates the SDK MessageStream only when it is
iterable; a shim exposing just get_final_message() (the auxiliary client
fake and any gateway wrapper of that shape) falls straight through to the
snapshot instead of raising TypeError. Restores the pre-refusal-fix
contract where the aux path never required event iteration.
This commit is contained in:
teknium1
2026-09-18 03:55:19 -07:00
committed by Teknium
parent 3f3fe7d763
commit eb942819fa

View File

@@ -8,6 +8,7 @@ import logging
import math
import re
import subprocess
from collections.abc import Iterable
from contextlib import suppress
from typing import Any, Dict, List, Optional
@@ -663,8 +664,9 @@ def _stream_final_message(stream_fn, api_kwargs, log_prefix, on_stream_event, on
# has given up, so abandon the stream (``with`` closes it) instead of streaming an answer
# nobody reads.
# Some SDK versions drop optional message_delta metadata from the final snapshot.
# Non-iterable shims (get_final_message-only) skip straight to the snapshot.
stop_details = None
for event in stream:
for event in (stream if isinstance(stream, Iterable) else ()):
if getattr(event, "type", None) == "message_delta":
details = getattr(getattr(event, "delta", None), "stop_details", None)
if details is not None: