-
Notifications
You must be signed in to change notification settings - Fork 514
Add 'data' type to ThreadMessageLike #1601
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
base: main
Are you sure you want to change the base?
Add 'data' type to ThreadMessageLike #1601
Conversation
@brandonbevans is attempting to deploy a commit to the assistant-ui Team on Vercel. A member of the Team first needs to authorize it. |
export type ThreadMessageLike = { | ||
readonly role: "assistant" | "user" | "system"; | ||
readonly role: "assistant" | "user" | "system" | "data"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default
case in fromThreadMessageLike
does not handle the new data
role, causing runtime errors when processing data messages
📝 Committable Code Suggestion
‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.
export type ThreadMessageLike = { | |
readonly role: "assistant" | "user" | "system"; | |
readonly role: "assistant" | "user" | "system" | "data"; | |
export type ThreadMessageLike = { | |
readonly role: "assistant" | "user" | "system" | "data"; |
📝 Documentation updates detected! You can review documentation updates here |
@@ -22,7 +22,7 @@ import { | |||
import { parsePartialJson } from "../../utils/json/parse-partial-json"; | |||
|
|||
export type ThreadMessageLike = { | |||
readonly role: "assistant" | "user" | "system"; | |||
readonly role: "assistant" | "user" | "system" | "data"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'data' role is added to the type but not handled in the switch statement of fromThreadMessageLike function, which will cause the 'unsupportedRole' error case to be triggered.
|
||
export type MessageRole = "user" | "assistant" | "system"; | ||
export type MessageRole = "user" | "assistant" | "system" | "data"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'data' role is added to MessageRole but there's no corresponding message type definition (like ThreadDataMessage) or handling in ThreadMessage union type, creating type inconsistency.
@@ -22,7 +22,7 @@ import { | |||
import { parsePartialJson } from "../../utils/json/parse-partial-json"; | |||
|
|||
export type ThreadMessageLike = { | |||
readonly role: "assistant" | "user" | "system"; | |||
readonly role: "assistant" | "user" | "system" | "data"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding 'data' to ThreadMessageLike is not enough; the conversion function (fromThreadMessageLike) doesn’t handle role 'data', causing the default case to throw an error. Consider adding a case for 'data' or handling it appropriately.
Pull request summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
Added 'data' role to ThreadMessageLike and MessageRole types to support Vercel AI SDK compatibility, though implementation is incomplete.
- Missing implementation for 'data' role handling in
fromThreadMessageLike
function in/packages/react/src/runtimes/external-store/ThreadMessageLike.tsx
- Need corresponding
ThreadDataMessage
type definition in/packages/react/src/types/AssistantTypes.ts
CoreMessage
andThreadMessage
unions need to be updated to include the new 'data' role type- Type inconsistency between
MessageRole
and message handling implementations could cause runtime errors
💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!
2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile
WalkthroughThe changes extend the available message roles by adding a new role, Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 ESLint
packages/react/src/runtimes/external-store/ThreadMessageLike.tsxOops! Something went wrong! :( ESLint: 9.20.0 ESLint couldn't find an eslint.config.(js|mjs|cjs) file. From ESLint v9.0.0, the default configuration file is now eslint.config.js. https://eslint.org/docs/latest/use/configure/migration-guide If you still have problems after following the migration guide, please stop by packages/react/src/types/AssistantTypes.tsOops! Something went wrong! :( ESLint: 9.20.0 ESLint couldn't find an eslint.config.(js|mjs|cjs) file. From ESLint v9.0.0, the default configuration file is now eslint.config.js. https://eslint.org/docs/latest/use/configure/migration-guide If you still have problems after following the migration guide, please stop by 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🔇 Additional comments (5)
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Hey @Yonom I would love to add this change but the bots bring up a good point about not propogating this "data" content type through the code. It seems like it may be a bit beyond me. |
Hmm - ThreadMessageLike is not intended to be compatible with AI SDK's message type... it just happens to overlap enough for some cases nevertheless - especially when using useChatRuntime, I'd want to let you pass in AI SDK UI message objects to initialMessages - so the solution is probably to add a ~ Let me investigate this a bit more and get back to you |
For Vercel AI SDK compatibility with messages, ThreadMessageLike needs to be able to accept a 'data' role as well, otherweise we get a type error like the following:

Where "Message[]" is from the "ai" package
Currently for this code to work, the commented out code is required, because MessageThreadLike doesn't allow for the role: 'data' that is present in the Message type from the "ai" package