Skip to content

feat(react-ai-sdk): allow passing id generator to the AISdkRuntime #2354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Velka-DEV
Copy link

@Velka-DEV Velka-DEV commented Aug 22, 2025

When sending messages, the generated IDs are not using the ID generator defined in chatHelpers from ai-sdk.

Currently, the Chat object in ai-sdk does not expose the ID generator. As a workaround, we can pass the generator directly to useAISDKRuntime.


Important

Add optional ID generator to useAISDKRuntime for custom message ID generation in react-ai-sdk.

  • Feature:
    • Add optional idGenerator parameter to AISDKRuntimeAdapter in useAISDKRuntime.tsx.
    • Pass idGenerator to toCreateMessage in useAISDKRuntime.
    • Use idGenerator in toCreateMessage.ts to generate message IDs, defaulting to generateId if not provided.

This description was created by Ellipsis for 1361839. You can customize this summary. It will automatically update as commits are pushed.

@Copilot Copilot AI review requested due to automatic review settings August 22, 2025 11:37
Copy link

changeset-bot bot commented Aug 22, 2025

⚠️ No Changeset found

Latest commit: 1361839

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@Copilot Copilot AI left a comment

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 allows passing an ID generator to the AISdkRuntime to ensure message IDs are generated consistently with the ai-sdk's ID generator configuration. Currently, messages use a default generateId() function instead of respecting any custom ID generator defined in chatHelpers.

  • Modified toCreateMessage function to accept an optional idGenerator parameter
  • Updated AISDKRuntimeAdapter type to include optional idGenerator field
  • Updated both message creation call sites in useAISDKRuntime to pass the adapter's ID generator

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/react-ai-sdk/src/ui/utils/toCreateMessage.ts Added optional idGenerator parameter and fallback logic for message ID generation
packages/react-ai-sdk/src/ui/use-chat/useAISDKRuntime.tsx Added idGenerator to adapter type and passed it to toCreateMessage calls

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

Copy link
Contributor

promptless bot commented Aug 22, 2025

📝 Documentation updates detected!

New suggestion: Document idGenerator option in useAISDKRuntime for custom message ID generation

Copy link

trag-bot bot commented Aug 22, 2025

@trag-bot didn't find any issues in the code! ✅✨

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.

1 participant