Skip to content

feat: adopt streamEvents v2 protocol for enhanced real-time TUI streaming - #56

Merged
avoidwork merged 1 commit into
mainfrom
feat/event-streaming-enhanced-ui
May 31, 2026
Merged

feat: adopt streamEvents v2 protocol for enhanced real-time TUI streaming#56
avoidwork merged 1 commit into
mainfrom
feat/event-streaming-enhanced-ui

Conversation

@avoidwork

@avoidwork avoidwork commented May 31, 2026

Copy link
Copy Markdown
Owner

Description

Switches the agent streaming from streamMode: "values" to the streamEvents v2 protocol for finer-grained event-based streaming. This enables real-time reasoning/thought display, explicit tool lifecycle signals, and incremental text streaming in the TUI.

Type of Change

  • New feature (non-breaking change which adds functionality)

Testing

  • npm run test — 776 tests pass, 164 suites
  • All agent streaming tests rewritten to mock streamEvents instead of stream/AgentStream
  • Added tests for: reasoning content extraction, tool lifecycle events (start/end/error), deduplication logic, content format handling (string, object, array), configurable propagation
  • Pre-existing failures: 3 tests in prompts.test.js (unrelated — pre-date this change)

Coverage

  • 100% line coverage maintained (regenerated via npm run coverage — pre-commit hook passes)

Checklist

  • npm run lint passes
  • Tests pass with 100% line coverage
  • No forbidden patterns used
  • Conventional Commit style applied

Changes by file

File Change
src/agent/react.js callReactAgentStreaming uses agent.streamEvents({ messages }, { version: "v2" }); emits text, reasoning, tool_start, tool_end, tool_error
src/provider/openai.js ChatOpenAI created with streaming: true by default
src/tui/app.js Handlers for reasoning (thinking content) and activeToolCall (running tool indicator); uses committedContent for final response text
src/tui/conversationPanel.js Renders (thinking) prefix for reasoning; - Running: tool_name ... for active tool calls
src/tui/messages.js Message typedef extended with reasoningContent, activeToolCall, toolCallDisplay fields

Architecture: streamEvents v2 vs streamMode: "values"

Feature streamMode: "values" (old) streamEvents v2 (new)
Granularity State snapshots per step Individual runnable events
Text streaming Full content replacing Incremental delta chunks
Reasoning content Not accessible on_chat_model_stream with chunk.reasoning
Tool start signal Inferred from message tool_calls Explicit on_tool_start event
Tool result data Not available on_tool_end with data.output
Tool errors Not surfaced on_tool_error with error message

PR Template Checklist

All sections below filled per section 5.4 (no blanks).

Files Changed (10 files, +543 −277)

src/agent/react.js, src/provider/openai.js, src/tui/app.js, src/tui/conversationPanel.js, src/tui/messages.js, tests/unit/conversationPanel.test.js, tests/unit/provider.test.js, tests/unit/react_agent.test.js, tests/unit/react_agent_checkpoint.test.js, coverage.txt

…ming

Switch agent streaming from streamMode 'values' to streamEvents with
v2 protocol for granular event-based streaming. This enables:

- Reasoning/thinking content streamed in real-time via on_chat_model_stream
  events with chunk.reasoning property (e.g., Claude thought blocks)
- Explicit tool lifecycle events: on_tool_start, on_tool_end, on_tool_error
  with input/output context, showing 'Running: tool_name' during execution
- Final AI response text streaming as token deltas via on_chat_model_stream
  events with AIMessageChunk content extraction
- Model-level streaming enabled by default (ChatOpenAI streaming: true)

Changes:
- src/agent/react.js: rewrite callReactAgentStreaming to use streamEvents v2
  protocol, emit text/reasoning/tool_start/tool_end/tool_error events
- src/provider/openai.js: enable streaming: true on ChatOpenAI instances
- src/tui/app.js: handle reasoning, activeToolCall, and text append events
- src/tui/conversationPanel.js: render reasoning content and running tool
  indicators alongside existing toolCallDisplay
- src/tui/messages.js: extend Message typedef with new fields
- Update all related tests to mock streamEvents instead of stream/AgentStream
@avoidwork
avoidwork force-pushed the feat/event-streaming-enhanced-ui branch from 6885c0a to 9f68037 Compare May 31, 2026 17:32
@avoidwork avoidwork changed the title feat: streamEvents v2 protocol for enhanced TUI streaming feat: adopt streamEvents v2 protocol for enhanced real-time TUI streaming May 31, 2026
@avoidwork avoidwork self-assigned this May 31, 2026
@avoidwork
avoidwork merged commit 4911865 into main May 31, 2026
@avoidwork
avoidwork deleted the feat/event-streaming-enhanced-ui branch May 31, 2026 17:38
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