@zero-library/chat-agent 2.2.7 → 2.2.9

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 CHANGED
@@ -281,7 +281,7 @@ var classifyTime = (timestamp) => {
281
281
  return "\u66F4\u65E9";
282
282
  }
283
283
  };
284
- var replaceThinkTags = (str) => {
284
+ var replaceMarkdownTags = (str) => {
285
285
  return str.replace(/<think>/g, ":::alert type=think data={content:'").replace(/<\/think>/g, "'} :::");
286
286
  };
287
287
  var getChatSocketUrl = (baseURL, params) => {
@@ -468,8 +468,13 @@ function createChatStore() {
468
468
  config.services.websocketUrls = [url, ""];
469
469
  }
470
470
  };
471
- const setPreview = (file = {}, isEdit = false) => {
472
- if (common.shouldRender(config.layout.preview)) {
471
+ const setPreview = async (file = {}, isEdit = false) => {
472
+ const preview = common.shouldRender(config.layout.preview);
473
+ const canProceed = await config.hooks?.onBeforeFilePreview?.(file, preview);
474
+ if (canProceed === false) {
475
+ throw new Error("\u64CD\u4F5C\u88AB\u963B\u6B62");
476
+ }
477
+ if (preview) {
473
478
  config.preview = {
474
479
  file,
475
480
  isEdit
@@ -477,10 +482,11 @@ function createChatStore() {
477
482
  } else {
478
483
  if (file?.fileUrl) {
479
484
  window.open(file.fileUrl, "_blank");
480
- } else {
485
+ } else if (file?.content) {
481
486
  console.log("\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301\u9884\u89C8");
482
487
  }
483
488
  }
489
+ config.hooks?.onAfterFilePreview?.(file, preview);
484
490
  };
485
491
  const setLayout = (layout, receiverType = 3) => {
486
492
  const defaultLayout = receiverType === 3 ? defaultAgentLayout : defaultExpertLayout;
@@ -799,7 +805,7 @@ function createChatStore() {
799
805
  throw new Error("\u64CD\u4F5C\u88AB\u963B\u6B62");
800
806
  }
801
807
  await initConversation(conversationId);
802
- setPreview();
808
+ await setPreview();
803
809
  config.hooks?.onAfterSwitchConversation?.(conversationId);
804
810
  try {
805
811
  if (conversation.active.member.agent) {
@@ -1081,28 +1087,50 @@ var styles_module_default2 = {
1081
1087
  loadingMessage: "styles_module_loadingMessage",
1082
1088
  chatAttachments: "styles_module_chatAttachments",
1083
1089
  chatSender: "styles_module_chatSender",
1084
- chatQuoteMsg: "styles_module_chatQuoteMsg"
1090
+ chatQuoteMsg: "styles_module_chatQuoteMsg",
1091
+ quoteTooltip: "styles_module_quoteTooltip",
1092
+ quoteTooltipContainer: "styles_module_quoteTooltipContainer"
1085
1093
  };
1086
- var MessageRender_default = ({ message: message2, placement }) => {
1087
- const content = react.useMemo(
1094
+ var MessageRender_default = ({ message: message2, placement, onFilePreview }) => {
1095
+ const msgContent = react.useMemo(
1088
1096
  () => `${message2.msgContent || ""}${message2.msgContent && message2.tempContent ? "\n\n" : ""}${message2.tempContent || ""}`,
1089
1097
  [message2.msgContent, message2.tempContent]
1090
1098
  );
1091
- const paramsCitation = react.useMemo(() => {
1092
- let citation = "";
1093
- try {
1094
- citation = JSON.parse(message2.params || "{}").citation || "";
1095
- } catch (e) {
1099
+ const quoteMsg = react.useMemo(() => {
1100
+ const quoteMsg2 = {};
1101
+ if (message2.quoteMsg?.id) {
1102
+ if (message2.quoteMsg.msgContent) {
1103
+ quoteMsg2.msgContent = message2.quoteMsg.msgContent;
1104
+ }
1105
+ if (message2.quoteMsg.msgFiles?.length) {
1106
+ quoteMsg2.msgFiles = message2.quoteMsg.msgFiles;
1107
+ }
1108
+ } else if (message2.params) {
1109
+ try {
1110
+ const citation = JSON.parse(message2.params).citation;
1111
+ if (citation) {
1112
+ quoteMsg2.msgContent = citation;
1113
+ }
1114
+ } catch (e) {
1115
+ }
1116
+ }
1117
+ if (quoteMsg2.msgContent) {
1118
+ quoteMsg2.msgContentText = common.markdownToText(quoteMsg2.msgContent);
1096
1119
  }
1097
- return citation;
1098
- }, [message2.params]);
1099
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { vertical: true, children: !(message2.msgContent || message2.tempContent || message2.msgFiles.length) ? /* @__PURE__ */ jsxRuntime.jsx(antd.Typography, { children: /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { size: "small" }) }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1100
- content && /* @__PURE__ */ jsxRuntime.jsx(
1120
+ return common.isEmptyObj(quoteMsg2) ? null : quoteMsg2;
1121
+ }, [message2.params, message2.quoteMsg]);
1122
+ const filePreview = (file) => {
1123
+ if (file.content && !["image"].includes(file.type)) {
1124
+ onFilePreview?.(file);
1125
+ }
1126
+ };
1127
+ return /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { vertical: true, children: !(msgContent || message2.msgFiles.length) ? /* @__PURE__ */ jsxRuntime.jsx(antd.Typography, { children: /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { size: "small" }) }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1128
+ msgContent && /* @__PURE__ */ jsxRuntime.jsx(
1101
1129
  x.Bubble,
1102
1130
  {
1103
1131
  placement,
1104
1132
  className: classNames9__default.default({ [styles_module_default2.loadingMessage]: message2.type }),
1105
- content: /* @__PURE__ */ jsxRuntime.jsx(common.RenderMarkdown, { content: replaceThinkTags(content), customComponents, message: message2 })
1133
+ content: /* @__PURE__ */ jsxRuntime.jsx(common.RenderMarkdown, { content: replaceMarkdownTags(msgContent), customComponents, message: message2 })
1106
1134
  }
1107
1135
  ),
1108
1136
  message2.msgFiles?.map((file) => /* @__PURE__ */ jsxRuntime.jsx(
@@ -1111,7 +1139,7 @@ var MessageRender_default = ({ message: message2, placement }) => {
1111
1139
  className: "m-t-8",
1112
1140
  variant: "borderless",
1113
1141
  placement,
1114
- content: /* @__PURE__ */ jsxRuntime.jsx(
1142
+ content: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cursor-pointer", onClick: () => filePreview(file), children: /* @__PURE__ */ jsxRuntime.jsx(
1115
1143
  x.Attachments.FileCard,
1116
1144
  {
1117
1145
  item: {
@@ -1119,25 +1147,36 @@ var MessageRender_default = ({ message: message2, placement }) => {
1119
1147
  name: file.name,
1120
1148
  url: file.content
1121
1149
  }
1122
- },
1123
- file.content
1124
- )
1150
+ }
1151
+ ) })
1125
1152
  },
1126
1153
  file.content
1127
1154
  )),
1128
- message2.quoteMsg?.id ? /* @__PURE__ */ jsxRuntime.jsx(
1155
+ quoteMsg && /* @__PURE__ */ jsxRuntime.jsx(
1129
1156
  x.Bubble,
1130
1157
  {
1131
- className: classNames9__default.default(styles_module_default2.chatQuoteMsg),
1158
+ className: styles_module_default2.chatQuoteMsg,
1132
1159
  placement,
1133
1160
  content: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, gap: 8, children: [
1134
- message2.quoteMsg.msgContent && /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { children: [
1135
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u3010\u5F15\u7528\u6D88\u606F\u3011\uFF1A" }),
1136
- /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { flex: 1, className: "text-ellipsis", title: message2.quoteMsg.msgContent, children: /* @__PURE__ */ jsxRuntime.jsx(common.RenderMarkdown, { content: message2.quoteMsg.msgContent }) })
1137
- ] }),
1138
- message2.quoteMsg?.msgFiles && message2.quoteMsg.msgFiles.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { children: [
1161
+ quoteMsg.msgContent && /* @__PURE__ */ jsxRuntime.jsx(
1162
+ antd.Tooltip,
1163
+ {
1164
+ color: "#fff",
1165
+ classNames: {
1166
+ root: styles_module_default2.quoteTooltip,
1167
+ body: `${styles_module_default2.quoteTooltipContainer} scroll-fade-in`
1168
+ },
1169
+ title: /* @__PURE__ */ jsxRuntime.jsx(common.RenderMarkdown, { content: quoteMsg.msgContent }),
1170
+ getPopupContainer: (node) => node,
1171
+ children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { children: [
1172
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u3010\u5F15\u7528\u6D88\u606F\u3011\uFF1A" }),
1173
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { flex: 1, className: "text-ellipsis-2", children: quoteMsg.msgContentText })
1174
+ ] })
1175
+ }
1176
+ ),
1177
+ quoteMsg?.msgFiles && /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { children: [
1139
1178
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u3010\u5F15\u7528\u6587\u4EF6\u3011\uFF1A" }),
1140
- /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { gap: 8, wrap: true, flex: 1, children: message2.quoteMsg.msgFiles.map((file) => /* @__PURE__ */ jsxRuntime.jsx(
1179
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { gap: 8, wrap: true, flex: 1, children: quoteMsg.msgFiles.map((file) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cursor-pointer", onClick: () => filePreview(file), children: /* @__PURE__ */ jsxRuntime.jsx(
1141
1180
  x.Attachments.FileCard,
1142
1181
  {
1143
1182
  item: {
@@ -1145,22 +1184,11 @@ var MessageRender_default = ({ message: message2, placement }) => {
1145
1184
  name: file.name,
1146
1185
  url: file.content
1147
1186
  }
1148
- },
1149
- file.content
1150
- )) })
1187
+ }
1188
+ ) }, file.content)) })
1151
1189
  ] })
1152
1190
  ] })
1153
1191
  }
1154
- ) : paramsCitation && /* @__PURE__ */ jsxRuntime.jsx(
1155
- x.Bubble,
1156
- {
1157
- className: classNames9__default.default(styles_module_default2.chatQuoteMsg),
1158
- placement,
1159
- content: /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { vertical: true, gap: 8, children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { children: [
1160
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u3010\u5F15\u7528\u6D88\u606F\u3011\uFF1A" }),
1161
- /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { flex: 1, className: "text-ellipsis", title: paramsCitation, children: /* @__PURE__ */ jsxRuntime.jsx(common.RenderMarkdown, { content: paramsCitation }) })
1162
- ] }) })
1163
- }
1164
1192
  )
1165
1193
  ] }) });
1166
1194
  };
@@ -1332,8 +1360,19 @@ var BubbleListItems_default = ({ firstMessage = false, welcomeMessage = true, av
1332
1360
  placement: role.placement,
1333
1361
  variant: "borderless",
1334
1362
  avatar: role.avatar,
1335
- content: /* @__PURE__ */ jsxRuntime.jsx(MessageRender_default, { message: message2, placement: role.placement }),
1336
- footer: role.user === "agent" && /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { children: [
1363
+ content: /* @__PURE__ */ jsxRuntime.jsx(
1364
+ MessageRender_default,
1365
+ {
1366
+ message: message2,
1367
+ placement: role.placement,
1368
+ onFilePreview: (file) => chatStore.setPreview({
1369
+ fileUrl: file.content,
1370
+ suffix: file.extension,
1371
+ fileName: file.name
1372
+ })
1373
+ }
1374
+ ),
1375
+ footer: /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { children: role.user === "agent" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1337
1376
  /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { onClick: () => common.copyText(message2.msgContent), color: "default", variant: "text", size: "small", icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CopyOutlined, {}) }),
1338
1377
  /* @__PURE__ */ jsxRuntime.jsx(
1339
1378
  antd.Button,
@@ -1357,7 +1396,7 @@ var BubbleListItems_default = ({ firstMessage = false, welcomeMessage = true, av
1357
1396
  onClick: () => chatStore.feedback(conversationState.active.id, message2.id, 2, index)
1358
1397
  }
1359
1398
  )
1360
- ] })
1399
+ ] }) })
1361
1400
  // ...(isHasTime
1362
1401
  // ? { rootClassName: styles.hasSendTime, classNames: { header: styles.sendTime }, header: <span>{formatDate(message.sendDate)}</span> }
1363
1402
  // : {})
@@ -1727,6 +1766,7 @@ var Attachments_default = react.forwardRef(({ fileUpload, fileUploadConfig = [],
1727
1766
  beforeUpload: (file, files) => onBeforeUpload(files),
1728
1767
  items: attachedFiles,
1729
1768
  onRemove,
1769
+ overflow: "wrap",
1730
1770
  placeholder: (type) => type === "drop" ? { title: "\u5C06\u6587\u4EF6\u653E\u5230\u8FD9\u91CC" } : {
1731
1771
  icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CloudUploadOutlined, {}),
1732
1772
  title: "\u63D0\u4EA4\u6587\u4EF6",
@@ -1799,7 +1839,7 @@ var ChatSender_default = react.forwardRef(
1799
1839
  autoSize: { minRows: 2, maxRows: 6 },
1800
1840
  onCancel,
1801
1841
  footer: ({ components }) => {
1802
- const { SendButton, LoadingButton, SpeechButton } = components;
1842
+ const { SendButton, LoadingButton } = components;
1803
1843
  return /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, children: [
1804
1844
  /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { justify: "space-between", align: "center", gap: 12, children: [
1805
1845
  /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { className: "flex-1", gap: 6, align: "center", children: [
@@ -1807,10 +1847,7 @@ var ChatSender_default = react.forwardRef(
1807
1847
  extraFooter,
1808
1848
  " "
1809
1849
  ] }),
1810
- /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { align: "center", gap: 6, children: [
1811
- /* @__PURE__ */ jsxRuntime.jsx(SpeechButton, {}),
1812
- loading ? /* @__PURE__ */ jsxRuntime.jsx(LoadingButton, { disabled: false }) : /* @__PURE__ */ jsxRuntime.jsx(SendButton, { ...sendBtnProps })
1813
- ] })
1850
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { align: "center", gap: 6, children: loading ? /* @__PURE__ */ jsxRuntime.jsx(LoadingButton, { disabled: false }) : /* @__PURE__ */ jsxRuntime.jsx(SendButton, { ...sendBtnProps }) })
1814
1851
  ] }),
1815
1852
  extraFooterBelow
1816
1853
  ] });
@@ -1873,12 +1910,16 @@ var ChatSender_default2 = react.forwardRef(
1873
1910
  () => conversationState.messages[conversationState.active.id] || {},
1874
1911
  [conversationState.messages[conversationState.active.id]]
1875
1912
  );
1913
+ const referenceContent = react.useMemo(() => {
1914
+ const content = chatMessage.references?.content?.name;
1915
+ if (content) {
1916
+ return common.markdownToText(content);
1917
+ }
1918
+ }, [chatMessage.references]);
1876
1919
  const referenceHandle = (con) => {
1877
1920
  if (chatMessage?.loading) return;
1878
1921
  chatStore.setContent(con);
1879
- setTimeout(() => {
1880
- chatStore.sendMessage();
1881
- }, 10);
1922
+ chatStore.sendMessage();
1882
1923
  };
1883
1924
  return /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, gap: 8, className: "zero-chat-sender", children: [
1884
1925
  /* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: prompts, DefaultComponent: SenderPromptsItems_default }),
@@ -1936,9 +1977,9 @@ var ChatSender_default2 = react.forwardRef(
1936
1977
  {
1937
1978
  title: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { gap: 4, children: [
1938
1979
  /* @__PURE__ */ jsxRuntime.jsx(icons.EnterOutlined, {}),
1939
- /* @__PURE__ */ jsxRuntime.jsx(antd.Typography.Text, { type: "secondary", ellipsis: true, children: chatMessage?.references?.content?.name })
1980
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Typography.Text, { type: "secondary", ellipsis: true, children: referenceContent })
1940
1981
  ] }),
1941
- open: !!chatMessage?.references?.content?.name,
1982
+ open: !!referenceContent,
1942
1983
  onOpenChange: () => chatStore.setReferences(),
1943
1984
  classNames: {
1944
1985
  header: styles_module_default3.nsSenderReferenceHeaderTitle,