@zero-library/chat-copilot 1.0.9 → 1.0.10
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 +76 -29
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.mts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.esm.js +80 -33
- package/dist/index.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -163,6 +163,7 @@ declare const createChatService: (request: ReturnType<typeof createRequest>, con
|
|
|
163
163
|
feedbackUpdate: (params: FeedbackUpdate) => Promise<R<null>>;
|
|
164
164
|
chatUpload: (agentId: string, data: FormData, conversationId: string, signal?: AbortSignal) => Promise<R<InputFile[]>>;
|
|
165
165
|
getPreviewUrl: (agentId: string, conversationId: string, path: string) => string;
|
|
166
|
+
docQuery: (params: string) => Promise<R<DocType>>;
|
|
166
167
|
};
|
|
167
168
|
|
|
168
169
|
type RequestInstance = ReturnType<typeof createChatService>;
|
|
@@ -1480,6 +1481,25 @@ interface ProviderModel {
|
|
|
1480
1481
|
icon?: string;
|
|
1481
1482
|
models: Model[];
|
|
1482
1483
|
}
|
|
1484
|
+
/**
|
|
1485
|
+
* 文档类型接口
|
|
1486
|
+
*/
|
|
1487
|
+
interface DocType {
|
|
1488
|
+
/** 文档内容 */
|
|
1489
|
+
content: string;
|
|
1490
|
+
/** 文档唯一标识 */
|
|
1491
|
+
docId: string;
|
|
1492
|
+
/** 文档关键字列表 */
|
|
1493
|
+
keywords?: string[];
|
|
1494
|
+
/** 文档位置 */
|
|
1495
|
+
position?: number;
|
|
1496
|
+
/** 文档分段ID */
|
|
1497
|
+
sid?: string;
|
|
1498
|
+
/** 文档令牌数量 */
|
|
1499
|
+
tokens?: number;
|
|
1500
|
+
/** 文档字数 */
|
|
1501
|
+
wordCount?: number;
|
|
1502
|
+
}
|
|
1483
1503
|
|
|
1484
1504
|
/**
|
|
1485
1505
|
* 附件组件属性接口
|
package/dist/index.d.ts
CHANGED
|
@@ -163,6 +163,7 @@ declare const createChatService: (request: ReturnType<typeof createRequest>, con
|
|
|
163
163
|
feedbackUpdate: (params: FeedbackUpdate) => Promise<R<null>>;
|
|
164
164
|
chatUpload: (agentId: string, data: FormData, conversationId: string, signal?: AbortSignal) => Promise<R<InputFile[]>>;
|
|
165
165
|
getPreviewUrl: (agentId: string, conversationId: string, path: string) => string;
|
|
166
|
+
docQuery: (params: string) => Promise<R<DocType>>;
|
|
166
167
|
};
|
|
167
168
|
|
|
168
169
|
type RequestInstance = ReturnType<typeof createChatService>;
|
|
@@ -1480,6 +1481,25 @@ interface ProviderModel {
|
|
|
1480
1481
|
icon?: string;
|
|
1481
1482
|
models: Model[];
|
|
1482
1483
|
}
|
|
1484
|
+
/**
|
|
1485
|
+
* 文档类型接口
|
|
1486
|
+
*/
|
|
1487
|
+
interface DocType {
|
|
1488
|
+
/** 文档内容 */
|
|
1489
|
+
content: string;
|
|
1490
|
+
/** 文档唯一标识 */
|
|
1491
|
+
docId: string;
|
|
1492
|
+
/** 文档关键字列表 */
|
|
1493
|
+
keywords?: string[];
|
|
1494
|
+
/** 文档位置 */
|
|
1495
|
+
position?: number;
|
|
1496
|
+
/** 文档分段ID */
|
|
1497
|
+
sid?: string;
|
|
1498
|
+
/** 文档令牌数量 */
|
|
1499
|
+
tokens?: number;
|
|
1500
|
+
/** 文档字数 */
|
|
1501
|
+
wordCount?: number;
|
|
1502
|
+
}
|
|
1483
1503
|
|
|
1484
1504
|
/**
|
|
1485
1505
|
* 附件组件属性接口
|
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CloudUploadOutlined, PaperClipOutlined, LoadingOutlined, createFromIconfontCN, EnterOutlined, DownloadOutlined, CloseOutlined, PlusOutlined, CommentOutlined, FileTextOutlined, CopyOutlined, LikeOutlined, DislikeOutlined, ToolOutlined,
|
|
2
|
-
import { Attachments, Sender, Think, FileCard, Bubble, XProvider,
|
|
3
|
-
import { useRefState, useDebounce, useSyncInput, createTokenManager, isEmptyObj, markdownToText, RenderWrapper, shouldRender, isFunction, downloadFile, LuyaFilePreview, MarkdownEditor, useDeepEffect, isObject, useWebSocket, isNullOrUnDef, isNumber, getFileSuffixName, isBoolean, UserAvatar, htmlToMarkdown, copyText, deepCopy, transforms, deepMerge, buildUrlParams, createRequest, HttpStatus, isArray, isString,
|
|
4
|
-
import { App, Badge, Button, Flex, Typography, Tooltip, Tag, Spin, Splitter, theme, Collapse, Avatar, Space, Popover, Form, Empty, Input, InputNumber, Switch as Switch$1, message, List,
|
|
1
|
+
import { CloudUploadOutlined, PaperClipOutlined, LoadingOutlined, createFromIconfontCN, EnterOutlined, DownloadOutlined, CloseOutlined, PlusOutlined, CommentOutlined, FileTextOutlined, CopyOutlined, LikeOutlined, DislikeOutlined, ToolOutlined, PlayCircleOutlined, DotChartOutlined, RedoOutlined, DeleteOutlined, ClockCircleOutlined, CheckCircleOutlined } from '@ant-design/icons';
|
|
2
|
+
import { Attachments, Sender, Think, FileCard, Bubble, XProvider, Mermaid, CodeHighlighter, Conversations, Welcome, Prompts } from '@ant-design/x-v2';
|
|
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, formatSize, isDef, isNull, transform, emit, getWebSocketUrl, safeParseJson } from '@zero-library/common';
|
|
4
|
+
import { App, Badge, Button, Flex, Typography, Tooltip, Tag, Spin, Splitter, theme, Collapse, Avatar, Space, Popover, Form, Skeleton, Alert, Empty, Input, InputNumber, Switch as Switch$1, message, List, Drawer, Upload, Card, Table, Progress as Progress$1, Divider as Divider$1, Select as Select$1 } from 'antd';
|
|
5
5
|
import React6, { createContext, forwardRef, useRef, useEffect, useImperativeHandle, useMemo, memo, useState, useContext, useCallback } from 'react';
|
|
6
6
|
import { useSnapshot, proxy } from 'valtio';
|
|
7
7
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
@@ -434,6 +434,9 @@ var createChatService = (request, config) => {
|
|
|
434
434
|
const getPreviewUrl = (agentId, conversationId, path) => {
|
|
435
435
|
return `${config?.baseURL}/agents/${agentId}/${conversationId}/files/download?path=${encodeURIComponent(path)}&${TOKEN_KEY}=${tokenManager.get()}`;
|
|
436
436
|
};
|
|
437
|
+
const docQuery = (params) => {
|
|
438
|
+
return request.get(`/library/cloud/document?${params}`);
|
|
439
|
+
};
|
|
437
440
|
return {
|
|
438
441
|
fetchModelList,
|
|
439
442
|
fetchAgentInfo,
|
|
@@ -447,7 +450,8 @@ var createChatService = (request, config) => {
|
|
|
447
450
|
getAgentUserInput,
|
|
448
451
|
feedbackUpdate,
|
|
449
452
|
chatUpload,
|
|
450
|
-
getPreviewUrl
|
|
453
|
+
getPreviewUrl,
|
|
454
|
+
docQuery
|
|
451
455
|
};
|
|
452
456
|
};
|
|
453
457
|
|
|
@@ -2067,13 +2071,14 @@ var FileView_default = ({ data, loading }) => {
|
|
|
2067
2071
|
};
|
|
2068
2072
|
var DocDrawer_default = ({ title, open, onClose, paramsStr }) => {
|
|
2069
2073
|
const chatStore = useChatStore();
|
|
2070
|
-
useSnapshot(chatStore.config);
|
|
2074
|
+
const configState = useSnapshot(chatStore.config);
|
|
2071
2075
|
const [content, setContent] = useState("");
|
|
2072
2076
|
const [loading, setLoading] = useState(false);
|
|
2073
2077
|
const getContent = async () => {
|
|
2074
2078
|
try {
|
|
2075
2079
|
setLoading(true);
|
|
2076
|
-
|
|
2080
|
+
const res = await configState.services.request.docQuery(paramsStr);
|
|
2081
|
+
setContent(res.data?.content || "");
|
|
2077
2082
|
} finally {
|
|
2078
2083
|
setLoading(false);
|
|
2079
2084
|
}
|
|
@@ -2168,6 +2173,7 @@ var Think_default = ({ data }) => {
|
|
|
2168
2173
|
var styles_module_default4 = {
|
|
2169
2174
|
xMarkdownStyle: "styles_module_xMarkdownStyle"
|
|
2170
2175
|
};
|
|
2176
|
+
var MARKDOWN_PAYLOAD_PLACEHOLDER_PREFIX = "XMD_PAYLOAD_";
|
|
2171
2177
|
var singleTildeExtension = {
|
|
2172
2178
|
name: "singleTilde",
|
|
2173
2179
|
level: "inline",
|
|
@@ -2194,45 +2200,86 @@ var getMarkdownConfig = (options) => {
|
|
|
2194
2200
|
breaks: options?.breaks ?? false
|
|
2195
2201
|
};
|
|
2196
2202
|
};
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
+
function makeMarkdownPayloadPlaceholder(index) {
|
|
2204
|
+
return `${MARKDOWN_PAYLOAD_PLACEHOLDER_PREFIX}${index}`;
|
|
2205
|
+
}
|
|
2206
|
+
function resolveMappedMarkdownPayload(value, payloadMap) {
|
|
2207
|
+
if (isString(value)) {
|
|
2208
|
+
if (new RegExp(`^${MARKDOWN_PAYLOAD_PLACEHOLDER_PREFIX}\\d+$`).test(value)) {
|
|
2209
|
+
return safeParseJson(payloadMap.get(value), { repair: true });
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
return value;
|
|
2213
|
+
}
|
|
2203
2214
|
function formatMixedContent(content) {
|
|
2204
2215
|
return content.replace(/<!DOCTYPE html>[\s\S]*?<\/html>/gi, (match) => `\`\`\`html
|
|
2205
2216
|
${match}
|
|
2206
2217
|
\`\`\``);
|
|
2207
2218
|
}
|
|
2208
|
-
|
|
2219
|
+
function preprocessCustomTagPayloads(content = "", payloadTagPattern) {
|
|
2220
|
+
let id = 0;
|
|
2221
|
+
const payloadMap = /* @__PURE__ */ new Map();
|
|
2222
|
+
const processedContent = content.replace(
|
|
2223
|
+
new RegExp(`(?<opening><(?<tag>${payloadTagPattern})\\b[^>]*>)(?<inner>[\\s\\S]*?)(?<closing><\\/\\k<tag>\\s*>|$)`, "gi"),
|
|
2224
|
+
(match, _opening, _tag, _inner, _closing, _offset, _source, groups) => {
|
|
2225
|
+
const openingText = groups?.opening ?? "";
|
|
2226
|
+
if (!openingText) {
|
|
2227
|
+
return match;
|
|
2228
|
+
}
|
|
2229
|
+
const innerText = groups?.inner ?? "";
|
|
2230
|
+
const closingText = groups?.closing ?? "";
|
|
2231
|
+
const placeholder = makeMarkdownPayloadPlaceholder(id++);
|
|
2232
|
+
payloadMap.set(placeholder, innerText.trim());
|
|
2233
|
+
return `${openingText}${placeholder}${closingText}`;
|
|
2234
|
+
}
|
|
2235
|
+
);
|
|
2236
|
+
return {
|
|
2237
|
+
content: processedContent,
|
|
2238
|
+
payloadMap
|
|
2239
|
+
};
|
|
2240
|
+
}
|
|
2241
|
+
var adaptMarkdownComponent = (Component, payloadMap = /* @__PURE__ */ new Map(), message3) => {
|
|
2242
|
+
const WrappedComponent = ({ children, streamStatus, ...rest }) => {
|
|
2243
|
+
const rawData = resolveMappedMarkdownPayload(children, payloadMap);
|
|
2244
|
+
return /* @__PURE__ */ jsx(Component, { message: message3, ...rest, data: rawData, loading: streamStatus === "loading" });
|
|
2245
|
+
};
|
|
2246
|
+
WrappedComponent.displayName = `AdaptedMarkdownComponent(${Component.displayName || Component.name || "Anonymous"})`;
|
|
2247
|
+
return WrappedComponent;
|
|
2248
|
+
};
|
|
2249
|
+
var adaptMarkdownComponents = (components, payloadMap = /* @__PURE__ */ new Map(), message3) => Object.fromEntries(Object.entries(components ?? {}).map(([key, Component]) => [key, adaptMarkdownComponent(Component, payloadMap, message3)]));
|
|
2250
|
+
var XMarkdown_default = ({ message: message3, components = {}, content = "", ...rest }) => {
|
|
2209
2251
|
const config = useMemo(() => getMarkdownConfig(), []);
|
|
2210
|
-
const
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2252
|
+
const formattedContent = useMemo(() => formatMixedContent(content), [content]);
|
|
2253
|
+
const newComponents = useMemo(
|
|
2254
|
+
() => ({
|
|
2255
|
+
think: Think_default,
|
|
2256
|
+
code: CodeHighlight_default,
|
|
2257
|
+
agentnavigate: AgentNavigate_default,
|
|
2258
|
+
a: PreviewLink_default,
|
|
2259
|
+
appcard: AppCard_default,
|
|
2260
|
+
fileview: FileView_default,
|
|
2261
|
+
charts: Charts_default,
|
|
2262
|
+
indexquote: IndexQuote_default,
|
|
2263
|
+
mdedit: MdEdit_default,
|
|
2264
|
+
fileedit: FileEdit_default,
|
|
2265
|
+
...components
|
|
2266
|
+
}),
|
|
2267
|
+
[components]
|
|
2268
|
+
);
|
|
2269
|
+
const componentKeys = useMemo(() => Object.keys(newComponents), [newComponents]);
|
|
2270
|
+
const payloadTagPattern = useMemo(() => componentKeys.join("|"), [componentKeys]);
|
|
2271
|
+
const { content: processedContent, payloadMap } = useMemo(
|
|
2272
|
+
() => preprocessCustomTagPayloads(formattedContent, payloadTagPattern),
|
|
2273
|
+
[formattedContent, payloadTagPattern]
|
|
2228
2274
|
);
|
|
2275
|
+
const markdownComponents = useMemo(() => adaptMarkdownComponents(newComponents, payloadMap, message3), [componentKeys, message3, payloadMap]);
|
|
2229
2276
|
return /* @__PURE__ */ jsx(
|
|
2230
2277
|
XMarkdown,
|
|
2231
2278
|
{
|
|
2232
2279
|
className: classNames2("x-markdown-light", styles_module_default4.xMarkdownStyle),
|
|
2233
2280
|
config,
|
|
2234
2281
|
...rest,
|
|
2235
|
-
content:
|
|
2282
|
+
content: processedContent,
|
|
2236
2283
|
components: markdownComponents
|
|
2237
2284
|
}
|
|
2238
2285
|
);
|