@zero-library/chat-copilot 1.0.9 → 1.0.11
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.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
|
|
|
@@ -2078,13 +2082,14 @@ var FileView_default = ({ data, loading }) => {
|
|
|
2078
2082
|
};
|
|
2079
2083
|
var DocDrawer_default = ({ title, open, onClose, paramsStr }) => {
|
|
2080
2084
|
const chatStore = useChatStore();
|
|
2081
|
-
valtio.useSnapshot(chatStore.config);
|
|
2085
|
+
const configState = valtio.useSnapshot(chatStore.config);
|
|
2082
2086
|
const [content, setContent] = React6.useState("");
|
|
2083
2087
|
const [loading, setLoading] = React6.useState(false);
|
|
2084
2088
|
const getContent = async () => {
|
|
2085
2089
|
try {
|
|
2086
2090
|
setLoading(true);
|
|
2087
|
-
|
|
2091
|
+
const res = await configState.services.request.docQuery(paramsStr);
|
|
2092
|
+
setContent(res.data?.content || "");
|
|
2088
2093
|
} finally {
|
|
2089
2094
|
setLoading(false);
|
|
2090
2095
|
}
|
|
@@ -2179,6 +2184,7 @@ var Think_default = ({ data }) => {
|
|
|
2179
2184
|
var styles_module_default4 = {
|
|
2180
2185
|
xMarkdownStyle: "styles_module_xMarkdownStyle"
|
|
2181
2186
|
};
|
|
2187
|
+
var MARKDOWN_PAYLOAD_PLACEHOLDER_PREFIX = "XMD_PAYLOAD_";
|
|
2182
2188
|
var singleTildeExtension = {
|
|
2183
2189
|
name: "singleTilde",
|
|
2184
2190
|
level: "inline",
|
|
@@ -2205,45 +2211,86 @@ var getMarkdownConfig = (options) => {
|
|
|
2205
2211
|
breaks: options?.breaks ?? false
|
|
2206
2212
|
};
|
|
2207
2213
|
};
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
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
|
+
}
|
|
2214
2225
|
function formatMixedContent(content) {
|
|
2215
2226
|
return content.replace(/<!DOCTYPE html>[\s\S]*?<\/html>/gi, (match) => `\`\`\`html
|
|
2216
2227
|
${match}
|
|
2217
2228
|
\`\`\``);
|
|
2218
2229
|
}
|
|
2219
|
-
|
|
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 }) => {
|
|
2220
2262
|
const config = React6.useMemo(() => getMarkdownConfig(), []);
|
|
2221
|
-
const
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
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]
|
|
2239
2285
|
);
|
|
2286
|
+
const markdownComponents = React6.useMemo(() => adaptMarkdownComponents(newComponents, payloadMap, message3), [componentKeys, message3, payloadMap]);
|
|
2240
2287
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2241
2288
|
XMarkdown__default.default,
|
|
2242
2289
|
{
|
|
2243
2290
|
className: classNames2__default.default("x-markdown-light", styles_module_default4.xMarkdownStyle),
|
|
2244
2291
|
config,
|
|
2245
2292
|
...rest,
|
|
2246
|
-
content:
|
|
2293
|
+
content: processedContent,
|
|
2247
2294
|
components: markdownComponents
|
|
2248
2295
|
}
|
|
2249
2296
|
);
|