@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.
Files changed (113) hide show
  1. package/dist/builtins/Playground/index.js +1 -1
  2. package/dist/builtins/Playground/index.module.less +0 -1
  3. package/dist/common/styles/Common.js +1 -1
  4. package/dist/common/styles/theme.js +1 -1
  5. package/dist/components/AI/HomeDialog/AntVBanner/index.js +4 -0
  6. package/dist/components/AI/HomeDialog/AntVBanner/index.module.less +35 -0
  7. package/dist/components/AI/HomeDialog/ModeSelector/ModeSelectorDropdown.js +42 -0
  8. package/dist/components/AI/HomeDialog/ModeSelector/index.js +32 -0
  9. package/dist/components/AI/HomeDialog/ModeSelector/index.module.less +289 -0
  10. package/dist/components/AI/HomeDialog/PromptTextarea/ChooseLib/index.js +62 -0
  11. package/dist/components/AI/HomeDialog/PromptTextarea/ChooseLib/index.module.less +4 -0
  12. package/dist/components/AI/HomeDialog/PromptTextarea/DatasourceCard/index.js +25 -0
  13. package/dist/components/AI/HomeDialog/PromptTextarea/DatasourceCard/index.module.less +42 -0
  14. package/dist/components/AI/HomeDialog/PromptTextarea/SendButton.js +23 -0
  15. package/dist/components/AI/HomeDialog/PromptTextarea/SendButton.module.less +9 -0
  16. package/dist/components/AI/HomeDialog/PromptTextarea/Uploader/DataUploader.js +225 -0
  17. package/dist/components/AI/HomeDialog/PromptTextarea/index.js +172 -0
  18. package/dist/components/AI/HomeDialog/PromptTextarea/index.module.less +128 -0
  19. package/dist/components/AI/HomeDialog/RecommendCase/Card.js +80 -0
  20. package/dist/components/AI/HomeDialog/RecommendCase/card.module.less +131 -0
  21. package/dist/components/AI/HomeDialog/RecommendCase/index.js +130 -0
  22. package/dist/components/AI/HomeDialog/RecommendCase/index.module.less +45 -0
  23. package/dist/components/AI/HomeDialog/RecommendCase/recommend.json +66 -0
  24. package/dist/components/AI/HomeDialog/index.js +62 -0
  25. package/dist/components/AI/HomeDialog/index.module.less +3 -0
  26. package/dist/components/AI/constant.js +37 -0
  27. package/dist/components/AI/index.js +1 -0
  28. package/dist/components/AI/types.js +1 -0
  29. package/dist/components/AI/utils.js +38 -0
  30. package/dist/components/Login/Captcha/index.js +185 -0
  31. package/dist/components/Login/Captcha/index.less +91 -0
  32. package/dist/components/Login/CheckCode/index.js +244 -0
  33. package/dist/components/Login/CheckCode/index.less +137 -0
  34. package/dist/components/Login/CountDownButton/index.js +109 -0
  35. package/dist/components/Login/CountDownButton/index.less +8 -0
  36. package/dist/components/Login/LoginForm.js +239 -0
  37. package/dist/components/Login/LoginForm.less +408 -0
  38. package/dist/components/Login/index.js +24 -0
  39. package/dist/components/Login/openAuthWindow.js +54 -0
  40. package/dist/components/Login/types.js +5 -0
  41. package/dist/components/Login/utils.js +47 -0
  42. package/dist/hooks/useProducts.js +39 -0
  43. package/dist/hooks/useStreamingText.js +139 -0
  44. package/dist/hooks/useTypewriter.js +69 -0
  45. package/dist/hooks/useVisionsnapSdk.js +159 -0
  46. package/dist/layouts/DocLayout.js +2 -2
  47. package/dist/layouts/GlobalLayout/index.js +22 -0
  48. package/dist/locales/en.json +132 -1
  49. package/dist/locales/zh.json +132 -1
  50. package/dist/model/AIChat.js +313 -0
  51. package/dist/model/auth.js +147 -0
  52. package/dist/pages/AIPlayground/components/ConversationsMenu/index.js +176 -0
  53. package/dist/pages/AIPlayground/components/ConversationsMenu/index.module.less +46 -0
  54. package/dist/pages/AIPlayground/components/MarkdownComponent/MarkdownCodeBlock.js +97 -0
  55. package/dist/pages/AIPlayground/components/MarkdownComponent/MarkdownCodeBlock.module.less +13 -0
  56. package/dist/pages/AIPlayground/components/MarkdownComponent/index.js +50 -0
  57. package/dist/pages/AIPlayground/components/MsgBox/index.js +407 -0
  58. package/dist/pages/AIPlayground/components/MsgBox/index.module.less +43 -0
  59. package/dist/pages/AIPlayground/components/MsgBox/useAutoScroll.js +46 -0
  60. package/dist/pages/AIPlayground/components/SessionLayout/index.js +62 -0
  61. package/dist/pages/AIPlayground/components/SessionLayout/index.module.less +37 -0
  62. package/dist/pages/AIPlayground/components/TaskBox/generateCode.js +230 -0
  63. package/dist/pages/AIPlayground/components/TaskBox/index.js +101 -0
  64. package/dist/pages/AIPlayground/components/TaskBox/index.module.less +9 -0
  65. package/dist/pages/AIPlayground/demo.js +34 -0
  66. package/dist/pages/AIPlayground/index.js +12 -0
  67. package/dist/pages/AIPlayground/index.module.less +5 -0
  68. package/dist/pages/Examples/components/Accouncement/index.module.less +1 -1
  69. package/dist/pages/Examples/index.module.less +11 -11
  70. package/dist/pages/Index/components/Cases/index.module.less +8 -8
  71. package/dist/pages/Index/components/Companies/index.module.less +4 -3
  72. package/dist/pages/Index/components/Features/FeatureCard.module.less +4 -5
  73. package/dist/pages/Index/components/Features/index.module.less +5 -5
  74. package/dist/pages/Index/components/_.less +9 -9
  75. package/dist/pages/Index/index.js +1 -1
  76. package/dist/plugin/index.js +14 -6
  77. package/dist/slots/Banner/Notification.module.less +8 -8
  78. package/dist/slots/Banner/index.module.less +10 -9
  79. package/dist/slots/CodeEditor/Toolbar.js +23 -27
  80. package/dist/slots/CodeEditor/Toolbar.module.less +7 -0
  81. package/dist/slots/CodeEditor/index.js +67 -5
  82. package/dist/slots/CodeEditor/index.module.less +24 -0
  83. package/dist/slots/CodeEditor/utils.js +2 -1
  84. package/dist/slots/CodePreview/index.module.less +0 -3
  85. package/dist/slots/CodeRunner/index.js +24 -11
  86. package/dist/slots/ContentTable/index.module.less +2 -1
  87. package/dist/{pages/Index/components → slots}/Detail/News.js +1 -1
  88. package/dist/{pages/Index/components → slots}/Detail/News.module.less +9 -9
  89. package/dist/{pages/Index/components → slots}/Detail/index.js +13 -29
  90. package/dist/{pages/Index/components → slots}/Detail/index.module.less +23 -20
  91. package/dist/slots/ExampleSider/index.module.less +3 -4
  92. package/dist/slots/Footer/index.module.less +2 -2
  93. package/dist/slots/Header/Products/Product.module.less +2 -2
  94. package/dist/slots/Header/Products/getProducts.js +20 -26
  95. package/dist/slots/Header/Products/index.js +20 -16
  96. package/dist/slots/Header/Search/SearchResult.js +53 -14
  97. package/dist/slots/Header/Search/SearchResult.module.less +1 -0
  98. package/dist/slots/Header/Search/index.js +2 -1
  99. package/dist/slots/Header/index.js +72 -30
  100. package/dist/slots/Header/index.module.less +14 -6
  101. package/dist/slots/LiveExample/index.js +1 -1
  102. package/dist/slots/LiveExample/index.module.less +1 -1
  103. package/dist/slots/Loading/index.module.less +30 -28
  104. package/dist/slots/ManualContent/index.module.less +14 -17
  105. package/dist/slots/_.less +9 -9
  106. package/dist/static/user.svg +3 -0
  107. package/dist/typings.d.ts +11 -0
  108. package/dist/utils/analytics.js +16 -0
  109. package/dist/utils/code.js +35 -0
  110. package/dist/utils/env.js +63 -0
  111. package/dist/utils/index.js +7 -0
  112. package/dist/utils/request.js +42 -0
  113. package/package.json +31 -15
@@ -0,0 +1,225 @@
1
+ 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; }
2
+ 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); } }
3
+ 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); }); }; }
4
+ 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); }
5
+ // src/components/DataUploader.tsx
6
+ import React from 'react';
7
+ import { Upload, message, Tooltip } from 'antd';
8
+ import { useRequest } from 'ahooks';
9
+ import { useIntl } from 'dumi';
10
+ import { FileIcons } from "../../../constant";
11
+
12
+ // 定义文件元信息类型,与父组件保持一致
13
+
14
+ // 定义回调函数返回的完整数据类型
15
+
16
+ // 定义组件Props
17
+
18
+ // 新增:直接发送给AI的原始内容最大字符数阈值
19
+ var DIRECT_FEED_CHAR_THRESHOLD = 4000; // 约1k tokens,这是一个比较保守和经济的阈值
20
+ var MAX_FILE_SIZE_MB = 5;
21
+ var MAX_CONTEXT_CHARS = 5000;
22
+ var ALLOWED_FILE_TYPES = ['csv', 'json', 'tsv', 'txt'];
23
+ var MAX_LINES = 10;
24
+
25
+ // --- 辅助函数(与之前相同) ---
26
+ var formatBytes = function formatBytes(bytes) {
27
+ var decimals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
28
+ if (bytes === 0) return '0 Bytes';
29
+ var k = 1024;
30
+ var dm = decimals < 0 ? 0 : decimals;
31
+ var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
32
+ var i = Math.floor(Math.log(bytes) / Math.log(k));
33
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
34
+ };
35
+
36
+ // 这些函数负责将文件内容转换成给AI看的摘要
37
+ function getTableSummary(content, fileType, intl) {
38
+ var lines = content.replace(/\r\n/g, '\n').split('\n');
39
+ if (lines.length === 0) return intl.formatMessage({
40
+ id: 'ai.upload.file.empty'
41
+ });
42
+ var delimiter = fileType === 'csv' ? ',' : '\t';
43
+ var header = lines[0];
44
+ // 取前MAX_LINES行有效数据作为样本
45
+ var sampleRows = lines.slice(1).filter(function (line) {
46
+ return line.trim() !== '';
47
+ }).slice(0, MAX_LINES).join('\n');
48
+ var columnCount = header.split(delimiter).length;
49
+ var rowCount = lines.filter(function (line) {
50
+ return line.trim() !== '';
51
+ }).length;
52
+ return intl.formatMessage({
53
+ id: 'ai.upload.file.table.summary'
54
+ }, {
55
+ rowCount: rowCount,
56
+ columnCount: columnCount,
57
+ header: header,
58
+ maxLines: MAX_LINES,
59
+ sampleRows: sampleRows
60
+ });
61
+ }
62
+ function getJsonSummary(data, intl) {
63
+ if (Array.isArray(data) && data.length > 0 && _typeof(data[0]) === 'object') {
64
+ var keys = Object.keys(data[0]);
65
+ var sampleData = data.slice(0, MAX_LINES).map(function (item) {
66
+ return JSON.stringify(item);
67
+ }).join('\n');
68
+ return intl.formatMessage({
69
+ id: 'ai.upload.file.json.array.summary'
70
+ }, {
71
+ dataLength: data.length,
72
+ keys: keys.join(', '),
73
+ maxLines: MAX_LINES,
74
+ sampleData: sampleData
75
+ });
76
+ }
77
+ return intl.formatMessage({
78
+ id: 'ai.upload.file.json.object.summary'
79
+ }) + '\n' + JSON.stringify(data, null, 2);
80
+ }
81
+
82
+ // --- 文件解析服务函数 ---
83
+ function parseFile(_x, _x2) {
84
+ return _parseFile.apply(this, arguments);
85
+ }
86
+ function _parseFile() {
87
+ _parseFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(file, intl) {
88
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
89
+ while (1) switch (_context.prev = _context.next) {
90
+ case 0:
91
+ return _context.abrupt("return", new Promise(function (resolve, reject) {
92
+ var reader = new FileReader();
93
+ reader.onload = function (event) {
94
+ try {
95
+ var _event$target;
96
+ var fileContent = (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.result;
97
+ var dataSummary;
98
+
99
+ // --- 智能策略判断 ---
100
+ if (fileContent.length <= DIRECT_FEED_CHAR_THRESHOLD) {
101
+ // 策略1:文件内容足够小,直接作为上下文
102
+ dataSummary = intl.formatMessage({
103
+ id: 'ai.upload.file.full.content'
104
+ }, {
105
+ fileContent: fileContent
106
+ });
107
+ } else {
108
+ var _file$name$split$pop2;
109
+ // 策略2:文件内容过大,执行摘要算法
110
+ var fileType = ((_file$name$split$pop2 = file.name.split('.').pop()) === null || _file$name$split$pop2 === void 0 ? void 0 : _file$name$split$pop2.toLowerCase()) || '';
111
+ if (fileType === 'json') {
112
+ var jsonData = JSON.parse(fileContent);
113
+ dataSummary = getJsonSummary(jsonData, intl);
114
+ } else if (['csv', 'tsv', 'txt'].includes(fileType)) {
115
+ dataSummary = getTableSummary(fileContent, fileType, intl);
116
+ } else {
117
+ reject(new Error(intl.formatMessage({
118
+ id: 'ai.upload.file.parse.type.error'
119
+ })));
120
+ return;
121
+ }
122
+ if (dataSummary.length > MAX_CONTEXT_CHARS) {
123
+ dataSummary = dataSummary.substring(0, MAX_CONTEXT_CHARS) + "\n" + intl.formatMessage({
124
+ id: 'ai.upload.file.summary.truncated'
125
+ });
126
+ }
127
+ }
128
+ resolve({
129
+ dataSummary: dataSummary,
130
+ fileMeta: {
131
+ type: 'FILE',
132
+ fileName: file.name,
133
+ fileSize: formatBytes(file.size)
134
+ }
135
+ });
136
+ } catch (e) {
137
+ reject(new Error(intl.formatMessage({
138
+ id: 'ai.upload.file.parse.error'
139
+ })));
140
+ }
141
+ };
142
+ reader.onerror = function () {
143
+ return reject(new Error(intl.formatMessage({
144
+ id: 'ai.upload.file.read.error'
145
+ })));
146
+ };
147
+ reader.readAsText(file);
148
+ }));
149
+ case 1:
150
+ case "end":
151
+ return _context.stop();
152
+ }
153
+ }, _callee);
154
+ }));
155
+ return _parseFile.apply(this, arguments);
156
+ }
157
+ export var DataUploader = function DataUploader(_ref) {
158
+ var onDataAnalyzed = _ref.onDataAnalyzed,
159
+ isCompact = _ref.isCompact,
160
+ tooltipText = _ref.tooltipText;
161
+ var intl = useIntl();
162
+ var _useRequest = useRequest(function (file) {
163
+ return parseFile(file, intl);
164
+ }, {
165
+ manual: true,
166
+ onSuccess: function onSuccess(result) {
167
+ // message.success(`${result.fileMeta?.fileName} 分析成功!`);
168
+ onDataAnalyzed(result);
169
+ },
170
+ onError: function onError(e) {
171
+ message.error(e.message);
172
+ // 如果解析失败,也需要通知父组件清空数据
173
+ onDataAnalyzed({
174
+ fileMeta: null,
175
+ dataSummary: ''
176
+ });
177
+ }
178
+ }),
179
+ runParse = _useRequest.run,
180
+ loading = _useRequest.loading;
181
+ var uploadProps = {
182
+ showUploadList: false,
183
+ // 我们用自己的DatasourceCard来回显,所以隐藏默认列表
184
+ accept: ALLOWED_FILE_TYPES.map(function (ext) {
185
+ return ".".concat(ext);
186
+ }).join(','),
187
+ beforeUpload: function beforeUpload(file) {
188
+ var _file$name$split$pop;
189
+ var fileExtension = ((_file$name$split$pop = file.name.split('.').pop()) === null || _file$name$split$pop === void 0 ? void 0 : _file$name$split$pop.toLowerCase()) || '';
190
+ if (!ALLOWED_FILE_TYPES.includes(fileExtension)) {
191
+ message.error(intl.formatMessage({
192
+ id: 'ai.upload.file.type.error'
193
+ }, {
194
+ types: ALLOWED_FILE_TYPES.join(', ')
195
+ }));
196
+ return Upload.LIST_IGNORE;
197
+ }
198
+ if (file.size / 1024 / 1024 > MAX_FILE_SIZE_MB) {
199
+ message.error(intl.formatMessage({
200
+ id: 'ai.upload.file.size.error'
201
+ }, {
202
+ size: MAX_FILE_SIZE_MB
203
+ }));
204
+ return Upload.LIST_IGNORE;
205
+ }
206
+ runParse(file);
207
+ return false; // 总是返回 false 来手动控制
208
+ }
209
+ };
210
+ return /*#__PURE__*/React.createElement(Tooltip, {
211
+ title: isCompact ? "".concat(intl.formatMessage({
212
+ id: 'ai.upload.data'
213
+ }), "\u3002").concat(tooltipText) : tooltipText
214
+ }, /*#__PURE__*/React.createElement(Upload, uploadProps, /*#__PURE__*/React.createElement("button", {
215
+ type: "button",
216
+ disabled: loading
217
+ }, loading ? intl.formatMessage({
218
+ id: 'ai.upload.analyzing'
219
+ }) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("img", {
220
+ src: FileIcons.FILE,
221
+ alt: "file-icon"
222
+ }), " ", !isCompact && intl.formatMessage({
223
+ id: 'ai.upload.data'
224
+ })))));
225
+ };
@@ -0,0 +1,172 @@
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 _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; }
3
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
4
+ 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); }
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 { DatasourceCard } from "./DatasourceCard";
12
+ import { useEventListener } from 'ahooks';
13
+ import classnames from 'classnames';
14
+ import _ from 'lodash';
15
+ import React, { useEffect, useRef, useState } from 'react';
16
+ import styles from "./index.module.less";
17
+ import { SendButton } from "./SendButton";
18
+ import { ChooseLib } from "./ChooseLib";
19
+ import { useSiteData, useIntl } from 'dumi';
20
+ import { ic } from "../../../../slots/hooks";
21
+ import { useTypewriter } from "../../../../hooks/useTypewriter";
22
+ import { authStore, showLoginModal } from "../../../../model/auth";
23
+ import { useSnapshot } from "valtio";
24
+ import { AIChatStore } from "../../../../model/AIChat";
25
+ import { ModeSelectorDropdown } from "../ModeSelector/ModeSelectorDropdown";
26
+ var PLACEHOLDER = {
27
+ implement: 'ai.placeholder.implement',
28
+ solve: 'ai.placeholder.solve'
29
+ };
30
+ export var PromptTextarea = /*#__PURE__*/React.memo(function PromptTextareaInner(props) {
31
+ var value = props.value,
32
+ size = props.size,
33
+ _onChange = props.onChange,
34
+ onDataSummaryChange = props.onDataSummaryChange,
35
+ onConfirm = props.onConfirm,
36
+ onCancel = props.onCancel,
37
+ loading = props.loading,
38
+ _props$showAction = props.showAction,
39
+ showAction = _props$showAction === void 0 ? true : _props$showAction,
40
+ _props$showModeSelect = props.showModeSelector,
41
+ showModeSelector = _props$showModeSelect === void 0 ? false : _props$showModeSelect;
42
+ var snap = useSnapshot(AIChatStore);
43
+ var authSnap = useSnapshot(authStore);
44
+ var _useIntl = useIntl(),
45
+ formatMessage = _useIntl.formatMessage;
46
+ var textareaRef = useRef(null);
47
+ var _useSiteData = useSiteData(),
48
+ themeConfig = _useSiteData.themeConfig;
49
+ useEffect(function () {
50
+ if (!themeConfig.isAntVSite && !snap.lib) {
51
+ AIChatStore.lib = themeConfig.title;
52
+ }
53
+ }, [themeConfig.isAntVSite, themeConfig.title]);
54
+ // 将fileMeta状态移到组件内部管理
55
+ var _useState = useState(null),
56
+ _useState2 = _slicedToArray(_useState, 2),
57
+ fileMeta = _useState2[0],
58
+ setFileMeta = _useState2[1];
59
+
60
+ // ... 其他状态和hooks保持不变
61
+ var _useState3 = useState(false),
62
+ _useState4 = _slicedToArray(_useState3, 2),
63
+ focus = _useState4[0],
64
+ setFocus = _useState4[1];
65
+ var isCompact = size === 'compact';
66
+ var typedPlaceholder = useTypewriter({
67
+ texts: [formatMessage({
68
+ id: 'ai.placeholder.whatis'
69
+ }, {
70
+ title: themeConfig.title
71
+ }), ic(themeConfig.metas.description)]
72
+ });
73
+
74
+ // 处理DataUploader的回调
75
+ var handleDataAnalyzed = function handleDataAnalyzed(analyzedData) {
76
+ setFileMeta(analyzedData.fileMeta);
77
+ if (onDataSummaryChange) {
78
+ onDataSummaryChange(analyzedData.dataSummary);
79
+ }
80
+ };
81
+ function renderDatasourceCard() {
82
+ if (((fileMeta === null || fileMeta === void 0 ? void 0 : fileMeta.type) === 'FILE' || (fileMeta === null || fileMeta === void 0 ? void 0 : fileMeta.type) === 'IMAGE') && fileMeta !== null && fileMeta !== void 0 && fileMeta.fileName) {
83
+ // 当点击DatasourceCard的关闭按钮时,应该清空状态
84
+ var handleClose = function handleClose() {
85
+ setFileMeta(null);
86
+ if (onDataSummaryChange) {
87
+ onDataSummaryChange('');
88
+ }
89
+ };
90
+ return /*#__PURE__*/React.createElement(DatasourceCard, {
91
+ type: fileMeta.type,
92
+ title: fileMeta.fileName,
93
+ desc: fileMeta.fileSize,
94
+ onDelete: handleClose
95
+ });
96
+ } else {
97
+ return null;
98
+ }
99
+ }
100
+ var datasourceNode = renderDatasourceCard();
101
+ var promptTextValid = Boolean(value);
102
+ var pureSend = function pureSend() {
103
+ if (promptTextValid) {
104
+ onConfirm === null || onConfirm === void 0 || onConfirm();
105
+ }
106
+ };
107
+ var send = function send() {
108
+ if (!authSnap.isAuthenticated) {
109
+ showLoginModal(pureSend);
110
+ return;
111
+ }
112
+ pureSend();
113
+ };
114
+ useEventListener('keydown', function (event) {
115
+ if (event.key === 'Enter') {
116
+ // 不区分 textarea 是否聚焦
117
+ if (!event.shiftKey && !event.isComposing && !loading) {
118
+ event.preventDefault();
119
+ send(); // 触发自定义事件
120
+ }
121
+ }
122
+ }, {
123
+ target: textareaRef
124
+ });
125
+ return /*#__PURE__*/React.createElement("div", {
126
+ className: classnames(styles.container, _defineProperty(_defineProperty(_defineProperty({}, styles.active, focus), styles.compact, isCompact), styles.withDatasource, Boolean(datasourceNode))),
127
+ style: props.style
128
+ }, datasourceNode && /*#__PURE__*/React.createElement("div", {
129
+ className: styles.header
130
+ }, datasourceNode), /*#__PURE__*/React.createElement("textarea", {
131
+ onFocus: function onFocus() {
132
+ return setFocus(true);
133
+ },
134
+ onBlur: function onBlur() {
135
+ return setFocus(false);
136
+ },
137
+ id: "prompt-textarea",
138
+ className: classnames(styles.promptTextarea),
139
+ ref: textareaRef,
140
+ placeholder:
141
+ // (!isCompact && !themeConfig.isAntVSite && ic(themeConfig.metas.description)) ||
142
+ !isCompact && !themeConfig.isAntVSite ? typedPlaceholder : formatMessage({
143
+ id: _.get(PLACEHOLDER, snap.mode, 'ai.placeholder.implement')
144
+ }),
145
+ value: value,
146
+ onChange: function onChange(evt) {
147
+ _onChange(evt.target.value);
148
+ }
149
+ }), /*#__PURE__*/React.createElement("div", {
150
+ className: styles.footer
151
+ }, /*#__PURE__*/React.createElement("div", {
152
+ className: styles.dataActions
153
+ }, showAction && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ChooseLib, {
154
+ size: size,
155
+ value: snap.lib,
156
+ onChange: function onChange(s) {
157
+ return AIChatStore.lib = s;
158
+ }
159
+ })), showModeSelector && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ModeSelectorDropdown, null))), /*#__PURE__*/React.createElement("div", {
160
+ className: styles.actions
161
+ }, loading ? /*#__PURE__*/React.createElement("img", {
162
+ className: styles.actionBtn,
163
+ onClick: onCancel,
164
+ src: "https://mdn.alipayobjects.com/huamei_2yzvel/afts/img/A*Yin-QLza5hMAAAAAQBAAAAgAeriAAQ/original"
165
+ }) : /*#__PURE__*/React.createElement(SendButton, {
166
+ onClick: send,
167
+ disabled: !promptTextValid,
168
+ tip: !promptTextValid ? formatMessage({
169
+ id: 'ai.msgbox.send.tip'
170
+ }) : undefined
171
+ }))));
172
+ });
@@ -0,0 +1,128 @@
1
+ .container {
2
+ position: relative;
3
+ margin: 0 auto;
4
+ width: 760px;
5
+ height: 144px;
6
+ font-size: 0;
7
+ padding: 16px;
8
+ gap: 16px;
9
+ transition: all 0.2s;
10
+ border: 1px solid rgba(134, 144, 156, 20%);
11
+ border-radius: 16px;
12
+ background: #fff9;
13
+ box-shadow: 8px 8px 20px 0 #0000000a, inset 1px -1px 0 0 #ffffffe3;
14
+ z-index: 10;
15
+ display: flex;
16
+ flex-direction: column;
17
+
18
+ &.withDatasource {
19
+ height: 184px;
20
+ }
21
+
22
+ .header {
23
+ > div {
24
+ max-width: 300px;
25
+ }
26
+ }
27
+
28
+ .footer {
29
+ display: flex;
30
+ flex-direction: row;
31
+ justify-content: space-between;
32
+ height: 32px;
33
+
34
+ .dataActions {
35
+ display: flex;
36
+ gap: 8px;
37
+
38
+ :global {
39
+ button {
40
+ cursor: pointer;
41
+ display: inline-flex;
42
+ align-items: center;
43
+ height: 32px;
44
+ padding: 0 12px;
45
+ border-radius: 8px;
46
+ outline: none;
47
+ max-width: 240px;
48
+ background: #3f4b660a;
49
+ font-size: 14px;
50
+ color: #1d2129;
51
+ border-color: transparent;
52
+
53
+ &.btn-error {
54
+ color: #ff4d4f;
55
+ box-shadow: inset 1px -1px 0 0 rgba(255, 255, 255, 89%),
56
+ 0 0 12px 0 rgba(250, 16, 16, 23%);
57
+ }
58
+
59
+ .btn-icon,
60
+ img {
61
+ display: block;
62
+ width: 20px;
63
+ height: 20px;
64
+ margin-right: 4px;
65
+ }
66
+
67
+ span {
68
+ white-space: nowrap;
69
+ overflow: hidden;
70
+ text-overflow: ellipsis;
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
76
+
77
+ &.active {
78
+ background: #fff9;
79
+ border: 1px solid #1677ff;
80
+ box-shadow: 0 8px 20px 0 #1677ff29, inset 1px -1px 0 0 #ffffffe3;
81
+
82
+ .promptTextarea::placeholder {
83
+ color: transparent;
84
+ }
85
+ }
86
+
87
+ &.compact {
88
+ margin-bottom: 0;
89
+ padding: 8px 12px;
90
+ gap: 6px;
91
+ width: 100%;
92
+ height: 124px;
93
+
94
+ &.withDatasource {
95
+ height: 160px;
96
+ }
97
+
98
+ .promptTextarea {
99
+ font-size: 14px;
100
+ }
101
+ }
102
+ }
103
+
104
+ .datasourceBtn {
105
+ position: absolute;
106
+ left: 20px;
107
+ bottom: 20px;
108
+ width: 10px;
109
+ height: 10px;
110
+ background-color: red;
111
+ }
112
+
113
+ .promptTextarea {
114
+ flex: 1 1;
115
+ display: block;
116
+ font-size: 16px;
117
+ color: #1d2129;
118
+ width: 100%;
119
+ resize: none;
120
+ border: none;
121
+ outline: none;
122
+ padding: 0;
123
+ background: transparent;
124
+
125
+ &::placeholder {
126
+ color: rgba(122, 132, 153, 85%);
127
+ }
128
+ }
@@ -0,0 +1,80 @@
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
+ import { Popover } from 'antd';
3
+ import React from 'react';
4
+ import styles from "./card.module.less";
5
+ import { BarChartOutlined, QuestionCircleOutlined } from "@ant-design/icons";
6
+ import { AIMode, AIModeMeta, COLORS } from "../../constant";
7
+ import { FormattedMessage, useLocale } from 'dumi';
8
+ export var Card = function Card(_ref) {
9
+ var _AIModeMeta$tag;
10
+ var item = _ref.item,
11
+ index = _ref.index,
12
+ onClick = _ref.onClick;
13
+ var _item$query = item.query,
14
+ query = _item$query === void 0 ? {} : _item$query,
15
+ _item$description = item.description,
16
+ description = _item$description === void 0 ? {} : _item$description,
17
+ _item$imageUrls = item.imageUrls,
18
+ imageUrls = _item$imageUrls === void 0 ? [] : _item$imageUrls,
19
+ tag = item.tag;
20
+ var style = COLORS[index];
21
+ var locale = useLocale();
22
+ var lang = locale.id === 'zh' ? 'zh' : 'en';
23
+ var handleClick = function handleClick(e) {
24
+ e.stopPropagation();
25
+ onClick === null || onClick === void 0 || onClick();
26
+ };
27
+ var popoverContent = /*#__PURE__*/React.createElement("div", {
28
+ className: styles.popoverContent
29
+ }, /*#__PURE__*/React.createElement("div", {
30
+ className: styles.popoverItem
31
+ }, /*#__PURE__*/React.createElement("div", {
32
+ className: styles.popoverLabel
33
+ }, /*#__PURE__*/React.createElement(FormattedMessage, {
34
+ id: "ai.recommend.card.caseName"
35
+ })), /*#__PURE__*/React.createElement("div", {
36
+ className: styles.popoverValue
37
+ }, _typeof(query) === 'object' ? query[lang] : query)), /*#__PURE__*/React.createElement("div", {
38
+ className: styles.popoverItem
39
+ }, /*#__PURE__*/React.createElement("div", {
40
+ className: styles.popoverLabel
41
+ }, /*#__PURE__*/React.createElement(FormattedMessage, {
42
+ id: "ai.recommend.card.description"
43
+ })), /*#__PURE__*/React.createElement("div", {
44
+ className: styles.popoverValue
45
+ }, _typeof(description) === 'object' ? description[lang] : description)));
46
+ return /*#__PURE__*/React.createElement(Popover, {
47
+ content: popoverContent,
48
+ placement: "top",
49
+ overlayClassName: styles.popoverOverlay
50
+ }, /*#__PURE__*/React.createElement("div", {
51
+ className: styles.card,
52
+ style: {
53
+ background: style === null || style === void 0 ? void 0 : style.backgroundColor
54
+ },
55
+ onClick: handleClick
56
+ }, /*#__PURE__*/React.createElement("div", {
57
+ className: styles.typeTag,
58
+ style: style
59
+ }, tag === AIMode.implement ? /*#__PURE__*/React.createElement(BarChartOutlined, {
60
+ className: styles.typeIcon
61
+ }) : /*#__PURE__*/React.createElement(QuestionCircleOutlined, {
62
+ className: styles.typeIcon
63
+ }), /*#__PURE__*/React.createElement("span", {
64
+ className: styles.typeText
65
+ }, /*#__PURE__*/React.createElement(FormattedMessage, {
66
+ id: ((_AIModeMeta$tag = AIModeMeta[tag]) === null || _AIModeMeta$tag === void 0 ? void 0 : _AIModeMeta$tag.name) || tag
67
+ }))), /*#__PURE__*/React.createElement("div", {
68
+ className: styles.title
69
+ }, _typeof(query) === 'object' ? query[lang] : query), /*#__PURE__*/React.createElement("div", {
70
+ className: styles.imageContainer
71
+ }, imageUrls.slice(0, 2).map(function (item, idx) {
72
+ return /*#__PURE__*/React.createElement("img", {
73
+ src: item,
74
+ key: idx,
75
+ className: styles["image".concat(idx)]
76
+ });
77
+ })), /*#__PURE__*/React.createElement("div", {
78
+ className: styles.hoverMask
79
+ })));
80
+ };