@antv/dumi-theme-antv 0.8.0-beta.0 → 0.8.0-beta.2
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/components/AI/HomeDialog/ModeSelector/index.js +4 -1
- package/dist/components/AI/HomeDialog/PromptTextarea/ChooseLib/index.js +5 -2
- package/dist/components/AI/HomeDialog/PromptTextarea/Uploader/DataUploader.js +225 -0
- package/dist/components/AI/HomeDialog/PromptTextarea/index.js +62 -24
- package/dist/components/AI/HomeDialog/PromptTextarea/index.module.less +1 -0
- package/dist/components/AI/HomeDialog/RecommendCase/Card.js +10 -3
- package/dist/components/AI/HomeDialog/RecommendCase/index.js +8 -3
- package/dist/components/AI/HomeDialog/index.js +12 -3
- package/dist/components/AI/constant.js +2 -2
- package/dist/hooks/useStreamingText.js +38 -18
- package/dist/hooks/useTypewriter.js +69 -0
- package/dist/locales/en.json +91 -1
- package/dist/locales/zh.json +91 -1
- package/dist/model/AIChat.js +20 -8
- package/dist/pages/AIPlayground/components/ConversationsMenu/index.js +29 -7
- package/dist/pages/AIPlayground/components/MarkdownComponent/MarkdownCodeBlock.js +41 -18
- package/dist/pages/AIPlayground/components/MarkdownComponent/MarkdownCodeBlock.module.less +14 -0
- package/dist/pages/AIPlayground/components/MarkdownComponent/index.js +1 -1
- package/dist/pages/AIPlayground/components/MsgBox/index.js +149 -47
- package/dist/pages/AIPlayground/components/SessionLayout/index.js +18 -10
- package/dist/pages/AIPlayground/components/SessionLayout/index.module.less +3 -0
- package/dist/pages/AIPlayground/components/TaskBox/generateCode.js +3 -4
- package/dist/pages/AIPlayground/components/TaskBox/index.js +1 -0
- package/dist/plugin/index.js +2 -2
- package/dist/slots/CodeEditor/Toolbar.js +17 -7
- package/dist/slots/CodeEditor/Toolbar.module.less +1 -0
- package/dist/slots/CodeEditor/index.js +18 -4
- package/dist/slots/CodeRunner/index.js +2 -1
- package/dist/slots/Header/Search/SearchResult.js +9 -3
- package/dist/slots/Header/index.js +24 -8
- package/dist/static/SearchAiIcon.svg +14 -0
- package/dist/utils/code.js +35 -0
- package/package.json +1 -1
|
@@ -1,21 +1,27 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
4
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
1
5
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
6
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
7
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
8
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
9
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
10
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
+
import { CheckOutlined, CopyOutlined, DislikeOutlined, LikeOutlined, PlusSquareOutlined, SyncOutlined } from '@ant-design/icons';
|
|
12
|
+
import { Bubble } from '@ant-design/x';
|
|
13
|
+
import { Button, Flex, Space, Tooltip } from 'antd';
|
|
14
|
+
import { history, useSiteData, useIntl } from 'dumi';
|
|
15
|
+
import { findLast } from 'lodash-es';
|
|
7
16
|
import React, { useEffect, useState } from 'react';
|
|
17
|
+
import { useCopyToClipboard } from 'react-use';
|
|
18
|
+
import { useSnapshot } from 'valtio';
|
|
8
19
|
import { PromptTextarea } from "../../../../components/AI/HomeDialog/PromptTextarea";
|
|
9
|
-
import { Flex, Space } from 'antd';
|
|
10
|
-
import { Bubble } from '@ant-design/x';
|
|
11
|
-
import { history } from 'dumi';
|
|
12
20
|
import { useStreamingText } from "../../../../hooks/useStreamingText";
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
15
|
-
import { useSnapshot } from 'valtio';
|
|
16
|
-
import { AIChatStore, createNewSession, derivedState } from "../../../../model/AIChat";
|
|
17
|
-
import { findLast } from "lodash-es";
|
|
21
|
+
import { AIChatStore, clearEmptySession, createPureNewSession, derivedState } from "../../../../model/AIChat";
|
|
22
|
+
import { getCodeFromMarkdown, isPreviewable } from "../../../../utils/code";
|
|
18
23
|
import { MarkdownComponent } from "../MarkdownComponent";
|
|
24
|
+
import styles from "./index.module.less";
|
|
19
25
|
var avatar = {
|
|
20
26
|
icon: /*#__PURE__*/React.createElement("img", {
|
|
21
27
|
draggable: false,
|
|
@@ -24,47 +30,78 @@ var avatar = {
|
|
|
24
30
|
}),
|
|
25
31
|
style: {
|
|
26
32
|
borderRadius: 0,
|
|
27
|
-
backgroundColor:
|
|
33
|
+
backgroundColor: 'transparent'
|
|
28
34
|
}
|
|
29
35
|
};
|
|
30
36
|
var chatScrollIntoView = function chatScrollIntoView() {
|
|
31
37
|
setTimeout(function () {
|
|
32
|
-
var nodeList = document.querySelectorAll(
|
|
38
|
+
var nodeList = document.querySelectorAll('.ant-bubble');
|
|
33
39
|
nodeList[nodeList.length - 1].scrollIntoView({
|
|
34
|
-
behavior:
|
|
35
|
-
block: "center"
|
|
40
|
+
behavior: 'smooth'
|
|
36
41
|
});
|
|
37
42
|
});
|
|
38
43
|
};
|
|
39
44
|
function MsgBox(props) {
|
|
40
|
-
var _derivedSnap$activeSe,
|
|
41
|
-
var
|
|
45
|
+
var _derivedSnap$activeSe, _derivedSnap$activeSe2, _derivedSnap$activeSe3;
|
|
46
|
+
var _props$messages = props.messages,
|
|
47
|
+
messages = _props$messages === void 0 ? [] : _props$messages,
|
|
48
|
+
_props$simple = props.simple,
|
|
49
|
+
simple = _props$simple === void 0 ? false : _props$simple,
|
|
50
|
+
_props$context = props.context,
|
|
51
|
+
context = _props$context === void 0 ? '' : _props$context,
|
|
52
|
+
onCodegen = props.onCodegen,
|
|
53
|
+
title = props.title;
|
|
54
|
+
var _useSiteData = useSiteData(),
|
|
55
|
+
themeConfig = _useSiteData.themeConfig;
|
|
56
|
+
var _useIntl = useIntl(),
|
|
57
|
+
formatMessage = _useIntl.formatMessage;
|
|
58
|
+
var _useState = useState(!themeConfig.isAntVSite ? themeConfig.title : undefined),
|
|
42
59
|
_useState2 = _slicedToArray(_useState, 2),
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var _useState3 = useState(
|
|
60
|
+
lib = _useState2[0],
|
|
61
|
+
setLib = _useState2[1];
|
|
62
|
+
var _useState3 = useState(''),
|
|
46
63
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
47
|
-
|
|
48
|
-
|
|
64
|
+
promptText = _useState4[0],
|
|
65
|
+
setPromptText = _useState4[1];
|
|
49
66
|
var _useState5 = useState(false),
|
|
50
67
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
51
|
-
|
|
52
|
-
|
|
68
|
+
isStreaming = _useState6[0],
|
|
69
|
+
setIsStreaming = _useState6[1]; // trigger
|
|
70
|
+
var _useState7 = useState(false),
|
|
71
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
72
|
+
loading = _useState8[0],
|
|
73
|
+
setLoading = _useState8[1];
|
|
53
74
|
var snap = useSnapshot(AIChatStore);
|
|
54
75
|
var derivedSnap = useSnapshot(derivedState);
|
|
76
|
+
var _useCopyToClipboard = useCopyToClipboard(),
|
|
77
|
+
_useCopyToClipboard2 = _slicedToArray(_useCopyToClipboard, 2),
|
|
78
|
+
copyState = _useCopyToClipboard2[0],
|
|
79
|
+
copyToClipboard = _useCopyToClipboard2[1];
|
|
80
|
+
var latestUserMessage = findLast((_derivedSnap$activeSe = derivedSnap.activeSession) === null || _derivedSnap$activeSe === void 0 ? void 0 : _derivedSnap$activeSe.messages, function (msg) {
|
|
81
|
+
return msg.role === 'user';
|
|
82
|
+
});
|
|
83
|
+
var _useState9 = useState(''),
|
|
84
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
85
|
+
fileSummary = _useState10[0],
|
|
86
|
+
setFileSummary = _useState10[1];
|
|
55
87
|
var streamingText = useStreamingText({
|
|
56
|
-
url: '
|
|
88
|
+
url: 'https://webgw-pre.alipay.com/visqaservice/external/chat',
|
|
57
89
|
method: 'POST',
|
|
58
90
|
body: {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
91
|
+
gptConversationId: (_derivedSnap$activeSe2 = derivedSnap.activeSession) === null || _derivedSnap$activeSe2 === void 0 ? void 0 : _derivedSnap$activeSe2.id,
|
|
92
|
+
query: latestUserMessage === null || latestUserMessage === void 0 ? void 0 : latestUserMessage.content,
|
|
93
|
+
library: (latestUserMessage === null || latestUserMessage === void 0 ? void 0 : latestUserMessage.lib) || lib,
|
|
94
|
+
mode: latestUserMessage === null || latestUserMessage === void 0 ? void 0 : latestUserMessage.mode,
|
|
95
|
+
anonymousUserId: snap.anonymousUserId,
|
|
96
|
+
context: (latestUserMessage === null || latestUserMessage === void 0 ? void 0 : latestUserMessage.context) || context,
|
|
97
|
+
mountId: "container"
|
|
63
98
|
},
|
|
64
99
|
trigger: isStreaming,
|
|
65
100
|
// 将 isStreaming 状态作为 trigger
|
|
66
101
|
headers: {
|
|
67
|
-
'Content-Type': 'application/json'
|
|
102
|
+
'Content-Type': 'application/json',
|
|
103
|
+
'x-webgw-version': '2.0',
|
|
104
|
+
'x-webgw-appid': '180020010001210065'
|
|
68
105
|
},
|
|
69
106
|
beforeStart: function beforeStart() {
|
|
70
107
|
setLoading(true);
|
|
@@ -81,6 +118,11 @@ function MsgBox(props) {
|
|
|
81
118
|
// mode,
|
|
82
119
|
// lib,
|
|
83
120
|
});
|
|
121
|
+
if (isPreviewable(finalJSON.content)) {
|
|
122
|
+
var codeBlock = getCodeFromMarkdown(finalJSON.content).code;
|
|
123
|
+
AIChatStore.codeBlock = codeBlock;
|
|
124
|
+
onCodegen === null || onCodegen === void 0 || onCodegen(codeBlock);
|
|
125
|
+
}
|
|
84
126
|
} catch (e) {
|
|
85
127
|
// 说明不是JSON格式
|
|
86
128
|
} finally {
|
|
@@ -91,34 +133,36 @@ function MsgBox(props) {
|
|
|
91
133
|
}
|
|
92
134
|
},
|
|
93
135
|
onError: function onError(error) {
|
|
136
|
+
var _derivedState$activeS2;
|
|
137
|
+
console.log('回答失败', error);
|
|
94
138
|
// 处理错误
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
139
|
+
(_derivedState$activeS2 = derivedState.activeSession) === null || _derivedState$activeS2 === void 0 || (_derivedState$activeS2 = _derivedState$activeS2.messages) === null || _derivedState$activeS2 === void 0 || _derivedState$activeS2.push({
|
|
140
|
+
id: crypto.randomUUID(),
|
|
141
|
+
role: 'assistant',
|
|
142
|
+
content: formatMessage({
|
|
143
|
+
id: 'ai.msgbox.error.response'
|
|
144
|
+
}),
|
|
145
|
+
createdAt: Date.now()
|
|
146
|
+
// mode,
|
|
147
|
+
// lib,
|
|
148
|
+
});
|
|
149
|
+
setIsStreaming(false);
|
|
150
|
+
setLoading(false);
|
|
101
151
|
}
|
|
102
152
|
});
|
|
103
153
|
|
|
104
154
|
// 3. 处理用户提交
|
|
105
155
|
var handleSubmit = function handleSubmit() {
|
|
106
|
-
var _derivedState$
|
|
107
|
-
if (props.simple) {
|
|
108
|
-
createNewSession({
|
|
109
|
-
promptText: promptText
|
|
110
|
-
});
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
156
|
+
var _derivedState$activeS3;
|
|
113
157
|
if (!promptText.trim() || isStreaming) return; // 如果正在流式输出,则不允许发送
|
|
114
158
|
setPromptText('');
|
|
115
|
-
(_derivedState$
|
|
159
|
+
(_derivedState$activeS3 = derivedState.activeSession) === null || _derivedState$activeS3 === void 0 || (_derivedState$activeS3 = _derivedState$activeS3.messages) === null || _derivedState$activeS3 === void 0 || _derivedState$activeS3.push({
|
|
116
160
|
id: crypto.randomUUID(),
|
|
117
161
|
role: 'user',
|
|
118
162
|
content: promptText,
|
|
119
|
-
createdAt: Date.now()
|
|
120
|
-
|
|
121
|
-
|
|
163
|
+
createdAt: Date.now(),
|
|
164
|
+
context: fileSummary,
|
|
165
|
+
lib: lib
|
|
122
166
|
});
|
|
123
167
|
// **关键:开启 trigger,开始请求**
|
|
124
168
|
setIsStreaming(true);
|
|
@@ -135,6 +179,12 @@ function MsgBox(props) {
|
|
|
135
179
|
AIChatStore.tempMessage = null;
|
|
136
180
|
}
|
|
137
181
|
}
|
|
182
|
+
if (simple) {
|
|
183
|
+
createPureNewSession(title);
|
|
184
|
+
}
|
|
185
|
+
return function () {
|
|
186
|
+
clearEmptySession();
|
|
187
|
+
};
|
|
138
188
|
}, []);
|
|
139
189
|
useEffect(function () {
|
|
140
190
|
if (derivedState.activeSession && Date.now() - derivedState.activeSession.createdAt > 5000) {
|
|
@@ -142,17 +192,64 @@ function MsgBox(props) {
|
|
|
142
192
|
setIsStreaming(false);
|
|
143
193
|
}
|
|
144
194
|
}, [snap.activeSessionId]);
|
|
195
|
+
var showMessages = [].concat(_toConsumableArray(messages), _toConsumableArray(((_derivedSnap$activeSe3 = derivedSnap.activeSession) === null || _derivedSnap$activeSe3 === void 0 ? void 0 : _derivedSnap$activeSe3.messages) || []));
|
|
145
196
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Flex, {
|
|
146
197
|
gap: "middle",
|
|
147
198
|
vertical: true,
|
|
148
199
|
className: styles.chatContainer
|
|
149
|
-
},
|
|
200
|
+
}, showMessages === null || showMessages === void 0 ? void 0 : showMessages.map(function (msg, index) {
|
|
150
201
|
return /*#__PURE__*/React.createElement(Bubble, {
|
|
151
202
|
key: index,
|
|
152
203
|
content: /*#__PURE__*/React.createElement(MarkdownComponent, {
|
|
153
204
|
content: msg.content
|
|
154
205
|
}),
|
|
155
206
|
avatar: msg.role === 'assistant' ? avatar : null,
|
|
207
|
+
footer: msg.role === 'assistant' && index > 0 ? /*#__PURE__*/React.createElement(Space, {
|
|
208
|
+
size: "small"
|
|
209
|
+
}, /*#__PURE__*/React.createElement(Tooltip, {
|
|
210
|
+
title: formatMessage({
|
|
211
|
+
id: 'ai.msgbox.like'
|
|
212
|
+
})
|
|
213
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
214
|
+
color: "default",
|
|
215
|
+
variant: "text",
|
|
216
|
+
size: "small",
|
|
217
|
+
icon: /*#__PURE__*/React.createElement(LikeOutlined, null)
|
|
218
|
+
})), /*#__PURE__*/React.createElement(Tooltip, {
|
|
219
|
+
title: formatMessage({
|
|
220
|
+
id: 'ai.msgbox.dislike'
|
|
221
|
+
})
|
|
222
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
223
|
+
color: "default",
|
|
224
|
+
variant: "text",
|
|
225
|
+
size: "small",
|
|
226
|
+
icon: /*#__PURE__*/React.createElement(DislikeOutlined, null)
|
|
227
|
+
})), index === showMessages.length - 1 && /*#__PURE__*/React.createElement(Tooltip, {
|
|
228
|
+
title: formatMessage({
|
|
229
|
+
id: 'ai.msgbox.retry'
|
|
230
|
+
})
|
|
231
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
232
|
+
onClick: function onClick() {
|
|
233
|
+
derivedState.activeSession.messages.pop();
|
|
234
|
+
setIsStreaming(true);
|
|
235
|
+
},
|
|
236
|
+
color: "default",
|
|
237
|
+
variant: "text",
|
|
238
|
+
size: "small",
|
|
239
|
+
icon: /*#__PURE__*/React.createElement(SyncOutlined, null)
|
|
240
|
+
})), /*#__PURE__*/React.createElement(Tooltip, {
|
|
241
|
+
title: formatMessage({
|
|
242
|
+
id: 'ai.msgbox.copy'
|
|
243
|
+
})
|
|
244
|
+
}, /*#__PURE__*/React.createElement(Button, {
|
|
245
|
+
color: "default",
|
|
246
|
+
variant: "text",
|
|
247
|
+
size: "small",
|
|
248
|
+
onClick: function onClick() {
|
|
249
|
+
return copyToClipboard(msg.content);
|
|
250
|
+
},
|
|
251
|
+
icon: copyState.value === msg.content ? /*#__PURE__*/React.createElement(CheckOutlined, null) : /*#__PURE__*/React.createElement(CopyOutlined, null)
|
|
252
|
+
}))) : null,
|
|
156
253
|
placement: msg.role === 'user' ? 'end' : 'start'
|
|
157
254
|
});
|
|
158
255
|
}), loading && /*#__PURE__*/React.createElement(Bubble, {
|
|
@@ -167,7 +264,9 @@ function MsgBox(props) {
|
|
|
167
264
|
return history.push('/');
|
|
168
265
|
},
|
|
169
266
|
className: styles.newButton
|
|
170
|
-
}, /*#__PURE__*/React.createElement(Space, null, /*#__PURE__*/React.createElement(PlusSquareOutlined, null),
|
|
267
|
+
}, /*#__PURE__*/React.createElement(Space, null, /*#__PURE__*/React.createElement(PlusSquareOutlined, null), formatMessage({
|
|
268
|
+
id: 'ai.msgbox.start.new.chat'
|
|
269
|
+
})))), /*#__PURE__*/React.createElement(PromptTextarea, {
|
|
171
270
|
size: "compact",
|
|
172
271
|
mode: "implement",
|
|
173
272
|
value: promptText,
|
|
@@ -181,7 +280,10 @@ function MsgBox(props) {
|
|
|
181
280
|
style: {
|
|
182
281
|
marginBottom: 0
|
|
183
282
|
},
|
|
184
|
-
onConfirm: handleSubmit
|
|
283
|
+
onConfirm: handleSubmit,
|
|
284
|
+
lib: lib,
|
|
285
|
+
onLibChange: setLib,
|
|
286
|
+
onDataSummaryChange: setFileSummary
|
|
185
287
|
})));
|
|
186
288
|
}
|
|
187
289
|
export default MsgBox;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
3
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
4
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
5
1
|
import React from 'react';
|
|
6
2
|
import styles from "./index.module.less";
|
|
7
3
|
import { ConversationsMenu } from "../ConversationsMenu";
|
|
8
4
|
import { AIChatStore } from "../../../../model/AIChat";
|
|
9
|
-
import { useSnapshot } from
|
|
10
|
-
import classnames from
|
|
5
|
+
import { useSnapshot } from 'valtio';
|
|
6
|
+
import classnames from 'classnames';
|
|
7
|
+
import SplitPane from 'react-split-pane';
|
|
11
8
|
function SessionLayout(props) {
|
|
12
9
|
var children = props.children;
|
|
13
10
|
var snap = useSnapshot(AIChatStore);
|
|
@@ -16,10 +13,21 @@ function SessionLayout(props) {
|
|
|
16
13
|
}
|
|
17
14
|
return /*#__PURE__*/React.createElement("div", {
|
|
18
15
|
className: styles.container
|
|
19
|
-
}, /*#__PURE__*/React.createElement(ConversationsMenu, null),
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
}, /*#__PURE__*/React.createElement(ConversationsMenu, null),
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
snap.codeBlock ? /*#__PURE__*/React.createElement(SplitPane, {
|
|
19
|
+
split: "vertical",
|
|
20
|
+
defaultSize: "50vw",
|
|
21
|
+
primary: "second",
|
|
22
|
+
style: {
|
|
23
|
+
position: "unset"
|
|
24
|
+
}
|
|
25
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
26
|
+
className: classnames(styles.msgBox)
|
|
27
|
+
}, children[0]), /*#__PURE__*/React.createElement("div", {
|
|
22
28
|
className: styles.taskBox
|
|
23
|
-
}, children[1]))
|
|
29
|
+
}, children[1])) : /*#__PURE__*/React.createElement("div", {
|
|
30
|
+
className: classnames(styles.msgBox, styles.msgBoxFull)
|
|
31
|
+
}, children[0]));
|
|
24
32
|
}
|
|
25
33
|
export { SessionLayout };
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
.msgBox {
|
|
17
|
+
height: 100%;
|
|
17
18
|
padding: 16px;
|
|
18
19
|
min-width: 400px;
|
|
19
20
|
justify-content: space-between;
|
|
@@ -28,7 +29,9 @@
|
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
.taskBox {
|
|
32
|
+
height: calc(100% - 32px);
|
|
31
33
|
margin: 16px;
|
|
34
|
+
padding: 16px;
|
|
32
35
|
flex-grow: 1;
|
|
33
36
|
background: #ffffff;
|
|
34
37
|
}
|
|
@@ -97,14 +97,13 @@ export function wrap2Sandpack() {
|
|
|
97
97
|
// if (match) {
|
|
98
98
|
return {
|
|
99
99
|
"/package.json": {
|
|
100
|
-
code: "{\n \"name\": \"AntV-AI-Code\",\n \"version\": \"1.0.0\",\n \"main\": \"/index.
|
|
100
|
+
code: "{\n \"name\": \"AntV-AI-Code\",\n \"version\": \"1.0.0\",\n \"main\": \"/index.tsx\",\n \"dependencies\": ".concat(JSON.stringify(generateDependencies(codeBlock), null, 2), "\n }")
|
|
101
101
|
},
|
|
102
|
-
"/index.
|
|
103
|
-
// 入口文件是纯 JS
|
|
102
|
+
"/index.tsx": {
|
|
104
103
|
code: codeBlock
|
|
105
104
|
},
|
|
106
105
|
"/index.html": {
|
|
107
|
-
code: "<!DOCTYPE html>\n<html>\n<head>\n <title>Vanilla JS Example</title>\n</head>\n<body>\n <div id=\"root\"></div>\n <div id=\"container\"></div>\n <script src=\"index.
|
|
106
|
+
code: "<!DOCTYPE html>\n<html>\n<head>\n <title>Vanilla JS Example</title>\n</head>\n<body>\n <div id=\"root\"></div>\n <div id=\"container\"></div>\n <script src=\"index.tsx\"></script>\n</body>\n</html>"
|
|
108
107
|
}
|
|
109
108
|
};
|
|
110
109
|
}
|
package/dist/plugin/index.js
CHANGED
|
@@ -168,8 +168,8 @@ export default function ThemeAntVContextWrapper() {
|
|
|
168
168
|
},
|
|
169
169
|
{
|
|
170
170
|
id: "dumi-theme-antv-ai-playground-lang",
|
|
171
|
-
absPath: "/:language/ai-playground
|
|
172
|
-
path: ":language/ai-playground
|
|
171
|
+
absPath: "/:language/ai-playground",
|
|
172
|
+
path: ":language/ai-playground",
|
|
173
173
|
file: `${PAGES_DIR}/AIPlayground`
|
|
174
174
|
}
|
|
175
175
|
];
|
|
@@ -10,7 +10,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
10
10
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
11
11
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
12
12
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
13
|
-
import { CodeSandboxOutlined, PlayCircleOutlined, ThunderboltOutlined } from '@ant-design/icons';
|
|
13
|
+
import { CodeSandboxOutlined, PlayCircleOutlined, ReloadOutlined, ThunderboltOutlined } from '@ant-design/icons';
|
|
14
14
|
import stackblitzSdk from '@stackblitz/sdk';
|
|
15
15
|
import { Tooltip, Typography } from 'antd';
|
|
16
16
|
import { getParameters } from 'codesandbox/lib/api/define';
|
|
@@ -43,7 +43,8 @@ export var Toolbar = function Toolbar(_ref) {
|
|
|
43
43
|
_ref$onToggleFullscre = _ref.onToggleFullscreen,
|
|
44
44
|
onToggleFullscreen = _ref$onToggleFullscre === void 0 ? null : _ref$onToggleFullscre,
|
|
45
45
|
onExecuteCode = _ref.onExecuteCode,
|
|
46
|
-
onClickAI = _ref.onClickAI
|
|
46
|
+
onClickAI = _ref.onClickAI,
|
|
47
|
+
onReload = _ref.onReload;
|
|
47
48
|
var locale = useLocale();
|
|
48
49
|
var exampleTitle = _typeof(title) === 'object' ? title[locale.id] : title;
|
|
49
50
|
|
|
@@ -82,7 +83,16 @@ export var Toolbar = function Toolbar(_ref) {
|
|
|
82
83
|
})), /*#__PURE__*/React.createElement("a", {
|
|
83
84
|
className: styles.ai,
|
|
84
85
|
onClick: onClickAI
|
|
85
|
-
},
|
|
86
|
+
}, /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
87
|
+
id: "ai.toolbar.assistant"
|
|
88
|
+
})), /*#__PURE__*/React.createElement(Tooltip, {
|
|
89
|
+
title: /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
90
|
+
id: "ai.toolbar.restore"
|
|
91
|
+
})
|
|
92
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
93
|
+
className: styles.ai,
|
|
94
|
+
onClick: onReload
|
|
95
|
+
}, /*#__PURE__*/React.createElement(ReloadOutlined, null))), riddleVisible ? /*#__PURE__*/React.createElement("form", {
|
|
86
96
|
action: "//riddle.alibaba-inc.com/riddles/define",
|
|
87
97
|
method: "POST",
|
|
88
98
|
target: "_blank"
|
|
@@ -92,7 +102,7 @@ export var Toolbar = function Toolbar(_ref) {
|
|
|
92
102
|
value: JSON.stringify(riddlePrefillConfig)
|
|
93
103
|
}), /*#__PURE__*/React.createElement(Tooltip, {
|
|
94
104
|
title: /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
95
|
-
id: "
|
|
105
|
+
id: "ai.toolbar.open.riddle"
|
|
96
106
|
})
|
|
97
107
|
}, /*#__PURE__*/React.createElement("input", {
|
|
98
108
|
type: "submit",
|
|
@@ -100,7 +110,7 @@ export var Toolbar = function Toolbar(_ref) {
|
|
|
100
110
|
className: styles.riddle
|
|
101
111
|
}))) : null, /*#__PURE__*/React.createElement(Tooltip, {
|
|
102
112
|
title: /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
103
|
-
id: "
|
|
113
|
+
id: "ai.toolbar.open.stackblitz"
|
|
104
114
|
})
|
|
105
115
|
}, /*#__PURE__*/React.createElement(ThunderboltOutlined, {
|
|
106
116
|
className: styles.stackblitz,
|
|
@@ -109,7 +119,7 @@ export var Toolbar = function Toolbar(_ref) {
|
|
|
109
119
|
}
|
|
110
120
|
})), /*#__PURE__*/React.createElement(Tooltip, {
|
|
111
121
|
title: /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
112
|
-
id: "
|
|
122
|
+
id: "ai.toolbar.open.codesandbox"
|
|
113
123
|
})
|
|
114
124
|
}, /*#__PURE__*/React.createElement("form", {
|
|
115
125
|
action: "https://codesandbox.io/api/v1/sandboxes/define",
|
|
@@ -135,7 +145,7 @@ export var Toolbar = function Toolbar(_ref) {
|
|
|
135
145
|
}
|
|
136
146
|
}), /*#__PURE__*/React.createElement(Tooltip, {
|
|
137
147
|
title: /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
138
|
-
id: "
|
|
148
|
+
id: "ai.toolbar.execute"
|
|
139
149
|
})
|
|
140
150
|
}, /*#__PURE__*/React.createElement(PlayCircleOutlined, {
|
|
141
151
|
onClick: onExecuteCode,
|
|
@@ -15,7 +15,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
15
15
|
import MonacoEditor, { loader } from '@monaco-editor/react';
|
|
16
16
|
import { Drawer, Switch } from 'antd';
|
|
17
17
|
import { autoType as d3AutoType, dsvFormat } from 'd3-dsv';
|
|
18
|
-
import { useLocale, useSiteData } from 'dumi';
|
|
18
|
+
import { useLocale, useSiteData, useIntl } from 'dumi';
|
|
19
19
|
import { debounce, noop } from 'lodash-es';
|
|
20
20
|
import { format } from 'prettier';
|
|
21
21
|
import parserBabel from 'prettier/parser-babel';
|
|
@@ -61,6 +61,7 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
61
61
|
var locale = useLocale();
|
|
62
62
|
var _useSiteData = useSiteData(),
|
|
63
63
|
themeConfig = _useSiteData.themeConfig;
|
|
64
|
+
var intl = useIntl();
|
|
64
65
|
var _themeConfig$es = themeConfig.es5,
|
|
65
66
|
es5 = _themeConfig$es === void 0 ? true : _themeConfig$es,
|
|
66
67
|
_themeConfig$showSpec = themeConfig.showSpecTab,
|
|
@@ -280,6 +281,7 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
280
281
|
// 用于更新当前 example 的 spec 和 data
|
|
281
282
|
useEffect(function () {
|
|
282
283
|
setCurrentEditorTab(EDITOR_TABS.JAVASCRIPT);
|
|
284
|
+
setShowAI(false);
|
|
283
285
|
}, [exampleId]);
|
|
284
286
|
|
|
285
287
|
// hook 用户的数据
|
|
@@ -385,6 +387,9 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
385
387
|
var onClickAI = function onClickAI() {
|
|
386
388
|
setShowAI(true);
|
|
387
389
|
};
|
|
390
|
+
var onReload = function onReload() {
|
|
391
|
+
setCode(source);
|
|
392
|
+
};
|
|
388
393
|
return /*#__PURE__*/React.createElement("div", {
|
|
389
394
|
className: styles.editor
|
|
390
395
|
}, /*#__PURE__*/React.createElement(Toolbar, {
|
|
@@ -402,6 +407,7 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
402
407
|
onEditorTabChange: onTabChange,
|
|
403
408
|
onToggleFullscreen: onFullscreen,
|
|
404
409
|
onClickAI: onClickAI,
|
|
410
|
+
onReload: onReload,
|
|
405
411
|
slots: {
|
|
406
412
|
Spec: /*#__PURE__*/React.createElement("span", {
|
|
407
413
|
style: {
|
|
@@ -461,15 +467,23 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
461
467
|
onClose: function onClose() {
|
|
462
468
|
return setShowAI(false);
|
|
463
469
|
},
|
|
464
|
-
rootClassName: styles.drawer
|
|
470
|
+
rootClassName: styles.drawer,
|
|
471
|
+
width: '90%'
|
|
465
472
|
}, /*#__PURE__*/React.createElement(MsgBox, {
|
|
466
473
|
simple: true,
|
|
467
474
|
messages: [{
|
|
468
475
|
id: crypto.randomUUID(),
|
|
469
476
|
role: 'assistant',
|
|
470
|
-
content:
|
|
477
|
+
content: intl.formatMessage({
|
|
478
|
+
id: 'ai.assistant.editor.intro'
|
|
479
|
+
}),
|
|
471
480
|
createdAt: Date.now()
|
|
472
|
-
}]
|
|
481
|
+
}],
|
|
482
|
+
context: valueOf(tab),
|
|
483
|
+
onCodegen: function onCodegen(codeBlock) {
|
|
484
|
+
setCode(codeBlock);
|
|
485
|
+
},
|
|
486
|
+
title: title
|
|
473
487
|
})));
|
|
474
488
|
}));
|
|
475
489
|
};
|
|
@@ -38,16 +38,22 @@ export var SearchResult = function SearchResult(_ref) {
|
|
|
38
38
|
createNewSession({
|
|
39
39
|
promptText: keywords,
|
|
40
40
|
mode: "solve",
|
|
41
|
-
lib: !themeConfig.isAntVSite ? themeConfig.title : undefined
|
|
41
|
+
lib: !themeConfig.isAntVSite ? themeConfig.title : undefined,
|
|
42
|
+
jump: true,
|
|
43
|
+
lang: intl.locale === 'zh' ? 'zh' : 'en'
|
|
42
44
|
});
|
|
43
45
|
}
|
|
44
46
|
}, /*#__PURE__*/React.createElement("div", {
|
|
45
47
|
className: classnames(styles.title, styles.highlighted)
|
|
46
48
|
}, keywords), /*#__PURE__*/React.createElement("div", {
|
|
47
49
|
className: styles.description
|
|
48
|
-
},
|
|
50
|
+
}, intl.formatMessage({
|
|
51
|
+
id: 'ai.search.try'
|
|
52
|
+
}), "\xA0", /*#__PURE__*/React.createElement("span", {
|
|
49
53
|
className: styles.highlighted
|
|
50
|
-
}, "AI"), "\xA0
|
|
54
|
+
}, "AI"), "\xA0", intl.formatMessage({
|
|
55
|
+
id: 'ai.search.visualization'
|
|
56
|
+
})))), results !== null && results !== void 0 && results.length ? results.map(function (r, index) {
|
|
51
57
|
return /*#__PURE__*/React.createElement("div", {
|
|
52
58
|
className: styles.item,
|
|
53
59
|
key: index
|