@zero-library/chat-agent 2.1.3 → 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 +13 -10
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +13 -10
- package/dist/index.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -327,6 +327,7 @@ interface ChatHandle {
|
|
|
327
327
|
sendMessage: (message?: string, files?: InputFile[]) => void;
|
|
328
328
|
switchAgentConversation: (agentId: AgentInfo['id'], strategy?: ConversationStrategy) => void;
|
|
329
329
|
switchConversation: (id?: Conversation['id']) => void;
|
|
330
|
+
createConversation: () => Promise<void>;
|
|
330
331
|
setReferences: (references?: ReferencesType) => void;
|
|
331
332
|
setMessage: (message?: string) => void;
|
|
332
333
|
setFiles: (files?: InputFile[]) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -327,6 +327,7 @@ interface ChatHandle {
|
|
|
327
327
|
sendMessage: (message?: string, files?: InputFile[]) => void;
|
|
328
328
|
switchAgentConversation: (agentId: AgentInfo['id'], strategy?: ConversationStrategy) => void;
|
|
329
329
|
switchConversation: (id?: Conversation['id']) => void;
|
|
330
|
+
createConversation: () => Promise<void>;
|
|
330
331
|
setReferences: (references?: ReferencesType) => void;
|
|
331
332
|
setMessage: (message?: string) => void;
|
|
332
333
|
setFiles: (files?: InputFile[]) => void;
|
package/dist/index.esm.js
CHANGED
|
@@ -573,7 +573,7 @@ function createChatStore() {
|
|
|
573
573
|
conversations.list.items = conversations.list.items.filter((item) => item.key !== conversationId);
|
|
574
574
|
delete conversation.messages[conversationId];
|
|
575
575
|
if (conversation.active.id === conversationId) {
|
|
576
|
-
|
|
576
|
+
createConversation();
|
|
577
577
|
}
|
|
578
578
|
config.hooks?.onAfterDelConversation?.(conversationId, conversation.active.id === conversationId);
|
|
579
579
|
} finally {
|
|
@@ -687,20 +687,23 @@ function createChatStore() {
|
|
|
687
687
|
} finally {
|
|
688
688
|
}
|
|
689
689
|
};
|
|
690
|
-
const switchAgentConversation = async (
|
|
690
|
+
const switchAgentConversation = async (id, strategy) => {
|
|
691
|
+
const agentId = String(id);
|
|
691
692
|
await switchAgent(agentId);
|
|
692
693
|
const conversationId = await resolveConversationId(agentId, strategy);
|
|
693
694
|
if (conversationId) {
|
|
694
695
|
switchConversation(conversationId);
|
|
695
696
|
}
|
|
696
697
|
};
|
|
697
|
-
const
|
|
698
|
+
const createConversation = async () => {
|
|
699
|
+
if (!receiver.active.id) return;
|
|
698
700
|
const conversationId = await resolveConversationId(receiver.active.id);
|
|
699
701
|
if (conversationId) {
|
|
700
702
|
switchConversation(conversationId);
|
|
701
703
|
}
|
|
702
704
|
};
|
|
703
|
-
const switchConversation = async (
|
|
705
|
+
const switchConversation = async (id) => {
|
|
706
|
+
const conversationId = String(id);
|
|
704
707
|
if (conversation.active.id === conversationId) return;
|
|
705
708
|
const canProceed = await config.hooks?.onBeforeSwitchConversation?.(conversationId);
|
|
706
709
|
if (canProceed === false) return;
|
|
@@ -885,7 +888,7 @@ function createChatStore() {
|
|
|
885
888
|
setHeaderOpen,
|
|
886
889
|
feedback,
|
|
887
890
|
switchAgentConversation,
|
|
888
|
-
|
|
891
|
+
createConversation,
|
|
889
892
|
switchConversation,
|
|
890
893
|
sendMessage,
|
|
891
894
|
cancelReceive,
|
|
@@ -1137,7 +1140,7 @@ var BubbleListItems_default = ({ firstMessage = false, avatar = { user: false, a
|
|
|
1137
1140
|
);
|
|
1138
1141
|
const chatRecords = useMemo(() => {
|
|
1139
1142
|
return (chatMessage?.message || []).map((message3, index) => {
|
|
1140
|
-
const role = conversationRoles[MEMBER_TYPE[message3.sender.type]];
|
|
1143
|
+
const role = conversationRoles[MEMBER_TYPE[message3.sender.type]] || {};
|
|
1141
1144
|
return {
|
|
1142
1145
|
key: message3.id,
|
|
1143
1146
|
placement: role.placement,
|
|
@@ -1380,7 +1383,7 @@ var ChatHeader_default = ({
|
|
|
1380
1383
|
RenderWrapper,
|
|
1381
1384
|
{
|
|
1382
1385
|
control: newConversationBtn,
|
|
1383
|
-
DefaultComponent: /* @__PURE__ */ jsx(Button, { title: "\u65B0\u5EFA\u4F1A\u8BDD", type: "text", size: "large", icon: /* @__PURE__ */ jsx(PlusOutlined, {}), onClick: () => chatStore.
|
|
1386
|
+
DefaultComponent: /* @__PURE__ */ jsx(Button, { title: "\u65B0\u5EFA\u4F1A\u8BDD", type: "text", size: "large", icon: /* @__PURE__ */ jsx(PlusOutlined, {}), onClick: () => chatStore.createConversation() })
|
|
1384
1387
|
}
|
|
1385
1388
|
),
|
|
1386
1389
|
/* @__PURE__ */ jsx(
|
|
@@ -1752,7 +1755,7 @@ var ConversationListHeader_default = () => {
|
|
|
1752
1755
|
block: true,
|
|
1753
1756
|
type: "primary",
|
|
1754
1757
|
shape: "round",
|
|
1755
|
-
onClick: () => chatStore.
|
|
1758
|
+
onClick: () => chatStore.createConversation(),
|
|
1756
1759
|
className: classNames7("m-t-16"),
|
|
1757
1760
|
icon: /* @__PURE__ */ jsx(PlusOutlined, {}),
|
|
1758
1761
|
children: "\u65B0\u5EFA\u4F1A\u8BDD"
|
|
@@ -1822,7 +1825,7 @@ var layouts_default = forwardRef(({ theme, params, userInfo, hooks, layout, conf
|
|
|
1822
1825
|
return;
|
|
1823
1826
|
}
|
|
1824
1827
|
if (config?.receiverId && config?.receiverType === 3) {
|
|
1825
|
-
chatStore.switchAgentConversation(
|
|
1828
|
+
chatStore.switchAgentConversation(config.receiverId, config.conversationStrategy);
|
|
1826
1829
|
}
|
|
1827
1830
|
}, [config]);
|
|
1828
1831
|
useEffect(() => {
|
|
@@ -1838,7 +1841,6 @@ var layouts_default = forwardRef(({ theme, params, userInfo, hooks, layout, conf
|
|
|
1838
1841
|
chatStore.setHooks(hooks);
|
|
1839
1842
|
}, [hooks]);
|
|
1840
1843
|
const receiverState = useSnapshot(chatStore.receiver);
|
|
1841
|
-
useSnapshot(chatStore.conversation);
|
|
1842
1844
|
const configState = useSnapshot(chatStore.config);
|
|
1843
1845
|
useImperativeHandle(
|
|
1844
1846
|
ref,
|
|
@@ -1846,6 +1848,7 @@ var layouts_default = forwardRef(({ theme, params, userInfo, hooks, layout, conf
|
|
|
1846
1848
|
sendMessage: chatStore.sendMessage,
|
|
1847
1849
|
switchAgentConversation: chatStore.switchAgentConversation,
|
|
1848
1850
|
switchConversation: chatStore.switchConversation,
|
|
1851
|
+
createConversation: chatStore.createConversation,
|
|
1849
1852
|
setReferences: chatStore.setReferences,
|
|
1850
1853
|
setMessage: chatStore.setContent,
|
|
1851
1854
|
setFiles: chatStore.setFileList
|