@antv/dumi-theme-antv 0.8.0-beta.1 → 0.8.0-beta.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/builtins/Playground/index.module.less +0 -1
- package/dist/components/AI/HomeDialog/AntVBanner/index.module.less +2 -2
- package/dist/components/AI/HomeDialog/ModeSelector/index.js +4 -1
- package/dist/components/AI/HomeDialog/ModeSelector/index.module.less +39 -22
- package/dist/components/AI/HomeDialog/PromptTextarea/ChooseLib/index.js +4 -2
- package/dist/components/AI/HomeDialog/PromptTextarea/ChooseLib/index.module.less +0 -1
- package/dist/components/AI/HomeDialog/PromptTextarea/DatasourceCard/index.module.less +3 -3
- package/dist/components/AI/HomeDialog/PromptTextarea/Uploader/DataUploader.js +225 -0
- package/dist/components/AI/HomeDialog/PromptTextarea/index.js +74 -43
- package/dist/components/AI/HomeDialog/PromptTextarea/index.module.less +9 -8
- package/dist/components/AI/HomeDialog/RecommendCase/Card.js +13 -8
- package/dist/components/AI/HomeDialog/RecommendCase/card.module.less +1 -1
- package/dist/components/AI/HomeDialog/RecommendCase/index.js +46 -14
- package/dist/components/AI/HomeDialog/RecommendCase/index.module.less +3 -2
- package/dist/components/AI/HomeDialog/index.js +19 -17
- package/dist/components/AI/constant.js +2 -2
- package/dist/components/Login/Captcha/index.js +185 -0
- package/dist/components/Login/Captcha/index.less +91 -0
- package/dist/components/Login/CheckCode/index.js +244 -0
- package/dist/components/Login/CheckCode/index.less +137 -0
- package/dist/components/Login/CountDownButton/index.js +109 -0
- package/dist/components/Login/CountDownButton/index.less +8 -0
- package/dist/components/Login/LoginForm.js +239 -0
- package/dist/components/Login/LoginForm.less +409 -0
- package/dist/components/Login/index.js +24 -0
- package/dist/components/Login/openAuthWindow.js +54 -0
- package/dist/components/Login/types.js +5 -0
- package/dist/components/Login/utils.js +47 -0
- package/dist/layouts/DocLayout.js +2 -1
- package/dist/layouts/GlobalLayout/index.js +10 -4
- package/dist/locales/en.json +125 -1
- package/dist/locales/zh.json +125 -1
- package/dist/model/AIChat.js +72 -8
- package/dist/model/auth.js +133 -0
- package/dist/pages/AIPlayground/components/ConversationsMenu/index.js +36 -12
- package/dist/pages/AIPlayground/components/ConversationsMenu/index.module.less +2 -0
- package/dist/pages/AIPlayground/components/MarkdownComponent/MarkdownCodeBlock.js +25 -11
- package/dist/pages/AIPlayground/components/MarkdownComponent/MarkdownCodeBlock.module.less +1 -2
- package/dist/pages/AIPlayground/components/MarkdownComponent/index.js +5 -2
- package/dist/pages/AIPlayground/components/MsgBox/index.js +202 -146
- package/dist/pages/AIPlayground/components/MsgBox/index.module.less +3 -2
- package/dist/pages/AIPlayground/components/MsgBox/useAutoScroll.js +46 -0
- package/dist/pages/AIPlayground/components/SessionLayout/index.js +2 -2
- package/dist/pages/AIPlayground/components/SessionLayout/index.module.less +4 -2
- package/dist/pages/AIPlayground/components/TaskBox/generateCode.js +7 -1
- package/dist/pages/AIPlayground/components/TaskBox/index.js +78 -55
- package/dist/pages/AIPlayground/components/TaskBox/index.module.less +1 -0
- package/dist/pages/Examples/components/Accouncement/index.module.less +1 -1
- package/dist/pages/Examples/index.module.less +11 -11
- package/dist/pages/Index/components/Cases/index.module.less +8 -8
- package/dist/pages/Index/components/Companies/index.module.less +4 -3
- package/dist/pages/Index/components/Features/FeatureCard.module.less +4 -5
- package/dist/pages/Index/components/Features/index.module.less +5 -5
- package/dist/pages/Index/components/_.less +9 -9
- package/dist/plugin/index.js +2 -2
- package/dist/slots/Banner/Notification.module.less +8 -8
- package/dist/slots/Banner/index.module.less +10 -9
- package/dist/slots/CodeEditor/Toolbar.js +15 -9
- package/dist/slots/CodeEditor/index.js +35 -12
- package/dist/slots/CodeEditor/index.module.less +3 -1
- package/dist/slots/CodePreview/index.module.less +0 -3
- package/dist/slots/CodeRunner/index.js +5 -2
- package/dist/slots/ContentTable/index.module.less +2 -1
- package/dist/slots/Detail/News.module.less +9 -9
- package/dist/slots/Detail/index.module.less +11 -14
- package/dist/slots/ExampleSider/index.module.less +3 -4
- package/dist/slots/Footer/index.module.less +2 -2
- package/dist/slots/Header/Products/Product.module.less +2 -2
- package/dist/slots/Header/Search/SearchResult.js +23 -8
- package/dist/slots/Header/Search/SearchResult.module.less +1 -0
- package/dist/slots/Header/index.js +72 -12
- package/dist/slots/Header/index.module.less +13 -5
- package/dist/slots/LiveExample/index.module.less +1 -1
- package/dist/slots/Loading/index.module.less +30 -28
- package/dist/slots/ManualContent/index.module.less +14 -17
- package/dist/slots/_.less +9 -9
- package/dist/static/user.svg +3 -0
- package/dist/utils/env.js +37 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/request.js +42 -0
- package/package.json +7 -3
|
@@ -6,6 +6,7 @@ import classnames from 'classnames';
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
import styles from "./index.module.less";
|
|
8
8
|
import { AIMode, AIModeMeta } from "../../constant";
|
|
9
|
+
import { FormattedMessage } from 'dumi';
|
|
9
10
|
export var ModeSelector = function ModeSelector(_ref) {
|
|
10
11
|
var value = _ref.value,
|
|
11
12
|
size = _ref.size,
|
|
@@ -24,6 +25,8 @@ export var ModeSelector = function ModeSelector(_ref) {
|
|
|
24
25
|
onChange(mode);
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
|
-
}, meta.icon, /*#__PURE__*/React.createElement(
|
|
28
|
+
}, meta.icon, /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
29
|
+
id: meta.name
|
|
30
|
+
}));
|
|
28
31
|
})));
|
|
29
32
|
};
|
|
@@ -21,11 +21,10 @@
|
|
|
21
21
|
display: flex;
|
|
22
22
|
flex-direction: row;
|
|
23
23
|
gap: 6px;
|
|
24
|
-
|
|
25
24
|
backdrop-filter: blur(12px);
|
|
26
25
|
padding: 4px;
|
|
27
26
|
border-radius: 26px;
|
|
28
|
-
box-shadow: inset 1px -1px 0 0 rgba(255, 255, 255,
|
|
27
|
+
box-shadow: inset 1px -1px 0 0 rgba(255, 255, 255, 89%);
|
|
29
28
|
|
|
30
29
|
&::before {
|
|
31
30
|
border-radius: 26px;
|
|
@@ -40,12 +39,12 @@
|
|
|
40
39
|
opacity: 0.75;
|
|
41
40
|
background-image: linear-gradient(
|
|
42
41
|
90deg,
|
|
43
|
-
rgba(255, 255, 255,
|
|
44
|
-
rgba(217, 217, 217,
|
|
45
|
-
rgba(29, 33, 41, 0) 100%
|
|
42
|
+
rgba(255, 255, 255, 2%) 0%,
|
|
43
|
+
rgba(217, 217, 217, 6%) 50%,
|
|
44
|
+
rgba(29, 33, 41, 0%) 100%
|
|
46
45
|
);
|
|
47
|
-
box-shadow: inset 1px -1px 0 0 rgba(255, 255, 255,
|
|
48
|
-
background: rgba(255, 255, 255,
|
|
46
|
+
box-shadow: inset 1px -1px 0 0 rgba(255, 255, 255, 89%);
|
|
47
|
+
background: rgba(255, 255, 255, 50%);
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
.switchBtn {
|
|
@@ -53,7 +52,6 @@
|
|
|
53
52
|
align-items: center;
|
|
54
53
|
justify-content: center;
|
|
55
54
|
gap: 8px;
|
|
56
|
-
|
|
57
55
|
width: 120px;
|
|
58
56
|
height: 38px;
|
|
59
57
|
cursor: pointer;
|
|
@@ -68,42 +66,48 @@
|
|
|
68
66
|
&.active {
|
|
69
67
|
color: #1d2129;
|
|
70
68
|
font-weight: 500;
|
|
71
|
-
|
|
72
|
-
background: #ffffff;
|
|
69
|
+
background: #fff;
|
|
73
70
|
border-color: #eeeef0;
|
|
74
|
-
box-shadow: 0 0 4px 0 rgba(0, 0, 0,
|
|
71
|
+
box-shadow: 0 0 4px 0 rgba(0, 0, 0, 8%);
|
|
75
72
|
}
|
|
76
73
|
}
|
|
77
74
|
}
|
|
78
75
|
|
|
79
76
|
.datasetSelectorModal {
|
|
80
|
-
top:
|
|
81
|
-
padding-bottom:
|
|
77
|
+
top: 0;
|
|
78
|
+
padding-bottom: 0;
|
|
82
79
|
|
|
83
80
|
.listItemContent {
|
|
84
81
|
cursor: pointer;
|
|
85
82
|
border: none;
|
|
86
83
|
line-height: 22px;
|
|
84
|
+
|
|
87
85
|
&.disabled {
|
|
88
86
|
color: #86909c;
|
|
89
87
|
cursor: not-allowed;
|
|
90
88
|
}
|
|
89
|
+
|
|
91
90
|
&:hover {
|
|
92
91
|
background: #1677ff1a;
|
|
93
92
|
}
|
|
93
|
+
|
|
94
94
|
&:not(.disabled):hover {
|
|
95
95
|
color: #1677ff;
|
|
96
96
|
}
|
|
97
|
+
|
|
97
98
|
padding: 7px 16px 7px 7px;
|
|
99
|
+
|
|
98
100
|
&--multiline {
|
|
99
101
|
padding: 4px 16px 4px 7px;
|
|
100
102
|
}
|
|
101
103
|
}
|
|
104
|
+
|
|
102
105
|
.selected {
|
|
103
106
|
background: #1677ff1a;
|
|
104
107
|
font-weight: 500;
|
|
105
108
|
color: #1677ff;
|
|
106
109
|
}
|
|
110
|
+
|
|
107
111
|
.nameWrapper {
|
|
108
112
|
flex: 1 1;
|
|
109
113
|
min-width: 0;
|
|
@@ -122,20 +126,24 @@
|
|
|
122
126
|
min-width: 0;
|
|
123
127
|
}
|
|
124
128
|
}
|
|
129
|
+
|
|
125
130
|
.desc {
|
|
126
131
|
font-size: 12px;
|
|
127
132
|
color: #86909ccc;
|
|
128
133
|
line-height: 22px;
|
|
129
134
|
}
|
|
130
135
|
}
|
|
136
|
+
|
|
131
137
|
.list {
|
|
132
138
|
background: #ffffffdb;
|
|
133
|
-
padding: 10px 18px 18px
|
|
139
|
+
padding: 10px 18px 18px;
|
|
140
|
+
|
|
134
141
|
:global {
|
|
135
142
|
.ant-input-affix-wrapper {
|
|
136
143
|
margin-bottom: 8px;
|
|
137
144
|
border-radius: 6px;
|
|
138
145
|
color: #5a607f65;
|
|
146
|
+
|
|
139
147
|
.ant-input-prefix {
|
|
140
148
|
margin-right: 8px;
|
|
141
149
|
}
|
|
@@ -148,13 +156,16 @@
|
|
|
148
156
|
.ant-alert-info .ant-alert-icon {
|
|
149
157
|
color: #1677ff;
|
|
150
158
|
}
|
|
159
|
+
|
|
151
160
|
.ant-modal-footer {
|
|
152
161
|
button {
|
|
153
162
|
box-shadow: none;
|
|
163
|
+
|
|
154
164
|
&.ant-btn-primary {
|
|
155
165
|
color: white;
|
|
156
166
|
background: #1677ff;
|
|
157
167
|
}
|
|
168
|
+
|
|
158
169
|
background: none;
|
|
159
170
|
border: none;
|
|
160
171
|
border-radius: 6px;
|
|
@@ -162,15 +173,18 @@
|
|
|
162
173
|
width: 60px;
|
|
163
174
|
height: 32px;
|
|
164
175
|
color: #4e5969e6;
|
|
176
|
+
|
|
165
177
|
&:disabled {
|
|
166
178
|
background: #4e59693c;
|
|
167
179
|
color: white;
|
|
168
180
|
}
|
|
169
181
|
}
|
|
170
182
|
}
|
|
183
|
+
|
|
171
184
|
.ant-modal-close-x {
|
|
172
185
|
display: none;
|
|
173
186
|
}
|
|
187
|
+
|
|
174
188
|
.ant-modal-body {
|
|
175
189
|
padding: 0;
|
|
176
190
|
}
|
|
@@ -178,21 +192,26 @@
|
|
|
178
192
|
.ant-modal-header {
|
|
179
193
|
border-radius: 8px 8px 0 0;
|
|
180
194
|
}
|
|
195
|
+
|
|
181
196
|
.ant-modal-content {
|
|
182
197
|
border-radius: 8px;
|
|
183
198
|
}
|
|
199
|
+
|
|
184
200
|
.ant-modal-content {
|
|
185
201
|
background-color: rgb(251, 252, 253);
|
|
186
202
|
}
|
|
203
|
+
|
|
187
204
|
.ant-tabs-nav {
|
|
188
205
|
padding-left: 18px;
|
|
189
206
|
padding-right: 18px;
|
|
190
207
|
margin-bottom: 0;
|
|
191
208
|
}
|
|
209
|
+
|
|
192
210
|
.ant-tabs-tab {
|
|
193
211
|
font-size: 14px;
|
|
194
|
-
padding: 14px 0 13px
|
|
212
|
+
padding: 14px 0 13px;
|
|
195
213
|
}
|
|
214
|
+
|
|
196
215
|
.ant-alert {
|
|
197
216
|
padding: 4px 15px;
|
|
198
217
|
}
|
|
@@ -214,7 +233,6 @@
|
|
|
214
233
|
white-space: nowrap;
|
|
215
234
|
text-overflow: ellipsis;
|
|
216
235
|
overflow: hidden;
|
|
217
|
-
|
|
218
236
|
font-size: 14px;
|
|
219
237
|
color: #5a607fe0;
|
|
220
238
|
}
|
|
@@ -230,17 +248,17 @@
|
|
|
230
248
|
.switchBtn {
|
|
231
249
|
width: 100px;
|
|
232
250
|
border-radius: 12px;
|
|
233
|
-
background: #
|
|
251
|
+
background: #fff;
|
|
234
252
|
border: 1px solid #5a607fe0;
|
|
235
253
|
opacity: 0.4;
|
|
236
|
-
box-shadow:
|
|
254
|
+
box-shadow: 0 3px 12px 0 #0000000a;
|
|
237
255
|
font-size: 14px;
|
|
238
256
|
color: #86909c;
|
|
239
257
|
line-height: 24px;
|
|
240
258
|
height: 24px;
|
|
241
259
|
|
|
242
260
|
&.active {
|
|
243
|
-
background: #
|
|
261
|
+
background: #fff;
|
|
244
262
|
border: 1px solid #2d84ff;
|
|
245
263
|
color: #1677ff;
|
|
246
264
|
opacity: 1;
|
|
@@ -261,12 +279,11 @@
|
|
|
261
279
|
border-radius: 4px;
|
|
262
280
|
margin-left: 8px;
|
|
263
281
|
flex-shrink: 0;
|
|
264
|
-
|
|
265
282
|
color: #86909c;
|
|
266
|
-
background: rgba(0, 0, 0,
|
|
283
|
+
background: rgba(0, 0, 0, 4%);
|
|
267
284
|
|
|
268
285
|
&.primary {
|
|
269
286
|
color: #f68b02;
|
|
270
|
-
background: rgba(246, 144, 61,
|
|
287
|
+
background: rgba(246, 144, 61, 10%);
|
|
271
288
|
}
|
|
272
289
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Dropdown } from "antd";
|
|
3
3
|
import { useProducts } from "../../../../../hooks/useProducts";
|
|
4
|
-
import { useLocale } from "dumi";
|
|
4
|
+
import { useLocale, FormattedMessage } from "dumi";
|
|
5
5
|
import styles from "./index.module.less";
|
|
6
6
|
export function ChooseLib(props) {
|
|
7
7
|
var _data$find;
|
|
@@ -47,5 +47,7 @@ export function ChooseLib(props) {
|
|
|
47
47
|
return item.title === value;
|
|
48
48
|
})) === null || _data$find === void 0 ? void 0 : _data$find.icon) || "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*7svFR6wkPMoAAAAAAAAAAAAADmJ7AQ/original",
|
|
49
49
|
alt: "AntV"
|
|
50
|
-
}), value || !isCompact &&
|
|
50
|
+
}), value || !isCompact && /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
51
|
+
id: "ai.chooseLib.placeholder"
|
|
52
|
+
})));
|
|
51
53
|
}
|
|
@@ -3,11 +3,10 @@
|
|
|
3
3
|
align-items: center;
|
|
4
4
|
height: 32px;
|
|
5
5
|
position: relative;
|
|
6
|
-
|
|
7
6
|
padding-left: 8px;
|
|
8
7
|
padding-right: 12px;
|
|
9
|
-
background: rgba(212, 215, 219,
|
|
10
|
-
border: 1px solid rgba(222, 226, 241,
|
|
8
|
+
background: rgba(212, 215, 219, 40%);
|
|
9
|
+
border: 1px solid rgba(222, 226, 241, 70%);
|
|
11
10
|
border-radius: 8px;
|
|
12
11
|
|
|
13
12
|
img {
|
|
@@ -24,6 +23,7 @@
|
|
|
24
23
|
text-overflow: ellipsis;
|
|
25
24
|
white-space: nowrap;
|
|
26
25
|
}
|
|
26
|
+
|
|
27
27
|
.desc {
|
|
28
28
|
margin-left: 16px;
|
|
29
29
|
font-size: 10px;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
2
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
3
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
4
|
+
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); }
|
|
5
|
+
// src/components/DataUploader.tsx
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { Upload, message, Tooltip } from 'antd';
|
|
8
|
+
import { useRequest } from 'ahooks';
|
|
9
|
+
import { useIntl } from 'dumi';
|
|
10
|
+
import { FileIcons } from "../../../constant";
|
|
11
|
+
|
|
12
|
+
// 定义文件元信息类型,与父组件保持一致
|
|
13
|
+
|
|
14
|
+
// 定义回调函数返回的完整数据类型
|
|
15
|
+
|
|
16
|
+
// 定义组件Props
|
|
17
|
+
|
|
18
|
+
// 新增:直接发送给AI的原始内容最大字符数阈值
|
|
19
|
+
var DIRECT_FEED_CHAR_THRESHOLD = 4000; // 约1k tokens,这是一个比较保守和经济的阈值
|
|
20
|
+
var MAX_FILE_SIZE_MB = 5;
|
|
21
|
+
var MAX_CONTEXT_CHARS = 5000;
|
|
22
|
+
var ALLOWED_FILE_TYPES = ['csv', 'json', 'tsv', 'txt'];
|
|
23
|
+
var MAX_LINES = 10;
|
|
24
|
+
|
|
25
|
+
// --- 辅助函数(与之前相同) ---
|
|
26
|
+
var formatBytes = function formatBytes(bytes) {
|
|
27
|
+
var decimals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
28
|
+
if (bytes === 0) return '0 Bytes';
|
|
29
|
+
var k = 1024;
|
|
30
|
+
var dm = decimals < 0 ? 0 : decimals;
|
|
31
|
+
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
|
32
|
+
var i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
33
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// 这些函数负责将文件内容转换成给AI看的摘要
|
|
37
|
+
function getTableSummary(content, fileType, intl) {
|
|
38
|
+
var lines = content.replace(/\r\n/g, '\n').split('\n');
|
|
39
|
+
if (lines.length === 0) return intl.formatMessage({
|
|
40
|
+
id: 'ai.upload.file.empty'
|
|
41
|
+
});
|
|
42
|
+
var delimiter = fileType === 'csv' ? ',' : '\t';
|
|
43
|
+
var header = lines[0];
|
|
44
|
+
// 取前MAX_LINES行有效数据作为样本
|
|
45
|
+
var sampleRows = lines.slice(1).filter(function (line) {
|
|
46
|
+
return line.trim() !== '';
|
|
47
|
+
}).slice(0, MAX_LINES).join('\n');
|
|
48
|
+
var columnCount = header.split(delimiter).length;
|
|
49
|
+
var rowCount = lines.filter(function (line) {
|
|
50
|
+
return line.trim() !== '';
|
|
51
|
+
}).length;
|
|
52
|
+
return intl.formatMessage({
|
|
53
|
+
id: 'ai.upload.file.table.summary'
|
|
54
|
+
}, {
|
|
55
|
+
rowCount: rowCount,
|
|
56
|
+
columnCount: columnCount,
|
|
57
|
+
header: header,
|
|
58
|
+
maxLines: MAX_LINES,
|
|
59
|
+
sampleRows: sampleRows
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function getJsonSummary(data, intl) {
|
|
63
|
+
if (Array.isArray(data) && data.length > 0 && _typeof(data[0]) === 'object') {
|
|
64
|
+
var keys = Object.keys(data[0]);
|
|
65
|
+
var sampleData = data.slice(0, MAX_LINES).map(function (item) {
|
|
66
|
+
return JSON.stringify(item);
|
|
67
|
+
}).join('\n');
|
|
68
|
+
return intl.formatMessage({
|
|
69
|
+
id: 'ai.upload.file.json.array.summary'
|
|
70
|
+
}, {
|
|
71
|
+
dataLength: data.length,
|
|
72
|
+
keys: keys.join(', '),
|
|
73
|
+
maxLines: MAX_LINES,
|
|
74
|
+
sampleData: sampleData
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return intl.formatMessage({
|
|
78
|
+
id: 'ai.upload.file.json.object.summary'
|
|
79
|
+
}) + '\n' + JSON.stringify(data, null, 2);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// --- 文件解析服务函数 ---
|
|
83
|
+
function parseFile(_x, _x2) {
|
|
84
|
+
return _parseFile.apply(this, arguments);
|
|
85
|
+
}
|
|
86
|
+
function _parseFile() {
|
|
87
|
+
_parseFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(file, intl) {
|
|
88
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
89
|
+
while (1) switch (_context.prev = _context.next) {
|
|
90
|
+
case 0:
|
|
91
|
+
return _context.abrupt("return", new Promise(function (resolve, reject) {
|
|
92
|
+
var reader = new FileReader();
|
|
93
|
+
reader.onload = function (event) {
|
|
94
|
+
try {
|
|
95
|
+
var _event$target;
|
|
96
|
+
var fileContent = (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.result;
|
|
97
|
+
var dataSummary;
|
|
98
|
+
|
|
99
|
+
// --- 智能策略判断 ---
|
|
100
|
+
if (fileContent.length <= DIRECT_FEED_CHAR_THRESHOLD) {
|
|
101
|
+
// 策略1:文件内容足够小,直接作为上下文
|
|
102
|
+
dataSummary = intl.formatMessage({
|
|
103
|
+
id: 'ai.upload.file.full.content'
|
|
104
|
+
}, {
|
|
105
|
+
fileContent: fileContent
|
|
106
|
+
});
|
|
107
|
+
} else {
|
|
108
|
+
var _file$name$split$pop2;
|
|
109
|
+
// 策略2:文件内容过大,执行摘要算法
|
|
110
|
+
var fileType = ((_file$name$split$pop2 = file.name.split('.').pop()) === null || _file$name$split$pop2 === void 0 ? void 0 : _file$name$split$pop2.toLowerCase()) || '';
|
|
111
|
+
if (fileType === 'json') {
|
|
112
|
+
var jsonData = JSON.parse(fileContent);
|
|
113
|
+
dataSummary = getJsonSummary(jsonData, intl);
|
|
114
|
+
} else if (['csv', 'tsv', 'txt'].includes(fileType)) {
|
|
115
|
+
dataSummary = getTableSummary(fileContent, fileType, intl);
|
|
116
|
+
} else {
|
|
117
|
+
reject(new Error(intl.formatMessage({
|
|
118
|
+
id: 'ai.upload.file.parse.type.error'
|
|
119
|
+
})));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (dataSummary.length > MAX_CONTEXT_CHARS) {
|
|
123
|
+
dataSummary = dataSummary.substring(0, MAX_CONTEXT_CHARS) + "\n" + intl.formatMessage({
|
|
124
|
+
id: 'ai.upload.file.summary.truncated'
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
resolve({
|
|
129
|
+
dataSummary: dataSummary,
|
|
130
|
+
fileMeta: {
|
|
131
|
+
type: 'FILE',
|
|
132
|
+
fileName: file.name,
|
|
133
|
+
fileSize: formatBytes(file.size)
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
} catch (e) {
|
|
137
|
+
reject(new Error(intl.formatMessage({
|
|
138
|
+
id: 'ai.upload.file.parse.error'
|
|
139
|
+
})));
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
reader.onerror = function () {
|
|
143
|
+
return reject(new Error(intl.formatMessage({
|
|
144
|
+
id: 'ai.upload.file.read.error'
|
|
145
|
+
})));
|
|
146
|
+
};
|
|
147
|
+
reader.readAsText(file);
|
|
148
|
+
}));
|
|
149
|
+
case 1:
|
|
150
|
+
case "end":
|
|
151
|
+
return _context.stop();
|
|
152
|
+
}
|
|
153
|
+
}, _callee);
|
|
154
|
+
}));
|
|
155
|
+
return _parseFile.apply(this, arguments);
|
|
156
|
+
}
|
|
157
|
+
export var DataUploader = function DataUploader(_ref) {
|
|
158
|
+
var onDataAnalyzed = _ref.onDataAnalyzed,
|
|
159
|
+
isCompact = _ref.isCompact,
|
|
160
|
+
tooltipText = _ref.tooltipText;
|
|
161
|
+
var intl = useIntl();
|
|
162
|
+
var _useRequest = useRequest(function (file) {
|
|
163
|
+
return parseFile(file, intl);
|
|
164
|
+
}, {
|
|
165
|
+
manual: true,
|
|
166
|
+
onSuccess: function onSuccess(result) {
|
|
167
|
+
// message.success(`${result.fileMeta?.fileName} 分析成功!`);
|
|
168
|
+
onDataAnalyzed(result);
|
|
169
|
+
},
|
|
170
|
+
onError: function onError(e) {
|
|
171
|
+
message.error(e.message);
|
|
172
|
+
// 如果解析失败,也需要通知父组件清空数据
|
|
173
|
+
onDataAnalyzed({
|
|
174
|
+
fileMeta: null,
|
|
175
|
+
dataSummary: ''
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}),
|
|
179
|
+
runParse = _useRequest.run,
|
|
180
|
+
loading = _useRequest.loading;
|
|
181
|
+
var uploadProps = {
|
|
182
|
+
showUploadList: false,
|
|
183
|
+
// 我们用自己的DatasourceCard来回显,所以隐藏默认列表
|
|
184
|
+
accept: ALLOWED_FILE_TYPES.map(function (ext) {
|
|
185
|
+
return ".".concat(ext);
|
|
186
|
+
}).join(','),
|
|
187
|
+
beforeUpload: function beforeUpload(file) {
|
|
188
|
+
var _file$name$split$pop;
|
|
189
|
+
var fileExtension = ((_file$name$split$pop = file.name.split('.').pop()) === null || _file$name$split$pop === void 0 ? void 0 : _file$name$split$pop.toLowerCase()) || '';
|
|
190
|
+
if (!ALLOWED_FILE_TYPES.includes(fileExtension)) {
|
|
191
|
+
message.error(intl.formatMessage({
|
|
192
|
+
id: 'ai.upload.file.type.error'
|
|
193
|
+
}, {
|
|
194
|
+
types: ALLOWED_FILE_TYPES.join(', ')
|
|
195
|
+
}));
|
|
196
|
+
return Upload.LIST_IGNORE;
|
|
197
|
+
}
|
|
198
|
+
if (file.size / 1024 / 1024 > MAX_FILE_SIZE_MB) {
|
|
199
|
+
message.error(intl.formatMessage({
|
|
200
|
+
id: 'ai.upload.file.size.error'
|
|
201
|
+
}, {
|
|
202
|
+
size: MAX_FILE_SIZE_MB
|
|
203
|
+
}));
|
|
204
|
+
return Upload.LIST_IGNORE;
|
|
205
|
+
}
|
|
206
|
+
runParse(file);
|
|
207
|
+
return false; // 总是返回 false 来手动控制
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
return /*#__PURE__*/React.createElement(Tooltip, {
|
|
211
|
+
title: isCompact ? "".concat(intl.formatMessage({
|
|
212
|
+
id: 'ai.upload.data'
|
|
213
|
+
}), "\u3002").concat(tooltipText) : tooltipText
|
|
214
|
+
}, /*#__PURE__*/React.createElement(Upload, uploadProps, /*#__PURE__*/React.createElement("button", {
|
|
215
|
+
type: "button",
|
|
216
|
+
disabled: loading
|
|
217
|
+
}, loading ? intl.formatMessage({
|
|
218
|
+
id: 'ai.upload.analyzing'
|
|
219
|
+
}) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("img", {
|
|
220
|
+
src: FileIcons.FILE,
|
|
221
|
+
alt: "file-icon"
|
|
222
|
+
}), " ", !isCompact && intl.formatMessage({
|
|
223
|
+
id: 'ai.upload.data'
|
|
224
|
+
})))));
|
|
225
|
+
};
|