@myun/gimi-chat 0.0.2 → 0.0.4
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/fetch.d.ts +64 -0
- package/dist/apis/fetch.js +512 -0
- package/dist/apis/useApi.d.ts +57 -0
- package/dist/apis/useApi.js +378 -0
- package/dist/assets/image/Subtract.png +0 -0
- package/dist/assets/image/ai-logo.png +0 -0
- package/dist/assets/image/copyIcon.png +0 -0
- package/dist/assets/image/deepthinkActive.png +0 -0
- package/dist/assets/image/empty-img-dark.png +0 -0
- package/dist/assets/image/empty-img.png +0 -0
- package/dist/assets/image/like_active.png +0 -0
- package/dist/assets/image/love.png +0 -0
- package/dist/assets/image/retry.png +0 -0
- package/dist/assets/image/soundOut.png +0 -0
- package/dist/assets/image/unlike_active.png +0 -0
- package/dist/assets/image/unlove.png +0 -0
- package/dist/assets/lottie/ai-bg.json +1704 -0
- package/dist/assets/lottie/ai-loading.json +192 -0
- package/dist/assets/lottie/ai-output-loading.json +272 -0
- package/dist/assets/lottie/ai-output-normal.json +17694 -0
- package/dist/assets/lottie/ai-output-strengthen.json +17321 -0
- package/dist/assets/lottie/ai-voice-play.json +1 -0
- package/dist/assets/lottie/living.json +705 -0
- package/dist/assets/lottie/myun-living.json +726 -0
- package/dist/assets/lottie/myun-loading.json +530 -0
- package/dist/components/ai-chat-dialogue/index.d.ts +16 -0
- package/dist/components/ai-chat-dialogue/index.js +1056 -0
- package/dist/components/ai-chat-dialogue/index.module.scss +272 -0
- package/dist/components/ai-chat-dialogue/message-parser.d.ts +36 -0
- package/dist/components/ai-chat-dialogue/message-parser.js +52 -0
- package/dist/components/ai-chat-dialogue/tlv.d.ts +7 -0
- package/dist/components/ai-chat-dialogue/tlv.js +32 -0
- package/dist/components/ai-chat-dialogue/volc-voice-call-client.d.ts +47 -0
- package/dist/components/ai-chat-dialogue/volc-voice-call-client.js +246 -0
- package/dist/components/ai-correction/index.d.ts +5 -0
- package/dist/components/ai-correction/index.js +45 -0
- package/dist/components/ai-loading/index.d.ts +3 -0
- package/dist/components/ai-loading/index.js +14 -0
- package/dist/components/ai-loading/index.module.scss +11 -0
- package/dist/components/answer-item/index.d.ts +27 -0
- package/dist/components/answer-item/index.js +194 -0
- package/dist/components/answer-item/index.module.scss +295 -0
- package/dist/components/ask-card/index.d.ts +10 -0
- package/dist/components/ask-card/index.js +76 -0
- package/dist/components/ask-card/index.module.scss +125 -0
- package/dist/components/chat-input/index.d.ts +31 -0
- package/dist/components/chat-input/index.js +433 -0
- package/dist/components/chat-input/index.module.scss +44 -0
- package/dist/components/chat-voice/VoiceCommunication.d.ts +7 -0
- package/dist/components/chat-voice/VoiceCommunication.js +69 -0
- package/dist/components/chat-voice/VoiceRecord.d.ts +7 -0
- package/dist/components/chat-voice/VoiceRecord.js +34 -0
- package/dist/components/conversation-delete/index.d.ts +5 -0
- package/dist/components/conversation-delete/index.js +24 -0
- package/dist/components/dots-loading/index.d.ts +2 -0
- package/dist/components/dots-loading/index.js +11 -0
- package/dist/components/dots-loading/index.module.scss +45 -0
- package/dist/components/empty/index.d.ts +9 -0
- package/dist/components/empty/index.js +32 -0
- package/dist/components/empty/index.module.scss +27 -0
- package/dist/components/excel-components/ExcelCard.d.ts +11 -0
- package/dist/components/excel-components/ExcelCard.js +35 -0
- package/dist/components/excel-components/ExcelExcuting.d.ts +10 -0
- package/dist/components/excel-components/ExcelExcuting.js +263 -0
- package/dist/components/excel-components/ExcelFailCard.d.ts +9 -0
- package/dist/components/excel-components/ExcelFailCard.js +20 -0
- package/dist/components/excel-components/ExcelSuccessCard.d.ts +5 -0
- package/dist/components/excel-components/ExcelSuccessCard.js +50 -0
- package/dist/components/excel-components/index.module.scss +210 -0
- package/dist/components/excel-components/styles.module.scss +186 -0
- package/dist/components/file-card/fileCardSidebar.d.ts +8 -0
- package/dist/components/file-card/fileCardSidebar.js +56 -0
- package/dist/components/file-card/index.d.ts +15 -0
- package/dist/components/file-card/index.js +97 -0
- package/dist/components/file-card/index.module.scss +139 -0
- package/dist/components/file-preview/index.d.ts +3 -0
- package/dist/components/file-preview/index.js +229 -0
- package/dist/components/file-preview/index.module.scss +120 -0
- package/dist/components/file-upload/index.d.ts +16 -0
- package/dist/components/file-upload/index.js +238 -0
- package/dist/components/file-upload/uploadV1.d.ts +16 -0
- package/dist/components/file-upload/uploadV1.js +267 -0
- package/dist/components/gimi-sidebar/index.d.ts +17 -0
- package/dist/components/gimi-sidebar/index.js +41 -0
- package/dist/components/gimi-sidebar/index.module.scss +136 -0
- package/dist/components/header/index.d.ts +5 -0
- package/dist/components/header/index.js +20 -0
- package/dist/components/header/index.module.scss +26 -0
- package/dist/components/iconfont-com/index.d.ts +11 -0
- package/dist/components/iconfont-com/index.js +29 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/knowledge-trace/KnowledgeIconComponent.d.ts +7 -0
- package/dist/components/knowledge-trace/KnowledgeIconComponent.js +101 -0
- package/dist/components/knowledge-trace/classList.d.ts +6 -0
- package/dist/components/knowledge-trace/classList.js +72 -0
- package/dist/components/knowledge-trace/documentList.d.ts +6 -0
- package/dist/components/knowledge-trace/documentList.js +75 -0
- package/dist/components/knowledge-trace/index.d.ts +18 -0
- package/dist/components/knowledge-trace/index.js +155 -0
- package/dist/components/knowledge-trace/index.module.scss +262 -0
- package/dist/components/knowledge-trace/interfaces.d.ts +166 -0
- package/dist/components/knowledge-trace/interfaces.js +1 -0
- package/dist/components/knowledge-trace/videoList.d.ts +6 -0
- package/dist/components/knowledge-trace/videoList.js +91 -0
- package/dist/components/lottie-img/index.d.ts +8 -0
- package/dist/components/lottie-img/index.js +99 -0
- package/dist/components/message-actions/CopyButton.d.ts +7 -0
- package/dist/components/message-actions/CopyButton.js +33 -0
- package/dist/components/message-actions/LikeButton.d.ts +7 -0
- package/dist/components/message-actions/LikeButton.js +34 -0
- package/dist/components/message-actions/RegenerateButton.d.ts +5 -0
- package/dist/components/message-actions/RegenerateButton.js +27 -0
- package/dist/components/message-actions/UnLikeButton.d.ts +7 -0
- package/dist/components/message-actions/UnLikeButton.js +34 -0
- package/dist/components/message-actions/VoicePlay.d.ts +10 -0
- package/dist/components/message-actions/VoicePlay.js +74 -0
- package/dist/components/message-list/index.d.ts +19 -0
- package/dist/components/message-list/index.js +167 -0
- package/dist/components/message-list/index.module.scss +304 -0
- package/dist/components/no-microphone-root/index.d.ts +6 -0
- package/dist/components/no-microphone-root/index.js +36 -0
- package/dist/components/no-microphone-root/index.module.scss +42 -0
- package/dist/components/preset-agent-content/index.d.ts +8 -0
- package/dist/components/preset-agent-content/index.js +24 -0
- package/dist/components/preset-agent-content/index.module.scss +48 -0
- package/dist/components/quoted-content/index.d.ts +0 -0
- package/dist/components/quoted-content/index.js +171 -0
- package/dist/components/quoted-content/index.module.scss +76 -0
- package/dist/components/reasoning-content/index.d.ts +6 -0
- package/dist/components/reasoning-content/index.js +116 -0
- package/dist/components/reasoning-content/index.module.scss +164 -0
- package/dist/components/reference-content/index.d.ts +28 -0
- package/dist/components/reference-content/index.js +125 -0
- package/dist/components/reference-content/index.module.scss +73 -0
- package/dist/components/templates/CommonChat.d.ts +5 -0
- package/dist/components/templates/CommonChat.js +218 -0
- package/dist/components/templates/GimiChatComponent.d.ts +4 -0
- package/dist/components/templates/GimiChatComponent.js +23 -0
- package/dist/components/templates/demo/demo.d.ts +2 -0
- package/dist/components/templates/demo/demo.js +110 -0
- package/dist/components/templates/index.module.scss +119 -0
- package/dist/components/upload-list/index.d.ts +15 -0
- package/dist/components/upload-list/index.js +90 -0
- package/dist/components/upload-list/index.module.scss +119 -0
- package/dist/components/voice-bars/index.d.ts +4 -0
- package/dist/components/voice-bars/index.js +174 -0
- package/dist/components/voice-check-dialog/index.d.ts +8 -0
- package/dist/components/voice-check-dialog/index.js +163 -0
- package/dist/components/voice-check-dialog/index.module.scss +9 -0
- package/dist/components/voice-recording/index.d.ts +9 -0
- package/dist/components/voice-recording/index.js +54 -0
- package/dist/components/voice-recording/index.module.scss +41 -0
- package/dist/components/work-flow-content/demo.d.ts +3 -0
- package/dist/components/work-flow-content/demo.js +11 -0
- package/dist/components/work-flow-content/index.d.ts +6 -0
- package/dist/components/work-flow-content/index.js +55 -0
- package/dist/components/work-flow-content/index.module.scss +23 -0
- package/dist/constants.d.ts +24 -0
- package/dist/constants.js +24 -0
- package/dist/hooks/useChatActions.d.ts +12 -0
- package/dist/hooks/useChatActions.js +207 -0
- package/dist/hooks/useChatHistory.d.ts +8 -0
- package/dist/hooks/useChatHistory.js +225 -0
- package/dist/hooks/useChatMessage.d.ts +49 -0
- package/dist/hooks/useChatMessage.js +87 -0
- package/dist/hooks/useChatRecommend.d.ts +8 -0
- package/dist/hooks/useChatRecommend.js +126 -0
- package/dist/hooks/useChatStream.d.ts +20 -0
- package/dist/hooks/useChatStream.js +244 -0
- package/dist/hooks/useChatUI.d.ts +32 -0
- package/dist/hooks/useChatUI.js +134 -0
- package/dist/hooks/useChatVoice.d.ts +11 -0
- package/dist/hooks/useChatVoice.js +379 -0
- package/dist/hooks/useCommonChatAPI.d.ts +27 -0
- package/dist/hooks/useCommonChatAPI.js +1276 -0
- package/dist/hooks/useFile.d.ts +13 -0
- package/dist/hooks/useFile.js +288 -0
- package/dist/hooks/useKnowledgeService.d.ts +17 -0
- package/dist/hooks/useKnowledgeService.js +210 -0
- package/dist/hooks/useLastEventId.d.ts +8 -0
- package/dist/hooks/useLastEventId.js +66 -0
- package/dist/hooks/useLongPoll.d.ts +3 -0
- package/dist/hooks/useLongPoll.js +111 -0
- package/dist/hooks/useScroll.d.ts +4 -0
- package/dist/hooks/useScroll.js +172 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interfaces/chatMessage.d.ts +139 -0
- package/dist/interfaces/fileInterface.d.ts +10 -0
- package/dist/interfaces/fileInterface.js +11 -0
- package/dist/interfaces/knowledgeTrace.d.ts +177 -0
- package/dist/store/hooks.d.ts +4 -0
- package/dist/store/hooks.js +3 -0
- package/dist/store/index.d.ts +7 -0
- package/dist/store/index.js +7 -0
- package/dist/store/slices/gimiMenuSlice.d.ts +95 -0
- package/dist/store/slices/gimiMenuSlice.js +251 -0
- package/dist/utils/chatInputUtil.d.ts +19 -0
- package/dist/utils/chatInputUtil.js +45 -0
- package/dist/utils/tools.d.ts +50 -0
- package/dist/utils/tools.js +474 -0
- package/dist/utils/voice-stream.d.ts +119 -0
- package/dist/utils/voice-stream.js +1162 -0
- package/package.json +2 -3
- package/LICENSE +0 -21
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 管理聊天消息的创建和格式化
|
|
3
|
+
*/
|
|
4
|
+
export declare const useChatMessage: () => {
|
|
5
|
+
createUserChat: (val: string, conversationId: string) => {
|
|
6
|
+
quoteProductList?: {
|
|
7
|
+
productId: number;
|
|
8
|
+
productName: string;
|
|
9
|
+
}[] | undefined;
|
|
10
|
+
quoteTeachModelList?: {
|
|
11
|
+
teachModelId: number;
|
|
12
|
+
teachModelName: string;
|
|
13
|
+
type?: string | undefined;
|
|
14
|
+
duration: number;
|
|
15
|
+
}[] | undefined;
|
|
16
|
+
id: number;
|
|
17
|
+
content: string;
|
|
18
|
+
status: number;
|
|
19
|
+
botId: string;
|
|
20
|
+
messageId: string;
|
|
21
|
+
conversationId: string;
|
|
22
|
+
role: number;
|
|
23
|
+
sectionId: string;
|
|
24
|
+
type: number;
|
|
25
|
+
messageFiles: import("../types/file").FileItem | null;
|
|
26
|
+
};
|
|
27
|
+
createAiChat: (result: any) => {
|
|
28
|
+
role: number;
|
|
29
|
+
type: number;
|
|
30
|
+
content: string;
|
|
31
|
+
id: any;
|
|
32
|
+
chatId: any;
|
|
33
|
+
botId: any;
|
|
34
|
+
messageId: string;
|
|
35
|
+
relatedCount: any;
|
|
36
|
+
videoResourceList: any;
|
|
37
|
+
relatedCourseRecommendation: never[];
|
|
38
|
+
loading: boolean;
|
|
39
|
+
expand: boolean;
|
|
40
|
+
stop: number;
|
|
41
|
+
questionId: any;
|
|
42
|
+
vipLevel: number;
|
|
43
|
+
reasoningContent: string;
|
|
44
|
+
reasoningStatus: number;
|
|
45
|
+
query: any;
|
|
46
|
+
needSearch: any;
|
|
47
|
+
relatedResourceList: never[];
|
|
48
|
+
};
|
|
49
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
import React from 'react';
|
|
8
|
+
import { useAppSelector } from "../store/hooks";
|
|
9
|
+
/**
|
|
10
|
+
* 管理聊天消息的创建和格式化
|
|
11
|
+
*/
|
|
12
|
+
export var useChatMessage = function useChatMessage() {
|
|
13
|
+
var fileList = useAppSelector(function (state) {
|
|
14
|
+
return state.gimiMenu.fileList;
|
|
15
|
+
});
|
|
16
|
+
var quoteProductList = useAppSelector(function (state) {
|
|
17
|
+
return state.gimiMenu.quoteProductList;
|
|
18
|
+
});
|
|
19
|
+
var quoteTeachModelList = useAppSelector(function (state) {
|
|
20
|
+
return state.gimiMenu.quoteTeachModelList;
|
|
21
|
+
});
|
|
22
|
+
var fileListRef = React.useRef(fileList);
|
|
23
|
+
fileListRef.current = fileList;
|
|
24
|
+
var quoteProductListRef = React.useRef(quoteProductList);
|
|
25
|
+
quoteProductListRef.current = quoteProductList;
|
|
26
|
+
var quoteTeachModelListRef = React.useRef(quoteTeachModelList);
|
|
27
|
+
quoteTeachModelListRef.current = quoteTeachModelList;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 创建用户消息对象
|
|
31
|
+
*/
|
|
32
|
+
var createUserChat = React.useCallback(function (val, conversationId) {
|
|
33
|
+
var _fileListRef$current, _quoteTeachModelListR, _quoteProductListRef$;
|
|
34
|
+
return _objectSpread(_objectSpread({
|
|
35
|
+
id: +new Date(),
|
|
36
|
+
content: val,
|
|
37
|
+
status: 1,
|
|
38
|
+
// 0 正在发送 1 已发送 2 失败 (重试3次才变成失败)
|
|
39
|
+
botId: 'user',
|
|
40
|
+
messageId: 'msg_' + Date.now(),
|
|
41
|
+
conversationId: conversationId,
|
|
42
|
+
role: 0,
|
|
43
|
+
sectionId: '1',
|
|
44
|
+
type: 0,
|
|
45
|
+
messageFiles: ((_fileListRef$current = fileListRef.current) === null || _fileListRef$current === void 0 ? void 0 : _fileListRef$current.length) > 0 ? fileListRef.current[0] : null
|
|
46
|
+
}, ((_quoteTeachModelListR = quoteTeachModelListRef.current) === null || _quoteTeachModelListR === void 0 ? void 0 : _quoteTeachModelListR.length) > 0 && {
|
|
47
|
+
quoteTeachModelList: quoteTeachModelListRef.current
|
|
48
|
+
}), ((_quoteProductListRef$ = quoteProductListRef.current) === null || _quoteProductListRef$ === void 0 ? void 0 : _quoteProductListRef$.length) > 0 && {
|
|
49
|
+
quoteProductList: quoteProductListRef.current
|
|
50
|
+
});
|
|
51
|
+
}, []);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 创建AI消息对象
|
|
55
|
+
*/
|
|
56
|
+
var createAiChat = React.useCallback(function (result) {
|
|
57
|
+
var uid = 'msg_' + Date.now();
|
|
58
|
+
return {
|
|
59
|
+
role: 1,
|
|
60
|
+
type: 1,
|
|
61
|
+
content: '',
|
|
62
|
+
id: result.id,
|
|
63
|
+
chatId: result.id,
|
|
64
|
+
botId: result.botId,
|
|
65
|
+
messageId: uid,
|
|
66
|
+
relatedCount: result.relatedCount,
|
|
67
|
+
videoResourceList: result.videoResourceList,
|
|
68
|
+
relatedCourseRecommendation: [],
|
|
69
|
+
loading: false,
|
|
70
|
+
expand: true,
|
|
71
|
+
stop: 0,
|
|
72
|
+
questionId: result.id,
|
|
73
|
+
vipLevel: 0,
|
|
74
|
+
reasoningContent: '',
|
|
75
|
+
// 推理内容
|
|
76
|
+
reasoningStatus: 1,
|
|
77
|
+
// 推理状态 1 正在推理 2 推理完成 3 停止
|
|
78
|
+
query: result.query,
|
|
79
|
+
needSearch: result.needSearch || false,
|
|
80
|
+
relatedResourceList: []
|
|
81
|
+
};
|
|
82
|
+
}, []);
|
|
83
|
+
return {
|
|
84
|
+
createUserChat: createUserChat,
|
|
85
|
+
createAiChat: createAiChat
|
|
86
|
+
};
|
|
87
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IChatMessageItem } from '../interfaces/chatMessage';
|
|
2
|
+
/**
|
|
3
|
+
* 管理推荐列表相关逻辑
|
|
4
|
+
*/
|
|
5
|
+
export declare const useChatRecommend: () => {
|
|
6
|
+
getRecommendList: (chatList: IChatMessageItem[], msgId: string | number, chatStatus: number) => Promise<never[] | undefined>;
|
|
7
|
+
rewriteRecommendListFormHistory: (chatList: IChatMessageItem[], msgId: string | number) => Promise<void>;
|
|
8
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function 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; }
|
|
4
|
+
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; }
|
|
5
|
+
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; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
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); }
|
|
8
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
|
+
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."); }
|
|
10
|
+
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); }
|
|
11
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
12
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
13
|
+
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; }
|
|
14
|
+
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); } }
|
|
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
|
+
import React from 'react';
|
|
17
|
+
import { Toast } from '@douyinfe/semi-ui';
|
|
18
|
+
import useApi from "../apis/useApi";
|
|
19
|
+
import { useAppDispatch } from "../store/hooks";
|
|
20
|
+
import { setMessageList } from "../store/slices/gimiMenuSlice";
|
|
21
|
+
/**
|
|
22
|
+
* 管理推荐列表相关逻辑
|
|
23
|
+
*/
|
|
24
|
+
export var useChatRecommend = function useChatRecommend() {
|
|
25
|
+
var _useApi = useApi(),
|
|
26
|
+
getProbeList = _useApi.getProbeList;
|
|
27
|
+
var dispatch = useAppDispatch();
|
|
28
|
+
/**
|
|
29
|
+
* 获取推荐列表
|
|
30
|
+
*/
|
|
31
|
+
var getRecommendList = React.useCallback( /*#__PURE__*/function () {
|
|
32
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(chatList, msgId, chatStatus) {
|
|
33
|
+
var issueRecommendList, _yield$getProbeList, result, status, newMessageList;
|
|
34
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
35
|
+
while (1) switch (_context.prev = _context.next) {
|
|
36
|
+
case 0:
|
|
37
|
+
issueRecommendList = [];
|
|
38
|
+
_context.prev = 1;
|
|
39
|
+
_context.next = 4;
|
|
40
|
+
return getProbeList({
|
|
41
|
+
messageId: msgId
|
|
42
|
+
});
|
|
43
|
+
case 4:
|
|
44
|
+
_yield$getProbeList = _context.sent;
|
|
45
|
+
result = _yield$getProbeList.result;
|
|
46
|
+
status = _yield$getProbeList.status;
|
|
47
|
+
if (status === 0 && result && result !== null && result !== void 0 && result.content) {
|
|
48
|
+
issueRecommendList = JSON.parse(result === null || result === void 0 ? void 0 : result.content) || [];
|
|
49
|
+
}
|
|
50
|
+
if (issueRecommendList.length && chatStatus === 2) {
|
|
51
|
+
newMessageList = [].concat(_toConsumableArray(chatList.slice(0, -1)), [_objectSpread(_objectSpread({}, chatList[chatList.length - 1]), {}, {
|
|
52
|
+
relatedResourceList: issueRecommendList
|
|
53
|
+
})]);
|
|
54
|
+
dispatch(setMessageList({
|
|
55
|
+
messageList: newMessageList
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
_context.next = 15;
|
|
59
|
+
break;
|
|
60
|
+
case 11:
|
|
61
|
+
_context.prev = 11;
|
|
62
|
+
_context.t0 = _context["catch"](1);
|
|
63
|
+
Toast.error('服务异常');
|
|
64
|
+
return _context.abrupt("return", []);
|
|
65
|
+
case 15:
|
|
66
|
+
case "end":
|
|
67
|
+
return _context.stop();
|
|
68
|
+
}
|
|
69
|
+
}, _callee, null, [[1, 11]]);
|
|
70
|
+
}));
|
|
71
|
+
return function (_x, _x2, _x3) {
|
|
72
|
+
return _ref.apply(this, arguments);
|
|
73
|
+
};
|
|
74
|
+
}(), [dispatch]);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 重写历史记录中的推荐列表
|
|
78
|
+
*/
|
|
79
|
+
var rewriteRecommendListFormHistory = React.useCallback( /*#__PURE__*/function () {
|
|
80
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(chatList, msgId) {
|
|
81
|
+
var _yield$getProbeList2, result, status, issueRecommendList, newMessageList;
|
|
82
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
83
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
84
|
+
case 0:
|
|
85
|
+
_context2.prev = 0;
|
|
86
|
+
_context2.next = 3;
|
|
87
|
+
return getProbeList({
|
|
88
|
+
messageId: msgId
|
|
89
|
+
});
|
|
90
|
+
case 3:
|
|
91
|
+
_yield$getProbeList2 = _context2.sent;
|
|
92
|
+
result = _yield$getProbeList2.result;
|
|
93
|
+
status = _yield$getProbeList2.status;
|
|
94
|
+
issueRecommendList = [];
|
|
95
|
+
if (status === 0 && result && result !== null && result !== void 0 && result.content) {
|
|
96
|
+
issueRecommendList = JSON.parse(result === null || result === void 0 ? void 0 : result.content) || [];
|
|
97
|
+
}
|
|
98
|
+
if (issueRecommendList.length) {
|
|
99
|
+
newMessageList = [].concat(_toConsumableArray(chatList.slice(0, -1)), [_objectSpread(_objectSpread({}, chatList[chatList.length - 1]), {}, {
|
|
100
|
+
relatedResourceList: issueRecommendList
|
|
101
|
+
})]);
|
|
102
|
+
dispatch(setMessageList({
|
|
103
|
+
messageList: newMessageList
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
_context2.next = 14;
|
|
107
|
+
break;
|
|
108
|
+
case 11:
|
|
109
|
+
_context2.prev = 11;
|
|
110
|
+
_context2.t0 = _context2["catch"](0);
|
|
111
|
+
Toast.error('服务异常');
|
|
112
|
+
case 14:
|
|
113
|
+
case "end":
|
|
114
|
+
return _context2.stop();
|
|
115
|
+
}
|
|
116
|
+
}, _callee2, null, [[0, 11]]);
|
|
117
|
+
}));
|
|
118
|
+
return function (_x4, _x5) {
|
|
119
|
+
return _ref2.apply(this, arguments);
|
|
120
|
+
};
|
|
121
|
+
}(), []);
|
|
122
|
+
return {
|
|
123
|
+
getRecommendList: getRecommendList,
|
|
124
|
+
rewriteRecommendListFormHistory: rewriteRecommendListFormHistory
|
|
125
|
+
};
|
|
126
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface StreamChatCallbacks {
|
|
3
|
+
onSseOpen?: (response: Response) => void;
|
|
4
|
+
onDataReceived?: (response: string, type: 'content' | 'reasoningContent') => void;
|
|
5
|
+
onComplete?: (response: any, type: string, reasoningResponse?: string) => void;
|
|
6
|
+
onErrorComplete?: () => void;
|
|
7
|
+
onMCPToolsStream?: (dataObj: any) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 处理流式聊天逻辑
|
|
11
|
+
*/
|
|
12
|
+
export declare const useChatStream: () => {
|
|
13
|
+
fetchChatStream: (messageId: string | number, reSumeInfo?: any, callbacks?: StreamChatCallbacks, method?: 'GET' | 'POST', requestUrl?: string) => Promise<void>;
|
|
14
|
+
abortStream: () => void;
|
|
15
|
+
setIgnoreOnMessage: (ignore: boolean) => void;
|
|
16
|
+
getIgnoreOnMessage: () => boolean;
|
|
17
|
+
esAbortRef: import("react").MutableRefObject<AbortController | null>;
|
|
18
|
+
esRef: import("react").MutableRefObject<Response | null>;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function 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; }
|
|
4
|
+
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; }
|
|
5
|
+
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; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
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); }
|
|
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
|
+
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
|
+
import { useRef, useCallback } from 'react';
|
|
11
|
+
import { fetchEventSource } from '@microsoft/fetch-event-source';
|
|
12
|
+
import { Toast } from '@douyinfe/semi-ui';
|
|
13
|
+
import { useLastEventId } from "./useLastEventId";
|
|
14
|
+
import { useAppSelector, useAppDispatch } from "../store/hooks";
|
|
15
|
+
import { setIsMsgRecieving } from "../store/slices/gimiMenuSlice";
|
|
16
|
+
/**
|
|
17
|
+
* 处理流式聊天逻辑
|
|
18
|
+
*/
|
|
19
|
+
export var useChatStream = function useChatStream() {
|
|
20
|
+
var esAbortRef = useRef(null);
|
|
21
|
+
var esRef = useRef(null);
|
|
22
|
+
var ignoreOnMessageRef = useRef(true);
|
|
23
|
+
var _useLastEventId = useLastEventId(),
|
|
24
|
+
getLastEventId = _useLastEventId.getLastEventId,
|
|
25
|
+
saveLastEventId = _useLastEventId.saveLastEventId,
|
|
26
|
+
removeLastEventId = _useLastEventId.removeLastEventId;
|
|
27
|
+
var token = useAppSelector(function (state) {
|
|
28
|
+
return state.gimiMenu.token;
|
|
29
|
+
});
|
|
30
|
+
var tokenRef = useRef(token);
|
|
31
|
+
tokenRef.current = token;
|
|
32
|
+
var baseUrl = useAppSelector(function (state) {
|
|
33
|
+
return state.gimiMenu.baseUrl;
|
|
34
|
+
});
|
|
35
|
+
var baseUrlRef = useRef(baseUrl);
|
|
36
|
+
baseUrlRef.current = baseUrl;
|
|
37
|
+
var bussinessParams = useAppSelector(function (state) {
|
|
38
|
+
return state.gimiMenu.bussinessParams;
|
|
39
|
+
});
|
|
40
|
+
var bussinessParamsRef = useRef(bussinessParams);
|
|
41
|
+
bussinessParamsRef.current = bussinessParams;
|
|
42
|
+
var agentDetail = useAppSelector(function (state) {
|
|
43
|
+
return state.gimiMenu.agentObj;
|
|
44
|
+
});
|
|
45
|
+
var agentDetailRef = useRef(agentDetail);
|
|
46
|
+
agentDetailRef.current = agentDetail;
|
|
47
|
+
var dispatch = useAppDispatch();
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 发起流式聊天请求
|
|
51
|
+
*/
|
|
52
|
+
var fetchChatStream = useCallback( /*#__PURE__*/function () {
|
|
53
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(messageId) {
|
|
54
|
+
var reSumeInfo,
|
|
55
|
+
callbacks,
|
|
56
|
+
method,
|
|
57
|
+
requestUrl,
|
|
58
|
+
onSseOpen,
|
|
59
|
+
onDataReceived,
|
|
60
|
+
onComplete,
|
|
61
|
+
onErrorComplete,
|
|
62
|
+
onMCPToolsStream,
|
|
63
|
+
signal,
|
|
64
|
+
currentLastEventId,
|
|
65
|
+
url,
|
|
66
|
+
fullResponse,
|
|
67
|
+
reasoningResponse,
|
|
68
|
+
_bussinessParamsRef$c,
|
|
69
|
+
_args = arguments;
|
|
70
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
71
|
+
while (1) switch (_context.prev = _context.next) {
|
|
72
|
+
case 0:
|
|
73
|
+
reSumeInfo = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
|
|
74
|
+
callbacks = _args.length > 2 && _args[2] !== undefined ? _args[2] : {};
|
|
75
|
+
method = _args.length > 3 ? _args[3] : undefined;
|
|
76
|
+
requestUrl = _args.length > 4 ? _args[4] : undefined;
|
|
77
|
+
onSseOpen = callbacks.onSseOpen, onDataReceived = callbacks.onDataReceived, onComplete = callbacks.onComplete, onErrorComplete = callbacks.onErrorComplete, onMCPToolsStream = callbacks.onMCPToolsStream; // 中止之前的请求
|
|
78
|
+
if (esAbortRef.current) {
|
|
79
|
+
esAbortRef.current.abort();
|
|
80
|
+
}
|
|
81
|
+
esAbortRef.current = new AbortController();
|
|
82
|
+
signal = esAbortRef.current.signal;
|
|
83
|
+
ignoreOnMessageRef.current = false;
|
|
84
|
+
|
|
85
|
+
// 监听abort事件,确保外部调用abort时也能重置状态
|
|
86
|
+
signal.addEventListener('abort', function () {
|
|
87
|
+
dispatch(setIsMsgRecieving({
|
|
88
|
+
isMsgRecieving: false
|
|
89
|
+
}));
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// 获取 lastEventId
|
|
93
|
+
currentLastEventId = getLastEventId(messageId); // 构建URL
|
|
94
|
+
url = requestUrl ? "https://".concat(baseUrlRef.current).concat(requestUrl) : Object.keys(reSumeInfo).length === 0 ? "https://".concat(baseUrlRef.current, "/mbot/web/chat/execute?messageId=").concat(messageId) : "https://".concat(baseUrlRef.current, "/mbot/web/agent-message/getSwitchStreamOut?messageId=").concat(messageId, "&lastEventId=").concat(currentLastEventId);
|
|
95
|
+
fullResponse = Object.keys(reSumeInfo).length > 0 ? reSumeInfo.content : '';
|
|
96
|
+
reasoningResponse = Object.keys(reSumeInfo).length > 0 ? reSumeInfo.reasoningContent : '';
|
|
97
|
+
_context.prev = 14;
|
|
98
|
+
_context.next = 17;
|
|
99
|
+
return fetchEventSource(url, _objectSpread(_objectSpread({
|
|
100
|
+
method: method || 'GET',
|
|
101
|
+
headers: _objectSpread({
|
|
102
|
+
Accept: 'text/event-stream',
|
|
103
|
+
'Cache-Control': 'no-cache',
|
|
104
|
+
Connection: 'keep-alive',
|
|
105
|
+
Authorization: "Bearer ".concat(tokenRef.current)
|
|
106
|
+
}, method === 'POST' ? {
|
|
107
|
+
'Content-Type': 'application/json'
|
|
108
|
+
} : {}),
|
|
109
|
+
signal: signal
|
|
110
|
+
}, method === 'POST' && {
|
|
111
|
+
body: JSON.stringify({
|
|
112
|
+
botId: "BOT1766633236586",
|
|
113
|
+
content: '',
|
|
114
|
+
mapInput: {},
|
|
115
|
+
sysInfo: _objectSpread({}, (_bussinessParamsRef$c = bussinessParamsRef.current) === null || _bussinessParamsRef$c === void 0 ? void 0 : _bussinessParamsRef$c.bussinessParams)
|
|
116
|
+
})
|
|
117
|
+
}), {}, {
|
|
118
|
+
openWhenHidden: true,
|
|
119
|
+
onopen: function onopen(response) {
|
|
120
|
+
esRef.current = response;
|
|
121
|
+
onSseOpen === null || onSseOpen === void 0 || onSseOpen(response);
|
|
122
|
+
return Promise.resolve();
|
|
123
|
+
},
|
|
124
|
+
onmessage: function onmessage(event) {
|
|
125
|
+
dispatch(setIsMsgRecieving({
|
|
126
|
+
isMsgRecieving: true
|
|
127
|
+
}));
|
|
128
|
+
if (!(event !== null && event !== void 0 && event.data) || ignoreOnMessageRef.current) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
var data = JSON.parse(event.data);
|
|
133
|
+
var _dataObj = JSON.parse(data.result || '{}');
|
|
134
|
+
|
|
135
|
+
// 保存 lastEventId
|
|
136
|
+
if (messageId && event.id) {
|
|
137
|
+
saveLastEventId(messageId, event.id);
|
|
138
|
+
}
|
|
139
|
+
if (data.status === 0 && data.result && ['end', 'ask', 'skill', 'tool_call', 'COMPLETED'].includes(_dataObj.moduleType) && !_dataObj.ERROR) {
|
|
140
|
+
if (_dataObj.status === 'RUNNING' && _dataObj.moduleType === 'end') {
|
|
141
|
+
if (_dataObj.content && !_dataObj.reasoningContent) {
|
|
142
|
+
fullResponse += _dataObj.content;
|
|
143
|
+
onDataReceived === null || onDataReceived === void 0 || onDataReceived(fullResponse, 'content');
|
|
144
|
+
} else if (_dataObj.reasoningContent && !_dataObj.content) {
|
|
145
|
+
reasoningResponse += _dataObj.reasoningContent;
|
|
146
|
+
onDataReceived === null || onDataReceived === void 0 || onDataReceived(reasoningResponse, 'reasoningContent');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (_dataObj.moduleType === 'tool_call') {
|
|
150
|
+
onMCPToolsStream === null || onMCPToolsStream === void 0 || onMCPToolsStream(_dataObj);
|
|
151
|
+
}
|
|
152
|
+
if ((_dataObj.moduleType === 'ask' || _dataObj.moduleType === 'skill') && _dataObj.status === 'PENDING') {
|
|
153
|
+
onComplete === null || onComplete === void 0 || onComplete(_dataObj, _dataObj.moduleType);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (_dataObj.status === 'COMPLETED' && _dataObj.moduleType === 'end' || _dataObj.moduleType === 'COMPLETED') {
|
|
157
|
+
removeLastEventId(messageId);
|
|
158
|
+
onComplete === null || onComplete === void 0 || onComplete(fullResponse, _dataObj.moduleType, reasoningResponse);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
} else if (_dataObj.ERROR || _dataObj.moduleType === 'FAILED') {
|
|
162
|
+
Toast.error('服务异常');
|
|
163
|
+
onErrorComplete === null || onErrorComplete === void 0 || onErrorComplete();
|
|
164
|
+
return;
|
|
165
|
+
} else if (data.status && data.status !== 0 && !_dataObj.ERROR) {
|
|
166
|
+
Toast.error(data.message);
|
|
167
|
+
onErrorComplete === null || onErrorComplete === void 0 || onErrorComplete();
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
} catch (parseErr) {
|
|
171
|
+
console.error('解析消息失败:', parseErr);
|
|
172
|
+
onErrorComplete === null || onErrorComplete === void 0 || onErrorComplete();
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
onerror: function onerror(error) {
|
|
176
|
+
var _esAbortRef$current;
|
|
177
|
+
dispatch(setIsMsgRecieving({
|
|
178
|
+
isMsgRecieving: false
|
|
179
|
+
}));
|
|
180
|
+
(_esAbortRef$current = esAbortRef.current) === null || _esAbortRef$current === void 0 || _esAbortRef$current.abort();
|
|
181
|
+
throw error;
|
|
182
|
+
},
|
|
183
|
+
onclose: function onclose() {
|
|
184
|
+
dispatch(setIsMsgRecieving({
|
|
185
|
+
isMsgRecieving: false
|
|
186
|
+
}));
|
|
187
|
+
console.log('流式结束');
|
|
188
|
+
}
|
|
189
|
+
}));
|
|
190
|
+
case 17:
|
|
191
|
+
_context.next = 23;
|
|
192
|
+
break;
|
|
193
|
+
case 19:
|
|
194
|
+
_context.prev = 19;
|
|
195
|
+
_context.t0 = _context["catch"](14);
|
|
196
|
+
dispatch(setIsMsgRecieving({
|
|
197
|
+
isMsgRecieving: false
|
|
198
|
+
}));
|
|
199
|
+
console.error('流式请求失败:', _context.t0);
|
|
200
|
+
case 23:
|
|
201
|
+
case "end":
|
|
202
|
+
return _context.stop();
|
|
203
|
+
}
|
|
204
|
+
}, _callee, null, [[14, 19]]);
|
|
205
|
+
}));
|
|
206
|
+
return function (_x) {
|
|
207
|
+
return _ref.apply(this, arguments);
|
|
208
|
+
};
|
|
209
|
+
}(), [token, getLastEventId, saveLastEventId, removeLastEventId, dispatch]);
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* 中止流式请求
|
|
213
|
+
*/
|
|
214
|
+
var abortStream = useCallback(function () {
|
|
215
|
+
if (esAbortRef.current) {
|
|
216
|
+
esAbortRef.current.abort();
|
|
217
|
+
esAbortRef.current = null;
|
|
218
|
+
}
|
|
219
|
+
// Response 对象没有 close 方法,通过 AbortController 中止时会自动关闭连接
|
|
220
|
+
esRef.current = null;
|
|
221
|
+
}, []);
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* 设置是否忽略消息
|
|
225
|
+
*/
|
|
226
|
+
var setIgnoreOnMessage = useCallback(function (ignore) {
|
|
227
|
+
ignoreOnMessageRef.current = ignore;
|
|
228
|
+
}, []);
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* 获取是否忽略消息
|
|
232
|
+
*/
|
|
233
|
+
var getIgnoreOnMessage = useCallback(function () {
|
|
234
|
+
return ignoreOnMessageRef.current;
|
|
235
|
+
}, []);
|
|
236
|
+
return {
|
|
237
|
+
fetchChatStream: fetchChatStream,
|
|
238
|
+
abortStream: abortStream,
|
|
239
|
+
setIgnoreOnMessage: setIgnoreOnMessage,
|
|
240
|
+
getIgnoreOnMessage: getIgnoreOnMessage,
|
|
241
|
+
esAbortRef: esAbortRef,
|
|
242
|
+
esRef: esRef
|
|
243
|
+
};
|
|
244
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* 管理聊天UI相关状态(右侧面板、搜索等)
|
|
4
|
+
*/
|
|
5
|
+
export declare const useChatUI: () => {
|
|
6
|
+
showCopyId: number | null;
|
|
7
|
+
showSearchResults: boolean;
|
|
8
|
+
showType: number | null;
|
|
9
|
+
videoIds: string[] | null;
|
|
10
|
+
videoResourceList: null;
|
|
11
|
+
searchStr: string;
|
|
12
|
+
selectedItem: {
|
|
13
|
+
id: string | null;
|
|
14
|
+
index: number | null;
|
|
15
|
+
} | null;
|
|
16
|
+
currentId: string | null;
|
|
17
|
+
setShowCopyId: import("react").Dispatch<import("react").SetStateAction<number | null>>;
|
|
18
|
+
setShowSearchResults: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
19
|
+
setShowType: import("react").Dispatch<import("react").SetStateAction<number | null>>;
|
|
20
|
+
setVideoIds: import("react").Dispatch<import("react").SetStateAction<string[] | null>>;
|
|
21
|
+
setVideoResourceList: import("react").Dispatch<import("react").SetStateAction<null>>;
|
|
22
|
+
setSearchStr: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
23
|
+
setSelectedItem: import("react").Dispatch<import("react").SetStateAction<{
|
|
24
|
+
id: string | null;
|
|
25
|
+
index: number | null;
|
|
26
|
+
} | null>>;
|
|
27
|
+
setCurrentId: import("react").Dispatch<import("react").SetStateAction<string | null>>;
|
|
28
|
+
closePanel: () => void;
|
|
29
|
+
showSearchResult: (messageId: string, query?: string) => void;
|
|
30
|
+
showVideo: (content: string, id: string, index: number) => void;
|
|
31
|
+
showCourse: (messageId: string, videoResourceList?: any) => void;
|
|
32
|
+
};
|