# @deepinnet/ai-robot

可嵌入的 AI 对话机器人组件，基于 Dify API，支持流式输出、多轮对话、可拖拽缩放弹窗。

## 安装

```bash
npm install @deepinnet/ai-robot
# 或
pnpm add @deepinnet/ai-robot
```

### Peer Dependencies

```bash
npm install react react-dom antd @ant-design/icons
```

## 使用

```tsx
import { AiRobot } from "@deepinnet/ai-robot";
import "@deepinnet/ai-robot/style.css";

function App() {
  return (
    <AiRobot
      serverUrl="https://your-dify-server.com"
      appCode="your-app-code"
      robotIcon="https://your-cdn.com/robot.png"
      className="my-ai-robot"
    />
  );
}
```

```css
.my-ai-robot {
  /* 覆盖悬浮入口图片或弹窗根节点样式 */
}
```

## Props

| 属性                     | 类型                  | 必填 | 默认值                       | 说明                                   |
| ------------------------ | --------------------- | ---- | ---------------------------- | -------------------------------------- |
| `serverUrl`              | `string`              | 是   | -                            | Dify API 基础地址                      |
| `appCode`                | `string`              | 是   | -                            | Dify App Code，用于 passport 鉴权      |
| `tokenStorageKey`        | `string`              | 否   | `ai_robot_token`             | Token 的 localStorage key              |
| `conversationStorageKey` | `string`              | 否   | `ai_robot_conversation_id`   | 会话 ID 的 localStorage key            |
| `robotIcon`              | `string`              | 否   | 内置图标                     | 自定义机器人图标 URL                   |
| `className`              | `string`              | 否   | -                            | 自定义样式类名，会应用到悬浮图标和弹窗 |
| `tooltipText`            | `string`              | 否   | `您好，有什么可以帮您？`     | 悬浮图标提示文案                       |
| `position`               | `{ right?, bottom? }` | 否   | `{ right: 32, bottom: 132 }` | 悬浮图标位置                           |
| `showVoiceChat`          | `boolean`             | 否   | `false`                      | 显示语音输入（Mock）                   |
| `showImageRecognition`   | `boolean`             | 否   | `false`                      | 显示图片识别（Mock）                   |
| `showPlugins`            | `boolean`             | 否   | `false`                      | 显示插件菜单（Mock）                   |
| `onError`                | `(error) => void`     | 否   | -                            | 错误回调                               |
