@antv/dumi-theme-antv 0.8.0-beta.0 → 0.8.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/dist/builtins/Playground/index.module.less +0 -1
  2. package/dist/components/AI/HomeDialog/AntVBanner/index.module.less +2 -2
  3. package/dist/components/AI/HomeDialog/ModeSelector/index.js +4 -1
  4. package/dist/components/AI/HomeDialog/ModeSelector/index.module.less +39 -22
  5. package/dist/components/AI/HomeDialog/PromptTextarea/ChooseLib/index.js +5 -2
  6. package/dist/components/AI/HomeDialog/PromptTextarea/ChooseLib/index.module.less +0 -1
  7. package/dist/components/AI/HomeDialog/PromptTextarea/DatasourceCard/index.module.less +3 -3
  8. package/dist/components/AI/HomeDialog/PromptTextarea/Uploader/DataUploader.js +225 -0
  9. package/dist/components/AI/HomeDialog/PromptTextarea/index.js +66 -34
  10. package/dist/components/AI/HomeDialog/PromptTextarea/index.module.less +9 -8
  11. package/dist/components/AI/HomeDialog/RecommendCase/Card.js +13 -8
  12. package/dist/components/AI/HomeDialog/RecommendCase/card.module.less +1 -1
  13. package/dist/components/AI/HomeDialog/RecommendCase/index.js +46 -14
  14. package/dist/components/AI/HomeDialog/RecommendCase/index.module.less +3 -2
  15. package/dist/components/AI/HomeDialog/index.js +18 -4
  16. package/dist/components/AI/constant.js +2 -2
  17. package/dist/components/Login/Captcha/index.js +185 -0
  18. package/dist/components/Login/Captcha/index.less +91 -0
  19. package/dist/components/Login/CheckCode/index.js +244 -0
  20. package/dist/components/Login/CheckCode/index.less +137 -0
  21. package/dist/components/Login/CountDownButton/index.js +109 -0
  22. package/dist/components/Login/CountDownButton/index.less +8 -0
  23. package/dist/components/Login/LoginForm.js +239 -0
  24. package/dist/components/Login/LoginForm.less +409 -0
  25. package/dist/components/Login/index.js +24 -0
  26. package/dist/components/Login/openAuthWindow.js +54 -0
  27. package/dist/components/Login/types.js +5 -0
  28. package/dist/components/Login/utils.js +47 -0
  29. package/dist/hooks/useStreamingText.js +38 -18
  30. package/dist/hooks/useTypewriter.js +69 -0
  31. package/dist/layouts/DocLayout.js +2 -1
  32. package/dist/layouts/GlobalLayout/index.js +10 -4
  33. package/dist/locales/en.json +121 -1
  34. package/dist/locales/zh.json +121 -1
  35. package/dist/model/AIChat.js +79 -11
  36. package/dist/model/auth.js +133 -0
  37. package/dist/pages/AIPlayground/components/ConversationsMenu/index.js +31 -10
  38. package/dist/pages/AIPlayground/components/ConversationsMenu/index.module.less +2 -0
  39. package/dist/pages/AIPlayground/components/MarkdownComponent/MarkdownCodeBlock.js +47 -20
  40. package/dist/pages/AIPlayground/components/MarkdownComponent/MarkdownCodeBlock.module.less +13 -0
  41. package/dist/pages/AIPlayground/components/MarkdownComponent/index.js +6 -3
  42. package/dist/pages/AIPlayground/components/MsgBox/index.js +250 -106
  43. package/dist/pages/AIPlayground/components/MsgBox/index.module.less +3 -2
  44. package/dist/pages/AIPlayground/components/MsgBox/useAutoScroll.js +46 -0
  45. package/dist/pages/AIPlayground/components/SessionLayout/index.js +18 -10
  46. package/dist/pages/AIPlayground/components/SessionLayout/index.module.less +3 -1
  47. package/dist/pages/AIPlayground/components/TaskBox/generateCode.js +10 -5
  48. package/dist/pages/AIPlayground/components/TaskBox/index.js +79 -54
  49. package/dist/pages/AIPlayground/components/TaskBox/index.module.less +1 -0
  50. package/dist/pages/Examples/components/Accouncement/index.module.less +1 -1
  51. package/dist/pages/Examples/index.module.less +11 -11
  52. package/dist/pages/Index/components/Cases/index.module.less +8 -8
  53. package/dist/pages/Index/components/Companies/index.module.less +4 -3
  54. package/dist/pages/Index/components/Features/FeatureCard.module.less +4 -5
  55. package/dist/pages/Index/components/Features/index.module.less +5 -5
  56. package/dist/pages/Index/components/_.less +9 -9
  57. package/dist/plugin/index.js +2 -2
  58. package/dist/slots/Banner/Notification.module.less +8 -8
  59. package/dist/slots/Banner/index.module.less +10 -9
  60. package/dist/slots/CodeEditor/Toolbar.js +20 -8
  61. package/dist/slots/CodeEditor/Toolbar.module.less +1 -0
  62. package/dist/slots/CodeEditor/index.js +30 -10
  63. package/dist/slots/CodeEditor/index.module.less +3 -0
  64. package/dist/slots/CodePreview/index.module.less +0 -3
  65. package/dist/slots/CodeRunner/index.js +6 -2
  66. package/dist/slots/ContentTable/index.module.less +2 -1
  67. package/dist/slots/Detail/News.module.less +9 -9
  68. package/dist/slots/Detail/index.module.less +11 -14
  69. package/dist/slots/ExampleSider/index.module.less +3 -4
  70. package/dist/slots/Footer/index.module.less +2 -2
  71. package/dist/slots/Header/Products/Product.module.less +2 -2
  72. package/dist/slots/Header/Search/SearchResult.js +23 -7
  73. package/dist/slots/Header/Search/SearchResult.module.less +1 -0
  74. package/dist/slots/Header/index.js +56 -11
  75. package/dist/slots/Header/index.module.less +13 -5
  76. package/dist/slots/LiveExample/index.module.less +1 -1
  77. package/dist/slots/Loading/index.module.less +30 -28
  78. package/dist/slots/ManualContent/index.module.less +14 -17
  79. package/dist/slots/_.less +9 -9
  80. package/dist/static/user.svg +3 -0
  81. package/dist/utils/code.js +35 -0
  82. package/dist/utils/env.js +37 -0
  83. package/dist/utils/request.js +42 -0
  84. package/package.json +7 -2
@@ -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
@@ -48,9 +49,14 @@ subscribe(AIChatStore, function () {
48
49
  // 异步保存,不阻塞UI
49
50
  localforage.setItem(STORAGE_KEY, stateToPersist);
50
51
  });
52
+ export var clearEmptySession = function clearEmptySession() {
53
+ AIChatStore.sessions = AIChatStore.sessions.filter(function (s) {
54
+ return s.messages.length > 0;
55
+ });
56
+ };
51
57
 
52
58
  // --- 初始化逻辑 ---
53
- export var initializeStore = /*#__PURE__*/function () {
59
+ export var initializeAIChat = /*#__PURE__*/function () {
54
60
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
55
61
  var persistedState, fp, result, newSession, _AIChatStore$sessions;
56
62
  return _regeneratorRuntime().wrap(function _callee$(_context) {
@@ -113,17 +119,18 @@ export var initializeStore = /*#__PURE__*/function () {
113
119
  })) {
114
120
  AIChatStore.activeSessionId = ((_AIChatStore$sessions = AIChatStore.sessions[0]) === null || _AIChatStore$sessions === void 0 ? void 0 : _AIChatStore$sessions.id) || null;
115
121
  }
122
+ clearEmptySession();
116
123
 
117
124
  // 4. 标记初始化完成,这将触发持久化订阅
118
125
  AIChatStore.isInitialized = true;
119
126
  // console.log('Valtio store initialized:', snapshot(AIChatStore));
120
- case 21:
127
+ case 22:
121
128
  case "end":
122
129
  return _context.stop();
123
130
  }
124
131
  }, _callee, null, [[5, 15]]);
125
132
  }));
126
- return function initializeStore() {
133
+ return function initializeAIChat() {
127
134
  return _ref.apply(this, arguments);
128
135
  };
129
136
  }();
@@ -188,18 +195,26 @@ export var handlePinSession = function handlePinSession(sessionId) {
188
195
  subscribeKey(AIChatStore, 'activeSessionId', function () {
189
196
  AIChatStore.codeBlock = null;
190
197
  });
191
- export var createNewSession = function createNewSession(config) {
192
- // todo 埋点
193
- // 1. 创建一个新的会话
198
+ export var createPureNewSession = function createPureNewSession(title) {
199
+ var newConversationName = 'New Conversation';
200
+ if (AIChatStore.sessions.some(function (s) {
201
+ return s.title === newConversationName && s.messages.length === 0;
202
+ })) {
203
+ return;
204
+ }
194
205
  var newSessionId = crypto.randomUUID();
195
206
  AIChatStore.sessions.unshift({
196
207
  id: newSessionId,
197
- title: config.promptText.substring(0, 20),
198
- // 使用输入内容作为初始标题
208
+ title: title !== null && title !== void 0 ? title : newConversationName,
199
209
  createdAt: Date.now(),
200
210
  messages: []
201
211
  });
202
212
  AIChatStore.activeSessionId = newSessionId;
213
+ };
214
+ export var createNewSession = function createNewSession(config) {
215
+ // todo 埋点
216
+ // 1. 创建一个新的会话
217
+ createPureNewSession(config.promptText);
203
218
 
204
219
  // 2. 创建临时消息并存入 store
205
220
  AIChatStore.tempMessage = {
@@ -208,7 +223,60 @@ export var createNewSession = function createNewSession(config) {
208
223
  content: config.promptText,
209
224
  createdAt: Date.now(),
210
225
  mode: config.mode,
211
- lib: config.lib
226
+ lib: config.lib,
227
+ context: config.context
228
+ };
229
+ if (config.jump) {
230
+ var _config$lang;
231
+ history.push("/".concat((_config$lang = config.lang) !== null && _config$lang !== void 0 ? _config$lang : 'zh', "/ai-playground"));
232
+ }
233
+ };
234
+
235
+ /**
236
+ * 清空所有本地AI对话记录和相关状态。用户注销账户或手动请求清除数据时调用。
237
+ *
238
+ * 该函数会执行以下操作:
239
+ * 1. 从 localforage 中删除持久化的状态数据。
240
+ * 2. 将内存中的 AIChatStore 重置为初始状态。
241
+ *
242
+ */
243
+ export var clearAllChatData = /*#__PURE__*/function () {
244
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
245
+ var initialKeys, _i, _initialKeys, key;
246
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
247
+ while (1) switch (_context2.prev = _context2.next) {
248
+ case 0:
249
+ _context2.prev = 0;
250
+ _context2.next = 3;
251
+ return localforage.removeItem(STORAGE_KEY);
252
+ case 3:
253
+ console.log("[AIChat] Persistent state with key \"".concat(STORAGE_KEY, "\" has been removed."));
254
+
255
+ // 步骤 2: 将内存中的 valtio store 重置为初始状态。
256
+ // 这会立即更新UI,让所有对话记录从界面上消失。
257
+ // 注意:我们不能直接做 AIChatStore = initialState,
258
+ // 因为 proxy 对象是不可替换的。我们必须逐个属性地重置。
259
+ initialKeys = Object.keys(initialState);
260
+ for (_i = 0, _initialKeys = initialKeys; _i < _initialKeys.length; _i++) {
261
+ key = _initialKeys[_i];
262
+ // @ts-ignore
263
+ AIChatStore[key] = initialState[key];
264
+ }
265
+ console.log('[AIChat] In-memory state has been reset to initial values.');
266
+ _context2.next = 13;
267
+ break;
268
+ case 9:
269
+ _context2.prev = 9;
270
+ _context2.t0 = _context2["catch"](0);
271
+ console.error('[AIChat] Failed to clear all chat data:', _context2.t0);
272
+ message.error('清空对话记录失败,请刷新页面后重试。');
273
+ case 13:
274
+ case "end":
275
+ return _context2.stop();
276
+ }
277
+ }, _callee2, null, [[0, 9]]);
278
+ }));
279
+ return function clearAllChatData() {
280
+ return _ref2.apply(this, arguments);
212
281
  };
213
- history.push("/zh/ai-playground/2");
214
- };
282
+ }();
@@ -0,0 +1,133 @@
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 _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; }
3
+ 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); } }
4
+ 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); }); }; }
5
+ import { proxy } from 'valtio';
6
+ import request from "../utils/request";
7
+
8
+ /**
9
+ * 检查当前 URL 是否包含 'skipLogin=1' 参数
10
+ * @returns {boolean} 如果包含则返回 true, 否则返回 false
11
+ */
12
+ function hasSkipLoginParam() {
13
+ if (typeof window === 'undefined') {
14
+ return false;
15
+ }
16
+ // 1. 获取当前 URL 的查询字符串 (例如 "?foo=bar&skipLogin=1")
17
+ var queryString = window.location.search;
18
+
19
+ // 2. 创建一个 URLSearchParams 实例
20
+ var urlParams = new URLSearchParams(queryString);
21
+
22
+ // 3. 使用 .get() 方法获取 'skipLogin' 参数的值,并判断是否为 '1'
23
+ // 注意:URL参数的值总是字符串类型,所以我们用 '1' 而不是 1 进行比较。
24
+ return urlParams.get('skipLogin') === '1';
25
+ }
26
+
27
+ // 1. 定义 State (只包含数据)
28
+ export var authStore = proxy({
29
+ isModalOpen: false,
30
+ isAuthenticated: false,
31
+ loginCallback: function loginCallback() {}
32
+ });
33
+
34
+ // 2. 定义 Actions (作为独立函数)
35
+ export var showLoginModal = function showLoginModal(callback) {
36
+ authStore.isModalOpen = true;
37
+ authStore.loginCallback = callback;
38
+ };
39
+ export var hideLoginModal = function hideLoginModal() {
40
+ authStore.isModalOpen = false;
41
+ };
42
+ export var loginOrRegister = /*#__PURE__*/function () {
43
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
44
+ var _authStore$loginCallb;
45
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
46
+ while (1) switch (_context.prev = _context.next) {
47
+ case 0:
48
+ _context.prev = 0;
49
+ _context.next = 3;
50
+ return request.post('/api/modules/user/api/accounts/login_or_register', params);
51
+ case 3:
52
+ authStore.isAuthenticated = true;
53
+ hideLoginModal();
54
+ (_authStore$loginCallb = authStore.loginCallback) === null || _authStore$loginCallb === void 0 || _authStore$loginCallb.call(authStore);
55
+ return _context.abrupt("return", true);
56
+ case 9:
57
+ _context.prev = 9;
58
+ _context.t0 = _context["catch"](0);
59
+ console.error('Login failed in store:', _context.t0);
60
+ return _context.abrupt("return", false);
61
+ case 13:
62
+ case "end":
63
+ return _context.stop();
64
+ }
65
+ }, _callee, null, [[0, 9]]);
66
+ }));
67
+ return function loginOrRegister(_x) {
68
+ return _ref.apply(this, arguments);
69
+ };
70
+ }();
71
+ export var logout = /*#__PURE__*/function () {
72
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
73
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
74
+ while (1) switch (_context2.prev = _context2.next) {
75
+ case 0:
76
+ _context2.prev = 0;
77
+ _context2.next = 3;
78
+ return request.delete('/api/modules/user/api/accounts/logout');
79
+ case 3:
80
+ _context2.next = 8;
81
+ break;
82
+ case 5:
83
+ _context2.prev = 5;
84
+ _context2.t0 = _context2["catch"](0);
85
+ console.error('Logout failed in store:', _context2.t0);
86
+ case 8:
87
+ _context2.prev = 8;
88
+ authStore.isAuthenticated = false;
89
+ return _context2.finish(8);
90
+ case 11:
91
+ case "end":
92
+ return _context2.stop();
93
+ }
94
+ }, _callee2, null, [[0, 5, 8, 11]]);
95
+ }));
96
+ return function logout() {
97
+ return _ref2.apply(this, arguments);
98
+ };
99
+ }();
100
+ export function sendValidationCode(data) {
101
+ return request.post('/api/modules/user/api/validation_code/send', data);
102
+ }
103
+ export var initializeAuth = /*#__PURE__*/function () {
104
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
105
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
106
+ while (1) switch (_context3.prev = _context3.next) {
107
+ case 0:
108
+ _context3.prev = 0;
109
+ if (hasSkipLoginParam()) {
110
+ _context3.next = 4;
111
+ break;
112
+ }
113
+ _context3.next = 4;
114
+ return request.get('/api/modules/user/api/accounts/get_company_info');
115
+ case 4:
116
+ authStore.isAuthenticated = true;
117
+ _context3.next = 11;
118
+ break;
119
+ case 7:
120
+ _context3.prev = 7;
121
+ _context3.t0 = _context3["catch"](0);
122
+ console.error('Initialize auth failed in store:', _context3.t0);
123
+ authStore.isAuthenticated = false;
124
+ case 11:
125
+ case "end":
126
+ return _context3.stop();
127
+ }
128
+ }, _callee3, null, [[0, 7]]);
129
+ }));
130
+ return function initializeAuth() {
131
+ return _ref3.apply(this, arguments);
132
+ };
133
+ }();
@@ -10,9 +10,9 @@ import { Dropdown, Input, Modal } from 'antd';
10
10
  import { Menu } from 'antd';
11
11
  import styles from "./index.module.less";
12
12
  import { useSnapshot } from 'valtio';
13
- import { AIChatStore, handleDeleteSession, handlePinSession, handleRenameSession } from "../../../../model/AIChat";
14
- import { history } from 'dumi';
13
+ import { AIChatStore, createPureNewSession, handleDeleteSession, handlePinSession, handleRenameSession } from "../../../../model/AIChat";
15
14
  import { useSetState } from "ahooks";
15
+ import { useIntl } from 'dumi';
16
16
  export var ConversationsMenu = function ConversationsMenu() {
17
17
  var _useSetState = useSetState({
18
18
  open: false,
@@ -33,23 +33,33 @@ export var ConversationsMenu = function ConversationsMenu() {
33
33
  var toggleCollapsed = function toggleCollapsed() {
34
34
  setCollapsed(!collapsed);
35
35
  };
36
+ var _useIntl = useIntl(),
37
+ formatMessage = _useIntl.formatMessage;
36
38
  var items = [{
37
39
  key: 'fold',
38
40
  extra: !collapsed ? /*#__PURE__*/React.createElement(MenuFoldOutlined, null) : null,
39
41
  onClick: toggleCollapsed,
40
42
  label: null,
41
43
  icon: !collapsed ? null : /*#__PURE__*/React.createElement(MenuUnfoldOutlined, null),
42
- title: '展开'
44
+ title: collapsed ? formatMessage({
45
+ id: 'ai.conversations.expand'
46
+ }) : formatMessage({
47
+ id: 'ai.conversations.collapse'
48
+ })
43
49
  }, {
44
50
  key: 'new',
45
51
  icon: /*#__PURE__*/React.createElement(PlusSquareOutlined, null),
46
- label: '开始新对话',
52
+ label: formatMessage({
53
+ id: 'ai.conversations.new'
54
+ }),
47
55
  onClick: function onClick() {
48
- return history.push('/');
56
+ return createPureNewSession();
49
57
  }
50
58
  }, {
51
59
  key: 'history',
52
- label: '历史对话',
60
+ label: formatMessage({
61
+ id: 'ai.conversations.history'
62
+ }),
53
63
  icon: /*#__PURE__*/React.createElement(HistoryOutlined, null),
54
64
  children: snap.sessions.map(function (session) {
55
65
  return {
@@ -62,7 +72,9 @@ export var ConversationsMenu = function ConversationsMenu() {
62
72
  menu: {
63
73
  items: [{
64
74
  key: 'edit',
65
- label: '重命名',
75
+ label: formatMessage({
76
+ id: 'ai.conversations.rename'
77
+ }),
66
78
  icon: /*#__PURE__*/React.createElement(EditOutlined, null),
67
79
  onClick: function onClick(_ref) {
68
80
  var domEvent = _ref.domEvent;
@@ -75,7 +87,9 @@ export var ConversationsMenu = function ConversationsMenu() {
75
87
  }
76
88
  }, {
77
89
  key: 'top',
78
- label: '置顶',
90
+ label: formatMessage({
91
+ id: 'ai.conversations.pin'
92
+ }),
79
93
  icon: /*#__PURE__*/React.createElement(VerticalAlignTopOutlined, null),
80
94
  onClick: function onClick(_ref2) {
81
95
  var domEvent = _ref2.domEvent;
@@ -84,7 +98,9 @@ export var ConversationsMenu = function ConversationsMenu() {
84
98
  }
85
99
  }, {
86
100
  key: 'delete',
87
- label: '删除',
101
+ label: formatMessage({
102
+ id: 'ai.conversations.delete'
103
+ }),
88
104
  icon: /*#__PURE__*/React.createElement(DeleteOutlined, null),
89
105
  onClick: function onClick(_ref3) {
90
106
  var domEvent = _ref3.domEvent;
@@ -118,7 +134,9 @@ export var ConversationsMenu = function ConversationsMenu() {
118
134
  return handleSelectSession(key);
119
135
  }
120
136
  }), /*#__PURE__*/React.createElement(Modal, {
121
- title: "\u7F16\u8F91\u5BF9\u8BDD\u540D\u79F0",
137
+ title: formatMessage({
138
+ id: 'ai.conversations.edit.title'
139
+ }),
122
140
  open: state.open,
123
141
  centered: true,
124
142
  maskClosable: false,
@@ -132,6 +150,9 @@ export var ConversationsMenu = function ConversationsMenu() {
132
150
  return setState({
133
151
  open: false
134
152
  });
153
+ },
154
+ okButtonProps: {
155
+ disabled: !state.rename
135
156
  }
136
157
  }, /*#__PURE__*/React.createElement(Input, {
137
158
  showCount: true,
@@ -1,5 +1,6 @@
1
1
  .container {
2
2
  background: #fff;
3
+
3
4
  :global {
4
5
  .ant-menu {
5
6
  width: 16vw;
@@ -38,6 +39,7 @@
38
39
  border-radius: 50%;
39
40
  transition: background-color 0.3s ease;
40
41
  cursor: pointer;
42
+
41
43
  &:hover{
42
44
  background-color: #fbfcfd;
43
45
  }
@@ -1,14 +1,32 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ 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
+ 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
+ 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
+ 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
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
1
7
  import React from 'react';
2
8
  import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
3
9
  import { a11yLight } from "react-syntax-highlighter/dist/cjs/styles/hljs";
4
10
  import { AIChatStore } from "../../../../model/AIChat";
11
+ import { useCopyToClipboard } from "react-use";
12
+ import { CheckOutlined, CopyOutlined, PlaySquareOutlined } from "@ant-design/icons";
13
+ import { Button, Space, Tooltip } from "antd";
14
+ import styles from "./MarkdownCodeBlock.module.less";
15
+ import { useIntl } from 'dumi';
5
16
 
6
17
  // 定义 props 类型,它将接收 react-markdown 传递的所有属性
7
18
 
8
19
  export var MarkdownCodeBlock = function MarkdownCodeBlock(_ref) {
9
20
  var inline = _ref.inline,
10
21
  className = _ref.className,
11
- 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();
26
+ var _useCopyToClipboard = useCopyToClipboard(),
27
+ _useCopyToClipboard2 = _slicedToArray(_useCopyToClipboard, 2),
28
+ copyState = _useCopyToClipboard2[0],
29
+ copyToClipboard = _useCopyToClipboard2[1];
12
30
  // 1. 处理行内代码:如果是行内代码,不做特殊处理,直接返回一个 <code> 标签
13
31
  if (inline || typeof children === 'string' && !children.includes("\n")) {
14
32
  return /*#__PURE__*/React.createElement("code", {
@@ -23,8 +41,8 @@ export var MarkdownCodeBlock = function MarkdownCodeBlock(_ref) {
23
41
  // 3. 将 children 转换为字符串,并移除末尾的换行符
24
42
  var codeString = String(children).replace(/\n$/, '');
25
43
 
26
- // 4. 实现核心逻辑:判断是否显示“运行”按钮
27
- var showRunButton = codeString.trim().startsWith('import');
44
+ // 4. 判断是否显示“运行”按钮
45
+ var showRunButton = showRunButtonProp && /\bimport\b/.test(codeString);
28
46
 
29
47
  // 5. 定义运行代码的逻辑
30
48
  var handleRunCode = function handleRunCode() {
@@ -38,24 +56,33 @@ export var MarkdownCodeBlock = function MarkdownCodeBlock(_ref) {
38
56
  position: 'relative',
39
57
  margin: '1em 0'
40
58
  }
41
- }, showRunButton && /*#__PURE__*/React.createElement("button", {
42
- type: "button",
43
- onClick: handleRunCode,
44
- style: {
45
- position: 'absolute',
46
- top: '0.5em',
47
- right: '0.5em',
48
- zIndex: 1,
49
- padding: '5px 10px',
50
- border: 'none',
51
- borderRadius: '5px',
52
- backgroundColor: '#4a4a4a',
53
- color: 'white',
54
- cursor: 'pointer',
55
- fontSize: '0.8em'
59
+ }, /*#__PURE__*/React.createElement(Space, {
60
+ className: styles.button
61
+ }, /*#__PURE__*/React.createElement(Tooltip, {
62
+ title: intl.formatMessage({
63
+ id: 'ai.markdown.copy'
64
+ })
65
+ }, /*#__PURE__*/React.createElement(Button, {
66
+ variant: "link",
67
+ size: "small",
68
+ onClick: function onClick() {
69
+ return copyToClipboard(codeString);
56
70
  },
57
- title: "\u8FD0\u884C\u6B64\u4EE3\u7801\u7247\u6BB5"
58
- }, "\u8FD0\u884C"), /*#__PURE__*/React.createElement(SyntaxHighlighter, {
71
+ title: intl.formatMessage({
72
+ id: 'ai.markdown.copy'
73
+ })
74
+ }, copyState.value === codeString ? /*#__PURE__*/React.createElement(CheckOutlined, null) : /*#__PURE__*/React.createElement(CopyOutlined, null))), showRunButton && /*#__PURE__*/React.createElement(Tooltip, {
75
+ title: intl.formatMessage({
76
+ id: 'ai.markdown.run'
77
+ })
78
+ }, /*#__PURE__*/React.createElement(Button, {
79
+ variant: "link",
80
+ size: "small",
81
+ onClick: handleRunCode,
82
+ title: intl.formatMessage({
83
+ id: 'ai.markdown.run'
84
+ })
85
+ }, /*#__PURE__*/React.createElement(PlaySquareOutlined, null)))), /*#__PURE__*/React.createElement(SyntaxHighlighter, {
59
86
  style: a11yLight,
60
87
  language: language,
61
88
  PreTag: "div" // 使用 div 作为外层标签,避免 pre 标签的默认样式冲突
@@ -0,0 +1,13 @@
1
+ .button {
2
+ position: absolute;
3
+ top: 0.5em;
4
+ right: 0.5em;
5
+ z-index: 1;
6
+
7
+ button {
8
+ border: none;
9
+ border-radius: 5px;
10
+ cursor: pointer;
11
+ font-size: 0.8em;
12
+ }
13
+ }
@@ -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],
@@ -20,14 +21,16 @@ export var MarkdownComponent = function MarkdownComponent(_ref) {
20
21
  rest = _objectWithoutProperties(props, _excluded);
21
22
  return /*#__PURE__*/React.createElement("p", _extends({
22
23
  style: {
23
- marginBottom: '1em',
24
+ marginBottom: 'unset',
24
25
  lineHeight: '1.6'
25
26
  }
26
27
  }, rest));
27
28
  },
28
29
  // 2. 【核心】重写 `code` 标签的渲染,使用我们自己的组件
29
30
  code: function code(props) {
30
- return /*#__PURE__*/React.createElement(MarkdownCodeBlock, props);
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 标签