@myun/gimi-chat 0.9.6 → 0.9.7

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 (83) hide show
  1. package/dist/client/components/history-list/index.js +14 -11
  2. package/dist/client/components/slider/index.js +5 -2
  3. package/dist/client/core/index.js +6 -2
  4. package/dist/components/ai-chat-dialogue/index.js +26 -23
  5. package/dist/components/ai-loading/index.js +4 -1
  6. package/dist/components/answer-item/index.js +7 -4
  7. package/dist/components/ask-card/index.js +5 -2
  8. package/dist/components/ask-card/index.module.css +8 -1
  9. package/dist/components/chat-input/index.js +29 -25
  10. package/dist/components/chat-voice/VoiceCommunication.js +6 -4
  11. package/dist/components/chat-voice/VoiceRecord.js +6 -3
  12. package/dist/components/conversation-delete/index.js +5 -2
  13. package/dist/components/excel-components/ExcelExcuting.js +28 -23
  14. package/dist/components/excel-components/ExcelFailCard.js +4 -1
  15. package/dist/components/excel-components/ExcelSuccessCard.js +8 -5
  16. package/dist/components/excel-components/index.module.css +1 -1
  17. package/dist/components/file-card/fileCardSidebar.js +7 -2
  18. package/dist/components/file-card/index.js +10 -5
  19. package/dist/components/file-card/index.module.css +3 -1
  20. package/dist/components/file-upload/index.js +15 -7
  21. package/dist/components/file-upload/uploadV1.js +15 -8
  22. package/dist/components/knowledge-trace/KnowledgeIconComponent.js +10 -2
  23. package/dist/components/knowledge-trace/classList.js +11 -4
  24. package/dist/components/knowledge-trace/documentList.js +11 -4
  25. package/dist/components/knowledge-trace/index.js +6 -3
  26. package/dist/components/knowledge-trace/index.module.css +6 -3
  27. package/dist/components/knowledge-trace/videoList.js +16 -6
  28. package/dist/components/message-actions/CopyButton.js +4 -1
  29. package/dist/components/message-actions/LikeButton.js +4 -1
  30. package/dist/components/message-actions/RegenerateButton.js +5 -2
  31. package/dist/components/message-actions/UnLikeButton.js +4 -1
  32. package/dist/components/message-actions/VoicePlay.js +6 -2
  33. package/dist/components/no-microphone-root/index.js +9 -7
  34. package/dist/components/no-microphone-root/index.module.css +10 -1
  35. package/dist/components/product-tag/index.js +10 -7
  36. package/dist/components/quoted-content/index.js +17 -12
  37. package/dist/components/reasoning-content/index.js +8 -5
  38. package/dist/components/reasoning-search/index.d.ts +1 -1
  39. package/dist/components/reasoning-search/index.js +15 -6
  40. package/dist/components/reference-content/index.js +10 -3
  41. package/dist/components/search-course-list/index.js +13 -6
  42. package/dist/components/search-course-list/index.module.css +6 -3
  43. package/dist/components/search-course-list/sidebar.js +7 -2
  44. package/dist/components/templates/GimiChatComponent.js +5 -1
  45. package/dist/components/unified-sidebar/FileListContent.js +8 -2
  46. package/dist/components/unified-sidebar/KnowledgeTraceContent.d.ts +1 -0
  47. package/dist/components/unified-sidebar/KnowledgeTraceContent.js +33 -3
  48. package/dist/components/unified-sidebar/SearchCourseListContent.js +8 -4
  49. package/dist/components/unified-sidebar/index.js +14 -8
  50. package/dist/components/upload-list/index.js +6 -3
  51. package/dist/components/voice-recording/index.js +10 -7
  52. package/dist/components/work-flow-content/index.js +7 -1
  53. package/dist/hooks/useChatActions.js +9 -6
  54. package/dist/hooks/useChatHistory.js +4 -1
  55. package/dist/hooks/useChatRecommend.js +7 -4
  56. package/dist/hooks/useChatStream.js +12 -2
  57. package/dist/hooks/useChatVoice.js +12 -6
  58. package/dist/hooks/useCommonChatAPI.js +25 -21
  59. package/dist/hooks/useFile.js +14 -9
  60. package/dist/hooks/useLongPoll.js +5 -2
  61. package/dist/hooks/useSearchCase.js +5 -2
  62. package/dist/i18n/GimiChatI18nProvider.d.ts +9 -0
  63. package/dist/i18n/GimiChatI18nProvider.js +25 -0
  64. package/dist/i18n/core.d.ts +12 -0
  65. package/dist/i18n/core.js +71 -0
  66. package/dist/i18n/index.d.ts +4 -0
  67. package/dist/i18n/index.js +3 -0
  68. package/dist/i18n/locales/en-US.d.ts +216 -0
  69. package/dist/i18n/locales/en-US.js +242 -0
  70. package/dist/i18n/locales/zh-CN.d.ts +216 -0
  71. package/dist/i18n/locales/zh-CN.js +242 -0
  72. package/dist/i18n/useGimiChatTranslation.d.ts +2 -0
  73. package/dist/i18n/useGimiChatTranslation.js +5 -0
  74. package/dist/index.d.ts +1 -0
  75. package/dist/index.js +1 -0
  76. package/dist/types/chat.d.ts +4 -1
  77. package/dist/types/modules.d.ts +1 -0
  78. package/dist/umd/index.min.js +1 -1
  79. package/dist/utils/tools.d.ts +1 -1
  80. package/dist/utils/tools.js +5 -5
  81. package/dist/utils/voice-stream.d.ts +2 -0
  82. package/dist/utils/voice-stream.js +43 -20
  83. package/package.json +6 -4
@@ -15,6 +15,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
15
15
  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); }); }; }
16
16
  import React from 'react';
17
17
  import { Toast } from '@douyinfe/semi-ui';
18
+ import { useTranslation } from 'react-i18next';
18
19
  import { useContext } from 'react';
19
20
  import ChatContext from "../components/templates/chatContext";
20
21
  import { useAppDispatch } from "../store/hooks";
@@ -23,6 +24,8 @@ import { setMessageList } from "../store/slices/gimiMenuSlice";
23
24
  * 管理推荐列表相关逻辑
24
25
  */
25
26
  export var useChatRecommend = function useChatRecommend() {
27
+ var _useTranslation = useTranslation(),
28
+ t = _useTranslation.t;
26
29
  var _useContext = useContext(ChatContext),
27
30
  apiService = _useContext.apiService;
28
31
  var _ref = apiService,
@@ -63,7 +66,7 @@ export var useChatRecommend = function useChatRecommend() {
63
66
  case 11:
64
67
  _context.prev = 11;
65
68
  _context.t0 = _context["catch"](1);
66
- Toast.error('服务异常');
69
+ Toast.error(t('common.serviceError'));
67
70
  return _context.abrupt("return", []);
68
71
  case 15:
69
72
  case "end":
@@ -74,7 +77,7 @@ export var useChatRecommend = function useChatRecommend() {
74
77
  return function (_x, _x2, _x3) {
75
78
  return _ref2.apply(this, arguments);
76
79
  };
77
- }(), [dispatch]);
80
+ }(), [dispatch, t]);
78
81
 
79
82
  /**
80
83
  * 重写历史记录中的推荐列表
@@ -111,7 +114,7 @@ export var useChatRecommend = function useChatRecommend() {
111
114
  case 11:
112
115
  _context2.prev = 11;
113
116
  _context2.t0 = _context2["catch"](0);
114
- Toast.error('服务异常');
117
+ Toast.error(t('common.serviceError'));
115
118
  case 14:
116
119
  case "end":
117
120
  return _context2.stop();
@@ -121,7 +124,7 @@ export var useChatRecommend = function useChatRecommend() {
121
124
  return function (_x4, _x5) {
122
125
  return _ref3.apply(this, arguments);
123
126
  };
124
- }(), []);
127
+ }(), [dispatch, t]);
125
128
  return {
126
129
  getRecommendList: getRecommendList,
127
130
  rewriteRecommendListFormHistory: rewriteRecommendListFormHistory
@@ -10,6 +10,7 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
10
10
  import { useRef, useCallback } from 'react';
11
11
  import { fetchEventSource } from '@microsoft/fetch-event-source';
12
12
  import { Toast } from '@douyinfe/semi-ui';
13
+ import { useTranslation } from 'react-i18next';
13
14
  import { useLastEventId } from "./useLastEventId";
14
15
  import { useAppSelector, useAppDispatch } from "../store/hooks";
15
16
  import { setIsMsgRecieving } from "../store/slices/gimiMenuSlice";
@@ -17,6 +18,8 @@ import { setIsMsgRecieving } from "../store/slices/gimiMenuSlice";
17
18
  * 处理流式聊天逻辑
18
19
  */
19
20
  export var useChatStream = function useChatStream(platform) {
21
+ var _useTranslation = useTranslation(),
22
+ t = _useTranslation.t;
20
23
  var esAbortRef = useRef(null);
21
24
  var esRef = useRef(null);
22
25
  var ignoreOnMessageRef = useRef(true);
@@ -160,20 +163,27 @@ export var useChatStream = function useChatStream(platform) {
160
163
  } else if (_dataObj.ERROR || _dataObj.moduleType === 'FAILED') {
161
164
  var isRefresh = parseInt(_dataObj.status, 10) === 10002026;
162
165
  if (isRefresh) {
163
- Toast.error(_dataObj.message || '当前工作流正在其它设备运行中,请稍作等待后刷新页面重试');
166
+ Toast.error(_dataObj.message || t('common.workflowRunningOnOtherDevice'));
164
167
  setTimeout(function () {
165
168
  window.location.reload();
166
169
  }, 2000);
167
170
  onErrorComplete === null || onErrorComplete === void 0 || onErrorComplete();
168
171
  return;
169
172
  }
173
+ // TODO 国际化问题
170
174
  var errorMessage = '内容过大,请精简后开启新对话';
171
- Toast.error(_dataObj.ERROR === errorMessage ? errorMessage : '服务异常');
175
+ Toast.error(_dataObj.ERROR === errorMessage ? t('common.contentTooLarge') : t('common.serviceError'));
172
176
  onErrorComplete === null || onErrorComplete === void 0 || onErrorComplete();
177
+ dispatch(setIsMsgRecieving({
178
+ isMsgRecieving: false
179
+ }));
173
180
  return;
174
181
  } else if (data.status && data.status !== 0 && !_dataObj.ERROR) {
175
182
  Toast.error(data.message);
176
183
  onErrorComplete === null || onErrorComplete === void 0 || onErrorComplete();
184
+ dispatch(setIsMsgRecieving({
185
+ isMsgRecieving: false
186
+ }));
177
187
  return;
178
188
  }
179
189
  } catch (parseErr) {
@@ -10,16 +10,22 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
10
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
11
  import { VoiceRecorder } from "../utils/voice-stream";
12
12
  import { useCallback, useState, useEffect, useRef, useMemo } from 'react';
13
+ import { useTranslation } from 'react-i18next';
13
14
  import { Toast } from '@douyinfe/semi-ui';
14
15
  import { useAppDispatch, useAppSelector } from "../store/hooks";
15
16
  import { setShowMicWarning } from "../store/slices/gimiMenuSlice";
16
17
  var useChatVoice = function useChatVoice(baseUrl, token) {
18
+ var _useTranslation = useTranslation(),
19
+ t = _useTranslation.t;
17
20
  var _useState = useState(false),
18
21
  _useState2 = _slicedToArray(_useState, 2),
19
22
  isPlaying = _useState2[0],
20
23
  setIsPlaying = _useState2[1];
21
24
  var isPlayingRef = useRef(false);
22
25
  var isRecordingRef = useRef(false);
26
+ useEffect(function () {
27
+ VoiceRecorderEvent.setTranslation(t);
28
+ }, [t]);
23
29
  var _useState3 = useState(false),
24
30
  _useState4 = _slicedToArray(_useState3, 2),
25
31
  isRecording = _useState4[0],
@@ -79,7 +85,7 @@ var useChatVoice = function useChatVoice(baseUrl, token) {
79
85
  _context.next = 3;
80
86
  break;
81
87
  }
82
- Toast.error('无法连接到网络');
88
+ Toast.error(t('common.networkUnavailable'));
83
89
  return _context.abrupt("return");
84
90
  case 3:
85
91
  _context.prev = 3;
@@ -165,14 +171,14 @@ var useChatVoice = function useChatVoice(baseUrl, token) {
165
171
  }
166
172
  if (res !== null && res !== void 0 && res.success) {
167
173
  if (!res.result) {
168
- Toast.info('未识别到语音内容');
174
+ Toast.info(t('voice.noRecognizedContent'));
169
175
  }
170
176
  setAsrText(function (pre) {
171
177
  return pre + res.result;
172
178
  });
173
179
  }
174
180
  }, token, baseUrl).catch(function (err) {
175
- Toast.error('转写失败,请重试');
181
+ Toast.error(t('voice.transcribeFailed'));
176
182
  console.error("\u4E00\u53E5\u8BDD\u5F55\u97F3\u8F6C\u5199\u5931\u8D25: ".concat(err.message));
177
183
  }).finally(function () {
178
184
  setIsExecuting(false);
@@ -320,14 +326,14 @@ var useChatVoice = function useChatVoice(baseUrl, token) {
320
326
  _context4.next = 4;
321
327
  break;
322
328
  }
323
- Toast.error('无法连接到网络');
329
+ Toast.error(t('common.networkUnavailable'));
324
330
  return _context4.abrupt("return");
325
331
  case 4:
326
332
  if (!currentIsRecording) {
327
333
  _context4.next = 7;
328
334
  break;
329
335
  }
330
- Toast.info('请先停止录音');
336
+ Toast.info(t('voice.stopRecordingFirst'));
331
337
  return _context4.abrupt("return");
332
338
  case 7:
333
339
  _context4.prev = 7;
@@ -358,7 +364,7 @@ var useChatVoice = function useChatVoice(baseUrl, token) {
358
364
  _context4.prev = 19;
359
365
  _context4.t0 = _context4["catch"](7);
360
366
  setIsPlaying(false);
361
- Toast.error('语音播放失败');
367
+ Toast.error(t('voice.playFailed'));
362
368
  console.error("TTS \u64AD\u653E\u5931\u8D25: ".concat(_context4.t0.message || _context4.t0), 'error');
363
369
  case 24:
364
370
  case "end":
@@ -20,6 +20,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
20
20
  import { useContext } from 'react';
21
21
  import ChatContext from "../components/templates/chatContext";
22
22
  import React, { useRef } from 'react';
23
+ import { useTranslation } from 'react-i18next';
23
24
  import { Toast } from "@douyinfe/semi-ui";
24
25
  import { useAppDispatch, useAppSelector } from "../store/hooks";
25
26
  import { setMessageList, setFileList, setConversationId, setAgentDetail, setAutoLoadConversation, updateState, closeSidebar } from "../store/slices/gimiMenuSlice";
@@ -34,6 +35,8 @@ import { set, cloneDeep } from 'lodash';
34
35
  import { FileStatus } from "../interfaces/fileInterface";
35
36
  import useChatHistory from "./useChatHistory";
36
37
  var useCommonChatAPI = function useCommonChatAPI(props) {
38
+ var _useTranslation = useTranslation(),
39
+ t = _useTranslation.t;
37
40
  var containerRef = props.containerRef,
38
41
  platform = props.platform,
39
42
  stopTTSByText = props.stopTTSByText,
@@ -214,7 +217,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
214
217
  _context.next = 3;
215
218
  break;
216
219
  }
217
- Toast.error('会话ID不存在');
220
+ Toast.error(t('chatApi.conversationIdMissing'));
218
221
  return _context.abrupt("return");
219
222
  case 3:
220
223
  _context.next = 5;
@@ -222,21 +225,21 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
222
225
  case 5:
223
226
  res = _context.sent;
224
227
  if (res.status === 0) {
225
- Toast.success('删除会话成功');
228
+ Toast.success(t('chatApi.deleteSuccess'));
226
229
  // 清空Redux状态
227
230
  dispatch(setMessageList({
228
231
  messageList: []
229
232
  }));
230
233
  setHeaderValue('');
231
234
  } else {
232
- Toast.error(res.message || '删除会话失败');
235
+ Toast.error(res.message || t('chatApi.deleteFailed'));
233
236
  }
234
237
  case 7:
235
238
  case "end":
236
239
  return _context.stop();
237
240
  }
238
241
  }, _callee);
239
- })), [dispatch]);
242
+ })), [dispatch, t]);
240
243
 
241
244
  // 打断ai输出
242
245
  var handleInterrupt = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
@@ -249,14 +252,14 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
249
252
  _context2.next = 4;
250
253
  break;
251
254
  }
252
- Toast.error('无法连接到网络');
255
+ Toast.error(t('common.networkUnavailable'));
253
256
  return _context2.abrupt("return");
254
257
  case 4:
255
258
  if (streamEsAbortRef.current) {
256
259
  _context2.next = 7;
257
260
  break;
258
261
  }
259
- Toast.error('没有可取消的请求');
262
+ Toast.error(t('chatApi.noRequestToCancel'));
260
263
  return _context2.abrupt("return");
261
264
  case 7:
262
265
  streamEsAbortRef.current.abort();
@@ -571,20 +574,20 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
571
574
  // 继续流式处理聊天
572
575
  streamChat(retryId, false);
573
576
  } else {
574
- Toast.error(res.message || '当前消息不可进行重试');
577
+ Toast.error(res.message || t('chatApi.retryUnavailable'));
575
578
  }
576
579
  _context7.next = 10;
577
580
  break;
578
581
  case 7:
579
582
  _context7.prev = 7;
580
583
  _context7.t0 = _context7["catch"](0);
581
- Toast.error('重试失败');
584
+ Toast.error(t('chatApi.retryFailed'));
582
585
  case 10:
583
586
  case "end":
584
587
  return _context7.stop();
585
588
  }
586
589
  }, _callee7, null, [[0, 7]]);
587
- })), [streamChat, dispatch]);
590
+ })), [streamChat, dispatch, t]);
588
591
 
589
592
  // 单独的断点续传
590
593
  var checkUnfinishedMessage = React.useCallback( /*#__PURE__*/function () {
@@ -792,7 +795,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
792
795
  setStatus(0);
793
796
  }
794
797
  } else {
795
- Toast.error('网络异常');
798
+ Toast.error(t('common.networkUnavailable'));
796
799
  setMsgLoading(false);
797
800
  if (inputValue) {
798
801
  setStatus(1);
@@ -853,14 +856,14 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
853
856
  _context10.next = 9;
854
857
  break;
855
858
  }
856
- Toast.error('无法连接到网络');
859
+ Toast.error(t('common.networkUnavailable'));
857
860
  return _context10.abrupt("return");
858
861
  case 9:
859
862
  if (!(status === 2 || msgLoading)) {
860
863
  _context10.next = 12;
861
864
  break;
862
865
  }
863
- Toast.error('AI正在输出中,请稍后');
866
+ Toast.error(t('chatApi.aiResponding'));
864
867
  return _context10.abrupt("return");
865
868
  case 12:
866
869
  chatInputConfig === null || chatInputConfig === void 0 || (_chatInputConfig$onBe = chatInputConfig.onBeforeSend) === null || _chatInputConfig$onBe === void 0 || _chatInputConfig$onBe.call(chatInputConfig, value);
@@ -942,7 +945,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
942
945
  case 9:
943
946
  _context11.prev = 9;
944
947
  _context11.t0 = _context11["catch"](2);
945
- Toast.error('网络异常');
948
+ Toast.error(t('common.networkUnavailable'));
946
949
  case 12:
947
950
  case "end":
948
951
  return _context11.stop();
@@ -952,7 +955,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
952
955
  return function (_x16) {
953
956
  return _ref13.apply(this, arguments);
954
957
  };
955
- }(), []);
958
+ }(), [t]);
956
959
  React.useEffect(function () {
957
960
  if (conversationId && conversationIdRef.current !== conversationId) {
958
961
  conversationIdRef.current = conversationId;
@@ -1039,7 +1042,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
1039
1042
  _context13.next = 3;
1040
1043
  break;
1041
1044
  }
1042
- Toast.error('请先关联智能体');
1045
+ Toast.error(t('chatApi.agentMissing'));
1043
1046
  return _context13.abrupt("return");
1044
1047
  case 3:
1045
1048
  currentBusinessParams = _objectSpread({}, businessParamsRef.current || {});
@@ -1079,7 +1082,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
1079
1082
  case 14:
1080
1083
  _context13.prev = 14;
1081
1084
  _context13.t0 = _context13["catch"](6);
1082
- Toast.error('创建会话失败');
1085
+ Toast.error(t('chatApi.createFailed'));
1083
1086
  console.log('error', _context13.t0);
1084
1087
  setMsgLoading(false);
1085
1088
  case 19:
@@ -1091,7 +1094,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
1091
1094
  return function (_x18) {
1092
1095
  return _ref15.apply(this, arguments);
1093
1096
  };
1094
- }(), [handleSend, platform, dispatch, createRoomId, onConversationCreated, getHeaderValue]);
1097
+ }(), [handleSend, platform, dispatch, createRoomId, onConversationCreated, getHeaderValue, t]);
1095
1098
  React.useEffect(function () {
1096
1099
  if (agentId && baseUrl) {
1097
1100
  fetchAgentDetail(agentId);
@@ -1126,11 +1129,11 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
1126
1129
  }, [resetKey, dispatch, streamEsAbortRef]);
1127
1130
  var handleSendFile = React.useCallback(function (messageList) {
1128
1131
  if (!navigator.onLine) {
1129
- Toast.error('无法连接到网络');
1132
+ Toast.error(t('common.networkUnavailable'));
1130
1133
  return;
1131
1134
  }
1132
1135
  if (status === 2) {
1133
- Toast.error('AI正在输出中,请稍后');
1136
+ Toast.error(t('chatApi.aiResponding'));
1134
1137
  return;
1135
1138
  }
1136
1139
  setMsgLoading(true);
@@ -1265,8 +1268,9 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
1265
1268
  isRetry: true
1266
1269
  };
1267
1270
  inputModelRef.current = _inputModel;
1268
- handleSend('重试');
1269
- }, [handleSend, dispatch]);
1271
+ // TODO 国际化问题
1272
+ handleSend(t('chatApi.retryActionText'), agentObjRef.current);
1273
+ }, [handleSend, dispatch, t]);
1270
1274
  React.useEffect(function () {
1271
1275
  if (interruptKey && interruptKey !== interruptKeyRef.current) {
1272
1276
  interruptKeyRef.current = interruptKey || '';
@@ -8,6 +8,7 @@ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyri
8
8
  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); } }
9
9
  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); }); }; }
10
10
  import { useSelector, useDispatch, useStore } from 'react-redux';
11
+ import { useTranslation } from 'react-i18next';
11
12
  import { setFileList } from "../store/slices/gimiMenuSlice";
12
13
  import { useRef } from 'react';
13
14
  import { fetchEventSource } from '@microsoft/fetch-event-source';
@@ -82,6 +83,8 @@ var parseStrToObj = function parseStrToObj(value) {
82
83
  return result;
83
84
  };
84
85
  export var useGimiFileUpload = function useGimiFileUpload(onFileUploaded) {
86
+ var _useTranslation = useTranslation(),
87
+ t = _useTranslation.t;
85
88
  var abortControllerRef = useRef(null);
86
89
  var token = useSelector(function (state) {
87
90
  return state.gimiMenu.token;
@@ -166,10 +169,10 @@ export var useGimiFileUpload = function useGimiFileUpload(onFileUploaded) {
166
169
  resolve();
167
170
  }
168
171
  } else {
169
- reject(new Error(data.message || '文件解析失败'));
172
+ reject(new Error(data.message || t('upload.parseFailed')));
170
173
  }
171
174
  } catch (error) {
172
- reject(new Error('文件解析失败'));
175
+ reject(new Error(t('upload.parseFailed')));
173
176
  }
174
177
  },
175
178
  onclose: function onclose() {
@@ -178,7 +181,7 @@ export var useGimiFileUpload = function useGimiFileUpload(onFileUploaded) {
178
181
  onerror: function onerror(error) {
179
182
  abortController.abort();
180
183
  abortControllerRef.current = null;
181
- reject(new Error('文件解析失败')); // 将错误抛出以触发重试逻辑
184
+ reject(new Error(t('upload.parseFailed'))); // 将错误抛出以触发重试逻辑
182
185
  throw error; // 抛出异常阻止默认的ES重连
183
186
  }
184
187
  });
@@ -196,13 +199,13 @@ export var useGimiFileUpload = function useGimiFileUpload(onFileUploaded) {
196
199
  }).catch(function () {
197
200
  changeFileStatus(FileStatus.ANALYSE_FAILED, file);
198
201
  abortControllerRef.current = null;
199
- Toast.error('文件解析失败,已达到最大重试次数');
202
+ Toast.error(t('upload.parseFailedMaxRetry'));
200
203
  });
201
204
  } else {
202
205
  fetchSSE().catch(function () {
203
206
  changeFileStatus(FileStatus.ANALYSE_FAILED, file);
204
207
  abortControllerRef.current = null;
205
- Toast.error('文件解析失败');
208
+ Toast.error(t('upload.parseFailed'));
206
209
  });
207
210
  }
208
211
  };
@@ -228,7 +231,9 @@ export var useGimiFileUpload = function useGimiFileUpload(onFileUploaded) {
228
231
  var data = response[0];
229
232
  var result = data === null || data === void 0 ? void 0 : data.result;
230
233
  if ((data === null || data === void 0 ? void 0 : data.status) === 0 && result !== null && result !== void 0 && result.fileToken) {
231
- Toast.success("".concat(file.name, " \u4E0A\u4F20\u6210\u529F"));
234
+ Toast.success(t('upload.successWithName', {
235
+ name: file.name
236
+ }));
232
237
  var responseObj = {
233
238
  fileUrl: result.fileAddr,
234
239
  fileName: result.fileName,
@@ -252,10 +257,10 @@ export var useGimiFileUpload = function useGimiFileUpload(onFileUploaded) {
252
257
  });
253
258
  handleSSEFileAnalyize(_objectSpread(_objectSpread({}, pendingFile), responseObj), true);
254
259
  } else {
255
- throw new Error('文件上传失败');
260
+ throw new Error(t('upload.failed'));
256
261
  }
257
262
  }).catch(function () {
258
- throw new Error('文件上传失败');
263
+ throw new Error(t('upload.failed'));
259
264
  }));
260
265
  case 4:
261
266
  case "end":
@@ -278,7 +283,7 @@ export var useGimiFileUpload = function useGimiFileUpload(onFileUploaded) {
278
283
  }
279
284
  }).catch(function () {
280
285
  changeFileStatus(FileStatus.UPLOAD_FAILED, file);
281
- Toast.error('文件上传失败,已达到最大重试次数');
286
+ Toast.error(t('upload.failedMaxRetry'));
282
287
  });
283
288
  } else {
284
289
  upload().catch(function (error) {
@@ -12,7 +12,10 @@ import React from 'react';
12
12
  import ChatContext from "../components/templates/chatContext";
13
13
  import { useContext } from 'react';
14
14
  import { Toast } from '@douyinfe/semi-ui';
15
+ import { useTranslation } from 'react-i18next';
15
16
  export var useExcelExcuteLongPoll = function useExcelExcuteLongPoll(requestStatus, maxPolltime, requestId) {
17
+ var _useTranslation = useTranslation(),
18
+ t = _useTranslation.t;
16
19
  var _useContext = useContext(ChatContext),
17
20
  apiService = _useContext.apiService;
18
21
  var _ref = apiService,
@@ -67,7 +70,7 @@ export var useExcelExcuteLongPoll = function useExcelExcuteLongPoll(requestStatu
67
70
  _context2.next = 5;
68
71
  break;
69
72
  }
70
- Toast.warning('轮询已超过最大时长,自动终止');
73
+ Toast.warning(t('polling.timeoutStopped'));
71
74
  clearInterval(intervalRef.current);
72
75
  return _context2.abrupt("return");
73
76
  case 5:
@@ -107,7 +110,7 @@ export var useExcelExcuteLongPoll = function useExcelExcuteLongPoll(requestStatu
107
110
  clearInterval(intervalRef.current);
108
111
  }
109
112
  };
110
- }, [maxPolltime, requestId, requestStatus, onPoll]);
113
+ }, [maxPolltime, requestId, requestStatus, onPoll, t]);
111
114
  return {
112
115
  pollResult: pollResult
113
116
  };
@@ -7,8 +7,11 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
7
  import { useState } from "react";
8
8
  import { useContext } from "react";
9
9
  import ChatContext from "../components/templates/chatContext";
10
+ import { useTranslation } from "react-i18next";
10
11
  import { Toast } from "@douyinfe/semi-ui";
11
12
  var useSearchCourse = function useSearchCourse(enableSearchCourse) {
13
+ var _useTranslation = useTranslation(),
14
+ t = _useTranslation.t;
12
15
  var _useContext = useContext(ChatContext),
13
16
  apiService = _useContext.apiService;
14
17
  var _ref = apiService,
@@ -33,11 +36,11 @@ var useSearchCourse = function useSearchCourse(enableSearchCourse) {
33
36
  callback === null || callback === void 0 || callback();
34
37
  } else {
35
38
  setSearchedCourseList([]);
36
- Toast.error(res.message || '搜索相关课程失败');
39
+ Toast.error(res.message || t('common.searchCourseFailed'));
37
40
  }
38
41
  }).catch(function () {
39
42
  setSearchedCourseList([]);
40
- Toast.error('搜索相关课程失败');
43
+ Toast.error(t('common.searchCourseFailed'));
41
44
  }).finally(function () {
42
45
  setSearching(false);
43
46
  });
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ import { GimiChatMessages } from './core';
3
+ interface GimiChatI18nProviderProps {
4
+ locale?: string;
5
+ messages?: GimiChatMessages;
6
+ children: React.ReactNode;
7
+ }
8
+ declare const GimiChatI18nProvider: React.FC<GimiChatI18nProviderProps>;
9
+ export default GimiChatI18nProvider;
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { I18nextProvider } from 'react-i18next';
3
+ import { createGimiChatI18n, createGimiChatResources, resolveGimiChatLocale } from "./core";
4
+ var GimiChatI18nProvider = function GimiChatI18nProvider(_ref) {
5
+ var locale = _ref.locale,
6
+ messages = _ref.messages,
7
+ children = _ref.children;
8
+ var i18nInstance = React.useMemo(function () {
9
+ return createGimiChatI18n({
10
+ locale: locale,
11
+ messages: messages
12
+ });
13
+ }, [messages]);
14
+ React.useEffect(function () {
15
+ var resources = createGimiChatResources(messages);
16
+ var nextLocale = resolveGimiChatLocale(locale, resources);
17
+ if (i18nInstance.language !== nextLocale) {
18
+ void i18nInstance.changeLanguage(nextLocale);
19
+ }
20
+ }, [i18nInstance, locale, messages]);
21
+ return /*#__PURE__*/React.createElement(I18nextProvider, {
22
+ i18n: i18nInstance
23
+ }, children);
24
+ };
25
+ export default GimiChatI18nProvider;
@@ -0,0 +1,12 @@
1
+ import { i18n, Resource } from 'i18next';
2
+ export declare type GimiChatTranslation = Record<string, string>;
3
+ export declare type GimiChatMessages = Record<string, GimiChatTranslation>;
4
+ export declare const GIMI_CHAT_DEFAULT_LOCALE = "zh-CN";
5
+ export declare const GIMI_CHAT_FALLBACK_LOCALE = "zh-CN";
6
+ export declare const createGimiChatResources: (messages?: GimiChatMessages) => Resource;
7
+ export declare const resolveGimiChatLocale: (locale: string | undefined, resources: Resource) => string;
8
+ export interface CreateGimiChatI18nOptions {
9
+ locale?: string;
10
+ messages?: GimiChatMessages;
11
+ }
12
+ export declare const createGimiChatI18n: (options?: CreateGimiChatI18nOptions) => i18n;
@@ -0,0 +1,71 @@
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 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; }
3
+ 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; }
4
+ 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; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ 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); }
7
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
8
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ 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); }
10
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
11
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
12
+ 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; }
13
+ import { createInstance } from 'i18next';
14
+ import { initReactI18next } from 'react-i18next';
15
+ import zhCN from "./locales/zh-CN";
16
+ import enUS from "./locales/en-US";
17
+ export var GIMI_CHAT_DEFAULT_LOCALE = 'zh-CN';
18
+ export var GIMI_CHAT_FALLBACK_LOCALE = 'zh-CN';
19
+ var normalizeLocale = function normalizeLocale(locale) {
20
+ return locale.trim().replace('_', '-').toLowerCase();
21
+ };
22
+ var normalizeMessages = function normalizeMessages(messages) {
23
+ if (!messages) return {};
24
+ return Object.keys(messages).reduce(function (acc, locale) {
25
+ var normalizedLocale = normalizeLocale(locale);
26
+ acc[normalizedLocale] = messages[locale];
27
+ return acc;
28
+ }, {});
29
+ };
30
+ export var createGimiChatResources = function createGimiChatResources(messages) {
31
+ var normalizedMessages = normalizeMessages(messages);
32
+ var builtInResources = {
33
+ 'zh-cn': zhCN,
34
+ 'en-us': enUS
35
+ };
36
+ var locales = new Set([].concat(_toConsumableArray(Object.keys(builtInResources)), _toConsumableArray(Object.keys(normalizedMessages))));
37
+ return Array.from(locales).reduce(function (acc, locale) {
38
+ acc[locale] = {
39
+ translation: _objectSpread(_objectSpread({}, builtInResources[locale] || {}), normalizedMessages[locale] || {})
40
+ };
41
+ return acc;
42
+ }, {});
43
+ };
44
+ export var resolveGimiChatLocale = function resolveGimiChatLocale(locale, resources) {
45
+ if (!locale) return normalizeLocale(GIMI_CHAT_DEFAULT_LOCALE);
46
+ var normalizedLocale = normalizeLocale(locale);
47
+ if (resources[normalizedLocale]) return normalizedLocale;
48
+ var languageCode = normalizedLocale.split('-')[0];
49
+ var candidate = Object.keys(resources).find(function (item) {
50
+ return item.split('-')[0] === languageCode;
51
+ });
52
+ if (candidate) return candidate;
53
+ return normalizeLocale(GIMI_CHAT_DEFAULT_LOCALE);
54
+ };
55
+ export var createGimiChatI18n = function createGimiChatI18n() {
56
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
57
+ var resources = createGimiChatResources(options.messages);
58
+ var instance = createInstance();
59
+ instance.use(initReactI18next);
60
+ void instance.init({
61
+ resources: resources,
62
+ lng: resolveGimiChatLocale(options.locale, resources),
63
+ fallbackLng: normalizeLocale(GIMI_CHAT_FALLBACK_LOCALE),
64
+ lowerCaseLng: true,
65
+ initImmediate: false,
66
+ interpolation: {
67
+ escapeValue: false
68
+ }
69
+ });
70
+ return instance;
71
+ };
@@ -0,0 +1,4 @@
1
+ export { default as GimiChatI18nProvider } from './GimiChatI18nProvider';
2
+ export { default as useGimiChatTranslation } from './useGimiChatTranslation';
3
+ export { createGimiChatI18n, createGimiChatResources, resolveGimiChatLocale, GIMI_CHAT_DEFAULT_LOCALE, GIMI_CHAT_FALLBACK_LOCALE, } from './core';
4
+ export type { GimiChatMessages, GimiChatTranslation, CreateGimiChatI18nOptions } from './core';
@@ -0,0 +1,3 @@
1
+ export { default as GimiChatI18nProvider } from "./GimiChatI18nProvider";
2
+ export { default as useGimiChatTranslation } from "./useGimiChatTranslation";
3
+ export { createGimiChatI18n, createGimiChatResources, resolveGimiChatLocale, GIMI_CHAT_DEFAULT_LOCALE, GIMI_CHAT_FALLBACK_LOCALE } from "./core";