@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.d.mts CHANGED
@@ -162,14 +162,10 @@ declare const createChatService: (request: ReturnType<typeof createRequest>, con
162
162
  fetchMessages: (params: ConversationMessagesQuery) => Promise<R<ConversationMessage[]>>;
163
163
  sendMessageStream: (params: ConversationMessageSend, agentId: string) => Promise<R<ConversationMessage[]>>;
164
164
  cancelMessage: (executionId: string) => Promise<R<string>>;
165
- getRecommendQuestions: (params: {
166
- conversationId: string;
167
- messageId: string;
168
- }) => Promise<R<string[]>>;
169
165
  getAgentUserInput: (agentId: string) => Promise<R<UserInputType>>;
170
166
  feedbackUpdate: (params: FeedbackUpdate) => Promise<R<null>>;
171
167
  chatUpload: (agentId: string, data: FormData, conversationId: string, signal?: AbortSignal) => Promise<R<InputFile[]>>;
172
- getPreviewUrl: (agentId: string, conversationId: string, path: string, type: string) => string;
168
+ getPreviewUrl: (agentId: string, conversationId: string, path: string) => string;
173
169
  docQuery: (params: string) => Promise<R<DocType>>;
174
170
  listSkills: (params?: ListSkillReq) => Promise<R<Skill[]>>;
175
171
  listLibrarys: (params?: ListLibraryReq) => Promise<R<Library[]>>;
@@ -1128,7 +1124,7 @@ interface ChatHooks {
1128
1124
  * return true
1129
1125
  * }
1130
1126
  */
1131
- onBeforeAcceptMessage?: (message: ConversationMessage) => boolean | Promise<boolean> | void;
1127
+ onBeforeAcceptMessage?: (message: ConversationMessage, isActive: boolean) => boolean | Promise<boolean> | void;
1132
1128
  /**
1133
1129
  * 在接收到WebSocket消息并处理完成后调用
1134
1130
  *
package/dist/index.d.ts CHANGED
@@ -162,14 +162,10 @@ declare const createChatService: (request: ReturnType<typeof createRequest>, con
162
162
  fetchMessages: (params: ConversationMessagesQuery) => Promise<R<ConversationMessage[]>>;
163
163
  sendMessageStream: (params: ConversationMessageSend, agentId: string) => Promise<R<ConversationMessage[]>>;
164
164
  cancelMessage: (executionId: string) => Promise<R<string>>;
165
- getRecommendQuestions: (params: {
166
- conversationId: string;
167
- messageId: string;
168
- }) => Promise<R<string[]>>;
169
165
  getAgentUserInput: (agentId: string) => Promise<R<UserInputType>>;
170
166
  feedbackUpdate: (params: FeedbackUpdate) => Promise<R<null>>;
171
167
  chatUpload: (agentId: string, data: FormData, conversationId: string, signal?: AbortSignal) => Promise<R<InputFile[]>>;
172
- getPreviewUrl: (agentId: string, conversationId: string, path: string, type: string) => string;
168
+ getPreviewUrl: (agentId: string, conversationId: string, path: string) => string;
173
169
  docQuery: (params: string) => Promise<R<DocType>>;
174
170
  listSkills: (params?: ListSkillReq) => Promise<R<Skill[]>>;
175
171
  listLibrarys: (params?: ListLibraryReq) => Promise<R<Library[]>>;
@@ -1128,7 +1124,7 @@ interface ChatHooks {
1128
1124
  * return true
1129
1125
  * }
1130
1126
  */
1131
- onBeforeAcceptMessage?: (message: ConversationMessage) => boolean | Promise<boolean> | void;
1127
+ onBeforeAcceptMessage?: (message: ConversationMessage, isActive: boolean) => boolean | Promise<boolean> | void;
1132
1128
  /**
1133
1129
  * 在接收到WebSocket消息并处理完成后调用
1134
1130
  *
package/dist/index.esm.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { CloudUploadOutlined, PaperClipOutlined, createFromIconfontCN, LoadingOutlined, EnterOutlined, DownloadOutlined, CloseOutlined, CopyOutlined, LikeOutlined, DislikeOutlined, ToolOutlined, PlayCircleOutlined, DotChartOutlined, SearchOutlined, UpOutlined, DownOutlined, PlusOutlined, CommentOutlined, RedoOutlined, DeleteOutlined, ClockCircleOutlined, CheckCircleOutlined } from '@ant-design/icons';
2
2
  import { Attachments, Sender, Think, FileCard, Bubble, XProvider, Mermaid, CodeHighlighter, Welcome, Prompts, Conversations } from '@ant-design/x-v2';
3
3
  import { useRefState, useDebounce, useSyncInput, createTokenManager, isEmptyObj, markdownToText, RenderWrapper, shouldRender, isFunction, downloadFile, LuyaFilePreview, MarkdownEditor, useDeepEffect, isObject, useWebSocket, isNullOrUnDef, isNumber, getFileSuffixName, isBoolean, UserAvatar, htmlToMarkdown, copyText, FileIcon, LazyComponent, deepCopy, transforms, deepMerge, buildUrlParams, createRequest, HttpStatus, isArray, isString, isExternal, transform, emit, getWebSocketUrl, safeParseJson } from '@zero-library/common';
4
- import dayjs from 'dayjs';
5
4
  import { App, Badge, Button, Flex, Typography, Tooltip, Layout, Tag, Spin, Splitter, theme, Collapse, Divider as Divider$1, Select as Select$1, Avatar, Space, Popover, Skeleton, Alert, Modal, Checkbox, Input, Empty, message, List, Drawer, Card, Table, Progress as Progress$1, Switch as Switch$1 } from 'antd';
6
5
  import React7, { createContext, forwardRef, useRef, useEffect, useImperativeHandle, useMemo, memo, useState, useContext, useCallback } from 'react';
7
6
  import { useSnapshot, proxy } from 'valtio';
8
7
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
9
8
  import classNames2 from 'classnames';
9
+ import dayjs from 'dayjs';
10
10
  import InfiniteScroll from 'react-infinite-scroll-component';
11
11
  import { XCard as XCard$1 } from '@ant-design/x-card';
12
12
  import '@ant-design/x-markdown/themes/light.css';
@@ -14,31 +14,6 @@ import XMarkdown from '@ant-design/x-markdown';
14
14
  import Latex from '@ant-design/x-markdown/plugins/Latex';
15
15
 
16
16
  // src/components/Attachments.tsx
17
- var classifyTime = (timestamp) => {
18
- const now = dayjs();
19
- const target = dayjs(timestamp);
20
- if (target.isSame(now, "day")) {
21
- return "\u4ECA\u5929";
22
- }
23
- const diffInDays = now.diff(target, "day");
24
- if (diffInDays < 7) {
25
- return "\u6700\u8FD1 7 \u5929";
26
- } else if (diffInDays < 30) {
27
- return "\u6700\u8FD1 30 \u5929";
28
- } else if (diffInDays < 180) {
29
- return "\u6700\u8FD1\u534A\u5E74";
30
- } else {
31
- return "\u66F4\u65E9";
32
- }
33
- };
34
- var getChatSocketUrl = (baseURL, params) => {
35
- return buildUrlParams(params, getWebSocketUrl(`${baseURL}/ws`), "comma");
36
- };
37
- var isDocument = (fileName) => {
38
- if (!fileName) return false;
39
- const ext = getFileSuffixName(fileName);
40
- return ["pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "csv"].includes(ext);
41
- };
42
17
  var ChatContext = createContext(null);
43
18
  function ChatProvider({ store, children }) {
44
19
  return React7.createElement(ChatContext.Provider, { value: store }, children);
@@ -147,21 +122,7 @@ var Attachments_default = forwardRef(({ fileUpload, fileUploadConfig, fileList =
147
122
  const uploadedFile = data[0];
148
123
  let previewUrl = uploadedFile.id;
149
124
  if (uploadedFile.conversationId && uploadedFile.path) {
150
- if (isDocument(uploadedFile.name)) {
151
- previewUrl = chatStore.config.services.request.getPreviewUrl(
152
- agentState.agentInfo.id,
153
- uploadedFile.conversationId,
154
- uploadedFile.path,
155
- "preview"
156
- );
157
- } else {
158
- previewUrl = chatStore.config.services.request.getPreviewUrl(
159
- agentState.agentInfo.id,
160
- uploadedFile.conversationId,
161
- uploadedFile.path,
162
- "download"
163
- );
164
- }
125
+ previewUrl = chatStore.config.services.request.getPreviewUrl(agentState.agentInfo.id, uploadedFile.conversationId, uploadedFile.path);
165
126
  }
166
127
  setAttachedFiles(
167
128
  getAttachedFiles().map((f) => {
@@ -345,6 +306,26 @@ var ChatSender_default = forwardRef(
345
306
  );
346
307
  }
347
308
  );
309
+ var classifyTime = (timestamp) => {
310
+ const now = dayjs();
311
+ const target = dayjs(timestamp);
312
+ if (target.isSame(now, "day")) {
313
+ return "\u4ECA\u5929";
314
+ }
315
+ const diffInDays = now.diff(target, "day");
316
+ if (diffInDays < 7) {
317
+ return "\u6700\u8FD1 7 \u5929";
318
+ } else if (diffInDays < 30) {
319
+ return "\u6700\u8FD1 30 \u5929";
320
+ } else if (diffInDays < 180) {
321
+ return "\u6700\u8FD1\u534A\u5E74";
322
+ } else {
323
+ return "\u66F4\u65E9";
324
+ }
325
+ };
326
+ var getChatSocketUrl = (baseURL, params) => {
327
+ return buildUrlParams(params, getWebSocketUrl(`${baseURL}/ws`), "comma");
328
+ };
348
329
 
349
330
  // src/core/constants.ts
350
331
  var CONV_MODE = {
@@ -384,9 +365,6 @@ var createChatService = (request, config) => {
384
365
  const cancelMessage = (executionId) => {
385
366
  return request.post(`/agents/executions/${executionId}/cancel`);
386
367
  };
387
- const getRecommendQuestions = (params) => {
388
- return request.post(`/agents/conversations/${params.conversationId}/messages/recommend`, params);
389
- };
390
368
  const getAgentUserInput = (agentId) => {
391
369
  return request.get(`/agents/${agentId}/workflow/params`);
392
370
  };
@@ -402,8 +380,8 @@ var createChatService = (request, config) => {
402
380
  signal
403
381
  });
404
382
  };
405
- const getPreviewUrl = (agentId, conversationId, path, type) => {
406
- return `${config?.baseURL}/agents/${agentId}/${conversationId}/files/${type}?path=${encodeURIComponent(path)}&${TOKEN_KEY}=${tokenManager.get()}`;
383
+ const getPreviewUrl = (agentId, conversationId, path) => {
384
+ return `${config?.baseURL}/agents/${agentId}/${conversationId}/files/download?path=${encodeURIComponent(path)}&${TOKEN_KEY}=${tokenManager.get()}`;
407
385
  };
408
386
  const docQuery = (params) => {
409
387
  return request.get(`/library/cloud/document?${params}`);
@@ -429,7 +407,6 @@ var createChatService = (request, config) => {
429
407
  fetchMessages,
430
408
  sendMessageStream,
431
409
  cancelMessage,
432
- getRecommendQuestions,
433
410
  getAgentUserInput,
434
411
  feedbackUpdate,
435
412
  chatUpload,
@@ -1155,7 +1132,8 @@ function createChatStore() {
1155
1132
  const acceptMessage = async (newMessage) => {
1156
1133
  const conversationId = newMessage.conversationId;
1157
1134
  if (!conversation.messages[conversationId]?.message) return;
1158
- const canProceed = await config.hooks?.onBeforeAcceptMessage?.(newMessage);
1135
+ const isActive = conversation.active.id === conversationId;
1136
+ const canProceed = await config.hooks?.onBeforeAcceptMessage?.(newMessage, isActive);
1159
1137
  if (canProceed === false) {
1160
1138
  throw new Error("\u64CD\u4F5C\u88AB\u963B\u6B62");
1161
1139
  }
@@ -2177,15 +2155,7 @@ var PreviewLink_default = ({ data, loading, message: message2, ...rest }) => {
2177
2155
  }
2178
2156
  };
2179
2157
  const getPreviewFileUrl = (href) => {
2180
- const url = new URL(href, window.location.origin);
2181
- const path = url.searchParams.get("path") || url.pathname;
2182
- const fileName = getLinkFileName(href);
2183
- console.log(path, fileName);
2184
- if (isDocument(fileName)) {
2185
- return chatStore.config.services.request.getPreviewUrl(message2.agentId, message2.conversationId, path, "preview");
2186
- } else {
2187
- return chatStore.config.services.request.getPreviewUrl(message2.agentId, message2.conversationId, path, "download");
2188
- }
2158
+ return buildUrlParams({ [TOKEN_KEY]: tokenManager.get() || "" }, href);
2189
2159
  };
2190
2160
  const handlePreviewLink = (href) => {
2191
2161
  const fileName = getLinkFileName(href);
@@ -3994,12 +3964,7 @@ var FilesNode = React7.memo(({ item }) => {
3994
3964
  const conversationState = useSnapshot(chatStore.conversation);
3995
3965
  const fileItems = useMemo(() => {
3996
3966
  return (item.files || []).map((file) => {
3997
- let previewUrl = file.id;
3998
- if (isDocument(file.name)) {
3999
- previewUrl = configState.services.request.getPreviewUrl(agentState.agentInfo.id, conversationState.active.id, file.path, "preview");
4000
- } else {
4001
- previewUrl = configState.services.request.getPreviewUrl(agentState.agentInfo.id, conversationState.active.id, file.path, "download");
4002
- }
3967
+ const previewUrl = configState.services.request.getPreviewUrl(agentState.agentInfo.id, conversationState.active.id, file.path);
4003
3968
  let fileType = "file";
4004
3969
  const ext = file.ext?.toLowerCase() || "";
4005
3970
  if (["jpg", "jpeg", "png", "gif", "bmp", "webp", "svg", "webp"].includes(ext)) {
@@ -4857,6 +4822,16 @@ var ChatMainPanel = memo(
4857
4822
  var ChatMainPanel_default = ChatMainPanel;
4858
4823
  var ChatPreviewPanel = memo(({ file }) => {
4859
4824
  const chatStore = useChatStore();
4825
+ const preview = useMemo(() => {
4826
+ const urlFile = file;
4827
+ if (urlFile.fileUrl) {
4828
+ return {
4829
+ ...file,
4830
+ fileUrl: urlFile.fileUrl + "&isPreview=true"
4831
+ };
4832
+ }
4833
+ return file;
4834
+ }, [file]);
4860
4835
  return /* @__PURE__ */ jsxs(Fragment, { children: [
4861
4836
  file.fileUrl && /* @__PURE__ */ jsxs(Flex, { vertical: true, className: "height-full", children: [
4862
4837
  /* @__PURE__ */ jsxs(Flex, { justify: "space-between", className: styles_module_default5.previewHeader, children: [
@@ -4874,7 +4849,7 @@ var ChatPreviewPanel = memo(({ file }) => {
4874
4849
  /* @__PURE__ */ jsx(Button, { type: "text", icon: /* @__PURE__ */ jsx(CloseOutlined, {}), className: styles_module_default5.actionIcon, onClick: () => chatStore.setPreview() })
4875
4850
  ] })
4876
4851
  ] }),
4877
- /* @__PURE__ */ jsx("div", { className: "full-scroll", children: /* @__PURE__ */ jsx(LuyaFilePreview, { ...file }) })
4852
+ /* @__PURE__ */ jsx("div", { className: "full-scroll", children: /* @__PURE__ */ jsx(LuyaFilePreview, { ...preview }) })
4878
4853
  ] }),
4879
4854
  file.content && /* @__PURE__ */ jsx(
4880
4855
  MarkdownEditor,