Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix(hetero-agent): hide sandbox selector when device switcher is visible and sync runtimeMode (#15252)

LiJian5eee6d21e320
diff --git a/src/features/ChatInput/RuntimeConfig/HeteroDeviceSwitcher.tsx b/src/features/ChatInput/RuntimeConfig/HeteroDeviceSwitcher.tsx
index b9191e40f92..977ba94092f 100644
--- a/src/features/ChatInput/RuntimeConfig/HeteroDeviceSwitcher.tsx
+++ b/src/features/ChatInput/RuntimeConfig/HeteroDeviceSwitcher.tsx
@@ -3,7 +3,7 @@
import { SiApple, SiLinux } from '@icons-pack/react-simple-icons';
import { isDesktop } from '@lobechat/const';
import { isRemoteHeterogeneousType } from '@lobechat/heterogeneous-agents';
-import type { HeteroExecutionTarget } from '@lobechat/types';
+import type { HeteroExecutionTarget, RuntimeEnvMode } from '@lobechat/types';
import { Microsoft } from '@lobehub/icons';
import { Flexbox, Icon, Popover, Tooltip } from '@lobehub/ui';
import { createStaticStyles, cssVar, cx } from 'antd-style';
@@ -226,7 +226,7 @@ const HeteroDeviceSwitcher = memo<HeteroDeviceSwitcherProps>(({ agentId }) => {
const [open, setOpen] = useState(false);
const agencyConfig = useAgentStore(agentByIdSelectors.getAgencyConfigById(agentId));
- const updateAgentConfig = useAgentStore((s) => s.updateAgentConfig);
+ const updateAgentConfigById = useAgentStore((s) => s.updateAgentConfigById);
const heteroType = agencyConfig?.heterogeneousProvider?.type;
const storedTarget = agencyConfig?.executionTarget;
@@ -242,15 +242,25 @@ const HeteroDeviceSwitcher = memo<HeteroDeviceSwitcherProps>(({ agentId }) => {
const handleSelect = useCallback(
async (target: HeteroExecutionTarget, deviceId?: string) => {
setOpen(false);
- await updateAgentConfig({
+
+ // Keep runtimeMode in sync so the server-side tool gate (runtimeMode === 'cloud'
+ // enables CloudSandbox) reflects the user's chosen execution target.
+ // Use a single updateAgentConfigById to persist both fields atomically β€” parallel
+ // calls share the same abort signal name and the second would cancel the first.
+ const platform = isDesktop ? 'desktop' : 'web';
+ const runtimeMode: RuntimeEnvMode =
+ target === 'sandbox' ? 'cloud' : target === 'local' ? 'local' : 'none';
+
+ await updateAgentConfigById(agentId, {
agencyConfig: {
...agencyConfig,
executionTarget: target,
...(target === 'device' && deviceId ? { boundDeviceId: deviceId } : {}),
},
+ chatConfig: { runtimeEnv: { runtimeMode: { [platform]: runtimeMode } } },
});
},
- [agencyConfig, updateAgentConfig],
+ [agentId, agencyConfig, updateAgentConfigById],
);
// Don't render for remote hetero agents β€” they use RemoteAgentConfigCard in profile.
diff --git a/src/features/ChatInput/RuntimeConfig/index.tsx b/src/features/ChatInput/RuntimeConfig/index.tsx
index baf90c1dc6e..b1980b87160 100644
--- a/src/features/ChatInput/RuntimeConfig/index.tsx
+++ b/src/features/ChatInput/RuntimeConfig/index.tsx
@@ -125,6 +125,11 @@ const RuntimeConfig = memo(() => {
labPreferSelectors.enableExecutionDeviceSwitcher,
);
+ // When the execution device switcher is visible, it takes over sandbox/runtime routing.
+ // Hide the runtimeMode selector to avoid two conflicting controls for the same decision.
+ const showDeviceSwitcher =
+ enableAgentMode && !isHeterogeneous && enableExecutionDeviceSwitcher && !!agentId;
+
const topicWorkingDirectory = useChatStore(topicSelectors.currentTopicWorkingDirectory);
const agentWorkingDirectory = useAgentStore((s) =>
agentId ? agentByIdSelectors.getAgentWorkingDirectoryById(agentId)(s) : undefined,
@@ -292,27 +297,27 @@ const RuntimeConfig = memo(() => {
{/* Left: Chat mode switcher + (agent-only) runtime env + working directory */}
<Flexbox horizontal align={'center'} gap={4}>
<ModeSelector />
- {enableAgentMode && !isHeterogeneous && enableExecutionDeviceSwitcher && agentId && (
- <HeteroDeviceSwitcher agentId={agentId} />
- )}
+ {showDeviceSwitcher && <HeteroDeviceSwitcher agentId={agentId} />}
{enableAgentMode && (
<>
- <Popover
- content={modeContent}
- open={modePopoverOpen}
- placement="top"
- styles={{ content: { padding: 4 } }}
- trigger="click"
- onOpenChange={setModePopoverOpen}
- >
- <div>
- {modePopoverOpen ? (
- modeButton
- ) : (
- <Tooltip title={t('runtimeEnv.selectMode')}>{modeButton}</Tooltip>
- )}
- </div>
- </Popover>
+ {!showDeviceSwitcher && (
+ <Popover
+ content={modeContent}
+ open={modePopoverOpen}
+ placement="top"
+ styles={{ content: { padding: 4 } }}
+ trigger="click"
+ onOpenChange={setModePopoverOpen}
+ >
+ <div>
+ {modePopoverOpen ? (
+ modeButton
+ ) : (
+ <Tooltip title={t('runtimeEnv.selectMode')}>{modeButton}</Tooltip>
+ )}
+ </div>
+ </Popover>
+ )}
{rightContent()}
</>
)}