@zero-library/chat-copilot 3.1.23 → 3.1.25

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
@@ -1409,6 +1409,7 @@ function createChatStore() {
1409
1409
  }
1410
1410
  };
1411
1411
  const conversation = valtio.proxy({
1412
+ loading: false,
1412
1413
  /** 当前激活的会话信息 */
1413
1414
  active: {
1414
1415
  id: "",
@@ -1480,6 +1481,7 @@ function createChatStore() {
1480
1481
  if (canProceed === false) {
1481
1482
  throw new Error("\u64CD\u4F5C\u88AB\u963B\u6B62");
1482
1483
  }
1484
+ conversation.loading = true;
1483
1485
  if (!conversation.messages[conversationId]) {
1484
1486
  setInitMessage(conversationId);
1485
1487
  }
@@ -1502,6 +1504,7 @@ function createChatStore() {
1502
1504
  normalizeMessagesByExecutionAndRole(conversation.messages[conversationId].message);
1503
1505
  }
1504
1506
  }
1507
+ conversation.loading = false;
1505
1508
  config.hooks?.onAfterInitMessages?.(conversation.messages[conversationId].message);
1506
1509
  config.hooks?.onAfterInit?.();
1507
1510
  };
@@ -5716,44 +5719,16 @@ var BubbleListItems_default = ({
5716
5719
  return [...welcomeMessageRecord];
5717
5720
  }, [chatRecords, welcomeMessageRecord, firstMessagesRecord]);
5718
5721
  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]);
5746
- return /* @__PURE__ */ jsxRuntime.jsx(A2uiRenderer, { messages: conversationMessages, children: /* @__PURE__ */ jsxRuntime.jsx(
5722
+ return /* @__PURE__ */ jsxRuntime.jsx(A2uiRenderer, { messages: conversationMessages, children: /* @__PURE__ */ jsxRuntime.jsx(antd.Spin, { spinning: conversationState.loading, classNames: { root: "full-spin" }, children: /* @__PURE__ */ jsxRuntime.jsx(
5747
5723
  xV2.Bubble.List,
5748
5724
  {
5749
- autoScroll: false,
5725
+ autoScroll: true,
5750
5726
  ref: listRef,
5751
5727
  items: bubbleListItems,
5752
- className: classNames2__default.default(styles_module_default2.bubbleList, "height-full", "scroll-fade-in"),
5753
- onScroll: handleScroll
5728
+ className: classNames2__default.default(styles_module_default2.bubbleList, "height-full", "scroll-fade-in")
5754
5729
  },
5755
5730
  conversationState.active.id
5756
- ) });
5731
+ ) }) });
5757
5732
  };
5758
5733
  var { Sider, Content } = antd.Layout;
5759
5734
  var { Title: Title2, Text: Text4 } = antd.Typography;
@@ -6032,9 +6007,13 @@ var ModelSelect_default = ({}) => {
6032
6007
  icon: model.icon
6033
6008
  }))
6034
6009
  }));
6035
- const selectedModelValue = modelOptions.find((item) => item.value === agentState.model.providerName)?.options.find((item) => item.modelName === agentState.model.modelName)?.value;
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;
6036
6014
  React10.useEffect(() => {
6037
- if (!selectedModelValue && models.length > 0 && models[0].models?.length > 0) {
6015
+ const shouldUseDefaultModel = !hasSelectedModelConfig || !selectedModel;
6016
+ if (shouldUseDefaultModel && models.length > 0 && models[0].models?.length > 0) {
6038
6017
  const firstProvider = models[0];
6039
6018
  const firstModel = firstProvider.models[0];
6040
6019
  chatStore.setAgentModel({
@@ -6042,7 +6021,7 @@ var ModelSelect_default = ({}) => {
6042
6021
  providerName: firstProvider.providerName
6043
6022
  });
6044
6023
  }
6045
- }, [selectedModelValue, models, agentState.model, chatStore]);
6024
+ }, [hasSelectedModelConfig, selectedModel, models, chatStore]);
6046
6025
  const handleModelChange = (_, option) => {
6047
6026
  if (Array.isArray(option) || !option || !("providerName" in option)) return;
6048
6027
  chatStore.setAgentModel({
@@ -6109,7 +6088,25 @@ var SkillBtn_default = ({}) => {
6109
6088
  const chatStore = useChatStore();
6110
6089
  const conversationState = valtio.useSnapshot(chatStore.conversation);
6111
6090
  const [modalOpen, setModalOpen] = React10.useState(false);
6112
- const skillsCount = conversationState.active.spec?.skills?.items?.length ?? 0;
6091
+ const [skillsCount, setSkillsCount] = React10.useState(0);
6092
+ React10.useEffect(() => {
6093
+ let canceled = false;
6094
+ const syncSkillsCount = async () => {
6095
+ const initialItems = conversationState.active.spec?.skills?.items;
6096
+ if (!initialItems?.length) {
6097
+ setSkillsCount(0);
6098
+ return;
6099
+ }
6100
+ const { data } = await chatStore.config.services.request.listSkills();
6101
+ if (canceled) return;
6102
+ const validIds = new Set((data || []).map((item) => item.id));
6103
+ setSkillsCount(initialItems.map((item) => item.id).filter((id) => validIds.has(id)).length);
6104
+ };
6105
+ syncSkillsCount();
6106
+ return () => {
6107
+ canceled = true;
6108
+ };
6109
+ }, [chatStore, conversationState.active.spec?.skills?.items]);
6113
6110
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
6114
6111
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: style_module_default.resourceBtn, onClick: () => setModalOpen(true), children: [
6115
6112
  /* @__PURE__ */ jsxRuntime.jsx(IconFont_default, { type: "icon-skill" }),