MCPcopy Create free account
hub / github.com/TanStack/ai / buildUserOrToolMessage

Function buildUserOrToolMessage

packages/ai/src/activities/chat/messages.ts:178–190  ·  view source on GitHub ↗

* Build a single ModelMessage for user messages (simple path). * Preserves ordering of text and multimodal content parts.

(uiMessage: UIMessage)

Source from the content-addressed store, hash-verified

176 * Preserves ordering of text and multimodal content parts.
177 */
178function buildUserOrToolMessage(uiMessage: UIMessage): ModelMessage {
179 const contentParts: Array<ContentPart> = []
180 for (const part of uiMessage.parts) {
181 if (isContentPart(part)) {
182 contentParts.push(part)
183 }
184 }
185
186 return {
187 role: uiMessage.role as 'user' | 'assistant' | 'tool',
188 content: collapseContentParts(contentParts),
189 }
190}
191
192// Accumulator for building an assistant segment (content + tool calls)
193interface AssistantSegment {

Callers 1

uiMessageToModelMessagesFunction · 0.85

Calls 3

collapseContentPartsFunction · 0.85
isContentPartFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected