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
This commit is contained in:
Classic298 authored and GitHub committed 2026-11-17 22:20:06 +09:00
1 parent aca79d17b2
commit d4128f0895
1 file changed
+9 -1
+9 -1
View File
@@ -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);