Repository navigation
feat(typespec-ts): generate structured JSONL and SSE streaming by default - #1
Closed
l0lawrence wants to merge 1 commit into
Closed
l0lawrence wants to merge 1 commit into
l0lawrence wants to merge 1 commit into
Conversation
…ault JSONL/SSE stream responses now return Promise<AsyncIterable<T>> of deserialized items/events instead of the raw binary Uint8Array body. JsonlStream<T> lazily decodes JSON Lines; SSEStream<T> dispatches each Server-Sent Event by its event: name (via @azure/core-sse), deserializes the payload, and stops at the terminal event. Heterogeneous multi-event dispatch and terminal-event handling are supported. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: de6a6ea9-d1f8-4a50-831f-d64d9f7cfa0d
Owner
Author
|
Superseded by the upstream draft PR against Azure/typespec-azure main (Azure#5196). Closing this fork-targeted duplicate; branch and commit remain intact. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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. This mirrors microsoft/typespec#11594 (Python emitter) and the sibling@typespec/http-client-jswork.This is the default behavior — there is no opt-in option.
What's 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 (both named terminals, keyed on the terminal flag, and unnameddata: [DONE]sentinel terminals).Operations connect eagerly (HTTP status/errors surface at call time) and decode the body lazily.
Implementation
static/static-helpers/streamingHelpers.ts(getStreamResponse,readJsonlStream,readSseStream,SseEventDescriptor), registered instatic-helpers-metadata.tsand loaded only when the package actually has a structured-stream operation (packageHasStructuredStreaming, a side-effect-free metadata check).operation-helpers.ts:getStructuredStreamInforesolves stream metadata (gated purely onresponse.streamMetadata/sseMetadata); branches in the operation and deserialize builders emit the AsyncIterable shape.@azure/core-sseadded toAzureCoreDependenciesand injected into the generated package's dependencies only when an SSE op is present.Tests
Three new
unit-modularscenarios: JSONL, SSE named (heterogeneous + terminal[DONE]), and SSE unnamed (homogeneousmessageevents). Terminal handling was verified against the realhttp-specsSSE spec wire frames plus a runtime smoke of the helper.Validation
pnpm build(tsc) — passpnpm lint(oxlint --deny-warnings) — passOnly the 3 new streaming scenarios are semantically changed baselines; no non-streaming snapshots change.