From d2915f6984fad826d7255ffe32d307a470b98ba8 Mon Sep 17 00:00:00 2001 From: balibabu Date: Fri, 28 Nov 2025 19:05:43 +0800 Subject: [PATCH] Fix: Error 102 "Can't find dialog by ID" when embedding agent with from=agent** #11552 (#11594) ### What problem does this PR solve? Fix: Error 102 "Can't find dialog by ID" when embedding agent with from=agent** #11552 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- web/src/components/floating-chat-widget.tsx | 42 ++++++++++++++------- web/src/pages/agent/chat/box.tsx | 14 ++++--- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/web/src/components/floating-chat-widget.tsx b/web/src/components/floating-chat-widget.tsx index c31cb41bd..c02d28f0a 100644 --- a/web/src/components/floating-chat-widget.tsx +++ b/web/src/components/floating-chat-widget.tsx @@ -1,8 +1,10 @@ import PdfSheet from '@/components/pdf-drawer'; import { useClickDrawer } from '@/components/pdf-drawer/hooks'; -import { MessageType } from '@/constants/chat'; +import { MessageType, SharedFrom } from '@/constants/chat'; +import { useFetchExternalAgentInputs } from '@/hooks/use-agent-request'; import { useFetchExternalChatInfo } from '@/hooks/use-chat-request'; import i18n from '@/locales/config'; +import { useSendNextSharedMessage } from '@/pages/agent/hooks/use-send-shared-message'; import { MessageCircle, Minimize2, Send, X } from 'lucide-react'; import React, { useCallback, useEffect, useRef, useState } from 'react'; import { @@ -20,7 +22,13 @@ const FloatingChatWidget = () => { const [isLoaded, setIsLoaded] = useState(false); const messagesEndRef = useRef(null); - const { sharedId: conversationId, locale } = useGetSharedChatSearchParams(); + const { + sharedId: conversationId, + locale, + from, + } = useGetSharedChatSearchParams(); + + const isFromAgent = from === SharedFrom.Agent; // Check if we're in button-only mode or window-only mode const urlParams = new URLSearchParams(window.location.search); @@ -34,7 +42,7 @@ const FloatingChatWidget = () => { sendLoading, derivedMessages, hasError, - } = useSendSharedMessage(); + } = (isFromAgent ? useSendNextSharedMessage : useSendSharedMessage)(() => {}); // Sync our local input with the hook's value when needed useEffect(() => { @@ -43,7 +51,11 @@ const FloatingChatWidget = () => { } }, [hookValue, inputValue]); - const { data: chatInfo } = useFetchExternalChatInfo(); + const { data } = ( + isFromAgent ? useFetchExternalAgentInputs : useFetchExternalChatInfo + )(); + + const title = data.title; const { visible, hideModal, documentId, selectedChunk, clickDocumentButton } = useClickDrawer(); @@ -372,7 +384,7 @@ const FloatingChatWidget = () => {

- {chatInfo?.title || 'Chat Support'} + {title || 'Chat Support'}

We typically reply instantly @@ -494,14 +506,16 @@ const FloatingChatWidget = () => {

- + {visible && ( + + )} ); } // Full mode - render everything together (original behavior) @@ -524,7 +538,7 @@ const FloatingChatWidget = () => {

- {chatInfo?.title || 'Chat Support'} + {title || 'Chat Support'}

We typically reply instantly diff --git a/web/src/pages/agent/chat/box.tsx b/web/src/pages/agent/chat/box.tsx index 85abf6827..df4d006b2 100644 --- a/web/src/pages/agent/chat/box.tsx +++ b/web/src/pages/agent/chat/box.tsx @@ -127,12 +127,14 @@ function AgentChatBox() { /> )} - + {visible && ( + + )} ); }