From ec9db9f0f68425ef0fb04a2a03d243c7d048c001 Mon Sep 17 00:00:00 2001 From: coso Date: Mon, 16 Feb 2026 10:16:00 +0800 Subject: [PATCH] fix(agent-chat): align clearMessages signature with unified hook callers --- .../agent/chat/hooks/useAsterAgentChat.ts | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/components/agent/chat/hooks/useAsterAgentChat.ts b/src/components/agent/chat/hooks/useAsterAgentChat.ts index d0f460bc8..98e5d22d6 100644 --- a/src/components/agent/chat/hooks/useAsterAgentChat.ts +++ b/src/components/agent/chat/hooks/useAsterAgentChat.ts @@ -936,16 +936,29 @@ export function useAsterAgentChat(options: UseAsterAgentChatOptions) { await sendMessage("", [], false, false, true); }, [sendMessage]); - // 清空消息 - const clearMessages = useCallback(() => { - setMessages([]); - setSessionId(null); - setPendingActions([]); - restoredWorkspaceRef.current = null; - hydratedSessionRef.current = null; - skipAutoRestoreRef.current = true; - toast.success("新话题已创建"); - }, []); + // 清空消息(兼容 useAgentChat 的可选参数) + const clearMessages = useCallback( + ( + options: { + showToast?: boolean; + toastMessage?: string; + } = {}, + ) => { + const { showToast = true, toastMessage = "新话题已创建" } = options; + + setMessages([]); + setSessionId(null); + setPendingActions([]); + restoredWorkspaceRef.current = null; + hydratedSessionRef.current = null; + skipAutoRestoreRef.current = true; + + if (showToast) { + toast.success(toastMessage); + } + }, + [], + ); // 删除消息 const deleteMessage = useCallback((id: string) => {