MCPcopy Index your code
hub / github.com/TanStack/ai / sendMessage

Method sendMessage

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

* Send a message and stream the response. * Supports both simple string content and multimodal content (images, audio, video, documents). * * @param content - The message content. Can be: * - A simple string for text-only messages * - A MultimodalContent object with content array

(
    content: string | MultimodalContent,
    body?: Record<string, any>,
  )

Source from the content-addressed store, hash-verified

769 * ```
770 */
771 async sendMessage(
772 content: string | MultimodalContent,
773 body?: Record<string, any>,
774 ): Promise<void> {
775 this.mountDevtools()
776 const emptyMessage = typeof content === 'string' && !content.trim()
777 if (emptyMessage || this.isLoading) {
778 return
779 }
780 // Normalize input to extract content, id, and validate
781 const normalizedContent = this.normalizeMessageInput(content)
782
783 // Store the per-message body for use in streamResponse
784 this.pendingMessageBody = body
785
786 // Add user message via processor
787 const userMessage = this.processor.addUserMessage(
788 normalizedContent.content,
789 normalizedContent.id,
790 )
791 this.events.messageSent(userMessage.id, normalizedContent.content)
792
793 await this.streamResponse()
794 }
795
796 /**
797 * Normalize the message input to extract content and optional id.

Callers

nothing calls this directly

Calls 5

mountDevtoolsMethod · 0.95
normalizeMessageInputMethod · 0.95
streamResponseMethod · 0.95
addUserMessageMethod · 0.80
messageSentMethod · 0.80

Tested by

no test coverage detected