Skip to content

feat: upgrade TUI streaming to LangGraph streamEvents v3 - #29

Merged
avoidwork merged 1 commit into
mainfrom
feat/stream-events-tui
May 25, 2026
Merged

feat: upgrade TUI streaming to LangGraph streamEvents v3#29
avoidwork merged 1 commit into
mainfrom
feat/stream-events-tui

Conversation

@avoidwork

@avoidwork avoidwork commented May 25, 2026

Copy link
Copy Markdown
Owner

Description

Upgrade the TUI streaming implementation to use LangGraph's streamEvents v3 API for real-time token-by-token rendering with tool call visibility. Replaces the old streamMode: "updates" approach with the newer event streaming API that provides typed projections for messages and tool lifecycle events. Text now renders incrementally as tokens arrive.

Type of Change

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

Testing

  • Replaced all 4 old streamMode: "updates" tests in tests/unit/react_agent.test.js with 8 new streamEvents v3 tests:
    • Token-by-token text delta streaming with accumulated display
    • Empty/whitespace token filtering (trim-based)
    • Tool event emission (tool_start, tool_end, tool_error, tool_event)
    • Fallback when no text content
    • Async iterable text handling on ChatModelStream
    • Text projection error handling (throws)
  • Added 3 new TUI event dispatch tests in tests/unit/tui.test.js:
    • Text event dispatch from streamEvents callback
    • Tool end and tool error event formatting
    • Tool call display line formatting with newlines
  • All 61 tests pass (18 agent + 43 TUI)
  • Integration tests run as part of pre-commit hook

Coverage

  • react.js: 100% line coverage (100.00 / 58.82% branch / 100.00% functions)
  • Overall: 88.97% line coverage (up from 88.65%)
  • All modified files have test coverage

Checklist

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

Changes

src/agent/react.js

  • callReactAgentStreaming uses agent.streamEvents({ version: "v3" })
  • Iterates stream.messages for ChatModelStream instances
  • Real incremental streaming: iterates chatMessage.text as async iterable, accumulating deltas and trimming before each callback
  • Iterates raw ProtocolEvents to capture tools channel events
  • New emitToolEvent() normalizes ProtocolEvents into typed callbacks

src/tui/app.js

  • Unified event dispatch callback in handleChat processes all event types
  • text events update streaming content with \u2588 cursor
  • tool_end/tool_error events append formatted tool results to toolCallDisplay
  • Tool call display persists after streaming completes

src/tui/conversationPanel.js

  • Assistant messages with toolCallDisplay render tool results below content
  • Dim/gray styled text for tool interactions

src/tui/messages.js

  • Added getToolCallLines() helper function
  • Updated Message typedef with toolCalls and toolCallDisplay fields

@avoidwork avoidwork self-assigned this May 25, 2026
- Replace streamMode: updates with streamEvents(v3) for token-by-token streaming
- Add typed event callback: text, tool_start, tool_event, tool_end, tool_error
- Display tool call results separately from assistant message content
- Update Message typedef with toolCalls and toolCallDisplay fields
- Add comprehensive tests for streamEvents callback dispatch
- Add coverage tests for tool_event emission and text error handling
@avoidwork
avoidwork force-pushed the feat/stream-events-tui branch from 21cac37 to 24ce366 Compare May 25, 2026 17:35
@avoidwork
avoidwork merged commit 2ac67ae into main May 25, 2026
@avoidwork
avoidwork deleted the feat/stream-events-tui branch May 25, 2026 17:37
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