@zero-library/chat-agent 2.0.7 → 2.0.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 +60 -24
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.mts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.esm.js +69 -33
- package/dist/index.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs.js
CHANGED
|
@@ -26,6 +26,19 @@ 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 docQuery, fileCreate;
|
|
30
|
+
var init_file = __esm({
|
|
31
|
+
"src/services/file.ts"() {
|
|
32
|
+
docQuery = (paramsStr) => {
|
|
33
|
+
return common.request.get(`/uc/doc?${paramsStr}`);
|
|
34
|
+
};
|
|
35
|
+
fileCreate = async (fileContent, fileName, targetFormat = "docx") => {
|
|
36
|
+
const blob = await common.request.post(`/uc/doc/convert`, { fileContent, fileName, targetFormat }, { responseType: "blob" });
|
|
37
|
+
const url = URL.createObjectURL(blob);
|
|
38
|
+
common.downloadFile(url, fileName);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
});
|
|
29
42
|
function transform(source, fieldMap) {
|
|
30
43
|
const result = {};
|
|
31
44
|
for (const [targetKey, mapping] of Object.entries(fieldMap)) {
|
|
@@ -152,14 +165,6 @@ var init_FileView = __esm({
|
|
|
152
165
|
};
|
|
153
166
|
}
|
|
154
167
|
});
|
|
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
168
|
var DocDrawer_default;
|
|
164
169
|
var init_DocDrawer = __esm({
|
|
165
170
|
"src/ui/common/markdownAlert/components/DocDrawer.tsx"() {
|
|
@@ -317,6 +322,9 @@ var init_QuoteList = __esm({
|
|
|
317
322
|
}
|
|
318
323
|
});
|
|
319
324
|
|
|
325
|
+
// src/ui/layouts/index.tsx
|
|
326
|
+
init_file();
|
|
327
|
+
|
|
320
328
|
// src/core/constants.ts
|
|
321
329
|
var DEFAULT_NEW_CONV_ID = "newConvId";
|
|
322
330
|
var ChatRoleMap = {
|
|
@@ -392,7 +400,7 @@ async function handleStreamResponse(response, options) {
|
|
|
392
400
|
buffer = parseBuffer(buffer, onChunk);
|
|
393
401
|
}
|
|
394
402
|
}
|
|
395
|
-
async function
|
|
403
|
+
async function request2(url, data = {}, options = {}) {
|
|
396
404
|
const { stream = false, method = "POST", headers = {}, signal } = options;
|
|
397
405
|
const controller = new AbortController();
|
|
398
406
|
signal?.addEventListener("abort", () => controller.abort());
|
|
@@ -429,10 +437,10 @@ async function request(url, data = {}, options = {}) {
|
|
|
429
437
|
}
|
|
430
438
|
return r;
|
|
431
439
|
}
|
|
432
|
-
var get = (url, params = {}, options = {}) =>
|
|
433
|
-
var post = (url, data = {}, options = {}) =>
|
|
434
|
-
var put = (url, data = {}, options = {}) =>
|
|
435
|
-
var del = (url, data = {}, options = {}) =>
|
|
440
|
+
var get = (url, params = {}, options = {}) => request2(url, params, { ...options, method: "GET" });
|
|
441
|
+
var post = (url, data = {}, options = {}) => request2(url, data, { ...options, method: "POST" });
|
|
442
|
+
var put = (url, data = {}, options = {}) => request2(url, data, { ...options, method: "PUT" });
|
|
443
|
+
var del = (url, data = {}, options = {}) => request2(url, data, { ...options, method: "DELETE" });
|
|
436
444
|
var fetchRequest_default = { delete: del, get, post, put };
|
|
437
445
|
|
|
438
446
|
// src/services/index.ts
|
|
@@ -951,7 +959,6 @@ var ConversationList_default = () => {
|
|
|
951
959
|
) : /* @__PURE__ */ jsxRuntime.jsx(antd.Empty, { description: "\u6682\u65E0\u4F1A\u8BDD\u8BB0\u5F55", image: antd.Empty.PRESENTED_IMAGE_SIMPLE }) }) });
|
|
952
960
|
};
|
|
953
961
|
var AgentHeader_default = ({ title = true, closeBtn = false, newConversationBtn = true, conversationListBtn = true }) => {
|
|
954
|
-
console.log("AgentHeader", title, closeBtn, newConversationBtn, conversationListBtn);
|
|
955
962
|
const chatStore = useChatStore();
|
|
956
963
|
const agentState = valtio.useSnapshot(chatStore.agent);
|
|
957
964
|
const configState = valtio.useSnapshot(chatStore.config);
|
|
@@ -1248,17 +1255,37 @@ var BubbleListItems_default = ({ avatar = true }) => {
|
|
|
1248
1255
|
return [...placeholderNode];
|
|
1249
1256
|
}, [chatRecords, questionList, placeholderNode]);
|
|
1250
1257
|
const listRef = react.useRef(null);
|
|
1258
|
+
const autoScrollRef = react.useRef(true);
|
|
1259
|
+
const handleScroll = (el) => {
|
|
1260
|
+
const target = el.target;
|
|
1261
|
+
const distanceToBottom = target.scrollHeight - target.scrollTop - target.clientHeight;
|
|
1262
|
+
autoScrollRef.current = distanceToBottom < 100;
|
|
1263
|
+
};
|
|
1251
1264
|
react.useEffect(() => {
|
|
1252
|
-
|
|
1253
|
-
|
|
1265
|
+
autoScrollRef.current = true;
|
|
1266
|
+
}, [bubbleListItems.length]);
|
|
1267
|
+
react.useEffect(() => {
|
|
1268
|
+
const el = listRef.current?.nativeElement;
|
|
1269
|
+
if (!el || !bubbleListItems.length) return;
|
|
1270
|
+
if (autoScrollRef.current) {
|
|
1271
|
+
setTimeout(() => {
|
|
1272
|
+
if (autoScrollRef.current) {
|
|
1273
|
+
listRef.current?.scrollTo({
|
|
1274
|
+
key: bubbleListItems[bubbleListItems.length - 1].key,
|
|
1275
|
+
block: "end"
|
|
1276
|
+
});
|
|
1277
|
+
}
|
|
1278
|
+
}, 100);
|
|
1254
1279
|
}
|
|
1255
1280
|
}, [bubbleListItems]);
|
|
1256
1281
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1257
1282
|
x.Bubble.List,
|
|
1258
1283
|
{
|
|
1284
|
+
autoScroll: false,
|
|
1259
1285
|
ref: listRef,
|
|
1260
1286
|
items: bubbleListItems,
|
|
1261
|
-
className: classNames6__default.default(styles_module_default.nsBubbleList, "height-full", "scroll-fade-in")
|
|
1287
|
+
className: classNames6__default.default(styles_module_default.nsBubbleList, "height-full", "scroll-fade-in"),
|
|
1288
|
+
onScroll: handleScroll
|
|
1262
1289
|
},
|
|
1263
1290
|
conversationState.active.key
|
|
1264
1291
|
);
|
|
@@ -1698,19 +1725,27 @@ var layouts_default = react.forwardRef(({ theme, params, hooks, layout, defaultA
|
|
|
1698
1725
|
}),
|
|
1699
1726
|
[]
|
|
1700
1727
|
);
|
|
1701
|
-
const setSplitterSizes = (sizes) => {
|
|
1702
|
-
console.log(sizes);
|
|
1703
|
-
};
|
|
1704
1728
|
const hasPreView = react.useMemo(() => {
|
|
1705
1729
|
return common.shouldRender(configState.layout.preview) && (!!configState.preview.file.fileUrl || !!configState.preview.file.content);
|
|
1706
1730
|
}, [configState.layout.preview, configState.preview.file]);
|
|
1731
|
+
const [sizes, setSizes] = react.useState([0, "100%"]);
|
|
1732
|
+
const setSplitterSizes = (sizes2) => {
|
|
1733
|
+
setSizes(sizes2);
|
|
1734
|
+
};
|
|
1735
|
+
react.useEffect(() => {
|
|
1736
|
+
if (hasPreView) {
|
|
1737
|
+
setSplitterSizes(["70%", "30%"]);
|
|
1738
|
+
} else {
|
|
1739
|
+
setSplitterSizes([0, "100%"]);
|
|
1740
|
+
}
|
|
1741
|
+
}, [hasPreView]);
|
|
1707
1742
|
return /* @__PURE__ */ jsxRuntime.jsx(x.XProvider, { theme: { cssVar: true, ...theme }, children: /* @__PURE__ */ jsxRuntime.jsx(ChatProvider, { store: chatStore, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { spinning: agentState.loading, wrapperClassName: "full-spin", children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, className: classNames6__default.default(styles_module_default3.nsChatLayout, "height-full"), children: [
|
|
1708
1743
|
/* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.globalHeader, DefaultComponent: AgentHeader_default }),
|
|
1709
1744
|
/* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { className: "full-scroll", children: [
|
|
1710
1745
|
/* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.leftPanel, DefaultComponent: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {}) }),
|
|
1711
1746
|
/* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.conversationList, DefaultComponent: ConversationListPanel_default }),
|
|
1712
|
-
/* @__PURE__ */ jsxRuntime.jsxs(antd.Splitter, { onResize: setSplitterSizes, children: [
|
|
1713
|
-
|
|
1747
|
+
/* @__PURE__ */ jsxRuntime.jsxs(antd.Splitter, { className: "flex-1", onResize: setSplitterSizes, children: [
|
|
1748
|
+
/* @__PURE__ */ jsxRuntime.jsx(antd.Splitter.Panel, { collapsible: false, min: 600, size: sizes[0], children: hasPreView && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1714
1749
|
configState.preview.file.fileUrl && /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, className: "height-full", children: [
|
|
1715
1750
|
/* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { justify: "space-between", align: "center", gap: 16, className: styles_module_default3.nsPreviewHeader, children: [
|
|
1716
1751
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: styles_module_default3.nsPreviewHeaderTitle, children: configState.preview.file.fileName }),
|
|
@@ -1753,11 +1788,12 @@ var layouts_default = react.forwardRef(({ theme, params, hooks, layout, defaultA
|
|
|
1753
1788
|
}
|
|
1754
1789
|
});
|
|
1755
1790
|
},
|
|
1791
|
+
onDownloadFile: (content, type) => fileCreate(content, configState.preview.file.fileName, type),
|
|
1756
1792
|
extraNav: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(antd.Tag, { bordered: false, color: "default", className: "cursor-pointer", onClick: () => chatStore.setPreview(), children: /* @__PURE__ */ jsxRuntime.jsx(icons.CloseOutlined, {}) }) })
|
|
1757
1793
|
}
|
|
1758
1794
|
)
|
|
1759
|
-
] }),
|
|
1760
|
-
/* @__PURE__ */ jsxRuntime.jsx(antd.Splitter.Panel, { collapsible: false,
|
|
1795
|
+
] }) }),
|
|
1796
|
+
/* @__PURE__ */ jsxRuntime.jsx(antd.Splitter.Panel, { collapsible: false, max: 800, min: 400, size: sizes[1], children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, className: classNames6__default.default("height-full"), children: [
|
|
1761
1797
|
/* @__PURE__ */ jsxRuntime.jsx(common.RenderWrapper, { control: configState.layout.chatHeader, DefaultComponent: AgentHeader_default }),
|
|
1762
1798
|
/* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { vertical: true, className: classNames6__default.default("full-scroll"), children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { justify: "center", vertical: true, gap: 24, className: classNames6__default.default("height-full p-t-8 p-b-8", styles_module_default.nsBodyWidth), children: [
|
|
1763
1799
|
common.shouldRender(configState.layout.messageList) && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "full-scroll", children: /* @__PURE__ */ jsxRuntime.jsx(
|