fix(chat): sync subagent prompting in context panel
This commit is contained in:
@@ -586,7 +586,40 @@ export const ChatContainer: React.FC<ChatContainerProps> = ({ autoOpenDraft = tr
|
|||||||
{t('chat.container.returnToParent.label')}
|
{t('chat.container.returnToParent.label')}
|
||||||
</Button>
|
</Button>
|
||||||
) : null;
|
) : null;
|
||||||
const promptReadOnly = readOnly || (Boolean(parentSession) && !allowPromptingSubagentSessions);
|
const promptReadOnly = parentSession ? !allowPromptingSubagentSessions : readOnly;
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (typeof window === 'undefined' || window.parent === window) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const applySetting = (value: boolean) => {
|
||||||
|
useUIStore.getState().setAllowPromptingSubagentSessions(value);
|
||||||
|
};
|
||||||
|
const scopedWindow = window as typeof window & {
|
||||||
|
__openchamberApplyChatSettingsSync?: (payload: { allowPromptingSubagentSessions: boolean }) => void;
|
||||||
|
};
|
||||||
|
const applySync = (payload: { allowPromptingSubagentSessions: boolean }) => {
|
||||||
|
applySetting(payload.allowPromptingSubagentSessions);
|
||||||
|
};
|
||||||
|
const handleMessage = (event: MessageEvent) => {
|
||||||
|
if (event.source !== window.parent || event.origin !== window.location.origin) return;
|
||||||
|
const data = event.data as { type?: unknown; payload?: { allowPromptingSubagentSessions?: unknown } };
|
||||||
|
if (data?.type !== 'openchamber:chat-settings-sync'
|
||||||
|
|| typeof data.payload?.allowPromptingSubagentSessions !== 'boolean') return;
|
||||||
|
applySetting(data.payload.allowPromptingSubagentSessions);
|
||||||
|
};
|
||||||
|
|
||||||
|
scopedWindow.__openchamberApplyChatSettingsSync = applySync;
|
||||||
|
window.addEventListener('message', handleMessage);
|
||||||
|
window.parent.postMessage({ type: 'openchamber:chat-settings-request' }, window.location.origin);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('message', handleMessage);
|
||||||
|
if (scopedWindow.__openchamberApplyChatSettingsSync === applySync) {
|
||||||
|
delete scopedWindow.__openchamberApplyChatSettingsSync;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (autoOpenDraft && !currentSessionId && !draftOpen) {
|
if (autoOpenDraft && !currentSessionId && !draftOpen) {
|
||||||
|
|||||||
@@ -1017,6 +1017,7 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
|
|||||||
isUser={isUser}
|
isUser={isUser}
|
||||||
isMessageCompleted={isMessageCompleted}
|
isMessageCompleted={isMessageCompleted}
|
||||||
messageFinish={messageFinish}
|
messageFinish={messageFinish}
|
||||||
|
messageCreatedAt={messageCreatedAt ?? undefined}
|
||||||
isMobile={isMobile}
|
isMobile={isMobile}
|
||||||
alwaysShowActions={alwaysShowMessageActions}
|
alwaysShowActions={alwaysShowMessageActions}
|
||||||
hasTouchInput={hasTouchInput}
|
hasTouchInput={hasTouchInput}
|
||||||
@@ -1050,6 +1051,7 @@ const ChatMessage: React.FC<ChatMessageProps> = ({
|
|||||||
isUser={isUser}
|
isUser={isUser}
|
||||||
isMessageCompleted={isMessageCompleted}
|
isMessageCompleted={isMessageCompleted}
|
||||||
messageFinish={messageFinish}
|
messageFinish={messageFinish}
|
||||||
|
messageCreatedAt={messageCreatedAt ?? undefined}
|
||||||
isMobile={isMobile}
|
isMobile={isMobile}
|
||||||
alwaysShowActions={alwaysShowMessageActions}
|
alwaysShowActions={alwaysShowMessageActions}
|
||||||
hasTouchInput={hasTouchInput}
|
hasTouchInput={hasTouchInput}
|
||||||
|
|||||||
@@ -2070,6 +2070,7 @@ export const ContextPanel: React.FC = () => {
|
|||||||
const reorderContextPanelTabs = useUIStore((state) => state.reorderContextPanelTabs);
|
const reorderContextPanelTabs = useUIStore((state) => state.reorderContextPanelTabs);
|
||||||
const setSelectedFilePath = useFilesViewTabsStore((state) => state.setSelectedPath);
|
const setSelectedFilePath = useFilesViewTabsStore((state) => state.setSelectedPath);
|
||||||
const openContextPreview = useUIStore((state) => state.openContextPreview);
|
const openContextPreview = useUIStore((state) => state.openContextPreview);
|
||||||
|
const allowPromptingSubagentSessions = useUIStore((state) => state.allowPromptingSubagentSessions);
|
||||||
const { themeMode, setThemeMode, lightThemeId, darkThemeId, currentTheme } = useThemeSystem();
|
const { themeMode, setThemeMode, lightThemeId, darkThemeId, currentTheme } = useThemeSystem();
|
||||||
|
|
||||||
const tabs = React.useMemo(() => panelState?.tabs ?? [], [panelState?.tabs]);
|
const tabs = React.useMemo(() => panelState?.tabs ?? [], [panelState?.tabs]);
|
||||||
@@ -2359,6 +2360,30 @@ export const ContextPanel: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, [currentTheme, darkThemeId, lightThemeId, themeMode]);
|
}, [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(() => {
|
const postEmbeddedVisibilityToChats = React.useCallback(() => {
|
||||||
if (typeof window === 'undefined') {
|
if (typeof window === 'undefined') {
|
||||||
return;
|
return;
|
||||||
@@ -2411,6 +2436,10 @@ export const ContextPanel: React.FC = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = event.data as { type?: unknown };
|
const data = event.data as { type?: unknown };
|
||||||
|
if (data?.type === 'openchamber:chat-settings-request') {
|
||||||
|
postChatSettingsSyncToEmbeddedChat();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (data?.type !== 'openchamber:cycle-theme-request') {
|
if (data?.type !== 'openchamber:cycle-theme-request') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2423,7 +2452,7 @@ export const ContextPanel: React.FC = () => {
|
|||||||
|
|
||||||
window.addEventListener('message', handleMessage);
|
window.addEventListener('message', handleMessage);
|
||||||
return () => window.removeEventListener('message', handleMessage);
|
return () => window.removeEventListener('message', handleMessage);
|
||||||
}, [setThemeMode, themeMode]);
|
}, [postChatSettingsSyncToEmbeddedChat, setThemeMode, themeMode]);
|
||||||
|
|
||||||
React.useLayoutEffect(() => {
|
React.useLayoutEffect(() => {
|
||||||
const hasAnyChatTab = tabs.some((tab) => tab.mode === 'chat');
|
const hasAnyChatTab = tabs.some((tab) => tab.mode === 'chat');
|
||||||
@@ -2432,8 +2461,9 @@ export const ContextPanel: React.FC = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
postThemeSyncToEmbeddedChat();
|
postThemeSyncToEmbeddedChat();
|
||||||
|
postChatSettingsSyncToEmbeddedChat();
|
||||||
postEmbeddedVisibilityToChats();
|
postEmbeddedVisibilityToChats();
|
||||||
}, [darkThemeId, lightThemeId, postEmbeddedVisibilityToChats, postThemeSyncToEmbeddedChat, tabs, themeMode]);
|
}, [darkThemeId, lightThemeId, postChatSettingsSyncToEmbeddedChat, postEmbeddedVisibilityToChats, postThemeSyncToEmbeddedChat, tabs, themeMode]);
|
||||||
|
|
||||||
const tabItems = React.useMemo(() => tabs.map((tab) => {
|
const tabItems = React.useMemo(() => tabs.map((tab) => {
|
||||||
const rawLabel = getTabLabel(tab, sessionTitleById, t);
|
const rawLabel = getTabLabel(tab, sessionTitleById, t);
|
||||||
@@ -2628,6 +2658,7 @@ export const ContextPanel: React.FC = () => {
|
|||||||
)}
|
)}
|
||||||
onLoad={() => {
|
onLoad={() => {
|
||||||
postThemeSyncToEmbeddedChat();
|
postThemeSyncToEmbeddedChat();
|
||||||
|
postChatSettingsSyncToEmbeddedChat();
|
||||||
postEmbeddedVisibilityToChats();
|
postEmbeddedVisibilityToChats();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user