chore(github-copilot): restore stream chunk type safety#33636
Open
Robin1987China wants to merge 1 commit into
Open
chore(github-copilot): restore stream chunk type safety#33636Robin1987China wants to merge 1 commit into
Robin1987China wants to merge 1 commit into
Conversation
Replace the generic createOpenAICompatibleChatChunkSchema with a non-generic version that preserves the output type. The from ProviderErrorStructure<any> was propagating through the union schema to the TransformStream, leaving all chunk.value accesses untyped. Extract the success schema into a named constant and cast the union return to a concrete type so the transform callback regains type checking on choices, usage, delta, etc.
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #33093
Type of change
What does this PR do?
Restores TypeScript type safety on the chunk stream transform callback in
OpenAICompatibleChatLanguageModel.doStream().ProviderErrorStructure<any>passesZodType<any>as the error schema to the genericcreateOpenAICompatibleChatChunkSchema. The generic infersany, soz.union([successSchema, ZodType<any>])collapses output toany. This propagates throughz.infer<typeof chunkSchema>to the TransformStream'sParseResult<any>, leaving allchunk.valueaccesses (choices, usage, delta, etc.) untyped.Fix: extract the success chunk schema into a named const, derive a concrete type, and use a non-generic version of the chunk schema builder with an explicit cast. This preserves runtime validation (error schema still participates in the union) while giving TypeScript a proper type for narrowing.
How did you verify your code works?
bun typecheck— zero new errorsbun test --filter copilot-chat-model— 11/11 passScreenshots / recordings
N/A
Checklist