From d4128f0895d7747ee18b063962374fa5c0541dc7 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Tue, 17 Nov 2026 14:20:06 +0100 Subject: [PATCH] fix: a prompt from an embed goes to the wrong chat or to two chats at once (#34161) * fix: a prompt from an embed goes to the wrong chat or to two chats at once With a note open and its chat beside it, a prompt sent by an embed in that chat was picked up by that chat and by the main chat behind the note tab, so a tool embed's "ask the chat" button opened two confirmation dialogs. In a side chat the same button asked the prompt in the main chat. Each embed now belongs to the chat that shows it, and only that chat takes its prompt; a prompt from anywhere else goes to the page's main chat as before. Fixes #34152 * fix: route a prompt from any embedded frame to the chat that shows it The chat a prompt belongs to is now read from where the sending frame sits on the page, for every frame and not only tool embeds, so artifacts and inline HTML in a chat tab or beside a note also reach the right chat. A prompt that comes from no frame goes to the main chat. * Name the message's source chat apart from the chat object --- src/lib/components/chat/Chat.svelte | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 558a1a21e9..f8050e18e6 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -2106,6 +2106,14 @@ return; } + const iframe = [...document.querySelectorAll('iframe')].find( + (frame) => frame.contentWindow === event.source + ); + const sourceChat = iframe?.closest('[data-chat]')?.getAttribute('data-chat') ?? 'main'; + if (sourceChat !== (embedded ? instanceId : 'main')) { + return; + } + if (type === 'action:submit') { console.debug(event.data.text); @@ -2222,7 +2230,7 @@ loading = true; console.log('mounted'); if (!embedded && appLayout) appLayout.initNewChat = initNewChat; - if (!tabbed) window.addEventListener('message', onMessageHandler); + window.addEventListener('message', onMessageHandler); $socket?.on('events', chatEventHandler); $socket?.on('connect', handleSocketConnect); $socket?.on('disconnect', clearTyping);