Skip to content

docs: Improve streaming documentation with event diagrams and correct types#1780

Open
darshjme wants to merge 1 commit intoopenai:masterfrom
darshjme:docs/streaming-improvements
Open

docs: Improve streaming documentation with event diagrams and correct types#1780
darshjme wants to merge 1 commit intoopenai:masterfrom
darshjme:docs/streaming-improvements

Conversation

@darshjme
Copy link

Summary

Addresses #860 -- the streaming documentation uses convenience event names (textCreated, textDelta, toolCallCreated) without explaining how they relate to the raw SSE events (thread.message.delta, thread.run.step.delta, etc.) from the API reference. This makes it hard to discover events like thread.run.completed or thread.run.requires_action that don't have convenience wrappers.

Changes:

  • helpers.md: Added a full Responses API streaming section with Mermaid sequence diagrams showing the event lifecycle, an event type reference table, and a tool-call flow diagram
  • helpers.md: Added a mapping table connecting each Assistant convenience event to its underlying SSE event(s), plus a Mermaid sequence diagram for the Assistant streaming lifecycle
  • helpers.md: Added a raw event listener example showing how to use .on('event', ...) for events like thread.run.completed and thread.run.requires_action
  • README.md: Expanded the streaming section with a Mermaid sequence diagram and examples showing both .on() typed event listeners and for await...of iteration

Test plan

  • Verify Mermaid diagrams render correctly on GitHub
  • Confirm event type names match the SDK source (src/resources/responses/responses.ts, src/lib/AssistantStream.ts)
  • Check all code examples for TypeScript correctness

Addresses openai#860 by clarifying the relationship between raw SSE events
and the SDK's convenience event listeners.

Changes:
- Add Responses API streaming section to helpers.md with Mermaid
  sequence diagrams showing the event lifecycle
- Add event type reference table for Responses streaming
- Add mapping table showing how Assistant convenience events (textDelta,
  toolCallCreated, etc.) relate to raw SSE events (thread.message.delta,
  thread.run.step.delta, etc.)
- Add Mermaid diagram for Assistant streaming lifecycle
- Add raw event listener example for Assistants (thread.run.completed,
  thread.run.requires_action) that were previously undocumented
- Update README streaming section with Mermaid diagram and typed event
  examples
@darshjme darshjme requested a review from a team as a code owner March 19, 2026 15:50
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4720553dd3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

| `event` | _all events_ | `(event: AssistantStreamEvent) => void` |
| `runStepCreated` | `thread.run.step.created` | `(runStep: RunStep) => void` |
| `runStepDelta` | `thread.run.step.delta` | `(delta: RunStepDelta, snapshot: RunStep) => void` |
| `runStepDone` | `thread.run.step.completed` | `(runStep: RunStep) => void` |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Correct runStepDone mapping for non-completed terminal events

The new mapping row documents runStepDone as if it only comes from thread.run.step.completed, but AssistantStream.#handleRunStep emits runStepDone for thread.run.step.failed, thread.run.step.cancelled, and thread.run.step.expired as well (src/lib/AssistantStream.ts, switch cases around lines 537-550). Users following this table may skip failure/cancellation handling and incorrectly assume no runStepDone callback will fire in those paths.

Useful? React with 👍 / 👎.

| `textDone` | `thread.message.completed` | `(content: Text, snapshot: Message) => void` |
| `toolCallCreated` | `thread.run.step.delta` (first tool call) | `(toolCall: ToolCall) => void` |
| `toolCallDelta` | `thread.run.step.delta` (subsequent) | `(delta: ToolCallDelta, snapshot: ToolCall) => void` |
| `toolCallDone` | `thread.run.step.completed` | `(toolCall: ToolCall) => void` |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Expand toolCallDone mapping to include delta/terminal emissions

This row says toolCallDone is triggered by thread.run.step.completed, but the stream implementation also emits toolCallDone when switching tool-call indices during thread.run.step.delta and on other terminal step states (failed, cancelled, expired) in src/lib/AssistantStream.ts (around lines 524-546). Documenting only thread.run.step.completed can lead integrators to miss legitimate toolCallDone callbacks and mishandle tool-call lifecycle state.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant