@zero-library/chat-agent 2.1.18 → 2.1.20
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/index.cjs.js +130 -157
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.css +0 -24
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +295 -197
- package/dist/index.d.ts +295 -197
- package/dist/index.esm.js +131 -158
- package/dist/index.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { useRefState, useDebounce, useSyncInput, RenderWrapper, shouldRender, isFunction, useDeepEffect, useWebSocket, getWebSocketUrl, getToken, isLocalhost, downloadFile, FilePreview, MarkdownEditor,
|
|
2
|
-
import { App, Badge, Button, Flex, Typography, Spin, Splitter, Tag, Popover, List, Avatar, Space, message, Empty,
|
|
3
|
-
import dayjs from 'dayjs';
|
|
1
|
+
import { useRefState, useDebounce, useSyncInput, RenderWrapper, shouldRender, isFunction, useDeepEffect, useWebSocket, getWebSocketUrl, getToken, isLocalhost, downloadFile, FilePreview, MarkdownEditor, isNumber, getFileSuffixName, isObject, isNullOrUnDef, isBoolean, UserAvatar, copyText, deepCopy, transforms, transform, getCurrentUser, deepMerge, createRequest, RenderMarkdown, useCreateValtioContext, FileIcon, isExternal } from '@zero-library/common';
|
|
2
|
+
import { App, Badge, Button, Flex, Typography, Spin, Splitter, Tag, Popover, List, Avatar, Space, message, Empty, Modal, Row, Col, Collapse, Drawer } from 'antd';
|
|
4
3
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
4
|
import { forwardRef, useRef, useEffect, useImperativeHandle, useMemo, useState } from 'react';
|
|
6
5
|
import { useSnapshot, proxy } from 'valtio';
|
|
7
6
|
import { CloudUploadOutlined, PaperClipOutlined, EnterOutlined, UserSwitchOutlined, CloseOutlined, PlusOutlined, CommentOutlined, OpenAIOutlined, CopyOutlined, LikeOutlined, DislikeOutlined, DeleteOutlined, RedoOutlined, PlayCircleOutlined, CaretRightOutlined } from '@ant-design/icons';
|
|
8
7
|
import { Attachments, Sender, Suggestion, XProvider, Welcome, Prompts, Bubble, Conversations } from '@ant-design/x';
|
|
9
8
|
export * from '@ant-design/x';
|
|
10
|
-
import
|
|
9
|
+
import classNames8 from 'classnames';
|
|
10
|
+
import dayjs from 'dayjs';
|
|
11
11
|
import InfiniteScroll from 'react-infinite-scroll-component';
|
|
12
12
|
|
|
13
13
|
var __defProp = Object.defineProperty;
|
|
@@ -19,33 +19,6 @@ var __export = (target, all) => {
|
|
|
19
19
|
for (var name in all)
|
|
20
20
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
21
21
|
};
|
|
22
|
-
var classifyTime, copy;
|
|
23
|
-
var init_utils = __esm({
|
|
24
|
-
"src/core/utils.ts"() {
|
|
25
|
-
classifyTime = (timestamp) => {
|
|
26
|
-
const now = dayjs();
|
|
27
|
-
const target = dayjs(timestamp);
|
|
28
|
-
if (target.isSame(now, "day")) {
|
|
29
|
-
return "\u4ECA\u5929";
|
|
30
|
-
}
|
|
31
|
-
const diffInDays = now.diff(target, "day");
|
|
32
|
-
if (diffInDays < 7) {
|
|
33
|
-
return "\u6700\u8FD1 7 \u5929";
|
|
34
|
-
} else if (diffInDays < 30) {
|
|
35
|
-
return "\u6700\u8FD1 30 \u5929";
|
|
36
|
-
} else if (diffInDays < 180) {
|
|
37
|
-
return "\u6700\u8FD1\u534A\u5E74";
|
|
38
|
-
} else {
|
|
39
|
-
return "\u66F4\u65E9";
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
copy = (value) => {
|
|
43
|
-
copyText(value).then(() => {
|
|
44
|
-
message.success("\u590D\u5236\u6210\u529F");
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
22
|
var ChatProvider, useChatStore;
|
|
50
23
|
var init_Context = __esm({
|
|
51
24
|
"src/stores/Context.ts"() {
|
|
@@ -204,7 +177,6 @@ __export(FileEdit_exports, {
|
|
|
204
177
|
var FileEdit_default;
|
|
205
178
|
var init_FileEdit = __esm({
|
|
206
179
|
"src/ui/common/markdownAlert/FileEdit.tsx"() {
|
|
207
|
-
init_utils();
|
|
208
180
|
init_Context();
|
|
209
181
|
init_styles_module();
|
|
210
182
|
FileEdit_default = ({ data, loading }) => {
|
|
@@ -220,7 +192,7 @@ var init_FileEdit = __esm({
|
|
|
220
192
|
] }),
|
|
221
193
|
/* @__PURE__ */ jsx(Spin, { spinning: loading, size: "small", children: /* @__PURE__ */ jsxs(Flex, { children: [
|
|
222
194
|
/* @__PURE__ */ jsx(Button, { color: "default", variant: "text", size: "small", icon: /* @__PURE__ */ jsx(PlayCircleOutlined, {}), onClick: onPreview, children: "\u9884\u89C8\u7F16\u8F91" }),
|
|
223
|
-
/* @__PURE__ */ jsx(Button, { color: "default", variant: "text", size: "small", icon: /* @__PURE__ */ jsx(CopyOutlined, {}), onClick: () =>
|
|
195
|
+
/* @__PURE__ */ jsx(Button, { color: "default", variant: "text", size: "small", icon: /* @__PURE__ */ jsx(CopyOutlined, {}), onClick: () => copyText(data.content), children: "\u590D\u5236" })
|
|
224
196
|
] }) })
|
|
225
197
|
] }),
|
|
226
198
|
/* @__PURE__ */ jsx(Flex, { gap: 8, align: "center", className: styles_module_default.fileEditContent, children: /* @__PURE__ */ jsx(RenderMarkdown, { content: data.content }) })
|
|
@@ -303,9 +275,26 @@ var init_Think = __esm({
|
|
|
303
275
|
};
|
|
304
276
|
}
|
|
305
277
|
});
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
278
|
+
var classifyTime = (timestamp) => {
|
|
279
|
+
const now = dayjs();
|
|
280
|
+
const target = dayjs(timestamp);
|
|
281
|
+
if (target.isSame(now, "day")) {
|
|
282
|
+
return "\u4ECA\u5929";
|
|
283
|
+
}
|
|
284
|
+
const diffInDays = now.diff(target, "day");
|
|
285
|
+
if (diffInDays < 7) {
|
|
286
|
+
return "\u6700\u8FD1 7 \u5929";
|
|
287
|
+
} else if (diffInDays < 30) {
|
|
288
|
+
return "\u6700\u8FD1 30 \u5929";
|
|
289
|
+
} else if (diffInDays < 180) {
|
|
290
|
+
return "\u6700\u8FD1\u534A\u5E74";
|
|
291
|
+
} else {
|
|
292
|
+
return "\u66F4\u65E9";
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
var replaceThinkTags = (str) => {
|
|
296
|
+
return str.replace(/<think>/g, ":::alert type=think data={content:'").replace(/<\/think>/g, "'} :::");
|
|
297
|
+
};
|
|
309
298
|
|
|
310
299
|
// src/services/index.ts
|
|
311
300
|
var createChatService = (request) => {
|
|
@@ -441,6 +430,7 @@ function createChatStore() {
|
|
|
441
430
|
},
|
|
442
431
|
hooks: {},
|
|
443
432
|
layout: {},
|
|
433
|
+
/** 文件预览状态 */
|
|
444
434
|
preview: {
|
|
445
435
|
file: {},
|
|
446
436
|
isEdit: false
|
|
@@ -448,7 +438,9 @@ function createChatStore() {
|
|
|
448
438
|
// isShow: 0, // 0 不显示 1 显示 2 用户关闭
|
|
449
439
|
// isIntact: false // true 完整 false 不完整
|
|
450
440
|
},
|
|
441
|
+
/** 当前用户信息 */
|
|
451
442
|
userInfo: {},
|
|
443
|
+
/** 聊天参数配置 */
|
|
452
444
|
params: {}
|
|
453
445
|
});
|
|
454
446
|
const setServices = ({ baseUrl = "/api" } = {}) => {
|
|
@@ -490,14 +482,16 @@ function createChatStore() {
|
|
|
490
482
|
},
|
|
491
483
|
name: "name",
|
|
492
484
|
iconUrl: "avatar",
|
|
493
|
-
description: "
|
|
485
|
+
description: "remark"
|
|
494
486
|
});
|
|
495
487
|
};
|
|
496
488
|
const receiver = proxy({
|
|
489
|
+
/** 当前激活的接收者信息(智能体或专家) */
|
|
497
490
|
active: {},
|
|
491
|
+
/** 接收者加载状态 */
|
|
498
492
|
loading: false,
|
|
493
|
+
/** 接收者透传参数,后期可能扩展不透传参数 */
|
|
499
494
|
params: {}
|
|
500
|
-
// 透传参数,后期可能扩展不透传参数
|
|
501
495
|
});
|
|
502
496
|
const setReceiverParams = (params) => {
|
|
503
497
|
if (isObject(params)) {
|
|
@@ -556,10 +550,15 @@ function createChatStore() {
|
|
|
556
550
|
setReceiverParams();
|
|
557
551
|
};
|
|
558
552
|
const character = proxy({
|
|
553
|
+
/** 性格列表 */
|
|
559
554
|
list: [],
|
|
555
|
+
/** 当前激活的性格 */
|
|
560
556
|
active: {},
|
|
557
|
+
/** 性格选择面板是否打开 */
|
|
561
558
|
open: false,
|
|
559
|
+
/** 加载性格列表的状态 */
|
|
562
560
|
loading: false,
|
|
561
|
+
/** 切换性格时的加载状态 */
|
|
563
562
|
switchLoading: false
|
|
564
563
|
});
|
|
565
564
|
const getCharacters = async (agentId) => {
|
|
@@ -594,16 +593,20 @@ function createChatStore() {
|
|
|
594
593
|
}
|
|
595
594
|
};
|
|
596
595
|
const conversations = proxy({
|
|
596
|
+
/** 会话列表数据 */
|
|
597
597
|
list: {
|
|
598
598
|
items: [],
|
|
599
|
+
/** 分页查询参数 */
|
|
599
600
|
params: {
|
|
600
601
|
pageNum: 1,
|
|
601
602
|
pageSize: 1e3
|
|
602
603
|
}
|
|
603
604
|
},
|
|
605
|
+
/** 当前会话索引,创建会话时更新,促使页面更新会话列表 */
|
|
604
606
|
updateIndex: 0,
|
|
605
|
-
|
|
607
|
+
/** 获取会话列表的加载状态 */
|
|
606
608
|
loading: false,
|
|
609
|
+
/** 删除会话的加载状态 */
|
|
607
610
|
delLoading: false
|
|
608
611
|
});
|
|
609
612
|
const getConversations = async (targetId, targetType) => {
|
|
@@ -649,14 +652,18 @@ function createChatStore() {
|
|
|
649
652
|
}
|
|
650
653
|
};
|
|
651
654
|
const conversation = proxy({
|
|
652
|
-
|
|
655
|
+
/** 当前激活的会话信息 */
|
|
653
656
|
active: {
|
|
654
657
|
id: "",
|
|
658
|
+
/** 会话成员对象,包含用户、智能体、专家等 */
|
|
655
659
|
member: {}
|
|
656
660
|
},
|
|
661
|
+
/** 每个会话的消息存储,以会话ID为键 */
|
|
657
662
|
messages: {},
|
|
663
|
+
/** 消息反馈状态 */
|
|
658
664
|
feedback: {
|
|
659
665
|
// open: false,
|
|
666
|
+
/** 反馈操作加载状态 */
|
|
660
667
|
loading: false
|
|
661
668
|
// recordId: '',
|
|
662
669
|
// target: undefined as number | undefined
|
|
@@ -704,14 +711,18 @@ function createChatStore() {
|
|
|
704
711
|
};
|
|
705
712
|
const setInitMessage = async (conversationId) => {
|
|
706
713
|
conversation.messages[conversationId] = {
|
|
714
|
+
/** 输入框内容 */
|
|
707
715
|
content: "",
|
|
716
|
+
/** 上传文件列表 */
|
|
708
717
|
files: [],
|
|
709
|
-
|
|
718
|
+
/** 头部展开状态 */
|
|
710
719
|
headerOpen: false,
|
|
720
|
+
/** 消息发送/接收加载状态 */
|
|
711
721
|
loading: false,
|
|
722
|
+
/** 消息列表 */
|
|
712
723
|
message: [],
|
|
724
|
+
/** 推荐问题列表 */
|
|
713
725
|
questionList: []
|
|
714
|
-
// 推荐问题
|
|
715
726
|
};
|
|
716
727
|
};
|
|
717
728
|
const resolveConversationId = async (receiverId, strategy = 2) => {
|
|
@@ -816,13 +827,13 @@ function createChatStore() {
|
|
|
816
827
|
if (other) return other;
|
|
817
828
|
return void 0;
|
|
818
829
|
};
|
|
819
|
-
const sendMessage = async (
|
|
830
|
+
const sendMessage = async (message2, files = [], params) => {
|
|
820
831
|
const conversationId = conversation.active.id;
|
|
821
832
|
if (conversation.messages[conversationId].loading) return;
|
|
822
833
|
let msgContent = "", msgFiles;
|
|
823
834
|
const references = conversation.messages[conversationId].references;
|
|
824
|
-
if (
|
|
825
|
-
msgContent =
|
|
835
|
+
if (message2) {
|
|
836
|
+
msgContent = message2;
|
|
826
837
|
msgFiles = files;
|
|
827
838
|
} else {
|
|
828
839
|
if (references?.type === 1 && references?.content?.markdown) {
|
|
@@ -850,9 +861,9 @@ function createChatStore() {
|
|
|
850
861
|
stream: true
|
|
851
862
|
};
|
|
852
863
|
const extraParams = deepCopy(config.params.params || {});
|
|
853
|
-
Object.assign(extraParams, receiver.params,
|
|
864
|
+
Object.assign(extraParams, receiver.params, message2 ? {} : references?.params, params);
|
|
854
865
|
sendParams.params = JSON.stringify(extraParams);
|
|
855
|
-
if (!
|
|
866
|
+
if (!message2) {
|
|
856
867
|
setContent("");
|
|
857
868
|
setFileList([]);
|
|
858
869
|
setReferences();
|
|
@@ -898,15 +909,15 @@ function createChatStore() {
|
|
|
898
909
|
const messages = conversation.messages[msg.conversationId].message;
|
|
899
910
|
const idx = findMsgIndex(msg.conversationId, msg.id);
|
|
900
911
|
if (idx === -1) return;
|
|
901
|
-
const
|
|
912
|
+
const message2 = messages[idx];
|
|
902
913
|
conversation.messages[msg.conversationId].loading = true;
|
|
903
|
-
if (
|
|
914
|
+
if (message2?.type === "STEP_STARTED" || message2?.type === "TEXT_MESSAGE_START") {
|
|
904
915
|
messages[idx] = msg;
|
|
905
916
|
return;
|
|
906
917
|
}
|
|
907
918
|
messages[idx] = {
|
|
908
|
-
...
|
|
909
|
-
msgContent:
|
|
919
|
+
...message2,
|
|
920
|
+
msgContent: message2.msgContent + (msg.msgContent || "")
|
|
910
921
|
};
|
|
911
922
|
};
|
|
912
923
|
const endCallback = (msg) => {
|
|
@@ -946,35 +957,65 @@ function createChatStore() {
|
|
|
946
957
|
}
|
|
947
958
|
};
|
|
948
959
|
return {
|
|
960
|
+
/** 全局配置对象 */
|
|
949
961
|
config,
|
|
962
|
+
/** 设置服务配置 */
|
|
950
963
|
setServices,
|
|
964
|
+
/** 设置文件预览 */
|
|
951
965
|
setPreview,
|
|
966
|
+
/** 设置布局配置 */
|
|
952
967
|
setLayout,
|
|
968
|
+
/** 设置生命周期钩子 */
|
|
953
969
|
setHooks,
|
|
970
|
+
/** 设置聊天参数 */
|
|
954
971
|
setParams,
|
|
972
|
+
/** 设置用户信息 */
|
|
955
973
|
setUserInfo,
|
|
974
|
+
/** 智能体性格状态 */
|
|
956
975
|
character,
|
|
976
|
+
/** 获取性格列表 */
|
|
957
977
|
getCharacters,
|
|
978
|
+
/** 打开性格选择面板 */
|
|
958
979
|
openCharacterList,
|
|
980
|
+
/** 关闭性格选择面板 */
|
|
959
981
|
closeCharacterList,
|
|
982
|
+
/** 切换性格 */
|
|
960
983
|
switchCharacter,
|
|
984
|
+
/** 接收者状态 */
|
|
961
985
|
receiver,
|
|
986
|
+
/** 设置接收者参数 */
|
|
962
987
|
setReceiverParams,
|
|
988
|
+
/** 历史会话状态 */
|
|
963
989
|
conversations,
|
|
990
|
+
/** 获取会话列表 */
|
|
964
991
|
getConversations,
|
|
992
|
+
/** 删除会话 */
|
|
965
993
|
delConversation,
|
|
994
|
+
/** 当前会话状态 */
|
|
966
995
|
conversation,
|
|
996
|
+
/** 设置说话人类型 */
|
|
967
997
|
setSpeakHuman,
|
|
998
|
+
/** 设置引用消息 */
|
|
968
999
|
setReferences,
|
|
1000
|
+
/** 设置消息内容 */
|
|
969
1001
|
setContent,
|
|
1002
|
+
/** 设置文件列表 */
|
|
970
1003
|
setFileList,
|
|
1004
|
+
/** 设置头部展开状态 */
|
|
971
1005
|
setHeaderOpen,
|
|
1006
|
+
/** 消息反馈操作 */
|
|
972
1007
|
feedback,
|
|
1008
|
+
/** 切换智能体会话 */
|
|
973
1009
|
switchAgentConversation,
|
|
1010
|
+
/** 创建新会话 */
|
|
974
1011
|
createConversation,
|
|
1012
|
+
/** 切换会话 */
|
|
975
1013
|
switchConversation,
|
|
1014
|
+
/** 发送消息 */
|
|
976
1015
|
sendMessage,
|
|
1016
|
+
/** 取消接收 */
|
|
977
1017
|
cancelReceive,
|
|
1018
|
+
/** 接收消息 */
|
|
978
1019
|
acceptMessage
|
|
979
1020
|
};
|
|
980
1021
|
}
|
|
@@ -1000,17 +1041,17 @@ var styles_module_default2 = {
|
|
|
1000
1041
|
chatSender: "styles_module_chatSender",
|
|
1001
1042
|
chatQuoteMsg: "styles_module_chatQuoteMsg"
|
|
1002
1043
|
};
|
|
1003
|
-
var MessageRender_default = ({ message:
|
|
1004
|
-
return /* @__PURE__ */ jsx(Flex, { vertical: true, children: !(
|
|
1005
|
-
|
|
1044
|
+
var MessageRender_default = ({ message: message2, placement }) => {
|
|
1045
|
+
return /* @__PURE__ */ jsx(Flex, { vertical: true, children: !(message2.msgContent || message2.msgFiles.length) ? /* @__PURE__ */ jsx(Typography, { children: /* @__PURE__ */ jsx(Spin, { size: "small" }) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1046
|
+
message2.msgContent && /* @__PURE__ */ jsx(
|
|
1006
1047
|
Bubble,
|
|
1007
1048
|
{
|
|
1008
1049
|
placement,
|
|
1009
|
-
className:
|
|
1010
|
-
content: /* @__PURE__ */ jsx(RenderMarkdown, { content:
|
|
1050
|
+
className: classNames8({ [styles_module_default2.loadingMessage]: message2.type }),
|
|
1051
|
+
content: /* @__PURE__ */ jsx(RenderMarkdown, { content: replaceThinkTags(message2.msgContent), customComponents })
|
|
1011
1052
|
}
|
|
1012
1053
|
),
|
|
1013
|
-
|
|
1054
|
+
message2.msgFiles?.map((file) => /* @__PURE__ */ jsx(
|
|
1014
1055
|
Bubble,
|
|
1015
1056
|
{
|
|
1016
1057
|
className: "m-t-8",
|
|
@@ -1030,19 +1071,19 @@ var MessageRender_default = ({ message: message3, placement }) => {
|
|
|
1030
1071
|
},
|
|
1031
1072
|
file.content
|
|
1032
1073
|
)),
|
|
1033
|
-
|
|
1074
|
+
message2.quoteMsg?.id && /* @__PURE__ */ jsx(
|
|
1034
1075
|
Bubble,
|
|
1035
1076
|
{
|
|
1036
|
-
className:
|
|
1077
|
+
className: classNames8(styles_module_default2.chatQuoteMsg),
|
|
1037
1078
|
placement,
|
|
1038
1079
|
content: /* @__PURE__ */ jsxs(Flex, { vertical: true, gap: 8, children: [
|
|
1039
|
-
|
|
1080
|
+
message2.quoteMsg.msgContent && /* @__PURE__ */ jsxs(Flex, { children: [
|
|
1040
1081
|
/* @__PURE__ */ jsx("span", { children: "\u3010\u5F15\u7528\u6D88\u606F\u3011\uFF1A" }),
|
|
1041
|
-
/* @__PURE__ */ jsx(Flex, { flex: 1, className: "text-ellipsis", children:
|
|
1082
|
+
/* @__PURE__ */ jsx(Flex, { flex: 1, className: "text-ellipsis", children: message2.quoteMsg.msgContent })
|
|
1042
1083
|
] }),
|
|
1043
|
-
|
|
1084
|
+
message2.quoteMsg?.msgFiles && message2.quoteMsg.msgFiles.length > 0 && /* @__PURE__ */ jsxs(Flex, { children: [
|
|
1044
1085
|
/* @__PURE__ */ jsx("span", { children: "\u3010\u5F15\u7528\u6587\u4EF6\u3011\uFF1A" }),
|
|
1045
|
-
/* @__PURE__ */ jsx(Flex, { gap: 8, wrap: true, flex: 1, children:
|
|
1086
|
+
/* @__PURE__ */ jsx(Flex, { gap: 8, wrap: true, flex: 1, children: message2.quoteMsg.msgFiles.map((file) => /* @__PURE__ */ jsx(
|
|
1046
1087
|
Attachments.FileCard,
|
|
1047
1088
|
{
|
|
1048
1089
|
item: {
|
|
@@ -1068,7 +1109,6 @@ var MEMBER_TYPE = {
|
|
|
1068
1109
|
};
|
|
1069
1110
|
|
|
1070
1111
|
// src/ui/common/BubbleListItems.tsx
|
|
1071
|
-
init_utils();
|
|
1072
1112
|
init_Context();
|
|
1073
1113
|
|
|
1074
1114
|
// src/ui/common/styles.module.less
|
|
@@ -1094,73 +1134,7 @@ var styles_module_default3 = {
|
|
|
1094
1134
|
nsAvatarListItem: "styles_module_nsAvatarListItem",
|
|
1095
1135
|
nsAvatarListItemIcon: "styles_module_nsAvatarListItemIcon",
|
|
1096
1136
|
nsAvatarListItemIconActive: "styles_module_nsAvatarListItemIconActive",
|
|
1097
|
-
nsAvatarListItemName: "styles_module_nsAvatarListItemName"
|
|
1098
|
-
think: "styles_module_think2",
|
|
1099
|
-
loadingMessage: "styles_module_loadingMessage2"
|
|
1100
|
-
};
|
|
1101
|
-
function extractThinkContent(content) {
|
|
1102
|
-
let main = content;
|
|
1103
|
-
const thinkContents = [];
|
|
1104
|
-
let buffer = "";
|
|
1105
|
-
const regex = /<think>(.*?)<\/think>/gs;
|
|
1106
|
-
for (const match of content.matchAll(regex)) {
|
|
1107
|
-
const thinkText = match[1].trim();
|
|
1108
|
-
thinkContents.push(thinkText);
|
|
1109
|
-
main = main.replace(match[0], "");
|
|
1110
|
-
}
|
|
1111
|
-
const lastStart = content.lastIndexOf("<think>");
|
|
1112
|
-
const lastEnd = content.lastIndexOf("</think>");
|
|
1113
|
-
if (lastStart > lastEnd) {
|
|
1114
|
-
buffer = content.slice(lastStart).replace("<think>", "");
|
|
1115
|
-
main = main.slice(0, lastStart);
|
|
1116
|
-
}
|
|
1117
|
-
return { mainContent: main, thinkContents, thinkBuffer: buffer };
|
|
1118
|
-
}
|
|
1119
|
-
function renderMarkdownPanel(content, label, key) {
|
|
1120
|
-
return {
|
|
1121
|
-
key,
|
|
1122
|
-
label,
|
|
1123
|
-
children: /* @__PURE__ */ jsx(RenderMarkdown, { content, customComponents })
|
|
1124
|
-
};
|
|
1125
|
-
}
|
|
1126
|
-
var MessageAIRender_default = ({ message: message3, placement }) => {
|
|
1127
|
-
const { mainContent, thinkContents, thinkBuffer } = useMemo(() => {
|
|
1128
|
-
if (!message3?.msgContent) return { mainContent: "", thinkContents: [], thinkBuffer: "" };
|
|
1129
|
-
return extractThinkContent(message3.msgContent);
|
|
1130
|
-
}, [message3?.msgContent]);
|
|
1131
|
-
if (!message3.msgContent) {
|
|
1132
|
-
return /* @__PURE__ */ jsx(Typography, { children: /* @__PURE__ */ jsx(Spin, { size: "small" }) });
|
|
1133
|
-
}
|
|
1134
|
-
return /* @__PURE__ */ jsx(Flex, { vertical: true, children: /* @__PURE__ */ jsx(
|
|
1135
|
-
Bubble,
|
|
1136
|
-
{
|
|
1137
|
-
placement,
|
|
1138
|
-
className: classNames9({ [styles_module_default3.loadingMessage]: message3.type && message3.type !== "TEXT_MESSAGE_END" }),
|
|
1139
|
-
content: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1140
|
-
thinkContents.length > 0 && /* @__PURE__ */ jsx(
|
|
1141
|
-
Collapse,
|
|
1142
|
-
{
|
|
1143
|
-
ghost: true,
|
|
1144
|
-
size: "small",
|
|
1145
|
-
className: styles_module_default3.think,
|
|
1146
|
-
defaultActiveKey: thinkContents.map((_, i) => `think-${i}`),
|
|
1147
|
-
items: thinkContents.map((content, index) => renderMarkdownPanel(content, `\u601D\u8003\u8FC7\u7A0B`, `think-${index}`))
|
|
1148
|
-
}
|
|
1149
|
-
),
|
|
1150
|
-
thinkBuffer && /* @__PURE__ */ jsx(
|
|
1151
|
-
Collapse,
|
|
1152
|
-
{
|
|
1153
|
-
ghost: true,
|
|
1154
|
-
size: "small",
|
|
1155
|
-
className: styles_module_default3.think,
|
|
1156
|
-
defaultActiveKey: ["buffer-think"],
|
|
1157
|
-
items: [renderMarkdownPanel(thinkBuffer, "\u4ED4\u7EC6\u601D\u8003\u4E2D...", "buffer-think")]
|
|
1158
|
-
}
|
|
1159
|
-
),
|
|
1160
|
-
/* @__PURE__ */ jsx(RenderMarkdown, { content: mainContent, customComponents })
|
|
1161
|
-
] })
|
|
1162
|
-
}
|
|
1163
|
-
) });
|
|
1137
|
+
nsAvatarListItemName: "styles_module_nsAvatarListItemName"
|
|
1164
1138
|
};
|
|
1165
1139
|
var BubbleListItems_default = ({ firstMessage = false, avatar = { user: false, agent: true, other: true } }) => {
|
|
1166
1140
|
const chatStore = useChatStore();
|
|
@@ -1210,7 +1184,7 @@ var BubbleListItems_default = ({ firstMessage = false, avatar = { user: false, a
|
|
|
1210
1184
|
/* @__PURE__ */ jsx(
|
|
1211
1185
|
Welcome,
|
|
1212
1186
|
{
|
|
1213
|
-
className:
|
|
1187
|
+
className: classNames8(styles_module_default3.chatWelcome, "p-t-32"),
|
|
1214
1188
|
variant: "borderless",
|
|
1215
1189
|
icon: /* @__PURE__ */ jsx(Avatar, { shape: "square", size: 58, src: receiverState.active.logo }),
|
|
1216
1190
|
title: `\u4F60\u597D\uFF0C\u6211\u662F${receiverState.active.name || ""}`,
|
|
@@ -1228,7 +1202,7 @@ var BubbleListItems_default = ({ firstMessage = false, avatar = { user: false, a
|
|
|
1228
1202
|
label: "\u{1F914} \u63A8\u8350\u95EE\u9898:",
|
|
1229
1203
|
children: receiverState.active.config.recommendQuestions.map(({ question }) => ({
|
|
1230
1204
|
key: question,
|
|
1231
|
-
description: /* @__PURE__ */ jsx("span", { onClick: () => chatStore.sendMessage(question), className:
|
|
1205
|
+
description: /* @__PURE__ */ jsx("span", { onClick: () => chatStore.sendMessage(question), className: classNames8(styles_module_default3.chatWelcomePrompts, "text-ellipsis"), children: question })
|
|
1232
1206
|
}))
|
|
1233
1207
|
}
|
|
1234
1208
|
]
|
|
@@ -1267,37 +1241,36 @@ var BubbleListItems_default = ({ firstMessage = false, avatar = { user: false, a
|
|
|
1267
1241
|
[chatMessage?.questionList]
|
|
1268
1242
|
);
|
|
1269
1243
|
const chatRecords = useMemo(() => {
|
|
1270
|
-
return (chatMessage?.message || []).map((
|
|
1271
|
-
const role = conversationRoles[MEMBER_TYPE[
|
|
1244
|
+
return (chatMessage?.message || []).map((message2, index) => {
|
|
1245
|
+
const role = conversationRoles[MEMBER_TYPE[message2.sender.type]] || {};
|
|
1272
1246
|
return {
|
|
1273
|
-
key:
|
|
1247
|
+
key: message2.id,
|
|
1274
1248
|
placement: role.placement,
|
|
1275
1249
|
variant: "borderless",
|
|
1276
1250
|
avatar: role.avatar,
|
|
1277
|
-
|
|
1278
|
-
content: role.user === "agent" ? /* @__PURE__ */ jsx(MessageAIRender_default, { message: message3, placement: role.placement }) : /* @__PURE__ */ jsx(MessageRender_default, { message: message3, placement: role.placement }),
|
|
1251
|
+
content: /* @__PURE__ */ jsx(MessageRender_default, { message: message2, placement: role.placement }),
|
|
1279
1252
|
footer: role.user === "agent" && /* @__PURE__ */ jsxs(Flex, { children: [
|
|
1280
|
-
/* @__PURE__ */ jsx(Button, { onClick: () =>
|
|
1253
|
+
/* @__PURE__ */ jsx(Button, { onClick: () => copyText(message2.msgContent), color: "default", variant: "text", size: "small", icon: /* @__PURE__ */ jsx(CopyOutlined, {}) }),
|
|
1281
1254
|
/* @__PURE__ */ jsx(
|
|
1282
1255
|
Button,
|
|
1283
1256
|
{
|
|
1284
|
-
color:
|
|
1285
|
-
disabled: !!
|
|
1257
|
+
color: message2.msgFeedback === 1 ? "primary" : "default",
|
|
1258
|
+
disabled: !!message2.type,
|
|
1286
1259
|
size: "small",
|
|
1287
1260
|
variant: "text",
|
|
1288
1261
|
icon: /* @__PURE__ */ jsx(LikeOutlined, {}),
|
|
1289
|
-
onClick: () => chatStore.feedback(conversationState.active.id,
|
|
1262
|
+
onClick: () => chatStore.feedback(conversationState.active.id, message2.id, 1, index)
|
|
1290
1263
|
}
|
|
1291
1264
|
),
|
|
1292
1265
|
/* @__PURE__ */ jsx(
|
|
1293
1266
|
Button,
|
|
1294
1267
|
{
|
|
1295
|
-
color:
|
|
1296
|
-
disabled: !!
|
|
1268
|
+
color: message2.msgFeedback === 2 ? "primary" : "default",
|
|
1269
|
+
disabled: !!message2.type,
|
|
1297
1270
|
size: "small",
|
|
1298
1271
|
variant: "text",
|
|
1299
1272
|
icon: /* @__PURE__ */ jsx(DislikeOutlined, {}),
|
|
1300
|
-
onClick: () => chatStore.feedback(conversationState.active.id,
|
|
1273
|
+
onClick: () => chatStore.feedback(conversationState.active.id, message2.id, 2, index)
|
|
1301
1274
|
}
|
|
1302
1275
|
)
|
|
1303
1276
|
] })
|
|
@@ -1336,7 +1309,7 @@ var BubbleListItems_default = ({ firstMessage = false, avatar = { user: false, a
|
|
|
1336
1309
|
const handleScroll = (el) => {
|
|
1337
1310
|
const target = el.target;
|
|
1338
1311
|
const distanceToBottom = target.scrollHeight - target.scrollTop - target.clientHeight;
|
|
1339
|
-
autoScrollRef.current = distanceToBottom <
|
|
1312
|
+
autoScrollRef.current = distanceToBottom < 150;
|
|
1340
1313
|
};
|
|
1341
1314
|
useEffect(() => {
|
|
1342
1315
|
autoScrollRef.current = true;
|
|
@@ -1361,7 +1334,7 @@ var BubbleListItems_default = ({ firstMessage = false, avatar = { user: false, a
|
|
|
1361
1334
|
autoScroll: false,
|
|
1362
1335
|
ref: listRef,
|
|
1363
1336
|
items: bubbleListItems,
|
|
1364
|
-
className:
|
|
1337
|
+
className: classNames8(styles_module_default3.nsBubbleList, "height-full", "scroll-fade-in", "zero-chat-bubbles"),
|
|
1365
1338
|
onScroll: handleScroll
|
|
1366
1339
|
},
|
|
1367
1340
|
conversationState.active.id
|
|
@@ -1396,7 +1369,7 @@ var CharacterList_default = () => {
|
|
|
1396
1369
|
/* @__PURE__ */ jsx(
|
|
1397
1370
|
Avatar,
|
|
1398
1371
|
{
|
|
1399
|
-
className:
|
|
1372
|
+
className: classNames8(styles_module_default3.nsAvatarListItemIcon, "cursor-pointer", {
|
|
1400
1373
|
[styles_module_default3.nsAvatarListItemIconActive]: activeCharacter.id === item.id
|
|
1401
1374
|
}),
|
|
1402
1375
|
size: 50,
|
|
@@ -1491,7 +1464,7 @@ var ChatHeader_default = ({
|
|
|
1491
1464
|
const chatStore = useChatStore();
|
|
1492
1465
|
const receiverState = useSnapshot(chatStore.receiver);
|
|
1493
1466
|
const configState = useSnapshot(chatStore.config);
|
|
1494
|
-
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(Flex, { justify: "space-between", align: "center", className:
|
|
1467
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(Flex, { justify: "space-between", align: "center", className: classNames8(styles_module_default3.nsChatHeader, "zero-chat-header"), children: [
|
|
1495
1468
|
/* @__PURE__ */ jsxs(Flex, { gap: 4, align: "center", children: [
|
|
1496
1469
|
/* @__PURE__ */ jsx(
|
|
1497
1470
|
RenderWrapper,
|
|
@@ -1542,7 +1515,7 @@ var ChatHeader_default = ({
|
|
|
1542
1515
|
] }) });
|
|
1543
1516
|
};
|
|
1544
1517
|
var Attachments_default = forwardRef(({ fileUpload, fileUploadConfig = [], fileList = [], onChange, extraParams }, ref) => {
|
|
1545
|
-
const { message:
|
|
1518
|
+
const { message: message2 } = App.useApp();
|
|
1546
1519
|
const fileListRef = useRef([]);
|
|
1547
1520
|
const [attachedFiles, setAttachedFiles, getAttachedFiles] = useRefState([]);
|
|
1548
1521
|
useEffect(() => {
|
|
@@ -1570,7 +1543,7 @@ var Attachments_default = forwardRef(({ fileUpload, fileUploadConfig = [], fileL
|
|
|
1570
1543
|
onChange(files);
|
|
1571
1544
|
}, [attachedFiles]);
|
|
1572
1545
|
const onErrorTip = useDebounce((errorMsg) => {
|
|
1573
|
-
|
|
1546
|
+
message2.error(errorMsg);
|
|
1574
1547
|
}, 300);
|
|
1575
1548
|
const findConfigByFile = (file) => {
|
|
1576
1549
|
return fileUploadConfig.find((cfg) => cfg.allowedFileTypes?.includes(getFileSuffixName(file.name).toLocaleUpperCase()));
|
|
@@ -1801,7 +1774,7 @@ var SenderPromptsItems_default = () => {
|
|
|
1801
1774
|
title: /* @__PURE__ */ jsx(
|
|
1802
1775
|
"div",
|
|
1803
1776
|
{
|
|
1804
|
-
className:
|
|
1777
|
+
className: classNames8(styles_module_default3.nsSenderListTitle, "text-ellipsis"),
|
|
1805
1778
|
children: `${receiverState.active.name}\u5F00\u59CB\u5173\u6CE8${question.name}\u5185\u5BB9\uFF01`
|
|
1806
1779
|
}
|
|
1807
1780
|
),
|
|
@@ -1930,7 +1903,7 @@ var ConversationListHeader_default = () => {
|
|
|
1930
1903
|
type: "primary",
|
|
1931
1904
|
shape: "round",
|
|
1932
1905
|
onClick: () => chatStore.createConversation(),
|
|
1933
|
-
className:
|
|
1906
|
+
className: classNames8("m-t-16"),
|
|
1934
1907
|
icon: /* @__PURE__ */ jsx(PlusOutlined, {}),
|
|
1935
1908
|
children: "\u65B0\u5EFA\u4F1A\u8BDD"
|
|
1936
1909
|
}
|
|
@@ -1938,7 +1911,7 @@ var ConversationListHeader_default = () => {
|
|
|
1938
1911
|
] });
|
|
1939
1912
|
};
|
|
1940
1913
|
var ConversationListPanel_default = ({ header }) => {
|
|
1941
|
-
return /* @__PURE__ */ jsxs(Flex, { vertical: true, className:
|
|
1914
|
+
return /* @__PURE__ */ jsxs(Flex, { vertical: true, className: classNames8("height-full", "zero-chat-conversations", styles_module_default3.nsConversationListPanel), children: [
|
|
1942
1915
|
/* @__PURE__ */ jsx(RenderWrapper, { control: header, DefaultComponent: ConversationListHeader_default }),
|
|
1943
1916
|
/* @__PURE__ */ jsx("div", { className: "full-scroll", children: /* @__PURE__ */ jsx(ConversationList_default, {}) })
|
|
1944
1917
|
] });
|
|
@@ -2036,7 +2009,7 @@ var layouts_default = forwardRef(({ theme, params, userInfo, hooks, layout, conf
|
|
|
2036
2009
|
useEffect(() => {
|
|
2037
2010
|
configState.hooks?.onBeforeInit?.();
|
|
2038
2011
|
}, []);
|
|
2039
|
-
return /* @__PURE__ */ jsx(XProvider, { theme: { cssVar: true, ...theme }, children: /* @__PURE__ */ jsx(ChatProvider, { store: chatStore, children: /* @__PURE__ */ jsx(Spin, { spinning: receiverState.loading, wrapperClassName: "full-spin", children: /* @__PURE__ */ jsxs(Flex, { vertical: true, className:
|
|
2012
|
+
return /* @__PURE__ */ jsx(XProvider, { theme: { cssVar: true, ...theme }, children: /* @__PURE__ */ jsx(ChatProvider, { store: chatStore, children: /* @__PURE__ */ jsx(Spin, { spinning: receiverState.loading, wrapperClassName: "full-spin", children: /* @__PURE__ */ jsxs(Flex, { vertical: true, className: classNames8(styles_module_default4.nsChatLayout, "zero-chat-layout", "height-full"), children: [
|
|
2040
2013
|
/* @__PURE__ */ jsx(RenderWrapper, { control: configState.layout.globalHeader, DefaultComponent: ChatHeader_default }),
|
|
2041
2014
|
/* @__PURE__ */ jsxs(Flex, { className: "full-scroll", children: [
|
|
2042
2015
|
/* @__PURE__ */ jsx(RenderWrapper, { control: configState.layout.leftPanel }),
|
|
@@ -2090,15 +2063,15 @@ var layouts_default = forwardRef(({ theme, params, userInfo, hooks, layout, conf
|
|
|
2090
2063
|
}
|
|
2091
2064
|
)
|
|
2092
2065
|
] }) }),
|
|
2093
|
-
/* @__PURE__ */ jsx(Splitter.Panel, { collapsible: false, max: 800, min: 400, size: sizes[1], children: /* @__PURE__ */ jsxs(Flex, { vertical: true, className:
|
|
2066
|
+
/* @__PURE__ */ jsx(Splitter.Panel, { collapsible: false, max: 800, min: 400, size: sizes[1], children: /* @__PURE__ */ jsxs(Flex, { vertical: true, className: classNames8("height-full"), children: [
|
|
2094
2067
|
/* @__PURE__ */ jsx(RenderWrapper, { control: configState.layout.chatHeader, DefaultComponent: ChatHeader_default }),
|
|
2095
|
-
/* @__PURE__ */ jsx(Flex, { vertical: true, className:
|
|
2068
|
+
/* @__PURE__ */ jsx(Flex, { vertical: true, className: classNames8("full-scroll"), children: /* @__PURE__ */ jsxs(
|
|
2096
2069
|
Flex,
|
|
2097
2070
|
{
|
|
2098
2071
|
justify: "center",
|
|
2099
2072
|
vertical: true,
|
|
2100
2073
|
gap: 24,
|
|
2101
|
-
className:
|
|
2074
|
+
className: classNames8("height-full", styles_module_default4.nsChatBody, "zero-chat-body", styles_module_default4.nsBodyWidth),
|
|
2102
2075
|
children: [
|
|
2103
2076
|
shouldRender(configState.layout.messageList) && /* @__PURE__ */ jsx("div", { className: "full-scroll", children: /* @__PURE__ */ jsx(RenderWrapper, { control: configState.layout.messageList, DefaultComponent: BubbleListItems_default }) }),
|
|
2104
2077
|
/* @__PURE__ */ jsxs(Flex, { vertical: true, gap: 8, children: [
|