Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-react-uikit-v7.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

{
  "component": "CometChatAIAssistantChat",
  "package": "@cometchat/chat-uikit-react",
  "import": "import { CometChatAIAssistantChat } from \"@cometchat/chat-uikit-react\";",
  "cssImport": "import \"@cometchat/chat-uikit-react/css-variables.css\";",
  "description": "AI agent chat interface with streaming responses, suggested messages, tool calling, and conversation history.",
  "cssRootClass": ".cometchat-ai-assistant-chat",
  "primaryOutput": {
    "prop": "onSendButtonClick",
    "type": "(message: CometChat.BaseMessage) => void"
  },
  "props": {
    "data": {
      "user": {
        "type": "CometChat.User",
        "default": "REQUIRED",
        "note": "The AI assistant user entity"
      },
      "streamingSpeed": {
        "type": "number",
        "default": 30,
        "note": "Milliseconds between text chunks during streaming"
      },
      "aiAssistantTools": {
        "type": "CometChatAIAssistantTools",
        "default": "undefined",
        "note": "Tool handlers for AI function calls"
      },
      "loadLastAgentConversation": {
        "type": "boolean",
        "default": false
      },
      "suggestedMessages": {
        "type": "string[]",
        "default": "[] (falls back to user metadata)"
      },
      "parentMessageId": {
        "type": "number",
        "default": "undefined",
        "note": "Load a specific conversation thread"
      }
    },
    "callbacks": {
      "onSendButtonClick": "(message: CometChat.BaseMessage) => void",
      "onBackButtonClicked": "() => void",
      "onCloseButtonClicked": "() => void",
      "onError": "((error: CometChat.CometChatException) => void) | null"
    },
    "visibility": {
      "hideSuggestedMessages": { "type": "boolean", "default": false },
      "hideChatHistory": { "type": "boolean", "default": false },
      "hideNewChat": { "type": "boolean", "default": false },
      "showBackButton": { "type": "boolean", "default": false },
      "showCloseButton": { "type": "boolean", "default": false }
    },
    "viewSlots": {
      "emptyChatImageView": "ReactNode",
      "emptyChatGreetingView": "ReactNode",
      "emptyChatIntroMessageView": "ReactNode",
      "emptyView": "ReactNode",
      "loadingView": "ReactNode",
      "errorView": "ReactNode",
      "headerItemView": "ReactNode",
      "headerTitleView": "ReactNode",
      "headerSubtitleView": "ReactNode",
      "headerLeadingView": "ReactNode",
      "headerTrailingView": "ReactNode",
      "headerAuxiliaryButtonView": "ReactNode"
    }
  },
  "events": [
    {
      "name": "ui:compose/text",
      "payload": "{ text }",
      "description": "Suggestion pill clicked (sets text in composer)"
    }
  ],
  "sdkListeners": [],
  "types": {
    "CometChatAIAssistantTools": "Class — maps tool function names to handler functions via constructor(actions: Record<string, (args: Record<string, unknown>) => void>)"
  }
}

Overview

CometChatAIAssistantChat is an AI agent chat interface. It renders a full chat experience with streaming responses, suggested message pills, tool calling support, and a conversation history sidebar. Pass a CometChat.User representing the AI assistant and the component handles the rest — message threading, streaming display, and composer integration.
Live Preview — interact with the default AI assistant chat.Open in Storybook ↗
The component handles:
  • Streaming AI responses with configurable speed
  • Suggested message pills (from props or user metadata)
  • Tool calling via aiAssistantTools
  • Conversation history sidebar
  • New chat creation
  • Custom header views

Usage

Flat API

import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

function AIChat({ aiUser }: { aiUser: CometChat.User }) {
  return (
    <CometChatAIAssistantChat
      user={aiUser}
      onSendButtonClick={(message) => {
        console.log("Message sent:", message);
      }}
    />
  );
}

With Tool Calling

import {
  CometChatAIAssistantChat,
  CometChatAIAssistantTools,
} from "@cometchat/chat-uikit-react";

function AIChat({ aiUser }: { aiUser: CometChat.User }) {
  const tools = new CometChatAIAssistantTools({
    getWeather: (args) => {
      console.log("Getting weather for:", args.location);
    },
    searchDocs: (args) => {
      console.log("Searching docs for:", args.query);
    },
  });

  return (
    <CometChatAIAssistantChat
      user={aiUser}
      aiAssistantTools={tools}
      suggestedMessages={["What's the weather?", "Search documentation"]}
    />
  );
}

With Custom Header

import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

function AIChat({ aiUser }: { aiUser: CometChat.User }) {
  return (
    <CometChatAIAssistantChat
      user={aiUser}
      showBackButton
      onBackButtonClicked={() => navigateBack()}
      headerTitleView={<span>My AI Assistant</span>}
      headerSubtitleView={<span>Always online</span>}
    />
  );
}

Full Layout Example

import { useState, useEffect } from "react";
import { CometChat } from "@cometchat/chat-sdk-javascript";
import { CometChatAIAssistantChat } from "@cometchat/chat-uikit-react";

function App() {
  const [aiUser, setAiUser] = useState<CometChat.User | null>(null);

  useEffect(() => {
    CometChat.getUser("ai-assistant-uid").then(setAiUser);
  }, []);

  if (!aiUser) return <div>Loading...</div>;

  return (
    <div style={{ height: "100vh" }}>
      <CometChatAIAssistantChat
        user={aiUser}
        loadLastAgentConversation
        suggestedMessages={[
          "How do I get started?",
          "What features are available?",
          "Help me with integration",
        ]}
        onSendButtonClick={(message) => {
          console.log("User sent:", message);
        }}
        onError={(error) => {
          console.error("AI Chat error:", error);
        }}
      />
    </div>
  );
}

Actions and Events

Callback Props

PropSignatureFires when
onSendButtonClick(message: CometChat.BaseMessage) => voidUser sends a message
onBackButtonClicked() => voidBack button is clicked
onCloseButtonClicked() => voidClose button is clicked
onError((error: CometChat.CometChatException) => void) | nullSDK error occurs

Events Emitted

UI events this component publishes:
EventPayloadFires when
ui:compose/text{ text }Suggestion pill clicked (sets text in composer)

Events Received

None.

SDK Listeners (Automatic)

None directly — the component uses CometChatMessageList internally which handles SDK listeners for message updates. The AI streaming is handled via CometChat.addAIAssistantListener.

Customization

View Props

Use view props to replace sections of the default UI while keeping the component’s behavior intact:
<CometChatAIAssistantChat
  user={aiUser}
  emptyChatImageView={<MyBotAvatar />}
  emptyChatGreetingView={<h2>Hello! I'm your assistant.</h2>}
  emptyChatIntroMessageView={<p>Ask me anything about our product.</p>}
  headerItemView={<MyCustomHeader />}
  loadingView={<AILoadingSkeleton />}
  errorView={<AIErrorState />}
/>
SlotSignatureReplaces
emptyChatImageViewReactNodeAI avatar/icon in empty state
emptyChatGreetingViewReactNodeGreeting message in empty state
emptyChatIntroMessageViewReactNodeIntro message in empty state
emptyViewReactNodeEntire empty state (replaces default greeting)
loadingViewReactNodeLoading shimmer
errorViewReactNodeError state
headerItemViewReactNodeEntire header (replaces default)
headerTitleViewReactNodeHeader title
headerSubtitleViewReactNodeHeader subtitle
headerLeadingViewReactNodeHeader avatar area
headerTrailingViewReactNodeHeader trailing section
headerAuxiliaryButtonViewReactNodeHeader auxiliary buttons (New Chat + History)

CSS Styling

Override design tokens on the component selector:
.cometchat-ai-assistant-chat {
  --cometchat-background-color-01: #1a1a2e;
  --cometchat-text-color-primary: #ffffff;
}

.cometchat-ai-assistant-chat__empty-state-greeting-message {
  font-size: 1.5rem;
  font-weight: 600;
}

Props

user is required. All other props are optional.

user

The AI assistant user entity. This is the CometChat user that represents the AI agent.
TypeCometChat.User
DefaultREQUIRED

streamingSpeed

Milliseconds between text chunks during streaming display.
Typenumber
Default30

aiAssistantTools

Tool handlers for AI function calls. Maps tool names to handler functions.
TypeCometChatAIAssistantTools
Defaultundefined
const tools = new CometChatAIAssistantTools({
  getWeather: (args) => fetchWeather(args.location as string),
  searchDocs: (args) => searchDocumentation(args.query as string),
});

<CometChatAIAssistantChat user={aiUser} aiAssistantTools={tools} />

loadLastAgentConversation

Auto-load the most recent conversation with the AI assistant on mount.
Typeboolean
Defaultfalse

hideSuggestedMessages

Hide the suggestion pills in the empty chat state.
Typeboolean
Defaultfalse

suggestedMessages

Custom suggestion texts displayed as pills in the empty state. Overrides suggestions from user metadata.
Typestring[]
Default[] (falls back to user metadata suggestedMessages)

emptyChatImageView

Custom image/icon view for the empty chat state.
TypeReactNode
DefaultBuilt-in AI avatar

emptyChatGreetingView

Custom greeting message view for the empty chat state.
TypeReactNode
DefaultUser’s greetingMessage metadata or display name

emptyChatIntroMessageView

Custom intro message view for the empty chat state.
TypeReactNode
DefaultUser’s introductoryMessage metadata or “I am here to assist you!“

hideChatHistory

Hide the chat history sidebar button in the header.
Typeboolean
Defaultfalse

hideNewChat

Hide the “New Chat” button in the header.
Typeboolean
Defaultfalse

showBackButton

Show the back button in the header.
Typeboolean
Defaultfalse

showCloseButton

Show the close button in the header.
Typeboolean
Defaultfalse

onBackButtonClicked

Callback when the back button is clicked.
Type() => void
Defaultundefined

onCloseButtonClicked

Callback when the close button is clicked.
Type() => void
Defaultundefined

onSendButtonClick

Callback when a message is sent to the AI assistant.
Type(message: CometChat.BaseMessage) => void
Defaultundefined

emptyView

Custom empty state view. Replaces the entire default greeting (image + greeting + intro + suggestions).
TypeReactNode
DefaultBuilt-in greeting with suggestions

loadingView

Custom loading view.
TypeReactNode
DefaultBuilt-in loading state

errorView

Custom error view.
TypeReactNode
DefaultBuilt-in error state

onError

Callback when an SDK error occurs.
Type((error: CometChat.CometChatException) => void) | null
Defaultnull

className

Additional CSS class name applied to the root element.
Typestring
Defaultundefined

parentMessageId

Load a specific conversation thread by parent message ID.
Typenumber
Defaultundefined

headerItemView

Custom view that replaces the entire header.
TypeReactNode
DefaultBuilt-in CometChatMessageHeader

headerTitleView

Custom title view for the header.
TypeReactNode
DefaultAI user’s display name

headerSubtitleView

Custom subtitle view for the header.
TypeReactNode
DefaultBuilt-in subtitle

headerLeadingView

Custom leading view (avatar area) for the header.
TypeReactNode
DefaultAI user’s avatar

headerTrailingView

Custom trailing view for the header.
TypeReactNode
Defaultundefined

headerAuxiliaryButtonView

Custom auxiliary button view for the header. Replaces the default New Chat + History buttons.
TypeReactNode
DefaultBuilt-in New Chat + History buttons

CSS Selectors

TargetSelector
Root container.cometchat-ai-assistant-chat
Header.cometchat-ai-assistant-chat__header
Body.cometchat-ai-assistant-chat__body
Empty state.cometchat-ai-assistant-chat__empty-state
Empty state icon.cometchat-ai-assistant-chat__empty-state-icon
Greeting message.cometchat-ai-assistant-chat__empty-state-greeting-message
Intro message.cometchat-ai-assistant-chat__empty-state-intro-message
Suggested messages.cometchat-ai-assistant-chat__empty-state-suggested-messages

Next Steps

Message List

Display messages in a conversation

Message Composer

Compose and send messages

Theming

Customize colors, fonts, and spacing