@eloquentai/chat-sdk

中文文档
0.36.1发布于 2026/11/12TypeScriptES Module近 30 天下载 5929

React SDK for integrating Eloquent AI's chat functionality into your applications.

原始使用文档
文档目录15 节
  1. Prerequisites
  2. Installation
  3. Quick Start
  4. React Implementation
  5. Vanilla Implementation
  6. Features
  7. Configuration
  8. Chat component props
  9. Chat interface options
  10. Theming
  11. Advanced usage
  12. renderChat
  13. ChatInterface
  14. useRealtimeSocket
  15. Support

@eloquentai/chat-sdk

React SDK for integrating Eloquent AI's chat functionality into your applications.

Prerequisites

  • React 18 or higher (only for the React implementation)
  • Node.js 18 or higher
  • A modern browser that supports ES6+

Installation

# Using npm
npm install @eloquentai/chat-sdk

# Using yarn
yarn add @eloquentai/chat-sdk

# Using pnpm
pnpm add @eloquentai/chat-sdk

Quick Start

React Implementation

To use the SDK in a React application, import the Chat component from the SDK.

import { Chat } from "@eloquentai/chat-sdk";

function App() {
  return (
    <Chat
      // REQUIRED - Your Eloquent AI app ID
      appId="YOUR_APP_ID"
      // OPTIONAL - You can provide a unique id that should be used to identify the user
      userId={crypto.randomUUID()}
    />
  );
}

Don't forget to import the base styles once, somewhere in your app:

import "@eloquentai/chat-sdk/index.css";

Vanilla Implementation

To use the SDK in a vanilla environment, include the script tag in your HTML file and call renderChat.

<script src="https://unpkg.com/@eloquentai/chat-sdk"></script>

<div id="chat-container"></div>

<script>
  EloquentChatSDK.renderChat(document.getElementById("chat-container"), {
    // REQUIRED - Your Eloquent AI app ID
    appId: "YOUR_APP_ID",
    // OPTIONAL - You can provide a unique id that should be used to identify the user
    userId: crypto.randomUUID(),
  });
</script>

renderChat returns an unmount function you can call to remove the chat widget:

<script>
  const unmount = EloquentChatSDK.renderChat(
    document.getElementById("chat-container"),
    { appId: "YOUR_APP_ID" },
  );

  // Later, to remove the widget:
  unmount();
</script>

Features

  • Floating chat widget — a launcher bubble plus chat window, rendered in an isolated iframe so host page styles never leak in or out.
  • Real-time messaging — assistant replies stream in over a WebSocket connection (AWS AppSync), with automatic reconnect and a backup polling fallback if the socket drops.
  • Conversation persistence — the active conversation is restored automatically (e.g. on page reload) via local storage.
  • User identification — supports anonymous device-based identity as well as an optional external user ID and custom user metadata.
  • Proactive/welcome messages — an optional message bubble can appear automatically to invite users to start a conversation.
  • Chat ratings — users can rate a conversation after it's closed or escalated.
  • Human handoff / escalation — the SDK recognizes when a conversation is escalated to a human agent and closes the AI chat session accordingly.
  • Theming — customize bubble colors and legal text to match your brand.
  • Mobile responsive — automatically adapts layout for mobile viewports.

Configuration

Chat component props

PropTypeRequiredDescription
appIdstringYesYour Eloquent AI application ID.
userIdstringNoA unique identifier for the user. If omitted, an anonymous device ID is used instead.
userNamestringNoA display name for the user.
userDataRecord<string, string | number | boolean>NoArbitrary metadata attached to the user/conversation (e.g. plan, account type).
themePartial<ThemeContextType>NoTheming overrides — see Theming below.
chatPropsPartial<ChatInterfaceProps>NoFine-grained UI configuration — see Chat interface options.
isMobilebooleanNoForce mobile layout instead of relying on automatic viewport detection.
closeButtonboolean (default: true)NoShow/hide the close button in the chat header.
cleanChatButtonboolean (default: true)NoShow/hide the "start new chat" button.
initialOpenboolean (default: false)NoWhether the chat window is open by default.
proactiveMessageHideDelaynumber (default: 5000)NoMilliseconds before the proactive/welcome message auto-hides.

Chat interface options

Passed via the chatProps prop.

PropTypeDescription
displayWelcomeMessagesbooleanEnable the proactive welcome message bubble.
assistantNamestringName shown for the assistant in the chat header.
assistantLogostringURL of the logo shown for the assistant.
legalTextstringLegal/disclaimer text shown in the chat window.
hasCopyButtonbooleanShow the "copy message" button on assistant messages.
collectUserFeedbackbooleanEnable thumbs up/down feedback on assistant messages.
suggestedMessagesbooleanShow suggested message chips to the user.
titlestringTitle shown in the chat header.
subtitlestringSubtitle shown in the chat header.
onMessageClick(message: MessageData) => voidCallback fired when a message is clicked.

Theming

<Chat
  appId="YOUR_APP_ID"
  theme={{
    userBubbleColor: "#6f34b7",
    legalText: "Powered by Eloquent AI",
  }}
/>
PropertyDescription
userBubbleColorBackground color of the end-user's chat bubbles.
legalTextLegal/disclaimer text rendered below the input.

Advanced usage

renderChat

Programmatically mount the chat widget into any DOM element — used internally by the vanilla/UMD build, but also available from the ES module for non-JSX setups:

import { renderChat } from "@eloquentai/chat-sdk";

const unmount = renderChat(document.getElementById("chat-container"), {
  appId: "YOUR_APP_ID",
});

ChatInterface

The chat window UI without the floating launcher bubble or iframe isolation, for embedding the chat directly into your own layout (e.g. a dedicated support page).

import { ChatInterface } from "@eloquentai/chat-sdk";

<ChatInterface
  isOpen
  closeButton={false}
  cleanChatButton
  messages={messages}
  onSendMessage={onSendMessage}
/>;

useRealtimeSocket

A lower-level hook for subscribing directly to the real-time conversation event stream, if you need custom message handling outside of the provided components.

import { useRealtimeSocket } from "@eloquentai/chat-sdk";

const { connect, disconnect, clearProcessedIds } = useRealtimeSocket({
  chatSettings,
  chatId,
  messages,
  onMessage: (response, chatId) => {
    /* handle incoming assistant message */
  },
  onCognition: (content) => {
    /* assistant is "thinking" */
  },
  onCognitionComplete: () => {},
  fetchHistory: async (chatId) => [],
});

Support

For issues, feature requests, or questions, please contact the Eloquent AI team.

版本与发布记录

@eloquentai/chat-sdk 共发布 303 个版本,首次发布于 2025/01/10;过去 12 个月发布了 152 个版本。

版本发布日期距今
0.36.1latest2026/11/121 天前
0.36.1-dev.1dev2026/11/121 天前
0.36.02026/11/103 天前
0.36.0-dev.22026/11/076 天前
0.36.0-dev.12026/11/076 天前
0.35.1-dev.22026/11/066 天前

关于 @eloquentai/chat-sdk 的常见问题

@eloquentai/chat-sdk 是什么?

React SDK for integrating Eloquent AI's chat functionality into your applications.

如何安装 @eloquentai/chat-sdk?

在项目目录运行 npm install @eloquentai/chat-sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18)、react-dom(>=18)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@eloquentai/chat-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@eloquentai/chat-sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@eloquentai/chat-sdk 可以商用吗?

@eloquentai/chat-sdk 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@eloquentai/chat-sdk 的下载量有多少?

根据 npm 官方下载统计,@eloquentai/chat-sdk 在 2026/10/14 – 2026/11/12 这 30 天内被下载 5,929 次,日均约 198 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@eloquentai/chat-sdk 还在维护吗?

最新版本 0.36.1 发布于 2026/11/12(1 天前);至今共发布 303 个版本,其中过去 12 个月发布了 152 个;首次发布于 2025/01/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。