@zero-library/chat-agent 2.1.18 → 2.1.19
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 +26 -87
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.css +0 -24
- package/dist/index.css.map +1 -1
- package/dist/index.esm.js +26 -87
- package/dist/index.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs.js
CHANGED
|
@@ -8,13 +8,13 @@ var react = require('react');
|
|
|
8
8
|
var valtio = require('valtio');
|
|
9
9
|
var icons = require('@ant-design/icons');
|
|
10
10
|
var x = require('@ant-design/x');
|
|
11
|
-
var
|
|
11
|
+
var classNames8 = require('classnames');
|
|
12
12
|
var InfiniteScroll = require('react-infinite-scroll-component');
|
|
13
13
|
|
|
14
14
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
15
|
|
|
16
16
|
var dayjs__default = /*#__PURE__*/_interopDefault(dayjs);
|
|
17
|
-
var
|
|
17
|
+
var classNames8__default = /*#__PURE__*/_interopDefault(classNames8);
|
|
18
18
|
var InfiniteScroll__default = /*#__PURE__*/_interopDefault(InfiniteScroll);
|
|
19
19
|
|
|
20
20
|
var __defProp = Object.defineProperty;
|
|
@@ -26,7 +26,7 @@ var __export = (target, all) => {
|
|
|
26
26
|
for (var name in all)
|
|
27
27
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
28
28
|
};
|
|
29
|
-
var classifyTime, copy;
|
|
29
|
+
var classifyTime, replaceThinkTags, copy;
|
|
30
30
|
var init_utils = __esm({
|
|
31
31
|
"src/core/utils.ts"() {
|
|
32
32
|
classifyTime = (timestamp) => {
|
|
@@ -46,6 +46,9 @@ var init_utils = __esm({
|
|
|
46
46
|
return "\u66F4\u65E9";
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
+
replaceThinkTags = (str) => {
|
|
50
|
+
return str.replace(/<think>/g, ":::alert type=think data={content:'").replace(/<\/think>/g, "'} ::: ");
|
|
51
|
+
};
|
|
49
52
|
copy = (value) => {
|
|
50
53
|
common.copyText(value).then(() => {
|
|
51
54
|
antd.message.success("\u590D\u5236\u6210\u529F");
|
|
@@ -989,6 +992,9 @@ function createChatStore() {
|
|
|
989
992
|
// src/ui/layouts/index.tsx
|
|
990
993
|
init_Context();
|
|
991
994
|
|
|
995
|
+
// src/components/MessageRender.tsx
|
|
996
|
+
init_utils();
|
|
997
|
+
|
|
992
998
|
// src/ui/common/markdownAlert/index.ts
|
|
993
999
|
var customComponents = {
|
|
994
1000
|
appCard: () => Promise.resolve().then(() => (init_AppCard(), AppCard_exports)),
|
|
@@ -1013,8 +1019,8 @@ var MessageRender_default = ({ message: message3, placement }) => {
|
|
|
1013
1019
|
x.Bubble,
|
|
1014
1020
|
{
|
|
1015
1021
|
placement,
|
|
1016
|
-
className:
|
|
1017
|
-
content: /* @__PURE__ */ jsxRuntime.jsx(common.RenderMarkdown, { content: message3.msgContent, customComponents })
|
|
1022
|
+
className: classNames8__default.default({ [styles_module_default2.loadingMessage]: message3.type }),
|
|
1023
|
+
content: /* @__PURE__ */ jsxRuntime.jsx(common.RenderMarkdown, { content: replaceThinkTags(message3.msgContent), customComponents })
|
|
1018
1024
|
}
|
|
1019
1025
|
),
|
|
1020
1026
|
message3.msgFiles?.map((file) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1040,7 +1046,7 @@ var MessageRender_default = ({ message: message3, placement }) => {
|
|
|
1040
1046
|
message3.quoteMsg?.id && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1041
1047
|
x.Bubble,
|
|
1042
1048
|
{
|
|
1043
|
-
className:
|
|
1049
|
+
className: classNames8__default.default(styles_module_default2.chatQuoteMsg),
|
|
1044
1050
|
placement,
|
|
1045
1051
|
content: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, gap: 8, children: [
|
|
1046
1052
|
message3.quoteMsg.msgContent && /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { children: [
|
|
@@ -1101,73 +1107,7 @@ var styles_module_default3 = {
|
|
|
1101
1107
|
nsAvatarListItem: "styles_module_nsAvatarListItem",
|
|
1102
1108
|
nsAvatarListItemIcon: "styles_module_nsAvatarListItemIcon",
|
|
1103
1109
|
nsAvatarListItemIconActive: "styles_module_nsAvatarListItemIconActive",
|
|
1104
|
-
nsAvatarListItemName: "styles_module_nsAvatarListItemName"
|
|
1105
|
-
think: "styles_module_think2",
|
|
1106
|
-
loadingMessage: "styles_module_loadingMessage2"
|
|
1107
|
-
};
|
|
1108
|
-
function extractThinkContent(content) {
|
|
1109
|
-
let main = content;
|
|
1110
|
-
const thinkContents = [];
|
|
1111
|
-
let buffer = "";
|
|
1112
|
-
const regex = /<think>(.*?)<\/think>/gs;
|
|
1113
|
-
for (const match of content.matchAll(regex)) {
|
|
1114
|
-
const thinkText = match[1].trim();
|
|
1115
|
-
thinkContents.push(thinkText);
|
|
1116
|
-
main = main.replace(match[0], "");
|
|
1117
|
-
}
|
|
1118
|
-
const lastStart = content.lastIndexOf("<think>");
|
|
1119
|
-
const lastEnd = content.lastIndexOf("</think>");
|
|
1120
|
-
if (lastStart > lastEnd) {
|
|
1121
|
-
buffer = content.slice(lastStart).replace("<think>", "");
|
|
1122
|
-
main = main.slice(0, lastStart);
|
|
1123
|
-
}
|
|
1124
|
-
return { mainContent: main, thinkContents, thinkBuffer: buffer };
|
|
1125
|
-
}
|
|
1126
|
-
function renderMarkdownPanel(content, label, key) {
|
|
1127
|
-
return {
|
|
1128
|
-
key,
|
|
1129
|
-
label,
|
|
1130
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(common.RenderMarkdown, { content, customComponents })
|
|
1131
|
-
};
|
|
1132
|
-
}
|
|
1133
|
-
var MessageAIRender_default = ({ message: message3, placement }) => {
|
|
1134
|
-
const { mainContent, thinkContents, thinkBuffer } = react.useMemo(() => {
|
|
1135
|
-
if (!message3?.msgContent) return { mainContent: "", thinkContents: [], thinkBuffer: "" };
|
|
1136
|
-
return extractThinkContent(message3.msgContent);
|
|
1137
|
-
}, [message3?.msgContent]);
|
|
1138
|
-
if (!message3.msgContent) {
|
|
1139
|
-
return /* @__PURE__ */ jsxRuntime.jsx(antd.Typography, { children: /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { size: "small" }) });
|
|
1140
|
-
}
|
|
1141
|
-
return /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { vertical: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1142
|
-
x.Bubble,
|
|
1143
|
-
{
|
|
1144
|
-
placement,
|
|
1145
|
-
className: classNames9__default.default({ [styles_module_default3.loadingMessage]: message3.type && message3.type !== "TEXT_MESSAGE_END" }),
|
|
1146
|
-
content: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1147
|
-
thinkContents.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1148
|
-
antd.Collapse,
|
|
1149
|
-
{
|
|
1150
|
-
ghost: true,
|
|
1151
|
-
size: "small",
|
|
1152
|
-
className: styles_module_default3.think,
|
|
1153
|
-
defaultActiveKey: thinkContents.map((_, i) => `think-${i}`),
|
|
1154
|
-
items: thinkContents.map((content, index) => renderMarkdownPanel(content, `\u601D\u8003\u8FC7\u7A0B`, `think-${index}`))
|
|
1155
|
-
}
|
|
1156
|
-
),
|
|
1157
|
-
thinkBuffer && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1158
|
-
antd.Collapse,
|
|
1159
|
-
{
|
|
1160
|
-
ghost: true,
|
|
1161
|
-
size: "small",
|
|
1162
|
-
className: styles_module_default3.think,
|
|
1163
|
-
defaultActiveKey: ["buffer-think"],
|
|
1164
|
-
items: [renderMarkdownPanel(thinkBuffer, "\u4ED4\u7EC6\u601D\u8003\u4E2D...", "buffer-think")]
|
|
1165
|
-
}
|
|
1166
|
-
),
|
|
1167
|
-
/* @__PURE__ */ jsxRuntime.jsx(common.RenderMarkdown, { content: mainContent, customComponents })
|
|
1168
|
-
] })
|
|
1169
|
-
}
|
|
1170
|
-
) });
|
|
1110
|
+
nsAvatarListItemName: "styles_module_nsAvatarListItemName"
|
|
1171
1111
|
};
|
|
1172
1112
|
var BubbleListItems_default = ({ firstMessage = false, avatar = { user: false, agent: true, other: true } }) => {
|
|
1173
1113
|
const chatStore = useChatStore();
|
|
@@ -1217,7 +1157,7 @@ var BubbleListItems_default = ({ firstMessage = false, avatar = { user: false, a
|
|
|
1217
1157
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1218
1158
|
x.Welcome,
|
|
1219
1159
|
{
|
|
1220
|
-
className:
|
|
1160
|
+
className: classNames8__default.default(styles_module_default3.chatWelcome, "p-t-32"),
|
|
1221
1161
|
variant: "borderless",
|
|
1222
1162
|
icon: /* @__PURE__ */ jsxRuntime.jsx(antd.Avatar, { shape: "square", size: 58, src: receiverState.active.logo }),
|
|
1223
1163
|
title: `\u4F60\u597D\uFF0C\u6211\u662F${receiverState.active.name || ""}`,
|
|
@@ -1235,7 +1175,7 @@ var BubbleListItems_default = ({ firstMessage = false, avatar = { user: false, a
|
|
|
1235
1175
|
label: "\u{1F914} \u63A8\u8350\u95EE\u9898:",
|
|
1236
1176
|
children: receiverState.active.config.recommendQuestions.map(({ question }) => ({
|
|
1237
1177
|
key: question,
|
|
1238
|
-
description: /* @__PURE__ */ jsxRuntime.jsx("span", { onClick: () => chatStore.sendMessage(question), className:
|
|
1178
|
+
description: /* @__PURE__ */ jsxRuntime.jsx("span", { onClick: () => chatStore.sendMessage(question), className: classNames8__default.default(styles_module_default3.chatWelcomePrompts, "text-ellipsis"), children: question })
|
|
1239
1179
|
}))
|
|
1240
1180
|
}
|
|
1241
1181
|
]
|
|
@@ -1281,8 +1221,7 @@ var BubbleListItems_default = ({ firstMessage = false, avatar = { user: false, a
|
|
|
1281
1221
|
placement: role.placement,
|
|
1282
1222
|
variant: "borderless",
|
|
1283
1223
|
avatar: role.avatar,
|
|
1284
|
-
|
|
1285
|
-
content: role.user === "agent" ? /* @__PURE__ */ jsxRuntime.jsx(MessageAIRender_default, { message: message3, placement: role.placement }) : /* @__PURE__ */ jsxRuntime.jsx(MessageRender_default, { message: message3, placement: role.placement }),
|
|
1224
|
+
content: /* @__PURE__ */ jsxRuntime.jsx(MessageRender_default, { message: message3, placement: role.placement }),
|
|
1286
1225
|
footer: role.user === "agent" && /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { children: [
|
|
1287
1226
|
/* @__PURE__ */ jsxRuntime.jsx(antd.Button, { onClick: () => copy(message3.msgContent), color: "default", variant: "text", size: "small", icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CopyOutlined, {}) }),
|
|
1288
1227
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1368,7 +1307,7 @@ var BubbleListItems_default = ({ firstMessage = false, avatar = { user: false, a
|
|
|
1368
1307
|
autoScroll: false,
|
|
1369
1308
|
ref: listRef,
|
|
1370
1309
|
items: bubbleListItems,
|
|
1371
|
-
className:
|
|
1310
|
+
className: classNames8__default.default(styles_module_default3.nsBubbleList, "height-full", "scroll-fade-in", "zero-chat-bubbles"),
|
|
1372
1311
|
onScroll: handleScroll
|
|
1373
1312
|
},
|
|
1374
1313
|
conversationState.active.id
|
|
@@ -1403,7 +1342,7 @@ var CharacterList_default = () => {
|
|
|
1403
1342
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1404
1343
|
antd.Avatar,
|
|
1405
1344
|
{
|
|
1406
|
-
className:
|
|
1345
|
+
className: classNames8__default.default(styles_module_default3.nsAvatarListItemIcon, "cursor-pointer", {
|
|
1407
1346
|
[styles_module_default3.nsAvatarListItemIconActive]: activeCharacter.id === item.id
|
|
1408
1347
|
}),
|
|
1409
1348
|
size: 50,
|
|
@@ -1498,7 +1437,7 @@ var ChatHeader_default = ({
|
|
|
1498
1437
|
const chatStore = useChatStore();
|
|
1499
1438
|
const receiverState = valtio.useSnapshot(chatStore.receiver);
|
|
1500
1439
|
const configState = valtio.useSnapshot(chatStore.config);
|
|
1501
|
-
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { justify: "space-between", align: "center", className:
|
|
1440
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { justify: "space-between", align: "center", className: classNames8__default.default(styles_module_default3.nsChatHeader, "zero-chat-header"), children: [
|
|
1502
1441
|
/* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { gap: 4, align: "center", children: [
|
|
1503
1442
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1504
1443
|
common.RenderWrapper,
|
|
@@ -1808,7 +1747,7 @@ var SenderPromptsItems_default = () => {
|
|
|
1808
1747
|
title: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1809
1748
|
"div",
|
|
1810
1749
|
{
|
|
1811
|
-
className:
|
|
1750
|
+
className: classNames8__default.default(styles_module_default3.nsSenderListTitle, "text-ellipsis"),
|
|
1812
1751
|
children: `${receiverState.active.name}\u5F00\u59CB\u5173\u6CE8${question.name}\u5185\u5BB9\uFF01`
|
|
1813
1752
|
}
|
|
1814
1753
|
),
|
|
@@ -1937,7 +1876,7 @@ var ConversationListHeader_default = () => {
|
|
|
1937
1876
|
type: "primary",
|
|
1938
1877
|
shape: "round",
|
|
1939
1878
|
onClick: () => chatStore.createConversation(),
|
|
1940
|
-
className:
|
|
1879
|
+
className: classNames8__default.default("m-t-16"),
|
|
1941
1880
|
icon: /* @__PURE__ */ jsxRuntime.jsx(icons.PlusOutlined, {}),
|
|
1942
1881
|
children: "\u65B0\u5EFA\u4F1A\u8BDD"
|
|
1943
1882
|
}
|
|
@@ -1945,7 +1884,7 @@ var ConversationListHeader_default = () => {
|
|
|
1945
1884
|
] });
|
|
1946
1885
|
};
|
|
1947
1886
|
var ConversationListPanel_default = ({ header }) => {
|
|
1948
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, className:
|
|
1887
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, className: classNames8__default.default("height-full", "zero-chat-conversations", styles_module_default3.nsConversationListPanel), children: [
|
|
1949
1888
|
/* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: header, DefaultComponent: ConversationListHeader_default }),
|
|
1950
1889
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "full-scroll", children: /* @__PURE__ */ jsxRuntime.jsx(ConversationList_default, {}) })
|
|
1951
1890
|
] });
|
|
@@ -2043,7 +1982,7 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
|
|
|
2043
1982
|
react.useEffect(() => {
|
|
2044
1983
|
configState.hooks?.onBeforeInit?.();
|
|
2045
1984
|
}, []);
|
|
2046
|
-
return /* @__PURE__ */ jsxRuntime.jsx(x.XProvider, { theme: { cssVar: true, ...theme }, children: /* @__PURE__ */ jsxRuntime.jsx(ChatProvider, { store: chatStore, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { spinning: receiverState.loading, wrapperClassName: "full-spin", children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, className:
|
|
1985
|
+
return /* @__PURE__ */ jsxRuntime.jsx(x.XProvider, { theme: { cssVar: true, ...theme }, children: /* @__PURE__ */ jsxRuntime.jsx(ChatProvider, { store: chatStore, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { spinning: receiverState.loading, wrapperClassName: "full-spin", children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, className: classNames8__default.default(styles_module_default4.nsChatLayout, "zero-chat-layout", "height-full"), children: [
|
|
2047
1986
|
/* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.globalHeader, DefaultComponent: ChatHeader_default }),
|
|
2048
1987
|
/* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { className: "full-scroll", children: [
|
|
2049
1988
|
/* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.leftPanel }),
|
|
@@ -2097,15 +2036,15 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
|
|
|
2097
2036
|
}
|
|
2098
2037
|
)
|
|
2099
2038
|
] }) }),
|
|
2100
|
-
/* @__PURE__ */ jsxRuntime.jsx(antd.Splitter.Panel, { collapsible: false, max: 800, min: 400, size: sizes[1], children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, className:
|
|
2039
|
+
/* @__PURE__ */ jsxRuntime.jsx(antd.Splitter.Panel, { collapsible: false, max: 800, min: 400, size: sizes[1], children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, className: classNames8__default.default("height-full"), children: [
|
|
2101
2040
|
/* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.chatHeader, DefaultComponent: ChatHeader_default }),
|
|
2102
|
-
/* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { vertical: true, className:
|
|
2041
|
+
/* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { vertical: true, className: classNames8__default.default("full-scroll"), children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2103
2042
|
antd.Flex,
|
|
2104
2043
|
{
|
|
2105
2044
|
justify: "center",
|
|
2106
2045
|
vertical: true,
|
|
2107
2046
|
gap: 24,
|
|
2108
|
-
className:
|
|
2047
|
+
className: classNames8__default.default("height-full", styles_module_default4.nsChatBody, "zero-chat-body", styles_module_default4.nsBodyWidth),
|
|
2109
2048
|
children: [
|
|
2110
2049
|
common.shouldRender(configState.layout.messageList) && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "full-scroll", children: /* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.messageList, DefaultComponent: BubbleListItems_default }) }),
|
|
2111
2050
|
/* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, gap: 8, children: [
|