@zero-library/chat-copilot 3.1.26 → 3.1.28
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 +79 -39
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +80 -40
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CloudUploadOutlined, PaperClipOutlined, createFromIconfontCN, EnterOutlined, DownloadOutlined, CloseOutlined, PlayCircleOutlined, CopyOutlined, DotChartOutlined, LoadingOutlined, RightOutlined, LikeOutlined, DislikeOutlined, ToolOutlined, SearchOutlined, UpOutlined, DownOutlined, PlusOutlined, CommentOutlined, StarFilled, StarOutlined, ShareAltOutlined, DeleteOutlined, RedoOutlined, ClockCircleOutlined, CheckCircleOutlined, FileImageOutlined, FilePdfOutlined, FileWordOutlined, FileExcelOutlined, FilePptOutlined, FileZipOutlined, FileTextOutlined, FileUnknownOutlined } from '@ant-design/icons';
|
|
2
2
|
import { Attachments, Sender, FileCard, Bubble, Think, XProvider, Mermaid, CodeHighlighter, Welcome, Prompts, Conversations } from '@ant-design/x-v2';
|
|
3
|
-
import { useRefState, useDebounce, createTokenManager, useSyncInput, isEmptyObj, markdownToText, RenderWrapper, shouldRender, isFunction, downloadFile, LuyaFilePreview, MarkdownEditor, useDeepEffect, useWebSocket, isObject, isNullOrUnDef, isNumber, getFileSuffixName, emit, FileIcon, copyText, LazyComponent, isBoolean, UserAvatar, htmlToMarkdown, buildUrlParams, isExternal, transforms,
|
|
3
|
+
import { useRefState, useDebounce, createTokenManager, useSyncInput, isEmptyObj, markdownToText, RenderWrapper, shouldRender, isFunction, downloadFile, LuyaFilePreview, MarkdownEditor, useDeepEffect, useWebSocket, isObject, isNullOrUnDef, isNumber, getFileSuffixName, emit, FileIcon, copyText, LazyComponent, deepCopy, isBoolean, UserAvatar, htmlToMarkdown, buildUrlParams, isExternal, transforms, deepMerge, createRequest, HttpStatus, isArray, isString, isDef, isNull, transform, getWebSocketUrl, safeParseJson } from '@zero-library/common';
|
|
4
4
|
import { App, Badge, Button, Flex, Typography, Tooltip, Layout, Tag, Spin, Splitter, Image as Image$1, Popover, Skeleton, Alert, theme, Collapse, Divider as Divider$1, Select as Select$1, Avatar, Space, Form, Drawer, Empty, Modal, Checkbox, Input, InputNumber, Switch as Switch$1, message, Tabs, List, Upload, Popconfirm, Card, Table, Progress as Progress$1 } from 'antd';
|
|
5
5
|
import * as React10 from 'react';
|
|
6
6
|
import React10__default, { createContext, forwardRef, useRef, useEffect, useImperativeHandle, useMemo, memo, useState, useContext, useCallback, useLayoutEffect } from 'react';
|
|
@@ -1160,18 +1160,20 @@ function createChatStore() {
|
|
|
1160
1160
|
const agent = proxy({
|
|
1161
1161
|
/** 当前智能体 */
|
|
1162
1162
|
agentInfo: {},
|
|
1163
|
-
model: {
|
|
1164
|
-
modelName: "",
|
|
1165
|
-
providerName: "",
|
|
1166
|
-
reasoning: true
|
|
1167
|
-
},
|
|
1168
1163
|
/** 智能体加载状态 */
|
|
1169
1164
|
loading: false
|
|
1170
1165
|
});
|
|
1171
1166
|
const setAgentModel = (updater) => {
|
|
1172
|
-
const
|
|
1173
|
-
|
|
1174
|
-
|
|
1167
|
+
const prevModel = agent.agentInfo.spec?.model || {
|
|
1168
|
+
modelName: "",
|
|
1169
|
+
providerName: "",
|
|
1170
|
+
reasoning: true
|
|
1171
|
+
};
|
|
1172
|
+
const nextPatch = typeof updater === "function" ? updater(prevModel) : updater;
|
|
1173
|
+
const nextSpec = deepCopy(agent.agentInfo.spec || {});
|
|
1174
|
+
nextSpec.model = { ...prevModel, ...nextPatch };
|
|
1175
|
+
agent.agentInfo.spec = nextSpec;
|
|
1176
|
+
config.hooks?.onAfterSwitchModel?.(agent.agentInfo.spec.model);
|
|
1175
1177
|
};
|
|
1176
1178
|
const getUserInput = async (agentId) => {
|
|
1177
1179
|
agent.loading = true;
|
|
@@ -1200,16 +1202,11 @@ function createChatStore() {
|
|
|
1200
1202
|
}
|
|
1201
1203
|
};
|
|
1202
1204
|
const setAgent = async (agentInfo) => {
|
|
1203
|
-
if (!agent.agentInfo.id || agent.agentInfo.id !== agentInfo.id) {
|
|
1205
|
+
if (!agent.agentInfo.id && !agentInfo.updatedAt || agent.agentInfo.id !== agentInfo.id) {
|
|
1204
1206
|
await getAgentInfo(agentInfo.id);
|
|
1205
1207
|
}
|
|
1206
1208
|
agent.agentInfo = { ...agent.agentInfo, ...agentInfo };
|
|
1207
|
-
if (
|
|
1208
|
-
setAgentModel({
|
|
1209
|
-
modelName: agent.agentInfo.spec?.model?.modelName || "",
|
|
1210
|
-
providerName: agent.agentInfo.spec?.model?.providerName || ""
|
|
1211
|
-
});
|
|
1212
|
-
} else if (config.layout.userInput) {
|
|
1209
|
+
if (config.layout.userInput) {
|
|
1213
1210
|
await getUserInput(agent.agentInfo.id);
|
|
1214
1211
|
}
|
|
1215
1212
|
};
|
|
@@ -2044,7 +2041,7 @@ function createChatStore() {
|
|
|
2044
2041
|
files,
|
|
2045
2042
|
spec: {
|
|
2046
2043
|
...conversation.active.spec,
|
|
2047
|
-
model: agent.model
|
|
2044
|
+
model: agent.agentInfo.spec?.model
|
|
2048
2045
|
},
|
|
2049
2046
|
stream: true,
|
|
2050
2047
|
responseMode: 2
|
|
@@ -2339,7 +2336,7 @@ var ConversationTabPane = ({ items, activeKey, emptyDescription, scrollableTarge
|
|
|
2339
2336
|
console2.log("next");
|
|
2340
2337
|
},
|
|
2341
2338
|
loader: /* @__PURE__ */ jsx("div", { className: "text-center", children: /* @__PURE__ */ jsx(Spin, { indicator: /* @__PURE__ */ jsx(RedoOutlined, { spin: true }), size: "small" }) }),
|
|
2342
|
-
style: { overflow: "hidden" },
|
|
2339
|
+
style: { overflow: "hidden", padding: "0 10px" },
|
|
2343
2340
|
scrollableTarget,
|
|
2344
2341
|
children: /* @__PURE__ */ jsx(
|
|
2345
2342
|
Conversations,
|
|
@@ -5689,13 +5686,41 @@ var BubbleListItems_default = ({
|
|
|
5689
5686
|
return [...welcomeMessageRecord];
|
|
5690
5687
|
}, [chatRecords, welcomeMessageRecord, firstMessagesRecord]);
|
|
5691
5688
|
const listRef = useRef(null);
|
|
5689
|
+
const autoScrollRef = useRef(true);
|
|
5690
|
+
const handleScroll = (el) => {
|
|
5691
|
+
const target = el.target;
|
|
5692
|
+
const distanceToBottom = target.scrollHeight - target.scrollTop - target.clientHeight;
|
|
5693
|
+
autoScrollRef.current = distanceToBottom < 90;
|
|
5694
|
+
};
|
|
5695
|
+
useEffect(() => {
|
|
5696
|
+
const latestMessage = conversationMessages[conversationMessages?.length - 1];
|
|
5697
|
+
if (!latestMessage) return;
|
|
5698
|
+
if (latestMessage.generating) {
|
|
5699
|
+
autoScrollRef.current = true;
|
|
5700
|
+
}
|
|
5701
|
+
}, [conversationMessages?.length]);
|
|
5702
|
+
useEffect(() => {
|
|
5703
|
+
const el = listRef.current?.nativeElement;
|
|
5704
|
+
if (!el || !bubbleListItems.length) return;
|
|
5705
|
+
if (autoScrollRef.current) {
|
|
5706
|
+
setTimeout(() => {
|
|
5707
|
+
if (autoScrollRef.current) {
|
|
5708
|
+
listRef.current?.scrollTo({
|
|
5709
|
+
top: "bottom",
|
|
5710
|
+
behavior: "instant"
|
|
5711
|
+
});
|
|
5712
|
+
}
|
|
5713
|
+
}, 300);
|
|
5714
|
+
}
|
|
5715
|
+
}, [bubbleListItems]);
|
|
5692
5716
|
return /* @__PURE__ */ jsx(A2uiRenderer, { messages: conversationMessages, children: /* @__PURE__ */ jsx(Spin, { spinning: conversationState.loading, classNames: { root: "full-spin" }, children: /* @__PURE__ */ jsx(
|
|
5693
5717
|
Bubble.List,
|
|
5694
5718
|
{
|
|
5695
|
-
autoScroll:
|
|
5719
|
+
autoScroll: false,
|
|
5696
5720
|
ref: listRef,
|
|
5697
5721
|
items: bubbleListItems,
|
|
5698
|
-
className: classNames2(styles_module_default2.bubbleList, "height-full", "scroll-fade-in")
|
|
5722
|
+
className: classNames2(styles_module_default2.bubbleList, "height-full", "scroll-fade-in"),
|
|
5723
|
+
onScroll: handleScroll
|
|
5699
5724
|
},
|
|
5700
5725
|
conversationState.active.id
|
|
5701
5726
|
) }) });
|
|
@@ -5964,6 +5989,23 @@ var ModelSelect_default = ({}) => {
|
|
|
5964
5989
|
const chatStore = useChatStore();
|
|
5965
5990
|
const agentState = useSnapshot(chatStore.agent);
|
|
5966
5991
|
const [models, setModels] = useState([]);
|
|
5992
|
+
const currentModel = agentState.agentInfo.spec?.model;
|
|
5993
|
+
const updateAgentModel = useCallback(
|
|
5994
|
+
(model) => {
|
|
5995
|
+
const nextAgentInfo = deepCopy(agentState.agentInfo || {});
|
|
5996
|
+
const nextSpec = deepCopy(agentState.agentInfo.spec || {});
|
|
5997
|
+
nextSpec.model = {
|
|
5998
|
+
modelName: "",
|
|
5999
|
+
providerName: "",
|
|
6000
|
+
reasoning: true,
|
|
6001
|
+
...nextSpec.model || {},
|
|
6002
|
+
...model
|
|
6003
|
+
};
|
|
6004
|
+
nextAgentInfo.spec = nextSpec;
|
|
6005
|
+
chatStore.setAgent(nextAgentInfo);
|
|
6006
|
+
},
|
|
6007
|
+
[agentState.agentInfo, chatStore]
|
|
6008
|
+
);
|
|
5967
6009
|
const modelOptions = models.map((item) => ({
|
|
5968
6010
|
label: item.providerLabel || item.providerName,
|
|
5969
6011
|
title: item.providerLabel || item.providerName,
|
|
@@ -5977,24 +6019,10 @@ var ModelSelect_default = ({}) => {
|
|
|
5977
6019
|
icon: model.icon
|
|
5978
6020
|
}))
|
|
5979
6021
|
}));
|
|
5980
|
-
const
|
|
5981
|
-
const selectedProvider = hasSelectedModelConfig ? modelOptions.find((item) => item.value === agentState.model.providerName) : void 0;
|
|
5982
|
-
const selectedModel = selectedProvider?.options.find((item) => item.modelName === agentState.model.modelName);
|
|
5983
|
-
const selectedModelValue = selectedModel?.value;
|
|
5984
|
-
useEffect(() => {
|
|
5985
|
-
const shouldUseDefaultModel = !hasSelectedModelConfig || !selectedModel;
|
|
5986
|
-
if (shouldUseDefaultModel && models.length > 0 && models[0].models?.length > 0) {
|
|
5987
|
-
const firstProvider = models[0];
|
|
5988
|
-
const firstModel = firstProvider.models[0];
|
|
5989
|
-
chatStore.setAgentModel({
|
|
5990
|
-
modelName: firstModel.modelName,
|
|
5991
|
-
providerName: firstProvider.providerName
|
|
5992
|
-
});
|
|
5993
|
-
}
|
|
5994
|
-
}, [hasSelectedModelConfig, selectedModel, models, chatStore]);
|
|
6022
|
+
const selectedModelValue = currentModel?.providerName && currentModel?.modelName ? `${currentModel.providerName}:${currentModel.modelName}` : void 0;
|
|
5995
6023
|
const handleModelChange = (_, option) => {
|
|
5996
6024
|
if (Array.isArray(option) || !option || !("providerName" in option)) return;
|
|
5997
|
-
|
|
6025
|
+
updateAgentModel({
|
|
5998
6026
|
modelName: option.modelName,
|
|
5999
6027
|
providerName: option.providerName
|
|
6000
6028
|
});
|
|
@@ -6039,13 +6067,25 @@ var ModelSelect_default = ({}) => {
|
|
|
6039
6067
|
var ReasonBtn_default = ({}) => {
|
|
6040
6068
|
const chatStore = useChatStore();
|
|
6041
6069
|
const agentState = useSnapshot(chatStore.agent);
|
|
6070
|
+
const currentModel = agentState.agentInfo.spec?.model;
|
|
6071
|
+
const updateAgentModel = (reasoning) => {
|
|
6072
|
+
const nextAgentInfo = deepCopy(agentState.agentInfo || {});
|
|
6073
|
+
const nextSpec = deepCopy(agentState.agentInfo.spec || {});
|
|
6074
|
+
nextSpec.model = {
|
|
6075
|
+
modelName: "",
|
|
6076
|
+
providerName: "",
|
|
6077
|
+
reasoning: true,
|
|
6078
|
+
...nextSpec.model || {}
|
|
6079
|
+
};
|
|
6080
|
+
nextSpec.model.reasoning = reasoning;
|
|
6081
|
+
nextAgentInfo.spec = nextSpec;
|
|
6082
|
+
chatStore.setAgent(nextAgentInfo);
|
|
6083
|
+
};
|
|
6042
6084
|
return /* @__PURE__ */ jsxs(
|
|
6043
6085
|
"div",
|
|
6044
6086
|
{
|
|
6045
|
-
className: classNames2(style_module_default.resourceBtn, { [style_module_default.resourceBtnActive]:
|
|
6046
|
-
onClick: () =>
|
|
6047
|
-
reasoning: !prevModel.reasoning
|
|
6048
|
-
})),
|
|
6087
|
+
className: classNames2(style_module_default.resourceBtn, { [style_module_default.resourceBtnActive]: currentModel?.reasoning }),
|
|
6088
|
+
onClick: () => updateAgentModel(!currentModel?.reasoning),
|
|
6049
6089
|
children: [
|
|
6050
6090
|
/* @__PURE__ */ jsx(IconFont_default, { type: "icon-reason" }),
|
|
6051
6091
|
/* @__PURE__ */ jsx("span", { children: "\u6DF1\u5EA6\u601D\u8003" })
|