@zero-library/chat-agent 2.2.1 → 2.2.3

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
@@ -62,8 +62,14 @@ var init_AppCard = __esm({
62
62
  init_styles_module();
63
63
  AppCard_default = ({ data, loading }) => {
64
64
  const chatStore = useChatStore();
65
- const onClick = () => {
66
- chatStore.switchAgentConversation(data.appKey);
65
+ const onClick = async () => {
66
+ if (data.appKey) {
67
+ const canProceed = await chatStore.config.hooks?.onAppRightVerify?.(data.appKey);
68
+ if (canProceed === false) {
69
+ return;
70
+ }
71
+ }
72
+ chatStore.switchAgentConversation(data.agentId);
67
73
  };
68
74
  return /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { spinning: loading, size: "small", children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, gap: 4, align: "center", className: styles_module_default.appCard, onClick, children: [
69
75
  /* @__PURE__ */ jsxRuntime.jsx("img", { src: data.iconUrl }),
@@ -99,7 +105,7 @@ var DocDrawer_default;
99
105
  var init_DocDrawer = __esm({
100
106
  "src/ui/common/markdownAlert/components/DocDrawer.tsx"() {
101
107
  init_Context();
102
- DocDrawer_default = ({ title, open, onClose, fileUrl }) => {
108
+ DocDrawer_default = ({ title, open, onClose, paramsStr }) => {
103
109
  const chatStore = useChatStore();
104
110
  const configState = valtio.useSnapshot(chatStore.config);
105
111
  const [content, setContent] = react.useState("");
@@ -107,7 +113,7 @@ var init_DocDrawer = __esm({
107
113
  const getContent = async () => {
108
114
  try {
109
115
  setLoading(true);
110
- const res = await configState.services.request.docQuery(fileUrl);
116
+ const res = await configState.services.request.docQuery(paramsStr);
111
117
  setContent(res.data?.content);
112
118
  } finally {
113
119
  setLoading(false);
@@ -115,7 +121,7 @@ var init_DocDrawer = __esm({
115
121
  };
116
122
  react.useEffect(() => {
117
123
  getContent();
118
- }, [fileUrl]);
124
+ }, [paramsStr]);
119
125
  return /* @__PURE__ */ jsxRuntime.jsx(antd.Drawer, { title, push: false, width: "100%", open, onClose, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { spinning: loading, children: content ? /* @__PURE__ */ jsxRuntime.jsx(common.RenderMarkdown, { content }) : /* @__PURE__ */ jsxRuntime.jsx(antd.Empty, { className: "m-t-32" }) }) });
120
126
  };
121
127
  }
@@ -130,20 +136,28 @@ var IndexQuote_default;
130
136
  var init_IndexQuote = __esm({
131
137
  "src/ui/common/markdownAlert/IndexQuote.tsx"() {
132
138
  init_DocDrawer();
133
- IndexQuote_default = ({ data, loading }) => {
139
+ IndexQuote_default = ({ data, loading, message: message2 }) => {
134
140
  const [open, setOpen] = react.useState(false);
141
+ const citation = react.useMemo(() => {
142
+ let citations = [];
143
+ try {
144
+ citations = JSON.parse(message2.citations);
145
+ } catch (e) {
146
+ }
147
+ return citations?.find((item) => String(item.citationId) === String(data.citationId));
148
+ }, [data.citationId, message2.citations]);
135
149
  const onClick = () => {
136
- if (!data.fileUrl) return;
137
- if (common.isExternal(data.fileUrl)) {
138
- window.open(data.fileUrl, "_blank");
150
+ if (!citation?.citationUrl) return;
151
+ if (common.isExternal(citation.citationUrl)) {
152
+ window.open(citation.citationUrl, "_blank");
139
153
  } else {
140
154
  setOpen(true);
141
155
  }
142
156
  };
143
- const Content = /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { align: "center", gap: 8, children: /* @__PURE__ */ jsxRuntime.jsx("a", { onClick, children: data.fileName }) }) });
157
+ const Content = /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { align: "center", gap: 8, children: /* @__PURE__ */ jsxRuntime.jsx("a", { onClick, children: citation?.citationName }) }) });
144
158
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "inline-block m-l-8", children: [
145
- /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { spinning: loading, size: "small", children: /* @__PURE__ */ jsxRuntime.jsx(antd.Popover, { content: Content, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Tag, { bordered: false, color: "processing", className: "cursor-pointer", children: data.index }) }) }),
146
- open && /* @__PURE__ */ jsxRuntime.jsx(DocDrawer_default, { fileUrl: data.fileUrl, title: data.fileName, open, onClose: () => setOpen(false) })
159
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { spinning: loading, size: "small", children: /* @__PURE__ */ jsxRuntime.jsx(antd.Popover, { content: Content, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Tag, { bordered: false, color: "processing", className: "cursor-pointer", children: data?.citationName }) }) }),
160
+ open && /* @__PURE__ */ jsxRuntime.jsx(DocDrawer_default, { paramsStr: citation?.citationUrl, title: citation?.citationName, open, onClose: () => setOpen(false) })
147
161
  ] });
148
162
  };
149
163
  }
@@ -163,7 +177,7 @@ var init_MdEdit = __esm({
163
177
  const chatStore = useChatStore();
164
178
  const [value, setValue] = react.useState("");
165
179
  const onOk = () => {
166
- chatStore.sendMessage("\u5F00\u59CB\u5199\u4F5C", [], { outline: value });
180
+ chatStore.sendMessage("\u5F00\u59CB\u5199\u4F5C", [], { citation: value });
167
181
  };
168
182
  react.useEffect(() => {
169
183
  setValue(data.content);
@@ -208,51 +222,6 @@ var init_FileEdit = __esm({
208
222
  }
209
223
  });
210
224
 
211
- // src/ui/common/markdownAlert/QuoteList.tsx
212
- var QuoteList_exports = {};
213
- __export(QuoteList_exports, {
214
- default: () => QuoteList_default
215
- });
216
- var QuoteList_default;
217
- var init_QuoteList = __esm({
218
- "src/ui/common/markdownAlert/QuoteList.tsx"() {
219
- init_DocDrawer();
220
- init_styles_module();
221
- QuoteList_default = ({ data, loading }) => {
222
- const [open, setOpen] = react.useState(false);
223
- const [selectItem, setSelectItem] = react.useState({});
224
- const onClick = (item) => {
225
- if (!item.fileUrl) return;
226
- if (common.isExternal(item.fileUrl)) {
227
- window.open(item.fileUrl, "_blank");
228
- } else {
229
- setSelectItem(item);
230
- setOpen(true);
231
- }
232
- };
233
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
234
- /* @__PURE__ */ jsxRuntime.jsx(
235
- antd.Collapse,
236
- {
237
- className: styles_module_default.quoteList,
238
- bordered: false,
239
- ghost: true,
240
- expandIcon: ({ isActive }) => /* @__PURE__ */ jsxRuntime.jsx(icons.CaretRightOutlined, { rotate: isActive ? 90 : 0 }),
241
- items: [
242
- {
243
- key: "1",
244
- label: "\u53C2\u8003\u8D44\u6599",
245
- children: /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { vertical: true, gap: 4, children: data.list.map((item) => /* @__PURE__ */ jsxRuntime.jsx("p", { onClick: () => !loading && onClick(item), className: "cursor-pointer", children: item.title }, item.fileUrl)) })
246
- }
247
- ]
248
- }
249
- ),
250
- open && /* @__PURE__ */ jsxRuntime.jsx(DocDrawer_default, { fileUrl: selectItem.fileUrl, title: selectItem.title, open, onClose: () => setOpen(false) })
251
- ] });
252
- };
253
- }
254
- });
255
-
256
225
  // src/ui/common/markdownAlert/Think.tsx
257
226
  var Think_exports = {};
258
227
  __export(Think_exports, {
@@ -808,8 +777,7 @@ function createChatStore() {
808
777
  }
809
778
  };
810
779
  const switchAgentConversation = async (id, strategy) => {
811
- const agentId = String(id);
812
- await switchAgent(agentId);
780
+ await switchAgent(String(id));
813
781
  const conversationId = await resolveConversationId(receiver.active.id, strategy);
814
782
  if (conversationId) {
815
783
  await switchConversation(conversationId);
@@ -920,60 +888,84 @@ function createChatStore() {
920
888
  const cancelReceive = async () => {
921
889
  console.log("\u53D6\u6D88\u63A5\u6536");
922
890
  await config.services.request.conversationStop(conversation.active.id);
891
+ conversation.messages[conversation.active.id].loading = false;
923
892
  };
924
893
  const updateConversationTitle = (conversationId, title) => {
925
- const idx = conversations.list.items.findIndex((item) => item.id === conversationId);
926
- if (idx === -1) return;
927
- conversations.list.items[idx].title = title;
894
+ if (title && conversations.list.items.length) {
895
+ const idx = conversations.list.items.findIndex((item) => item.id === conversationId);
896
+ if (idx === -1) return;
897
+ conversations.list.items[idx].label = title;
898
+ }
928
899
  };
929
- const findMsgIndex = (conversationId, msgId) => {
930
- const messages = conversation.messages[conversationId]?.message || [];
931
- return messages.findLastIndex((item) => item.id === msgId);
900
+ const findMsgIndex = (msgId, messages) => {
901
+ return (messages || []).findLastIndex((item) => item.id === msgId);
932
902
  };
933
903
  const startCallback = (msg) => {
934
- if (msg.conversationTitle && conversations.list.items.length) {
935
- updateConversationTitle(msg.conversationId, msg.conversationTitle);
936
- }
937
904
  removeQuestionList(msg.conversationId);
938
- const messages = conversation.messages[msg.conversationId].message;
939
- messages.push(msg.sender.type === 3 ? { ...msg, msgContent: "\u6B63\u5728\u52AA\u529B\u601D\u8003\u4E2D" } : msg);
905
+ const messages = conversation.messages[msg.conversationId]?.message;
906
+ if (!messages) return;
907
+ messages.push(msg.sender.type === 3 ? { ...msg, tempContent: "\u6B63\u5728\u52AA\u529B\u601D\u8003\u4E2D" } : msg);
940
908
  conversation.messages[msg.conversationId].loading = true;
941
909
  };
942
910
  const stepCallback = (msg) => {
943
- const messages = conversation.messages[msg.conversationId].message;
944
- const idx = findMsgIndex(msg.conversationId, msg.id);
911
+ const messages = conversation.messages[msg.conversationId]?.message;
912
+ const idx = findMsgIndex(msg.id, messages);
945
913
  if (idx === -1) return;
946
- messages[idx] = msg;
947
914
  conversation.messages[msg.conversationId].loading = true;
915
+ messages[idx] = {
916
+ ...messages[idx],
917
+ params: messages[idx]?.params || msg.params,
918
+ type: msg.type,
919
+ tempContent: msg.msgContent
920
+ };
948
921
  };
949
922
  const contentCallback = (msg) => {
950
- const messages = conversation.messages[msg.conversationId].message;
951
- const idx = findMsgIndex(msg.conversationId, msg.id);
923
+ const messages = conversation.messages[msg.conversationId]?.message;
924
+ const idx = findMsgIndex(msg.id, messages);
952
925
  if (idx === -1) return;
953
- const message2 = messages[idx];
954
926
  conversation.messages[msg.conversationId].loading = true;
955
- if (message2?.type === "STEP_STARTED" || message2?.type === "TEXT_MESSAGE_START") {
956
- messages[idx] = msg;
957
- return;
958
- }
959
927
  messages[idx] = {
960
- ...message2,
961
- msgContent: message2.msgContent + (msg.msgContent || "")
928
+ ...messages[idx],
929
+ params: messages[idx]?.params || msg.params,
930
+ type: msg.type,
931
+ tempContent: "",
932
+ msgContent: messages[idx].msgContent + (msg.msgContent || "")
962
933
  };
963
934
  };
964
935
  const endCallback = (msg) => {
965
- const messages = conversation.messages[msg.conversationId].message;
966
- const idx = findMsgIndex(msg.conversationId, msg.id);
936
+ const messages = conversation.messages[msg.conversationId]?.message;
937
+ const idx = findMsgIndex(msg.id, messages);
967
938
  if (idx === -1) return;
968
- messages[idx] = { ...messages[idx], type: void 0 };
939
+ messages[idx] = {
940
+ ...messages[idx],
941
+ tempContent: "",
942
+ type: void 0
943
+ };
969
944
  conversation.messages[msg.conversationId].loading = false;
970
945
  getQuestionList(msg.conversationId, msg.id);
971
946
  };
947
+ const citationCallback = (msg) => {
948
+ const messages = conversation.messages[msg.conversationId]?.message;
949
+ const idx = findMsgIndex(msg.id, messages);
950
+ if (idx === -1) return;
951
+ messages[idx] = {
952
+ ...messages[idx],
953
+ citations: msg.msgContent
954
+ };
955
+ };
972
956
  const errCallback = (msg) => {
973
957
  const messages = conversation.messages[msg.conversationId].message;
974
- const idx = findMsgIndex(msg.conversationId, msg.id);
958
+ const idx = findMsgIndex(msg.id, messages);
975
959
  if (idx === -1) return;
976
- messages[idx] = { ...msg, type: void 0 };
960
+ messages[idx] = {
961
+ ...messages[idx],
962
+ params: messages[idx]?.params || msg.params,
963
+ tempContent: msg.msgContent,
964
+ type: void 0,
965
+ // 报错后清空消息内容
966
+ msgContent: "",
967
+ citations: ""
968
+ };
977
969
  conversation.messages[msg.conversationId].loading = false;
978
970
  };
979
971
  const acceptMessage = async (newMessage) => {
@@ -983,6 +975,7 @@ function createChatStore() {
983
975
  if (canProceed === false) {
984
976
  throw new Error("\u64CD\u4F5C\u88AB\u963B\u6B62");
985
977
  }
978
+ updateConversationTitle(conversationId, newMessage.data.conversationTitle);
986
979
  switch (newMessage.data.type) {
987
980
  case "TEXT_MESSAGE_START":
988
981
  startCallback(newMessage.data);
@@ -996,6 +989,9 @@ function createChatStore() {
996
989
  case "TEXT_MESSAGE_END":
997
990
  endCallback(newMessage.data);
998
991
  break;
992
+ case "TEXT_MESSAGE_CITATION":
993
+ citationCallback(newMessage.data);
994
+ break;
999
995
  case "RUN_ERROR":
1000
996
  errCallback(newMessage.data);
1001
997
  break;
@@ -1076,7 +1072,7 @@ var customComponents = {
1076
1072
  indexQuote: () => Promise.resolve().then(() => (init_IndexQuote(), IndexQuote_exports)),
1077
1073
  mdEdit: () => Promise.resolve().then(() => (init_MdEdit(), MdEdit_exports)),
1078
1074
  fileEdit: () => Promise.resolve().then(() => (init_FileEdit(), FileEdit_exports)),
1079
- quoteList: () => Promise.resolve().then(() => (init_QuoteList(), QuoteList_exports)),
1075
+ // quoteList: () => import('./QuoteList'),
1080
1076
  think: () => Promise.resolve().then(() => (init_Think(), Think_exports))
1081
1077
  };
1082
1078
 
@@ -1088,13 +1084,25 @@ var styles_module_default2 = {
1088
1084
  chatQuoteMsg: "styles_module_chatQuoteMsg"
1089
1085
  };
1090
1086
  var MessageRender_default = ({ message: message2, placement }) => {
1091
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { vertical: true, children: !(message2.msgContent || message2.msgFiles.length) ? /* @__PURE__ */ jsxRuntime.jsx(antd.Typography, { children: /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { size: "small" }) }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1092
- message2.msgContent && /* @__PURE__ */ jsxRuntime.jsx(
1087
+ const content = react.useMemo(
1088
+ () => `${message2.msgContent || ""}${message2.msgContent && message2.tempContent ? "\n\n" : ""}${message2.tempContent || ""}`,
1089
+ [message2.msgContent, message2.tempContent]
1090
+ );
1091
+ const paramsCitation = react.useMemo(() => {
1092
+ let citation = "";
1093
+ try {
1094
+ citation = JSON.parse(message2.params || "{}").citation || "";
1095
+ } catch (e) {
1096
+ }
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(
1093
1101
  x.Bubble,
1094
1102
  {
1095
1103
  placement,
1096
1104
  className: classNames9__default.default({ [styles_module_default2.loadingMessage]: message2.type }),
1097
- content: /* @__PURE__ */ jsxRuntime.jsx(common.RenderMarkdown, { content: replaceThinkTags(message2.msgContent), customComponents })
1105
+ content: /* @__PURE__ */ jsxRuntime.jsx(common.RenderMarkdown, { content: replaceThinkTags(content), customComponents, message: message2 })
1098
1106
  }
1099
1107
  ),
1100
1108
  message2.msgFiles?.map((file) => /* @__PURE__ */ jsxRuntime.jsx(
@@ -1117,7 +1125,7 @@ var MessageRender_default = ({ message: message2, placement }) => {
1117
1125
  },
1118
1126
  file.content
1119
1127
  )),
1120
- message2.quoteMsg?.id && /* @__PURE__ */ jsxRuntime.jsx(
1128
+ message2.quoteMsg?.id ? /* @__PURE__ */ jsxRuntime.jsx(
1121
1129
  x.Bubble,
1122
1130
  {
1123
1131
  className: classNames9__default.default(styles_module_default2.chatQuoteMsg),
@@ -1125,7 +1133,7 @@ var MessageRender_default = ({ message: message2, placement }) => {
1125
1133
  content: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, gap: 8, children: [
1126
1134
  message2.quoteMsg.msgContent && /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { children: [
1127
1135
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u3010\u5F15\u7528\u6D88\u606F\u3011\uFF1A" }),
1128
- /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { flex: 1, className: "text-ellipsis", children: message2.quoteMsg.msgContent })
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 }) })
1129
1137
  ] }),
1130
1138
  message2.quoteMsg?.msgFiles && message2.quoteMsg.msgFiles.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { children: [
1131
1139
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u3010\u5F15\u7528\u6587\u4EF6\u3011\uFF1A" }),
@@ -1143,6 +1151,16 @@ var MessageRender_default = ({ message: message2, placement }) => {
1143
1151
  ] })
1144
1152
  ] })
1145
1153
  }
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
+ }
1146
1164
  )
1147
1165
  ] }) });
1148
1166
  };
@@ -2097,13 +2115,13 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
2097
2115
  value: configState.preview.file.content,
2098
2116
  onQuote: (text) => {
2099
2117
  chatStore.setReferences({
2100
- type: 1,
2118
+ type: 2,
2101
2119
  content: {
2102
2120
  name: text,
2103
2121
  markdown: text
2104
2122
  },
2105
2123
  params: {
2106
- outline: text
2124
+ citation: text
2107
2125
  }
2108
2126
  });
2109
2127
  },