Normalize a provider-reported finish reason onto the canonical
StreamFinishReason union.
Providers disagree on vocabulary: OpenAI-compatible hosts emit
length / tool_calls / stop; Anthropic's adapter maps its raw
stop_reason before it reaches this layer but raw max_tokens /
tool_use / end_turn are accepted here too so a provider that
skips that mapping still normalizes. Unknown strings and null/undefined
degrade to 'stop' — the pre-existing semantics of the streaming
surface, which fabricated 'stop' unconditionally.
Normalize a provider-reported finish reason onto the canonical StreamFinishReason union.
Providers disagree on vocabulary: OpenAI-compatible hosts emit
length/tool_calls/stop; Anthropic's adapter maps its rawstop_reasonbefore it reaches this layer but rawmax_tokens/tool_use/end_turnare accepted here too so a provider that skips that mapping still normalizes. Unknown strings and null/undefined degrade to'stop'— the pre-existing semantics of the streaming surface, which fabricated'stop'unconditionally.