@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.
- package/dist/builtins/Playground/index.js +1 -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/index.js +29 -0
- package/dist/components/AI/HomeDialog/ModeSelector/index.module.less +272 -0
- package/dist/components/AI/HomeDialog/PromptTextarea/ChooseLib/index.js +51 -0
- package/dist/components/AI/HomeDialog/PromptTextarea/ChooseLib/index.module.less +5 -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/index.js +132 -0
- package/dist/components/AI/HomeDialog/PromptTextarea/index.module.less +127 -0
- package/dist/components/AI/HomeDialog/RecommendCase/Card.js +70 -0
- package/dist/components/AI/HomeDialog/RecommendCase/card.module.less +131 -0
- package/dist/components/AI/HomeDialog/RecommendCase/index.js +76 -0
- package/dist/components/AI/HomeDialog/RecommendCase/index.module.less +43 -0
- package/dist/components/AI/HomeDialog/RecommendCase/recommend.json +42 -0
- package/dist/components/AI/HomeDialog/index.js +65 -0
- package/dist/components/AI/HomeDialog/index.module.less +3 -0
- package/dist/components/AI/constant.js +35 -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/hooks/useProducts.js +18 -0
- package/dist/hooks/useStreamingText.js +119 -0
- package/dist/hooks/useVisionsnapSdk.js +159 -0
- package/dist/layouts/DocLayout.js +0 -1
- package/dist/layouts/GlobalLayout/index.js +15 -0
- package/dist/model/AIChat.js +214 -0
- package/dist/pages/AIPlayground/components/ConversationsMenu/index.js +146 -0
- package/dist/pages/AIPlayground/components/ConversationsMenu/index.module.less +44 -0
- package/dist/pages/AIPlayground/components/MarkdownComponent/MarkdownCodeBlock.js +65 -0
- package/dist/pages/AIPlayground/components/MarkdownComponent/index.js +47 -0
- package/dist/pages/AIPlayground/components/MsgBox/index.js +187 -0
- package/dist/pages/AIPlayground/components/MsgBox/index.module.less +42 -0
- package/dist/pages/AIPlayground/components/SessionLayout/index.js +25 -0
- package/dist/pages/AIPlayground/components/SessionLayout/index.module.less +34 -0
- package/dist/pages/AIPlayground/components/TaskBox/generateCode.js +110 -0
- package/dist/pages/AIPlayground/components/TaskBox/index.js +60 -0
- package/dist/pages/AIPlayground/components/TaskBox/index.module.less +8 -0
- package/dist/pages/AIPlayground/demo.js +34 -0
- package/dist/pages/AIPlayground/index.js +9 -0
- package/dist/pages/AIPlayground/index.module.less +0 -0
- package/dist/pages/Index/index.js +1 -1
- package/dist/plugin/index.js +14 -6
- package/dist/slots/CodeEditor/Toolbar.js +6 -2
- package/dist/slots/CodeEditor/Toolbar.module.less +6 -0
- package/dist/slots/CodeEditor/index.js +28 -2
- package/dist/slots/CodeEditor/index.module.less +22 -0
- package/dist/{pages/Index/components → slots}/Detail/News.js +1 -1
- package/dist/{pages/Index/components → slots}/Detail/index.js +11 -28
- package/dist/{pages/Index/components → slots}/Detail/index.module.less +12 -6
- 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 +35 -14
- package/dist/slots/Header/Search/index.js +2 -1
- package/dist/slots/Header/index.module.less +1 -1
- package/dist/typings.d.ts +5 -0
- package/package.json +23 -4
- /package/dist/{pages/Index/components → slots}/Detail/News.module.less +0 -0
|
@@ -0,0 +1,65 @@
|
|
|
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 styles from "./index.module.less";
|
|
9
|
+
import { AntVBanner } from "./AntVBanner";
|
|
10
|
+
import { PromptTextarea } from "./PromptTextarea";
|
|
11
|
+
import { RecommendCase } from "./RecommendCase";
|
|
12
|
+
import { ModeSelector } from "./ModeSelector";
|
|
13
|
+
import { useLocalStorageState } from 'ahooks';
|
|
14
|
+
import { AIMode } from "../constant";
|
|
15
|
+
import classnames from 'classnames';
|
|
16
|
+
import { useSiteData } from 'dumi';
|
|
17
|
+
import { createNewSession } from "../../../model/AIChat";
|
|
18
|
+
export function HomeDialog(props) {
|
|
19
|
+
var _useSiteData = useSiteData(),
|
|
20
|
+
themeConfig = _useSiteData.themeConfig;
|
|
21
|
+
var _useState = useState(!themeConfig.isAntVSite ? themeConfig.title : undefined),
|
|
22
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
23
|
+
lib = _useState2[0],
|
|
24
|
+
setLib = _useState2[1];
|
|
25
|
+
var _useLocalStorageState = useLocalStorageState('use-local-storage-ai-mode-type', {
|
|
26
|
+
defaultValue: AIMode.implement
|
|
27
|
+
}),
|
|
28
|
+
_useLocalStorageState2 = _slicedToArray(_useLocalStorageState, 2),
|
|
29
|
+
mode = _useLocalStorageState2[0],
|
|
30
|
+
setMode = _useLocalStorageState2[1];
|
|
31
|
+
var _useState3 = useState(''),
|
|
32
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
33
|
+
promptText = _useState4[0],
|
|
34
|
+
setPromptText = _useState4[1];
|
|
35
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
36
|
+
className: classnames(styles.content, props.className),
|
|
37
|
+
style: props.style
|
|
38
|
+
}, /*#__PURE__*/React.createElement(AntVBanner, null), /*#__PURE__*/React.createElement(ModeSelector, {
|
|
39
|
+
onChange: function onChange(v) {
|
|
40
|
+
setMode(v);
|
|
41
|
+
// todo 埋点
|
|
42
|
+
},
|
|
43
|
+
value: mode
|
|
44
|
+
}), /*#__PURE__*/React.createElement(PromptTextarea, {
|
|
45
|
+
mode: mode,
|
|
46
|
+
value: promptText,
|
|
47
|
+
lib: lib,
|
|
48
|
+
onLibChange: function onLibChange(v) {
|
|
49
|
+
setLib(v);
|
|
50
|
+
},
|
|
51
|
+
onChange: function onChange(val) {
|
|
52
|
+
setPromptText(val);
|
|
53
|
+
},
|
|
54
|
+
onConfirm: function onConfirm() {
|
|
55
|
+
createNewSession({
|
|
56
|
+
promptText: promptText,
|
|
57
|
+
mode: mode,
|
|
58
|
+
lib: lib
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
style: props.promptTextareaStyle
|
|
62
|
+
}), /*#__PURE__*/React.createElement(RecommendCase, {
|
|
63
|
+
className: props.recommendCaseClassName
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BarChartOutlined, QuestionCircleOutlined } from '@ant-design/icons';
|
|
2
|
+
import React from "react";
|
|
3
|
+
export var AIMode = {
|
|
4
|
+
implement: 'implement',
|
|
5
|
+
solve: 'solve'
|
|
6
|
+
};
|
|
7
|
+
export var AIModeMeta = {
|
|
8
|
+
implement: {
|
|
9
|
+
name: '可视化研发',
|
|
10
|
+
icon: /*#__PURE__*/React.createElement(BarChartOutlined, null)
|
|
11
|
+
},
|
|
12
|
+
solve: {
|
|
13
|
+
name: '可视化答疑',
|
|
14
|
+
icon: /*#__PURE__*/React.createElement(QuestionCircleOutlined, null)
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// 循环取这几个颜色
|
|
19
|
+
export var COLORS = [{
|
|
20
|
+
color: '#5792E6',
|
|
21
|
+
backgroundColor: 'rgba(22,119,255,0.06)'
|
|
22
|
+
}, {
|
|
23
|
+
color: '#66cf85',
|
|
24
|
+
backgroundColor: 'rgba(44,208,119,0.06)'
|
|
25
|
+
}, {
|
|
26
|
+
color: '#f99542',
|
|
27
|
+
backgroundColor: 'rgba(231,173,69,0.08)'
|
|
28
|
+
}, {
|
|
29
|
+
color: '#5761f3',
|
|
30
|
+
backgroundColor: 'rgba(22,55,255,0.06)'
|
|
31
|
+
}];
|
|
32
|
+
export var FileIcons = {
|
|
33
|
+
FILE: 'https://mdn.alipayobjects.com/huamei_2yzvel/afts/img/A*bc2KQq259ucAAAAAAAAAAAAAeriAAQ/original',
|
|
34
|
+
IMAGE: 'https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*6I-zQKAmDUsAAAAAQBAAAAgAemJ7AQ/original'
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./HomeDialog";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export function getFileExtension(filename) {
|
|
2
|
+
// 查找最后一个点的位置
|
|
3
|
+
var dotIndex = filename.lastIndexOf('.');
|
|
4
|
+
|
|
5
|
+
// 如果没有找到点,返回空字符串
|
|
6
|
+
if (dotIndex === -1) {
|
|
7
|
+
return '';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// 提取后缀名,并返回
|
|
11
|
+
return filename.slice(dotIndex + 1);
|
|
12
|
+
}
|
|
13
|
+
export function formatFileSize(fileSize) {
|
|
14
|
+
if (!fileSize) {
|
|
15
|
+
return '0B';
|
|
16
|
+
}
|
|
17
|
+
var units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
18
|
+
var size = fileSize;
|
|
19
|
+
var unitIndex = 0;
|
|
20
|
+
|
|
21
|
+
// 当文件大小大于等于1024且还有更大的单位可用时,进行转换
|
|
22
|
+
while (size >= 1024 && unitIndex < units.length - 1) {
|
|
23
|
+
size /= 1024;
|
|
24
|
+
unitIndex++;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 如果小于1MB,强制使用KB为单位
|
|
28
|
+
if (unitIndex === 0 && fileSize >= 1024) {
|
|
29
|
+
size = fileSize / 1024;
|
|
30
|
+
unitIndex = 1;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 保留一位小数
|
|
34
|
+
size = Number(size.toFixed(1));
|
|
35
|
+
|
|
36
|
+
// 如果小数部分为0,则去掉小数部分
|
|
37
|
+
return "".concat(size % 1 === 0 ? Math.floor(size) : size).concat(units[unitIndex]);
|
|
38
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
export function getProducts() {
|
|
3
|
+
// 如需要修改产品信息,请到 https://yuyan.antfin-inc.com/antv/site-data/sprints 修改区块内容
|
|
4
|
+
return fetch('https://assets.antv.antgroup.com/antv/products.json' // 生产环境
|
|
5
|
+
// 'https://site-data-pre.alipay.com/antv/products.json', // 预发测试
|
|
6
|
+
).then(function (res) {
|
|
7
|
+
return res.json();
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// 封装了 queryKey 和 fetcher 的自定义 Hook
|
|
12
|
+
export function useProducts() {
|
|
13
|
+
return useQuery({
|
|
14
|
+
queryKey: ['antv-products'],
|
|
15
|
+
queryFn: getProducts,
|
|
16
|
+
staleTime: 24 * 60 * 60 * 1000 // 一天内数据不会被认为是 "stale",不会触发后台刷新
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
+
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."); }
|
|
7
|
+
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); }
|
|
8
|
+
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; }
|
|
9
|
+
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; } }
|
|
10
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
+
import { useState } from 'react';
|
|
12
|
+
import { useDeepCompareEffect } from 'ahooks';
|
|
13
|
+
export var useStreamingText = function useStreamingText(_ref) {
|
|
14
|
+
var url = _ref.url,
|
|
15
|
+
_ref$method = _ref.method,
|
|
16
|
+
method = _ref$method === void 0 ? 'POST' : _ref$method,
|
|
17
|
+
_ref$headers = _ref.headers,
|
|
18
|
+
headers = _ref$headers === void 0 ? {
|
|
19
|
+
'Content-Type': 'application/json'
|
|
20
|
+
} : _ref$headers,
|
|
21
|
+
body = _ref.body,
|
|
22
|
+
trigger = _ref.trigger,
|
|
23
|
+
onFinish = _ref.onFinish,
|
|
24
|
+
onError = _ref.onError,
|
|
25
|
+
beforeStart = _ref.beforeStart;
|
|
26
|
+
var _useState = useState(''),
|
|
27
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
28
|
+
text = _useState2[0],
|
|
29
|
+
setText = _useState2[1];
|
|
30
|
+
useDeepCompareEffect(function () {
|
|
31
|
+
if (!trigger || !body.query) {
|
|
32
|
+
setText('');
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
var abortController = new AbortController();
|
|
36
|
+
var fetchData = /*#__PURE__*/function () {
|
|
37
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
38
|
+
var response, reader, decoder, accumulatedText, _yield$reader$read, done, value, chunk;
|
|
39
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
40
|
+
while (1) switch (_context.prev = _context.next) {
|
|
41
|
+
case 0:
|
|
42
|
+
_context.prev = 0;
|
|
43
|
+
_context.next = 3;
|
|
44
|
+
return fetch(url, {
|
|
45
|
+
method: method,
|
|
46
|
+
headers: headers,
|
|
47
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
48
|
+
signal: abortController.signal
|
|
49
|
+
});
|
|
50
|
+
case 3:
|
|
51
|
+
response = _context.sent;
|
|
52
|
+
if (response.ok) {
|
|
53
|
+
_context.next = 6;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
throw new Error("HTTP error! status: ".concat(response.status));
|
|
57
|
+
case 6:
|
|
58
|
+
if (response.body) {
|
|
59
|
+
_context.next = 8;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
throw new Error('Response body is null');
|
|
63
|
+
case 8:
|
|
64
|
+
reader = response.body.getReader();
|
|
65
|
+
decoder = new TextDecoder();
|
|
66
|
+
accumulatedText = '';
|
|
67
|
+
case 11:
|
|
68
|
+
if (!true) {
|
|
69
|
+
_context.next = 25;
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
_context.next = 14;
|
|
73
|
+
return reader.read();
|
|
74
|
+
case 14:
|
|
75
|
+
_yield$reader$read = _context.sent;
|
|
76
|
+
done = _yield$reader$read.done;
|
|
77
|
+
value = _yield$reader$read.value;
|
|
78
|
+
if (!done) {
|
|
79
|
+
_context.next = 20;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
onFinish === null || onFinish === void 0 || onFinish(accumulatedText); // 流结束时调用 onFinish
|
|
83
|
+
return _context.abrupt("break", 25);
|
|
84
|
+
case 20:
|
|
85
|
+
chunk = decoder.decode(value, {
|
|
86
|
+
stream: true
|
|
87
|
+
});
|
|
88
|
+
accumulatedText += chunk;
|
|
89
|
+
setText(accumulatedText);
|
|
90
|
+
_context.next = 11;
|
|
91
|
+
break;
|
|
92
|
+
case 25:
|
|
93
|
+
_context.next = 30;
|
|
94
|
+
break;
|
|
95
|
+
case 27:
|
|
96
|
+
_context.prev = 27;
|
|
97
|
+
_context.t0 = _context["catch"](0);
|
|
98
|
+
if (_context.t0.name !== 'AbortError') {
|
|
99
|
+
console.error('Streaming fetch error:', _context.t0);
|
|
100
|
+
onError === null || onError === void 0 || onError(_context.t0);
|
|
101
|
+
}
|
|
102
|
+
case 30:
|
|
103
|
+
case "end":
|
|
104
|
+
return _context.stop();
|
|
105
|
+
}
|
|
106
|
+
}, _callee, null, [[0, 27]]);
|
|
107
|
+
}));
|
|
108
|
+
return function fetchData() {
|
|
109
|
+
return _ref2.apply(this, arguments);
|
|
110
|
+
};
|
|
111
|
+
}();
|
|
112
|
+
beforeStart === null || beforeStart === void 0 || beforeStart();
|
|
113
|
+
fetchData();
|
|
114
|
+
return function () {
|
|
115
|
+
abortController.abort();
|
|
116
|
+
};
|
|
117
|
+
}, [trigger, url, method, headers, body]);
|
|
118
|
+
return text;
|
|
119
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
|
+
import React, { useEffect, useState, useRef, useCallback } from 'react';
|
|
14
|
+
import * as ReactDOMClient from 'react-dom/client';
|
|
15
|
+
import * as ReactDOM from 'react-dom';
|
|
16
|
+
|
|
17
|
+
// 将 React 暴露到全局作用域,供第三方 SDK 使用
|
|
18
|
+
|
|
19
|
+
if (!React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) {
|
|
20
|
+
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = {
|
|
21
|
+
ReactCurrentOwner: {
|
|
22
|
+
current: null
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 只有在全局 React 不存在时才设置
|
|
28
|
+
if (typeof window !== 'undefined') {
|
|
29
|
+
if (!window.React) {
|
|
30
|
+
window.React = React;
|
|
31
|
+
}
|
|
32
|
+
if (!window.ReactDOM) {
|
|
33
|
+
// 合并 ReactDOM 和 ReactDOMClient 的功能,确保新的 API 来自正确的模块
|
|
34
|
+
window.ReactDOM = _objectSpread(_objectSpread({}, ReactDOM), {}, {
|
|
35
|
+
// 明确从 react-dom/client 导入新的 API
|
|
36
|
+
createRoot: ReactDOMClient.createRoot,
|
|
37
|
+
hydrateRoot: ReactDOMClient.hydrateRoot
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 扩展 Window 接口以支持动态属性访问
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 自定义 useInterval hook,用于轮询检查远程组件是否加载完成
|
|
46
|
+
* @param callback 回调函数
|
|
47
|
+
* @param delay 轮询间隔时间(毫秒)
|
|
48
|
+
* @returns 清除定时器的函数
|
|
49
|
+
*/
|
|
50
|
+
function useInterval(callback, delay) {
|
|
51
|
+
var intervalRef = useRef(null);
|
|
52
|
+
var savedCallback = useRef();
|
|
53
|
+
|
|
54
|
+
// 保存最新的回调函数
|
|
55
|
+
useEffect(function () {
|
|
56
|
+
savedCallback.current = callback;
|
|
57
|
+
}, [callback]);
|
|
58
|
+
|
|
59
|
+
// 清除定时器的函数,使用 useCallback 优化性能
|
|
60
|
+
var clear = useCallback(function () {
|
|
61
|
+
if (intervalRef.current !== null) {
|
|
62
|
+
clearInterval(intervalRef.current);
|
|
63
|
+
intervalRef.current = null;
|
|
64
|
+
}
|
|
65
|
+
}, []);
|
|
66
|
+
|
|
67
|
+
// 设置和清理定时器
|
|
68
|
+
useEffect(function () {
|
|
69
|
+
var tick = function tick() {
|
|
70
|
+
if (savedCallback.current) {
|
|
71
|
+
savedCallback.current();
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
intervalRef.current = setInterval(tick, delay);
|
|
75
|
+
return clear;
|
|
76
|
+
}, [delay, clear]);
|
|
77
|
+
return clear;
|
|
78
|
+
}
|
|
79
|
+
function load(url, name) {
|
|
80
|
+
var id = "__umd_component__".concat(name, "_");
|
|
81
|
+
if (document.getElementById(id)) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
var script = document.createElement('script');
|
|
85
|
+
script.async = true;
|
|
86
|
+
script.src = url;
|
|
87
|
+
script.id = id;
|
|
88
|
+
script.crossOrigin = 'anonymous';
|
|
89
|
+
// attach it to DOM
|
|
90
|
+
document.body.appendChild(script);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* a hook to use Remote React Component.
|
|
95
|
+
* @param url component CDN url
|
|
96
|
+
* @param name global name
|
|
97
|
+
* @return global variable
|
|
98
|
+
*/
|
|
99
|
+
export function useRemoteComponent(url, name) {
|
|
100
|
+
var _window;
|
|
101
|
+
var _useState = useState(null),
|
|
102
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
103
|
+
Component = _useState2[0],
|
|
104
|
+
setComponent = _useState2[1];
|
|
105
|
+
var _useState3 = useState(true),
|
|
106
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
107
|
+
loading = _useState4[0],
|
|
108
|
+
setLoading = _useState4[1];
|
|
109
|
+
useEffect(function () {
|
|
110
|
+
load(url, name);
|
|
111
|
+
}, [url, name]);
|
|
112
|
+
var clear = useInterval(function () {
|
|
113
|
+
if (window[name]) {
|
|
114
|
+
setComponent(window[name]);
|
|
115
|
+
setLoading(false);
|
|
116
|
+
clear();
|
|
117
|
+
}
|
|
118
|
+
}, 100);
|
|
119
|
+
if ((_window = window) !== null && _window !== void 0 && _window[name]) {
|
|
120
|
+
return [window[name], false];
|
|
121
|
+
}
|
|
122
|
+
return [Component, loading];
|
|
123
|
+
}
|
|
124
|
+
function getJSSDKURL(options) {
|
|
125
|
+
var packageName = options.packageName,
|
|
126
|
+
version = options.version,
|
|
127
|
+
_options$file = options.file,
|
|
128
|
+
file = _options$file === void 0 ? 'dist/sdk.js' : _options$file;
|
|
129
|
+
var jssdkVersion = version;
|
|
130
|
+
var jssdkCdnUrl = jssdkVersion.includes('dev') ? "https://g.alipay.com/".concat(packageName, "@").concat(jssdkVersion, "/").concat(file) : "https://gw.alipayobjects.com/render/p/yuyan_npm/".concat(packageName.replace('/', '_'), "/").concat(jssdkVersion, "/").concat(file);
|
|
131
|
+
return jssdkCdnUrl;
|
|
132
|
+
}
|
|
133
|
+
function useRemoteSdk(options) {
|
|
134
|
+
var _options$sdkInstanceN = options.sdkInstanceName,
|
|
135
|
+
sdkInstanceName = _options$sdkInstanceN === void 0 ? 'sdk' : _options$sdkInstanceN;
|
|
136
|
+
|
|
137
|
+
// dev 版本只能走 g.alipay.com 域名,外网千万不能配
|
|
138
|
+
var jssdkCdnUrl = getJSSDKURL(options);
|
|
139
|
+
var _useRemoteComponent = useRemoteComponent(jssdkCdnUrl, sdkInstanceName),
|
|
140
|
+
_useRemoteComponent2 = _slicedToArray(_useRemoteComponent, 2),
|
|
141
|
+
sdk = _useRemoteComponent2[0],
|
|
142
|
+
sdkLoading = _useRemoteComponent2[1];
|
|
143
|
+
return {
|
|
144
|
+
sdk: sdk,
|
|
145
|
+
loading: sdkLoading
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
export function useVisionsnapSdk(visionsnapVersion) {
|
|
149
|
+
return useRemoteSdk({
|
|
150
|
+
packageName: '@alipay/visionsnap-client',
|
|
151
|
+
version: visionsnapVersion,
|
|
152
|
+
sdkInstanceName: 'VisionSnapSDK',
|
|
153
|
+
file: 'dist/sdk.js'
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
export var requestProxy = {
|
|
157
|
+
getAuthToken: "https://www.weavefox.cn/api/visionsnap/auth_token",
|
|
158
|
+
getImportMaps: "https://www.weavefox.cn/api/visionsnap/import_maps"
|
|
159
|
+
};
|
|
@@ -14,7 +14,6 @@ import ManualLayout from "./ManualLayout";
|
|
|
14
14
|
import GlobalStyles from "../common/GlobalStyles";
|
|
15
15
|
import { defaultToken } from "../common/styles/theme";
|
|
16
16
|
import "../static/style";
|
|
17
|
-
|
|
18
17
|
/**
|
|
19
18
|
* DocLayout 是 dumi2 的内置 layout 入口,在这里使用页面路径进行区分成自己不同的 Layout。
|
|
20
19
|
*/
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { useOutlet } from 'dumi';
|
|
3
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
4
|
+
import { initializeStore } from "../../model/AIChat";
|
|
5
|
+
var queryClient = new QueryClient();
|
|
6
|
+
var GlobalLayout = function GlobalLayout() {
|
|
7
|
+
var outlet = useOutlet();
|
|
8
|
+
useEffect(function () {
|
|
9
|
+
initializeStore();
|
|
10
|
+
}, []);
|
|
11
|
+
return outlet && /*#__PURE__*/React.createElement(QueryClientProvider, {
|
|
12
|
+
client: queryClient
|
|
13
|
+
}, outlet);
|
|
14
|
+
};
|
|
15
|
+
export default GlobalLayout;
|