Repository navigation
feat(typespec-ts): streaming - #5196
Libba Lawrence (l0lawrence) merged 36 commits into
Conversation
|
❌ There is undocummented changes. Run The following packages have changes but are not documented.
The following packages have already been documented:
Show changes
|
📦 Package size report1 package changed size, +18.99 KB (+0.1%) packed overall.
13 package(s) with no notable change
Packed = gzipped |
commit: |
|
You can try these changes here
|
Maor Leger (maorleger)
left a comment
There was a problem hiding this comment.
This is coming along quite nicely!! Thanks so much for all the effort in getting this together.
I still have lots to review, but the overall direction seems ok. I noted a few findings that we should fix though
c503c07 to
1a2adc2
Compare
|
Hi @Libba Lawrence (@l0lawrence). Your PR has had no update for 14 days and it is marked as a stale PR. If it is not updated within 14 days, the PR will automatically be closed. If you want to refresh the PR, please remove the |
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical and moderate streaming-generation and runtime issues remain.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds structured JSONL and SSE streaming generation for the TypeScript emitter, producing lazy AsyncIterable responses with deserialization and terminal-event handling.
Changes:
- Adds Node, browser, and React Native streaming helpers.
- Integrates stream metadata and conditional
@azure/core-ssedependencies. - Adds scenarios, tests, generated baselines, configuration, and changelog updates.
File summaries
| File | Summary |
|---|---|
pnpm-workspace.yaml |
Adds the SSE dependency catalog entry. |
pnpm-lock.yaml |
Locks streaming-related dependencies. |
packages/typespec-ts/test/util/test-util.ts |
Adds streaming test-library support. |
packages/typespec-ts/test/modular-unit/scenarios/operations/streaming.md |
Adds JSONL and SSE generation scenarios. |
packages/typespec-ts/test/azure-modular-integration/streaming-sse.test.ts |
Adds SSE integration coverage. |
packages/typespec-ts/test/azure-modular-integration/generated/streaming/sse/tspconfig.yaml |
Configures the generated SSE fixture. |
packages/typespec-ts/test/azure-modular-integration/generated/streaming/sse/src/index.d.ts |
Adds the generated SSE API baseline. |
packages/typespec-ts/test/azure-modular-integration/generated/streaming/sse/.gitignore |
Tracks generated fixture artifacts. |
packages/typespec-ts/test-next/unit/static-helpers/sse-streaming-helpers.test.ts |
Tests SSE helper behavior. |
packages/typespec-ts/static/static-helpers/streamingHelpers.ts |
Implements Node JSONL streaming; includes a moderate decoder-flush issue and a nit for missing JSONL coverage. |
packages/typespec-ts/static/static-helpers/streamingHelpers-react-native.mts |
Re-exports browser streaming helpers for React Native. |
packages/typespec-ts/static/static-helpers/streamingHelpers-browser.mts |
Implements browser streaming; has moderate cancellation and decoder-flush issues. |
packages/typespec-ts/static/static-helpers/sseStreamingHelpers.ts |
Implements SSE parsing, dispatch, and termination. |
packages/typespec-ts/static/static-helpers/sseStreamingHelpers-react-native.mts |
Provides React Native SSE exports. |
packages/typespec-ts/static/static-helpers/sseStreamingHelpers-browser.mts |
Provides browser SSE exports. |
packages/typespec-ts/src/modular/static-helpers-metadata.ts |
Registers streaming helper metadata. |
packages/typespec-ts/src/modular/helpers/operation-helpers.ts |
Generates streaming operations and deserializers; has two critical and two moderate unresolved issues involving envelopes, content types, response options, and modeled errors. |
packages/typespec-ts/src/modular/external-dependencies.ts |
Registers the SSE runtime dependency. |
packages/typespec-ts/src/index.ts |
Loads helpers and injects dependencies conditionally. |
packages/typespec-ts/spector.config.yaml |
Enables the SSE Spector scenario. |
packages/typespec-ts/package.json |
Declares streaming-related dependencies. |
.chronus/changes/structured-jsonl-sse-streaming-2026-7-30-0-0-0.md |
Documents the streaming feature. |
Review details
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
Suppressed comments (3)
packages/typespec-ts/src/modular/helpers/operation-helpers.ts:925
- This early return bypasses the existing
enableStorageCompatandincludeHeadersInResponsehandling below. Structured-stream operations therefore never install the storage-compatonResponseinterceptor, never return the configured response/header metadata, and silently ignore those emitter options, unlike the existing streaming response path. Support these options for structured streams or reject/document the incompatible combination instead of silently changing the contract.
const structuredStreamInfo = getStructuredStreamInfo(context, operation);
if (structuredStreamInfo) {
packages/typespec-ts/static/static-helpers/streamingHelpers-browser.mts:78
- The browser implementation has the same unflushed
TextDecoderstate: a UTF-8 code point split at end-of-stream is not emitted before the trailing JSONL fragment is parsed. Flush the decoder before readingbufferafter the loop.
buffer += typeof chunk === "string" ? chunk : decoder.decode(chunk, { stream: true });
packages/typespec-ts/static/static-helpers/streamingHelpers.ts:52
TextDecoder.decode(..., { stream: true })can retain a partial UTF-8 sequence at the end of the body. Because the decoder is never flushed after the loop, a multibyte character split across the final chunk is silently dropped/replaced before the last JSON line is parsed. Flush the decoder before processingbufferafter iteration.
buffer += typeof chunk === "string" ? chunk : decoder.decode(chunk, { stream: true });
- Files reviewed: 18/22 changed files
- Comments generated: 5
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Hi @Libba Lawrence (@l0lawrence). This PR will be closed since it has had no update for 28 days. If this change is still relevant, please reopen the PR. |
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
Review effort: Lite
Findings: 4
Open (13)
Same issue as the Node helper: the browser JSONL decoder never flushes the TextDecoder, which can… · NewreadJsonlStream()uses TextDecoder with{ stream: true }but never flushes the decoder at the… · NewgetStreamResponseleavesresult.bodyas anAsyncIterable, butgetExceptionThrowStatement… This path ignoressseEvent.isEventEnvelopeand deserializespayloadTypedirectly. For an event… The SSE reconnection options are added purely based on(streamMetadata && sseMetadata), but the… · NewpackageHasSseStreaming()doesn’t fully mirrorgetStructuredStreamInfo()’s SSE gating:… · NewpackageHasStructuredStreaming()can load the streaming helper set for any response that has… · NewreadSseStream()does not stop iteration after a typed terminal event (`descriptor.isTerminal ===… · New The PR adds substantial JSONL decoding logic (line splitting, buffering across chunks, JSON.parse… · New On early termination (for example, after an SSE terminal event), this generator'sfinallyonly… An omittedpayloadContentTypeis not always JSON: TCGC leaves it undefined for inferred event… The JSONL deserializer emits an inline status check even though a shared helper… · New The new JSONL decoder has no runtime unit or integration coverage; the added helper tests exercise…
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
Remove obsolete protocol skip detection and compatibility casts. Assert explicit @DaTa payloads and full-model SSE events independently through EOF using generated operation types. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8bbec15a-04ed-41e4-9fae-e27932b80317
Use ordinary JSON.stringify quoting instead of custom script-embedding escapes. Remove the dedicated utility and exotic-metadata tests while preserving SSE Spector coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8bbec15a-04ed-41e4-9fae-e27932b80317
Include terminal constants in generated return types and yield them before stopping. Preserve named event envelopes with the default message name for unnamed terminals, keep unnamed streams payload-only, and update runtime, snapshots and Spector coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8bbec15a-04ed-41e4-9fae-e27932b80317
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8bbec15a-04ed-41e4-9fae-e27932b80317
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8bbec15a-04ed-41e4-9fae-e27932b80317
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8bbec15a-04ed-41e4-9fae-e27932b80317
…tream on terminal event Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8bbec15a-04ed-41e4-9fae-e27932b80317
Handle unnamed constant payloads and declared bodyless SSE responses, preserve exact public method names, and avoid the contentType local collision. Keep dedicated nullable SSE payload support deferred and shorten the changelog.
Drop three transport-prefetch assertions that depend on core-sse and Node scheduling. Preserve the existing terminal cleanup and typed cutoff coverage.
9aad75c to
3601b6c
Compare
Maor Leger (maorleger)
left a comment
There was a problem hiding this comment.
Thanks for pushing this along!!
d30e2a6
into
Azure:release/october-2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> ## Summary Prepare the October release-branch publication of `@azure-tools/typespec-ts@0.58.0` for the streaming functionality merged in #5196. - Bump only `@azure-tools/typespec-ts` from `0.57.1` to `0.58.0`. - Generate the changelog entry for JSONL and SSE streaming and consume its Chronus change description. - Leave all other package versions, `core`, and `pnpm-lock.yaml` unchanged. Generated with: ```sh pnpm chronus version --ignore-policies --only "@azure-tools/typespec-ts" ``` ## Validation - `pnpm format` passed. - `git diff --check` passed; verified exactly the three expected release files changed and no TypeScript package changes remain pending in Chronus. - `pnpm lint` was attempted but blocked by the missing `vite/client` type definition in `packages/typespec-azure-playground-website`. Full dependency installation could not complete because the registry download for `@fluentui/react-icons@2.0.339` stalled; fetching it from npm also failed with a TLS handshake error. The cached root release tools and formatter prerequisites were restored successfully. ## Release Target: **`release/october-2026`**, not `main`. The `0.58.0` minor version is intentional because #5196 is a feature. After CI and approval, **squash merge** this PR to trigger publication. Verify npm publication, then open the automatically generated `backmerge/release/october-2026-YYYY-MM-DD` branch as a PR into `main` and **rebase merge** it. Copilot-Session: bdcbe5ce-69fd-4bac-8980-7c2d1a73dc34



Adds structured JSONL + SSE streaming code generation to the
@azure-tools/typespec-tsmodular emitter. A response whose TCGC metadata indicates a structured stream now generates aPromise<AsyncIterable<T>>of deserialized items/events instead of returning the raw binaryUint8Arraybody. Does not contain reconnection support - depends on createStreamSSE(). Azure Search, the library requesting this feature, does not support reconnection at this point in time.The sse spec this is based on: https://html.spec.whatwg.org/multipage/server-sent-events.html
What is generated
JsonlStream<T>) ->Promise<AsyncIterable<T>>that lazily decodes JSON Lines.SSEStream<T>) ->Promise<AsyncIterable<...>>that dispatches each Server-Sent Event by itsevent:name (via@azure/core-sse), deserializes the payload, and stops at the terminal event. Full heterogeneous multi-event dispatch and@terminalEventhandling are supported (named terminals keyed on the terminal flag; unnameddata: [DONE]sentinel terminals). Generation is driven by TCGCstreamMetadata/sseMetadata.Issues for the future:
#5660 #5659
Related pr to core for abort signal/canceling stream: Azure/azure-sdk-for-js#40238