@ai-group/chat-sdk 3.0.9 → 3.0.11
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.
- package/dist/cjs/components/FileGallery/index.js +10 -9
- package/dist/cjs/components/FileGallery/index.js.map +2 -2
- package/dist/cjs/components/FileGallery/styles.js +1 -0
- package/dist/cjs/components/FileGallery/styles.js.map +2 -2
- package/dist/cjs/components/XAdkChatbot/components/MarkdownRender/index.d.ts +3 -0
- package/dist/cjs/components/XAdkChatbot/components/MarkdownRender/index.js +74 -2
- package/dist/cjs/components/XAdkChatbot/components/MarkdownRender/index.js.map +3 -3
- package/dist/cjs/components/XAdkChatbot/index.js +10 -7
- package/dist/cjs/components/XAdkChatbot/index.js.map +2 -2
- package/dist/cjs/types/FileGallery.d.ts +2 -0
- package/dist/cjs/types/FileGallery.js.map +1 -1
- package/dist/cjs/types/XAdkChatbot.d.ts +3 -0
- package/dist/cjs/types/XAdkChatbot.js.map +1 -1
- package/dist/esm/components/FileGallery/index.js +19 -7
- package/dist/esm/components/FileGallery/index.js.map +1 -1
- package/dist/esm/components/FileGallery/styles.js +1 -1
- package/dist/esm/components/FileGallery/styles.js.map +1 -1
- package/dist/esm/components/XAdkChatbot/components/MarkdownRender/index.d.ts +3 -0
- package/dist/esm/components/XAdkChatbot/components/MarkdownRender/index.js +81 -2
- package/dist/esm/components/XAdkChatbot/components/MarkdownRender/index.js.map +1 -1
- package/dist/esm/components/XAdkChatbot/index.js +14 -8
- package/dist/esm/components/XAdkChatbot/index.js.map +1 -1
- package/dist/esm/types/FileGallery.d.ts +2 -0
- package/dist/esm/types/FileGallery.js.map +1 -1
- package/dist/esm/types/XAdkChatbot.d.ts +3 -0
- package/dist/esm/types/XAdkChatbot.js.map +1 -1
- package/dist/umd/chat-sdk.min.js +1 -1
- package/package.json +2 -3
- package/dist/cjs/components/FileGallery/FileGallery.stories.d.ts +0 -6
- package/dist/cjs/components/FileGallery/FileGallery.stories.js +0 -143
- package/dist/cjs/components/FileGallery/FileGallery.stories.js.map +0 -7
- package/dist/cjs/components/XAdkChatbot/XAdkChatbot.stories.d.ts +0 -13
- package/dist/cjs/components/XAdkChatbot/XAdkChatbot.stories.js +0 -633
- package/dist/cjs/components/XAdkChatbot/XAdkChatbot.stories.js.map +0 -7
- package/dist/cjs/components/XAdkProvider/XAdkProvider.stories.d.ts +0 -10
- package/dist/cjs/components/XAdkProvider/XAdkProvider.stories.js +0 -394
- package/dist/cjs/components/XAdkProvider/XAdkProvider.stories.js.map +0 -7
- package/dist/cjs/components/XAdkSender/XAdkSender.stories.d.ts +0 -6
- package/dist/cjs/components/XAdkSender/XAdkSender.stories.js +0 -121
- package/dist/cjs/components/XAdkSender/XAdkSender.stories.js.map +0 -7
- package/dist/cjs/components/XAiChatbot/XAiChatbot.stories.d.ts +0 -10
- package/dist/cjs/components/XAiChatbot/XAiChatbot.stories.js +0 -773
- package/dist/cjs/components/XAiChatbot/XAiChatbot.stories.js.map +0 -7
- package/dist/cjs/components/XAiConversations/XAiConversations.stories.d.ts +0 -6
- package/dist/cjs/components/XAiConversations/XAiConversations.stories.js +0 -83
- package/dist/cjs/components/XAiConversations/XAiConversations.stories.js.map +0 -7
- package/dist/cjs/components/XAiProvider/XAiProvider.stories.d.ts +0 -8
- package/dist/cjs/components/XAiProvider/XAiProvider.stories.js +0 -206
- package/dist/cjs/components/XAiProvider/XAiProvider.stories.js.map +0 -7
- package/dist/cjs/components/XAiSender/XAiSender.stories.d.ts +0 -6
- package/dist/cjs/components/XAiSender/XAiSender.stories.js +0 -102
- package/dist/cjs/components/XAiSender/XAiSender.stories.js.map +0 -7
- package/dist/cjs/components/XAiThoughtChain/XAiThoughtChain.stories.d.ts +0 -6
- package/dist/cjs/components/XAiThoughtChain/XAiThoughtChain.stories.js +0 -180
- package/dist/cjs/components/XAiThoughtChain/XAiThoughtChain.stories.js.map +0 -7
- package/dist/esm/components/FileGallery/FileGallery.stories.d.ts +0 -6
- package/dist/esm/components/FileGallery/FileGallery.stories.js +0 -48
- package/dist/esm/components/FileGallery/FileGallery.stories.js.map +0 -1
- package/dist/esm/components/XAdkChatbot/XAdkChatbot.stories.d.ts +0 -13
- package/dist/esm/components/XAdkChatbot/XAdkChatbot.stories.js +0 -510
- package/dist/esm/components/XAdkChatbot/XAdkChatbot.stories.js.map +0 -1
- package/dist/esm/components/XAdkProvider/XAdkProvider.stories.d.ts +0 -10
- package/dist/esm/components/XAdkProvider/XAdkProvider.stories.js +0 -338
- package/dist/esm/components/XAdkProvider/XAdkProvider.stories.js.map +0 -1
- package/dist/esm/components/XAdkSender/XAdkSender.stories.d.ts +0 -6
- package/dist/esm/components/XAdkSender/XAdkSender.stories.js +0 -128
- package/dist/esm/components/XAdkSender/XAdkSender.stories.js.map +0 -1
- package/dist/esm/components/XAiChatbot/XAiChatbot.stories.d.ts +0 -10
- package/dist/esm/components/XAiChatbot/XAiChatbot.stories.js +0 -636
- package/dist/esm/components/XAiChatbot/XAiChatbot.stories.js.map +0 -1
- package/dist/esm/components/XAiConversations/XAiConversations.stories.d.ts +0 -6
- package/dist/esm/components/XAiConversations/XAiConversations.stories.js +0 -42
- package/dist/esm/components/XAiConversations/XAiConversations.stories.js.map +0 -1
- package/dist/esm/components/XAiProvider/XAiProvider.stories.d.ts +0 -8
- package/dist/esm/components/XAiProvider/XAiProvider.stories.js +0 -208
- package/dist/esm/components/XAiProvider/XAiProvider.stories.js.map +0 -1
- package/dist/esm/components/XAiSender/XAiSender.stories.d.ts +0 -6
- package/dist/esm/components/XAiSender/XAiSender.stories.js +0 -87
- package/dist/esm/components/XAiSender/XAiSender.stories.js.map +0 -1
- package/dist/esm/components/XAiThoughtChain/XAiThoughtChain.stories.d.ts +0 -6
- package/dist/esm/components/XAiThoughtChain/XAiThoughtChain.stories.js +0 -159
- package/dist/esm/components/XAiThoughtChain/XAiThoughtChain.stories.js.map +0 -1
|
@@ -1,636 +0,0 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
-
import React, { useEffect, useState } from "react";
|
|
5
|
-
import { Divider } from "antd";
|
|
6
|
-
import { MessageRole, MessageStatus } from "../../types/XAiMessage";
|
|
7
|
-
import documentIcon from "../../assets/document.svg";
|
|
8
|
-
import XAiProvider from "../XAiProvider";
|
|
9
|
-
import XAiChatbot from ".";
|
|
10
|
-
import { useProviderContext, useProviderMethods } from "../../hooks/useProviderContext";
|
|
11
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
var meta = {
|
|
14
|
-
title: "AI组件/XAiChatbot 聊天框【下线】",
|
|
15
|
-
component: XAiChatbot,
|
|
16
|
-
parameters: {
|
|
17
|
-
layout: "centered"
|
|
18
|
-
},
|
|
19
|
-
tags: ["autodocs"],
|
|
20
|
-
argTypes: {
|
|
21
|
-
navbar: {
|
|
22
|
-
description: "导航栏配置"
|
|
23
|
-
},
|
|
24
|
-
messages: {
|
|
25
|
-
description: "消息列表"
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
export default meta;
|
|
30
|
-
// mock 消息数据,严格符合 Messages 类型
|
|
31
|
-
var mockMessages = [{
|
|
32
|
-
id: "1",
|
|
33
|
-
type: "TextMessage",
|
|
34
|
-
createdAt: new Date(),
|
|
35
|
-
status: MessageStatus.done,
|
|
36
|
-
role: MessageRole.assistant,
|
|
37
|
-
content: {
|
|
38
|
-
text: "你好,有什么我能帮助你的吗?"
|
|
39
|
-
}
|
|
40
|
-
}, {
|
|
41
|
-
id: "2",
|
|
42
|
-
type: "TextMessage",
|
|
43
|
-
createdAt: new Date(),
|
|
44
|
-
status: MessageStatus.done,
|
|
45
|
-
role: MessageRole.user,
|
|
46
|
-
content: {
|
|
47
|
-
text: "检索从北京到上海的车票数据给我",
|
|
48
|
-
files: [{
|
|
49
|
-
fileName: "4250105220774925bfaeb3ca2a3350fe.jpg",
|
|
50
|
-
fileId: 334,
|
|
51
|
-
fileUrl: "https://ai-platform-test.oss-cn-hangzhou.aliyuncs.com/ZABX/vbvljaaxlhlcy.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20260112T132456Z&X-Amz-SignedHeaders=host&X-Amz-Credential=LTAI5tSfMvkvWhU43Ev1cFJo%2F20260112%2Foss-cn-hangzhou%2Fs3%2Faws4_request&X-Amz-Expires=518400&X-Amz-Signature=3a8546bfdf0332a5188e9e7c47c9b8d0bb46424177c5f9be703ade8482a6e4e2",
|
|
52
|
-
fileType: "image",
|
|
53
|
-
fileSize: 28118
|
|
54
|
-
}, {
|
|
55
|
-
fileName: "4250105220774925bfaeb3ca2a3350fe.pdf",
|
|
56
|
-
fileId: 334,
|
|
57
|
-
fileUrl: "https://ai-platform-test.oss-cn-hangzhou.aliyuncs.com/ZABX/vbvljaaxlhlcy.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20260112T132456Z&X-Amz-SignedHeaders=host&X-Amz-Credential=LTAI5tSfMvkvWhU43Ev1cFJo%2F20260112%2Foss-cn-hangzhou%2Fs3%2Faws4_request&X-Amz-Expires=518400&X-Amz-Signature=3a8546bfdf0332a5188e9e7c47c9b8d0bb46424177c5f9be703ade8482a6e4e2",
|
|
58
|
-
fileType: "pdf",
|
|
59
|
-
fileSize: 28118
|
|
60
|
-
}]
|
|
61
|
-
},
|
|
62
|
-
parentMessageId: "1"
|
|
63
|
-
}, {
|
|
64
|
-
id: "22",
|
|
65
|
-
type: "TextMessage",
|
|
66
|
-
createdAt: new Date(),
|
|
67
|
-
status: MessageStatus.done,
|
|
68
|
-
role: MessageRole.assistant,
|
|
69
|
-
content: {
|
|
70
|
-
text: ""
|
|
71
|
-
},
|
|
72
|
-
thinks: "",
|
|
73
|
-
// execute: [
|
|
74
|
-
// // 工具库调用(MCP_TOOL)
|
|
75
|
-
// {
|
|
76
|
-
// type: 'ActionExecutionMessage',
|
|
77
|
-
// createdAt: new Date(),
|
|
78
|
-
// id: 'tool-1',
|
|
79
|
-
// name: '已调用MCP智能工具',
|
|
80
|
-
// arguments: { param1: 'foo' },
|
|
81
|
-
// extra: {
|
|
82
|
-
// action: 'INVOKE_AGENT_TOOL_START',
|
|
83
|
-
// icon: documentIcon,
|
|
84
|
-
// type: 'MCP_TOOL',
|
|
85
|
-
// cost: '3.9',
|
|
86
|
-
// },
|
|
87
|
-
// },
|
|
88
|
-
// // // 工具库调用(PLUGIN_TOOL)
|
|
89
|
-
// {
|
|
90
|
-
// type: 'ActionExecutionMessage',
|
|
91
|
-
// createdAt: new Date(),
|
|
92
|
-
// id: 'tool-2',
|
|
93
|
-
// name: '已调用插件工具',
|
|
94
|
-
// arguments: { param1: 'foo' },
|
|
95
|
-
// extra: {
|
|
96
|
-
// action: 'INVOKE_AGENT_TOOL_START',
|
|
97
|
-
// icon: documentIcon,
|
|
98
|
-
// type: 'MCP_TOOL',
|
|
99
|
-
// cost: '3.9',
|
|
100
|
-
// },
|
|
101
|
-
// },
|
|
102
|
-
// // // 工具库调用(SKILL)
|
|
103
|
-
// // {
|
|
104
|
-
// // action: 'INVOKE_AGENT_TOOL_START',
|
|
105
|
-
// // id: 'tool-3',
|
|
106
|
-
// // toolType: 'SKILL',
|
|
107
|
-
// // agentToolName: '技能工具',
|
|
108
|
-
// // args: { param3: 'baz' },
|
|
109
|
-
|
|
110
|
-
// // },
|
|
111
|
-
// // // 知识库调用(FAQ)
|
|
112
|
-
// // {
|
|
113
|
-
// // action: 'RECALL_KNOWLEDGE_START',
|
|
114
|
-
// // uniqueId: 'kb-1',
|
|
115
|
-
// // processStatus: 'START',
|
|
116
|
-
// // args: { question: '什么是FAQ?' },
|
|
117
|
-
// // knowledgeType: 'FAQ',
|
|
118
|
-
// // },
|
|
119
|
-
// {
|
|
120
|
-
// type: 'ActionExecutionMessage',
|
|
121
|
-
// createdAt: new Date(),
|
|
122
|
-
// id: 'tool-3',
|
|
123
|
-
// name: '已调用文档知识库',
|
|
124
|
-
// arguments: { param1: 'foo' },
|
|
125
|
-
// extra: {
|
|
126
|
-
// action: 'RECALL_KNOWLEDGE_START',
|
|
127
|
-
// icon: documentIcon,
|
|
128
|
-
// type: 'MCP_TOOL',
|
|
129
|
-
// cost: '3.9',
|
|
130
|
-
// },
|
|
131
|
-
// },
|
|
132
|
-
// // // 知识库调用(DOCUMENT)
|
|
133
|
-
// // {
|
|
134
|
-
// // action: 'RECALL_KNOWLEDGE_START',
|
|
135
|
-
// // uniqueId: 'kb-2',
|
|
136
|
-
// // processStatus: 'START',
|
|
137
|
-
// // args: { question: '文档库介绍' },
|
|
138
|
-
// // knowledgeType: 'DOCUMENT',
|
|
139
|
-
// // },
|
|
140
|
-
// // 运行完毕
|
|
141
|
-
// ],
|
|
142
|
-
extra: {
|
|
143
|
-
noFooter: true
|
|
144
|
-
}
|
|
145
|
-
}, {
|
|
146
|
-
id: "4",
|
|
147
|
-
type: "TextMessage",
|
|
148
|
-
createdAt: new Date(),
|
|
149
|
-
status: MessageStatus.done,
|
|
150
|
-
role: MessageRole.user,
|
|
151
|
-
content: {
|
|
152
|
-
text: "能否生成一段明年的产品计划开发计划文档给我"
|
|
153
|
-
}
|
|
154
|
-
}, {
|
|
155
|
-
id: "0",
|
|
156
|
-
type: "TextMessage",
|
|
157
|
-
createdAt: new Date(),
|
|
158
|
-
status: MessageStatus.done,
|
|
159
|
-
role: MessageRole.assistant,
|
|
160
|
-
content: {
|
|
161
|
-
text: "\n# \u9879\u76EE\u5F00\u53D1\u8BA1\u5212\n\n\u672C\u6587\u6863\u6982\u8FF0\u4E86 2025 \u5E74\u7B2C\u4E09\u5B63\u5EA6\u7684\u4EA7\u54C1\u5F00\u53D1\u8BA1\u5212\uFF0C\u5305\u62EC\u76EE\u6807\u3001\u91CC\u7A0B\u7891\u3001\u56E2\u961F\u5206\u5DE5\u548C\u98CE\u9669\u9884\u6848\u3002\n\n---\n\n## \uD83C\uDFAF \u6838\u5FC3\u76EE\u6807\n\n- \u63D0\u5347\u7528\u6237\u7559\u5B58\u7387\u81F3 **45%**\n- \u5B8C\u6210 Web \u7AEF\u65B0\u7248\u4E0A\u7EBF\n- \u5EFA\u7ACB AI \u63A8\u8350\u6A21\u5757 MVP\n- \u4F18\u5316\u6570\u636E\u5E93\u8BBF\u95EE\u6027\u80FD\n\n---\n\n## \uD83D\uDCC5 \u5173\u952E\u65F6\u95F4\u8282\u70B9\n\n| \u91CC\u7A0B\u7891 | \u622A\u6B62\u65E5\u671F | \u8D1F\u8D23\u4EBA | \u4EE3\u7406\u4EBA | \u622A\u6B62\u65E5\u671F | \u8D1F\u8D23\u4EBA |\n|------------------|--------------|----------|------------------|--------------|----------|\n| \u4EA7\u54C1\u9700\u6C42\u51BB\u7ED3 | 2025-08-01 | Alice | \u4EA7\u54C1\u9700\u6C42\u51BB\u7ED3 | 2025-08-01 | Alice |\n| UI \u8BBE\u8BA1\u5B9A\u7A3F | 2025-08-10 | Bob | \u4EA7\u54C1\u9700\u6C42\u51BB\u7ED3 | 2025-08-01 | Alice |\n| \u5F00\u53D1\u5B8C\u6210\uFF08\u5185\u6D4B\uFF09 | 2025-09-15 | Charlie | \u4EA7\u54C1\u9700\u6C42\u51BB\u7ED3 | 2025-08-01 | Alice |\n| \u6B63\u5F0F\u4E0A\u7EBF | 2025-09-30 | Diana | \u4EA7\u54C1\u9700\u6C42\u51BB\u7ED3 | 2025-08-01 | Alice |\n\n---\n\n## \uD83D\uDEE0\uFE0F \u6280\u672F\u65B9\u6848\u7B80\u8FF0\n\n\u6211\u4EEC\u5C06\u4F7F\u7528\u4EE5\u4E0B\u6280\u672F\u6808\uFF1A\n\n- \u524D\u7AEF\uFF1AReact + Vite + Zustand\n- \u540E\u7AEF\uFF1ANode.js + PostgreSQL\n- \u6570\u636E\u5206\u6790\uFF1APython + Pandas\n- \u90E8\u7F72\u73AF\u5883\uFF1AKubernetes on AWS\n\n---\n\n## \uD83D\uDCA1 \u793A\u4F8B\u4EE3\u7801\u7247\u6BB5\n\n\u4EE5\u4E0B\u662F\u4E00\u4E2A\u7528\u4E8E\u751F\u6210\u552F\u4E00 ID \u7684\u51FD\u6570\u793A\u4F8B\uFF1A\n\n~~~ts\nimport { nanoid } from 'nanoid'\n\nexport function generateSessionId() {\n return `sess-${nanoid()}`\n}\n~~~\n"
|
|
162
|
-
},
|
|
163
|
-
extra: {
|
|
164
|
-
noFooter: true
|
|
165
|
-
}
|
|
166
|
-
}, {
|
|
167
|
-
id: "11",
|
|
168
|
-
type: "SuggestionMessage",
|
|
169
|
-
createdAt: new Date(),
|
|
170
|
-
status: MessageStatus.done,
|
|
171
|
-
role: MessageRole.suggestion,
|
|
172
|
-
content: [{
|
|
173
|
-
key: "1",
|
|
174
|
-
description: "我要查看 AI 文档"
|
|
175
|
-
}, {
|
|
176
|
-
key: "2",
|
|
177
|
-
description: "我如何看待 AI"
|
|
178
|
-
}, {
|
|
179
|
-
key: "3",
|
|
180
|
-
description: "你是谁?"
|
|
181
|
-
}]
|
|
182
|
-
}];
|
|
183
|
-
|
|
184
|
-
// 基础用法
|
|
185
|
-
var BasicUsageStory = function BasicUsageStory(args) {
|
|
186
|
-
var _useState = useState(mockMessages),
|
|
187
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
188
|
-
messages = _useState2[0],
|
|
189
|
-
setMessages = _useState2[1];
|
|
190
|
-
var _useState3 = useState(false),
|
|
191
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
192
|
-
loading = _useState4[0],
|
|
193
|
-
setLoading = _useState4[1];
|
|
194
|
-
|
|
195
|
-
// 模拟随机字符串流式返回
|
|
196
|
-
var handleSendMessage = function handleSendMessage() {
|
|
197
|
-
setLoading(true);
|
|
198
|
-
|
|
199
|
-
// 模拟流式输出(向 mockMessages 第二条消息 content.text 追加)
|
|
200
|
-
var stream = ["我", "正在", "为", "你", "生成", "内容", "我", "正在", "为", "你", "生成", "内容", "我", "正在", "为", "你", "生成", "内容", "我", "正在", "为", "你", "生成", "内容", "我", "正在", "为", "你", "生成", "内容", "我", "正在", "为", "你", "生成", "内容", "我", "正在", "为", "你", "生成", "内容", "我", "正在", "为", "你", "生成", "内容", "我", "正在", "为", "你", "生成", "内容", "我", "正在", "为", "你", "生成", "内容", "我", "正在", "为", "你", "生成", "内容", "好", "多", "好", "多", "好", "多", "好", "多", "好", "多", "好", "多", "好", "多", "好", "多", "好", "多", "好", "多", "好", "多", "……"];
|
|
201
|
-
stream.forEach(function (chunk, idx) {
|
|
202
|
-
setTimeout(function () {
|
|
203
|
-
setMessages(function (prev) {
|
|
204
|
-
var updated = _toConsumableArray(prev);
|
|
205
|
-
var targetIndex = 2; // mockMessages 的第二条(索引 1)
|
|
206
|
-
var targetMsg = updated[targetIndex];
|
|
207
|
-
|
|
208
|
-
// 确保该消息存在且是 TextMessage
|
|
209
|
-
if (targetMsg && targetMsg.type === "TextMessage") {
|
|
210
|
-
// content 可能是多种类型,这里做类型守卫
|
|
211
|
-
if ("text" in targetMsg.content) {
|
|
212
|
-
updated[targetIndex] = _objectSpread(_objectSpread({}, targetMsg), {}, {
|
|
213
|
-
content: _objectSpread({}, targetMsg.content),
|
|
214
|
-
thinks: targetMsg.thinks + chunk + Math.random().toString(36).slice(2, 5),
|
|
215
|
-
status: MessageStatus.pending
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// 最后一个流块时,标记完成
|
|
221
|
-
if (idx === stream.length - 1) {
|
|
222
|
-
var _updated$targetIndex$;
|
|
223
|
-
(_updated$targetIndex$ = updated[targetIndex].execute) === null || _updated$targetIndex$ === void 0 || _updated$targetIndex$.push({
|
|
224
|
-
id: "5",
|
|
225
|
-
type: "ActionExecutionMessage",
|
|
226
|
-
extra: {
|
|
227
|
-
icon: documentIcon
|
|
228
|
-
},
|
|
229
|
-
name: "运行完毕",
|
|
230
|
-
createdAt: new Date()
|
|
231
|
-
});
|
|
232
|
-
setLoading(false);
|
|
233
|
-
updated[targetIndex] = _objectSpread(_objectSpread({}, updated[targetIndex]), {}, {
|
|
234
|
-
status: MessageStatus.done
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
return updated;
|
|
238
|
-
});
|
|
239
|
-
}, 200 * (idx + 1)); // 每个片段延迟 600ms 模拟流
|
|
240
|
-
});
|
|
241
|
-
};
|
|
242
|
-
useEffect(function () {
|
|
243
|
-
if (messages) {
|
|
244
|
-
handleSendMessage();
|
|
245
|
-
}
|
|
246
|
-
}, []);
|
|
247
|
-
|
|
248
|
-
// 清空消息
|
|
249
|
-
var handleClear = function handleClear() {
|
|
250
|
-
setMessages([]);
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
// 模拟按钮回调
|
|
254
|
-
var handleActions = function handleActions(index, data) {
|
|
255
|
-
console.log(index, data);
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
// 模拟快捷短语点击
|
|
259
|
-
var handleSuggestMessageClick = function handleSuggestMessageClick(_item, id) {
|
|
260
|
-
setMessages(function (prev) {
|
|
261
|
-
return prev.filter(function (m) {
|
|
262
|
-
return m.id !== id;
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
// tooltip
|
|
268
|
-
var ToolTip = function ToolTip(data) {
|
|
269
|
-
var _ref = (data === null || data === void 0 ? void 0 : data.extra) || {},
|
|
270
|
-
cost = _ref.cost,
|
|
271
|
-
token = _ref.token;
|
|
272
|
-
if (!cost && !token) return null;
|
|
273
|
-
return /*#__PURE__*/_jsxs("div", {
|
|
274
|
-
style: {
|
|
275
|
-
display: "flex",
|
|
276
|
-
alignItems: "center",
|
|
277
|
-
fontSize: "12px",
|
|
278
|
-
color: "#949494",
|
|
279
|
-
flex: 1,
|
|
280
|
-
paddingRight: "40px"
|
|
281
|
-
},
|
|
282
|
-
children: [cost && /*#__PURE__*/_jsxs("div", {
|
|
283
|
-
children: [cost, "s"]
|
|
284
|
-
}), token && /*#__PURE__*/_jsx(Divider, {
|
|
285
|
-
type: "vertical"
|
|
286
|
-
}), token && /*#__PURE__*/_jsxs("div", {
|
|
287
|
-
children: [token, " tokens"]
|
|
288
|
-
})]
|
|
289
|
-
});
|
|
290
|
-
};
|
|
291
|
-
return /*#__PURE__*/_jsx("div", {
|
|
292
|
-
style: {
|
|
293
|
-
height: "600px",
|
|
294
|
-
width: "400px",
|
|
295
|
-
border: "1px solid #e7e7e7",
|
|
296
|
-
borderRadius: "8px"
|
|
297
|
-
},
|
|
298
|
-
children: /*#__PURE__*/_jsx(XAiChatbot, _objectSpread(_objectSpread({}, args), {}, {
|
|
299
|
-
messages: messages,
|
|
300
|
-
loading: loading,
|
|
301
|
-
messageTooltip: ToolTip,
|
|
302
|
-
onClear: handleClear,
|
|
303
|
-
onSuggestMessageClick: handleSuggestMessageClick,
|
|
304
|
-
onSend: handleSendMessage,
|
|
305
|
-
onMessagesActionsCallback: handleActions,
|
|
306
|
-
enableUpload: true,
|
|
307
|
-
uploadRequest: function uploadRequest(_ref2) {
|
|
308
|
-
var file = _ref2.file,
|
|
309
|
-
onProgress = _ref2.onProgress,
|
|
310
|
-
onSuccess = _ref2.onSuccess;
|
|
311
|
-
onProgress === null || onProgress === void 0 || onProgress({
|
|
312
|
-
percent: 50
|
|
313
|
-
});
|
|
314
|
-
setTimeout(function () {
|
|
315
|
-
onSuccess === null || onSuccess === void 0 || onSuccess({
|
|
316
|
-
fileName: "4250105220774925bfaeb3ca2a3350fe.jpg",
|
|
317
|
-
fileId: 334,
|
|
318
|
-
fileUrl: "https://ai-platform-test.oss-cn-hangzhou.aliyuncs.com/ZABX/vbvljaaxlhlcy.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20260112T132456Z&X-Amz-SignedHeaders=host&X-Amz-Credential=LTAI5tSfMvkvWhU43Ev1cFJo%2F20260112%2Foss-cn-hangzhou%2Fs3%2Faws4_request&X-Amz-Expires=518400&X-Amz-Signature=3a8546bfdf0332a5188e9e7c47c9b8d0bb46424177c5f9be703ade8482a6e4e2",
|
|
319
|
-
fileType: "image",
|
|
320
|
-
fileSize: 28118,
|
|
321
|
-
mimeType: "image/jpeg",
|
|
322
|
-
tempUrl: "https://ai-platform-test.oss-cn-hangzhou.aliyuncs.com/ZABX/vbvljaaxlhlcy.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20260112T132456Z&X-Amz-SignedHeaders=host&X-Amz-Credential=LTAI5tSfMvkvWhU43Ev1cFJo%2F20260112%2Foss-cn-hangzhou%2Fs3%2Faws4_request&X-Amz-Expires=518400&X-Amz-Signature=3a8546bfdf0332a5188e9e7c47c9b8d0bb46424177c5f9be703ade8482a6e4e2",
|
|
323
|
-
type: "image"
|
|
324
|
-
});
|
|
325
|
-
}, 1000);
|
|
326
|
-
}
|
|
327
|
-
}))
|
|
328
|
-
});
|
|
329
|
-
};
|
|
330
|
-
export var 基础用法 = {
|
|
331
|
-
render: BasicUsageStory,
|
|
332
|
-
args: {
|
|
333
|
-
navbar: {
|
|
334
|
-
title: "智能助手"
|
|
335
|
-
},
|
|
336
|
-
// messages: mockMessages,
|
|
337
|
-
emptyStateText: "众安智能体"
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
// 在 Provider 中使用
|
|
342
|
-
export var 在Provider中使用 = {
|
|
343
|
-
decorators: [function (Story) {
|
|
344
|
-
return /*#__PURE__*/_jsx(XAiProvider, {
|
|
345
|
-
token: "test-token",
|
|
346
|
-
url: "https://api.example.com",
|
|
347
|
-
children: /*#__PURE__*/_jsx(Story, {})
|
|
348
|
-
});
|
|
349
|
-
}],
|
|
350
|
-
args: {
|
|
351
|
-
navbar: {
|
|
352
|
-
title: "智能助手"
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
// 多个 Provider 实例
|
|
358
|
-
export var 多个Provider实例 = {
|
|
359
|
-
decorators: [function (Story) {
|
|
360
|
-
return /*#__PURE__*/_jsxs("div", {
|
|
361
|
-
style: {
|
|
362
|
-
display: "flex",
|
|
363
|
-
gap: "50px",
|
|
364
|
-
height: "600px"
|
|
365
|
-
},
|
|
366
|
-
children: [/*#__PURE__*/_jsx(XAiProvider, {
|
|
367
|
-
providerId: "chat1",
|
|
368
|
-
token: "token1",
|
|
369
|
-
url: "https://api1.example.com",
|
|
370
|
-
children: /*#__PURE__*/_jsx("div", {
|
|
371
|
-
style: {
|
|
372
|
-
width: "300px",
|
|
373
|
-
marginRight: "40px"
|
|
374
|
-
},
|
|
375
|
-
children: /*#__PURE__*/_jsx(Story, {})
|
|
376
|
-
})
|
|
377
|
-
}), /*#__PURE__*/_jsx(XAiProvider, {
|
|
378
|
-
providerId: "chat2",
|
|
379
|
-
token: "token2",
|
|
380
|
-
url: "https://api2.example.com",
|
|
381
|
-
children: /*#__PURE__*/_jsx("div", {
|
|
382
|
-
style: {
|
|
383
|
-
width: "300px"
|
|
384
|
-
},
|
|
385
|
-
children: /*#__PURE__*/_jsx(Story, {})
|
|
386
|
-
})
|
|
387
|
-
})]
|
|
388
|
-
});
|
|
389
|
-
}],
|
|
390
|
-
args: {
|
|
391
|
-
navbar: {
|
|
392
|
-
title: "智能助手"
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
// 展示新架构的示例组件
|
|
398
|
-
var ArchitectureDemoComponent = function ArchitectureDemoComponent(_ref3) {
|
|
399
|
-
var _getProviderValue;
|
|
400
|
-
var title = _ref3.title;
|
|
401
|
-
var _useProviderContext = useProviderContext({
|
|
402
|
-
props: {
|
|
403
|
-
title: title
|
|
404
|
-
},
|
|
405
|
-
mergeLogic: function mergeLogic(props, context) {
|
|
406
|
-
var _context$messages;
|
|
407
|
-
if (!(context !== null && context !== void 0 && context.isInProvider)) {
|
|
408
|
-
return props;
|
|
409
|
-
}
|
|
410
|
-
return _objectSpread(_objectSpread({}, props), {}, {
|
|
411
|
-
messages: context.messages,
|
|
412
|
-
loading: context.loading,
|
|
413
|
-
customData: ((_context$messages = context.messages) === null || _context$messages === void 0 ? void 0 : _context$messages.length) || 0
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
}),
|
|
417
|
-
mergedProps = _useProviderContext.mergedProps,
|
|
418
|
-
isInProvider = _useProviderContext.isInProvider,
|
|
419
|
-
getProviderValue = _useProviderContext.getProviderValue;
|
|
420
|
-
var providerMethods = useProviderMethods();
|
|
421
|
-
return /*#__PURE__*/_jsxs("div", {
|
|
422
|
-
style: {
|
|
423
|
-
padding: "15px",
|
|
424
|
-
border: "1px solid #e7e7e7",
|
|
425
|
-
borderRadius: "8px",
|
|
426
|
-
marginBottom: "10px",
|
|
427
|
-
backgroundColor: "#fafafa"
|
|
428
|
-
},
|
|
429
|
-
children: [/*#__PURE__*/_jsx("h4", {
|
|
430
|
-
style: {
|
|
431
|
-
margin: "0 0 10px 0"
|
|
432
|
-
},
|
|
433
|
-
children: mergedProps.title
|
|
434
|
-
}), /*#__PURE__*/_jsxs("div", {
|
|
435
|
-
style: {
|
|
436
|
-
fontSize: "12px",
|
|
437
|
-
color: "#666"
|
|
438
|
-
},
|
|
439
|
-
children: [/*#__PURE__*/_jsxs("p", {
|
|
440
|
-
children: ["Provider \u72B6\u6001: ", isInProvider ? "✅ 已连接" : "❌ 未连接"]
|
|
441
|
-
}), /*#__PURE__*/_jsxs("p", {
|
|
442
|
-
children: ["\u6D88\u606F\u6570\u91CF: ", ((_getProviderValue = getProviderValue("messages")) === null || _getProviderValue === void 0 ? void 0 : _getProviderValue.length) || 0]
|
|
443
|
-
}), /*#__PURE__*/_jsxs("p", {
|
|
444
|
-
children: ["\u52A0\u8F7D\u72B6\u6001: ", getProviderValue("loading") ? "🔄 加载中" : "✅ 就绪"]
|
|
445
|
-
}), /*#__PURE__*/_jsx("button", {
|
|
446
|
-
onClick: function onClick() {
|
|
447
|
-
var _providerMethods$send;
|
|
448
|
-
return (_providerMethods$send = providerMethods.sendMessage) === null || _providerMethods$send === void 0 ? void 0 : _providerMethods$send.call(providerMethods, {
|
|
449
|
-
text: "来自架构演示组件的消息"
|
|
450
|
-
});
|
|
451
|
-
},
|
|
452
|
-
disabled: !isInProvider,
|
|
453
|
-
style: {
|
|
454
|
-
fontSize: "12px",
|
|
455
|
-
padding: "4px 8px",
|
|
456
|
-
backgroundColor: isInProvider ? "#1890ff" : "#d9d9d9",
|
|
457
|
-
color: "white",
|
|
458
|
-
border: "none",
|
|
459
|
-
borderRadius: "4px",
|
|
460
|
-
cursor: isInProvider ? "pointer" : "not-allowed"
|
|
461
|
-
},
|
|
462
|
-
children: isInProvider ? "发送消息" : "需要 Provider"
|
|
463
|
-
})]
|
|
464
|
-
})]
|
|
465
|
-
});
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
// 展示新架构的示例
|
|
469
|
-
export var 新架构演示 = {
|
|
470
|
-
render: function render(args) {
|
|
471
|
-
return /*#__PURE__*/_jsx("div", {
|
|
472
|
-
style: {
|
|
473
|
-
width: "500px",
|
|
474
|
-
height: "700px"
|
|
475
|
-
},
|
|
476
|
-
children: /*#__PURE__*/_jsx(XAiProvider, {
|
|
477
|
-
token: "demo-token",
|
|
478
|
-
url: "https://api.example.com",
|
|
479
|
-
providerId: "architecture-demo",
|
|
480
|
-
children: /*#__PURE__*/_jsxs("div", {
|
|
481
|
-
style: {
|
|
482
|
-
padding: "20px"
|
|
483
|
-
},
|
|
484
|
-
children: [/*#__PURE__*/_jsx("h3", {
|
|
485
|
-
style: {
|
|
486
|
-
marginBottom: "20px"
|
|
487
|
-
},
|
|
488
|
-
children: "\u65B0\u67B6\u6784\u6F14\u793A"
|
|
489
|
-
}), /*#__PURE__*/_jsx("p", {
|
|
490
|
-
style: {
|
|
491
|
-
marginBottom: "20px",
|
|
492
|
-
color: "#666"
|
|
493
|
-
},
|
|
494
|
-
children: "\u5C55\u793A\u5982\u4F55\u4F7F\u7528 useProviderContext \u548C useProviderMethods Hook"
|
|
495
|
-
}), /*#__PURE__*/_jsxs("div", {
|
|
496
|
-
style: {
|
|
497
|
-
marginBottom: "20px"
|
|
498
|
-
},
|
|
499
|
-
children: [/*#__PURE__*/_jsx(ArchitectureDemoComponent, {
|
|
500
|
-
title: "\u6F14\u793A\u7EC4\u4EF6 A"
|
|
501
|
-
}), /*#__PURE__*/_jsx(ArchitectureDemoComponent, {
|
|
502
|
-
title: "\u6F14\u793A\u7EC4\u4EF6 B"
|
|
503
|
-
}), /*#__PURE__*/_jsx(ArchitectureDemoComponent, {
|
|
504
|
-
title: "\u6F14\u793A\u7EC4\u4EF6 C"
|
|
505
|
-
})]
|
|
506
|
-
}), /*#__PURE__*/_jsx(XAiChatbot, _objectSpread(_objectSpread({}, args), {}, {
|
|
507
|
-
navbarShow: true,
|
|
508
|
-
navbar: {
|
|
509
|
-
title: "架构演示聊天机器人",
|
|
510
|
-
subtitle: "展示新 Hook 的使用"
|
|
511
|
-
},
|
|
512
|
-
enableUpload: true,
|
|
513
|
-
uploadRequest: function uploadRequest(_ref4) {
|
|
514
|
-
var file = _ref4.file,
|
|
515
|
-
onProgress = _ref4.onProgress,
|
|
516
|
-
onSuccess = _ref4.onSuccess;
|
|
517
|
-
console.info(file);
|
|
518
|
-
onProgress === null || onProgress === void 0 || onProgress({
|
|
519
|
-
percent: 50
|
|
520
|
-
});
|
|
521
|
-
setTimeout(function () {
|
|
522
|
-
onSuccess === null || onSuccess === void 0 || onSuccess({});
|
|
523
|
-
}, 1000);
|
|
524
|
-
}
|
|
525
|
-
}))]
|
|
526
|
-
})
|
|
527
|
-
})
|
|
528
|
-
});
|
|
529
|
-
},
|
|
530
|
-
args: {
|
|
531
|
-
navbar: {
|
|
532
|
-
title: "智能助手"
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
|
-
|
|
537
|
-
// 对比示例:独立使用 vs Provider 模式
|
|
538
|
-
export var 架构对比演示 = {
|
|
539
|
-
render: function render(args) {
|
|
540
|
-
return /*#__PURE__*/_jsxs("div", {
|
|
541
|
-
style: {
|
|
542
|
-
display: "flex",
|
|
543
|
-
gap: "20px",
|
|
544
|
-
padding: "20px"
|
|
545
|
-
},
|
|
546
|
-
children: [/*#__PURE__*/_jsxs("div", {
|
|
547
|
-
style: {
|
|
548
|
-
width: "300px"
|
|
549
|
-
},
|
|
550
|
-
children: [/*#__PURE__*/_jsx("h4", {
|
|
551
|
-
children: "\u72EC\u7ACB\u4F7F\u7528\u6A21\u5F0F"
|
|
552
|
-
}), /*#__PURE__*/_jsxs("div", {
|
|
553
|
-
style: {
|
|
554
|
-
border: "1px solid #e7e7e7",
|
|
555
|
-
borderRadius: "8px",
|
|
556
|
-
padding: "15px"
|
|
557
|
-
},
|
|
558
|
-
children: [/*#__PURE__*/_jsx(ArchitectureDemoComponent, {
|
|
559
|
-
title: "\u72EC\u7ACB\u7EC4\u4EF6"
|
|
560
|
-
}), /*#__PURE__*/_jsx(XAiChatbot, _objectSpread(_objectSpread({}, args), {}, {
|
|
561
|
-
navbarShow: true,
|
|
562
|
-
navbar: {
|
|
563
|
-
title: "独立聊天机器人",
|
|
564
|
-
subtitle: "不依赖 Provider"
|
|
565
|
-
},
|
|
566
|
-
onSend: function onSend(content) {
|
|
567
|
-
console.log("独立模式发送:", content);
|
|
568
|
-
},
|
|
569
|
-
onClear: function onClear() {
|
|
570
|
-
console.log("独立模式清空");
|
|
571
|
-
},
|
|
572
|
-
enableUpload: true,
|
|
573
|
-
uploadRequest: function uploadRequest(_ref5) {
|
|
574
|
-
var file = _ref5.file,
|
|
575
|
-
onProgress = _ref5.onProgress,
|
|
576
|
-
onSuccess = _ref5.onSuccess;
|
|
577
|
-
console.info(file);
|
|
578
|
-
onProgress === null || onProgress === void 0 || onProgress({
|
|
579
|
-
percent: 50
|
|
580
|
-
});
|
|
581
|
-
setTimeout(function () {
|
|
582
|
-
onSuccess === null || onSuccess === void 0 || onSuccess({});
|
|
583
|
-
}, 1000);
|
|
584
|
-
}
|
|
585
|
-
}))]
|
|
586
|
-
})]
|
|
587
|
-
}), /*#__PURE__*/_jsxs("div", {
|
|
588
|
-
style: {
|
|
589
|
-
width: "300px"
|
|
590
|
-
},
|
|
591
|
-
children: [/*#__PURE__*/_jsx("h4", {
|
|
592
|
-
children: "Provider \u6A21\u5F0F"
|
|
593
|
-
}), /*#__PURE__*/_jsx(XAiProvider, {
|
|
594
|
-
token: "demo-token",
|
|
595
|
-
url: "https://api.example.com",
|
|
596
|
-
providerId: "comparison-demo",
|
|
597
|
-
children: /*#__PURE__*/_jsxs("div", {
|
|
598
|
-
style: {
|
|
599
|
-
border: "1px solid #e7e7e7",
|
|
600
|
-
borderRadius: "8px",
|
|
601
|
-
padding: "15px"
|
|
602
|
-
},
|
|
603
|
-
children: [/*#__PURE__*/_jsx(ArchitectureDemoComponent, {
|
|
604
|
-
title: "Provider \u7EC4\u4EF6"
|
|
605
|
-
}), /*#__PURE__*/_jsx(XAiChatbot, _objectSpread(_objectSpread({}, args), {}, {
|
|
606
|
-
navbarShow: true,
|
|
607
|
-
navbar: {
|
|
608
|
-
title: "Provider 聊天机器人",
|
|
609
|
-
subtitle: "由 Provider 管理"
|
|
610
|
-
},
|
|
611
|
-
enableUpload: true,
|
|
612
|
-
uploadRequest: function uploadRequest(_ref6) {
|
|
613
|
-
var file = _ref6.file,
|
|
614
|
-
onProgress = _ref6.onProgress,
|
|
615
|
-
onSuccess = _ref6.onSuccess;
|
|
616
|
-
console.info(file);
|
|
617
|
-
onProgress === null || onProgress === void 0 || onProgress({
|
|
618
|
-
percent: 50
|
|
619
|
-
});
|
|
620
|
-
setTimeout(function () {
|
|
621
|
-
onSuccess === null || onSuccess === void 0 || onSuccess({});
|
|
622
|
-
}, 1000);
|
|
623
|
-
}
|
|
624
|
-
}))]
|
|
625
|
-
})
|
|
626
|
-
})]
|
|
627
|
-
})]
|
|
628
|
-
});
|
|
629
|
-
},
|
|
630
|
-
args: {
|
|
631
|
-
navbar: {
|
|
632
|
-
title: "智能助手"
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
};
|
|
636
|
-
//# sourceMappingURL=XAiChatbot.stories.js.map
|