diff --git a/src/ProChat/hooks/useProChat.ts b/src/ProChat/hooks/useProChat.ts index dbdce67e..f805c7d8 100644 --- a/src/ProChat/hooks/useProChat.ts +++ b/src/ProChat/hooks/useProChat.ts @@ -39,6 +39,11 @@ export interface ProChatInstance * @returns */ scrollToBottom?: () => void; + /** + * 获取当前 loading 生成的消息 id + * @returns 消息 id | undefined + */ + getChatLoadingId: () => string | undefined; } export const useProChat = () => { @@ -51,6 +56,7 @@ export const useProChat = () => { deleteMessage, clearMessage, dispatchMessage, + getChatLoadingId, } = storeApi.getState(); const getChats = useRefFunction(() => storeApi.getState().chats); @@ -72,6 +78,7 @@ export const useProChat = () => { getChatMessages, resendMessage, sendMessage, + getChatLoadingId, stopGenerateMessage, deleteMessage, clearMessage, diff --git a/src/ProChat/store/action.ts b/src/ProChat/store/action.ts index 88ad201c..b11d7954 100644 --- a/src/ProChat/store/action.ts +++ b/src/ProChat/store/action.ts @@ -104,14 +104,26 @@ export interface ChatAction { */ getMessageId: (messages: ChatMessage[], parentId: string) => Promise; + /** + * 用于更新一条消息的内容(目前仅用于平滑输出时候,其余情况请直接使用 dispatchMessage ) + */ updateMessageContent: (id: string, content: string) => Promise; + /** + * 创建一条平滑输出的内容 + */ createSmoothMessage: (id: string) => { startAnimation: (speed?: number) => Promise; stopAnimation: () => void; outputQueue: string[]; isAnimationActive: boolean; }; + + /** + * 获取当前 loading 生成的消息 id + * @returns 消息 id | undefined + */ + getChatLoadingId: () => string | undefined; } export const chatAction: StateCreator = ( @@ -445,4 +457,9 @@ export const chatAction: StateCreator { + const { chatLoadingId } = get(); + return chatLoadingId; + }, });