@antv/dumi-theme-antv 0.8.0-beta.6 → 0.8.0-beta.8
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/Login/CheckCode/index.js +0 -2
- package/dist/layouts/GlobalLayout/index.js +3 -1
- package/dist/model/AIChat.js +51 -1
- package/dist/model/auth.js +50 -36
- package/dist/pages/AIPlayground/components/MarkdownComponent/MarkdownCodeBlock.js +5 -3
- package/dist/pages/AIPlayground/components/MarkdownComponent/index.js +5 -2
- package/dist/pages/AIPlayground/components/MsgBox/index.js +18 -17
- package/dist/slots/CodeEditor/index.js +5 -2
- package/dist/slots/Header/index.js +32 -3
- package/dist/slots/Header/index.module.less +8 -0
- package/dist/static/user.svg +3 -0
- package/dist/utils/env.js +14 -1
- package/dist/utils/request.js +0 -12
- package/dist/utils/uid.js +17 -0
- package/package.json +1 -1
- package/dist/utils/auth.js +0 -10
|
@@ -17,13 +17,11 @@ import { useRef, useState } from 'react';
|
|
|
17
17
|
import { Form, Input, message } from 'antd';
|
|
18
18
|
import CountDownButton from "../CountDownButton";
|
|
19
19
|
import cls from 'classnames';
|
|
20
|
-
import { UIA_UA_RE } from "../utils";
|
|
21
20
|
import Captcha from "../Captcha";
|
|
22
21
|
import { useIntl } from 'dumi';
|
|
23
22
|
import "./index.less";
|
|
24
23
|
import React from 'react';
|
|
25
24
|
import { sendValidationCode } from "../../../model/auth";
|
|
26
|
-
var isUIA = UIA_UA_RE.test(navigator.userAgent);
|
|
27
25
|
function CheckCode(_ref) {
|
|
28
26
|
var en = _ref.en,
|
|
29
27
|
form = _ref.form,
|
|
@@ -5,12 +5,14 @@ import React, { useEffect } from 'react';
|
|
|
5
5
|
import { initializeAIChat } from "../../model/AIChat";
|
|
6
6
|
import { initializeAuth } from "../../model/auth";
|
|
7
7
|
var queryClient = new QueryClient();
|
|
8
|
-
window.antd = antd;
|
|
9
8
|
var GlobalLayout = function GlobalLayout() {
|
|
10
9
|
var outlet = useOutlet();
|
|
11
10
|
useEffect(function () {
|
|
12
11
|
initializeAIChat();
|
|
13
12
|
initializeAuth();
|
|
13
|
+
if (typeof window !== 'undefined') {
|
|
14
|
+
window.antd = antd;
|
|
15
|
+
}
|
|
14
16
|
}, []);
|
|
15
17
|
return outlet && /*#__PURE__*/React.createElement(QueryClientProvider, {
|
|
16
18
|
client: queryClient
|
package/dist/model/AIChat.js
CHANGED
|
@@ -13,6 +13,7 @@ import { derive, subscribeKey } from 'valtio/utils';
|
|
|
13
13
|
import localforage from 'localforage';
|
|
14
14
|
import FingerprintJS from '@fingerprintjs/fingerprintjs';
|
|
15
15
|
import { history } from "dumi";
|
|
16
|
+
import { message } from "antd";
|
|
16
17
|
|
|
17
18
|
// --- 配置 ---
|
|
18
19
|
// 定义需要持久化的 state key
|
|
@@ -223,4 +224,53 @@ export var createNewSession = function createNewSession(config) {
|
|
|
223
224
|
var _config$lang;
|
|
224
225
|
history.push("/".concat((_config$lang = config.lang) !== null && _config$lang !== void 0 ? _config$lang : 'zh', "/ai-playground"));
|
|
225
226
|
}
|
|
226
|
-
};
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* 清空所有本地AI对话记录和相关状态。用户注销账户或手动请求清除数据时调用。
|
|
231
|
+
*
|
|
232
|
+
* 该函数会执行以下操作:
|
|
233
|
+
* 1. 从 localforage 中删除持久化的状态数据。
|
|
234
|
+
* 2. 将内存中的 AIChatStore 重置为初始状态。
|
|
235
|
+
*
|
|
236
|
+
*/
|
|
237
|
+
export var clearAllChatData = /*#__PURE__*/function () {
|
|
238
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
239
|
+
var initialKeys, _i, _initialKeys, key;
|
|
240
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
241
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
242
|
+
case 0:
|
|
243
|
+
_context2.prev = 0;
|
|
244
|
+
_context2.next = 3;
|
|
245
|
+
return localforage.removeItem(STORAGE_KEY);
|
|
246
|
+
case 3:
|
|
247
|
+
console.log("[AIChat] Persistent state with key \"".concat(STORAGE_KEY, "\" has been removed."));
|
|
248
|
+
|
|
249
|
+
// 步骤 2: 将内存中的 valtio store 重置为初始状态。
|
|
250
|
+
// 这会立即更新UI,让所有对话记录从界面上消失。
|
|
251
|
+
// 注意:我们不能直接做 AIChatStore = initialState,
|
|
252
|
+
// 因为 proxy 对象是不可替换的。我们必须逐个属性地重置。
|
|
253
|
+
initialKeys = Object.keys(initialState);
|
|
254
|
+
for (_i = 0, _initialKeys = initialKeys; _i < _initialKeys.length; _i++) {
|
|
255
|
+
key = _initialKeys[_i];
|
|
256
|
+
// @ts-ignore
|
|
257
|
+
AIChatStore[key] = initialState[key];
|
|
258
|
+
}
|
|
259
|
+
console.log('[AIChat] In-memory state has been reset to initial values.');
|
|
260
|
+
_context2.next = 13;
|
|
261
|
+
break;
|
|
262
|
+
case 9:
|
|
263
|
+
_context2.prev = 9;
|
|
264
|
+
_context2.t0 = _context2["catch"](0);
|
|
265
|
+
console.error('[AIChat] Failed to clear all chat data:', _context2.t0);
|
|
266
|
+
message.error('清空对话记录失败,请刷新页面后重试。');
|
|
267
|
+
case 13:
|
|
268
|
+
case "end":
|
|
269
|
+
return _context2.stop();
|
|
270
|
+
}
|
|
271
|
+
}, _callee2, null, [[0, 9]]);
|
|
272
|
+
}));
|
|
273
|
+
return function clearAllChatData() {
|
|
274
|
+
return _ref2.apply(this, arguments);
|
|
275
|
+
};
|
|
276
|
+
}();
|
package/dist/model/auth.js
CHANGED
|
@@ -10,6 +10,9 @@ import request from "../utils/request";
|
|
|
10
10
|
* @returns {boolean} 如果包含则返回 true, 否则返回 false
|
|
11
11
|
*/
|
|
12
12
|
function hasSkipLoginParam() {
|
|
13
|
+
if (typeof window === 'undefined') {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
13
16
|
// 1. 获取当前 URL 的查询字符串 (例如 "?foo=bar&skipLogin=1")
|
|
14
17
|
var queryString = window.location.search;
|
|
15
18
|
|
|
@@ -24,8 +27,7 @@ function hasSkipLoginParam() {
|
|
|
24
27
|
// 1. 定义 State (只包含数据)
|
|
25
28
|
export var authStore = proxy({
|
|
26
29
|
isModalOpen: false,
|
|
27
|
-
isAuthenticated:
|
|
28
|
-
token: localStorage.getItem('authToken')
|
|
30
|
+
isAuthenticated: false
|
|
29
31
|
});
|
|
30
32
|
|
|
31
33
|
// 2. 定义 Actions (作为独立函数)
|
|
@@ -37,7 +39,6 @@ export var hideLoginModal = function hideLoginModal() {
|
|
|
37
39
|
};
|
|
38
40
|
export var loginOrRegister = /*#__PURE__*/function () {
|
|
39
41
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
40
|
-
var result;
|
|
41
42
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
42
43
|
while (1) switch (_context.prev = _context.next) {
|
|
43
44
|
case 0:
|
|
@@ -45,71 +46,84 @@ export var loginOrRegister = /*#__PURE__*/function () {
|
|
|
45
46
|
_context.next = 3;
|
|
46
47
|
return request.post('/api/modules/user/api/accounts/login_or_register', params);
|
|
47
48
|
case 3:
|
|
48
|
-
result = _context.sent;
|
|
49
|
-
authStore.token = result.token;
|
|
50
49
|
authStore.isAuthenticated = true;
|
|
51
|
-
if (typeof window !== 'undefined') {
|
|
52
|
-
localStorage.setItem('authToken', result.token);
|
|
53
|
-
}
|
|
54
50
|
hideLoginModal();
|
|
55
51
|
return _context.abrupt("return", true);
|
|
56
|
-
case
|
|
57
|
-
_context.prev =
|
|
52
|
+
case 8:
|
|
53
|
+
_context.prev = 8;
|
|
58
54
|
_context.t0 = _context["catch"](0);
|
|
59
55
|
console.error('Login failed in store:', _context.t0);
|
|
60
56
|
return _context.abrupt("return", false);
|
|
61
|
-
case
|
|
57
|
+
case 12:
|
|
62
58
|
case "end":
|
|
63
59
|
return _context.stop();
|
|
64
60
|
}
|
|
65
|
-
}, _callee, null, [[0,
|
|
61
|
+
}, _callee, null, [[0, 8]]);
|
|
66
62
|
}));
|
|
67
63
|
return function loginOrRegister(_x) {
|
|
68
64
|
return _ref.apply(this, arguments);
|
|
69
65
|
};
|
|
70
66
|
}();
|
|
71
|
-
export var logout = function
|
|
72
|
-
try {
|
|
73
|
-
request.delete('/api/modules/user/api/accounts/logout');
|
|
74
|
-
} catch (e) {
|
|
75
|
-
console.error('Logout failed in store:', e);
|
|
76
|
-
} finally {
|
|
77
|
-
authStore.token = null;
|
|
78
|
-
authStore.isAuthenticated = false;
|
|
79
|
-
localStorage.removeItem('authToken');
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
export function sendValidationCode(data) {
|
|
83
|
-
return request.post('/api/modules/user/api/validation_code/send', data);
|
|
84
|
-
}
|
|
85
|
-
export var initializeAuth = /*#__PURE__*/function () {
|
|
67
|
+
export var logout = /*#__PURE__*/function () {
|
|
86
68
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
87
69
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
88
70
|
while (1) switch (_context2.prev = _context2.next) {
|
|
89
71
|
case 0:
|
|
90
72
|
_context2.prev = 0;
|
|
73
|
+
_context2.next = 3;
|
|
74
|
+
return request.delete('/api/modules/user/api/accounts/logout');
|
|
75
|
+
case 3:
|
|
76
|
+
_context2.next = 8;
|
|
77
|
+
break;
|
|
78
|
+
case 5:
|
|
79
|
+
_context2.prev = 5;
|
|
80
|
+
_context2.t0 = _context2["catch"](0);
|
|
81
|
+
console.error('Logout failed in store:', _context2.t0);
|
|
82
|
+
case 8:
|
|
83
|
+
_context2.prev = 8;
|
|
84
|
+
authStore.isAuthenticated = false;
|
|
85
|
+
return _context2.finish(8);
|
|
86
|
+
case 11:
|
|
87
|
+
case "end":
|
|
88
|
+
return _context2.stop();
|
|
89
|
+
}
|
|
90
|
+
}, _callee2, null, [[0, 5, 8, 11]]);
|
|
91
|
+
}));
|
|
92
|
+
return function logout() {
|
|
93
|
+
return _ref2.apply(this, arguments);
|
|
94
|
+
};
|
|
95
|
+
}();
|
|
96
|
+
export function sendValidationCode(data) {
|
|
97
|
+
return request.post('/api/modules/user/api/validation_code/send', data);
|
|
98
|
+
}
|
|
99
|
+
export var initializeAuth = /*#__PURE__*/function () {
|
|
100
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
101
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
102
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
103
|
+
case 0:
|
|
104
|
+
_context3.prev = 0;
|
|
91
105
|
if (hasSkipLoginParam()) {
|
|
92
|
-
|
|
106
|
+
_context3.next = 4;
|
|
93
107
|
break;
|
|
94
108
|
}
|
|
95
|
-
|
|
109
|
+
_context3.next = 4;
|
|
96
110
|
return request.get('/api/modules/user/api/accounts/get_company_info');
|
|
97
111
|
case 4:
|
|
98
112
|
authStore.isAuthenticated = true;
|
|
99
|
-
|
|
113
|
+
_context3.next = 11;
|
|
100
114
|
break;
|
|
101
115
|
case 7:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
console.error('Initialize auth failed in store:',
|
|
116
|
+
_context3.prev = 7;
|
|
117
|
+
_context3.t0 = _context3["catch"](0);
|
|
118
|
+
console.error('Initialize auth failed in store:', _context3.t0);
|
|
105
119
|
authStore.isAuthenticated = false;
|
|
106
120
|
case 11:
|
|
107
121
|
case "end":
|
|
108
|
-
return
|
|
122
|
+
return _context3.stop();
|
|
109
123
|
}
|
|
110
|
-
},
|
|
124
|
+
}, _callee3, null, [[0, 7]]);
|
|
111
125
|
}));
|
|
112
126
|
return function initializeAuth() {
|
|
113
|
-
return
|
|
127
|
+
return _ref3.apply(this, arguments);
|
|
114
128
|
};
|
|
115
129
|
}();
|
|
@@ -19,7 +19,10 @@ import { useIntl } from 'dumi';
|
|
|
19
19
|
export var MarkdownCodeBlock = function MarkdownCodeBlock(_ref) {
|
|
20
20
|
var inline = _ref.inline,
|
|
21
21
|
className = _ref.className,
|
|
22
|
-
children = _ref.children
|
|
22
|
+
children = _ref.children,
|
|
23
|
+
_ref$showRunButton = _ref.showRunButton,
|
|
24
|
+
showRunButtonProp = _ref$showRunButton === void 0 ? true : _ref$showRunButton;
|
|
25
|
+
var intl = useIntl();
|
|
23
26
|
var _useCopyToClipboard = useCopyToClipboard(),
|
|
24
27
|
_useCopyToClipboard2 = _slicedToArray(_useCopyToClipboard, 2),
|
|
25
28
|
copyState = _useCopyToClipboard2[0],
|
|
@@ -39,7 +42,7 @@ export var MarkdownCodeBlock = function MarkdownCodeBlock(_ref) {
|
|
|
39
42
|
var codeString = String(children).replace(/\n$/, '');
|
|
40
43
|
|
|
41
44
|
// 4. 判断是否显示“运行”按钮
|
|
42
|
-
var showRunButton = /\bimport\b/.test(codeString);
|
|
45
|
+
var showRunButton = showRunButtonProp && /\bimport\b/.test(codeString);
|
|
43
46
|
|
|
44
47
|
// 5. 定义运行代码的逻辑
|
|
45
48
|
var handleRunCode = function handleRunCode() {
|
|
@@ -48,7 +51,6 @@ export var MarkdownCodeBlock = function MarkdownCodeBlock(_ref) {
|
|
|
48
51
|
};
|
|
49
52
|
|
|
50
53
|
// 6. 返回最终的 JSX 结构
|
|
51
|
-
var intl = useIntl();
|
|
52
54
|
return /*#__PURE__*/React.createElement("div", {
|
|
53
55
|
style: {
|
|
54
56
|
position: 'relative',
|
|
@@ -9,7 +9,8 @@ import remarkGfm from 'remark-gfm';
|
|
|
9
9
|
import { MarkdownCodeBlock } from "./MarkdownCodeBlock"; // 引入我们创建的自定义组件
|
|
10
10
|
|
|
11
11
|
export var MarkdownComponent = function MarkdownComponent(_ref) {
|
|
12
|
-
var content = _ref.content
|
|
12
|
+
var content = _ref.content,
|
|
13
|
+
showRunButton = _ref.showRunButton;
|
|
13
14
|
return /*#__PURE__*/React.createElement(Markdown, {
|
|
14
15
|
remarkPlugins: [remarkGfm],
|
|
15
16
|
rehypePlugins: [rehypeRaw],
|
|
@@ -27,7 +28,9 @@ export var MarkdownComponent = function MarkdownComponent(_ref) {
|
|
|
27
28
|
},
|
|
28
29
|
// 2. 【核心】重写 `code` 标签的渲染,使用我们自己的组件
|
|
29
30
|
code: function code(props) {
|
|
30
|
-
return /*#__PURE__*/React.createElement(MarkdownCodeBlock,
|
|
31
|
+
return /*#__PURE__*/React.createElement(MarkdownCodeBlock, _extends({
|
|
32
|
+
showRunButton: showRunButton
|
|
33
|
+
}, props));
|
|
31
34
|
},
|
|
32
35
|
// 3. 重写非标准 `description` 标签的渲染
|
|
33
36
|
// @ts-expect-error - 告知 TypeScript 我们知道这是一个自定义的、非标准的 HTML 标签
|
|
@@ -10,6 +10,7 @@ import { Button, Flex, Space, Tooltip } from 'antd';
|
|
|
10
10
|
import { useChat } from '@ai-sdk/react';
|
|
11
11
|
import { TextStreamChatTransport } from 'ai';
|
|
12
12
|
import { history, useIntl, useSiteData } from 'dumi';
|
|
13
|
+
import { findLast } from 'lodash-es';
|
|
13
14
|
import React, { useEffect, useState, useMemo, useRef } from 'react';
|
|
14
15
|
import { useCopyToClipboard } from 'react-use';
|
|
15
16
|
import { useSnapshot } from 'valtio';
|
|
@@ -62,13 +63,11 @@ var getTextContent = function getTextContent(message) {
|
|
|
62
63
|
}).join('');
|
|
63
64
|
};
|
|
64
65
|
function MsgBox(props) {
|
|
65
|
-
var _derivedSnap$activeSe, _derivedSnap$
|
|
66
|
+
var _derivedSnap$activeSe, _derivedSnap$activeSe2, _derivedSnap$activeSe4, _derivedSnap$activeSe6, _derivedSnap$activeSe7, _messages;
|
|
66
67
|
var _props$messages = props.messages,
|
|
67
68
|
initialMessages = _props$messages === void 0 ? [] : _props$messages,
|
|
68
69
|
_props$simple = props.simple,
|
|
69
70
|
simple = _props$simple === void 0 ? false : _props$simple,
|
|
70
|
-
_props$context = props.context,
|
|
71
|
-
context = _props$context === void 0 ? '' : _props$context,
|
|
72
71
|
onCodegen = props.onCodegen,
|
|
73
72
|
title = props.title;
|
|
74
73
|
var _useSiteData = useSiteData(),
|
|
@@ -93,16 +92,17 @@ function MsgBox(props) {
|
|
|
93
92
|
_useCopyToClipboard2 = _slicedToArray(_useCopyToClipboard, 2),
|
|
94
93
|
copyState = _useCopyToClipboard2[0],
|
|
95
94
|
copyToClipboard = _useCopyToClipboard2[1];
|
|
96
|
-
|
|
95
|
+
var latestUserMessage = findLast((_derivedSnap$activeSe = derivedSnap.activeSession) === null || _derivedSnap$activeSe === void 0 ? void 0 : _derivedSnap$activeSe.messages, function (msg) {
|
|
96
|
+
return msg.role === 'user';
|
|
97
|
+
});
|
|
97
98
|
// 使用 ref 存储动态值,避免重新创建 transport
|
|
98
99
|
var anonymousUserIdRef = useRef(snap.anonymousUserId);
|
|
99
|
-
var
|
|
100
|
-
var activeSessionIdRef = useRef((_derivedSnap$activeSe = derivedSnap.activeSession) === null || _derivedSnap$activeSe === void 0 ? void 0 : _derivedSnap$activeSe.id);
|
|
100
|
+
var activeSessionIdRef = useRef((_derivedSnap$activeSe2 = derivedSnap.activeSession) === null || _derivedSnap$activeSe2 === void 0 ? void 0 : _derivedSnap$activeSe2.id);
|
|
101
101
|
useEffect(function () {
|
|
102
|
-
var _derivedSnap$
|
|
102
|
+
var _derivedSnap$activeSe3;
|
|
103
103
|
anonymousUserIdRef.current = snap.anonymousUserId;
|
|
104
|
-
activeSessionIdRef.current = (_derivedSnap$
|
|
105
|
-
}, [snap.anonymousUserId, (_derivedSnap$
|
|
104
|
+
activeSessionIdRef.current = (_derivedSnap$activeSe3 = derivedSnap.activeSession) === null || _derivedSnap$activeSe3 === void 0 ? void 0 : _derivedSnap$activeSe3.id;
|
|
105
|
+
}, [snap.anonymousUserId, (_derivedSnap$activeSe4 = derivedSnap.activeSession) === null || _derivedSnap$activeSe4 === void 0 ? void 0 : _derivedSnap$activeSe4.id]);
|
|
106
106
|
|
|
107
107
|
// 转换初始消息为新格式
|
|
108
108
|
var convertedInitialMessages = useMemo(function () {
|
|
@@ -123,8 +123,9 @@ function MsgBox(props) {
|
|
|
123
123
|
gptConversationId: activeSessionIdRef.current,
|
|
124
124
|
anonymousUserId: anonymousUserIdRef.current,
|
|
125
125
|
mountId: 'container',
|
|
126
|
-
antvContext: props.context,
|
|
127
|
-
library: lib
|
|
126
|
+
antvContext: (latestUserMessage === null || latestUserMessage === void 0 ? void 0 : latestUserMessage.context) || props.context,
|
|
127
|
+
library: (latestUserMessage === null || latestUserMessage === void 0 ? void 0 : latestUserMessage.lib) || lib,
|
|
128
|
+
mode: latestUserMessage === null || latestUserMessage === void 0 ? void 0 : latestUserMessage.mode
|
|
128
129
|
};
|
|
129
130
|
}
|
|
130
131
|
}),
|
|
@@ -208,8 +209,8 @@ function MsgBox(props) {
|
|
|
208
209
|
return;
|
|
209
210
|
}
|
|
210
211
|
setTimeout(function () {
|
|
211
|
-
var _derivedSnap$
|
|
212
|
-
var sessionMessages = (_derivedSnap$
|
|
212
|
+
var _derivedSnap$activeSe5;
|
|
213
|
+
var sessionMessages = (_derivedSnap$activeSe5 = derivedSnap.activeSession) === null || _derivedSnap$activeSe5 === void 0 ? void 0 : _derivedSnap$activeSe5.messages;
|
|
213
214
|
if ((sessionMessages === null || sessionMessages === void 0 ? void 0 : sessionMessages.length) > 0) {
|
|
214
215
|
var converted = convertToUIMessages(sessionMessages);
|
|
215
216
|
// 避免无限循环,仅当消息数量或内容不同时更新
|
|
@@ -218,7 +219,7 @@ function MsgBox(props) {
|
|
|
218
219
|
}
|
|
219
220
|
}
|
|
220
221
|
});
|
|
221
|
-
}, [(_derivedSnap$
|
|
222
|
+
}, [(_derivedSnap$activeSe6 = derivedSnap.activeSession) === null || _derivedSnap$activeSe6 === void 0 ? void 0 : _derivedSnap$activeSe6.id, (_derivedSnap$activeSe7 = derivedSnap.activeSession) === null || _derivedSnap$activeSe7 === void 0 || (_derivedSnap$activeSe7 = _derivedSnap$activeSe7.messages) === null || _derivedSnap$activeSe7 === void 0 ? void 0 : _derivedSnap$activeSe7.length]);
|
|
222
223
|
|
|
223
224
|
// 处理从外部(如demo页)发起的对话
|
|
224
225
|
useEffect(function () {
|
|
@@ -247,8 +248,7 @@ function MsgBox(props) {
|
|
|
247
248
|
// 将 messages 数组作为依赖项。当它变化时,Hook 会运行。
|
|
248
249
|
var _useAutoScroll = useAutoScroll(messages),
|
|
249
250
|
containerRef = _useAutoScroll.containerRef,
|
|
250
|
-
anchorRef = _useAutoScroll.anchorRef
|
|
251
|
-
showScrollDownButton = _useAutoScroll.showScrollDownButton;
|
|
251
|
+
anchorRef = _useAutoScroll.anchorRef;
|
|
252
252
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Flex, {
|
|
253
253
|
gap: "middle",
|
|
254
254
|
vertical: true,
|
|
@@ -259,7 +259,8 @@ function MsgBox(props) {
|
|
|
259
259
|
return /*#__PURE__*/React.createElement(Bubble, {
|
|
260
260
|
key: msg.id || index,
|
|
261
261
|
content: /*#__PURE__*/React.createElement(MarkdownComponent, {
|
|
262
|
-
content: textContent
|
|
262
|
+
content: textContent,
|
|
263
|
+
showRunButton: !props.simple
|
|
263
264
|
}),
|
|
264
265
|
avatar: msg.role === 'assistant' ? avatar : null,
|
|
265
266
|
footer: msg.role === 'assistant' && index > 0 && index === messages.length - 1 && status === 'ready' ? /*#__PURE__*/React.createElement(Space, {
|
|
@@ -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, useIntl } from 'dumi';
|
|
18
|
+
import { useLocale, useSiteData, useIntl, useLocation } from 'dumi';
|
|
19
19
|
import { debounce, noop } from 'lodash-es';
|
|
20
20
|
import { format } from 'prettier';
|
|
21
21
|
import parserBabel from 'prettier/parser-babel';
|
|
@@ -60,6 +60,7 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
60
60
|
onFullscreen = _ref$onFullscreen === void 0 ? noop : _ref$onFullscreen,
|
|
61
61
|
_ref$showAI = _ref.showAI,
|
|
62
62
|
showAI = _ref$showAI === void 0 ? true : _ref$showAI;
|
|
63
|
+
var umiLocation = useLocation();
|
|
63
64
|
var locale = useLocale();
|
|
64
65
|
var _useSiteData = useSiteData(),
|
|
65
66
|
themeConfig = _useSiteData.themeConfig;
|
|
@@ -471,8 +472,10 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
471
472
|
return setShowAIDrawer(false);
|
|
472
473
|
},
|
|
473
474
|
rootClassName: styles.drawer,
|
|
474
|
-
width: '
|
|
475
|
+
width: '80%',
|
|
476
|
+
key: "".concat(umiLocation.hash, "_").concat(umiLocation.key)
|
|
475
477
|
}, /*#__PURE__*/React.createElement(MsgBox, {
|
|
478
|
+
key: "".concat(umiLocation.hash, "_").concat(umiLocation.key),
|
|
476
479
|
simple: true,
|
|
477
480
|
messages: [{
|
|
478
481
|
id: crypto.randomUUID(),
|
|
@@ -13,7 +13,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
13
13
|
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; }
|
|
14
14
|
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; } }
|
|
15
15
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
16
|
-
import { CaretDownFilled, DownOutlined, GithubOutlined, LinkOutlined, MenuOutlined, WechatOutlined } from '@ant-design/icons';
|
|
16
|
+
import { CaretDownFilled, DownOutlined, GithubOutlined, LinkOutlined, LogoutOutlined, MenuOutlined, UserDeleteOutlined, WechatOutlined } from '@ant-design/icons';
|
|
17
17
|
import { Alert, Button, Dropdown, Menu, Modal, Popover } from 'antd';
|
|
18
18
|
import cx from 'classnames';
|
|
19
19
|
import { FormattedMessage, Link, useLocale, useSiteData } from 'dumi';
|
|
@@ -26,11 +26,15 @@ import { Navs } from "./Navs";
|
|
|
26
26
|
import { Products } from "./Products";
|
|
27
27
|
import { Search } from "./Search";
|
|
28
28
|
import { findVersion } from "./utils";
|
|
29
|
+
import { ReactComponent as UserIcon } from "../../static/user.svg";
|
|
29
30
|
import { Assistant } from '@petercatai/assistant';
|
|
30
31
|
import '@petercatai/assistant/style';
|
|
31
32
|
import { useLocation } from 'react-router-dom';
|
|
32
33
|
import { determineUserType } from "../../utils/user";
|
|
33
34
|
import styles from "./index.module.less";
|
|
35
|
+
import { useSnapshot } from "valtio";
|
|
36
|
+
import { authStore, logout } from "../../model/auth";
|
|
37
|
+
import { clearAllChatData } from "../../model/AIChat";
|
|
34
38
|
function redirectChinaMirror(chinaMirrorOrigin) {
|
|
35
39
|
window.location.href = window.location.href.replace(window.location.origin, chinaMirrorOrigin);
|
|
36
40
|
}
|
|
@@ -76,7 +80,7 @@ var HeaderComponent = function HeaderComponent(_ref) {
|
|
|
76
80
|
ecosystems = _ref.ecosystems,
|
|
77
81
|
announcement = _ref.announcement;
|
|
78
82
|
var isAntVHome = isAntVSite && isHomePage; // 是否为AntV官网首页
|
|
79
|
-
|
|
83
|
+
var authSnap = useSnapshot(authStore);
|
|
80
84
|
var _useState = useState(false),
|
|
81
85
|
_useState2 = _slicedToArray(_useState, 2),
|
|
82
86
|
bannerVisible = _useState2[0],
|
|
@@ -403,7 +407,32 @@ var HeaderComponent = function HeaderComponent(_ref) {
|
|
|
403
407
|
href: githubUrl,
|
|
404
408
|
target: "_blank",
|
|
405
409
|
rel: "noreferrer"
|
|
406
|
-
}, /*#__PURE__*/React.createElement(GithubOutlined, null)))
|
|
410
|
+
}, /*#__PURE__*/React.createElement(GithubOutlined, null))), authSnap.isAuthenticated && /*#__PURE__*/React.createElement("li", {
|
|
411
|
+
className: cx(styles.navIcon, styles.githubCorner)
|
|
412
|
+
}, /*#__PURE__*/React.createElement(Dropdown, {
|
|
413
|
+
menu: {
|
|
414
|
+
items: [{
|
|
415
|
+
key: 'logout',
|
|
416
|
+
label: /*#__PURE__*/React.createElement("a", {
|
|
417
|
+
onClick: function onClick() {
|
|
418
|
+
return logout();
|
|
419
|
+
}
|
|
420
|
+
}, "\u9000\u51FA\u767B\u5F55"),
|
|
421
|
+
icon: /*#__PURE__*/React.createElement(LogoutOutlined, null)
|
|
422
|
+
}, {
|
|
423
|
+
key: 'deleteAccount',
|
|
424
|
+
label: /*#__PURE__*/React.createElement("a", {
|
|
425
|
+
onClick: function onClick() {
|
|
426
|
+
logout();
|
|
427
|
+
clearAllChatData();
|
|
428
|
+
}
|
|
429
|
+
}, "\u6CE8\u9500\u8D26\u53F7"),
|
|
430
|
+
icon: /*#__PURE__*/React.createElement(UserDeleteOutlined, null)
|
|
431
|
+
}]
|
|
432
|
+
}
|
|
433
|
+
}, /*#__PURE__*/React.createElement("a", null, /*#__PURE__*/React.createElement(UserIcon, {
|
|
434
|
+
className: styles.userIcon
|
|
435
|
+
})))));
|
|
407
436
|
return /*#__PURE__*/React.createElement("header", {
|
|
408
437
|
className: cx(styles.header, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, styles.transparent, !!transparent && !productMenuVisible), styles.isHomePage, !!isHomePage && !isAntVHome), styles.lightTheme, !!isAntVHome && !productMenuVisible && isWide), styles.isAntVHome, !!isAntVHome), styles.fixed, popupMenuVisible))
|
|
409
438
|
}, bannerVisible && announcementTitle && /*#__PURE__*/React.createElement(Alert, {
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M512 74.666667C270.933333 74.666667 74.666667 270.933333 74.666667 512S270.933333 949.333333 512 949.333333 949.333333 753.066667 949.333333 512 753.066667 74.666667 512 74.666667z m0 160c70.4 0 128 57.6 128 128s-57.6 128-128 128-128-57.6-128-128 57.6-128 128-128z m236.8 507.733333c-23.466667 32-117.333333 100.266667-236.8 100.266667s-213.333333-68.266667-236.8-100.266667c-8.533333-10.666667-10.666667-21.333333-8.533333-32 29.866667-110.933333 130.133333-187.733333 245.333333-187.733333s215.466667 76.8 245.333333 187.733333c2.133333 10.666667 0 21.333333-8.533333 32z" fill="currentColor"></path>
|
|
3
|
+
</svg>
|
package/dist/utils/env.js
CHANGED
|
@@ -11,10 +11,21 @@ export var safeWindow = function safeWindow(fn) {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* 根据当前环境动态获取 API 的 baseURL。
|
|
15
|
+
* 在浏览器中,它会根据域名判断;在服务端,它会返回一个固定的生产环境地址。
|
|
15
16
|
* @returns {string} API 的 baseURL
|
|
16
17
|
*/
|
|
17
18
|
export var getBaseURL = function getBaseURL() {
|
|
19
|
+
// 关键:检查是否在浏览器环境
|
|
20
|
+
if (typeof window === 'undefined') {
|
|
21
|
+
// === 服务端环境 (SSR/Pre-render) ===
|
|
22
|
+
// 在服务端渲染时,我们无法知道用户最终会通过哪个域名访问。
|
|
23
|
+
// 通常,我们默认返回生产环境的 API 地址。
|
|
24
|
+
// 这样预渲染出的页面如果需要请求数据,会直接请求线上API。
|
|
25
|
+
return 'https://www.weavefox.cn';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// === 浏览器环境 ===
|
|
18
29
|
var hostname = window.location.hostname;
|
|
19
30
|
|
|
20
31
|
// 生产环境
|
|
@@ -31,5 +42,7 @@ export var getBaseURL = function getBaseURL() {
|
|
|
31
42
|
if (hostname.endsWith('.alipay.net')) {
|
|
32
43
|
return 'https://weavefox.alipay.net:8443';
|
|
33
44
|
}
|
|
45
|
+
|
|
46
|
+
// 默认返回生产环境地址,适用于其他未知域名(如 localhost)
|
|
34
47
|
return 'https://www.weavefox.cn';
|
|
35
48
|
};
|
package/dist/utils/request.js
CHANGED
|
@@ -6,24 +6,12 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
6
6
|
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); }
|
|
7
7
|
import axios from 'axios';
|
|
8
8
|
import { getBaseURL } from "./env";
|
|
9
|
-
import { getToken } from "./auth";
|
|
10
9
|
var req = axios.create({
|
|
11
10
|
baseURL: getBaseURL(),
|
|
12
11
|
timeout: 60000,
|
|
13
12
|
withCredentials: true
|
|
14
13
|
});
|
|
15
14
|
|
|
16
|
-
// 请求拦截器
|
|
17
|
-
req.interceptors.request.use(function (config) {
|
|
18
|
-
var token = getToken();
|
|
19
|
-
if (token && config.headers) {
|
|
20
|
-
config.headers.Authorization = "Bearer ".concat(token);
|
|
21
|
-
}
|
|
22
|
-
return config;
|
|
23
|
-
}, function (error) {
|
|
24
|
-
return Promise.reject(error);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
15
|
// 响应拦截器
|
|
28
16
|
req.interceptors.response.use(
|
|
29
17
|
// @ts-ignore - Temporarily ignore type mismatch if it occurs with custom ApiResponse
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var ALL_CHARS = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 生成一个指定长度的、完全随机的字母数字ID。
|
|
5
|
+
* @param l ID 长度,默认为 6
|
|
6
|
+
*/
|
|
7
|
+
export function simpleUid(l) {
|
|
8
|
+
var n = l !== null && l !== void 0 ? l : 6;
|
|
9
|
+
if (n <= 0) {
|
|
10
|
+
throw new RangeError('ID 长度必须大于 0');
|
|
11
|
+
}
|
|
12
|
+
return Array.from({
|
|
13
|
+
length: n
|
|
14
|
+
}, function () {
|
|
15
|
+
return ALL_CHARS[Math.floor(Math.random() * ALL_CHARS.length)];
|
|
16
|
+
}).join('');
|
|
17
|
+
}
|
package/package.json
CHANGED
package/dist/utils/auth.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
var TokenKey = 'My-App-Token';
|
|
2
|
-
export var getToken = function getToken() {
|
|
3
|
-
return localStorage.getItem(TokenKey);
|
|
4
|
-
};
|
|
5
|
-
export var setToken = function setToken(token) {
|
|
6
|
-
return localStorage.setItem(TokenKey, token);
|
|
7
|
-
};
|
|
8
|
-
export var removeToken = function removeToken() {
|
|
9
|
-
return localStorage.removeItem(TokenKey);
|
|
10
|
-
};
|