@zero-library/chat-copilot 1.0.20 → 1.0.21
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 +40 -65
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.mts +2 -6
- package/dist/index.d.ts +2 -6
- package/dist/index.esm.js +39 -64
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
var icons = require('@ant-design/icons');
|
|
4
4
|
var xV2 = require('@ant-design/x-v2');
|
|
5
5
|
var common = require('@zero-library/common');
|
|
6
|
-
var dayjs = require('dayjs');
|
|
7
6
|
var antd = require('antd');
|
|
8
7
|
var React7 = require('react');
|
|
9
8
|
var valtio = require('valtio');
|
|
10
9
|
var jsxRuntime = require('react/jsx-runtime');
|
|
11
10
|
var classNames2 = require('classnames');
|
|
11
|
+
var dayjs = require('dayjs');
|
|
12
12
|
var InfiniteScroll = require('react-infinite-scroll-component');
|
|
13
13
|
var xCard = require('@ant-design/x-card');
|
|
14
14
|
require('@ant-design/x-markdown/themes/light.css');
|
|
@@ -17,39 +17,14 @@ var Latex = require('@ant-design/x-markdown/plugins/Latex');
|
|
|
17
17
|
|
|
18
18
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
19
|
|
|
20
|
-
var dayjs__default = /*#__PURE__*/_interopDefault(dayjs);
|
|
21
20
|
var React7__default = /*#__PURE__*/_interopDefault(React7);
|
|
22
21
|
var classNames2__default = /*#__PURE__*/_interopDefault(classNames2);
|
|
22
|
+
var dayjs__default = /*#__PURE__*/_interopDefault(dayjs);
|
|
23
23
|
var InfiniteScroll__default = /*#__PURE__*/_interopDefault(InfiniteScroll);
|
|
24
24
|
var XMarkdown__default = /*#__PURE__*/_interopDefault(XMarkdown);
|
|
25
25
|
var Latex__default = /*#__PURE__*/_interopDefault(Latex);
|
|
26
26
|
|
|
27
27
|
// src/components/Attachments.tsx
|
|
28
|
-
var classifyTime = (timestamp) => {
|
|
29
|
-
const now = dayjs__default.default();
|
|
30
|
-
const target = dayjs__default.default(timestamp);
|
|
31
|
-
if (target.isSame(now, "day")) {
|
|
32
|
-
return "\u4ECA\u5929";
|
|
33
|
-
}
|
|
34
|
-
const diffInDays = now.diff(target, "day");
|
|
35
|
-
if (diffInDays < 7) {
|
|
36
|
-
return "\u6700\u8FD1 7 \u5929";
|
|
37
|
-
} else if (diffInDays < 30) {
|
|
38
|
-
return "\u6700\u8FD1 30 \u5929";
|
|
39
|
-
} else if (diffInDays < 180) {
|
|
40
|
-
return "\u6700\u8FD1\u534A\u5E74";
|
|
41
|
-
} else {
|
|
42
|
-
return "\u66F4\u65E9";
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
var getChatSocketUrl = (baseURL, params) => {
|
|
46
|
-
return common.buildUrlParams(params, common.getWebSocketUrl(`${baseURL}/ws`), "comma");
|
|
47
|
-
};
|
|
48
|
-
var isDocument = (fileName) => {
|
|
49
|
-
if (!fileName) return false;
|
|
50
|
-
const ext = common.getFileSuffixName(fileName);
|
|
51
|
-
return ["pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "csv"].includes(ext);
|
|
52
|
-
};
|
|
53
28
|
var ChatContext = React7.createContext(null);
|
|
54
29
|
function ChatProvider({ store, children }) {
|
|
55
30
|
return React7__default.default.createElement(ChatContext.Provider, { value: store }, children);
|
|
@@ -158,21 +133,7 @@ var Attachments_default = React7.forwardRef(({ fileUpload, fileUploadConfig, fil
|
|
|
158
133
|
const uploadedFile = data[0];
|
|
159
134
|
let previewUrl = uploadedFile.id;
|
|
160
135
|
if (uploadedFile.conversationId && uploadedFile.path) {
|
|
161
|
-
|
|
162
|
-
previewUrl = chatStore.config.services.request.getPreviewUrl(
|
|
163
|
-
agentState.agentInfo.id,
|
|
164
|
-
uploadedFile.conversationId,
|
|
165
|
-
uploadedFile.path,
|
|
166
|
-
"preview"
|
|
167
|
-
);
|
|
168
|
-
} else {
|
|
169
|
-
previewUrl = chatStore.config.services.request.getPreviewUrl(
|
|
170
|
-
agentState.agentInfo.id,
|
|
171
|
-
uploadedFile.conversationId,
|
|
172
|
-
uploadedFile.path,
|
|
173
|
-
"download"
|
|
174
|
-
);
|
|
175
|
-
}
|
|
136
|
+
previewUrl = chatStore.config.services.request.getPreviewUrl(agentState.agentInfo.id, uploadedFile.conversationId, uploadedFile.path);
|
|
176
137
|
}
|
|
177
138
|
setAttachedFiles(
|
|
178
139
|
getAttachedFiles().map((f) => {
|
|
@@ -356,6 +317,26 @@ var ChatSender_default = React7.forwardRef(
|
|
|
356
317
|
);
|
|
357
318
|
}
|
|
358
319
|
);
|
|
320
|
+
var classifyTime = (timestamp) => {
|
|
321
|
+
const now = dayjs__default.default();
|
|
322
|
+
const target = dayjs__default.default(timestamp);
|
|
323
|
+
if (target.isSame(now, "day")) {
|
|
324
|
+
return "\u4ECA\u5929";
|
|
325
|
+
}
|
|
326
|
+
const diffInDays = now.diff(target, "day");
|
|
327
|
+
if (diffInDays < 7) {
|
|
328
|
+
return "\u6700\u8FD1 7 \u5929";
|
|
329
|
+
} else if (diffInDays < 30) {
|
|
330
|
+
return "\u6700\u8FD1 30 \u5929";
|
|
331
|
+
} else if (diffInDays < 180) {
|
|
332
|
+
return "\u6700\u8FD1\u534A\u5E74";
|
|
333
|
+
} else {
|
|
334
|
+
return "\u66F4\u65E9";
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
var getChatSocketUrl = (baseURL, params) => {
|
|
338
|
+
return common.buildUrlParams(params, common.getWebSocketUrl(`${baseURL}/ws`), "comma");
|
|
339
|
+
};
|
|
359
340
|
|
|
360
341
|
// src/core/constants.ts
|
|
361
342
|
var CONV_MODE = {
|
|
@@ -395,9 +376,6 @@ var createChatService = (request, config) => {
|
|
|
395
376
|
const cancelMessage = (executionId) => {
|
|
396
377
|
return request.post(`/agents/executions/${executionId}/cancel`);
|
|
397
378
|
};
|
|
398
|
-
const getRecommendQuestions = (params) => {
|
|
399
|
-
return request.post(`/agents/conversations/${params.conversationId}/messages/recommend`, params);
|
|
400
|
-
};
|
|
401
379
|
const getAgentUserInput = (agentId) => {
|
|
402
380
|
return request.get(`/agents/${agentId}/workflow/params`);
|
|
403
381
|
};
|
|
@@ -413,8 +391,8 @@ var createChatService = (request, config) => {
|
|
|
413
391
|
signal
|
|
414
392
|
});
|
|
415
393
|
};
|
|
416
|
-
const getPreviewUrl = (agentId, conversationId, path
|
|
417
|
-
return `${config?.baseURL}/agents/${agentId}/${conversationId}/files
|
|
394
|
+
const getPreviewUrl = (agentId, conversationId, path) => {
|
|
395
|
+
return `${config?.baseURL}/agents/${agentId}/${conversationId}/files/download?path=${encodeURIComponent(path)}&${TOKEN_KEY}=${tokenManager.get()}`;
|
|
418
396
|
};
|
|
419
397
|
const docQuery = (params) => {
|
|
420
398
|
return request.get(`/library/cloud/document?${params}`);
|
|
@@ -440,7 +418,6 @@ var createChatService = (request, config) => {
|
|
|
440
418
|
fetchMessages,
|
|
441
419
|
sendMessageStream,
|
|
442
420
|
cancelMessage,
|
|
443
|
-
getRecommendQuestions,
|
|
444
421
|
getAgentUserInput,
|
|
445
422
|
feedbackUpdate,
|
|
446
423
|
chatUpload,
|
|
@@ -1166,7 +1143,8 @@ function createChatStore() {
|
|
|
1166
1143
|
const acceptMessage = async (newMessage) => {
|
|
1167
1144
|
const conversationId = newMessage.conversationId;
|
|
1168
1145
|
if (!conversation.messages[conversationId]?.message) return;
|
|
1169
|
-
const
|
|
1146
|
+
const isActive = conversation.active.id === conversationId;
|
|
1147
|
+
const canProceed = await config.hooks?.onBeforeAcceptMessage?.(newMessage, isActive);
|
|
1170
1148
|
if (canProceed === false) {
|
|
1171
1149
|
throw new Error("\u64CD\u4F5C\u88AB\u963B\u6B62");
|
|
1172
1150
|
}
|
|
@@ -2188,15 +2166,7 @@ var PreviewLink_default = ({ data, loading, message: message2, ...rest }) => {
|
|
|
2188
2166
|
}
|
|
2189
2167
|
};
|
|
2190
2168
|
const getPreviewFileUrl = (href) => {
|
|
2191
|
-
|
|
2192
|
-
const path = url.searchParams.get("path") || url.pathname;
|
|
2193
|
-
const fileName = getLinkFileName(href);
|
|
2194
|
-
console.log(path, fileName);
|
|
2195
|
-
if (isDocument(fileName)) {
|
|
2196
|
-
return chatStore.config.services.request.getPreviewUrl(message2.agentId, message2.conversationId, path, "preview");
|
|
2197
|
-
} else {
|
|
2198
|
-
return chatStore.config.services.request.getPreviewUrl(message2.agentId, message2.conversationId, path, "download");
|
|
2199
|
-
}
|
|
2169
|
+
return common.buildUrlParams({ [TOKEN_KEY]: tokenManager.get() || "" }, href);
|
|
2200
2170
|
};
|
|
2201
2171
|
const handlePreviewLink = (href) => {
|
|
2202
2172
|
const fileName = getLinkFileName(href);
|
|
@@ -4005,12 +3975,7 @@ var FilesNode = React7__default.default.memo(({ item }) => {
|
|
|
4005
3975
|
const conversationState = valtio.useSnapshot(chatStore.conversation);
|
|
4006
3976
|
const fileItems = React7.useMemo(() => {
|
|
4007
3977
|
return (item.files || []).map((file) => {
|
|
4008
|
-
|
|
4009
|
-
if (isDocument(file.name)) {
|
|
4010
|
-
previewUrl = configState.services.request.getPreviewUrl(agentState.agentInfo.id, conversationState.active.id, file.path, "preview");
|
|
4011
|
-
} else {
|
|
4012
|
-
previewUrl = configState.services.request.getPreviewUrl(agentState.agentInfo.id, conversationState.active.id, file.path, "download");
|
|
4013
|
-
}
|
|
3978
|
+
const previewUrl = configState.services.request.getPreviewUrl(agentState.agentInfo.id, conversationState.active.id, file.path);
|
|
4014
3979
|
let fileType = "file";
|
|
4015
3980
|
const ext = file.ext?.toLowerCase() || "";
|
|
4016
3981
|
if (["jpg", "jpeg", "png", "gif", "bmp", "webp", "svg", "webp"].includes(ext)) {
|
|
@@ -4868,6 +4833,16 @@ var ChatMainPanel = React7.memo(
|
|
|
4868
4833
|
var ChatMainPanel_default = ChatMainPanel;
|
|
4869
4834
|
var ChatPreviewPanel = React7.memo(({ file }) => {
|
|
4870
4835
|
const chatStore = useChatStore();
|
|
4836
|
+
const preview = React7.useMemo(() => {
|
|
4837
|
+
const urlFile = file;
|
|
4838
|
+
if (urlFile.fileUrl) {
|
|
4839
|
+
return {
|
|
4840
|
+
...file,
|
|
4841
|
+
fileUrl: urlFile.fileUrl + "&isPreview=true"
|
|
4842
|
+
};
|
|
4843
|
+
}
|
|
4844
|
+
return file;
|
|
4845
|
+
}, [file]);
|
|
4871
4846
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4872
4847
|
file.fileUrl && /* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { vertical: true, className: "height-full", children: [
|
|
4873
4848
|
/* @__PURE__ */ jsxRuntime.jsxs(antd.Flex, { justify: "space-between", className: styles_module_default5.previewHeader, children: [
|
|
@@ -4885,7 +4860,7 @@ var ChatPreviewPanel = React7.memo(({ file }) => {
|
|
|
4885
4860
|
/* @__PURE__ */ jsxRuntime.jsx(antd.Button, { type: "text", icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CloseOutlined, {}), className: styles_module_default5.actionIcon, onClick: () => chatStore.setPreview() })
|
|
4886
4861
|
] })
|
|
4887
4862
|
] }),
|
|
4888
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "full-scroll", children: /* @__PURE__ */ jsxRuntime.jsx(common.LuyaFilePreview, { ...
|
|
4863
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "full-scroll", children: /* @__PURE__ */ jsxRuntime.jsx(common.LuyaFilePreview, { ...preview }) })
|
|
4889
4864
|
] }),
|
|
4890
4865
|
file.content && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4891
4866
|
common.MarkdownEditor,
|