@alicloud/appflow-chat 0.0.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README-ZH.md +188 -0
  2. package/README.md +190 -0
  3. package/dist/appflow-chat.cjs.js +1903 -0
  4. package/dist/appflow-chat.esm.js +36965 -0
  5. package/dist/types/index.d.ts +862 -0
  6. package/package.json +87 -0
  7. package/src/components/DocReferences.tsx +64 -0
  8. package/src/components/HumanVerify/CustomParamsRenderer/ArrayField.tsx +394 -0
  9. package/src/components/HumanVerify/CustomParamsRenderer/FieldRenderer.tsx +202 -0
  10. package/src/components/HumanVerify/CustomParamsRenderer/ObjectField.tsx +126 -0
  11. package/src/components/HumanVerify/CustomParamsRenderer/index.tsx +166 -0
  12. package/src/components/HumanVerify/CustomParamsRenderer/types.ts +203 -0
  13. package/src/components/HumanVerify/HistoryCard.tsx +156 -0
  14. package/src/components/HumanVerify/HumanVerify.tsx +184 -0
  15. package/src/components/HumanVerify/index.ts +11 -0
  16. package/src/components/MarkdownRenderer.tsx +195 -0
  17. package/src/components/MessageBubble.tsx +400 -0
  18. package/src/components/RichMessageBubble.tsx +283 -0
  19. package/src/components/WebSearchPanel.tsx +68 -0
  20. package/src/context/RichBubble.tsx +21 -0
  21. package/src/core/BubbleContent.tsx +75 -0
  22. package/src/core/RichBubbleContent.tsx +324 -0
  23. package/src/core/SourceContent.tsx +285 -0
  24. package/src/core/WebSearchContent.tsx +219 -0
  25. package/src/core/index.ts +16 -0
  26. package/src/hooks/usePreSignUpload.ts +36 -0
  27. package/src/index.ts +80 -0
  28. package/src/markdown/components/Chart.tsx +120 -0
  29. package/src/markdown/components/Error.tsx +39 -0
  30. package/src/markdown/components/FileDisplay.tsx +246 -0
  31. package/src/markdown/components/Loading.tsx +41 -0
  32. package/src/markdown/components/SyntaxHighlight.tsx +182 -0
  33. package/src/markdown/index.tsx +250 -0
  34. package/src/markdown/styled.ts +234 -0
  35. package/src/markdown/utils/dataProcessor.ts +89 -0
  36. package/src/services/ChatService.ts +926 -0
  37. package/src/utils/fetchEventSource.ts +65 -0
  38. package/src/utils/loadEcharts.ts +32 -0
  39. package/src/utils/loadPrism.ts +156 -0
  40. package/src/vite-env.d.ts +1 -0
package/README-ZH.md ADDED
@@ -0,0 +1,188 @@
1
+ # Appflow Chat SDK
2
+
3
+ AI 聊天机器人组件库,提供聊天服务和 UI 组件。
4
+
5
+ ## 安装
6
+
7
+ ### 基础安装
8
+
9
+ ```bash
10
+ # 阿里内部
11
+ tnpm install @ali/appflow-chat
12
+
13
+ # NPM 官方
14
+ npm install appflow-chat
15
+ ```
16
+
17
+ ### 安装 Peer Dependencies
18
+
19
+ 本 SDK 需要以下 peer dependencies,请确保你的项目中已安装:
20
+
21
+ ```bash
22
+ npm install react react-dom antd
23
+ ```
24
+
25
+ | 依赖 | 说明 |
26
+ |-----|------|
27
+ | `react` | React 核心库 |
28
+ | `react-dom` | React DOM 渲染 |
29
+ | `antd` | Ant Design UI 组件库 |
30
+
31
+ ## 快速开始
32
+
33
+ ### 1. 初始化服务
34
+
35
+ ```typescript
36
+ import { chatService } from '@ali/appflow-chat';
37
+
38
+ // 初始化
39
+ const config = await chatService.setup({
40
+ integrateId: 'your-integrate-id',
41
+ domain: 'https://your-domain.com',
42
+ access_session_token: 'optional-token'
43
+ });
44
+
45
+ console.log('欢迎语:', config.welcome);
46
+ console.log('推荐问题:', config.questions);
47
+ ```
48
+
49
+ ### 2. 发送消息
50
+
51
+ ```typescript
52
+ // 发送文本消息
53
+ chatService.chat({ text: '你好' })
54
+ .onMessage((content, done, meta) => {
55
+ console.log('AI回复:', content);
56
+ if (done) {
57
+ console.log('回复完成');
58
+ }
59
+ })
60
+ .onError((error) => {
61
+ console.error('错误:', error);
62
+ });
63
+ ```
64
+
65
+ ### 3. 使用 UI 组件
66
+
67
+ ```tsx
68
+ import { MessageBubble, RichMessageBubble } from '@ali/appflow-chat';
69
+
70
+ // 简单消息气泡
71
+ <MessageBubble
72
+ content="这是AI的回复,支持**Markdown**格式"
73
+ role="bot"
74
+ status="Success"
75
+ />
76
+
77
+ // 富文本消息气泡(支持图表、表格等)
78
+ <RichMessageBubble
79
+ content={richContent}
80
+ messageType="rich"
81
+ status="Success"
82
+ />
83
+ ```
84
+
85
+ ### 4. 使用 MarkdownView 组件
86
+
87
+ ```tsx
88
+ import { MarkdownView } from '@ali/appflow-chat';
89
+
90
+ // 渲染 Markdown 内容
91
+ <MarkdownView
92
+ content="# 标题\n\n这是一段 **Markdown** 内容,支持:\n- 代码高亮\n- 数学公式\n- 图表渲染"
93
+ waitingMessage="正在思考..."
94
+ />
95
+ ```
96
+
97
+ ### 5. 使用 Core 组件(高级定制)
98
+
99
+ ```tsx
100
+ import { BubbleContent, SourceContent } from '@ali/appflow-chat';
101
+
102
+ // 自定义消息气泡
103
+ <div className="my-bubble">
104
+ <BubbleContent content={content} status={status}>
105
+ {/* 自定义参考资料组件 */}
106
+ <SourceContent items={references} />
107
+ </BubbleContent>
108
+ </div>
109
+ ```
110
+
111
+ ## API 文档
112
+
113
+ ### ChatService
114
+
115
+ | 方法 | 说明 |
116
+ |-----|------|
117
+ | `setup(config)` | 初始化 SDK |
118
+ | `chat(message)` | 发送消息 |
119
+ | `upload(file)` | 上传文件 |
120
+ | `cancel()` | 取消当前请求 |
121
+ | `clear()` | 清除会话 |
122
+ | `getHistory(sessionId?)` | 获取历史记录 |
123
+ | `getSessions()` | 获取会话列表 |
124
+ | `sendEventCallback(data)` | 发送事件回调(用于 humanVerify 等场景) |
125
+ | `submitHumanVerify(data)` | 提交人工审核结果(sendEventCallback 的便捷封装) |
126
+
127
+ ### UI 组件
128
+
129
+ | 组件 | 说明 |
130
+ |-----|------|
131
+ | `MarkdownRenderer` | Markdown 渲染组件(带交互) |
132
+ | `MessageBubble` | 消息气泡组件 |
133
+ | `RichMessageBubble` | 富文本消息气泡组件 |
134
+ | `DocReferences` | 参考资料组件 |
135
+ | `WebSearchPanel` | 网页搜索结果面板 |
136
+ | `HumanVerify` | 人工审核表单组件 |
137
+ | `HistoryCard` | 历史审核记录卡片组件 |
138
+ | `CustomParamsRenderer` | 自定义参数渲染器组件 |
139
+
140
+ ### Markdown 组件
141
+
142
+ | 组件 | 说明 |
143
+ |-----|------|
144
+ | `MarkdownView` | Markdown 渲染核心组件,支持代码高亮、数学公式、图表等 |
145
+
146
+ ### Core 组件
147
+
148
+ | 组件 | 说明 |
149
+ |-----|------|
150
+ | `BubbleContent` | 气泡内容核心组件 |
151
+ | `RichBubbleContent` | 富文本气泡内容核心组件 |
152
+ | `SourceContent` | 参考资料核心组件 |
153
+ | `WebSearchContent` | 网页搜索核心组件 |
154
+
155
+ ## 项目结构
156
+
157
+ ```
158
+ src/
159
+ ├── index.ts # 入口文件
160
+ ├── services/
161
+ │ └── ChatService.ts # 聊天服务
162
+ ├── components/ # SDK 组件(简化接口)
163
+ │ ├── MarkdownRenderer.tsx
164
+ │ ├── MessageBubble.tsx
165
+ │ ├── RichMessageBubble.tsx
166
+ │ ├── DocReferences.tsx
167
+ │ ├── WebSearchPanel.tsx
168
+ │ └── HumanVerify/ # 人工审核组件
169
+ │ ├── HumanVerify.tsx
170
+ │ ├── HistoryCard.tsx
171
+ │ └── CustomParamsRenderer/
172
+ ├── core/ # Core 组件(纯展示)
173
+ │ ├── BubbleContent.tsx
174
+ │ ├── RichBubbleContent.tsx
175
+ │ ├── SourceContent.tsx
176
+ │ └── WebSearchContent.tsx
177
+ ├── markdown/ # Markdown 渲染
178
+ │ ├── index.tsx # MarkdownView 组件
179
+ │ └── ...
180
+ ├── hooks/
181
+ │ └── usePreSignUpload.ts
182
+ └── utils/
183
+ └── loadEcharts.ts
184
+ ```
185
+
186
+ ## License
187
+
188
+ MIT
package/README.md ADDED
@@ -0,0 +1,190 @@
1
+ # Appflow Chat SDK
2
+
3
+ AI chatbot component library providing chat services and UI components.
4
+
5
+ [中文文档](./README-ZH.md)
6
+
7
+ ## Installation
8
+
9
+ ### Basic Installation
10
+
11
+ ```bash
12
+ # Alibaba Internal
13
+ tnpm install @ali/appflow-chat
14
+
15
+ # NPM Official
16
+ npm install appflow-chat
17
+ ```
18
+
19
+ ### Install Peer Dependencies
20
+
21
+ This SDK requires the following peer dependencies. Please ensure they are installed in your project:
22
+
23
+ ```bash
24
+ npm install react react-dom antd
25
+ ```
26
+
27
+ | Dependency | Description |
28
+ |-----|------|
29
+ | `react` | React core library |
30
+ | `react-dom` | React DOM rendering |
31
+ | `antd` | Ant Design UI component library |
32
+
33
+ ## Quick Start
34
+
35
+ ### 1. Initialize Service
36
+
37
+ ```typescript
38
+ import { chatService } from '@ali/appflow-chat';
39
+
40
+ // Initialize
41
+ const config = await chatService.setup({
42
+ integrateId: 'your-integrate-id',
43
+ domain: 'https://your-domain.com',
44
+ access_session_token: 'optional-token'
45
+ });
46
+
47
+ console.log('Welcome message:', config.welcome);
48
+ console.log('Suggested questions:', config.questions);
49
+ ```
50
+
51
+ ### 2. Send Messages
52
+
53
+ ```typescript
54
+ // Send text message
55
+ chatService.chat({ text: 'Hello' })
56
+ .onMessage((content, done, meta) => {
57
+ console.log('AI response:', content);
58
+ if (done) {
59
+ console.log('Response complete');
60
+ }
61
+ })
62
+ .onError((error) => {
63
+ console.error('Error:', error);
64
+ });
65
+ ```
66
+
67
+ ### 3. Use UI Components
68
+
69
+ ```tsx
70
+ import { MessageBubble, RichMessageBubble } from '@ali/appflow-chat';
71
+
72
+ // Simple message bubble
73
+ <MessageBubble
74
+ content="This is AI response, supports **Markdown** format"
75
+ role="bot"
76
+ status="Success"
77
+ />
78
+
79
+ // Rich text message bubble (supports charts, tables, etc.)
80
+ <RichMessageBubble
81
+ content={richContent}
82
+ messageType="rich"
83
+ status="Success"
84
+ />
85
+ ```
86
+
87
+ ### 4. Use MarkdownView Component
88
+
89
+ ```tsx
90
+ import { MarkdownView } from '@ali/appflow-chat';
91
+
92
+ // Render Markdown content
93
+ <MarkdownView
94
+ content="# Title\n\nThis is **Markdown** content, supports:\n- Code highlighting\n- Math formulas\n- Chart rendering"
95
+ waitingMessage="Thinking..."
96
+ />
97
+ ```
98
+
99
+ ### 5. Use Core Components (Advanced Customization)
100
+
101
+ ```tsx
102
+ import { BubbleContent, SourceContent } from '@ali/appflow-chat';
103
+
104
+ // Custom message bubble
105
+ <div className="my-bubble">
106
+ <BubbleContent content={content} status={status}>
107
+ {/* Custom reference component */}
108
+ <SourceContent items={references} />
109
+ </BubbleContent>
110
+ </div>
111
+ ```
112
+
113
+ ## API Documentation
114
+
115
+ ### ChatService
116
+
117
+ | Method | Description |
118
+ |-----|------|
119
+ | `setup(config)` | Initialize SDK |
120
+ | `chat(message)` | Send message |
121
+ | `upload(file)` | Upload file |
122
+ | `cancel()` | Cancel current request |
123
+ | `clear()` | Clear session |
124
+ | `getHistory(sessionId?)` | Get chat history |
125
+ | `getSessions()` | Get session list |
126
+ | `sendEventCallback(data)` | Send event callback (for humanVerify, cardCallBack, etc.) |
127
+ | `submitHumanVerify(data)` | Submit human verification result (convenience wrapper for sendEventCallback) |
128
+
129
+ ### UI Components
130
+
131
+ | Component | Description |
132
+ |-----|------|
133
+ | `MarkdownRenderer` | Markdown rendering component (with interactions) |
134
+ | `MessageBubble` | Message bubble component |
135
+ | `RichMessageBubble` | Rich text message bubble component |
136
+ | `DocReferences` | Document references component |
137
+ | `WebSearchPanel` | Web search results panel |
138
+ | `HumanVerify` | Human verification form component |
139
+ | `HistoryCard` | History card component for approval records |
140
+ | `CustomParamsRenderer` | Custom parameters renderer component |
141
+
142
+ ### Markdown Components
143
+
144
+ | Component | Description |
145
+ |-----|------|
146
+ | `MarkdownView` | Core Markdown rendering component, supports code highlighting, math formulas, charts, etc. |
147
+
148
+ ### Core Components
149
+
150
+ | Component | Description |
151
+ |-----|------|
152
+ | `BubbleContent` | Core bubble content component |
153
+ | `RichBubbleContent` | Core rich text bubble content component |
154
+ | `SourceContent` | Core reference content component |
155
+ | `WebSearchContent` | Core web search content component |
156
+
157
+ ## Project Structure
158
+
159
+ ```
160
+ src/
161
+ ├── index.ts # Entry file
162
+ ├── services/
163
+ │ └── ChatService.ts # Chat service
164
+ ├── components/ # SDK components (simplified interface)
165
+ │ ├── MarkdownRenderer.tsx
166
+ │ ├── MessageBubble.tsx
167
+ │ ├── RichMessageBubble.tsx
168
+ │ ├── DocReferences.tsx
169
+ │ ├── WebSearchPanel.tsx
170
+ │ └── HumanVerify/ # Human verification components
171
+ │ ├── HumanVerify.tsx
172
+ │ ├── HistoryCard.tsx
173
+ │ └── CustomParamsRenderer/
174
+ ├── core/ # Core components (pure display)
175
+ │ ├── BubbleContent.tsx
176
+ │ ├── RichBubbleContent.tsx
177
+ │ ├── SourceContent.tsx
178
+ │ └── WebSearchContent.tsx
179
+ ├── markdown/ # Markdown rendering
180
+ │ ├── index.tsx # MarkdownView component
181
+ │ └── ...
182
+ ├── hooks/
183
+ │ └── usePreSignUpload.ts
184
+ └── utils/
185
+ └── loadEcharts.ts
186
+ ```
187
+
188
+ ## License
189
+
190
+ MIT