Skip to content

Stabilized message.id during streamText call with multiple steps #6267

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

crazyjncsu
Copy link

@crazyjncsu crazyjncsu commented May 10, 2025

Background

When dealing with chat message persistence, it is certainly helpful if the server and client have similar representations of a message, most importantly the key/identifier/id being the same. The id of a message is a bit of a difficult concept due to the message being an aggregation of activities from an AI model and tool executions where each component has an id.

In vercel ai, the server message id comes from the first step part, but the client message id comes from the last step part. The messages on the client get their ids in processChatResponse, on the server in appendResponseMessages. The server chooses the id from the first message part. The client seems to attempt to do this, but fails because the logic doesn't fail to prevent the id from being overridden.

#4845

Summary

I fixed the client processChatResponse to keep the message id from the first step part even as more step parts come in.

Verification

I tested with a variety of ai multi-step responses.

Tasks

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • Formatting issues have been fixed (run pnpm prettier-fix in the project root)

Future Work

Related Issues

@borisghidaglia
Copy link

Related to #5318.
cc @lgrammel

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