Skip to content

Conversation

@boylec
Copy link
Contributor

@boylec boylec commented Jan 20, 2026

Summary

Aligns xAI provider streaming behavior with OpenAI's pattern for text-end event timing.

Problem

Currently, xAI emits text-end events only in the flush() handler at the very end of the stream. This differs from OpenAI which emits text-end when the message item is done (response.output_item.done).

Solution

Emit text-end immediately when message content completes, matching OpenAI's behavior. This gives consumers accurate timing for when text content is finished.

Why This Matters

Applications that process streaming events need to know when text content is complete (e.g., to trigger UI updates, start processing, etc.). Deferring text-end to flush means consumers can't distinguish between "text is done" and "entire response is done".

Changes

  • Track ended state in contentBlocks to avoid duplicate emissions
  • Emit text-end in response.output_item.done handler when message content completes
  • Update flush() to only emit text-end for blocks that weren't already ended

Checklist

  • Tests have been added / updated
  • A changeset has been added

Aligns xAI provider with OpenAI's streaming pattern by emitting text-end
events when the message item is done, rather than deferring to flush().

This ensures consumers receive text-end at the correct time in the stream,
which is important for applications that need to know when text content
is complete before the entire response finishes.
@boylec boylec force-pushed the fix/xai-text-end-timing branch from 54c8f04 to 0445fc8 Compare January 20, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant