@myun/gimi-chat 0.9.65 → 0.9.66
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 +6 -0
- package/dist/apis/useApi.js +45 -1
- package/dist/components/ai-chat-dialogue/index copy.js +1 -1
- package/dist/components/ai-chat-dialogue/index.js +4 -2
- package/dist/components/answer-item/component/artifacts/index.d.ts +13 -0
- package/dist/components/answer-item/component/artifacts/index.js +52 -0
- package/dist/components/answer-item/component/artifacts/index.module.css +24 -0
- package/dist/components/answer-item/component/tool-list/index.d.ts +7 -0
- package/dist/components/answer-item/component/tool-list/index.js +117 -0
- package/dist/components/answer-item/component/tool-list/index.module.css +97 -0
- package/dist/components/answer-item/index.d.ts +2 -1
- package/dist/components/answer-item/index.js +179 -8
- package/dist/components/answer-item/index.module.css +35 -0
- package/dist/components/ask-card/index.d.ts +1 -1
- package/dist/components/chat-input/extension/index.d.ts +1 -0
- package/dist/components/chat-input/extension/index.js +2 -1
- package/dist/components/chat-input/extension/skill/MentionList.d.ts +31 -0
- package/dist/components/chat-input/extension/skill/MentionList.js +199 -0
- package/dist/components/chat-input/extension/skill/ReferSlot.d.ts +3 -0
- package/dist/components/chat-input/extension/skill/ReferSlot.js +100 -0
- package/dist/components/chat-input/extension/skill/data.d.ts +10 -0
- package/dist/components/chat-input/extension/skill/data.js +49 -0
- package/dist/components/chat-input/extension/skill/index.d.ts +7 -0
- package/dist/components/chat-input/extension/skill/index.js +5 -0
- package/dist/components/chat-input/extension/skill/index.less +117 -0
- package/dist/components/chat-input/extension/skill/suggestion.d.ts +16 -0
- package/dist/components/chat-input/extension/skill/suggestion.js +206 -0
- package/dist/components/chat-input/index.js +145 -24
- package/dist/components/chat-input/index.module.css +6 -0
- package/dist/components/file-card/index.js +2 -1
- package/dist/components/file-card/index.module.css +1 -0
- package/dist/components/knowledge-trace/KnowledgeIconComponent.js +6 -1
- package/dist/components/knowledge-trace/tryWatch.js +2 -2
- package/dist/components/message-list/index.js +15 -3
- package/dist/components/message-list/index.module.css +3 -0
- package/dist/components/message-list/skill-tag/index.d.ts +5 -0
- package/dist/components/message-list/skill-tag/index.js +23 -0
- package/dist/components/message-list/skill-tag/index.module.css +22 -0
- package/dist/components/templates/CommonChat.js +3 -1
- package/dist/hooks/useChatActions.d.ts +2 -1
- package/dist/hooks/useChatActions.js +52 -12
- package/dist/hooks/useChatStream.d.ts +6 -1
- package/dist/hooks/useChatStream.js +97 -5
- package/dist/hooks/useCommonChatAPI.d.ts +1 -1
- package/dist/hooks/useCommonChatAPI.js +212 -58
- package/dist/i18n/locales/en-US.d.ts +7 -0
- package/dist/i18n/locales/en-US.js +8 -1
- package/dist/i18n/locales/zh-CN.d.ts +7 -0
- package/dist/i18n/locales/zh-CN.js +8 -1
- package/dist/interfaces/chatMessage.d.ts +40 -0
- package/dist/umd/index.min.js +1 -1
- package/dist/utils/tools.d.ts +7 -0
- package/dist/utils/tools.js +38 -1
- package/package.json +4 -2
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
export declare const TOOL_MODULE_TYPES: string[];
|
|
3
|
+
export declare const MODULE_TYPE_NAMES: Record<string, string>;
|
|
4
|
+
export declare const getToolNameByStatus: (moduleType: string, status?: string) => string;
|
|
2
5
|
interface StreamChatCallbacks {
|
|
3
6
|
onSseOpen?: (response: Response) => void;
|
|
4
7
|
onDataReceived?: (response: string, type: 'content' | 'reasoningContent') => void;
|
|
5
|
-
onComplete?: (response: any, type: string, reasoningResponse?: string) => void;
|
|
8
|
+
onComplete?: (response: any, type: string, reasoningResponse?: string, dataObj?: any) => void;
|
|
6
9
|
onErrorComplete?: () => void;
|
|
7
10
|
onMCPToolsStream?: (dataObj: any) => void;
|
|
11
|
+
onToolStream?: (dataObj: any) => void;
|
|
12
|
+
onArtifactStream?: (dataObj: any) => void;
|
|
8
13
|
}
|
|
9
14
|
/**
|
|
10
15
|
* 处理流式聊天逻辑
|
|
@@ -15,6 +15,76 @@ import { useLastEventId } from "./useLastEventId";
|
|
|
15
15
|
import { useAppSelector, useAppDispatch } from "../store/hooks";
|
|
16
16
|
import { setIsMsgRecieving } from "../store/slices/gimiMenuSlice";
|
|
17
17
|
import { getTimeZone } from "../utils/tools";
|
|
18
|
+
|
|
19
|
+
// 需要展示为工具调用的模块类型
|
|
20
|
+
export var TOOL_MODULE_TYPES = ['tool_invocation', 'tool_result', "thinking"
|
|
21
|
+
// 'start', 'llm', 'knowledge', 'video', 'image-text',
|
|
22
|
+
// 'input', 'if-select', 'intent', 'talk', 'text',
|
|
23
|
+
// 'video-caption', 'summary', 'loop', 'skillBase',
|
|
24
|
+
// 'break', 'http', 'esKnowledge', 'mcp'
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
// 所有需要进入处理流程的模块类型(包括工具类型 + 特殊处理类型)
|
|
28
|
+
var PROCESSABLE_MODULE_TYPES = [].concat(TOOL_MODULE_TYPES, ['end', 'ask', 'skill', 'tool_call', 'artifact', 'user_confirm', 'COMPLETED']);
|
|
29
|
+
|
|
30
|
+
// 模块类型到工具名称的映射
|
|
31
|
+
export var MODULE_TYPE_NAMES = {
|
|
32
|
+
'start': '开始节点',
|
|
33
|
+
'end': '结束节点',
|
|
34
|
+
'llm': '模型节点',
|
|
35
|
+
'knowledge': '知识库节点',
|
|
36
|
+
'video': '视频节点',
|
|
37
|
+
'image-text': '图文节点',
|
|
38
|
+
'input': '输入节点',
|
|
39
|
+
'if-select': '选择节点',
|
|
40
|
+
'intent': '意图识别节点',
|
|
41
|
+
'talk': '讨论节点',
|
|
42
|
+
'ask': '问答节点',
|
|
43
|
+
'text': '文本处理节点',
|
|
44
|
+
'video-caption': '视频字幕节点',
|
|
45
|
+
'summary': '章节总结节点',
|
|
46
|
+
'loop': '循环节点',
|
|
47
|
+
'skill': '技能节点',
|
|
48
|
+
'skillBase': '通用技能节点',
|
|
49
|
+
'break': '终止循环节点',
|
|
50
|
+
'http': 'HTTP节点',
|
|
51
|
+
'esKnowledge': '知识库节点',
|
|
52
|
+
'mcp': 'MCP节点'
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// 根据 moduleType 和 status 生成 toolName
|
|
56
|
+
export var getToolNameByStatus = function getToolNameByStatus(moduleType, status) {
|
|
57
|
+
// thinking 类型定制文案
|
|
58
|
+
if (moduleType === 'thinking') {
|
|
59
|
+
if (status === 'STARTED') {
|
|
60
|
+
return '开始分析问题';
|
|
61
|
+
} else if (status === 'RUNNING') {
|
|
62
|
+
return '正在分析问题';
|
|
63
|
+
} else if (status === 'COMPLETED') {
|
|
64
|
+
return '已完成分析';
|
|
65
|
+
}
|
|
66
|
+
return '深度思考';
|
|
67
|
+
}
|
|
68
|
+
var baseName = MODULE_TYPE_NAMES[moduleType] || moduleType;
|
|
69
|
+
if (!status) {
|
|
70
|
+
return baseName;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 根据状态生成描述
|
|
74
|
+
if (status === 'STARTED') {
|
|
75
|
+
return "\u5F00\u59CB\u8FD0\u884C".concat(baseName);
|
|
76
|
+
} else if (status === 'COMPLETED') {
|
|
77
|
+
return "".concat(baseName, "\u8FD0\u884C\u5B8C\u6210");
|
|
78
|
+
} else if (status === 'RUNNING') {
|
|
79
|
+
return "".concat(baseName, "\u8FD0\u884C\u4E2D");
|
|
80
|
+
} else if (status === 'PENDING') {
|
|
81
|
+
return "".concat(baseName, "\u7B49\u5F85\u4E2D");
|
|
82
|
+
} else if (status === 'FAILED') {
|
|
83
|
+
return "".concat(baseName, "\u8FD0\u884C\u5931\u8D25");
|
|
84
|
+
} else {
|
|
85
|
+
return baseName;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
18
88
|
/**
|
|
19
89
|
* 处理流式聊天逻辑
|
|
20
90
|
*/
|
|
@@ -65,6 +135,8 @@ export var useChatStream = function useChatStream(platform) {
|
|
|
65
135
|
onComplete,
|
|
66
136
|
onErrorComplete,
|
|
67
137
|
onMCPToolsStream,
|
|
138
|
+
onToolStream,
|
|
139
|
+
onArtifactStream,
|
|
68
140
|
signal,
|
|
69
141
|
currentLastEventId,
|
|
70
142
|
url,
|
|
@@ -78,7 +150,7 @@ export var useChatStream = function useChatStream(platform) {
|
|
|
78
150
|
callbacks = _args.length > 2 && _args[2] !== undefined ? _args[2] : {};
|
|
79
151
|
method = _args.length > 3 ? _args[3] : undefined;
|
|
80
152
|
requestUrl = _args.length > 4 ? _args[4] : undefined;
|
|
81
|
-
onSseOpen = callbacks.onSseOpen, onDataReceived = callbacks.onDataReceived, onComplete = callbacks.onComplete, onErrorComplete = callbacks.onErrorComplete, onMCPToolsStream = callbacks.onMCPToolsStream; // 中止之前的请求
|
|
153
|
+
onSseOpen = callbacks.onSseOpen, onDataReceived = callbacks.onDataReceived, onComplete = callbacks.onComplete, onErrorComplete = callbacks.onErrorComplete, onMCPToolsStream = callbacks.onMCPToolsStream, onToolStream = callbacks.onToolStream, onArtifactStream = callbacks.onArtifactStream; // 中止之前的请求
|
|
82
154
|
if (esAbortRef.current) {
|
|
83
155
|
esAbortRef.current.abort();
|
|
84
156
|
}
|
|
@@ -142,7 +214,8 @@ export var useChatStream = function useChatStream(platform) {
|
|
|
142
214
|
if (messageId && event.id) {
|
|
143
215
|
saveLastEventId(messageId, event.id);
|
|
144
216
|
}
|
|
145
|
-
if (data.status === 0 && data.result &&
|
|
217
|
+
if (data.status === 0 && data.result && PROCESSABLE_MODULE_TYPES.includes(_dataObj.moduleType) && !_dataObj.ERROR) {
|
|
218
|
+
console.log('dataObj-----', _dataObj);
|
|
146
219
|
if (_dataObj.status === 'RUNNING' && _dataObj.moduleType === 'end') {
|
|
147
220
|
if (_dataObj.content && !_dataObj.reasoningContent) {
|
|
148
221
|
fullResponse += _dataObj.content;
|
|
@@ -155,15 +228,33 @@ export var useChatStream = function useChatStream(platform) {
|
|
|
155
228
|
if (_dataObj.moduleType === 'tool_call') {
|
|
156
229
|
onMCPToolsStream === null || onMCPToolsStream === void 0 || onMCPToolsStream(_dataObj);
|
|
157
230
|
}
|
|
231
|
+
|
|
232
|
+
// 工具调用
|
|
233
|
+
if (TOOL_MODULE_TYPES.includes(_dataObj.moduleType) && !["execute", "notifyWorkflowStart"].includes(_dataObj.name)) {
|
|
234
|
+
// console.log('dataObj',dataObj);
|
|
235
|
+
onToolStream === null || onToolStream === void 0 || onToolStream(_dataObj);
|
|
236
|
+
}
|
|
237
|
+
// 生成产物
|
|
238
|
+
if (_dataObj.moduleType === 'artifact' && _dataObj.status === 'COMPLETED') {
|
|
239
|
+
onArtifactStream === null || onArtifactStream === void 0 || onArtifactStream(_dataObj);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// 问答确认
|
|
158
243
|
if ((_dataObj.moduleType === 'ask' || _dataObj.moduleType === 'skill') && _dataObj.status === 'PENDING') {
|
|
159
244
|
onComplete === null || onComplete === void 0 || onComplete(_dataObj, _dataObj.moduleType);
|
|
160
245
|
return;
|
|
161
246
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
onComplete === null || onComplete === void 0 || onComplete(
|
|
247
|
+
// 确认模式
|
|
248
|
+
if (_dataObj.moduleType === 'user_confirm' && _dataObj.status === 'ASKING') {
|
|
249
|
+
onComplete === null || onComplete === void 0 || onComplete(_dataObj, _dataObj.moduleType);
|
|
165
250
|
return;
|
|
166
251
|
}
|
|
252
|
+
} else if (_dataObj.moduleType === 'agent' && _dataObj.status === 'STARTED') {
|
|
253
|
+
onToolStream === null || onToolStream === void 0 || onToolStream(_dataObj);
|
|
254
|
+
} else if (_dataObj.moduleType === 'agent' && _dataObj.status === 'COMPLETED' || _dataObj.type === 'WORKFLOW_COMPLETED') {
|
|
255
|
+
removeLastEventId(messageId);
|
|
256
|
+
onComplete === null || onComplete === void 0 || onComplete(fullResponse, 'end', reasoningResponse, _dataObj);
|
|
257
|
+
return;
|
|
167
258
|
} else if (_dataObj.ERROR || _dataObj.moduleType === 'FAILED') {
|
|
168
259
|
var isRefresh = parseInt(_dataObj.status, 10) === 10002026;
|
|
169
260
|
if (isRefresh) {
|
|
@@ -207,6 +298,7 @@ export var useChatStream = function useChatStream(platform) {
|
|
|
207
298
|
dispatch(setIsMsgRecieving({
|
|
208
299
|
isMsgRecieving: false
|
|
209
300
|
}));
|
|
301
|
+
esAbortRef.current = null; // 清空,避免残留
|
|
210
302
|
console.log('流式结束');
|
|
211
303
|
}
|
|
212
304
|
}));
|
|
@@ -33,7 +33,7 @@ declare const useCommonChatAPI: (props: IHookProps) => {
|
|
|
33
33
|
getContentMessageList: (pageIndex?: number, curPageSize?: number) => Promise<void>;
|
|
34
34
|
hasMore: React.MutableRefObject<boolean>;
|
|
35
35
|
loadMore: () => void;
|
|
36
|
-
handleSend: (val: string, agent?: any, isSystemAuto?: boolean, conversationId?: number) => Promise<void>;
|
|
36
|
+
handleSend: (val: string, agent?: any, isSystemAuto?: boolean, conversationId?: number, skipCreateNewMessage?: boolean) => Promise<void>;
|
|
37
37
|
scrollBottomForce: (animate?: boolean | undefined) => void;
|
|
38
38
|
showBackBottom: boolean;
|
|
39
39
|
isScrolling: boolean;
|