fix(chat): sync subagent prompting in context panel

This commit is contained in:
Bohdan Triapitsyn
2026-07-13 01:21:18 +03:00
parent 7e12a0dcef
commit 08e4ce5b99
3 changed files with 69 additions and 3 deletions
@@ -2070,6 +2070,7 @@ export const ContextPanel: React.FC = () => {
const reorderContextPanelTabs = useUIStore((state) => state.reorderContextPanelTabs);
const setSelectedFilePath = useFilesViewTabsStore((state) => state.setSelectedPath);
const openContextPreview = useUIStore((state) => state.openContextPreview);
const allowPromptingSubagentSessions = useUIStore((state) => state.allowPromptingSubagentSessions);
const { themeMode, setThemeMode, lightThemeId, darkThemeId, currentTheme } = useThemeSystem();
const tabs = React.useMemo(() => panelState?.tabs ?? [], [panelState?.tabs]);
@@ -2359,6 +2360,30 @@ export const ContextPanel: React.FC = () => {
}
}, [currentTheme, darkThemeId, lightThemeId, themeMode]);
const postChatSettingsSyncToEmbeddedChat = React.useCallback(() => {
if (typeof window === 'undefined') return;
const payload = { allowPromptingSubagentSessions };
for (const frame of chatFrameRefs.current.values()) {
const frameWindow = frame.contentWindow;
if (!frameWindow) continue;
const directSync = (frameWindow as unknown as {
__openchamberApplyChatSettingsSync?: (settings: typeof payload) => void;
}).__openchamberApplyChatSettingsSync;
if (typeof directSync === 'function') {
try {
directSync(payload);
continue;
} catch {
// fallback to postMessage below
}
}
frameWindow.postMessage({ type: 'openchamber:chat-settings-sync', payload }, window.location.origin);
}
}, [allowPromptingSubagentSessions]);
const postEmbeddedVisibilityToChats = React.useCallback(() => {
if (typeof window === 'undefined') {
return;
@@ -2411,6 +2436,10 @@ export const ContextPanel: React.FC = () => {
}
const data = event.data as { type?: unknown };
if (data?.type === 'openchamber:chat-settings-request') {
postChatSettingsSyncToEmbeddedChat();
return;
}
if (data?.type !== 'openchamber:cycle-theme-request') {
return;
}
@@ -2423,7 +2452,7 @@ export const ContextPanel: React.FC = () => {
window.addEventListener('message', handleMessage);
return () => window.removeEventListener('message', handleMessage);
}, [setThemeMode, themeMode]);
}, [postChatSettingsSyncToEmbeddedChat, setThemeMode, themeMode]);
React.useLayoutEffect(() => {
const hasAnyChatTab = tabs.some((tab) => tab.mode === 'chat');
@@ -2432,8 +2461,9 @@ export const ContextPanel: React.FC = () => {
}
postThemeSyncToEmbeddedChat();
postChatSettingsSyncToEmbeddedChat();
postEmbeddedVisibilityToChats();
}, [darkThemeId, lightThemeId, postEmbeddedVisibilityToChats, postThemeSyncToEmbeddedChat, tabs, themeMode]);
}, [darkThemeId, lightThemeId, postChatSettingsSyncToEmbeddedChat, postEmbeddedVisibilityToChats, postThemeSyncToEmbeddedChat, tabs, themeMode]);
const tabItems = React.useMemo(() => tabs.map((tab) => {
const rawLabel = getTabLabel(tab, sessionTitleById, t);
@@ -2628,6 +2658,7 @@ export const ContextPanel: React.FC = () => {
)}
onLoad={() => {
postThemeSyncToEmbeddedChat();
postChatSettingsSyncToEmbeddedChat();
postEmbeddedVisibilityToChats();
}}
/>