@zero-library/chat-copilot 1.0.8 → 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 +118 -29
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.mts +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.esm.js +124 -35
- package/dist/index.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs.js
CHANGED
|
@@ -445,6 +445,9 @@ var createChatService = (request, config) => {
|
|
|
445
445
|
const getPreviewUrl = (agentId, conversationId, path) => {
|
|
446
446
|
return `${config?.baseURL}/agents/${agentId}/${conversationId}/files/download?path=${encodeURIComponent(path)}&${TOKEN_KEY}=${tokenManager.get()}`;
|
|
447
447
|
};
|
|
448
|
+
const docQuery = (params) => {
|
|
449
|
+
return request.get(`/library/cloud/document?${params}`);
|
|
450
|
+
};
|
|
448
451
|
return {
|
|
449
452
|
fetchModelList,
|
|
450
453
|
fetchAgentInfo,
|
|
@@ -458,7 +461,8 @@ var createChatService = (request, config) => {
|
|
|
458
461
|
getAgentUserInput,
|
|
459
462
|
feedbackUpdate,
|
|
460
463
|
chatUpload,
|
|
461
|
-
getPreviewUrl
|
|
464
|
+
getPreviewUrl,
|
|
465
|
+
docQuery
|
|
462
466
|
};
|
|
463
467
|
};
|
|
464
468
|
|
|
@@ -1160,7 +1164,7 @@ function createChatStore() {
|
|
|
1160
1164
|
messages.push(finalMsg);
|
|
1161
1165
|
} else {
|
|
1162
1166
|
const prevContent = messages[idx]?.content || [];
|
|
1163
|
-
messages[idx].content = [...prevContent, newMessage.content
|
|
1167
|
+
messages[idx].content = [...prevContent, ...newMessage.content];
|
|
1164
1168
|
}
|
|
1165
1169
|
conversation.messages[newMessage.conversationId].loading = true;
|
|
1166
1170
|
break;
|
|
@@ -2076,6 +2080,45 @@ var FileView_default = ({ data, loading }) => {
|
|
|
2076
2080
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-ellipsis", title: data.fileName, children: data.fileName })
|
|
2077
2081
|
] }) });
|
|
2078
2082
|
};
|
|
2083
|
+
var DocDrawer_default = ({ title, open, onClose, paramsStr }) => {
|
|
2084
|
+
const chatStore = useChatStore();
|
|
2085
|
+
const configState = valtio.useSnapshot(chatStore.config);
|
|
2086
|
+
const [content, setContent] = React6.useState("");
|
|
2087
|
+
const [loading, setLoading] = React6.useState(false);
|
|
2088
|
+
const getContent = async () => {
|
|
2089
|
+
try {
|
|
2090
|
+
setLoading(true);
|
|
2091
|
+
const res = await configState.services.request.docQuery(paramsStr);
|
|
2092
|
+
setContent(res.data?.content || "");
|
|
2093
|
+
} finally {
|
|
2094
|
+
setLoading(false);
|
|
2095
|
+
}
|
|
2096
|
+
};
|
|
2097
|
+
React6.useEffect(() => {
|
|
2098
|
+
getContent();
|
|
2099
|
+
}, [paramsStr]);
|
|
2100
|
+
return /* @__PURE__ */ jsxRuntime.jsx(antd.Drawer, { title, push: false, size: "100%", open, onClose, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { spinning: loading, children: content ? /* @__PURE__ */ jsxRuntime.jsx(XMarkdown__default.default, { content }) : /* @__PURE__ */ jsxRuntime.jsx(antd.Empty, { className: "m-t-32" }) }) });
|
|
2101
|
+
};
|
|
2102
|
+
var IndexQuote_default = ({ data, loading, message: message3 }) => {
|
|
2103
|
+
const [open, setOpen] = React6.useState(false);
|
|
2104
|
+
const citation = React6.useMemo(() => {
|
|
2105
|
+
const citations = message3.content?.find((item) => item.type === "citation")?.citations ?? [];
|
|
2106
|
+
return citations?.find((item) => String(item.citationId) === String(data.citationId));
|
|
2107
|
+
}, [data.citationId, message3.content]);
|
|
2108
|
+
const onClick = () => {
|
|
2109
|
+
if (!citation?.citationUrl) return;
|
|
2110
|
+
if (common.isExternal(citation.citationUrl)) {
|
|
2111
|
+
window.open(citation.citationUrl, "_blank");
|
|
2112
|
+
} else {
|
|
2113
|
+
setOpen(true);
|
|
2114
|
+
}
|
|
2115
|
+
};
|
|
2116
|
+
const Content = /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(antd.Flex, { align: "center", gap: 8, children: /* @__PURE__ */ jsxRuntime.jsx("a", { onClick, children: citation?.citationName }) }) });
|
|
2117
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "inline-block m-l-8", children: [
|
|
2118
|
+
/* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { spinning: loading, size: "small", children: /* @__PURE__ */ jsxRuntime.jsx(antd.Popover, { content: Content, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Tag, { variant: "filled", color: "processing", className: "cursor-pointer", children: data?.citationName }) }) }),
|
|
2119
|
+
open && /* @__PURE__ */ jsxRuntime.jsx(DocDrawer_default, { paramsStr: citation?.citationUrl, title: citation?.citationName, open, onClose: () => setOpen(false) })
|
|
2120
|
+
] });
|
|
2121
|
+
};
|
|
2079
2122
|
var MdEdit_default = ({ data, loading }) => {
|
|
2080
2123
|
const chatStore = useChatStore();
|
|
2081
2124
|
const [value, setValue] = React6.useState("");
|
|
@@ -2133,11 +2176,15 @@ var PreviewLink_default = ({ data, loading, domNode, ...rest }) => {
|
|
|
2133
2176
|
};
|
|
2134
2177
|
return /* @__PURE__ */ jsxRuntime.jsx("a", { ...rest, onClick: handleClick, children: data });
|
|
2135
2178
|
};
|
|
2179
|
+
var Think_default = ({ data }) => {
|
|
2180
|
+
return /* @__PURE__ */ jsxRuntime.jsx(xV2.Think, { title: "\u6DF1\u5EA6\u601D\u8003", className: "m-b-16", children: data });
|
|
2181
|
+
};
|
|
2136
2182
|
|
|
2137
2183
|
// src/components/XMarkdown/styles.module.less
|
|
2138
2184
|
var styles_module_default4 = {
|
|
2139
2185
|
xMarkdownStyle: "styles_module_xMarkdownStyle"
|
|
2140
2186
|
};
|
|
2187
|
+
var MARKDOWN_PAYLOAD_PLACEHOLDER_PREFIX = "XMD_PAYLOAD_";
|
|
2141
2188
|
var singleTildeExtension = {
|
|
2142
2189
|
name: "singleTilde",
|
|
2143
2190
|
level: "inline",
|
|
@@ -2164,44 +2211,86 @@ var getMarkdownConfig = (options) => {
|
|
|
2164
2211
|
breaks: options?.breaks ?? false
|
|
2165
2212
|
};
|
|
2166
2213
|
};
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2214
|
+
function makeMarkdownPayloadPlaceholder(index) {
|
|
2215
|
+
return `${MARKDOWN_PAYLOAD_PLACEHOLDER_PREFIX}${index}`;
|
|
2216
|
+
}
|
|
2217
|
+
function resolveMappedMarkdownPayload(value, payloadMap) {
|
|
2218
|
+
if (common.isString(value)) {
|
|
2219
|
+
if (new RegExp(`^${MARKDOWN_PAYLOAD_PLACEHOLDER_PREFIX}\\d+$`).test(value)) {
|
|
2220
|
+
return common.safeParseJson(payloadMap.get(value), { repair: true });
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
return value;
|
|
2224
|
+
}
|
|
2173
2225
|
function formatMixedContent(content) {
|
|
2174
2226
|
return content.replace(/<!DOCTYPE html>[\s\S]*?<\/html>/gi, (match) => `\`\`\`html
|
|
2175
2227
|
${match}
|
|
2176
2228
|
\`\`\``);
|
|
2177
2229
|
}
|
|
2178
|
-
|
|
2230
|
+
function preprocessCustomTagPayloads(content = "", payloadTagPattern) {
|
|
2231
|
+
let id = 0;
|
|
2232
|
+
const payloadMap = /* @__PURE__ */ new Map();
|
|
2233
|
+
const processedContent = content.replace(
|
|
2234
|
+
new RegExp(`(?<opening><(?<tag>${payloadTagPattern})\\b[^>]*>)(?<inner>[\\s\\S]*?)(?<closing><\\/\\k<tag>\\s*>|$)`, "gi"),
|
|
2235
|
+
(match, _opening, _tag, _inner, _closing, _offset, _source, groups) => {
|
|
2236
|
+
const openingText = groups?.opening ?? "";
|
|
2237
|
+
if (!openingText) {
|
|
2238
|
+
return match;
|
|
2239
|
+
}
|
|
2240
|
+
const innerText = groups?.inner ?? "";
|
|
2241
|
+
const closingText = groups?.closing ?? "";
|
|
2242
|
+
const placeholder = makeMarkdownPayloadPlaceholder(id++);
|
|
2243
|
+
payloadMap.set(placeholder, innerText.trim());
|
|
2244
|
+
return `${openingText}${placeholder}${closingText}`;
|
|
2245
|
+
}
|
|
2246
|
+
);
|
|
2247
|
+
return {
|
|
2248
|
+
content: processedContent,
|
|
2249
|
+
payloadMap
|
|
2250
|
+
};
|
|
2251
|
+
}
|
|
2252
|
+
var adaptMarkdownComponent = (Component, payloadMap = /* @__PURE__ */ new Map(), message3) => {
|
|
2253
|
+
const WrappedComponent = ({ children, streamStatus, ...rest }) => {
|
|
2254
|
+
const rawData = resolveMappedMarkdownPayload(children, payloadMap);
|
|
2255
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { message: message3, ...rest, data: rawData, loading: streamStatus === "loading" });
|
|
2256
|
+
};
|
|
2257
|
+
WrappedComponent.displayName = `AdaptedMarkdownComponent(${Component.displayName || Component.name || "Anonymous"})`;
|
|
2258
|
+
return WrappedComponent;
|
|
2259
|
+
};
|
|
2260
|
+
var adaptMarkdownComponents = (components, payloadMap = /* @__PURE__ */ new Map(), message3) => Object.fromEntries(Object.entries(components ?? {}).map(([key, Component]) => [key, adaptMarkdownComponent(Component, payloadMap, message3)]));
|
|
2261
|
+
var XMarkdown_default = ({ message: message3, components = {}, content = "", ...rest }) => {
|
|
2179
2262
|
const config = React6.useMemo(() => getMarkdownConfig(), []);
|
|
2180
|
-
const
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2263
|
+
const formattedContent = React6.useMemo(() => formatMixedContent(content), [content]);
|
|
2264
|
+
const newComponents = React6.useMemo(
|
|
2265
|
+
() => ({
|
|
2266
|
+
think: Think_default,
|
|
2267
|
+
code: CodeHighlight_default,
|
|
2268
|
+
agentnavigate: AgentNavigate_default,
|
|
2269
|
+
a: PreviewLink_default,
|
|
2270
|
+
appcard: AppCard_default,
|
|
2271
|
+
fileview: FileView_default,
|
|
2272
|
+
charts: Charts_default,
|
|
2273
|
+
indexquote: IndexQuote_default,
|
|
2274
|
+
mdedit: MdEdit_default,
|
|
2275
|
+
fileedit: FileEdit_default,
|
|
2276
|
+
...components
|
|
2277
|
+
}),
|
|
2278
|
+
[components]
|
|
2279
|
+
);
|
|
2280
|
+
const componentKeys = React6.useMemo(() => Object.keys(newComponents), [newComponents]);
|
|
2281
|
+
const payloadTagPattern = React6.useMemo(() => componentKeys.join("|"), [componentKeys]);
|
|
2282
|
+
const { content: processedContent, payloadMap } = React6.useMemo(
|
|
2283
|
+
() => preprocessCustomTagPayloads(formattedContent, payloadTagPattern),
|
|
2284
|
+
[formattedContent, payloadTagPattern]
|
|
2197
2285
|
);
|
|
2286
|
+
const markdownComponents = React6.useMemo(() => adaptMarkdownComponents(newComponents, payloadMap, message3), [componentKeys, message3, payloadMap]);
|
|
2198
2287
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2199
2288
|
XMarkdown__default.default,
|
|
2200
2289
|
{
|
|
2201
2290
|
className: classNames2__default.default("x-markdown-light", styles_module_default4.xMarkdownStyle),
|
|
2202
2291
|
config,
|
|
2203
2292
|
...rest,
|
|
2204
|
-
content:
|
|
2293
|
+
content: processedContent,
|
|
2205
2294
|
components: markdownComponents
|
|
2206
2295
|
}
|
|
2207
2296
|
);
|
|
@@ -2557,7 +2646,7 @@ var Button7 = ({ label, variant = "default", onClick, action, onAction }) => {
|
|
|
2557
2646
|
return /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { type: variant === "primary" ? "primary" : "default", danger: variant === "danger", onClick: handleClick, style: { borderRadius: 8 }, children: label });
|
|
2558
2647
|
};
|
|
2559
2648
|
var Divider = () => /* @__PURE__ */ jsxRuntime.jsx(antd.Divider, { style: { margin: "8px 0" } });
|
|
2560
|
-
var
|
|
2649
|
+
var Tag2 = ({ text, color }) => /* @__PURE__ */ jsxRuntime.jsx(antd.Tag, { color, children: text });
|
|
2561
2650
|
var Progress = ({
|
|
2562
2651
|
percent,
|
|
2563
2652
|
status = "normal",
|
|
@@ -2575,7 +2664,7 @@ var A2uiComponents = {
|
|
|
2575
2664
|
Switch,
|
|
2576
2665
|
Button: Button7,
|
|
2577
2666
|
Divider,
|
|
2578
|
-
Tag,
|
|
2667
|
+
Tag: Tag2,
|
|
2579
2668
|
Progress,
|
|
2580
2669
|
ArtifactCard,
|
|
2581
2670
|
TableViewer,
|