@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 CHANGED
@@ -1190,18 +1190,20 @@ function createChatStore() {
1190
1190
  const agent = valtio.proxy({
1191
1191
  /** 当前智能体 */
1192
1192
  agentInfo: {},
1193
- model: {
1194
- modelName: "",
1195
- providerName: "",
1196
- reasoning: true
1197
- },
1198
1193
  /** 智能体加载状态 */
1199
1194
  loading: false
1200
1195
  });
1201
1196
  const setAgentModel = (updater) => {
1202
- const nextPatch = typeof updater === "function" ? updater(agent.model) : updater;
1203
- agent.model = { ...agent.model, ...nextPatch };
1204
- config.hooks?.onAfterSwitchModel?.(agent.model);
1197
+ const prevModel = agent.agentInfo.spec?.model || {
1198
+ modelName: "",
1199
+ providerName: "",
1200
+ reasoning: true
1201
+ };
1202
+ const nextPatch = typeof updater === "function" ? updater(prevModel) : updater;
1203
+ const nextSpec = common.deepCopy(agent.agentInfo.spec || {});
1204
+ nextSpec.model = { ...prevModel, ...nextPatch };
1205
+ agent.agentInfo.spec = nextSpec;
1206
+ config.hooks?.onAfterSwitchModel?.(agent.agentInfo.spec.model);
1205
1207
  };
1206
1208
  const getUserInput = async (agentId) => {
1207
1209
  agent.loading = true;
@@ -1230,16 +1232,11 @@ function createChatStore() {
1230
1232
  }
1231
1233
  };
1232
1234
  const setAgent = async (agentInfo) => {
1233
- if (!agent.agentInfo.id || agent.agentInfo.id !== agentInfo.id) {
1235
+ if (!agent.agentInfo.id && !agentInfo.updatedAt || agent.agentInfo.id !== agentInfo.id) {
1234
1236
  await getAgentInfo(agentInfo.id);
1235
1237
  }
1236
1238
  agent.agentInfo = { ...agent.agentInfo, ...agentInfo };
1237
- if (agentInfo.agentType === 2 /* AUTONOMOUS */) {
1238
- setAgentModel({
1239
- modelName: agent.agentInfo.spec?.model?.modelName || "",
1240
- providerName: agent.agentInfo.spec?.model?.providerName || ""
1241
- });
1242
- } else if (config.layout.userInput) {
1239
+ if (config.layout.userInput) {
1243
1240
  await getUserInput(agent.agentInfo.id);
1244
1241
  }
1245
1242
  };
@@ -2074,7 +2071,7 @@ function createChatStore() {
2074
2071
  files,
2075
2072
  spec: {
2076
2073
  ...conversation.active.spec,
2077
- model: agent.model
2074
+ model: agent.agentInfo.spec?.model
2078
2075
  },
2079
2076
  stream: true,
2080
2077
  responseMode: 2
@@ -2369,7 +2366,7 @@ var ConversationTabPane = ({ items, activeKey, emptyDescription, scrollableTarge
2369
2366
  console2__default.default.log("next");
2370
2367
  },
2371
2368
  loader: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-center", children: /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { indicator: /* @__PURE__ */ jsxRuntime.jsx(icons.RedoOutlined, { spin: true }), size: "small" }) }),
2372
- style: { overflow: "hidden" },
2369
+ style: { overflow: "hidden", padding: "0 10px" },
2373
2370
  scrollableTarget,
2374
2371
  children: /* @__PURE__ */ jsxRuntime.jsx(
2375
2372
  xV2.Conversations,
@@ -5719,13 +5716,41 @@ var BubbleListItems_default = ({
5719
5716
  return [...welcomeMessageRecord];
5720
5717
  }, [chatRecords, welcomeMessageRecord, firstMessagesRecord]);
5721
5718
  const listRef = React10.useRef(null);
5719
+ const autoScrollRef = React10.useRef(true);
5720
+ const handleScroll = (el) => {
5721
+ const target = el.target;
5722
+ const distanceToBottom = target.scrollHeight - target.scrollTop - target.clientHeight;
5723
+ autoScrollRef.current = distanceToBottom < 90;
5724
+ };
5725
+ React10.useEffect(() => {
5726
+ const latestMessage = conversationMessages[conversationMessages?.length - 1];
5727
+ if (!latestMessage) return;
5728
+ if (latestMessage.generating) {
5729
+ autoScrollRef.current = true;
5730
+ }
5731
+ }, [conversationMessages?.length]);
5732
+ React10.useEffect(() => {
5733
+ const el = listRef.current?.nativeElement;
5734
+ if (!el || !bubbleListItems.length) return;
5735
+ if (autoScrollRef.current) {
5736
+ setTimeout(() => {
5737
+ if (autoScrollRef.current) {
5738
+ listRef.current?.scrollTo({
5739
+ top: "bottom",
5740
+ behavior: "instant"
5741
+ });
5742
+ }
5743
+ }, 300);
5744
+ }
5745
+ }, [bubbleListItems]);
5722
5746
  return /* @__PURE__ */ jsxRuntime.jsx(A2uiRenderer, { messages: conversationMessages, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { spinning: conversationState.loading, classNames: { root: "full-spin" }, children: /* @__PURE__ */ jsxRuntime.jsx(
5723
5747
  xV2.Bubble.List,
5724
5748
  {
5725
- autoScroll: true,
5749
+ autoScroll: false,
5726
5750
  ref: listRef,
5727
5751
  items: bubbleListItems,
5728
- className: classNames2__default.default(styles_module_default2.bubbleList, "height-full", "scroll-fade-in")
5752
+ className: classNames2__default.default(styles_module_default2.bubbleList, "height-full", "scroll-fade-in"),
5753
+ onScroll: handleScroll
5729
5754
  },
5730
5755
  conversationState.active.id
5731
5756
  ) }) });
@@ -5994,6 +6019,23 @@ var ModelSelect_default = ({}) => {
5994
6019
  const chatStore = useChatStore();
5995
6020
  const agentState = valtio.useSnapshot(chatStore.agent);
5996
6021
  const [models, setModels] = React10.useState([]);
6022
+ const currentModel = agentState.agentInfo.spec?.model;
6023
+ const updateAgentModel = React10.useCallback(
6024
+ (model) => {
6025
+ const nextAgentInfo = common.deepCopy(agentState.agentInfo || {});
6026
+ const nextSpec = common.deepCopy(agentState.agentInfo.spec || {});
6027
+ nextSpec.model = {
6028
+ modelName: "",
6029
+ providerName: "",
6030
+ reasoning: true,
6031
+ ...nextSpec.model || {},
6032
+ ...model
6033
+ };
6034
+ nextAgentInfo.spec = nextSpec;
6035
+ chatStore.setAgent(nextAgentInfo);
6036
+ },
6037
+ [agentState.agentInfo, chatStore]
6038
+ );
5997
6039
  const modelOptions = models.map((item) => ({
5998
6040
  label: item.providerLabel || item.providerName,
5999
6041
  title: item.providerLabel || item.providerName,
@@ -6007,24 +6049,10 @@ var ModelSelect_default = ({}) => {
6007
6049
  icon: model.icon
6008
6050
  }))
6009
6051
  }));
6010
- const hasSelectedModelConfig = Boolean(agentState.model.providerName && agentState.model.modelName);
6011
- const selectedProvider = hasSelectedModelConfig ? modelOptions.find((item) => item.value === agentState.model.providerName) : void 0;
6012
- const selectedModel = selectedProvider?.options.find((item) => item.modelName === agentState.model.modelName);
6013
- const selectedModelValue = selectedModel?.value;
6014
- React10.useEffect(() => {
6015
- const shouldUseDefaultModel = !hasSelectedModelConfig || !selectedModel;
6016
- if (shouldUseDefaultModel && models.length > 0 && models[0].models?.length > 0) {
6017
- const firstProvider = models[0];
6018
- const firstModel = firstProvider.models[0];
6019
- chatStore.setAgentModel({
6020
- modelName: firstModel.modelName,
6021
- providerName: firstProvider.providerName
6022
- });
6023
- }
6024
- }, [hasSelectedModelConfig, selectedModel, models, chatStore]);
6052
+ const selectedModelValue = currentModel?.providerName && currentModel?.modelName ? `${currentModel.providerName}:${currentModel.modelName}` : void 0;
6025
6053
  const handleModelChange = (_, option) => {
6026
6054
  if (Array.isArray(option) || !option || !("providerName" in option)) return;
6027
- chatStore.setAgentModel({
6055
+ updateAgentModel({
6028
6056
  modelName: option.modelName,
6029
6057
  providerName: option.providerName
6030
6058
  });
@@ -6069,13 +6097,25 @@ var ModelSelect_default = ({}) => {
6069
6097
  var ReasonBtn_default = ({}) => {
6070
6098
  const chatStore = useChatStore();
6071
6099
  const agentState = valtio.useSnapshot(chatStore.agent);
6100
+ const currentModel = agentState.agentInfo.spec?.model;
6101
+ const updateAgentModel = (reasoning) => {
6102
+ const nextAgentInfo = common.deepCopy(agentState.agentInfo || {});
6103
+ const nextSpec = common.deepCopy(agentState.agentInfo.spec || {});
6104
+ nextSpec.model = {
6105
+ modelName: "",
6106
+ providerName: "",
6107
+ reasoning: true,
6108
+ ...nextSpec.model || {}
6109
+ };
6110
+ nextSpec.model.reasoning = reasoning;
6111
+ nextAgentInfo.spec = nextSpec;
6112
+ chatStore.setAgent(nextAgentInfo);
6113
+ };
6072
6114
  return /* @__PURE__ */ jsxRuntime.jsxs(
6073
6115
  "div",
6074
6116
  {
6075
- className: classNames2__default.default(style_module_default.resourceBtn, { [style_module_default.resourceBtnActive]: agentState.model.reasoning }),
6076
- onClick: () => chatStore.setAgentModel((prevModel) => ({
6077
- reasoning: !prevModel.reasoning
6078
- })),
6117
+ className: classNames2__default.default(style_module_default.resourceBtn, { [style_module_default.resourceBtnActive]: currentModel?.reasoning }),
6118
+ onClick: () => updateAgentModel(!currentModel?.reasoning),
6079
6119
  children: [
6080
6120
  /* @__PURE__ */ jsxRuntime.jsx(IconFont_default, { type: "icon-reason" }),
6081
6121
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u6DF1\u5EA6\u601D\u8003" })