Skip to content

Comments

feat(stream): add optional typed streaming callbacks#26

Merged
activadee merged 3 commits intomainfrom
codex/optional-sugar-layer-over-typed-streaming-events-to-44
Nov 6, 2025
Merged

feat(stream): add optional typed streaming callbacks#26
activadee merged 3 commits intomainfrom
codex/optional-sugar-layer-over-typed-streaming-events-to-44

Conversation

@activadee
Copy link
Owner

@activadee activadee commented Nov 6, 2025

This PR introduces an optional sugar layer for handling typed streaming events without writing a large switch over ThreadEvent.

Summary

  • Add StreamCallbacks with a generic OnEvent and type-specific hooks (message, reasoning, command execution, patch + per-file changes, web search, MCP tool call, todo list, error item).
  • Wire callbacks into Thread.runStreamed so callbacks run first, then the raw event is forwarded through Events(), preserving backpressure semantics.
  • Extend TurnOptions with a Callbacks field to opt into the feature.
  • Document usage in README with a runnable example under examples/streaming_callbacks.
  • Add tests verifying typed callback dispatch and stages.

Notes

activadee added 3 commits November 6, 2025 21:22
- Introduce StreamCallbacks with generic OnEvent and typed hooks for
  messages, reasoning, command exec, patches + per-file changes, web search,
  MCP tool calls, todo lists, and error items.
- Wire callbacks into Thread.runStreamed so events are first dispatched to
  callbacks, then forwarded on the Events() channel to preserve existing
  behavior and backpressure semantics.
- Add TurnOptions.Callbacks to opt into the sugar layer without breaking
  existing users.
- Assert Message, Command, Patch, FileChange, WebSearch callbacks fire
  with correct stages and payloads.
- Ensure draining Events() remains required while using callbacks.
- Add README section with guidance, usage snippet, and backpressure note.
- Provide examples/streaming_callbacks showing typed callback usage.
@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

Codex Review Summary

Recommendation: ✅ Ready to merge – no blocking issues detected.

Summary:
All changes look solid. The new callback plumbing in thread.go:97 invokes user hooks only after the thread ID is set, the typed payloads in callbacks.go:17 mirror our item types correctly, and the regression test in thread_stream_test.go:49 exercises the critical paths. With documentation updated in README.md:75 and the runnable sample in examples/streaming_callbacks/main.go:1, I’m confident the feature behaves as expected. Only remaining consideration is the documented need for callers to keep draining RunStreamed’s Events() channel when relying on callbacks.

Inline findings:

  • No inline findings.

Generated at 2025-11-06T20:28:06.800Z.

@activadee activadee merged commit 6b8933e into main Nov 6, 2025
2 checks passed
@activadee activadee deleted the codex/optional-sugar-layer-over-typed-streaming-events-to-44 branch November 6, 2025 20:34
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.

SDK DX: streaming callbacks (OnMessage/OnCommand/OnWebSearch/OnPatch/OnFileChange)

1 participant