Skip to content

feat(4): support streaming typed clients#146

Closed
0xpolarzero wants to merge 8 commits into
wevm:mainfrom
0xpolarzero:feature/streaming-typed-client
Closed

feat(4): support streaming typed clients#146
0xpolarzero wants to merge 8 commits into
wevm:mainfrom
0xpolarzero:feature/streaming-typed-client

Conversation

@0xpolarzero
Copy link
Copy Markdown

@0xpolarzero 0xpolarzero commented May 22, 2026

Warning

This PR is part of a stacked PR chain. Review/merge in order:
#144
#145
#143
> #146
#147

Overview

Adds streaming command support to the generated TypeScript client and structured RPC route.

API

// Commands declared with `async *run` return typed async iterables.
const stream = await client('project logs')({
  args: { id: 'p1' },
})
//    ^? AsyncIterable<{ line: string }>

for await (const chunk of stream) {
  //             ^? { line: string }
  console.log(chunk.line)
}

// Non-streaming commands keep returning regular promise results.
const result = await client('project deploy')({
  args: { id: 'p1' },
})
//    ^? project deploy output

Changes

  • Detect async generator command handlers and emit stream: true metadata in typegen.
  • Type streaming client calls as async iterables while preserving existing non-streaming call types.
  • Add application/x-ndjson handling for RPC stream responses.
  • Preserve returned CTA/error records from async generator RPC streams.
  • Cancel the response body when consumers stop reading a stream early.

Tests

  • Adds client tests for NDJSON chunks, stream errors, malformed streams, missing completion records, and cancellation.
  • Adds type tests for streaming command return inference.
  • Adds typegen snapshot coverage for generated stream metadata.
  • Adds RPC route coverage for async generator streams preserving returned CTA/error records.

@0xpolarzero 0xpolarzero force-pushed the feature/streaming-typed-client branch from 8441d5d to b1b1f53 Compare May 22, 2026 20:49
@0xpolarzero 0xpolarzero force-pushed the feature/streaming-typed-client branch from b1b1f53 to b247edf Compare May 22, 2026 20:55
@0xpolarzero 0xpolarzero force-pushed the feature/streaming-typed-client branch from b247edf to bfc33e6 Compare May 22, 2026 21:53
@0xpolarzero 0xpolarzero deleted the feature/streaming-typed-client branch May 24, 2026 23:16
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