appendResponseMessages()

Appends an array of ResponseMessage objects (from the AI response) to an existing array of UI messages. It reuses the existing IDs from the response messages, generates new timestamps, and merges tool-call results with the previous assistant message (if any). This is useful for maintaining a unified message history when working with AI responses in a client-side chat application.

Import

import { appendResponseMessages } from "ai"

API Signature

Parameters

messages:

Message[]

responseMessages:

ResponseMessage[]

Returns

An updated array of Message objects.

Message[]:

Array