@zero-library/chat-agent 2.0.0 → 2.0.2

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
@@ -2,19 +2,19 @@
2
2
 
3
3
  var common = require('@zero-library/common');
4
4
  var antd = require('antd');
5
+ var dayjs = require('dayjs');
5
6
  var jsxRuntime = require('react/jsx-runtime');
6
7
  var react = require('react');
7
8
  var icons = require('@ant-design/icons');
8
9
  var x = require('@ant-design/x');
9
10
  var classNames2 = require('classnames');
10
11
  var valtio = require('valtio');
11
- var dayjs = require('dayjs');
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
- var classNames2__default = /*#__PURE__*/_interopDefault(classNames2);
17
16
  var dayjs__default = /*#__PURE__*/_interopDefault(dayjs);
17
+ var classNames2__default = /*#__PURE__*/_interopDefault(classNames2);
18
18
  var InfiniteScroll__default = /*#__PURE__*/_interopDefault(InfiniteScroll);
19
19
 
20
20
  var __defProp = Object.defineProperty;
@@ -26,6 +26,64 @@ var __export = (target, all) => {
26
26
  for (var name in all)
27
27
  __defProp(target, name, { get: all[name], enumerable: true });
28
28
  };
29
+ function transform(source, fieldMap) {
30
+ const result = {};
31
+ for (const [targetKey, mapping] of Object.entries(fieldMap)) {
32
+ const key = targetKey;
33
+ if (typeof mapping === "function") {
34
+ result[key] = mapping(source);
35
+ } else if (typeof mapping === "string" && source && mapping in source) {
36
+ result[key] = source[mapping];
37
+ } else {
38
+ result[key] = mapping;
39
+ }
40
+ }
41
+ return result;
42
+ }
43
+ function transforms(sources, fieldMap) {
44
+ return sources?.map((source) => transform(source, fieldMap)) || [];
45
+ }
46
+ function buildURLWithParams(url, params) {
47
+ const query = new URLSearchParams(
48
+ Object.entries(params || {}).flatMap(([key, val]) => Array.isArray(val) ? val.map((v) => [key, String(v)]) : [[key, String(val)]])
49
+ ).toString();
50
+ return query ? `${url}${url.includes("?") ? "&" : "?"}${query}` : url;
51
+ }
52
+ var copy, classifyTime, getBase64;
53
+ var init_utils = __esm({
54
+ "src/core/utils.ts"() {
55
+ copy = (value) => {
56
+ common.copyText(value).then(() => {
57
+ antd.message.success("\u590D\u5236\u6210\u529F");
58
+ });
59
+ };
60
+ classifyTime = (timestamp) => {
61
+ const now = dayjs__default.default();
62
+ const target = dayjs__default.default(timestamp);
63
+ if (target.isSame(now, "day")) {
64
+ return "\u4ECA\u5929";
65
+ }
66
+ const diffInDays = now.diff(target, "day");
67
+ if (diffInDays < 7) {
68
+ return "\u6700\u8FD1 7 \u5929";
69
+ } else if (diffInDays < 30) {
70
+ return "\u6700\u8FD1 30 \u5929";
71
+ } else if (diffInDays < 180) {
72
+ return "\u6700\u8FD1\u534A\u5E74";
73
+ } else {
74
+ return "\u66F4\u65E9";
75
+ }
76
+ };
77
+ getBase64 = (file) => {
78
+ return new Promise((resolve, reject) => {
79
+ const reader = new FileReader();
80
+ reader.onload = () => resolve(reader.result);
81
+ reader.onerror = reject;
82
+ reader.readAsDataURL(file);
83
+ });
84
+ };
85
+ }
86
+ });
29
87
  var ChatProvider, useChatStore;
30
88
  var init_Context = __esm({
31
89
  "src/stores/Context.ts"() {
@@ -94,6 +152,37 @@ var init_FileView = __esm({
94
152
  };
95
153
  }
96
154
  });
155
+ var docQuery;
156
+ var init_file = __esm({
157
+ "src/services/file.ts"() {
158
+ docQuery = (paramsStr) => {
159
+ return common.request.get(`/uc/doc?${paramsStr}`);
160
+ };
161
+ }
162
+ });
163
+ var DocDrawer_default;
164
+ var init_DocDrawer = __esm({
165
+ "src/ui/common/markdownAlert/components/DocDrawer.tsx"() {
166
+ init_file();
167
+ DocDrawer_default = ({ title, open, onClose, fileUrl }) => {
168
+ const [content, setContent] = react.useState("");
169
+ const [loading, setLoading] = react.useState(false);
170
+ const getContent = async () => {
171
+ try {
172
+ setLoading(true);
173
+ const res = await docQuery(fileUrl);
174
+ setContent(res.data?.content);
175
+ } finally {
176
+ setLoading(false);
177
+ }
178
+ };
179
+ react.useEffect(() => {
180
+ getContent();
181
+ }, [fileUrl]);
182
+ 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" }) }) });
183
+ };
184
+ }
185
+ });
97
186
 
98
187
  // src/ui/common/markdownAlert/IndexQuote.tsx
99
188
  var IndexQuote_exports = {};
@@ -103,12 +192,30 @@ __export(IndexQuote_exports, {
103
192
  var IndexQuote_default;
104
193
  var init_IndexQuote = __esm({
105
194
  "src/ui/common/markdownAlert/IndexQuote.tsx"() {
195
+ init_DocDrawer();
106
196
  IndexQuote_default = ({ data, loading }) => {
197
+ const [open, setOpen] = react.useState(false);
107
198
  const onClick = () => {
108
- window.open(data.fileUrl, "_blank");
199
+ if (!data.fileUrl) return;
200
+ if (common.isExternal(data.fileUrl)) {
201
+ window.open(data.fileUrl, "_blank");
202
+ } else {
203
+ setOpen(true);
204
+ }
109
205
  };
110
206
  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 }) }) });
111
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { spinning: loading, size: "small", wrapperClassName: "inline-block index-quote", children: /* @__PURE__ */ jsxRuntime.jsx(antd.Popover, { content: Content, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Tag, { bordered: false, color: "processing", className: "cursor-pointer", children: data.index }) }) });
207
+ const rootRef = react.useRef(null);
208
+ react.useEffect(() => {
209
+ const el = rootRef.current;
210
+ if (!el) return;
211
+ const previous = el.previousElementSibling;
212
+ if (!previous) return;
213
+ previous.appendChild(el);
214
+ }, []);
215
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: rootRef, className: "inline-block m-l-8", children: [
216
+ /* @__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 }) }) }),
217
+ open && /* @__PURE__ */ jsxRuntime.jsx(DocDrawer_default, { fileUrl: data.fileUrl, title: data.fileName, open, onClose: () => setOpen(false) })
218
+ ] });
112
219
  };
113
220
  }
114
221
  });
@@ -149,20 +256,27 @@ __export(FileEdit_exports, {
149
256
  var FileEdit_default;
150
257
  var init_FileEdit = __esm({
151
258
  "src/ui/common/markdownAlert/FileEdit.tsx"() {
259
+ init_utils();
152
260
  init_Context();
153
261
  init_styles_module();
154
262
  FileEdit_default = ({ data, loading }) => {
155
263
  const chatStore = useChatStore();
156
- const onClick = () => {
264
+ const onPreview = () => {
157
265
  chatStore.setPreview(data, true);
158
266
  };
159
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { spinning: loading, size: "small", children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, className: styles_module_default2.fileEdit, children: [
160
- /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { gap: 8, justify: "end", className: styles_module_default2.fileEditHeader, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { color: "default", variant: "text", size: "small", icon: /* @__PURE__ */ jsxRuntime.jsx(icons.PlayCircleOutlined, {}), onClick, children: "\u9884\u89C8\u7F16\u8F91" }) }),
161
- /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { gap: 8, align: "center", className: styles_module_default2.fileEditContent, children: [
162
- /* @__PURE__ */ jsxRuntime.jsx(common.FileIcon, { suffix: "md" }),
163
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ellipsis", title: data.fileName, children: data.fileName })
164
- ] })
165
- ] }) });
267
+ return /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, className: styles_module_default2.fileEdit, children: [
268
+ /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { gap: 8, align: "center", justify: "space-between", className: styles_module_default2.fileEditHeader, children: [
269
+ /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { gap: 4, align: "center", className: "flex-1", children: [
270
+ /* @__PURE__ */ jsxRuntime.jsx(common.FileIcon, { suffix: "md", fontSize: 18 }),
271
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ellipsis", title: data.fileName, children: data.fileName })
272
+ ] }),
273
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { spinning: loading, size: "small", children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { children: [
274
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { color: "default", variant: "text", size: "small", icon: /* @__PURE__ */ jsxRuntime.jsx(icons.PlayCircleOutlined, {}), onClick: onPreview, children: "\u9884\u89C8\u7F16\u8F91" }),
275
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { color: "default", variant: "text", size: "small", icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CopyOutlined, {}), onClick: () => copy(data.content), children: "\u590D\u5236" })
276
+ ] }) })
277
+ ] }),
278
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { gap: 8, align: "center", className: styles_module_default2.fileEditContent, children: /* @__PURE__ */ jsxRuntime.jsx(common.RenderMarkdown, { content: data.content }) })
279
+ ] });
166
280
  };
167
281
  }
168
282
  });
@@ -175,27 +289,39 @@ __export(QuoteList_exports, {
175
289
  var QuoteList_default;
176
290
  var init_QuoteList = __esm({
177
291
  "src/ui/common/markdownAlert/QuoteList.tsx"() {
292
+ init_DocDrawer();
178
293
  init_styles_module();
179
294
  QuoteList_default = ({ data, loading }) => {
295
+ const [open, setOpen] = react.useState(false);
296
+ const [selectItem, setSelectItem] = react.useState({});
180
297
  const onClick = (item) => {
181
- window.open(item.fileUrl, "_blank");
182
- };
183
- return /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { spinning: loading, size: "small", children: /* @__PURE__ */ jsxRuntime.jsx(
184
- antd.Collapse,
185
- {
186
- className: styles_module_default2.quoteList,
187
- bordered: false,
188
- ghost: true,
189
- expandIcon: ({ isActive }) => /* @__PURE__ */ jsxRuntime.jsx(icons.CaretRightOutlined, { rotate: isActive ? 90 : 0 }),
190
- items: [
191
- {
192
- key: "1",
193
- label: "\u53C2\u8003\u8D44\u6599",
194
- children: /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { vertical: true, gap: 4, children: data.list.map((item) => /* @__PURE__ */ jsxRuntime.jsx("p", { onClick: () => onClick(item), className: "cursor-pointer", children: item.title }, item.fileUrl)) })
195
- }
196
- ]
298
+ if (!item.fileUrl) return;
299
+ if (common.isExternal(item.fileUrl)) {
300
+ window.open(item.fileUrl, "_blank");
301
+ } else {
302
+ setSelectItem(item);
303
+ setOpen(true);
197
304
  }
198
- ) });
305
+ };
306
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
307
+ /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { spinning: loading, size: "small", children: /* @__PURE__ */ jsxRuntime.jsx(
308
+ antd.Collapse,
309
+ {
310
+ className: styles_module_default2.quoteList,
311
+ bordered: false,
312
+ ghost: true,
313
+ expandIcon: ({ isActive }) => /* @__PURE__ */ jsxRuntime.jsx(icons.CaretRightOutlined, { rotate: isActive ? 90 : 0 }),
314
+ items: [
315
+ {
316
+ key: "1",
317
+ label: "\u53C2\u8003\u8D44\u6599",
318
+ children: /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { vertical: true, gap: 4, children: data.list.map((item) => /* @__PURE__ */ jsxRuntime.jsx("p", { onClick: () => onClick(item), className: "cursor-pointer", children: item.title }, item.fileUrl)) })
319
+ }
320
+ ]
321
+ }
322
+ ) }),
323
+ open && /* @__PURE__ */ jsxRuntime.jsx(DocDrawer_default, { fileUrl: selectItem.fileUrl, title: selectItem.title, open, onClose: () => setOpen(false) })
324
+ ] });
199
325
  };
200
326
  }
201
327
  });
@@ -206,59 +332,12 @@ var ChatRoleMap = {
206
332
  1: "user",
207
333
  2: "assistant"
208
334
  };
209
- var copy = (value) => {
210
- common.copyText(value).then(() => {
211
- antd.message.success("\u590D\u5236\u6210\u529F");
212
- });
213
- };
214
- var classifyTime = (timestamp) => {
215
- const now = dayjs__default.default();
216
- const target = dayjs__default.default(timestamp);
217
- if (target.isSame(now, "day")) {
218
- return "\u4ECA\u5929";
219
- }
220
- const diffInDays = now.diff(target, "day");
221
- if (diffInDays < 7) {
222
- return "\u6700\u8FD1 7 \u5929";
223
- } else if (diffInDays < 30) {
224
- return "\u6700\u8FD1 30 \u5929";
225
- } else if (diffInDays < 180) {
226
- return "\u6700\u8FD1\u534A\u5E74";
227
- } else {
228
- return "\u66F4\u65E9";
229
- }
230
- };
231
- function transform(source, fieldMap) {
232
- const result = {};
233
- for (const [targetKey, mapping] of Object.entries(fieldMap)) {
234
- const key = targetKey;
235
- if (typeof mapping === "function") {
236
- result[key] = mapping(source);
237
- } else if (typeof mapping === "string" && source && mapping in source) {
238
- result[key] = source[mapping];
239
- } else {
240
- result[key] = mapping;
241
- }
242
- }
243
- return result;
244
- }
245
- function transforms(sources, fieldMap) {
246
- return sources?.map((source) => transform(source, fieldMap)) || [];
247
- }
248
- function buildURLWithParams(url, params) {
249
- const query = new URLSearchParams(
250
- Object.entries(params || {}).flatMap(([key, val]) => Array.isArray(val) ? val.map((v) => [key, String(v)]) : [[key, String(val)]])
251
- ).toString();
252
- return query ? `${url}${url.includes("?") ? "&" : "?"}${query}` : url;
253
- }
254
- var getBase64 = (file) => {
255
- return new Promise((resolve, reject) => {
256
- const reader = new FileReader();
257
- reader.onload = () => resolve(reader.result);
258
- reader.onerror = reject;
259
- reader.readAsDataURL(file);
260
- });
261
- };
335
+
336
+ // src/stores/index.ts
337
+ init_utils();
338
+
339
+ // src/core/fetchRequest.ts
340
+ init_utils();
262
341
  function processChunk(chunk, onChunk) {
263
342
  if (onChunk) {
264
343
  onChunk(typeof chunk === "string" ? chunk : JSON.stringify(chunk));
@@ -365,7 +444,7 @@ var put = (url, data = {}, options = {}) => request(url, data, { ...options, met
365
444
  var del = (url, data = {}, options = {}) => request(url, data, { ...options, method: "DELETE" });
366
445
  var fetchRequest_default = { delete: del, get, post, put };
367
446
 
368
- // src/services/index.tsx
447
+ // src/services/index.ts
369
448
  var agentInfoQuery = (agentId) => {
370
449
  return common.request.get("/agent/detail", { agentId });
371
450
  };
@@ -555,7 +634,7 @@ function createChatStore() {
555
634
  });
556
635
  const setAgentParams = (params = {}) => {
557
636
  agent.params = {
558
- thinkMode: 2,
637
+ thinkMode: "2",
559
638
  ...params
560
639
  };
561
640
  };
@@ -843,7 +922,7 @@ var ConversationList_default = () => {
843
922
  chatStore.getConversations(agentState.active.id);
844
923
  }
845
924
  }, [agentState.active.id]);
846
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "height-full scroll-fade-in", id: "scrollableDiv", children: /* @__PURE__ */ jsxRuntime.jsx(
925
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "height-full scroll-fade-in", id: "scrollableDiv", children: conversationsState.list.items.length ? /* @__PURE__ */ jsxRuntime.jsx(
847
926
  InfiniteScroll__default.default,
848
927
  {
849
928
  dataLength: conversationsState.list.items.length,
@@ -880,13 +959,13 @@ var ConversationList_default = () => {
880
959
  }
881
960
  )
882
961
  }
883
- ) }) });
962
+ ) : /* @__PURE__ */ jsxRuntime.jsx(antd.Empty, { description: "\u6682\u65E0\u4F1A\u8BDD\u8BB0\u5F55", image: antd.Empty.PRESENTED_IMAGE_SIMPLE }) }) });
884
963
  };
885
964
  var AgentHeader_default = () => {
886
965
  const chatStore = useChatStore();
887
966
  const agentState = valtio.useSnapshot(chatStore.agent);
888
967
  const configState = valtio.useSnapshot(chatStore.config);
889
- const conversationsState = valtio.useSnapshot(chatStore.conversations);
968
+ valtio.useSnapshot(chatStore.conversations);
890
969
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { justify: "space-between", align: "center", className: styles_module_default.nsAgentHeader, children: [
891
970
  /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { gap: 4, align: "center", children: [
892
971
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -913,7 +992,7 @@ var AgentHeader_default = () => {
913
992
  common.RenderWrapper,
914
993
  {
915
994
  control: configState.layout.headerConversationListBtn,
916
- DefaultComponent: conversationsState.list.items.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(
995
+ DefaultComponent: /* @__PURE__ */ jsxRuntime.jsx(
917
996
  antd.Popover,
918
997
  {
919
998
  getPopupContainer: (e) => e,
@@ -973,6 +1052,7 @@ var MessageRender_default = ({ message: message4, placement }) => {
973
1052
  };
974
1053
 
975
1054
  // src/ui/common/BubbleListItems.tsx
1055
+ init_utils();
976
1056
  init_Context();
977
1057
  function extractThinkContent(content) {
978
1058
  let main = content;
@@ -1194,6 +1274,9 @@ var BubbleListItems_default = ({ avatar = true }) => {
1194
1274
  conversationState.active.key
1195
1275
  );
1196
1276
  };
1277
+
1278
+ // src/components/Attachments.tsx
1279
+ init_utils();
1197
1280
  var Attachments_default = react.forwardRef(({ maxCount, accept, fileSize, fileSizeTip, fileList = [], onChange, extraParams }, ref) => {
1198
1281
  const fileListRef = react.useRef([]);
1199
1282
  const [attachedFiles, setAttachedFiles, getAttachedFiles] = common.useRefState([]);
@@ -1479,9 +1562,9 @@ var ChatSender_default2 = () => {
1479
1562
  antd.Button,
1480
1563
  {
1481
1564
  size: "small",
1482
- color: agentState.params.thinkMode === 1 ? "primary" : "default",
1565
+ color: agentState.params.thinkMode === "1" ? "primary" : "default",
1483
1566
  variant: "filled",
1484
- onClick: () => chatStore.setAgentParams({ thinkMode: agentState.params.thinkMode === 1 ? 2 : 1 }),
1567
+ onClick: () => chatStore.setAgentParams({ thinkMode: agentState.params.thinkMode === "1" ? "2" : "1" }),
1485
1568
  children: "\u6DF1\u5EA6\u601D\u8003"
1486
1569
  }
1487
1570
  ),