@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 +15 -11
- 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 +15 -11
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
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;
|
|
@@ -791,6 +794,7 @@ function createChatStore() {
|
|
|
791
794
|
}
|
|
792
795
|
};
|
|
793
796
|
const cancelReceive = async () => {
|
|
797
|
+
console.log("\u53D6\u6D88\u63A5\u6536");
|
|
794
798
|
await conversationStop(conversation.active.id);
|
|
795
799
|
};
|
|
796
800
|
const updateConversationTitle = (conversationId, title) => {
|
|
@@ -884,7 +888,7 @@ function createChatStore() {
|
|
|
884
888
|
setHeaderOpen,
|
|
885
889
|
feedback,
|
|
886
890
|
switchAgentConversation,
|
|
887
|
-
|
|
891
|
+
createConversation,
|
|
888
892
|
switchConversation,
|
|
889
893
|
sendMessage,
|
|
890
894
|
cancelReceive,
|
|
@@ -1136,7 +1140,7 @@ var BubbleListItems_default = ({ firstMessage = false, avatar = { user: false, a
|
|
|
1136
1140
|
);
|
|
1137
1141
|
const chatRecords = useMemo(() => {
|
|
1138
1142
|
return (chatMessage?.message || []).map((message3, index) => {
|
|
1139
|
-
const role = conversationRoles[MEMBER_TYPE[message3.sender.type]];
|
|
1143
|
+
const role = conversationRoles[MEMBER_TYPE[message3.sender.type]] || {};
|
|
1140
1144
|
return {
|
|
1141
1145
|
key: message3.id,
|
|
1142
1146
|
placement: role.placement,
|
|
@@ -1379,7 +1383,7 @@ var ChatHeader_default = ({
|
|
|
1379
1383
|
RenderWrapper,
|
|
1380
1384
|
{
|
|
1381
1385
|
control: newConversationBtn,
|
|
1382
|
-
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() })
|
|
1383
1387
|
}
|
|
1384
1388
|
),
|
|
1385
1389
|
/* @__PURE__ */ jsx(
|
|
@@ -1751,7 +1755,7 @@ var ConversationListHeader_default = () => {
|
|
|
1751
1755
|
block: true,
|
|
1752
1756
|
type: "primary",
|
|
1753
1757
|
shape: "round",
|
|
1754
|
-
onClick: () => chatStore.
|
|
1758
|
+
onClick: () => chatStore.createConversation(),
|
|
1755
1759
|
className: classNames7("m-t-16"),
|
|
1756
1760
|
icon: /* @__PURE__ */ jsx(PlusOutlined, {}),
|
|
1757
1761
|
children: "\u65B0\u5EFA\u4F1A\u8BDD"
|
|
@@ -1821,7 +1825,7 @@ var layouts_default = forwardRef(({ theme, params, userInfo, hooks, layout, conf
|
|
|
1821
1825
|
return;
|
|
1822
1826
|
}
|
|
1823
1827
|
if (config?.receiverId && config?.receiverType === 3) {
|
|
1824
|
-
chatStore.switchAgentConversation(
|
|
1828
|
+
chatStore.switchAgentConversation(config.receiverId, config.conversationStrategy);
|
|
1825
1829
|
}
|
|
1826
1830
|
}, [config]);
|
|
1827
1831
|
useEffect(() => {
|
|
@@ -1837,7 +1841,6 @@ var layouts_default = forwardRef(({ theme, params, userInfo, hooks, layout, conf
|
|
|
1837
1841
|
chatStore.setHooks(hooks);
|
|
1838
1842
|
}, [hooks]);
|
|
1839
1843
|
const receiverState = useSnapshot(chatStore.receiver);
|
|
1840
|
-
useSnapshot(chatStore.conversation);
|
|
1841
1844
|
const configState = useSnapshot(chatStore.config);
|
|
1842
1845
|
useImperativeHandle(
|
|
1843
1846
|
ref,
|
|
@@ -1845,6 +1848,7 @@ var layouts_default = forwardRef(({ theme, params, userInfo, hooks, layout, conf
|
|
|
1845
1848
|
sendMessage: chatStore.sendMessage,
|
|
1846
1849
|
switchAgentConversation: chatStore.switchAgentConversation,
|
|
1847
1850
|
switchConversation: chatStore.switchConversation,
|
|
1851
|
+
createConversation: chatStore.createConversation,
|
|
1848
1852
|
setReferences: chatStore.setReferences,
|
|
1849
1853
|
setMessage: chatStore.setContent,
|
|
1850
1854
|
setFiles: chatStore.setFileList
|
|
@@ -1866,7 +1870,7 @@ var layouts_default = forwardRef(({ theme, params, userInfo, hooks, layout, conf
|
|
|
1866
1870
|
}
|
|
1867
1871
|
}, [hasPreView]);
|
|
1868
1872
|
useWebSocket({
|
|
1869
|
-
url: getWebSocketUrl(`/lolr/conversation/ws/subscribe?NS-TOKEN=${getToken()}`, isLocalhost() ? "192.168.6.23
|
|
1873
|
+
url: getWebSocketUrl(`/api/lolr/conversation/ws/subscribe?NS-TOKEN=${getToken()}`, isLocalhost() ? "192.168.6.23" : ""),
|
|
1870
1874
|
onMessage: chatStore.acceptMessage,
|
|
1871
1875
|
clientHeartbeat: false,
|
|
1872
1876
|
reconnectInterval: 1e4
|