Skip to content

Conversation

@Drew-Garratt
Copy link
Contributor

@Drew-Garratt Drew-Garratt commented Oct 22, 2025

Summary

Adds optional convertDataPart callback to convertToModelMessages for converting custom data parts (URLs, code files, etc.) into text or file parts that models can process.

Changes

  • Add convertDataPart option to convertToModelMessages function
  • Add isTextUIPart and isFileUIPart to ui-messages.ts

Testing

  • 8 new test cases covering all conversion scenarios
  • All 46 tests passing in convert-to-model-messages.test.ts

Documentation

  • Updated API reference with examples
  • Includes usage examples for URL content, code files, and selective inclusion
  • Type safety guidance included

Related Issues

Closes #9617

Add optional convertDataPart callback for converting custom data parts (URLs, code files, etc.) to text or file parts that models can process. Fully type-safe using existing UIMessage generics.
});
```

**Including Code Files as Context**
Copy link
Contributor

Choose a reason for hiding this comment

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

Love this, thanks for putting this together @Drew-Garratt 👏

Would it be worth to include an example here for toggling on custom tools that a user might turn on when sending the user message? In this way, it can be stored alongside the other user message parts inside the DB and one can easily restore this context when the user wants to edit the message later on.

@lgrammel
Copy link
Collaborator

Thanks for the PR! i like where it is headed but some details need to be changed. I'll see if I can make the changes today on this branch.

@lgrammel lgrammel self-assigned this Oct 23, 2025
@lgrammel lgrammel marked this pull request as ready for review October 23, 2025 12:22
@lgrammel
Copy link
Collaborator

Changed the generics, simplified the tests, changed return from null to undefined, exposed is* helpers again, supported assistant data parts.

lgrammel and others added 2 commits October 23, 2025 14:37
…sages.mdx

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
@lgrammel lgrammel merged commit 9b83947 into vercel:main Oct 23, 2025
17 of 18 checks passed
vercel-ai-sdk bot pushed a commit that referenced this pull request Oct 23, 2025
@vercel-ai-sdk vercel-ai-sdk bot removed the backport label Oct 23, 2025
@vercel-ai-sdk
Copy link
Contributor

vercel-ai-sdk bot commented Oct 23, 2025

⚠️ Backport to release-v5.0 created but has conflicts: #9748

lgrammel added a commit that referenced this pull request Oct 23, 2025
…ges (#9748)

This is an automated backport of #9720 to the release-v5.0 branch.

---------

Co-authored-by: Drew Foxall <drew_garratt@mckinsey.com>
Co-authored-by: Lars Grammel <lars.grammel@gmail.com>
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
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.

Support for Custom Context Attachments in UserMessage

3 participants