@myun/gimi-chat 0.9.9 → 0.9.11
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/apis/useApi.d.ts
CHANGED
|
@@ -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;
|
package/dist/apis/useApi.js
CHANGED
|
@@ -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 () {
|
|
@@ -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
|
* 中止流式请求
|
|
@@ -23,7 +23,7 @@ import React, { useRef } from 'react';
|
|
|
23
23
|
import { useTranslation } from 'react-i18next';
|
|
24
24
|
import { Toast } from "@douyinfe/semi-ui";
|
|
25
25
|
import { useAppDispatch, useAppSelector } from "../store/hooks";
|
|
26
|
-
import { setMessageList, setFileList, setConversationId, setAgentDetail, setAutoLoadConversation, updateState, closeSidebar } from "../store/slices/gimiMenuSlice";
|
|
26
|
+
import { setMessageList, setFileList, setConversationId, setAgentDetail, setBusinessParams, setAutoLoadConversation, updateState, closeSidebar } from "../store/slices/gimiMenuSlice";
|
|
27
27
|
import { fileValidation, parseMessageContent, processString } from "../utils/tools";
|
|
28
28
|
import { filterPropmptFromUserInput } from "../utils/tools";
|
|
29
29
|
import { useChatMessage } from "./useChatMessage";
|
|
@@ -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)
|
|
@@ -993,7 +995,7 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
993
995
|
}, [conversationId, dispatch, clearQuotesFromRedux, streamEsAbortRef]);
|
|
994
996
|
var fetchAgentDetail = React.useCallback( /*#__PURE__*/function () {
|
|
995
997
|
var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(agentId) {
|
|
996
|
-
var res;
|
|
998
|
+
var res, _res$result2, _businessParamsRef$cu;
|
|
997
999
|
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
998
1000
|
while (1) switch (_context12.prev = _context12.next) {
|
|
999
1001
|
case 0:
|
|
@@ -1003,29 +1005,37 @@ var useCommonChatAPI = function useCommonChatAPI(props) {
|
|
|
1003
1005
|
case 3:
|
|
1004
1006
|
res = _context12.sent;
|
|
1005
1007
|
if (!(res.status === 0)) {
|
|
1006
|
-
_context12.next =
|
|
1008
|
+
_context12.next = 10;
|
|
1007
1009
|
break;
|
|
1008
1010
|
}
|
|
1009
1011
|
dispatch(setAgentDetail({
|
|
1010
1012
|
agentDetail: res.result
|
|
1011
1013
|
}));
|
|
1014
|
+
if (((_res$result2 = res.result) === null || _res$result2 === void 0 ? void 0 : _res$result2.businessType) === 7) {
|
|
1015
|
+
dispatch(setBusinessParams(_objectSpread(_objectSpread({}, businessParamsRef.current), {}, {
|
|
1016
|
+
sysInfo: {
|
|
1017
|
+
platform: businessParamsRef.current.platform,
|
|
1018
|
+
agencyId: (_businessParamsRef$cu = businessParamsRef.current) === null || _businessParamsRef$cu === void 0 ? void 0 : _businessParamsRef$cu.agencyId
|
|
1019
|
+
}
|
|
1020
|
+
})));
|
|
1021
|
+
}
|
|
1012
1022
|
return _context12.abrupt("return", res.result);
|
|
1013
|
-
case
|
|
1023
|
+
case 10:
|
|
1014
1024
|
Toast.error(res.message);
|
|
1015
1025
|
return _context12.abrupt("return", null);
|
|
1016
|
-
case
|
|
1017
|
-
_context12.next =
|
|
1026
|
+
case 12:
|
|
1027
|
+
_context12.next = 18;
|
|
1018
1028
|
break;
|
|
1019
|
-
case
|
|
1020
|
-
_context12.prev =
|
|
1029
|
+
case 14:
|
|
1030
|
+
_context12.prev = 14;
|
|
1021
1031
|
_context12.t0 = _context12["catch"](0);
|
|
1022
1032
|
console.log('error', _context12.t0);
|
|
1023
1033
|
return _context12.abrupt("return", null);
|
|
1024
|
-
case
|
|
1034
|
+
case 18:
|
|
1025
1035
|
case "end":
|
|
1026
1036
|
return _context12.stop();
|
|
1027
1037
|
}
|
|
1028
|
-
}, _callee12, null, [[0,
|
|
1038
|
+
}, _callee12, null, [[0, 14]]);
|
|
1029
1039
|
}));
|
|
1030
1040
|
return function (_x17) {
|
|
1031
1041
|
return _ref14.apply(this, arguments);
|