@zero-library/chat-agent 2.1.3 → 2.1.5

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 {
@@ -685,7 +685,7 @@ function createChatStore() {
685
685
  if (member.memberType === 3) {
686
686
  conversation.active.member.agent = member;
687
687
  } else {
688
- if (member.memberId === config.userInfo.id) {
688
+ if (member.memberId === config.userInfo.id || member.memberType === 1) {
689
689
  conversation.active.member.user = member;
690
690
  } else {
691
691
  conversation.active.member.other = member;
@@ -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;
@@ -893,7 +896,7 @@ function createChatStore() {
893
896
  setHeaderOpen,
894
897
  feedback,
895
898
  switchAgentConversation,
896
- createAgentConversation,
899
+ createConversation,
897
900
  switchConversation,
898
901
  sendMessage,
899
902
  cancelReceive,
@@ -1145,7 +1148,7 @@ var BubbleListItems_default = ({ firstMessage = false, avatar = { user: false, a
1145
1148
  );
1146
1149
  const chatRecords = react.useMemo(() => {
1147
1150
  return (chatMessage?.message || []).map((message3, index) => {
1148
- const role = conversationRoles[MEMBER_TYPE[message3.sender.type]];
1151
+ const role = conversationRoles[MEMBER_TYPE[message3.sender.type]] || {};
1149
1152
  return {
1150
1153
  key: message3.id,
1151
1154
  placement: role.placement,
@@ -1388,7 +1391,7 @@ var ChatHeader_default = ({
1388
1391
  common.RenderWrapper,
1389
1392
  {
1390
1393
  control: newConversationBtn,
1391
- 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() })
1392
1395
  }
1393
1396
  ),
1394
1397
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -1760,7 +1763,7 @@ var ConversationListHeader_default = () => {
1760
1763
  block: true,
1761
1764
  type: "primary",
1762
1765
  shape: "round",
1763
- onClick: () => chatStore.createAgentConversation(),
1766
+ onClick: () => chatStore.createConversation(),
1764
1767
  className: classNames7__default.default("m-t-16"),
1765
1768
  icon: /* @__PURE__ */ jsxRuntime.jsx(icons.PlusOutlined, {}),
1766
1769
  children: "\u65B0\u5EFA\u4F1A\u8BDD"
@@ -1830,7 +1833,7 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
1830
1833
  return;
1831
1834
  }
1832
1835
  if (config?.receiverId && config?.receiverType === 3) {
1833
- chatStore.switchAgentConversation(String(config.receiverId), config.conversationStrategy);
1836
+ chatStore.switchAgentConversation(config.receiverId, config.conversationStrategy);
1834
1837
  }
1835
1838
  }, [config]);
1836
1839
  react.useEffect(() => {
@@ -1846,7 +1849,6 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
1846
1849
  chatStore.setHooks(hooks);
1847
1850
  }, [hooks]);
1848
1851
  const receiverState = valtio.useSnapshot(chatStore.receiver);
1849
- valtio.useSnapshot(chatStore.conversation);
1850
1852
  const configState = valtio.useSnapshot(chatStore.config);
1851
1853
  react.useImperativeHandle(
1852
1854
  ref,
@@ -1854,6 +1856,7 @@ var layouts_default = react.forwardRef(({ theme, params, userInfo, hooks, layout
1854
1856
  sendMessage: chatStore.sendMessage,
1855
1857
  switchAgentConversation: chatStore.switchAgentConversation,
1856
1858
  switchConversation: chatStore.switchConversation,
1859
+ createConversation: chatStore.createConversation,
1857
1860
  setReferences: chatStore.setReferences,
1858
1861
  setMessage: chatStore.setContent,
1859
1862
  setFiles: chatStore.setFileList