Skip to content

feat(middleware): implement DeliveryAdapter with streaming and chunk splitting#27

Merged
alexey-pelykh merged 1 commit intomainfrom
feat/delivery-adapter
Feb 26, 2026
Merged

feat(middleware): implement DeliveryAdapter with streaming and chunk splitting#27
alexey-pelykh merged 1 commit intomainfrom
feat/delivery-adapter

Conversation

@alexey-pelykh
Copy link
Copy Markdown

Summary

Implements the DeliveryAdapter class that converts AgentEvent async iterables from CLI runtimes into channel-deliverable ReplyPayload chunks.

  • Text accumulation: Buffers incremental text events into coherent chunks
  • Smart splitting: Splits at chunkLimit (default 4000) with boundary preference: paragraph (\n\n) > line (\n) > word (space) > hard split
  • Code fence preservation: Detects open markdown fences and either splits before them or closes/reopens at split points
  • Streaming callbacks: Invokes BridgeCallbacks (onPartialReply, onBlockReply, onToolResult) for real-time channel delivery
  • Error formatting: Formats error events with isError: true and optional error codes
  • Tool result formatting: Formats tool results via onToolResult callback

Test plan

  • 33 tests covering all acceptance criteria
  • Text accumulation (single, multiple, empty, none)
  • Message splitting (paragraph, line, word, hard boundaries)
  • Streaming callbacks (partial, block, tool result, async, optional)
  • Event types (tool_use no-op, tool_result, error, done flush)
  • Code fence preservation (backtick, tilde, closed fences)
  • Integration pattern (realistic sequence, no-done fallback, very long text)
  • Default chunk limit verification
  • Full test suite passes (861 tests)
  • pnpm check passes (format + typecheck + lint)

Closes #26

🤖 Generated with Claude Code

…splitting (#26)

Converts AgentEvent async iterable from CLI runtimes into
channel-deliverable ReplyPayload chunks. Handles text accumulation,
smart boundary splitting (paragraph > line > word > hard), markdown
code fence preservation, streaming callbacks, and error formatting.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@alexey-pelykh alexey-pelykh merged commit cd6f416 into main Feb 26, 2026
2 checks passed
@alexey-pelykh alexey-pelykh deleted the feat/delivery-adapter branch February 26, 2026 06:51
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.

Implement DeliveryAdapter

1 participant