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.

✨ feat(chat-input): show device details in the project execution environment switcher (#21495)

Lobehub Coder400eadc733f0
diff --git a/src/features/ChatInput/ControlBar/DeviceDetailPopover.tsx b/src/features/ChatInput/ControlBar/DeviceDetailPopover.tsx
new file mode 100644
index 00000000000..7a7c4a7bc86
--- /dev/null
+++ b/src/features/ChatInput/ControlBar/DeviceDetailPopover.tsx
@@ -0,0 +1,42 @@
+'use client';
+
+import type { DeviceListItem } from '@lobechat/types';
+import { Popover } from '@lobehub/ui';
+import type { ReactElement } from 'react';
+
+import DeviceHoverPanel from '@/features/DeviceManager/DeviceHoverPanel';
+
+/** Long enough that sweeping the pointer down the list doesn't flash a panel per row. */
+const DETAIL_OPEN_DELAY_MS = 300;
+
+/**
+ * Rows sit ~5px inside the menu edge, so the default 6px offset leaves the
+ * panels touching. 12px matches the model provider submenu (~7px visible gap).
+ */
+const DETAIL_SIDE_OFFSET = 12;
+
+interface DeviceDetailPopoverProps {
+ children: ReactElement;
+ device: DeviceListItem;
+}
+
+/**
+ * Opens a device's details beside an execution environment menu while its row
+ * is hovered — offline rows too, since "why can't I pick this" is exactly when
+ * the specs and last-seen time matter.
+ */
+const DeviceDetailPopover = ({ children, device }: DeviceDetailPopoverProps) => (
+ <Popover
+ arrow={false}
+ content={<DeviceHoverPanel device={device} />}
+ openDelay={DETAIL_OPEN_DELAY_MS}
+ placement={'rightTop'}
+ positionerProps={{ sideOffset: DETAIL_SIDE_OFFSET }}
+ styles={{ content: { padding: 4 } }}
+ trigger={'hover'}
+ >
+ {children}
+ </Popover>
+);
+
+export default DeviceDetailPopover;
diff --git a/src/features/ChatInput/ControlBar/DeviceOptionRow.tsx b/src/features/ChatInput/ControlBar/DeviceOptionRow.tsx
index 6c4d923e454..d24435072b0 100644
--- a/src/features/ChatInput/ControlBar/DeviceOptionRow.tsx
+++ b/src/features/ChatInput/ControlBar/DeviceOptionRow.tsx
@@ -1,15 +1,15 @@
'use client';
import type { DeviceListItem } from '@lobechat/types';
-import { Button, createStaticStyles, Icon, Popover } from '@lobehub/ui';
+import { Button, createStaticStyles, Icon } from '@lobehub/ui';
import { RefreshCwIcon } from 'lucide-react';
import type { ReactNode } from 'react';
import { useTranslation } from 'react-i18next';
-import DeviceHoverPanel from '@/features/DeviceManager/DeviceHoverPanel';
import { ExecutionTargetDeviceStatus, ExecutionTargetIcon } from '@/features/ExecutionTargetPicker';
import { isDevicePresenceUnknown } from '@/store/device';
+import DeviceDetailPopover from './DeviceDetailPopover';
import { handleDeviceRowKeyDown } from './deviceRowKeyDown';
import OptionRow from './OptionRow';
@@ -22,15 +22,6 @@ const styles = createStaticStyles(({ css }) => ({
`,
}));
-/** Long enough that sweeping the pointer down the list doesn't flash a panel per row. */
-const DETAIL_OPEN_DELAY_MS = 300;
-
-/**
- * Rows sit ~5px inside the menu edge, so the default 6px offset leaves the
- * panels touching. 12px matches the model provider submenu (~7px visible gap).
- */
-const DETAIL_SIDE_OFFSET = 12;
-
interface DeviceOptionRowProps {
active: boolean;
device: DeviceListItem;
@@ -44,8 +35,7 @@ interface DeviceOptionRowProps {
/**
* One device in the execution environment picker. Hovering it opens the
- * device's details beside the menu — offline rows too, since "why can't I pick
- * this" is exactly when the specs and last-seen time matter.
+ * device's details beside the menu.
*/
const DeviceOptionRow = ({
active,
@@ -61,15 +51,7 @@ const DeviceOptionRow = ({
const presenceUnknown = isDevicePresenceUnknown(device);
return (
- <Popover
- arrow={false}
- content={<DeviceHoverPanel device={device} />}
- openDelay={DETAIL_OPEN_DELAY_MS}
- placement={'rightTop'}
- positionerProps={{ sideOffset: DETAIL_SIDE_OFFSET }}
- styles={{ content: { padding: 4 } }}
- trigger={'hover'}
- >
+ <DeviceDetailPopover device={device}>
<div
data-testid={`device-option-${device.deviceId}`}
onKeyDown={(event) => handleDeviceRowKeyDown(event, { disabled: !device.online, onSelect })}
@@ -115,7 +97,7 @@ const DeviceOptionRow = ({
onClick={onSelect}
/>
</div>
- </Popover>
+ </DeviceDetailPopover>
);
};
diff --git a/src/features/ChatInput/ControlBar/ProjectDeviceSwitcher.tsx b/src/features/ChatInput/ControlBar/ProjectDeviceSwitcher.tsx
index 5e79582c4f2..ef71d05410a 100644
--- a/src/features/ChatInput/ControlBar/ProjectDeviceSwitcher.tsx
+++ b/src/features/ChatInput/ControlBar/ProjectDeviceSwitcher.tsx
@@ -12,6 +12,7 @@ import { agentByIdSelectors } from '@/store/agent/selectors';
import { useDeviceList } from '@/store/device';
import { type ProjectDirectory } from '@/store/projectWorkingDirectory';
+import DeviceDetailPopover from './DeviceDetailPopover';
import OptionRow from './OptionRow';
import {
listProjectDeviceTargets,
@@ -101,7 +102,7 @@ const ProjectDeviceSwitcher = ({
<div className={styles.title}>{t('heteroAgent.executionTarget.title')}</div>
{targets.map((target) => {
const selectable = target.online && target.allowed;
- return (
+ const row = (
<OptionRow
active={target.active}
disabled={!selectable}
@@ -132,6 +133,15 @@ const ProjectDeviceSwitcher = ({
onClick={() => (selectable ? handleSelect(target) : undefined)}
/>
);
+ // Same hover details as the regular device picker: the label alone
+ // can't tell two machines' specs or last-seen time apart.
+ return target.device ? (
+ <DeviceDetailPopover device={target.device} key={target.directory.id}>
+ <div>{row}</div>
+ </DeviceDetailPopover>
+ ) : (
+ row
+ );
})}
<div className={styles.hint}>{t('heteroAgent.executionTarget.projectDevicesHint')}</div>
</Flexbox>
diff --git a/src/features/ChatInput/ControlBar/__tests__/projectDeviceTargets.test.ts b/src/features/ChatInput/ControlBar/__tests__/projectDeviceTargets.test.ts
index 1d6c76c6467..f9f9b7b9fcf 100644
--- a/src/features/ChatInput/ControlBar/__tests__/projectDeviceTargets.test.ts
+++ b/src/features/ChatInput/ControlBar/__tests__/projectDeviceTargets.test.ts
@@ -83,4 +83,14 @@ describe('listProjectDeviceTargets', () => {
);
expect(target).toMatchObject({ label: 'Build box', online: false });
});
+
+ it('carries the registered device so the row can show its details', () => {
+ const [known, unknown] = listProjectDeviceTargets(
+ [directory('dir-a', 'dev-a'), directory('dir-x', 'dev-x')],
+ devices,
+ undefined,
+ );
+ expect(known.device).toBe(devices[0]);
+ expect(unknown.device).toBeUndefined();
+ });
});
diff --git a/src/features/ChatInput/ControlBar/projectDeviceTargets.ts b/src/features/ChatInput/ControlBar/projectDeviceTargets.ts
index 6448e2250c4..25606255881 100644
--- a/src/features/ChatInput/ControlBar/projectDeviceTargets.ts
+++ b/src/features/ChatInput/ControlBar/projectDeviceTargets.ts
@@ -6,6 +6,8 @@ export interface ProjectDeviceTarget {
active: boolean;
/** False when the agent is fixed to another device — the move would be refused. */
allowed: boolean;
+ /** The registered device behind the directory, when the device list knows it. */
+ device?: DeviceListItem;
directory: ProjectDirectory;
label: string;
online: boolean;
@@ -42,6 +44,7 @@ export const listProjectDeviceTargets = (
return {
active: directory.id === currentDirectoryId,
allowed: !fixedDeviceId || directory.deviceId === fixedDeviceId,
+ device,
directory,
label: projectDirectoryDeviceName(directory, devices),
online: !!device?.online,