From 2e8f2954f58eb3954d309165f4c0756185cc9c84 Mon Sep 17 00:00:00 2001 From: Shinji-Li <1349021570@qq.com> Date: Wed, 31 Jul 2024 14:39:48 +0800 Subject: [PATCH] feat: add setChats hooks (#289) * :memo: docs: core api request docs * :sparkles: feat: add setChats hooks --- src/ProChat/hooks/useProChat.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/ProChat/hooks/useProChat.ts b/src/ProChat/hooks/useProChat.ts index cc84246..f3c8d23 100644 --- a/src/ProChat/hooks/useProChat.ts +++ b/src/ProChat/hooks/useProChat.ts @@ -24,6 +24,14 @@ export interface ProChatInstance * @returns void */ pushChat: (chats: { id?: string; content: string; role: string; [key: string]: any }) => void; + /** + * 往数据流中推送消息 + * @returns void + */ + setChat: ( + id: string, + chats: { id?: string; content?: string; role?: string; [key: string]: any }, + ) => void; /** * 获取当前聊天消息列表 * @returns ChatMessage[] @@ -77,6 +85,14 @@ export const useProChat = () => { message: chat?.content, }); }); + const setChat = useRefFunction((id, chat) => { + return dispatchMessage({ + ...chat, + type: 'updateMessage', + id, + value: chat?.content, + }); + }); const getChatMessages = useRefFunction(() => chatSelectors.currentChats(storeApi.getState())); const setMessageContent = useRefFunction((id: string, content: string) => { @@ -98,6 +114,7 @@ export const useProChat = () => { getChatById, getChats, pushChat, + setChat, getChatMessages, resendMessage, sendMessage,