Skip to content

feat: #279 add OpenAI raw model stream event narrowing helpers#1091

Merged
seratch merged 1 commit intomainfrom
fix/issue-279-openai-raw-model-event-helpers
Mar 13, 2026
Merged

feat: #279 add OpenAI raw model stream event narrowing helpers#1091
seratch merged 1 commit intomainfrom
fix/issue-279-openai-raw-model-event-helpers

Conversation

@seratch
Copy link
Copy Markdown
Member

@seratch seratch commented Mar 13, 2026

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-written raw_model_stream_event checks and unsafe casts.

The main changes are:

  • add source derivation to raw model stream events in packages/agents-core/src/events.ts
  • add isOpenAIResponsesRawModelStreamEvent(...) and isOpenAIChatCompletionsRawModelStreamEvent(...) plus typed aliases in packages/agents-openai/src/rawModelEvents.ts, and export them through @openai/agents-openai and @openai/agents
  • tag OpenAI Responses and Chat Completions raw model events with an explicit source in packages/agents-openai/src/openaiResponsesModel.ts and packages/agents-openai/src/openaiChatCompletionsStreaming.ts
  • add regression coverage in packages/agents-core/test/events.test.ts and packages/agents-openai/test/rawModelEvents.test.ts, plus update existing OpenAI streaming tests
  • update user-facing examples in examples/basic/stream-ws.ts, examples/connectors/index.ts, examples/tools/code-interpreter.ts, and examples/docs/mcp/hostedStream.ts to use the new helpers
  • update the streaming guide in docs/src/content/docs/guides/streaming.mdx
  • include an untracked new docs example file: examples/docs/streaming/openaiResponsesRawModelStreamEvent.ts

This 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.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 13, 2026

🦋 Changeset detected

Latest commit: b3e111b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@openai/agents Patch
@openai/agents-core Patch
@openai/agents-openai Patch
@openai/agents-extensions Patch
@openai/agents-realtime Patch

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

@github-actions github-actions bot added this to the 0.7.x milestone Mar 13, 2026
seratch added a commit that referenced this pull request Mar 13, 2026
@seratch seratch merged commit 7fc871a into main Mar 13, 2026
6 checks passed
@seratch seratch deleted the fix/issue-279-openai-raw-model-event-helpers branch March 13, 2026 05:41
seratch added a commit that referenced this pull request Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change StreamEventGenericItem.event Type from any to OpenAI ResponseStreamEvent

1 participant