Skip to content

fix(ai-sdk): make smartQuoteTransform generic for tool type compatibility - #10

Merged
andybons merged 1 commit into
mainfrom
andybons/fix-transform-type
Jan 10, 2026
Merged

fix(ai-sdk): make smartQuoteTransform generic for tool type compatibility#10
andybons merged 1 commit into
mainfrom
andybons/fix-transform-type

Conversation

@andybons

Copy link
Copy Markdown
Owner

Summary

  • Fixed TypeScript typing issue where smartQuoteTransform returned StreamTextTransform<ToolSet>, causing type incompatibility when used with streamText() calls that have specific tool types
  • Made the function generic over TOOLS extends ToolSet, matching the pattern used by smoothStream and other AI SDK transforms
  • Added regression tests to verify type compatibility with custom tool types

Problem

Previously, consumers were forced to use as any casts when using the transform with typed tools:

streamText({
  model,
  tools: myTypedTools,
  experimental_transform: smartQuoteTransform() as any, // Required cast
});

Solution

The function is now generic and TypeScript properly infers tool types:

streamText({
  model,
  tools: myTypedTools,
  experimental_transform: smartQuoteTransform(), // No cast needed
});

Test plan

  • Existing tests pass
  • New type compatibility tests verify the fix
  • Type check passes
  • Build succeeds

🤖 Generated with Claude Code

…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.
Copilot AI review requested due to automatic review settings January 10, 2026 00:00
@vercel

vercel Bot commented Jan 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
smartquote Ready Ready Preview, Comment Jan 10, 2026 0:00am

@andybons
andybons merged commit 91a4603 into main Jan 10, 2026
9 checks passed
@andybons
andybons deleted the andybons/fix-transform-type branch January 10, 2026 00:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 smartQuoteTransform generic over the TOOLS type 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

    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.

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.

2 participants