@antv/dumi-theme-antv 0.7.10 → 0.8.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builtins/Playground/index.js +1 -1
- package/dist/builtins/Playground/index.module.less +0 -1
- package/dist/common/styles/Common.js +1 -1
- package/dist/common/styles/theme.js +1 -1
- package/dist/components/AI/HomeDialog/AntVBanner/index.js +4 -0
- package/dist/components/AI/HomeDialog/AntVBanner/index.module.less +35 -0
- package/dist/components/AI/HomeDialog/ModeSelector/ModeSelectorDropdown.js +42 -0
- package/dist/components/AI/HomeDialog/ModeSelector/index.js +32 -0
- package/dist/components/AI/HomeDialog/ModeSelector/index.module.less +289 -0
- package/dist/components/AI/HomeDialog/PromptTextarea/ChooseLib/index.js +62 -0
- package/dist/components/AI/HomeDialog/PromptTextarea/ChooseLib/index.module.less +4 -0
- package/dist/components/AI/HomeDialog/PromptTextarea/DatasourceCard/index.js +25 -0
- package/dist/components/AI/HomeDialog/PromptTextarea/DatasourceCard/index.module.less +42 -0
- package/dist/components/AI/HomeDialog/PromptTextarea/SendButton.js +23 -0
- package/dist/components/AI/HomeDialog/PromptTextarea/SendButton.module.less +9 -0
- package/dist/components/AI/HomeDialog/PromptTextarea/Uploader/DataUploader.js +225 -0
- package/dist/components/AI/HomeDialog/PromptTextarea/index.js +172 -0
- package/dist/components/AI/HomeDialog/PromptTextarea/index.module.less +128 -0
- package/dist/components/AI/HomeDialog/RecommendCase/Card.js +80 -0
- package/dist/components/AI/HomeDialog/RecommendCase/card.module.less +131 -0
- package/dist/components/AI/HomeDialog/RecommendCase/index.js +130 -0
- package/dist/components/AI/HomeDialog/RecommendCase/index.module.less +45 -0
- package/dist/components/AI/HomeDialog/RecommendCase/recommend.json +66 -0
- package/dist/components/AI/HomeDialog/index.js +62 -0
- package/dist/components/AI/HomeDialog/index.module.less +3 -0
- package/dist/components/AI/constant.js +37 -0
- package/dist/components/AI/index.js +1 -0
- package/dist/components/AI/types.js +1 -0
- package/dist/components/AI/utils.js +38 -0
- package/dist/components/Login/Captcha/index.js +185 -0
- package/dist/components/Login/Captcha/index.less +91 -0
- package/dist/components/Login/CheckCode/index.js +244 -0
- package/dist/components/Login/CheckCode/index.less +137 -0
- package/dist/components/Login/CountDownButton/index.js +109 -0
- package/dist/components/Login/CountDownButton/index.less +8 -0
- package/dist/components/Login/LoginForm.js +239 -0
- package/dist/components/Login/LoginForm.less +408 -0
- package/dist/components/Login/index.js +24 -0
- package/dist/components/Login/openAuthWindow.js +54 -0
- package/dist/components/Login/types.js +5 -0
- package/dist/components/Login/utils.js +47 -0
- package/dist/hooks/useProducts.js +39 -0
- package/dist/hooks/useStreamingText.js +139 -0
- package/dist/hooks/useTypewriter.js +69 -0
- package/dist/hooks/useVisionsnapSdk.js +159 -0
- package/dist/layouts/DocLayout.js +2 -2
- package/dist/layouts/GlobalLayout/index.js +22 -0
- package/dist/locales/en.json +132 -1
- package/dist/locales/zh.json +132 -1
- package/dist/model/AIChat.js +313 -0
- package/dist/model/auth.js +147 -0
- package/dist/pages/AIPlayground/components/ConversationsMenu/index.js +176 -0
- package/dist/pages/AIPlayground/components/ConversationsMenu/index.module.less +46 -0
- package/dist/pages/AIPlayground/components/MarkdownComponent/MarkdownCodeBlock.js +97 -0
- package/dist/pages/AIPlayground/components/MarkdownComponent/MarkdownCodeBlock.module.less +13 -0
- package/dist/pages/AIPlayground/components/MarkdownComponent/index.js +50 -0
- package/dist/pages/AIPlayground/components/MsgBox/index.js +407 -0
- package/dist/pages/AIPlayground/components/MsgBox/index.module.less +43 -0
- package/dist/pages/AIPlayground/components/MsgBox/useAutoScroll.js +46 -0
- package/dist/pages/AIPlayground/components/SessionLayout/index.js +62 -0
- package/dist/pages/AIPlayground/components/SessionLayout/index.module.less +37 -0
- package/dist/pages/AIPlayground/components/TaskBox/generateCode.js +230 -0
- package/dist/pages/AIPlayground/components/TaskBox/index.js +101 -0
- package/dist/pages/AIPlayground/components/TaskBox/index.module.less +9 -0
- package/dist/pages/AIPlayground/demo.js +34 -0
- package/dist/pages/AIPlayground/index.js +12 -0
- package/dist/pages/AIPlayground/index.module.less +5 -0
- package/dist/pages/Examples/components/Accouncement/index.module.less +1 -1
- package/dist/pages/Examples/index.module.less +11 -11
- package/dist/pages/Index/components/Cases/index.module.less +8 -8
- package/dist/pages/Index/components/Companies/index.module.less +4 -3
- package/dist/pages/Index/components/Features/FeatureCard.module.less +4 -5
- package/dist/pages/Index/components/Features/index.module.less +5 -5
- package/dist/pages/Index/components/_.less +9 -9
- package/dist/pages/Index/index.js +1 -1
- package/dist/plugin/index.js +14 -6
- package/dist/slots/Banner/Notification.module.less +8 -8
- package/dist/slots/Banner/index.module.less +10 -9
- package/dist/slots/CodeEditor/Toolbar.js +23 -27
- package/dist/slots/CodeEditor/Toolbar.module.less +7 -0
- package/dist/slots/CodeEditor/index.js +67 -5
- package/dist/slots/CodeEditor/index.module.less +24 -0
- package/dist/slots/CodeEditor/utils.js +2 -1
- package/dist/slots/CodePreview/index.module.less +0 -3
- package/dist/slots/CodeRunner/index.js +24 -11
- package/dist/slots/ContentTable/index.module.less +2 -1
- package/dist/{pages/Index/components → slots}/Detail/News.js +1 -1
- package/dist/{pages/Index/components → slots}/Detail/News.module.less +9 -9
- package/dist/{pages/Index/components → slots}/Detail/index.js +13 -29
- package/dist/{pages/Index/components → slots}/Detail/index.module.less +23 -20
- package/dist/slots/ExampleSider/index.module.less +3 -4
- package/dist/slots/Footer/index.module.less +2 -2
- package/dist/slots/Header/Products/Product.module.less +2 -2
- package/dist/slots/Header/Products/getProducts.js +20 -26
- package/dist/slots/Header/Products/index.js +20 -16
- package/dist/slots/Header/Search/SearchResult.js +53 -14
- package/dist/slots/Header/Search/SearchResult.module.less +1 -0
- package/dist/slots/Header/Search/index.js +2 -1
- package/dist/slots/Header/index.js +72 -30
- package/dist/slots/Header/index.module.less +14 -6
- package/dist/slots/LiveExample/index.js +1 -1
- package/dist/slots/LiveExample/index.module.less +1 -1
- package/dist/slots/Loading/index.module.less +30 -28
- package/dist/slots/ManualContent/index.module.less +14 -17
- package/dist/slots/_.less +9 -9
- package/dist/static/user.svg +3 -0
- package/dist/typings.d.ts +11 -0
- package/dist/utils/analytics.js +16 -0
- package/dist/utils/code.js +35 -0
- package/dist/utils/env.js +63 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/request.js +42 -0
- package/package.json +31 -15
package/dist/locales/zh.json
CHANGED
|
@@ -177,5 +177,136 @@
|
|
|
177
177
|
"企业级 Node 开发框架": "企业级 Node 开发框架",
|
|
178
178
|
"Sketch 工具集": "Sketch 工具集",
|
|
179
179
|
"互动图形解决方案": "互动图形解决方案",
|
|
180
|
-
"前端智能研发": "前端智能研发"
|
|
180
|
+
"前端智能研发": "前端智能研发",
|
|
181
|
+
"ai.placeholder.implement": "今天,你想可视化什么?",
|
|
182
|
+
"ai.placeholder.solve": "今天,你想解决什么可视化问题?",
|
|
183
|
+
"ai.mode.implement": "可视化研发",
|
|
184
|
+
"ai.mode.implement.short": "研发",
|
|
185
|
+
"ai.mode.solve": "可视化答疑",
|
|
186
|
+
"ai.mode.solve.short": "答疑",
|
|
187
|
+
"ai.upload.tooltip": "仅支持csv,json,tsv,txt文件,为了性能和成本,只会使用文件的前几行作为样本",
|
|
188
|
+
"ai.upload.data": "上传数据",
|
|
189
|
+
"ai.upload.image": "上传图片",
|
|
190
|
+
"ai.upload.analyzing": "分析中...",
|
|
191
|
+
"ai.upload.file.empty": "文件为空。",
|
|
192
|
+
"ai.upload.file.parse.error": "文件内容格式错误,无法解析。",
|
|
193
|
+
"ai.upload.file.read.error": "读取文件失败。",
|
|
194
|
+
"ai.upload.file.type.error": "不支持的文件类型。请上传 {types} 文件。",
|
|
195
|
+
"ai.upload.file.size.error": "文件大小不能超过 {size}MB!",
|
|
196
|
+
"ai.upload.file.parse.type.error": "不支持的文件解析类型",
|
|
197
|
+
"ai.upload.file.summary.truncated": "... (数据摘要已截断)",
|
|
198
|
+
"ai.upload.file.full.content": "用户上传了一个数据文件,其完整内容如下:\n\n{fileContent}",
|
|
199
|
+
"ai.upload.file.table.summary": "这是一个包含约 {rowCount} 行和 {columnCount} 列的表格数据。\n列名(Header)是: {header}\n前{maxLines}行样本数据如下:\n{sampleRows}",
|
|
200
|
+
"ai.upload.file.json.array.summary": "这是一个包含 {dataLength} 个对象的JSON数组。\n每个对象的键(Keys)是: {keys}\n前{maxLines}个样本对象如下:\n{sampleData}",
|
|
201
|
+
"ai.upload.file.json.object.summary": "这是一个JSON对象。其结构和部分数据如下:",
|
|
202
|
+
"ai.msgbox.like": "点赞",
|
|
203
|
+
"ai.msgbox.dislike": "点踩",
|
|
204
|
+
"ai.msgbox.retry": "再来一次",
|
|
205
|
+
"ai.msgbox.copy": "复制",
|
|
206
|
+
"ai.msgbox.start.new.chat": "开始新对话",
|
|
207
|
+
"ai.msgbox.send.tip": "请输入内容后发送指令",
|
|
208
|
+
"ai.msgbox.error.response": "抱歉,我没能成功处理您的请求,请稍后再次提问",
|
|
209
|
+
"ai.recommend.title": "精选案例",
|
|
210
|
+
"ai.recommend.refresh": "换一批",
|
|
211
|
+
"ai.recommend.card.caseName": "案例名",
|
|
212
|
+
"ai.recommend.card.description": "描述信息",
|
|
213
|
+
"ai.markdown.copy": "复制",
|
|
214
|
+
"ai.markdown.run": "运行此代码片段",
|
|
215
|
+
"ai.toolbar.assistant": "AI 助手",
|
|
216
|
+
"ai.toolbar.restore": "还原",
|
|
217
|
+
"ai.toolbar.execute": "执行代码",
|
|
218
|
+
"ai.toolbar.open.codesandbox": "在 CodeSandbox 中打开",
|
|
219
|
+
"ai.toolbar.open.stackblitz": "在 StackBlitz 中打开",
|
|
220
|
+
"ai.toolbar.open.riddle": "在 Riddle 中打开",
|
|
221
|
+
"ai.toolbar.html.code": "HTML 代码",
|
|
222
|
+
"ai.toolbar.clear.conversation": "清空对话",
|
|
223
|
+
"ai.conversations.expand": "展开",
|
|
224
|
+
"ai.conversations.collapse": "收起",
|
|
225
|
+
"ai.msgbox.continue.from.here": "从这里继续",
|
|
226
|
+
"ai.conversations.new": "开始新对话",
|
|
227
|
+
"ai.conversations.history": "历史对话",
|
|
228
|
+
"ai.conversations.rename": "重命名",
|
|
229
|
+
"ai.conversations.pin": "置顶",
|
|
230
|
+
"ai.conversations.delete": "删除",
|
|
231
|
+
"ai.conversations.edit.title": "编辑对话名称",
|
|
232
|
+
"ai.conversations.ok": "确定",
|
|
233
|
+
"ai.conversations.cancel": "取消",
|
|
234
|
+
"ai.msgbox.delete": "删除",
|
|
235
|
+
"ai.msgbox.auto.fix": "自动修复",
|
|
236
|
+
"ai.msgbox.auto.fix.prompt": "这个代码在执行时遇到了问题。下面是它抛出的确切错误信息。",
|
|
237
|
+
"ai.chooseLib.placeholder": "选择技术栈",
|
|
238
|
+
"ai.search.try": "试试",
|
|
239
|
+
"ai.search.visualization": "可视化答疑",
|
|
240
|
+
"ai.assistant.editor.intro": "我是AntV AI助手。您可以随时向我提问,让我为您:\n\n1、解读当前图表的代码配置。\n2、通过自然语言对话,基于当前案例生成新代码以定制图表。",
|
|
241
|
+
"ai.placeholder.whatis": "{title}是什么?",
|
|
242
|
+
"header.user.history": "历史会话",
|
|
243
|
+
"header.user.logout": "退出登录",
|
|
244
|
+
"header.user.deleteAccount": "注销账号",
|
|
245
|
+
"header.china.mirror.title": "AntV 系列网站部署在 gh-pages 上,若访问速度不佳,可以前往国内镜像站点。",
|
|
246
|
+
"header.china.mirror.temp.close": "暂时关闭",
|
|
247
|
+
"header.china.mirror.no.more": "不再提醒",
|
|
248
|
+
"header.wx.qrcode.title": "微信扫一扫关注",
|
|
249
|
+
"feedback.page.helpful": "这个页面对你有帮助吗?",
|
|
250
|
+
"feedback.page.easy.understand": "容易理解",
|
|
251
|
+
"feedback.page.solved.problem": "解决了我的问题",
|
|
252
|
+
"feedback.page.other": "其它",
|
|
253
|
+
"feedback.page.missing.info": "缺少我需要的信息",
|
|
254
|
+
"feedback.page.too.complex": "过于复杂/步骤太多",
|
|
255
|
+
"feedback.page.outdated": "内容更新不及时",
|
|
256
|
+
"feedback.page.code.issue": "示例/代码有问题",
|
|
257
|
+
"feedback.page.reason.title": "🚀 留下你的真实感受",
|
|
258
|
+
"feedback.page.issue.alert": "如果遇到问题或发现某些功能无法正常工作,请通过",
|
|
259
|
+
"feedback.page.issue.report": "提交问题报告",
|
|
260
|
+
"feedback.page.issue.alert.end": "来反馈。否则,团队将无法提供进一步的答复或获取更多信息。",
|
|
261
|
+
"feedback.section.improve": "你认为",
|
|
262
|
+
"feedback.section.improve.end": "部分如何改进更好?",
|
|
263
|
+
"feedback.result.success": "谢谢你的反馈意见!",
|
|
264
|
+
"feedback.result.error": "报错了,请稍后再试",
|
|
265
|
+
"feedback.result.thanks": "感谢你的支持!",
|
|
266
|
+
"feedback.result.github.issue": "如果问题持续,请前往 GitHub 提交 issue。",
|
|
267
|
+
"feedback.result.problem.type": "你遇到的问题是什么?",
|
|
268
|
+
"feedback.result.reason": "🚀 留下你的真实感受",
|
|
269
|
+
"feedback.result.easy.understand": "容易理解",
|
|
270
|
+
"feedback.result.solved.problem": "有效解决了我的问题",
|
|
271
|
+
"feedback.result.other": "其它",
|
|
272
|
+
"feedback.result.missing.info": "缺少我需要的信息",
|
|
273
|
+
"feedback.result.too.complex": "过于复杂/步骤太多",
|
|
274
|
+
"feedback.result.outdated": "内容更新不及时",
|
|
275
|
+
"feedback.result.code.issue": "示例/代码有问题",
|
|
276
|
+
"feedback.result.previous": "上一篇",
|
|
277
|
+
"feedback.result.next": "下一篇",
|
|
278
|
+
"feedback.result.demo.error": "演示代码报错,请检查",
|
|
279
|
+
"feedback.result.reading.time": "阅读时间约",
|
|
280
|
+
"feedback.result.minutes": "分钟",
|
|
281
|
+
"feedback.result.no.results": "没有找到查询结果",
|
|
282
|
+
"login.user.protocol.title": "用户协议 ",
|
|
283
|
+
"login.user.protocol.content": "为更好地保护你的合法权益,请阅读并同意 WeaveFox ",
|
|
284
|
+
"login.user.protocol.link": "用户协议 ",
|
|
285
|
+
"login.protocol.agree": "同意",
|
|
286
|
+
"login.protocol.disagree": "不同意",
|
|
287
|
+
"login.placeholder.phone": "请输入手机号",
|
|
288
|
+
"login.placeholder.phone.or.email": "请输入手机号或邮箱",
|
|
289
|
+
"login.error.invalid.phone": "请输入正确的手机号",
|
|
290
|
+
"login.error.invalid.phone.or.email": "请输入正确的手机号或邮箱",
|
|
291
|
+
"login.button.login.or.register": "登录 / 注册",
|
|
292
|
+
"login.protocol.read.agree": "我已阅读并同意 AntV ",
|
|
293
|
+
"login.protocol.link": "用户协议 ",
|
|
294
|
+
"login.link.home": "返回首页",
|
|
295
|
+
"login.checkcode.get": "获取验证码",
|
|
296
|
+
"login.checkcode.send.success": "验证码发送成功",
|
|
297
|
+
"login.checkcode.error.incomplete": "先完成滑块验证",
|
|
298
|
+
"login.checkcode.sent": "已发送验证码",
|
|
299
|
+
"login.checkcode.required": "验证码不能为空",
|
|
300
|
+
"login.checkcode.invalid": "请输入有效的 6 位数字验证码",
|
|
301
|
+
"login.checkcode.placeholder": "6 位验证码",
|
|
302
|
+
"login.countdown.resend": "重新获取({time})",
|
|
303
|
+
"login.countdown.resend.simple": "重新获取",
|
|
304
|
+
"login.captcha.drag": "按住滑块,拖动到最右边",
|
|
305
|
+
"login.captcha.success": "验证通过",
|
|
306
|
+
"login.captcha.loading": "加载中",
|
|
307
|
+
"login.captcha.error.wrong": "哎呀,出错了,单击",
|
|
308
|
+
"login.captcha.error.network": "网络不给力,单击",
|
|
309
|
+
"login.captcha.error.refresh": "刷新",
|
|
310
|
+
"login.captcha.required": "拖动滑块验证",
|
|
311
|
+
"login.modal.title": "验证码登录"
|
|
181
312
|
}
|
|
@@ -0,0 +1,313 @@
|
|
|
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
|
+
import { message } from "antd";
|
|
17
|
+
import { AIMode } from "../components/AI/constant";
|
|
18
|
+
import { trackEvent } from "../utils/analytics";
|
|
19
|
+
|
|
20
|
+
// --- 配置 ---
|
|
21
|
+
// 定义需要持久化的 state key
|
|
22
|
+
var PERSIST_KEYS = ['anonymousUserId', 'sessions'];
|
|
23
|
+
var STORAGE_KEY = 'ai-chat-state-v1';
|
|
24
|
+
|
|
25
|
+
// --- 初始状态 ---
|
|
26
|
+
var initialState = {
|
|
27
|
+
isInitialized: false,
|
|
28
|
+
anonymousUserId: null,
|
|
29
|
+
sessions: [],
|
|
30
|
+
activeSessionId: null,
|
|
31
|
+
tempMessage: null,
|
|
32
|
+
codeBlock: null,
|
|
33
|
+
lib: null,
|
|
34
|
+
mode: AIMode.implement,
|
|
35
|
+
errorMsg: null
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// --- valtio Store 创建 ---
|
|
39
|
+
export var AIChatStore = proxy(initialState);
|
|
40
|
+
|
|
41
|
+
// --- 持久化订阅 ---
|
|
42
|
+
subscribe(AIChatStore, function () {
|
|
43
|
+
// 确保只在初始化后才进行持久化
|
|
44
|
+
if (!AIChatStore.isInitialized) return;
|
|
45
|
+
var stateSnapshot = snapshot(AIChatStore);
|
|
46
|
+
|
|
47
|
+
// console.log('stateSnapshot', stateSnapshot);
|
|
48
|
+
|
|
49
|
+
var stateToPersist = {};
|
|
50
|
+
PERSIST_KEYS.forEach(function (key) {
|
|
51
|
+
stateToPersist[key] = stateSnapshot[key];
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// 异步保存,不阻塞UI
|
|
55
|
+
localforage.setItem(STORAGE_KEY, stateToPersist);
|
|
56
|
+
});
|
|
57
|
+
export var clearEmptySession = function clearEmptySession() {
|
|
58
|
+
AIChatStore.sessions = AIChatStore.sessions.filter(function (s) {
|
|
59
|
+
return s.messages.length > 0;
|
|
60
|
+
});
|
|
61
|
+
if (AIChatStore.sessions.every(function (s) {
|
|
62
|
+
return s.id !== AIChatStore.activeSessionId;
|
|
63
|
+
}) && AIChatStore.sessions.length > 0) {
|
|
64
|
+
AIChatStore.activeSessionId = AIChatStore.sessions[0].id;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// --- 初始化逻辑 ---
|
|
69
|
+
export var initializeAIChat = /*#__PURE__*/function () {
|
|
70
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
71
|
+
var persistedState, fp, result, newSession, _AIChatStore$sessions;
|
|
72
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
73
|
+
while (1) switch (_context.prev = _context.next) {
|
|
74
|
+
case 0:
|
|
75
|
+
_context.next = 2;
|
|
76
|
+
return localforage.getItem(STORAGE_KEY);
|
|
77
|
+
case 2:
|
|
78
|
+
persistedState = _context.sent;
|
|
79
|
+
// 2. 合并加载的数据到 store
|
|
80
|
+
if (persistedState) {
|
|
81
|
+
PERSIST_KEYS.forEach(function (key) {
|
|
82
|
+
if (persistedState[key] !== undefined) {
|
|
83
|
+
// @ts-ignore - Directly assigning to the proxy state
|
|
84
|
+
AIChatStore[key] = persistedState[key];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// 3. 处理初始化边缘情况
|
|
90
|
+
if (AIChatStore.anonymousUserId) {
|
|
91
|
+
_context.next = 18;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
_context.prev = 5;
|
|
95
|
+
_context.next = 8;
|
|
96
|
+
return FingerprintJS.load();
|
|
97
|
+
case 8:
|
|
98
|
+
fp = _context.sent;
|
|
99
|
+
_context.next = 11;
|
|
100
|
+
return fp.get();
|
|
101
|
+
case 11:
|
|
102
|
+
result = _context.sent;
|
|
103
|
+
// result.visitorId 是一个基于浏览器指纹生成的哈希值
|
|
104
|
+
// 例如:'d8b759e6a5b2f1c3d9e8a6f0b7c5d4a3'
|
|
105
|
+
AIChatStore.anonymousUserId = result.visitorId;
|
|
106
|
+
// console.log('FingerprintJS ID generated:', result.visitorId);
|
|
107
|
+
_context.next = 18;
|
|
108
|
+
break;
|
|
109
|
+
case 15:
|
|
110
|
+
_context.prev = 15;
|
|
111
|
+
_context.t0 = _context["catch"](5);
|
|
112
|
+
// console.error('FingerprintJS failed, falling back to simple ID:', error);
|
|
113
|
+
// 如果指纹生成失败(例如被浏览器插件阻止),回退到一个简单方案
|
|
114
|
+
// 如果需要兼容旧浏览器,可以换成 `import { v4 as uuidv4 } from 'uuid';` 和 `uuidv4()`
|
|
115
|
+
AIChatStore.anonymousUserId = crypto.randomUUID();
|
|
116
|
+
case 18:
|
|
117
|
+
if (AIChatStore.sessions.length === 0) {
|
|
118
|
+
newSession = {
|
|
119
|
+
id: crypto.randomUUID(),
|
|
120
|
+
title: 'New Conversation',
|
|
121
|
+
createdAt: Date.now(),
|
|
122
|
+
messages: []
|
|
123
|
+
};
|
|
124
|
+
AIChatStore.sessions.push(newSession);
|
|
125
|
+
AIChatStore.activeSessionId = newSession.id;
|
|
126
|
+
}
|
|
127
|
+
if (!AIChatStore.activeSessionId || !AIChatStore.sessions.find(function (s) {
|
|
128
|
+
return s.id === AIChatStore.activeSessionId;
|
|
129
|
+
})) {
|
|
130
|
+
AIChatStore.activeSessionId = ((_AIChatStore$sessions = AIChatStore.sessions[0]) === null || _AIChatStore$sessions === void 0 ? void 0 : _AIChatStore$sessions.id) || null;
|
|
131
|
+
}
|
|
132
|
+
clearEmptySession();
|
|
133
|
+
|
|
134
|
+
// 4. 标记初始化完成,这将触发持久化订阅
|
|
135
|
+
AIChatStore.isInitialized = true;
|
|
136
|
+
// console.log('Valtio store initialized:', snapshot(AIChatStore));
|
|
137
|
+
case 22:
|
|
138
|
+
case "end":
|
|
139
|
+
return _context.stop();
|
|
140
|
+
}
|
|
141
|
+
}, _callee, null, [[5, 15]]);
|
|
142
|
+
}));
|
|
143
|
+
return function initializeAIChat() {
|
|
144
|
+
return _ref.apply(this, arguments);
|
|
145
|
+
};
|
|
146
|
+
}();
|
|
147
|
+
|
|
148
|
+
// --- 计算属性 (使用 derive) ---
|
|
149
|
+
export var derivedState = derive({
|
|
150
|
+
// 获取当前激活的会话对象
|
|
151
|
+
activeSession: function activeSession(get) {
|
|
152
|
+
var _get = get(AIChatStore),
|
|
153
|
+
sessions = _get.sessions,
|
|
154
|
+
activeSessionId = _get.activeSessionId;
|
|
155
|
+
if (!activeSessionId) return null;
|
|
156
|
+
return sessions.find(function (s) {
|
|
157
|
+
return s.id === activeSessionId;
|
|
158
|
+
}) || null;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// --- 删除会话 ---
|
|
163
|
+
export var handleDeleteSession = function handleDeleteSession(sessionId) {
|
|
164
|
+
var sessionIndex = AIChatStore.sessions.findIndex(function (s) {
|
|
165
|
+
return s.id === sessionId;
|
|
166
|
+
});
|
|
167
|
+
if (sessionIndex === -1) return;
|
|
168
|
+
|
|
169
|
+
// 从数组中移除
|
|
170
|
+
AIChatStore.sessions.splice(sessionIndex, 1);
|
|
171
|
+
|
|
172
|
+
// 如果删除的是当前激活的会话,需要重置 activeSessionId
|
|
173
|
+
if (AIChatStore.activeSessionId === sessionId) {
|
|
174
|
+
var _AIChatStore$sessions2;
|
|
175
|
+
AIChatStore.activeSessionId = ((_AIChatStore$sessions2 = AIChatStore.sessions[0]) === null || _AIChatStore$sessions2 === void 0 ? void 0 : _AIChatStore$sessions2.id) || null;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// --- 重命名会话 ---
|
|
180
|
+
export var handleRenameSession = function handleRenameSession(sessionId, newTitle) {
|
|
181
|
+
var session = AIChatStore.sessions.find(function (s) {
|
|
182
|
+
return s.id === sessionId;
|
|
183
|
+
});
|
|
184
|
+
if (session) {
|
|
185
|
+
session.title = newTitle;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// --- 置顶会话 ---
|
|
190
|
+
export var handlePinSession = function handlePinSession(sessionId) {
|
|
191
|
+
var sessionIndex = AIChatStore.sessions.findIndex(function (s) {
|
|
192
|
+
return s.id === sessionId;
|
|
193
|
+
});
|
|
194
|
+
if (sessionIndex <= 0) return; // 如果找不到或者已经在第一位,则不操作
|
|
195
|
+
|
|
196
|
+
// 找到会话,从原位置删除,然后添加到数组头部
|
|
197
|
+
var _AIChatStore$sessions3 = AIChatStore.sessions.splice(sessionIndex, 1),
|
|
198
|
+
_AIChatStore$sessions4 = _slicedToArray(_AIChatStore$sessions3, 1),
|
|
199
|
+
sessionToPin = _AIChatStore$sessions4[0];
|
|
200
|
+
AIChatStore.sessions.unshift(sessionToPin);
|
|
201
|
+
|
|
202
|
+
// (可选)置顶后自动激活该会话
|
|
203
|
+
AIChatStore.activeSessionId = sessionId;
|
|
204
|
+
};
|
|
205
|
+
subscribeKey(AIChatStore, 'activeSessionId', function () {
|
|
206
|
+
AIChatStore.codeBlock = null;
|
|
207
|
+
});
|
|
208
|
+
export var createPureNewSession = function createPureNewSession(title) {
|
|
209
|
+
var newConversationName = 'New Conversation';
|
|
210
|
+
var existNewSession = AIChatStore.sessions.find(function (s) {
|
|
211
|
+
return s.title === newConversationName && s.messages.length === 0;
|
|
212
|
+
});
|
|
213
|
+
if (existNewSession) {
|
|
214
|
+
AIChatStore.activeSessionId = existNewSession.id;
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
var newSessionId = crypto.randomUUID();
|
|
218
|
+
AIChatStore.sessions.unshift({
|
|
219
|
+
id: newSessionId,
|
|
220
|
+
title: title !== null && title !== void 0 ? title : newConversationName,
|
|
221
|
+
createdAt: Date.now(),
|
|
222
|
+
messages: []
|
|
223
|
+
});
|
|
224
|
+
AIChatStore.activeSessionId = newSessionId;
|
|
225
|
+
};
|
|
226
|
+
export var createNewSession = function createNewSession(config) {
|
|
227
|
+
// 1. 创建一个新的会话
|
|
228
|
+
createPureNewSession(config.promptText);
|
|
229
|
+
|
|
230
|
+
// 2. 创建临时消息并存入 store
|
|
231
|
+
AIChatStore.tempMessage = {
|
|
232
|
+
id: crypto.randomUUID(),
|
|
233
|
+
role: 'user',
|
|
234
|
+
content: config.promptText,
|
|
235
|
+
createdAt: Date.now(),
|
|
236
|
+
mode: config.mode,
|
|
237
|
+
lib: config.lib,
|
|
238
|
+
context: config.context
|
|
239
|
+
};
|
|
240
|
+
if (config.jump) {
|
|
241
|
+
var _config$lang;
|
|
242
|
+
history.push("/".concat((_config$lang = config.lang) !== null && _config$lang !== void 0 ? _config$lang : 'zh', "/ai-playground"));
|
|
243
|
+
}
|
|
244
|
+
// 埋点
|
|
245
|
+
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object') {
|
|
246
|
+
trackEvent('start_ai_chat', {
|
|
247
|
+
entry_point: config.entry_point,
|
|
248
|
+
mode: AIChatStore.mode,
|
|
249
|
+
lib: AIChatStore.lib,
|
|
250
|
+
page_title: document.title,
|
|
251
|
+
location: location.href
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* 清空所有本地AI对话记录和相关状态。用户注销账户或手动请求清除数据时调用。
|
|
258
|
+
*
|
|
259
|
+
* 该函数会执行以下操作:
|
|
260
|
+
* 1. 从 localforage 中删除持久化的状态数据。
|
|
261
|
+
* 2. 将内存中的 AIChatStore 重置为初始状态。
|
|
262
|
+
*
|
|
263
|
+
*/
|
|
264
|
+
export var clearAllChatData = /*#__PURE__*/function () {
|
|
265
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
266
|
+
var initialKeys, _i, _initialKeys, key;
|
|
267
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
268
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
269
|
+
case 0:
|
|
270
|
+
_context2.prev = 0;
|
|
271
|
+
_context2.next = 3;
|
|
272
|
+
return localforage.removeItem(STORAGE_KEY);
|
|
273
|
+
case 3:
|
|
274
|
+
console.log("[AIChat] Persistent state with key \"".concat(STORAGE_KEY, "\" has been removed."));
|
|
275
|
+
|
|
276
|
+
// 步骤 2: 将内存中的 valtio store 重置为初始状态。
|
|
277
|
+
// 这会立即更新UI,让所有对话记录从界面上消失。
|
|
278
|
+
// 注意:我们不能直接做 AIChatStore = initialState,
|
|
279
|
+
// 因为 proxy 对象是不可替换的。我们必须逐个属性地重置。
|
|
280
|
+
initialKeys = Object.keys(initialState);
|
|
281
|
+
for (_i = 0, _initialKeys = initialKeys; _i < _initialKeys.length; _i++) {
|
|
282
|
+
key = _initialKeys[_i];
|
|
283
|
+
// @ts-ignore
|
|
284
|
+
AIChatStore[key] = initialState[key];
|
|
285
|
+
}
|
|
286
|
+
console.log('[AIChat] In-memory state has been reset to initial values.');
|
|
287
|
+
_context2.next = 13;
|
|
288
|
+
break;
|
|
289
|
+
case 9:
|
|
290
|
+
_context2.prev = 9;
|
|
291
|
+
_context2.t0 = _context2["catch"](0);
|
|
292
|
+
console.error('[AIChat] Failed to clear all chat data:', _context2.t0);
|
|
293
|
+
message.error('清空对话记录失败,请刷新页面后重试。');
|
|
294
|
+
case 13:
|
|
295
|
+
case "end":
|
|
296
|
+
return _context2.stop();
|
|
297
|
+
}
|
|
298
|
+
}, _callee2, null, [[0, 9]]);
|
|
299
|
+
}));
|
|
300
|
+
return function clearAllChatData() {
|
|
301
|
+
return _ref2.apply(this, arguments);
|
|
302
|
+
};
|
|
303
|
+
}();
|
|
304
|
+
export function deleteMessage(msgId) {
|
|
305
|
+
derivedState.activeSession.messages = derivedState.activeSession.messages.filter(function (m) {
|
|
306
|
+
return m.id !== msgId;
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
export function branchMessage(index) {
|
|
310
|
+
var messages = derivedState.activeSession.messages.slice(0, index + 1);
|
|
311
|
+
createPureNewSession(messages[0].content);
|
|
312
|
+
AIChatStore.sessions[0].messages = messages;
|
|
313
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
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
|
+
import { history } from 'dumi';
|
|
8
|
+
import { message } from "antd";
|
|
9
|
+
import { subscribeKey } from "valtio/utils";
|
|
10
|
+
import { trackEvent } from "../utils/analytics";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 检查当前 URL 是否包含 'skipLogin=1' 参数
|
|
14
|
+
* @returns {boolean} 如果包含则返回 true, 否则返回 false
|
|
15
|
+
*/
|
|
16
|
+
function hasSkipLoginParam() {
|
|
17
|
+
if (typeof window === 'undefined') {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
// 1. 获取当前 URL 的查询字符串 (例如 "?foo=bar&skipLogin=1")
|
|
21
|
+
var queryString = window.location.search;
|
|
22
|
+
|
|
23
|
+
// 2. 创建一个 URLSearchParams 实例
|
|
24
|
+
var urlParams = new URLSearchParams(queryString);
|
|
25
|
+
|
|
26
|
+
// 3. 使用 .get() 方法获取 'skipLogin' 参数的值,并判断是否为 '1'
|
|
27
|
+
// 注意:URL参数的值总是字符串类型,所以我们用 '1' 而不是 1 进行比较。
|
|
28
|
+
return urlParams.get('skipLogin') === '1';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 1. 定义 State (只包含数据)
|
|
32
|
+
export var authStore = proxy({
|
|
33
|
+
isModalOpen: false,
|
|
34
|
+
isAuthenticated: false,
|
|
35
|
+
loginCallback: function loginCallback() {}
|
|
36
|
+
});
|
|
37
|
+
subscribeKey(authStore, 'isModalOpen', function (open) {
|
|
38
|
+
if (open) {
|
|
39
|
+
trackEvent('login_modal_open');
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// 2. 定义 Actions (作为独立函数)
|
|
44
|
+
export var showLoginModal = function showLoginModal(callback) {
|
|
45
|
+
authStore.isModalOpen = true;
|
|
46
|
+
authStore.loginCallback = callback;
|
|
47
|
+
};
|
|
48
|
+
export var hideLoginModal = function hideLoginModal() {
|
|
49
|
+
authStore.isModalOpen = false;
|
|
50
|
+
};
|
|
51
|
+
export var loginOrRegister = /*#__PURE__*/function () {
|
|
52
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
53
|
+
var _authStore$loginCallb, _error$response, errorMessage;
|
|
54
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
55
|
+
while (1) switch (_context.prev = _context.next) {
|
|
56
|
+
case 0:
|
|
57
|
+
_context.prev = 0;
|
|
58
|
+
_context.next = 3;
|
|
59
|
+
return request.post('/api/modules/user/api/accounts/login_or_register', params);
|
|
60
|
+
case 3:
|
|
61
|
+
authStore.isAuthenticated = true;
|
|
62
|
+
hideLoginModal();
|
|
63
|
+
(_authStore$loginCallb = authStore.loginCallback) === null || _authStore$loginCallb === void 0 || _authStore$loginCallb.call(authStore);
|
|
64
|
+
return _context.abrupt("return", true);
|
|
65
|
+
case 9:
|
|
66
|
+
_context.prev = 9;
|
|
67
|
+
_context.t0 = _context["catch"](0);
|
|
68
|
+
console.error('Login failed in store:', _context.t0);
|
|
69
|
+
errorMessage = _context.t0 === null || _context.t0 === void 0 || (_error$response = _context.t0.response) === null || _error$response === void 0 || (_error$response = _error$response.data) === null || _error$response === void 0 ? void 0 : _error$response.message;
|
|
70
|
+
if (errorMessage) {
|
|
71
|
+
message.error(errorMessage);
|
|
72
|
+
}
|
|
73
|
+
return _context.abrupt("return", false);
|
|
74
|
+
case 15:
|
|
75
|
+
case "end":
|
|
76
|
+
return _context.stop();
|
|
77
|
+
}
|
|
78
|
+
}, _callee, null, [[0, 9]]);
|
|
79
|
+
}));
|
|
80
|
+
return function loginOrRegister(_x) {
|
|
81
|
+
return _ref.apply(this, arguments);
|
|
82
|
+
};
|
|
83
|
+
}();
|
|
84
|
+
export var logout = /*#__PURE__*/function () {
|
|
85
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
86
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
87
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
88
|
+
case 0:
|
|
89
|
+
_context2.prev = 0;
|
|
90
|
+
_context2.next = 3;
|
|
91
|
+
return request.delete('/api/modules/user/api/accounts/logout');
|
|
92
|
+
case 3:
|
|
93
|
+
_context2.next = 8;
|
|
94
|
+
break;
|
|
95
|
+
case 5:
|
|
96
|
+
_context2.prev = 5;
|
|
97
|
+
_context2.t0 = _context2["catch"](0);
|
|
98
|
+
console.error('Logout failed in store:', _context2.t0);
|
|
99
|
+
case 8:
|
|
100
|
+
_context2.prev = 8;
|
|
101
|
+
authStore.isAuthenticated = false;
|
|
102
|
+
history.push('/');
|
|
103
|
+
return _context2.finish(8);
|
|
104
|
+
case 12:
|
|
105
|
+
case "end":
|
|
106
|
+
return _context2.stop();
|
|
107
|
+
}
|
|
108
|
+
}, _callee2, null, [[0, 5, 8, 12]]);
|
|
109
|
+
}));
|
|
110
|
+
return function logout() {
|
|
111
|
+
return _ref2.apply(this, arguments);
|
|
112
|
+
};
|
|
113
|
+
}();
|
|
114
|
+
export function sendValidationCode(data) {
|
|
115
|
+
return request.post('/api/modules/user/api/validation_code/send', data);
|
|
116
|
+
}
|
|
117
|
+
export var initializeAuth = /*#__PURE__*/function () {
|
|
118
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
119
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
120
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
121
|
+
case 0:
|
|
122
|
+
_context3.prev = 0;
|
|
123
|
+
if (hasSkipLoginParam()) {
|
|
124
|
+
_context3.next = 4;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
_context3.next = 4;
|
|
128
|
+
return request.get('/api/modules/user/api/accounts/get_company_info');
|
|
129
|
+
case 4:
|
|
130
|
+
authStore.isAuthenticated = true;
|
|
131
|
+
_context3.next = 11;
|
|
132
|
+
break;
|
|
133
|
+
case 7:
|
|
134
|
+
_context3.prev = 7;
|
|
135
|
+
_context3.t0 = _context3["catch"](0);
|
|
136
|
+
console.error('Initialize auth failed in store:', _context3.t0);
|
|
137
|
+
authStore.isAuthenticated = false;
|
|
138
|
+
case 11:
|
|
139
|
+
case "end":
|
|
140
|
+
return _context3.stop();
|
|
141
|
+
}
|
|
142
|
+
}, _callee3, null, [[0, 7]]);
|
|
143
|
+
}));
|
|
144
|
+
return function initializeAuth() {
|
|
145
|
+
return _ref3.apply(this, arguments);
|
|
146
|
+
};
|
|
147
|
+
}();
|