MCPcopy
hub / github.com/TanStack/ai / append

Method append

packages/ai-client/src/chat-client.ts:813–843  ·  view source on GitHub ↗

* Append a message and stream the response

(message: UIMessage | ModelMessage)

Source from the content-addressed store, hash-verified

811 * Append a message and stream the response
812 */
813 async append(message: UIMessage | ModelMessage): Promise<void> {
814 this.mountDevtools()
815 // Normalize the message to ensure it has id and createdAt
816 const normalizedMessage = normalizeToUIMessage(message, generateMessageId)
817
818 // Skip system messages - they're handled via systemPrompts, not UIMessages
819 if (normalizedMessage.role === 'system') {
820 return
821 }
822
823 // Type assertion: after checking for system, we know it's user or assistant
824 const uiMessage = normalizedMessage as UIMessage
825
826 // Emit message appended event
827 this.events.messageAppended(uiMessage)
828
829 // Add to messages
830 const messages = this.processor.getMessages()
831 this.processor.setMessages([...messages, uiMessage])
832 this.devtoolsBridge.emitSnapshot()
833
834 // If stream is in progress, queue the response for after it ends
835 if (this.isLoading) {
836 this.queuePostStreamAction(async () => {
837 await this.streamResponse()
838 })
839 return
840 }
841
842 await this.streamResponse()
843 }
844
845 /**
846 * Stream a response from the LLM.

Callers

nothing calls this directly

Calls 8

mountDevtoolsMethod · 0.95
queuePostStreamActionMethod · 0.95
streamResponseMethod · 0.95
normalizeToUIMessageFunction · 0.85
messageAppendedMethod · 0.80
setMessagesMethod · 0.80
getMessagesMethod · 0.45
emitSnapshotMethod · 0.45

Tested by

no test coverage detected