@myun/gimi-chat 0.9.10 → 0.9.12

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.
@@ -64,5 +64,5 @@ export interface IUseApi {
64
64
  checkProductType: (productId: number) => Promise<FetchResponse<any>>;
65
65
  getBusinessAgent: (bussinessType: number) => Promise<FetchResponse<any>>;
66
66
  }
67
- declare const useApi: (baseUrl: string, authToken: string) => IUseApi;
67
+ declare const useApi: (baseUrl: string, authToken: string, locale?: string) => IUseApi;
68
68
  export default useApi;
@@ -4,6 +4,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
4
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
5
  import { createFetch } from "./fetch";
6
6
  var useApi = function useApi(baseUrl, authToken) {
7
+ var locale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'zh-cn';
7
8
  var token = authToken;
8
9
  var baseURL = baseUrl;
9
10
  var fetchService = createFetch({
@@ -12,7 +13,8 @@ var useApi = function useApi(baseUrl, authToken) {
12
13
  headers: {
13
14
  'Authorization': 'Bearer ' + token,
14
15
  'X-Mc-Domain': location.hostname,
15
- 'Content-Type': 'application/json'
16
+ 'Content-Type': 'application/json',
17
+ 'Language': locale
16
18
  }
17
19
  });
18
20
  var getAiCorrection = /*#__PURE__*/function () {
@@ -10,6 +10,7 @@ import WorkFlowContent from "../work-flow-content";
10
10
  import ExcelSuccessCard from "../excel-components/ExcelSuccessCard";
11
11
  import KnowledgeIconGroup from "../knowledge-trace/KnowledgeIconComponent";
12
12
  import ExcelCard from "../excel-components/ExcelCard";
13
+ import WordCard from "../custom-render/WordCard";
13
14
  import { IconTickCircle } from '@douyinfe/semi-icons';
14
15
  import VoicePlay from "../message-actions/VoicePlay";
15
16
  import { useAppSelector } from "../../store/hooks";
@@ -111,6 +112,18 @@ var AnswerItem = function AnswerItem(_ref) {
111
112
  value: newVal
112
113
  });
113
114
  }
115
+ }, {
116
+ type: 'word',
117
+ component: function component(value) {
118
+ var newVal = {
119
+ content: value.value,
120
+ onDownloadCallback: onDownloadCallback,
121
+ model: model
122
+ };
123
+ return /*#__PURE__*/React.createElement(WordCard, {
124
+ value: newVal
125
+ });
126
+ }
114
127
  }, {
115
128
  type: 'knowledge',
116
129
  component: function component(value) {
@@ -0,0 +1,8 @@
1
+ declare const WordCard: ({ value }: {
2
+ value: {
3
+ content: any;
4
+ onDownloadCallback?: () => void;
5
+ model: 'fullscreen' | 'sidebar';
6
+ };
7
+ }) => any;
8
+ export default WordCard;
@@ -0,0 +1,62 @@
1
+ import React from "react";
2
+ import { useTranslation } from 'react-i18next';
3
+ import { FileCard, MultipleFileCard } from "../file-card";
4
+ var transforata = function transforata(data, t) {
5
+ var fileName = data.fileName || t('excel.defaultFileName') + '.docx';
6
+ var size = data.size || '0.0KB';
7
+ var downloadUrl = data.fileAddr || '';
8
+ var tempArr = fileName.split('.');
9
+ var fileType = (tempArr === null || tempArr === void 0 ? void 0 : tempArr.length) > 1 ? tempArr.pop() : 'docx';
10
+ return {
11
+ fileName: fileName,
12
+ fileType: fileType,
13
+ size: size,
14
+ downloadUrl: downloadUrl
15
+ };
16
+ };
17
+ var WordCard = function WordCard(_ref) {
18
+ var _detail, _detail2;
19
+ var value = _ref.value;
20
+ var _useTranslation = useTranslation(),
21
+ t = _useTranslation.t;
22
+ var _ref2 = value || {},
23
+ content = _ref2.content,
24
+ onDownloadCallback = _ref2.onDownloadCallback,
25
+ model = _ref2.model;
26
+ var detail = {};
27
+ try {
28
+ detail = typeof content === 'string' ? JSON.parse(content) : content;
29
+ } catch (error) {
30
+ console.error(error);
31
+ return content;
32
+ }
33
+ if (((_detail = detail) === null || _detail === void 0 ? void 0 : _detail.code) !== 0) return content;
34
+ var skillDetail = ((_detail2 = detail) === null || _detail2 === void 0 || (_detail2 = _detail2.data) === null || _detail2 === void 0 ? void 0 : _detail2.list) || [];
35
+ if (Array.isArray(skillDetail)) {
36
+ var renderData = skillDetail.map(function (item) {
37
+ return transforata(item, t);
38
+ });
39
+ return /*#__PURE__*/React.createElement(MultipleFileCard, {
40
+ list: renderData,
41
+ onDownloadCallback: onDownloadCallback,
42
+ model: model,
43
+ showAll: true
44
+ });
45
+ }
46
+ var _transforata = transforata(skillDetail, t),
47
+ fileName = _transforata.fileName,
48
+ downloadUrl = _transforata.downloadUrl,
49
+ size = _transforata.size,
50
+ fileType = _transforata.fileType;
51
+ return /*#__PURE__*/React.createElement(FileCard, {
52
+ fileName: fileName,
53
+ fileType: fileType,
54
+ size: size,
55
+ downloadUrl: downloadUrl,
56
+ downloadText: t('excel.download'),
57
+ onDownloadCallback: onDownloadCallback,
58
+ model: model,
59
+ disablePreview: true
60
+ });
61
+ };
62
+ export default WordCard;
@@ -2,7 +2,7 @@ import React from "react";
2
2
  import { useTranslation } from 'react-i18next';
3
3
  import { FileCard, MultipleFileCard } from "../file-card";
4
4
  var transforata = function transforata(data, t) {
5
- var fileName = data.file_name || t('excel.defaultFileName');
5
+ var fileName = data.file_name || t('excel.defaultFileName') + '.xlsx';
6
6
  var size = data.size || '0.0KB';
7
7
  var downloadUrl = data.result_url || '';
8
8
  var tempArr = fileName.split('.');
@@ -9,10 +9,12 @@ export interface IFileCardProps {
9
9
  export declare const FileCard: React.FC<IFileCardProps & {
10
10
  downloadText?: string;
11
11
  model: 'fullscreen' | 'sidebar';
12
+ disablePreview?: boolean;
12
13
  }>;
13
14
  export declare const MultipleFileCard: React.FC<{
14
15
  list: IFileCardProps[];
15
16
  onDownloadCallback?: () => void;
16
17
  model: 'fullscreen' | 'sidebar';
18
+ showAll?: boolean;
17
19
  }>;
18
20
  export default MultipleFileCard;
@@ -14,16 +14,23 @@ export var FileCard = function FileCard(_ref) {
14
14
  fileType = _ref.fileType,
15
15
  downloadText = _ref.downloadText,
16
16
  onDownloadCallback = _ref.onDownloadCallback,
17
- model = _ref.model;
17
+ model = _ref.model,
18
+ _ref$disablePreview = _ref.disablePreview,
19
+ disablePreview = _ref$disablePreview === void 0 ? false : _ref$disablePreview;
18
20
  var _useTranslation = useTranslation(),
19
21
  t = _useTranslation.t;
20
22
  var dispatch = useAppDispatch();
23
+ var fileImgMap = {
24
+ "docx": "https://simg01.gaodunwangxiao.com/uploadfiles/tmp/upload/202604/22/2fe5c_20260422110615.png",
25
+ "xlsx": "https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202512/19/b8723_20251219094824.png"
26
+ };
21
27
  var handleDownLoad = function handleDownLoad(_event) {
22
28
  _event.stopPropagation();
23
- downloadExcelByUrl(downloadUrl, decodeURIComponent(fileName) || t('file.defaultFileName'));
29
+ downloadExcelByUrl(downloadUrl, decodeURIComponent(fileName) || t('file.defaultFileName') + '.' + fileType);
24
30
  onDownloadCallback === null || onDownloadCallback === void 0 || onDownloadCallback();
25
31
  };
26
32
  var previewExcel = function previewExcel() {
33
+ if (disablePreview) return;
27
34
  if (model === 'sidebar') {
28
35
  window.open("https://view.officeapps.live.com/op/embed.aspx?src=".concat(encodeURIComponent(downloadUrl)), '_blank');
29
36
  return;
@@ -42,7 +49,7 @@ export var FileCard = function FileCard(_ref) {
42
49
  }, /*#__PURE__*/React.createElement("div", {
43
50
  className: styles.icon
44
51
  }, /*#__PURE__*/React.createElement("img", {
45
- src: "https://simg01.gaodunwangxiao.com/uploadimgs/tmp/upload/202512/19/b8723_20251219094824.png",
52
+ src: fileImgMap[fileType] || fileImgMap['xlsx'],
46
53
  alt: ""
47
54
  })), /*#__PURE__*/React.createElement("div", {
48
55
  className: styles.left
@@ -72,12 +79,14 @@ export var FileCard = function FileCard(_ref) {
72
79
  export var MultipleFileCard = function MultipleFileCard(_ref2) {
73
80
  var list = _ref2.list,
74
81
  onDownloadCallback = _ref2.onDownloadCallback,
75
- model = _ref2.model;
82
+ model = _ref2.model,
83
+ _ref2$showAll = _ref2.showAll,
84
+ showAll = _ref2$showAll === void 0 ? false : _ref2$showAll;
76
85
  var dispatch = useAppDispatch();
77
86
  var _useTranslation2 = useTranslation(),
78
87
  t = _useTranslation2.t;
79
88
  var renderList = [];
80
- var hasMore = (list === null || list === void 0 ? void 0 : list.length) > 2;
89
+ var hasMore = !showAll && (list === null || list === void 0 ? void 0 : list.length) > 2;
81
90
  if (hasMore) {
82
91
  renderList = list.slice(0, 2);
83
92
  } else {
@@ -35,7 +35,7 @@ var GimiChatComponent = /*#__PURE__*/React.forwardRef(function (props, ref) {
35
35
  }
36
36
  };
37
37
  });
38
- var apiService = useApi(props.baseUrl, props.token);
38
+ var apiService = useApi(props.baseUrl, props.token, props.locale);
39
39
  return /*#__PURE__*/React.createElement(Provider, {
40
40
  store: store
41
41
  }, /*#__PURE__*/React.createElement(GimiChatI18nProvider, {
@@ -19,7 +19,8 @@ import { setIsMsgRecieving } from "../store/slices/gimiMenuSlice";
19
19
  */
20
20
  export var useChatStream = function useChatStream(platform) {
21
21
  var _useTranslation = useTranslation(),
22
- t = _useTranslation.t;
22
+ t = _useTranslation.t,
23
+ i18n = _useTranslation.i18n;
23
24
  var esAbortRef = useRef(null);
24
25
  var esRef = useRef(null);
25
26
  var ignoreOnMessageRef = useRef(true);
@@ -104,7 +105,8 @@ export var useChatStream = function useChatStream(platform) {
104
105
  Accept: 'text/event-stream',
105
106
  'Cache-Control': 'no-cache',
106
107
  Connection: 'keep-alive',
107
- Authorization: "Bearer ".concat(tokenRef.current)
108
+ Authorization: "Bearer ".concat(tokenRef.current),
109
+ 'Language': i18n.language
108
110
  }, method === 'POST' ? {
109
111
  'Content-Type': 'application/json'
110
112
  } : {}),
@@ -225,7 +227,7 @@ export var useChatStream = function useChatStream(platform) {
225
227
  return function (_x) {
226
228
  return _ref.apply(this, arguments);
227
229
  };
228
- }(), [getLastEventId, saveLastEventId, removeLastEventId, dispatch, platform]);
230
+ }(), [getLastEventId, saveLastEventId, removeLastEventId, dispatch, platform, i18n.language]);
229
231
 
230
232
  /**
231
233
  * 中止流式请求
@@ -36,7 +36,8 @@ import { FileStatus } from "../interfaces/fileInterface";
36
36
  import useChatHistory from "./useChatHistory";
37
37
  var useCommonChatAPI = function useCommonChatAPI(props) {
38
38
  var _useTranslation = useTranslation(),
39
- t = _useTranslation.t;
39
+ t = _useTranslation.t,
40
+ i18n = _useTranslation.i18n;
40
41
  var containerRef = props.containerRef,
41
42
  platform = props.platform,
42
43
  stopTTSByText = props.stopTTSByText,
@@ -736,7 +737,8 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
736
737
  method: 'POST',
737
738
  headers: {
738
739
  'Content-Type': 'application/json',
739
- Authorization: "Bearer ".concat(tokenRef.current)
740
+ Authorization: "Bearer ".concat(tokenRef.current),
741
+ 'Language': i18n.language
740
742
  },
741
743
  signal: signal,
742
744
  body: JSON.stringify(params)
@@ -193,7 +193,7 @@ var enUS = {
193
193
  'excel.finishing': 'Analysis complete. Result is being generated and prepared for presentation...',
194
194
  'excel.finished': 'Analysis complete. Result is being generated and prepared for presentation',
195
195
  'excel.retry': 'Retry',
196
- 'excel.defaultFileName': 'Download.xlsx',
196
+ 'excel.defaultFileName': 'Download',
197
197
  'excel.download': 'Download',
198
198
  // AI Chat Dialogue
199
199
  'aiDialogue.newConversation': 'New Chat',
@@ -193,7 +193,7 @@ var zhCN = {
193
193
  'excel.finishing': '分析完成,结果载体即将生成,正准备呈现...',
194
194
  'excel.finished': '分析完成,结果载体即将生成,正在准备呈现',
195
195
  'excel.retry': '重试',
196
- 'excel.defaultFileName': '文件下载.xlsx',
196
+ 'excel.defaultFileName': '文件下载',
197
197
  'excel.download': '下载',
198
198
  // AI Chat Dialogue
199
199
  'aiDialogue.newConversation': '新对话',