Docs
CodeRabbit
Cloudflare
AG Grid
SerpAPI
Netlify
Neon
WorkOS
Clerk
Convex
Electric
PowerSync
Sentry
Railway
Prisma
Strapi
Unkey
CodeRabbit
Cloudflare
AG Grid
SerpAPI
Netlify
Neon
WorkOS
Clerk
Convex
Electric
PowerSync
Sentry
Railway
Prisma
Strapi
Unkey
Class References
Function References
Interface References
Type Alias References
Variable References
Function References

uiMessageToModelMessages

Function: uiMessageToModelMessages()

ts
function uiMessageToModelMessages(uiMessage): ModelMessage<
  | string
  | ContentPart<unknown, unknown, unknown, unknown, unknown>[]
  | null>[];

Defined in: activities/chat/messages.ts:98

Convert a UIMessage to ModelMessage(s)

Walks the parts array IN ORDER to preserve the interleaving of text, tool calls, and tool results. This is critical for multi-round tool flows where the model generates text, calls a tool, gets the result, then generates more text and calls another tool.

The output preserves the sequential structure: text1 → toolCall1 → toolResult1 → text2 → toolCall2 → toolResult2 becomes: assistant: {content: "text1", toolCalls: [toolCall1]} tool: toolResult1 assistant: {content: "text2", toolCalls: [toolCall2]} tool: toolResult2

Parameters

uiMessage

UIMessage

The UIMessage to convert

Returns

ModelMessage< | string | ContentPart<unknown, unknown, unknown, unknown, unknown>[] | null>[]

An array of ModelMessages preserving part ordering