@zero-library/chat-agent 2.1.2 → 2.1.4

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
@@ -581,7 +581,7 @@ function createChatStore() {
581
581
  conversations.list.items = conversations.list.items.filter((item) => item.key !== conversationId);
582
582
  delete conversation.messages[conversationId];
583
583
  if (conversation.active.id === conversationId) {
584
- createAgentConversation();
584
+ createConversation();
585
585
  }
586
586
  config.hooks?.onAfterDelConversation?.(conversationId, conversation.active.id === conversationId);
587
587
  } finally {
@@ -695,20 +695,23 @@ function createChatStore() {
695
695
  } finally {
696
696
  }
697
697
  };
698
- const switchAgentConversation = async (agentId, strategy) => {
698
+ const switchAgentConversation = async (id, strategy) => {
699
+ const agentId = String(id);
699
700
  await switchAgent(agentId);
700
701
  const conversationId = await resolveConversationId(agentId, strategy);
701
702
  if (conversationId) {
702
703
  switchConversation(conversationId);
703
704
  }
704
705
  };
705
- const createAgentConversation = async () => {
706
+ const createConversation = async () => {
707
+ if (!receiver.active.id) return;
706
708
  const conversationId = await resolveConversationId(receiver.active.id);
707
709
  if (conversationId) {
708
710
  switchConversation(conversationId);
709
711
  }
710
712
  };
711
- const switchConversation = async (conversationId) => {
713
+ const switchConversation = async (id) => {
714
+ const conversationId = String(id);
712
715
  if (conversation.active.id === conversationId) return;
713
716
  const canProceed = await config.hooks?.onBeforeSwitchConversation?.(conversationId);
714
717
  if (canProceed === false) return;
@@ -799,6 +802,7 @@ function createChatStore() {
799
802
  }
800
803
  };
801
804
  const cancelReceive = async () => {
805
+ console.log("\u53D6\u6D88\u63A5\u6536");
802
806
  await conversationStop(conversation.active.id);
803
807
  };
804
808
  const updateConversationTitle = (conversationId, title) => {
@@ -892,7 +896,7 @@ function createChatStore() {
892
896
  setHeaderOpen,
893
897
  feedback,
894
898
  switchAgentConversation,
895
- createAgentConversation,
899
+ createConversation,
896
900
  switchConversation,
897
901
  sendMessage,
898
902
  cancelReceive,
@@ -1144,7 +1148,7 @@ var BubbleListItems_default = ({ firstMessage = false, avatar = { user: false, a
1144
1148
  );
1145
1149
  const chatRecords = react.useMemo(() => {
1146
1150
  return (chatMessage?.message || []).map((message3, index) => {
1147
- const role = conversationRoles[MEMBER_TYPE[message3.sender.type]];
1151
+ const role = conversationRoles[MEMBER_TYPE[message3.sender.type]] || {};
1148
1152
  return {
1149
1153
  key: message3.id,
1150
1154
  placement: role.placement,
@@ -1387,7 +1391,7 @@ var ChatHeader_default = ({
1387
1391
  common.RenderWrapper,
1388
1392
  {
1389
1393
  control: newConversationBtn,
1390
- DefaultComponent: /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { title: "\u65B0\u5EFA\u4F1A\u8BDD", type: "text", size: "large", icon: /* @__PURE__ */ jsxRuntime.jsx(icons.PlusOutlined, {}), onClick: () => chatStore.createAgentConversation() })
1394
+ DefaultComponent: /* @__PURE__ */ jsxRuntime.jsx(antd.Button, { title: "\u65B0\u5EFA\u4F1A\u8BDD", type: "text", size: "large", icon: /* @__PURE__ */ jsxRuntime.jsx(icons.PlusOutlined, {}), onClick: () => chatStore.createConversation() })
1391
1395
  }
1392
1396
  ),
1393
1397
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -1759,7 +1763,7 @@ var ConversationListHeader_default = () => {
1759
1763
  block: true,
1760
1764
  type: "primary",
1761
1765
  shape: "round",
1762
- onClick: () => chatStore.createAgentConversation(),
1766
+ onClick: () => chatStore.createConversation(),
1763
1767
  className: classNames7__default.default("m-t-16"),
1764
1768
  icon: /* @__PURE__ */ jsxRuntime.jsx(icons.PlusOutlined, {}),
1765
1769
  children: "\u65B0\u5EFA\u4F1A\u8BDD"
@@ -1829,7 +1833,7 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
1829
1833
  return;
1830
1834
  }
1831
1835
  if (config?.receiverId && config?.receiverType === 3) {
1832
- chatStore.switchAgentConversation(String(config.receiverId), config.conversationStrategy);
1836
+ chatStore.switchAgentConversation(config.receiverId, config.conversationStrategy);
1833
1837
  }
1834
1838
  }, [config]);
1835
1839
  react.useEffect(() => {
@@ -1845,7 +1849,6 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
1845
1849
  chatStore.setHooks(hooks);
1846
1850
  }, [hooks]);
1847
1851
  const receiverState = valtio.useSnapshot(chatStore.receiver);
1848
- valtio.useSnapshot(chatStore.conversation);
1849
1852
  const configState = valtio.useSnapshot(chatStore.config);
1850
1853
  react.useImperativeHandle(
1851
1854
  ref,
@@ -1853,6 +1856,7 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
1853
1856
  sendMessage: chatStore.sendMessage,
1854
1857
  switchAgentConversation: chatStore.switchAgentConversation,
1855
1858
  switchConversation: chatStore.switchConversation,
1859
+ createConversation: chatStore.createConversation,
1856
1860
  setReferences: chatStore.setReferences,
1857
1861
  setMessage: chatStore.setContent,
1858
1862
  setFiles: chatStore.setFileList
@@ -1874,7 +1878,7 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
1874
1878
  }
1875
1879
  }, [hasPreView]);
1876
1880
  common.useWebSocket({
1877
- url: common.getWebSocketUrl(`/lolr/conversation/ws/subscribe?NS-TOKEN=${common.getToken()}`, common.isLocalhost() ? "192.168.6.23:9090" : ""),
1881
+ url: common.getWebSocketUrl(`/api/lolr/conversation/ws/subscribe?NS-TOKEN=${common.getToken()}`, common.isLocalhost() ? "192.168.6.23" : ""),
1878
1882
  onMessage: chatStore.acceptMessage,
1879
1883
  clientHeartbeat: false,
1880
1884
  reconnectInterval: 1e4