fix(ai-sdk): make smartQuoteTransform generic for tool type compatibility - #10
Merged
Conversation
…lity The function previously returned StreamTextTransform<ToolSet>, which caused type incompatibility when used with streamText() calls that have specific tool types. Consumers were forced to use `as any` casts. Changed the function to be generic over TOOLS extends ToolSet, matching the pattern used by smoothStream and other AI SDK transforms. This allows TypeScript to properly infer and propagate tool types through the transform. Added regression tests to verify type compatibility with custom tool types.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a TypeScript typing issue where smartQuoteTransform was incompatible with streamText() calls using specific tool types, requiring unsafe type casts.
- Made
smartQuoteTransformgeneric over theTOOLStype parameter - Added comprehensive TSDoc documentation explaining the generic parameter
- Added regression tests to verify type compatibility with custom tool types
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/smartquote/src/ai-sdk/index.ts | Made smartQuoteTransform generic over TOOLS extends ToolSet for type compatibility with custom tool configurations |
| packages/smartquote/src/ai-sdk/index.test.ts | Added type compatibility tests to verify the transform works with both custom tool types and default ToolSet |
Comments suppressed due to low confidence (1)
packages/smartquote/src/ai-sdk/index.ts:91
- Superfluous argument passed to function TransformStream.
return new TransformStream<TextStreamPart<TOOLS>, TextStreamPart<TOOLS>>({
transform(part, controller) {
if (part.type === 'text-delta') {
const converted = transform(part.text);
if (converted) {
controller.enqueue({
...part,
text: converted,
});
}
} else {
controller.enqueue(part);
}
},
flush(controller) {
const remaining = transform.flush();
if (remaining) {
// Generate a unique ID for the final flush chunk
controller.enqueue({
type: 'text-delta',
id: `smartquotes-flush-${Date.now()}`,
text: remaining,
});
}
},
});
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
smartQuoteTransformreturnedStreamTextTransform<ToolSet>, causing type incompatibility when used withstreamText()calls that have specific tool typesTOOLS extends ToolSet, matching the pattern used bysmoothStreamand other AI SDK transformsProblem
Previously, consumers were forced to use
as anycasts when using the transform with typed tools:Solution
The function is now generic and TypeScript properly infers tool types:
Test plan
🤖 Generated with Claude Code