feat: #279 add OpenAI raw model stream event narrowing helpers#1091
Merged
feat: #279 add OpenAI raw model stream event narrowing helpers#1091
Conversation
🦋 Changeset detectedLatest commit: b3e111b The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
seratch
added a commit
that referenced
this pull request
Mar 13, 2026
seratch
added a commit
that referenced
this pull request
Mar 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request resolves #279.
This pull request fixes the lack of precise typing for OpenAI raw model stream events while preserving the released generic stream surface in
@openai/agents-core. It adds OpenAI-specific narrowing helpers in@openai/agents-openai, threads a lightweight source marker through raw model events, and updates examples/docs to use the new guards instead of hand-writtenraw_model_stream_eventchecks and unsafe casts.The main changes are:
sourcederivation to raw model stream events inpackages/agents-core/src/events.tsisOpenAIResponsesRawModelStreamEvent(...)andisOpenAIChatCompletionsRawModelStreamEvent(...)plus typed aliases inpackages/agents-openai/src/rawModelEvents.ts, and export them through@openai/agents-openaiand@openai/agentsmodelevents with an explicit source inpackages/agents-openai/src/openaiResponsesModel.tsandpackages/agents-openai/src/openaiChatCompletionsStreaming.tspackages/agents-core/test/events.test.tsandpackages/agents-openai/test/rawModelEvents.test.ts, plus update existing OpenAI streaming testsexamples/basic/stream-ws.ts,examples/connectors/index.ts,examples/tools/code-interpreter.ts, andexamples/docs/mcp/hostedStream.tsto use the new helpersdocs/src/content/docs/guides/streaming.mdxexamples/docs/streaming/openaiResponsesRawModelStreamEvent.tsThis change is additive rather than breaking: generic consumers can keep using
RunRawModelStreamEvent, while OpenAI-specific consumers now get a sound way to recover the precise Responses or Chat Completions event unions.