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

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 (63) hide show
  1. package/dist/builtins/Playground/index.js +1 -1
  2. package/dist/common/styles/Common.js +1 -1
  3. package/dist/common/styles/theme.js +1 -1
  4. package/dist/components/AI/HomeDialog/AntVBanner/index.js +4 -0
  5. package/dist/components/AI/HomeDialog/AntVBanner/index.module.less +35 -0
  6. package/dist/components/AI/HomeDialog/ModeSelector/index.js +29 -0
  7. package/dist/components/AI/HomeDialog/ModeSelector/index.module.less +272 -0
  8. package/dist/components/AI/HomeDialog/PromptTextarea/ChooseLib/index.js +51 -0
  9. package/dist/components/AI/HomeDialog/PromptTextarea/ChooseLib/index.module.less +5 -0
  10. package/dist/components/AI/HomeDialog/PromptTextarea/DatasourceCard/index.js +25 -0
  11. package/dist/components/AI/HomeDialog/PromptTextarea/DatasourceCard/index.module.less +42 -0
  12. package/dist/components/AI/HomeDialog/PromptTextarea/SendButton.js +23 -0
  13. package/dist/components/AI/HomeDialog/PromptTextarea/SendButton.module.less +9 -0
  14. package/dist/components/AI/HomeDialog/PromptTextarea/index.js +132 -0
  15. package/dist/components/AI/HomeDialog/PromptTextarea/index.module.less +127 -0
  16. package/dist/components/AI/HomeDialog/RecommendCase/Card.js +70 -0
  17. package/dist/components/AI/HomeDialog/RecommendCase/card.module.less +131 -0
  18. package/dist/components/AI/HomeDialog/RecommendCase/index.js +76 -0
  19. package/dist/components/AI/HomeDialog/RecommendCase/index.module.less +43 -0
  20. package/dist/components/AI/HomeDialog/RecommendCase/recommend.json +42 -0
  21. package/dist/components/AI/HomeDialog/index.js +65 -0
  22. package/dist/components/AI/HomeDialog/index.module.less +3 -0
  23. package/dist/components/AI/constant.js +35 -0
  24. package/dist/components/AI/index.js +1 -0
  25. package/dist/components/AI/types.js +1 -0
  26. package/dist/components/AI/utils.js +38 -0
  27. package/dist/hooks/useProducts.js +18 -0
  28. package/dist/hooks/useStreamingText.js +119 -0
  29. package/dist/hooks/useVisionsnapSdk.js +159 -0
  30. package/dist/layouts/DocLayout.js +0 -1
  31. package/dist/layouts/GlobalLayout/index.js +15 -0
  32. package/dist/model/AIChat.js +214 -0
  33. package/dist/pages/AIPlayground/components/ConversationsMenu/index.js +146 -0
  34. package/dist/pages/AIPlayground/components/ConversationsMenu/index.module.less +44 -0
  35. package/dist/pages/AIPlayground/components/MarkdownComponent/MarkdownCodeBlock.js +65 -0
  36. package/dist/pages/AIPlayground/components/MarkdownComponent/index.js +47 -0
  37. package/dist/pages/AIPlayground/components/MsgBox/index.js +187 -0
  38. package/dist/pages/AIPlayground/components/MsgBox/index.module.less +42 -0
  39. package/dist/pages/AIPlayground/components/SessionLayout/index.js +25 -0
  40. package/dist/pages/AIPlayground/components/SessionLayout/index.module.less +34 -0
  41. package/dist/pages/AIPlayground/components/TaskBox/generateCode.js +110 -0
  42. package/dist/pages/AIPlayground/components/TaskBox/index.js +60 -0
  43. package/dist/pages/AIPlayground/components/TaskBox/index.module.less +8 -0
  44. package/dist/pages/AIPlayground/demo.js +34 -0
  45. package/dist/pages/AIPlayground/index.js +9 -0
  46. package/dist/pages/AIPlayground/index.module.less +0 -0
  47. package/dist/pages/Index/index.js +1 -1
  48. package/dist/plugin/index.js +14 -6
  49. package/dist/slots/CodeEditor/Toolbar.js +6 -2
  50. package/dist/slots/CodeEditor/Toolbar.module.less +6 -0
  51. package/dist/slots/CodeEditor/index.js +28 -2
  52. package/dist/slots/CodeEditor/index.module.less +22 -0
  53. package/dist/{pages/Index/components → slots}/Detail/News.js +1 -1
  54. package/dist/{pages/Index/components → slots}/Detail/index.js +11 -28
  55. package/dist/{pages/Index/components → slots}/Detail/index.module.less +12 -6
  56. package/dist/slots/Header/Products/getProducts.js +20 -26
  57. package/dist/slots/Header/Products/index.js +20 -16
  58. package/dist/slots/Header/Search/SearchResult.js +35 -14
  59. package/dist/slots/Header/Search/index.js +2 -1
  60. package/dist/slots/Header/index.module.less +1 -1
  61. package/dist/typings.d.ts +5 -0
  62. package/package.json +23 -4
  63. /package/dist/{pages/Index/components → slots}/Detail/News.module.less +0 -0
@@ -0,0 +1,214 @@
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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ 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."); }
4
+ 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); }
5
+ 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; }
6
+ 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; } }
7
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
+ 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; }
9
+ 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); } }
10
+ 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); }); }; }
11
+ import { proxy, subscribe, snapshot } from 'valtio';
12
+ import { derive, subscribeKey } from 'valtio/utils';
13
+ import localforage from 'localforage';
14
+ import FingerprintJS from '@fingerprintjs/fingerprintjs';
15
+ import { history } from "dumi";
16
+
17
+ // --- 配置 ---
18
+ // 定义需要持久化的 state key
19
+ var PERSIST_KEYS = ['anonymousUserId', 'sessions'];
20
+ var STORAGE_KEY = 'ai-chat-state-v1';
21
+
22
+ // --- 初始状态 ---
23
+ var initialState = {
24
+ isInitialized: false,
25
+ anonymousUserId: null,
26
+ sessions: [],
27
+ activeSessionId: null,
28
+ tempMessage: null,
29
+ codeBlock: null
30
+ };
31
+
32
+ // --- valtio Store 创建 ---
33
+ export var AIChatStore = proxy(initialState);
34
+
35
+ // --- 持久化订阅 ---
36
+ subscribe(AIChatStore, function () {
37
+ // 确保只在初始化后才进行持久化
38
+ if (!AIChatStore.isInitialized) return;
39
+ var stateSnapshot = snapshot(AIChatStore);
40
+
41
+ // console.log('stateSnapshot', stateSnapshot);
42
+
43
+ var stateToPersist = {};
44
+ PERSIST_KEYS.forEach(function (key) {
45
+ stateToPersist[key] = stateSnapshot[key];
46
+ });
47
+
48
+ // 异步保存,不阻塞UI
49
+ localforage.setItem(STORAGE_KEY, stateToPersist);
50
+ });
51
+
52
+ // --- 初始化逻辑 ---
53
+ export var initializeStore = /*#__PURE__*/function () {
54
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
55
+ var persistedState, fp, result, newSession, _AIChatStore$sessions;
56
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
57
+ while (1) switch (_context.prev = _context.next) {
58
+ case 0:
59
+ _context.next = 2;
60
+ return localforage.getItem(STORAGE_KEY);
61
+ case 2:
62
+ persistedState = _context.sent;
63
+ // 2. 合并加载的数据到 store
64
+ if (persistedState) {
65
+ PERSIST_KEYS.forEach(function (key) {
66
+ if (persistedState[key] !== undefined) {
67
+ // @ts-ignore - Directly assigning to the proxy state
68
+ AIChatStore[key] = persistedState[key];
69
+ }
70
+ });
71
+ }
72
+
73
+ // 3. 处理初始化边缘情况
74
+ if (AIChatStore.anonymousUserId) {
75
+ _context.next = 18;
76
+ break;
77
+ }
78
+ _context.prev = 5;
79
+ _context.next = 8;
80
+ return FingerprintJS.load();
81
+ case 8:
82
+ fp = _context.sent;
83
+ _context.next = 11;
84
+ return fp.get();
85
+ case 11:
86
+ result = _context.sent;
87
+ // result.visitorId 是一个基于浏览器指纹生成的哈希值
88
+ // 例如:'d8b759e6a5b2f1c3d9e8a6f0b7c5d4a3'
89
+ AIChatStore.anonymousUserId = result.visitorId;
90
+ // console.log('FingerprintJS ID generated:', result.visitorId);
91
+ _context.next = 18;
92
+ break;
93
+ case 15:
94
+ _context.prev = 15;
95
+ _context.t0 = _context["catch"](5);
96
+ // console.error('FingerprintJS failed, falling back to simple ID:', error);
97
+ // 如果指纹生成失败(例如被浏览器插件阻止),回退到一个简单方案
98
+ // 如果需要兼容旧浏览器,可以换成 `import { v4 as uuidv4 } from 'uuid';` 和 `uuidv4()`
99
+ AIChatStore.anonymousUserId = crypto.randomUUID();
100
+ case 18:
101
+ if (AIChatStore.sessions.length === 0) {
102
+ newSession = {
103
+ id: crypto.randomUUID(),
104
+ title: 'New Conversation',
105
+ createdAt: Date.now(),
106
+ messages: []
107
+ };
108
+ AIChatStore.sessions.push(newSession);
109
+ AIChatStore.activeSessionId = newSession.id;
110
+ }
111
+ if (!AIChatStore.activeSessionId || !AIChatStore.sessions.find(function (s) {
112
+ return s.id === AIChatStore.activeSessionId;
113
+ })) {
114
+ AIChatStore.activeSessionId = ((_AIChatStore$sessions = AIChatStore.sessions[0]) === null || _AIChatStore$sessions === void 0 ? void 0 : _AIChatStore$sessions.id) || null;
115
+ }
116
+
117
+ // 4. 标记初始化完成,这将触发持久化订阅
118
+ AIChatStore.isInitialized = true;
119
+ // console.log('Valtio store initialized:', snapshot(AIChatStore));
120
+ case 21:
121
+ case "end":
122
+ return _context.stop();
123
+ }
124
+ }, _callee, null, [[5, 15]]);
125
+ }));
126
+ return function initializeStore() {
127
+ return _ref.apply(this, arguments);
128
+ };
129
+ }();
130
+
131
+ // --- 计算属性 (使用 derive) ---
132
+ export var derivedState = derive({
133
+ // 获取当前激活的会话对象
134
+ activeSession: function activeSession(get) {
135
+ var _get = get(AIChatStore),
136
+ sessions = _get.sessions,
137
+ activeSessionId = _get.activeSessionId;
138
+ if (!activeSessionId) return null;
139
+ return sessions.find(function (s) {
140
+ return s.id === activeSessionId;
141
+ }) || null;
142
+ }
143
+ });
144
+
145
+ // --- 删除会话 ---
146
+ export var handleDeleteSession = function handleDeleteSession(sessionId) {
147
+ var sessionIndex = AIChatStore.sessions.findIndex(function (s) {
148
+ return s.id === sessionId;
149
+ });
150
+ if (sessionIndex === -1) return;
151
+
152
+ // 从数组中移除
153
+ AIChatStore.sessions.splice(sessionIndex, 1);
154
+
155
+ // 如果删除的是当前激活的会话,需要重置 activeSessionId
156
+ if (AIChatStore.activeSessionId === sessionId) {
157
+ var _AIChatStore$sessions2;
158
+ AIChatStore.activeSessionId = ((_AIChatStore$sessions2 = AIChatStore.sessions[0]) === null || _AIChatStore$sessions2 === void 0 ? void 0 : _AIChatStore$sessions2.id) || null;
159
+ }
160
+ };
161
+
162
+ // --- 重命名会话 ---
163
+ export var handleRenameSession = function handleRenameSession(sessionId, newTitle) {
164
+ var session = AIChatStore.sessions.find(function (s) {
165
+ return s.id === sessionId;
166
+ });
167
+ if (session) {
168
+ session.title = newTitle;
169
+ }
170
+ };
171
+
172
+ // --- 置顶会话 ---
173
+ export var handlePinSession = function handlePinSession(sessionId) {
174
+ var sessionIndex = AIChatStore.sessions.findIndex(function (s) {
175
+ return s.id === sessionId;
176
+ });
177
+ if (sessionIndex <= 0) return; // 如果找不到或者已经在第一位,则不操作
178
+
179
+ // 找到会话,从原位置删除,然后添加到数组头部
180
+ var _AIChatStore$sessions3 = AIChatStore.sessions.splice(sessionIndex, 1),
181
+ _AIChatStore$sessions4 = _slicedToArray(_AIChatStore$sessions3, 1),
182
+ sessionToPin = _AIChatStore$sessions4[0];
183
+ AIChatStore.sessions.unshift(sessionToPin);
184
+
185
+ // (可选)置顶后自动激活该会话
186
+ AIChatStore.activeSessionId = sessionId;
187
+ };
188
+ subscribeKey(AIChatStore, 'activeSessionId', function () {
189
+ AIChatStore.codeBlock = null;
190
+ });
191
+ export var createNewSession = function createNewSession(config) {
192
+ // todo 埋点
193
+ // 1. 创建一个新的会话
194
+ var newSessionId = crypto.randomUUID();
195
+ AIChatStore.sessions.unshift({
196
+ id: newSessionId,
197
+ title: config.promptText.substring(0, 20),
198
+ // 使用输入内容作为初始标题
199
+ createdAt: Date.now(),
200
+ messages: []
201
+ });
202
+ AIChatStore.activeSessionId = newSessionId;
203
+
204
+ // 2. 创建临时消息并存入 store
205
+ AIChatStore.tempMessage = {
206
+ id: crypto.randomUUID(),
207
+ role: 'user',
208
+ content: config.promptText,
209
+ createdAt: Date.now(),
210
+ mode: config.mode,
211
+ lib: config.lib
212
+ };
213
+ history.push("/zh/ai-playground/2");
214
+ };
@@ -0,0 +1,146 @@
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; }
7
+ import React, { useState } from 'react';
8
+ import { DeleteOutlined, EditOutlined, EllipsisOutlined, HistoryOutlined, MenuFoldOutlined, MenuUnfoldOutlined, PlusSquareOutlined, VerticalAlignTopOutlined } from '@ant-design/icons';
9
+ import { Dropdown, Input, Modal } from 'antd';
10
+ import { Menu } from 'antd';
11
+ import styles from "./index.module.less";
12
+ import { useSnapshot } from 'valtio';
13
+ import { AIChatStore, handleDeleteSession, handlePinSession, handleRenameSession } from "../../../../model/AIChat";
14
+ import { history } from 'dumi';
15
+ import { useSetState } from "ahooks";
16
+ export var ConversationsMenu = function ConversationsMenu() {
17
+ var _useSetState = useSetState({
18
+ open: false,
19
+ session: null,
20
+ rename: ''
21
+ }),
22
+ _useSetState2 = _slicedToArray(_useSetState, 2),
23
+ state = _useSetState2[0],
24
+ setState = _useSetState2[1];
25
+ var _useState = useState(false),
26
+ _useState2 = _slicedToArray(_useState, 2),
27
+ collapsed = _useState2[0],
28
+ setCollapsed = _useState2[1];
29
+ var snap = useSnapshot(AIChatStore);
30
+ var handleSelectSession = function handleSelectSession(sessionId) {
31
+ AIChatStore.activeSessionId = sessionId;
32
+ };
33
+ var toggleCollapsed = function toggleCollapsed() {
34
+ setCollapsed(!collapsed);
35
+ };
36
+ var items = [{
37
+ key: 'fold',
38
+ extra: !collapsed ? /*#__PURE__*/React.createElement(MenuFoldOutlined, null) : null,
39
+ onClick: toggleCollapsed,
40
+ label: null,
41
+ icon: !collapsed ? null : /*#__PURE__*/React.createElement(MenuUnfoldOutlined, null),
42
+ title: '展开'
43
+ }, {
44
+ key: 'new',
45
+ icon: /*#__PURE__*/React.createElement(PlusSquareOutlined, null),
46
+ label: '开始新对话',
47
+ onClick: function onClick() {
48
+ return history.push('/');
49
+ }
50
+ }, {
51
+ key: 'history',
52
+ label: '历史对话',
53
+ icon: /*#__PURE__*/React.createElement(HistoryOutlined, null),
54
+ children: snap.sessions.map(function (session) {
55
+ return {
56
+ key: session.id,
57
+ label: /*#__PURE__*/React.createElement("div", {
58
+ className: styles.menuItem
59
+ }, /*#__PURE__*/React.createElement("span", {
60
+ className: styles.title
61
+ }, session.title), /*#__PURE__*/React.createElement(Dropdown, {
62
+ menu: {
63
+ items: [{
64
+ key: 'edit',
65
+ label: '重命名',
66
+ icon: /*#__PURE__*/React.createElement(EditOutlined, null),
67
+ onClick: function onClick(_ref) {
68
+ var domEvent = _ref.domEvent;
69
+ domEvent.stopPropagation();
70
+ setState({
71
+ open: true,
72
+ session: session,
73
+ rename: session.title
74
+ });
75
+ }
76
+ }, {
77
+ key: 'top',
78
+ label: '置顶',
79
+ icon: /*#__PURE__*/React.createElement(VerticalAlignTopOutlined, null),
80
+ onClick: function onClick(_ref2) {
81
+ var domEvent = _ref2.domEvent;
82
+ domEvent.stopPropagation();
83
+ handlePinSession(session.id);
84
+ }
85
+ }, {
86
+ key: 'delete',
87
+ label: '删除',
88
+ icon: /*#__PURE__*/React.createElement(DeleteOutlined, null),
89
+ onClick: function onClick(_ref3) {
90
+ var domEvent = _ref3.domEvent;
91
+ domEvent.stopPropagation();
92
+ handleDeleteSession(session.id);
93
+ }
94
+ }]
95
+ },
96
+ trigger: ['click']
97
+ }, /*#__PURE__*/React.createElement("span", {
98
+ className: styles.iconWrapper,
99
+ onClick: function onClick(e) {
100
+ e.preventDefault();
101
+ e.stopPropagation();
102
+ }
103
+ }, /*#__PURE__*/React.createElement(EllipsisOutlined, null))))
104
+ };
105
+ })
106
+ }];
107
+ return /*#__PURE__*/React.createElement("div", {
108
+ className: styles.container
109
+ }, /*#__PURE__*/React.createElement(Menu, {
110
+ selectedKeys: [snap.activeSessionId],
111
+ defaultOpenKeys: ['history'],
112
+ mode: "inline",
113
+ theme: "light",
114
+ inlineCollapsed: collapsed,
115
+ items: items,
116
+ onSelect: function onSelect(_ref4) {
117
+ var key = _ref4.key;
118
+ return handleSelectSession(key);
119
+ }
120
+ }), /*#__PURE__*/React.createElement(Modal, {
121
+ title: "\u7F16\u8F91\u5BF9\u8BDD\u540D\u79F0",
122
+ open: state.open,
123
+ centered: true,
124
+ maskClosable: false,
125
+ onOk: function onOk() {
126
+ handleRenameSession(state.session.id, state.rename);
127
+ setState({
128
+ open: false
129
+ });
130
+ },
131
+ onCancel: function onCancel() {
132
+ return setState({
133
+ open: false
134
+ });
135
+ }
136
+ }, /*#__PURE__*/React.createElement(Input, {
137
+ showCount: true,
138
+ maxLength: 20,
139
+ onChange: function onChange(e) {
140
+ return setState({
141
+ rename: e.target.value
142
+ });
143
+ },
144
+ value: state.rename
145
+ })));
146
+ };
@@ -0,0 +1,44 @@
1
+ .container {
2
+ background: #fff;
3
+ :global {
4
+ .ant-menu {
5
+ width: 16vw;
6
+ min-width: 200px;
7
+ height: 100%;
8
+ overflow-y: auto;
9
+ overflow-x: hidden;
10
+ }
11
+
12
+ .ant-menu-inline-collapsed{
13
+ width: 80px;
14
+ min-width: 80px;
15
+ }
16
+ }
17
+ }
18
+
19
+ .title {
20
+ width: 200px;
21
+ overflow: hidden;
22
+ white-space: nowrap;
23
+ text-overflow: ellipsis;
24
+ }
25
+
26
+ .menuItem{
27
+ display: flex;
28
+ justify-content: space-between;
29
+ }
30
+
31
+ .iconWrapper{
32
+ display: inline-flex;
33
+ align-items: center;
34
+ justify-content: center;
35
+ width: 20px;
36
+ height: 20px;
37
+ margin-top: 10px;
38
+ border-radius: 50%;
39
+ transition: background-color 0.3s ease;
40
+ cursor: pointer;
41
+ &:hover{
42
+ background-color: #fbfcfd;
43
+ }
44
+ }
@@ -0,0 +1,65 @@
1
+ import React from 'react';
2
+ import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
3
+ import { a11yLight } from "react-syntax-highlighter/dist/cjs/styles/hljs";
4
+ import { AIChatStore } from "../../../../model/AIChat";
5
+
6
+ // 定义 props 类型,它将接收 react-markdown 传递的所有属性
7
+
8
+ export var MarkdownCodeBlock = function MarkdownCodeBlock(_ref) {
9
+ var inline = _ref.inline,
10
+ className = _ref.className,
11
+ children = _ref.children;
12
+ // 1. 处理行内代码:如果是行内代码,不做特殊处理,直接返回一个 <code> 标签
13
+ if (inline || typeof children === 'string' && !children.includes("\n")) {
14
+ return /*#__PURE__*/React.createElement("code", {
15
+ className: className
16
+ }, children);
17
+ }
18
+
19
+ // 2. 提取语言:从 className 中提取代码语言,例如 "language-javascript" -> "javascript"
20
+ var match = /language-(\w+)/.exec(className || '');
21
+ var language = match ? match[1] : 'text'; // 如果没有指定语言,默认为纯文本
22
+
23
+ // 3. 将 children 转换为字符串,并移除末尾的换行符
24
+ var codeString = String(children).replace(/\n$/, '');
25
+
26
+ // 4. 实现核心逻辑:判断是否显示“运行”按钮
27
+ var showRunButton = codeString.trim().startsWith('import');
28
+
29
+ // 5. 定义运行代码的逻辑
30
+ var handleRunCode = function handleRunCode() {
31
+ // console.log("准备运行的代码:", codeString);
32
+ AIChatStore.codeBlock = codeString;
33
+ };
34
+
35
+ // 6. 返回最终的 JSX 结构
36
+ return /*#__PURE__*/React.createElement("div", {
37
+ style: {
38
+ position: 'relative',
39
+ margin: '1em 0'
40
+ }
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'
56
+ },
57
+ title: "\u8FD0\u884C\u6B64\u4EE3\u7801\u7247\u6BB5"
58
+ }, "\u8FD0\u884C"), /*#__PURE__*/React.createElement(SyntaxHighlighter, {
59
+ style: a11yLight,
60
+ language: language,
61
+ PreTag: "div" // 使用 div 作为外层标签,避免 pre 标签的默认样式冲突
62
+ ,
63
+ showLineNumbers: false // (可选) 显示行号
64
+ }, codeString));
65
+ };
@@ -0,0 +1,47 @@
1
+ var _excluded = ["node"];
2
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
4
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
5
+ import React from 'react';
6
+ import Markdown from 'react-markdown';
7
+ import rehypeRaw from 'rehype-raw';
8
+ import remarkGfm from 'remark-gfm';
9
+ import { MarkdownCodeBlock } from "./MarkdownCodeBlock"; // 引入我们创建的自定义组件
10
+
11
+ export var MarkdownComponent = function MarkdownComponent(_ref) {
12
+ var content = _ref.content;
13
+ return /*#__PURE__*/React.createElement(Markdown, {
14
+ remarkPlugins: [remarkGfm],
15
+ rehypePlugins: [rehypeRaw],
16
+ components: {
17
+ // 1. 重写 `p` 标签的渲染
18
+ p: function p(props) {
19
+ var node = props.node,
20
+ rest = _objectWithoutProperties(props, _excluded);
21
+ return /*#__PURE__*/React.createElement("p", _extends({
22
+ style: {
23
+ marginBottom: '1em',
24
+ lineHeight: '1.6'
25
+ }
26
+ }, rest));
27
+ },
28
+ // 2. 【核心】重写 `code` 标签的渲染,使用我们自己的组件
29
+ code: function code(props) {
30
+ return /*#__PURE__*/React.createElement(MarkdownCodeBlock, props);
31
+ },
32
+ // 3. 重写非标准 `description` 标签的渲染
33
+ // @ts-expect-error - 告知 TypeScript 我们知道这是一个自定义的、非标准的 HTML 标签
34
+ description: function description(props) {
35
+ return /*#__PURE__*/React.createElement("span", _extends({
36
+ style: {
37
+ fontSize: '12px',
38
+ color: '#777',
39
+ display: 'block'
40
+ }
41
+ }, props));
42
+ } // 你还可以重写更多...
43
+ // h1: (props) => <h1 style={{ color: 'blue' }} {...props} />,
44
+ // a: (props) => <a style={{ color: 'green' }} target="_blank" rel="noopener noreferrer" {...props} />,
45
+ }
46
+ }, content);
47
+ };